@libp2p/noise 17.0.2 → 17.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +3 -3
- package/package.json +4 -4
package/dist/index.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PNoise = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PNoise=(()=>{var Jn=Object.defineProperty;var Hc=Object.getOwnPropertyDescriptor;var qc=Object.getOwnPropertyNames;var zc=Object.prototype.hasOwnProperty;var Ae=(t,e)=>{for(var r in e)Jn(t,r,{get:e[r],enumerable:!0})},jc=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of qc(e))!zc.call(t,s)&&s!==r&&Jn(t,s,{get:()=>e[s],enumerable:!(n=Hc(e,s))||n.enumerable});return t};var Vc=t=>jc(Jn({},"__esModule",{value:!0}),t);var gl={};Ae(gl,{noise:()=>yl,pureJsCrypto:()=>Wn});var zr=class extends Error{static name="UnexpectedPeerError";constructor(e="Unexpected Peer"){super(e),this.name="UnexpectedPeerError"}},jr=class extends Error{static name="InvalidCryptoExchangeError";constructor(e="Invalid crypto exchange"){super(e),this.name="InvalidCryptoExchangeError"}},ie=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Kt=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var Vr=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var et=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},mt=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var Ut=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var $r=class extends Event{data;constructor(e,r){super("message",r),this.data=e}},Pt=class extends Event{error;local;constructor(e,r,n){super("close",n),this.error=r,this.local=e}},Yr=class extends Pt{constructor(e,r){super(!0,e,r)}},Wr=class extends Pt{constructor(e,r){super(!1,e,r)}};var Qn=Symbol.for("@libp2p/peer-id");function $c(t){return typeof t?.handleEvent=="function"}function Yc(t){return t===!0||t===!1}function Wc(t){return Yc(t)?t:t?.capture??!1}function es(t){let e={capture:Wc(t),once:!!t?.once};return t?.passive!=null&&(e.passive=t?.passive),t?.signal!=null&&(e.signal=t?.signal),e}function ii(t,e){return es(t).capture===es(e).capture}var Gr=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=es(n);if(s?.signal?.aborted===!0)return;let o=f=>{s.once&&this.removeEventListener(e,r,s),$c(r)?r.handleEvent(f):r(f)},i=this.#e.get(e);if(i==null&&(i=[],this.#e.set(e,i)),i.some(f=>f.callback!==r?!1:ii(f.options,s)))return;super.addEventListener(e,o,s);let c=()=>{this.removeEventListener(e,r,s)};s.signal?.addEventListener("abort",c),i.push({callback:r,wrapper:o,options:s,onAbort:c})}removeEventListener(e,r,n){let s=this.#e.get(e);if(s==null){super.removeEventListener(e,r??null,n);return}this.#e.set(e,s.filter(o=>o.callback===r&&ii(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 ai=Symbol.for("@libp2p/service-capabilities");var os={};Ae(os,{base58btc:()=>fe,base58flickr:()=>rf});var Wl=new Uint8Array(0);function fi(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 Te(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return yt(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return yt(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function ui(t){let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}var ci=4096;function hi(t){let e=t.length;if(e<=ci)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.subarray(n,n+=ci));return r}function Gc(t){return t?.buffer instanceof ArrayBuffer}function yt(t){return Gc(t)?t:t.slice()}function Zc(t,e,r){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),s=0;s<n.length;s++)n[s]=255;for(var o=0;o<t.length;o++){var i=t.charAt(o),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=o,r){var c=i.toLowerCase().charCodeAt(0),f=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=o),f!==a&&(n[f]=o)}}var u=t.length,h=t.charAt(0),p=Math.log(u)/Math.log(256),d=Math.log(256)/Math.log(u);function w(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,b=0,R=0,T=x.length;R!==T&&x[R]===0;)R++,E++;for(var O=(T-R)*d+1>>>0,N=new Uint8Array(O);R!==T;){for(var K=x[R],_=0,C=O-1;(K!==0||_<b)&&C!==-1;C--,_++)K+=256*N[C]>>>0,N[C]=K%u>>>0,K=K/u>>>0;if(K!==0)throw new Error("Non-zero carry");b=_,R++}for(var F=O-b;F!==O&&N[F]===0;)F++;for(var M=h.repeat(E);F<O;++F)M+=t.charAt(N[F]);return M}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 b=0,R=0;x[E]===h;)b++,E++;for(var T=(x.length-E)*p+1>>>0,O=new Uint8Array(T);x[E];){var N=n[x.charCodeAt(E)];if(N===255)return;for(var K=0,_=T-1;(N!==0||K<R)&&_!==-1;_--,K++)N+=u*O[_]>>>0,O[_]=N%256>>>0,N=N/256>>>0;if(N!==0)throw new Error("Non-zero carry");R=K,E++}if(x[E]!==" "){for(var C=T-R;C!==T&&O[C]===0;)C++;for(var F=new Uint8Array(b+(T-C)),M=b;C!==T;)F[M++]=O[C++];return F}}}function y(x){var E=g(x);if(E)return E;throw new Error(`Non-${e} character`)}return{encode:w,decodeUnsafe:g,decode:y}}var Xc=Zc,Jc=Xc,di=Jc;var ts=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")}},rs=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 pi(this,e)}},ns=class{decoders;constructor(e){this.decoders=e}or(e){return pi(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 pi(t,e){return new ns({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var ss=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 ts(e,r,n),this.decoder=new rs(e,r,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Nt({name:t,prefix:e,encode:r,decode:n}){return new ss(t,e,r,n)}function tt({name:t,prefix:e,alphabet:r,caseInsensitive:n=!1}){let{encode:s,decode:o}=di(r,t,n);return Nt({prefix:e,name:t,encode:s,decode:i=>Te(o(i))})}function Qc(t,e,r,n){let s=t.length;for(;t[s-1]==="=";)--s;let o=new Uint8Array(s*r/8|0),i=0,a=0,c=0;for(let f=0;f<s;++f){let u=e[t[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|u,i+=r,i>=8&&(i-=8,o[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return o}function ef(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 tf(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 ae({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:s=!1}){let o=tf(n,s);return Nt({prefix:e,name:t,encode(i){return ef(i,n,r)},decode(i){return Qc(i,o,r,t)}})}var fe=tt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),rf=tt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var is={};Ae(is,{base32:()=>Mt,base32hex:()=>af,base32hexpad:()=>ff,base32hexpadupper:()=>uf,base32hexupper:()=>cf,base32pad:()=>sf,base32padupper:()=>of,base32upper:()=>nf,base32z:()=>hf});var Mt=ae({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),nf=ae({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),sf=ae({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),of=ae({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),af=ae({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),cf=ae({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),ff=ae({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),uf=ae({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),hf=ae({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var as={};Ae(as,{base36:()=>cr,base36upper:()=>lf});var cr=tt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),lf=tt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var df=gi,mi=128,pf=127,mf=~pf,yf=Math.pow(2,31);function gi(t,e,r){e=e||[],r=r||0;for(var n=r;t>=yf;)e[r++]=t&255|mi,t/=128;for(;t&mf;)e[r++]=t&255|mi,t>>>=7;return e[r]=t|0,gi.bytes=r-n+1,e}var gf=cs,bf=128,yi=127;function cs(t,n){var r=0,n=n||0,s=0,o=n,i,a=t.length;do{if(o>=a)throw cs.bytes=0,new RangeError("Could not decode varint");i=t[o++],r+=s<28?(i&yi)<<s:(i&yi)*Math.pow(2,s),s+=7}while(i>=bf);return cs.bytes=o-n,r}var wf=Math.pow(2,7),xf=Math.pow(2,14),Ef=Math.pow(2,21),Sf=Math.pow(2,28),Af=Math.pow(2,35),vf=Math.pow(2,42),Bf=Math.pow(2,49),Lf=Math.pow(2,56),If=Math.pow(2,63),Tf=function(t){return t<wf?1:t<xf?2:t<Ef?3:t<Sf?4:t<Af?5:t<vf?6:t<Bf?7:t<Lf?8:t<If?9:10},_f={encode:df,decode:gf,encodingLength:Tf},Rf=_f,fr=Rf;function ur(t,e=0){let r=fr.decode(t,e),n=fr.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 Ft(t,e,r=0){return fr.encode(t,e,r),e}function Ht(t){return fr.encodingLength(t)}function Ne(t,e){let r=e.byteLength,n=Ht(t),s=n+Ht(r),o=new Uint8Array(s+r);return Ft(t,o,0),Ft(r,o,n),o.set(e,s),new qt(t,r,e,o)}function fs(t){let e=Te(t),[r,n]=ur(e),[s,o]=ur(e.subarray(n)),i=e.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new qt(r,s,i,e)}function bi(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&fi(t.bytes,r.bytes)}}var qt=class{code;size;digest;bytes;constructor(e,r,n,s){this.code=e,this.size=r,this.digest=yt(n),this.bytes=yt(s)}};function wi(t,e){let{bytes:r,version:n}=t;return n===0?Df(r,us(t),e??fe.encoder):Of(r,us(t),e??Mt.encoder)}var xi=new WeakMap;function us(t){let e=xi.get(t);if(e==null){let r=new Map;return xi.set(t,r),r}return e}var ye=class t{code;version;multihash;bytes;"/";constructor(e,r,n,s){this.code=r,this.version=e,this.multihash=n,this.bytes=yt(s),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==hr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==kf)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=Ne(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&&bi(e.multihash,n.multihash)}toString(e){return wi(this,e)}toJSON(){return{"/":wi(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??Ei(n,s,o.bytes))}else if(r[Kf]===!0){let{version:n,multihash:s,code:o}=r,i=fs(s);return t.create(n,o,i)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==hr)throw new Error(`Version 0 CID must use dag-pb (code: ${hr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let s=Ei(e,r,n.bytes);return new t(e,r,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,hr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,s=Te(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 qt(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[h,p]=ur(e.subarray(r));return r+=p,h},s=n(),o=hr;if(s===18?(s=0,r=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=r,a=n(),c=n(),f=r+c,u=f-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(e,r){let[n,s]=Cf(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 us(o).set(n,e),o}};function Cf(t,e){switch(t[0]){case"Q":{let r=e??fe;return[fe.prefix,r.decode(`${fe.prefix}${t}`)]}case fe.prefix:{let r=e??fe;return[fe.prefix,r.decode(t)]}case Mt.prefix:{let r=e??Mt;return[Mt.prefix,r.decode(t)]}case cr.prefix:{let r=e??cr;return[cr.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 Df(t,e,r){let{prefix:n}=r;if(n!==fe.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 Of(t,e,r){let{prefix:n}=r,s=e.get(n);if(s==null){let o=r.encode(t);return e.set(n,o),o}else return s}var hr=112,kf=18;function Ei(t,e,r){let n=Ht(t),s=n+Ht(e),o=new Uint8Array(s+r.byteLength);return Ft(t,o,0),Ft(e,o,n),o.set(r,s),o}var Kf=Symbol.for("@ipld/js-cid/CID");var hs={};Ae(hs,{identity:()=>Me});var Si=0,Uf="identity",Ai=Te;function Pf(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 Ne(Si,Ai(t))}var Me={code:Si,name:Uf,encode:Ai,digest:Pf};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 Nf(t){return t.buffer instanceof ArrayBuffer}function Le(t){return Nf(t)?t:t.slice()}async function vi(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,Le(e),Le(r.subarray()));return n?.signal?.throwIfAborted(),o}function he(t=0){return new Uint8Array(t)}function pe(t=0){return new Uint8Array(t)}function Mf(t){return t?.buffer instanceof ArrayBuffer}function ls(t){if(Mf(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function gt(t,e){e==null&&(e=t.reduce((s,o)=>s+o.length,0));let r=pe(e),n=0;for(let s of t)r.set(s,n),n+=s.length;return ls(r)}var Li=Symbol.for("@achingbrain/uint8arraylist");function Bi(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 Xr(t){return!!t?.[Li]}var G=class t{bufs;length;[Li]=!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(Xr(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(Xr(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=Bi(this.bufs,e);return r.buf[r.index]}set(e,r){let n=Bi(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(Xr(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 gt(n,s)}subarray(e,r){let{bufs:n,length:s}=this._subList(e,r);return n.length===1?n[0]:gt(n,s)}sublist(e,r){let{bufs:n,length:s}=this._subList(e,r),o=new t;return o.length=s,o.bufs=n,o}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],s=0;for(let o=0;o<this.bufs.length;o++){let i=this.bufs[o],a=s,c=a+i.byteLength;if(s=c,e>=c)continue;let f=e>=a&&e<c,u=r>a&&r<=c;if(f&&u){if(e===a&&r===c){n.push(i);break}let h=e-a;n.push(i.subarray(h,h+(r-e)));break}if(f){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(u){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!Xr(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 h=0;h<o;h++)i[h]=-1;for(let h=0;h<s;h++)i[n[h]]=h;let a=i,c=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let h=r;h<=c;h+=u){u=0;for(let p=f;p>=0;p--){let d=this.get(h+p);if(n[p]!==d){u=Math.max(1,p-a[d]);break}}if(u===0)return h}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=pe(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=he(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=he(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=he(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=pe(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=he(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=he(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=he(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=he(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=he(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 ds={};Ae(ds,{base10:()=>Ff});var Ff=tt({prefix:"9",name:"base10",alphabet:"0123456789"});var ps={};Ae(ps,{base16:()=>Hf,base16upper:()=>qf});var Hf=ae({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),qf=ae({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var ms={};Ae(ms,{base2:()=>zf});var zf=ae({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ys={};Ae(ys,{base256emoji:()=>Wf});var Ii=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),jf=Ii.reduce((t,e,r)=>(t[r]=e,t),[]),Vf=Ii.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function $f(t){return t.reduce((e,r)=>(e+=jf[r],e),"")}function Yf(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let s=Vf[n];if(s==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(s)}return new Uint8Array(e)}var Wf=Nt({prefix:"\u{1F680}",name:"base256emoji",encode:$f,decode:Yf});var gs={};Ae(gs,{base64:()=>Gf,base64pad:()=>Zf,base64url:()=>Xf,base64urlpad:()=>Jf});var Gf=ae({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Zf=ae({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Xf=ae({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Jf=ae({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var bs={};Ae(bs,{base8:()=>Qf});var Qf=ae({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ws={};Ae(ws,{identity:()=>eu});var eu=Nt({prefix:"\0",name:"identity",encode:t=>hi(Te(t)),decode:t=>Te(ui(t))});var Od=new TextEncoder,kd=new TextDecoder;var Ss={};Ae(Ss,{sha256:()=>Jr,sha512:()=>su});var nu=20;function Es({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:s}){return new xs(t,e,r,n,s)}var xs=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,s,o){this.name=e,this.code=r,this.encode=n,this.minDigestLength=s??nu,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?Ti(n,this.code,r?.truncate):n.then(s=>Ti(s,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ti(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 Ne(e,t)}function Ri(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Jr=Es({name:"sha2-256",code:18,encode:Ri("SHA-256")}),su=Es({name:"sha2-512",code:19,encode:Ri("SHA-512")});var As={...ws,...ms,...bs,...ds,...ps,...is,...as,...os,...gs,...ys},$d={...Ss,...hs};function Di(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Ci=Di("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),vs=Di("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=pe(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),ou={utf8:Ci,"utf-8":Ci,hex:As.base16,latin1:vs,ascii:vs,binary:vs,...As},Qr=ou;function re(t,e="utf8"){let r=Qr[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function Z(t,e="utf8"){let r=Qr[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var iu=parseInt("11111",2),Bs=parseInt("10000000",2),au=parseInt("01111111",2),Oi={0:lr,1:lr,2:cu,3:hu,4:lu,5:uu,6:fu,16:lr,22:lr,48:lr};function $e(t,e={offset:0}){let r=t[e.offset]&iu;if(e.offset++,Oi[r]!=null)return Oi[r](t,e);throw new Error("No decoder for tag "+r)}function dr(t,e){let r=0;if((t[e.offset]&Bs)===Bs){let n=t[e.offset]&au,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 lr(t,e){dr(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=$e(t,e);if(n===null)break;r.push(n)}return r}function cu(t,e){let r=dr(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 fu(t,e){let r=dr(t,e),n=e.offset+r,s=t[e.offset];e.offset++;let o=0,i=0;s<40?(o=0,i=s):s<80?(o=1,i=s-40):(o=2,i=s-80);let a=`${o}.${i}`,c=[];for(;e.offset<n;){let f=t[e.offset];if(e.offset++,c.push(f&127),f<128){c.reverse();let u=0;for(let h=0;h<c.length;h++)u+=c[h]<<h*7;a+=`.${u}`,c=[]}}return a}function uu(t,e){return e.offset++,null}function hu(t,e){let r=dr(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 lu(t,e){let r=dr(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function du(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new G;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function Ls(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=du(t.byteLength);return new G(Uint8Array.from([e.byteLength|Bs]),e)}function ve(t){let e=new G,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new G(Uint8Array.from([2]),Ls(e),e)}function en(t){let e=Uint8Array.from([0]),r=new G(e,t);return new G(Uint8Array.from([3]),Ls(r),r)}function rt(t,e=48){let r=new G;for(let n of t)r.append(n);return new G(Uint8Array.from([e]),Ls(r),r)}var pu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),mu=Uint8Array.from([6,5,43,129,4,0,34]),yu=Uint8Array.from([6,5,43,129,4,0,35]),gu={ext:!0,kty:"EC",crv:"P-256"},bu={ext:!0,kty:"EC",crv:"P-384"},wu={ext:!0,kty:"EC",crv:"P-521"},Is=32,Ts=48,_s=66;function ki(t){let e=$e(t);return Ki(e)}function Ki(t){let e=t[1][1][0],r=1,n,s;if(e.byteLength===Is*2+1)return n=Z(e.subarray(r,r+Is),"base64url"),s=Z(e.subarray(r+Is),"base64url"),new jt({...gu,key_ops:["verify"],x:n,y:s});if(e.byteLength===Ts*2+1)return n=Z(e.subarray(r,r+Ts),"base64url"),s=Z(e.subarray(r+Ts),"base64url"),new jt({...bu,key_ops:["verify"],x:n,y:s});if(e.byteLength===_s*2+1)return n=Z(e.subarray(r,r+_s),"base64url"),s=Z(e.subarray(r+_s),"base64url"),new jt({...wu,key_ops:["verify"],x:n,y:s});throw new ie(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Ui(t){return rt([ve(Uint8Array.from([1])),rt([xu(t.crv)],160),rt([en(new G(Uint8Array.from([4]),re(t.x??"","base64url"),re(t.y??"","base64url")))],161)]).subarray()}function xu(t){if(t==="P-256")return pu;if(t==="P-384")return mu;if(t==="P-521")return yu;throw new ie(`Invalid curve ${t}`)}var jt=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Ui(this.jwk)),this._raw}toMultihash(){return Me.digest(nt(this))}toCID(){return ye.createV1(114,this.toMultihash())}toString(){return fe.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 vi(this.jwk,r,e,n)}};var tn=BigInt(4294967295),Pi=BigInt(32);function Eu(t,e=!1){return e?{h:Number(t&tn),l:Number(t>>Pi&tn)}:{h:Number(t>>Pi&tn)|0,l:Number(t&tn)|0}}function Ni(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}=Eu(t[o],e);[n[o],s[o]]=[i,a]}return[n,s]}var Su=t=>t/2**32|0,Au=t=>t>>>0;function Mi(t,e,r,n){let s=Su(r),o=Au(r);t.setUint32(e,n?o:s,n),t.setUint32(e+4,n?s:o,n)}var Rs=(t,e,r)=>t>>>r,Cs=(t,e,r)=>t<<32-r|e>>>r,bt=(t,e,r)=>t>>>r|e<<32-r,wt=(t,e,r)=>t<<32-r|e>>>r,pr=(t,e,r)=>t<<64-r|e>>>r-32,mr=(t,e,r)=>t>>>r-32|e<<64-r;function Fe(t,e,r,n){let s=(e>>>0)+(n>>>0);return{h:t+r+(s/2**32|0)|0,l:s|0}}var Fi=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Hi=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,qi=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),zi=(t,e,r,n,s)=>e+r+n+s+(t/2**32|0)|0,ji=(t,e,r,n,s)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(s>>>0),Vi=(t,e,r,n,s,o)=>e+r+n+s+o+(t/2**32|0)|0;function rn(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var Ds=t=>t?`"${t}" `:"";function Oe(t,e=""){if(typeof t!="number")throw new TypeError(Ds(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(Ds(e)+"expected integer >= 0, got "+t);return t}function Ee(t,e,r=""){if(rn(t)&&(e===void 0||t.length===e))return t;e!==void 0&&Oe(e,"length");let n=rn(t),s=e!==void 0?` of length ${e}`:"",o=n?`length=${t.length}`:`type=${typeof t}`,i=Ds(r)+"expected Uint8Array"+s+", got "+o;throw n?new RangeError(i):new TypeError(i)}function xt(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(Oe(t.outputLen),Oe(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var Bu=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)},$i=(t,e)=>{Bu(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 Vt(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function nn(t,e){Ee(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function _e(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function sn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function ke(t,e){return t<<32-e|t>>>e}var Wi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Lu=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function on(t){if(Ee(t),Wi)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=Lu[t[r]];return e}function Yi(t){return t>=48&&t<=57?t-48:t>=65&&t<=70?t-55:t>=97&&t<=102?t-87:void 0}function an(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(Wi)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=Yi(t.charCodeAt(o)),a=Yi(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 Os(...t){let e=0;for(let n=0;n<t.length;n++){let s=t[n];Ee(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 Iu(t,e,r="opts"){return $i(t,"defaults"),e!==void 0&&$i(e,r),Object.assign(Object.create(null),t,e)}function ks(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=Iu({},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 Gi(t=32){Oe(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 Ks=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Zi(t,e,r){return t&e^~t&r}function Xi(t,e,r){return t&e^t&r^e&r}var yr=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=sn(this.buffer)}update(e){Vt(this),Ee(e);let{view:r,buffer:n,blockLen:s}=this,o=e.length,i=!1;for(let a=0;a<o;){let c=Math.min(s-this.pos,o-a);if(c===s){let f=sn(e);for(;s<=o-a;a+=s)this.process(f,a);i=!0;continue}n.set(a===0&&c===o?e:e.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===s&&(this.process(r,0),this.pos=0,i=!0)}return this.length+=e.length,i&&this.roundClean(),this}digestInto(e){Vt(this),nn(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)),Mi(n,s-8,this.length*8,o),this.process(n,0),this.roundClean();let a=e===r?n:sn(e),c=this.outputLen,f=c/4,u=this.get();if(c%4||f>u.length)throw new Error("invalid outputLen");for(let h=0;h<f;h++)a.setUint32(4*h,u[h],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()}},Ji=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Qi=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Tu=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]),st=new Uint32Array(64),Us=class extends yr{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 h=0;h<16;h++,r+=4)st[h]=e.getUint32(r,!1);for(let h=16;h<64;h++){let p=st[h-15],d=st[h-2],w=ke(p,7)^ke(p,18)^p>>>3,g=ke(d,17)^ke(d,19)^d>>>10;st[h]=g+st[h-7]+w+st[h-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:f,H:u}=this;for(let h=0;h<64;h++){let p=ke(a,6)^ke(a,11)^ke(a,25),d=u+p+Zi(a,c,f)+Tu[h]+st[h]|0,g=(ke(n,2)^ke(n,13)^ke(n,22))+Xi(n,s,o)|0;u=f,f=c,c=a,a=i+d|0,i=o,o=s,s=n,n=d+g|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,s,o,i,a,c,f,u)}roundClean(){_e(st)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),_e(this.buffer)}},Ps=class extends Us{constructor(){super(32,Ji)}};var ea=Ni(["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))),_u=ea[0],Ru=ea[1],ot=new Uint32Array(80),it=new Uint32Array(80),Ns=class extends yr{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(e,r){super(128,e,16,!1),this.Ah=r[0]|0,this.Al=r[1]|0,this.Bh=r[2]|0,this.Bl=r[3]|0,this.Ch=r[4]|0,this.Cl=r[5]|0,this.Dh=r[6]|0,this.Dl=r[7]|0,this.Eh=r[8]|0,this.El=r[9]|0,this.Fh=r[10]|0,this.Fl=r[11]|0,this.Gh=r[12]|0,this.Gl=r[13]|0,this.Hh=r[14]|0,this.Hl=r[15]|0}get(){let{Ah:e,Al:r,Bh:n,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:f,El:u,Fh:h,Fl:p,Gh:d,Gl:w,Hh:g,Hl:y}=this;return[e,r,n,s,o,i,a,c,f,u,h,p,d,w,g,y]}set(e,r,n,s,o,i,a,c,f,u,h,p,d,w,g,y){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=s|0,this.Ch=o|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=h|0,this.Fl=p|0,this.Gh=d|0,this.Gl=w|0,this.Hh=g|0,this.Hl=y|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let b=0;b<16;b++,r+=4)ot[b]=e.getUint32(r),it[b]=e.getUint32(r+=4);for(let b=16;b<80;b++){let R=ot[b-15]|0,T=it[b-15]|0,O=bt(R,T,1)^bt(R,T,8)^Rs(R,T,7),N=wt(R,T,1)^wt(R,T,8)^Cs(R,T,7),K=ot[b-2]|0,_=it[b-2]|0,C=bt(K,_,19)^pr(K,_,61)^Rs(K,_,6),F=wt(K,_,19)^mr(K,_,61)^Cs(K,_,6),M=qi(N,F,it[b-7],it[b-16]),j=zi(M,O,C,ot[b-7],ot[b-16]);ot[b]=j|0,it[b]=M|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:f,Dl:u,Eh:h,El:p,Fh:d,Fl:w,Gh:g,Gl:y,Hh:x,Hl:E}=this;for(let b=0;b<80;b++){let R=bt(h,p,14)^bt(h,p,18)^pr(h,p,41),T=wt(h,p,14)^wt(h,p,18)^mr(h,p,41),O=h&d^~h&g,N=p&w^~p&y,K=ji(E,T,N,Ru[b],it[b]),_=Vi(K,x,R,O,_u[b],ot[b]),C=K|0,F=bt(n,s,28)^pr(n,s,34)^pr(n,s,39),M=wt(n,s,28)^mr(n,s,34)^mr(n,s,39),j=n&o^n&a^o&a,B=s&i^s&c^i&c;x=g|0,E=y|0,g=d|0,y=w|0,d=h|0,w=p|0,{h,l:p}=Fe(f|0,u|0,_|0,C|0),f=a|0,u=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let k=Fi(C,M,B);n=Hi(k,_,F,j),s=k|0}({h:n,l:s}=Fe(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=Fe(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=Fe(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=Fe(this.Dh|0,this.Dl|0,f|0,u|0),{h,l:p}=Fe(this.Eh|0,this.El|0,h|0,p|0),{h:d,l:w}=Fe(this.Fh|0,this.Fl|0,d|0,w|0),{h:g,l:y}=Fe(this.Gh|0,this.Gl|0,g|0,y|0),{h:x,l:E}=Fe(this.Hh|0,this.Hl|0,x|0,E|0),this.set(n,s,o,i,a,c,f,u,h,p,d,w,g,y,x,E)}roundClean(){_e(ot,it)}destroy(){this.destroyed=!0,_e(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Ms=class extends Ns{constructor(){super(64,Qi)}};var He=ks(()=>new Ps,Ks(1));var Fs=ks(()=>new Ms,Ks(3));function fn(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 Y=(t,e,r)=>Ee(t,e,r),Hs=Oe;function ra(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 Et(t,e){if(typeof t!="function")throw new TypeError(`"${e}" is invalid: expected function, got ${typeof t}`);return t}var gr=on,Re=(...t)=>Os(...t),$t=t=>an(t),ft=rn,Ye=t=>Gi(t),cn=BigInt(0),ta=BigInt(1),Cu=t=>t?`"${t}" `:"";function Be(t,e=""){if(typeof t!="boolean")throw new TypeError(Cu(e)+"expected boolean, got type="+typeof t);return t}function un(t){if(typeof t=="bigint"){if(!ct(t))throw new RangeError("positive bigint expected, got "+t)}else Hs(t);return t}function We(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 br(t){let e=un(t).toString(16);return e.length&1?"0"+e:e}function na(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?cn:BigInt("0x"+t)}function qe(t){return na(on(t))}function ze(t){return na(on(ut(Ee(t)).reverse()))}function hn(t,e){if(Oe(e),e===0)throw new Error("zero output length is invalid");t=un(t);let r=e*2,n=t.toString(16);if(n.length>r)throw new RangeError("number is too large");return an(n.padStart(r,"0"))}function wr(t,e){return hn(t,e).reverse()}function ut(t){return Uint8Array.from(Y(t))}function ct(t){return typeof t=="bigint"&&cn<=t}function qs(t,e,r){return ct(t)&&ct(e)&&ct(r)&&e<=t&&t<r}function je(t,e,r,n){if(!qs(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Yt(t){if(t<cn)throw new Error("expected non-negative bigint, got "+t);return t===cn?0:t.toString(2).length}var xr=t=>(We(t,"n"),(ta<<BigInt(t))-ta);function sa(t,e,r){if(Oe(t,"hashLen"),Oe(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=y=>new Uint8Array(y),s=Uint8Array.of(),o=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(t),f=n(t),u=0,h=()=>{c.fill(1),f.fill(0),u=0},p=(...y)=>r(f,Re(c,...y)),d=(y=s)=>{f=p(o,y),c=p(),y.length!==0&&(f=p(i,y),c=p())},w=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let y=0,x=[];for(;y<e;){c=p();let E=c.slice();x.push(E),y+=c.length}return Re(...x)};return(y,x)=>{h(),d(y);let E;for(;(E=x(w()))===void 0;)d();return h(),E}}function ge(t,e={},r={},n="object"){at(t,n),at(e,"fields"),at(r,"optFields");function s(i,a,c){let f=n==="object"?`param "${String(i)}"`:`"${n}.${String(i)}"`,u=t[i];if(!Object.hasOwn(t,i)&&(c?u!==void 0:a!=="function"))throw new TypeError(`${f} is invalid: expected own property`);if(c&&u===void 0)return;let h=typeof u;if(h!==a||u===null)throw new TypeError(`${f} is invalid: expected ${a}, got ${h}`)}let o=(i,a)=>Object.entries(i).forEach(([c,f])=>s(c,f,a));o(e,!1),o(r,!0)}var de=BigInt(0),X=BigInt(1),ht=BigInt(2),aa=BigInt(3),zs=BigInt(4),ca=BigInt(5),Du=BigInt(7),fa=BigInt(8),Ou=BigInt(9),ku=BigInt(15),ua=BigInt(16),Ku=BigInt("0x10000000000000000");function Q(t,e){if(e<=de)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=de?r:e+r}function ha(t,e,r){if(r<=X)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<de)throw new Error("invalid exponent, negatives unsupported");if(e===de)return X;if(e===X)return t;let n=t%r;if(n<de&&(n+=r),e<Ku){let a=X;for(;e>de;)e&X&&(a=a*n%r),n=n*n%r,e>>=X;return a}let s=[];for(;e>de;)s.push(Number(e&ku)),e>>=zs;let o=new Array(16);o[0]=X,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 se(t,e,r){if(r<=X)throw new Error("pow2: expected modulus > 1, got "+r);if(e<de)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >de;)n*=n,n%=r;return n}function oa(t,e){if(t===de)throw new Error("invert: expected non-zero number");if(e<=X)throw new Error("invert: expected modulus > 1, got "+e);let r=Q(t,e),n=e,s=de,o=X;for(;r!==de;){let a=n/r,c=n-r*a,f=s-o*a;n=r,r=c,s=o,o=f}if(n!==X)throw new Error("invert: does not exist");return Q(s,e)}function la(t,e){if(e<=X)throw new Error("invertCt: expected prime modulus > 1, got "+e);let r=Q(t,e);if(r===de)throw new Error("invertCt: expected non-zero number");let n=ha(r,e-ht,e);if(Q(r*n,e)!==X)throw new Error("invertCt: does not exist");return n}function js(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function Vs(t,e){if((t&X)===de)throw new Error(e+": expected odd modulus, got "+t)}function da(t,e){let r=t,n=(r.ORDER+X)/zs,s=r.pow(e,n);return js(r,s,e),s}function Uu(t,e){let r=t,n=(r.ORDER-ca)/fa,s=r.mul(e,ht),o=r.pow(s,n),i=r.mul(e,o),a=r.mul(r.mul(i,ht),o),c=r.mul(i,r.sub(a,r.ONE));return js(r,c,e),c}function Pu(t){let e=Gt(t),r=pa(t),n=r(e,e.neg(e.ONE)),s=r(e,n),o=r(e,e.neg(n)),i=(t+Du)/ua;return((a,c)=>{let f=a,u=f.pow(c,i),h=f.mul(u,n),p=f.mul(u,s),d=f.mul(u,o),w=f.eql(f.sqr(h),c),g=f.eql(f.sqr(p),c);u=f.cmov(u,h,w),h=f.cmov(d,p,g);let y=f.eql(f.sqr(h),c),x=f.cmov(u,h,y);return js(f,x,c),x})}function pa(t){if(t<aa)throw new Error("sqrt is not defined for small field");Vs(t,"tonelliShanks");let e=t-X,r=0;for(;e%ht===de;)e/=ht,r++;let n=ht,s=Gt(t);for(;Er(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return da;let o=s.pow(n,e),i=(e+X)/ht;return function(c,f){let u=c;if(u.is0(f))return f;if(Er(u,f)!==1)throw new Error("Cannot find square root");let h=r,p=u.mul(u.ONE,o),d=u.pow(f,e),w=u.pow(f,i);for(;!u.eql(d,u.ONE);){if(u.is0(d))throw new Error("Cannot find square root: probably non-prime P");let g=1,y=u.sqr(d);for(;!u.eql(y,u.ONE);)if(g++,y=u.sqr(y),g===h)throw new Error("Cannot find square root");let x=X<<BigInt(h-g-1),E=u.pow(p,x);h=g,p=u.sqr(E),d=u.mul(d,p),w=u.mul(w,E)}return w}}function Nu(t){return Vs(t,"Fp.sqrt"),t%zs===aa?da:t%fa===ca?Uu:t%ua===Ou?Pu(t):pa(t)}var ma=(t,e)=>(Q(t,e)&X)===X,Mu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Wt(t){if(at(t,"field"),typeof t.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof t.ORDER);We(t.BYTES,"BYTES"),We(t.BITS,"BITS");for(let e of Mu)Et(t[e],"field."+e);if(t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=X)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function dn(t,e,r=!1){Wt(t),fn(e,"nums"),Be(r,"passZero");let n=t,s=new Array(e.length).fill(r?n.ZERO:void 0),o=e.reduce((a,c,f)=>n.is0(c)?a:(s[f]=a,n.mul(a,c)),n.ONE),i=n.inv(o);return e.reduceRight((a,c,f)=>n.is0(c)?a:(s[f]=n.mul(a,s[f]),n.mul(a,c)),i),s}function Er(t,e){Wt(t);let r=t;Vs(r.ORDER,"FpLegendre");let n=(r.ORDER-X)/ht,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 Fu(t,e){if(e!==void 0&&Hs(e),t<=de)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=Yt(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 ia=new WeakMap,ln=class{ORDER;BITS;BYTES;isLE;ZERO=de;ONE=X;_lengths;_mod;constructor(e,r={}){if(e<=X)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}=Fu(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 Q(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return de<=e&&e<this.ORDER}is0(e){return e===de}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&X)===X}neg(e){return Q(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return Q(e*e,this.ORDER)}add(e,r){return Q(e+r,this.ORDER)}sub(e,r){return Q(e-r,this.ORDER)}mul(e,r){return Q(e*r,this.ORDER)}pow(e,r){return ha(e,r,this.ORDER)}div(e,r){return Q(e*oa(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 oa(e,this.ORDER)}sqrt(e){let r=ia.get(this);return r||ia.set(this,r=Nu(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?wr(e,this.BYTES):hn(e,this.BYTES)}fromBytes(e,r=!1){Y(e);let{_lengths:n,BYTES:s,isLE:o,ORDER:i,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>s)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let f=new Uint8Array(s);f.set(e,o?0:f.length-e.length),e=f}if(e.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+e.length);let c=o?ze(e):qe(e);if(a&&(c=Q(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return dn(this,e,!0)}cmov(e,r,n){return Be(n,"condition"),n?r:e}};function Gt(t,e={}){return Object.freeze(ln.prototype),new ln(t,e)}function ya(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=X)throw new Error("field order must be greater than 1");let e=Yt(t-X);return Math.ceil(e/8)}function pn(t){let e=ya(t);return e+Math.ceil(e/2)}function mn(t,e,r=!1){Y(t);let n=t.length,s=ya(e),o=Math.max(pn(e),16);if(n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);let i=r?ze(t):qe(t),a=Q(i,e-X)+X;return r?wr(a,s):hn(a,s)}var Ws=BigInt(0),Sr=BigInt(1),Hu=BigInt(4),$s=16,ga=128,qu=5,ba=2**31;function lt(t){let e=t;if(typeof e!="function")throw new TypeError('"Point" expected constructor, got type='+typeof t);Et(e.fromAffine,"Point.fromAffine"),Et(e.fromBytes,"Point.fromBytes"),Et(e.fromHex,"Point.fromHex"),at(e.BASE,"Point.BASE"),at(e.ZERO,"Point.ZERO"),Wt(e.Fp),Wt(e.Fn)}function yn(t,e){lt(t),xa(e,t);let r=dn(t.Fp,e.map(n=>n.Z));return e.map((n,s)=>t.fromAffine(n.toAffine(r[s])))}function zu(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 ju(t,e){let r=t*(4*e+128);if(r>ba)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+ba/2**20+" MiB")}function Gs(t,e){if(t!==void 0){Et(t,"randomBytes");try{let r=t(e);if(!ft(r)||r.length!==e)return}catch{return}return t}}function xa(t,e){fn(t,"points"),t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function Vu(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):ct(n)&&n<r))throw new Error("invalid scalar at index "+s)})}var Ea=new WeakMap;function Ys(t){return Ea.get(t)||1}function $u(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 Yu(t,e){let r=2**e,n=r/2,s=BigInt(r-1),o=[];for(;t>Ws;){let i=0;t&Sr&&(i=Number(t&s),i>=n&&(i-=r),t-=BigInt(i)),o.push(i),t>>=Sr}return o}function Wu(t,e,r){let n=2**e,s=n/2,o=BigInt(n-1),i=BigInt(e),a=[];for(let c=0;c<r;c++){let f=Number(t&o);t>>=i,f>s&&(f-=n,t+=Sr),a.push(f)}if(t!==Ws)throw new Error("invalid wnaf");return a}function Gu(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 Zt=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(e,r){lt(e),this.randomBytes=Gs(r,$s),this.Point=e,this.BASE=e.BASE,this.ZERO=e.ZERO,this.bits=e.Fn.BITS}buildWnafTable(e,r,n){let s=Math.ceil(n/r)+1,o=2**(r-1),i=[],a=e;for(let c=0;c<s;c++){let f=a;for(let u=0;u<o;u++)i.push(f),f=f.add(a);a=i[i.length-1].double()}return{W:r,bits:n,windows:s,comp:i}}wnafCachedCT(e,r){let{W:n,windows:s,comp:o}=e,i=2**(n-1),a=Wu(r,n,s),c=this.ZERO,f=this.BASE;for(let u=0;u<s;u++){let h=a[u],p=u*i,d=Math.abs(h)-1,w=o[p];for(let y=1;y<i;y++)w=y===d?o[p+y]:w;let g=w.negate();h===0?f=f.add(o[p]):c=c.add(h<0?g:w)}return{p:c,f}}getWnafPrecomputes(e,r,n,s){let o=this.wnafPrecomputes.get(r),i=o?.find(a=>a.W===e&&a.bits===n);return i||(i=this.buildWnafTable(r,e,n),typeof s=="function"&&(i={...i,comp:s(i.comp)}),o||(o=[],this.wnafPrecomputes.set(r,o)),o.push(i)),i}assertPoint(e){if(!(e instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof e)}validateMulInput(e,r){if(this.assertPoint(e),!qs(r,Sr,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(e,r,n,s){let o=Ys(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+ga,o=this.randomBytes($s);if(!ft(o)||o.length!==$s)throw new Error("randomBytes returned invalid byte array");o[0]=o[0]&63|128;let i=r+qe(o)*this.Point.Fn.ORDER;return this.runCT(e,i,s,n)}fixedWindowCT(e,r,n){let s=qu,o=1<<s,i=xr(s),a=new Array(o);a[0]=this.ZERO;for(let u=1;u<o;u++)a[u]=a[u-1].add(e);let c=Math.ceil(n/s),f=this.ZERO;for(let u=c-1;u>=0;u--){if(u!==c-1)for(let d=0;d<s;d++)f=f.double();let h=Number(r>>BigInt(u*s)&i),p=a[0];for(let d=1;d<o;d++)p=d===h?a[d]:p;f=f.add(p)}return{p:f,f}}shouldBlind(e,r){return this.randomBytes===void 0?!1:r===Sr?!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),!ct(r))throw new Error("invalid scalar");let s=Ys(e);if(s===1||r>=this.Point.Fn.ORDER)return gn(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),zu(r,this.bits);let n=Math.ceil((this.bits+ga)/r)+1;ju(n*2**(r-1),this.Point.Fp.BYTES),Ea.set(e,r),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return Ys(e)!==1}};function gn(t,e,r,n=!1){if(lt(t),xa(e,t),Be(n,"allowOversized"),Vu(r,t.Fn,n?t.Fn.ORDER**Hu:void 0),e.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let s=e.map(i=>$u(i,4)),o=r.map(i=>Yu(i,4));return Gu(t.ZERO,s,o)}function wa(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Wt(e),e}else return Gt(t,{isLE:r})}function bn(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`);ge(r);for(let c of["p","n","h"]){let f=e[c];if(!(ct(f)&&f!==Ws))throw new Error(`CURVE.${c} must be positive bigint`)}let s=wa(e.p,r.Fp,n),o=wa(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 Xt(t,e){return function(n){let s=t(n);return{secretKey:s,publicKey:e(s)}}}var wn=BigInt(0),xn=BigInt(1),En=BigInt(2),Zu=BigInt(4),Sa=BigInt(8);function Xu(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 Aa(t,e={}){ge(e,{},{},"extraOpts");let r=e,n=bn("edwards",t,r,r.FpFnLE),{Fp:s,Fn:o}=n,i=n.CURVE,{h:a}=i;if(Er(s,i.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(Er(s,i.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");ge(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?Ye:r.randomBytes,f=En<<BigInt(s.BYTES*8)-xn;function u(E){if(!s.isOdd)throw new Error("Field does not have .isOdd()");return s.isOdd(E)}let h=r.uvRatio===void 0?(E,b)=>{try{return{isValid:!0,value:s.sqrt(s.div(E,b))}}catch{return{isValid:!1,value:wn}}}:r.uvRatio;if(!Xu(s,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");let p=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 d(E,b,R=!1){let T=R?xn:wn;return je("coordinate "+E,b,T,f),b}function w(E){if(!(E instanceof g))throw new Error("EdwardsPoint expected")}class g{static BASE=new g(i.Gx,i.Gy,s.ONE,s.mul(i.Gx,i.Gy));static ZERO=new g(s.ZERO,s.ONE,s.ONE,s.ZERO);static Fp=s;static Fn=o;X;Y;Z;T;constructor(b,R,T,O){this.X=d("x",b),this.Y=d("y",R),this.Z=d("z",T,!0),this.T=d("t",O),Object.freeze(this)}static CURVE(){return i}static fromAffine(b){if(b instanceof g)throw new Error("extended point not allowed");let{x:R,y:T}=b||{};return d("x",R),d("y",T),new g(R,T,s.ONE,s.mul(R,T))}static fromBytes(b,R=!1){let T=s.BYTES,{a:O,d:N}=i;b=ut(Y(b,T,"point")),Be(R,"zip215");let K=ut(b),_=b[T-1];K[T-1]=_&-129;let C=ze(K),F=R?f:s.ORDER;je("point.y",C,wn,F);let M=s.sqr(C),j=s.sub(M,s.ONE),B=s.sub(s.mulN(N,M),O),{isValid:k,value:L}=h(j,B);if(!k)throw new Error("bad point: invalid y coordinate");let v=u(L),H=(_&128)!==0;if(!R&&s.is0(L)&&H)throw new Error("bad point: x=0 and x_0=1");return H!==v&&(L=s.neg(L)),g.fromAffine({x:L,y:C})}static fromHex(b,R=!1){return g.fromBytes($t(b),R)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=6,R=!0){return x.setWindowSize(this,b),R||this.multiply(En),this}assertValidity(){let b=this,{a:R,d:T}=i;if(b.is0())throw new Error("bad point: ZERO");let{X:O,Y:N,Z:K,T:_}=b,C=s.sqr(O),F=s.sqr(N),M=s.sqr(K),j=s.sqr(M),B=s.mul(C,R),k=s.mul(s.add(B,F),M),L=s.add(j,s.mul(T,s.mul(C,F)));if(!s.eql(k,L))throw new Error("bad point: equation left != right (1)");let v=s.mul(O,N),H=s.mul(K,_);if(!s.eql(v,H))throw new Error("bad point: equation left != right (2)")}equals(b){w(b);let{X:R,Y:T,Z:O}=this,{X:N,Y:K,Z:_}=b,C=s.mul(R,_),F=s.mul(N,O),M=s.mul(T,_),j=s.mul(K,O);return s.eql(C,F)&&s.eql(M,j)}is0(){return this.equals(g.ZERO)}negate(){return new g(s.neg(this.X),this.Y,this.Z,s.neg(this.T))}double(){let{X:b,Y:R,Z:T}=this,O=s.sqr(b),N=s.sqr(R),K=s.mul(s.sqr(T),En),_=p(O),C=s.addN(b,R),F=s.sub(s.subN(s.sqr(C),O),N),M=s.addN(_,N),j=s.subN(M,K),B=s.subN(_,N),k=s.mul(F,j),L=s.mul(M,B),v=s.mul(F,B),H=s.mul(j,M);return new g(k,L,H,v)}add(b){w(b);let{d:R}=i,{X:T,Y:O,Z:N,T:K}=this,{X:_,Y:C,Z:F,T:M}=b,j=s.mul(T,_),B=s.mul(O,C),k=s.mul(s.mulN(K,R),M),L=s.mul(N,F),v=s.sub(s.subN(s.mulN(s.addN(T,O),s.addN(_,C)),j),B),H=s.subN(L,k),I=s.addN(L,k),S=s.sub(B,p(j)),l=s.mul(v,H),m=s.mul(I,S),A=s.mul(v,S),D=s.mul(H,I);return new g(l,m,D,A)}subtract(b){return w(b),this.add(b.negate())}multiply(b){if(!o.isValidNot0(b))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:R,f:T}=x.mulSecret(this,b,a,y);return y([R,T])[0]}multiplyUnsafe(b){if(!o.isValid(b))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return b===wn?g.ZERO:this.is0()||b===xn?this:x.mulUnsafe(this,b,y)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return x.mulUnsafe(this,i.n).is0()}toAffine(b){let R=this,T=b;if(T!=null&&typeof T!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof T);let{X:O,Y:N,Z:K}=R,_=R.is0();T==null&&(T=_?s.create(Sa):s.inv(K));let C=s.mul(O,T),F=s.mul(N,T),M=s.mul(K,T);if(_)return{x:s.ZERO,y:s.ONE};if(!s.eql(M,s.ONE))throw new Error("invZ was invalid");return{x:C,y:F}}clearCofactor(){return a===xn?this:a===En?this.double():a===Zu?this.double().double():a===Sa?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:b,y:R}=this.toAffine(),T=s.toBytes(R);return T[T.length-1]|=u(b)?128:0,T}toHex(){return gr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let y=E=>yn(g,E),x=new Zt(g,c);return x.bits>=6&&g.BASE.precompute(6),Object.freeze(g.prototype),Object.freeze(g),g}function va(t,e,r={}){if(lt(t),typeof e!="function")throw new Error('"hash" function param is required');let n=e,s=r;ge(s,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:o}=s,{BASE:i,Fp:a,Fn:c}=t,f=n.outputLen,u=2*a.BYTES;if(f!==void 0&&(We(f,"hash.outputLen"),f!==u))throw new Error(`hash.outputLen must be ${u}, got ${f}`);let h=s.randomBytes===void 0?Ye:s.randomBytes,p=s.toMontgomery,d=s.toMontgomerySecret,w=s.adjustScalarBytes===void 0?B=>B:s.adjustScalarBytes,g=s.domain===void 0?(B,k,L)=>{if(Be(L,"phflag"),k.length||L)throw new Error("Contexts/pre-hash are not supported");return B}:s.domain;function y(B){return c.create(ze(B))}function x(B){let k=_.secretKey;Y(B,_.secretKey,"secretKey");let L=Y(n(B),2*k,"hashedSecretKey"),v=w(L.slice(0,k)),H=L.slice(k,2*k),I=y(v);return{head:v,prefix:H,scalar:I}}function E(B){let{head:k,prefix:L,scalar:v}=x(B),H=i.multiply(v),I=H.toBytes();return{head:k,prefix:L,scalar:v,point:H,pointBytes:I}}function b(B){return E(B).pointBytes}function R(B=Uint8Array.of(),...k){let L=Re(...k);return y(n(g(L,Y(B,void 0,"context"),!!o)))}function T(B,k,L={}){ge(L,{},{},"options"),B=ut(Y(B,void 0,"message")),o&&(B=o(B));let{prefix:v,scalar:H,pointBytes:I}=E(k),S=R(L.context,v,B),l=i.multiply(S).toBytes(),m=R(L.context,l,I,B),A=c.create(S+m*H);if(!c.isValid(A))throw new Error("sign failed: invalid s");let D=Re(l,c.toBytes(A));return Y(D,_.signature,"result")}let O={zip215:s.zip215};function N(B,k,L,v=O){ge(v);let{context:H}=v,I=v.zip215===void 0?!!O.zip215:v.zip215,S=_.signature;B=Y(B,S,"signature"),k=Y(k,void 0,"message"),L=Y(L,_.publicKey,"publicKey"),I!==void 0&&Be(I,"zip215"),o&&(k=o(k));let l=S/2,m=B.subarray(0,l),A=ze(B.subarray(l,S)),D,U,P;try{D=t.fromBytes(L,I),U=t.fromBytes(m,I),P=i.multiplyUnsafe(A)}catch{return!1}if(!I&&D.isSmallOrder())return!1;let q=R(H,m,L,k);return U.add(D.multiplyUnsafe(q)).subtract(P).clearCofactor().is0()}let K=a.BYTES,_={secretKey:K,publicKey:K,signature:2*K,seed:K};function C(B){return B=B===void 0?h(_.seed):B,Y(B,_.seed,"seed")}function F(B){return ft(B)&&B.length===_.secretKey}function M(B,k){try{return!!t.fromBytes(B,k===void 0?O.zip215:k)}catch{return!1}}let j={getExtendedPublicKey:E,randomSecretKey:C,isValidSecretKey:F,isValidPublicKey:M,toMontgomery(B){if(p===void 0)throw new Error("Montgomery conversion is not supported for this curve");return p(t.fromBytes(B))},toMontgomerySecret(B){if(d===void 0)throw new Error("Montgomery conversion is not supported for this curve");return d(B)}};return Object.freeze(_),Object.freeze(j),Object.freeze({keygen:Xt(C,b),getPublicKey:b,sign:T,verify:N,utils:j,Point:t,lengths:_})}var St=BigInt(0),Ce=BigInt(1),Sn=BigInt(2);function Ba(t,e){return t+e-(e>>Ce<<Ce)}function Ju(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 Qu(t){return ge(t,{P:"bigint",type:"string",adjustScalarBytes:"function",powPminus2:"function"},{randomBytes:"function",scalarMultBase:"function"}),Object.freeze({...t})}function La(t){let e=Qu(t),{P:r,type:n,adjustScalarBytes:s,powPminus2:o,randomBytes:i}=e,a=e.scalarMultBase,c=n==="x25519";if(!c&&n!=="x448")throw new Error("invalid type");let f=i===void 0?Ye:i,u=c?255:448,h=Ju(r),p=c?32:56,d=BigInt(c?9:5),w=BigInt(c?121665:39081),g=c?Sn**BigInt(254):Sn**BigInt(447),y=c?BigInt(8)*(Sn**BigInt(251)-Ce):BigInt(4)*(Sn**BigInt(445)-Ce),x=g+y+Ce,E=L=>Q(L,r),b=R(d);function R(L){return wr(E(L),p)}function T(L){let v=ut(Y(L,p,"uCoordinate"));return c&&(v[31]&=127),E(ze(v))}function O(L){return ze(s(ut(Y(L,p,"scalar"))))}let N=new Set(c?[St,Ce,r-Ce,BigInt("325606250916557431795983626356110631294008115727848805560023387167927233504"),BigInt("39382357235489614581723060781553021112529911719440698176882885853963445705823")]:[St,Ce,r-Ce]);function K(L,v){let H=T(v);if(N.has(H))throw new Error("invalid private or public key received");let I=M(H,O(L));if(I===St)throw new Error("invalid private or public key received");return R(I)}function _(L){if(a===void 0)return K(L,b);let v=O(L);je("scalar",v,g,x);let H=E(a(v));if(H===St)throw new Error("invalid private or public key received");return R(H)}let C=_,F=K;function M(L,v){je("u",L,St,r),je("scalar",v,g,x);let H=v,I=L,S=Ce,l=St,m=L,A=Ce,D=H^H>>Ce;for(let q=BigInt(u-1);q>=St;q--){let z=Ba(r,D>>q);({x_2:S,x_3:m}=h(z,S,m)),{x_2:l,x_3:A}=h(z,l,A);let V=S+l,$=E(V*V),ne=S-l,ee=E(ne*ne),ce=$-ee,Se=m+A,te=m-A,oe=E(te*V),kt=E(Se*ne),ar=oe+kt,Qe=oe-kt;m=E(ar*ar),A=E(I*E(Qe*Qe)),S=E($*ee),l=E(ce*($+E(w*ce)))}let U=Ba(r,H);({x_2:S,x_3:m}=h(U,S,m)),{x_2:l,x_3:A}=h(U,l,A);let P=o(l);return E(S*P)}let j={secretKey:p,publicKey:p,seed:p},B=L=>(L=L===void 0?f(p):L,Y(L,j.seed,"seed"),L),k={randomSecretKey:B};return Object.freeze(j),Object.freeze(k),Object.freeze({keygen:Xt(B,C),getSharedSecret:F,getPublicKey:C,scalarMult:K,scalarMultBase:_,utils:k,GuBytes:b.slice(),lengths:j})}var Ia=BigInt(0),Zs=BigInt(1),Ta=BigInt(2),eh=BigInt(3),th=BigInt(5),rh=BigInt(8),An=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),nh={p:An,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:rh,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Ca(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),s=BigInt(80),o=An,a=t*t%o*t%o,c=se(a,Ta,o)*a%o,f=se(c,Zs,o)*t%o,u=se(f,th,o)*f%o,h=se(u,e,o)*u%o,p=se(h,r,o)*h%o,d=se(p,n,o)*p%o,w=se(d,s,o)*d%o,g=se(w,s,o)*d%o,y=se(g,e,o)*u%o;return{pow_p_5_8:se(y,Ta,o)*t%o,b2:a}}function Xs(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var _a=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function sh(t,e){let r=An,n=Q(e*e*e,r),s=Q(n*n*e,r),o=Ca(t*s).pow_p_5_8,i=Q(t*n*o,r),a=Q(e*i*i,r),c=i,f=Q(i*_a,r),u=a===t,h=a===Q(-t,r),p=a===Q(-t*_a,r);return u&&(i=c),(h||p)&&(i=f),ma(i,r)&&(i=Q(-i,r)),{isValid:u||h,value:i}}var Ar=Aa(nh,{uvRatio:sh}),Ra=Ar.Fp;function oh(t){let{y:e}=t;return Ra.toBytes(Ra.div(Zs+e,Zs-e))}function ih(t){let e=Ar.Fp.BYTES;return Ee(t,e),Xs(Fs(t.subarray(0,e))).subarray(0,e)}function ah(t){return va(Ar,Fs,Object.assign({adjustScalarBytes:Xs,toMontgomery:oh,toMontgomerySecret:ih,zip215:!0},t))}var Da=ah({});var vr=(()=>{let t=An,e=r=>{let{pow_p_5_8:n,b2:s}=Ca(r);return Q(se(n,eh,t)*s,t)};return La({P:t,type:"x25519",powPminus2:e,adjustScalarBytes:Xs,scalarMultBase:r=>{let n=Q(r,Ar.Fn.ORDER);if(n===Ia)return Ia;let s=Ar.BASE.multiply(n);return Q((s.Z+s.Y)*e(Q(s.Z-s.Y,t)),t)}})})();var Br=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},vn=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var De={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new vn("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 Bn=32;var Js,ch=(async()=>{try{return await De.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function fh(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await De.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await De.get().subtle.verify({name:"Ed25519"},n,Le(e),Le(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function uh(t,e,r){return Da.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function Oa(t,e,r){return Js==null&&(Js=await ch),Js?fh(t,e,r):uh(t,e,r)}function Ln(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var In=class{type="Ed25519";raw;constructor(e){this.raw=Qs(e,Bn)}toMultihash(){return Me.digest(nt(this))}toCID(){return ye.createV1(114,this.toMultihash())}toString(){return fe.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=Oa(this.raw,r,e);return Ln(s)?s.then(o=>(n?.signal?.throwIfAborted(),o)):s}};function Ka(t){return t=Qs(t,Bn),new In(t)}function Qs(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new ie(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}var lh=Math.pow(2,7),dh=Math.pow(2,14),ph=Math.pow(2,21),eo=Math.pow(2,28),to=Math.pow(2,35),ro=Math.pow(2,42),no=Math.pow(2,49),J=128,be=127;function Ke(t){if(t<lh)return 1;if(t<dh)return 2;if(t<ph)return 3;if(t<eo)return 4;if(t<to)return 5;if(t<ro)return 6;if(t<no)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function so(t,e,r=0){switch(Ke(t)){case 8:e[r++]=t&255|J,t/=128;case 7:e[r++]=t&255|J,t/=128;case 6:e[r++]=t&255|J,t/=128;case 5:e[r++]=t&255|J,t/=128;case 4:e[r++]=t&255|J,t>>>=7;case 3:e[r++]=t&255|J,t>>>=7;case 2:e[r++]=t&255|J,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function mh(t,e,r=0){switch(Ke(t)){case 8:e.set(r++,t&255|J),t/=128;case 7:e.set(r++,t&255|J),t/=128;case 6:e.set(r++,t&255|J),t/=128;case 5:e.set(r++,t&255|J),t/=128;case 4:e.set(r++,t&255|J),t>>>=7;case 3:e.set(r++,t&255|J),t>>>=7;case 2:e.set(r++,t&255|J),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function oo(t,e){let r=t[e],n=0;if(n+=r&be,r<J||(r=t[e+1],n+=(r&be)<<7,r<J)||(r=t[e+2],n+=(r&be)<<14,r<J)||(r=t[e+3],n+=(r&be)<<21,r<J)||(r=t[e+4],n+=(r&be)*eo,r<J)||(r=t[e+5],n+=(r&be)*to,r<J)||(r=t[e+6],n+=(r&be)*ro,r<J)||(r=t[e+7],n+=(r&be)*no,r<J))return n;throw new RangeError("Could not decode varint")}function yh(t,e){let r=t.get(e),n=0;if(n+=r&be,r<J||(r=t.get(e+1),n+=(r&be)<<7,r<J)||(r=t.get(e+2),n+=(r&be)<<14,r<J)||(r=t.get(e+3),n+=(r&be)<<21,r<J)||(r=t.get(e+4),n+=(r&be)*eo,r<J)||(r=t.get(e+5),n+=(r&be)*to,r<J)||(r=t.get(e+6),n+=(r&be)*ro,r<J)||(r=t.get(e+7),n+=(r&be)*no,r<J))return n;throw new RangeError("Could not decode varint")}function Ua(t,e,r=0){return e==null&&(e=pe(Ke(t))),e instanceof Uint8Array?so(t,e,r):mh(t,e,r)}function Tn(t,e=0){return t instanceof Uint8Array?oo(t,e):yh(t,e)}var io=new Float32Array([-0]),dt=new Uint8Array(io.buffer);function Na(t,e,r){io[0]=t,e[r]=dt[0],e[r+1]=dt[1],e[r+2]=dt[2],e[r+3]=dt[3]}function Ma(t,e){return dt[0]=t[e],dt[1]=t[e+1],dt[2]=t[e+2],dt[3]=t[e+3],io[0]}var ao=new Float64Array([-0]),we=new Uint8Array(ao.buffer);function Fa(t,e,r){ao[0]=t,e[r]=we[0],e[r+1]=we[1],e[r+2]=we[2],e[r+3]=we[3],e[r+4]=we[4],e[r+5]=we[5],e[r+6]=we[6],e[r+7]=we[7]}function Ha(t,e){return we[0]=t[e],we[1]=t[e+1],we[2]=t[e+2],we[3]=t[e+3],we[4]=t[e+4],we[5]=t[e+5],we[6]=t[e+6],we[7]=t[e+7],ao[0]}var gh=BigInt(Number.MAX_SAFE_INTEGER),bh=BigInt(Number.MIN_SAFE_INTEGER),Ie=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 At;if(e<gh&&e>bh)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>qa&&(s=0n,++n>qa&&(n=0n))),new t(Number(s),Number(n))}static fromNumber(e){if(e===0)return At;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):At}},At=new Ie(0,0);At.toBigInt=function(){return 0n};At.zzEncode=At.zzDecode=function(){return this};At.length=function(){return 1};var qa=4294967296n;function za(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 ja(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 co(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 Ue(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function _n(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var fo=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=Le(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,Ue(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 Ue(this,4);return _n(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ue(this,4);return _n(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ue(this,4);let e=Ma(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ue(this,4);let e=Ha(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 Ue(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return ja(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ue(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ue(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 Ie(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 Ue(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 Ue(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 Ue(this,8);let e=_n(this.buf,this.pos+=4),r=_n(this.buf,this.pos+=4);return new Ie(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=oo(this.buf,this.pos);return this.pos+=Ke(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 Lr(t){return new fo(t instanceof Uint8Array?t:t.subarray())}function vt(t,e,r){let n=Lr(t);return e.decode(n,void 0,r)}function uo(t){let e=t??8192,r=e>>>1,n,s=e;return function(i){if(i<1||i>r)return pe(i);s+i>e&&(n=pe(e),s=0);let a=n.subarray(s,s+=i);return(s&7)!==0&&(s=(s|7)+1),a}}var Bt=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function ho(){}var po=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},wh=uo();function xh(t){return globalThis.Buffer!=null?pe(t):wh(t)}var Tr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Bt(ho,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Bt(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new mo((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(Rn,10,Ie.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Ie.fromBigInt(e);return this._push(Rn,r.length(),r)}uint64Number(e){return this._push(so,Ke(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=Ie.fromBigInt(e).zzEncode();return this._push(Rn,r.length(),r)}sint64Number(e){let r=Ie.fromNumber(e).zzEncode();return this._push(Rn,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(lo,1,e?1:0)}fixed32(e){return this._push(Ir,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Ie.fromBigInt(e);return this._push(Ir,4,r.lo)._push(Ir,4,r.hi)}fixed64Number(e){let r=Ie.fromNumber(e);return this._push(Ir,4,r.lo)._push(Ir,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(Na,4,e)}double(e){return this._push(Fa,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(lo,1,0):this.uint32(r)._push(Sh,r,e)}string(e){let r=za(e);return r!==0?this.uint32(r)._push(co,r,e):this._push(lo,1,0)}fork(){return this.states=new po(this),this.head=this.tail=new Bt(ho,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 Bt(ho,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=xh(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function lo(t,e,r){e[r]=t&255}function Eh(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var mo=class extends Bt{next;constructor(e,r){super(Eh,e,r),this.next=void 0}};function Rn(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 Ir(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 Sh(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(Tr.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(Ah,e,t),this},Tr.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(vh,e,t),this});function Ah(t,e,r){e.set(t,r)}function vh(t,e,r){t.length<40?co(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(re(t),r)}function yo(){return new Tr}function Lt(t,e){let r=yo();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*It(t,e,r){let n=Lr(t);yield*e.stream(n,void 0,"$",r)}var Cn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Dn(t,e,r,n,s){return{name:t,type:e,encode:r,decode:n,stream:s}}function go(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 Dn("enum",Cn.VARINT,r,n,s)}function Tt(t,e,r){return Dn("message",Cn.LENGTH_DELIMITED,t,e,r)}var _t=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var le;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(le||(le={}));var bo;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(bo||(bo={}));(function(t){t.codec=()=>go(bo)})(le||(le={}));var Ge;(function(t){let e;t.codec=()=>(e==null&&(e=Tt((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.Type!=null&&(i.uint32(8),le.codec().encode(o.Type,i)),o.Data!=null&&(i.uint32(18),i.bytes(o.Data)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={},f=i==null?o.len:o.pos+i;for(;o.pos<f;){let u=o.uint32();switch(u>>>3){case 1:{c.Type=le.codec().decode(o);break}case 2:{c.Data=o.bytes();break}default:{o.skipType(u&7);break}}}return c},function*(o,i,a,c={}){let f=i==null?o.len:o.pos+i;for(;o.pos<f;){let u=o.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:le.codec().decode(o)};break}case 2:{yield{field:`${a}.Data`,value:o.bytes()};break}default:{o.skipType(u&7);break}}}})),e);function r(o){return Lt(o,t.codec())}t.encode=r;function n(o,i){return vt(o,t.codec(),i)}t.decode=n;function s(o,i){return It(o,t.codec(),i)}t.stream=s})(Ge||(Ge={}));var wo;(function(t){let e;t.codec=()=>(e==null&&(e=Tt((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.Type!=null&&(i.uint32(8),le.codec().encode(o.Type,i)),o.Data!=null&&(i.uint32(18),i.bytes(o.Data)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={},f=i==null?o.len:o.pos+i;for(;o.pos<f;){let u=o.uint32();switch(u>>>3){case 1:{c.Type=le.codec().decode(o);break}case 2:{c.Data=o.bytes();break}default:{o.skipType(u&7);break}}}return c},function*(o,i,a,c={}){let f=i==null?o.len:o.pos+i;for(;o.pos<f;){let u=o.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:le.codec().decode(o)};break}case 2:{yield{field:`${a}.Data`,value:o.bytes()};break}default:{o.skipType(u&7);break}}}})),e);function r(o){return Lt(o,t.codec())}t.encode=r;function n(o,i){return vt(o,t.codec(),i)}t.decode=n;function s(o,i){return It(o,t.codec(),i)}t.stream=s})(wo||(wo={}));var Rr={};Ae(Rr,{MAX_RSA_KEY_SIZE:()=>xo,generateRSAKeyPair:()=>Za,jwkToJWKKeyPair:()=>Xa,jwkToPkcs1:()=>Th,jwkToPkix:()=>vo,jwkToRSAPrivateKey:()=>To,pkcs1MessageToJwk:()=>So,pkcs1MessageToRSAPrivateKey:()=>Bo,pkcs1ToJwk:()=>Ih,pkcs1ToRSAPrivateKey:()=>Ga,pkixMessageToJwk:()=>Ao,pkixMessageToRSAPublicKey:()=>Io,pkixToJwk:()=>_h,pkixToRSAPublicKey:()=>Lo});var Jt=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Rr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ye.createV1(114,this._multihash)}toString(){return fe.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 Wa(this.jwk,r,e,n)}},_r=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Rr.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:xe(this.raw,e.raw)}sign(e,r){return Ya(this.jwk,e,r)}};var xo=8192,Eo=18,Bh=1062,Lh=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Ih(t){let e=$e(t);return So(e)}function So(t){return{n:Z(t[1],"base64url"),e:Z(t[2],"base64url"),d:Z(t[3],"base64url"),p:Z(t[4],"base64url"),q:Z(t[5],"base64url"),dp:Z(t[6],"base64url"),dq:Z(t[7],"base64url"),qi:Z(t[8],"base64url"),kty:"RSA"}}function Th(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 ie("JWK was missing components");return rt([ve(Uint8Array.from([0])),ve(re(t.n,"base64url")),ve(re(t.e,"base64url")),ve(re(t.d,"base64url")),ve(re(t.p,"base64url")),ve(re(t.q,"base64url")),ve(re(t.dp,"base64url")),ve(re(t.dq,"base64url")),ve(re(t.qi,"base64url"))]).subarray()}function _h(t){let e=$e(t,{offset:0});return Ao(e)}function Ao(t){let e=$e(t[1],{offset:0});return{kty:"RSA",n:Z(e[0],"base64url"),e:Z(e[1],"base64url")}}function vo(t){if(t.n==null||t.e==null)throw new ie("JWK was missing components");return rt([Lh,en(rt([ve(re(t.n,"base64url")),ve(re(t.e,"base64url"))]))]).subarray()}function Ga(t){let e=$e(t);return Bo(e)}function Bo(t){let e=So(t);return To(e)}function Lo(t,e){if(t.byteLength>=Bh)throw new Kt("Key size is too large");let r=$e(t,{offset:0});return Io(r,t,e)}function Io(t,e,r){let n=Ao(t);if(r==null){let s=He(Ge.encode({Type:le.RSA,Data:e}));r=Ne(Eo,s)}return new Jt(n,r)}function To(t){if(Qa(t)>xo)throw new ie("Key size is too large");let e=Xa(t),r=He(Ge.encode({Type:le.RSA,Data:vo(e.publicKey)})),n=Ne(Eo,r);return new _r(e.privateKey,new Jt(e.publicKey,n))}async function Za(t){if(t>xo)throw new ie("Key size is too large");let e=await Ja(t),r=He(Ge.encode({Type:le.RSA,Data:vo(e.publicKey)})),n=Ne(Eo,r);return new _r(e.privateKey,new Jt(e.publicKey,n))}function Xa(t){if(t==null)throw new ie("Missing key parameter");return{privateKey:t,publicKey:{kty:t.kty,n:t.n,e:t.e}}}async function Ja(t,e){let r=await De.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 Rh(r,e);return{privateKey:n[0],publicKey:n[1]}}async function Ya(t,e,r){let n=await De.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let s=await De.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,Le(e instanceof Uint8Array?e:e.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(s,0,s.byteLength)}async function Wa(t,e,r,n){let s=await De.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let o=await De.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},s,Le(e),Le(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),o}async function Rh(t,e){if(t.privateKey==null||t.publicKey==null)throw new ie("Private and public key are required");let r=await Promise.all([De.get().subtle.exportKey("jwk",t.privateKey),De.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function Qa(t){if(t.kty!=="RSA")throw new ie("invalid key type");if(t.n==null)throw new ie("invalid key modulus");return re(t.n,"base64url").length*8}var On=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(xt(e),Ee(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),_e(s)}update(e){return Vt(this),this.iHash.update(e),this}digestInto(e){Vt(this),nn(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()}},Cr=(()=>{let t=((e,r,n)=>new On(e,r).update(n).digest());return t.create=(e,r)=>new On(e,r),t})();var Ch=BigInt(0),_o=class extends Error{constructor(e=""){super(e)}},Ze={Err:_o,_tlv:{encode:(t,e)=>{let{Err:r}=Ze;if(We(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(ra(e,"data"),e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,s=br(n);if(s.length/2&128)throw new r("tlv.encode: long form length too big");let o=n>127?br(s.length/2|128):"";return br(t)+o+s+e},decode(t,e){let{Err:r}=Ze;e=Y(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.decode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let s=e[n++],o=!!(s&128),i=0;if(!o)i=s;else{let c=s&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let f=e.subarray(n,n+c);if(f.length!==c)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of f)i=i<<8|u;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+i)}}},_int:{encode(t){let{Err:e}=Ze;if(un(t),t<Ch)throw new e("integer: negative integers are not allowed");let r=br(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}=Ze;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 qe(t)}},toSig(t,e){let{Err:r,_int:n,_tlv:s}=Ze;if(e!==void 0&&(We(e,"maxScalarBytes"),e<1))throw new r("invalid signature: maxScalarBytes must be positive");let o=Y(t,void 0,"signature"),{v:i,l:a}=s.decode(48,o);if(a.length)throw new r("invalid signature: left bytes after parsing");let{v:c,l:f}=s.decode(2,i),{v:u,l:h}=s.decode(2,f);if(h.length)throw new r("invalid signature: left bytes after parsing");if(e!==void 0&&(c.length>e||u.length>e))throw new r("invalid signature: integer too large");return{r:n.decode(c),s:n.decode(u)}},hexFromSig(t){let{_tlv:e,_int:r}=Ze;ge(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)}},kn=(Object.freeze(Ze._tlv),Object.freeze(Ze._int),Object.freeze(Ze));var ec=(t,e)=>(t+(t>=0?e:-e)/tc)/e;function Dh(t,e,r){je("scalar",t,Xe,r);let[[n,s],[o,i]]=e,a=ec(i*t,r),c=ec(-s*t,r),f=t-a*n-c*o,u=-a*s-c*i,h=f<Xe,p=u<Xe;h&&(f=-f),p&&(u=-u);let d=xr(Math.ceil(Yt(r)/2))+Rt;if(f<Xe||f>=d||u<Xe||u>=d)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:h,k1:f,k2neg:p,k2:u}}function Do(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Ro(t,e){ge(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Be(r.lowS,"lowS"),Be(r.prehash,"prehash"),r.format!==void 0&&Do(r.format),r}var Xe=BigInt(0),Rt=BigInt(1),tc=BigInt(2),Co=BigInt(3),Oh=BigInt(4);function rc(t,e={}){let r=bn("weierstrass",t,e),n=r.Fp,s=r.Fn,o=r.CURVE,{h:i,n:a}=o;ge(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:f,clearCofactor:u,isTorsionFree:h,fromBytes:p,toBytes:d}=e,w=e.randomBytes===void 0?Ye:e.randomBytes;if(c&&(!n.is0(o.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let g=c?{beta:c.beta,basises:c.basises.map(S=>[...S])}:void 0,y=sc(n,s);function x(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function E(S,l,m){if(l.is0()){if(!f)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x:A,y:D}=l.toAffine(),U=n.toBytes(A);if(Be(m,"isCompressed"),m){x();let P=!n.isOdd(D);return Re(nc(P),U)}else return Re(Uint8Array.of(4),U,n.toBytes(D))}function b(S){Y(S,void 0,"Point");let{publicKey:l,publicKeyUncompressed:m}=y,A=S.length,D=S[0],U=S.subarray(1);if(f&&A===1&&D===0)return{x:n.ZERO,y:n.ZERO};if(A===l&&(D===2||D===3)){let P=n.fromBytes(U);if(!n.isValid(P))throw new Error("bad point: is not on curve, wrong x");let q=K(P),z;try{z=n.sqrt(q)}catch(ne){let ee=ne instanceof Error?": "+ne.message:"";throw new Error("bad point: is not on curve, sqrt error"+ee)}x();let V=n.isOdd(z);return(D&1)===1!==V&&(z=n.neg(z)),{x:P,y:z}}else if(A===m&&D===4){let P=n.BYTES,q=n.fromBytes(U.subarray(0,P)),z=n.fromBytes(U.subarray(P,P*2));if(!_(q,z))throw new Error("bad point: is not on curve");return{x:q,y:z}}else throw new Error(`bad point: got length ${A}, expected compressed=${l} or uncompressed=${m}`)}let R=d===void 0?E:d,T=p===void 0?b:p,O=n.mul(o.b,Co),N=n.is0(o.a)?S=>n.ZERO:S=>n.mul(o.a,S);function K(S){let l=n.sqr(S),m=n.mul(l,S);return n.add(n.add(m,n.mul(S,o.a)),o.b)}function _(S,l){let m=n.sqr(l),A=K(S);return n.eql(m,A)}if(!_(o.Gx,o.Gy))throw new Error("bad curve params: generator point");let C=n.mul(n.pow(o.a,Co),Oh),F=n.mul(n.sqr(o.b),BigInt(27));if(n.is0(n.add(C,F)))throw new Error("bad curve params: a or b");function M(S,l,m=!1){if(!n.isValid(l)||m&&n.is0(l))throw new Error(`bad point coordinate ${S}`);return typeof l=="object"&&l!==null?n.create(l):l}function j(S){if(!(S instanceof v))throw new Error("Weierstrass Point expected")}function B(S){if(!g||!g.basises)throw new Error("no endo");return Dh(S,g.basises,s.ORDER)}function k(S,l,m,A){if(!s.isValid(A))throw new RangeError("invalid scalar: out of range");if(g){let{k1neg:D,k1:U,k2neg:P,k2:q}=B(A),z=new v(n.mul(m.X,g.beta),m.Y,m.Z);S.push(D?m.negate():m,P?z.negate():z),l.push(U,q)}else S.push(m),l.push(A)}let L=new WeakSet;class v{static BASE=new v(o.Gx,o.Gy,n.ONE);static ZERO=new v(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=s;X;Y;Z;constructor(l,m,A){this.X=M("x",l),this.Y=M("y",m,!0),this.Z=M("z",A),Object.freeze(this)}static CURVE(){return o}static fromAffine(l){let{x:m,y:A}=l||{};if(!l||!n.isValid(m)||!n.isValid(A))throw new Error("invalid affine point");if(l instanceof v)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(A)?v.ZERO:new v(m,A,n.ONE)}static fromBytes(l){let m=v.fromAffine(T(Y(l,void 0,"point")));return m.assertValidity(),m}static fromHex(l){return v.fromBytes($t(l))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(l=6,m=!0){return I.setWindowSize(this,l),m||this.multiply(Co),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(L.has(l))return;let{x:m,y:A}=l.toAffine();if(!n.isValid(m)||!n.isValid(A))throw new Error("bad point: x or y not field elements");if(!_(m,A))throw new Error("bad point: equation left != right");if(!l.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");L.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){j(l);let{X:m,Y:A,Z:D}=this,{X:U,Y:P,Z:q}=l,z=n.eql(n.mul(m,q),n.mul(U,D)),V=n.eql(n.mul(A,q),n.mul(P,D));return z&&V}negate(){return new v(this.X,n.neg(this.Y),this.Z)}double(){let{X:l,Y:m,Z:A}=this,D=n.ZERO,U=n.ZERO,P=n.ZERO,q=n.mul(l,l),z=n.mul(m,m),V=n.mul(A,A),$=n.mul(l,m);return $=n.add($,$),P=n.mul(l,A),P=n.add(P,P),D=N(P),U=n.mul(O,V),U=n.add(D,U),D=n.sub(z,U),U=n.add(z,U),U=n.mul(D,U),D=n.mul($,D),P=n.mul(O,P),V=N(V),$=n.sub(q,V),$=N($),$=n.add($,P),P=n.add(q,q),q=n.add(P,q),q=n.add(q,V),q=n.mul(q,$),U=n.add(U,q),V=n.mul(m,A),V=n.add(V,V),q=n.mul(V,$),D=n.sub(D,q),P=n.mul(V,z),P=n.add(P,P),P=n.add(P,P),new v(D,U,P)}add(l){j(l);let{X:m,Y:A,Z:D}=this,{X:U,Y:P,Z:q}=l,z=n.ZERO,V=n.ZERO,$=n.ZERO,ne=n.mul(m,U),ee=n.mul(A,P),ce=n.mul(D,q),Se=n.add(m,A),te=n.add(U,P);Se=n.mul(Se,te),te=n.add(ne,ee),Se=n.sub(Se,te),te=n.add(m,D);let oe=n.add(U,q);return te=n.mul(te,oe),oe=n.add(ne,ce),te=n.sub(te,oe),oe=n.add(A,D),z=n.add(P,q),oe=n.mul(oe,z),z=n.add(ee,ce),oe=n.sub(oe,z),$=N(te),z=n.mul(O,ce),$=n.add(z,$),z=n.sub(ee,$),$=n.add(ee,$),V=n.mul(z,$),ee=n.add(ne,ne),ee=n.add(ee,ne),ce=N(ce),te=n.mul(O,te),ee=n.add(ee,ce),ce=n.sub(ne,ce),ce=N(ce),te=n.add(te,ce),ne=n.mul(ee,te),V=n.add(V,ne),ne=n.mul(oe,te),z=n.mul(Se,z),z=n.sub(z,ne),ne=n.mul(Se,ee),$=n.mul(oe,$),$=n.add($,ne),new v(z,V,$)}subtract(l){return j(l),this.add(l.negate())}is0(){return this.equals(v.ZERO)}multiply(l){if(!s.isValidNot0(l))throw new RangeError("invalid scalar: out of range");let{p:m,f:A}=I.mulSecret(this,l,i,H);return H([m,A])[0]}multiplyUnsafe(l){let m=this,A=l;if(!s.isValid(A))throw new RangeError("invalid scalar: out of range");if(A===Xe||m.is0())return v.ZERO;if(A===Rt)return m;if(I.hasWindowSize(this))return I.mulUnsafe(m,A,H);let D=[],U=[];return k(D,U,m,A),gn(v,D,U)}mulAddUnsafe(l,m,A){j(m);let D=[],U=[];return k(D,U,this,l),k(D,U,m,A),gn(v,D,U)}toAffine(l){let m=this,A=l;if(A!=null&&!n.isValid(A))throw new RangeError('"invertedZ" expected valid field element');let{X:D,Y:U,Z:P}=m;if(n.eql(P,n.ONE))return{x:D,y:U};let q=m.is0();A==null&&(A=q?n.ONE:n.inv(P));let z=n.mul(D,A),V=n.mul(U,A),$=n.mul(P,A);if(q)return{x:n.ZERO,y:n.ZERO};if(!n.eql($,n.ONE))throw new Error("invZ was invalid");return{x:z,y:V}}isTorsionFree(){return i===Rt?!0:h?h(v,this):I.mulUnsafe(this,a).is0()}clearCofactor(){return i===Rt?this:u?u(v,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===Rt?this.is0():this.clearCofactor().is0()}toBytes(l=!0){return Be(l,"isCompressed"),this.assertValidity(),R(v,this,l)}toHex(l=!0){return gr(this.toBytes(l))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let H=S=>yn(v,S),I=new Zt(v,w);return I.bits>=6&&v.BASE.precompute(6),Object.freeze(v.prototype),Object.freeze(v),v}function nc(t){return Uint8Array.of(t?2:3)}function sc(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function kh(t,e={}){lt(t);let{Fn:r}=t,n=e.randomBytes===void 0?Ye:e.randomBytes,s=Object.assign(sc(t.Fp,r),{seed:Math.max(pn(r.ORDER),16)});function o(d){try{let w=r.fromBytes(d);return r.isValidNot0(w)}catch{return!1}}function i(d,w){let{publicKey:g,publicKeyUncompressed:y}=s;try{let x=d.length;return w===!0&&x!==g||w===!1&&x!==y?!1:!t.fromBytes(d).is0()}catch{return!1}}function a(d){return d=d===void 0?n(s.seed):d,mn(Y(d,s.seed,"seed"),r.ORDER)}function c(d,w=!0){return t.BASE.multiply(r.fromBytes(d)).toBytes(w)}function f(d){let{secretKey:w,publicKey:g,publicKeyUncompressed:y}=s,x=r._lengths;if(!ft(d))return;let E=Y(d,void 0,"key").length,b=E===g||E===y,R=E===w||!!x?.includes(E);if(!(b&&R))return b}function u(d,w,g=!0){if(f(d)===!0)throw new Error("first arg must be private key");if(f(w)===!1)throw new Error("second arg must be public key");let y=r.fromBytes(d),x=t.fromBytes(w);if(x.is0())throw new Error("invalid public key: point at infinity");return x.multiply(y).toBytes(g)}let h={isValidSecretKey:o,isValidPublicKey:i,randomSecretKey:a},p=Xt(a,c);return Object.freeze(h),Object.freeze(s),Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:p,Point:t,utils:h,lengths:s})}function oc(t,e,r={}){lt(t);let n=e;xt(n),ge(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let s=Object.assign({},r),o=s.randomBytes===void 0?Ye:s.randomBytes,i=s.hmac===void 0?(S,l)=>Cr(n,S,l):s.hmac,{Fp:a,Fn:c}=t,{ORDER:f,BITS:u}=c,h=pn(f),p=Gs(o,h),{keygen:d,getPublicKey:w,getSharedSecret:g,utils:y,lengths:x}=kh(t,s),E={prehash:!0,lowS:typeof s.lowS=="boolean"?s.lowS:!0,format:"compact",extraEntropy:!1},b=f*tc+Rt<a.ORDER;function R(S){let l=f>>Rt;return S>l}function T(S,l){if(!c.isValidNot0(l))throw new Error(`invalid signature ${S}: out of range 1..Point.Fn.ORDER`);return l}function O(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function N(S,l,m){return O(),(S===m?0:2)|Number(a.isOdd(l))}function K(){if(b)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function _(S,l){Do(l);let m=x.signature,A=l==="compact"?m:l==="recovered"?m+1:void 0;return Y(S,A)}class C{r;s;recovery;constructor(l,m,A){if(this.r=T("r",l),this.s=T("s",m),A!=null){if(K(),![0,1,2,3].includes(A))throw new Error("invalid recovery id");this.recovery=A}Object.freeze(this)}static fromBytes(l,m=E.format){_(l,m);let A;if(m==="der"){if(l.length>2*c.BYTES+16)throw new kn.Err("invalid signature: DER signature too long");let{r:q,s:z}=kn.toSig(Y(l),c.BYTES+1);return new C(q,z)}m==="recovered"&&(A=l[0],m="compact",l=l.subarray(1));let D=x.signature/2,U=l.subarray(0,D),P=l.subarray(D,D*2);return new C(c.fromBytes(U),c.fromBytes(P),A)}static fromHex(l,m){return this.fromBytes($t(l),m)}assertRecovery(){let{recovery:l}=this;if(l==null)throw new Error("invalid recovery id: must be present");return l}addRecoveryBit(l){return new C(this.r,this.s,l)}recoverPublicKey(l){let{r:m,s:A}=this,D=this.assertRecovery(),U=D===2||D===3?m+f:m;if(!a.isValid(U))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let P=a.toBytes(U),q=t.fromBytes(Re(nc((D&1)===0),P)),z=c.inv(U),V=M(Y(l,void 0,"msgHash")),$=c.create(-V*z),ne=c.create(A*z),ee=t.BASE.mulAddUnsafe($,q,ne);if(ee.is0())throw new Error("invalid recovery: point at infinify");return ee.assertValidity(),ee}hasHighS(){return R(this.s)}toBytes(l=E.format){if(Do(l),l==="der")return $t(kn.hexFromSig(this));let{r:m,s:A}=this,D=c.toBytes(m),U=c.toBytes(A);return l==="recovered"?(K(),Re(Uint8Array.of(this.assertRecovery()),D,U)):Re(D,U)}toHex(l){return gr(this.toBytes(l))}}Object.freeze(C.prototype),Object.freeze(C);let F=s.bits2int===void 0?function(l){if(l.length>8192)throw new Error("input is too large");let m=qe(l),A=l.length*8-u;return A>0?m>>BigInt(A):m}:s.bits2int,M=s.bits2int_modN===void 0?function(l){return c.create(F(l))}:s.bits2int_modN,j=xr(u);function B(S){return je("num < 2^"+u,S,Xe,j),c.toBytes(S)}function k(S,l){return Y(S,void 0,"message"),l?Y(n(S),void 0,"prehashed message"):S}function L(S,l,m){let{lowS:A,prehash:D,extraEntropy:U}=Ro(m,E);S=k(S,D);let P=M(S),q=c.fromBytes(l);if(!c.isValidNot0(q))throw new Error("invalid private key");let z=[B(q),B(P)];if(U!=null&&U!==!1){let ee=U===!0?o(x.secretKey):U;z.push(Y(ee,void 0,"extraEntropy"))}let V=Re(...z),$=P;function ne(ee){let ce=F(ee);if(!c.isValidNot0(ce))return;let Se=t.BASE.multiply(ce).toAffine(),te=c.create(Se.x);if(te===Xe)return;let oe;if(p!==void 0){let Qe=qe(mn(p(h),f)),Nc=c.inv(c.mul(Qe,ce)),Mc=c.mul(Qe,$),Fc=c.mul(Qe,q);oe=c.create(Nc*c.create(Mc+Fc*te))}else{let Qe=la(ce,f);oe=c.create(Qe*c.create($+te*q))}if(oe===Xe)return;let kt=N(Se.x,Se.y,te),ar=oe;return A&&R(oe)&&(ar=c.neg(oe),kt^=1),new C(te,ar,b?void 0:kt)}return{seed:V,k2sig:ne}}function v(S,l,m={}){let{seed:A,k2sig:D}=L(S,l,m);return sa(n.outputLen,c.BYTES,i)(A,D).toBytes(m.format)}function H(S,l,m,A={}){let{lowS:D,prehash:U,format:P}=Ro(A,E);if(m=Y(m,void 0,"publicKey"),l=k(l,U),!ft(S)){let q=S instanceof C?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+q)}_(S,P);try{let q=C.fromBytes(S,P),z=t.fromBytes(m);if(z.is0()||D&&q.hasHighS())return!1;let{r:V,s:$}=q,ne=M(l),ee=c.inv($),ce=c.create(ne*ee),Se=c.create(V*ee),te=t.BASE.mulAddUnsafe(ce,z,Se);if(te.is0())return!1;let oe=te.toAffine();return!(c.create(oe.x)!==V||P==="recovered"&&q.recovery!==N(oe.x,oe.y,V))}catch{return!1}}function I(S,l,m={}){let{prehash:A}=Ro(m,E);return l=k(l,A),C.fromBytes(S,"recovered").recoverPublicKey(l).toBytes()}return Object.freeze({keygen:d,getPublicKey:w,getSharedSecret:g,utils:y,lengths:x,Point:t,sign:v,verify:H,recoverPublicKey:I,Signature:C,hash:n})}var ko={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Kh={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var ic=BigInt(2);function Uh(t){let e=ko.p,r=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),f=t*t*t%e,u=f*f*t%e,h=se(u,r,e)*u%e,p=se(h,r,e)*u%e,d=se(p,ic,e)*f%e,w=se(d,s,e)*d%e,g=se(w,o,e)*w%e,y=se(g,a,e)*g%e,x=se(y,c,e)*y%e,E=se(x,a,e)*g%e,b=se(E,r,e)*u%e,R=se(b,i,e)*w%e,T=se(R,n,e)*f%e,O=se(T,ic,e);if(!Oo.eql(Oo.sqr(O),t))throw new Error("Cannot find square root");return O}var Oo=Gt(ko.p,{sqrt:Uh}),Ph=rc(ko,{Fp:Oo,endo:Kh}),Qt=oc(Ph,He);function ac(t,e,r,n){let s=Jr.digest(r instanceof Uint8Array?r:r.subarray());if(Ln(s))return s.then(({digest:o})=>(n?.signal?.throwIfAborted(),Qt.verify(e,o,t,{prehash:!1,format:"der"}))).catch(o=>{throw o.name==="AbortError"?o:new Br(String(o))});try{return n?.signal?.throwIfAborted(),Qt.verify(e,s.digest,t,{prehash:!1,format:"der"})}catch(o){throw new Br(String(o))}}var Kn=class{type="secp256k1";raw;_key;constructor(e){this._key=fc(e),this.raw=cc(this._key)}toMultihash(){return Me.digest(nt(this))}toCID(){return ye.createV1(114,this.toMultihash())}toString(){return fe.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 ac(this._key,r,e,n)}};function uc(t){return new Kn(t)}function cc(t){return Qt.Point.fromBytes(t).toBytes()}function fc(t){try{return Qt.Point.fromBytes(t),t}catch(e){throw new Kt(String(e))}}function Dr(t,e){let{Type:r,Data:n}=Ge.decode(t),s=n??new Uint8Array;switch(r){case le.RSA:return Lo(s,e);case le.Ed25519:return Ka(s);case le.secp256k1:return uc(s);case le.ECDSA:return ki(s);default:throw new Ut}}function nt(t){return Ge.encode({Type:le[t.type],Data:t.raw})}var hc=Symbol.for("nodejs.util.inspect.custom"),Nh=114,Or=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()})`}[Qn]=!0;toString(){return this.string==null&&(this.string=fe.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ye.createV1(Nh,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")}[hc](){return`PeerId(${this.toString()})`}},Un=class extends Or{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Pn=class extends Or{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Nn=class extends Or{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},Mh=2336,Ko=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Me.digest(re(this.url))}[hc](){return`PeerId(${this.url})`}[Qn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ye.createV1(Mh,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=Z(e)),e.toString()===this.toString())}};function Uo(t){if(t.type==="Ed25519")return new Pn({multihash:t.toCID().multihash,publicKey:t});if(t.type==="secp256k1")return new Nn({multihash:t.toCID().multihash,publicKey:t});if(t.type==="RSA")return new Un({multihash:t.toCID().multihash,publicKey:t});throw new Ut}function Mn(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Fn=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}},er=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Fn(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 Fn(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 Po=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Hn(t={}){return Fh(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 Fh(t,e){e=e??{};let r=e.onEnd,n=new er,s,o,i,a=Mn(),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(b){x(b)}return s}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Mn()})}},f=y=>o!=null?o(y):(n.push(y),s),u=y=>(n=new er,o!=null?o({error:y}):(n.push({error:y}),s)),h=y=>{if(i)return s;if(e?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:y})},p=y=>i?s:(i=!0,y!=null?u(y):f({done:!0})),d=()=>(n=new er,p(),{done:!0}),w=y=>(p(y),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:d,throw:w,push:h,end:p,get readableLength(){return n.size},onEmpty:async y=>{let x=y?.signal;if(x?.throwIfAborted(),n.isEmpty())return;let E,b;x!=null&&(E=new Promise((R,T)=>{b=()=>{T(new Po)},x.addEventListener("abort",b)}));try{await Promise.race([a.promise,E])}finally{b!=null&&x!=null&&x?.removeEventListener("abort",b)}}},r==null)return s;let g=s;return s={[Symbol.asyncIterator](){return this},next(){return g.next()},throw(y){return g.throw(y),r!=null&&(r(y),r=void 0),{done:!0}},return(){return g.return(),r!=null&&(r(),r=void 0),{done:!0}},push:h,end(y){return g.end(y),r!=null&&(r(y),r=void 0),s},get readableLength(){return g.readableLength},onEmpty:y=>g.onEmpty(y)},s}var No=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},lc=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function Mo(t,e){let{milliseconds:r,fallback:n,message:s,customTimers:o={setTimeout,clearTimeout},signal:i}=e,a,c,u=new Promise((h,p)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){p(lc(i));return}if(i&&(c=()=>{p(lc(i))},i.addEventListener("abort",c,{once:!0})),t.then(h,p),r===Number.POSITIVE_INFINITY)return;let d=new No;a=o.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(w){p(w)}return}typeof t.cancel=="function"&&t.cancel(),s===!1?h():s instanceof Error?p(s):(d.message=s??`Promise timed out after ${r} milliseconds`,p(d))},r)}).finally(()=>{u.clear(),c&&i&&i.removeEventListener("abort",c)});return u.clear=()=>{o.clearTimeout.call(void 0,a),a=void 0},u}var Hh=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 qh(t,e,r){let n,s=new Promise((o,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:f,removeListener:u}=Hh(t),h=async(...d)=>{let w=r.multiArgs?d:d[0];if(r.filter)try{if(!await r.filter(w))return}catch(g){n(),i(g);return}c.push(w),r.count===c.length&&(n(),o(c))},p=(...d)=>{n(),i(r.rejectionMultiArgs?d:d[0])};n=()=>{for(let d of a)u(d,h);for(let d of r.rejectionEvents)a.includes(d)||u(d,p)};for(let d of a)f(d,h);for(let d of r.rejectionEvents)a.includes(d)||f(d,p);r.signal&&r.signal.addEventListener("abort",()=>{p(r.signal.reason)},{once:!0}),r.resolveImmediately&&o(c)});if(s.cancel=n,typeof r.timeout=="number"){let o=Mo(s,{milliseconds:r.timeout});return o.cancel=()=>{n(),o.clear()},o}return s}function dc(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=qh(t,e,r),s=n.then(o=>o[0]);return s.cancel=n.cancel,s}var Ct=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};var qn=class extends Error{static name="StreamClosedError";name="StreamClosedError"};function zh(t){return t.reason}function kr(t,e,r){if(e==null||t==null)return t;let n=r?.translateError??zh;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 jh=Math.pow(2,20)*4,zn=class extends Gr{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??jh,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new G,this.writeBuffer=new G,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 qn)};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()),kr(this.onDrainPromise.promise,e?.signal))}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=Hn(),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 et(`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 Yr(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new et("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 et("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 et(`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 et(`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 Wr(new Vr))}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 Pt))}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 G(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 $r(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 mt(`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 mt(`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 Vh=4194304,jn=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Kr=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Ho=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},qo=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function $h(t){return typeof t?.closeRead=="function"}function Yh(t){return typeof t?.close=="function"}function Fo(t){return $h(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:Yh(t)?t.status!=="open":!1}function Wh(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function Gh(t,e){let r=e?.maxBufferSize??Vh,n=new G,s,o=!1,i;if(!Wh(t))throw new ie("Argument should be a Stream or a Multiaddr");let a=h=>{if(i==null){if(n.append(h.data),n.byteLength>r){let p=n.byteLength;n.consume(p);let d=new mt(`Read buffer overflow - ${p} > ${r}`);i=d,s?.reject(d),queueMicrotask(()=>{t.abort(d)});return}s?.resolve()}};t.addEventListener("message",a);let c=h=>{h.error!=null?s?.reject(h.error):s?.resolve()};t.addEventListener("close",c);let f=()=>{s?.resolve()};t.addEventListener("remoteCloseWrite",f);let u={readBuffer:n,async read(h){if(o===!0)throw new jn("Stream was unwrapped");if(i!=null)throw i;if(Fo(t)){if(n.byteLength===0&&h?.bytes==null)return null;if(h?.bytes!=null&&n.byteLength<h.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,h.bytes),new Ct(`Unexpected EOF - stream closed after reading ${n.byteLength}/${h.bytes} bytes`)}let p=h?.bytes??1;for(s=Promise.withResolvers();;){if(n.byteLength>=p){s.resolve();break}if(await kr(s.promise,h?.signal),Fo(t)){if(n.byteLength===0&&h?.bytes==null)return null;break}s=Promise.withResolvers()}let d=h?.bytes??n.byteLength;if(n.byteLength<d){if(Fo(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,d),new Ct(`Unexpected EOF - stream closed while reading ${n.byteLength}/${d} bytes`);return u.read(h)}let w=n.sublist(0,d);return n.consume(d),w},async write(h,p){if(o===!0)throw new jn("Stream was unwrapped");t.send(h)||await dc(t,"drain",{signal:p?.signal,rejectionEvents:["close"]})},unwrap(){return o||(o=!0,t.removeEventListener("message",a),t.removeEventListener("close",c),t.removeEventListener("remoteCloseWrite",f),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.unshift(n))),t}};return u}function zo(t,e={}){let r=Gh(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Ke(e.maxDataLength));let n=e?.lengthDecoder??Tn,s=e?.lengthEncoder??Ua;return{async read(i){let a=-1,c=new G;for(;;){let u=await r.read({...i,bytes:1});if(u==null)break;c.append(u);try{a=n(c)}catch(h){if(h instanceof RangeError)continue;throw h}if(a<0)throw new Kr("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new qo(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new Ho(`Message length too long - ${a} > ${e.maxDataLength}`);let f=await r.read({...i,bytes:a});if(f==null)throw t.log.error("tried to read %d bytes but the stream closed",a),new Ct(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(f.byteLength!==a)throw t.log.error("read %d/%d bytes before the stream closed",f.byteLength,a),new Ct(`Unexpected EOF - read ${f.byteLength}/${a} bytes before the stream closed`);return f},async write(i,a){await r.write(new G(s(i.byteLength),i),a)},async writeV(i,a){let c=new G(...i.flatMap(f=>[s(f.byteLength),f]));await r.write(c,a)},unwrap(){return r.unwrap()}}}var Zh=1024*1024*4,Xh=1024*1024*4,Vn=class{buffer;maxBufferSize;lengthDecoder;maxDataLength;encodingLength;constructor(e={}){this.buffer=new G,this.maxBufferSize=e.maxBufferSize??Zh,this.maxDataLength=e.maxDataLength??Xh,this.lengthDecoder=e.lengthDecoder??Tn,this.encodingLength=e.encodingLength??Ke}*decode(e){if(this.buffer.append(e),this.buffer.byteLength>this.maxBufferSize)throw new ie(`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 Kr("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 tr=!!globalThis.process?.env?.DUMP_SESSION_KEYS,jo=16;function Vo(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var $n=t=>t?`"${t}" `:"";function Yn(t,e=""){if(typeof t!="boolean")throw new TypeError($n(e)+"expected boolean, got type="+typeof t);return t}function Dt(t,e=""){if(typeof t!="number")throw new TypeError($n(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError($n(e)+"expected integer >= 0, got "+t);return t}function ue(t,e,r=""){if(Vo(t)&&(e===void 0||t.length===e))return t;e!==void 0&&Dt(e,"length");let n=Vo(t),s=e!==void 0?` of length ${e}`:"",o=n?`length=${t.length}`:`type=${typeof t}`,i=$n(r)+"expected Uint8Array"+s+", got "+o;throw n?new RangeError(i):new TypeError(i)}var pc=(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 $o(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function mc(t,e){ue(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function Ve(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function Pe(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Jh(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}var pt=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Qh(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function el(t){for(let e=0;e<t.length;e++)t[e]=Qh(t[e]);return t}var Je=pt?t=>t:el;function tl(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 yc(t,e){if(tl(t,e)&&t.byteOffset<e.byteOffset)throw new Error("complex overlap of input and output is not supported")}function gc(t,e){return pc(t,"defaults"),pc(e,"opts"),Object.assign(t,e)}function bc(t,e){if(t=ue(t),e=ue(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 wc(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 xc=(t,e)=>{function r(n,...s){if(ue(n,void 0,"key"),t.nonceLength!==void 0){let h=s[0];ue(h,t.varSizeNonce?void 0:t.nonceLength,"nonce")}let o=t.tagLength,i=t.nonceLength!==void 0?1:0;if(!t.withAAD){for(let h=i;h<s.length;h++)if(Vo(s[h]))throw new Error("AAD not supported")}t.withAAD&&s[i]!==void 0&&ue(s[i],void 0,"AAD");let a=e(n,...s),c=(h,p)=>{if(p!==void 0){if(h!==2)throw new Error("cipher output not supported");ue(p,void 0,"output")}},f=!1;return{encrypt(h,p){if(f)throw new Error("cannot encrypt() twice with same key + nonce");return f=!0,ue(h,void 0,"data"),c(a.encrypt.length,p),a.encrypt(h,p)},decrypt(h,p){if(ue(h,void 0,"data"),o&&h.length<o)throw new Error('"ciphertext" expected length >= tagLength='+o);return c(a.decrypt.length,p),a.decrypt(h,p)}}}return Object.assign(r,t),r};function Ur(t,e,r=!0){if(e===void 0)return new Uint8Array(t);if(ue(e,t,"output"),r&&!Pr(e))throw new Error("invalid output, must be aligned");return e}function Ec(t,e,r){Dt(t),Dt(e),Yn(r);let n=new Uint8Array(16),s=Jh(n);return s.setBigUint64(0,BigInt(e),r),s.setBigUint64(8,BigInt(t),r),n}function Pr(t){return t.byteOffset%4===0}function rr(t){return Uint8Array.from(ue(t))}var Ac=t=>Uint8Array.from(t.split(""),e=>e.charCodeAt(0)),rl=Je(Ve(Ac("expand 16-byte k"))),nl=Je(Ve(Ac("expand 32-byte k")));function W(t,e){return t<<e|t>>>32-e}var Nr=64,sl=16,Yo=2**32-1,Sc=Uint32Array.of();function ol(t,e,r,n,s,o,i,a){let c=s.length,f=new Uint8Array(Nr),u=Ve(f),h=pt&&Pr(s)&&Pr(o),p=h?Ve(s):Sc,d=h?Ve(o):Sc;if(!pt){for(let w=0;w<c;i++){if(t(e,r,n,u,i,a),Je(u),i>=Yo)throw new Error("arx: counter overflow");let g=Math.min(Nr,c-w);for(let y=0,x;y<g;y++)x=w+y,o[x]=s[x]^f[y];w+=g}return}for(let w=0;w<c;i++){if(t(e,r,n,u,i,a),i>=Yo)throw new Error("arx: counter overflow");let g=Math.min(Nr,c-w);if(h&&g===Nr){let y=w/4;if(w%4!==0)throw new Error("arx: invalid block position");for(let x=0,E;x<sl;x++)E=y+x,d[E]=p[E]^u[x];w+=Nr;continue}for(let y=0,x;y<g;y++)x=w+y,o[x]=s[x]^f[y];w+=g}}function vc(t,e){let{allowShortKeys:r,extendNonceFn:n,counterLength:s,counterRight:o,rounds:i}=gc({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof t!="function")throw new Error("core must be a function");return Dt(s),Dt(i),Yn(o),Yn(r),(a,c,f,u,h=0)=>{ue(a,void 0,"key"),ue(c,void 0,"nonce"),ue(f,void 0,"data");let p=f.length,d=u!==void 0;if(u=Ur(p,u,!1),d&&yc(f,u),Dt(h),h<0||h>=Yo)throw new Error("arx: counter overflow");let w=[],g=a.length,y,x;if(g===32)w.push(y=rr(a)),x=nl;else if(g===16&&r)y=new Uint8Array(32),y.set(a),y.set(a,16),x=rl,w.push(y);else throw ue(a,32,"arx key"),new Error("invalid key size");(!pt||!Pr(c))&&w.push(c=rr(c));let E=Ve(y);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");let T=c.subarray(0,16);if(pt)n(x,E,Ve(T),E);else{let O=Je(Uint32Array.from(x));n(O,E,Ve(T),E),Pe(O),Je(E)}c=c.subarray(16)}else pt||Je(E);let b=16-s;if(b!==c.length)throw new Error(`arx: nonce must be ${b} or 16 bytes`);if(b!==12){let T=new Uint8Array(12);T.set(c,o?0:12-c.length),c=T,w.push(c)}let R=Je(Ve(c));try{return ol(t,x,E,R,f,u,h,i),u}finally{Pe(...w)}}}function me(t,e){return t[e++]&255|(t[e++]&255)<<8}var Wo=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=rr(ue(e,32,"key"));let r=me(e,0),n=me(e,2),s=me(e,4),o=me(e,6),i=me(e,8),a=me(e,10),c=me(e,12),f=me(e,14);this.r[0]=r&8191,this.r[1]=(r>>>13|n<<3)&8191,this.r[2]=(n>>>10|s<<6)&7939,this.r[3]=(s>>>7|o<<9)&8191,this.r[4]=(o>>>4|i<<12)&255,this.r[5]=i>>>1&8190,this.r[6]=(i>>>14|a<<2)&8191,this.r[7]=(a>>>11|c<<5)&8065,this.r[8]=(c>>>8|f<<8)&8191,this.r[9]=f>>>5&127;for(let u=0;u<8;u++)this.pad[u]=me(e,16+2*u)}process(e,r,n=!1){let s=n?0:2048,{h:o,r:i}=this,a=i[0],c=i[1],f=i[2],u=i[3],h=i[4],p=i[5],d=i[6],w=i[7],g=i[8],y=i[9],x=me(e,r+0),E=me(e,r+2),b=me(e,r+4),R=me(e,r+6),T=me(e,r+8),O=me(e,r+10),N=me(e,r+12),K=me(e,r+14),_=o[0]+(x&8191),C=o[1]+((x>>>13|E<<3)&8191),F=o[2]+((E>>>10|b<<6)&8191),M=o[3]+((b>>>7|R<<9)&8191),j=o[4]+((R>>>4|T<<12)&8191),B=o[5]+(T>>>1&8191),k=o[6]+((T>>>14|O<<2)&8191),L=o[7]+((O>>>11|N<<5)&8191),v=o[8]+((N>>>8|K<<8)&8191),H=o[9]+(K>>>5|s),I=0,S=I+_*a+C*(5*y)+F*(5*g)+M*(5*w)+j*(5*d);I=S>>>13,S&=8191,S+=B*(5*p)+k*(5*h)+L*(5*u)+v*(5*f)+H*(5*c),I+=S>>>13,S&=8191;let l=I+_*c+C*a+F*(5*y)+M*(5*g)+j*(5*w);I=l>>>13,l&=8191,l+=B*(5*d)+k*(5*p)+L*(5*h)+v*(5*u)+H*(5*f),I+=l>>>13,l&=8191;let m=I+_*f+C*c+F*a+M*(5*y)+j*(5*g);I=m>>>13,m&=8191,m+=B*(5*w)+k*(5*d)+L*(5*p)+v*(5*h)+H*(5*u),I+=m>>>13,m&=8191;let A=I+_*u+C*f+F*c+M*a+j*(5*y);I=A>>>13,A&=8191,A+=B*(5*g)+k*(5*w)+L*(5*d)+v*(5*p)+H*(5*h),I+=A>>>13,A&=8191;let D=I+_*h+C*u+F*f+M*c+j*a;I=D>>>13,D&=8191,D+=B*(5*y)+k*(5*g)+L*(5*w)+v*(5*d)+H*(5*p),I+=D>>>13,D&=8191;let U=I+_*p+C*h+F*u+M*f+j*c;I=U>>>13,U&=8191,U+=B*a+k*(5*y)+L*(5*g)+v*(5*w)+H*(5*d),I+=U>>>13,U&=8191;let P=I+_*d+C*p+F*h+M*u+j*f;I=P>>>13,P&=8191,P+=B*c+k*a+L*(5*y)+v*(5*g)+H*(5*w),I+=P>>>13,P&=8191;let q=I+_*w+C*d+F*p+M*h+j*u;I=q>>>13,q&=8191,q+=B*f+k*c+L*a+v*(5*y)+H*(5*g),I+=q>>>13,q&=8191;let z=I+_*g+C*w+F*d+M*p+j*h;I=z>>>13,z&=8191,z+=B*u+k*f+L*c+v*a+H*(5*y),I+=z>>>13,z&=8191;let V=I+_*y+C*g+F*w+M*d+j*p;I=V>>>13,V&=8191,V+=B*h+k*u+L*f+v*c+H*a,I+=V>>>13,V&=8191,I=(I<<2)+I|0,I=I+S|0,S=I&8191,I=I>>>13,l+=I,o[0]=S,o[1]=l,o[2]=m,o[3]=A,o[4]=D,o[5]=U,o[6]=P,o[7]=q,o[8]=z,o[9]=V}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;Pe(n)}update(e){$o(this),ue(e),e=rr(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,Pe(this.h,this.r,this.buffer,this.pad)}digestInto(e){$o(this),mc(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}},Bc=wc(32,t=>new Wo(t));function il(t,e,r,n,s,o=20){let i=t[0],a=t[1],c=t[2],f=t[3],u=e[0],h=e[1],p=e[2],d=e[3],w=e[4],g=e[5],y=e[6],x=e[7],E=s,b=r[0],R=r[1],T=r[2],O=i,N=a,K=c,_=f,C=u,F=h,M=p,j=d,B=w,k=g,L=y,v=x,H=E,I=b,S=R,l=T;for(let A=0;A<o;A+=2)O=O+C|0,H=W(H^O,16),B=B+H|0,C=W(C^B,12),O=O+C|0,H=W(H^O,8),B=B+H|0,C=W(C^B,7),N=N+F|0,I=W(I^N,16),k=k+I|0,F=W(F^k,12),N=N+F|0,I=W(I^N,8),k=k+I|0,F=W(F^k,7),K=K+M|0,S=W(S^K,16),L=L+S|0,M=W(M^L,12),K=K+M|0,S=W(S^K,8),L=L+S|0,M=W(M^L,7),_=_+j|0,l=W(l^_,16),v=v+l|0,j=W(j^v,12),_=_+j|0,l=W(l^_,8),v=v+l|0,j=W(j^v,7),O=O+F|0,l=W(l^O,16),L=L+l|0,F=W(F^L,12),O=O+F|0,l=W(l^O,8),L=L+l|0,F=W(F^L,7),N=N+M|0,H=W(H^N,16),v=v+H|0,M=W(M^v,12),N=N+M|0,H=W(H^N,8),v=v+H|0,M=W(M^v,7),K=K+j|0,I=W(I^K,16),B=B+I|0,j=W(j^B,12),K=K+j|0,I=W(I^K,8),B=B+I|0,j=W(j^B,7),_=_+C|0,S=W(S^_,16),k=k+S|0,C=W(C^k,12),_=_+C|0,S=W(S^_,8),k=k+S|0,C=W(C^k,7);let m=0;n[m++]=i+O|0,n[m++]=a+N|0,n[m++]=c+K|0,n[m++]=f+_|0,n[m++]=u+C|0,n[m++]=h+F|0,n[m++]=p+M|0,n[m++]=d+j|0,n[m++]=w+B|0,n[m++]=g+k|0,n[m++]=y+L|0,n[m++]=x+v|0,n[m++]=E+H|0,n[m++]=b+I|0,n[m++]=R+S|0,n[m++]=T+l|0}var al=vc(il,{counterRight:!1,counterLength:4,allowShortKeys:!1});var cl=new Uint8Array(16),Lc=(t,e)=>{t.update(e);let r=e.length%16;r&&t.update(cl.subarray(r))},fl=new Uint8Array(32);function Ic(t,e,r,n,s){s!==void 0&&ue(s,void 0,"AAD");let o=t(e,r,fl),i=Ec(n.length,s?s.length:0,!0),a=Bc.create(o);s&&Lc(a,s),Lc(a,n),a.update(i);let c=a.digest();return Pe(o,i),c}var ul=t=>(e,r,n)=>({encrypt(o,i){let a=o.length;i=Ur(a+16,i,!1),i.set(o);let c=i.subarray(0,-16);t(e,r,c,c,1);let f=Ic(t,e,r,c,n);return i.set(f,a),Pe(f),i},decrypt(o,i){i=Ur(o.length-16,i,!1);let a=o.subarray(0,-16),c=o.subarray(-16),f=Ic(t,e,r,a,n);if(!bc(c,f))throw Pe(f),new Error("invalid tag");return i.set(o.subarray(0,-16)),t(e,r,i,i,1),Pe(f),i}}),Go=xc({blockSize:64,nonceLength:12,tagLength:16,withAAD:!0},ul(al));function Tc(t,e,r){return xt(t),r===void 0&&(r=new Uint8Array(t.outputLen)),Cr(t,r,e)}var Mr=Uint8Array.of(0),hl=Uint8Array.of();function _c(t,e,r,n=32,s){xt(t),Oe(n,"length"),Ee(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=hl:Ee(r,void 0,"info"),!i)return s&&_e(e),new Uint8Array;let a=s&&i===1?e:new Uint8Array(i*o),{iHash:c,oHash:f}=Cr.create(t,e),u=s?e:new Uint8Array(o),h=i>1?s?.iHash||t.create():void 0;for(let d=0;d<i-1;d++){Mr[0]=d+1;let w=c._cloneInto(h);d&&w.update(u),w.update(r).update(Mr).digestInto(u),f._cloneInto(h).update(u).digestInto(u),a.set(u,o*d)}if(Mr[0]=i,i>1&&c.update(u),c.update(r).update(Mr).digestInto(u),f.update(u).digestInto(u),a.set(u,o*(i-1)),c.destroy(),f.destroy(),h?.destroy(),u!==a&&_e(u),_e(Mr),n===a.length)return a;let p=a.slice(0,n);return _e(a),p}var Wn={hashSHA256(t){return He(t.subarray())},getHKDF(t,e){let r=Tc(He,e,t),s=_c(He,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=vr.utils.randomSecretKey();return{publicKey:vr.getPublicKey(t),privateKey:t}},generateX25519KeyPairFromSeed(t){return{publicKey:vr.getPublicKey(t),privateKey:t}},generateX25519SharedKey(t,e){return vr.getSharedSecret(t.subarray(),e.subarray())},chaCha20Poly1305Encrypt(t,e,r,n){return Go(n,e,r).encrypt(t.subarray())},chaCha20Poly1305Decrypt(t,e,r,n,s){return Go(n,e,r).decrypt(t.subarray(),s)}};var Rc=Wn;function Cc(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 nr=t=>{let e=pe(2);return e[0]=t>>8,e[1]=t,e};nr.bytes=2;var sr=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)};sr.bytes=2;function Dc(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 Zo(t,e){!e.enabled||!tr||(t?(e(`LOCAL_STATIC_PUBLIC_KEY ${Z(t.publicKey,"hex")}`),e(`LOCAL_STATIC_PRIVATE_KEY ${Z(t.privateKey,"hex")}`)):e("Missing local static keys."))}function Xo(t,e){!e.enabled||!tr||(t?(e(`LOCAL_PUBLIC_EPHEMERAL_KEY ${Z(t.publicKey,"hex")}`),e(`LOCAL_PRIVATE_EPHEMERAL_KEY ${Z(t.privateKey,"hex")}`)):e("Missing local ephemeral keys."))}function Oc(t,e){!e.enabled||!tr||e(t?`REMOTE_STATIC_PUBLIC_KEY ${Z(t.subarray(),"hex")}`:"Missing remote static public key.")}function Jo(t,e){!e.enabled||!tr||e(t?`REMOTE_EPHEMERAL_PUBLIC_KEY ${Z(t.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function Qo(t,e,r){!r.enabled||!tr||(r(`CIPHER_STATE_1 ${t.n.getUint64()} ${t.k&&Z(t.k,"hex")}`),r(`CIPHER_STATE_2 ${e.n.getUint64()} ${e.k&&Z(e.k,"hex")}`))}var or=class t extends Error{code;constructor(e="Invalid crypto exchange"){super(e),this.code=t.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var ll=0,dl=4294967295,pl="Cipherstate has reached maximum n, a new handshake must be performed",Gn=class{n;bytes;view;constructor(e=ll){this.n=e,this.bytes=he(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>dl)throw new Error(pl)}};var Ot=he(0),ir=class{k;n;crypto;constructor(e,r=void 0,n=0){this.crypto=e,this.k=r,this.n=new Gn(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}},ei=class{cs;ck;h;crypto;constructor(e,r){this.crypto=e;let n=re(r,"utf-8");this.h=ml(e,n),this.ck=this.h,this.cs=new ir(e)}mixKey(e){let[r,n]=this.crypto.hkdf(this.ck,e);this.ck=r,this.cs=new ir(this.crypto,n)}mixHash(e){this.h=this.crypto.hash(new G(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,Ot);return[new ir(this.crypto,e),new ir(this.crypto,r)]}},ti=class{ss;s;e;rs;re;initiator;crypto;constructor(e){let{crypto:r,protocolName:n,prologue:s,initiator:o,s:i,e:a,rs:c,re:f}=e;this.crypto=r,this.ss=new ei(r,n),this.ss.mixHash(s),this.initiator=o,this.s=i,this.e=a,this.rs=c,this.re=f}writeE(){if(this.e)throw new Error("ephemeral keypair is already set");let e=this.crypto.generateKeypair();return this.ss.mixHash(e.publicKey),this.e=e,e.publicKey}writeS(){if(!this.s)throw new Error("static keypair is not set");return this.ss.encryptAndHash(this.s.publicKey)}writeEE(){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.re))}writeES(){if(this.initiator){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}else{if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}}writeSE(){if(this.initiator){if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}else{if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}}readE(e,r=0){if(this.re)throw new Error("remote ephemeral public key is already set");if(e.byteLength<r+32)throw new Error("message is not long enough");this.re=e.sublist(r,r+32),this.ss.mixHash(this.re)}readS(e,r=0){if(this.rs)throw new Error("remote static public key is already set");let n=32+(this.ss.cs.hasKey()?16:0);if(e.byteLength<r+n)throw new Error("message is not long enough");let s=e.sublist(r,r+n);return this.rs=this.ss.decryptAndHash(s),n}readEE(){this.writeEE()}readES(){this.writeES()}readSE(){this.writeSE()}},Fr=class extends ti{writeMessageA(e){return new G(this.writeE(),this.ss.encryptAndHash(e))}writeMessageB(e){let r=this.writeE();this.writeEE();let n=this.writeS();return this.writeES(),new G(r,n,this.ss.encryptAndHash(e))}writeMessageC(e){let r=this.writeS();return this.writeSE(),new G(r,this.ss.encryptAndHash(e))}readMessageA(e){try{return this.readE(e),this.ss.decryptAndHash(e.sublist(32))}catch(r){throw new or(`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 or(`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 or(`handshake stage 2 validation fail: ${r.message}`)}}};function ml(t,e){if(e.length<=32){let r=he(32);return r.set(e),r}else return t.hash(e)}var Hr;(function(t){let e;t.codec=()=>(e==null&&(e=Tt((o,i,a={})=>{if(a.lengthDelimited!==!1&&i.fork(),o.webtransportCerthashes!=null&&o.webtransportCerthashes.length>0)for(let c of o.webtransportCerthashes)i.uint32(10),i.bytes(c);if(o.streamMuxers!=null&&o.streamMuxers.length>0)for(let c of o.streamMuxers)i.uint32(18),i.string(c);a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={webtransportCerthashes:[],streamMuxers:[]},f=i==null?o.len:o.pos+i;for(;o.pos<f;){let u=o.uint32();switch(u>>>3){case 1:{if(a.limits?.webtransportCerthashes!=null&&c.webtransportCerthashes.length===a.limits.webtransportCerthashes)throw new _t('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 _t('Decode error - repeated field "streamMuxers" had too many elements');c.streamMuxers.push(o.string());break}default:{o.skipType(u&7);break}}}return c},function*(o,i,a,c={}){let f={webtransportCerthashes:0,streamMuxers:0},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let h=o.uint32();switch(h>>>3){case 1:{if(c.limits?.webtransportCerthashes!=null&&f.webtransportCerthashes===c.limits.webtransportCerthashes)throw new _t('Streaming decode error - repeated field "webtransportCerthashes" had too many elements');yield{field:`${a}.webtransportCerthashes[]`,index:f.webtransportCerthashes,value:o.bytes()},f.webtransportCerthashes++;break}case 2:{if(c.limits?.streamMuxers!=null&&f.streamMuxers===c.limits.streamMuxers)throw new _t('Streaming decode error - repeated field "streamMuxers" had too many elements');yield{field:`${a}.streamMuxers[]`,index:f.streamMuxers,value:o.string()},f.streamMuxers++;break}default:{o.skipType(h&7);break}}}})),e);function r(o){return Lt(o,t.codec())}t.encode=r;function n(o,i){return vt(o,t.codec(),i)}t.decode=n;function s(o,i){return It(o,t.codec(),i)}t.stream=s})(Hr||(Hr={}));var qr;(function(t){let e;t.codec=()=>(e==null&&(e=Tt((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),Hr.codec().encode(o.extensions,i)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={identityKey:he(0),identitySig:he(0)},f=i==null?o.len:o.pos+i;for(;o.pos<f;){let u=o.uint32();switch(u>>>3){case 1:{c.identityKey=o.bytes();break}case 2:{c.identitySig=o.bytes();break}case 4:{c.extensions=Hr.codec().decode(o,o.uint32(),{limits:a.limits?.extensions});break}default:{o.skipType(u&7);break}}}return c},function*(o,i,a,c={}){let f=i==null?o.len:o.pos+i;for(;o.pos<f;){let u=o.uint32();switch(u>>>3){case 1:{yield{field:`${a}.identityKey`,value:o.bytes()};break}case 2:{yield{field:`${a}.identitySig`,value:o.bytes()};break}case 4:{yield*Hr.codec().stream(o,o.uint32(),`${a}.extensions`,{limits:c.limits?.extensions});break}default:{o.skipType(u&7);break}}}})),e);function r(o){return Lt(o,t.codec())}t.encode=r;function n(o,i){return vt(o,t.codec(),i)}t.decode=n;function s(o,i){return It(o,t.codec(),i)}t.stream=s})(qr||(qr={}));async function ni(t,e,r){let n=await t.sign(Kc(e));return qr.encode({identityKey:nt(t.publicKey),identitySig:n,extensions:r})}async function si(t,e,r){try{let n=qr.decode(t),s=Dr(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=Kc(e);if(!await s.verify(o,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new zr(n.message)}}function Kc(t){let e=re("noise-libp2p-static-key:");return t instanceof Uint8Array?gt([e,t],e.length+t.length):(t.prepend(e),t)}var ri=class extends zn{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 Vn({lengthDecoder:sr,maxBufferSize:16*1024*1024,encodingLength:()=>2});let s=c=>{try{for(let f of this.decoder.decode(c.data))this.onData(this.decrypt(f))}catch(f){this.abort(f)}};this.stream.addEventListener("message",s);let o=c=>{c.error!=null?c.local===!0?this.abort(c.error):this.onRemoteReset():this.onTransportClosed()};this.stream.addEventListener("close",o);let i=()=>{this.safeDispatchEvent("drain")};this.stream.addEventListener("drain",i);let a=()=>{this.onRemoteCloseWrite()};this.stream.addEventListener("remoteCloseWrite",a)}encrypt(e){let r=new G;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(nr(o.byteLength)),r.append(o)}return r}decrypt(e){let r=new G;for(let n=0;n<e.byteLength;n+=65535){let s=n+65535;if(s>e.byteLength&&(s=e.byteLength),s-jo<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-jo);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 oi(t,e,r){return new ri(t,e,r)}async function Uc(t,e){let{log:r,connection:n,crypto:s,privateKey:o,prologue:i,s:a,remoteIdentityKey:c,extensions:f}=t,u=await ni(o,a.publicKey,f),h=new Fr({crypto:s,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:i,s:a});Zo(h.s,r),r.trace("Stage 0 - Initiator starting to send first message."),await n.write(h.writeMessageA(Ot),e),r.trace("Stage 0 - Initiator finished sending first message."),Xo(h.e,r),r.trace("Stage 1 - Initiator waiting to receive first message from responder...");let p=h.readMessageB(await n.read(e));r.trace("Stage 1 - Initiator received the message."),Jo(h.re,r),Oc(h.rs,r),r.trace("Initiator going to check remote's signature...");let d=await si(p,h.rs,c);r.trace("All good with the signature!"),r.trace("Stage 2 - Initiator sending third handshake message."),await n.write(h.writeMessageC(u),e),r.trace("Stage 2 - Initiator sent message with signed payload.");let[w,g]=h.ss.split();return Qo(w,g,r),{payload:d,encrypt:y=>w.encryptWithAd(Ot,y),decrypt:(y,x)=>g.decryptWithAd(Ot,y,x)}}async function Pc(t,e){let{log:r,connection:n,crypto:s,privateKey:o,prologue:i,s:a,remoteIdentityKey:c,extensions:f}=t,u=await ni(o,a.publicKey,f),h=new Fr({crypto:s,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:i,s:a});Zo(h.s,r),r.trace("Stage 0 - Responder waiting to receive first message."),h.readMessageA(await n.read(e)),r.trace("Stage 0 - Responder received first message."),Jo(h.re,r),r.trace("Stage 1 - Responder sending out first message with signed payload and static key."),await n.write(h.writeMessageB(u),e),r.trace("Stage 1 - Responder sent the second handshake message with signed payload."),Xo(h.e,r),r.trace("Stage 2 - Responder waiting for third handshake message...");let p=h.readMessageC(await n.read(e));r.trace("Stage 2 - Responder received the message, finished handshake.");let d=await si(p,h.rs,c),[w,g]=h.ss.split();return Qo(w,g,r),{payload:d,encrypt:y=>g.encryptWithAd(Ot,y),decrypt:(y,x)=>w.decryptWithAd(Ot,y,x)}}var Xn=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??Rc;this.crypto=Cc(c),this.extensions={webtransportCerthashes:[],...s},this.metrics=a?Dc(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=i??he(0)}[Symbol.toStringTag]="@libp2p/noise";[ai]=["@libp2p/connection-encryption","@libp2p/noise"];async secureOutbound(e,r){let n=e.log?.newScope("noise")??this.log,s=zo(e,{lengthEncoder:nr,lengthDecoder:sr,maxDataLength:65535}),o=await this.performHandshakeInitiator(s,this.components.privateKey,n,r?.remotePeer?.publicKey,r),i=Dr(o.payload.identityKey);return{connection:oi(s.unwrap(),o,this.metrics),remoteExtensions:o.payload.extensions,remotePeer:Uo(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 jr("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=zo(e,{lengthEncoder:nr,lengthDecoder:sr,maxDataLength:65535}),o=await this.performHandshakeResponder(s,this.components.privateKey,n,r?.remotePeer?.publicKey,r),i=Dr(o.payload.identityKey);return{connection:oi(s.unwrap(),o,this.metrics),remoteExtensions:o.payload.extensions,remotePeer:Uo(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 Uc({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 Pc({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 yl(t={}){return e=>new Xn(e,t)}return Vc(gl);})();
|
|
2
|
+
"use strict";var Libp2PNoise=(()=>{var Jn=Object.defineProperty;var Hc=Object.getOwnPropertyDescriptor;var qc=Object.getOwnPropertyNames;var zc=Object.prototype.hasOwnProperty;var Ae=(t,e)=>{for(var r in e)Jn(t,r,{get:e[r],enumerable:!0})},jc=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of qc(e))!zc.call(t,s)&&s!==r&&Jn(t,s,{get:()=>e[s],enumerable:!(n=Hc(e,s))||n.enumerable});return t};var Vc=t=>jc(Jn({},"__esModule",{value:!0}),t);var gl={};Ae(gl,{noise:()=>yl,pureJsCrypto:()=>Wn});var zr=class extends Error{static name="UnexpectedPeerError";constructor(e="Unexpected Peer"){super(e),this.name="UnexpectedPeerError"}},jr=class extends Error{static name="InvalidCryptoExchangeError";constructor(e="Invalid crypto exchange"){super(e),this.name="InvalidCryptoExchangeError"}},ie=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Kt=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var Vr=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var et=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},mt=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var Ut=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var $r=class extends Event{data;constructor(e,r){super("message",r),this.data=e}},Pt=class extends Event{error;local;constructor(e,r,n){super("close",n),this.error=r,this.local=e}},Yr=class extends Pt{constructor(e,r){super(!0,e,r)}},Wr=class extends Pt{constructor(e,r){super(!1,e,r)}};var Qn=Symbol.for("@libp2p/peer-id");function $c(t){return typeof t?.handleEvent=="function"}function Yc(t){return t===!0||t===!1}function Wc(t){return Yc(t)?t:t?.capture??!1}function es(t){let e={capture:Wc(t),once:!!t?.once};return t?.passive!=null&&(e.passive=t?.passive),t?.signal!=null&&(e.signal=t?.signal),e}function ii(t,e){return es(t).capture===es(e).capture}var Gr=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=es(n);if(s?.signal?.aborted===!0)return;let o=f=>{s.once&&this.removeEventListener(e,r,s),$c(r)?r.handleEvent(f):r(f)},i=this.#e.get(e);if(i==null&&(i=[],this.#e.set(e,i)),i.some(f=>f.callback!==r?!1:ii(f.options,s)))return;super.addEventListener(e,o,s);let c=()=>{this.removeEventListener(e,r,s)};s.signal?.addEventListener("abort",c),i.push({callback:r,wrapper:o,options:s,onAbort:c})}removeEventListener(e,r,n){let s=this.#e.get(e);if(s==null){super.removeEventListener(e,r??null,n);return}this.#e.set(e,s.filter(o=>o.callback===r&&ii(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 ai=Symbol.for("@libp2p/service-capabilities");var os={};Ae(os,{base58btc:()=>fe,base58flickr:()=>rf});var Wl=new Uint8Array(0);function fi(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 Te(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return yt(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return yt(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function ui(t){let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}var ci=4096;function hi(t){let e=t.length;if(e<=ci)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.subarray(n,n+=ci));return r}function Gc(t){return t?.buffer instanceof ArrayBuffer}function yt(t){return Gc(t)?t:t.slice()}function Zc(t,e,r){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),s=0;s<n.length;s++)n[s]=255;for(var o=0;o<t.length;o++){var i=t.charAt(o),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=o,r){var c=i.toLowerCase().charCodeAt(0),f=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=o),f!==a&&(n[f]=o)}}var u=t.length,h=t.charAt(0),p=Math.log(u)/Math.log(256),d=Math.log(256)/Math.log(u);function w(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,b=0,R=0,T=x.length;R!==T&&x[R]===0;)R++,E++;for(var O=(T-R)*d+1>>>0,N=new Uint8Array(O);R!==T;){for(var K=x[R],_=0,C=O-1;(K!==0||_<b)&&C!==-1;C--,_++)K+=256*N[C]>>>0,N[C]=K%u>>>0,K=K/u>>>0;if(K!==0)throw new Error("Non-zero carry");b=_,R++}for(var F=O-b;F!==O&&N[F]===0;)F++;for(var M=h.repeat(E);F<O;++F)M+=t.charAt(N[F]);return M}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 b=0,R=0;x[E]===h;)b++,E++;for(var T=(x.length-E)*p+1>>>0,O=new Uint8Array(T);x[E];){var N=n[x.charCodeAt(E)];if(N===255)return;for(var K=0,_=T-1;(N!==0||K<R)&&_!==-1;_--,K++)N+=u*O[_]>>>0,O[_]=N%256>>>0,N=N/256>>>0;if(N!==0)throw new Error("Non-zero carry");R=K,E++}if(x[E]!==" "){for(var C=T-R;C!==T&&O[C]===0;)C++;for(var F=new Uint8Array(b+(T-C)),M=b;C!==T;)F[M++]=O[C++];return F}}}function y(x){var E=g(x);if(E)return E;throw new Error(`Non-${e} character`)}return{encode:w,decodeUnsafe:g,decode:y}}var Xc=Zc,Jc=Xc,di=Jc;var ts=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")}},rs=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 pi(this,e)}},ns=class{decoders;constructor(e){this.decoders=e}or(e){return pi(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 pi(t,e){return new ns({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var ss=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 ts(e,r,n),this.decoder=new rs(e,r,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Nt({name:t,prefix:e,encode:r,decode:n}){return new ss(t,e,r,n)}function tt({name:t,prefix:e,alphabet:r,caseInsensitive:n=!1}){let{encode:s,decode:o}=di(r,t,n);return Nt({prefix:e,name:t,encode:s,decode:i=>Te(o(i))})}function Qc(t,e,r,n){let s=t.length;for(;t[s-1]==="=";)--s;let o=new Uint8Array(s*r/8|0),i=0,a=0,c=0;for(let f=0;f<s;++f){let u=e[t[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|u,i+=r,i>=8&&(i-=8,o[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return o}function ef(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 tf(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 ae({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:s=!1}){let o=tf(n,s);return Nt({prefix:e,name:t,encode(i){return ef(i,n,r)},decode(i){return Qc(i,o,r,t)}})}var fe=tt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),rf=tt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var is={};Ae(is,{base32:()=>Mt,base32hex:()=>af,base32hexpad:()=>ff,base32hexpadupper:()=>uf,base32hexupper:()=>cf,base32pad:()=>sf,base32padupper:()=>of,base32upper:()=>nf,base32z:()=>hf});var Mt=ae({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),nf=ae({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),sf=ae({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),of=ae({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),af=ae({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),cf=ae({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),ff=ae({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),uf=ae({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),hf=ae({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var as={};Ae(as,{base36:()=>cr,base36upper:()=>lf});var cr=tt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),lf=tt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var df=gi,mi=128,pf=127,mf=~pf,yf=Math.pow(2,31);function gi(t,e,r){e=e||[],r=r||0;for(var n=r;t>=yf;)e[r++]=t&255|mi,t/=128;for(;t&mf;)e[r++]=t&255|mi,t>>>=7;return e[r]=t|0,gi.bytes=r-n+1,e}var gf=cs,bf=128,yi=127;function cs(t,n){var r=0,n=n||0,s=0,o=n,i,a=t.length;do{if(o>=a)throw cs.bytes=0,new RangeError("Could not decode varint");i=t[o++],r+=s<28?(i&yi)<<s:(i&yi)*Math.pow(2,s),s+=7}while(i>=bf);return cs.bytes=o-n,r}var wf=Math.pow(2,7),xf=Math.pow(2,14),Ef=Math.pow(2,21),Sf=Math.pow(2,28),Af=Math.pow(2,35),vf=Math.pow(2,42),Bf=Math.pow(2,49),Lf=Math.pow(2,56),If=Math.pow(2,63),Tf=function(t){return t<wf?1:t<xf?2:t<Ef?3:t<Sf?4:t<Af?5:t<vf?6:t<Bf?7:t<Lf?8:t<If?9:10},_f={encode:df,decode:gf,encodingLength:Tf},Rf=_f,fr=Rf;function ur(t,e=0){let r=fr.decode(t,e),n=fr.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 Ft(t,e,r=0){return fr.encode(t,e,r),e}function Ht(t){return fr.encodingLength(t)}function Ne(t,e){let r=e.byteLength,n=Ht(t),s=n+Ht(r),o=new Uint8Array(s+r);return Ft(t,o,0),Ft(r,o,n),o.set(e,s),new qt(t,r,e,o)}function fs(t){let e=Te(t),[r,n]=ur(e),[s,o]=ur(e.subarray(n)),i=e.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new qt(r,s,i,e)}function bi(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&fi(t.bytes,r.bytes)}}var qt=class{code;size;digest;bytes;constructor(e,r,n,s){this.code=e,this.size=r,this.digest=yt(n),this.bytes=yt(s)}};function wi(t,e){let{bytes:r,version:n}=t;return n===0?Df(r,us(t),e??fe.encoder):Of(r,us(t),e??Mt.encoder)}var xi=new WeakMap;function us(t){let e=xi.get(t);if(e==null){let r=new Map;return xi.set(t,r),r}return e}var ye=class t{code;version;multihash;bytes;"/";constructor(e,r,n,s){this.code=r,this.version=e,this.multihash=n,this.bytes=yt(s),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==hr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==kf)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=Ne(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&&bi(e.multihash,n.multihash)}toString(e){return wi(this,e)}toJSON(){return{"/":wi(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??Ei(n,s,o.bytes))}else if(r[Kf]===!0){let{version:n,multihash:s,code:o}=r,i=fs(s);return t.create(n,o,i)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==hr)throw new Error(`Version 0 CID must use dag-pb (code: ${hr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let s=Ei(e,r,n.bytes);return new t(e,r,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,hr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,s=Te(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 qt(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[h,p]=ur(e.subarray(r));return r+=p,h},s=n(),o=hr;if(s===18?(s=0,r=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=r,a=n(),c=n(),f=r+c,u=f-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(e,r){let[n,s]=Cf(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 us(o).set(n,e),o}};function Cf(t,e){switch(t[0]){case"Q":{let r=e??fe;return[fe.prefix,r.decode(`${fe.prefix}${t}`)]}case fe.prefix:{let r=e??fe;return[fe.prefix,r.decode(t)]}case Mt.prefix:{let r=e??Mt;return[Mt.prefix,r.decode(t)]}case cr.prefix:{let r=e??cr;return[cr.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 Df(t,e,r){let{prefix:n}=r;if(n!==fe.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 Of(t,e,r){let{prefix:n}=r,s=e.get(n);if(s==null){let o=r.encode(t);return e.set(n,o),o}else return s}var hr=112,kf=18;function Ei(t,e,r){let n=Ht(t),s=n+Ht(e),o=new Uint8Array(s+r.byteLength);return Ft(t,o,0),Ft(e,o,n),o.set(r,s),o}var Kf=Symbol.for("@ipld/js-cid/CID");var hs={};Ae(hs,{identity:()=>Me});var Si=0,Uf="identity",Ai=Te;function Pf(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 Ne(Si,Ai(t))}var Me={code:Si,name:Uf,encode:Ai,digest:Pf};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 Nf(t){return t.buffer instanceof ArrayBuffer}function Le(t){return Nf(t)?t:t.slice()}async function vi(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,Le(e),Le(r.subarray()));return n?.signal?.throwIfAborted(),o}function he(t=0){return new Uint8Array(t)}function pe(t=0){return new Uint8Array(t)}function Mf(t){return t?.buffer instanceof ArrayBuffer}function ls(t){if(Mf(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function gt(t,e){e==null&&(e=t.reduce((s,o)=>s+o.length,0));let r=pe(e),n=0;for(let s of t)r.set(s,n),n+=s.length;return ls(r)}var Li=Symbol.for("@achingbrain/uint8arraylist");function Bi(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 Xr(t){return!!t?.[Li]}var G=class t{bufs;length;[Li]=!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(Xr(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(Xr(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=Bi(this.bufs,e);return r.buf[r.index]}set(e,r){let n=Bi(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(Xr(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 gt(n,s)}subarray(e,r){let{bufs:n,length:s}=this._subList(e,r);return n.length===1?n[0]:gt(n,s)}sublist(e,r){let{bufs:n,length:s}=this._subList(e,r),o=new t;return o.length=s,o.bufs=n,o}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],s=0;for(let o=0;o<this.bufs.length;o++){let i=this.bufs[o],a=s,c=a+i.byteLength;if(s=c,e>=c)continue;let f=e>=a&&e<c,u=r>a&&r<=c;if(f&&u){if(e===a&&r===c){n.push(i);break}let h=e-a;n.push(i.subarray(h,h+(r-e)));break}if(f){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(u){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!Xr(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 h=0;h<o;h++)i[h]=-1;for(let h=0;h<s;h++)i[n[h]]=h;let a=i,c=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let h=r;h<=c;h+=u){u=0;for(let p=f;p>=0;p--){let d=this.get(h+p);if(n[p]!==d){u=Math.max(1,p-a[d]);break}}if(u===0)return h}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=pe(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=he(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=he(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=he(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=pe(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=he(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=he(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=he(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=he(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=he(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 ds={};Ae(ds,{base10:()=>Ff});var Ff=tt({prefix:"9",name:"base10",alphabet:"0123456789"});var ps={};Ae(ps,{base16:()=>Hf,base16upper:()=>qf});var Hf=ae({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),qf=ae({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var ms={};Ae(ms,{base2:()=>zf});var zf=ae({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ys={};Ae(ys,{base256emoji:()=>Wf});var Ii=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),jf=Ii.reduce((t,e,r)=>(t[r]=e,t),[]),Vf=Ii.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function $f(t){return t.reduce((e,r)=>(e+=jf[r],e),"")}function Yf(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let s=Vf[n];if(s==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(s)}return new Uint8Array(e)}var Wf=Nt({prefix:"\u{1F680}",name:"base256emoji",encode:$f,decode:Yf});var gs={};Ae(gs,{base64:()=>Gf,base64pad:()=>Zf,base64url:()=>Xf,base64urlpad:()=>Jf});var Gf=ae({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Zf=ae({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Xf=ae({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Jf=ae({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var bs={};Ae(bs,{base8:()=>Qf});var Qf=ae({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ws={};Ae(ws,{identity:()=>eu});var eu=Nt({prefix:"\0",name:"identity",encode:t=>hi(Te(t)),decode:t=>Te(ui(t))});var Od=new TextEncoder,kd=new TextDecoder;var Ss={};Ae(Ss,{sha256:()=>Jr,sha512:()=>su});var nu=20;function Es({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:s}){return new xs(t,e,r,n,s)}var xs=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,s,o){this.name=e,this.code=r,this.encode=n,this.minDigestLength=s??nu,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?Ti(n,this.code,r?.truncate):n.then(s=>Ti(s,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ti(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 Ne(e,t)}function Ri(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Jr=Es({name:"sha2-256",code:18,encode:Ri("SHA-256")}),su=Es({name:"sha2-512",code:19,encode:Ri("SHA-512")});var As={...ws,...ms,...bs,...ds,...ps,...is,...as,...os,...gs,...ys},$d={...Ss,...hs};function Di(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Ci=Di("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),vs=Di("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=pe(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),ou={utf8:Ci,"utf-8":Ci,hex:As.base16,latin1:vs,ascii:vs,binary:vs,...As},Qr=ou;function re(t,e="utf8"){let r=Qr[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function Z(t,e="utf8"){let r=Qr[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var iu=parseInt("11111",2),Bs=parseInt("10000000",2),au=parseInt("01111111",2),Oi={0:lr,1:lr,2:cu,3:hu,4:lu,5:uu,6:fu,16:lr,22:lr,48:lr};function $e(t,e={offset:0}){let r=t[e.offset]&iu;if(e.offset++,Oi[r]!=null)return Oi[r](t,e);throw new Error("No decoder for tag "+r)}function dr(t,e){let r=0;if((t[e.offset]&Bs)===Bs){let n=t[e.offset]&au,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 lr(t,e){dr(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=$e(t,e);if(n===null)break;r.push(n)}return r}function cu(t,e){let r=dr(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 fu(t,e){let r=dr(t,e),n=e.offset+r,s=t[e.offset];e.offset++;let o=0,i=0;s<40?(o=0,i=s):s<80?(o=1,i=s-40):(o=2,i=s-80);let a=`${o}.${i}`,c=[];for(;e.offset<n;){let f=t[e.offset];if(e.offset++,c.push(f&127),f<128){c.reverse();let u=0;for(let h=0;h<c.length;h++)u+=c[h]<<h*7;a+=`.${u}`,c=[]}}return a}function uu(t,e){return e.offset++,null}function hu(t,e){let r=dr(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 lu(t,e){let r=dr(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function du(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new G;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function Ls(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=du(t.byteLength);return new G(Uint8Array.from([e.byteLength|Bs]),e)}function ve(t){let e=new G,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new G(Uint8Array.from([2]),Ls(e),e)}function en(t){let e=Uint8Array.from([0]),r=new G(e,t);return new G(Uint8Array.from([3]),Ls(r),r)}function rt(t,e=48){let r=new G;for(let n of t)r.append(n);return new G(Uint8Array.from([e]),Ls(r),r)}var pu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),mu=Uint8Array.from([6,5,43,129,4,0,34]),yu=Uint8Array.from([6,5,43,129,4,0,35]),gu={ext:!0,kty:"EC",crv:"P-256"},bu={ext:!0,kty:"EC",crv:"P-384"},wu={ext:!0,kty:"EC",crv:"P-521"},Is=32,Ts=48,_s=66;function ki(t){let e=$e(t);return Ki(e)}function Ki(t){let e=t[1][1][0],r=1,n,s;if(e.byteLength===Is*2+1)return n=Z(e.subarray(r,r+Is),"base64url"),s=Z(e.subarray(r+Is),"base64url"),new jt({...gu,key_ops:["verify"],x:n,y:s});if(e.byteLength===Ts*2+1)return n=Z(e.subarray(r,r+Ts),"base64url"),s=Z(e.subarray(r+Ts),"base64url"),new jt({...bu,key_ops:["verify"],x:n,y:s});if(e.byteLength===_s*2+1)return n=Z(e.subarray(r,r+_s),"base64url"),s=Z(e.subarray(r+_s),"base64url"),new jt({...wu,key_ops:["verify"],x:n,y:s});throw new ie(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Ui(t){return rt([ve(Uint8Array.from([1])),rt([xu(t.crv)],160),rt([en(new G(Uint8Array.from([4]),re(t.x??"","base64url"),re(t.y??"","base64url")))],161)]).subarray()}function xu(t){if(t==="P-256")return pu;if(t==="P-384")return mu;if(t==="P-521")return yu;throw new ie(`Invalid curve ${t}`)}var jt=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Ui(this.jwk)),this._raw}toMultihash(){return Me.digest(nt(this))}toCID(){return ye.createV1(114,this.toMultihash())}toString(){return fe.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 vi(this.jwk,r,e,n)}};var tn=BigInt(4294967295),Pi=BigInt(32);function Eu(t,e=!1){return e?{h:Number(t&tn),l:Number(t>>Pi&tn)}:{h:Number(t>>Pi&tn)|0,l:Number(t&tn)|0}}function Ni(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}=Eu(t[o],e);[n[o],s[o]]=[i,a]}return[n,s]}var Su=t=>t/2**32|0,Au=t=>t>>>0;function Mi(t,e,r,n){let s=Su(r),o=Au(r);t.setUint32(e,n?o:s,n),t.setUint32(e+4,n?s:o,n)}var Rs=(t,e,r)=>t>>>r,Cs=(t,e,r)=>t<<32-r|e>>>r,bt=(t,e,r)=>t>>>r|e<<32-r,wt=(t,e,r)=>t<<32-r|e>>>r,pr=(t,e,r)=>t<<64-r|e>>>r-32,mr=(t,e,r)=>t>>>r-32|e<<64-r;function Fe(t,e,r,n){let s=(e>>>0)+(n>>>0);return{h:t+r+(s/2**32|0)|0,l:s|0}}var Fi=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Hi=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,qi=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),zi=(t,e,r,n,s)=>e+r+n+s+(t/2**32|0)|0,ji=(t,e,r,n,s)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(s>>>0),Vi=(t,e,r,n,s,o)=>e+r+n+s+o+(t/2**32|0)|0;function rn(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var Ds=t=>t?`"${t}" `:"";function Oe(t,e=""){if(typeof t!="number")throw new TypeError(Ds(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(Ds(e)+"expected integer >= 0, got "+t);return t}function Ee(t,e,r=""){if(rn(t)&&(e===void 0||t.length===e))return t;e!==void 0&&Oe(e,"length");let n=rn(t),s=e!==void 0?` of length ${e}`:"",o=n?`length=${t.length}`:`type=${typeof t}`,i=Ds(r)+"expected Uint8Array"+s+", got "+o;throw n?new RangeError(i):new TypeError(i)}function xt(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(Oe(t.outputLen),Oe(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var Bu=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)},$i=(t,e)=>{Bu(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 Vt(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function nn(t,e){Ee(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function _e(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function sn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function ke(t,e){return t<<32-e|t>>>e}var Wi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Lu=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function on(t){if(Ee(t),Wi)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=Lu[t[r]];return e}function Yi(t){return t>=48&&t<=57?t-48:t>=65&&t<=70?t-55:t>=97&&t<=102?t-87:void 0}function an(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(Wi)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=Yi(t.charCodeAt(o)),a=Yi(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 Os(...t){let e=0;for(let n=0;n<t.length;n++){let s=t[n];Ee(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 Iu(t,e,r="opts"){return $i(t,"defaults"),e!==void 0&&$i(e,r),Object.assign(Object.create(null),t,e)}function ks(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=Iu({},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 Gi(t=32){Oe(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 Ks=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Zi(t,e,r){return t&e^~t&r}function Xi(t,e,r){return t&e^t&r^e&r}var yr=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=sn(this.buffer)}update(e){Vt(this),Ee(e);let{view:r,buffer:n,blockLen:s}=this,o=e.length,i=!1;for(let a=0;a<o;){let c=Math.min(s-this.pos,o-a);if(c===s){let f=sn(e);for(;s<=o-a;a+=s)this.process(f,a);i=!0;continue}n.set(a===0&&c===o?e:e.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===s&&(this.process(r,0),this.pos=0,i=!0)}return this.length+=e.length,i&&this.roundClean(),this}digestInto(e){Vt(this),nn(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)),Mi(n,s-8,this.length*8,o),this.process(n,0),this.roundClean();let a=e===r?n:sn(e),c=this.outputLen,f=c/4,u=this.get();if(c%4||f>u.length)throw new Error("invalid outputLen");for(let h=0;h<f;h++)a.setUint32(4*h,u[h],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()}},Ji=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Qi=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Tu=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]),st=new Uint32Array(64),Us=class extends yr{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 h=0;h<16;h++,r+=4)st[h]=e.getUint32(r,!1);for(let h=16;h<64;h++){let p=st[h-15],d=st[h-2],w=ke(p,7)^ke(p,18)^p>>>3,g=ke(d,17)^ke(d,19)^d>>>10;st[h]=g+st[h-7]+w+st[h-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:f,H:u}=this;for(let h=0;h<64;h++){let p=ke(a,6)^ke(a,11)^ke(a,25),d=u+p+Zi(a,c,f)+Tu[h]+st[h]|0,g=(ke(n,2)^ke(n,13)^ke(n,22))+Xi(n,s,o)|0;u=f,f=c,c=a,a=i+d|0,i=o,o=s,s=n,n=d+g|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,s,o,i,a,c,f,u)}roundClean(){_e(st)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),_e(this.buffer)}},Ps=class extends Us{constructor(){super(32,Ji)}};var ea=Ni(["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))),_u=ea[0],Ru=ea[1],ot=new Uint32Array(80),it=new Uint32Array(80),Ns=class extends yr{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(e,r){super(128,e,16,!1),this.Ah=r[0]|0,this.Al=r[1]|0,this.Bh=r[2]|0,this.Bl=r[3]|0,this.Ch=r[4]|0,this.Cl=r[5]|0,this.Dh=r[6]|0,this.Dl=r[7]|0,this.Eh=r[8]|0,this.El=r[9]|0,this.Fh=r[10]|0,this.Fl=r[11]|0,this.Gh=r[12]|0,this.Gl=r[13]|0,this.Hh=r[14]|0,this.Hl=r[15]|0}get(){let{Ah:e,Al:r,Bh:n,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:f,El:u,Fh:h,Fl:p,Gh:d,Gl:w,Hh:g,Hl:y}=this;return[e,r,n,s,o,i,a,c,f,u,h,p,d,w,g,y]}set(e,r,n,s,o,i,a,c,f,u,h,p,d,w,g,y){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=s|0,this.Ch=o|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=h|0,this.Fl=p|0,this.Gh=d|0,this.Gl=w|0,this.Hh=g|0,this.Hl=y|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let b=0;b<16;b++,r+=4)ot[b]=e.getUint32(r),it[b]=e.getUint32(r+=4);for(let b=16;b<80;b++){let R=ot[b-15]|0,T=it[b-15]|0,O=bt(R,T,1)^bt(R,T,8)^Rs(R,T,7),N=wt(R,T,1)^wt(R,T,8)^Cs(R,T,7),K=ot[b-2]|0,_=it[b-2]|0,C=bt(K,_,19)^pr(K,_,61)^Rs(K,_,6),F=wt(K,_,19)^mr(K,_,61)^Cs(K,_,6),M=qi(N,F,it[b-7],it[b-16]),j=zi(M,O,C,ot[b-7],ot[b-16]);ot[b]=j|0,it[b]=M|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:f,Dl:u,Eh:h,El:p,Fh:d,Fl:w,Gh:g,Gl:y,Hh:x,Hl:E}=this;for(let b=0;b<80;b++){let R=bt(h,p,14)^bt(h,p,18)^pr(h,p,41),T=wt(h,p,14)^wt(h,p,18)^mr(h,p,41),O=h&d^~h&g,N=p&w^~p&y,K=ji(E,T,N,Ru[b],it[b]),_=Vi(K,x,R,O,_u[b],ot[b]),C=K|0,F=bt(n,s,28)^pr(n,s,34)^pr(n,s,39),M=wt(n,s,28)^mr(n,s,34)^mr(n,s,39),j=n&o^n&a^o&a,B=s&i^s&c^i&c;x=g|0,E=y|0,g=d|0,y=w|0,d=h|0,w=p|0,{h,l:p}=Fe(f|0,u|0,_|0,C|0),f=a|0,u=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let k=Fi(C,M,B);n=Hi(k,_,F,j),s=k|0}({h:n,l:s}=Fe(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=Fe(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=Fe(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=Fe(this.Dh|0,this.Dl|0,f|0,u|0),{h,l:p}=Fe(this.Eh|0,this.El|0,h|0,p|0),{h:d,l:w}=Fe(this.Fh|0,this.Fl|0,d|0,w|0),{h:g,l:y}=Fe(this.Gh|0,this.Gl|0,g|0,y|0),{h:x,l:E}=Fe(this.Hh|0,this.Hl|0,x|0,E|0),this.set(n,s,o,i,a,c,f,u,h,p,d,w,g,y,x,E)}roundClean(){_e(ot,it)}destroy(){this.destroyed=!0,_e(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Ms=class extends Ns{constructor(){super(64,Qi)}};var He=ks(()=>new Ps,Ks(1));var Fs=ks(()=>new Ms,Ks(3));function fn(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 Y=(t,e,r)=>Ee(t,e,r),Hs=Oe;function ra(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 Et(t,e){if(typeof t!="function")throw new TypeError(`"${e}" is invalid: expected function, got ${typeof t}`);return t}var gr=on,Re=(...t)=>Os(...t),$t=t=>an(t),ft=rn,Ye=t=>Gi(t),cn=BigInt(0),ta=BigInt(1),Cu=t=>t?`"${t}" `:"";function Be(t,e=""){if(typeof t!="boolean")throw new TypeError(Cu(e)+"expected boolean, got type="+typeof t);return t}function un(t){if(typeof t=="bigint"){if(!ct(t))throw new RangeError("positive bigint expected, got "+t)}else Hs(t);return t}function We(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 br(t){let e=un(t).toString(16);return e.length&1?"0"+e:e}function na(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?cn:BigInt("0x"+t)}function qe(t){return na(on(t))}function ze(t){return na(on(ut(Ee(t)).reverse()))}function hn(t,e){if(Oe(e),e===0)throw new Error("zero output length is invalid");t=un(t);let r=e*2,n=t.toString(16);if(n.length>r)throw new RangeError("number is too large");return an(n.padStart(r,"0"))}function wr(t,e){return hn(t,e).reverse()}function ut(t){return Uint8Array.from(Y(t))}function ct(t){return typeof t=="bigint"&&cn<=t}function qs(t,e,r){return ct(t)&&ct(e)&&ct(r)&&e<=t&&t<r}function je(t,e,r,n){if(!qs(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Yt(t){if(t<cn)throw new Error("expected non-negative bigint, got "+t);return t===cn?0:t.toString(2).length}var xr=t=>(We(t,"n"),(ta<<BigInt(t))-ta);function sa(t,e,r){if(Oe(t,"hashLen"),Oe(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=y=>new Uint8Array(y),s=Uint8Array.of(),o=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(t),f=n(t),u=0,h=()=>{c.fill(1),f.fill(0),u=0},p=(...y)=>r(f,Re(c,...y)),d=(y=s)=>{f=p(o,y),c=p(),y.length!==0&&(f=p(i,y),c=p())},w=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let y=0,x=[];for(;y<e;){c=p();let E=c.slice();x.push(E),y+=c.length}return Re(...x)};return(y,x)=>{h(),d(y);let E;for(;(E=x(w()))===void 0;)d();return h(),E}}function ge(t,e={},r={},n="object"){at(t,n),at(e,"fields"),at(r,"optFields");function s(i,a,c){let f=n==="object"?`param "${String(i)}"`:`"${n}.${String(i)}"`,u=t[i];if(!Object.hasOwn(t,i)&&(c?u!==void 0:a!=="function"))throw new TypeError(`${f} is invalid: expected own property`);if(c&&u===void 0)return;let h=typeof u;if(h!==a||u===null)throw new TypeError(`${f} is invalid: expected ${a}, got ${h}`)}let o=(i,a)=>Object.entries(i).forEach(([c,f])=>s(c,f,a));o(e,!1),o(r,!0)}var de=BigInt(0),X=BigInt(1),ht=BigInt(2),aa=BigInt(3),zs=BigInt(4),ca=BigInt(5),Du=BigInt(7),fa=BigInt(8),Ou=BigInt(9),ku=BigInt(15),ua=BigInt(16),Ku=BigInt("0x10000000000000000");function Q(t,e){if(e<=de)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=de?r:e+r}function ha(t,e,r){if(r<=X)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<de)throw new Error("invalid exponent, negatives unsupported");if(e===de)return X;if(e===X)return t;let n=t%r;if(n<de&&(n+=r),e<Ku){let a=X;for(;e>de;)e&X&&(a=a*n%r),n=n*n%r,e>>=X;return a}let s=[];for(;e>de;)s.push(Number(e&ku)),e>>=zs;let o=new Array(16);o[0]=X,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 se(t,e,r){if(r<=X)throw new Error("pow2: expected modulus > 1, got "+r);if(e<de)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >de;)n*=n,n%=r;return n}function oa(t,e){if(t===de)throw new Error("invert: expected non-zero number");if(e<=X)throw new Error("invert: expected modulus > 1, got "+e);let r=Q(t,e),n=e,s=de,o=X;for(;r!==de;){let a=n/r,c=n-r*a,f=s-o*a;n=r,r=c,s=o,o=f}if(n!==X)throw new Error("invert: does not exist");return Q(s,e)}function la(t,e){if(e<=X)throw new Error("invertCt: expected prime modulus > 1, got "+e);let r=Q(t,e);if(r===de)throw new Error("invertCt: expected non-zero number");let n=ha(r,e-ht,e);if(Q(r*n,e)!==X)throw new Error("invertCt: does not exist");return n}function js(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function Vs(t,e){if((t&X)===de)throw new Error(e+": expected odd modulus, got "+t)}function da(t,e){let r=t,n=(r.ORDER+X)/zs,s=r.pow(e,n);return js(r,s,e),s}function Uu(t,e){let r=t,n=(r.ORDER-ca)/fa,s=r.mul(e,ht),o=r.pow(s,n),i=r.mul(e,o),a=r.mul(r.mul(i,ht),o),c=r.mul(i,r.sub(a,r.ONE));return js(r,c,e),c}function Pu(t){let e=Gt(t),r=pa(t),n=r(e,e.neg(e.ONE)),s=r(e,n),o=r(e,e.neg(n)),i=(t+Du)/ua;return((a,c)=>{let f=a,u=f.pow(c,i),h=f.mul(u,n),p=f.mul(u,s),d=f.mul(u,o),w=f.eql(f.sqr(h),c),g=f.eql(f.sqr(p),c);u=f.cmov(u,h,w),h=f.cmov(d,p,g);let y=f.eql(f.sqr(h),c),x=f.cmov(u,h,y);return js(f,x,c),x})}function pa(t){if(t<aa)throw new Error("sqrt is not defined for small field");Vs(t,"tonelliShanks");let e=t-X,r=0;for(;e%ht===de;)e/=ht,r++;let n=ht,s=Gt(t);for(;Er(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return da;let o=s.pow(n,e),i=(e+X)/ht;return function(c,f){let u=c;if(u.is0(f))return f;if(Er(u,f)!==1)throw new Error("Cannot find square root");let h=r,p=u.mul(u.ONE,o),d=u.pow(f,e),w=u.pow(f,i);for(;!u.eql(d,u.ONE);){if(u.is0(d))throw new Error("Cannot find square root: probably non-prime P");let g=1,y=u.sqr(d);for(;!u.eql(y,u.ONE);)if(g++,y=u.sqr(y),g===h)throw new Error("Cannot find square root");let x=X<<BigInt(h-g-1),E=u.pow(p,x);h=g,p=u.sqr(E),d=u.mul(d,p),w=u.mul(w,E)}return w}}function Nu(t){return Vs(t,"Fp.sqrt"),t%zs===aa?da:t%fa===ca?Uu:t%ua===Ou?Pu(t):pa(t)}var ma=(t,e)=>(Q(t,e)&X)===X,Mu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Wt(t){if(at(t,"field"),typeof t.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof t.ORDER);We(t.BYTES,"BYTES"),We(t.BITS,"BITS");for(let e of Mu)Et(t[e],"field."+e);if(t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=X)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function dn(t,e,r=!1){Wt(t),fn(e,"nums"),Be(r,"passZero");let n=t,s=new Array(e.length).fill(r?n.ZERO:void 0),o=e.reduce((a,c,f)=>n.is0(c)?a:(s[f]=a,n.mul(a,c)),n.ONE),i=n.inv(o);return e.reduceRight((a,c,f)=>n.is0(c)?a:(s[f]=n.mul(a,s[f]),n.mul(a,c)),i),s}function Er(t,e){Wt(t);let r=t;Vs(r.ORDER,"FpLegendre");let n=(r.ORDER-X)/ht,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 Fu(t,e){if(e!==void 0&&Hs(e),t<=de)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=Yt(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 ia=new WeakMap,ln=class{ORDER;BITS;BYTES;isLE;ZERO=de;ONE=X;_lengths;_mod;constructor(e,r={}){if(e<=X)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}=Fu(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 Q(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return de<=e&&e<this.ORDER}is0(e){return e===de}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&X)===X}neg(e){return Q(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return Q(e*e,this.ORDER)}add(e,r){return Q(e+r,this.ORDER)}sub(e,r){return Q(e-r,this.ORDER)}mul(e,r){return Q(e*r,this.ORDER)}pow(e,r){return ha(e,r,this.ORDER)}div(e,r){return Q(e*oa(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 oa(e,this.ORDER)}sqrt(e){let r=ia.get(this);return r||ia.set(this,r=Nu(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?wr(e,this.BYTES):hn(e,this.BYTES)}fromBytes(e,r=!1){Y(e);let{_lengths:n,BYTES:s,isLE:o,ORDER:i,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>s)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let f=new Uint8Array(s);f.set(e,o?0:f.length-e.length),e=f}if(e.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+e.length);let c=o?ze(e):qe(e);if(a&&(c=Q(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return dn(this,e,!0)}cmov(e,r,n){return Be(n,"condition"),n?r:e}};function Gt(t,e={}){return Object.freeze(ln.prototype),new ln(t,e)}function ya(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=X)throw new Error("field order must be greater than 1");let e=Yt(t-X);return Math.ceil(e/8)}function pn(t){let e=ya(t);return e+Math.ceil(e/2)}function mn(t,e,r=!1){Y(t);let n=t.length,s=ya(e),o=Math.max(pn(e),16);if(n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);let i=r?ze(t):qe(t),a=Q(i,e-X)+X;return r?wr(a,s):hn(a,s)}var Ws=BigInt(0),Sr=BigInt(1),Hu=BigInt(4),$s=16,ga=128,qu=5,ba=2**31;function lt(t){let e=t;if(typeof e!="function")throw new TypeError('"Point" expected constructor, got type='+typeof t);Et(e.fromAffine,"Point.fromAffine"),Et(e.fromBytes,"Point.fromBytes"),Et(e.fromHex,"Point.fromHex"),at(e.BASE,"Point.BASE"),at(e.ZERO,"Point.ZERO"),Wt(e.Fp),Wt(e.Fn)}function yn(t,e){lt(t),xa(e,t);let r=dn(t.Fp,e.map(n=>n.Z));return e.map((n,s)=>t.fromAffine(n.toAffine(r[s])))}function zu(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 ju(t,e){let r=t*(4*e+128);if(r>ba)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+ba/2**20+" MiB")}function Gs(t,e){if(t!==void 0){Et(t,"randomBytes");try{let r=t(e);if(!ft(r)||r.length!==e)return}catch{return}return t}}function xa(t,e){fn(t,"points"),t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function Vu(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):ct(n)&&n<r))throw new Error("invalid scalar at index "+s)})}var Ea=new WeakMap;function Ys(t){return Ea.get(t)||1}function $u(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 Yu(t,e){let r=2**e,n=r/2,s=BigInt(r-1),o=[];for(;t>Ws;){let i=0;t&Sr&&(i=Number(t&s),i>=n&&(i-=r),t-=BigInt(i)),o.push(i),t>>=Sr}return o}function Wu(t,e,r){let n=2**e,s=n/2,o=BigInt(n-1),i=BigInt(e),a=[];for(let c=0;c<r;c++){let f=Number(t&o);t>>=i,f>s&&(f-=n,t+=Sr),a.push(f)}if(t!==Ws)throw new Error("invalid wnaf");return a}function Gu(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 Zt=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(e,r){lt(e),this.randomBytes=Gs(r,$s),this.Point=e,this.BASE=e.BASE,this.ZERO=e.ZERO,this.bits=e.Fn.BITS}buildWnafTable(e,r,n){let s=Math.ceil(n/r)+1,o=2**(r-1),i=[],a=e;for(let c=0;c<s;c++){let f=a;for(let u=0;u<o;u++)i.push(f),f=f.add(a);a=i[i.length-1].double()}return{W:r,bits:n,windows:s,comp:i}}wnafCachedCT(e,r){let{W:n,windows:s,comp:o}=e,i=2**(n-1),a=Wu(r,n,s),c=this.ZERO,f=this.BASE;for(let u=0;u<s;u++){let h=a[u],p=u*i,d=Math.abs(h)-1,w=o[p];for(let y=1;y<i;y++)w=y===d?o[p+y]:w;let g=w.negate();h===0?f=f.add(o[p]):c=c.add(h<0?g:w)}return{p:c,f}}getWnafPrecomputes(e,r,n,s){let o=this.wnafPrecomputes.get(r),i=o?.find(a=>a.W===e&&a.bits===n);return i||(i=this.buildWnafTable(r,e,n),typeof s=="function"&&(i={...i,comp:s(i.comp)}),o||(o=[],this.wnafPrecomputes.set(r,o)),o.push(i)),i}assertPoint(e){if(!(e instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof e)}validateMulInput(e,r){if(this.assertPoint(e),!qs(r,Sr,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(e,r,n,s){let o=Ys(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+ga,o=this.randomBytes($s);if(!ft(o)||o.length!==$s)throw new Error("randomBytes returned invalid byte array");o[0]=o[0]&63|128;let i=r+qe(o)*this.Point.Fn.ORDER;return this.runCT(e,i,s,n)}fixedWindowCT(e,r,n){let s=qu,o=1<<s,i=xr(s),a=new Array(o);a[0]=this.ZERO;for(let u=1;u<o;u++)a[u]=a[u-1].add(e);let c=Math.ceil(n/s),f=this.ZERO;for(let u=c-1;u>=0;u--){if(u!==c-1)for(let d=0;d<s;d++)f=f.double();let h=Number(r>>BigInt(u*s)&i),p=a[0];for(let d=1;d<o;d++)p=d===h?a[d]:p;f=f.add(p)}return{p:f,f}}shouldBlind(e,r){return this.randomBytes===void 0?!1:r===Sr?!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),!ct(r))throw new Error("invalid scalar");let s=Ys(e);if(s===1||r>=this.Point.Fn.ORDER)return gn(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),zu(r,this.bits);let n=Math.ceil((this.bits+ga)/r)+1;ju(n*2**(r-1),this.Point.Fp.BYTES),Ea.set(e,r),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return Ys(e)!==1}};function gn(t,e,r,n=!1){if(lt(t),xa(e,t),Be(n,"allowOversized"),Vu(r,t.Fn,n?t.Fn.ORDER**Hu:void 0),e.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let s=e.map(i=>$u(i,4)),o=r.map(i=>Yu(i,4));return Gu(t.ZERO,s,o)}function wa(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Wt(e),e}else return Gt(t,{isLE:r})}function bn(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`);ge(r);for(let c of["p","n","h"]){let f=e[c];if(!(ct(f)&&f!==Ws))throw new Error(`CURVE.${c} must be positive bigint`)}let s=wa(e.p,r.Fp,n),o=wa(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 Xt(t,e){return function(n){let s=t(n);return{secretKey:s,publicKey:e(s)}}}var wn=BigInt(0),xn=BigInt(1),En=BigInt(2),Zu=BigInt(4),Sa=BigInt(8);function Xu(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 Aa(t,e={}){ge(e,{},{},"extraOpts");let r=e,n=bn("edwards",t,r,r.FpFnLE),{Fp:s,Fn:o}=n,i=n.CURVE,{h:a}=i;if(Er(s,i.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(Er(s,i.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");ge(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?Ye:r.randomBytes,f=En<<BigInt(s.BYTES*8)-xn;function u(E){if(!s.isOdd)throw new Error("Field does not have .isOdd()");return s.isOdd(E)}let h=r.uvRatio===void 0?(E,b)=>{try{return{isValid:!0,value:s.sqrt(s.div(E,b))}}catch{return{isValid:!1,value:wn}}}:r.uvRatio;if(!Xu(s,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");let p=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 d(E,b,R=!1){let T=R?xn:wn;return je("coordinate "+E,b,T,f),b}function w(E){if(!(E instanceof g))throw new Error("EdwardsPoint expected")}class g{static BASE=new g(i.Gx,i.Gy,s.ONE,s.mul(i.Gx,i.Gy));static ZERO=new g(s.ZERO,s.ONE,s.ONE,s.ZERO);static Fp=s;static Fn=o;X;Y;Z;T;constructor(b,R,T,O){this.X=d("x",b),this.Y=d("y",R),this.Z=d("z",T,!0),this.T=d("t",O),Object.freeze(this)}static CURVE(){return i}static fromAffine(b){if(b instanceof g)throw new Error("extended point not allowed");let{x:R,y:T}=b||{};return d("x",R),d("y",T),new g(R,T,s.ONE,s.mul(R,T))}static fromBytes(b,R=!1){let T=s.BYTES,{a:O,d:N}=i;b=ut(Y(b,T,"point")),Be(R,"zip215");let K=ut(b),_=b[T-1];K[T-1]=_&-129;let C=ze(K),F=R?f:s.ORDER;je("point.y",C,wn,F);let M=s.sqr(C),j=s.sub(M,s.ONE),B=s.sub(s.mulN(N,M),O),{isValid:k,value:L}=h(j,B);if(!k)throw new Error("bad point: invalid y coordinate");let v=u(L),H=(_&128)!==0;if(!R&&s.is0(L)&&H)throw new Error("bad point: x=0 and x_0=1");return H!==v&&(L=s.neg(L)),g.fromAffine({x:L,y:C})}static fromHex(b,R=!1){return g.fromBytes($t(b),R)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=6,R=!0){return x.setWindowSize(this,b),R||this.multiply(En),this}assertValidity(){let b=this,{a:R,d:T}=i;if(b.is0())throw new Error("bad point: ZERO");let{X:O,Y:N,Z:K,T:_}=b,C=s.sqr(O),F=s.sqr(N),M=s.sqr(K),j=s.sqr(M),B=s.mul(C,R),k=s.mul(s.add(B,F),M),L=s.add(j,s.mul(T,s.mul(C,F)));if(!s.eql(k,L))throw new Error("bad point: equation left != right (1)");let v=s.mul(O,N),H=s.mul(K,_);if(!s.eql(v,H))throw new Error("bad point: equation left != right (2)")}equals(b){w(b);let{X:R,Y:T,Z:O}=this,{X:N,Y:K,Z:_}=b,C=s.mul(R,_),F=s.mul(N,O),M=s.mul(T,_),j=s.mul(K,O);return s.eql(C,F)&&s.eql(M,j)}is0(){return this.equals(g.ZERO)}negate(){return new g(s.neg(this.X),this.Y,this.Z,s.neg(this.T))}double(){let{X:b,Y:R,Z:T}=this,O=s.sqr(b),N=s.sqr(R),K=s.mul(s.sqr(T),En),_=p(O),C=s.addN(b,R),F=s.sub(s.subN(s.sqr(C),O),N),M=s.addN(_,N),j=s.subN(M,K),B=s.subN(_,N),k=s.mul(F,j),L=s.mul(M,B),v=s.mul(F,B),H=s.mul(j,M);return new g(k,L,H,v)}add(b){w(b);let{d:R}=i,{X:T,Y:O,Z:N,T:K}=this,{X:_,Y:C,Z:F,T:M}=b,j=s.mul(T,_),B=s.mul(O,C),k=s.mul(s.mulN(K,R),M),L=s.mul(N,F),v=s.sub(s.subN(s.mulN(s.addN(T,O),s.addN(_,C)),j),B),H=s.subN(L,k),I=s.addN(L,k),S=s.sub(B,p(j)),l=s.mul(v,H),m=s.mul(I,S),A=s.mul(v,S),D=s.mul(H,I);return new g(l,m,D,A)}subtract(b){return w(b),this.add(b.negate())}multiply(b){if(!o.isValidNot0(b))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:R,f:T}=x.mulSecret(this,b,a,y);return y([R,T])[0]}multiplyUnsafe(b){if(!o.isValid(b))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return b===wn?g.ZERO:this.is0()||b===xn?this:x.mulUnsafe(this,b,y)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return x.mulUnsafe(this,i.n).is0()}toAffine(b){let R=this,T=b;if(T!=null&&typeof T!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof T);let{X:O,Y:N,Z:K}=R,_=R.is0();T==null&&(T=_?s.create(Sa):s.inv(K));let C=s.mul(O,T),F=s.mul(N,T),M=s.mul(K,T);if(_)return{x:s.ZERO,y:s.ONE};if(!s.eql(M,s.ONE))throw new Error("invZ was invalid");return{x:C,y:F}}clearCofactor(){return a===xn?this:a===En?this.double():a===Zu?this.double().double():a===Sa?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:b,y:R}=this.toAffine(),T=s.toBytes(R);return T[T.length-1]|=u(b)?128:0,T}toHex(){return gr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let y=E=>yn(g,E),x=new Zt(g,c);return x.bits>=6&&g.BASE.precompute(6),Object.freeze(g.prototype),Object.freeze(g),g}function va(t,e,r={}){if(lt(t),typeof e!="function")throw new Error('"hash" function param is required');let n=e,s=r;ge(s,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:o}=s,{BASE:i,Fp:a,Fn:c}=t,f=n.outputLen,u=2*a.BYTES;if(f!==void 0&&(We(f,"hash.outputLen"),f!==u))throw new Error(`hash.outputLen must be ${u}, got ${f}`);let h=s.randomBytes===void 0?Ye:s.randomBytes,p=s.toMontgomery,d=s.toMontgomerySecret,w=s.adjustScalarBytes===void 0?B=>B:s.adjustScalarBytes,g=s.domain===void 0?(B,k,L)=>{if(Be(L,"phflag"),k.length||L)throw new Error("Contexts/pre-hash are not supported");return B}:s.domain;function y(B){return c.create(ze(B))}function x(B){let k=_.secretKey;Y(B,_.secretKey,"secretKey");let L=Y(n(B),2*k,"hashedSecretKey"),v=w(L.slice(0,k)),H=L.slice(k,2*k),I=y(v);return{head:v,prefix:H,scalar:I}}function E(B){let{head:k,prefix:L,scalar:v}=x(B),H=i.multiply(v),I=H.toBytes();return{head:k,prefix:L,scalar:v,point:H,pointBytes:I}}function b(B){return E(B).pointBytes}function R(B=Uint8Array.of(),...k){let L=Re(...k);return y(n(g(L,Y(B,void 0,"context"),!!o)))}function T(B,k,L={}){ge(L,{},{},"options"),B=ut(Y(B,void 0,"message")),o&&(B=o(B));let{prefix:v,scalar:H,pointBytes:I}=E(k),S=R(L.context,v,B),l=i.multiply(S).toBytes(),m=R(L.context,l,I,B),A=c.create(S+m*H);if(!c.isValid(A))throw new Error("sign failed: invalid s");let D=Re(l,c.toBytes(A));return Y(D,_.signature,"result")}let O={zip215:s.zip215};function N(B,k,L,v=O){ge(v);let{context:H}=v,I=v.zip215===void 0?!!O.zip215:v.zip215,S=_.signature;B=Y(B,S,"signature"),k=Y(k,void 0,"message"),L=Y(L,_.publicKey,"publicKey"),I!==void 0&&Be(I,"zip215"),o&&(k=o(k));let l=S/2,m=B.subarray(0,l),A=ze(B.subarray(l,S)),D,U,P;try{D=t.fromBytes(L,I),U=t.fromBytes(m,I),P=i.multiplyUnsafe(A)}catch{return!1}if(!I&&D.isSmallOrder())return!1;let q=R(H,m,L,k);return U.add(D.multiplyUnsafe(q)).subtract(P).clearCofactor().is0()}let K=a.BYTES,_={secretKey:K,publicKey:K,signature:2*K,seed:K};function C(B){return B=B===void 0?h(_.seed):B,Y(B,_.seed,"seed")}function F(B){return ft(B)&&B.length===_.secretKey}function M(B,k){try{return!!t.fromBytes(B,k===void 0?O.zip215:k)}catch{return!1}}let j={getExtendedPublicKey:E,randomSecretKey:C,isValidSecretKey:F,isValidPublicKey:M,toMontgomery(B){if(p===void 0)throw new Error("Montgomery conversion is not supported for this curve");return p(t.fromBytes(B))},toMontgomerySecret(B){if(d===void 0)throw new Error("Montgomery conversion is not supported for this curve");return d(B)}};return Object.freeze(_),Object.freeze(j),Object.freeze({keygen:Xt(C,b),getPublicKey:b,sign:T,verify:N,utils:j,Point:t,lengths:_})}var St=BigInt(0),Ce=BigInt(1),Sn=BigInt(2);function Ba(t,e){return t+e-(e>>Ce<<Ce)}function Ju(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 Qu(t){return ge(t,{P:"bigint",type:"string",adjustScalarBytes:"function",powPminus2:"function"},{randomBytes:"function",scalarMultBase:"function"}),Object.freeze({...t})}function La(t){let e=Qu(t),{P:r,type:n,adjustScalarBytes:s,powPminus2:o,randomBytes:i}=e,a=e.scalarMultBase,c=n==="x25519";if(!c&&n!=="x448")throw new Error("invalid type");let f=i===void 0?Ye:i,u=c?255:448,h=Ju(r),p=c?32:56,d=BigInt(c?9:5),w=BigInt(c?121665:39081),g=c?Sn**BigInt(254):Sn**BigInt(447),y=c?BigInt(8)*(Sn**BigInt(251)-Ce):BigInt(4)*(Sn**BigInt(445)-Ce),x=g+y+Ce,E=L=>Q(L,r),b=R(d);function R(L){return wr(E(L),p)}function T(L){let v=ut(Y(L,p,"uCoordinate"));return c&&(v[31]&=127),E(ze(v))}function O(L){return ze(s(ut(Y(L,p,"scalar"))))}let N=new Set(c?[St,Ce,r-Ce,BigInt("325606250916557431795983626356110631294008115727848805560023387167927233504"),BigInt("39382357235489614581723060781553021112529911719440698176882885853963445705823")]:[St,Ce,r-Ce]);function K(L,v){let H=T(v);if(N.has(H))throw new Error("invalid private or public key received");let I=M(H,O(L));if(I===St)throw new Error("invalid private or public key received");return R(I)}function _(L){if(a===void 0)return K(L,b);let v=O(L);je("scalar",v,g,x);let H=E(a(v));if(H===St)throw new Error("invalid private or public key received");return R(H)}let C=_,F=K;function M(L,v){je("u",L,St,r),je("scalar",v,g,x);let H=v,I=L,S=Ce,l=St,m=L,A=Ce,D=H^H>>Ce;for(let q=BigInt(u-1);q>=St;q--){let z=Ba(r,D>>q);({x_2:S,x_3:m}=h(z,S,m)),{x_2:l,x_3:A}=h(z,l,A);let V=S+l,$=E(V*V),ne=S-l,ee=E(ne*ne),ce=$-ee,Se=m+A,te=m-A,oe=E(te*V),kt=E(Se*ne),ar=oe+kt,Qe=oe-kt;m=E(ar*ar),A=E(I*E(Qe*Qe)),S=E($*ee),l=E(ce*($+E(w*ce)))}let U=Ba(r,H);({x_2:S,x_3:m}=h(U,S,m)),{x_2:l,x_3:A}=h(U,l,A);let P=o(l);return E(S*P)}let j={secretKey:p,publicKey:p,seed:p},B=L=>(L=L===void 0?f(p):L,Y(L,j.seed,"seed"),L),k={randomSecretKey:B};return Object.freeze(j),Object.freeze(k),Object.freeze({keygen:Xt(B,C),getSharedSecret:F,getPublicKey:C,scalarMult:K,scalarMultBase:_,utils:k,GuBytes:b.slice(),lengths:j})}var Ia=BigInt(0),Zs=BigInt(1),Ta=BigInt(2),eh=BigInt(3),th=BigInt(5),rh=BigInt(8),An=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),nh={p:An,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:rh,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Ca(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),s=BigInt(80),o=An,a=t*t%o*t%o,c=se(a,Ta,o)*a%o,f=se(c,Zs,o)*t%o,u=se(f,th,o)*f%o,h=se(u,e,o)*u%o,p=se(h,r,o)*h%o,d=se(p,n,o)*p%o,w=se(d,s,o)*d%o,g=se(w,s,o)*d%o,y=se(g,e,o)*u%o;return{pow_p_5_8:se(y,Ta,o)*t%o,b2:a}}function Xs(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var _a=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function sh(t,e){let r=An,n=Q(e*e*e,r),s=Q(n*n*e,r),o=Ca(t*s).pow_p_5_8,i=Q(t*n*o,r),a=Q(e*i*i,r),c=i,f=Q(i*_a,r),u=a===t,h=a===Q(-t,r),p=a===Q(-t*_a,r);return u&&(i=c),(h||p)&&(i=f),ma(i,r)&&(i=Q(-i,r)),{isValid:u||h,value:i}}var Ar=Aa(nh,{uvRatio:sh}),Ra=Ar.Fp;function oh(t){let{y:e}=t;return Ra.toBytes(Ra.div(Zs+e,Zs-e))}function ih(t){let e=Ar.Fp.BYTES;return Ee(t,e),Xs(Fs(t.subarray(0,e))).subarray(0,e)}function ah(t){return va(Ar,Fs,Object.assign({adjustScalarBytes:Xs,toMontgomery:oh,toMontgomerySecret:ih,zip215:!0},t))}var Da=ah({});var vr=(()=>{let t=An,e=r=>{let{pow_p_5_8:n,b2:s}=Ca(r);return Q(se(n,eh,t)*s,t)};return La({P:t,type:"x25519",powPminus2:e,adjustScalarBytes:Xs,scalarMultBase:r=>{let n=Q(r,Ar.Fn.ORDER);if(n===Ia)return Ia;let s=Ar.BASE.multiply(n);return Q((s.Z+s.Y)*e(Q(s.Z-s.Y,t)),t)}})})();var Br=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},vn=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var De={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new vn("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 Bn=32;var Js,ch=(async()=>{try{return await De.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function fh(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await De.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await De.get().subtle.verify({name:"Ed25519"},n,Le(e),Le(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function uh(t,e,r){return Da.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function Oa(t,e,r){return Js==null&&(Js=await ch),Js?fh(t,e,r):uh(t,e,r)}function Ln(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var In=class{type="Ed25519";raw;constructor(e){this.raw=Qs(e,Bn)}toMultihash(){return Me.digest(nt(this))}toCID(){return ye.createV1(114,this.toMultihash())}toString(){return fe.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=Oa(this.raw,r,e);return Ln(s)?s.then(o=>(n?.signal?.throwIfAborted(),o)):s}};function Ka(t){return t=Qs(t,Bn),new In(t)}function Qs(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new ie(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}var lh=Math.pow(2,7),dh=Math.pow(2,14),ph=Math.pow(2,21),eo=Math.pow(2,28),to=Math.pow(2,35),ro=Math.pow(2,42),no=Math.pow(2,49),J=128,be=127;function Ke(t){if(t<lh)return 1;if(t<dh)return 2;if(t<ph)return 3;if(t<eo)return 4;if(t<to)return 5;if(t<ro)return 6;if(t<no)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function so(t,e,r=0){switch(Ke(t)){case 8:e[r++]=t&255|J,t/=128;case 7:e[r++]=t&255|J,t/=128;case 6:e[r++]=t&255|J,t/=128;case 5:e[r++]=t&255|J,t/=128;case 4:e[r++]=t&255|J,t>>>=7;case 3:e[r++]=t&255|J,t>>>=7;case 2:e[r++]=t&255|J,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function mh(t,e,r=0){switch(Ke(t)){case 8:e.set(r++,t&255|J),t/=128;case 7:e.set(r++,t&255|J),t/=128;case 6:e.set(r++,t&255|J),t/=128;case 5:e.set(r++,t&255|J),t/=128;case 4:e.set(r++,t&255|J),t>>>=7;case 3:e.set(r++,t&255|J),t>>>=7;case 2:e.set(r++,t&255|J),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function oo(t,e){let r=t[e],n=0;if(n+=r&be,r<J||(r=t[e+1],n+=(r&be)<<7,r<J)||(r=t[e+2],n+=(r&be)<<14,r<J)||(r=t[e+3],n+=(r&be)<<21,r<J)||(r=t[e+4],n+=(r&be)*eo,r<J)||(r=t[e+5],n+=(r&be)*to,r<J)||(r=t[e+6],n+=(r&be)*ro,r<J)||(r=t[e+7],n+=(r&be)*no,r<J))return n;throw new RangeError("Could not decode varint")}function yh(t,e){let r=t.get(e),n=0;if(n+=r&be,r<J||(r=t.get(e+1),n+=(r&be)<<7,r<J)||(r=t.get(e+2),n+=(r&be)<<14,r<J)||(r=t.get(e+3),n+=(r&be)<<21,r<J)||(r=t.get(e+4),n+=(r&be)*eo,r<J)||(r=t.get(e+5),n+=(r&be)*to,r<J)||(r=t.get(e+6),n+=(r&be)*ro,r<J)||(r=t.get(e+7),n+=(r&be)*no,r<J))return n;throw new RangeError("Could not decode varint")}function Ua(t,e,r=0){return e==null&&(e=pe(Ke(t))),e instanceof Uint8Array?so(t,e,r):mh(t,e,r)}function Tn(t,e=0){return t instanceof Uint8Array?oo(t,e):yh(t,e)}var io=new Float32Array([-0]),dt=new Uint8Array(io.buffer);function Na(t,e,r){io[0]=t,e[r]=dt[0],e[r+1]=dt[1],e[r+2]=dt[2],e[r+3]=dt[3]}function Ma(t,e){return dt[0]=t[e],dt[1]=t[e+1],dt[2]=t[e+2],dt[3]=t[e+3],io[0]}var ao=new Float64Array([-0]),we=new Uint8Array(ao.buffer);function Fa(t,e,r){ao[0]=t,e[r]=we[0],e[r+1]=we[1],e[r+2]=we[2],e[r+3]=we[3],e[r+4]=we[4],e[r+5]=we[5],e[r+6]=we[6],e[r+7]=we[7]}function Ha(t,e){return we[0]=t[e],we[1]=t[e+1],we[2]=t[e+2],we[3]=t[e+3],we[4]=t[e+4],we[5]=t[e+5],we[6]=t[e+6],we[7]=t[e+7],ao[0]}var gh=BigInt(Number.MAX_SAFE_INTEGER),bh=BigInt(Number.MIN_SAFE_INTEGER),Ie=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 At;if(e<gh&&e>bh)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>qa&&(s=0n,++n>qa&&(n=0n))),new t(Number(s),Number(n))}static fromNumber(e){if(e===0)return At;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):At}},At=new Ie(0,0);At.toBigInt=function(){return 0n};At.zzEncode=At.zzDecode=function(){return this};At.length=function(){return 1};var qa=4294967296n;function za(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 ja(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 co(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 Ue(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function _n(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var fo=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=Le(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,Ue(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 Ue(this,4);return _n(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ue(this,4);return _n(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ue(this,4);let e=Ma(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ue(this,4);let e=Ha(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 Ue(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return ja(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ue(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ue(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 Ie(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 Ue(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 Ue(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 Ue(this,8);let e=_n(this.buf,this.pos+=4),r=_n(this.buf,this.pos+=4);return new Ie(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=oo(this.buf,this.pos);return this.pos+=Ke(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 Lr(t){return new fo(t instanceof Uint8Array?t:t.subarray())}function vt(t,e,r){let n=Lr(t);return e.decode(n,void 0,r)}function uo(t){let e=t??8192,r=e>>>1,n,s=e;return function(i){if(i<1||i>r)return pe(i);s+i>e&&(n=pe(e),s=0);let a=n.subarray(s,s+=i);return(s&7)!==0&&(s=(s|7)+1),a}}var Bt=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function ho(){}var po=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},wh=uo();function xh(t){return globalThis.Buffer!=null?pe(t):wh(t)}var Tr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Bt(ho,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Bt(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new mo((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(Rn,10,Ie.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Ie.fromBigInt(e);return this._push(Rn,r.length(),r)}uint64Number(e){return this._push(so,Ke(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=Ie.fromBigInt(e).zzEncode();return this._push(Rn,r.length(),r)}sint64Number(e){let r=Ie.fromNumber(e).zzEncode();return this._push(Rn,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(lo,1,e?1:0)}fixed32(e){return this._push(Ir,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Ie.fromBigInt(e);return this._push(Ir,4,r.lo)._push(Ir,4,r.hi)}fixed64Number(e){let r=Ie.fromNumber(e);return this._push(Ir,4,r.lo)._push(Ir,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(Na,4,e)}double(e){return this._push(Fa,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(lo,1,0):this.uint32(r)._push(Sh,r,e)}string(e){let r=za(e);return r!==0?this.uint32(r)._push(co,r,e):this._push(lo,1,0)}fork(){return this.states=new po(this),this.head=this.tail=new Bt(ho,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 Bt(ho,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=xh(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function lo(t,e,r){e[r]=t&255}function Eh(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var mo=class extends Bt{next;constructor(e,r){super(Eh,e,r),this.next=void 0}};function Rn(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 Ir(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 Sh(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(Tr.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(Ah,e,t),this},Tr.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(vh,e,t),this});function Ah(t,e,r){e.set(t,r)}function vh(t,e,r){t.length<40?co(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(re(t),r)}function yo(){return new Tr}function Lt(t,e){let r=yo();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*It(t,e,r){let n=Lr(t);yield*e.stream(n,void 0,".",r)}var Cn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Dn(t,e,r,n,s){return{name:t,type:e,encode:r,decode:n,stream:s}}function go(t){function e(o){if(t[o.toString()]==null)throw new Error("Invalid enum value");return t[o]}let r=function(i,a){let c=e(i);a.int32(c)},n=function(i){let a=i.int32();return e(a)},s=function*(i,a){};return Dn("enum",Cn.VARINT,r,n,s)}function Tt(t,e,r){return Dn("message",Cn.LENGTH_DELIMITED,t,e,r)}var _t=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var le;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(le||(le={}));var bo;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(bo||(bo={}));(function(t){t.codec=()=>go(bo)})(le||(le={}));var Ge;(function(t){let e;t.codec=()=>(e==null&&(e=Tt((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.Type!=null&&(i.uint32(8),le.codec().encode(o.Type,i)),o.Data!=null&&(i.uint32(18),i.bytes(o.Data)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={},f=i==null?o.len:o.pos+i;for(;o.pos<f;){let u=o.uint32();switch(u>>>3){case 1:{c.Type=le.codec().decode(o);break}case 2:{c.Data=o.bytes();break}default:{o.skipType(u&7);break}}}return c},function*(o,i,a,c={}){let f=i==null?o.len:o.pos+i;for(;o.pos<f;){let u=o.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:le.codec().decode(o)};break}case 2:{yield{field:`${a}.Data`,value:o.bytes()};break}default:{o.skipType(u&7);break}}}})),e);function r(o){return Lt(o,t.codec())}t.encode=r;function n(o,i){return vt(o,t.codec(),i)}t.decode=n;function s(o,i){return It(o,t.codec(),i)}t.stream=s})(Ge||(Ge={}));var wo;(function(t){let e;t.codec=()=>(e==null&&(e=Tt((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.Type!=null&&(i.uint32(8),le.codec().encode(o.Type,i)),o.Data!=null&&(i.uint32(18),i.bytes(o.Data)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={},f=i==null?o.len:o.pos+i;for(;o.pos<f;){let u=o.uint32();switch(u>>>3){case 1:{c.Type=le.codec().decode(o);break}case 2:{c.Data=o.bytes();break}default:{o.skipType(u&7);break}}}return c},function*(o,i,a,c={}){let f=i==null?o.len:o.pos+i;for(;o.pos<f;){let u=o.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:le.codec().decode(o)};break}case 2:{yield{field:`${a}.Data`,value:o.bytes()};break}default:{o.skipType(u&7);break}}}})),e);function r(o){return Lt(o,t.codec())}t.encode=r;function n(o,i){return vt(o,t.codec(),i)}t.decode=n;function s(o,i){return It(o,t.codec(),i)}t.stream=s})(wo||(wo={}));var Rr={};Ae(Rr,{MAX_RSA_KEY_SIZE:()=>xo,generateRSAKeyPair:()=>Za,jwkToJWKKeyPair:()=>Xa,jwkToPkcs1:()=>Th,jwkToPkix:()=>vo,jwkToRSAPrivateKey:()=>To,pkcs1MessageToJwk:()=>So,pkcs1MessageToRSAPrivateKey:()=>Bo,pkcs1ToJwk:()=>Ih,pkcs1ToRSAPrivateKey:()=>Ga,pkixMessageToJwk:()=>Ao,pkixMessageToRSAPublicKey:()=>Io,pkixToJwk:()=>_h,pkixToRSAPublicKey:()=>Lo});var Jt=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Rr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ye.createV1(114,this._multihash)}toString(){return fe.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 Wa(this.jwk,r,e,n)}},_r=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Rr.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:xe(this.raw,e.raw)}sign(e,r){return Ya(this.jwk,e,r)}};var xo=8192,Eo=18,Bh=1062,Lh=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Ih(t){let e=$e(t);return So(e)}function So(t){return{n:Z(t[1],"base64url"),e:Z(t[2],"base64url"),d:Z(t[3],"base64url"),p:Z(t[4],"base64url"),q:Z(t[5],"base64url"),dp:Z(t[6],"base64url"),dq:Z(t[7],"base64url"),qi:Z(t[8],"base64url"),kty:"RSA"}}function Th(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 ie("JWK was missing components");return rt([ve(Uint8Array.from([0])),ve(re(t.n,"base64url")),ve(re(t.e,"base64url")),ve(re(t.d,"base64url")),ve(re(t.p,"base64url")),ve(re(t.q,"base64url")),ve(re(t.dp,"base64url")),ve(re(t.dq,"base64url")),ve(re(t.qi,"base64url"))]).subarray()}function _h(t){let e=$e(t,{offset:0});return Ao(e)}function Ao(t){let e=$e(t[1],{offset:0});return{kty:"RSA",n:Z(e[0],"base64url"),e:Z(e[1],"base64url")}}function vo(t){if(t.n==null||t.e==null)throw new ie("JWK was missing components");return rt([Lh,en(rt([ve(re(t.n,"base64url")),ve(re(t.e,"base64url"))]))]).subarray()}function Ga(t){let e=$e(t);return Bo(e)}function Bo(t){let e=So(t);return To(e)}function Lo(t,e){if(t.byteLength>=Bh)throw new Kt("Key size is too large");let r=$e(t,{offset:0});return Io(r,t,e)}function Io(t,e,r){let n=Ao(t);if(r==null){let s=He(Ge.encode({Type:le.RSA,Data:e}));r=Ne(Eo,s)}return new Jt(n,r)}function To(t){if(Qa(t)>xo)throw new ie("Key size is too large");let e=Xa(t),r=He(Ge.encode({Type:le.RSA,Data:vo(e.publicKey)})),n=Ne(Eo,r);return new _r(e.privateKey,new Jt(e.publicKey,n))}async function Za(t){if(t>xo)throw new ie("Key size is too large");let e=await Ja(t),r=He(Ge.encode({Type:le.RSA,Data:vo(e.publicKey)})),n=Ne(Eo,r);return new _r(e.privateKey,new Jt(e.publicKey,n))}function Xa(t){if(t==null)throw new ie("Missing key parameter");return{privateKey:t,publicKey:{kty:t.kty,n:t.n,e:t.e}}}async function Ja(t,e){let r=await De.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 Rh(r,e);return{privateKey:n[0],publicKey:n[1]}}async function Ya(t,e,r){let n=await De.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let s=await De.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,Le(e instanceof Uint8Array?e:e.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(s,0,s.byteLength)}async function Wa(t,e,r,n){let s=await De.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let o=await De.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},s,Le(e),Le(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),o}async function Rh(t,e){if(t.privateKey==null||t.publicKey==null)throw new ie("Private and public key are required");let r=await Promise.all([De.get().subtle.exportKey("jwk",t.privateKey),De.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function Qa(t){if(t.kty!=="RSA")throw new ie("invalid key type");if(t.n==null)throw new ie("invalid key modulus");return re(t.n,"base64url").length*8}var On=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(xt(e),Ee(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),_e(s)}update(e){return Vt(this),this.iHash.update(e),this}digestInto(e){Vt(this),nn(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()}},Cr=(()=>{let t=((e,r,n)=>new On(e,r).update(n).digest());return t.create=(e,r)=>new On(e,r),t})();var Ch=BigInt(0),_o=class extends Error{constructor(e=""){super(e)}},Ze={Err:_o,_tlv:{encode:(t,e)=>{let{Err:r}=Ze;if(We(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(ra(e,"data"),e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,s=br(n);if(s.length/2&128)throw new r("tlv.encode: long form length too big");let o=n>127?br(s.length/2|128):"";return br(t)+o+s+e},decode(t,e){let{Err:r}=Ze;e=Y(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.decode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let s=e[n++],o=!!(s&128),i=0;if(!o)i=s;else{let c=s&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let f=e.subarray(n,n+c);if(f.length!==c)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of f)i=i<<8|u;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+i)}}},_int:{encode(t){let{Err:e}=Ze;if(un(t),t<Ch)throw new e("integer: negative integers are not allowed");let r=br(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}=Ze;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 qe(t)}},toSig(t,e){let{Err:r,_int:n,_tlv:s}=Ze;if(e!==void 0&&(We(e,"maxScalarBytes"),e<1))throw new r("invalid signature: maxScalarBytes must be positive");let o=Y(t,void 0,"signature"),{v:i,l:a}=s.decode(48,o);if(a.length)throw new r("invalid signature: left bytes after parsing");let{v:c,l:f}=s.decode(2,i),{v:u,l:h}=s.decode(2,f);if(h.length)throw new r("invalid signature: left bytes after parsing");if(e!==void 0&&(c.length>e||u.length>e))throw new r("invalid signature: integer too large");return{r:n.decode(c),s:n.decode(u)}},hexFromSig(t){let{_tlv:e,_int:r}=Ze;ge(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)}},kn=(Object.freeze(Ze._tlv),Object.freeze(Ze._int),Object.freeze(Ze));var ec=(t,e)=>(t+(t>=0?e:-e)/tc)/e;function Dh(t,e,r){je("scalar",t,Xe,r);let[[n,s],[o,i]]=e,a=ec(i*t,r),c=ec(-s*t,r),f=t-a*n-c*o,u=-a*s-c*i,h=f<Xe,p=u<Xe;h&&(f=-f),p&&(u=-u);let d=xr(Math.ceil(Yt(r)/2))+Rt;if(f<Xe||f>=d||u<Xe||u>=d)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:h,k1:f,k2neg:p,k2:u}}function Do(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Ro(t,e){ge(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Be(r.lowS,"lowS"),Be(r.prehash,"prehash"),r.format!==void 0&&Do(r.format),r}var Xe=BigInt(0),Rt=BigInt(1),tc=BigInt(2),Co=BigInt(3),Oh=BigInt(4);function rc(t,e={}){let r=bn("weierstrass",t,e),n=r.Fp,s=r.Fn,o=r.CURVE,{h:i,n:a}=o;ge(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:f,clearCofactor:u,isTorsionFree:h,fromBytes:p,toBytes:d}=e,w=e.randomBytes===void 0?Ye:e.randomBytes;if(c&&(!n.is0(o.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let g=c?{beta:c.beta,basises:c.basises.map(S=>[...S])}:void 0,y=sc(n,s);function x(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function E(S,l,m){if(l.is0()){if(!f)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x:A,y:D}=l.toAffine(),U=n.toBytes(A);if(Be(m,"isCompressed"),m){x();let P=!n.isOdd(D);return Re(nc(P),U)}else return Re(Uint8Array.of(4),U,n.toBytes(D))}function b(S){Y(S,void 0,"Point");let{publicKey:l,publicKeyUncompressed:m}=y,A=S.length,D=S[0],U=S.subarray(1);if(f&&A===1&&D===0)return{x:n.ZERO,y:n.ZERO};if(A===l&&(D===2||D===3)){let P=n.fromBytes(U);if(!n.isValid(P))throw new Error("bad point: is not on curve, wrong x");let q=K(P),z;try{z=n.sqrt(q)}catch(ne){let ee=ne instanceof Error?": "+ne.message:"";throw new Error("bad point: is not on curve, sqrt error"+ee)}x();let V=n.isOdd(z);return(D&1)===1!==V&&(z=n.neg(z)),{x:P,y:z}}else if(A===m&&D===4){let P=n.BYTES,q=n.fromBytes(U.subarray(0,P)),z=n.fromBytes(U.subarray(P,P*2));if(!_(q,z))throw new Error("bad point: is not on curve");return{x:q,y:z}}else throw new Error(`bad point: got length ${A}, expected compressed=${l} or uncompressed=${m}`)}let R=d===void 0?E:d,T=p===void 0?b:p,O=n.mul(o.b,Co),N=n.is0(o.a)?S=>n.ZERO:S=>n.mul(o.a,S);function K(S){let l=n.sqr(S),m=n.mul(l,S);return n.add(n.add(m,n.mul(S,o.a)),o.b)}function _(S,l){let m=n.sqr(l),A=K(S);return n.eql(m,A)}if(!_(o.Gx,o.Gy))throw new Error("bad curve params: generator point");let C=n.mul(n.pow(o.a,Co),Oh),F=n.mul(n.sqr(o.b),BigInt(27));if(n.is0(n.add(C,F)))throw new Error("bad curve params: a or b");function M(S,l,m=!1){if(!n.isValid(l)||m&&n.is0(l))throw new Error(`bad point coordinate ${S}`);return typeof l=="object"&&l!==null?n.create(l):l}function j(S){if(!(S instanceof v))throw new Error("Weierstrass Point expected")}function B(S){if(!g||!g.basises)throw new Error("no endo");return Dh(S,g.basises,s.ORDER)}function k(S,l,m,A){if(!s.isValid(A))throw new RangeError("invalid scalar: out of range");if(g){let{k1neg:D,k1:U,k2neg:P,k2:q}=B(A),z=new v(n.mul(m.X,g.beta),m.Y,m.Z);S.push(D?m.negate():m,P?z.negate():z),l.push(U,q)}else S.push(m),l.push(A)}let L=new WeakSet;class v{static BASE=new v(o.Gx,o.Gy,n.ONE);static ZERO=new v(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=s;X;Y;Z;constructor(l,m,A){this.X=M("x",l),this.Y=M("y",m,!0),this.Z=M("z",A),Object.freeze(this)}static CURVE(){return o}static fromAffine(l){let{x:m,y:A}=l||{};if(!l||!n.isValid(m)||!n.isValid(A))throw new Error("invalid affine point");if(l instanceof v)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(A)?v.ZERO:new v(m,A,n.ONE)}static fromBytes(l){let m=v.fromAffine(T(Y(l,void 0,"point")));return m.assertValidity(),m}static fromHex(l){return v.fromBytes($t(l))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(l=6,m=!0){return I.setWindowSize(this,l),m||this.multiply(Co),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(L.has(l))return;let{x:m,y:A}=l.toAffine();if(!n.isValid(m)||!n.isValid(A))throw new Error("bad point: x or y not field elements");if(!_(m,A))throw new Error("bad point: equation left != right");if(!l.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");L.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){j(l);let{X:m,Y:A,Z:D}=this,{X:U,Y:P,Z:q}=l,z=n.eql(n.mul(m,q),n.mul(U,D)),V=n.eql(n.mul(A,q),n.mul(P,D));return z&&V}negate(){return new v(this.X,n.neg(this.Y),this.Z)}double(){let{X:l,Y:m,Z:A}=this,D=n.ZERO,U=n.ZERO,P=n.ZERO,q=n.mul(l,l),z=n.mul(m,m),V=n.mul(A,A),$=n.mul(l,m);return $=n.add($,$),P=n.mul(l,A),P=n.add(P,P),D=N(P),U=n.mul(O,V),U=n.add(D,U),D=n.sub(z,U),U=n.add(z,U),U=n.mul(D,U),D=n.mul($,D),P=n.mul(O,P),V=N(V),$=n.sub(q,V),$=N($),$=n.add($,P),P=n.add(q,q),q=n.add(P,q),q=n.add(q,V),q=n.mul(q,$),U=n.add(U,q),V=n.mul(m,A),V=n.add(V,V),q=n.mul(V,$),D=n.sub(D,q),P=n.mul(V,z),P=n.add(P,P),P=n.add(P,P),new v(D,U,P)}add(l){j(l);let{X:m,Y:A,Z:D}=this,{X:U,Y:P,Z:q}=l,z=n.ZERO,V=n.ZERO,$=n.ZERO,ne=n.mul(m,U),ee=n.mul(A,P),ce=n.mul(D,q),Se=n.add(m,A),te=n.add(U,P);Se=n.mul(Se,te),te=n.add(ne,ee),Se=n.sub(Se,te),te=n.add(m,D);let oe=n.add(U,q);return te=n.mul(te,oe),oe=n.add(ne,ce),te=n.sub(te,oe),oe=n.add(A,D),z=n.add(P,q),oe=n.mul(oe,z),z=n.add(ee,ce),oe=n.sub(oe,z),$=N(te),z=n.mul(O,ce),$=n.add(z,$),z=n.sub(ee,$),$=n.add(ee,$),V=n.mul(z,$),ee=n.add(ne,ne),ee=n.add(ee,ne),ce=N(ce),te=n.mul(O,te),ee=n.add(ee,ce),ce=n.sub(ne,ce),ce=N(ce),te=n.add(te,ce),ne=n.mul(ee,te),V=n.add(V,ne),ne=n.mul(oe,te),z=n.mul(Se,z),z=n.sub(z,ne),ne=n.mul(Se,ee),$=n.mul(oe,$),$=n.add($,ne),new v(z,V,$)}subtract(l){return j(l),this.add(l.negate())}is0(){return this.equals(v.ZERO)}multiply(l){if(!s.isValidNot0(l))throw new RangeError("invalid scalar: out of range");let{p:m,f:A}=I.mulSecret(this,l,i,H);return H([m,A])[0]}multiplyUnsafe(l){let m=this,A=l;if(!s.isValid(A))throw new RangeError("invalid scalar: out of range");if(A===Xe||m.is0())return v.ZERO;if(A===Rt)return m;if(I.hasWindowSize(this))return I.mulUnsafe(m,A,H);let D=[],U=[];return k(D,U,m,A),gn(v,D,U)}mulAddUnsafe(l,m,A){j(m);let D=[],U=[];return k(D,U,this,l),k(D,U,m,A),gn(v,D,U)}toAffine(l){let m=this,A=l;if(A!=null&&!n.isValid(A))throw new RangeError('"invertedZ" expected valid field element');let{X:D,Y:U,Z:P}=m;if(n.eql(P,n.ONE))return{x:D,y:U};let q=m.is0();A==null&&(A=q?n.ONE:n.inv(P));let z=n.mul(D,A),V=n.mul(U,A),$=n.mul(P,A);if(q)return{x:n.ZERO,y:n.ZERO};if(!n.eql($,n.ONE))throw new Error("invZ was invalid");return{x:z,y:V}}isTorsionFree(){return i===Rt?!0:h?h(v,this):I.mulUnsafe(this,a).is0()}clearCofactor(){return i===Rt?this:u?u(v,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===Rt?this.is0():this.clearCofactor().is0()}toBytes(l=!0){return Be(l,"isCompressed"),this.assertValidity(),R(v,this,l)}toHex(l=!0){return gr(this.toBytes(l))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let H=S=>yn(v,S),I=new Zt(v,w);return I.bits>=6&&v.BASE.precompute(6),Object.freeze(v.prototype),Object.freeze(v),v}function nc(t){return Uint8Array.of(t?2:3)}function sc(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function kh(t,e={}){lt(t);let{Fn:r}=t,n=e.randomBytes===void 0?Ye:e.randomBytes,s=Object.assign(sc(t.Fp,r),{seed:Math.max(pn(r.ORDER),16)});function o(d){try{let w=r.fromBytes(d);return r.isValidNot0(w)}catch{return!1}}function i(d,w){let{publicKey:g,publicKeyUncompressed:y}=s;try{let x=d.length;return w===!0&&x!==g||w===!1&&x!==y?!1:!t.fromBytes(d).is0()}catch{return!1}}function a(d){return d=d===void 0?n(s.seed):d,mn(Y(d,s.seed,"seed"),r.ORDER)}function c(d,w=!0){return t.BASE.multiply(r.fromBytes(d)).toBytes(w)}function f(d){let{secretKey:w,publicKey:g,publicKeyUncompressed:y}=s,x=r._lengths;if(!ft(d))return;let E=Y(d,void 0,"key").length,b=E===g||E===y,R=E===w||!!x?.includes(E);if(!(b&&R))return b}function u(d,w,g=!0){if(f(d)===!0)throw new Error("first arg must be private key");if(f(w)===!1)throw new Error("second arg must be public key");let y=r.fromBytes(d),x=t.fromBytes(w);if(x.is0())throw new Error("invalid public key: point at infinity");return x.multiply(y).toBytes(g)}let h={isValidSecretKey:o,isValidPublicKey:i,randomSecretKey:a},p=Xt(a,c);return Object.freeze(h),Object.freeze(s),Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:p,Point:t,utils:h,lengths:s})}function oc(t,e,r={}){lt(t);let n=e;xt(n),ge(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let s=Object.assign({},r),o=s.randomBytes===void 0?Ye:s.randomBytes,i=s.hmac===void 0?(S,l)=>Cr(n,S,l):s.hmac,{Fp:a,Fn:c}=t,{ORDER:f,BITS:u}=c,h=pn(f),p=Gs(o,h),{keygen:d,getPublicKey:w,getSharedSecret:g,utils:y,lengths:x}=kh(t,s),E={prehash:!0,lowS:typeof s.lowS=="boolean"?s.lowS:!0,format:"compact",extraEntropy:!1},b=f*tc+Rt<a.ORDER;function R(S){let l=f>>Rt;return S>l}function T(S,l){if(!c.isValidNot0(l))throw new Error(`invalid signature ${S}: out of range 1..Point.Fn.ORDER`);return l}function O(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function N(S,l,m){return O(),(S===m?0:2)|Number(a.isOdd(l))}function K(){if(b)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function _(S,l){Do(l);let m=x.signature,A=l==="compact"?m:l==="recovered"?m+1:void 0;return Y(S,A)}class C{r;s;recovery;constructor(l,m,A){if(this.r=T("r",l),this.s=T("s",m),A!=null){if(K(),![0,1,2,3].includes(A))throw new Error("invalid recovery id");this.recovery=A}Object.freeze(this)}static fromBytes(l,m=E.format){_(l,m);let A;if(m==="der"){if(l.length>2*c.BYTES+16)throw new kn.Err("invalid signature: DER signature too long");let{r:q,s:z}=kn.toSig(Y(l),c.BYTES+1);return new C(q,z)}m==="recovered"&&(A=l[0],m="compact",l=l.subarray(1));let D=x.signature/2,U=l.subarray(0,D),P=l.subarray(D,D*2);return new C(c.fromBytes(U),c.fromBytes(P),A)}static fromHex(l,m){return this.fromBytes($t(l),m)}assertRecovery(){let{recovery:l}=this;if(l==null)throw new Error("invalid recovery id: must be present");return l}addRecoveryBit(l){return new C(this.r,this.s,l)}recoverPublicKey(l){let{r:m,s:A}=this,D=this.assertRecovery(),U=D===2||D===3?m+f:m;if(!a.isValid(U))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let P=a.toBytes(U),q=t.fromBytes(Re(nc((D&1)===0),P)),z=c.inv(U),V=M(Y(l,void 0,"msgHash")),$=c.create(-V*z),ne=c.create(A*z),ee=t.BASE.mulAddUnsafe($,q,ne);if(ee.is0())throw new Error("invalid recovery: point at infinify");return ee.assertValidity(),ee}hasHighS(){return R(this.s)}toBytes(l=E.format){if(Do(l),l==="der")return $t(kn.hexFromSig(this));let{r:m,s:A}=this,D=c.toBytes(m),U=c.toBytes(A);return l==="recovered"?(K(),Re(Uint8Array.of(this.assertRecovery()),D,U)):Re(D,U)}toHex(l){return gr(this.toBytes(l))}}Object.freeze(C.prototype),Object.freeze(C);let F=s.bits2int===void 0?function(l){if(l.length>8192)throw new Error("input is too large");let m=qe(l),A=l.length*8-u;return A>0?m>>BigInt(A):m}:s.bits2int,M=s.bits2int_modN===void 0?function(l){return c.create(F(l))}:s.bits2int_modN,j=xr(u);function B(S){return je("num < 2^"+u,S,Xe,j),c.toBytes(S)}function k(S,l){return Y(S,void 0,"message"),l?Y(n(S),void 0,"prehashed message"):S}function L(S,l,m){let{lowS:A,prehash:D,extraEntropy:U}=Ro(m,E);S=k(S,D);let P=M(S),q=c.fromBytes(l);if(!c.isValidNot0(q))throw new Error("invalid private key");let z=[B(q),B(P)];if(U!=null&&U!==!1){let ee=U===!0?o(x.secretKey):U;z.push(Y(ee,void 0,"extraEntropy"))}let V=Re(...z),$=P;function ne(ee){let ce=F(ee);if(!c.isValidNot0(ce))return;let Se=t.BASE.multiply(ce).toAffine(),te=c.create(Se.x);if(te===Xe)return;let oe;if(p!==void 0){let Qe=qe(mn(p(h),f)),Nc=c.inv(c.mul(Qe,ce)),Mc=c.mul(Qe,$),Fc=c.mul(Qe,q);oe=c.create(Nc*c.create(Mc+Fc*te))}else{let Qe=la(ce,f);oe=c.create(Qe*c.create($+te*q))}if(oe===Xe)return;let kt=N(Se.x,Se.y,te),ar=oe;return A&&R(oe)&&(ar=c.neg(oe),kt^=1),new C(te,ar,b?void 0:kt)}return{seed:V,k2sig:ne}}function v(S,l,m={}){let{seed:A,k2sig:D}=L(S,l,m);return sa(n.outputLen,c.BYTES,i)(A,D).toBytes(m.format)}function H(S,l,m,A={}){let{lowS:D,prehash:U,format:P}=Ro(A,E);if(m=Y(m,void 0,"publicKey"),l=k(l,U),!ft(S)){let q=S instanceof C?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+q)}_(S,P);try{let q=C.fromBytes(S,P),z=t.fromBytes(m);if(z.is0()||D&&q.hasHighS())return!1;let{r:V,s:$}=q,ne=M(l),ee=c.inv($),ce=c.create(ne*ee),Se=c.create(V*ee),te=t.BASE.mulAddUnsafe(ce,z,Se);if(te.is0())return!1;let oe=te.toAffine();return!(c.create(oe.x)!==V||P==="recovered"&&q.recovery!==N(oe.x,oe.y,V))}catch{return!1}}function I(S,l,m={}){let{prehash:A}=Ro(m,E);return l=k(l,A),C.fromBytes(S,"recovered").recoverPublicKey(l).toBytes()}return Object.freeze({keygen:d,getPublicKey:w,getSharedSecret:g,utils:y,lengths:x,Point:t,sign:v,verify:H,recoverPublicKey:I,Signature:C,hash:n})}var ko={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Kh={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var ic=BigInt(2);function Uh(t){let e=ko.p,r=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),f=t*t*t%e,u=f*f*t%e,h=se(u,r,e)*u%e,p=se(h,r,e)*u%e,d=se(p,ic,e)*f%e,w=se(d,s,e)*d%e,g=se(w,o,e)*w%e,y=se(g,a,e)*g%e,x=se(y,c,e)*y%e,E=se(x,a,e)*g%e,b=se(E,r,e)*u%e,R=se(b,i,e)*w%e,T=se(R,n,e)*f%e,O=se(T,ic,e);if(!Oo.eql(Oo.sqr(O),t))throw new Error("Cannot find square root");return O}var Oo=Gt(ko.p,{sqrt:Uh}),Ph=rc(ko,{Fp:Oo,endo:Kh}),Qt=oc(Ph,He);function ac(t,e,r,n){let s=Jr.digest(r instanceof Uint8Array?r:r.subarray());if(Ln(s))return s.then(({digest:o})=>(n?.signal?.throwIfAborted(),Qt.verify(e,o,t,{prehash:!1,format:"der"}))).catch(o=>{throw o.name==="AbortError"?o:new Br(String(o))});try{return n?.signal?.throwIfAborted(),Qt.verify(e,s.digest,t,{prehash:!1,format:"der"})}catch(o){throw new Br(String(o))}}var Kn=class{type="secp256k1";raw;_key;constructor(e){this._key=fc(e),this.raw=cc(this._key)}toMultihash(){return Me.digest(nt(this))}toCID(){return ye.createV1(114,this.toMultihash())}toString(){return fe.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 ac(this._key,r,e,n)}};function uc(t){return new Kn(t)}function cc(t){return Qt.Point.fromBytes(t).toBytes()}function fc(t){try{return Qt.Point.fromBytes(t),t}catch(e){throw new Kt(String(e))}}function Dr(t,e){let{Type:r,Data:n}=Ge.decode(t),s=n??new Uint8Array;switch(r){case le.RSA:return Lo(s,e);case le.Ed25519:return Ka(s);case le.secp256k1:return uc(s);case le.ECDSA:return ki(s);default:throw new Ut}}function nt(t){return Ge.encode({Type:le[t.type],Data:t.raw})}var hc=Symbol.for("nodejs.util.inspect.custom"),Nh=114,Or=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()})`}[Qn]=!0;toString(){return this.string==null&&(this.string=fe.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ye.createV1(Nh,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")}[hc](){return`PeerId(${this.toString()})`}},Un=class extends Or{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Pn=class extends Or{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Nn=class extends Or{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},Mh=2336,Ko=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Me.digest(re(this.url))}[hc](){return`PeerId(${this.url})`}[Qn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ye.createV1(Mh,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=Z(e)),e.toString()===this.toString())}};function Uo(t){if(t.type==="Ed25519")return new Pn({multihash:t.toCID().multihash,publicKey:t});if(t.type==="secp256k1")return new Nn({multihash:t.toCID().multihash,publicKey:t});if(t.type==="RSA")return new Un({multihash:t.toCID().multihash,publicKey:t});throw new Ut}function Mn(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Fn=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}},er=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Fn(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 Fn(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 Po=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Hn(t={}){return Fh(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 Fh(t,e){e=e??{};let r=e.onEnd,n=new er,s,o,i,a=Mn(),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(b){x(b)}return s}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Mn()})}},f=y=>o!=null?o(y):(n.push(y),s),u=y=>(n=new er,o!=null?o({error:y}):(n.push({error:y}),s)),h=y=>{if(i)return s;if(e?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:y})},p=y=>i?s:(i=!0,y!=null?u(y):f({done:!0})),d=()=>(n=new er,p(),{done:!0}),w=y=>(p(y),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:d,throw:w,push:h,end:p,get readableLength(){return n.size},onEmpty:async y=>{let x=y?.signal;if(x?.throwIfAborted(),n.isEmpty())return;let E,b;x!=null&&(E=new Promise((R,T)=>{b=()=>{T(new Po)},x.addEventListener("abort",b)}));try{await Promise.race([a.promise,E])}finally{b!=null&&x!=null&&x?.removeEventListener("abort",b)}}},r==null)return s;let g=s;return s={[Symbol.asyncIterator](){return this},next(){return g.next()},throw(y){return g.throw(y),r!=null&&(r(y),r=void 0),{done:!0}},return(){return g.return(),r!=null&&(r(),r=void 0),{done:!0}},push:h,end(y){return g.end(y),r!=null&&(r(y),r=void 0),s},get readableLength(){return g.readableLength},onEmpty:y=>g.onEmpty(y)},s}var No=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},lc=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function Mo(t,e){let{milliseconds:r,fallback:n,message:s,customTimers:o={setTimeout,clearTimeout},signal:i}=e,a,c,u=new Promise((h,p)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){p(lc(i)),t.then(h,p);return}if(i&&(c=()=>{p(lc(i))},i.addEventListener("abort",c,{once:!0})),t.then(h,p),r===Number.POSITIVE_INFINITY)return;let d=new No;a=o.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(w){p(w)}return}typeof t.cancel=="function"&&t.cancel(),s===!1?h():s instanceof Error?p(s):(d.message=s??`Promise timed out after ${r} milliseconds`,p(d))},r)}).finally(()=>{u.clear(),c&&i&&i.removeEventListener("abort",c)});return u.clear=()=>{o.clearTimeout.call(void 0,a),a=void 0},u}var Hh=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 qh(t,e,r){let n,s=new Promise((o,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:f,removeListener:u}=Hh(t),h=async(...d)=>{let w=r.multiArgs?d:d[0];if(r.filter)try{if(!await r.filter(w))return}catch(g){n(),i(g);return}c.push(w),r.count===c.length&&(n(),o(c))},p=(...d)=>{n(),i(r.rejectionMultiArgs?d:d[0])};n=()=>{for(let d of a)u(d,h);for(let d of r.rejectionEvents)a.includes(d)||u(d,p)};for(let d of a)f(d,h);for(let d of r.rejectionEvents)a.includes(d)||f(d,p);r.signal&&r.signal.addEventListener("abort",()=>{p(r.signal.reason)},{once:!0}),r.resolveImmediately&&o(c)});if(s.cancel=n,typeof r.timeout=="number"){let o=Mo(s,{milliseconds:r.timeout});return o.cancel=()=>{n(),o.clear()},o}return s}function dc(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=qh(t,e,r),s=n.then(o=>o[0]);return s.cancel=n.cancel,s}var Ct=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};var qn=class extends Error{static name="StreamClosedError";name="StreamClosedError"};function zh(t){return t.reason}function kr(t,e,r){if(e==null||t==null)return t;let n=r?.translateError??zh;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 jh=Math.pow(2,20)*4,zn=class extends Gr{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??jh,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new G,this.writeBuffer=new G,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 qn)};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()),kr(this.onDrainPromise.promise,e?.signal))}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=Hn(),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 et(`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 Yr(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new et("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 et("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 et(`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 et(`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 Wr(new Vr))}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 Pt))}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 G(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 $r(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 mt(`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 mt(`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 Vh=4194304,jn=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Kr=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Ho=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},qo=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function $h(t){return typeof t?.closeRead=="function"}function Yh(t){return typeof t?.close=="function"}function Fo(t){return $h(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:Yh(t)?t.status!=="open":!1}function Wh(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function Gh(t,e){let r=e?.maxBufferSize??Vh,n=new G,s,o=!1,i;if(!Wh(t))throw new ie("Argument should be a Stream or a Multiaddr");let a=h=>{if(i==null){if(n.append(h.data),n.byteLength>r){let p=n.byteLength;n.consume(p);let d=new mt(`Read buffer overflow - ${p} > ${r}`);i=d,s?.reject(d),queueMicrotask(()=>{t.abort(d)});return}s?.resolve()}};t.addEventListener("message",a);let c=h=>{h.error!=null?s?.reject(h.error):s?.resolve()};t.addEventListener("close",c);let f=()=>{s?.resolve()};t.addEventListener("remoteCloseWrite",f);let u={readBuffer:n,async read(h){if(o===!0)throw new jn("Stream was unwrapped");if(i!=null)throw i;if(Fo(t)){if(n.byteLength===0&&h?.bytes==null)return null;if(h?.bytes!=null&&n.byteLength<h.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,h.bytes),new Ct(`Unexpected EOF - stream closed after reading ${n.byteLength}/${h.bytes} bytes`)}let p=h?.bytes??1;for(s=Promise.withResolvers();;){if(n.byteLength>=p){s.resolve();break}if(await kr(s.promise,h?.signal),Fo(t)){if(n.byteLength===0&&h?.bytes==null)return null;break}s=Promise.withResolvers()}let d=h?.bytes??n.byteLength;if(n.byteLength<d){if(Fo(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,d),new Ct(`Unexpected EOF - stream closed while reading ${n.byteLength}/${d} bytes`);return u.read(h)}let w=n.sublist(0,d);return n.consume(d),w},async write(h,p){if(o===!0)throw new jn("Stream was unwrapped");t.send(h)||await dc(t,"drain",{signal:p?.signal,rejectionEvents:["close"]})},unwrap(){return o||(o=!0,t.removeEventListener("message",a),t.removeEventListener("close",c),t.removeEventListener("remoteCloseWrite",f),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.unshift(n))),t}};return u}function zo(t,e={}){let r=Gh(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Ke(e.maxDataLength));let n=e?.lengthDecoder??Tn,s=e?.lengthEncoder??Ua;return{async read(i){let a=-1,c=new G;for(;;){let u=await r.read({...i,bytes:1});if(u==null)break;c.append(u);try{a=n(c)}catch(h){if(h instanceof RangeError)continue;throw h}if(a<0)throw new Kr("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new qo(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new Ho(`Message length too long - ${a} > ${e.maxDataLength}`);let f=await r.read({...i,bytes:a});if(f==null)throw t.log.error("tried to read %d bytes but the stream closed",a),new Ct(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(f.byteLength!==a)throw t.log.error("read %d/%d bytes before the stream closed",f.byteLength,a),new Ct(`Unexpected EOF - read ${f.byteLength}/${a} bytes before the stream closed`);return f},async write(i,a){await r.write(new G(s(i.byteLength),i),a)},async writeV(i,a){let c=new G(...i.flatMap(f=>[s(f.byteLength),f]));await r.write(c,a)},unwrap(){return r.unwrap()}}}var Zh=1024*1024*4,Xh=1024*1024*4,Vn=class{buffer;maxBufferSize;lengthDecoder;maxDataLength;encodingLength;constructor(e={}){this.buffer=new G,this.maxBufferSize=e.maxBufferSize??Zh,this.maxDataLength=e.maxDataLength??Xh,this.lengthDecoder=e.lengthDecoder??Tn,this.encodingLength=e.encodingLength??Ke}*decode(e){if(this.buffer.append(e),this.buffer.byteLength>this.maxBufferSize)throw new ie(`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 Kr("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 tr=!!globalThis.process?.env?.DUMP_SESSION_KEYS,jo=16;function Vo(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var $n=t=>t?`"${t}" `:"";function Yn(t,e=""){if(typeof t!="boolean")throw new TypeError($n(e)+"expected boolean, got type="+typeof t);return t}function Dt(t,e=""){if(typeof t!="number")throw new TypeError($n(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError($n(e)+"expected integer >= 0, got "+t);return t}function ue(t,e,r=""){if(Vo(t)&&(e===void 0||t.length===e))return t;e!==void 0&&Dt(e,"length");let n=Vo(t),s=e!==void 0?` of length ${e}`:"",o=n?`length=${t.length}`:`type=${typeof t}`,i=$n(r)+"expected Uint8Array"+s+", got "+o;throw n?new RangeError(i):new TypeError(i)}var pc=(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 $o(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function mc(t,e){ue(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function Ve(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function Pe(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Jh(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}var pt=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Qh(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function el(t){for(let e=0;e<t.length;e++)t[e]=Qh(t[e]);return t}var Je=pt?t=>t:el;function tl(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 yc(t,e){if(tl(t,e)&&t.byteOffset<e.byteOffset)throw new Error("complex overlap of input and output is not supported")}function gc(t,e){return pc(t,"defaults"),pc(e,"opts"),Object.assign(t,e)}function bc(t,e){if(t=ue(t),e=ue(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 wc(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 xc=(t,e)=>{function r(n,...s){if(ue(n,void 0,"key"),t.nonceLength!==void 0){let h=s[0];ue(h,t.varSizeNonce?void 0:t.nonceLength,"nonce")}let o=t.tagLength,i=t.nonceLength!==void 0?1:0;if(!t.withAAD){for(let h=i;h<s.length;h++)if(Vo(s[h]))throw new Error("AAD not supported")}t.withAAD&&s[i]!==void 0&&ue(s[i],void 0,"AAD");let a=e(n,...s),c=(h,p)=>{if(p!==void 0){if(h!==2)throw new Error("cipher output not supported");ue(p,void 0,"output")}},f=!1;return{encrypt(h,p){if(f)throw new Error("cannot encrypt() twice with same key + nonce");return f=!0,ue(h,void 0,"data"),c(a.encrypt.length,p),a.encrypt(h,p)},decrypt(h,p){if(ue(h,void 0,"data"),o&&h.length<o)throw new Error('"ciphertext" expected length >= tagLength='+o);return c(a.decrypt.length,p),a.decrypt(h,p)}}}return Object.assign(r,t),r};function Ur(t,e,r=!0){if(e===void 0)return new Uint8Array(t);if(ue(e,t,"output"),r&&!Pr(e))throw new Error("invalid output, must be aligned");return e}function Ec(t,e,r){Dt(t),Dt(e),Yn(r);let n=new Uint8Array(16),s=Jh(n);return s.setBigUint64(0,BigInt(e),r),s.setBigUint64(8,BigInt(t),r),n}function Pr(t){return t.byteOffset%4===0}function rr(t){return Uint8Array.from(ue(t))}var Ac=t=>Uint8Array.from(t.split(""),e=>e.charCodeAt(0)),rl=Je(Ve(Ac("expand 16-byte k"))),nl=Je(Ve(Ac("expand 32-byte k")));function W(t,e){return t<<e|t>>>32-e}var Nr=64,sl=16,Yo=2**32-1,Sc=Uint32Array.of();function ol(t,e,r,n,s,o,i,a){let c=s.length,f=new Uint8Array(Nr),u=Ve(f),h=pt&&Pr(s)&&Pr(o),p=h?Ve(s):Sc,d=h?Ve(o):Sc;if(!pt){for(let w=0;w<c;i++){if(t(e,r,n,u,i,a),Je(u),i>=Yo)throw new Error("arx: counter overflow");let g=Math.min(Nr,c-w);for(let y=0,x;y<g;y++)x=w+y,o[x]=s[x]^f[y];w+=g}return}for(let w=0;w<c;i++){if(t(e,r,n,u,i,a),i>=Yo)throw new Error("arx: counter overflow");let g=Math.min(Nr,c-w);if(h&&g===Nr){let y=w/4;if(w%4!==0)throw new Error("arx: invalid block position");for(let x=0,E;x<sl;x++)E=y+x,d[E]=p[E]^u[x];w+=Nr;continue}for(let y=0,x;y<g;y++)x=w+y,o[x]=s[x]^f[y];w+=g}}function vc(t,e){let{allowShortKeys:r,extendNonceFn:n,counterLength:s,counterRight:o,rounds:i}=gc({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof t!="function")throw new Error("core must be a function");return Dt(s),Dt(i),Yn(o),Yn(r),(a,c,f,u,h=0)=>{ue(a,void 0,"key"),ue(c,void 0,"nonce"),ue(f,void 0,"data");let p=f.length,d=u!==void 0;if(u=Ur(p,u,!1),d&&yc(f,u),Dt(h),h<0||h>=Yo)throw new Error("arx: counter overflow");let w=[],g=a.length,y,x;if(g===32)w.push(y=rr(a)),x=nl;else if(g===16&&r)y=new Uint8Array(32),y.set(a),y.set(a,16),x=rl,w.push(y);else throw ue(a,32,"arx key"),new Error("invalid key size");(!pt||!Pr(c))&&w.push(c=rr(c));let E=Ve(y);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");let T=c.subarray(0,16);if(pt)n(x,E,Ve(T),E);else{let O=Je(Uint32Array.from(x));n(O,E,Ve(T),E),Pe(O),Je(E)}c=c.subarray(16)}else pt||Je(E);let b=16-s;if(b!==c.length)throw new Error(`arx: nonce must be ${b} or 16 bytes`);if(b!==12){let T=new Uint8Array(12);T.set(c,o?0:12-c.length),c=T,w.push(c)}let R=Je(Ve(c));try{return ol(t,x,E,R,f,u,h,i),u}finally{Pe(...w)}}}function me(t,e){return t[e++]&255|(t[e++]&255)<<8}var Wo=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=rr(ue(e,32,"key"));let r=me(e,0),n=me(e,2),s=me(e,4),o=me(e,6),i=me(e,8),a=me(e,10),c=me(e,12),f=me(e,14);this.r[0]=r&8191,this.r[1]=(r>>>13|n<<3)&8191,this.r[2]=(n>>>10|s<<6)&7939,this.r[3]=(s>>>7|o<<9)&8191,this.r[4]=(o>>>4|i<<12)&255,this.r[5]=i>>>1&8190,this.r[6]=(i>>>14|a<<2)&8191,this.r[7]=(a>>>11|c<<5)&8065,this.r[8]=(c>>>8|f<<8)&8191,this.r[9]=f>>>5&127;for(let u=0;u<8;u++)this.pad[u]=me(e,16+2*u)}process(e,r,n=!1){let s=n?0:2048,{h:o,r:i}=this,a=i[0],c=i[1],f=i[2],u=i[3],h=i[4],p=i[5],d=i[6],w=i[7],g=i[8],y=i[9],x=me(e,r+0),E=me(e,r+2),b=me(e,r+4),R=me(e,r+6),T=me(e,r+8),O=me(e,r+10),N=me(e,r+12),K=me(e,r+14),_=o[0]+(x&8191),C=o[1]+((x>>>13|E<<3)&8191),F=o[2]+((E>>>10|b<<6)&8191),M=o[3]+((b>>>7|R<<9)&8191),j=o[4]+((R>>>4|T<<12)&8191),B=o[5]+(T>>>1&8191),k=o[6]+((T>>>14|O<<2)&8191),L=o[7]+((O>>>11|N<<5)&8191),v=o[8]+((N>>>8|K<<8)&8191),H=o[9]+(K>>>5|s),I=0,S=I+_*a+C*(5*y)+F*(5*g)+M*(5*w)+j*(5*d);I=S>>>13,S&=8191,S+=B*(5*p)+k*(5*h)+L*(5*u)+v*(5*f)+H*(5*c),I+=S>>>13,S&=8191;let l=I+_*c+C*a+F*(5*y)+M*(5*g)+j*(5*w);I=l>>>13,l&=8191,l+=B*(5*d)+k*(5*p)+L*(5*h)+v*(5*u)+H*(5*f),I+=l>>>13,l&=8191;let m=I+_*f+C*c+F*a+M*(5*y)+j*(5*g);I=m>>>13,m&=8191,m+=B*(5*w)+k*(5*d)+L*(5*p)+v*(5*h)+H*(5*u),I+=m>>>13,m&=8191;let A=I+_*u+C*f+F*c+M*a+j*(5*y);I=A>>>13,A&=8191,A+=B*(5*g)+k*(5*w)+L*(5*d)+v*(5*p)+H*(5*h),I+=A>>>13,A&=8191;let D=I+_*h+C*u+F*f+M*c+j*a;I=D>>>13,D&=8191,D+=B*(5*y)+k*(5*g)+L*(5*w)+v*(5*d)+H*(5*p),I+=D>>>13,D&=8191;let U=I+_*p+C*h+F*u+M*f+j*c;I=U>>>13,U&=8191,U+=B*a+k*(5*y)+L*(5*g)+v*(5*w)+H*(5*d),I+=U>>>13,U&=8191;let P=I+_*d+C*p+F*h+M*u+j*f;I=P>>>13,P&=8191,P+=B*c+k*a+L*(5*y)+v*(5*g)+H*(5*w),I+=P>>>13,P&=8191;let q=I+_*w+C*d+F*p+M*h+j*u;I=q>>>13,q&=8191,q+=B*f+k*c+L*a+v*(5*y)+H*(5*g),I+=q>>>13,q&=8191;let z=I+_*g+C*w+F*d+M*p+j*h;I=z>>>13,z&=8191,z+=B*u+k*f+L*c+v*a+H*(5*y),I+=z>>>13,z&=8191;let V=I+_*y+C*g+F*w+M*d+j*p;I=V>>>13,V&=8191,V+=B*h+k*u+L*f+v*c+H*a,I+=V>>>13,V&=8191,I=(I<<2)+I|0,I=I+S|0,S=I&8191,I=I>>>13,l+=I,o[0]=S,o[1]=l,o[2]=m,o[3]=A,o[4]=D,o[5]=U,o[6]=P,o[7]=q,o[8]=z,o[9]=V}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;Pe(n)}update(e){$o(this),ue(e),e=rr(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,Pe(this.h,this.r,this.buffer,this.pad)}digestInto(e){$o(this),mc(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}},Bc=wc(32,t=>new Wo(t));function il(t,e,r,n,s,o=20){let i=t[0],a=t[1],c=t[2],f=t[3],u=e[0],h=e[1],p=e[2],d=e[3],w=e[4],g=e[5],y=e[6],x=e[7],E=s,b=r[0],R=r[1],T=r[2],O=i,N=a,K=c,_=f,C=u,F=h,M=p,j=d,B=w,k=g,L=y,v=x,H=E,I=b,S=R,l=T;for(let A=0;A<o;A+=2)O=O+C|0,H=W(H^O,16),B=B+H|0,C=W(C^B,12),O=O+C|0,H=W(H^O,8),B=B+H|0,C=W(C^B,7),N=N+F|0,I=W(I^N,16),k=k+I|0,F=W(F^k,12),N=N+F|0,I=W(I^N,8),k=k+I|0,F=W(F^k,7),K=K+M|0,S=W(S^K,16),L=L+S|0,M=W(M^L,12),K=K+M|0,S=W(S^K,8),L=L+S|0,M=W(M^L,7),_=_+j|0,l=W(l^_,16),v=v+l|0,j=W(j^v,12),_=_+j|0,l=W(l^_,8),v=v+l|0,j=W(j^v,7),O=O+F|0,l=W(l^O,16),L=L+l|0,F=W(F^L,12),O=O+F|0,l=W(l^O,8),L=L+l|0,F=W(F^L,7),N=N+M|0,H=W(H^N,16),v=v+H|0,M=W(M^v,12),N=N+M|0,H=W(H^N,8),v=v+H|0,M=W(M^v,7),K=K+j|0,I=W(I^K,16),B=B+I|0,j=W(j^B,12),K=K+j|0,I=W(I^K,8),B=B+I|0,j=W(j^B,7),_=_+C|0,S=W(S^_,16),k=k+S|0,C=W(C^k,12),_=_+C|0,S=W(S^_,8),k=k+S|0,C=W(C^k,7);let m=0;n[m++]=i+O|0,n[m++]=a+N|0,n[m++]=c+K|0,n[m++]=f+_|0,n[m++]=u+C|0,n[m++]=h+F|0,n[m++]=p+M|0,n[m++]=d+j|0,n[m++]=w+B|0,n[m++]=g+k|0,n[m++]=y+L|0,n[m++]=x+v|0,n[m++]=E+H|0,n[m++]=b+I|0,n[m++]=R+S|0,n[m++]=T+l|0}var al=vc(il,{counterRight:!1,counterLength:4,allowShortKeys:!1});var cl=new Uint8Array(16),Lc=(t,e)=>{t.update(e);let r=e.length%16;r&&t.update(cl.subarray(r))},fl=new Uint8Array(32);function Ic(t,e,r,n,s){s!==void 0&&ue(s,void 0,"AAD");let o=t(e,r,fl),i=Ec(n.length,s?s.length:0,!0),a=Bc.create(o);s&&Lc(a,s),Lc(a,n),a.update(i);let c=a.digest();return Pe(o,i),c}var ul=t=>(e,r,n)=>({encrypt(o,i){let a=o.length;i=Ur(a+16,i,!1),i.set(o);let c=i.subarray(0,-16);t(e,r,c,c,1);let f=Ic(t,e,r,c,n);return i.set(f,a),Pe(f),i},decrypt(o,i){i=Ur(o.length-16,i,!1);let a=o.subarray(0,-16),c=o.subarray(-16),f=Ic(t,e,r,a,n);if(!bc(c,f))throw Pe(f),new Error("invalid tag");return i.set(o.subarray(0,-16)),t(e,r,i,i,1),Pe(f),i}}),Go=xc({blockSize:64,nonceLength:12,tagLength:16,withAAD:!0},ul(al));function Tc(t,e,r){return xt(t),r===void 0&&(r=new Uint8Array(t.outputLen)),Cr(t,r,e)}var Mr=Uint8Array.of(0),hl=Uint8Array.of();function _c(t,e,r,n=32,s){xt(t),Oe(n,"length"),Ee(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=hl:Ee(r,void 0,"info"),!i)return s&&_e(e),new Uint8Array;let a=s&&i===1?e:new Uint8Array(i*o),{iHash:c,oHash:f}=Cr.create(t,e),u=s?e:new Uint8Array(o),h=i>1?s?.iHash||t.create():void 0;for(let d=0;d<i-1;d++){Mr[0]=d+1;let w=c._cloneInto(h);d&&w.update(u),w.update(r).update(Mr).digestInto(u),f._cloneInto(h).update(u).digestInto(u),a.set(u,o*d)}if(Mr[0]=i,i>1&&c.update(u),c.update(r).update(Mr).digestInto(u),f.update(u).digestInto(u),a.set(u,o*(i-1)),c.destroy(),f.destroy(),h?.destroy(),u!==a&&_e(u),_e(Mr),n===a.length)return a;let p=a.slice(0,n);return _e(a),p}var Wn={hashSHA256(t){return He(t.subarray())},getHKDF(t,e){let r=Tc(He,e,t),s=_c(He,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=vr.utils.randomSecretKey();return{publicKey:vr.getPublicKey(t),privateKey:t}},generateX25519KeyPairFromSeed(t){return{publicKey:vr.getPublicKey(t),privateKey:t}},generateX25519SharedKey(t,e){return vr.getSharedSecret(t.subarray(),e.subarray())},chaCha20Poly1305Encrypt(t,e,r,n){return Go(n,e,r).encrypt(t.subarray())},chaCha20Poly1305Decrypt(t,e,r,n,s){return Go(n,e,r).decrypt(t.subarray(),s)}};var Rc=Wn;function Cc(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 nr=t=>{let e=pe(2);return e[0]=t>>8,e[1]=t,e};nr.bytes=2;var sr=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)};sr.bytes=2;function Dc(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 Zo(t,e){!e.enabled||!tr||(t?(e(`LOCAL_STATIC_PUBLIC_KEY ${Z(t.publicKey,"hex")}`),e(`LOCAL_STATIC_PRIVATE_KEY ${Z(t.privateKey,"hex")}`)):e("Missing local static keys."))}function Xo(t,e){!e.enabled||!tr||(t?(e(`LOCAL_PUBLIC_EPHEMERAL_KEY ${Z(t.publicKey,"hex")}`),e(`LOCAL_PRIVATE_EPHEMERAL_KEY ${Z(t.privateKey,"hex")}`)):e("Missing local ephemeral keys."))}function Oc(t,e){!e.enabled||!tr||e(t?`REMOTE_STATIC_PUBLIC_KEY ${Z(t.subarray(),"hex")}`:"Missing remote static public key.")}function Jo(t,e){!e.enabled||!tr||e(t?`REMOTE_EPHEMERAL_PUBLIC_KEY ${Z(t.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function Qo(t,e,r){!r.enabled||!tr||(r(`CIPHER_STATE_1 ${t.n.getUint64()} ${t.k&&Z(t.k,"hex")}`),r(`CIPHER_STATE_2 ${e.n.getUint64()} ${e.k&&Z(e.k,"hex")}`))}var or=class t extends Error{code;constructor(e="Invalid crypto exchange"){super(e),this.code=t.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var ll=0,dl=4294967295,pl="Cipherstate has reached maximum n, a new handshake must be performed",Gn=class{n;bytes;view;constructor(e=ll){this.n=e,this.bytes=he(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>dl)throw new Error(pl)}};var Ot=he(0),ir=class{k;n;crypto;constructor(e,r=void 0,n=0){this.crypto=e,this.k=r,this.n=new Gn(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}},ei=class{cs;ck;h;crypto;constructor(e,r){this.crypto=e;let n=re(r,"utf-8");this.h=ml(e,n),this.ck=this.h,this.cs=new ir(e)}mixKey(e){let[r,n]=this.crypto.hkdf(this.ck,e);this.ck=r,this.cs=new ir(this.crypto,n)}mixHash(e){this.h=this.crypto.hash(new G(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,Ot);return[new ir(this.crypto,e),new ir(this.crypto,r)]}},ti=class{ss;s;e;rs;re;initiator;crypto;constructor(e){let{crypto:r,protocolName:n,prologue:s,initiator:o,s:i,e:a,rs:c,re:f}=e;this.crypto=r,this.ss=new ei(r,n),this.ss.mixHash(s),this.initiator=o,this.s=i,this.e=a,this.rs=c,this.re=f}writeE(){if(this.e)throw new Error("ephemeral keypair is already set");let e=this.crypto.generateKeypair();return this.ss.mixHash(e.publicKey),this.e=e,e.publicKey}writeS(){if(!this.s)throw new Error("static keypair is not set");return this.ss.encryptAndHash(this.s.publicKey)}writeEE(){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.re))}writeES(){if(this.initiator){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}else{if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}}writeSE(){if(this.initiator){if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}else{if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}}readE(e,r=0){if(this.re)throw new Error("remote ephemeral public key is already set");if(e.byteLength<r+32)throw new Error("message is not long enough");this.re=e.sublist(r,r+32),this.ss.mixHash(this.re)}readS(e,r=0){if(this.rs)throw new Error("remote static public key is already set");let n=32+(this.ss.cs.hasKey()?16:0);if(e.byteLength<r+n)throw new Error("message is not long enough");let s=e.sublist(r,r+n);return this.rs=this.ss.decryptAndHash(s),n}readEE(){this.writeEE()}readES(){this.writeES()}readSE(){this.writeSE()}},Fr=class extends ti{writeMessageA(e){return new G(this.writeE(),this.ss.encryptAndHash(e))}writeMessageB(e){let r=this.writeE();this.writeEE();let n=this.writeS();return this.writeES(),new G(r,n,this.ss.encryptAndHash(e))}writeMessageC(e){let r=this.writeS();return this.writeSE(),new G(r,this.ss.encryptAndHash(e))}readMessageA(e){try{return this.readE(e),this.ss.decryptAndHash(e.sublist(32))}catch(r){throw new or(`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 or(`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 or(`handshake stage 2 validation fail: ${r.message}`)}}};function ml(t,e){if(e.length<=32){let r=he(32);return r.set(e),r}else return t.hash(e)}var Hr;(function(t){let e;t.codec=()=>(e==null&&(e=Tt((o,i,a={})=>{if(a.lengthDelimited!==!1&&i.fork(),o.webtransportCerthashes!=null&&o.webtransportCerthashes.length>0)for(let c of o.webtransportCerthashes)i.uint32(10),i.bytes(c);if(o.streamMuxers!=null&&o.streamMuxers.length>0)for(let c of o.streamMuxers)i.uint32(18),i.string(c);a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={webtransportCerthashes:[],streamMuxers:[]},f=i==null?o.len:o.pos+i;for(;o.pos<f;){let u=o.uint32();switch(u>>>3){case 1:{if(a.limits?.webtransportCerthashes!=null&&c.webtransportCerthashes.length===a.limits.webtransportCerthashes)throw new _t('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 _t('Decode error - repeated field "streamMuxers" had too many elements');c.streamMuxers.push(o.string());break}default:{o.skipType(u&7);break}}}return c},function*(o,i,a,c={}){let f={webtransportCerthashes:0,streamMuxers:0},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let h=o.uint32();switch(h>>>3){case 1:{if(c.limits?.webtransportCerthashes!=null&&f.webtransportCerthashes===c.limits.webtransportCerthashes)throw new _t('Streaming decode error - repeated field "webtransportCerthashes" had too many elements');yield{field:`${a}.webtransportCerthashes[]`,index:f.webtransportCerthashes,value:o.bytes()},f.webtransportCerthashes++;break}case 2:{if(c.limits?.streamMuxers!=null&&f.streamMuxers===c.limits.streamMuxers)throw new _t('Streaming decode error - repeated field "streamMuxers" had too many elements');yield{field:`${a}.streamMuxers[]`,index:f.streamMuxers,value:o.string()},f.streamMuxers++;break}default:{o.skipType(h&7);break}}}})),e);function r(o){return Lt(o,t.codec())}t.encode=r;function n(o,i){return vt(o,t.codec(),i)}t.decode=n;function s(o,i){return It(o,t.codec(),i)}t.stream=s})(Hr||(Hr={}));var qr;(function(t){let e;t.codec=()=>(e==null&&(e=Tt((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),Hr.codec().encode(o.extensions,i)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={identityKey:he(0),identitySig:he(0)},f=i==null?o.len:o.pos+i;for(;o.pos<f;){let u=o.uint32();switch(u>>>3){case 1:{c.identityKey=o.bytes();break}case 2:{c.identitySig=o.bytes();break}case 4:{c.extensions=Hr.codec().decode(o,o.uint32(),{limits:a.limits?.extensions});break}default:{o.skipType(u&7);break}}}return c},function*(o,i,a,c={}){let f=i==null?o.len:o.pos+i;for(;o.pos<f;){let u=o.uint32();switch(u>>>3){case 1:{yield{field:`${a}.identityKey`,value:o.bytes()};break}case 2:{yield{field:`${a}.identitySig`,value:o.bytes()};break}case 4:{yield*Hr.codec().stream(o,o.uint32(),`${a}.extensions`,{limits:c.limits?.extensions});break}default:{o.skipType(u&7);break}}}})),e);function r(o){return Lt(o,t.codec())}t.encode=r;function n(o,i){return vt(o,t.codec(),i)}t.decode=n;function s(o,i){return It(o,t.codec(),i)}t.stream=s})(qr||(qr={}));async function ni(t,e,r){let n=await t.sign(Kc(e));return qr.encode({identityKey:nt(t.publicKey),identitySig:n,extensions:r})}async function si(t,e,r){try{let n=qr.decode(t),s=Dr(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=Kc(e);if(!await s.verify(o,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new zr(n.message)}}function Kc(t){let e=re("noise-libp2p-static-key:");return t instanceof Uint8Array?gt([e,t],e.length+t.length):(t.prepend(e),t)}var ri=class extends zn{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 Vn({lengthDecoder:sr,maxBufferSize:16*1024*1024,encodingLength:()=>2});let s=c=>{try{for(let f of this.decoder.decode(c.data))this.onData(this.decrypt(f))}catch(f){this.abort(f)}};this.stream.addEventListener("message",s);let o=c=>{c.error!=null?c.local===!0?this.abort(c.error):this.onRemoteReset():this.onTransportClosed()};this.stream.addEventListener("close",o);let i=()=>{this.safeDispatchEvent("drain")};this.stream.addEventListener("drain",i);let a=()=>{this.onRemoteCloseWrite()};this.stream.addEventListener("remoteCloseWrite",a)}encrypt(e){let r=new G;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(nr(o.byteLength)),r.append(o)}return r}decrypt(e){let r=new G;for(let n=0;n<e.byteLength;n+=65535){let s=n+65535;if(s>e.byteLength&&(s=e.byteLength),s-jo<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-jo);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 oi(t,e,r){return new ri(t,e,r)}async function Uc(t,e){let{log:r,connection:n,crypto:s,privateKey:o,prologue:i,s:a,remoteIdentityKey:c,extensions:f}=t,u=await ni(o,a.publicKey,f),h=new Fr({crypto:s,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:i,s:a});Zo(h.s,r),r.trace("Stage 0 - Initiator starting to send first message."),await n.write(h.writeMessageA(Ot),e),r.trace("Stage 0 - Initiator finished sending first message."),Xo(h.e,r),r.trace("Stage 1 - Initiator waiting to receive first message from responder...");let p=h.readMessageB(await n.read(e));r.trace("Stage 1 - Initiator received the message."),Jo(h.re,r),Oc(h.rs,r),r.trace("Initiator going to check remote's signature...");let d=await si(p,h.rs,c);r.trace("All good with the signature!"),r.trace("Stage 2 - Initiator sending third handshake message."),await n.write(h.writeMessageC(u),e),r.trace("Stage 2 - Initiator sent message with signed payload.");let[w,g]=h.ss.split();return Qo(w,g,r),{payload:d,encrypt:y=>w.encryptWithAd(Ot,y),decrypt:(y,x)=>g.decryptWithAd(Ot,y,x)}}async function Pc(t,e){let{log:r,connection:n,crypto:s,privateKey:o,prologue:i,s:a,remoteIdentityKey:c,extensions:f}=t,u=await ni(o,a.publicKey,f),h=new Fr({crypto:s,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:i,s:a});Zo(h.s,r),r.trace("Stage 0 - Responder waiting to receive first message."),h.readMessageA(await n.read(e)),r.trace("Stage 0 - Responder received first message."),Jo(h.re,r),r.trace("Stage 1 - Responder sending out first message with signed payload and static key."),await n.write(h.writeMessageB(u),e),r.trace("Stage 1 - Responder sent the second handshake message with signed payload."),Xo(h.e,r),r.trace("Stage 2 - Responder waiting for third handshake message...");let p=h.readMessageC(await n.read(e));r.trace("Stage 2 - Responder received the message, finished handshake.");let d=await si(p,h.rs,c),[w,g]=h.ss.split();return Qo(w,g,r),{payload:d,encrypt:y=>g.encryptWithAd(Ot,y),decrypt:(y,x)=>w.decryptWithAd(Ot,y,x)}}var Xn=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??Rc;this.crypto=Cc(c),this.extensions={webtransportCerthashes:[],...s},this.metrics=a?Dc(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=i??he(0)}[Symbol.toStringTag]="@libp2p/noise";[ai]=["@libp2p/connection-encryption","@libp2p/noise"];async secureOutbound(e,r){let n=e.log?.newScope("noise")??this.log,s=zo(e,{lengthEncoder:nr,lengthDecoder:sr,maxDataLength:65535}),o=await this.performHandshakeInitiator(s,this.components.privateKey,n,r?.remotePeer?.publicKey,r),i=Dr(o.payload.identityKey);return{connection:oi(s.unwrap(),o,this.metrics),remoteExtensions:o.payload.extensions,remotePeer:Uo(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 jr("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=zo(e,{lengthEncoder:nr,lengthDecoder:sr,maxDataLength:65535}),o=await this.performHandshakeResponder(s,this.components.privateKey,n,r?.remotePeer?.publicKey,r),i=Dr(o.payload.identityKey);return{connection:oi(s.unwrap(),o,this.metrics),remoteExtensions:o.payload.extensions,remotePeer:Uo(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 Uc({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 Pc({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 yl(t={}){return e=>new Xn(e,t)}return Vc(gl);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/curves/utils.js:
|