@libp2p/webtransport 6.0.38-5cb617ae2 → 6.0.39-d91797b55
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 +10 -10
package/dist/index.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PWebtransport = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PWebtransport=(()=>{var Zs=Object.defineProperty;var tl=Object.getOwnPropertyDescriptor;var rl=Object.getOwnPropertyNames;var nl=Object.prototype.hasOwnProperty;var Re=(t,e)=>{for(var r in e)Zs(t,r,{get:e[r],enumerable:!0})},sl=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of rl(e))!nl.call(t,s)&&s!==r&&Zs(t,s,{get:()=>e[s],enumerable:!(n=tl(e,s))||n.enumerable});return t};var ol=t=>sl(Zs({},"__esModule",{value:!0}),t);var ym={};Re(ym,{webTransport:()=>mm});var Bn=class extends Error{static name="UnexpectedPeerError";constructor(e="Unexpected Peer"){super(e),this.name="UnexpectedPeerError"}},or=class extends Error{static name="InvalidCryptoExchangeError";constructor(e="Invalid crypto exchange"){super(e),this.name="InvalidCryptoExchangeError"}},se=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},ir=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var _n=class extends Error{static name="MuxerClosedError";constructor(e="The muxer is closed"){super(e),this.name="MuxerClosedError"}},Ln=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var yt=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},Ot=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var Tn=class extends Error{static name="InvalidMultiaddrError";constructor(e="Invalid multiaddr"){super(e),this.name="InvalidMultiaddrError"}},Cn=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},In=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Pt=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Dn=class extends Event{data;constructor(e,r){super("message",r),this.data=e}},ar=class extends Event{error;local;constructor(e,r,n){super("close",n),this.error=r,this.local=e}},Rn=class extends ar{constructor(e,r){super(!0,e,r)}},On=class extends ar{constructor(e,r){super(!1,e,r)}};var Xs=Symbol.for("@libp2p/peer-id");var za=Symbol.for("@libp2p/transport");var qa;(function(t){t[t.FATAL_ALL=0]="FATAL_ALL",t[t.NO_FATAL=1]="NO_FATAL"})(qa||(qa={}));function il(t){return typeof t?.handleEvent=="function"}function al(t){return t===!0||t===!1}function cl(t){return al(t)?t:t?.capture??!1}function Qs(t){let e={capture:cl(t),once:!!t?.once};return t?.passive!=null&&(e.passive=t?.passive),t?.signal!=null&&(e.signal=t?.signal),e}function $a(t,e){return Qs(t).capture===Qs(e).capture}var cr=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){let s=Qs(n);if(s?.signal?.aborted===!0)return;let o=u=>{s.once&&this.removeEventListener(e,r,s),il(r)?r.handleEvent(u):r(u)},i=this.#e.get(e);if(i==null&&(i=[],this.#e.set(e,i)),i.some(u=>u.callback!==r?!1:$a(u.options,s)))return;super.addEventListener(e,o,s);let c=()=>{this.removeEventListener(e,r,s)};s.signal?.addEventListener("abort",c),i.push({callback:r,wrapper:o,options:s,onAbort:c})}removeEventListener(e,r,n){let s=this.#e.get(e);if(s==null){super.removeEventListener(e,r??null,n);return}this.#e.set(e,s.filter(o=>o.callback===r&&$a(o.options,n)?(super.removeEventListener(e,o.wrapper,n),o.options?.signal?.removeEventListener("abort",o.onAbort),!1):!0))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var Pn=Symbol.for("@libp2p/service-capabilities");var no={};Re(no,{base58btc:()=>me,base58flickr:()=>yl});var Ym=new Uint8Array(0);function ja(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Me(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return Ut(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return Ut(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function Wa(t){let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}var Va=4096;function Ya(t){let e=t.length;if(e<=Va)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.subarray(n,n+=Va));return r}function ul(t){return t?.buffer instanceof ArrayBuffer}function Ut(t){return ul(t)?t:t.slice()}function fl(t,e,r){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),s=0;s<n.length;s++)n[s]=255;for(var o=0;o<t.length;o++){var i=t.charAt(o),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=o,r){var c=i.toLowerCase().charCodeAt(0),u=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=o),u!==a&&(n[u]=o)}}var f=t.length,l=t.charAt(0),d=Math.log(f)/Math.log(256),p=Math.log(256)/Math.log(f);function g(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var E=0,w=0,I=0,T=x.length;I!==T&&x[I]===0;)I++,E++;for(var O=(T-I)*p+1>>>0,M=new Uint8Array(O);I!==T;){for(var U=x[I],C=0,D=O-1;(U!==0||C<w)&&D!==-1;D--,C++)U+=256*M[D]>>>0,M[D]=U%f>>>0,U=U/f>>>0;if(U!==0)throw new Error("Non-zero carry");w=C,I++}for(var F=O-w;F!==O&&M[F]===0;)F++;for(var K=l.repeat(E);F<O;++F)K+=t.charAt(M[F]);return K}function b(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var E=0;if(x[E]!==" "){for(var w=0,I=0;x[E]===l;)w++,E++;for(var T=(x.length-E)*d+1>>>0,O=new Uint8Array(T);x[E];){var M=n[x.charCodeAt(E)];if(M===255)return;for(var U=0,C=T-1;(M!==0||U<I)&&C!==-1;C--,U++)M+=f*O[C]>>>0,O[C]=M%256>>>0,M=M/256>>>0;if(M!==0)throw new Error("Non-zero carry");I=U,E++}if(x[E]!==" "){for(var D=T-I;D!==T&&O[D]===0;)D++;for(var F=new Uint8Array(w+(T-D)),K=w;D!==T;)F[K++]=O[D++];return F}}}function y(x){var E=b(x);if(E)return E;throw new Error(`Non-${e} character`)}return{encode:g,decodeUnsafe:b,decode:y}}var ll=fl,hl=ll,Za=hl;var Js=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},eo=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let s=r.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Xa(this,e)}},to=class{decoders;constructor(e){this.decoders=e}or(e){return Xa(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Xa(t,e){return new to({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var ro=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,s){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=s,this.encoder=new Js(e,r,n),this.decoder=new eo(e,r,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ur({name:t,prefix:e,encode:r,decode:n}){return new ro(t,e,r,n)}function gt({name:t,prefix:e,alphabet:r,caseInsensitive:n=!1}){let{encode:s,decode:o}=Za(r,t,n);return ur({prefix:e,name:t,encode:s,decode:i=>Me(o(i))})}function dl(t,e,r,n){let s=t.length;for(;t[s-1]==="=";)--s;let o=new Uint8Array(s*r/8|0),i=0,a=0,c=0;for(let u=0;u<s;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,o[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return o}function pl(t,e,r){let n=e[e.length-1]==="=",s=(1<<r)-1,o="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,o+=e[s&a>>i];if(i!==0&&(o+=e[s&a<<r-i]),n)for(;(o.length*r&7)!==0;)o+="=";return o}function ml(t,e){let r={};for(let n=0;n<t.length;++n)if(r[t[n]]=n,e){let s=t[n].toLowerCase(),o=t[n].toUpperCase();s!==t[n]&&(r[s]=n),o!==t[n]&&(r[o]=n)}return r}function pe({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:s=!1}){let o=ml(n,s);return ur({prefix:e,name:t,encode(i){return pl(i,n,r)},decode(i){return dl(i,o,r,t)}})}var me=gt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),yl=gt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var so={};Re(so,{base32:()=>bt,base32hex:()=>xl,base32hexpad:()=>Sl,base32hexpadupper:()=>vl,base32hexupper:()=>El,base32pad:()=>bl,base32padupper:()=>wl,base32upper:()=>gl,base32z:()=>Al});var bt=pe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),gl=pe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),bl=pe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),wl=pe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),xl=pe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),El=pe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),Sl=pe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),vl=pe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),Al=pe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var oo={};Re(oo,{base36:()=>kr,base36upper:()=>Bl});var kr=gt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),Bl=gt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var ot={};Re(ot,{Digest:()=>Nt,create:()=>Ve,decode:()=>hr,equals:()=>ao,hasCode:()=>$l});var _l=ec,Qa=128,Ll=127,Tl=~Ll,Cl=Math.pow(2,31);function ec(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Cl;)e[r++]=t&255|Qa,t/=128;for(;t&Tl;)e[r++]=t&255|Qa,t>>>=7;return e[r]=t|0,ec.bytes=r-n+1,e}var Il=io,Dl=128,Ja=127;function io(t,n){var r=0,n=n||0,s=0,o=n,i,a=t.length;do{if(o>=a)throw io.bytes=0,new RangeError("Could not decode varint");i=t[o++],r+=s<28?(i&Ja)<<s:(i&Ja)*Math.pow(2,s),s+=7}while(i>=Dl);return io.bytes=o-n,r}var Rl=Math.pow(2,7),Ol=Math.pow(2,14),Pl=Math.pow(2,21),Ul=Math.pow(2,28),Nl=Math.pow(2,35),kl=Math.pow(2,42),Ml=Math.pow(2,49),Kl=Math.pow(2,56),Fl=Math.pow(2,63),Hl=function(t){return t<Rl?1:t<Ol?2:t<Pl?3:t<Ul?4:t<Nl?5:t<kl?6:t<Ml?7:t<Kl?8:t<Fl?9:10},ql={encode:_l,decode:Il,encodingLength:Hl},zl=ql,Mr=zl;function Kr(t,e=0){let r=Mr.decode(t,e),n=Mr.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&t[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function fr(t,e,r=0){return Mr.encode(t,e,r),e}function lr(t){return Mr.encodingLength(t)}function Ve(t,e){let r=e.byteLength,n=lr(t),s=n+lr(r),o=new Uint8Array(s+r);return fr(t,o,0),fr(r,o,n),o.set(e,s),new Nt(t,r,e,o)}function hr(t){let e=Me(t),[r,n]=Kr(e),[s,o]=Kr(e.subarray(n)),i=e.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new Nt(r,s,i,e)}function ao(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&ja(t.bytes,r.bytes)}}var Nt=class{code;size;digest;bytes;constructor(e,r,n,s){this.code=e,this.size=r,this.digest=Ut(n),this.bytes=Ut(s)}};function $l(t,e){return t.code===e}function tc(t,e){let{bytes:r,version:n}=t;return n===0?jl(r,co(t),e??me.encoder):Wl(r,co(t),e??bt.encoder)}var rc=new WeakMap;function co(t){let e=rc.get(t);if(e==null){let r=new Map;return rc.set(t,r),r}return e}var we=class t{code;version;multihash;bytes;"/";constructor(e,r,n,s){this.code=r,this.version=e,this.multihash=n,this.bytes=Ut(s),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==Fr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Yl)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=Ve(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&ao(e.multihash,n.multihash)}toString(e){return tc(this,e)}toJSON(){return{"/":tc(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:s,multihash:o,bytes:i}=r;return new t(n,s,o,i??nc(n,s,o.bytes))}else if(r[Gl]===!0){let{version:n,multihash:s,code:o}=r,i=hr(s);return t.create(n,o,i)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==Fr)throw new Error(`Version 0 CID must use dag-pb (code: ${Fr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let s=nc(e,r,n.bytes);return new t(e,r,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Fr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,s=Me(e.subarray(n,n+r.multihashSize));if(s.byteLength!==r.multihashSize)throw new Error("Incorrect length");let o=s.subarray(r.multihashSize-r.digestSize),i=new Nt(r.multihashCode,r.digestSize,o,s);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[l,d]=Kr(e.subarray(r));return r+=d,l},s=n(),o=Fr;if(s===18?(s=0,r=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,s]=Vl(e,r),o=t.decode(s);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return co(o).set(n,e),o}};function Vl(t,e){switch(t[0]){case"Q":{let r=e??me;return[me.prefix,r.decode(`${me.prefix}${t}`)]}case me.prefix:{let r=e??me;return[me.prefix,r.decode(t)]}case bt.prefix:{let r=e??bt;return[bt.prefix,r.decode(t)]}case kr.prefix:{let r=e??kr;return[kr.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function jl(t,e,r){let{prefix:n}=r;if(n!==me.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let s=e.get(n);if(s==null){let o=r.encode(t).slice(1);return e.set(n,o),o}else return s}function Wl(t,e,r){let{prefix:n}=r,s=e.get(n);if(s==null){let o=r.encode(t);return e.set(n,o),o}else return s}var Fr=112,Yl=18;function nc(t,e,r){let n=lr(t),s=n+lr(e),o=new Uint8Array(s+r.byteLength);return fr(t,o,0),fr(e,o,n),o.set(r,s),o}var Gl=Symbol.for("@ipld/js-cid/CID");var uo={};Re(uo,{identity:()=>je});var sc=0,Zl="identity",oc=Me;function Xl(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return Ve(sc,oc(t))}var je={code:sc,name:Zl,encode:oc,digest:Xl};function xe(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Ql(t){return t.buffer instanceof ArrayBuffer}function Ae(t){return Ql(t)?t:t.slice()}async function ic(t,e,r,n){let s=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let o=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},s,Ae(e),Ae(r.subarray()));return n?.signal?.throwIfAborted(),o}function be(t=0){return new Uint8Array(t)}function Se(t=0){return new Uint8Array(t)}function Jl(t){return t?.buffer instanceof ArrayBuffer}function fo(t){if(Jl(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function Ke(t,e){e==null&&(e=t.reduce((s,o)=>s+o.length,0));let r=Se(e),n=0;for(let s of t)r.set(s,n),n+=s.length;return fo(r)}var cc=Symbol.for("@achingbrain/uint8arraylist");function ac(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let s=r+n.byteLength;if(e<s)return{buf:n,index:e-r};r=s}throw new RangeError("index is out of bounds")}function Nn(t){return!!t?.[cc]}var Q=class t{bufs;length;[cc]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Nn(n)){r+=n.byteLength;for(let s of n.bufs)this.bufs.push(s)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Nn(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(e){let r=ac(this.bufs,e);return r.buf[r.index]}set(e,r){let n=ac(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(Nn(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:s}=this._subList(e,r);return Ke(n,s)}subarray(e,r){let{bufs:n,length:s}=this._subList(e,r);return n.length===1?n[0]:Ke(n,s)}sublist(e,r){let{bufs:n,length:s}=this._subList(e,r),o=new t;return o.length=s,o.bufs=n,o}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],s=0;for(let o=0;o<this.bufs.length;o++){let i=this.bufs[o],a=s,c=a+i.byteLength;if(s=c,e>=c)continue;let u=e>=a&&e<c,f=r>a&&r<=c;if(u&&f){if(e===a&&r===c){n.push(i);break}let l=e-a;n.push(i.subarray(l,l+(r-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!Nn(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let o=256,i=new Int32Array(o);for(let l=0;l<o;l++)i[l]=-1;for(let l=0;l<s;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let d=u;d>=0;d--){let p=this.get(l+d);if(n[d]!==p){f=Math.max(1,d-a[p]);break}}if(f===0)return l}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=Se(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let s=be(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,r,n),this.write(s,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let s=be(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,r,n),this.write(s,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let s=be(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,r,n),this.write(s,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=Se(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let s=be(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,r,n),this.write(s,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let s=be(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,r,n),this.write(s,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let s=be(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,r,n),this.write(s,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let s=be(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,r,n),this.write(s,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let s=be(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,r,n),this.write(s,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!xe(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((s,o)=>s+o.byteLength,0)),n.length=r,n}};var lo={};Re(lo,{base10:()=>eh});var eh=gt({prefix:"9",name:"base10",alphabet:"0123456789"});var ho={};Re(ho,{base16:()=>th,base16upper:()=>rh});var th=pe({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),rh=pe({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var po={};Re(po,{base2:()=>nh});var nh=pe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var mo={};Re(mo,{base256emoji:()=>ch});var uc=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),sh=uc.reduce((t,e,r)=>(t[r]=e,t),[]),oh=uc.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function ih(t){return t.reduce((e,r)=>(e+=sh[r],e),"")}function ah(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let s=oh[n];if(s==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(s)}return new Uint8Array(e)}var ch=ur({prefix:"\u{1F680}",name:"base256emoji",encode:ih,decode:ah});var go={};Re(go,{base64:()=>uh,base64pad:()=>fh,base64url:()=>yo,base64urlpad:()=>lh});var uh=pe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),fh=pe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),yo=pe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),lh=pe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var bo={};Re(bo,{base8:()=>hh});var hh=pe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var wo={};Re(wo,{identity:()=>dh});var dh=ur({prefix:"\0",name:"identity",encode:t=>Ya(Me(t)),decode:t=>Me(Wa(t))});var O0=new TextEncoder,P0=new TextDecoder;var So={};Re(So,{sha256:()=>Hr,sha512:()=>gh});var yh=20;function Eo({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:s}){return new xo(t,e,r,n,s)}var xo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,s,o){this.name=e,this.code=r,this.encode=n,this.minDigestLength=s??yh,this.maxDigestLength=o}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?fc(n,this.code,r?.truncate):n.then(s=>fc(s,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function fc(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return Ve(e,t)}function hc(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Hr=Eo({name:"sha2-256",code:18,encode:hc("SHA-256")}),gh=Eo({name:"sha2-512",code:19,encode:hc("SHA-512")});var kt={...wo,...po,...bo,...lo,...ho,...so,...oo,...no,...go,...mo},j0={...So,...uo};function pc(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var dc=pc("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),vo=pc("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=Se(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),bh={utf8:dc,"utf-8":dc,hex:kt.base16,latin1:vo,ascii:vo,binary:vo,...kt},kn=bh;function ee(t,e="utf8"){let r=kn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function W(t,e="utf8"){let r=kn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var wh=parseInt("11111",2),Ao=parseInt("10000000",2),xh=parseInt("01111111",2),mc={0:qr,1:qr,2:Eh,3:Ah,4:Bh,5:vh,6:Sh,16:qr,22:qr,48:qr};function it(t,e={offset:0}){let r=t[e.offset]&wh;if(e.offset++,mc[r]!=null)return mc[r](t,e);throw new Error("No decoder for tag "+r)}function zr(t,e){let r=0;if((t[e.offset]&Ao)===Ao){let n=t[e.offset]&xh,s="0x";e.offset++;for(let o=0;o<n;o++,e.offset++){if(e.offset>=t.byteLength)throw new Error("invalid DER element length");s+=t[e.offset].toString(16).padStart(2,"0")}r=parseInt(s,16)}else r=t[e.offset],e.offset++;if(!Number.isInteger(r)||r<0||r>t.byteLength-e.offset)throw new Error("invalid DER element length");return r}function qr(t,e){zr(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=it(t,e);if(n===null)break;r.push(n)}return r}function Eh(t,e){let r=zr(t,e),n=e.offset,s=e.offset+r,o=[];for(let i=n;i<s;i++)i===n&&t[i]===0||o.push(t[i]);return e.offset+=r,Uint8Array.from(o)}function Sh(t,e){let r=zr(t,e),n=e.offset+r,s=t[e.offset];e.offset++;let o=0,i=0;s<40?(o=0,i=s):s<80?(o=1,i=s-40):(o=2,i=s-80);let a=`${o}.${i}`,c=[];for(;e.offset<n;){let u=t[e.offset];if(e.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function vh(t,e){return e.offset++,null}function Ah(t,e){let r=zr(t,e),n=t[e.offset];e.offset++;let s=t.subarray(e.offset,e.offset+r-1);if(e.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return s}function Bh(t,e){let r=zr(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function _h(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new Q;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function Bo(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=_h(t.byteLength);return new Q(Uint8Array.from([e.byteLength|Ao]),e)}function Ue(t){let e=new Q,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new Q(Uint8Array.from([2]),Bo(e),e)}function Mn(t){let e=Uint8Array.from([0]),r=new Q(e,t);return new Q(Uint8Array.from([3]),Bo(r),r)}function wt(t,e=48){let r=new Q;for(let n of t)r.append(n);return new Q(Uint8Array.from([e]),Bo(r),r)}var Lh=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Th=Uint8Array.from([6,5,43,129,4,0,34]),Ch=Uint8Array.from([6,5,43,129,4,0,35]),Ih={ext:!0,kty:"EC",crv:"P-256"},Dh={ext:!0,kty:"EC",crv:"P-384"},Rh={ext:!0,kty:"EC",crv:"P-521"},_o=32,Lo=48,To=66;function Co(t){let e=it(t);return yc(e)}function yc(t){let e=t[1][1][0],r=1,n,s;if(e.byteLength===_o*2+1)return n=W(e.subarray(r,r+_o),"base64url"),s=W(e.subarray(r+_o),"base64url"),new dr({...Ih,key_ops:["verify"],x:n,y:s});if(e.byteLength===Lo*2+1)return n=W(e.subarray(r,r+Lo),"base64url"),s=W(e.subarray(r+Lo),"base64url"),new dr({...Dh,key_ops:["verify"],x:n,y:s});if(e.byteLength===To*2+1)return n=W(e.subarray(r,r+To),"base64url"),s=W(e.subarray(r+To),"base64url"),new dr({...Rh,key_ops:["verify"],x:n,y:s});throw new se(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function gc(t){return wt([Ue(Uint8Array.from([1])),wt([Oh(t.crv)],160),wt([Mn(new Q(Uint8Array.from([4]),ee(t.x??"","base64url"),ee(t.y??"","base64url")))],161)]).subarray()}function Oh(t){if(t==="P-256")return Lh;if(t==="P-384")return Th;if(t==="P-521")return Ch;throw new se(`Invalid curve ${t}`)}var dr=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=gc(this.jwk)),this._raw}toMultihash(){return je.digest(xt(this))}toCID(){return we.createV1(114,this.toMultihash())}toString(){return me.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:xe(this.raw,e.raw)}async verify(e,r,n){return ic(this.jwk,r,e,n)}};var Kn=BigInt(4294967295),bc=BigInt(32);function Ph(t,e=!1){return e?{h:Number(t&Kn),l:Number(t>>bc&Kn)}:{h:Number(t>>bc&Kn)|0,l:Number(t&Kn)|0}}function wc(t,e=!1){let r=t.length,n=new Uint32Array(r),s=new Uint32Array(r);for(let o=0;o<r;o++){let{h:i,l:a}=Ph(t[o],e);[n[o],s[o]]=[i,a]}return[n,s]}var Uh=t=>t/2**32|0,Nh=t=>t>>>0;function xc(t,e,r,n){let s=Uh(r),o=Nh(r);t.setUint32(e,n?o:s,n),t.setUint32(e+4,n?s:o,n)}var Io=(t,e,r)=>t>>>r,Do=(t,e,r)=>t<<32-r|e>>>r,Mt=(t,e,r)=>t>>>r|e<<32-r,Kt=(t,e,r)=>t<<32-r|e>>>r,$r=(t,e,r)=>t<<64-r|e>>>r-32,Vr=(t,e,r)=>t>>>r-32|e<<64-r;function Xe(t,e,r,n){let s=(e>>>0)+(n>>>0);return{h:t+r+(s/2**32|0)|0,l:s|0}}var Ec=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Sc=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,vc=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Ac=(t,e,r,n,s)=>e+r+n+s+(t/2**32|0)|0,Bc=(t,e,r,n,s)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(s>>>0),_c=(t,e,r,n,s,o)=>e+r+n+s+o+(t/2**32|0)|0;function Fn(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var Ro=t=>t?`"${t}" `:"";function We(t,e=""){if(typeof t!="number")throw new TypeError(Ro(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(Ro(e)+"expected integer >= 0, got "+t);return t}function Oe(t,e,r=""){if(Fn(t)&&(e===void 0||t.length===e))return t;e!==void 0&&We(e,"length");let n=Fn(t),s=e!==void 0?` of length ${e}`:"",o=n?`length=${t.length}`:`type=${typeof t}`,i=Ro(r)+"expected Uint8Array"+s+", got "+o;throw n?new RangeError(i):new TypeError(i)}function Ft(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(We(t.outputLen),We(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var Mh=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)},Lc=(t,e)=>{Mh(t,e);let r=Object.getPrototypeOf(t);if(r!==Object.prototype&&r!==null)throw new TypeError(`"${e}" expected plain object`);if(Object.hasOwn(t,"__proto__"))throw new TypeError(`"${e}.__proto__" is not allowed`)};function pr(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function Hn(t,e){Oe(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function Fe(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function qn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Ye(t,e){return t<<32-e|t>>>e}var Cc=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Kh=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function zn(t){if(Oe(t),Cc)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=Kh[t[r]];return e}function Tc(t){return t>=48&&t<=57?t-48:t>=65&&t<=70?t-55:t>=97&&t<=102?t-87:void 0}function $n(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(Cc)try{return Uint8Array.fromHex(t)}catch(s){throw s instanceof SyntaxError?new RangeError(s.message):s}let e=t.length,r=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let s=0,o=0;s<r;s++,o+=2){let i=Tc(t.charCodeAt(o)),a=Tc(t.charCodeAt(o+1));if(i===void 0||a===void 0){let c=t[o]+t[o+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+o)}n[s]=i*16+a}return n}function Oo(...t){let e=0;for(let n=0;n<t.length;n++){let s=t[n];Oe(s),e+=s.length}let r=new Uint8Array(e);for(let n=0,s=0;n<t.length;n++){let o=t[n];r.set(o,s),s+=o.length}return r}function Fh(t,e,r="opts"){return Lc(t,"defaults"),e!==void 0&&Lc(e,r),Object.assign(Object.create(null),t,e)}function Po(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=Fh({},e,"info");let r=(s,o)=>t(o).update(s).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=s=>t(s),Object.assign(r,e),Object.freeze(r)}function Ic(t=32){We(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var Uo=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Dc(t,e,r){return t&e^~t&r}function Rc(t,e,r){return t&e^t&r^e&r}var jr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,s){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(e),this.view=qn(this.buffer)}update(e){pr(this),Oe(e);let{view:r,buffer:n,blockLen:s}=this,o=e.length,i=!1;for(let a=0;a<o;){let c=Math.min(s-this.pos,o-a);if(c===s){let u=qn(e);for(;s<=o-a;a+=s)this.process(u,a);i=!0;continue}n.set(a===0&&c===o?e:e.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===s&&(this.process(r,0),this.pos=0,i=!0)}return this.length+=e.length,i&&this.roundClean(),this}digestInto(e){pr(this),Hn(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:s,isLE:o}=this,{pos:i}=this;r[i++]=128,r.fill(0,i),this.padOffset>s-i&&(this.process(n,0),r.fill(0)),xc(n,s-8,this.length*8,o),this.process(n,0),this.roundClean();let a=e===r?n:qn(e),c=this.outputLen,u=c/4,f=this.get();if(c%4||u>f.length)throw new Error("invalid outputLen");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],o)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:r,length:n,finished:s,destroyed:o,pos:i}=this;return e.destroyed=o,e.finished=s,e.length=n,e.pos=i,i&&e.buffer.set(r),e}clone(){return this._cloneInto()}},Oc=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Pc=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Hh=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Et=new Uint32Array(64),No=class extends jr{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(e,r){super(64,e,8,!1),this.A=r[0]|0,this.B=r[1]|0,this.C=r[2]|0,this.D=r[3]|0,this.E=r[4]|0,this.F=r[5]|0,this.G=r[6]|0,this.H=r[7]|0}get(){let{A:e,B:r,C:n,D:s,E:o,F:i,G:a,H:c}=this;return[e,r,n,s,o,i,a,c]}set(e,r,n,s,o,i,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let l=0;l<16;l++,r+=4)Et[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let d=Et[l-15],p=Et[l-2],g=Ye(d,7)^Ye(d,18)^d>>>3,b=Ye(p,17)^Ye(p,19)^p>>>10;Et[l]=b+Et[l-7]+g+Et[l-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let d=Ye(a,6)^Ye(a,11)^Ye(a,25),p=f+d+Dc(a,c,u)+Hh[l]+Et[l]|0,b=(Ye(n,2)^Ye(n,13)^Ye(n,22))+Rc(n,s,o)|0;f=u,u=c,c=a,a=i+p|0,i=o,o=s,s=n,n=p+b|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,s,o,i,a,c,u,f)}roundClean(){Fe(Et)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Fe(this.buffer)}},ko=class extends No{constructor(){super(32,Oc)}};var Uc=wc(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),qh=Uc[0],zh=Uc[1],St=new Uint32Array(80),vt=new Uint32Array(80),Mo=class extends jr{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(e,r){super(128,e,16,!1),this.Ah=r[0]|0,this.Al=r[1]|0,this.Bh=r[2]|0,this.Bl=r[3]|0,this.Ch=r[4]|0,this.Cl=r[5]|0,this.Dh=r[6]|0,this.Dl=r[7]|0,this.Eh=r[8]|0,this.El=r[9]|0,this.Fh=r[10]|0,this.Fl=r[11]|0,this.Gh=r[12]|0,this.Gl=r[13]|0,this.Hh=r[14]|0,this.Hl=r[15]|0}get(){let{Ah:e,Al:r,Bh:n,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:d,Gh:p,Gl:g,Hh:b,Hl:y}=this;return[e,r,n,s,o,i,a,c,u,f,l,d,p,g,b,y]}set(e,r,n,s,o,i,a,c,u,f,l,d,p,g,b,y){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=s|0,this.Ch=o|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=d|0,this.Gh=p|0,this.Gl=g|0,this.Hh=b|0,this.Hl=y|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let w=0;w<16;w++,r+=4)St[w]=e.getUint32(r),vt[w]=e.getUint32(r+=4);for(let w=16;w<80;w++){let I=St[w-15]|0,T=vt[w-15]|0,O=Mt(I,T,1)^Mt(I,T,8)^Io(I,T,7),M=Kt(I,T,1)^Kt(I,T,8)^Do(I,T,7),U=St[w-2]|0,C=vt[w-2]|0,D=Mt(U,C,19)^$r(U,C,61)^Io(U,C,6),F=Kt(U,C,19)^Vr(U,C,61)^Do(U,C,6),K=vc(M,F,vt[w-7],vt[w-16]),$=Ac(K,O,D,St[w-7],St[w-16]);St[w]=$|0,vt[w]=K|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:d,Fh:p,Fl:g,Gh:b,Gl:y,Hh:x,Hl:E}=this;for(let w=0;w<80;w++){let I=Mt(l,d,14)^Mt(l,d,18)^$r(l,d,41),T=Kt(l,d,14)^Kt(l,d,18)^Vr(l,d,41),O=l&p^~l&b,M=d&g^~d&y,U=Bc(E,T,M,zh[w],vt[w]),C=_c(U,x,I,O,qh[w],St[w]),D=U|0,F=Mt(n,s,28)^$r(n,s,34)^$r(n,s,39),K=Kt(n,s,28)^Vr(n,s,34)^Vr(n,s,39),$=n&o^n&a^o&a,B=s&i^s&c^i&c;x=b|0,E=y|0,b=p|0,y=g|0,p=l|0,g=d|0,{h:l,l:d}=Xe(u|0,f|0,C|0,D|0),u=a|0,f=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let P=Ec(D,K,B);n=Sc(P,C,F,$),s=P|0}({h:n,l:s}=Xe(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=Xe(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=Xe(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Xe(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:d}=Xe(this.Eh|0,this.El|0,l|0,d|0),{h:p,l:g}=Xe(this.Fh|0,this.Fl|0,p|0,g|0),{h:b,l:y}=Xe(this.Gh|0,this.Gl|0,b|0,y|0),{h:x,l:E}=Xe(this.Hh|0,this.Hl|0,x|0,E|0),this.set(n,s,o,i,a,c,u,f,l,d,p,g,b,y,x,E)}roundClean(){Fe(St,vt)}destroy(){this.destroyed=!0,Fe(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Ko=class extends Mo{constructor(){super(64,Pc)}};var Qe=Po(()=>new ko,Uo(1));var Fo=Po(()=>new Ko,Uo(3));function jn(t,e,r=()=>{}){if(!Array.isArray(t))throw new TypeError(`"${e}" expected array, got type=${typeof t}`);for(let n=0;n<t.length;n++)r(t[n],`${e}[${n}]`);return t}var Z=(t,e,r)=>Oe(t,e,r),Ho=We;function kc(t,e=""){if(typeof t!="string"){let r=e&&`"${e}" `;throw new TypeError(r+"expected string, got type="+typeof t)}return t}function At(t,e="object"){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof t}`);return t}function Ht(t,e){if(typeof t!="function")throw new TypeError(`"${e}" is invalid: expected function, got ${typeof t}`);return t}var Wr=zn,He=(...t)=>Oo(...t),mr=t=>$n(t),_t=Fn,at=t=>Ic(t),Vn=BigInt(0),Nc=BigInt(1),$h=t=>t?`"${t}" `:"";function Ne(t,e=""){if(typeof t!="boolean")throw new TypeError($h(e)+"expected boolean, got type="+typeof t);return t}function Wn(t){if(typeof t=="bigint"){if(!Bt(t))throw new RangeError("positive bigint expected, got "+t)}else Ho(t);return t}function ct(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(r+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new RangeError(r+"expected safe integer, got "+t)}}function Yr(t){let e=Wn(t).toString(16);return e.length&1?"0"+e:e}function Mc(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?Vn:BigInt("0x"+t)}function Je(t){return Mc(zn(t))}function et(t){return Mc(zn(Lt(Oe(t)).reverse()))}function Yn(t,e){if(We(e),e===0)throw new Error("zero output length is invalid");t=Wn(t);let r=e*2,n=t.toString(16);if(n.length>r)throw new RangeError("number is too large");return $n(n.padStart(r,"0"))}function Gr(t,e){return Yn(t,e).reverse()}function Lt(t){return Uint8Array.from(Z(t))}function Bt(t){return typeof t=="bigint"&&Vn<=t}function qo(t,e,r){return Bt(t)&&Bt(e)&&Bt(r)&&e<=t&&t<r}function tt(t,e,r,n){if(!qo(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function yr(t){if(t<Vn)throw new Error("expected non-negative bigint, got "+t);return t===Vn?0:t.toString(2).length}var Zr=t=>(ct(t,"n"),(Nc<<BigInt(t))-Nc);function Kc(t,e,r){if(We(t,"hashLen"),We(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=y=>new Uint8Array(y),s=Uint8Array.of(),o=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(t),u=n(t),f=0,l=()=>{c.fill(1),u.fill(0),f=0},d=(...y)=>r(u,He(c,...y)),p=(y=s)=>{u=d(o,y),c=d(),y.length!==0&&(u=d(i,y),c=d())},g=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let y=0,x=[];for(;y<e;){c=d();let E=c.slice();x.push(E),y+=c.length}return He(...x)};return(y,x)=>{l(),p(y);let E;for(;(E=x(g()))===void 0;)p();return l(),E}}function Le(t,e={},r={},n="object"){At(t,n),At(e,"fields"),At(r,"optFields");function s(i,a,c){let u=n==="object"?`param "${String(i)}"`:`"${n}.${String(i)}"`,f=t[i];if(!Object.hasOwn(t,i)&&(c?f!==void 0:a!=="function"))throw new TypeError(`${u} is invalid: expected own property`);if(c&&f===void 0)return;let l=typeof f;if(l!==a||f===null)throw new TypeError(`${u} is invalid: expected ${a}, got ${l}`)}let o=(i,a)=>Object.entries(i).forEach(([c,u])=>s(c,u,a));o(e,!1),o(r,!0)}var Ee=BigInt(0),te=BigInt(1),Tt=BigInt(2),qc=BigInt(3),zo=BigInt(4),zc=BigInt(5),Vh=BigInt(7),$c=BigInt(8),jh=BigInt(9),Wh=BigInt(15),Vc=BigInt(16),Yh=BigInt("0x10000000000000000");function ne(t,e){if(e<=Ee)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=Ee?r:e+r}function jc(t,e,r){if(r<=te)throw new Error("pow: expected modulus > 1, got "+r);if(typeof e!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof e);if(e<Ee)throw new Error("invalid exponent, negatives unsupported");if(e===Ee)return te;if(e===te)return t;let n=t%r;if(n<Ee&&(n+=r),e<Yh){let a=te;for(;e>Ee;)e&te&&(a=a*n%r),n=n*n%r,e>>=te;return a}let s=[];for(;e>Ee;)s.push(Number(e&Wh)),e>>=zo;let o=new Array(16);o[0]=te,o[1]=n;for(let a=2;a<16;a++)o[a]=o[a-1]*n%r;let i=o[s[s.length-1]];for(let a=s.length-2;a>=0;a--){i=i*i%r,i=i*i%r,i=i*i%r,i=i*i%r;let c=s[a];c!==0&&(i=i*o[c]%r)}return i}function ue(t,e,r){if(r<=te)throw new Error("pow2: expected modulus > 1, got "+r);if(e<Ee)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >Ee;)n*=n,n%=r;return n}function Fc(t,e){if(t===Ee)throw new Error("invert: expected non-zero number");if(e<=te)throw new Error("invert: expected modulus > 1, got "+e);let r=ne(t,e),n=e,s=Ee,o=te;for(;r!==Ee;){let a=n/r,c=n-r*a,u=s-o*a;n=r,r=c,s=o,o=u}if(n!==te)throw new Error("invert: does not exist");return ne(s,e)}function Wc(t,e){if(e<=te)throw new Error("invertCt: expected prime modulus > 1, got "+e);let r=ne(t,e);if(r===Ee)throw new Error("invertCt: expected non-zero number");let n=jc(r,e-Tt,e);if(ne(r*n,e)!==te)throw new Error("invertCt: does not exist");return n}function $o(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function Vo(t,e){if((t&te)===Ee)throw new Error(e+": expected odd modulus, got "+t)}function Yc(t,e){let r=t,n=(r.ORDER+te)/zo,s=r.pow(e,n);return $o(r,s,e),s}function Gh(t,e){let r=t,n=(r.ORDER-zc)/$c,s=r.mul(e,Tt),o=r.pow(s,n),i=r.mul(e,o),a=r.mul(r.mul(i,Tt),o),c=r.mul(i,r.sub(a,r.ONE));return $o(r,c,e),c}function Zh(t){let e=br(t),r=Gc(t),n=r(e,e.neg(e.ONE)),s=r(e,n),o=r(e,e.neg(n)),i=(t+Vh)/Vc;return((a,c)=>{let u=a,f=u.pow(c,i),l=u.mul(f,n),d=u.mul(f,s),p=u.mul(f,o),g=u.eql(u.sqr(l),c),b=u.eql(u.sqr(d),c);f=u.cmov(f,l,g),l=u.cmov(p,d,b);let y=u.eql(u.sqr(l),c),x=u.cmov(f,l,y);return $o(u,x,c),x})}function Gc(t){if(t<qc)throw new Error("sqrt is not defined for small field");Vo(t,"tonelliShanks");let e=t-te,r=0;for(;e%Tt===Ee;)e/=Tt,r++;let n=Tt,s=br(t);for(;Xr(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Yc;let o=s.pow(n,e),i=(e+te)/Tt;return function(c,u){let f=c;if(f.is0(u))return u;if(Xr(f,u)!==1)throw new Error("Cannot find square root");let l=r,d=f.mul(f.ONE,o),p=f.pow(u,e),g=f.pow(u,i);for(;!f.eql(p,f.ONE);){if(f.is0(p))throw new Error("Cannot find square root: probably non-prime P");let b=1,y=f.sqr(p);for(;!f.eql(y,f.ONE);)if(b++,y=f.sqr(y),b===l)throw new Error("Cannot find square root");let x=te<<BigInt(l-b-1),E=f.pow(d,x);l=b,d=f.sqr(E),p=f.mul(p,d),g=f.mul(g,E)}return g}}function Xh(t){return Vo(t,"Fp.sqrt"),t%zo===qc?Yc:t%$c===zc?Gh:t%Vc===jh?Zh(t):Gc(t)}var Zc=(t,e)=>(ne(t,e)&te)===te,Qh=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function gr(t){if(At(t,"field"),typeof t.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof t.ORDER);ct(t.BYTES,"BYTES"),ct(t.BITS,"BITS");for(let e of Qh)Ht(t[e],"field."+e);if(t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=te)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function Zn(t,e,r=!1){gr(t),jn(e,"nums"),Ne(r,"passZero");let n=t,s=new Array(e.length).fill(r?n.ZERO:void 0),o=e.reduce((a,c,u)=>n.is0(c)?a:(s[u]=a,n.mul(a,c)),n.ONE),i=n.inv(o);return e.reduceRight((a,c,u)=>n.is0(c)?a:(s[u]=n.mul(a,s[u]),n.mul(a,c)),i),s}function Xr(t,e){gr(t);let r=t;Vo(r.ORDER,"FpLegendre");let n=(r.ORDER-te)/Tt,s=r.pow(e,n),o=r.eql(s,r.ONE),i=r.eql(s,r.ZERO),a=r.eql(s,r.neg(r.ONE));if(!o&&!i&&!a)throw new Error("invalid Legendre symbol result");return o?1:i?0:-1}function Jh(t,e){if(e!==void 0&&Ho(e),t<=Ee)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=yr(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected nBitLength (${e}) >= bitLen(n) (${r})`);let n=e!==void 0?e:r,s=Math.ceil(n/8);return{nBitLength:n,nByteLength:s}}var Hc=new WeakMap,Gn=class{ORDER;BITS;BYTES;isLE;ZERO=Ee;ONE=te;_lengths;_mod;constructor(e,r={}){if(e<=te)throw new Error("invalid field: expected ORDER > 1, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:s,nByteLength:o}=Jh(e,n);if(o>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=s,this.BYTES=o,Object.freeze(this)}create(e){return ne(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return Ee<=e&&e<this.ORDER}is0(e){return e===Ee}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&te)===te}neg(e){return ne(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return ne(e*e,this.ORDER)}add(e,r){return ne(e+r,this.ORDER)}sub(e,r){return ne(e-r,this.ORDER)}mul(e,r){return ne(e*r,this.ORDER)}pow(e,r){return jc(e,r,this.ORDER)}div(e,r){return ne(e*Fc(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return Fc(e,this.ORDER)}sqrt(e){let r=Hc.get(this);return r||Hc.set(this,r=Xh(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?Gr(e,this.BYTES):Yn(e,this.BYTES)}fromBytes(e,r=!1){Z(e);let{_lengths:n,BYTES:s,isLE:o,ORDER:i,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>s)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(s);u.set(e,o?0:u.length-e.length),e=u}if(e.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+e.length);let c=o?et(e):Je(e);if(a&&(c=ne(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return Zn(this,e,!0)}cmov(e,r,n){return Ne(n,"condition"),n?r:e}};function br(t,e={}){return Object.freeze(Gn.prototype),new Gn(t,e)}function Xc(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=te)throw new Error("field order must be greater than 1");let e=yr(t-te);return Math.ceil(e/8)}function Xn(t){let e=Xc(t);return e+Math.ceil(e/2)}function Qn(t,e,r=!1){Z(t);let n=t.length,s=Xc(e),o=Math.max(Xn(e),16);if(n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);let i=r?et(t):Je(t),a=ne(i,e-te)+te;return r?Gr(a,s):Yn(a,s)}var Yo=BigInt(0),Qr=BigInt(1),ed=BigInt(4),jo=16,Qc=128,td=5,Jc=2**31;function Ct(t){let e=t;if(typeof e!="function")throw new TypeError('"Point" expected constructor, got type='+typeof t);Ht(e.fromAffine,"Point.fromAffine"),Ht(e.fromBytes,"Point.fromBytes"),Ht(e.fromHex,"Point.fromHex"),At(e.BASE,"Point.BASE"),At(e.ZERO,"Point.ZERO"),gr(e.Fp),gr(e.Fn)}function Jn(t,e){Ct(t),tu(e,t);let r=Zn(t.Fp,e.map(n=>n.Z));return e.map((n,s)=>t.fromAffine(n.toAffine(r[s])))}function rd(t,e,r=1){if(!Number.isSafeInteger(t)||t<r||t>e)throw new Error("invalid window size, expected ["+r+".."+e+"], got W="+t)}function nd(t,e){let r=t*(4*e+128);if(r>Jc)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+Jc/2**20+" MiB")}function Go(t,e){if(t!==void 0){Ht(t,"randomBytes");try{let r=t(e);if(!_t(r)||r.length!==e)return}catch{return}return t}}function tu(t,e){jn(t,"points"),t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function sd(t,e,r){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,s)=>{if(!(r===void 0?e.isValid(n):Bt(n)&&n<r))throw new Error("invalid scalar at index "+s)})}var ru=new WeakMap;function Wo(t){return ru.get(t)||1}function od(t,e){let r=t.double(),n=[t];for(let s=1;s<e;s++)n.push(n[s-1].add(r));return n}function id(t,e){let r=2**e,n=r/2,s=BigInt(r-1),o=[];for(;t>Yo;){let i=0;t&Qr&&(i=Number(t&s),i>=n&&(i-=r),t-=BigInt(i)),o.push(i),t>>=Qr}return o}function ad(t,e,r){let n=2**e,s=n/2,o=BigInt(n-1),i=BigInt(e),a=[];for(let c=0;c<r;c++){let u=Number(t&o);t>>=i,u>s&&(u-=n,t+=Qr),a.push(u)}if(t!==Yo)throw new Error("invalid wnaf");return a}function cd(t,e,r){let n=0;for(let o of r)n=Math.max(n,o.length);let s=t;for(let o=n-1;o>=0;o--){o!==n-1&&(s=s.double());for(let i=0;i<r.length;i++){let a=r[i][o];if(a){let c=e[i][Math.abs(a)-1>>1];s=s.add(a<0?c.negate():c)}}}return s}var wr=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(e,r){Ct(e),this.randomBytes=Go(r,jo),this.Point=e,this.BASE=e.BASE,this.ZERO=e.ZERO,this.bits=e.Fn.BITS}buildWnafTable(e,r,n){let s=Math.ceil(n/r)+1,o=2**(r-1),i=[],a=e;for(let c=0;c<s;c++){let u=a;for(let f=0;f<o;f++)i.push(u),u=u.add(a);a=i[i.length-1].double()}return{W:r,bits:n,windows:s,comp:i}}wnafCachedCT(e,r){let{W:n,windows:s,comp:o}=e,i=2**(n-1),a=ad(r,n,s),c=this.ZERO,u=this.BASE;for(let f=0;f<s;f++){let l=a[f],d=f*i,p=Math.abs(l)-1,g=o[d];for(let y=1;y<i;y++)g=y===p?o[d+y]:g;let b=g.negate();l===0?u=u.add(o[d]):c=c.add(l<0?b:g)}return{p:c,f:u}}getWnafPrecomputes(e,r,n,s){let o=this.wnafPrecomputes.get(r),i=o?.find(a=>a.W===e&&a.bits===n);return i||(i=this.buildWnafTable(r,e,n),typeof s=="function"&&(i={...i,comp:s(i.comp)}),o||(o=[],this.wnafPrecomputes.set(r,o)),o.push(i)),i}assertPoint(e){if(!(e instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof e)}validateMulInput(e,r){if(this.assertPoint(e),!qo(r,Qr,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(e,r,n,s){let o=Wo(e);return o===1?this.fixedWindowCT(e,r,n):this.wnafCachedCT(this.getWnafPrecomputes(o,e,n,s),r)}mulCT(e,r,n){return this.validateMulInput(e,r),this.runCT(e,r,this.bits,n)}mulCTBlinded(e,r,n){if(this.validateMulInput(e,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let s=this.Point.Fn.BITS+Qc,o=this.randomBytes(jo);if(!_t(o)||o.length!==jo)throw new Error("randomBytes returned invalid byte array");o[0]=o[0]&63|128;let i=r+Je(o)*this.Point.Fn.ORDER;return this.runCT(e,i,s,n)}fixedWindowCT(e,r,n){let s=td,o=1<<s,i=Zr(s),a=new Array(o);a[0]=this.ZERO;for(let f=1;f<o;f++)a[f]=a[f-1].add(e);let c=Math.ceil(n/s),u=this.ZERO;for(let f=c-1;f>=0;f--){if(f!==c-1)for(let p=0;p<s;p++)u=u.double();let l=Number(r>>BigInt(f*s)&i),d=a[0];for(let p=1;p<o;p++)d=p===l?a[p]:d;u=u.add(d)}return{p:u,f:u}}shouldBlind(e,r){return this.randomBytes===void 0?!1:r===Qr?!0:e!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(e,r,n,s){return this.shouldBlind(e,n)?this.mulCTBlinded(e,r,s):this.mulCT(e,r,s)}mulUnsafe(e,r,n){if(this.assertPoint(e),!Bt(r))throw new Error("invalid scalar");let s=Wo(e);if(s===1||r>=this.Point.Fn.ORDER)return es(this.Point,[e],[r],!0);let o=this.getWnafPrecomputes(s,e,this.bits,n);return this.wnafCachedCT(o,r).p}setWindowSize(e,r){this.assertPoint(e),rd(r,this.bits);let n=Math.ceil((this.bits+Qc)/r)+1;nd(n*2**(r-1),this.Point.Fp.BYTES),ru.set(e,r),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return Wo(e)!==1}};function es(t,e,r,n=!1){if(Ct(t),tu(e,t),Ne(n,"allowOversized"),sd(r,t.Fn,n?t.Fn.ORDER**ed:void 0),e.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let s=e.map(i=>od(i,4)),o=r.map(i=>id(i,4));return cd(t.ZERO,s,o)}function eu(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return gr(e),e}else return br(t,{isLE:r})}function ts(t,e,r={},n){if(t!=="weierstrass"&&t!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);Le(r);for(let c of["p","n","h"]){let u=e[c];if(!(Bt(u)&&u!==Yo))throw new Error(`CURVE.${c} must be positive bigint`)}let s=eu(e.p,r.Fp,n),o=eu(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!s.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:s,Fn:o}}function xr(t,e){return function(n){let s=t(n);return{secretKey:s,publicKey:e(s)}}}var rs=BigInt(0),ns=BigInt(1),ss=BigInt(2),ud=BigInt(4),nu=BigInt(8);function fd(t,e,r,n){let s=t.sqr(r),o=t.sqr(n),i=t.add(t.mul(e.a,s),o),a=t.add(t.ONE,t.mul(e.d,t.mul(s,o)));return t.eql(i,a)}function su(t,e={}){Le(e,{},{},"extraOpts");let r=e,n=ts("edwards",t,r,r.FpFnLE),{Fp:s,Fn:o}=n,i=n.CURVE,{h:a}=i;if(Xr(s,i.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(Xr(s,i.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");Le(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?at:r.randomBytes,u=ss<<BigInt(s.BYTES*8)-ns;function f(E){if(!s.isOdd)throw new Error("Field does not have .isOdd()");return s.isOdd(E)}let l=r.uvRatio===void 0?(E,w)=>{try{return{isValid:!0,value:s.sqrt(s.div(E,w))}}catch{return{isValid:!1,value:rs}}}:r.uvRatio;if(!fd(s,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");let d=s.eql(i.a,s.neg(s.ONE))?E=>s.neg(E):s.eql(i.a,s.ONE)?E=>E:E=>s.mul(i.a,E);function p(E,w,I=!1){let T=I?ns:rs;return tt("coordinate "+E,w,T,u),w}function g(E){if(!(E instanceof b))throw new Error("EdwardsPoint expected")}class b{static BASE=new b(i.Gx,i.Gy,s.ONE,s.mul(i.Gx,i.Gy));static ZERO=new b(s.ZERO,s.ONE,s.ONE,s.ZERO);static Fp=s;static Fn=o;X;Y;Z;T;constructor(w,I,T,O){this.X=p("x",w),this.Y=p("y",I),this.Z=p("z",T,!0),this.T=p("t",O),Object.freeze(this)}static CURVE(){return i}static fromAffine(w){if(w instanceof b)throw new Error("extended point not allowed");let{x:I,y:T}=w||{};return p("x",I),p("y",T),new b(I,T,s.ONE,s.mul(I,T))}static fromBytes(w,I=!1){let T=s.BYTES,{a:O,d:M}=i;w=Lt(Z(w,T,"point")),Ne(I,"zip215");let U=Lt(w),C=w[T-1];U[T-1]=C&-129;let D=et(U),F=I?u:s.ORDER;tt("point.y",D,rs,F);let K=s.sqr(D),$=s.sub(K,s.ONE),B=s.sub(s.mulN(M,K),O),{isValid:P,value:_}=l($,B);if(!P)throw new Error("bad point: invalid y coordinate");let A=f(_),H=(C&128)!==0;if(!I&&s.is0(_)&&H)throw new Error("bad point: x=0 and x_0=1");return H!==A&&(_=s.neg(_)),b.fromAffine({x:_,y:D})}static fromHex(w,I=!1){return b.fromBytes(mr(w),I)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(w=6,I=!0){return x.setWindowSize(this,w),I||this.multiply(ss),this}assertValidity(){let w=this,{a:I,d:T}=i;if(w.is0())throw new Error("bad point: ZERO");let{X:O,Y:M,Z:U,T:C}=w,D=s.sqr(O),F=s.sqr(M),K=s.sqr(U),$=s.sqr(K),B=s.mul(D,I),P=s.mul(s.add(B,F),K),_=s.add($,s.mul(T,s.mul(D,F)));if(!s.eql(P,_))throw new Error("bad point: equation left != right (1)");let A=s.mul(O,M),H=s.mul(U,C);if(!s.eql(A,H))throw new Error("bad point: equation left != right (2)")}equals(w){g(w);let{X:I,Y:T,Z:O}=this,{X:M,Y:U,Z:C}=w,D=s.mul(I,C),F=s.mul(M,O),K=s.mul(T,C),$=s.mul(U,O);return s.eql(D,F)&&s.eql(K,$)}is0(){return this.equals(b.ZERO)}negate(){return new b(s.neg(this.X),this.Y,this.Z,s.neg(this.T))}double(){let{X:w,Y:I,Z:T}=this,O=s.sqr(w),M=s.sqr(I),U=s.mul(s.sqr(T),ss),C=d(O),D=s.addN(w,I),F=s.sub(s.subN(s.sqr(D),O),M),K=s.addN(C,M),$=s.subN(K,U),B=s.subN(C,M),P=s.mul(F,$),_=s.mul(K,B),A=s.mul(F,B),H=s.mul($,K);return new b(P,_,H,A)}add(w){g(w);let{d:I}=i,{X:T,Y:O,Z:M,T:U}=this,{X:C,Y:D,Z:F,T:K}=w,$=s.mul(T,C),B=s.mul(O,D),P=s.mul(s.mulN(U,I),K),_=s.mul(M,F),A=s.sub(s.subN(s.mulN(s.addN(T,O),s.addN(C,D)),$),B),H=s.subN(_,P),L=s.addN(_,P),S=s.sub(B,d($)),h=s.mul(A,H),m=s.mul(L,S),v=s.mul(A,S),R=s.mul(H,L);return new b(h,m,R,v)}subtract(w){return g(w),this.add(w.negate())}multiply(w){if(!o.isValidNot0(w))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:I,f:T}=x.mulSecret(this,w,a,y);return y([I,T])[0]}multiplyUnsafe(w){if(!o.isValid(w))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return w===rs?b.ZERO:this.is0()||w===ns?this:x.mulUnsafe(this,w,y)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return x.mulUnsafe(this,i.n).is0()}toAffine(w){let I=this,T=w;if(T!=null&&typeof T!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof T);let{X:O,Y:M,Z:U}=I,C=I.is0();T==null&&(T=C?s.create(nu):s.inv(U));let D=s.mul(O,T),F=s.mul(M,T),K=s.mul(U,T);if(C)return{x:s.ZERO,y:s.ONE};if(!s.eql(K,s.ONE))throw new Error("invZ was invalid");return{x:D,y:F}}clearCofactor(){return a===ns?this:a===ss?this.double():a===ud?this.double().double():a===nu?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:w,y:I}=this.toAffine(),T=s.toBytes(I);return T[T.length-1]|=f(w)?128:0,T}toHex(){return Wr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let y=E=>Jn(b,E),x=new wr(b,c);return x.bits>=6&&b.BASE.precompute(6),Object.freeze(b.prototype),Object.freeze(b),b}function ou(t,e,r={}){if(Ct(t),typeof e!="function")throw new Error('"hash" function param is required');let n=e,s=r;Le(s,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:o}=s,{BASE:i,Fp:a,Fn:c}=t,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(ct(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=s.randomBytes===void 0?at:s.randomBytes,d=s.toMontgomery,p=s.toMontgomerySecret,g=s.adjustScalarBytes===void 0?B=>B:s.adjustScalarBytes,b=s.domain===void 0?(B,P,_)=>{if(Ne(_,"phflag"),P.length||_)throw new Error("Contexts/pre-hash are not supported");return B}:s.domain;function y(B){return c.create(et(B))}function x(B){let P=C.secretKey;Z(B,C.secretKey,"secretKey");let _=Z(n(B),2*P,"hashedSecretKey"),A=g(_.slice(0,P)),H=_.slice(P,2*P),L=y(A);return{head:A,prefix:H,scalar:L}}function E(B){let{head:P,prefix:_,scalar:A}=x(B),H=i.multiply(A),L=H.toBytes();return{head:P,prefix:_,scalar:A,point:H,pointBytes:L}}function w(B){return E(B).pointBytes}function I(B=Uint8Array.of(),...P){let _=He(...P);return y(n(b(_,Z(B,void 0,"context"),!!o)))}function T(B,P,_={}){Le(_,{},{},"options"),B=Lt(Z(B,void 0,"message")),o&&(B=o(B));let{prefix:A,scalar:H,pointBytes:L}=E(P),S=I(_.context,A,B),h=i.multiply(S).toBytes(),m=I(_.context,h,L,B),v=c.create(S+m*H);if(!c.isValid(v))throw new Error("sign failed: invalid s");let R=He(h,c.toBytes(v));return Z(R,C.signature,"result")}let O={zip215:s.zip215};function M(B,P,_,A=O){Le(A);let{context:H}=A,L=A.zip215===void 0?!!O.zip215:A.zip215,S=C.signature;B=Z(B,S,"signature"),P=Z(P,void 0,"message"),_=Z(_,C.publicKey,"publicKey"),L!==void 0&&Ne(L,"zip215"),o&&(P=o(P));let h=S/2,m=B.subarray(0,h),v=et(B.subarray(h,S)),R,N,k;try{R=t.fromBytes(_,L),N=t.fromBytes(m,L),k=i.multiplyUnsafe(v)}catch{return!1}if(!L&&R.isSmallOrder())return!1;let q=I(H,m,_,P);return N.add(R.multiplyUnsafe(q)).subtract(k).clearCofactor().is0()}let U=a.BYTES,C={secretKey:U,publicKey:U,signature:2*U,seed:U};function D(B){return B=B===void 0?l(C.seed):B,Z(B,C.seed,"seed")}function F(B){return _t(B)&&B.length===C.secretKey}function K(B,P){try{return!!t.fromBytes(B,P===void 0?O.zip215:P)}catch{return!1}}let $={getExtendedPublicKey:E,randomSecretKey:D,isValidSecretKey:F,isValidPublicKey:K,toMontgomery(B){if(d===void 0)throw new Error("Montgomery conversion is not supported for this curve");return d(t.fromBytes(B))},toMontgomerySecret(B){if(p===void 0)throw new Error("Montgomery conversion is not supported for this curve");return p(B)}};return Object.freeze(C),Object.freeze($),Object.freeze({keygen:xr(D,w),getPublicKey:w,sign:T,verify:M,utils:$,Point:t,lengths:C})}var qt=BigInt(0),qe=BigInt(1),os=BigInt(2);function iu(t,e){return t+e-(e>>qe<<qe)}function ld(t){let e=BigInt(6)*t;return(r,n,s)=>{let o=n+s,a=((e+s-n)*r+n)%t;return{x_2:a,x_3:o-a}}}function hd(t){return Le(t,{P:"bigint",type:"string",adjustScalarBytes:"function",powPminus2:"function"},{randomBytes:"function",scalarMultBase:"function"}),Object.freeze({...t})}function au(t){let e=hd(t),{P:r,type:n,adjustScalarBytes:s,powPminus2:o,randomBytes:i}=e,a=e.scalarMultBase,c=n==="x25519";if(!c&&n!=="x448")throw new Error("invalid type");let u=i===void 0?at:i,f=c?255:448,l=ld(r),d=c?32:56,p=BigInt(c?9:5),g=BigInt(c?121665:39081),b=c?os**BigInt(254):os**BigInt(447),y=c?BigInt(8)*(os**BigInt(251)-qe):BigInt(4)*(os**BigInt(445)-qe),x=b+y+qe,E=_=>ne(_,r),w=I(p);function I(_){return Gr(E(_),d)}function T(_){let A=Lt(Z(_,d,"uCoordinate"));return c&&(A[31]&=127),E(et(A))}function O(_){return et(s(Lt(Z(_,d,"scalar"))))}let M=new Set(c?[qt,qe,r-qe,BigInt("325606250916557431795983626356110631294008115727848805560023387167927233504"),BigInt("39382357235489614581723060781553021112529911719440698176882885853963445705823")]:[qt,qe,r-qe]);function U(_,A){let H=T(A);if(M.has(H))throw new Error("invalid private or public key received");let L=K(H,O(_));if(L===qt)throw new Error("invalid private or public key received");return I(L)}function C(_){if(a===void 0)return U(_,w);let A=O(_);tt("scalar",A,b,x);let H=E(a(A));if(H===qt)throw new Error("invalid private or public key received");return I(H)}let D=C,F=U;function K(_,A){tt("u",_,qt,r),tt("scalar",A,b,x);let H=A,L=_,S=qe,h=qt,m=_,v=qe,R=H^H>>qe;for(let q=BigInt(f-1);q>=qt;q--){let z=iu(r,R>>q);({x_2:S,x_3:m}=l(z,S,m)),{x_2:h,x_3:v}=l(z,h,v);let j=S+h,Y=E(j*j),ce=S-h,ie=E(ce*ce),ye=Y-ie,Pe=m+v,ae=m-v,he=E(ae*j),sr=E(Pe*ce),Nr=he+sr,mt=he-sr;m=E(Nr*Nr),v=E(L*E(mt*mt)),S=E(Y*ie),h=E(ye*(Y+E(g*ye)))}let N=iu(r,H);({x_2:S,x_3:m}=l(N,S,m)),{x_2:h,x_3:v}=l(N,h,v);let k=o(h);return E(S*k)}let $={secretKey:d,publicKey:d,seed:d},B=_=>(_=_===void 0?u(d):_,Z(_,$.seed,"seed"),_),P={randomSecretKey:B};return Object.freeze($),Object.freeze(P),Object.freeze({keygen:xr(B,D),getSharedSecret:F,getPublicKey:D,scalarMult:U,scalarMultBase:C,utils:P,GuBytes:w.slice(),lengths:$})}var cu=BigInt(0),Zo=BigInt(1),uu=BigInt(2),dd=BigInt(3),pd=BigInt(5),md=BigInt(8),is=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),yd={p:is,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:md,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function hu(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),s=BigInt(80),o=is,a=t*t%o*t%o,c=ue(a,uu,o)*a%o,u=ue(c,Zo,o)*t%o,f=ue(u,pd,o)*u%o,l=ue(f,e,o)*f%o,d=ue(l,r,o)*l%o,p=ue(d,n,o)*d%o,g=ue(p,s,o)*p%o,b=ue(g,s,o)*p%o,y=ue(b,e,o)*f%o;return{pow_p_5_8:ue(y,uu,o)*t%o,b2:a}}function Xo(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var fu=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function gd(t,e){let r=is,n=ne(e*e*e,r),s=ne(n*n*e,r),o=hu(t*s).pow_p_5_8,i=ne(t*n*o,r),a=ne(e*i*i,r),c=i,u=ne(i*fu,r),f=a===t,l=a===ne(-t,r),d=a===ne(-t*fu,r);return f&&(i=c),(l||d)&&(i=u),Zc(i,r)&&(i=ne(-i,r)),{isValid:f||l,value:i}}var Jr=su(yd,{uvRatio:gd}),lu=Jr.Fp;function bd(t){let{y:e}=t;return lu.toBytes(lu.div(Zo+e,Zo-e))}function wd(t){let e=Jr.Fp.BYTES;return Oe(t,e),Xo(Fo(t.subarray(0,e))).subarray(0,e)}function xd(t){return ou(Jr,Fo,Object.assign({adjustScalarBytes:Xo,toMontgomery:bd,toMontgomerySecret:wd,zip215:!0},t))}var du=xd({});var en=(()=>{let t=is,e=r=>{let{pow_p_5_8:n,b2:s}=hu(r);return ne(ue(n,dd,t)*s,t)};return au({P:t,type:"x25519",powPminus2:e,adjustScalarBytes:Xo,scalarMultBase:r=>{let n=ne(r,Jr.Fn.ORDER);if(n===cu)return cu;let s=Jr.BASE.multiply(n);return ne((s.Z+s.Y)*e(ne(s.Z-s.Y,t)),t)}})})();var tn=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},as=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var ze={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new as("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return e}};var cs=32;var Qo,Ed=(async()=>{try{return await ze.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Sd(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await ze.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await ze.get().subtle.verify({name:"Ed25519"},n,Ae(e),Ae(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function vd(t,e,r){return du.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function pu(t,e,r){return Qo==null&&(Qo=await Ed),Qo?Sd(t,e,r):vd(t,e,r)}function us(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var fs=class{type="Ed25519";raw;constructor(e){this.raw=Jo(e,cs)}toMultihash(){return je.digest(xt(this))}toCID(){return we.createV1(114,this.toMultihash())}toString(){return me.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:xe(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let s=pu(this.raw,r,e);return us(s)?s.then(o=>(n?.signal?.throwIfAborted(),o)):s}};function ei(t){return t=Jo(t,cs),new fs(t)}function Jo(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new se(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}var Bd=Math.pow(2,7),_d=Math.pow(2,14),Ld=Math.pow(2,21),ti=Math.pow(2,28),ri=Math.pow(2,35),ni=Math.pow(2,42),si=Math.pow(2,49),re=128,Te=127;function Ce(t){if(t<Bd)return 1;if(t<_d)return 2;if(t<Ld)return 3;if(t<ti)return 4;if(t<ri)return 5;if(t<ni)return 6;if(t<si)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Er(t,e,r=0){switch(Ce(t)){case 8:e[r++]=t&255|re,t/=128;case 7:e[r++]=t&255|re,t/=128;case 6:e[r++]=t&255|re,t/=128;case 5:e[r++]=t&255|re,t/=128;case 4:e[r++]=t&255|re,t>>>=7;case 3:e[r++]=t&255|re,t>>>=7;case 2:e[r++]=t&255|re,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Td(t,e,r=0){switch(Ce(t)){case 8:e.set(r++,t&255|re),t/=128;case 7:e.set(r++,t&255|re),t/=128;case 6:e.set(r++,t&255|re),t/=128;case 5:e.set(r++,t&255|re),t/=128;case 4:e.set(r++,t&255|re),t>>>=7;case 3:e.set(r++,t&255|re),t>>>=7;case 2:e.set(r++,t&255|re),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function oi(t,e){let r=t[e],n=0;if(n+=r&Te,r<re||(r=t[e+1],n+=(r&Te)<<7,r<re)||(r=t[e+2],n+=(r&Te)<<14,r<re)||(r=t[e+3],n+=(r&Te)<<21,r<re)||(r=t[e+4],n+=(r&Te)*ti,r<re)||(r=t[e+5],n+=(r&Te)*ri,r<re)||(r=t[e+6],n+=(r&Te)*ni,r<re)||(r=t[e+7],n+=(r&Te)*si,r<re))return n;throw new RangeError("Could not decode varint")}function Cd(t,e){let r=t.get(e),n=0;if(n+=r&Te,r<re||(r=t.get(e+1),n+=(r&Te)<<7,r<re)||(r=t.get(e+2),n+=(r&Te)<<14,r<re)||(r=t.get(e+3),n+=(r&Te)<<21,r<re)||(r=t.get(e+4),n+=(r&Te)*ti,r<re)||(r=t.get(e+5),n+=(r&Te)*ri,r<re)||(r=t.get(e+6),n+=(r&Te)*ni,r<re)||(r=t.get(e+7),n+=(r&Te)*si,r<re))return n;throw new RangeError("Could not decode varint")}function yu(t,e,r=0){return e==null&&(e=Se(Ce(t))),e instanceof Uint8Array?Er(t,e,r):Td(t,e,r)}function zt(t,e=0){return t instanceof Uint8Array?oi(t,e):Cd(t,e)}var ai=new Float32Array([-0]),It=new Uint8Array(ai.buffer);function gu(t,e,r){ai[0]=t,e[r]=It[0],e[r+1]=It[1],e[r+2]=It[2],e[r+3]=It[3]}function bu(t,e){return It[0]=t[e],It[1]=t[e+1],It[2]=t[e+2],It[3]=t[e+3],ai[0]}var ci=new Float64Array([-0]),Ie=new Uint8Array(ci.buffer);function wu(t,e,r){ci[0]=t,e[r]=Ie[0],e[r+1]=Ie[1],e[r+2]=Ie[2],e[r+3]=Ie[3],e[r+4]=Ie[4],e[r+5]=Ie[5],e[r+6]=Ie[6],e[r+7]=Ie[7]}function xu(t,e){return Ie[0]=t[e],Ie[1]=t[e+1],Ie[2]=t[e+2],Ie[3]=t[e+3],Ie[4]=t[e+4],Ie[5]=t[e+5],Ie[6]=t[e+6],Ie[7]=t[e+7],ci[0]}var Id=BigInt(Number.MAX_SAFE_INTEGER),Dd=BigInt(Number.MIN_SAFE_INTEGER),ke=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return $t;if(e<Id&&e>Dd)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,s=e-(n<<32n);return r&&(n=~n|0n,s=~s|0n,++s>Eu&&(s=0n,++n>Eu&&(n=0n))),new t(Number(s),Number(n))}static fromNumber(e){if(e===0)return $t;let r=e<0;r&&(e=-e);let n=e>>>0,s=(e-n)/4294967296>>>0;return r&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new t(n,s)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):$t}},$t=new ke(0,0);$t.toBigInt=function(){return 0n};$t.zzEncode=$t.zzDecode=function(){return this};$t.length=function(){return 1};var Eu=4294967296n;function Su(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function vu(t,e,r){if(r-e<1)return"";let s,o=[],i=0,a;for(;e<r;)a=t[e++],a<128?o[i++]=a:a>191&&a<224?o[i++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,o[i++]=55296+(a>>10),o[i++]=56320+(a&1023)):o[i++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,i>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,o)),i=0);return s!=null?(i>0&&s.push(String.fromCharCode.apply(String,o.slice(0,i))),s.join("")):String.fromCharCode.apply(String,o.slice(0,i))}function ui(t,e,r){let n=r,s,o;for(let i=0;i<t.length;++i)s=t.charCodeAt(i),s<128?e[r++]=s:s<2048?(e[r++]=s>>6|192,e[r++]=s&63|128):(s&64512)===55296&&((o=t.charCodeAt(i+1))&64512)===56320?(s=65536+((s&1023)<<10)+(o&1023),++i,e[r++]=s>>18|240,e[r++]=s>>12&63|128,e[r++]=s>>6&63|128,e[r++]=s&63|128):(e[r++]=s>>12|224,e[r++]=s>>6&63|128,e[r++]=s&63|128);return r-n}function Ge(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function ls(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var fi=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=Ae(e),this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Ge(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ge(this,4);return ls(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ge(this,4);return ls(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ge(this,4);let e=bu(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ge(this,4);let e=xu(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw Ge(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return vu(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ge(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ge(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new ke(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Ge(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw Ge(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ge(this,8);let e=ls(this.buf,this.pos+=4),r=ls(this.buf,this.pos+=4);return new ke(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=oi(this.buf,this.pos);return this.pos+=Ce(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function rn(t){return new fi(t instanceof Uint8Array?t:t.subarray())}function Vt(t,e,r){let n=rn(t);return e.decode(n,void 0,r)}function li(t){let e=t??8192,r=e>>>1,n,s=e;return function(i){if(i<1||i>r)return Se(i);s+i>e&&(n=Se(e),s=0);let a=n.subarray(s,s+=i);return(s&7)!==0&&(s=(s|7)+1),a}}var jt=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function hi(){}var pi=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Rd=li();function Od(t){return globalThis.Buffer!=null?Se(t):Rd(t)}var sn=class{len;head;tail;states;constructor(){this.len=0,this.head=new jt(hi,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new jt(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new mi((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(hs,10,ke.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=ke.fromBigInt(e);return this._push(hs,r.length(),r)}uint64Number(e){return this._push(Er,Ce(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=ke.fromBigInt(e).zzEncode();return this._push(hs,r.length(),r)}sint64Number(e){let r=ke.fromNumber(e).zzEncode();return this._push(hs,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(di,1,e?1:0)}fixed32(e){return this._push(nn,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=ke.fromBigInt(e);return this._push(nn,4,r.lo)._push(nn,4,r.hi)}fixed64Number(e){let r=ke.fromNumber(e);return this._push(nn,4,r.lo)._push(nn,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(gu,4,e)}double(e){return this._push(wu,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(di,1,0):this.uint32(r)._push(Ud,r,e)}string(e){let r=Su(e);return r!==0?this.uint32(r)._push(ui,r,e):this._push(di,1,0)}fork(){return this.states=new pi(this),this.head=this.tail=new jt(hi,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new jt(hi,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=Od(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function di(t,e,r){e[r]=t&255}function Pd(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var mi=class extends jt{next;constructor(e,r){super(Pd,e,r),this.next=void 0}};function hs(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function nn(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function Ud(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(sn.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(Nd,e,t),this},sn.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(kd,e,t),this});function Nd(t,e,r){e.set(t,r)}function kd(t,e,r){t.length<40?ui(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(ee(t),r)}function yi(){return new sn}function Wt(t,e){let r=yi();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*Yt(t,e,r){let n=rn(t);yield*e.stream(n,void 0,"$",r)}var ds={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function ps(t,e,r,n,s){return{name:t,type:e,encode:r,decode:n,stream:s}}function gi(t){function e(o){if(t[o.toString()]==null)throw new Error("Invalid enum value");return t[o]}let r=function(i,a){let c=e(i);a.int32(c)},n=function(i){let a=i.int32();return e(a)},s=function*(i){let a=i.int32();yield e(a)};return ps("enum",ds.VARINT,r,n,s)}function Gt(t,e,r){return ps("message",ds.LENGTH_DELIMITED,t,e,r)}var Zt=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var de;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(de||(de={}));var bi;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(bi||(bi={}));(function(t){t.codec=()=>gi(bi)})(de||(de={}));var rt;(function(t){let e;t.codec=()=>(e==null&&(e=Gt((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.Type!=null&&(i.uint32(8),de.codec().encode(o.Type,i)),o.Data!=null&&(i.uint32(18),i.bytes(o.Data)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.Type=de.codec().decode(o);break}case 2:{c.Data=o.bytes();break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:de.codec().decode(o)};break}case 2:{yield{field:`${a}.Data`,value:o.bytes()};break}default:{o.skipType(f&7);break}}}})),e);function r(o){return Wt(o,t.codec())}t.encode=r;function n(o,i){return Vt(o,t.codec(),i)}t.decode=n;function s(o,i){return Yt(o,t.codec(),i)}t.stream=s})(rt||(rt={}));var wi;(function(t){let e;t.codec=()=>(e==null&&(e=Gt((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.Type!=null&&(i.uint32(8),de.codec().encode(o.Type,i)),o.Data!=null&&(i.uint32(18),i.bytes(o.Data)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.Type=de.codec().decode(o);break}case 2:{c.Data=o.bytes();break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:de.codec().decode(o)};break}case 2:{yield{field:`${a}.Data`,value:o.bytes()};break}default:{o.skipType(f&7);break}}}})),e);function r(o){return Wt(o,t.codec())}t.encode=r;function n(o,i){return Vt(o,t.codec(),i)}t.decode=n;function s(o,i){return Yt(o,t.codec(),i)}t.stream=s})(wi||(wi={}));var an={};Re(an,{MAX_RSA_KEY_SIZE:()=>xi,generateRSAKeyPair:()=>Cu,jwkToJWKKeyPair:()=>Iu,jwkToPkcs1:()=>Hd,jwkToPkix:()=>Ai,jwkToRSAPrivateKey:()=>Ti,pkcs1MessageToJwk:()=>Si,pkcs1MessageToRSAPrivateKey:()=>Bi,pkcs1ToJwk:()=>Fd,pkcs1ToRSAPrivateKey:()=>Tu,pkixMessageToJwk:()=>vi,pkixMessageToRSAPublicKey:()=>Li,pkixToJwk:()=>qd,pkixToRSAPublicKey:()=>_i});var Sr=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=an.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return we.createV1(114,this._multihash)}toString(){return me.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:xe(this.raw,e.raw)}verify(e,r,n){return Lu(this.jwk,r,e,n)}},on=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=an.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:xe(this.raw,e.raw)}sign(e,r){return _u(this.jwk,e,r)}};var xi=8192,Ei=18,Md=1062,Kd=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Fd(t){let e=it(t);return Si(e)}function Si(t){return{n:W(t[1],"base64url"),e:W(t[2],"base64url"),d:W(t[3],"base64url"),p:W(t[4],"base64url"),q:W(t[5],"base64url"),dp:W(t[6],"base64url"),dq:W(t[7],"base64url"),qi:W(t[8],"base64url"),kty:"RSA"}}function Hd(t){if(t.n==null||t.e==null||t.d==null||t.p==null||t.q==null||t.dp==null||t.dq==null||t.qi==null)throw new se("JWK was missing components");return wt([Ue(Uint8Array.from([0])),Ue(ee(t.n,"base64url")),Ue(ee(t.e,"base64url")),Ue(ee(t.d,"base64url")),Ue(ee(t.p,"base64url")),Ue(ee(t.q,"base64url")),Ue(ee(t.dp,"base64url")),Ue(ee(t.dq,"base64url")),Ue(ee(t.qi,"base64url"))]).subarray()}function qd(t){let e=it(t,{offset:0});return vi(e)}function vi(t){let e=it(t[1],{offset:0});return{kty:"RSA",n:W(e[0],"base64url"),e:W(e[1],"base64url")}}function Ai(t){if(t.n==null||t.e==null)throw new se("JWK was missing components");return wt([Kd,Mn(wt([Ue(ee(t.n,"base64url")),Ue(ee(t.e,"base64url"))]))]).subarray()}function Tu(t){let e=it(t);return Bi(e)}function Bi(t){let e=Si(t);return Ti(e)}function _i(t,e){if(t.byteLength>=Md)throw new ir("Key size is too large");let r=it(t,{offset:0});return Li(r,t,e)}function Li(t,e,r){let n=vi(t);if(r==null){let s=Qe(rt.encode({Type:de.RSA,Data:e}));r=Ve(Ei,s)}return new Sr(n,r)}function Ti(t){if(Ru(t)>xi)throw new se("Key size is too large");let e=Iu(t),r=Qe(rt.encode({Type:de.RSA,Data:Ai(e.publicKey)})),n=Ve(Ei,r);return new on(e.privateKey,new Sr(e.publicKey,n))}async function Cu(t){if(t>xi)throw new se("Key size is too large");let e=await Du(t),r=Qe(rt.encode({Type:de.RSA,Data:Ai(e.publicKey)})),n=Ve(Ei,r);return new on(e.privateKey,new Sr(e.publicKey,n))}function Iu(t){if(t==null)throw new se("Missing key parameter");return{privateKey:t,publicKey:{kty:t.kty,n:t.n,e:t.e}}}async function Du(t,e){let r=await ze.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:t,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);e?.signal?.throwIfAborted();let n=await zd(r,e);return{privateKey:n[0],publicKey:n[1]}}async function _u(t,e,r){let n=await ze.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let s=await ze.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,Ae(e instanceof Uint8Array?e:e.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(s,0,s.byteLength)}async function Lu(t,e,r,n){let s=await ze.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let o=await ze.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},s,Ae(e),Ae(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),o}async function zd(t,e){if(t.privateKey==null||t.publicKey==null)throw new se("Private and public key are required");let r=await Promise.all([ze.get().subtle.exportKey("jwk",t.privateKey),ze.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function Ru(t){if(t.kty!=="RSA")throw new se("invalid key type");if(t.n==null)throw new se("invalid key modulus");return ee(t.n,"base64url").length*8}var ms=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(Ft(e),Oe(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,s=new Uint8Array(n);s.set(r.length>n?e.create().update(r).digest():r);for(let o=0;o<s.length;o++)s[o]^=54;this.iHash.update(s),this.oHash=e.create();for(let o=0;o<s.length;o++)s[o]^=106;this.oHash.update(s),Fe(s)}update(e){return pr(this),this.iHash.update(e),this}digestInto(e){pr(this),Hn(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:s,destroyed:o,blockLen:i,outputLen:a,canXOF:c}=this;return e=e,e.finished=s,e.destroyed=o,e.blockLen=i,e.outputLen=a,e.canXOF=c,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},cn=(()=>{let t=((e,r,n)=>new ms(e,r).update(n).digest());return t.create=(e,r)=>new ms(e,r),t})();var $d=BigInt(0),Ci=class extends Error{constructor(e=""){super(e)}},ut={Err:Ci,_tlv:{encode:(t,e)=>{let{Err:r}=ut;if(ct(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(kc(e,"data"),e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,s=Yr(n);if(s.length/2&128)throw new r("tlv.encode: long form length too big");let o=n>127?Yr(s.length/2|128):"";return Yr(t)+o+s+e},decode(t,e){let{Err:r}=ut;e=Z(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.decode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let s=e[n++],o=!!(s&128),i=0;if(!o)i=s;else{let c=s&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+i)}}},_int:{encode(t){let{Err:e}=ut;if(Wn(t),t<$d)throw new e("integer: negative integers are not allowed");let r=Yr(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=ut;if(t.length<1)throw new e("invalid signature integer: empty");if(t[0]&128)throw new e("invalid signature integer: negative");if(t.length>1&&t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return Je(t)}},toSig(t,e){let{Err:r,_int:n,_tlv:s}=ut;if(e!==void 0&&(ct(e,"maxScalarBytes"),e<1))throw new r("invalid signature: maxScalarBytes must be positive");let o=Z(t,void 0,"signature"),{v:i,l:a}=s.decode(48,o);if(a.length)throw new r("invalid signature: left bytes after parsing");let{v:c,l:u}=s.decode(2,i),{v:f,l}=s.decode(2,u);if(l.length)throw new r("invalid signature: left bytes after parsing");if(e!==void 0&&(c.length>e||f.length>e))throw new r("invalid signature: integer too large");return{r:n.decode(c),s:n.decode(f)}},hexFromSig(t){let{_tlv:e,_int:r}=ut;Le(t,{r:"bigint",s:"bigint"},{},"sig");let n=e.encode(2,r.encode(t.r)),s=e.encode(2,r.encode(t.s)),o=n+s;return e.encode(48,o)}},ys=(Object.freeze(ut._tlv),Object.freeze(ut._int),Object.freeze(ut));var Ou=(t,e)=>(t+(t>=0?e:-e)/Pu)/e;function Vd(t,e,r){tt("scalar",t,ft,r);let[[n,s],[o,i]]=e,a=Ou(i*t,r),c=Ou(-s*t,r),u=t-a*n-c*o,f=-a*s-c*i,l=u<ft,d=f<ft;l&&(u=-u),d&&(f=-f);let p=Zr(Math.ceil(yr(r)/2))+Xt;if(u<ft||u>=p||f<ft||f>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:d,k2:f}}function Ri(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Ii(t,e){Le(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Ne(r.lowS,"lowS"),Ne(r.prehash,"prehash"),r.format!==void 0&&Ri(r.format),r}var ft=BigInt(0),Xt=BigInt(1),Pu=BigInt(2),Di=BigInt(3),jd=BigInt(4);function Uu(t,e={}){let r=ts("weierstrass",t,e),n=r.Fp,s=r.Fn,o=r.CURVE,{h:i,n:a}=o;Le(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:u,clearCofactor:f,isTorsionFree:l,fromBytes:d,toBytes:p}=e,g=e.randomBytes===void 0?at:e.randomBytes;if(c&&(!n.is0(o.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let b=c?{beta:c.beta,basises:c.basises.map(S=>[...S])}:void 0,y=ku(n,s);function x(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function E(S,h,m){if(h.is0()){if(!u)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x:v,y:R}=h.toAffine(),N=n.toBytes(v);if(Ne(m,"isCompressed"),m){x();let k=!n.isOdd(R);return He(Nu(k),N)}else return He(Uint8Array.of(4),N,n.toBytes(R))}function w(S){Z(S,void 0,"Point");let{publicKey:h,publicKeyUncompressed:m}=y,v=S.length,R=S[0],N=S.subarray(1);if(u&&v===1&&R===0)return{x:n.ZERO,y:n.ZERO};if(v===h&&(R===2||R===3)){let k=n.fromBytes(N);if(!n.isValid(k))throw new Error("bad point: is not on curve, wrong x");let q=U(k),z;try{z=n.sqrt(q)}catch(ce){let ie=ce instanceof Error?": "+ce.message:"";throw new Error("bad point: is not on curve, sqrt error"+ie)}x();let j=n.isOdd(z);return(R&1)===1!==j&&(z=n.neg(z)),{x:k,y:z}}else if(v===m&&R===4){let k=n.BYTES,q=n.fromBytes(N.subarray(0,k)),z=n.fromBytes(N.subarray(k,k*2));if(!C(q,z))throw new Error("bad point: is not on curve");return{x:q,y:z}}else throw new Error(`bad point: got length ${v}, expected compressed=${h} or uncompressed=${m}`)}let I=p===void 0?E:p,T=d===void 0?w:d,O=n.mul(o.b,Di),M=n.is0(o.a)?S=>n.ZERO:S=>n.mul(o.a,S);function U(S){let h=n.sqr(S),m=n.mul(h,S);return n.add(n.add(m,n.mul(S,o.a)),o.b)}function C(S,h){let m=n.sqr(h),v=U(S);return n.eql(m,v)}if(!C(o.Gx,o.Gy))throw new Error("bad curve params: generator point");let D=n.mul(n.pow(o.a,Di),jd),F=n.mul(n.sqr(o.b),BigInt(27));if(n.is0(n.add(D,F)))throw new Error("bad curve params: a or b");function K(S,h,m=!1){if(!n.isValid(h)||m&&n.is0(h))throw new Error(`bad point coordinate ${S}`);return typeof h=="object"&&h!==null?n.create(h):h}function $(S){if(!(S instanceof A))throw new Error("Weierstrass Point expected")}function B(S){if(!b||!b.basises)throw new Error("no endo");return Vd(S,b.basises,s.ORDER)}function P(S,h,m,v){if(!s.isValid(v))throw new RangeError("invalid scalar: out of range");if(b){let{k1neg:R,k1:N,k2neg:k,k2:q}=B(v),z=new A(n.mul(m.X,b.beta),m.Y,m.Z);S.push(R?m.negate():m,k?z.negate():z),h.push(N,q)}else S.push(m),h.push(v)}let _=new WeakSet;class A{static BASE=new A(o.Gx,o.Gy,n.ONE);static ZERO=new A(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=s;X;Y;Z;constructor(h,m,v){this.X=K("x",h),this.Y=K("y",m,!0),this.Z=K("z",v),Object.freeze(this)}static CURVE(){return o}static fromAffine(h){let{x:m,y:v}=h||{};if(!h||!n.isValid(m)||!n.isValid(v))throw new Error("invalid affine point");if(h instanceof A)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(v)?A.ZERO:new A(m,v,n.ONE)}static fromBytes(h){let m=A.fromAffine(T(Z(h,void 0,"point")));return m.assertValidity(),m}static fromHex(h){return A.fromBytes(mr(h))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(h=6,m=!0){return L.setWindowSize(this,h),m||this.multiply(Di),this}assertValidity(){let h=this;if(h.is0()){if(u&&n.is0(h.X)&&n.eql(h.Y,n.ONE)&&n.is0(h.Z))return;throw new Error("bad point: ZERO")}if(_.has(h))return;let{x:m,y:v}=h.toAffine();if(!n.isValid(m)||!n.isValid(v))throw new Error("bad point: x or y not field elements");if(!C(m,v))throw new Error("bad point: equation left != right");if(!h.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");_.add(h)}hasEvenY(){let{y:h}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(h)}equals(h){$(h);let{X:m,Y:v,Z:R}=this,{X:N,Y:k,Z:q}=h,z=n.eql(n.mul(m,q),n.mul(N,R)),j=n.eql(n.mul(v,q),n.mul(k,R));return z&&j}negate(){return new A(this.X,n.neg(this.Y),this.Z)}double(){let{X:h,Y:m,Z:v}=this,R=n.ZERO,N=n.ZERO,k=n.ZERO,q=n.mul(h,h),z=n.mul(m,m),j=n.mul(v,v),Y=n.mul(h,m);return Y=n.add(Y,Y),k=n.mul(h,v),k=n.add(k,k),R=M(k),N=n.mul(O,j),N=n.add(R,N),R=n.sub(z,N),N=n.add(z,N),N=n.mul(R,N),R=n.mul(Y,R),k=n.mul(O,k),j=M(j),Y=n.sub(q,j),Y=M(Y),Y=n.add(Y,k),k=n.add(q,q),q=n.add(k,q),q=n.add(q,j),q=n.mul(q,Y),N=n.add(N,q),j=n.mul(m,v),j=n.add(j,j),q=n.mul(j,Y),R=n.sub(R,q),k=n.mul(j,z),k=n.add(k,k),k=n.add(k,k),new A(R,N,k)}add(h){$(h);let{X:m,Y:v,Z:R}=this,{X:N,Y:k,Z:q}=h,z=n.ZERO,j=n.ZERO,Y=n.ZERO,ce=n.mul(m,N),ie=n.mul(v,k),ye=n.mul(R,q),Pe=n.add(m,v),ae=n.add(N,k);Pe=n.mul(Pe,ae),ae=n.add(ce,ie),Pe=n.sub(Pe,ae),ae=n.add(m,R);let he=n.add(N,q);return ae=n.mul(ae,he),he=n.add(ce,ye),ae=n.sub(ae,he),he=n.add(v,R),z=n.add(k,q),he=n.mul(he,z),z=n.add(ie,ye),he=n.sub(he,z),Y=M(ae),z=n.mul(O,ye),Y=n.add(z,Y),z=n.sub(ie,Y),Y=n.add(ie,Y),j=n.mul(z,Y),ie=n.add(ce,ce),ie=n.add(ie,ce),ye=M(ye),ae=n.mul(O,ae),ie=n.add(ie,ye),ye=n.sub(ce,ye),ye=M(ye),ae=n.add(ae,ye),ce=n.mul(ie,ae),j=n.add(j,ce),ce=n.mul(he,ae),z=n.mul(Pe,z),z=n.sub(z,ce),ce=n.mul(Pe,ie),Y=n.mul(he,Y),Y=n.add(Y,ce),new A(z,j,Y)}subtract(h){return $(h),this.add(h.negate())}is0(){return this.equals(A.ZERO)}multiply(h){if(!s.isValidNot0(h))throw new RangeError("invalid scalar: out of range");let{p:m,f:v}=L.mulSecret(this,h,i,H);return H([m,v])[0]}multiplyUnsafe(h){let m=this,v=h;if(!s.isValid(v))throw new RangeError("invalid scalar: out of range");if(v===ft||m.is0())return A.ZERO;if(v===Xt)return m;if(L.hasWindowSize(this))return L.mulUnsafe(m,v,H);let R=[],N=[];return P(R,N,m,v),es(A,R,N)}mulAddUnsafe(h,m,v){$(m);let R=[],N=[];return P(R,N,this,h),P(R,N,m,v),es(A,R,N)}toAffine(h){let m=this,v=h;if(v!=null&&!n.isValid(v))throw new RangeError('"invertedZ" expected valid field element');let{X:R,Y:N,Z:k}=m;if(n.eql(k,n.ONE))return{x:R,y:N};let q=m.is0();v==null&&(v=q?n.ONE:n.inv(k));let z=n.mul(R,v),j=n.mul(N,v),Y=n.mul(k,v);if(q)return{x:n.ZERO,y:n.ZERO};if(!n.eql(Y,n.ONE))throw new Error("invZ was invalid");return{x:z,y:j}}isTorsionFree(){return i===Xt?!0:l?l(A,this):L.mulUnsafe(this,a).is0()}clearCofactor(){return i===Xt?this:f?f(A,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===Xt?this.is0():this.clearCofactor().is0()}toBytes(h=!0){return Ne(h,"isCompressed"),this.assertValidity(),I(A,this,h)}toHex(h=!0){return Wr(this.toBytes(h))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let H=S=>Jn(A,S),L=new wr(A,g);return L.bits>=6&&A.BASE.precompute(6),Object.freeze(A.prototype),Object.freeze(A),A}function Nu(t){return Uint8Array.of(t?2:3)}function ku(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function Wd(t,e={}){Ct(t);let{Fn:r}=t,n=e.randomBytes===void 0?at:e.randomBytes,s=Object.assign(ku(t.Fp,r),{seed:Math.max(Xn(r.ORDER),16)});function o(p){try{let g=r.fromBytes(p);return r.isValidNot0(g)}catch{return!1}}function i(p,g){let{publicKey:b,publicKeyUncompressed:y}=s;try{let x=p.length;return g===!0&&x!==b||g===!1&&x!==y?!1:!t.fromBytes(p).is0()}catch{return!1}}function a(p){return p=p===void 0?n(s.seed):p,Qn(Z(p,s.seed,"seed"),r.ORDER)}function c(p,g=!0){return t.BASE.multiply(r.fromBytes(p)).toBytes(g)}function u(p){let{secretKey:g,publicKey:b,publicKeyUncompressed:y}=s,x=r._lengths;if(!_t(p))return;let E=Z(p,void 0,"key").length,w=E===b||E===y,I=E===g||!!x?.includes(E);if(!(w&&I))return w}function f(p,g,b=!0){if(u(p)===!0)throw new Error("first arg must be private key");if(u(g)===!1)throw new Error("second arg must be public key");let y=r.fromBytes(p),x=t.fromBytes(g);if(x.is0())throw new Error("invalid public key: point at infinity");return x.multiply(y).toBytes(b)}let l={isValidSecretKey:o,isValidPublicKey:i,randomSecretKey:a},d=xr(a,c);return Object.freeze(l),Object.freeze(s),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:d,Point:t,utils:l,lengths:s})}function Mu(t,e,r={}){Ct(t);let n=e;Ft(n),Le(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let s=Object.assign({},r),o=s.randomBytes===void 0?at:s.randomBytes,i=s.hmac===void 0?(S,h)=>cn(n,S,h):s.hmac,{Fp:a,Fn:c}=t,{ORDER:u,BITS:f}=c,l=Xn(u),d=Go(o,l),{keygen:p,getPublicKey:g,getSharedSecret:b,utils:y,lengths:x}=Wd(t,s),E={prehash:!0,lowS:typeof s.lowS=="boolean"?s.lowS:!0,format:"compact",extraEntropy:!1},w=u*Pu+Xt<a.ORDER;function I(S){let h=u>>Xt;return S>h}function T(S,h){if(!c.isValidNot0(h))throw new Error(`invalid signature ${S}: out of range 1..Point.Fn.ORDER`);return h}function O(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function M(S,h,m){return O(),(S===m?0:2)|Number(a.isOdd(h))}function U(){if(w)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function C(S,h){Ri(h);let m=x.signature,v=h==="compact"?m:h==="recovered"?m+1:void 0;return Z(S,v)}class D{r;s;recovery;constructor(h,m,v){if(this.r=T("r",h),this.s=T("s",m),v!=null){if(U(),![0,1,2,3].includes(v))throw new Error("invalid recovery id");this.recovery=v}Object.freeze(this)}static fromBytes(h,m=E.format){C(h,m);let v;if(m==="der"){if(h.length>2*c.BYTES+16)throw new ys.Err("invalid signature: DER signature too long");let{r:q,s:z}=ys.toSig(Z(h),c.BYTES+1);return new D(q,z)}m==="recovered"&&(v=h[0],m="compact",h=h.subarray(1));let R=x.signature/2,N=h.subarray(0,R),k=h.subarray(R,R*2);return new D(c.fromBytes(N),c.fromBytes(k),v)}static fromHex(h,m){return this.fromBytes(mr(h),m)}assertRecovery(){let{recovery:h}=this;if(h==null)throw new Error("invalid recovery id: must be present");return h}addRecoveryBit(h){return new D(this.r,this.s,h)}recoverPublicKey(h){let{r:m,s:v}=this,R=this.assertRecovery(),N=R===2||R===3?m+u:m;if(!a.isValid(N))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let k=a.toBytes(N),q=t.fromBytes(He(Nu((R&1)===0),k)),z=c.inv(N),j=K(Z(h,void 0,"msgHash")),Y=c.create(-j*z),ce=c.create(v*z),ie=t.BASE.mulAddUnsafe(Y,q,ce);if(ie.is0())throw new Error("invalid recovery: point at infinify");return ie.assertValidity(),ie}hasHighS(){return I(this.s)}toBytes(h=E.format){if(Ri(h),h==="der")return mr(ys.hexFromSig(this));let{r:m,s:v}=this,R=c.toBytes(m),N=c.toBytes(v);return h==="recovered"?(U(),He(Uint8Array.of(this.assertRecovery()),R,N)):He(R,N)}toHex(h){return Wr(this.toBytes(h))}}Object.freeze(D.prototype),Object.freeze(D);let F=s.bits2int===void 0?function(h){if(h.length>8192)throw new Error("input is too large");let m=Je(h),v=h.length*8-f;return v>0?m>>BigInt(v):m}:s.bits2int,K=s.bits2int_modN===void 0?function(h){return c.create(F(h))}:s.bits2int_modN,$=Zr(f);function B(S){return tt("num < 2^"+f,S,ft,$),c.toBytes(S)}function P(S,h){return Z(S,void 0,"message"),h?Z(n(S),void 0,"prehashed message"):S}function _(S,h,m){let{lowS:v,prehash:R,extraEntropy:N}=Ii(m,E);S=P(S,R);let k=K(S),q=c.fromBytes(h);if(!c.isValidNot0(q))throw new Error("invalid private key");let z=[B(q),B(k)];if(N!=null&&N!==!1){let ie=N===!0?o(x.secretKey):N;z.push(Z(ie,void 0,"extraEntropy"))}let j=He(...z),Y=k;function ce(ie){let ye=F(ie);if(!c.isValidNot0(ye))return;let Pe=t.BASE.multiply(ye).toAffine(),ae=c.create(Pe.x);if(ae===ft)return;let he;if(d!==void 0){let mt=Je(Qn(d(l),u)),Qf=c.inv(c.mul(mt,ye)),Jf=c.mul(mt,Y),el=c.mul(mt,q);he=c.create(Qf*c.create(Jf+el*ae))}else{let mt=Wc(ye,u);he=c.create(mt*c.create(Y+ae*q))}if(he===ft)return;let sr=M(Pe.x,Pe.y,ae),Nr=he;return v&&I(he)&&(Nr=c.neg(he),sr^=1),new D(ae,Nr,w?void 0:sr)}return{seed:j,k2sig:ce}}function A(S,h,m={}){let{seed:v,k2sig:R}=_(S,h,m);return Kc(n.outputLen,c.BYTES,i)(v,R).toBytes(m.format)}function H(S,h,m,v={}){let{lowS:R,prehash:N,format:k}=Ii(v,E);if(m=Z(m,void 0,"publicKey"),h=P(h,N),!_t(S)){let q=S instanceof D?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+q)}C(S,k);try{let q=D.fromBytes(S,k),z=t.fromBytes(m);if(z.is0()||R&&q.hasHighS())return!1;let{r:j,s:Y}=q,ce=K(h),ie=c.inv(Y),ye=c.create(ce*ie),Pe=c.create(j*ie),ae=t.BASE.mulAddUnsafe(ye,z,Pe);if(ae.is0())return!1;let he=ae.toAffine();return!(c.create(he.x)!==j||k==="recovered"&&q.recovery!==M(he.x,he.y,j))}catch{return!1}}function L(S,h,m={}){let{prehash:v}=Ii(m,E);return h=P(h,v),D.fromBytes(S,"recovered").recoverPublicKey(h).toBytes()}return Object.freeze({keygen:p,getPublicKey:g,getSharedSecret:b,utils:y,lengths:x,Point:t,sign:A,verify:H,recoverPublicKey:L,Signature:D,hash:n})}var Pi={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Yd={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Ku=BigInt(2);function Gd(t){let e=Pi.p,r=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=t*t*t%e,f=u*u*t%e,l=ue(f,r,e)*f%e,d=ue(l,r,e)*f%e,p=ue(d,Ku,e)*u%e,g=ue(p,s,e)*p%e,b=ue(g,o,e)*g%e,y=ue(b,a,e)*b%e,x=ue(y,c,e)*y%e,E=ue(x,a,e)*b%e,w=ue(E,r,e)*f%e,I=ue(w,i,e)*g%e,T=ue(I,n,e)*u%e,O=ue(T,Ku,e);if(!Oi.eql(Oi.sqr(O),t))throw new Error("Cannot find square root");return O}var Oi=br(Pi.p,{sqrt:Gd}),Zd=Uu(Pi,{Fp:Oi,endo:Yd}),vr=Mu(Zd,Qe);function Fu(t,e,r,n){let s=Hr.digest(r instanceof Uint8Array?r:r.subarray());if(us(s))return s.then(({digest:o})=>(n?.signal?.throwIfAborted(),vr.verify(e,o,t,{prehash:!1,format:"der"}))).catch(o=>{throw o.name==="AbortError"?o:new tn(String(o))});try{return n?.signal?.throwIfAborted(),vr.verify(e,s.digest,t,{prehash:!1,format:"der"})}catch(o){throw new tn(String(o))}}var gs=class{type="secp256k1";raw;_key;constructor(e){this._key=qu(e),this.raw=Hu(this._key)}toMultihash(){return je.digest(xt(this))}toCID(){return we.createV1(114,this.toMultihash())}toString(){return me.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:xe(this.raw,e.raw)}verify(e,r,n){return Fu(this._key,r,e,n)}};function Ui(t){return new gs(t)}function Hu(t){return vr.Point.fromBytes(t).toBytes()}function qu(t){try{return vr.Point.fromBytes(t),t}catch(e){throw new ir(String(e))}}function un(t,e){let{Type:r,Data:n}=rt.decode(t),s=n??new Uint8Array;switch(r){case de.RSA:return _i(s,e);case de.Ed25519:return ei(s);case de.secp256k1:return Ui(s);case de.ECDSA:return Co(s);default:throw new Pt}}function zu(t){let{Type:e,Data:r}=rt.decode(t.digest),n=r??new Uint8Array;switch(e){case de.Ed25519:return ei(n);case de.secp256k1:return Ui(n);case de.ECDSA:return Co(n);default:throw new Pt}}function xt(t){return rt.encode({Type:de[t.type],Data:t.raw})}var $u=Symbol.for("nodejs.util.inspect.custom"),Xd=114,fn=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Xs]=!0;toString(){return this.string==null&&(this.string=me.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return we.createV1(Xd,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return xe(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return xe(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[$u](){return`PeerId(${this.toString()})`}},ln=class extends fn{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},hn=class extends fn{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},dn=class extends fn{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},Qd=2336,pn=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=je.digest(ee(this.url))}[$u](){return`PeerId(${this.url})`}[Xs]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return we.createV1(Qd,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=W(e)),e.toString()===this.toString())}};var Jd=114,Vu=2336;function ju(t,e){let r;if(t.charAt(0)==="1"||t.charAt(0)==="Q")r=hr(me.decode(`z${t}`));else{if(t.startsWith("k51qzi5uqu5")||t.startsWith("kzwfwjn5ji4")||t.startsWith("k2k4r8")||t.startsWith("bafz"))return ep(we.parse(t));if(e==null)throw new se('Please pass a multibase decoder for strings that do not start with "1" or "Q"');r=hr(e.decode(t))}return Wu(r)}function Ni(t){if(t.type==="Ed25519")return new hn({multihash:t.toCID().multihash,publicKey:t});if(t.type==="secp256k1")return new dn({multihash:t.toCID().multihash,publicKey:t});if(t.type==="RSA")return new ln({multihash:t.toCID().multihash,publicKey:t});throw new Pt}function Wu(t){if(rp(t))return new ln({multihash:t});if(tp(t))try{let e=zu(t);if(e.type==="Ed25519")return new hn({multihash:t,publicKey:e});if(e.type==="secp256k1")return new dn({multihash:t,publicKey:e})}catch{let r=W(t.digest);return new pn(new URL(r))}throw new In("Supplied PeerID Multihash is invalid")}function ep(t){if(t?.multihash==null||t.version==null||t.version===1&&t.code!==Jd&&t.code!==Vu)throw new Cn("Supplied PeerID CID is invalid");if(t.code===Vu){let e=W(t.multihash.digest);return new pn(new URL(e))}return Wu(t.multihash)}function tp(t){return t.code===je.code}function rp(t){return t.code===Hr.code}function np(t){let e=t.getComponents(),r={},n=0;return e[n]?.name==="ip6zone"&&(r.zone=`${e[n].value}`,n++),e[n]?.name==="ip4"||e[n]?.name==="ip6"||e[n]?.name==="dns"||e[n]?.name==="dns4"||e[n]?.name==="dns6"?(r.type=e[n].name,r.host=e[n].value,n++):e[n]?.name==="dnsaddr"&&(r.type=e[n].name,r.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(r.protocol=e[n].name==="tcp"?"tcp":"udp",r.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(r.type==="ip4"?r.cidr=parseInt(`${e[n].value}`):r.type==="ip6"&&(r.cidr=`${e[n].value}`),n++),r.type==null||r.host==null?null:(e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(r.sni=e[n+1].value,n+=2),r)}function Yu(t){let e=np(t);if(e==null)throw new se(`Multiaddr ${t} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}var bs=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let r=this.index,n=e();return n===void 0&&(this.index=r),n}parseWith(e){let r=e();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let r=this.readChar();if(r===e)return r})}readSeparator(e,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,r,n,s){return this.readAtomically(()=>{let o=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*s)-1;for(;;){let f=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let d=Number.parseInt(l,e);if(!Number.isNaN(d))return d});if(f===void 0)break;if(o*=e,o+=f,o>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:o})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let r=0;r<e.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[r]=n}return e})}readIPv6Addr(){let e=r=>{for(let n=0;n<r.length/2;n++){let s=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[s]=i[0],r[s+1]=i[1],r[s+2]=i[2],r[s+3]=i[3],[s+4,!0]}let o=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(o===void 0)return[s,!1];r[s]=o>>8,r[s+1]=o&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,s]=e(r);if(n===16)return r;if(s||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let o=new Uint8Array(14),i=16-(n+2),[a]=e(o.subarray(0,i));return r.set(o.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var sp=45,op=15,ws=new bs;function Gu(t){if(!(t.length>op))return ws.new(t).parseWith(()=>ws.readIPv4Addr())}function Zu(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>sp))return ws.new(t).parseWith(()=>ws.readIPv6Addr())}function xs(t){return!!Gu(t)}function Xu(t){return!!Zu(t)}var Be=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},lt=class extends Error{static name="ValidationError";name="ValidationError"},Es=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Ss=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function Mi(t){return e=>W(e,t)}function Ki(t){return e=>ee(e,t)}function Ar(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function Qt(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function Qu(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let r=ee(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let s=Qt(n);return Ke([r,s],r.length+s.length)}function Ju(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let r=bt.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let s=Qt(n);return Ke([r,s],r.length+s.length)}function Fi(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=W(e,"base32"),s=Ar(r);return`${n}:${s}`}var Hi=function(t){t=t.toString().trim();let e=new Uint8Array(4);return t.split(/\./g).forEach((r,n)=>{let s=parseInt(r,10);if(isNaN(s)||s<0||s>255)throw new Be("Invalid byte value in IP address");e[n]=s}),e},ef=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let o=xs(r[n]),i;o&&(i=Hi(r[n]),r[n]=W(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,W(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let o=[n,1];for(n=9-r.length;n>0;n--)o.push("0");r.splice.apply(r,o)}let s=new Uint8Array(e+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let o=parseInt(r[n],16);if(isNaN(o)||o<0||o>65535)throw new Be("Invalid byte value in IP address");s[e++]=o>>8&255,s[e++]=o&255}return s},tf=function(t){if(t.byteLength!==4)throw new Be("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},rf=function(t){if(t.byteLength!==16)throw new Be("IPv6 address was incorrect length");let e=[];for(let n=0;n<t.byteLength;n+=2){let s=t[n],o=t[n+1],i=`${s.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}`;e.push(i)}let r=e.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new Be(`Invalid IPv6 address "${r}"`)}};function nf(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new Be(`Invalid IPv6 address "${t}"`)}}var ki=Object.values(kt).map(t=>t.decoder),ip=(function(){let t=ki[0].or(ki[1]);return ki.slice(2).forEach(e=>t=t.or(e)),t})();function sf(t){return ip.decode(t)}function of(t){return e=>t.encoder.encode(e)}function ap(t){if(parseInt(t).toString()!==t)throw new lt("Value must be an integer")}function cp(t){if(t<0)throw new lt("Value must be a positive integer, or zero")}function up(t){return e=>{if(e>t)throw new lt(`Value must be smaller than or equal to ${t}`)}}function fp(...t){return e=>{for(let r of t)r(e)}}var mn=fp(ap,cp,up(65535));var ve=-1,qi=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let r;if(typeof e=="string"?r=this.protocolsByName.get(e):r=this.protocolsByCode.get(e),r==null)throw new Ss(`Protocol ${e} was unknown`);return r}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(r=>{this.protocolsByName.set(r,e)})}removeProtocol(e){let r=this.protocolsByCode.get(e);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},dt=new qi,Ap=[{code:4,name:"ip4",size:32,valueToBytes:Hi,bytesToValue:tf,validate:t=>{if(!xs(t))throw new lt(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Qt,bytesToValue:Ar,validate:mn},{code:273,name:"udp",size:16,valueToBytes:Qt,bytesToValue:Ar,validate:mn},{code:33,name:"dccp",size:16,valueToBytes:Qt,bytesToValue:Ar,validate:mn},{code:41,name:"ip6",size:128,valueToBytes:ef,bytesToValue:rf,stringToValue:nf,validate:t=>{if(!Xu(t))throw new lt(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:ve},{code:43,name:"ipcidr",size:8,bytesToValue:Mi("base10"),valueToBytes:Ki("base10")},{code:53,name:"dns",size:ve},{code:54,name:"dns4",size:ve},{code:55,name:"dns6",size:ve},{code:56,name:"dnsaddr",size:ve},{code:132,name:"sctp",size:16,valueToBytes:Qt,bytesToValue:Ar,validate:mn},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ve,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:ve,bytesToValue:Mi("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?Ki("base58btc")(t):we.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Fi,valueToBytes:Qu},{code:445,name:"onion3",size:296,bytesToValue:Fi,valueToBytes:Ju},{code:446,name:"garlic64",size:ve},{code:447,name:"garlic32",size:ve},{code:448,name:"tls"},{code:449,name:"sni",size:ve},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:ve,bytesToValue:of(yo),valueToBytes:sf},{code:480,name:"http"},{code:481,name:"http-path",size:ve,stringToValue:t=>`/${decodeURIComponent(t)}`,valueToString:t=>encodeURIComponent(t.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:ve}];Ap.forEach(t=>{dt.addProtocol(t)});function af(t){let e=[],r=0;for(;r<t.length;){let n=zt(t,r),s=dt.getProtocol(n),o=Ce(n),i=Bp(s,t,r+o),a=0;i>0&&s.size===ve&&(a=Ce(i));let c=o+a+i,u={code:n,name:s.name,bytes:Ae(t.subarray(r,r+c))};if(i>0){let f=r+o+a,l=t.subarray(f,f+i);u.value=s.bytesToValue?.(l)??W(l)}e.push(u),r+=c}return e}function cf(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let s=dt.getProtocol(n.code),o=Ce(n.code),i,a=0,c=0;n.value!=null&&(i=s.valueToBytes?.(n.value)??ee(n.value),a=i.byteLength,s.size===ve&&(c=Ce(a)));let u=new Uint8Array(o+c+a),f=0;Er(n.code,u,f),f+=o,i!=null&&(s.size===ve&&(Er(a,u,f),f+=c),u.set(i,f)),n.bytes=u}r.push(n.bytes),e+=n.bytes.byteLength}return Ke(r,e)}function uf(t){if(t.charAt(0)!=="/")throw new Be('String multiaddr must start with "/"');let e=[],r="protocol",n="",s="";for(let o=1;o<t.length;o++){let i=t.charAt(o);i!=="/"&&(r==="protocol"?s+=t.charAt(o):n+=t.charAt(o));let a=o===t.length-1;if(i==="/"||a){let c=dt.getProtocol(s);if(r==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",s="",r="protocol";continue}else if(a)throw new Be(`Component ${s} was missing value`);r="value"}else if(r==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new Be(`Component ${s} was missing value`);u.value=c.stringToValue?.(n)??n}e.push(u),n="",s="",r="protocol"}}}if(s!==""&&n!=="")throw new Be("Incomplete multiaddr");return e}function ff(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=dt.getProtocol(e.code);if(r==null)throw new Be(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function Bp(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:zt(e,r)}var _p=Symbol.for("nodejs.util.inspect.custom"),ia=Symbol.for("@multiformats/multiaddr");function Lp(t){if(t==null&&(t="/"),lf(t))return t.getComponents();if(t instanceof Uint8Array)return af(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),uf(t);if(Array.isArray(t))return t;throw new Be("Must be a string, Uint8Array, Component[], or another Multiaddr")}var oa=class t{[ia]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=Lp(e),r.validate!==!1&&Tp(this)}get bytes(){return this.#r==null&&(this.#r=cf(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=ff(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let r=new t(e);return new t([...this.#e,...r.getComponents()],{validate:!1})}decapsulate(e){let r=e.toString(),n=this.toString(),s=n.lastIndexOf(r);if(s<0)throw new Es(`Address ${this.toString()} does not contain subaddress: ${r}`);return new t(n.slice(0,s),{validate:!1})}decapsulateCode(e){let r;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){r=n;break}return new t(this.#e.slice(0,r),{validate:!1})}equals(e){return xe(this.bytes,e.bytes)}[_p](){return`Multiaddr(${this.toString()})`}};function Tp(t){t.getComponents().forEach(e=>{let r=dt.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function lf(t){return!!t?.[ia]}var fe=t=>({match:e=>{let r=e[0];return r==null||r.code!==t||r.value!=null?!1:e.slice(1)}}),V=(t,e)=>({match:r=>{let n=r[0];return n?.code!==t||n.value==null||e!=null&&n.value!==e?!1:r.slice(1)}}),hf=t=>({match:e=>t.match(e)===!1?e:!1}),G=t=>({match:e=>{let r=t.match(e);return r===!1?e:r}}),De=(...t)=>({match:e=>{let r;for(let n of t){let s=n.match(e);s!==!1&&(r==null||s.length<r.length)&&(r=s)}return r??!1}}),J=(...t)=>({match:e=>{for(let r of t){let n=r.match(e);if(n===!1)return!1;e=n}return e}});function le(...t){function e(s){if(s==null)return!1;let o=s.getComponents();for(let i of t){let a=i.match(o);if(a===!1)return!1;o=a}return o}function r(s){return e(s)!==!1}function n(s){let o=e(s);return o===!1?!1:o.length===0}return{matchers:t,matches:r,exactMatch:n}}var Cp=V(421),e1=le(Cp),Cs=V(54),Is=V(55),Ds=V(56),ca=V(53),t1=le(Cs,G(V(421))),r1=le(Is,G(V(421))),n1=le(Ds,G(V(421))),s1=le(De(ca,Ds,Cs,Is),G(V(421))),df=J(V(4),G(V(43))),pf=J(G(V(42)),V(41),G(V(43))),ua=De(df,pf),Tr=De(ua,ca,Cs,Is,Ds),o1=le(De(ua,J(De(ca,Ds,Cs,Is),G(V(421))))),i1=le(df),a1=le(pf),c1=le(ua),fa=J(Tr,V(6)),yn=J(Tr,V(273)),u1=le(J(fa,G(V(421)))),f1=le(yn),la=J(yn,fe(460),G(V(421))),Rs=J(yn,fe(461),G(V(421))),Ip=De(la,Rs),l1=le(la),h1=le(Rs),aa=De(Tr,fa,yn,la,Rs),mf=De(J(aa,fe(477),G(V(421)))),d1=le(mf),yf=De(J(aa,fe(478),G(V(421))),J(aa,fe(448),G(V(449)),fe(477),G(V(421)))),p1=le(yf),gf=J(yn,fe(280),G(V(466)),G(V(466)),G(V(421))),m1=le(gf),bf=J(Rs,fe(465),G(V(466)),G(V(466)),G(V(421))),Os=le(bf),Ts=De(mf,yf,J(fa,G(V(421))),J(Ip,G(V(421))),J(Tr,G(V(421))),gf,bf,V(421)),y1=le(Ts),Dp=J(G(Ts),fe(290),hf(fe(281)),G(V(421))),g1=le(Dp),Rp=De(J(Ts,fe(290),fe(281),G(V(421))),J(Ts,fe(281),G(V(421))),J(fe(281),G(V(421)))),b1=le(Rp),Op=J(Tr,De(J(V(6,"80")),J(V(6),fe(480)),fe(480)),G(V(481)),G(V(421))),w1=le(Op),Pp=J(Tr,De(J(V(6,"443")),J(V(6,"443"),fe(480)),J(V(6),fe(443)),J(V(6),fe(448),fe(480)),J(fe(448),fe(480)),fe(448),fe(443)),G(V(481)),G(V(421))),x1=le(Pp),Up=De(J(V(777),G(V(421)))),E1=le(Up),Np=De(J(V(400),G(V(421)))),S1=le(Np);function Ps(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Us=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},Cr=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Us(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let r=this.head;this.head=r.next=new Us(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var ha=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Ns(t={}){return kp(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},t)}function kp(t,e){e=e??{};let r=e.onEnd,n=new Cr,s,o,i,a=Ps(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((y,x)=>{o=E=>{o=null,n.push(E);try{y(t(n))}catch(w){x(w)}return s}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Ps()})}},u=y=>o!=null?o(y):(n.push(y),s),f=y=>(n=new Cr,o!=null?o({error:y}):(n.push({error:y}),s)),l=y=>{if(i)return s;if(e?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:y})},d=y=>i?s:(i=!0,y!=null?f(y):u({done:!0})),p=()=>(n=new Cr,d(),{done:!0}),g=y=>(d(y),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:p,throw:g,push:l,end:d,get readableLength(){return n.size},onEmpty:async y=>{let x=y?.signal;if(x?.throwIfAborted(),n.isEmpty())return;let E,w;x!=null&&(E=new Promise((I,T)=>{w=()=>{T(new ha)},x.addEventListener("abort",w)}));try{await Promise.race([a.promise,E])}finally{w!=null&&x!=null&&x?.removeEventListener("abort",w)}}},r==null)return s;let b=s;return s={[Symbol.asyncIterator](){return this},next(){return b.next()},throw(y){return b.throw(y),r!=null&&(r(y),r=void 0),{done:!0}},return(){return b.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(y){return b.end(y),r!=null&&(r(y),r=void 0),s},get readableLength(){return b.readableLength},onEmpty:y=>b.onEmpty(y)},s}var da=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},wf=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function pa(t,e){let{milliseconds:r,fallback:n,message:s,customTimers:o={setTimeout,clearTimeout},signal:i}=e,a,c,f=new Promise((l,d)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){d(wf(i));return}if(i&&(c=()=>{d(wf(i))},i.addEventListener("abort",c,{once:!0})),t.then(l,d),r===Number.POSITIVE_INFINITY)return;let p=new da;a=o.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(g){d(g)}return}typeof t.cancel=="function"&&t.cancel(),s===!1?l():s instanceof Error?d(s):(p.message=s??`Promise timed out after ${r} milliseconds`,d(p))},r)}).finally(()=>{f.clear(),c&&i&&i.removeEventListener("abort",c)});return f.clear=()=>{o.clearTimeout.call(void 0,a),a=void 0},f}var Mp=t=>{let e=t.addEventListener||t.on||t.addListener,r=t.removeEventListener||t.off||t.removeListener;if(!e||!r)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(t),removeListener:r.bind(t)}};function Kp(t,e,r){let n,s=new Promise((o,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:u,removeListener:f}=Mp(t),l=async(...p)=>{let g=r.multiArgs?p:p[0];if(r.filter)try{if(!await r.filter(g))return}catch(b){n(),i(b);return}c.push(g),r.count===c.length&&(n(),o(c))},d=(...p)=>{n(),i(r.rejectionMultiArgs?p:p[0])};n=()=>{for(let p of a)f(p,l);for(let p of r.rejectionEvents)a.includes(p)||f(p,d)};for(let p of a)u(p,l);for(let p of r.rejectionEvents)a.includes(p)||u(p,d);r.signal&&r.signal.addEventListener("abort",()=>{d(r.signal.reason)},{once:!0}),r.resolveImmediately&&o(c)});if(s.cancel=n,typeof r.timeout=="number"){let o=pa(s,{milliseconds:r.timeout});return o.cancel=()=>{n(),o.clear()},o}return s}function Dt(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Kp(t,e,r),s=n.then(o=>o[0]);return s.cancel=n.cancel,s}var er=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"},ks=class extends Error{static name="MaxEarlyStreamsError";name="MaxEarlyStreamsError"},Ms=class extends Error{static name="StreamClosedError";name="StreamClosedError"};function Fp(t){return t.reason}function $e(t,e,r){if(e==null||t==null)return t;let n=r?.translateError??Fp;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let s;return Promise.race([t,new Promise((o,i)=>{s=()=>{i(n(e))},e.addEventListener("abort",s)})]).finally(()=>{s!=null&&e.removeEventListener("abort",s)})}var Hp=Math.pow(2,20)*4,nt=class extends cr{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;#e=!1;onDrainPromise;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??Hp,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new Q,this.writeBuffer=new Q,this.readStatus="readable",this.remoteReadStatus="readable",this.writeStatus="writable",this.remoteWriteStatus="writable",this.sendingData=!1,this.writableNeedsDrain=!1,this.timeline={open:Date.now()},this.processSendQueue=this.processSendQueue.bind(this);let r=()=>{this.writableNeedsDrain&&(this.log.trace("drain event received, continue sending data"),this.writableNeedsDrain=!1,queueMicrotask(()=>{try{this.processSendQueue()}catch(s){this.log.error("processSendQueue threw - %e",s)}})),this.onDrainPromise?.resolve()};this.addEventListener("drain",r);let n=s=>{this.onDrainPromise?.reject(s.error??new Ms)};this.addEventListener("close",n)}get readBufferLength(){return this.readBuffer.byteLength}get readableEnded(){return this.#e}get writeBufferLength(){return this.writeBuffer.byteLength}async onDrain(e){return this.writableNeedsDrain!==!0?Promise.resolve():(this.onDrainPromise==null&&(this.onDrainPromise=Promise.withResolvers()),$e(this.onDrainPromise.promise,e?.signal))}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=Ns(),r=o=>{e.push(o.data)};this.addEventListener("message",r);let n=o=>{e.end(o.error)};this.addEventListener("close",n);let s=()=>{e.end()};this.addEventListener("remoteCloseWrite",s);try{yield*e}finally{this.removeEventListener("message",r),this.removeEventListener("close",n),this.removeEventListener("remoteCloseWrite",s)}}isReadable(){return this.status==="open"}send(e){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new yt(`Cannot write to a stream that is ${this.writeStatus}`);return this.log.trace("append %d bytes to write buffer",e.byteLength),this.writeBuffer.append(e),this.processSendQueue()}abort(e){if(!(this.status==="aborted"||this.status==="reset"||this.status==="closed")){this.log.error("abort with error - %e",e),this.status="aborted",this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle")),this.writeStatus="closed",this.remoteWriteStatus="closed",this.readStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.maybeDispatchEnd();try{this.sendReset(e)}catch(r){this.log.error("failed to send reset to remote - %e",r)}this.dispatchEvent(new Rn(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new yt("Cannot pause a stream that is closing/closed");this.readStatus!=="paused"&&(this.readStatus="paused",this.sendPause())}resume(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new yt("Cannot resume a stream that is closing/closed");this.readStatus!=="readable"&&(this.readStatus="readable",this.dispatchReadBuffer(),this.sendResume())}push(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new yt(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.append(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}unshift(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new yt(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.prepend(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}onData(e){if(e.byteLength!==0){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("ignoring data - read status %s",this.readStatus);return}this.readBuffer.append(e),this.dispatchReadBuffer()}}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="message"&&this.readBuffer.byteLength>0&&queueMicrotask(()=>{this.dispatchReadBuffer()})}onRemoteReset(){this.log("remote reset"),this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed",this.maybeDispatchEnd()),this.dispatchEvent(new On(new Ln))}onTransportClosed(e){this.log("transport closed"),this.readStatus==="readable"&&this.readBuffer.byteLength===0&&(this.log("close readable end after transport closed and read buffer is empty"),this.readStatus="closed"),this.remoteReadStatus!=="closed"&&(this.remoteReadStatus="closed"),this.remoteWriteStatus!=="closed"&&(this.remoteWriteStatus="closed"),this.writeStatus!=="closed"&&(this.writeStatus="closed"),e!=null?this.abort(e):(this.status==="open"||this.status==="closing")&&(this.timeline.close=Date.now(),this.status="closed",this.maybeDispatchEnd(),this.dispatchEvent(new ar))}onRemoteCloseWrite(){this.remoteWriteStatus!=="closed"&&(this.log.trace("on remote close write"),this.remoteWriteStatus="closed",this.safeDispatchEvent("remoteCloseWrite"),this.maybeDispatchEnd(),this.writeStatus==="closed"&&this.onTransportClosed())}onRemoteCloseRead(){this.log.trace("on remote close read"),this.remoteReadStatus="closed",this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle"))}processSendQueue(){if(this.writableNeedsDrain)return this.log.trace("not processing send queue as drain is required"),this.checkWriteBufferLength(),!1;if(this.writeBuffer.byteLength===0)return this.log.trace("not processing send queue as no bytes to send"),!0;if(this.sendingData)return this.log.trace("not processing send queue as already sending data"),!0;if(this.writeStatus!=="writable"&&this.writeStatus!=="closing")return this.log.trace("not processing send queue as stream is %s",this.writeStatus),!1;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let e=!0,r=this.writeBuffer.byteLength,n=0;for(;this.writeBuffer.byteLength>0;){let s=Math.min(this.maxMessageSize??this.writeBuffer.byteLength,this.writeBuffer.byteLength);if(s===0){e=!1;break}let o=this.writeBuffer.sublist(0,s),i=new Q(o);this.writeBuffer.consume(o.byteLength);let a;try{a=this.sendData(o)}catch(c){throw this.writeBuffer.prepend(i),this.abort(c),c}if(e=a.canSendMore,n+=a.sentBytes,a.sentBytes!==i.byteLength&&(i.consume(a.sentBytes),this.writeBuffer.prepend(i)),!e)break}return e||(this.log.trace("sent %d/%d bytes, pausing sending because underlying stream is full, %d bytes left in the write buffer",n,r,this.writeBuffer.byteLength),this.writableNeedsDrain=!0,this.checkWriteBufferLength()),this.writeBuffer.byteLength===0&&this.safeDispatchEvent("idle"),e}finally{this.sendingData=!1}}maybeDispatchEnd(){this.#e||this.readBuffer.byteLength>0||this.remoteWriteStatus!=="closed"&&this.readStatus!=="closed"||(this.#e=!0,this.safeDispatchEvent("end"))}dispatchReadBuffer(){try{if(this.listenerCount("message")===0){this.log.trace("not dispatching pause buffer as there are no listeners for the message event");return}if(this.readBuffer.byteLength===0){this.log.trace("not dispatching pause buffer as there is no data to dispatch");return}if(this.readStatus==="paused"){this.log.trace("not dispatching pause buffer we are paused");return}if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("dropping %d bytes because the readable end is %s",this.readBuffer.byteLength,this.readStatus),this.readBuffer.consume(this.readBuffer.byteLength);return}let e=this.readBuffer.sublist();this.readBuffer.consume(e.byteLength),this.dispatchEvent(new Dn(e))}finally{this.readBuffer.byteLength===0&&this.remoteWriteStatus==="closed"&&(this.log("close readable end after dispatching read buffer and remote writable end is closed"),this.readStatus="closed",this.maybeDispatchEnd()),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new Ot(`Read buffer length of ${this.readBuffer.byteLength} exceeded limit of ${this.maxReadBufferLength}, read status is ${this.readStatus}`))}checkWriteBufferLength(){this.maxWriteBufferLength!=null&&this.writeBuffer.byteLength>this.maxWriteBufferLength&&this.abort(new Ot(`Write buffer length of ${this.writeBuffer.byteLength} exceeded limit of ${this.maxWriteBufferLength}, write status is ${this.writeStatus}`))}onMuxerNeedsDrain(){this.writableNeedsDrain=!0}onMuxerDrain(){this.safeDispatchEvent("drain")}};var Ks=class extends nt{remoteAddr;metricPrefix;metrics;constructor(e){super(e),this.metricPrefix=e.metricPrefix??"",this.metrics=e.metrics,this.remoteAddr=e.remoteAddr,this.addEventListener("close",r=>{this.metrics?.increment({[`${this.metricPrefix}end`]:!0}),r.error!=null?r.local?this.metrics?.increment({[`${this.metricPrefix}abort`]:!0}):this.metrics?.increment({[`${this.metricPrefix}reset`]:!0}):r.local?this.metrics?.increment({[`${this.metricPrefix}_local_close`]:!0}):this.metrics?.increment({[`${this.metricPrefix}_remote_close`]:!0})})}async close(e){this.status==="open"&&(this.status="closing",this.writeStatus="closing",this.remoteWriteStatus="closing",this.remoteReadStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await Dt(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await Dt(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};function xf(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Fs=class extends cr{streams;protocol;status;log;maConn;streamOptions;earlyStreams;maxEarlyStreams;metrics;constructor(e,r){super(),this.maConn=e,this.protocol=r.protocol,this.streams=[],this.earlyStreams=[],this.status="open",this.log=e.log.newScope(r.name),this.streamOptions=r.streamOptions,this.maxEarlyStreams=r.maxEarlyStreams??10,this.metrics=r.metrics;let n=i=>{try{this.onData(i.data)}catch(a){this.abort(a),this.maConn.abort(a)}};this.maConn.addEventListener("message",n);let s=()=>{this.log("underlying stream drained, signal %d streams to continue writing",this.streams.length),this.streams.forEach(i=>{i.onMuxerDrain()})};this.maConn.addEventListener("drain",s);let o=()=>{this.log("underlying stream closed with status %s and %d streams",this.status,this.streams.length),this.onTransportClosed()};this.maConn.addEventListener("close",o)}send(e){let r=this.maConn.send(e);return r===!1&&(this.log("underlying stream saturated, signal %d streams to pause writing",this.streams.length),this.streams.forEach(n=>{n.onMuxerNeedsDrain()})),r}async close(e){this.status==="closed"||this.status==="closing"||(this.status="closing",await $e(Promise.all([...this.streams].map(async r=>{await r.close(e)})),e?.signal),this.status="closed")}abort(e){this.status!=="closed"&&(this.status="closing",[...this.streams].forEach(r=>{r.abort(e)}),this.status="closed")}onTransportClosed(e){this.status="closing";try{[...this.streams].forEach(r=>{r.onTransportClosed(e)})}catch(r){this.abort(r)}this.status="closed"}async createStream(e){if(this.status!=="open")throw new _n;let r=this.onCreateStream({...this.streamOptions,...e});return xf(r)&&(r=await r),this.streams.push(r),this.cleanUpStream(r),r}onRemoteStream(e){if(this.streams.push(e),this.cleanUpStream(e),this.listenerCount("stream")===0){this.earlyStreams.push(e),this.earlyStreams.length>this.maxEarlyStreams&&this.abort(new ks(`Too many early streams were opened - ${this.earlyStreams.length}/${this.maxEarlyStreams}`));return}this.safeDispatchEvent("stream",{detail:e})}cleanUpStream(e){let r=n=>{let s=this.streams.findIndex(o=>o===e);s!==-1&&this.streams.splice(s,1),n.error!=null?n.local?this.metrics?.increment({[`${e.direction}_stream_reset`]:!0}):this.metrics?.increment({[`${e.direction}_stream_abort`]:!0}):this.metrics?.increment({[`${e.direction}_stream_end`]:!0})};e.addEventListener("close",r),this.metrics?.increment({[`${e.direction}_stream`]:!0})}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="stream"&&this.earlyStreams.length>0&&queueMicrotask(()=>{this.earlyStreams.forEach(r=>{this.safeDispatchEvent("stream",{detail:r})}),this.earlyStreams=[]})}};var Hs=class extends nt{id;protocol;constructor(e){super(e),this.id=e.id,this.protocol=e.protocol??""}async close(e){this.writeStatus==="closing"||this.writeStatus==="closed"||(this.writeStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await Dt(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes, sending %s",this.writeBuffer.byteLength,this.sendingData),await Dt(this,"drain",{...e,rejectionEvents:["close"]}),this.log("write queue drained, closing writable end of stream, %d unsent bytes, sending %s",this.writeBuffer.byteLength,this.sendingData)),await this.sendCloseWrite(e),this.writeStatus="closed",this.log("closed writable end gracefully"),this.remoteWriteStatus==="closed"&&this.onTransportClosed())}async closeRead(e){this.readStatus==="closing"||this.readStatus==="closed"||(this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.readStatus="closing",await this.sendCloseRead(e),this.readStatus="closed",this.maybeDispatchEnd(),this.log("closed readable end gracefully"))}};var qp=4194304,qs=class extends Error{static name="UnwrappedError";name="UnwrappedError"},gn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ya=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},ga=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function zp(t){return typeof t?.closeRead=="function"}function $p(t){return typeof t?.close=="function"}function ma(t){return zp(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:$p(t)?t.status!=="open":!1}function Vp(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function jp(t,e){let r=e?.maxBufferSize??qp,n=new Q,s,o=!1,i;if(!Vp(t))throw new se("Argument should be a Stream or a Multiaddr");let a=l=>{if(i==null){if(n.append(l.data),n.byteLength>r){let d=n.byteLength;n.consume(d);let p=new Ot(`Read buffer overflow - ${d} > ${r}`);i=p,s?.reject(p),queueMicrotask(()=>{t.abort(p)});return}s?.resolve()}};t.addEventListener("message",a);let c=l=>{l.error!=null?s?.reject(l.error):s?.resolve()};t.addEventListener("close",c);let u=()=>{s?.resolve()};t.addEventListener("remoteCloseWrite",u);let f={readBuffer:n,async read(l){if(o===!0)throw new qs("Stream was unwrapped");if(i!=null)throw i;if(ma(t)){if(n.byteLength===0&&l?.bytes==null)return null;if(l?.bytes!=null&&n.byteLength<l.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,l.bytes),new er(`Unexpected EOF - stream closed after reading ${n.byteLength}/${l.bytes} bytes`)}let d=l?.bytes??1;for(s=Promise.withResolvers();;){if(n.byteLength>=d){s.resolve();break}if(await $e(s.promise,l?.signal),ma(t)){if(n.byteLength===0&&l?.bytes==null)return null;break}s=Promise.withResolvers()}let p=l?.bytes??n.byteLength;if(n.byteLength<p){if(ma(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,p),new er(`Unexpected EOF - stream closed while reading ${n.byteLength}/${p} bytes`);return f.read(l)}let g=n.sublist(0,p);return n.consume(p),g},async write(l,d){if(o===!0)throw new qs("Stream was unwrapped");t.send(l)||await Dt(t,"drain",{signal:d?.signal,rejectionEvents:["close"]})},unwrap(){return o||(o=!0,t.removeEventListener("message",a),t.removeEventListener("close",c),t.removeEventListener("remoteCloseWrite",u),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.unshift(n))),t}};return f}function ba(t,e={}){let r=jp(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Ce(e.maxDataLength));let n=e?.lengthDecoder??zt,s=e?.lengthEncoder??yu;return{async read(i){let a=-1,c=new Q;for(;;){let f=await r.read({...i,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new gn("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new ga(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new ya(`Message length too long - ${a} > ${e.maxDataLength}`);let u=await r.read({...i,bytes:a});if(u==null)throw t.log.error("tried to read %d bytes but the stream closed",a),new er(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw t.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new er(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await r.write(new Q(s(i.byteLength),i),a)},async writeV(i,a){let c=new Q(...i.flatMap(u=>[s(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}var Wp=1024*1024*4,Yp=1024*1024*4,zs=class{buffer;maxBufferSize;lengthDecoder;maxDataLength;encodingLength;constructor(e={}){this.buffer=new Q,this.maxBufferSize=e.maxBufferSize??Wp,this.maxDataLength=e.maxDataLength??Yp,this.lengthDecoder=e.lengthDecoder??zt,this.encodingLength=e.encodingLength??Ce}*decode(e){if(this.buffer.append(e),this.buffer.byteLength>this.maxBufferSize)throw new se(`Buffer length limit exceeded - ${this.buffer.byteLength}/${this.maxBufferSize}`);for(;;){let r;try{r=this.lengthDecoder(this.buffer)}catch(o){if(o instanceof RangeError)break;throw o}if(r<0||r>this.maxDataLength)throw new gn("Invalid message length");let n=this.encodingLength(r),s=n+r;if(this.buffer.byteLength>=s){let o=this.buffer.sublist(n,s);this.buffer.consume(s),o.byteLength>0&&(yield o)}else break}}};var Ir=!!globalThis.process?.env?.DUMP_SESSION_KEYS,wa=16;function xa(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var $s=t=>t?`"${t}" `:"";function Vs(t,e=""){if(typeof t!="boolean")throw new TypeError($s(e)+"expected boolean, got type="+typeof t);return t}function tr(t,e=""){if(typeof t!="number")throw new TypeError($s(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError($s(e)+"expected integer >= 0, got "+t);return t}function ge(t,e,r=""){if(xa(t)&&(e===void 0||t.length===e))return t;e!==void 0&&tr(e,"length");let n=xa(t),s=e!==void 0?` of length ${e}`:"",o=n?`length=${t.length}`:`type=${typeof t}`,i=$s(r)+"expected Uint8Array"+s+", got "+o;throw n?new RangeError(i):new TypeError(i)}var Ef=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof t}`)};function Ea(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function Sf(t,e){ge(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function st(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function Ze(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Gp(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}var Rt=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Zp(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function Xp(t){for(let e=0;e<t.length;e++)t[e]=Zp(t[e]);return t}var pt=Rt?t=>t:Xp;function Qp(t,e){return!t.byteLength||!e.byteLength?!1:t.buffer===e.buffer&&t.byteOffset<e.byteOffset+e.byteLength&&e.byteOffset<t.byteOffset+t.byteLength}function vf(t,e){if(Qp(t,e)&&t.byteOffset<e.byteOffset)throw new Error("complex overlap of input and output is not supported")}function Af(t,e){return Ef(t,"defaults"),Ef(e,"opts"),Object.assign(t,e)}function Bf(t,e){if(t=ge(t),e=ge(e),t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function _f(t,e,r){let n=e,s=r||(()=>[]),o=(a,c)=>n(c,...s(a)).update(a).digest(),i=n(new Uint8Array(t),...s(new Uint8Array(0)));return o.outputLen=i.outputLen,o.blockLen=i.blockLen,o.create=(a,...c)=>n(a,...c),o}var Lf=(t,e)=>{function r(n,...s){if(ge(n,void 0,"key"),t.nonceLength!==void 0){let l=s[0];ge(l,t.varSizeNonce?void 0:t.nonceLength,"nonce")}let o=t.tagLength,i=t.nonceLength!==void 0?1:0;if(!t.withAAD){for(let l=i;l<s.length;l++)if(xa(s[l]))throw new Error("AAD not supported")}t.withAAD&&s[i]!==void 0&&ge(s[i],void 0,"AAD");let a=e(n,...s),c=(l,d)=>{if(d!==void 0){if(l!==2)throw new Error("cipher output not supported");ge(d,void 0,"output")}},u=!1;return{encrypt(l,d){if(u)throw new Error("cannot encrypt() twice with same key + nonce");return u=!0,ge(l,void 0,"data"),c(a.encrypt.length,d),a.encrypt(l,d)},decrypt(l,d){if(ge(l,void 0,"data"),o&&l.length<o)throw new Error('"ciphertext" expected length >= tagLength='+o);return c(a.decrypt.length,d),a.decrypt(l,d)}}}return Object.assign(r,t),r};function bn(t,e,r=!0){if(e===void 0)return new Uint8Array(t);if(ge(e,t,"output"),r&&!wn(e))throw new Error("invalid output, must be aligned");return e}function Tf(t,e,r){tr(t),tr(e),Vs(r);let n=new Uint8Array(16),s=Gp(n);return s.setBigUint64(0,BigInt(e),r),s.setBigUint64(8,BigInt(t),r),n}function wn(t){return t.byteOffset%4===0}function Dr(t){return Uint8Array.from(ge(t))}var If=t=>Uint8Array.from(t.split(""),e=>e.charCodeAt(0)),Jp=pt(st(If("expand 16-byte k"))),em=pt(st(If("expand 32-byte k")));function X(t,e){return t<<e|t>>>32-e}var xn=64,tm=16,Sa=2**32-1,Cf=Uint32Array.of();function rm(t,e,r,n,s,o,i,a){let c=s.length,u=new Uint8Array(xn),f=st(u),l=Rt&&wn(s)&&wn(o),d=l?st(s):Cf,p=l?st(o):Cf;if(!Rt){for(let g=0;g<c;i++){if(t(e,r,n,f,i,a),pt(f),i>=Sa)throw new Error("arx: counter overflow");let b=Math.min(xn,c-g);for(let y=0,x;y<b;y++)x=g+y,o[x]=s[x]^u[y];g+=b}return}for(let g=0;g<c;i++){if(t(e,r,n,f,i,a),i>=Sa)throw new Error("arx: counter overflow");let b=Math.min(xn,c-g);if(l&&b===xn){let y=g/4;if(g%4!==0)throw new Error("arx: invalid block position");for(let x=0,E;x<tm;x++)E=y+x,p[E]=d[E]^f[x];g+=xn;continue}for(let y=0,x;y<b;y++)x=g+y,o[x]=s[x]^u[y];g+=b}}function Df(t,e){let{allowShortKeys:r,extendNonceFn:n,counterLength:s,counterRight:o,rounds:i}=Af({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof t!="function")throw new Error("core must be a function");return tr(s),tr(i),Vs(o),Vs(r),(a,c,u,f,l=0)=>{ge(a,void 0,"key"),ge(c,void 0,"nonce"),ge(u,void 0,"data");let d=u.length,p=f!==void 0;if(f=bn(d,f,!1),p&&vf(u,f),tr(l),l<0||l>=Sa)throw new Error("arx: counter overflow");let g=[],b=a.length,y,x;if(b===32)g.push(y=Dr(a)),x=em;else if(b===16&&r)y=new Uint8Array(32),y.set(a),y.set(a,16),x=Jp,g.push(y);else throw ge(a,32,"arx key"),new Error("invalid key size");(!Rt||!wn(c))&&g.push(c=Dr(c));let E=st(y);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");let T=c.subarray(0,16);if(Rt)n(x,E,st(T),E);else{let O=pt(Uint32Array.from(x));n(O,E,st(T),E),Ze(O),pt(E)}c=c.subarray(16)}else Rt||pt(E);let w=16-s;if(w!==c.length)throw new Error(`arx: nonce must be ${w} or 16 bytes`);if(w!==12){let T=new Uint8Array(12);T.set(c,o?0:12-c.length),c=T,g.push(c)}let I=pt(st(c));try{return rm(t,x,E,I,u,f,l,i),f}finally{Ze(...g)}}}function _e(t,e){return t[e++]&255|(t[e++]&255)<<8}var va=class{blockLen=16;outputLen=16;buffer=new Uint8Array(16);r=new Uint16Array(10);h=new Uint16Array(10);pad=new Uint16Array(8);pos=0;finished=!1;destroyed=!1;constructor(e){e=Dr(ge(e,32,"key"));let r=_e(e,0),n=_e(e,2),s=_e(e,4),o=_e(e,6),i=_e(e,8),a=_e(e,10),c=_e(e,12),u=_e(e,14);this.r[0]=r&8191,this.r[1]=(r>>>13|n<<3)&8191,this.r[2]=(n>>>10|s<<6)&7939,this.r[3]=(s>>>7|o<<9)&8191,this.r[4]=(o>>>4|i<<12)&255,this.r[5]=i>>>1&8190,this.r[6]=(i>>>14|a<<2)&8191,this.r[7]=(a>>>11|c<<5)&8065,this.r[8]=(c>>>8|u<<8)&8191,this.r[9]=u>>>5&127;for(let f=0;f<8;f++)this.pad[f]=_e(e,16+2*f)}process(e,r,n=!1){let s=n?0:2048,{h:o,r:i}=this,a=i[0],c=i[1],u=i[2],f=i[3],l=i[4],d=i[5],p=i[6],g=i[7],b=i[8],y=i[9],x=_e(e,r+0),E=_e(e,r+2),w=_e(e,r+4),I=_e(e,r+6),T=_e(e,r+8),O=_e(e,r+10),M=_e(e,r+12),U=_e(e,r+14),C=o[0]+(x&8191),D=o[1]+((x>>>13|E<<3)&8191),F=o[2]+((E>>>10|w<<6)&8191),K=o[3]+((w>>>7|I<<9)&8191),$=o[4]+((I>>>4|T<<12)&8191),B=o[5]+(T>>>1&8191),P=o[6]+((T>>>14|O<<2)&8191),_=o[7]+((O>>>11|M<<5)&8191),A=o[8]+((M>>>8|U<<8)&8191),H=o[9]+(U>>>5|s),L=0,S=L+C*a+D*(5*y)+F*(5*b)+K*(5*g)+$*(5*p);L=S>>>13,S&=8191,S+=B*(5*d)+P*(5*l)+_*(5*f)+A*(5*u)+H*(5*c),L+=S>>>13,S&=8191;let h=L+C*c+D*a+F*(5*y)+K*(5*b)+$*(5*g);L=h>>>13,h&=8191,h+=B*(5*p)+P*(5*d)+_*(5*l)+A*(5*f)+H*(5*u),L+=h>>>13,h&=8191;let m=L+C*u+D*c+F*a+K*(5*y)+$*(5*b);L=m>>>13,m&=8191,m+=B*(5*g)+P*(5*p)+_*(5*d)+A*(5*l)+H*(5*f),L+=m>>>13,m&=8191;let v=L+C*f+D*u+F*c+K*a+$*(5*y);L=v>>>13,v&=8191,v+=B*(5*b)+P*(5*g)+_*(5*p)+A*(5*d)+H*(5*l),L+=v>>>13,v&=8191;let R=L+C*l+D*f+F*u+K*c+$*a;L=R>>>13,R&=8191,R+=B*(5*y)+P*(5*b)+_*(5*g)+A*(5*p)+H*(5*d),L+=R>>>13,R&=8191;let N=L+C*d+D*l+F*f+K*u+$*c;L=N>>>13,N&=8191,N+=B*a+P*(5*y)+_*(5*b)+A*(5*g)+H*(5*p),L+=N>>>13,N&=8191;let k=L+C*p+D*d+F*l+K*f+$*u;L=k>>>13,k&=8191,k+=B*c+P*a+_*(5*y)+A*(5*b)+H*(5*g),L+=k>>>13,k&=8191;let q=L+C*g+D*p+F*d+K*l+$*f;L=q>>>13,q&=8191,q+=B*u+P*c+_*a+A*(5*y)+H*(5*b),L+=q>>>13,q&=8191;let z=L+C*b+D*g+F*p+K*d+$*l;L=z>>>13,z&=8191,z+=B*f+P*u+_*c+A*a+H*(5*y),L+=z>>>13,z&=8191;let j=L+C*y+D*b+F*g+K*p+$*d;L=j>>>13,j&=8191,j+=B*l+P*f+_*u+A*c+H*a,L+=j>>>13,j&=8191,L=(L<<2)+L|0,L=L+S|0,S=L&8191,L=L>>>13,h+=L,o[0]=S,o[1]=h,o[2]=m,o[3]=v,o[4]=R,o[5]=N,o[6]=k,o[7]=q,o[8]=z,o[9]=j}finalize(){let{h:e,pad:r}=this,n=new Uint16Array(10),s=e[1]>>>13;e[1]&=8191;for(let a=2;a<10;a++)e[a]+=s,s=e[a]>>>13,e[a]&=8191;e[0]+=s*5,s=e[0]>>>13,e[0]&=8191,e[1]+=s,s=e[1]>>>13,e[1]&=8191,e[2]+=s,n[0]=e[0]+5,s=n[0]>>>13,n[0]&=8191;for(let a=1;a<10;a++)n[a]=e[a]+s,s=n[a]>>>13,n[a]&=8191;n[9]-=8192;let o=(s^1)-1;for(let a=0;a<10;a++)n[a]&=o;o=~o;for(let a=0;a<10;a++)e[a]=e[a]&o|n[a];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let i=e[0]+r[0];e[0]=i&65535;for(let a=1;a<8;a++)i=(e[a]+r[a]|0)+(i>>>16)|0,e[a]=i&65535;Ze(n)}update(e){Ea(this),ge(e),e=Dr(e);let{buffer:r,blockLen:n}=this,s=e.length;for(let o=0;o<s;){let i=Math.min(n-this.pos,s-o);if(i===n){for(;n<=s-o;o+=n)this.process(e,o);continue}r.set(e.subarray(o,o+i),this.pos),this.pos+=i,o+=i,this.pos===n&&(this.process(r,0,!1),this.pos=0)}return this}destroy(){this.destroyed=!0,Ze(this.h,this.r,this.buffer,this.pad)}digestInto(e){Ea(this),Sf(e,this),this.finished=!0;let{buffer:r,h:n}=this,{pos:s}=this;if(s){for(r[s++]=1;s<16;s++)r[s]=0;this.process(r,0,!0)}this.finalize();let o=0;for(let i=0;i<8;i++)e[o++]=n[i]>>>0,e[o++]=n[i]>>>8}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}},Rf=_f(32,t=>new va(t));function nm(t,e,r,n,s,o=20){let i=t[0],a=t[1],c=t[2],u=t[3],f=e[0],l=e[1],d=e[2],p=e[3],g=e[4],b=e[5],y=e[6],x=e[7],E=s,w=r[0],I=r[1],T=r[2],O=i,M=a,U=c,C=u,D=f,F=l,K=d,$=p,B=g,P=b,_=y,A=x,H=E,L=w,S=I,h=T;for(let v=0;v<o;v+=2)O=O+D|0,H=X(H^O,16),B=B+H|0,D=X(D^B,12),O=O+D|0,H=X(H^O,8),B=B+H|0,D=X(D^B,7),M=M+F|0,L=X(L^M,16),P=P+L|0,F=X(F^P,12),M=M+F|0,L=X(L^M,8),P=P+L|0,F=X(F^P,7),U=U+K|0,S=X(S^U,16),_=_+S|0,K=X(K^_,12),U=U+K|0,S=X(S^U,8),_=_+S|0,K=X(K^_,7),C=C+$|0,h=X(h^C,16),A=A+h|0,$=X($^A,12),C=C+$|0,h=X(h^C,8),A=A+h|0,$=X($^A,7),O=O+F|0,h=X(h^O,16),_=_+h|0,F=X(F^_,12),O=O+F|0,h=X(h^O,8),_=_+h|0,F=X(F^_,7),M=M+K|0,H=X(H^M,16),A=A+H|0,K=X(K^A,12),M=M+K|0,H=X(H^M,8),A=A+H|0,K=X(K^A,7),U=U+$|0,L=X(L^U,16),B=B+L|0,$=X($^B,12),U=U+$|0,L=X(L^U,8),B=B+L|0,$=X($^B,7),C=C+D|0,S=X(S^C,16),P=P+S|0,D=X(D^P,12),C=C+D|0,S=X(S^C,8),P=P+S|0,D=X(D^P,7);let m=0;n[m++]=i+O|0,n[m++]=a+M|0,n[m++]=c+U|0,n[m++]=u+C|0,n[m++]=f+D|0,n[m++]=l+F|0,n[m++]=d+K|0,n[m++]=p+$|0,n[m++]=g+B|0,n[m++]=b+P|0,n[m++]=y+_|0,n[m++]=x+A|0,n[m++]=E+H|0,n[m++]=w+L|0,n[m++]=I+S|0,n[m++]=T+h|0}var sm=Df(nm,{counterRight:!1,counterLength:4,allowShortKeys:!1});var om=new Uint8Array(16),Of=(t,e)=>{t.update(e);let r=e.length%16;r&&t.update(om.subarray(r))},im=new Uint8Array(32);function Pf(t,e,r,n,s){s!==void 0&&ge(s,void 0,"AAD");let o=t(e,r,im),i=Tf(n.length,s?s.length:0,!0),a=Rf.create(o);s&&Of(a,s),Of(a,n),a.update(i);let c=a.digest();return Ze(o,i),c}var am=t=>(e,r,n)=>({encrypt(o,i){let a=o.length;i=bn(a+16,i,!1),i.set(o);let c=i.subarray(0,-16);t(e,r,c,c,1);let u=Pf(t,e,r,c,n);return i.set(u,a),Ze(u),i},decrypt(o,i){i=bn(o.length-16,i,!1);let a=o.subarray(0,-16),c=o.subarray(-16),u=Pf(t,e,r,a,n);if(!Bf(c,u))throw Ze(u),new Error("invalid tag");return i.set(o.subarray(0,-16)),t(e,r,i,i,1),Ze(u),i}}),Aa=Lf({blockSize:64,nonceLength:12,tagLength:16,withAAD:!0},am(sm));function Uf(t,e,r){return Ft(t),r===void 0&&(r=new Uint8Array(t.outputLen)),cn(t,r,e)}var En=Uint8Array.of(0),cm=Uint8Array.of();function Nf(t,e,r,n=32,s){Ft(t),We(n,"length"),Oe(e,void 0,"prk");let o=t.outputLen;if(e.length<o)throw new Error('"prk" must be at least HashLen octets');if(n>255*o)throw new Error("Length must be <= 255*HashLen");let i=Math.ceil(n/o);if(r===void 0?r=cm:Oe(r,void 0,"info"),!i)return s&&Fe(e),new Uint8Array;let a=s&&i===1?e:new Uint8Array(i*o),{iHash:c,oHash:u}=cn.create(t,e),f=s?e:new Uint8Array(o),l=i>1?s?.iHash||t.create():void 0;for(let p=0;p<i-1;p++){En[0]=p+1;let g=c._cloneInto(l);p&&g.update(f),g.update(r).update(En).digestInto(f),u._cloneInto(l).update(f).digestInto(f),a.set(f,o*p)}if(En[0]=i,i>1&&c.update(f),c.update(r).update(En).digestInto(f),u.update(f).digestInto(f),a.set(f,o*(i-1)),c.destroy(),u.destroy(),l?.destroy(),f!==a&&Fe(f),Fe(En),n===a.length)return a;let d=a.slice(0,n);return Fe(a),d}var kf={hashSHA256(t){return Qe(t.subarray())},getHKDF(t,e){let r=Uf(Qe,e,t),s=Nf(Qe,r,void 0,96),o=s.subarray(0,32),i=s.subarray(32,64),a=s.subarray(64,96);return[o,i,a]},generateX25519KeyPair(){let t=en.utils.randomSecretKey();return{publicKey:en.getPublicKey(t),privateKey:t}},generateX25519KeyPairFromSeed(t){return{publicKey:en.getPublicKey(t),privateKey:t}},generateX25519SharedKey(t,e){return en.getSharedSecret(t.subarray(),e.subarray())},chaCha20Poly1305Encrypt(t,e,r,n){return Aa(n,e,r).encrypt(t.subarray())},chaCha20Poly1305Decrypt(t,e,r,n,s){return Aa(n,e,r).decrypt(t.subarray(),s)}};var Mf=kf;function Kf(t){return{generateKeypair:t.generateX25519KeyPair,dh:(e,r)=>t.generateX25519SharedKey(e.privateKey,r).subarray(0,32),encrypt:t.chaCha20Poly1305Encrypt,decrypt:t.chaCha20Poly1305Decrypt,hash:t.hashSHA256,hkdf:t.getHKDF}}var Rr=t=>{let e=Se(2);return e[0]=t>>8,e[1]=t,e};Rr.bytes=2;var Or=t=>{if(t.length<2)throw RangeError("Could not decode int16BE");if(t instanceof Uint8Array){let e=0;return e+=t[0]<<8,e+=t[1],e}return t.getUint16(0)};Or.bytes=2;function Ff(t){return{xxHandshakeSuccesses:t.registerCounter("libp2p_noise_xxhandshake_successes_total",{help:"Total count of noise xxHandshakes successes_"}),xxHandshakeErrors:t.registerCounter("libp2p_noise_xxhandshake_error_total",{help:"Total count of noise xxHandshakes errors"}),encryptedPackets:t.registerCounter("libp2p_noise_encrypted_packets_total",{help:"Total count of noise encrypted packets successfully"}),decryptedPackets:t.registerCounter("libp2p_noise_decrypted_packets_total",{help:"Total count of noise decrypted packets"}),decryptErrors:t.registerCounter("libp2p_noise_decrypt_errors_total",{help:"Total count of noise decrypt errors"})}}function Ba(t,e){!e.enabled||!Ir||(t?(e(`LOCAL_STATIC_PUBLIC_KEY ${W(t.publicKey,"hex")}`),e(`LOCAL_STATIC_PRIVATE_KEY ${W(t.privateKey,"hex")}`)):e("Missing local static keys."))}function _a(t,e){!e.enabled||!Ir||(t?(e(`LOCAL_PUBLIC_EPHEMERAL_KEY ${W(t.publicKey,"hex")}`),e(`LOCAL_PRIVATE_EPHEMERAL_KEY ${W(t.privateKey,"hex")}`)):e("Missing local ephemeral keys."))}function Hf(t,e){!e.enabled||!Ir||e(t?`REMOTE_STATIC_PUBLIC_KEY ${W(t.subarray(),"hex")}`:"Missing remote static public key.")}function La(t,e){!e.enabled||!Ir||e(t?`REMOTE_EPHEMERAL_PUBLIC_KEY ${W(t.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function Ta(t,e,r){!r.enabled||!Ir||(r(`CIPHER_STATE_1 ${t.n.getUint64()} ${t.k&&W(t.k,"hex")}`),r(`CIPHER_STATE_2 ${e.n.getUint64()} ${e.k&&W(e.k,"hex")}`))}var Pr=class t extends Error{code;constructor(e="Invalid crypto exchange"){super(e),this.code=t.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var um=0,fm=4294967295,lm="Cipherstate has reached maximum n, a new handshake must be performed",js=class{n;bytes;view;constructor(e=um){this.n=e,this.bytes=be(12),this.view=new DataView(this.bytes.buffer,this.bytes.byteOffset,this.bytes.byteLength),this.view.setUint32(4,e,!0)}increment(){this.n++,this.view.setUint32(4,this.n,!0)}getBytes(){return this.bytes}getUint64(){return this.n}assertValue(){if(this.n>fm)throw new Error(lm)}};var rr=be(0),Ur=class{k;n;crypto;constructor(e,r=void 0,n=0){this.crypto=e,this.k=r,this.n=new js(n)}hasKey(){return!!this.k}encryptWithAd(e,r){if(!this.hasKey())return r;this.n.assertValue();let n=this.crypto.encrypt(r,this.n.getBytes(),e,this.k);return this.n.increment(),n}decryptWithAd(e,r,n){if(!this.hasKey())return r;this.n.assertValue();let s=this.crypto.decrypt(r,this.n.getBytes(),e,this.k,n);return this.n.increment(),s}},Ca=class{cs;ck;h;crypto;constructor(e,r){this.crypto=e;let n=ee(r,"utf-8");this.h=hm(e,n),this.ck=this.h,this.cs=new Ur(e)}mixKey(e){let[r,n]=this.crypto.hkdf(this.ck,e);this.ck=r,this.cs=new Ur(this.crypto,n)}mixHash(e){this.h=this.crypto.hash(new Q(this.h,e))}encryptAndHash(e){let r=this.cs.encryptWithAd(this.h,e);return this.mixHash(r),r}decryptAndHash(e){let r=this.cs.decryptWithAd(this.h,e);return this.mixHash(e),r}split(){let[e,r]=this.crypto.hkdf(this.ck,rr);return[new Ur(this.crypto,e),new Ur(this.crypto,r)]}},Ia=class{ss;s;e;rs;re;initiator;crypto;constructor(e){let{crypto:r,protocolName:n,prologue:s,initiator:o,s:i,e:a,rs:c,re:u}=e;this.crypto=r,this.ss=new Ca(r,n),this.ss.mixHash(s),this.initiator=o,this.s=i,this.e=a,this.rs=c,this.re=u}writeE(){if(this.e)throw new Error("ephemeral keypair is already set");let e=this.crypto.generateKeypair();return this.ss.mixHash(e.publicKey),this.e=e,e.publicKey}writeS(){if(!this.s)throw new Error("static keypair is not set");return this.ss.encryptAndHash(this.s.publicKey)}writeEE(){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.re))}writeES(){if(this.initiator){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}else{if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}}writeSE(){if(this.initiator){if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}else{if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}}readE(e,r=0){if(this.re)throw new Error("remote ephemeral public key is already set");if(e.byteLength<r+32)throw new Error("message is not long enough");this.re=e.sublist(r,r+32),this.ss.mixHash(this.re)}readS(e,r=0){if(this.rs)throw new Error("remote static public key is already set");let n=32+(this.ss.cs.hasKey()?16:0);if(e.byteLength<r+n)throw new Error("message is not long enough");let s=e.sublist(r,r+n);return this.rs=this.ss.decryptAndHash(s),n}readEE(){this.writeEE()}readES(){this.writeES()}readSE(){this.writeSE()}},Sn=class extends Ia{writeMessageA(e){return new Q(this.writeE(),this.ss.encryptAndHash(e))}writeMessageB(e){let r=this.writeE();this.writeEE();let n=this.writeS();return this.writeES(),new Q(r,n,this.ss.encryptAndHash(e))}writeMessageC(e){let r=this.writeS();return this.writeSE(),new Q(r,this.ss.encryptAndHash(e))}readMessageA(e){try{return this.readE(e),this.ss.decryptAndHash(e.sublist(32))}catch(r){throw new Pr(`handshake stage 0 validation fail: ${r.message}`)}}readMessageB(e){try{this.readE(e),this.readEE();let r=this.readS(e,32);return this.readES(),this.ss.decryptAndHash(e.sublist(32+r))}catch(r){throw new Pr(`handshake stage 1 validation fail: ${r.message}`)}}readMessageC(e){try{let r=this.readS(e);return this.readSE(),this.ss.decryptAndHash(e.sublist(r))}catch(r){throw new Pr(`handshake stage 2 validation fail: ${r.message}`)}}};function hm(t,e){if(e.length<=32){let r=be(32);return r.set(e),r}else return t.hash(e)}var vn;(function(t){let e;t.codec=()=>(e==null&&(e=Gt((o,i,a={})=>{if(a.lengthDelimited!==!1&&i.fork(),o.webtransportCerthashes!=null&&o.webtransportCerthashes.length>0)for(let c of o.webtransportCerthashes)i.uint32(10),i.bytes(c);if(o.streamMuxers!=null&&o.streamMuxers.length>0)for(let c of o.streamMuxers)i.uint32(18),i.string(c);a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={webtransportCerthashes:[],streamMuxers:[]},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{if(a.limits?.webtransportCerthashes!=null&&c.webtransportCerthashes.length===a.limits.webtransportCerthashes)throw new Zt('Decode error - repeated field "webtransportCerthashes" had too many elements');c.webtransportCerthashes.push(o.bytes());break}case 2:{if(a.limits?.streamMuxers!=null&&c.streamMuxers.length===a.limits.streamMuxers)throw new Zt('Decode error - repeated field "streamMuxers" had too many elements');c.streamMuxers.push(o.string());break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u={webtransportCerthashes:0,streamMuxers:0},f=i==null?o.len:o.pos+i;for(;o.pos<f;){let l=o.uint32();switch(l>>>3){case 1:{if(c.limits?.webtransportCerthashes!=null&&u.webtransportCerthashes===c.limits.webtransportCerthashes)throw new Zt('Streaming decode error - repeated field "webtransportCerthashes" had too many elements');yield{field:`${a}.webtransportCerthashes[]`,index:u.webtransportCerthashes,value:o.bytes()},u.webtransportCerthashes++;break}case 2:{if(c.limits?.streamMuxers!=null&&u.streamMuxers===c.limits.streamMuxers)throw new Zt('Streaming decode error - repeated field "streamMuxers" had too many elements');yield{field:`${a}.streamMuxers[]`,index:u.streamMuxers,value:o.string()},u.streamMuxers++;break}default:{o.skipType(l&7);break}}}})),e);function r(o){return Wt(o,t.codec())}t.encode=r;function n(o,i){return Vt(o,t.codec(),i)}t.decode=n;function s(o,i){return Yt(o,t.codec(),i)}t.stream=s})(vn||(vn={}));var An;(function(t){let e;t.codec=()=>(e==null&&(e=Gt((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.identityKey!=null&&o.identityKey.byteLength>0&&(i.uint32(10),i.bytes(o.identityKey)),o.identitySig!=null&&o.identitySig.byteLength>0&&(i.uint32(18),i.bytes(o.identitySig)),o.extensions!=null&&(i.uint32(34),vn.codec().encode(o.extensions,i)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={identityKey:be(0),identitySig:be(0)},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.identityKey=o.bytes();break}case 2:{c.identitySig=o.bytes();break}case 4:{c.extensions=vn.codec().decode(o,o.uint32(),{limits:a.limits?.extensions});break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${a}.identityKey`,value:o.bytes()};break}case 2:{yield{field:`${a}.identitySig`,value:o.bytes()};break}case 4:{yield*vn.codec().stream(o,o.uint32(),`${a}.extensions`,{limits:c.limits?.extensions});break}default:{o.skipType(f&7);break}}}})),e);function r(o){return Wt(o,t.codec())}t.encode=r;function n(o,i){return Vt(o,t.codec(),i)}t.decode=n;function s(o,i){return Yt(o,t.codec(),i)}t.stream=s})(An||(An={}));async function Ra(t,e,r){let n=await t.sign(zf(e));return An.encode({identityKey:xt(t.publicKey),identitySig:n,extensions:r})}async function Oa(t,e,r){try{let n=An.decode(t),s=un(n.identityKey);if(r?.equals(s)===!1)throw new Error(`Payload identity key ${s} does not match expected remote identity key ${r}`);if(!e)throw new Error("Remote static does not exist");let o=zf(e);if(!await s.verify(o,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new Bn(n.message)}}function zf(t){let e=ee("noise-libp2p-static-key:");return t instanceof Uint8Array?Ke([e,t],e.length+t.length):(t.prepend(e),t)}var Da=class extends nt{stream;handshake;metrics;decoder;constructor(e,r,n){super({log:e.log,inactivityTimeout:e.inactivityTimeout,maxReadBufferLength:e.maxReadBufferLength,direction:e.direction}),this.stream=e,this.handshake=r,this.metrics=n,this.decoder=new zs({lengthDecoder:Or,maxBufferSize:16*1024*1024,encodingLength:()=>2});let s=c=>{try{for(let u of this.decoder.decode(c.data))this.onData(this.decrypt(u))}catch(u){this.abort(u)}};this.stream.addEventListener("message",s);let o=c=>{c.error!=null?c.local===!0?this.abort(c.error):this.onRemoteReset():this.onTransportClosed()};this.stream.addEventListener("close",o);let i=()=>{this.safeDispatchEvent("drain")};this.stream.addEventListener("drain",i);let a=()=>{this.onRemoteCloseWrite()};this.stream.addEventListener("remoteCloseWrite",a)}encrypt(e){let r=new Q;for(let n=0;n<e.byteLength;n+=65519){let s=n+65519;s>e.byteLength&&(s=e.byteLength);let o;e instanceof Uint8Array?o=this.handshake.encrypt(e.subarray(n,s)):o=this.handshake.encrypt(e.sublist(n,s)),this.metrics?.encryptedPackets.increment(),r.append(Rr(o.byteLength)),r.append(o)}return r}decrypt(e){let r=new Q;for(let n=0;n<e.byteLength;n+=65535){let s=n+65535;if(s>e.byteLength&&(s=e.byteLength),s-wa<n)throw new Error("Invalid chunk");let o;e instanceof Uint8Array?o=e.subarray(n,s):o=e.sublist(n,s);let i=e.subarray(n,s-wa);try{let a=this.handshake.decrypt(o,i);this.metrics?.decryptedPackets.increment(),r.append(a)}catch(a){throw this.metrics?.decryptErrors.increment(),a}}return r}close(e){return this.stream.close(e)}sendPause(){this.stream.pause()}sendResume(){this.stream.resume()}sendReset(e){this.stream.abort(e)}sendData(e){return{sentBytes:e.byteLength,canSendMore:this.stream.send(this.encrypt(e))}}};function Pa(t,e,r){return new Da(t,e,r)}async function $f(t,e){let{log:r,connection:n,crypto:s,privateKey:o,prologue:i,s:a,remoteIdentityKey:c,extensions:u}=t,f=await Ra(o,a.publicKey,u),l=new Sn({crypto:s,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:i,s:a});Ba(l.s,r),r.trace("Stage 0 - Initiator starting to send first message."),await n.write(l.writeMessageA(rr),e),r.trace("Stage 0 - Initiator finished sending first message."),_a(l.e,r),r.trace("Stage 1 - Initiator waiting to receive first message from responder...");let d=l.readMessageB(await n.read(e));r.trace("Stage 1 - Initiator received the message."),La(l.re,r),Hf(l.rs,r),r.trace("Initiator going to check remote's signature...");let p=await Oa(d,l.rs,c);r.trace("All good with the signature!"),r.trace("Stage 2 - Initiator sending third handshake message."),await n.write(l.writeMessageC(f),e),r.trace("Stage 2 - Initiator sent message with signed payload.");let[g,b]=l.ss.split();return Ta(g,b,r),{payload:p,encrypt:y=>g.encryptWithAd(rr,y),decrypt:(y,x)=>b.decryptWithAd(rr,y,x)}}async function Vf(t,e){let{log:r,connection:n,crypto:s,privateKey:o,prologue:i,s:a,remoteIdentityKey:c,extensions:u}=t,f=await Ra(o,a.publicKey,u),l=new Sn({crypto:s,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:i,s:a});Ba(l.s,r),r.trace("Stage 0 - Responder waiting to receive first message."),l.readMessageA(await n.read(e)),r.trace("Stage 0 - Responder received first message."),La(l.re,r),r.trace("Stage 1 - Responder sending out first message with signed payload and static key."),await n.write(l.writeMessageB(f),e),r.trace("Stage 1 - Responder sent the second handshake message with signed payload."),_a(l.e,r),r.trace("Stage 2 - Responder waiting for third handshake message...");let d=l.readMessageC(await n.read(e));r.trace("Stage 2 - Responder received the message, finished handshake.");let p=await Oa(d,l.rs,c),[g,b]=l.ss.split();return Ta(g,b,r),{payload:p,encrypt:y=>b.encryptWithAd(rr,y),decrypt:(y,x)=>g.decryptWithAd(rr,y,x)}}var Ys=class{protocol="/noise";crypto;prologue;staticKey;extensions;metrics;components;log;constructor(e,r={}){let{staticNoiseKey:n,extensions:s,crypto:o,prologueBytes:i}=r,{metrics:a}=e;this.components=e,this.log=e.logger.forComponent("libp2p:noise");let c=o??Mf;this.crypto=Kf(c),this.extensions={webtransportCerthashes:[],...s},this.metrics=a?Ff(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=i??be(0)}[Symbol.toStringTag]="@libp2p/noise";[Pn]=["@libp2p/connection-encryption","@libp2p/noise"];async secureOutbound(e,r){let n=e.log?.newScope("noise")??this.log,s=ba(e,{lengthEncoder:Rr,lengthDecoder:Or,maxDataLength:65535}),o=await this.performHandshakeInitiator(s,this.components.privateKey,n,r?.remotePeer?.publicKey,r),i=un(o.payload.identityKey);return{connection:Pa(s.unwrap(),o,this.metrics),remoteExtensions:o.payload.extensions,remotePeer:Ni(i),streamMuxer:r?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(o.payload.extensions?.streamMuxers)}}getStreamMuxer(e){if(e==null||e.length===0)return;let r=this.components.upgrader.getStreamMuxers();if(r!=null)for(let n of e){let s=r.get(n);if(s!=null)return s}if(e.length)throw new or("Early muxer negotiation was requested but the initiator and responder had no common muxers")}async secureInbound(e,r){let n=e.log?.newScope("noise")??this.log,s=ba(e,{lengthEncoder:Rr,lengthDecoder:Or,maxDataLength:65535}),o=await this.performHandshakeResponder(s,this.components.privateKey,n,r?.remotePeer?.publicKey,r),i=un(o.payload.identityKey);return{connection:Pa(s.unwrap(),o,this.metrics),remoteExtensions:o.payload.extensions,remotePeer:Ni(i),streamMuxer:r?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(o.payload.extensions?.streamMuxers)}}async performHandshakeInitiator(e,r,n,s,o){let i,a=o?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{i=await $f({connection:e,privateKey:r,remoteIdentityKey:s,log:n.newScope("xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:{streamMuxers:a,webtransportCerthashes:[],...this.extensions}},o),this.metrics?.xxHandshakeSuccesses.increment()}catch(c){throw this.metrics?.xxHandshakeErrors.increment(),c}return i}async performHandshakeResponder(e,r,n,s,o){let i,a=o?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{i=await Vf({connection:e,privateKey:r,remoteIdentityKey:s,log:n.newScope("xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:{streamMuxers:a,webtransportCerthashes:[],...this.extensions}},o),this.metrics?.xxHandshakeSuccesses.increment()}catch(c){throw this.metrics?.xxHandshakeErrors.increment(),c}return i}};function jf(t={}){return e=>new Ys(e,t)}var nr=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};function Ua(t){throw new Error("Not implemented")}var Na=class extends Hs{writer;reader;constructor(e){super(e),this.writer=e.stream.writable.getWriter(),this.reader=e.stream.readable.getReader(),this.writer.closed.then(()=>{this.log("writer closed gracefully")}).catch(r=>{r.message.includes("STOP_SENDING")||r.message.includes("StopSending")?this.onRemoteCloseRead():r.message.includes("RESET_STREAM")||r.message.includes("Reset")?this.onRemoteReset():this.log("writer close promise rejected - %e",r)}),this.readData()}readData(){Promise.resolve().then(async()=>{for(;;){let e=await this.reader.read();if(e.value!=null&&this.onData(e.value),e.done){this.log("remote closed write"),this.onRemoteCloseWrite();return}if(this.readStatus==="paused")break}}).catch(e=>{this.abort(e)}).finally(()=>{this.reader.releaseLock()})}sendData(e){for(let n of e)this.writer.write(n).catch(s=>{this.abort(s)});if(this.log.trace("desired size after sending %d bytes is %d bytes",e.byteLength,this.writer.desiredSize),this.writer.desiredSize==null)return{sentBytes:e.byteLength,canSendMore:!1};let r=this.writer.desiredSize>0;return r||this.writer.ready.then(()=>{this.safeDispatchEvent("drain")},n=>{this.abort(n)}),{sentBytes:e.byteLength,canSendMore:r}}sendReset(e){this.writer.abort(e).catch(r=>{this.log.error("error aborting writer - %e",r)})}async sendCloseWrite(e){this.log("sendCloseWrite closing writer"),await $e(this.writer.close().catch(()=>{}),e?.signal),this.log("sendCloseWrite closed writer")}async sendCloseRead(e){this.log("sendCloseRead cancelling reader"),await $e(this.reader.cancel(),e?.signal),this.log("sendCloseRead cancelled reader")}sendPause(){}sendResume(){this.readData()}};function ka(t,e,r,n,s){return new Na({...s,stream:t,id:e,direction:r,log:n.newScope(`${r}:${e}`),protocol:""})}var Wf="/webtransport",Ma=class extends Fs{webTransport;streamIDCounter;reader;constructor(e,r){super(r,{protocol:Wf,name:"muxer"}),this.webTransport=e,this.streamIDCounter=0,this.reader=this.webTransport.incomingBidirectionalStreams.getReader(),Promise.resolve().then(async()=>{for(;;){let{done:n,value:s}=await this.reader.read();if(n||s==null)break;this.onRemoteStream(ka(s,String(this.streamIDCounter++),"inbound",this.log,this.streamOptions))}}).catch(n=>{this.log.error("could not create a new stream - %e",n)})}async onCreateStream(e){let r=await this.webTransport.createBidirectionalStream();return e?.signal?.throwIfAborted(),ka(r,String(this.streamIDCounter++),"outbound",this.log,e)}onData(){}sendReset(){this.webTransport.close()}};function Yf(t){return{protocol:Wf,createStreamMuxer(e){return new Ma(t,e)}}}var Ka=class extends Ks{cleanUpWTSession;constructor(e){super(e),this.cleanUpWTSession=e.cleanUpWTSession}sendData(e){return{sentBytes:e.byteLength,canSendMore:!0}}sendReset(){this.cleanUpWTSession("abort")}async sendClose(e){this.cleanUpWTSession("close"),e?.signal?.throwIfAborted()}sendPause(){}sendResume(){}},Gf=t=>new Ka(t);function Zf(t,e){return e.filter(n=>!!t.find(s=>xe(n,s))).length===e.length}var dm=Object.values(kt).map(t=>t.decoder).reduce((t,e)=>t.or(e));function pm(t){return ot.decode(dm.decode(t))}function Fa(t){if(!Os.matches(t))throw new Tn("Invalid multiaddr, was not a WebTransport address");let e=[],r;for(let o of t.getComponents())o.name==="certhash"&&e.push(pm(o.value??"")),o.name==="p2p"&&r==null&&(r=ju(o.value??""));let n=Yu(t),s=n.host;return n.type==="ip6"&&s.includes(":")&&(s=`[${s}]`),{url:`https://${s}:${n.port}`,certhashes:e,remotePeer:r}}var Gs=class extends nt{writer;reader;constructor(e){super(e),this.writer=e.stream.writable.getWriter(),this.reader=e.stream.readable.getReader(),Promise.resolve().then(async()=>{for(;;){let{done:r,value:n}=await this.reader.read();if(n!=null&&this.onData(n),r)break}}).catch(r=>{this.abort(r)})}async close(e){await $e(this.writer.close(),e?.signal)}sendData(e){return this.writer.write(e.subarray()).catch(r=>{this.abort(r)}),{sentBytes:e.byteLength,canSendMore:!0}}sendReset(e){this.writer.abort(e).catch(r=>{this.log.error("could not send reset - %e",r)})}sendPause(){}sendResume(){}};var Xf=globalThis.WebTransport;var Ha=class{log;components;config;metrics;constructor(e,r={}){this.log=e.logger.forComponent("libp2p:webtransport"),this.components=e,this.config={...r,certificates:r.certificates??[]},e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_webtransport_dialer_events_total",{label:"event",help:"Total count of WebTransport dialer events by type"})})}[Symbol.toStringTag]="@libp2p/webtransport";[za]=!0;[Pn]=["@libp2p/transport"];async dial(e,r){r.signal.throwIfAborted(),this.log("dialing %s",e),r=r??{};let{url:n,certhashes:s,remotePeer:o}=Fa(e),i,a,c=()=>{},u=!1,f=!1,l=!1;try{this.metrics?.dialerEvents.increment({pending:!0});let d=new Xf(`${n}/.well-known/libp2p-webtransport?type=noise`,{serverCertificateHashes:s.map(g=>({algorithm:"sha-256",value:Ae(g.digest)}))});c=g=>{if(!u)try{this.metrics?.dialerEvents.increment({[g]:!0}),d.close()}catch(b){this.log.error("error closing wt session - %e",b)}finally{a!=null&&(a.timeline.close=Date.now()),u=!0}},i=()=>{c(f?"noise_timeout":"ready_timeout")},r.signal.addEventListener("abort",i,{once:!0}),this.log("wait for session to be ready"),r.onProgress?.(new nr("webtransport:wait-for-session")),await Promise.race([d.closed,d.ready]),this.log("session became ready"),f=!0,this.metrics?.dialerEvents.increment({ready:!0}),d.closed.catch(g=>{this.log.error("error on remote wt session close - %e",g)}).finally(()=>{c("remote_close")}),this.metrics?.dialerEvents.increment({open:!0}),a=Gf({remoteAddr:e,cleanUpWTSession:c,direction:"outbound",log:this.components.logger.forComponent("libp2p:webtransport:connection")});let p=await this.authenticateWebTransport({wt:d,maConn:a,remotePeer:o,certhashes:s,...r});if(l=!0,o!=null&&(l=o.equals(p)),!l)throw new or("Failed to authenticate webtransport");return await r.upgrader.upgradeOutbound(a,{...r,skipEncryption:!0,remotePeer:p,muxerFactory:Yf(d),skipProtection:!0})}catch(d){throw this.log.error("caught wt session err - %e",d),c(l?"upgrade_error":f?"noise_error":"ready_error"),d}finally{i!=null&&r.signal?.removeEventListener("abort",i)}}async authenticateWebTransport({wt:e,maConn:r,remotePeer:n,certhashes:s,onProgress:o,signal:i}){o?.(new nr("webtransport:open-authentication-stream"));let a=await e.createBidirectionalStream();i?.throwIfAborted();let c=new Gs({stream:a,log:r.log.newScope("muxer")}),u=jf()(this.components);o?.(new nr("webtransport:secure-outbound-connection"));let{remoteExtensions:f,remotePeer:l}=await u.secureOutbound(c,{signal:i,remotePeer:n,skipStreamMuxerNegotiation:!0});if(o?.(new nr("webtransport:close-authentication-stream")),await c.close({signal:i}),!Zf(f?.webtransportCerthashes??[],s.map(d=>d.bytes)))throw new se("Our certhashes are not a subset of the remote's reported certhashes");return l}createListener(e){return Ua(this.components,{...e,certificates:this.config.certificates})}listenFilter(){return[]}dialFilter(e){return globalThis.WebTransport==null?[]:e.filter(r=>{if(!Os.exactMatch(r))return!1;let{url:n,certhashes:s}=Fa(r);return n!=null&&s.length>0})}};function mm(t={}){return e=>new Ha(e,t)}return ol(ym);})();
|
|
2
|
+
"use strict";var Libp2PWebtransport=(()=>{var Zs=Object.defineProperty;var tl=Object.getOwnPropertyDescriptor;var rl=Object.getOwnPropertyNames;var nl=Object.prototype.hasOwnProperty;var Re=(t,e)=>{for(var r in e)Zs(t,r,{get:e[r],enumerable:!0})},sl=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of rl(e))!nl.call(t,s)&&s!==r&&Zs(t,s,{get:()=>e[s],enumerable:!(n=tl(e,s))||n.enumerable});return t};var ol=t=>sl(Zs({},"__esModule",{value:!0}),t);var ym={};Re(ym,{webTransport:()=>mm});var Bn=class extends Error{static name="UnexpectedPeerError";constructor(e="Unexpected Peer"){super(e),this.name="UnexpectedPeerError"}},or=class extends Error{static name="InvalidCryptoExchangeError";constructor(e="Invalid crypto exchange"){super(e),this.name="InvalidCryptoExchangeError"}},se=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},ir=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var _n=class extends Error{static name="MuxerClosedError";constructor(e="The muxer is closed"){super(e),this.name="MuxerClosedError"}},Ln=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var yt=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},Ot=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var Tn=class extends Error{static name="InvalidMultiaddrError";constructor(e="Invalid multiaddr"){super(e),this.name="InvalidMultiaddrError"}},Cn=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},In=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Pt=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Dn=class extends Event{data;constructor(e,r){super("message",r),this.data=e}},ar=class extends Event{error;local;constructor(e,r,n){super("close",n),this.error=r,this.local=e}},Rn=class extends ar{constructor(e,r){super(!0,e,r)}},On=class extends ar{constructor(e,r){super(!1,e,r)}};var Xs=Symbol.for("@libp2p/peer-id");var za=Symbol.for("@libp2p/transport");var qa;(function(t){t[t.FATAL_ALL=0]="FATAL_ALL",t[t.NO_FATAL=1]="NO_FATAL"})(qa||(qa={}));function il(t){return typeof t?.handleEvent=="function"}function al(t){return t===!0||t===!1}function cl(t){return al(t)?t:t?.capture??!1}function Qs(t){let e={capture:cl(t),once:!!t?.once};return t?.passive!=null&&(e.passive=t?.passive),t?.signal!=null&&(e.signal=t?.signal),e}function $a(t,e){return Qs(t).capture===Qs(e).capture}var cr=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){let s=Qs(n);if(s?.signal?.aborted===!0)return;let o=u=>{s.once&&this.removeEventListener(e,r,s),il(r)?r.handleEvent(u):r(u)},i=this.#e.get(e);if(i==null&&(i=[],this.#e.set(e,i)),i.some(u=>u.callback!==r?!1:$a(u.options,s)))return;super.addEventListener(e,o,s);let c=()=>{this.removeEventListener(e,r,s)};s.signal?.addEventListener("abort",c),i.push({callback:r,wrapper:o,options:s,onAbort:c})}removeEventListener(e,r,n){let s=this.#e.get(e);if(s==null){super.removeEventListener(e,r??null,n);return}this.#e.set(e,s.filter(o=>o.callback===r&&$a(o.options,n)?(super.removeEventListener(e,o.wrapper,n),o.options?.signal?.removeEventListener("abort",o.onAbort),!1):!0))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var Pn=Symbol.for("@libp2p/service-capabilities");var no={};Re(no,{base58btc:()=>me,base58flickr:()=>yl});var Ym=new Uint8Array(0);function ja(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Me(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return Ut(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return Ut(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function Wa(t){let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}var Va=4096;function Ya(t){let e=t.length;if(e<=Va)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.subarray(n,n+=Va));return r}function ul(t){return t?.buffer instanceof ArrayBuffer}function Ut(t){return ul(t)?t:t.slice()}function fl(t,e,r){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),s=0;s<n.length;s++)n[s]=255;for(var o=0;o<t.length;o++){var i=t.charAt(o),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=o,r){var c=i.toLowerCase().charCodeAt(0),u=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=o),u!==a&&(n[u]=o)}}var f=t.length,l=t.charAt(0),d=Math.log(f)/Math.log(256),p=Math.log(256)/Math.log(f);function g(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var E=0,w=0,I=0,T=x.length;I!==T&&x[I]===0;)I++,E++;for(var O=(T-I)*p+1>>>0,M=new Uint8Array(O);I!==T;){for(var U=x[I],C=0,D=O-1;(U!==0||C<w)&&D!==-1;D--,C++)U+=256*M[D]>>>0,M[D]=U%f>>>0,U=U/f>>>0;if(U!==0)throw new Error("Non-zero carry");w=C,I++}for(var F=O-w;F!==O&&M[F]===0;)F++;for(var K=l.repeat(E);F<O;++F)K+=t.charAt(M[F]);return K}function b(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var E=0;if(x[E]!==" "){for(var w=0,I=0;x[E]===l;)w++,E++;for(var T=(x.length-E)*d+1>>>0,O=new Uint8Array(T);x[E];){var M=n[x.charCodeAt(E)];if(M===255)return;for(var U=0,C=T-1;(M!==0||U<I)&&C!==-1;C--,U++)M+=f*O[C]>>>0,O[C]=M%256>>>0,M=M/256>>>0;if(M!==0)throw new Error("Non-zero carry");I=U,E++}if(x[E]!==" "){for(var D=T-I;D!==T&&O[D]===0;)D++;for(var F=new Uint8Array(w+(T-D)),K=w;D!==T;)F[K++]=O[D++];return F}}}function y(x){var E=b(x);if(E)return E;throw new Error(`Non-${e} character`)}return{encode:g,decodeUnsafe:b,decode:y}}var ll=fl,hl=ll,Za=hl;var Js=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},eo=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let s=r.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Xa(this,e)}},to=class{decoders;constructor(e){this.decoders=e}or(e){return Xa(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Xa(t,e){return new to({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var ro=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,s){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=s,this.encoder=new Js(e,r,n),this.decoder=new eo(e,r,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ur({name:t,prefix:e,encode:r,decode:n}){return new ro(t,e,r,n)}function gt({name:t,prefix:e,alphabet:r,caseInsensitive:n=!1}){let{encode:s,decode:o}=Za(r,t,n);return ur({prefix:e,name:t,encode:s,decode:i=>Me(o(i))})}function dl(t,e,r,n){let s=t.length;for(;t[s-1]==="=";)--s;let o=new Uint8Array(s*r/8|0),i=0,a=0,c=0;for(let u=0;u<s;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,o[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return o}function pl(t,e,r){let n=e[e.length-1]==="=",s=(1<<r)-1,o="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,o+=e[s&a>>i];if(i!==0&&(o+=e[s&a<<r-i]),n)for(;(o.length*r&7)!==0;)o+="=";return o}function ml(t,e){let r={};for(let n=0;n<t.length;++n)if(r[t[n]]=n,e){let s=t[n].toLowerCase(),o=t[n].toUpperCase();s!==t[n]&&(r[s]=n),o!==t[n]&&(r[o]=n)}return r}function pe({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:s=!1}){let o=ml(n,s);return ur({prefix:e,name:t,encode(i){return pl(i,n,r)},decode(i){return dl(i,o,r,t)}})}var me=gt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),yl=gt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var so={};Re(so,{base32:()=>bt,base32hex:()=>xl,base32hexpad:()=>Sl,base32hexpadupper:()=>vl,base32hexupper:()=>El,base32pad:()=>bl,base32padupper:()=>wl,base32upper:()=>gl,base32z:()=>Al});var bt=pe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),gl=pe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),bl=pe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),wl=pe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),xl=pe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),El=pe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),Sl=pe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),vl=pe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),Al=pe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var oo={};Re(oo,{base36:()=>kr,base36upper:()=>Bl});var kr=gt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),Bl=gt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var ot={};Re(ot,{Digest:()=>Nt,create:()=>Ve,decode:()=>hr,equals:()=>ao,hasCode:()=>$l});var _l=ec,Qa=128,Ll=127,Tl=~Ll,Cl=Math.pow(2,31);function ec(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Cl;)e[r++]=t&255|Qa,t/=128;for(;t&Tl;)e[r++]=t&255|Qa,t>>>=7;return e[r]=t|0,ec.bytes=r-n+1,e}var Il=io,Dl=128,Ja=127;function io(t,n){var r=0,n=n||0,s=0,o=n,i,a=t.length;do{if(o>=a)throw io.bytes=0,new RangeError("Could not decode varint");i=t[o++],r+=s<28?(i&Ja)<<s:(i&Ja)*Math.pow(2,s),s+=7}while(i>=Dl);return io.bytes=o-n,r}var Rl=Math.pow(2,7),Ol=Math.pow(2,14),Pl=Math.pow(2,21),Ul=Math.pow(2,28),Nl=Math.pow(2,35),kl=Math.pow(2,42),Ml=Math.pow(2,49),Kl=Math.pow(2,56),Fl=Math.pow(2,63),Hl=function(t){return t<Rl?1:t<Ol?2:t<Pl?3:t<Ul?4:t<Nl?5:t<kl?6:t<Ml?7:t<Kl?8:t<Fl?9:10},ql={encode:_l,decode:Il,encodingLength:Hl},zl=ql,Mr=zl;function Kr(t,e=0){let r=Mr.decode(t,e),n=Mr.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&t[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function fr(t,e,r=0){return Mr.encode(t,e,r),e}function lr(t){return Mr.encodingLength(t)}function Ve(t,e){let r=e.byteLength,n=lr(t),s=n+lr(r),o=new Uint8Array(s+r);return fr(t,o,0),fr(r,o,n),o.set(e,s),new Nt(t,r,e,o)}function hr(t){let e=Me(t),[r,n]=Kr(e),[s,o]=Kr(e.subarray(n)),i=e.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new Nt(r,s,i,e)}function ao(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&ja(t.bytes,r.bytes)}}var Nt=class{code;size;digest;bytes;constructor(e,r,n,s){this.code=e,this.size=r,this.digest=Ut(n),this.bytes=Ut(s)}};function $l(t,e){return t.code===e}function tc(t,e){let{bytes:r,version:n}=t;return n===0?jl(r,co(t),e??me.encoder):Wl(r,co(t),e??bt.encoder)}var rc=new WeakMap;function co(t){let e=rc.get(t);if(e==null){let r=new Map;return rc.set(t,r),r}return e}var we=class t{code;version;multihash;bytes;"/";constructor(e,r,n,s){this.code=r,this.version=e,this.multihash=n,this.bytes=Ut(s),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==Fr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Yl)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=Ve(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&ao(e.multihash,n.multihash)}toString(e){return tc(this,e)}toJSON(){return{"/":tc(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:s,multihash:o,bytes:i}=r;return new t(n,s,o,i??nc(n,s,o.bytes))}else if(r[Gl]===!0){let{version:n,multihash:s,code:o}=r,i=hr(s);return t.create(n,o,i)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==Fr)throw new Error(`Version 0 CID must use dag-pb (code: ${Fr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let s=nc(e,r,n.bytes);return new t(e,r,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Fr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,s=Me(e.subarray(n,n+r.multihashSize));if(s.byteLength!==r.multihashSize)throw new Error("Incorrect length");let o=s.subarray(r.multihashSize-r.digestSize),i=new Nt(r.multihashCode,r.digestSize,o,s);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[l,d]=Kr(e.subarray(r));return r+=d,l},s=n(),o=Fr;if(s===18?(s=0,r=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,s]=Vl(e,r),o=t.decode(s);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return co(o).set(n,e),o}};function Vl(t,e){switch(t[0]){case"Q":{let r=e??me;return[me.prefix,r.decode(`${me.prefix}${t}`)]}case me.prefix:{let r=e??me;return[me.prefix,r.decode(t)]}case bt.prefix:{let r=e??bt;return[bt.prefix,r.decode(t)]}case kr.prefix:{let r=e??kr;return[kr.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function jl(t,e,r){let{prefix:n}=r;if(n!==me.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let s=e.get(n);if(s==null){let o=r.encode(t).slice(1);return e.set(n,o),o}else return s}function Wl(t,e,r){let{prefix:n}=r,s=e.get(n);if(s==null){let o=r.encode(t);return e.set(n,o),o}else return s}var Fr=112,Yl=18;function nc(t,e,r){let n=lr(t),s=n+lr(e),o=new Uint8Array(s+r.byteLength);return fr(t,o,0),fr(e,o,n),o.set(r,s),o}var Gl=Symbol.for("@ipld/js-cid/CID");var uo={};Re(uo,{identity:()=>je});var sc=0,Zl="identity",oc=Me;function Xl(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return Ve(sc,oc(t))}var je={code:sc,name:Zl,encode:oc,digest:Xl};function xe(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Ql(t){return t.buffer instanceof ArrayBuffer}function Ae(t){return Ql(t)?t:t.slice()}async function ic(t,e,r,n){let s=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let o=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},s,Ae(e),Ae(r.subarray()));return n?.signal?.throwIfAborted(),o}function be(t=0){return new Uint8Array(t)}function Se(t=0){return new Uint8Array(t)}function Jl(t){return t?.buffer instanceof ArrayBuffer}function fo(t){if(Jl(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function Ke(t,e){e==null&&(e=t.reduce((s,o)=>s+o.length,0));let r=Se(e),n=0;for(let s of t)r.set(s,n),n+=s.length;return fo(r)}var cc=Symbol.for("@achingbrain/uint8arraylist");function ac(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let s=r+n.byteLength;if(e<s)return{buf:n,index:e-r};r=s}throw new RangeError("index is out of bounds")}function Nn(t){return!!t?.[cc]}var Q=class t{bufs;length;[cc]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Nn(n)){r+=n.byteLength;for(let s of n.bufs)this.bufs.push(s)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Nn(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(e){let r=ac(this.bufs,e);return r.buf[r.index]}set(e,r){let n=ac(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(Nn(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:s}=this._subList(e,r);return Ke(n,s)}subarray(e,r){let{bufs:n,length:s}=this._subList(e,r);return n.length===1?n[0]:Ke(n,s)}sublist(e,r){let{bufs:n,length:s}=this._subList(e,r),o=new t;return o.length=s,o.bufs=n,o}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],s=0;for(let o=0;o<this.bufs.length;o++){let i=this.bufs[o],a=s,c=a+i.byteLength;if(s=c,e>=c)continue;let u=e>=a&&e<c,f=r>a&&r<=c;if(u&&f){if(e===a&&r===c){n.push(i);break}let l=e-a;n.push(i.subarray(l,l+(r-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!Nn(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let o=256,i=new Int32Array(o);for(let l=0;l<o;l++)i[l]=-1;for(let l=0;l<s;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let d=u;d>=0;d--){let p=this.get(l+d);if(n[d]!==p){f=Math.max(1,d-a[p]);break}}if(f===0)return l}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=Se(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let s=be(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,r,n),this.write(s,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let s=be(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,r,n),this.write(s,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let s=be(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,r,n),this.write(s,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=Se(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let s=be(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,r,n),this.write(s,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let s=be(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,r,n),this.write(s,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let s=be(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,r,n),this.write(s,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let s=be(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,r,n),this.write(s,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let s=be(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,r,n),this.write(s,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!xe(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((s,o)=>s+o.byteLength,0)),n.length=r,n}};var lo={};Re(lo,{base10:()=>eh});var eh=gt({prefix:"9",name:"base10",alphabet:"0123456789"});var ho={};Re(ho,{base16:()=>th,base16upper:()=>rh});var th=pe({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),rh=pe({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var po={};Re(po,{base2:()=>nh});var nh=pe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var mo={};Re(mo,{base256emoji:()=>ch});var uc=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),sh=uc.reduce((t,e,r)=>(t[r]=e,t),[]),oh=uc.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function ih(t){return t.reduce((e,r)=>(e+=sh[r],e),"")}function ah(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let s=oh[n];if(s==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(s)}return new Uint8Array(e)}var ch=ur({prefix:"\u{1F680}",name:"base256emoji",encode:ih,decode:ah});var go={};Re(go,{base64:()=>uh,base64pad:()=>fh,base64url:()=>yo,base64urlpad:()=>lh});var uh=pe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),fh=pe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),yo=pe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),lh=pe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var bo={};Re(bo,{base8:()=>hh});var hh=pe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var wo={};Re(wo,{identity:()=>dh});var dh=ur({prefix:"\0",name:"identity",encode:t=>Ya(Me(t)),decode:t=>Me(Wa(t))});var O0=new TextEncoder,P0=new TextDecoder;var So={};Re(So,{sha256:()=>Hr,sha512:()=>gh});var yh=20;function Eo({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:s}){return new xo(t,e,r,n,s)}var xo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,s,o){this.name=e,this.code=r,this.encode=n,this.minDigestLength=s??yh,this.maxDigestLength=o}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?fc(n,this.code,r?.truncate):n.then(s=>fc(s,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function fc(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return Ve(e,t)}function hc(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Hr=Eo({name:"sha2-256",code:18,encode:hc("SHA-256")}),gh=Eo({name:"sha2-512",code:19,encode:hc("SHA-512")});var kt={...wo,...po,...bo,...lo,...ho,...so,...oo,...no,...go,...mo},j0={...So,...uo};function pc(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var dc=pc("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),vo=pc("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=Se(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),bh={utf8:dc,"utf-8":dc,hex:kt.base16,latin1:vo,ascii:vo,binary:vo,...kt},kn=bh;function ee(t,e="utf8"){let r=kn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function W(t,e="utf8"){let r=kn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var wh=parseInt("11111",2),Ao=parseInt("10000000",2),xh=parseInt("01111111",2),mc={0:qr,1:qr,2:Eh,3:Ah,4:Bh,5:vh,6:Sh,16:qr,22:qr,48:qr};function it(t,e={offset:0}){let r=t[e.offset]&wh;if(e.offset++,mc[r]!=null)return mc[r](t,e);throw new Error("No decoder for tag "+r)}function zr(t,e){let r=0;if((t[e.offset]&Ao)===Ao){let n=t[e.offset]&xh,s="0x";e.offset++;for(let o=0;o<n;o++,e.offset++){if(e.offset>=t.byteLength)throw new Error("invalid DER element length");s+=t[e.offset].toString(16).padStart(2,"0")}r=parseInt(s,16)}else r=t[e.offset],e.offset++;if(!Number.isInteger(r)||r<0||r>t.byteLength-e.offset)throw new Error("invalid DER element length");return r}function qr(t,e){zr(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=it(t,e);if(n===null)break;r.push(n)}return r}function Eh(t,e){let r=zr(t,e),n=e.offset,s=e.offset+r,o=[];for(let i=n;i<s;i++)i===n&&t[i]===0||o.push(t[i]);return e.offset+=r,Uint8Array.from(o)}function Sh(t,e){let r=zr(t,e),n=e.offset+r,s=t[e.offset];e.offset++;let o=0,i=0;s<40?(o=0,i=s):s<80?(o=1,i=s-40):(o=2,i=s-80);let a=`${o}.${i}`,c=[];for(;e.offset<n;){let u=t[e.offset];if(e.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function vh(t,e){return e.offset++,null}function Ah(t,e){let r=zr(t,e),n=t[e.offset];e.offset++;let s=t.subarray(e.offset,e.offset+r-1);if(e.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return s}function Bh(t,e){let r=zr(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function _h(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new Q;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function Bo(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=_h(t.byteLength);return new Q(Uint8Array.from([e.byteLength|Ao]),e)}function Ue(t){let e=new Q,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new Q(Uint8Array.from([2]),Bo(e),e)}function Mn(t){let e=Uint8Array.from([0]),r=new Q(e,t);return new Q(Uint8Array.from([3]),Bo(r),r)}function wt(t,e=48){let r=new Q;for(let n of t)r.append(n);return new Q(Uint8Array.from([e]),Bo(r),r)}var Lh=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Th=Uint8Array.from([6,5,43,129,4,0,34]),Ch=Uint8Array.from([6,5,43,129,4,0,35]),Ih={ext:!0,kty:"EC",crv:"P-256"},Dh={ext:!0,kty:"EC",crv:"P-384"},Rh={ext:!0,kty:"EC",crv:"P-521"},_o=32,Lo=48,To=66;function Co(t){let e=it(t);return yc(e)}function yc(t){let e=t[1][1][0],r=1,n,s;if(e.byteLength===_o*2+1)return n=W(e.subarray(r,r+_o),"base64url"),s=W(e.subarray(r+_o),"base64url"),new dr({...Ih,key_ops:["verify"],x:n,y:s});if(e.byteLength===Lo*2+1)return n=W(e.subarray(r,r+Lo),"base64url"),s=W(e.subarray(r+Lo),"base64url"),new dr({...Dh,key_ops:["verify"],x:n,y:s});if(e.byteLength===To*2+1)return n=W(e.subarray(r,r+To),"base64url"),s=W(e.subarray(r+To),"base64url"),new dr({...Rh,key_ops:["verify"],x:n,y:s});throw new se(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function gc(t){return wt([Ue(Uint8Array.from([1])),wt([Oh(t.crv)],160),wt([Mn(new Q(Uint8Array.from([4]),ee(t.x??"","base64url"),ee(t.y??"","base64url")))],161)]).subarray()}function Oh(t){if(t==="P-256")return Lh;if(t==="P-384")return Th;if(t==="P-521")return Ch;throw new se(`Invalid curve ${t}`)}var dr=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=gc(this.jwk)),this._raw}toMultihash(){return je.digest(xt(this))}toCID(){return we.createV1(114,this.toMultihash())}toString(){return me.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:xe(this.raw,e.raw)}async verify(e,r,n){return ic(this.jwk,r,e,n)}};var Kn=BigInt(4294967295),bc=BigInt(32);function Ph(t,e=!1){return e?{h:Number(t&Kn),l:Number(t>>bc&Kn)}:{h:Number(t>>bc&Kn)|0,l:Number(t&Kn)|0}}function wc(t,e=!1){let r=t.length,n=new Uint32Array(r),s=new Uint32Array(r);for(let o=0;o<r;o++){let{h:i,l:a}=Ph(t[o],e);[n[o],s[o]]=[i,a]}return[n,s]}var Uh=t=>t/2**32|0,Nh=t=>t>>>0;function xc(t,e,r,n){let s=Uh(r),o=Nh(r);t.setUint32(e,n?o:s,n),t.setUint32(e+4,n?s:o,n)}var Io=(t,e,r)=>t>>>r,Do=(t,e,r)=>t<<32-r|e>>>r,Mt=(t,e,r)=>t>>>r|e<<32-r,Kt=(t,e,r)=>t<<32-r|e>>>r,$r=(t,e,r)=>t<<64-r|e>>>r-32,Vr=(t,e,r)=>t>>>r-32|e<<64-r;function Xe(t,e,r,n){let s=(e>>>0)+(n>>>0);return{h:t+r+(s/2**32|0)|0,l:s|0}}var Ec=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Sc=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,vc=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Ac=(t,e,r,n,s)=>e+r+n+s+(t/2**32|0)|0,Bc=(t,e,r,n,s)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(s>>>0),_c=(t,e,r,n,s,o)=>e+r+n+s+o+(t/2**32|0)|0;function Fn(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var Ro=t=>t?`"${t}" `:"";function We(t,e=""){if(typeof t!="number")throw new TypeError(Ro(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(Ro(e)+"expected integer >= 0, got "+t);return t}function Oe(t,e,r=""){if(Fn(t)&&(e===void 0||t.length===e))return t;e!==void 0&&We(e,"length");let n=Fn(t),s=e!==void 0?` of length ${e}`:"",o=n?`length=${t.length}`:`type=${typeof t}`,i=Ro(r)+"expected Uint8Array"+s+", got "+o;throw n?new RangeError(i):new TypeError(i)}function Ft(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(We(t.outputLen),We(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var Mh=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)},Lc=(t,e)=>{Mh(t,e);let r=Object.getPrototypeOf(t);if(r!==Object.prototype&&r!==null)throw new TypeError(`"${e}" expected plain object`);if(Object.hasOwn(t,"__proto__"))throw new TypeError(`"${e}.__proto__" is not allowed`)};function pr(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function Hn(t,e){Oe(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function Fe(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function qn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Ye(t,e){return t<<32-e|t>>>e}var Cc=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Kh=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function zn(t){if(Oe(t),Cc)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=Kh[t[r]];return e}function Tc(t){return t>=48&&t<=57?t-48:t>=65&&t<=70?t-55:t>=97&&t<=102?t-87:void 0}function $n(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(Cc)try{return Uint8Array.fromHex(t)}catch(s){throw s instanceof SyntaxError?new RangeError(s.message):s}let e=t.length,r=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let s=0,o=0;s<r;s++,o+=2){let i=Tc(t.charCodeAt(o)),a=Tc(t.charCodeAt(o+1));if(i===void 0||a===void 0){let c=t[o]+t[o+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+o)}n[s]=i*16+a}return n}function Oo(...t){let e=0;for(let n=0;n<t.length;n++){let s=t[n];Oe(s),e+=s.length}let r=new Uint8Array(e);for(let n=0,s=0;n<t.length;n++){let o=t[n];r.set(o,s),s+=o.length}return r}function Fh(t,e,r="opts"){return Lc(t,"defaults"),e!==void 0&&Lc(e,r),Object.assign(Object.create(null),t,e)}function Po(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=Fh({},e,"info");let r=(s,o)=>t(o).update(s).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=s=>t(s),Object.assign(r,e),Object.freeze(r)}function Ic(t=32){We(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var Uo=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Dc(t,e,r){return t&e^~t&r}function Rc(t,e,r){return t&e^t&r^e&r}var jr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,s){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(e),this.view=qn(this.buffer)}update(e){pr(this),Oe(e);let{view:r,buffer:n,blockLen:s}=this,o=e.length,i=!1;for(let a=0;a<o;){let c=Math.min(s-this.pos,o-a);if(c===s){let u=qn(e);for(;s<=o-a;a+=s)this.process(u,a);i=!0;continue}n.set(a===0&&c===o?e:e.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===s&&(this.process(r,0),this.pos=0,i=!0)}return this.length+=e.length,i&&this.roundClean(),this}digestInto(e){pr(this),Hn(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:s,isLE:o}=this,{pos:i}=this;r[i++]=128,r.fill(0,i),this.padOffset>s-i&&(this.process(n,0),r.fill(0)),xc(n,s-8,this.length*8,o),this.process(n,0),this.roundClean();let a=e===r?n:qn(e),c=this.outputLen,u=c/4,f=this.get();if(c%4||u>f.length)throw new Error("invalid outputLen");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],o)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:r,length:n,finished:s,destroyed:o,pos:i}=this;return e.destroyed=o,e.finished=s,e.length=n,e.pos=i,i&&e.buffer.set(r),e}clone(){return this._cloneInto()}},Oc=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Pc=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Hh=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Et=new Uint32Array(64),No=class extends jr{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(e,r){super(64,e,8,!1),this.A=r[0]|0,this.B=r[1]|0,this.C=r[2]|0,this.D=r[3]|0,this.E=r[4]|0,this.F=r[5]|0,this.G=r[6]|0,this.H=r[7]|0}get(){let{A:e,B:r,C:n,D:s,E:o,F:i,G:a,H:c}=this;return[e,r,n,s,o,i,a,c]}set(e,r,n,s,o,i,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let l=0;l<16;l++,r+=4)Et[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let d=Et[l-15],p=Et[l-2],g=Ye(d,7)^Ye(d,18)^d>>>3,b=Ye(p,17)^Ye(p,19)^p>>>10;Et[l]=b+Et[l-7]+g+Et[l-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let d=Ye(a,6)^Ye(a,11)^Ye(a,25),p=f+d+Dc(a,c,u)+Hh[l]+Et[l]|0,b=(Ye(n,2)^Ye(n,13)^Ye(n,22))+Rc(n,s,o)|0;f=u,u=c,c=a,a=i+p|0,i=o,o=s,s=n,n=p+b|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,s,o,i,a,c,u,f)}roundClean(){Fe(Et)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Fe(this.buffer)}},ko=class extends No{constructor(){super(32,Oc)}};var Uc=wc(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),qh=Uc[0],zh=Uc[1],St=new Uint32Array(80),vt=new Uint32Array(80),Mo=class extends jr{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(e,r){super(128,e,16,!1),this.Ah=r[0]|0,this.Al=r[1]|0,this.Bh=r[2]|0,this.Bl=r[3]|0,this.Ch=r[4]|0,this.Cl=r[5]|0,this.Dh=r[6]|0,this.Dl=r[7]|0,this.Eh=r[8]|0,this.El=r[9]|0,this.Fh=r[10]|0,this.Fl=r[11]|0,this.Gh=r[12]|0,this.Gl=r[13]|0,this.Hh=r[14]|0,this.Hl=r[15]|0}get(){let{Ah:e,Al:r,Bh:n,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:d,Gh:p,Gl:g,Hh:b,Hl:y}=this;return[e,r,n,s,o,i,a,c,u,f,l,d,p,g,b,y]}set(e,r,n,s,o,i,a,c,u,f,l,d,p,g,b,y){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=s|0,this.Ch=o|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=d|0,this.Gh=p|0,this.Gl=g|0,this.Hh=b|0,this.Hl=y|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let w=0;w<16;w++,r+=4)St[w]=e.getUint32(r),vt[w]=e.getUint32(r+=4);for(let w=16;w<80;w++){let I=St[w-15]|0,T=vt[w-15]|0,O=Mt(I,T,1)^Mt(I,T,8)^Io(I,T,7),M=Kt(I,T,1)^Kt(I,T,8)^Do(I,T,7),U=St[w-2]|0,C=vt[w-2]|0,D=Mt(U,C,19)^$r(U,C,61)^Io(U,C,6),F=Kt(U,C,19)^Vr(U,C,61)^Do(U,C,6),K=vc(M,F,vt[w-7],vt[w-16]),$=Ac(K,O,D,St[w-7],St[w-16]);St[w]=$|0,vt[w]=K|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:d,Fh:p,Fl:g,Gh:b,Gl:y,Hh:x,Hl:E}=this;for(let w=0;w<80;w++){let I=Mt(l,d,14)^Mt(l,d,18)^$r(l,d,41),T=Kt(l,d,14)^Kt(l,d,18)^Vr(l,d,41),O=l&p^~l&b,M=d&g^~d&y,U=Bc(E,T,M,zh[w],vt[w]),C=_c(U,x,I,O,qh[w],St[w]),D=U|0,F=Mt(n,s,28)^$r(n,s,34)^$r(n,s,39),K=Kt(n,s,28)^Vr(n,s,34)^Vr(n,s,39),$=n&o^n&a^o&a,B=s&i^s&c^i&c;x=b|0,E=y|0,b=p|0,y=g|0,p=l|0,g=d|0,{h:l,l:d}=Xe(u|0,f|0,C|0,D|0),u=a|0,f=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let P=Ec(D,K,B);n=Sc(P,C,F,$),s=P|0}({h:n,l:s}=Xe(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=Xe(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=Xe(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Xe(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:d}=Xe(this.Eh|0,this.El|0,l|0,d|0),{h:p,l:g}=Xe(this.Fh|0,this.Fl|0,p|0,g|0),{h:b,l:y}=Xe(this.Gh|0,this.Gl|0,b|0,y|0),{h:x,l:E}=Xe(this.Hh|0,this.Hl|0,x|0,E|0),this.set(n,s,o,i,a,c,u,f,l,d,p,g,b,y,x,E)}roundClean(){Fe(St,vt)}destroy(){this.destroyed=!0,Fe(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Ko=class extends Mo{constructor(){super(64,Pc)}};var Qe=Po(()=>new ko,Uo(1));var Fo=Po(()=>new Ko,Uo(3));function jn(t,e,r=()=>{}){if(!Array.isArray(t))throw new TypeError(`"${e}" expected array, got type=${typeof t}`);for(let n=0;n<t.length;n++)r(t[n],`${e}[${n}]`);return t}var Z=(t,e,r)=>Oe(t,e,r),Ho=We;function kc(t,e=""){if(typeof t!="string"){let r=e&&`"${e}" `;throw new TypeError(r+"expected string, got type="+typeof t)}return t}function At(t,e="object"){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof t}`);return t}function Ht(t,e){if(typeof t!="function")throw new TypeError(`"${e}" is invalid: expected function, got ${typeof t}`);return t}var Wr=zn,He=(...t)=>Oo(...t),mr=t=>$n(t),_t=Fn,at=t=>Ic(t),Vn=BigInt(0),Nc=BigInt(1),$h=t=>t?`"${t}" `:"";function Ne(t,e=""){if(typeof t!="boolean")throw new TypeError($h(e)+"expected boolean, got type="+typeof t);return t}function Wn(t){if(typeof t=="bigint"){if(!Bt(t))throw new RangeError("positive bigint expected, got "+t)}else Ho(t);return t}function ct(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(r+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new RangeError(r+"expected safe integer, got "+t)}}function Yr(t){let e=Wn(t).toString(16);return e.length&1?"0"+e:e}function Mc(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?Vn:BigInt("0x"+t)}function Je(t){return Mc(zn(t))}function et(t){return Mc(zn(Lt(Oe(t)).reverse()))}function Yn(t,e){if(We(e),e===0)throw new Error("zero output length is invalid");t=Wn(t);let r=e*2,n=t.toString(16);if(n.length>r)throw new RangeError("number is too large");return $n(n.padStart(r,"0"))}function Gr(t,e){return Yn(t,e).reverse()}function Lt(t){return Uint8Array.from(Z(t))}function Bt(t){return typeof t=="bigint"&&Vn<=t}function qo(t,e,r){return Bt(t)&&Bt(e)&&Bt(r)&&e<=t&&t<r}function tt(t,e,r,n){if(!qo(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function yr(t){if(t<Vn)throw new Error("expected non-negative bigint, got "+t);return t===Vn?0:t.toString(2).length}var Zr=t=>(ct(t,"n"),(Nc<<BigInt(t))-Nc);function Kc(t,e,r){if(We(t,"hashLen"),We(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=y=>new Uint8Array(y),s=Uint8Array.of(),o=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(t),u=n(t),f=0,l=()=>{c.fill(1),u.fill(0),f=0},d=(...y)=>r(u,He(c,...y)),p=(y=s)=>{u=d(o,y),c=d(),y.length!==0&&(u=d(i,y),c=d())},g=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let y=0,x=[];for(;y<e;){c=d();let E=c.slice();x.push(E),y+=c.length}return He(...x)};return(y,x)=>{l(),p(y);let E;for(;(E=x(g()))===void 0;)p();return l(),E}}function Le(t,e={},r={},n="object"){At(t,n),At(e,"fields"),At(r,"optFields");function s(i,a,c){let u=n==="object"?`param "${String(i)}"`:`"${n}.${String(i)}"`,f=t[i];if(!Object.hasOwn(t,i)&&(c?f!==void 0:a!=="function"))throw new TypeError(`${u} is invalid: expected own property`);if(c&&f===void 0)return;let l=typeof f;if(l!==a||f===null)throw new TypeError(`${u} is invalid: expected ${a}, got ${l}`)}let o=(i,a)=>Object.entries(i).forEach(([c,u])=>s(c,u,a));o(e,!1),o(r,!0)}var Ee=BigInt(0),te=BigInt(1),Tt=BigInt(2),qc=BigInt(3),zo=BigInt(4),zc=BigInt(5),Vh=BigInt(7),$c=BigInt(8),jh=BigInt(9),Wh=BigInt(15),Vc=BigInt(16),Yh=BigInt("0x10000000000000000");function ne(t,e){if(e<=Ee)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=Ee?r:e+r}function jc(t,e,r){if(r<=te)throw new Error("pow: expected modulus > 1, got "+r);if(typeof e!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof e);if(e<Ee)throw new Error("invalid exponent, negatives unsupported");if(e===Ee)return te;if(e===te)return t;let n=t%r;if(n<Ee&&(n+=r),e<Yh){let a=te;for(;e>Ee;)e&te&&(a=a*n%r),n=n*n%r,e>>=te;return a}let s=[];for(;e>Ee;)s.push(Number(e&Wh)),e>>=zo;let o=new Array(16);o[0]=te,o[1]=n;for(let a=2;a<16;a++)o[a]=o[a-1]*n%r;let i=o[s[s.length-1]];for(let a=s.length-2;a>=0;a--){i=i*i%r,i=i*i%r,i=i*i%r,i=i*i%r;let c=s[a];c!==0&&(i=i*o[c]%r)}return i}function ue(t,e,r){if(r<=te)throw new Error("pow2: expected modulus > 1, got "+r);if(e<Ee)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >Ee;)n*=n,n%=r;return n}function Fc(t,e){if(t===Ee)throw new Error("invert: expected non-zero number");if(e<=te)throw new Error("invert: expected modulus > 1, got "+e);let r=ne(t,e),n=e,s=Ee,o=te;for(;r!==Ee;){let a=n/r,c=n-r*a,u=s-o*a;n=r,r=c,s=o,o=u}if(n!==te)throw new Error("invert: does not exist");return ne(s,e)}function Wc(t,e){if(e<=te)throw new Error("invertCt: expected prime modulus > 1, got "+e);let r=ne(t,e);if(r===Ee)throw new Error("invertCt: expected non-zero number");let n=jc(r,e-Tt,e);if(ne(r*n,e)!==te)throw new Error("invertCt: does not exist");return n}function $o(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function Vo(t,e){if((t&te)===Ee)throw new Error(e+": expected odd modulus, got "+t)}function Yc(t,e){let r=t,n=(r.ORDER+te)/zo,s=r.pow(e,n);return $o(r,s,e),s}function Gh(t,e){let r=t,n=(r.ORDER-zc)/$c,s=r.mul(e,Tt),o=r.pow(s,n),i=r.mul(e,o),a=r.mul(r.mul(i,Tt),o),c=r.mul(i,r.sub(a,r.ONE));return $o(r,c,e),c}function Zh(t){let e=br(t),r=Gc(t),n=r(e,e.neg(e.ONE)),s=r(e,n),o=r(e,e.neg(n)),i=(t+Vh)/Vc;return((a,c)=>{let u=a,f=u.pow(c,i),l=u.mul(f,n),d=u.mul(f,s),p=u.mul(f,o),g=u.eql(u.sqr(l),c),b=u.eql(u.sqr(d),c);f=u.cmov(f,l,g),l=u.cmov(p,d,b);let y=u.eql(u.sqr(l),c),x=u.cmov(f,l,y);return $o(u,x,c),x})}function Gc(t){if(t<qc)throw new Error("sqrt is not defined for small field");Vo(t,"tonelliShanks");let e=t-te,r=0;for(;e%Tt===Ee;)e/=Tt,r++;let n=Tt,s=br(t);for(;Xr(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Yc;let o=s.pow(n,e),i=(e+te)/Tt;return function(c,u){let f=c;if(f.is0(u))return u;if(Xr(f,u)!==1)throw new Error("Cannot find square root");let l=r,d=f.mul(f.ONE,o),p=f.pow(u,e),g=f.pow(u,i);for(;!f.eql(p,f.ONE);){if(f.is0(p))throw new Error("Cannot find square root: probably non-prime P");let b=1,y=f.sqr(p);for(;!f.eql(y,f.ONE);)if(b++,y=f.sqr(y),b===l)throw new Error("Cannot find square root");let x=te<<BigInt(l-b-1),E=f.pow(d,x);l=b,d=f.sqr(E),p=f.mul(p,d),g=f.mul(g,E)}return g}}function Xh(t){return Vo(t,"Fp.sqrt"),t%zo===qc?Yc:t%$c===zc?Gh:t%Vc===jh?Zh(t):Gc(t)}var Zc=(t,e)=>(ne(t,e)&te)===te,Qh=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function gr(t){if(At(t,"field"),typeof t.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof t.ORDER);ct(t.BYTES,"BYTES"),ct(t.BITS,"BITS");for(let e of Qh)Ht(t[e],"field."+e);if(t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=te)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function Zn(t,e,r=!1){gr(t),jn(e,"nums"),Ne(r,"passZero");let n=t,s=new Array(e.length).fill(r?n.ZERO:void 0),o=e.reduce((a,c,u)=>n.is0(c)?a:(s[u]=a,n.mul(a,c)),n.ONE),i=n.inv(o);return e.reduceRight((a,c,u)=>n.is0(c)?a:(s[u]=n.mul(a,s[u]),n.mul(a,c)),i),s}function Xr(t,e){gr(t);let r=t;Vo(r.ORDER,"FpLegendre");let n=(r.ORDER-te)/Tt,s=r.pow(e,n),o=r.eql(s,r.ONE),i=r.eql(s,r.ZERO),a=r.eql(s,r.neg(r.ONE));if(!o&&!i&&!a)throw new Error("invalid Legendre symbol result");return o?1:i?0:-1}function Jh(t,e){if(e!==void 0&&Ho(e),t<=Ee)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=yr(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected nBitLength (${e}) >= bitLen(n) (${r})`);let n=e!==void 0?e:r,s=Math.ceil(n/8);return{nBitLength:n,nByteLength:s}}var Hc=new WeakMap,Gn=class{ORDER;BITS;BYTES;isLE;ZERO=Ee;ONE=te;_lengths;_mod;constructor(e,r={}){if(e<=te)throw new Error("invalid field: expected ORDER > 1, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:s,nByteLength:o}=Jh(e,n);if(o>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=s,this.BYTES=o,Object.freeze(this)}create(e){return ne(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return Ee<=e&&e<this.ORDER}is0(e){return e===Ee}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&te)===te}neg(e){return ne(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return ne(e*e,this.ORDER)}add(e,r){return ne(e+r,this.ORDER)}sub(e,r){return ne(e-r,this.ORDER)}mul(e,r){return ne(e*r,this.ORDER)}pow(e,r){return jc(e,r,this.ORDER)}div(e,r){return ne(e*Fc(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return Fc(e,this.ORDER)}sqrt(e){let r=Hc.get(this);return r||Hc.set(this,r=Xh(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?Gr(e,this.BYTES):Yn(e,this.BYTES)}fromBytes(e,r=!1){Z(e);let{_lengths:n,BYTES:s,isLE:o,ORDER:i,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>s)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(s);u.set(e,o?0:u.length-e.length),e=u}if(e.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+e.length);let c=o?et(e):Je(e);if(a&&(c=ne(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return Zn(this,e,!0)}cmov(e,r,n){return Ne(n,"condition"),n?r:e}};function br(t,e={}){return Object.freeze(Gn.prototype),new Gn(t,e)}function Xc(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=te)throw new Error("field order must be greater than 1");let e=yr(t-te);return Math.ceil(e/8)}function Xn(t){let e=Xc(t);return e+Math.ceil(e/2)}function Qn(t,e,r=!1){Z(t);let n=t.length,s=Xc(e),o=Math.max(Xn(e),16);if(n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);let i=r?et(t):Je(t),a=ne(i,e-te)+te;return r?Gr(a,s):Yn(a,s)}var Yo=BigInt(0),Qr=BigInt(1),ed=BigInt(4),jo=16,Qc=128,td=5,Jc=2**31;function Ct(t){let e=t;if(typeof e!="function")throw new TypeError('"Point" expected constructor, got type='+typeof t);Ht(e.fromAffine,"Point.fromAffine"),Ht(e.fromBytes,"Point.fromBytes"),Ht(e.fromHex,"Point.fromHex"),At(e.BASE,"Point.BASE"),At(e.ZERO,"Point.ZERO"),gr(e.Fp),gr(e.Fn)}function Jn(t,e){Ct(t),tu(e,t);let r=Zn(t.Fp,e.map(n=>n.Z));return e.map((n,s)=>t.fromAffine(n.toAffine(r[s])))}function rd(t,e,r=1){if(!Number.isSafeInteger(t)||t<r||t>e)throw new Error("invalid window size, expected ["+r+".."+e+"], got W="+t)}function nd(t,e){let r=t*(4*e+128);if(r>Jc)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+Jc/2**20+" MiB")}function Go(t,e){if(t!==void 0){Ht(t,"randomBytes");try{let r=t(e);if(!_t(r)||r.length!==e)return}catch{return}return t}}function tu(t,e){jn(t,"points"),t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function sd(t,e,r){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,s)=>{if(!(r===void 0?e.isValid(n):Bt(n)&&n<r))throw new Error("invalid scalar at index "+s)})}var ru=new WeakMap;function Wo(t){return ru.get(t)||1}function od(t,e){let r=t.double(),n=[t];for(let s=1;s<e;s++)n.push(n[s-1].add(r));return n}function id(t,e){let r=2**e,n=r/2,s=BigInt(r-1),o=[];for(;t>Yo;){let i=0;t&Qr&&(i=Number(t&s),i>=n&&(i-=r),t-=BigInt(i)),o.push(i),t>>=Qr}return o}function ad(t,e,r){let n=2**e,s=n/2,o=BigInt(n-1),i=BigInt(e),a=[];for(let c=0;c<r;c++){let u=Number(t&o);t>>=i,u>s&&(u-=n,t+=Qr),a.push(u)}if(t!==Yo)throw new Error("invalid wnaf");return a}function cd(t,e,r){let n=0;for(let o of r)n=Math.max(n,o.length);let s=t;for(let o=n-1;o>=0;o--){o!==n-1&&(s=s.double());for(let i=0;i<r.length;i++){let a=r[i][o];if(a){let c=e[i][Math.abs(a)-1>>1];s=s.add(a<0?c.negate():c)}}}return s}var wr=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(e,r){Ct(e),this.randomBytes=Go(r,jo),this.Point=e,this.BASE=e.BASE,this.ZERO=e.ZERO,this.bits=e.Fn.BITS}buildWnafTable(e,r,n){let s=Math.ceil(n/r)+1,o=2**(r-1),i=[],a=e;for(let c=0;c<s;c++){let u=a;for(let f=0;f<o;f++)i.push(u),u=u.add(a);a=i[i.length-1].double()}return{W:r,bits:n,windows:s,comp:i}}wnafCachedCT(e,r){let{W:n,windows:s,comp:o}=e,i=2**(n-1),a=ad(r,n,s),c=this.ZERO,u=this.BASE;for(let f=0;f<s;f++){let l=a[f],d=f*i,p=Math.abs(l)-1,g=o[d];for(let y=1;y<i;y++)g=y===p?o[d+y]:g;let b=g.negate();l===0?u=u.add(o[d]):c=c.add(l<0?b:g)}return{p:c,f:u}}getWnafPrecomputes(e,r,n,s){let o=this.wnafPrecomputes.get(r),i=o?.find(a=>a.W===e&&a.bits===n);return i||(i=this.buildWnafTable(r,e,n),typeof s=="function"&&(i={...i,comp:s(i.comp)}),o||(o=[],this.wnafPrecomputes.set(r,o)),o.push(i)),i}assertPoint(e){if(!(e instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof e)}validateMulInput(e,r){if(this.assertPoint(e),!qo(r,Qr,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(e,r,n,s){let o=Wo(e);return o===1?this.fixedWindowCT(e,r,n):this.wnafCachedCT(this.getWnafPrecomputes(o,e,n,s),r)}mulCT(e,r,n){return this.validateMulInput(e,r),this.runCT(e,r,this.bits,n)}mulCTBlinded(e,r,n){if(this.validateMulInput(e,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let s=this.Point.Fn.BITS+Qc,o=this.randomBytes(jo);if(!_t(o)||o.length!==jo)throw new Error("randomBytes returned invalid byte array");o[0]=o[0]&63|128;let i=r+Je(o)*this.Point.Fn.ORDER;return this.runCT(e,i,s,n)}fixedWindowCT(e,r,n){let s=td,o=1<<s,i=Zr(s),a=new Array(o);a[0]=this.ZERO;for(let f=1;f<o;f++)a[f]=a[f-1].add(e);let c=Math.ceil(n/s),u=this.ZERO;for(let f=c-1;f>=0;f--){if(f!==c-1)for(let p=0;p<s;p++)u=u.double();let l=Number(r>>BigInt(f*s)&i),d=a[0];for(let p=1;p<o;p++)d=p===l?a[p]:d;u=u.add(d)}return{p:u,f:u}}shouldBlind(e,r){return this.randomBytes===void 0?!1:r===Qr?!0:e!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(e,r,n,s){return this.shouldBlind(e,n)?this.mulCTBlinded(e,r,s):this.mulCT(e,r,s)}mulUnsafe(e,r,n){if(this.assertPoint(e),!Bt(r))throw new Error("invalid scalar");let s=Wo(e);if(s===1||r>=this.Point.Fn.ORDER)return es(this.Point,[e],[r],!0);let o=this.getWnafPrecomputes(s,e,this.bits,n);return this.wnafCachedCT(o,r).p}setWindowSize(e,r){this.assertPoint(e),rd(r,this.bits);let n=Math.ceil((this.bits+Qc)/r)+1;nd(n*2**(r-1),this.Point.Fp.BYTES),ru.set(e,r),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return Wo(e)!==1}};function es(t,e,r,n=!1){if(Ct(t),tu(e,t),Ne(n,"allowOversized"),sd(r,t.Fn,n?t.Fn.ORDER**ed:void 0),e.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let s=e.map(i=>od(i,4)),o=r.map(i=>id(i,4));return cd(t.ZERO,s,o)}function eu(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return gr(e),e}else return br(t,{isLE:r})}function ts(t,e,r={},n){if(t!=="weierstrass"&&t!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);Le(r);for(let c of["p","n","h"]){let u=e[c];if(!(Bt(u)&&u!==Yo))throw new Error(`CURVE.${c} must be positive bigint`)}let s=eu(e.p,r.Fp,n),o=eu(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!s.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:s,Fn:o}}function xr(t,e){return function(n){let s=t(n);return{secretKey:s,publicKey:e(s)}}}var rs=BigInt(0),ns=BigInt(1),ss=BigInt(2),ud=BigInt(4),nu=BigInt(8);function fd(t,e,r,n){let s=t.sqr(r),o=t.sqr(n),i=t.add(t.mul(e.a,s),o),a=t.add(t.ONE,t.mul(e.d,t.mul(s,o)));return t.eql(i,a)}function su(t,e={}){Le(e,{},{},"extraOpts");let r=e,n=ts("edwards",t,r,r.FpFnLE),{Fp:s,Fn:o}=n,i=n.CURVE,{h:a}=i;if(Xr(s,i.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(Xr(s,i.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");Le(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?at:r.randomBytes,u=ss<<BigInt(s.BYTES*8)-ns;function f(E){if(!s.isOdd)throw new Error("Field does not have .isOdd()");return s.isOdd(E)}let l=r.uvRatio===void 0?(E,w)=>{try{return{isValid:!0,value:s.sqrt(s.div(E,w))}}catch{return{isValid:!1,value:rs}}}:r.uvRatio;if(!fd(s,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");let d=s.eql(i.a,s.neg(s.ONE))?E=>s.neg(E):s.eql(i.a,s.ONE)?E=>E:E=>s.mul(i.a,E);function p(E,w,I=!1){let T=I?ns:rs;return tt("coordinate "+E,w,T,u),w}function g(E){if(!(E instanceof b))throw new Error("EdwardsPoint expected")}class b{static BASE=new b(i.Gx,i.Gy,s.ONE,s.mul(i.Gx,i.Gy));static ZERO=new b(s.ZERO,s.ONE,s.ONE,s.ZERO);static Fp=s;static Fn=o;X;Y;Z;T;constructor(w,I,T,O){this.X=p("x",w),this.Y=p("y",I),this.Z=p("z",T,!0),this.T=p("t",O),Object.freeze(this)}static CURVE(){return i}static fromAffine(w){if(w instanceof b)throw new Error("extended point not allowed");let{x:I,y:T}=w||{};return p("x",I),p("y",T),new b(I,T,s.ONE,s.mul(I,T))}static fromBytes(w,I=!1){let T=s.BYTES,{a:O,d:M}=i;w=Lt(Z(w,T,"point")),Ne(I,"zip215");let U=Lt(w),C=w[T-1];U[T-1]=C&-129;let D=et(U),F=I?u:s.ORDER;tt("point.y",D,rs,F);let K=s.sqr(D),$=s.sub(K,s.ONE),B=s.sub(s.mulN(M,K),O),{isValid:P,value:_}=l($,B);if(!P)throw new Error("bad point: invalid y coordinate");let A=f(_),H=(C&128)!==0;if(!I&&s.is0(_)&&H)throw new Error("bad point: x=0 and x_0=1");return H!==A&&(_=s.neg(_)),b.fromAffine({x:_,y:D})}static fromHex(w,I=!1){return b.fromBytes(mr(w),I)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(w=6,I=!0){return x.setWindowSize(this,w),I||this.multiply(ss),this}assertValidity(){let w=this,{a:I,d:T}=i;if(w.is0())throw new Error("bad point: ZERO");let{X:O,Y:M,Z:U,T:C}=w,D=s.sqr(O),F=s.sqr(M),K=s.sqr(U),$=s.sqr(K),B=s.mul(D,I),P=s.mul(s.add(B,F),K),_=s.add($,s.mul(T,s.mul(D,F)));if(!s.eql(P,_))throw new Error("bad point: equation left != right (1)");let A=s.mul(O,M),H=s.mul(U,C);if(!s.eql(A,H))throw new Error("bad point: equation left != right (2)")}equals(w){g(w);let{X:I,Y:T,Z:O}=this,{X:M,Y:U,Z:C}=w,D=s.mul(I,C),F=s.mul(M,O),K=s.mul(T,C),$=s.mul(U,O);return s.eql(D,F)&&s.eql(K,$)}is0(){return this.equals(b.ZERO)}negate(){return new b(s.neg(this.X),this.Y,this.Z,s.neg(this.T))}double(){let{X:w,Y:I,Z:T}=this,O=s.sqr(w),M=s.sqr(I),U=s.mul(s.sqr(T),ss),C=d(O),D=s.addN(w,I),F=s.sub(s.subN(s.sqr(D),O),M),K=s.addN(C,M),$=s.subN(K,U),B=s.subN(C,M),P=s.mul(F,$),_=s.mul(K,B),A=s.mul(F,B),H=s.mul($,K);return new b(P,_,H,A)}add(w){g(w);let{d:I}=i,{X:T,Y:O,Z:M,T:U}=this,{X:C,Y:D,Z:F,T:K}=w,$=s.mul(T,C),B=s.mul(O,D),P=s.mul(s.mulN(U,I),K),_=s.mul(M,F),A=s.sub(s.subN(s.mulN(s.addN(T,O),s.addN(C,D)),$),B),H=s.subN(_,P),L=s.addN(_,P),S=s.sub(B,d($)),h=s.mul(A,H),m=s.mul(L,S),v=s.mul(A,S),R=s.mul(H,L);return new b(h,m,R,v)}subtract(w){return g(w),this.add(w.negate())}multiply(w){if(!o.isValidNot0(w))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:I,f:T}=x.mulSecret(this,w,a,y);return y([I,T])[0]}multiplyUnsafe(w){if(!o.isValid(w))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return w===rs?b.ZERO:this.is0()||w===ns?this:x.mulUnsafe(this,w,y)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return x.mulUnsafe(this,i.n).is0()}toAffine(w){let I=this,T=w;if(T!=null&&typeof T!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof T);let{X:O,Y:M,Z:U}=I,C=I.is0();T==null&&(T=C?s.create(nu):s.inv(U));let D=s.mul(O,T),F=s.mul(M,T),K=s.mul(U,T);if(C)return{x:s.ZERO,y:s.ONE};if(!s.eql(K,s.ONE))throw new Error("invZ was invalid");return{x:D,y:F}}clearCofactor(){return a===ns?this:a===ss?this.double():a===ud?this.double().double():a===nu?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:w,y:I}=this.toAffine(),T=s.toBytes(I);return T[T.length-1]|=f(w)?128:0,T}toHex(){return Wr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let y=E=>Jn(b,E),x=new wr(b,c);return x.bits>=6&&b.BASE.precompute(6),Object.freeze(b.prototype),Object.freeze(b),b}function ou(t,e,r={}){if(Ct(t),typeof e!="function")throw new Error('"hash" function param is required');let n=e,s=r;Le(s,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:o}=s,{BASE:i,Fp:a,Fn:c}=t,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(ct(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=s.randomBytes===void 0?at:s.randomBytes,d=s.toMontgomery,p=s.toMontgomerySecret,g=s.adjustScalarBytes===void 0?B=>B:s.adjustScalarBytes,b=s.domain===void 0?(B,P,_)=>{if(Ne(_,"phflag"),P.length||_)throw new Error("Contexts/pre-hash are not supported");return B}:s.domain;function y(B){return c.create(et(B))}function x(B){let P=C.secretKey;Z(B,C.secretKey,"secretKey");let _=Z(n(B),2*P,"hashedSecretKey"),A=g(_.slice(0,P)),H=_.slice(P,2*P),L=y(A);return{head:A,prefix:H,scalar:L}}function E(B){let{head:P,prefix:_,scalar:A}=x(B),H=i.multiply(A),L=H.toBytes();return{head:P,prefix:_,scalar:A,point:H,pointBytes:L}}function w(B){return E(B).pointBytes}function I(B=Uint8Array.of(),...P){let _=He(...P);return y(n(b(_,Z(B,void 0,"context"),!!o)))}function T(B,P,_={}){Le(_,{},{},"options"),B=Lt(Z(B,void 0,"message")),o&&(B=o(B));let{prefix:A,scalar:H,pointBytes:L}=E(P),S=I(_.context,A,B),h=i.multiply(S).toBytes(),m=I(_.context,h,L,B),v=c.create(S+m*H);if(!c.isValid(v))throw new Error("sign failed: invalid s");let R=He(h,c.toBytes(v));return Z(R,C.signature,"result")}let O={zip215:s.zip215};function M(B,P,_,A=O){Le(A);let{context:H}=A,L=A.zip215===void 0?!!O.zip215:A.zip215,S=C.signature;B=Z(B,S,"signature"),P=Z(P,void 0,"message"),_=Z(_,C.publicKey,"publicKey"),L!==void 0&&Ne(L,"zip215"),o&&(P=o(P));let h=S/2,m=B.subarray(0,h),v=et(B.subarray(h,S)),R,N,k;try{R=t.fromBytes(_,L),N=t.fromBytes(m,L),k=i.multiplyUnsafe(v)}catch{return!1}if(!L&&R.isSmallOrder())return!1;let q=I(H,m,_,P);return N.add(R.multiplyUnsafe(q)).subtract(k).clearCofactor().is0()}let U=a.BYTES,C={secretKey:U,publicKey:U,signature:2*U,seed:U};function D(B){return B=B===void 0?l(C.seed):B,Z(B,C.seed,"seed")}function F(B){return _t(B)&&B.length===C.secretKey}function K(B,P){try{return!!t.fromBytes(B,P===void 0?O.zip215:P)}catch{return!1}}let $={getExtendedPublicKey:E,randomSecretKey:D,isValidSecretKey:F,isValidPublicKey:K,toMontgomery(B){if(d===void 0)throw new Error("Montgomery conversion is not supported for this curve");return d(t.fromBytes(B))},toMontgomerySecret(B){if(p===void 0)throw new Error("Montgomery conversion is not supported for this curve");return p(B)}};return Object.freeze(C),Object.freeze($),Object.freeze({keygen:xr(D,w),getPublicKey:w,sign:T,verify:M,utils:$,Point:t,lengths:C})}var qt=BigInt(0),qe=BigInt(1),os=BigInt(2);function iu(t,e){return t+e-(e>>qe<<qe)}function ld(t){let e=BigInt(6)*t;return(r,n,s)=>{let o=n+s,a=((e+s-n)*r+n)%t;return{x_2:a,x_3:o-a}}}function hd(t){return Le(t,{P:"bigint",type:"string",adjustScalarBytes:"function",powPminus2:"function"},{randomBytes:"function",scalarMultBase:"function"}),Object.freeze({...t})}function au(t){let e=hd(t),{P:r,type:n,adjustScalarBytes:s,powPminus2:o,randomBytes:i}=e,a=e.scalarMultBase,c=n==="x25519";if(!c&&n!=="x448")throw new Error("invalid type");let u=i===void 0?at:i,f=c?255:448,l=ld(r),d=c?32:56,p=BigInt(c?9:5),g=BigInt(c?121665:39081),b=c?os**BigInt(254):os**BigInt(447),y=c?BigInt(8)*(os**BigInt(251)-qe):BigInt(4)*(os**BigInt(445)-qe),x=b+y+qe,E=_=>ne(_,r),w=I(p);function I(_){return Gr(E(_),d)}function T(_){let A=Lt(Z(_,d,"uCoordinate"));return c&&(A[31]&=127),E(et(A))}function O(_){return et(s(Lt(Z(_,d,"scalar"))))}let M=new Set(c?[qt,qe,r-qe,BigInt("325606250916557431795983626356110631294008115727848805560023387167927233504"),BigInt("39382357235489614581723060781553021112529911719440698176882885853963445705823")]:[qt,qe,r-qe]);function U(_,A){let H=T(A);if(M.has(H))throw new Error("invalid private or public key received");let L=K(H,O(_));if(L===qt)throw new Error("invalid private or public key received");return I(L)}function C(_){if(a===void 0)return U(_,w);let A=O(_);tt("scalar",A,b,x);let H=E(a(A));if(H===qt)throw new Error("invalid private or public key received");return I(H)}let D=C,F=U;function K(_,A){tt("u",_,qt,r),tt("scalar",A,b,x);let H=A,L=_,S=qe,h=qt,m=_,v=qe,R=H^H>>qe;for(let q=BigInt(f-1);q>=qt;q--){let z=iu(r,R>>q);({x_2:S,x_3:m}=l(z,S,m)),{x_2:h,x_3:v}=l(z,h,v);let j=S+h,Y=E(j*j),ce=S-h,ie=E(ce*ce),ye=Y-ie,Pe=m+v,ae=m-v,he=E(ae*j),sr=E(Pe*ce),Nr=he+sr,mt=he-sr;m=E(Nr*Nr),v=E(L*E(mt*mt)),S=E(Y*ie),h=E(ye*(Y+E(g*ye)))}let N=iu(r,H);({x_2:S,x_3:m}=l(N,S,m)),{x_2:h,x_3:v}=l(N,h,v);let k=o(h);return E(S*k)}let $={secretKey:d,publicKey:d,seed:d},B=_=>(_=_===void 0?u(d):_,Z(_,$.seed,"seed"),_),P={randomSecretKey:B};return Object.freeze($),Object.freeze(P),Object.freeze({keygen:xr(B,D),getSharedSecret:F,getPublicKey:D,scalarMult:U,scalarMultBase:C,utils:P,GuBytes:w.slice(),lengths:$})}var cu=BigInt(0),Zo=BigInt(1),uu=BigInt(2),dd=BigInt(3),pd=BigInt(5),md=BigInt(8),is=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),yd={p:is,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:md,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function hu(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),s=BigInt(80),o=is,a=t*t%o*t%o,c=ue(a,uu,o)*a%o,u=ue(c,Zo,o)*t%o,f=ue(u,pd,o)*u%o,l=ue(f,e,o)*f%o,d=ue(l,r,o)*l%o,p=ue(d,n,o)*d%o,g=ue(p,s,o)*p%o,b=ue(g,s,o)*p%o,y=ue(b,e,o)*f%o;return{pow_p_5_8:ue(y,uu,o)*t%o,b2:a}}function Xo(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var fu=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function gd(t,e){let r=is,n=ne(e*e*e,r),s=ne(n*n*e,r),o=hu(t*s).pow_p_5_8,i=ne(t*n*o,r),a=ne(e*i*i,r),c=i,u=ne(i*fu,r),f=a===t,l=a===ne(-t,r),d=a===ne(-t*fu,r);return f&&(i=c),(l||d)&&(i=u),Zc(i,r)&&(i=ne(-i,r)),{isValid:f||l,value:i}}var Jr=su(yd,{uvRatio:gd}),lu=Jr.Fp;function bd(t){let{y:e}=t;return lu.toBytes(lu.div(Zo+e,Zo-e))}function wd(t){let e=Jr.Fp.BYTES;return Oe(t,e),Xo(Fo(t.subarray(0,e))).subarray(0,e)}function xd(t){return ou(Jr,Fo,Object.assign({adjustScalarBytes:Xo,toMontgomery:bd,toMontgomerySecret:wd,zip215:!0},t))}var du=xd({});var en=(()=>{let t=is,e=r=>{let{pow_p_5_8:n,b2:s}=hu(r);return ne(ue(n,dd,t)*s,t)};return au({P:t,type:"x25519",powPminus2:e,adjustScalarBytes:Xo,scalarMultBase:r=>{let n=ne(r,Jr.Fn.ORDER);if(n===cu)return cu;let s=Jr.BASE.multiply(n);return ne((s.Z+s.Y)*e(ne(s.Z-s.Y,t)),t)}})})();var tn=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},as=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var ze={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new as("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return e}};var cs=32;var Qo,Ed=(async()=>{try{return await ze.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Sd(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await ze.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await ze.get().subtle.verify({name:"Ed25519"},n,Ae(e),Ae(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function vd(t,e,r){return du.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function pu(t,e,r){return Qo==null&&(Qo=await Ed),Qo?Sd(t,e,r):vd(t,e,r)}function us(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var fs=class{type="Ed25519";raw;constructor(e){this.raw=Jo(e,cs)}toMultihash(){return je.digest(xt(this))}toCID(){return we.createV1(114,this.toMultihash())}toString(){return me.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:xe(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let s=pu(this.raw,r,e);return us(s)?s.then(o=>(n?.signal?.throwIfAborted(),o)):s}};function ei(t){return t=Jo(t,cs),new fs(t)}function Jo(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new se(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}var Bd=Math.pow(2,7),_d=Math.pow(2,14),Ld=Math.pow(2,21),ti=Math.pow(2,28),ri=Math.pow(2,35),ni=Math.pow(2,42),si=Math.pow(2,49),re=128,Te=127;function Ce(t){if(t<Bd)return 1;if(t<_d)return 2;if(t<Ld)return 3;if(t<ti)return 4;if(t<ri)return 5;if(t<ni)return 6;if(t<si)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Er(t,e,r=0){switch(Ce(t)){case 8:e[r++]=t&255|re,t/=128;case 7:e[r++]=t&255|re,t/=128;case 6:e[r++]=t&255|re,t/=128;case 5:e[r++]=t&255|re,t/=128;case 4:e[r++]=t&255|re,t>>>=7;case 3:e[r++]=t&255|re,t>>>=7;case 2:e[r++]=t&255|re,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Td(t,e,r=0){switch(Ce(t)){case 8:e.set(r++,t&255|re),t/=128;case 7:e.set(r++,t&255|re),t/=128;case 6:e.set(r++,t&255|re),t/=128;case 5:e.set(r++,t&255|re),t/=128;case 4:e.set(r++,t&255|re),t>>>=7;case 3:e.set(r++,t&255|re),t>>>=7;case 2:e.set(r++,t&255|re),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function oi(t,e){let r=t[e],n=0;if(n+=r&Te,r<re||(r=t[e+1],n+=(r&Te)<<7,r<re)||(r=t[e+2],n+=(r&Te)<<14,r<re)||(r=t[e+3],n+=(r&Te)<<21,r<re)||(r=t[e+4],n+=(r&Te)*ti,r<re)||(r=t[e+5],n+=(r&Te)*ri,r<re)||(r=t[e+6],n+=(r&Te)*ni,r<re)||(r=t[e+7],n+=(r&Te)*si,r<re))return n;throw new RangeError("Could not decode varint")}function Cd(t,e){let r=t.get(e),n=0;if(n+=r&Te,r<re||(r=t.get(e+1),n+=(r&Te)<<7,r<re)||(r=t.get(e+2),n+=(r&Te)<<14,r<re)||(r=t.get(e+3),n+=(r&Te)<<21,r<re)||(r=t.get(e+4),n+=(r&Te)*ti,r<re)||(r=t.get(e+5),n+=(r&Te)*ri,r<re)||(r=t.get(e+6),n+=(r&Te)*ni,r<re)||(r=t.get(e+7),n+=(r&Te)*si,r<re))return n;throw new RangeError("Could not decode varint")}function yu(t,e,r=0){return e==null&&(e=Se(Ce(t))),e instanceof Uint8Array?Er(t,e,r):Td(t,e,r)}function zt(t,e=0){return t instanceof Uint8Array?oi(t,e):Cd(t,e)}var ai=new Float32Array([-0]),It=new Uint8Array(ai.buffer);function gu(t,e,r){ai[0]=t,e[r]=It[0],e[r+1]=It[1],e[r+2]=It[2],e[r+3]=It[3]}function bu(t,e){return It[0]=t[e],It[1]=t[e+1],It[2]=t[e+2],It[3]=t[e+3],ai[0]}var ci=new Float64Array([-0]),Ie=new Uint8Array(ci.buffer);function wu(t,e,r){ci[0]=t,e[r]=Ie[0],e[r+1]=Ie[1],e[r+2]=Ie[2],e[r+3]=Ie[3],e[r+4]=Ie[4],e[r+5]=Ie[5],e[r+6]=Ie[6],e[r+7]=Ie[7]}function xu(t,e){return Ie[0]=t[e],Ie[1]=t[e+1],Ie[2]=t[e+2],Ie[3]=t[e+3],Ie[4]=t[e+4],Ie[5]=t[e+5],Ie[6]=t[e+6],Ie[7]=t[e+7],ci[0]}var Id=BigInt(Number.MAX_SAFE_INTEGER),Dd=BigInt(Number.MIN_SAFE_INTEGER),ke=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return $t;if(e<Id&&e>Dd)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,s=e-(n<<32n);return r&&(n=~n|0n,s=~s|0n,++s>Eu&&(s=0n,++n>Eu&&(n=0n))),new t(Number(s),Number(n))}static fromNumber(e){if(e===0)return $t;let r=e<0;r&&(e=-e);let n=e>>>0,s=(e-n)/4294967296>>>0;return r&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new t(n,s)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):$t}},$t=new ke(0,0);$t.toBigInt=function(){return 0n};$t.zzEncode=$t.zzDecode=function(){return this};$t.length=function(){return 1};var Eu=4294967296n;function Su(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function vu(t,e,r){if(r-e<1)return"";let s,o=[],i=0,a;for(;e<r;)a=t[e++],a<128?o[i++]=a:a>191&&a<224?o[i++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,o[i++]=55296+(a>>10),o[i++]=56320+(a&1023)):o[i++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,i>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,o)),i=0);return s!=null?(i>0&&s.push(String.fromCharCode.apply(String,o.slice(0,i))),s.join("")):String.fromCharCode.apply(String,o.slice(0,i))}function ui(t,e,r){let n=r,s,o;for(let i=0;i<t.length;++i)s=t.charCodeAt(i),s<128?e[r++]=s:s<2048?(e[r++]=s>>6|192,e[r++]=s&63|128):(s&64512)===55296&&((o=t.charCodeAt(i+1))&64512)===56320?(s=65536+((s&1023)<<10)+(o&1023),++i,e[r++]=s>>18|240,e[r++]=s>>12&63|128,e[r++]=s>>6&63|128,e[r++]=s&63|128):(e[r++]=s>>12|224,e[r++]=s>>6&63|128,e[r++]=s&63|128);return r-n}function Ge(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function ls(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var fi=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=Ae(e),this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Ge(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ge(this,4);return ls(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ge(this,4);return ls(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ge(this,4);let e=bu(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ge(this,4);let e=xu(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw Ge(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return vu(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ge(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ge(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new ke(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Ge(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw Ge(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ge(this,8);let e=ls(this.buf,this.pos+=4),r=ls(this.buf,this.pos+=4);return new ke(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=oi(this.buf,this.pos);return this.pos+=Ce(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function rn(t){return new fi(t instanceof Uint8Array?t:t.subarray())}function Vt(t,e,r){let n=rn(t);return e.decode(n,void 0,r)}function li(t){let e=t??8192,r=e>>>1,n,s=e;return function(i){if(i<1||i>r)return Se(i);s+i>e&&(n=Se(e),s=0);let a=n.subarray(s,s+=i);return(s&7)!==0&&(s=(s|7)+1),a}}var jt=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function hi(){}var pi=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Rd=li();function Od(t){return globalThis.Buffer!=null?Se(t):Rd(t)}var sn=class{len;head;tail;states;constructor(){this.len=0,this.head=new jt(hi,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new jt(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new mi((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(hs,10,ke.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=ke.fromBigInt(e);return this._push(hs,r.length(),r)}uint64Number(e){return this._push(Er,Ce(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=ke.fromBigInt(e).zzEncode();return this._push(hs,r.length(),r)}sint64Number(e){let r=ke.fromNumber(e).zzEncode();return this._push(hs,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(di,1,e?1:0)}fixed32(e){return this._push(nn,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=ke.fromBigInt(e);return this._push(nn,4,r.lo)._push(nn,4,r.hi)}fixed64Number(e){let r=ke.fromNumber(e);return this._push(nn,4,r.lo)._push(nn,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(gu,4,e)}double(e){return this._push(wu,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(di,1,0):this.uint32(r)._push(Ud,r,e)}string(e){let r=Su(e);return r!==0?this.uint32(r)._push(ui,r,e):this._push(di,1,0)}fork(){return this.states=new pi(this),this.head=this.tail=new jt(hi,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new jt(hi,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=Od(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function di(t,e,r){e[r]=t&255}function Pd(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var mi=class extends jt{next;constructor(e,r){super(Pd,e,r),this.next=void 0}};function hs(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function nn(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function Ud(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(sn.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(Nd,e,t),this},sn.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(kd,e,t),this});function Nd(t,e,r){e.set(t,r)}function kd(t,e,r){t.length<40?ui(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(ee(t),r)}function yi(){return new sn}function Wt(t,e){let r=yi();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*Yt(t,e,r){let n=rn(t);yield*e.stream(n,void 0,".",r)}var ds={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function ps(t,e,r,n,s){return{name:t,type:e,encode:r,decode:n,stream:s}}function gi(t){function e(o){if(t[o.toString()]==null)throw new Error("Invalid enum value");return t[o]}let r=function(i,a){let c=e(i);a.int32(c)},n=function(i){let a=i.int32();return e(a)},s=function*(i,a){};return ps("enum",ds.VARINT,r,n,s)}function Gt(t,e,r){return ps("message",ds.LENGTH_DELIMITED,t,e,r)}var Zt=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var de;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(de||(de={}));var bi;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(bi||(bi={}));(function(t){t.codec=()=>gi(bi)})(de||(de={}));var rt;(function(t){let e;t.codec=()=>(e==null&&(e=Gt((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.Type!=null&&(i.uint32(8),de.codec().encode(o.Type,i)),o.Data!=null&&(i.uint32(18),i.bytes(o.Data)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.Type=de.codec().decode(o);break}case 2:{c.Data=o.bytes();break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:de.codec().decode(o)};break}case 2:{yield{field:`${a}.Data`,value:o.bytes()};break}default:{o.skipType(f&7);break}}}})),e);function r(o){return Wt(o,t.codec())}t.encode=r;function n(o,i){return Vt(o,t.codec(),i)}t.decode=n;function s(o,i){return Yt(o,t.codec(),i)}t.stream=s})(rt||(rt={}));var wi;(function(t){let e;t.codec=()=>(e==null&&(e=Gt((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.Type!=null&&(i.uint32(8),de.codec().encode(o.Type,i)),o.Data!=null&&(i.uint32(18),i.bytes(o.Data)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.Type=de.codec().decode(o);break}case 2:{c.Data=o.bytes();break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:de.codec().decode(o)};break}case 2:{yield{field:`${a}.Data`,value:o.bytes()};break}default:{o.skipType(f&7);break}}}})),e);function r(o){return Wt(o,t.codec())}t.encode=r;function n(o,i){return Vt(o,t.codec(),i)}t.decode=n;function s(o,i){return Yt(o,t.codec(),i)}t.stream=s})(wi||(wi={}));var an={};Re(an,{MAX_RSA_KEY_SIZE:()=>xi,generateRSAKeyPair:()=>Cu,jwkToJWKKeyPair:()=>Iu,jwkToPkcs1:()=>Hd,jwkToPkix:()=>Ai,jwkToRSAPrivateKey:()=>Ti,pkcs1MessageToJwk:()=>Si,pkcs1MessageToRSAPrivateKey:()=>Bi,pkcs1ToJwk:()=>Fd,pkcs1ToRSAPrivateKey:()=>Tu,pkixMessageToJwk:()=>vi,pkixMessageToRSAPublicKey:()=>Li,pkixToJwk:()=>qd,pkixToRSAPublicKey:()=>_i});var Sr=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=an.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return we.createV1(114,this._multihash)}toString(){return me.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:xe(this.raw,e.raw)}verify(e,r,n){return Lu(this.jwk,r,e,n)}},on=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=an.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:xe(this.raw,e.raw)}sign(e,r){return _u(this.jwk,e,r)}};var xi=8192,Ei=18,Md=1062,Kd=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Fd(t){let e=it(t);return Si(e)}function Si(t){return{n:W(t[1],"base64url"),e:W(t[2],"base64url"),d:W(t[3],"base64url"),p:W(t[4],"base64url"),q:W(t[5],"base64url"),dp:W(t[6],"base64url"),dq:W(t[7],"base64url"),qi:W(t[8],"base64url"),kty:"RSA"}}function Hd(t){if(t.n==null||t.e==null||t.d==null||t.p==null||t.q==null||t.dp==null||t.dq==null||t.qi==null)throw new se("JWK was missing components");return wt([Ue(Uint8Array.from([0])),Ue(ee(t.n,"base64url")),Ue(ee(t.e,"base64url")),Ue(ee(t.d,"base64url")),Ue(ee(t.p,"base64url")),Ue(ee(t.q,"base64url")),Ue(ee(t.dp,"base64url")),Ue(ee(t.dq,"base64url")),Ue(ee(t.qi,"base64url"))]).subarray()}function qd(t){let e=it(t,{offset:0});return vi(e)}function vi(t){let e=it(t[1],{offset:0});return{kty:"RSA",n:W(e[0],"base64url"),e:W(e[1],"base64url")}}function Ai(t){if(t.n==null||t.e==null)throw new se("JWK was missing components");return wt([Kd,Mn(wt([Ue(ee(t.n,"base64url")),Ue(ee(t.e,"base64url"))]))]).subarray()}function Tu(t){let e=it(t);return Bi(e)}function Bi(t){let e=Si(t);return Ti(e)}function _i(t,e){if(t.byteLength>=Md)throw new ir("Key size is too large");let r=it(t,{offset:0});return Li(r,t,e)}function Li(t,e,r){let n=vi(t);if(r==null){let s=Qe(rt.encode({Type:de.RSA,Data:e}));r=Ve(Ei,s)}return new Sr(n,r)}function Ti(t){if(Ru(t)>xi)throw new se("Key size is too large");let e=Iu(t),r=Qe(rt.encode({Type:de.RSA,Data:Ai(e.publicKey)})),n=Ve(Ei,r);return new on(e.privateKey,new Sr(e.publicKey,n))}async function Cu(t){if(t>xi)throw new se("Key size is too large");let e=await Du(t),r=Qe(rt.encode({Type:de.RSA,Data:Ai(e.publicKey)})),n=Ve(Ei,r);return new on(e.privateKey,new Sr(e.publicKey,n))}function Iu(t){if(t==null)throw new se("Missing key parameter");return{privateKey:t,publicKey:{kty:t.kty,n:t.n,e:t.e}}}async function Du(t,e){let r=await ze.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:t,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);e?.signal?.throwIfAborted();let n=await zd(r,e);return{privateKey:n[0],publicKey:n[1]}}async function _u(t,e,r){let n=await ze.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let s=await ze.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,Ae(e instanceof Uint8Array?e:e.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(s,0,s.byteLength)}async function Lu(t,e,r,n){let s=await ze.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let o=await ze.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},s,Ae(e),Ae(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),o}async function zd(t,e){if(t.privateKey==null||t.publicKey==null)throw new se("Private and public key are required");let r=await Promise.all([ze.get().subtle.exportKey("jwk",t.privateKey),ze.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function Ru(t){if(t.kty!=="RSA")throw new se("invalid key type");if(t.n==null)throw new se("invalid key modulus");return ee(t.n,"base64url").length*8}var ms=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(Ft(e),Oe(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,s=new Uint8Array(n);s.set(r.length>n?e.create().update(r).digest():r);for(let o=0;o<s.length;o++)s[o]^=54;this.iHash.update(s),this.oHash=e.create();for(let o=0;o<s.length;o++)s[o]^=106;this.oHash.update(s),Fe(s)}update(e){return pr(this),this.iHash.update(e),this}digestInto(e){pr(this),Hn(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:s,destroyed:o,blockLen:i,outputLen:a,canXOF:c}=this;return e=e,e.finished=s,e.destroyed=o,e.blockLen=i,e.outputLen=a,e.canXOF=c,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},cn=(()=>{let t=((e,r,n)=>new ms(e,r).update(n).digest());return t.create=(e,r)=>new ms(e,r),t})();var $d=BigInt(0),Ci=class extends Error{constructor(e=""){super(e)}},ut={Err:Ci,_tlv:{encode:(t,e)=>{let{Err:r}=ut;if(ct(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(kc(e,"data"),e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,s=Yr(n);if(s.length/2&128)throw new r("tlv.encode: long form length too big");let o=n>127?Yr(s.length/2|128):"";return Yr(t)+o+s+e},decode(t,e){let{Err:r}=ut;e=Z(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.decode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let s=e[n++],o=!!(s&128),i=0;if(!o)i=s;else{let c=s&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+i)}}},_int:{encode(t){let{Err:e}=ut;if(Wn(t),t<$d)throw new e("integer: negative integers are not allowed");let r=Yr(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=ut;if(t.length<1)throw new e("invalid signature integer: empty");if(t[0]&128)throw new e("invalid signature integer: negative");if(t.length>1&&t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return Je(t)}},toSig(t,e){let{Err:r,_int:n,_tlv:s}=ut;if(e!==void 0&&(ct(e,"maxScalarBytes"),e<1))throw new r("invalid signature: maxScalarBytes must be positive");let o=Z(t,void 0,"signature"),{v:i,l:a}=s.decode(48,o);if(a.length)throw new r("invalid signature: left bytes after parsing");let{v:c,l:u}=s.decode(2,i),{v:f,l}=s.decode(2,u);if(l.length)throw new r("invalid signature: left bytes after parsing");if(e!==void 0&&(c.length>e||f.length>e))throw new r("invalid signature: integer too large");return{r:n.decode(c),s:n.decode(f)}},hexFromSig(t){let{_tlv:e,_int:r}=ut;Le(t,{r:"bigint",s:"bigint"},{},"sig");let n=e.encode(2,r.encode(t.r)),s=e.encode(2,r.encode(t.s)),o=n+s;return e.encode(48,o)}},ys=(Object.freeze(ut._tlv),Object.freeze(ut._int),Object.freeze(ut));var Ou=(t,e)=>(t+(t>=0?e:-e)/Pu)/e;function Vd(t,e,r){tt("scalar",t,ft,r);let[[n,s],[o,i]]=e,a=Ou(i*t,r),c=Ou(-s*t,r),u=t-a*n-c*o,f=-a*s-c*i,l=u<ft,d=f<ft;l&&(u=-u),d&&(f=-f);let p=Zr(Math.ceil(yr(r)/2))+Xt;if(u<ft||u>=p||f<ft||f>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:d,k2:f}}function Ri(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Ii(t,e){Le(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Ne(r.lowS,"lowS"),Ne(r.prehash,"prehash"),r.format!==void 0&&Ri(r.format),r}var ft=BigInt(0),Xt=BigInt(1),Pu=BigInt(2),Di=BigInt(3),jd=BigInt(4);function Uu(t,e={}){let r=ts("weierstrass",t,e),n=r.Fp,s=r.Fn,o=r.CURVE,{h:i,n:a}=o;Le(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:u,clearCofactor:f,isTorsionFree:l,fromBytes:d,toBytes:p}=e,g=e.randomBytes===void 0?at:e.randomBytes;if(c&&(!n.is0(o.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let b=c?{beta:c.beta,basises:c.basises.map(S=>[...S])}:void 0,y=ku(n,s);function x(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function E(S,h,m){if(h.is0()){if(!u)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x:v,y:R}=h.toAffine(),N=n.toBytes(v);if(Ne(m,"isCompressed"),m){x();let k=!n.isOdd(R);return He(Nu(k),N)}else return He(Uint8Array.of(4),N,n.toBytes(R))}function w(S){Z(S,void 0,"Point");let{publicKey:h,publicKeyUncompressed:m}=y,v=S.length,R=S[0],N=S.subarray(1);if(u&&v===1&&R===0)return{x:n.ZERO,y:n.ZERO};if(v===h&&(R===2||R===3)){let k=n.fromBytes(N);if(!n.isValid(k))throw new Error("bad point: is not on curve, wrong x");let q=U(k),z;try{z=n.sqrt(q)}catch(ce){let ie=ce instanceof Error?": "+ce.message:"";throw new Error("bad point: is not on curve, sqrt error"+ie)}x();let j=n.isOdd(z);return(R&1)===1!==j&&(z=n.neg(z)),{x:k,y:z}}else if(v===m&&R===4){let k=n.BYTES,q=n.fromBytes(N.subarray(0,k)),z=n.fromBytes(N.subarray(k,k*2));if(!C(q,z))throw new Error("bad point: is not on curve");return{x:q,y:z}}else throw new Error(`bad point: got length ${v}, expected compressed=${h} or uncompressed=${m}`)}let I=p===void 0?E:p,T=d===void 0?w:d,O=n.mul(o.b,Di),M=n.is0(o.a)?S=>n.ZERO:S=>n.mul(o.a,S);function U(S){let h=n.sqr(S),m=n.mul(h,S);return n.add(n.add(m,n.mul(S,o.a)),o.b)}function C(S,h){let m=n.sqr(h),v=U(S);return n.eql(m,v)}if(!C(o.Gx,o.Gy))throw new Error("bad curve params: generator point");let D=n.mul(n.pow(o.a,Di),jd),F=n.mul(n.sqr(o.b),BigInt(27));if(n.is0(n.add(D,F)))throw new Error("bad curve params: a or b");function K(S,h,m=!1){if(!n.isValid(h)||m&&n.is0(h))throw new Error(`bad point coordinate ${S}`);return typeof h=="object"&&h!==null?n.create(h):h}function $(S){if(!(S instanceof A))throw new Error("Weierstrass Point expected")}function B(S){if(!b||!b.basises)throw new Error("no endo");return Vd(S,b.basises,s.ORDER)}function P(S,h,m,v){if(!s.isValid(v))throw new RangeError("invalid scalar: out of range");if(b){let{k1neg:R,k1:N,k2neg:k,k2:q}=B(v),z=new A(n.mul(m.X,b.beta),m.Y,m.Z);S.push(R?m.negate():m,k?z.negate():z),h.push(N,q)}else S.push(m),h.push(v)}let _=new WeakSet;class A{static BASE=new A(o.Gx,o.Gy,n.ONE);static ZERO=new A(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=s;X;Y;Z;constructor(h,m,v){this.X=K("x",h),this.Y=K("y",m,!0),this.Z=K("z",v),Object.freeze(this)}static CURVE(){return o}static fromAffine(h){let{x:m,y:v}=h||{};if(!h||!n.isValid(m)||!n.isValid(v))throw new Error("invalid affine point");if(h instanceof A)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(v)?A.ZERO:new A(m,v,n.ONE)}static fromBytes(h){let m=A.fromAffine(T(Z(h,void 0,"point")));return m.assertValidity(),m}static fromHex(h){return A.fromBytes(mr(h))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(h=6,m=!0){return L.setWindowSize(this,h),m||this.multiply(Di),this}assertValidity(){let h=this;if(h.is0()){if(u&&n.is0(h.X)&&n.eql(h.Y,n.ONE)&&n.is0(h.Z))return;throw new Error("bad point: ZERO")}if(_.has(h))return;let{x:m,y:v}=h.toAffine();if(!n.isValid(m)||!n.isValid(v))throw new Error("bad point: x or y not field elements");if(!C(m,v))throw new Error("bad point: equation left != right");if(!h.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");_.add(h)}hasEvenY(){let{y:h}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(h)}equals(h){$(h);let{X:m,Y:v,Z:R}=this,{X:N,Y:k,Z:q}=h,z=n.eql(n.mul(m,q),n.mul(N,R)),j=n.eql(n.mul(v,q),n.mul(k,R));return z&&j}negate(){return new A(this.X,n.neg(this.Y),this.Z)}double(){let{X:h,Y:m,Z:v}=this,R=n.ZERO,N=n.ZERO,k=n.ZERO,q=n.mul(h,h),z=n.mul(m,m),j=n.mul(v,v),Y=n.mul(h,m);return Y=n.add(Y,Y),k=n.mul(h,v),k=n.add(k,k),R=M(k),N=n.mul(O,j),N=n.add(R,N),R=n.sub(z,N),N=n.add(z,N),N=n.mul(R,N),R=n.mul(Y,R),k=n.mul(O,k),j=M(j),Y=n.sub(q,j),Y=M(Y),Y=n.add(Y,k),k=n.add(q,q),q=n.add(k,q),q=n.add(q,j),q=n.mul(q,Y),N=n.add(N,q),j=n.mul(m,v),j=n.add(j,j),q=n.mul(j,Y),R=n.sub(R,q),k=n.mul(j,z),k=n.add(k,k),k=n.add(k,k),new A(R,N,k)}add(h){$(h);let{X:m,Y:v,Z:R}=this,{X:N,Y:k,Z:q}=h,z=n.ZERO,j=n.ZERO,Y=n.ZERO,ce=n.mul(m,N),ie=n.mul(v,k),ye=n.mul(R,q),Pe=n.add(m,v),ae=n.add(N,k);Pe=n.mul(Pe,ae),ae=n.add(ce,ie),Pe=n.sub(Pe,ae),ae=n.add(m,R);let he=n.add(N,q);return ae=n.mul(ae,he),he=n.add(ce,ye),ae=n.sub(ae,he),he=n.add(v,R),z=n.add(k,q),he=n.mul(he,z),z=n.add(ie,ye),he=n.sub(he,z),Y=M(ae),z=n.mul(O,ye),Y=n.add(z,Y),z=n.sub(ie,Y),Y=n.add(ie,Y),j=n.mul(z,Y),ie=n.add(ce,ce),ie=n.add(ie,ce),ye=M(ye),ae=n.mul(O,ae),ie=n.add(ie,ye),ye=n.sub(ce,ye),ye=M(ye),ae=n.add(ae,ye),ce=n.mul(ie,ae),j=n.add(j,ce),ce=n.mul(he,ae),z=n.mul(Pe,z),z=n.sub(z,ce),ce=n.mul(Pe,ie),Y=n.mul(he,Y),Y=n.add(Y,ce),new A(z,j,Y)}subtract(h){return $(h),this.add(h.negate())}is0(){return this.equals(A.ZERO)}multiply(h){if(!s.isValidNot0(h))throw new RangeError("invalid scalar: out of range");let{p:m,f:v}=L.mulSecret(this,h,i,H);return H([m,v])[0]}multiplyUnsafe(h){let m=this,v=h;if(!s.isValid(v))throw new RangeError("invalid scalar: out of range");if(v===ft||m.is0())return A.ZERO;if(v===Xt)return m;if(L.hasWindowSize(this))return L.mulUnsafe(m,v,H);let R=[],N=[];return P(R,N,m,v),es(A,R,N)}mulAddUnsafe(h,m,v){$(m);let R=[],N=[];return P(R,N,this,h),P(R,N,m,v),es(A,R,N)}toAffine(h){let m=this,v=h;if(v!=null&&!n.isValid(v))throw new RangeError('"invertedZ" expected valid field element');let{X:R,Y:N,Z:k}=m;if(n.eql(k,n.ONE))return{x:R,y:N};let q=m.is0();v==null&&(v=q?n.ONE:n.inv(k));let z=n.mul(R,v),j=n.mul(N,v),Y=n.mul(k,v);if(q)return{x:n.ZERO,y:n.ZERO};if(!n.eql(Y,n.ONE))throw new Error("invZ was invalid");return{x:z,y:j}}isTorsionFree(){return i===Xt?!0:l?l(A,this):L.mulUnsafe(this,a).is0()}clearCofactor(){return i===Xt?this:f?f(A,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===Xt?this.is0():this.clearCofactor().is0()}toBytes(h=!0){return Ne(h,"isCompressed"),this.assertValidity(),I(A,this,h)}toHex(h=!0){return Wr(this.toBytes(h))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let H=S=>Jn(A,S),L=new wr(A,g);return L.bits>=6&&A.BASE.precompute(6),Object.freeze(A.prototype),Object.freeze(A),A}function Nu(t){return Uint8Array.of(t?2:3)}function ku(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function Wd(t,e={}){Ct(t);let{Fn:r}=t,n=e.randomBytes===void 0?at:e.randomBytes,s=Object.assign(ku(t.Fp,r),{seed:Math.max(Xn(r.ORDER),16)});function o(p){try{let g=r.fromBytes(p);return r.isValidNot0(g)}catch{return!1}}function i(p,g){let{publicKey:b,publicKeyUncompressed:y}=s;try{let x=p.length;return g===!0&&x!==b||g===!1&&x!==y?!1:!t.fromBytes(p).is0()}catch{return!1}}function a(p){return p=p===void 0?n(s.seed):p,Qn(Z(p,s.seed,"seed"),r.ORDER)}function c(p,g=!0){return t.BASE.multiply(r.fromBytes(p)).toBytes(g)}function u(p){let{secretKey:g,publicKey:b,publicKeyUncompressed:y}=s,x=r._lengths;if(!_t(p))return;let E=Z(p,void 0,"key").length,w=E===b||E===y,I=E===g||!!x?.includes(E);if(!(w&&I))return w}function f(p,g,b=!0){if(u(p)===!0)throw new Error("first arg must be private key");if(u(g)===!1)throw new Error("second arg must be public key");let y=r.fromBytes(p),x=t.fromBytes(g);if(x.is0())throw new Error("invalid public key: point at infinity");return x.multiply(y).toBytes(b)}let l={isValidSecretKey:o,isValidPublicKey:i,randomSecretKey:a},d=xr(a,c);return Object.freeze(l),Object.freeze(s),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:d,Point:t,utils:l,lengths:s})}function Mu(t,e,r={}){Ct(t);let n=e;Ft(n),Le(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let s=Object.assign({},r),o=s.randomBytes===void 0?at:s.randomBytes,i=s.hmac===void 0?(S,h)=>cn(n,S,h):s.hmac,{Fp:a,Fn:c}=t,{ORDER:u,BITS:f}=c,l=Xn(u),d=Go(o,l),{keygen:p,getPublicKey:g,getSharedSecret:b,utils:y,lengths:x}=Wd(t,s),E={prehash:!0,lowS:typeof s.lowS=="boolean"?s.lowS:!0,format:"compact",extraEntropy:!1},w=u*Pu+Xt<a.ORDER;function I(S){let h=u>>Xt;return S>h}function T(S,h){if(!c.isValidNot0(h))throw new Error(`invalid signature ${S}: out of range 1..Point.Fn.ORDER`);return h}function O(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function M(S,h,m){return O(),(S===m?0:2)|Number(a.isOdd(h))}function U(){if(w)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function C(S,h){Ri(h);let m=x.signature,v=h==="compact"?m:h==="recovered"?m+1:void 0;return Z(S,v)}class D{r;s;recovery;constructor(h,m,v){if(this.r=T("r",h),this.s=T("s",m),v!=null){if(U(),![0,1,2,3].includes(v))throw new Error("invalid recovery id");this.recovery=v}Object.freeze(this)}static fromBytes(h,m=E.format){C(h,m);let v;if(m==="der"){if(h.length>2*c.BYTES+16)throw new ys.Err("invalid signature: DER signature too long");let{r:q,s:z}=ys.toSig(Z(h),c.BYTES+1);return new D(q,z)}m==="recovered"&&(v=h[0],m="compact",h=h.subarray(1));let R=x.signature/2,N=h.subarray(0,R),k=h.subarray(R,R*2);return new D(c.fromBytes(N),c.fromBytes(k),v)}static fromHex(h,m){return this.fromBytes(mr(h),m)}assertRecovery(){let{recovery:h}=this;if(h==null)throw new Error("invalid recovery id: must be present");return h}addRecoveryBit(h){return new D(this.r,this.s,h)}recoverPublicKey(h){let{r:m,s:v}=this,R=this.assertRecovery(),N=R===2||R===3?m+u:m;if(!a.isValid(N))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let k=a.toBytes(N),q=t.fromBytes(He(Nu((R&1)===0),k)),z=c.inv(N),j=K(Z(h,void 0,"msgHash")),Y=c.create(-j*z),ce=c.create(v*z),ie=t.BASE.mulAddUnsafe(Y,q,ce);if(ie.is0())throw new Error("invalid recovery: point at infinify");return ie.assertValidity(),ie}hasHighS(){return I(this.s)}toBytes(h=E.format){if(Ri(h),h==="der")return mr(ys.hexFromSig(this));let{r:m,s:v}=this,R=c.toBytes(m),N=c.toBytes(v);return h==="recovered"?(U(),He(Uint8Array.of(this.assertRecovery()),R,N)):He(R,N)}toHex(h){return Wr(this.toBytes(h))}}Object.freeze(D.prototype),Object.freeze(D);let F=s.bits2int===void 0?function(h){if(h.length>8192)throw new Error("input is too large");let m=Je(h),v=h.length*8-f;return v>0?m>>BigInt(v):m}:s.bits2int,K=s.bits2int_modN===void 0?function(h){return c.create(F(h))}:s.bits2int_modN,$=Zr(f);function B(S){return tt("num < 2^"+f,S,ft,$),c.toBytes(S)}function P(S,h){return Z(S,void 0,"message"),h?Z(n(S),void 0,"prehashed message"):S}function _(S,h,m){let{lowS:v,prehash:R,extraEntropy:N}=Ii(m,E);S=P(S,R);let k=K(S),q=c.fromBytes(h);if(!c.isValidNot0(q))throw new Error("invalid private key");let z=[B(q),B(k)];if(N!=null&&N!==!1){let ie=N===!0?o(x.secretKey):N;z.push(Z(ie,void 0,"extraEntropy"))}let j=He(...z),Y=k;function ce(ie){let ye=F(ie);if(!c.isValidNot0(ye))return;let Pe=t.BASE.multiply(ye).toAffine(),ae=c.create(Pe.x);if(ae===ft)return;let he;if(d!==void 0){let mt=Je(Qn(d(l),u)),Qf=c.inv(c.mul(mt,ye)),Jf=c.mul(mt,Y),el=c.mul(mt,q);he=c.create(Qf*c.create(Jf+el*ae))}else{let mt=Wc(ye,u);he=c.create(mt*c.create(Y+ae*q))}if(he===ft)return;let sr=M(Pe.x,Pe.y,ae),Nr=he;return v&&I(he)&&(Nr=c.neg(he),sr^=1),new D(ae,Nr,w?void 0:sr)}return{seed:j,k2sig:ce}}function A(S,h,m={}){let{seed:v,k2sig:R}=_(S,h,m);return Kc(n.outputLen,c.BYTES,i)(v,R).toBytes(m.format)}function H(S,h,m,v={}){let{lowS:R,prehash:N,format:k}=Ii(v,E);if(m=Z(m,void 0,"publicKey"),h=P(h,N),!_t(S)){let q=S instanceof D?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+q)}C(S,k);try{let q=D.fromBytes(S,k),z=t.fromBytes(m);if(z.is0()||R&&q.hasHighS())return!1;let{r:j,s:Y}=q,ce=K(h),ie=c.inv(Y),ye=c.create(ce*ie),Pe=c.create(j*ie),ae=t.BASE.mulAddUnsafe(ye,z,Pe);if(ae.is0())return!1;let he=ae.toAffine();return!(c.create(he.x)!==j||k==="recovered"&&q.recovery!==M(he.x,he.y,j))}catch{return!1}}function L(S,h,m={}){let{prehash:v}=Ii(m,E);return h=P(h,v),D.fromBytes(S,"recovered").recoverPublicKey(h).toBytes()}return Object.freeze({keygen:p,getPublicKey:g,getSharedSecret:b,utils:y,lengths:x,Point:t,sign:A,verify:H,recoverPublicKey:L,Signature:D,hash:n})}var Pi={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Yd={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Ku=BigInt(2);function Gd(t){let e=Pi.p,r=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=t*t*t%e,f=u*u*t%e,l=ue(f,r,e)*f%e,d=ue(l,r,e)*f%e,p=ue(d,Ku,e)*u%e,g=ue(p,s,e)*p%e,b=ue(g,o,e)*g%e,y=ue(b,a,e)*b%e,x=ue(y,c,e)*y%e,E=ue(x,a,e)*b%e,w=ue(E,r,e)*f%e,I=ue(w,i,e)*g%e,T=ue(I,n,e)*u%e,O=ue(T,Ku,e);if(!Oi.eql(Oi.sqr(O),t))throw new Error("Cannot find square root");return O}var Oi=br(Pi.p,{sqrt:Gd}),Zd=Uu(Pi,{Fp:Oi,endo:Yd}),vr=Mu(Zd,Qe);function Fu(t,e,r,n){let s=Hr.digest(r instanceof Uint8Array?r:r.subarray());if(us(s))return s.then(({digest:o})=>(n?.signal?.throwIfAborted(),vr.verify(e,o,t,{prehash:!1,format:"der"}))).catch(o=>{throw o.name==="AbortError"?o:new tn(String(o))});try{return n?.signal?.throwIfAborted(),vr.verify(e,s.digest,t,{prehash:!1,format:"der"})}catch(o){throw new tn(String(o))}}var gs=class{type="secp256k1";raw;_key;constructor(e){this._key=qu(e),this.raw=Hu(this._key)}toMultihash(){return je.digest(xt(this))}toCID(){return we.createV1(114,this.toMultihash())}toString(){return me.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:xe(this.raw,e.raw)}verify(e,r,n){return Fu(this._key,r,e,n)}};function Ui(t){return new gs(t)}function Hu(t){return vr.Point.fromBytes(t).toBytes()}function qu(t){try{return vr.Point.fromBytes(t),t}catch(e){throw new ir(String(e))}}function un(t,e){let{Type:r,Data:n}=rt.decode(t),s=n??new Uint8Array;switch(r){case de.RSA:return _i(s,e);case de.Ed25519:return ei(s);case de.secp256k1:return Ui(s);case de.ECDSA:return Co(s);default:throw new Pt}}function zu(t){let{Type:e,Data:r}=rt.decode(t.digest),n=r??new Uint8Array;switch(e){case de.Ed25519:return ei(n);case de.secp256k1:return Ui(n);case de.ECDSA:return Co(n);default:throw new Pt}}function xt(t){return rt.encode({Type:de[t.type],Data:t.raw})}var $u=Symbol.for("nodejs.util.inspect.custom"),Xd=114,fn=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Xs]=!0;toString(){return this.string==null&&(this.string=me.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return we.createV1(Xd,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return xe(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return xe(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[$u](){return`PeerId(${this.toString()})`}},ln=class extends fn{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},hn=class extends fn{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},dn=class extends fn{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},Qd=2336,pn=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=je.digest(ee(this.url))}[$u](){return`PeerId(${this.url})`}[Xs]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return we.createV1(Qd,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=W(e)),e.toString()===this.toString())}};var Jd=114,Vu=2336;function ju(t,e){let r;if(t.charAt(0)==="1"||t.charAt(0)==="Q")r=hr(me.decode(`z${t}`));else{if(t.startsWith("k51qzi5uqu5")||t.startsWith("kzwfwjn5ji4")||t.startsWith("k2k4r8")||t.startsWith("bafz"))return ep(we.parse(t));if(e==null)throw new se('Please pass a multibase decoder for strings that do not start with "1" or "Q"');r=hr(e.decode(t))}return Wu(r)}function Ni(t){if(t.type==="Ed25519")return new hn({multihash:t.toCID().multihash,publicKey:t});if(t.type==="secp256k1")return new dn({multihash:t.toCID().multihash,publicKey:t});if(t.type==="RSA")return new ln({multihash:t.toCID().multihash,publicKey:t});throw new Pt}function Wu(t){if(rp(t))return new ln({multihash:t});if(tp(t))try{let e=zu(t);if(e.type==="Ed25519")return new hn({multihash:t,publicKey:e});if(e.type==="secp256k1")return new dn({multihash:t,publicKey:e})}catch{let r=W(t.digest);return new pn(new URL(r))}throw new In("Supplied PeerID Multihash is invalid")}function ep(t){if(t?.multihash==null||t.version==null||t.version===1&&t.code!==Jd&&t.code!==Vu)throw new Cn("Supplied PeerID CID is invalid");if(t.code===Vu){let e=W(t.multihash.digest);return new pn(new URL(e))}return Wu(t.multihash)}function tp(t){return t.code===je.code}function rp(t){return t.code===Hr.code}function np(t){let e=t.getComponents(),r={},n=0;return e[n]?.name==="ip6zone"&&(r.zone=`${e[n].value}`,n++),e[n]?.name==="ip4"||e[n]?.name==="ip6"||e[n]?.name==="dns"||e[n]?.name==="dns4"||e[n]?.name==="dns6"?(r.type=e[n].name,r.host=e[n].value,n++):e[n]?.name==="dnsaddr"&&(r.type=e[n].name,r.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(r.protocol=e[n].name==="tcp"?"tcp":"udp",r.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(r.type==="ip4"?r.cidr=parseInt(`${e[n].value}`):r.type==="ip6"&&(r.cidr=`${e[n].value}`),n++),r.type==null||r.host==null?null:(e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(r.sni=e[n+1].value,n+=2),r)}function Yu(t){let e=np(t);if(e==null)throw new se(`Multiaddr ${t} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}var bs=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let r=this.index,n=e();return n===void 0&&(this.index=r),n}parseWith(e){let r=e();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let r=this.readChar();if(r===e)return r})}readSeparator(e,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,r,n,s){return this.readAtomically(()=>{let o=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*s)-1;for(;;){let f=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let d=Number.parseInt(l,e);if(!Number.isNaN(d))return d});if(f===void 0)break;if(o*=e,o+=f,o>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:o})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let r=0;r<e.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[r]=n}return e})}readIPv6Addr(){let e=r=>{for(let n=0;n<r.length/2;n++){let s=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[s]=i[0],r[s+1]=i[1],r[s+2]=i[2],r[s+3]=i[3],[s+4,!0]}let o=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(o===void 0)return[s,!1];r[s]=o>>8,r[s+1]=o&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,s]=e(r);if(n===16)return r;if(s||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let o=new Uint8Array(14),i=16-(n+2),[a]=e(o.subarray(0,i));return r.set(o.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var sp=45,op=15,ws=new bs;function Gu(t){if(!(t.length>op))return ws.new(t).parseWith(()=>ws.readIPv4Addr())}function Zu(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>sp))return ws.new(t).parseWith(()=>ws.readIPv6Addr())}function xs(t){return!!Gu(t)}function Xu(t){return!!Zu(t)}var Be=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},lt=class extends Error{static name="ValidationError";name="ValidationError"},Es=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Ss=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function Mi(t){return e=>W(e,t)}function Ki(t){return e=>ee(e,t)}function Ar(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function Qt(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function Qu(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let r=ee(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let s=Qt(n);return Ke([r,s],r.length+s.length)}function Ju(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let r=bt.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let s=Qt(n);return Ke([r,s],r.length+s.length)}function Fi(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=W(e,"base32"),s=Ar(r);return`${n}:${s}`}var Hi=function(t){t=t.toString().trim();let e=new Uint8Array(4);return t.split(/\./g).forEach((r,n)=>{let s=parseInt(r,10);if(isNaN(s)||s<0||s>255)throw new Be("Invalid byte value in IP address");e[n]=s}),e},ef=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let o=xs(r[n]),i;o&&(i=Hi(r[n]),r[n]=W(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,W(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let o=[n,1];for(n=9-r.length;n>0;n--)o.push("0");r.splice.apply(r,o)}let s=new Uint8Array(e+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let o=parseInt(r[n],16);if(isNaN(o)||o<0||o>65535)throw new Be("Invalid byte value in IP address");s[e++]=o>>8&255,s[e++]=o&255}return s},tf=function(t){if(t.byteLength!==4)throw new Be("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},rf=function(t){if(t.byteLength!==16)throw new Be("IPv6 address was incorrect length");let e=[];for(let n=0;n<t.byteLength;n+=2){let s=t[n],o=t[n+1],i=`${s.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}`;e.push(i)}let r=e.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new Be(`Invalid IPv6 address "${r}"`)}};function nf(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new Be(`Invalid IPv6 address "${t}"`)}}var ki=Object.values(kt).map(t=>t.decoder),ip=(function(){let t=ki[0].or(ki[1]);return ki.slice(2).forEach(e=>t=t.or(e)),t})();function sf(t){return ip.decode(t)}function of(t){return e=>t.encoder.encode(e)}function ap(t){if(parseInt(t).toString()!==t)throw new lt("Value must be an integer")}function cp(t){if(t<0)throw new lt("Value must be a positive integer, or zero")}function up(t){return e=>{if(e>t)throw new lt(`Value must be smaller than or equal to ${t}`)}}function fp(...t){return e=>{for(let r of t)r(e)}}var mn=fp(ap,cp,up(65535));var ve=-1,qi=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let r;if(typeof e=="string"?r=this.protocolsByName.get(e):r=this.protocolsByCode.get(e),r==null)throw new Ss(`Protocol ${e} was unknown`);return r}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(r=>{this.protocolsByName.set(r,e)})}removeProtocol(e){let r=this.protocolsByCode.get(e);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},dt=new qi,Ap=[{code:4,name:"ip4",size:32,valueToBytes:Hi,bytesToValue:tf,validate:t=>{if(!xs(t))throw new lt(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Qt,bytesToValue:Ar,validate:mn},{code:273,name:"udp",size:16,valueToBytes:Qt,bytesToValue:Ar,validate:mn},{code:33,name:"dccp",size:16,valueToBytes:Qt,bytesToValue:Ar,validate:mn},{code:41,name:"ip6",size:128,valueToBytes:ef,bytesToValue:rf,stringToValue:nf,validate:t=>{if(!Xu(t))throw new lt(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:ve},{code:43,name:"ipcidr",size:8,bytesToValue:Mi("base10"),valueToBytes:Ki("base10")},{code:53,name:"dns",size:ve},{code:54,name:"dns4",size:ve},{code:55,name:"dns6",size:ve},{code:56,name:"dnsaddr",size:ve},{code:132,name:"sctp",size:16,valueToBytes:Qt,bytesToValue:Ar,validate:mn},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ve,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:ve,bytesToValue:Mi("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?Ki("base58btc")(t):we.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Fi,valueToBytes:Qu},{code:445,name:"onion3",size:296,bytesToValue:Fi,valueToBytes:Ju},{code:446,name:"garlic64",size:ve},{code:447,name:"garlic32",size:ve},{code:448,name:"tls"},{code:449,name:"sni",size:ve},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:ve,bytesToValue:of(yo),valueToBytes:sf},{code:480,name:"http"},{code:481,name:"http-path",size:ve,stringToValue:t=>`/${decodeURIComponent(t)}`,valueToString:t=>encodeURIComponent(t.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:ve}];Ap.forEach(t=>{dt.addProtocol(t)});function af(t){let e=[],r=0;for(;r<t.length;){let n=zt(t,r),s=dt.getProtocol(n),o=Ce(n),i=Bp(s,t,r+o),a=0;i>0&&s.size===ve&&(a=Ce(i));let c=o+a+i,u={code:n,name:s.name,bytes:Ae(t.subarray(r,r+c))};if(i>0){let f=r+o+a,l=t.subarray(f,f+i);u.value=s.bytesToValue?.(l)??W(l)}e.push(u),r+=c}return e}function cf(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let s=dt.getProtocol(n.code),o=Ce(n.code),i,a=0,c=0;n.value!=null&&(i=s.valueToBytes?.(n.value)??ee(n.value),a=i.byteLength,s.size===ve&&(c=Ce(a)));let u=new Uint8Array(o+c+a),f=0;Er(n.code,u,f),f+=o,i!=null&&(s.size===ve&&(Er(a,u,f),f+=c),u.set(i,f)),n.bytes=u}r.push(n.bytes),e+=n.bytes.byteLength}return Ke(r,e)}function uf(t){if(t.charAt(0)!=="/")throw new Be('String multiaddr must start with "/"');let e=[],r="protocol",n="",s="";for(let o=1;o<t.length;o++){let i=t.charAt(o);i!=="/"&&(r==="protocol"?s+=t.charAt(o):n+=t.charAt(o));let a=o===t.length-1;if(i==="/"||a){let c=dt.getProtocol(s);if(r==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",s="",r="protocol";continue}else if(a)throw new Be(`Component ${s} was missing value`);r="value"}else if(r==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new Be(`Component ${s} was missing value`);u.value=c.stringToValue?.(n)??n}e.push(u),n="",s="",r="protocol"}}}if(s!==""&&n!=="")throw new Be("Incomplete multiaddr");return e}function ff(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=dt.getProtocol(e.code);if(r==null)throw new Be(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function Bp(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:zt(e,r)}var _p=Symbol.for("nodejs.util.inspect.custom"),ia=Symbol.for("@multiformats/multiaddr");function Lp(t){if(t==null&&(t="/"),lf(t))return t.getComponents();if(t instanceof Uint8Array)return af(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),uf(t);if(Array.isArray(t))return t;throw new Be("Must be a string, Uint8Array, Component[], or another Multiaddr")}var oa=class t{[ia]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=Lp(e),r.validate!==!1&&Tp(this)}get bytes(){return this.#r==null&&(this.#r=cf(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=ff(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let r=new t(e);return new t([...this.#e,...r.getComponents()],{validate:!1})}decapsulate(e){let r=e.toString(),n=this.toString(),s=n.lastIndexOf(r);if(s<0)throw new Es(`Address ${this.toString()} does not contain subaddress: ${r}`);return new t(n.slice(0,s),{validate:!1})}decapsulateCode(e){let r;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){r=n;break}return new t(this.#e.slice(0,r),{validate:!1})}equals(e){return xe(this.bytes,e.bytes)}[_p](){return`Multiaddr(${this.toString()})`}};function Tp(t){t.getComponents().forEach(e=>{let r=dt.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function lf(t){return!!t?.[ia]}var fe=t=>({match:e=>{let r=e[0];return r==null||r.code!==t||r.value!=null?!1:e.slice(1)}}),V=(t,e)=>({match:r=>{let n=r[0];return n?.code!==t||n.value==null||e!=null&&n.value!==e?!1:r.slice(1)}}),hf=t=>({match:e=>t.match(e)===!1?e:!1}),G=t=>({match:e=>{let r=t.match(e);return r===!1?e:r}}),De=(...t)=>({match:e=>{let r;for(let n of t){let s=n.match(e);s!==!1&&(r==null||s.length<r.length)&&(r=s)}return r??!1}}),J=(...t)=>({match:e=>{for(let r of t){let n=r.match(e);if(n===!1)return!1;e=n}return e}});function le(...t){function e(s){if(s==null)return!1;let o=s.getComponents();for(let i of t){let a=i.match(o);if(a===!1)return!1;o=a}return o}function r(s){return e(s)!==!1}function n(s){let o=e(s);return o===!1?!1:o.length===0}return{matchers:t,matches:r,exactMatch:n}}var Cp=V(421),e1=le(Cp),Cs=V(54),Is=V(55),Ds=V(56),ca=V(53),t1=le(Cs,G(V(421))),r1=le(Is,G(V(421))),n1=le(Ds,G(V(421))),s1=le(De(ca,Ds,Cs,Is),G(V(421))),df=J(V(4),G(V(43))),pf=J(G(V(42)),V(41),G(V(43))),ua=De(df,pf),Tr=De(ua,ca,Cs,Is,Ds),o1=le(De(ua,J(De(ca,Ds,Cs,Is),G(V(421))))),i1=le(df),a1=le(pf),c1=le(ua),fa=J(Tr,V(6)),yn=J(Tr,V(273)),u1=le(J(fa,G(V(421)))),f1=le(yn),la=J(yn,fe(460),G(V(421))),Rs=J(yn,fe(461),G(V(421))),Ip=De(la,Rs),l1=le(la),h1=le(Rs),aa=De(Tr,fa,yn,la,Rs),mf=De(J(aa,fe(477),G(V(421)))),d1=le(mf),yf=De(J(aa,fe(478),G(V(421))),J(aa,fe(448),G(V(449)),fe(477),G(V(421)))),p1=le(yf),gf=J(yn,fe(280),G(V(466)),G(V(466)),G(V(421))),m1=le(gf),bf=J(Rs,fe(465),G(V(466)),G(V(466)),G(V(421))),Os=le(bf),Ts=De(mf,yf,J(fa,G(V(421))),J(Ip,G(V(421))),J(Tr,G(V(421))),gf,bf,V(421)),y1=le(Ts),Dp=J(G(Ts),fe(290),hf(fe(281)),G(V(421))),g1=le(Dp),Rp=De(J(Ts,fe(290),fe(281),G(V(421))),J(Ts,fe(281),G(V(421))),J(fe(281),G(V(421)))),b1=le(Rp),Op=J(Tr,De(J(V(6,"80")),J(V(6),fe(480)),fe(480)),G(V(481)),G(V(421))),w1=le(Op),Pp=J(Tr,De(J(V(6,"443")),J(V(6,"443"),fe(480)),J(V(6),fe(443)),J(V(6),fe(448),fe(480)),J(fe(448),fe(480)),fe(448),fe(443)),G(V(481)),G(V(421))),x1=le(Pp),Up=De(J(V(777),G(V(421)))),E1=le(Up),Np=De(J(V(400),G(V(421)))),S1=le(Np);function Ps(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Us=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},Cr=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Us(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let r=this.head;this.head=r.next=new Us(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var ha=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Ns(t={}){return kp(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},t)}function kp(t,e){e=e??{};let r=e.onEnd,n=new Cr,s,o,i,a=Ps(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((y,x)=>{o=E=>{o=null,n.push(E);try{y(t(n))}catch(w){x(w)}return s}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Ps()})}},u=y=>o!=null?o(y):(n.push(y),s),f=y=>(n=new Cr,o!=null?o({error:y}):(n.push({error:y}),s)),l=y=>{if(i)return s;if(e?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:y})},d=y=>i?s:(i=!0,y!=null?f(y):u({done:!0})),p=()=>(n=new Cr,d(),{done:!0}),g=y=>(d(y),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:p,throw:g,push:l,end:d,get readableLength(){return n.size},onEmpty:async y=>{let x=y?.signal;if(x?.throwIfAborted(),n.isEmpty())return;let E,w;x!=null&&(E=new Promise((I,T)=>{w=()=>{T(new ha)},x.addEventListener("abort",w)}));try{await Promise.race([a.promise,E])}finally{w!=null&&x!=null&&x?.removeEventListener("abort",w)}}},r==null)return s;let b=s;return s={[Symbol.asyncIterator](){return this},next(){return b.next()},throw(y){return b.throw(y),r!=null&&(r(y),r=void 0),{done:!0}},return(){return b.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(y){return b.end(y),r!=null&&(r(y),r=void 0),s},get readableLength(){return b.readableLength},onEmpty:y=>b.onEmpty(y)},s}var da=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},wf=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function pa(t,e){let{milliseconds:r,fallback:n,message:s,customTimers:o={setTimeout,clearTimeout},signal:i}=e,a,c,f=new Promise((l,d)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){d(wf(i)),t.then(l,d);return}if(i&&(c=()=>{d(wf(i))},i.addEventListener("abort",c,{once:!0})),t.then(l,d),r===Number.POSITIVE_INFINITY)return;let p=new da;a=o.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(g){d(g)}return}typeof t.cancel=="function"&&t.cancel(),s===!1?l():s instanceof Error?d(s):(p.message=s??`Promise timed out after ${r} milliseconds`,d(p))},r)}).finally(()=>{f.clear(),c&&i&&i.removeEventListener("abort",c)});return f.clear=()=>{o.clearTimeout.call(void 0,a),a=void 0},f}var Mp=t=>{let e=t.addEventListener||t.on||t.addListener,r=t.removeEventListener||t.off||t.removeListener;if(!e||!r)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(t),removeListener:r.bind(t)}};function Kp(t,e,r){let n,s=new Promise((o,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:u,removeListener:f}=Mp(t),l=async(...p)=>{let g=r.multiArgs?p:p[0];if(r.filter)try{if(!await r.filter(g))return}catch(b){n(),i(b);return}c.push(g),r.count===c.length&&(n(),o(c))},d=(...p)=>{n(),i(r.rejectionMultiArgs?p:p[0])};n=()=>{for(let p of a)f(p,l);for(let p of r.rejectionEvents)a.includes(p)||f(p,d)};for(let p of a)u(p,l);for(let p of r.rejectionEvents)a.includes(p)||u(p,d);r.signal&&r.signal.addEventListener("abort",()=>{d(r.signal.reason)},{once:!0}),r.resolveImmediately&&o(c)});if(s.cancel=n,typeof r.timeout=="number"){let o=pa(s,{milliseconds:r.timeout});return o.cancel=()=>{n(),o.clear()},o}return s}function Dt(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Kp(t,e,r),s=n.then(o=>o[0]);return s.cancel=n.cancel,s}var er=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"},ks=class extends Error{static name="MaxEarlyStreamsError";name="MaxEarlyStreamsError"},Ms=class extends Error{static name="StreamClosedError";name="StreamClosedError"};function Fp(t){return t.reason}function $e(t,e,r){if(e==null||t==null)return t;let n=r?.translateError??Fp;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let s;return Promise.race([t,new Promise((o,i)=>{s=()=>{i(n(e))},e.addEventListener("abort",s)})]).finally(()=>{s!=null&&e.removeEventListener("abort",s)})}var Hp=Math.pow(2,20)*4,nt=class extends cr{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;#e=!1;onDrainPromise;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??Hp,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new Q,this.writeBuffer=new Q,this.readStatus="readable",this.remoteReadStatus="readable",this.writeStatus="writable",this.remoteWriteStatus="writable",this.sendingData=!1,this.writableNeedsDrain=!1,this.timeline={open:Date.now()},this.processSendQueue=this.processSendQueue.bind(this);let r=()=>{this.writableNeedsDrain&&(this.log.trace("drain event received, continue sending data"),this.writableNeedsDrain=!1,queueMicrotask(()=>{try{this.processSendQueue()}catch(s){this.log.error("processSendQueue threw - %e",s)}})),this.onDrainPromise?.resolve()};this.addEventListener("drain",r);let n=s=>{this.onDrainPromise?.reject(s.error??new Ms)};this.addEventListener("close",n)}get readBufferLength(){return this.readBuffer.byteLength}get readableEnded(){return this.#e}get writeBufferLength(){return this.writeBuffer.byteLength}async onDrain(e){return this.writableNeedsDrain!==!0?Promise.resolve():(this.onDrainPromise==null&&(this.onDrainPromise=Promise.withResolvers()),$e(this.onDrainPromise.promise,e?.signal))}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=Ns(),r=o=>{e.push(o.data)};this.addEventListener("message",r);let n=o=>{e.end(o.error)};this.addEventListener("close",n);let s=()=>{e.end()};this.addEventListener("remoteCloseWrite",s);try{yield*e}finally{this.removeEventListener("message",r),this.removeEventListener("close",n),this.removeEventListener("remoteCloseWrite",s)}}isReadable(){return this.status==="open"}send(e){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new yt(`Cannot write to a stream that is ${this.writeStatus}`);return this.log.trace("append %d bytes to write buffer",e.byteLength),this.writeBuffer.append(e),this.processSendQueue()}abort(e){if(!(this.status==="aborted"||this.status==="reset"||this.status==="closed")){this.log.error("abort with error - %e",e),this.status="aborted",this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle")),this.writeStatus="closed",this.remoteWriteStatus="closed",this.readStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.maybeDispatchEnd();try{this.sendReset(e)}catch(r){this.log.error("failed to send reset to remote - %e",r)}this.dispatchEvent(new Rn(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new yt("Cannot pause a stream that is closing/closed");this.readStatus!=="paused"&&(this.readStatus="paused",this.sendPause())}resume(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new yt("Cannot resume a stream that is closing/closed");this.readStatus!=="readable"&&(this.readStatus="readable",this.dispatchReadBuffer(),this.sendResume())}push(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new yt(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.append(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}unshift(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new yt(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.prepend(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}onData(e){if(e.byteLength!==0){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("ignoring data - read status %s",this.readStatus);return}this.readBuffer.append(e),this.dispatchReadBuffer()}}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="message"&&this.readBuffer.byteLength>0&&queueMicrotask(()=>{this.dispatchReadBuffer()})}onRemoteReset(){this.log("remote reset"),this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed",this.maybeDispatchEnd()),this.dispatchEvent(new On(new Ln))}onTransportClosed(e){this.log("transport closed"),this.readStatus==="readable"&&this.readBuffer.byteLength===0&&(this.log("close readable end after transport closed and read buffer is empty"),this.readStatus="closed"),this.remoteReadStatus!=="closed"&&(this.remoteReadStatus="closed"),this.remoteWriteStatus!=="closed"&&(this.remoteWriteStatus="closed"),this.writeStatus!=="closed"&&(this.writeStatus="closed"),e!=null?this.abort(e):(this.status==="open"||this.status==="closing")&&(this.timeline.close=Date.now(),this.status="closed",this.maybeDispatchEnd(),this.dispatchEvent(new ar))}onRemoteCloseWrite(){this.remoteWriteStatus!=="closed"&&(this.log.trace("on remote close write"),this.remoteWriteStatus="closed",this.safeDispatchEvent("remoteCloseWrite"),this.maybeDispatchEnd(),this.writeStatus==="closed"&&this.onTransportClosed())}onRemoteCloseRead(){this.log.trace("on remote close read"),this.remoteReadStatus="closed",this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle"))}processSendQueue(){if(this.writableNeedsDrain)return this.log.trace("not processing send queue as drain is required"),this.checkWriteBufferLength(),!1;if(this.writeBuffer.byteLength===0)return this.log.trace("not processing send queue as no bytes to send"),!0;if(this.sendingData)return this.log.trace("not processing send queue as already sending data"),!0;if(this.writeStatus!=="writable"&&this.writeStatus!=="closing")return this.log.trace("not processing send queue as stream is %s",this.writeStatus),!1;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let e=!0,r=this.writeBuffer.byteLength,n=0;for(;this.writeBuffer.byteLength>0;){let s=Math.min(this.maxMessageSize??this.writeBuffer.byteLength,this.writeBuffer.byteLength);if(s===0){e=!1;break}let o=this.writeBuffer.sublist(0,s),i=new Q(o);this.writeBuffer.consume(o.byteLength);let a;try{a=this.sendData(o)}catch(c){throw this.writeBuffer.prepend(i),this.abort(c),c}if(e=a.canSendMore,n+=a.sentBytes,a.sentBytes!==i.byteLength&&(i.consume(a.sentBytes),this.writeBuffer.prepend(i)),!e)break}return e||(this.log.trace("sent %d/%d bytes, pausing sending because underlying stream is full, %d bytes left in the write buffer",n,r,this.writeBuffer.byteLength),this.writableNeedsDrain=!0,this.checkWriteBufferLength()),this.writeBuffer.byteLength===0&&this.safeDispatchEvent("idle"),e}finally{this.sendingData=!1}}maybeDispatchEnd(){this.#e||this.readBuffer.byteLength>0||this.remoteWriteStatus!=="closed"&&this.readStatus!=="closed"||(this.#e=!0,this.safeDispatchEvent("end"))}dispatchReadBuffer(){try{if(this.listenerCount("message")===0){this.log.trace("not dispatching pause buffer as there are no listeners for the message event");return}if(this.readBuffer.byteLength===0){this.log.trace("not dispatching pause buffer as there is no data to dispatch");return}if(this.readStatus==="paused"){this.log.trace("not dispatching pause buffer we are paused");return}if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("dropping %d bytes because the readable end is %s",this.readBuffer.byteLength,this.readStatus),this.readBuffer.consume(this.readBuffer.byteLength);return}let e=this.readBuffer.sublist();this.readBuffer.consume(e.byteLength),this.dispatchEvent(new Dn(e))}finally{this.readBuffer.byteLength===0&&this.remoteWriteStatus==="closed"&&(this.log("close readable end after dispatching read buffer and remote writable end is closed"),this.readStatus="closed",this.maybeDispatchEnd()),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new Ot(`Read buffer length of ${this.readBuffer.byteLength} exceeded limit of ${this.maxReadBufferLength}, read status is ${this.readStatus}`))}checkWriteBufferLength(){this.maxWriteBufferLength!=null&&this.writeBuffer.byteLength>this.maxWriteBufferLength&&this.abort(new Ot(`Write buffer length of ${this.writeBuffer.byteLength} exceeded limit of ${this.maxWriteBufferLength}, write status is ${this.writeStatus}`))}onMuxerNeedsDrain(){this.writableNeedsDrain=!0}onMuxerDrain(){this.safeDispatchEvent("drain")}};var Ks=class extends nt{remoteAddr;metricPrefix;metrics;constructor(e){super(e),this.metricPrefix=e.metricPrefix??"",this.metrics=e.metrics,this.remoteAddr=e.remoteAddr,this.addEventListener("close",r=>{this.metrics?.increment({[`${this.metricPrefix}end`]:!0}),r.error!=null?r.local?this.metrics?.increment({[`${this.metricPrefix}abort`]:!0}):this.metrics?.increment({[`${this.metricPrefix}reset`]:!0}):r.local?this.metrics?.increment({[`${this.metricPrefix}_local_close`]:!0}):this.metrics?.increment({[`${this.metricPrefix}_remote_close`]:!0})})}async close(e){this.status==="open"&&(this.status="closing",this.writeStatus="closing",this.remoteWriteStatus="closing",this.remoteReadStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await Dt(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await Dt(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};function xf(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Fs=class extends cr{streams;protocol;status;log;maConn;streamOptions;earlyStreams;maxEarlyStreams;metrics;constructor(e,r){super(),this.maConn=e,this.protocol=r.protocol,this.streams=[],this.earlyStreams=[],this.status="open",this.log=e.log.newScope(r.name),this.streamOptions=r.streamOptions,this.maxEarlyStreams=r.maxEarlyStreams??10,this.metrics=r.metrics;let n=i=>{try{this.onData(i.data)}catch(a){this.abort(a),this.maConn.abort(a)}};this.maConn.addEventListener("message",n);let s=()=>{this.log("underlying stream drained, signal %d streams to continue writing",this.streams.length),this.streams.forEach(i=>{i.onMuxerDrain()})};this.maConn.addEventListener("drain",s);let o=()=>{this.log("underlying stream closed with status %s and %d streams",this.status,this.streams.length),this.onTransportClosed()};this.maConn.addEventListener("close",o)}send(e){let r=this.maConn.send(e);return r===!1&&(this.log("underlying stream saturated, signal %d streams to pause writing",this.streams.length),this.streams.forEach(n=>{n.onMuxerNeedsDrain()})),r}async close(e){this.status==="closed"||this.status==="closing"||(this.status="closing",await $e(Promise.all([...this.streams].map(async r=>{await r.close(e)})),e?.signal),this.status="closed")}abort(e){this.status!=="closed"&&(this.status="closing",[...this.streams].forEach(r=>{r.abort(e)}),this.status="closed")}onTransportClosed(e){this.status="closing";try{[...this.streams].forEach(r=>{r.onTransportClosed(e)})}catch(r){this.abort(r)}this.status="closed"}async createStream(e){if(this.status!=="open")throw new _n;let r=this.onCreateStream({...this.streamOptions,...e});return xf(r)&&(r=await r),this.streams.push(r),this.cleanUpStream(r),r}onRemoteStream(e){if(this.streams.push(e),this.cleanUpStream(e),this.listenerCount("stream")===0){this.earlyStreams.push(e),this.earlyStreams.length>this.maxEarlyStreams&&this.abort(new ks(`Too many early streams were opened - ${this.earlyStreams.length}/${this.maxEarlyStreams}`));return}this.safeDispatchEvent("stream",{detail:e})}cleanUpStream(e){let r=n=>{let s=this.streams.findIndex(o=>o===e);s!==-1&&this.streams.splice(s,1),n.error!=null?n.local?this.metrics?.increment({[`${e.direction}_stream_reset`]:!0}):this.metrics?.increment({[`${e.direction}_stream_abort`]:!0}):this.metrics?.increment({[`${e.direction}_stream_end`]:!0})};e.addEventListener("close",r),this.metrics?.increment({[`${e.direction}_stream`]:!0})}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="stream"&&this.earlyStreams.length>0&&queueMicrotask(()=>{this.earlyStreams.forEach(r=>{this.safeDispatchEvent("stream",{detail:r})}),this.earlyStreams=[]})}};var Hs=class extends nt{id;protocol;constructor(e){super(e),this.id=e.id,this.protocol=e.protocol??""}async close(e){this.writeStatus==="closing"||this.writeStatus==="closed"||(this.writeStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await Dt(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes, sending %s",this.writeBuffer.byteLength,this.sendingData),await Dt(this,"drain",{...e,rejectionEvents:["close"]}),this.log("write queue drained, closing writable end of stream, %d unsent bytes, sending %s",this.writeBuffer.byteLength,this.sendingData)),await this.sendCloseWrite(e),this.writeStatus="closed",this.log("closed writable end gracefully"),this.remoteWriteStatus==="closed"&&this.onTransportClosed())}async closeRead(e){this.readStatus==="closing"||this.readStatus==="closed"||(this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.readStatus="closing",await this.sendCloseRead(e),this.readStatus="closed",this.maybeDispatchEnd(),this.log("closed readable end gracefully"))}};var qp=4194304,qs=class extends Error{static name="UnwrappedError";name="UnwrappedError"},gn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ya=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},ga=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function zp(t){return typeof t?.closeRead=="function"}function $p(t){return typeof t?.close=="function"}function ma(t){return zp(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:$p(t)?t.status!=="open":!1}function Vp(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function jp(t,e){let r=e?.maxBufferSize??qp,n=new Q,s,o=!1,i;if(!Vp(t))throw new se("Argument should be a Stream or a Multiaddr");let a=l=>{if(i==null){if(n.append(l.data),n.byteLength>r){let d=n.byteLength;n.consume(d);let p=new Ot(`Read buffer overflow - ${d} > ${r}`);i=p,s?.reject(p),queueMicrotask(()=>{t.abort(p)});return}s?.resolve()}};t.addEventListener("message",a);let c=l=>{l.error!=null?s?.reject(l.error):s?.resolve()};t.addEventListener("close",c);let u=()=>{s?.resolve()};t.addEventListener("remoteCloseWrite",u);let f={readBuffer:n,async read(l){if(o===!0)throw new qs("Stream was unwrapped");if(i!=null)throw i;if(ma(t)){if(n.byteLength===0&&l?.bytes==null)return null;if(l?.bytes!=null&&n.byteLength<l.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,l.bytes),new er(`Unexpected EOF - stream closed after reading ${n.byteLength}/${l.bytes} bytes`)}let d=l?.bytes??1;for(s=Promise.withResolvers();;){if(n.byteLength>=d){s.resolve();break}if(await $e(s.promise,l?.signal),ma(t)){if(n.byteLength===0&&l?.bytes==null)return null;break}s=Promise.withResolvers()}let p=l?.bytes??n.byteLength;if(n.byteLength<p){if(ma(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,p),new er(`Unexpected EOF - stream closed while reading ${n.byteLength}/${p} bytes`);return f.read(l)}let g=n.sublist(0,p);return n.consume(p),g},async write(l,d){if(o===!0)throw new qs("Stream was unwrapped");t.send(l)||await Dt(t,"drain",{signal:d?.signal,rejectionEvents:["close"]})},unwrap(){return o||(o=!0,t.removeEventListener("message",a),t.removeEventListener("close",c),t.removeEventListener("remoteCloseWrite",u),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.unshift(n))),t}};return f}function ba(t,e={}){let r=jp(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Ce(e.maxDataLength));let n=e?.lengthDecoder??zt,s=e?.lengthEncoder??yu;return{async read(i){let a=-1,c=new Q;for(;;){let f=await r.read({...i,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new gn("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new ga(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new ya(`Message length too long - ${a} > ${e.maxDataLength}`);let u=await r.read({...i,bytes:a});if(u==null)throw t.log.error("tried to read %d bytes but the stream closed",a),new er(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw t.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new er(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await r.write(new Q(s(i.byteLength),i),a)},async writeV(i,a){let c=new Q(...i.flatMap(u=>[s(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}var Wp=1024*1024*4,Yp=1024*1024*4,zs=class{buffer;maxBufferSize;lengthDecoder;maxDataLength;encodingLength;constructor(e={}){this.buffer=new Q,this.maxBufferSize=e.maxBufferSize??Wp,this.maxDataLength=e.maxDataLength??Yp,this.lengthDecoder=e.lengthDecoder??zt,this.encodingLength=e.encodingLength??Ce}*decode(e){if(this.buffer.append(e),this.buffer.byteLength>this.maxBufferSize)throw new se(`Buffer length limit exceeded - ${this.buffer.byteLength}/${this.maxBufferSize}`);for(;;){let r;try{r=this.lengthDecoder(this.buffer)}catch(o){if(o instanceof RangeError)break;throw o}if(r<0||r>this.maxDataLength)throw new gn("Invalid message length");let n=this.encodingLength(r),s=n+r;if(this.buffer.byteLength>=s){let o=this.buffer.sublist(n,s);this.buffer.consume(s),o.byteLength>0&&(yield o)}else break}}};var Ir=!!globalThis.process?.env?.DUMP_SESSION_KEYS,wa=16;function xa(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var $s=t=>t?`"${t}" `:"";function Vs(t,e=""){if(typeof t!="boolean")throw new TypeError($s(e)+"expected boolean, got type="+typeof t);return t}function tr(t,e=""){if(typeof t!="number")throw new TypeError($s(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError($s(e)+"expected integer >= 0, got "+t);return t}function ge(t,e,r=""){if(xa(t)&&(e===void 0||t.length===e))return t;e!==void 0&&tr(e,"length");let n=xa(t),s=e!==void 0?` of length ${e}`:"",o=n?`length=${t.length}`:`type=${typeof t}`,i=$s(r)+"expected Uint8Array"+s+", got "+o;throw n?new RangeError(i):new TypeError(i)}var Ef=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof t}`)};function Ea(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function Sf(t,e){ge(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function st(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function Ze(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Gp(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}var Rt=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Zp(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function Xp(t){for(let e=0;e<t.length;e++)t[e]=Zp(t[e]);return t}var pt=Rt?t=>t:Xp;function Qp(t,e){return!t.byteLength||!e.byteLength?!1:t.buffer===e.buffer&&t.byteOffset<e.byteOffset+e.byteLength&&e.byteOffset<t.byteOffset+t.byteLength}function vf(t,e){if(Qp(t,e)&&t.byteOffset<e.byteOffset)throw new Error("complex overlap of input and output is not supported")}function Af(t,e){return Ef(t,"defaults"),Ef(e,"opts"),Object.assign(t,e)}function Bf(t,e){if(t=ge(t),e=ge(e),t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function _f(t,e,r){let n=e,s=r||(()=>[]),o=(a,c)=>n(c,...s(a)).update(a).digest(),i=n(new Uint8Array(t),...s(new Uint8Array(0)));return o.outputLen=i.outputLen,o.blockLen=i.blockLen,o.create=(a,...c)=>n(a,...c),o}var Lf=(t,e)=>{function r(n,...s){if(ge(n,void 0,"key"),t.nonceLength!==void 0){let l=s[0];ge(l,t.varSizeNonce?void 0:t.nonceLength,"nonce")}let o=t.tagLength,i=t.nonceLength!==void 0?1:0;if(!t.withAAD){for(let l=i;l<s.length;l++)if(xa(s[l]))throw new Error("AAD not supported")}t.withAAD&&s[i]!==void 0&&ge(s[i],void 0,"AAD");let a=e(n,...s),c=(l,d)=>{if(d!==void 0){if(l!==2)throw new Error("cipher output not supported");ge(d,void 0,"output")}},u=!1;return{encrypt(l,d){if(u)throw new Error("cannot encrypt() twice with same key + nonce");return u=!0,ge(l,void 0,"data"),c(a.encrypt.length,d),a.encrypt(l,d)},decrypt(l,d){if(ge(l,void 0,"data"),o&&l.length<o)throw new Error('"ciphertext" expected length >= tagLength='+o);return c(a.decrypt.length,d),a.decrypt(l,d)}}}return Object.assign(r,t),r};function bn(t,e,r=!0){if(e===void 0)return new Uint8Array(t);if(ge(e,t,"output"),r&&!wn(e))throw new Error("invalid output, must be aligned");return e}function Tf(t,e,r){tr(t),tr(e),Vs(r);let n=new Uint8Array(16),s=Gp(n);return s.setBigUint64(0,BigInt(e),r),s.setBigUint64(8,BigInt(t),r),n}function wn(t){return t.byteOffset%4===0}function Dr(t){return Uint8Array.from(ge(t))}var If=t=>Uint8Array.from(t.split(""),e=>e.charCodeAt(0)),Jp=pt(st(If("expand 16-byte k"))),em=pt(st(If("expand 32-byte k")));function X(t,e){return t<<e|t>>>32-e}var xn=64,tm=16,Sa=2**32-1,Cf=Uint32Array.of();function rm(t,e,r,n,s,o,i,a){let c=s.length,u=new Uint8Array(xn),f=st(u),l=Rt&&wn(s)&&wn(o),d=l?st(s):Cf,p=l?st(o):Cf;if(!Rt){for(let g=0;g<c;i++){if(t(e,r,n,f,i,a),pt(f),i>=Sa)throw new Error("arx: counter overflow");let b=Math.min(xn,c-g);for(let y=0,x;y<b;y++)x=g+y,o[x]=s[x]^u[y];g+=b}return}for(let g=0;g<c;i++){if(t(e,r,n,f,i,a),i>=Sa)throw new Error("arx: counter overflow");let b=Math.min(xn,c-g);if(l&&b===xn){let y=g/4;if(g%4!==0)throw new Error("arx: invalid block position");for(let x=0,E;x<tm;x++)E=y+x,p[E]=d[E]^f[x];g+=xn;continue}for(let y=0,x;y<b;y++)x=g+y,o[x]=s[x]^u[y];g+=b}}function Df(t,e){let{allowShortKeys:r,extendNonceFn:n,counterLength:s,counterRight:o,rounds:i}=Af({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof t!="function")throw new Error("core must be a function");return tr(s),tr(i),Vs(o),Vs(r),(a,c,u,f,l=0)=>{ge(a,void 0,"key"),ge(c,void 0,"nonce"),ge(u,void 0,"data");let d=u.length,p=f!==void 0;if(f=bn(d,f,!1),p&&vf(u,f),tr(l),l<0||l>=Sa)throw new Error("arx: counter overflow");let g=[],b=a.length,y,x;if(b===32)g.push(y=Dr(a)),x=em;else if(b===16&&r)y=new Uint8Array(32),y.set(a),y.set(a,16),x=Jp,g.push(y);else throw ge(a,32,"arx key"),new Error("invalid key size");(!Rt||!wn(c))&&g.push(c=Dr(c));let E=st(y);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");let T=c.subarray(0,16);if(Rt)n(x,E,st(T),E);else{let O=pt(Uint32Array.from(x));n(O,E,st(T),E),Ze(O),pt(E)}c=c.subarray(16)}else Rt||pt(E);let w=16-s;if(w!==c.length)throw new Error(`arx: nonce must be ${w} or 16 bytes`);if(w!==12){let T=new Uint8Array(12);T.set(c,o?0:12-c.length),c=T,g.push(c)}let I=pt(st(c));try{return rm(t,x,E,I,u,f,l,i),f}finally{Ze(...g)}}}function _e(t,e){return t[e++]&255|(t[e++]&255)<<8}var va=class{blockLen=16;outputLen=16;buffer=new Uint8Array(16);r=new Uint16Array(10);h=new Uint16Array(10);pad=new Uint16Array(8);pos=0;finished=!1;destroyed=!1;constructor(e){e=Dr(ge(e,32,"key"));let r=_e(e,0),n=_e(e,2),s=_e(e,4),o=_e(e,6),i=_e(e,8),a=_e(e,10),c=_e(e,12),u=_e(e,14);this.r[0]=r&8191,this.r[1]=(r>>>13|n<<3)&8191,this.r[2]=(n>>>10|s<<6)&7939,this.r[3]=(s>>>7|o<<9)&8191,this.r[4]=(o>>>4|i<<12)&255,this.r[5]=i>>>1&8190,this.r[6]=(i>>>14|a<<2)&8191,this.r[7]=(a>>>11|c<<5)&8065,this.r[8]=(c>>>8|u<<8)&8191,this.r[9]=u>>>5&127;for(let f=0;f<8;f++)this.pad[f]=_e(e,16+2*f)}process(e,r,n=!1){let s=n?0:2048,{h:o,r:i}=this,a=i[0],c=i[1],u=i[2],f=i[3],l=i[4],d=i[5],p=i[6],g=i[7],b=i[8],y=i[9],x=_e(e,r+0),E=_e(e,r+2),w=_e(e,r+4),I=_e(e,r+6),T=_e(e,r+8),O=_e(e,r+10),M=_e(e,r+12),U=_e(e,r+14),C=o[0]+(x&8191),D=o[1]+((x>>>13|E<<3)&8191),F=o[2]+((E>>>10|w<<6)&8191),K=o[3]+((w>>>7|I<<9)&8191),$=o[4]+((I>>>4|T<<12)&8191),B=o[5]+(T>>>1&8191),P=o[6]+((T>>>14|O<<2)&8191),_=o[7]+((O>>>11|M<<5)&8191),A=o[8]+((M>>>8|U<<8)&8191),H=o[9]+(U>>>5|s),L=0,S=L+C*a+D*(5*y)+F*(5*b)+K*(5*g)+$*(5*p);L=S>>>13,S&=8191,S+=B*(5*d)+P*(5*l)+_*(5*f)+A*(5*u)+H*(5*c),L+=S>>>13,S&=8191;let h=L+C*c+D*a+F*(5*y)+K*(5*b)+$*(5*g);L=h>>>13,h&=8191,h+=B*(5*p)+P*(5*d)+_*(5*l)+A*(5*f)+H*(5*u),L+=h>>>13,h&=8191;let m=L+C*u+D*c+F*a+K*(5*y)+$*(5*b);L=m>>>13,m&=8191,m+=B*(5*g)+P*(5*p)+_*(5*d)+A*(5*l)+H*(5*f),L+=m>>>13,m&=8191;let v=L+C*f+D*u+F*c+K*a+$*(5*y);L=v>>>13,v&=8191,v+=B*(5*b)+P*(5*g)+_*(5*p)+A*(5*d)+H*(5*l),L+=v>>>13,v&=8191;let R=L+C*l+D*f+F*u+K*c+$*a;L=R>>>13,R&=8191,R+=B*(5*y)+P*(5*b)+_*(5*g)+A*(5*p)+H*(5*d),L+=R>>>13,R&=8191;let N=L+C*d+D*l+F*f+K*u+$*c;L=N>>>13,N&=8191,N+=B*a+P*(5*y)+_*(5*b)+A*(5*g)+H*(5*p),L+=N>>>13,N&=8191;let k=L+C*p+D*d+F*l+K*f+$*u;L=k>>>13,k&=8191,k+=B*c+P*a+_*(5*y)+A*(5*b)+H*(5*g),L+=k>>>13,k&=8191;let q=L+C*g+D*p+F*d+K*l+$*f;L=q>>>13,q&=8191,q+=B*u+P*c+_*a+A*(5*y)+H*(5*b),L+=q>>>13,q&=8191;let z=L+C*b+D*g+F*p+K*d+$*l;L=z>>>13,z&=8191,z+=B*f+P*u+_*c+A*a+H*(5*y),L+=z>>>13,z&=8191;let j=L+C*y+D*b+F*g+K*p+$*d;L=j>>>13,j&=8191,j+=B*l+P*f+_*u+A*c+H*a,L+=j>>>13,j&=8191,L=(L<<2)+L|0,L=L+S|0,S=L&8191,L=L>>>13,h+=L,o[0]=S,o[1]=h,o[2]=m,o[3]=v,o[4]=R,o[5]=N,o[6]=k,o[7]=q,o[8]=z,o[9]=j}finalize(){let{h:e,pad:r}=this,n=new Uint16Array(10),s=e[1]>>>13;e[1]&=8191;for(let a=2;a<10;a++)e[a]+=s,s=e[a]>>>13,e[a]&=8191;e[0]+=s*5,s=e[0]>>>13,e[0]&=8191,e[1]+=s,s=e[1]>>>13,e[1]&=8191,e[2]+=s,n[0]=e[0]+5,s=n[0]>>>13,n[0]&=8191;for(let a=1;a<10;a++)n[a]=e[a]+s,s=n[a]>>>13,n[a]&=8191;n[9]-=8192;let o=(s^1)-1;for(let a=0;a<10;a++)n[a]&=o;o=~o;for(let a=0;a<10;a++)e[a]=e[a]&o|n[a];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let i=e[0]+r[0];e[0]=i&65535;for(let a=1;a<8;a++)i=(e[a]+r[a]|0)+(i>>>16)|0,e[a]=i&65535;Ze(n)}update(e){Ea(this),ge(e),e=Dr(e);let{buffer:r,blockLen:n}=this,s=e.length;for(let o=0;o<s;){let i=Math.min(n-this.pos,s-o);if(i===n){for(;n<=s-o;o+=n)this.process(e,o);continue}r.set(e.subarray(o,o+i),this.pos),this.pos+=i,o+=i,this.pos===n&&(this.process(r,0,!1),this.pos=0)}return this}destroy(){this.destroyed=!0,Ze(this.h,this.r,this.buffer,this.pad)}digestInto(e){Ea(this),Sf(e,this),this.finished=!0;let{buffer:r,h:n}=this,{pos:s}=this;if(s){for(r[s++]=1;s<16;s++)r[s]=0;this.process(r,0,!0)}this.finalize();let o=0;for(let i=0;i<8;i++)e[o++]=n[i]>>>0,e[o++]=n[i]>>>8}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}},Rf=_f(32,t=>new va(t));function nm(t,e,r,n,s,o=20){let i=t[0],a=t[1],c=t[2],u=t[3],f=e[0],l=e[1],d=e[2],p=e[3],g=e[4],b=e[5],y=e[6],x=e[7],E=s,w=r[0],I=r[1],T=r[2],O=i,M=a,U=c,C=u,D=f,F=l,K=d,$=p,B=g,P=b,_=y,A=x,H=E,L=w,S=I,h=T;for(let v=0;v<o;v+=2)O=O+D|0,H=X(H^O,16),B=B+H|0,D=X(D^B,12),O=O+D|0,H=X(H^O,8),B=B+H|0,D=X(D^B,7),M=M+F|0,L=X(L^M,16),P=P+L|0,F=X(F^P,12),M=M+F|0,L=X(L^M,8),P=P+L|0,F=X(F^P,7),U=U+K|0,S=X(S^U,16),_=_+S|0,K=X(K^_,12),U=U+K|0,S=X(S^U,8),_=_+S|0,K=X(K^_,7),C=C+$|0,h=X(h^C,16),A=A+h|0,$=X($^A,12),C=C+$|0,h=X(h^C,8),A=A+h|0,$=X($^A,7),O=O+F|0,h=X(h^O,16),_=_+h|0,F=X(F^_,12),O=O+F|0,h=X(h^O,8),_=_+h|0,F=X(F^_,7),M=M+K|0,H=X(H^M,16),A=A+H|0,K=X(K^A,12),M=M+K|0,H=X(H^M,8),A=A+H|0,K=X(K^A,7),U=U+$|0,L=X(L^U,16),B=B+L|0,$=X($^B,12),U=U+$|0,L=X(L^U,8),B=B+L|0,$=X($^B,7),C=C+D|0,S=X(S^C,16),P=P+S|0,D=X(D^P,12),C=C+D|0,S=X(S^C,8),P=P+S|0,D=X(D^P,7);let m=0;n[m++]=i+O|0,n[m++]=a+M|0,n[m++]=c+U|0,n[m++]=u+C|0,n[m++]=f+D|0,n[m++]=l+F|0,n[m++]=d+K|0,n[m++]=p+$|0,n[m++]=g+B|0,n[m++]=b+P|0,n[m++]=y+_|0,n[m++]=x+A|0,n[m++]=E+H|0,n[m++]=w+L|0,n[m++]=I+S|0,n[m++]=T+h|0}var sm=Df(nm,{counterRight:!1,counterLength:4,allowShortKeys:!1});var om=new Uint8Array(16),Of=(t,e)=>{t.update(e);let r=e.length%16;r&&t.update(om.subarray(r))},im=new Uint8Array(32);function Pf(t,e,r,n,s){s!==void 0&&ge(s,void 0,"AAD");let o=t(e,r,im),i=Tf(n.length,s?s.length:0,!0),a=Rf.create(o);s&&Of(a,s),Of(a,n),a.update(i);let c=a.digest();return Ze(o,i),c}var am=t=>(e,r,n)=>({encrypt(o,i){let a=o.length;i=bn(a+16,i,!1),i.set(o);let c=i.subarray(0,-16);t(e,r,c,c,1);let u=Pf(t,e,r,c,n);return i.set(u,a),Ze(u),i},decrypt(o,i){i=bn(o.length-16,i,!1);let a=o.subarray(0,-16),c=o.subarray(-16),u=Pf(t,e,r,a,n);if(!Bf(c,u))throw Ze(u),new Error("invalid tag");return i.set(o.subarray(0,-16)),t(e,r,i,i,1),Ze(u),i}}),Aa=Lf({blockSize:64,nonceLength:12,tagLength:16,withAAD:!0},am(sm));function Uf(t,e,r){return Ft(t),r===void 0&&(r=new Uint8Array(t.outputLen)),cn(t,r,e)}var En=Uint8Array.of(0),cm=Uint8Array.of();function Nf(t,e,r,n=32,s){Ft(t),We(n,"length"),Oe(e,void 0,"prk");let o=t.outputLen;if(e.length<o)throw new Error('"prk" must be at least HashLen octets');if(n>255*o)throw new Error("Length must be <= 255*HashLen");let i=Math.ceil(n/o);if(r===void 0?r=cm:Oe(r,void 0,"info"),!i)return s&&Fe(e),new Uint8Array;let a=s&&i===1?e:new Uint8Array(i*o),{iHash:c,oHash:u}=cn.create(t,e),f=s?e:new Uint8Array(o),l=i>1?s?.iHash||t.create():void 0;for(let p=0;p<i-1;p++){En[0]=p+1;let g=c._cloneInto(l);p&&g.update(f),g.update(r).update(En).digestInto(f),u._cloneInto(l).update(f).digestInto(f),a.set(f,o*p)}if(En[0]=i,i>1&&c.update(f),c.update(r).update(En).digestInto(f),u.update(f).digestInto(f),a.set(f,o*(i-1)),c.destroy(),u.destroy(),l?.destroy(),f!==a&&Fe(f),Fe(En),n===a.length)return a;let d=a.slice(0,n);return Fe(a),d}var kf={hashSHA256(t){return Qe(t.subarray())},getHKDF(t,e){let r=Uf(Qe,e,t),s=Nf(Qe,r,void 0,96),o=s.subarray(0,32),i=s.subarray(32,64),a=s.subarray(64,96);return[o,i,a]},generateX25519KeyPair(){let t=en.utils.randomSecretKey();return{publicKey:en.getPublicKey(t),privateKey:t}},generateX25519KeyPairFromSeed(t){return{publicKey:en.getPublicKey(t),privateKey:t}},generateX25519SharedKey(t,e){return en.getSharedSecret(t.subarray(),e.subarray())},chaCha20Poly1305Encrypt(t,e,r,n){return Aa(n,e,r).encrypt(t.subarray())},chaCha20Poly1305Decrypt(t,e,r,n,s){return Aa(n,e,r).decrypt(t.subarray(),s)}};var Mf=kf;function Kf(t){return{generateKeypair:t.generateX25519KeyPair,dh:(e,r)=>t.generateX25519SharedKey(e.privateKey,r).subarray(0,32),encrypt:t.chaCha20Poly1305Encrypt,decrypt:t.chaCha20Poly1305Decrypt,hash:t.hashSHA256,hkdf:t.getHKDF}}var Rr=t=>{let e=Se(2);return e[0]=t>>8,e[1]=t,e};Rr.bytes=2;var Or=t=>{if(t.length<2)throw RangeError("Could not decode int16BE");if(t instanceof Uint8Array){let e=0;return e+=t[0]<<8,e+=t[1],e}return t.getUint16(0)};Or.bytes=2;function Ff(t){return{xxHandshakeSuccesses:t.registerCounter("libp2p_noise_xxhandshake_successes_total",{help:"Total count of noise xxHandshakes successes_"}),xxHandshakeErrors:t.registerCounter("libp2p_noise_xxhandshake_error_total",{help:"Total count of noise xxHandshakes errors"}),encryptedPackets:t.registerCounter("libp2p_noise_encrypted_packets_total",{help:"Total count of noise encrypted packets successfully"}),decryptedPackets:t.registerCounter("libp2p_noise_decrypted_packets_total",{help:"Total count of noise decrypted packets"}),decryptErrors:t.registerCounter("libp2p_noise_decrypt_errors_total",{help:"Total count of noise decrypt errors"})}}function Ba(t,e){!e.enabled||!Ir||(t?(e(`LOCAL_STATIC_PUBLIC_KEY ${W(t.publicKey,"hex")}`),e(`LOCAL_STATIC_PRIVATE_KEY ${W(t.privateKey,"hex")}`)):e("Missing local static keys."))}function _a(t,e){!e.enabled||!Ir||(t?(e(`LOCAL_PUBLIC_EPHEMERAL_KEY ${W(t.publicKey,"hex")}`),e(`LOCAL_PRIVATE_EPHEMERAL_KEY ${W(t.privateKey,"hex")}`)):e("Missing local ephemeral keys."))}function Hf(t,e){!e.enabled||!Ir||e(t?`REMOTE_STATIC_PUBLIC_KEY ${W(t.subarray(),"hex")}`:"Missing remote static public key.")}function La(t,e){!e.enabled||!Ir||e(t?`REMOTE_EPHEMERAL_PUBLIC_KEY ${W(t.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function Ta(t,e,r){!r.enabled||!Ir||(r(`CIPHER_STATE_1 ${t.n.getUint64()} ${t.k&&W(t.k,"hex")}`),r(`CIPHER_STATE_2 ${e.n.getUint64()} ${e.k&&W(e.k,"hex")}`))}var Pr=class t extends Error{code;constructor(e="Invalid crypto exchange"){super(e),this.code=t.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var um=0,fm=4294967295,lm="Cipherstate has reached maximum n, a new handshake must be performed",js=class{n;bytes;view;constructor(e=um){this.n=e,this.bytes=be(12),this.view=new DataView(this.bytes.buffer,this.bytes.byteOffset,this.bytes.byteLength),this.view.setUint32(4,e,!0)}increment(){this.n++,this.view.setUint32(4,this.n,!0)}getBytes(){return this.bytes}getUint64(){return this.n}assertValue(){if(this.n>fm)throw new Error(lm)}};var rr=be(0),Ur=class{k;n;crypto;constructor(e,r=void 0,n=0){this.crypto=e,this.k=r,this.n=new js(n)}hasKey(){return!!this.k}encryptWithAd(e,r){if(!this.hasKey())return r;this.n.assertValue();let n=this.crypto.encrypt(r,this.n.getBytes(),e,this.k);return this.n.increment(),n}decryptWithAd(e,r,n){if(!this.hasKey())return r;this.n.assertValue();let s=this.crypto.decrypt(r,this.n.getBytes(),e,this.k,n);return this.n.increment(),s}},Ca=class{cs;ck;h;crypto;constructor(e,r){this.crypto=e;let n=ee(r,"utf-8");this.h=hm(e,n),this.ck=this.h,this.cs=new Ur(e)}mixKey(e){let[r,n]=this.crypto.hkdf(this.ck,e);this.ck=r,this.cs=new Ur(this.crypto,n)}mixHash(e){this.h=this.crypto.hash(new Q(this.h,e))}encryptAndHash(e){let r=this.cs.encryptWithAd(this.h,e);return this.mixHash(r),r}decryptAndHash(e){let r=this.cs.decryptWithAd(this.h,e);return this.mixHash(e),r}split(){let[e,r]=this.crypto.hkdf(this.ck,rr);return[new Ur(this.crypto,e),new Ur(this.crypto,r)]}},Ia=class{ss;s;e;rs;re;initiator;crypto;constructor(e){let{crypto:r,protocolName:n,prologue:s,initiator:o,s:i,e:a,rs:c,re:u}=e;this.crypto=r,this.ss=new Ca(r,n),this.ss.mixHash(s),this.initiator=o,this.s=i,this.e=a,this.rs=c,this.re=u}writeE(){if(this.e)throw new Error("ephemeral keypair is already set");let e=this.crypto.generateKeypair();return this.ss.mixHash(e.publicKey),this.e=e,e.publicKey}writeS(){if(!this.s)throw new Error("static keypair is not set");return this.ss.encryptAndHash(this.s.publicKey)}writeEE(){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.re))}writeES(){if(this.initiator){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}else{if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}}writeSE(){if(this.initiator){if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}else{if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}}readE(e,r=0){if(this.re)throw new Error("remote ephemeral public key is already set");if(e.byteLength<r+32)throw new Error("message is not long enough");this.re=e.sublist(r,r+32),this.ss.mixHash(this.re)}readS(e,r=0){if(this.rs)throw new Error("remote static public key is already set");let n=32+(this.ss.cs.hasKey()?16:0);if(e.byteLength<r+n)throw new Error("message is not long enough");let s=e.sublist(r,r+n);return this.rs=this.ss.decryptAndHash(s),n}readEE(){this.writeEE()}readES(){this.writeES()}readSE(){this.writeSE()}},Sn=class extends Ia{writeMessageA(e){return new Q(this.writeE(),this.ss.encryptAndHash(e))}writeMessageB(e){let r=this.writeE();this.writeEE();let n=this.writeS();return this.writeES(),new Q(r,n,this.ss.encryptAndHash(e))}writeMessageC(e){let r=this.writeS();return this.writeSE(),new Q(r,this.ss.encryptAndHash(e))}readMessageA(e){try{return this.readE(e),this.ss.decryptAndHash(e.sublist(32))}catch(r){throw new Pr(`handshake stage 0 validation fail: ${r.message}`)}}readMessageB(e){try{this.readE(e),this.readEE();let r=this.readS(e,32);return this.readES(),this.ss.decryptAndHash(e.sublist(32+r))}catch(r){throw new Pr(`handshake stage 1 validation fail: ${r.message}`)}}readMessageC(e){try{let r=this.readS(e);return this.readSE(),this.ss.decryptAndHash(e.sublist(r))}catch(r){throw new Pr(`handshake stage 2 validation fail: ${r.message}`)}}};function hm(t,e){if(e.length<=32){let r=be(32);return r.set(e),r}else return t.hash(e)}var vn;(function(t){let e;t.codec=()=>(e==null&&(e=Gt((o,i,a={})=>{if(a.lengthDelimited!==!1&&i.fork(),o.webtransportCerthashes!=null&&o.webtransportCerthashes.length>0)for(let c of o.webtransportCerthashes)i.uint32(10),i.bytes(c);if(o.streamMuxers!=null&&o.streamMuxers.length>0)for(let c of o.streamMuxers)i.uint32(18),i.string(c);a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={webtransportCerthashes:[],streamMuxers:[]},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{if(a.limits?.webtransportCerthashes!=null&&c.webtransportCerthashes.length===a.limits.webtransportCerthashes)throw new Zt('Decode error - repeated field "webtransportCerthashes" had too many elements');c.webtransportCerthashes.push(o.bytes());break}case 2:{if(a.limits?.streamMuxers!=null&&c.streamMuxers.length===a.limits.streamMuxers)throw new Zt('Decode error - repeated field "streamMuxers" had too many elements');c.streamMuxers.push(o.string());break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u={webtransportCerthashes:0,streamMuxers:0},f=i==null?o.len:o.pos+i;for(;o.pos<f;){let l=o.uint32();switch(l>>>3){case 1:{if(c.limits?.webtransportCerthashes!=null&&u.webtransportCerthashes===c.limits.webtransportCerthashes)throw new Zt('Streaming decode error - repeated field "webtransportCerthashes" had too many elements');yield{field:`${a}.webtransportCerthashes[]`,index:u.webtransportCerthashes,value:o.bytes()},u.webtransportCerthashes++;break}case 2:{if(c.limits?.streamMuxers!=null&&u.streamMuxers===c.limits.streamMuxers)throw new Zt('Streaming decode error - repeated field "streamMuxers" had too many elements');yield{field:`${a}.streamMuxers[]`,index:u.streamMuxers,value:o.string()},u.streamMuxers++;break}default:{o.skipType(l&7);break}}}})),e);function r(o){return Wt(o,t.codec())}t.encode=r;function n(o,i){return Vt(o,t.codec(),i)}t.decode=n;function s(o,i){return Yt(o,t.codec(),i)}t.stream=s})(vn||(vn={}));var An;(function(t){let e;t.codec=()=>(e==null&&(e=Gt((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.identityKey!=null&&o.identityKey.byteLength>0&&(i.uint32(10),i.bytes(o.identityKey)),o.identitySig!=null&&o.identitySig.byteLength>0&&(i.uint32(18),i.bytes(o.identitySig)),o.extensions!=null&&(i.uint32(34),vn.codec().encode(o.extensions,i)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={identityKey:be(0),identitySig:be(0)},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.identityKey=o.bytes();break}case 2:{c.identitySig=o.bytes();break}case 4:{c.extensions=vn.codec().decode(o,o.uint32(),{limits:a.limits?.extensions});break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${a}.identityKey`,value:o.bytes()};break}case 2:{yield{field:`${a}.identitySig`,value:o.bytes()};break}case 4:{yield*vn.codec().stream(o,o.uint32(),`${a}.extensions`,{limits:c.limits?.extensions});break}default:{o.skipType(f&7);break}}}})),e);function r(o){return Wt(o,t.codec())}t.encode=r;function n(o,i){return Vt(o,t.codec(),i)}t.decode=n;function s(o,i){return Yt(o,t.codec(),i)}t.stream=s})(An||(An={}));async function Ra(t,e,r){let n=await t.sign(zf(e));return An.encode({identityKey:xt(t.publicKey),identitySig:n,extensions:r})}async function Oa(t,e,r){try{let n=An.decode(t),s=un(n.identityKey);if(r?.equals(s)===!1)throw new Error(`Payload identity key ${s} does not match expected remote identity key ${r}`);if(!e)throw new Error("Remote static does not exist");let o=zf(e);if(!await s.verify(o,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new Bn(n.message)}}function zf(t){let e=ee("noise-libp2p-static-key:");return t instanceof Uint8Array?Ke([e,t],e.length+t.length):(t.prepend(e),t)}var Da=class extends nt{stream;handshake;metrics;decoder;constructor(e,r,n){super({log:e.log,inactivityTimeout:e.inactivityTimeout,maxReadBufferLength:e.maxReadBufferLength,direction:e.direction}),this.stream=e,this.handshake=r,this.metrics=n,this.decoder=new zs({lengthDecoder:Or,maxBufferSize:16*1024*1024,encodingLength:()=>2});let s=c=>{try{for(let u of this.decoder.decode(c.data))this.onData(this.decrypt(u))}catch(u){this.abort(u)}};this.stream.addEventListener("message",s);let o=c=>{c.error!=null?c.local===!0?this.abort(c.error):this.onRemoteReset():this.onTransportClosed()};this.stream.addEventListener("close",o);let i=()=>{this.safeDispatchEvent("drain")};this.stream.addEventListener("drain",i);let a=()=>{this.onRemoteCloseWrite()};this.stream.addEventListener("remoteCloseWrite",a)}encrypt(e){let r=new Q;for(let n=0;n<e.byteLength;n+=65519){let s=n+65519;s>e.byteLength&&(s=e.byteLength);let o;e instanceof Uint8Array?o=this.handshake.encrypt(e.subarray(n,s)):o=this.handshake.encrypt(e.sublist(n,s)),this.metrics?.encryptedPackets.increment(),r.append(Rr(o.byteLength)),r.append(o)}return r}decrypt(e){let r=new Q;for(let n=0;n<e.byteLength;n+=65535){let s=n+65535;if(s>e.byteLength&&(s=e.byteLength),s-wa<n)throw new Error("Invalid chunk");let o;e instanceof Uint8Array?o=e.subarray(n,s):o=e.sublist(n,s);let i=e.subarray(n,s-wa);try{let a=this.handshake.decrypt(o,i);this.metrics?.decryptedPackets.increment(),r.append(a)}catch(a){throw this.metrics?.decryptErrors.increment(),a}}return r}close(e){return this.stream.close(e)}sendPause(){this.stream.pause()}sendResume(){this.stream.resume()}sendReset(e){this.stream.abort(e)}sendData(e){return{sentBytes:e.byteLength,canSendMore:this.stream.send(this.encrypt(e))}}};function Pa(t,e,r){return new Da(t,e,r)}async function $f(t,e){let{log:r,connection:n,crypto:s,privateKey:o,prologue:i,s:a,remoteIdentityKey:c,extensions:u}=t,f=await Ra(o,a.publicKey,u),l=new Sn({crypto:s,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:i,s:a});Ba(l.s,r),r.trace("Stage 0 - Initiator starting to send first message."),await n.write(l.writeMessageA(rr),e),r.trace("Stage 0 - Initiator finished sending first message."),_a(l.e,r),r.trace("Stage 1 - Initiator waiting to receive first message from responder...");let d=l.readMessageB(await n.read(e));r.trace("Stage 1 - Initiator received the message."),La(l.re,r),Hf(l.rs,r),r.trace("Initiator going to check remote's signature...");let p=await Oa(d,l.rs,c);r.trace("All good with the signature!"),r.trace("Stage 2 - Initiator sending third handshake message."),await n.write(l.writeMessageC(f),e),r.trace("Stage 2 - Initiator sent message with signed payload.");let[g,b]=l.ss.split();return Ta(g,b,r),{payload:p,encrypt:y=>g.encryptWithAd(rr,y),decrypt:(y,x)=>b.decryptWithAd(rr,y,x)}}async function Vf(t,e){let{log:r,connection:n,crypto:s,privateKey:o,prologue:i,s:a,remoteIdentityKey:c,extensions:u}=t,f=await Ra(o,a.publicKey,u),l=new Sn({crypto:s,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:i,s:a});Ba(l.s,r),r.trace("Stage 0 - Responder waiting to receive first message."),l.readMessageA(await n.read(e)),r.trace("Stage 0 - Responder received first message."),La(l.re,r),r.trace("Stage 1 - Responder sending out first message with signed payload and static key."),await n.write(l.writeMessageB(f),e),r.trace("Stage 1 - Responder sent the second handshake message with signed payload."),_a(l.e,r),r.trace("Stage 2 - Responder waiting for third handshake message...");let d=l.readMessageC(await n.read(e));r.trace("Stage 2 - Responder received the message, finished handshake.");let p=await Oa(d,l.rs,c),[g,b]=l.ss.split();return Ta(g,b,r),{payload:p,encrypt:y=>b.encryptWithAd(rr,y),decrypt:(y,x)=>g.decryptWithAd(rr,y,x)}}var Ys=class{protocol="/noise";crypto;prologue;staticKey;extensions;metrics;components;log;constructor(e,r={}){let{staticNoiseKey:n,extensions:s,crypto:o,prologueBytes:i}=r,{metrics:a}=e;this.components=e,this.log=e.logger.forComponent("libp2p:noise");let c=o??Mf;this.crypto=Kf(c),this.extensions={webtransportCerthashes:[],...s},this.metrics=a?Ff(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=i??be(0)}[Symbol.toStringTag]="@libp2p/noise";[Pn]=["@libp2p/connection-encryption","@libp2p/noise"];async secureOutbound(e,r){let n=e.log?.newScope("noise")??this.log,s=ba(e,{lengthEncoder:Rr,lengthDecoder:Or,maxDataLength:65535}),o=await this.performHandshakeInitiator(s,this.components.privateKey,n,r?.remotePeer?.publicKey,r),i=un(o.payload.identityKey);return{connection:Pa(s.unwrap(),o,this.metrics),remoteExtensions:o.payload.extensions,remotePeer:Ni(i),streamMuxer:r?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(o.payload.extensions?.streamMuxers)}}getStreamMuxer(e){if(e==null||e.length===0)return;let r=this.components.upgrader.getStreamMuxers();if(r!=null)for(let n of e){let s=r.get(n);if(s!=null)return s}if(e.length)throw new or("Early muxer negotiation was requested but the initiator and responder had no common muxers")}async secureInbound(e,r){let n=e.log?.newScope("noise")??this.log,s=ba(e,{lengthEncoder:Rr,lengthDecoder:Or,maxDataLength:65535}),o=await this.performHandshakeResponder(s,this.components.privateKey,n,r?.remotePeer?.publicKey,r),i=un(o.payload.identityKey);return{connection:Pa(s.unwrap(),o,this.metrics),remoteExtensions:o.payload.extensions,remotePeer:Ni(i),streamMuxer:r?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(o.payload.extensions?.streamMuxers)}}async performHandshakeInitiator(e,r,n,s,o){let i,a=o?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{i=await $f({connection:e,privateKey:r,remoteIdentityKey:s,log:n.newScope("xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:{streamMuxers:a,webtransportCerthashes:[],...this.extensions}},o),this.metrics?.xxHandshakeSuccesses.increment()}catch(c){throw this.metrics?.xxHandshakeErrors.increment(),c}return i}async performHandshakeResponder(e,r,n,s,o){let i,a=o?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{i=await Vf({connection:e,privateKey:r,remoteIdentityKey:s,log:n.newScope("xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:{streamMuxers:a,webtransportCerthashes:[],...this.extensions}},o),this.metrics?.xxHandshakeSuccesses.increment()}catch(c){throw this.metrics?.xxHandshakeErrors.increment(),c}return i}};function jf(t={}){return e=>new Ys(e,t)}var nr=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};function Ua(t){throw new Error("Not implemented")}var Na=class extends Hs{writer;reader;constructor(e){super(e),this.writer=e.stream.writable.getWriter(),this.reader=e.stream.readable.getReader(),this.writer.closed.then(()=>{this.log("writer closed gracefully")}).catch(r=>{r.message.includes("STOP_SENDING")||r.message.includes("StopSending")?this.onRemoteCloseRead():r.message.includes("RESET_STREAM")||r.message.includes("Reset")?this.onRemoteReset():this.log("writer close promise rejected - %e",r)}),this.readData()}readData(){Promise.resolve().then(async()=>{for(;;){let e=await this.reader.read();if(e.value!=null&&this.onData(e.value),e.done){this.log("remote closed write"),this.onRemoteCloseWrite();return}if(this.readStatus==="paused")break}}).catch(e=>{this.abort(e)}).finally(()=>{this.reader.releaseLock()})}sendData(e){for(let n of e)this.writer.write(n).catch(s=>{this.abort(s)});if(this.log.trace("desired size after sending %d bytes is %d bytes",e.byteLength,this.writer.desiredSize),this.writer.desiredSize==null)return{sentBytes:e.byteLength,canSendMore:!1};let r=this.writer.desiredSize>0;return r||this.writer.ready.then(()=>{this.safeDispatchEvent("drain")},n=>{this.abort(n)}),{sentBytes:e.byteLength,canSendMore:r}}sendReset(e){this.writer.abort(e).catch(r=>{this.log.error("error aborting writer - %e",r)})}async sendCloseWrite(e){this.log("sendCloseWrite closing writer"),await $e(this.writer.close().catch(()=>{}),e?.signal),this.log("sendCloseWrite closed writer")}async sendCloseRead(e){this.log("sendCloseRead cancelling reader"),await $e(this.reader.cancel(),e?.signal),this.log("sendCloseRead cancelled reader")}sendPause(){}sendResume(){this.readData()}};function ka(t,e,r,n,s){return new Na({...s,stream:t,id:e,direction:r,log:n.newScope(`${r}:${e}`),protocol:""})}var Wf="/webtransport",Ma=class extends Fs{webTransport;streamIDCounter;reader;constructor(e,r){super(r,{protocol:Wf,name:"muxer"}),this.webTransport=e,this.streamIDCounter=0,this.reader=this.webTransport.incomingBidirectionalStreams.getReader(),Promise.resolve().then(async()=>{for(;;){let{done:n,value:s}=await this.reader.read();if(n||s==null)break;this.onRemoteStream(ka(s,String(this.streamIDCounter++),"inbound",this.log,this.streamOptions))}}).catch(n=>{this.log.error("could not create a new stream - %e",n)})}async onCreateStream(e){let r=await this.webTransport.createBidirectionalStream();return e?.signal?.throwIfAborted(),ka(r,String(this.streamIDCounter++),"outbound",this.log,e)}onData(){}sendReset(){this.webTransport.close()}};function Yf(t){return{protocol:Wf,createStreamMuxer(e){return new Ma(t,e)}}}var Ka=class extends Ks{cleanUpWTSession;constructor(e){super(e),this.cleanUpWTSession=e.cleanUpWTSession}sendData(e){return{sentBytes:e.byteLength,canSendMore:!0}}sendReset(){this.cleanUpWTSession("abort")}async sendClose(e){this.cleanUpWTSession("close"),e?.signal?.throwIfAborted()}sendPause(){}sendResume(){}},Gf=t=>new Ka(t);function Zf(t,e){return e.filter(n=>!!t.find(s=>xe(n,s))).length===e.length}var dm=Object.values(kt).map(t=>t.decoder).reduce((t,e)=>t.or(e));function pm(t){return ot.decode(dm.decode(t))}function Fa(t){if(!Os.matches(t))throw new Tn("Invalid multiaddr, was not a WebTransport address");let e=[],r;for(let o of t.getComponents())o.name==="certhash"&&e.push(pm(o.value??"")),o.name==="p2p"&&r==null&&(r=ju(o.value??""));let n=Yu(t),s=n.host;return n.type==="ip6"&&s.includes(":")&&(s=`[${s}]`),{url:`https://${s}:${n.port}`,certhashes:e,remotePeer:r}}var Gs=class extends nt{writer;reader;constructor(e){super(e),this.writer=e.stream.writable.getWriter(),this.reader=e.stream.readable.getReader(),Promise.resolve().then(async()=>{for(;;){let{done:r,value:n}=await this.reader.read();if(n!=null&&this.onData(n),r)break}}).catch(r=>{this.abort(r)})}async close(e){await $e(this.writer.close(),e?.signal)}sendData(e){return this.writer.write(e.subarray()).catch(r=>{this.abort(r)}),{sentBytes:e.byteLength,canSendMore:!0}}sendReset(e){this.writer.abort(e).catch(r=>{this.log.error("could not send reset - %e",r)})}sendPause(){}sendResume(){}};var Xf=globalThis.WebTransport;var Ha=class{log;components;config;metrics;constructor(e,r={}){this.log=e.logger.forComponent("libp2p:webtransport"),this.components=e,this.config={...r,certificates:r.certificates??[]},e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_webtransport_dialer_events_total",{label:"event",help:"Total count of WebTransport dialer events by type"})})}[Symbol.toStringTag]="@libp2p/webtransport";[za]=!0;[Pn]=["@libp2p/transport"];async dial(e,r){r.signal.throwIfAborted(),this.log("dialing %s",e),r=r??{};let{url:n,certhashes:s,remotePeer:o}=Fa(e),i,a,c=()=>{},u=!1,f=!1,l=!1;try{this.metrics?.dialerEvents.increment({pending:!0});let d=new Xf(`${n}/.well-known/libp2p-webtransport?type=noise`,{serverCertificateHashes:s.map(g=>({algorithm:"sha-256",value:Ae(g.digest)}))});c=g=>{if(!u)try{this.metrics?.dialerEvents.increment({[g]:!0}),d.close()}catch(b){this.log.error("error closing wt session - %e",b)}finally{a!=null&&(a.timeline.close=Date.now()),u=!0}},i=()=>{c(f?"noise_timeout":"ready_timeout")},r.signal.addEventListener("abort",i,{once:!0}),this.log("wait for session to be ready"),r.onProgress?.(new nr("webtransport:wait-for-session")),await Promise.race([d.closed,d.ready]),this.log("session became ready"),f=!0,this.metrics?.dialerEvents.increment({ready:!0}),d.closed.catch(g=>{this.log.error("error on remote wt session close - %e",g)}).finally(()=>{c("remote_close")}),this.metrics?.dialerEvents.increment({open:!0}),a=Gf({remoteAddr:e,cleanUpWTSession:c,direction:"outbound",log:this.components.logger.forComponent("libp2p:webtransport:connection")});let p=await this.authenticateWebTransport({wt:d,maConn:a,remotePeer:o,certhashes:s,...r});if(l=!0,o!=null&&(l=o.equals(p)),!l)throw new or("Failed to authenticate webtransport");return await r.upgrader.upgradeOutbound(a,{...r,skipEncryption:!0,remotePeer:p,muxerFactory:Yf(d),skipProtection:!0})}catch(d){throw this.log.error("caught wt session err - %e",d),c(l?"upgrade_error":f?"noise_error":"ready_error"),d}finally{i!=null&&r.signal?.removeEventListener("abort",i)}}async authenticateWebTransport({wt:e,maConn:r,remotePeer:n,certhashes:s,onProgress:o,signal:i}){o?.(new nr("webtransport:open-authentication-stream"));let a=await e.createBidirectionalStream();i?.throwIfAborted();let c=new Gs({stream:a,log:r.log.newScope("muxer")}),u=jf()(this.components);o?.(new nr("webtransport:secure-outbound-connection"));let{remoteExtensions:f,remotePeer:l}=await u.secureOutbound(c,{signal:i,remotePeer:n,skipStreamMuxerNegotiation:!0});if(o?.(new nr("webtransport:close-authentication-stream")),await c.close({signal:i}),!Zf(f?.webtransportCerthashes??[],s.map(d=>d.bytes)))throw new se("Our certhashes are not a subset of the remote's reported certhashes");return l}createListener(e){return Ua(this.components,{...e,certificates:this.config.certificates})}listenFilter(){return[]}dialFilter(e){return globalThis.WebTransport==null?[]:e.filter(r=>{if(!Os.exactMatch(r))return!1;let{url:n,certhashes:s}=Fa(r);return n!=null&&s.length>0})}};function mm(t={}){return e=>new Ha(e,t)}return ol(ym);})();
|
|
3
3
|
//! TODO unclear how to add backpressure here?
|
|
4
4
|
/*! Bundled license information:
|
|
5
5
|
|