@libp2p/noise 16.1.4-f0afebfdf → 17.0.1-71e8ee163

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,22 +1,21 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PNoise = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PNoise=(()=>{var Pn=Object.defineProperty;var xc=Object.getOwnPropertyDescriptor;var wc=Object.getOwnPropertyNames;var Ec=Object.prototype.hasOwnProperty;var xt=(e,t)=>{for(var r in t)Pn(e,r,{get:t[r],enumerable:!0})},Sc=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of wc(t))!Ec.call(e,s)&&s!==r&&Pn(e,s,{get:()=>t[s],enumerable:!(n=xc(t,s))||n.enumerable});return e};var vc=e=>Sc(Pn({},"__esModule",{value:!0}),e);var Fh={};xt(Fh,{noise:()=>Vh,pureJsCrypto:()=>Kn});var kr=class extends Error{static name="UnexpectedPeerError";constructor(t="Unexpected Peer"){super(t),this.name="UnexpectedPeerError"}},Mr=class extends Error{static name="InvalidCryptoExchangeError";constructor(t="Invalid crypto exchange"){super(t),this.name="InvalidCryptoExchangeError"}},tt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Te=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Or=class extends Error{static name="StreamResetError";constructor(t="The stream has been reset"){super(t),this.name="StreamResetError"}};var he=class extends Error{static name="StreamStateError";constructor(t="The stream is in an invalid state"){super(t),this.name="StreamStateError"}},cr=class extends Error{static name="StreamBufferError";constructor(t="The stream buffer was full"){super(t),this.name="StreamBufferError"}};var Ce=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Hr=class extends Event{data;constructor(t,r){super("message",r),this.data=t}},Ke=class extends Event{error;local;constructor(t,r,n){super("close",n),this.error=r,this.local=t}},qr=class extends Ke{constructor(t,r){super(!0,t,r)}},Vr=class extends Ke{constructor(t,r){super(!1,t,r)}};var Nn=Symbol.for("@libp2p/peer-id");var Fr=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let r=this.#t.get(t);return r==null?0:r.length}addEventListener(t,r,n){super.addEventListener(t,r,n);let s=this.#t.get(t);s==null&&(s=[],this.#t.set(t,s)),s.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,r,n){super.removeEventListener(t.toString(),r??null,n);let s=this.#t.get(t);s!=null&&(s=s.filter(({callback:o})=>o!==r),this.#t.set(t,s))}dispatchEvent(t){let r=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:s})=>!s),this.#t.set(t.type,n)),r}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var $o=Symbol.for("@libp2p/service-capabilities"),Wh=Symbol.for("@libp2p/service-dependencies");var qn={};xt(qn,{base58btc:()=>rt,base58flickr:()=>Cc});var El=new Uint8Array(0);function Zo(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Pt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function Wo(e){return new TextEncoder().encode(e)}function Yo(e){return new TextDecoder().decode(e)}function Ac(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var s=0;s<e.length;s++){var o=e.charAt(s),i=o.charCodeAt(0);if(r[i]!==255)throw new TypeError(o+" is ambiguous");r[i]=s}var a=e.length,c=e.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function h(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var w=0,g=0,x=0,B=p.length;x!==B&&p[x]===0;)x++,w++;for(var E=(B-x)*f+1>>>0,R=new Uint8Array(E);x!==B;){for(var k=p[x],O=0,M=E-1;(k!==0||O<g)&&M!==-1;M--,O++)k+=256*R[M]>>>0,R[M]=k%a>>>0,k=k/a>>>0;if(k!==0)throw new Error("Non-zero carry");g=O,x++}for(var P=E-g;P!==E&&R[P]===0;)P++;for(var S=c.repeat(w);P<E;++P)S+=e.charAt(R[P]);return S}function l(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var w=0;if(p[w]!==" "){for(var g=0,x=0;p[w]===c;)g++,w++;for(var B=(p.length-w)*u+1>>>0,E=new Uint8Array(B);p[w];){var R=r[p.charCodeAt(w)];if(R===255)return;for(var k=0,O=B-1;(R!==0||k<x)&&O!==-1;O--,k++)R+=a*E[O]>>>0,E[O]=R%256>>>0,R=R/256>>>0;if(R!==0)throw new Error("Non-zero carry");x=k,w++}if(p[w]!==" "){for(var M=B-x;M!==B&&E[M]===0;)M++;for(var P=new Uint8Array(g+(B-M)),S=g;M!==B;)P[S++]=E[M++];return P}}}function d(p){var w=l(p);if(w)return w;throw new Error(`Non-${t} character`)}return{encode:h,decodeUnsafe:l,decode:d}}var Bc=Ac,Lc=Bc,Jo=Lc;var kn=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Mn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,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(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Qo(this,t)}},On=class{decoders;constructor(t){this.decoders=t}or(t){return Qo(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Qo(e,t){return new On({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Hn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,s){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=s,this.encoder=new kn(t,r,n),this.decoder=new Mn(t,r,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Re({name:e,prefix:t,encode:r,decode:n}){return new Hn(e,t,r,n)}function Jt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:s}=Jo(r,e);return Re({prefix:t,name:e,encode:n,decode:o=>Pt(s(o))})}function _c(e,t,r,n){let s=e.length;for(;e[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=t[e[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 Ic(e,t,r){let n=t[t.length-1]==="=",s=(1<<r)-1,o="",i=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],i+=8;i>r;)i-=r,o+=t[s&a>>i];if(i!==0&&(o+=t[s&a<<r-i]),n)for(;(o.length*r&7)!==0;)o+="=";return o}function Tc(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function et({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let s=Tc(n);return Re({prefix:t,name:e,encode(o){return Ic(o,n,r)},decode(o){return _c(o,s,r,e)}})}var rt=Jt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Cc=Jt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Vn={};xt(Vn,{base32:()=>Ue,base32hex:()=>Dc,base32hexpad:()=>Nc,base32hexpadupper:()=>kc,base32hexupper:()=>Pc,base32pad:()=>Rc,base32padupper:()=>Uc,base32upper:()=>Kc,base32z:()=>Mc});var Ue=et({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Kc=et({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Rc=et({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Uc=et({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Dc=et({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Pc=et({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Nc=et({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),kc=et({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Mc=et({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Fn={};xt(Fn,{base36:()=>fr,base36upper:()=>Oc});var fr=Jt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Oc=Jt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Hc=ri,ti=128,qc=127,Vc=~qc,Fc=Math.pow(2,31);function ri(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Fc;)t[r++]=e&255|ti,e/=128;for(;e&Vc;)t[r++]=e&255|ti,e>>>=7;return t[r]=e|0,ri.bytes=r-n+1,t}var zc=zn,Gc=128,ei=127;function zn(e,n){var r=0,n=n||0,s=0,o=n,i,a=e.length;do{if(o>=a)throw zn.bytes=0,new RangeError("Could not decode varint");i=e[o++],r+=s<28?(i&ei)<<s:(i&ei)*Math.pow(2,s),s+=7}while(i>=Gc);return zn.bytes=o-n,r}var jc=Math.pow(2,7),$c=Math.pow(2,14),Zc=Math.pow(2,21),Wc=Math.pow(2,28),Yc=Math.pow(2,35),Xc=Math.pow(2,42),Jc=Math.pow(2,49),Qc=Math.pow(2,56),tf=Math.pow(2,63),ef=function(e){return e<jc?1:e<$c?2:e<Zc?3:e<Wc?4:e<Yc?5:e<Xc?6:e<Jc?7:e<Qc?8:e<tf?9:10},rf={encode:Hc,decode:zc,encodingLength:ef},nf=rf,ur=nf;function hr(e,t=0){return[ur.decode(e,t),ur.decode.bytes]}function De(e,t,r=0){return ur.encode(e,t,r),t}function Pe(e){return ur.encodingLength(e)}function Kt(e,t){let r=t.byteLength,n=Pe(e),s=n+Pe(r),o=new Uint8Array(s+r);return De(e,o,0),De(r,o,n),o.set(t,s),new Ne(e,r,t,o)}function Gn(e){let t=Pt(e),[r,n]=hr(t),[s,o]=hr(t.subarray(n)),i=t.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new Ne(r,s,i,t)}function ni(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Zo(e.bytes,r.bytes)}}var Ne=class{code;size;digest;bytes;constructor(t,r,n,s){this.code=t,this.size=r,this.digest=n,this.bytes=s}};function si(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return of(r,jn(e),t??rt.encoder);default:return af(r,jn(e),t??Ue.encoder)}}var oi=new WeakMap;function jn(e){let t=oi.get(e);if(t==null){let r=new Map;return oi.set(e,r),r}return t}var ht=class e{code;version;multihash;bytes;"/";constructor(t,r,n,s){this.code=r,this.version=t,this.multihash=n,this.bytes=s,this["/"]=s}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==lr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==cf)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.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:t,digest:r}=this.multihash,n=Kt(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&ni(t.multihash,n.multihash)}toString(t){return si(this,t)}toJSON(){return{"/":si(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:s,multihash:o,bytes:i}=r;return new e(n,s,o,i??ii(n,s,o.bytes))}else if(r[ff]===!0){let{version:n,multihash:s,code:o}=r,i=Gn(s);return e.create(n,o,i)}else return null}static create(t,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(t){case 0:{if(r!==lr)throw new Error(`Version 0 CID must use dag-pb (code: ${lr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let s=ii(t,r,n.bytes);return new e(t,r,n,s)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,lr,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,s=Pt(t.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 Ne(r.multihashCode,r.digestSize,o,s);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[h,l]=hr(t.subarray(r));return r+=l,h},s=n(),o=lr;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(t,r){let[n,s]=sf(t,r),o=e.decode(s);if(o.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return jn(o).set(n,t),o}};function sf(e,t){switch(e[0]){case"Q":{let r=t??rt;return[rt.prefix,r.decode(`${rt.prefix}${e}`)]}case rt.prefix:{let r=t??rt;return[rt.prefix,r.decode(e)]}case Ue.prefix:{let r=t??Ue;return[Ue.prefix,r.decode(e)]}case fr.prefix:{let r=t??fr;return[fr.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function of(e,t,r){let{prefix:n}=r;if(n!==rt.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let s=t.get(n);if(s==null){let o=r.encode(e).slice(1);return t.set(n,o),o}else return s}function af(e,t,r){let{prefix:n}=r,s=t.get(n);if(s==null){let o=r.encode(e);return t.set(n,o),o}else return s}var lr=112,cf=18;function ii(e,t,r){let n=Pe(e),s=n+Pe(t),o=new Uint8Array(s+r.byteLength);return De(e,o,0),De(t,o,n),o.set(r,s),o}var ff=Symbol.for("@ipld/js-cid/CID");var $n={};xt($n,{identity:()=>Rt});var ai=0,uf="identity",ci=Pt;function hf(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return Kt(ai,ci(e))}var Rt={code:ai,name:uf,encode:ci,digest:hf};function yt(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function nt(e=0){return new Uint8Array(e)}function ct(e=0){return new Uint8Array(e)}function le(e,t){t==null&&(t=e.reduce((s,o)=>s+o.length,0));let r=ct(t),n=0;for(let s of e)r.set(s,n),n+=s.length;return r}var ui=Symbol.for("@achingbrain/uint8arraylist");function fi(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let s=r+n.byteLength;if(t<s)return{buf:n,index:t-r};r=s}throw new RangeError("index is out of bounds")}function Gr(e){return!!e?.[ui]}var G=class e{bufs;length;[ui]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Gr(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Gr(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(t){let r=fi(this.bufs,t);return r.buf[r.index]}set(t,r){let n=fi(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(Gr(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:s}=this._subList(t,r);return le(n,s)}subarray(t,r){let{bufs:n,length:s}=this._subList(t,r);return n.length===1?n[0]:le(n,s)}sublist(t,r){let{bufs:n,length:s}=this._subList(t,r),o=new e;return o.length=s,o.bufs=[...n],o}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===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,t>=c)continue;let u=t>=a&&t<c,f=r>a&&r<=c;if(u&&f){if(t===a&&r===c){n.push(i);break}let h=t-a;n.push(i.subarray(h,h+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-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-t}}indexOf(t,r=0){if(!Gr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let o=256,i=new Int32Array(o);for(let h=0;h<o;h++)i[h]=-1;for(let h=0;h<s;h++)i[n[h]]=h;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let h=r;h<=c;h+=f){f=0;for(let l=u;l>=0;l--){let d=this.get(h+l);if(n[l]!==d){f=Math.max(1,l-a[d]);break}}if(f===0)return h}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=ct(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let s=nt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,r,n),this.write(s,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let s=nt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,r,n),this.write(s,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let s=nt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,r,n),this.write(s,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=ct(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let s=nt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,r,n),this.write(s,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let s=nt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,r,n),this.write(s,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let s=nt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,r,n),this.write(s,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let s=nt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,r,n),this.write(s,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let s=nt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,r,n),this.write(s,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!yt(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((s,o)=>s+o.byteLength,0)),n.length=r,n}};var Zn={};xt(Zn,{base10:()=>df});var df=Jt({prefix:"9",name:"base10",alphabet:"0123456789"});var Wn={};xt(Wn,{base16:()=>pf,base16upper:()=>mf});var pf=et({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),mf=et({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Yn={};xt(Yn,{base2:()=>yf});var yf=et({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Xn={};xt(Xn,{base256emoji:()=>Ef});var hi=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}"),gf=hi.reduce((e,t,r)=>(e[r]=t,e),[]),bf=hi.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function xf(e){return e.reduce((t,r)=>(t+=gf[r],t),"")}function wf(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let s=bf[n];if(s==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(s)}return new Uint8Array(t)}var Ef=Re({prefix:"\u{1F680}",name:"base256emoji",encode:xf,decode:wf});var Jn={};xt(Jn,{base64:()=>Sf,base64pad:()=>vf,base64url:()=>Af,base64urlpad:()=>Bf});var Sf=et({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),vf=et({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Af=et({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Bf=et({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Qn={};xt(Qn,{base8:()=>Lf});var Lf=et({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ts={};xt(ts,{identity:()=>_f});var _f=Re({prefix:"\0",name:"identity",encode:e=>Yo(e),decode:e=>Wo(e)});var nd=new TextEncoder,sd=new TextDecoder;var ns={};xt(ns,{sha256:()=>jr,sha512:()=>Kf});var Cf=20;function rs({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:s}){return new es(e,t,r,n,s)}var es=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,s,o){this.name=t,this.code=r,this.encode=n,this.minDigestLength=s??Cf,this.maxDigestLength=o}digest(t,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(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?li(n,this.code,r?.truncate):n.then(s=>li(s,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function li(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Kt(t,e)}function pi(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var jr=rs({name:"sha2-256",code:18,encode:pi("SHA-256")}),Kf=rs({name:"sha2-512",code:19,encode:pi("SHA-512")});var ss={...ts,...Yn,...Qn,...Zn,...Wn,...Vn,...Fn,...qn,...Jn,...Xn},yd={...ns,...$n};function yi(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var mi=yi("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),os=yi("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=ct(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Rf={utf8:mi,"utf-8":mi,hex:ss.base16,latin1:os,ascii:os,binary:os,...ss},$r=Rf;function Y(e,t="utf8"){let r=$r[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function j(e,t="utf8"){let r=$r[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Uf=parseInt("11111",2),is=parseInt("10000000",2),Df=parseInt("01111111",2),gi={0:dr,1:dr,2:Pf,3:Mf,4:Of,5:kf,6:Nf,16:dr,22:dr,48:dr};function Nt(e,t={offset:0}){let r=e[t.offset]&Uf;if(t.offset++,gi[r]!=null)return gi[r](e,t);throw new Error("No decoder for tag "+r)}function pr(e,t){let r=0;if((e[t.offset]&is)===is){let n=e[t.offset]&Df,s="0x";t.offset++;for(let o=0;o<n;o++,t.offset++)s+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(s,16)}else r=e[t.offset],t.offset++;return r}function dr(e,t){pr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Nt(e,t);if(n===null)break;r.push(n)}return r}function Pf(e,t){let r=pr(e,t),n=t.offset,s=t.offset+r,o=[];for(let i=n;i<s;i++)i===n&&e[i]===0||o.push(e[i]);return t.offset+=r,Uint8Array.from(o)}function Nf(e,t){let r=pr(e,t),n=t.offset+r,s=e[t.offset];t.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(;t.offset<n;){let u=e[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let h=0;h<c.length;h++)f+=c[h]<<h*7;a+=`.${f}`,c=[]}}return a}function kf(e,t){return t.offset++,null}function Mf(e,t){let r=pr(e,t),n=e[t.offset];t.offset++;let s=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return s}function Of(e,t){let r=pr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Hf(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new G;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function as(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Hf(e.byteLength);return new G(Uint8Array.from([t.byteLength|is]),t)}function wt(e){let t=new G,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new G(Uint8Array.from([2]),as(t),t)}function Zr(e){let t=Uint8Array.from([0]),r=new G(t,e);return new G(Uint8Array.from([3]),as(r),r)}function Qt(e,t=48){let r=new G;for(let n of e)r.append(n);return new G(Uint8Array.from([t]),as(r),r)}async function bi(e,t,r,n){let s=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let o=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},s,t,r.subarray());return n?.signal?.throwIfAborted(),o}var qf=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Vf=Uint8Array.from([6,5,43,129,4,0,34]),Ff=Uint8Array.from([6,5,43,129,4,0,35]),zf={ext:!0,kty:"EC",crv:"P-256"},Gf={ext:!0,kty:"EC",crv:"P-384"},jf={ext:!0,kty:"EC",crv:"P-521"},cs=32,fs=48,us=66;function xi(e){let t=Nt(e);return wi(t)}function wi(e){let t=e[1][1][0],r=1,n,s;if(t.byteLength===cs*2+1)return n=j(t.subarray(r,r+cs),"base64url"),s=j(t.subarray(r+cs),"base64url"),new Me({...zf,key_ops:["verify"],x:n,y:s});if(t.byteLength===fs*2+1)return n=j(t.subarray(r,r+fs),"base64url"),s=j(t.subarray(r+fs),"base64url"),new Me({...Gf,key_ops:["verify"],x:n,y:s});if(t.byteLength===us*2+1)return n=j(t.subarray(r,r+us),"base64url"),s=j(t.subarray(r+us),"base64url"),new Me({...jf,key_ops:["verify"],x:n,y:s});throw new tt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Ei(e){return Qt([wt(Uint8Array.from([1])),Qt([$f(e.crv)],160),Qt([Zr(new G(Uint8Array.from([4]),Y(e.x??"","base64url"),Y(e.y??"","base64url")))],161)]).subarray()}function $f(e){if(e==="P-256")return qf;if(e==="P-384")return Vf;if(e==="P-521")return Ff;throw new tt(`Invalid curve ${e}`)}var Me=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Ei(this.jwk)),this._raw}toMultihash(){return Rt.digest(te(this))}toCID(){return ht.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:yt(this.raw,t.raw)}async verify(t,r,n){return bi(this.jwk,r,t,n)}};var de=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Mt(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function pe(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function lt(e,...t){if(!Mt(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function me(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");pe(e.outputLen),pe(e.blockLen)}function He(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function vi(e,t){lt(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function _t(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Wr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function It(e,t){return e<<32-t|e>>>t}var Ai=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Zf=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function At(e){if(lt(e),Ai)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Zf[e[r]];return t}var kt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Si(e){if(e>=kt._0&&e<=kt._9)return e-kt._0;if(e>=kt.A&&e<=kt.F)return e-(kt.A-10);if(e>=kt.a&&e<=kt.f)return e-(kt.a-10)}function ye(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Ai)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let s=0,o=0;s<r;s++,o+=2){let i=Si(e.charCodeAt(o)),a=Si(e.charCodeAt(o+1));if(i===void 0||a===void 0){let c=e[o]+e[o+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+o)}n[s]=i*16+a}return n}function hs(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function ee(e){return typeof e=="string"&&(e=hs(e)),lt(e),e}function gt(...e){let t=0;for(let n=0;n<e.length;n++){let s=e[n];lt(s),t+=s.length}let r=new Uint8Array(t);for(let n=0,s=0;n<e.length;n++){let o=e[n];r.set(o,s),s+=o.length}return r}var Oe=class{};function ls(e){let t=n=>e().update(ee(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function re(e=32){if(de&&typeof de.getRandomValues=="function")return de.getRandomValues(new Uint8Array(e));if(de&&typeof de.randomBytes=="function")return Uint8Array.from(de.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function Wf(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let s=BigInt(32),o=BigInt(4294967295),i=Number(r>>s&o),a=Number(r&o),c=n?4:0,u=n?0:4;e.setUint32(t+c,i,n),e.setUint32(t+u,a,n)}function Bi(e,t,r){return e&t^~e&r}function Li(e,t,r){return e&t^e&r^t&r}var mr=class extends Oe{constructor(t,r,n,s){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(t),this.view=Wr(this.buffer)}update(t){He(this),t=ee(t),lt(t);let{view:r,buffer:n,blockLen:s}=this,o=t.length;for(let i=0;i<o;){let a=Math.min(s-this.pos,o-i);if(a===s){let c=Wr(t);for(;s<=o-i;i+=s)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===s&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){He(this),vi(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:s,isLE:o}=this,{pos:i}=this;r[i++]=128,_t(this.buffer.subarray(i)),this.padOffset>s-i&&(this.process(n,0),i=0);for(let h=i;h<s;h++)r[h]=0;Wf(n,s-8,BigInt(this.length*8),o),this.process(n,0);let a=Wr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<u;h++)a.setUint32(4*h,f[h],o)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:s,finished:o,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=o,t.length=s,t.pos=a,s%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Ot=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ft=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Yr=BigInt(4294967295),_i=BigInt(32);function Yf(e,t=!1){return t?{h:Number(e&Yr),l:Number(e>>_i&Yr)}:{h:Number(e>>_i&Yr)|0,l:Number(e&Yr)|0}}function Ii(e,t=!1){let r=e.length,n=new Uint32Array(r),s=new Uint32Array(r);for(let o=0;o<r;o++){let{h:i,l:a}=Yf(e[o],t);[n[o],s[o]]=[i,a]}return[n,s]}var ds=(e,t,r)=>e>>>r,ps=(e,t,r)=>e<<32-r|t>>>r,ge=(e,t,r)=>e>>>r|t<<32-r,be=(e,t,r)=>e<<32-r|t>>>r,yr=(e,t,r)=>e<<64-r|t>>>r-32,gr=(e,t,r)=>e>>>r-32|t<<64-r;function Ut(e,t,r,n){let s=(t>>>0)+(n>>>0);return{h:e+r+(s/2**32|0)|0,l:s|0}}var Ti=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Ci=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Ki=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Ri=(e,t,r,n,s)=>t+r+n+s+(e/2**32|0)|0,Ui=(e,t,r,n,s)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(s>>>0),Di=(e,t,r,n,s,o)=>t+r+n+s+o+(e/2**32|0)|0;var Jf=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]),ne=new Uint32Array(64),Xr=class extends mr{constructor(t=32){super(64,t,8,!1),this.A=Ot[0]|0,this.B=Ot[1]|0,this.C=Ot[2]|0,this.D=Ot[3]|0,this.E=Ot[4]|0,this.F=Ot[5]|0,this.G=Ot[6]|0,this.H=Ot[7]|0}get(){let{A:t,B:r,C:n,D:s,E:o,F:i,G:a,H:c}=this;return[t,r,n,s,o,i,a,c]}set(t,r,n,s,o,i,a,c){this.A=t|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}process(t,r){for(let h=0;h<16;h++,r+=4)ne[h]=t.getUint32(r,!1);for(let h=16;h<64;h++){let l=ne[h-15],d=ne[h-2],p=It(l,7)^It(l,18)^l>>>3,w=It(d,17)^It(d,19)^d>>>10;ne[h]=w+ne[h-7]+p+ne[h-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:u,H:f}=this;for(let h=0;h<64;h++){let l=It(a,6)^It(a,11)^It(a,25),d=f+l+Bi(a,c,u)+Jf[h]+ne[h]|0,w=(It(n,2)^It(n,13)^It(n,22))+Li(n,s,o)|0;f=u,u=c,c=a,a=i+d|0,i=o,o=s,s=n,n=d+w|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(){_t(ne)}destroy(){this.set(0,0,0,0,0,0,0,0),_t(this.buffer)}};var Pi=Ii(["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(e=>BigInt(e))),Qf=Pi[0],tu=Pi[1],se=new Uint32Array(80),oe=new Uint32Array(80),ms=class extends mr{constructor(t=64){super(128,t,16,!1),this.Ah=ft[0]|0,this.Al=ft[1]|0,this.Bh=ft[2]|0,this.Bl=ft[3]|0,this.Ch=ft[4]|0,this.Cl=ft[5]|0,this.Dh=ft[6]|0,this.Dl=ft[7]|0,this.Eh=ft[8]|0,this.El=ft[9]|0,this.Fh=ft[10]|0,this.Fl=ft[11]|0,this.Gh=ft[12]|0,this.Gl=ft[13]|0,this.Hh=ft[14]|0,this.Hl=ft[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:h,Fl:l,Gh:d,Gl:p,Hh:w,Hl:g}=this;return[t,r,n,s,o,i,a,c,u,f,h,l,d,p,w,g]}set(t,r,n,s,o,i,a,c,u,f,h,l,d,p,w,g){this.Ah=t|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=h|0,this.Fl=l|0,this.Gh=d|0,this.Gl=p|0,this.Hh=w|0,this.Hl=g|0}process(t,r){for(let E=0;E<16;E++,r+=4)se[E]=t.getUint32(r),oe[E]=t.getUint32(r+=4);for(let E=16;E<80;E++){let R=se[E-15]|0,k=oe[E-15]|0,O=ge(R,k,1)^ge(R,k,8)^ds(R,k,7),M=be(R,k,1)^be(R,k,8)^ps(R,k,7),P=se[E-2]|0,S=oe[E-2]|0,T=ge(P,S,19)^yr(P,S,61)^ds(P,S,6),U=be(P,S,19)^gr(P,S,61)^ps(P,S,6),C=Ki(M,U,oe[E-7],oe[E-16]),m=Ri(C,O,T,se[E-7],se[E-16]);se[E]=m|0,oe[E]=C|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:h,El:l,Fh:d,Fl:p,Gh:w,Gl:g,Hh:x,Hl:B}=this;for(let E=0;E<80;E++){let R=ge(h,l,14)^ge(h,l,18)^yr(h,l,41),k=be(h,l,14)^be(h,l,18)^gr(h,l,41),O=h&d^~h&w,M=l&p^~l&g,P=Ui(B,k,M,tu[E],oe[E]),S=Di(P,x,R,O,Qf[E],se[E]),T=P|0,U=ge(n,s,28)^yr(n,s,34)^yr(n,s,39),C=be(n,s,28)^gr(n,s,34)^gr(n,s,39),m=n&o^n&a^o&a,y=s&i^s&c^i&c;x=w|0,B=g|0,w=d|0,g=p|0,d=h|0,p=l|0,{h,l}=Ut(u|0,f|0,S|0,T|0),u=a|0,f=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let b=Ti(T,C,y);n=Ci(b,S,U,m),s=b|0}({h:n,l:s}=Ut(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=Ut(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=Ut(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Ut(this.Dh|0,this.Dl|0,u|0,f|0),{h,l}=Ut(this.Eh|0,this.El|0,h|0,l|0),{h:d,l:p}=Ut(this.Fh|0,this.Fl|0,d|0,p|0),{h:w,l:g}=Ut(this.Gh|0,this.Gl|0,w|0,g|0),{h:x,l:B}=Ut(this.Hh|0,this.Hl|0,x|0,B|0),this.set(n,s,o,i,a,c,u,f,h,l,d,p,w,g,x,B)}roundClean(){_t(se,oe)}destroy(){_t(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var ie=ls(()=>new Xr);var Ni=ls(()=>new ms);var bs=BigInt(0),gs=BigInt(1);function Ht(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}"`;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function Et(e,t,r=""){let n=Mt(e),s=e?.length,o=t!==void 0;if(!n||o&&s!==t){let i=r&&`"${r}" `,a=o?` of length ${t}`:"",c=n?`length=${s}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return e}function br(e){let t=e.toString(16);return t.length&1?"0"+t:t}function ki(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?bs:BigInt("0x"+e)}function qe(e){return ki(At(e))}function Bt(e){return lt(e),ki(At(Uint8Array.from(e).reverse()))}function Jr(e,t){return ye(e.toString(16).padStart(t*2,"0"))}function xr(e,t){return Jr(e,t).reverse()}function $(e,t,r){let n;if(typeof t=="string")try{n=ye(t)}catch(o){throw new Error(e+" must be hex string or Uint8Array, cause: "+o)}else if(Mt(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let s=n.length;if(typeof r=="number"&&s!==r)throw new Error(e+" of length "+r+" expected, got "+s);return n}function Mi(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function xs(e){return Uint8Array.from(e)}var ys=e=>typeof e=="bigint"&&bs<=e;function Oi(e,t,r){return ys(e)&&ys(t)&&ys(r)&&t<=e&&e<r}function ae(e,t,r,n){if(!Oi(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Qr(e){let t;for(t=0;e>bs;e>>=gs,t+=1);return t}var ce=e=>(gs<<BigInt(e))-gs;function Hi(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=d=>new Uint8Array(d),s=d=>Uint8Array.of(d),o=n(e),i=n(e),a=0,c=()=>{o.fill(1),i.fill(0),a=0},u=(...d)=>r(i,o,...d),f=(d=n(0))=>{i=u(s(0),d),o=u(),d.length!==0&&(i=u(s(1),d),o=u())},h=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let d=0,p=[];for(;d<t;){o=u();let w=o.slice();p.push(w),d+=o.length}return gt(...p)};return(d,p)=>{c(),f(d);let w;for(;!(w=p(h()));)f();return c(),w}}function Dt(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(s,o,i){let a=e[s];if(i&&a===void 0)return;let c=typeof a;if(c!==o||a===null)throw new Error(`param "${s}" is invalid: expected ${o}, got ${c}`)}Object.entries(t).forEach(([s,o])=>n(s,o,!1)),Object.entries(r).forEach(([s,o])=>n(s,o,!0))}var ws=()=>{throw new Error("not implemented")};function Ve(e){let t=new WeakMap;return(r,...n)=>{let s=t.get(r);if(s!==void 0)return s;let o=e(r,...n);return t.set(r,o),o}}var bt=BigInt(0),ot=BigInt(1),xe=BigInt(2),Fi=BigInt(3),zi=BigInt(4),Gi=BigInt(5),eu=BigInt(7),ji=BigInt(8),ru=BigInt(9),$i=BigInt(16);function X(e,t){let r=e%t;return r>=bt?r:t+r}function J(e,t,r){let n=e;for(;t-- >bt;)n*=n,n%=r;return n}function qi(e,t){if(e===bt)throw new Error("invert: expected non-zero number");if(t<=bt)throw new Error("invert: expected positive modulus, got "+t);let r=X(e,t),n=t,s=bt,o=ot,i=ot,a=bt;for(;r!==bt;){let u=n/r,f=n%r,h=s-i*u,l=o-a*u;n=r,r=f,s=i,o=a,i=h,a=l}if(n!==ot)throw new Error("invert: does not exist");return X(s,t)}function Es(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function Zi(e,t){let r=(e.ORDER+ot)/zi,n=e.pow(t,r);return Es(e,n,t),n}function nu(e,t){let r=(e.ORDER-Gi)/ji,n=e.mul(t,xe),s=e.pow(n,r),o=e.mul(t,s),i=e.mul(e.mul(o,xe),s),a=e.mul(o,e.sub(i,e.ONE));return Es(e,a,t),a}function su(e){let t=St(e),r=Wi(e),n=r(t,t.neg(t.ONE)),s=r(t,n),o=r(t,t.neg(n)),i=(e+eu)/$i;return(a,c)=>{let u=a.pow(c,i),f=a.mul(u,n),h=a.mul(u,s),l=a.mul(u,o),d=a.eql(a.sqr(f),c),p=a.eql(a.sqr(h),c);u=a.cmov(u,f,d),f=a.cmov(l,h,p);let w=a.eql(a.sqr(f),c),g=a.cmov(u,f,w);return Es(a,g,c),g}}function Wi(e){if(e<Fi)throw new Error("sqrt is not defined for small field");let t=e-ot,r=0;for(;t%xe===bt;)t/=xe,r++;let n=xe,s=St(e);for(;Vi(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Zi;let o=s.pow(n,t),i=(t+ot)/xe;return function(c,u){if(c.is0(u))return u;if(Vi(c,u)!==1)throw new Error("Cannot find square root");let f=r,h=c.mul(c.ONE,o),l=c.pow(u,t),d=c.pow(u,i);for(;!c.eql(l,c.ONE);){if(c.is0(l))return c.ZERO;let p=1,w=c.sqr(l);for(;!c.eql(w,c.ONE);)if(p++,w=c.sqr(w),p===f)throw new Error("Cannot find square root");let g=ot<<BigInt(f-p-1),x=c.pow(h,g);f=p,h=c.sqr(x),l=c.mul(l,h),d=c.mul(d,x)}return d}}function ou(e){return e%zi===Fi?Zi:e%ji===Gi?nu:e%$i===ru?su(e):Wi(e)}var qt=(e,t)=>(X(e,t)&ot)===ot,iu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ss(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=iu.reduce((n,s)=>(n[s]="function",n),t);return Dt(e,r),e}function au(e,t,r){if(r<bt)throw new Error("invalid exponent, negatives unsupported");if(r===bt)return e.ONE;if(r===ot)return t;let n=e.ONE,s=t;for(;r>bt;)r&ot&&(n=e.mul(n,s)),s=e.sqr(s),r>>=ot;return n}function wr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),s=t.reduce((i,a,c)=>e.is0(a)?i:(n[c]=i,e.mul(i,a)),e.ONE),o=e.inv(s);return t.reduceRight((i,a,c)=>e.is0(a)?i:(n[c]=e.mul(i,n[c]),e.mul(i,a)),o),n}function Vi(e,t){let r=(e.ORDER-ot)/xe,n=e.pow(t,r),s=e.eql(n,e.ONE),o=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!s&&!o&&!i)throw new Error("invalid Legendre symbol result");return s?1:o?0:-1}function tn(e,t){t!==void 0&&pe(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function St(e,t,r=!1,n={}){if(e<=bt)throw new Error("invalid field: expected ORDER > 0, got "+e);let s,o,i=!1,a;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let l=t;l.BITS&&(s=l.BITS),l.sqrt&&(o=l.sqrt),typeof l.isLE=="boolean"&&(r=l.isLE),typeof l.modFromBytes=="boolean"&&(i=l.modFromBytes),a=l.allowedLengths}else typeof t=="number"&&(s=t),n.sqrt&&(o=n.sqrt);let{nBitLength:c,nByteLength:u}=tn(e,s);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let f,h=Object.freeze({ORDER:e,isLE:r,BITS:c,BYTES:u,MASK:ce(c),ZERO:bt,ONE:ot,allowedLengths:a,create:l=>X(l,e),isValid:l=>{if(typeof l!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof l);return bt<=l&&l<e},is0:l=>l===bt,isValidNot0:l=>!h.is0(l)&&h.isValid(l),isOdd:l=>(l&ot)===ot,neg:l=>X(-l,e),eql:(l,d)=>l===d,sqr:l=>X(l*l,e),add:(l,d)=>X(l+d,e),sub:(l,d)=>X(l-d,e),mul:(l,d)=>X(l*d,e),pow:(l,d)=>au(h,l,d),div:(l,d)=>X(l*qi(d,e),e),sqrN:l=>l*l,addN:(l,d)=>l+d,subN:(l,d)=>l-d,mulN:(l,d)=>l*d,inv:l=>qi(l,e),sqrt:o||(l=>(f||(f=ou(e)),f(h,l))),toBytes:l=>r?xr(l,u):Jr(l,u),fromBytes:(l,d=!0)=>{if(a){if(!a.includes(l.length)||l.length>u)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+l.length);let w=new Uint8Array(u);w.set(l,r?0:w.length-l.length),l=w}if(l.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+l.length);let p=r?Bt(l):qe(l);if(i&&(p=X(p,e)),!d&&!h.isValid(p))throw new Error("invalid field element: outside of range 0..ORDER");return p},invertBatch:l=>wr(h,l),cmov:(l,d,p)=>p?d:l});return Object.freeze(h)}function Yi(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function vs(e){let t=Yi(e);return t+Math.ceil(t/2)}function As(e,t,r=!1){let n=e.length,s=Yi(t),o=vs(t);if(n<16||n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);let i=r?Bt(e):qe(e),a=X(i,t-ot)+ot;return r?xr(a,s):Jr(a,s)}var Fe=BigInt(0),we=BigInt(1);function Er(e,t){let r=t.negate();return e?r:t}function Vt(e,t){let r=wr(e.Fp,t.map(n=>n.Z));return t.map((n,s)=>e.fromAffine(n.toAffine(r[s])))}function ta(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Bs(e,t){ta(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),s=2**e,o=ce(e),i=BigInt(e);return{windows:r,windowSize:n,mask:o,maxNumber:s,shiftBy:i}}function Xi(e,t,r){let{windowSize:n,mask:s,maxNumber:o,shiftBy:i}=r,a=Number(e&s),c=e>>i;a>n&&(a-=o,c+=we);let u=t*n,f=u+Math.abs(a)-1,h=a===0,l=a<0,d=t%2!==0;return{nextN:c,offset:f,isZero:h,isNeg:l,isNegF:d,offsetF:u}}function cu(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function fu(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var Ls=new WeakMap,ea=new WeakMap;function _s(e){return ea.get(e)||1}function Ji(e){if(e!==Fe)throw new Error("invalid wNAF")}var ze=class{constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let s=t;for(;r>Fe;)r&we&&(n=n.add(s)),s=s.double(),r>>=we;return n}precomputeWindow(t,r){let{windows:n,windowSize:s}=Bs(r,this.bits),o=[],i=t,a=i;for(let c=0;c<n;c++){a=i,o.push(a);for(let u=1;u<s;u++)a=a.add(i),o.push(a);i=a.double()}return o}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let s=this.ZERO,o=this.BASE,i=Bs(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:f,isNeg:h,isNegF:l,offsetF:d}=Xi(n,a,i);n=c,f?o=o.add(Er(l,r[d])):s=s.add(Er(h,r[u]))}return Ji(n),{p:s,f:o}}wNAFUnsafe(t,r,n,s=this.ZERO){let o=Bs(t,this.bits);for(let i=0;i<o.windows&&n!==Fe;i++){let{nextN:a,offset:c,isZero:u,isNeg:f}=Xi(n,i,o);if(n=a,!u){let h=r[c];s=s.add(f?h.negate():h)}}return Ji(n),s}getPrecomputes(t,r,n){let s=Ls.get(r);return s||(s=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(s=n(s)),Ls.set(r,s))),s}cached(t,r,n){let s=_s(t);return this.wNAF(s,this.getPrecomputes(s,t,n),r)}unsafe(t,r,n,s){let o=_s(t);return o===1?this._unsafeLadder(t,r,s):this.wNAFUnsafe(o,this.getPrecomputes(o,t,n),r,s)}createCache(t,r){ta(r,this.bits),ea.set(t,r),Ls.delete(t)}hasCache(t){return _s(t)!==1}};function ra(e,t,r,n){let s=t,o=e.ZERO,i=e.ZERO;for(;r>Fe||n>Fe;)r&we&&(o=o.add(s)),n&we&&(i=i.add(s)),s=s.double(),r>>=we,n>>=we;return{p1:o,p2:i}}function Ge(e,t,r,n){cu(r,e),fu(n,t);let s=r.length,o=n.length;if(s!==o)throw new Error("arrays of points and scalars must have equal length");let i=e.ZERO,a=Qr(BigInt(s)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let u=ce(c),f=new Array(Number(u)+1).fill(i),h=Math.floor((t.BITS-1)/c)*c,l=i;for(let d=h;d>=0;d-=c){f.fill(i);for(let w=0;w<o;w++){let g=n[w],x=Number(g>>BigInt(d)&u);f[x]=f[x].add(r[w])}let p=i;for(let w=f.length-1,g=i;w>0;w--)g=g.add(f[w]),p=p.add(g);if(l=l.add(p),d!==0)for(let w=0;w<c;w++)l=l.double()}return l}function Qi(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Ss(t),t}else return St(e,{isLE:r})}function en(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let c of["p","n","h"]){let u=t[c];if(!(typeof u=="bigint"&&u>Fe))throw new Error(`CURVE.${c} must be positive bigint`)}let s=Qi(t.p,r.Fp,n),o=Qi(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let c of a)if(!s.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:s,Fn:o}}var fe=BigInt(0),it=BigInt(1),Is=BigInt(2),uu=BigInt(8);function hu(e,t,r,n){let s=e.sqr(r),o=e.sqr(n),i=e.add(e.mul(t.a,s),o),a=e.add(e.ONE,e.mul(t.d,e.mul(s,o)));return e.eql(i,a)}function lu(e,t={}){let r=en("edwards",e,t,t.FpFnLE),{Fp:n,Fn:s}=r,o=r.CURVE,{h:i}=o;Dt(t,{},{uvRatio:"function"});let a=Is<<BigInt(s.BYTES*8)-it,c=g=>n.create(g),u=t.uvRatio||((g,x)=>{try{return{isValid:!0,value:n.sqrt(n.div(g,x))}}catch{return{isValid:!1,value:fe}}});if(!hu(n,o,o.Gx,o.Gy))throw new Error("bad curve params: generator point");function f(g,x,B=!1){let E=B?it:fe;return ae("coordinate "+g,x,E,a),x}function h(g){if(!(g instanceof p))throw new Error("ExtendedPoint expected")}let l=Ve((g,x)=>{let{X:B,Y:E,Z:R}=g,k=g.is0();x==null&&(x=k?uu:n.inv(R));let O=c(B*x),M=c(E*x),P=n.mul(R,x);if(k)return{x:fe,y:it};if(P!==it)throw new Error("invZ was invalid");return{x:O,y:M}}),d=Ve(g=>{let{a:x,d:B}=o;if(g.is0())throw new Error("bad point: ZERO");let{X:E,Y:R,Z:k,T:O}=g,M=c(E*E),P=c(R*R),S=c(k*k),T=c(S*S),U=c(M*x),C=c(S*c(U+P)),m=c(T+c(B*c(M*P)));if(C!==m)throw new Error("bad point: equation left != right (1)");let y=c(E*R),b=c(k*O);if(y!==b)throw new Error("bad point: equation left != right (2)");return!0});class p{constructor(x,B,E,R){this.X=f("x",x),this.Y=f("y",B),this.Z=f("z",E,!0),this.T=f("t",R),Object.freeze(this)}static CURVE(){return o}static fromAffine(x){if(x instanceof p)throw new Error("extended point not allowed");let{x:B,y:E}=x||{};return f("x",B),f("y",E),new p(B,E,it,c(B*E))}static fromBytes(x,B=!1){let E=n.BYTES,{a:R,d:k}=o;x=xs(Et(x,E,"point")),Ht(B,"zip215");let O=xs(x),M=x[E-1];O[E-1]=M&-129;let P=Bt(O),S=B?a:n.ORDER;ae("point.y",P,fe,S);let T=c(P*P),U=c(T-it),C=c(k*T-R),{isValid:m,value:y}=u(U,C);if(!m)throw new Error("bad point: invalid y coordinate");let b=(y&it)===it,A=(M&128)!==0;if(!B&&y===fe&&A)throw new Error("bad point: x=0 and x_0=1");return A!==b&&(y=c(-y)),p.fromAffine({x:y,y:P})}static fromHex(x,B=!1){return p.fromBytes($("point",x),B)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(x=8,B=!0){return w.createCache(this,x),B||this.multiply(Is),this}assertValidity(){d(this)}equals(x){h(x);let{X:B,Y:E,Z:R}=this,{X:k,Y:O,Z:M}=x,P=c(B*M),S=c(k*R),T=c(E*M),U=c(O*R);return P===S&&T===U}is0(){return this.equals(p.ZERO)}negate(){return new p(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:x}=o,{X:B,Y:E,Z:R}=this,k=c(B*B),O=c(E*E),M=c(Is*c(R*R)),P=c(x*k),S=B+E,T=c(c(S*S)-k-O),U=P+O,C=U-M,m=P-O,y=c(T*C),b=c(U*m),A=c(T*m),L=c(C*U);return new p(y,b,L,A)}add(x){h(x);let{a:B,d:E}=o,{X:R,Y:k,Z:O,T:M}=this,{X:P,Y:S,Z:T,T:U}=x,C=c(R*P),m=c(k*S),y=c(M*E*U),b=c(O*T),A=c((R+k)*(P+S)-C-m),L=b-y,I=b+y,v=c(m-B*C),_=c(A*L),K=c(I*v),D=c(A*v),q=c(L*I);return new p(_,K,q,D)}subtract(x){return this.add(x.negate())}multiply(x){if(!s.isValidNot0(x))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:B,f:E}=w.cached(this,x,R=>Vt(p,R));return Vt(p,[B,E])[0]}multiplyUnsafe(x,B=p.ZERO){if(!s.isValid(x))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return x===fe?p.ZERO:this.is0()||x===it?this:w.unsafe(this,x,E=>Vt(p,E),B)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return w.unsafe(this,o.n).is0()}toAffine(x){return l(this,x)}clearCofactor(){return i===it?this:this.multiplyUnsafe(i)}toBytes(){let{x,y:B}=this.toAffine(),E=n.toBytes(B);return E[E.length-1]|=x&it?128:0,E}toHex(){return At(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(x){return Vt(p,x)}static msm(x,B){return Ge(p,s,x,B)}_setWindowSize(x){this.precompute(x)}toRawBytes(){return this.toBytes()}}p.BASE=new p(o.Gx,o.Gy,it,c(o.Gx*o.Gy)),p.ZERO=new p(fe,it,it,fe),p.Fp=n,p.Fn=s;let w=new ze(p,s.BITS);return p.BASE.precompute(8),p}var rn=class{constructor(t){this.ep=t}static fromBytes(t){ws()}static fromHex(t){ws()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return At(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,r){return this.init(this.ep.precompute(t,r))}toRawBytes(){return this.toBytes()}};function du(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');Dt(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:s,Fp:o,Fn:i}=e,a=r.randomBytes||re,c=r.adjustScalarBytes||(S=>S),u=r.domain||((S,T,U)=>{if(Ht(U,"phflag"),T.length||U)throw new Error("Contexts/pre-hash are not supported");return S});function f(S){return i.create(Bt(S))}function h(S){let T=E.secretKey;S=$("private key",S,T);let U=$("hashed private key",t(S),2*T),C=c(U.slice(0,T)),m=U.slice(T,2*T),y=f(C);return{head:C,prefix:m,scalar:y}}function l(S){let{head:T,prefix:U,scalar:C}=h(S),m=s.multiply(C),y=m.toBytes();return{head:T,prefix:U,scalar:C,point:m,pointBytes:y}}function d(S){return l(S).pointBytes}function p(S=Uint8Array.of(),...T){let U=gt(...T);return f(t(u(U,$("context",S),!!n)))}function w(S,T,U={}){S=$("message",S),n&&(S=n(S));let{prefix:C,scalar:m,pointBytes:y}=l(T),b=p(U.context,C,S),A=s.multiply(b).toBytes(),L=p(U.context,A,y,S),I=i.create(b+L*m);if(!i.isValid(I))throw new Error("sign failed: invalid s");let v=gt(A,i.toBytes(I));return Et(v,E.signature,"result")}let g={zip215:!0};function x(S,T,U,C=g){let{context:m,zip215:y}=C,b=E.signature;S=$("signature",S,b),T=$("message",T),U=$("publicKey",U,E.publicKey),y!==void 0&&Ht(y,"zip215"),n&&(T=n(T));let A=b/2,L=S.subarray(0,A),I=Bt(S.subarray(A,b)),v,_,K;try{v=e.fromBytes(U,y),_=e.fromBytes(L,y),K=s.multiplyUnsafe(I)}catch{return!1}if(!y&&v.isSmallOrder())return!1;let D=p(m,_.toBytes(),v.toBytes(),T);return _.add(v.multiplyUnsafe(D)).subtract(K).clearCofactor().is0()}let B=o.BYTES,E={secretKey:B,publicKey:B,signature:2*B,seed:B};function R(S=a(E.seed)){return Et(S,E.seed,"seed")}function k(S){let T=P.randomSecretKey(S);return{secretKey:T,publicKey:d(T)}}function O(S){return Mt(S)&&S.length===i.BYTES}function M(S,T){try{return!!e.fromBytes(S,T)}catch{return!1}}let P={getExtendedPublicKey:l,randomSecretKey:R,isValidSecretKey:O,isValidPublicKey:M,toMontgomery(S){let{y:T}=e.fromBytes(S),U=E.publicKey,C=U===32;if(!C&&U!==57)throw new Error("only defined for 25519 and 448");let m=C?o.div(it+T,it-T):o.div(T-it,T+it);return o.toBytes(m)},toMontgomerySecret(S){let T=E.secretKey;Et(S,T);let U=t(S.subarray(0,T));return c(U).subarray(0,T)},randomPrivateKey:R,precompute(S=8,T=e.BASE){return T.precompute(S,!1)}};return Object.freeze({keygen:k,getPublicKey:d,sign:w,verify:x,utils:P,Point:e,lengths:E})}function pu(e){let t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=St(t.n,e.nBitLength,!0),s={Fp:r,Fn:n,uvRatio:e.uvRatio},o={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:s,hash:e.hash,eddsaOpts:o}}function mu(e,t){let r=t.Point;return Object.assign({},t,{ExtendedPoint:r,CURVE:e,nBitLength:r.Fn.BITS,nByteLength:r.Fn.BYTES})}function na(e){let{CURVE:t,curveOpts:r,hash:n,eddsaOpts:s}=pu(e),o=lu(t,r),i=du(o,n,s);return mu(e,i)}var Sr=BigInt(0),je=BigInt(1),nn=BigInt(2);function yu(e){return Dt(e,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...e})}function sa(e){let t=yu(e),{P:r,type:n,adjustScalarBytes:s,powPminus2:o,randomBytes:i}=t,a=n==="x25519";if(!a&&n!=="x448")throw new Error("invalid type");let c=i||re,u=a?255:448,f=a?32:56,h=BigInt(a?9:5),l=BigInt(a?121665:39081),d=a?nn**BigInt(254):nn**BigInt(447),p=a?BigInt(8)*nn**BigInt(251)-je:BigInt(4)*nn**BigInt(445)-je,w=d+p+je,g=m=>X(m,r),x=B(h);function B(m){return xr(g(m),f)}function E(m){let y=$("u coordinate",m,f);return a&&(y[31]&=127),g(Bt(y))}function R(m){return Bt(s($("scalar",m,f)))}function k(m,y){let b=P(E(y),R(m));if(b===Sr)throw new Error("invalid private or public key received");return B(b)}function O(m){return k(m,x)}function M(m,y,b){let A=g(m*(y-b));return y=g(y-A),b=g(b+A),{x_2:y,x_3:b}}function P(m,y){ae("u",m,Sr,r),ae("scalar",y,d,w);let b=y,A=m,L=je,I=Sr,v=m,_=je,K=Sr;for(let q=BigInt(u-1);q>=Sr;q--){let V=b>>q&je;K^=V,{x_2:L,x_3:v}=M(K,L,v),{x_2:I,x_3:_}=M(K,I,_),K=V;let H=L+I,F=g(H*H),Z=L-I,Q=g(Z*Z),z=F-Q,st=v+_,Ie=v-_,ir=g(Ie*H),ar=g(st*Z),Go=ir+ar,jo=ir-ar;v=g(Go*Go),_=g(A*g(jo*jo)),L=g(F*Q),I=g(z*(F+g(l*z)))}({x_2:L,x_3:v}=M(K,L,v)),{x_2:I,x_3:_}=M(K,I,_);let D=o(I);return g(L*D)}let S={secretKey:f,publicKey:f,seed:f},T=(m=c(f))=>(lt(m,S.seed),m);function U(m){let y=T(m);return{secretKey:y,publicKey:O(y)}}return{keygen:U,getSharedSecret:(m,y)=>k(m,y),getPublicKey:m=>O(m),scalarMult:k,scalarMultBase:O,utils:{randomSecretKey:T,randomPrivateKey:T},GuBytes:x.slice(),lengths:S}}var gu=BigInt(0),zt=BigInt(1),oa=BigInt(2),bu=BigInt(3),xu=BigInt(5),wu=BigInt(8),$e=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),vr={p:$e,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:wu,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function ca(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),s=BigInt(80),o=$e,a=e*e%o*e%o,c=J(a,oa,o)*a%o,u=J(c,zt,o)*e%o,f=J(u,xu,o)*u%o,h=J(f,t,o)*f%o,l=J(h,r,o)*h%o,d=J(l,n,o)*l%o,p=J(d,s,o)*d%o,w=J(p,s,o)*d%o,g=J(w,t,o)*f%o;return{pow_p_5_8:J(g,oa,o)*e%o,b2:a}}function fa(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Ts=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Rs(e,t){let r=$e,n=X(t*t*t,r),s=X(n*n*t,r),o=ca(e*s).pow_p_5_8,i=X(e*n*o,r),a=X(t*i*i,r),c=i,u=X(i*Ts,r),f=a===e,h=a===X(-e,r),l=a===X(-e*Ts,r);return f&&(i=c),(h||l)&&(i=u),qt(i,r)&&(i=X(-i,r)),{isValid:f||h,value:i}}var Ft=St(vr.p,{isLE:!0}),Eu=St(vr.n,{isLE:!0}),Su={...vr,Fp:Ft,hash:Ni,adjustScalarBytes:fa,uvRatio:Rs},Gt=na(Su);var Ar=(()=>{let e=Ft.ORDER;return sa({P:e,type:"x25519",powPminus2:t=>{let{pow_p_5_8:r,b2:n}=ca(t);return X(J(r,bu,e)*n,e)},adjustScalarBytes:fa})})();var Cs=Ts,vu=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Au=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Bu=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Lu=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),ia=e=>Rs(zt,e),_u=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Ks=e=>Gt.Point.Fp.create(Bt(e)&_u);function aa(e){let{d:t}=vr,r=$e,n=x=>Ft.create(x),s=n(Cs*e*e),o=n((s+zt)*Bu),i=BigInt(-1),a=n((i-t*s)*n(s+t)),{isValid:c,value:u}=Rs(o,a),f=n(u*e);qt(f,r)||(f=n(-f)),c||(u=f),c||(i=s);let h=n(i*(s-zt)*Lu-a),l=u*u,d=n((u+u)*a),p=n(h*vu),w=n(zt-l),g=n(zt+l);return new Gt.Point(n(d*g),n(w*p),n(p*g),n(d*w))}function Iu(e){lt(e,64);let t=Ks(e.subarray(0,32)),r=aa(t),n=Ks(e.subarray(32,64)),s=aa(n);return new jt(r.add(s))}var jt=class e extends rn{constructor(t){super(t)}static fromAffine(t){return new e(Gt.Point.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static hashToCurve(t){return Iu($("ristrettoHash",t,64))}static fromBytes(t){lt(t,32);let{a:r,d:n}=vr,s=$e,o=R=>Ft.create(R),i=Ks(t);if(!Mi(Ft.toBytes(i),t)||qt(i,s))throw new Error("invalid ristretto255 encoding 1");let a=o(i*i),c=o(zt+r*a),u=o(zt-r*a),f=o(c*c),h=o(u*u),l=o(r*n*f-h),{isValid:d,value:p}=ia(o(l*h)),w=o(p*u),g=o(p*w*l),x=o((i+i)*w);qt(x,s)&&(x=o(-x));let B=o(c*g),E=o(x*B);if(!d||qt(E,s)||B===gu)throw new Error("invalid ristretto255 encoding 2");return new e(new Gt.Point(x,B,zt,E))}static fromHex(t){return e.fromBytes($("ristrettoHex",t,32))}static msm(t,r){return Ge(e,Gt.Point.Fn,t,r)}toBytes(){let{X:t,Y:r,Z:n,T:s}=this.ep,o=$e,i=g=>Ft.create(g),a=i(i(n+r)*i(n-r)),c=i(t*r),u=i(c*c),{value:f}=ia(i(a*u)),h=i(f*a),l=i(f*c),d=i(h*l*s),p;if(qt(s*d,o)){let g=i(r*Cs),x=i(t*Cs);t=g,r=x,p=i(h*Au)}else p=l;qt(t*d,o)&&(r=i(-r));let w=i((n-r)*p);return qt(w,o)&&(w=i(-w)),Ft.toBytes(w)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:s,Y:o}=t.ep,i=u=>Ft.create(u),a=i(r*o)===i(n*s),c=i(n*o)===i(r*s);return a||c}is0(){return this.equals(e.ZERO)}};jt.BASE=new jt(Gt.Point.BASE);jt.ZERO=new jt(Gt.Point.ZERO);jt.Fp=Ft;jt.Fn=Eu;var Br=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},sn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var ua={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new sn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var Lt=ua;var on=32;var Us,Tu=(async()=>{try{return await Lt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Cu(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Lt.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Lt.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Ku(e,t,r){return Gt.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function ha(e,t,r){return Us==null&&(Us=await Tu),Us?Cu(e,t,r):Ku(e,t,r)}function an(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var cn=class{type="Ed25519";raw;constructor(t){this.raw=Ds(t,on)}toMultihash(){return Rt.digest(te(this))}toCID(){return ht.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:yt(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let s=ha(this.raw,r,t);return an(s)?s.then(o=>(n?.signal?.throwIfAborted(),o)):s}};function da(e){return e=Ds(e,on),new cn(e)}function Ds(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new tt(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Uu=Math.pow(2,7),Du=Math.pow(2,14),Pu=Math.pow(2,21),Ps=Math.pow(2,28),Ns=Math.pow(2,35),ks=Math.pow(2,42),Ms=Math.pow(2,49),W=128,dt=127;function Tt(e){if(e<Uu)return 1;if(e<Du)return 2;if(e<Pu)return 3;if(e<Ps)return 4;if(e<Ns)return 5;if(e<ks)return 6;if(e<Ms)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Os(e,t,r=0){switch(Tt(e)){case 8:t[r++]=e&255|W,e/=128;case 7:t[r++]=e&255|W,e/=128;case 6:t[r++]=e&255|W,e/=128;case 5:t[r++]=e&255|W,e/=128;case 4:t[r++]=e&255|W,e>>>=7;case 3:t[r++]=e&255|W,e>>>=7;case 2:t[r++]=e&255|W,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Nu(e,t,r=0){switch(Tt(e)){case 8:t.set(r++,e&255|W),e/=128;case 7:t.set(r++,e&255|W),e/=128;case 6:t.set(r++,e&255|W),e/=128;case 5:t.set(r++,e&255|W),e/=128;case 4:t.set(r++,e&255|W),e>>>=7;case 3:t.set(r++,e&255|W),e>>>=7;case 2:t.set(r++,e&255|W),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function Hs(e,t){let r=e[t],n=0;if(n+=r&dt,r<W||(r=e[t+1],n+=(r&dt)<<7,r<W)||(r=e[t+2],n+=(r&dt)<<14,r<W)||(r=e[t+3],n+=(r&dt)<<21,r<W)||(r=e[t+4],n+=(r&dt)*Ps,r<W)||(r=e[t+5],n+=(r&dt)*Ns,r<W)||(r=e[t+6],n+=(r&dt)*ks,r<W)||(r=e[t+7],n+=(r&dt)*Ms,r<W))return n;throw new RangeError("Could not decode varint")}function ku(e,t){let r=e.get(t),n=0;if(n+=r&dt,r<W||(r=e.get(t+1),n+=(r&dt)<<7,r<W)||(r=e.get(t+2),n+=(r&dt)<<14,r<W)||(r=e.get(t+3),n+=(r&dt)<<21,r<W)||(r=e.get(t+4),n+=(r&dt)*Ps,r<W)||(r=e.get(t+5),n+=(r&dt)*Ns,r<W)||(r=e.get(t+6),n+=(r&dt)*ks,r<W)||(r=e.get(t+7),n+=(r&dt)*Ms,r<W))return n;throw new RangeError("Could not decode varint")}function pa(e,t,r=0){return t==null&&(t=ct(Tt(e))),t instanceof Uint8Array?Os(e,t,r):Nu(e,t,r)}function fn(e,t=0){return e instanceof Uint8Array?Hs(e,t):ku(e,t)}var qs=new Float32Array([-0]),ue=new Uint8Array(qs.buffer);function ya(e,t,r){qs[0]=e,t[r]=ue[0],t[r+1]=ue[1],t[r+2]=ue[2],t[r+3]=ue[3]}function ga(e,t){return ue[0]=e[t],ue[1]=e[t+1],ue[2]=e[t+2],ue[3]=e[t+3],qs[0]}var Vs=new Float64Array([-0]),pt=new Uint8Array(Vs.buffer);function ba(e,t,r){Vs[0]=e,t[r]=pt[0],t[r+1]=pt[1],t[r+2]=pt[2],t[r+3]=pt[3],t[r+4]=pt[4],t[r+5]=pt[5],t[r+6]=pt[6],t[r+7]=pt[7]}function xa(e,t){return pt[0]=e[t],pt[1]=e[t+1],pt[2]=e[t+2],pt[3]=e[t+3],pt[4]=e[t+4],pt[5]=e[t+5],pt[6]=e[t+6],pt[7]=e[t+7],Vs[0]}var Mu=BigInt(Number.MAX_SAFE_INTEGER),Ou=BigInt(Number.MIN_SAFE_INTEGER),vt=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&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(t=!1){if(t)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(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return Ee;if(t<Mu&&t>Ou)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,s=t-(n<<32n);return r&&(n=~n|0n,s=~s|0n,++s>wa&&(s=0n,++n>wa&&(n=0n))),new e(Number(s),Number(n))}static fromNumber(t){if(t===0)return Ee;let r=t<0;r&&(t=-t);let n=t>>>0,s=(t-n)/4294967296>>>0;return r&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new e(n,s)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):Ee}},Ee=new vt(0,0);Ee.toBigInt=function(){return 0n};Ee.zzEncode=Ee.zzDecode=function(){return this};Ee.length=function(){return 1};var wa=4294967296n;function Ea(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Sa(e,t,r){if(r-t<1)return"";let s,o=[],i=0,a;for(;t<r;)a=e[t++],a<128?o[i++]=a:a>191&&a<224?o[i++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,o[i++]=55296+(a>>10),o[i++]=56320+(a&1023)):o[i++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&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 Fs(e,t,r){let n=r,s,o;for(let i=0;i<e.length;++i)s=e.charCodeAt(i),s<128?t[r++]=s:s<2048?(t[r++]=s>>6|192,t[r++]=s&63|128):(s&64512)===55296&&((o=e.charCodeAt(i+1))&64512)===56320?(s=65536+((s&1023)<<10)+(o&1023),++i,t[r++]=s>>18|240,t[r++]=s>>12&63|128,t[r++]=s>>6&63|128,t[r++]=s&63|128):(t[r++]=s>>12|224,t[r++]=s>>6&63|128,t[r++]=s&63|128);return r-n}function Ct(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function un(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var zs=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Ct(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ct(this,4);return un(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ct(this,4);return un(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ct(this,4);let t=ga(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Ct(this,4);let t=xa(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Ct(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Sa(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Ct(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Ct(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new vt(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Ct(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Ct(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ct(this,8);let t=un(this.buf,this.pos+=4),r=un(this.buf,this.pos+=4);return new vt(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Hs(this.buf,this.pos);return this.pos+=Tt(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Gs(e){return new zs(e instanceof Uint8Array?e:e.subarray())}function Se(e,t,r){let n=Gs(e);return t.decode(n,void 0,r)}function js(e){let t=e??8192,r=t>>>1,n,s=t;return function(i){if(i<1||i>r)return ct(i);s+i>t&&(n=ct(t),s=0);let a=n.subarray(s,s+=i);return(s&7)!==0&&(s=(s|7)+1),a}}var ve=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function $s(){}var Ws=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Hu=js();function qu(e){return globalThis.Buffer!=null?ct(e):Hu(e)}var _r=class{len;head;tail;states;constructor(){this.len=0,this.head=new ve($s,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new ve(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Ys((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(hn,10,vt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=vt.fromBigInt(t);return this._push(hn,r.length(),r)}uint64Number(t){return this._push(Os,Tt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=vt.fromBigInt(t).zzEncode();return this._push(hn,r.length(),r)}sint64Number(t){let r=vt.fromNumber(t).zzEncode();return this._push(hn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Zs,1,t?1:0)}fixed32(t){return this._push(Lr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=vt.fromBigInt(t);return this._push(Lr,4,r.lo)._push(Lr,4,r.hi)}fixed64Number(t){let r=vt.fromNumber(t);return this._push(Lr,4,r.lo)._push(Lr,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(ya,4,t)}double(t){return this._push(ba,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Zs,1,0):this.uint32(r)._push(Fu,r,t)}string(t){let r=Ea(t);return r!==0?this.uint32(r)._push(Fs,r,t):this._push(Zs,1,0)}fork(){return this.states=new Ws(this),this.head=this.tail=new ve($s,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 ve($s,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=qu(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Zs(e,t,r){t[r]=e&255}function Vu(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Ys=class extends ve{next;constructor(t,r){super(Vu,t,r),this.next=void 0}};function hn(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function Lr(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function Fu(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(_r.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(zu,t,e),this},_r.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Gu,t,e),this});function zu(e,t,r){t.set(e,r)}function Gu(e,t,r){e.length<40?Fs(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(Y(e),r)}function Xs(){return new _r}function Ae(e,t){let r=Xs();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var Ze;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(Ze||(Ze={}));function ln(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function Js(e){function t(s){if(e[s.toString()]==null)throw new Error("Invalid enum value");return e[s]}let r=function(o,i){let a=t(o);i.int32(a)},n=function(o){let i=o.int32();return t(i)};return ln("enum",Ze.VARINT,r,n)}function Be(e,t){return ln("message",Ze.LENGTH_DELIMITED,e,t)}var Ir=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var at;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(at||(at={}));var Qs;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Qs||(Qs={}));(function(e){e.codec=()=>Js(Qs)})(at||(at={}));var $t;(function(e){let t;e.codec=()=>(t==null&&(t=Be((r,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),at.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),s.lengthDelimited!==!1&&n.ldelim()},(r,n,s={})=>{let o={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{o.Type=at.codec().decode(r);break}case 2:{o.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return o})),t),e.encode=r=>Ae(r,e.codec()),e.decode=(r,n)=>Se(r,e.codec(),n)})($t||($t={}));var to;(function(e){let t;e.codec=()=>(t==null&&(t=Be((r,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),at.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),s.lengthDelimited!==!1&&n.ldelim()},(r,n,s={})=>{let o={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{o.Type=at.codec().decode(r);break}case 2:{o.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return o})),t),e.encode=r=>Ae(r,e.codec()),e.decode=(r,n)=>Se(r,e.codec(),n)})(to||(to={}));var Cr={};xt(Cr,{MAX_RSA_KEY_SIZE:()=>eo,generateRSAKeyPair:()=>Ia,jwkToJWKKeyPair:()=>Ta,jwkToPkcs1:()=>Wu,jwkToPkix:()=>oo,jwkToRSAPrivateKey:()=>fo,pkcs1MessageToJwk:()=>no,pkcs1MessageToRSAPrivateKey:()=>io,pkcs1ToJwk:()=>Zu,pkcs1ToRSAPrivateKey:()=>_a,pkixMessageToJwk:()=>so,pkixMessageToRSAPublicKey:()=>co,pkixToJwk:()=>Yu,pkixToRSAPublicKey:()=>ao});var dn=ie;var We=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Cr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ht.createV1(114,this._multihash)}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:yt(this.raw,t.raw)}verify(t,r,n){return La(this.jwk,r,t,n)}},Tr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Cr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:yt(this.raw,t.raw)}sign(t,r){return Ba(this.jwk,t,r)}};var eo=8192,ro=18,ju=1062,$u=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Zu(e){let t=Nt(e);return no(t)}function no(e){return{n:j(e[1],"base64url"),e:j(e[2],"base64url"),d:j(e[3],"base64url"),p:j(e[4],"base64url"),q:j(e[5],"base64url"),dp:j(e[6],"base64url"),dq:j(e[7],"base64url"),qi:j(e[8],"base64url"),kty:"RSA"}}function Wu(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new tt("JWK was missing components");return Qt([wt(Uint8Array.from([0])),wt(Y(e.n,"base64url")),wt(Y(e.e,"base64url")),wt(Y(e.d,"base64url")),wt(Y(e.p,"base64url")),wt(Y(e.q,"base64url")),wt(Y(e.dp,"base64url")),wt(Y(e.dq,"base64url")),wt(Y(e.qi,"base64url"))]).subarray()}function Yu(e){let t=Nt(e,{offset:0});return so(t)}function so(e){let t=Nt(e[1],{offset:0});return{kty:"RSA",n:j(t[0],"base64url"),e:j(t[1],"base64url")}}function oo(e){if(e.n==null||e.e==null)throw new tt("JWK was missing components");return Qt([$u,Zr(Qt([wt(Y(e.n,"base64url")),wt(Y(e.e,"base64url"))]))]).subarray()}function _a(e){let t=Nt(e);return io(t)}function io(e){let t=no(e);return fo(t)}function ao(e,t){if(e.byteLength>=ju)throw new Te("Key size is too large");let r=Nt(e,{offset:0});return co(r,e,t)}function co(e,t,r){let n=so(e);if(r==null){let s=dn($t.encode({Type:at.RSA,Data:t}));r=Kt(ro,s)}return new We(n,r)}function fo(e){if(Ka(e)>eo)throw new tt("Key size is too large");let t=Ta(e),r=dn($t.encode({Type:at.RSA,Data:oo(t.publicKey)})),n=Kt(ro,r);return new Tr(t.privateKey,new We(t.publicKey,n))}async function Ia(e){if(e>eo)throw new tt("Key size is too large");let t=await Ca(e),r=dn($t.encode({Type:at.RSA,Data:oo(t.publicKey)})),n=Kt(ro,r);return new Tr(t.privateKey,new We(t.publicKey,n))}function Ta(e){if(e==null)throw new tt("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function Ca(e,t){let r=await Lt.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await Xu(r,t);return{privateKey:n[0],publicKey:n[1]}}async function Ba(e,t,r){let n=await Lt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let s=await Lt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(s,0,s.byteLength)}async function La(e,t,r,n){let s=await Lt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let o=await Lt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},s,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),o}async function Xu(e,t){if(e.privateKey==null||e.publicKey==null)throw new tt("Private and public key are required");let r=await Promise.all([Lt.get().subtle.exportKey("jwk",e.privateKey),Lt.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function Ka(e){if(e.kty!=="RSA")throw new tt("invalid key type");if(e.n==null)throw new tt("invalid key modulus");return Y(e.n,"base64url").length*8}var pn=class extends Oe{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,me(t);let n=ee(r);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let s=this.blockLen,o=new Uint8Array(s);o.set(n.length>s?t.create().update(n).digest():n);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=t.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),_t(o)}update(t){return He(this),this.iHash.update(t),this}digestInto(t){He(this),lt(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:s,destroyed:o,blockLen:i,outputLen:a}=this;return t=t,t.finished=s,t.destroyed=o,t.blockLen=i,t.outputLen=a,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ye=(e,t,r)=>new pn(e,t).update(r).digest();Ye.create=(e,t)=>new pn(e,t);var Ra=(e,t)=>(e+(e>=0?t:-t)/Ua)/t;function Ju(e,t,r){let[[n,s],[o,i]]=t,a=Ra(i*e,r),c=Ra(-s*e,r),u=e-a*n-c*o,f=-a*s-c*i,h=u<Wt,l=f<Wt;h&&(u=-u),l&&(f=-f);let d=ce(Math.ceil(Qr(r)/2))+Je;if(u<Wt||u>=d||f<Wt||f>=d)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:h,k1:u,k2neg:l,k2:f}}function ho(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function uo(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return Ht(r.lowS,"lowS"),Ht(r.prehash,"prehash"),r.format!==void 0&&ho(r.format),r}var lo=class extends Error{constructor(t=""){super(t)}},Zt={Err:lo,_tlv:{encode:(e,t)=>{let{Err:r}=Zt;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,s=br(n);if(s.length/2&128)throw new r("tlv.encode: long form length too big");let o=n>127?br(s.length/2|128):"";return br(e)+o+s+t},decode(e,t){let{Err:r}=Zt,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let s=t[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=t.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=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=Zt;if(e<Wt)throw new t("integer: negative integers are not allowed");let r=br(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=Zt;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return qe(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Zt,s=$("signature",e),{v:o,l:i}=n.decode(48,s);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,o),{v:u,l:f}=n.decode(2,c);if(f.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=Zt,n=t.encode(2,r.encode(e.r)),s=t.encode(2,r.encode(e.s)),o=n+s;return t.encode(48,o)}},Wt=BigInt(0),Je=BigInt(1),Ua=BigInt(2),mn=BigInt(3),Qu=BigInt(4);function Xe(e,t){let{BYTES:r}=e,n;if(typeof t=="bigint")n=t;else{let s=$("private key",t);try{n=e.fromBytes(s)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof t}`)}}if(!e.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function th(e,t={}){let r=en("weierstrass",e,t),{Fp:n,Fn:s}=r,o=r.CURVE,{h:i,n:a}=o;Dt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:c}=t;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 u=Pa(n,s);function f(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function h(C,m,y){let{x:b,y:A}=m.toAffine(),L=n.toBytes(b);if(Ht(y,"isCompressed"),y){f();let I=!n.isOdd(A);return gt(Da(I),L)}else return gt(Uint8Array.of(4),L,n.toBytes(A))}function l(C){Et(C,void 0,"Point");let{publicKey:m,publicKeyUncompressed:y}=u,b=C.length,A=C[0],L=C.subarray(1);if(b===m&&(A===2||A===3)){let I=n.fromBytes(L);if(!n.isValid(I))throw new Error("bad point: is not on curve, wrong x");let v=w(I),_;try{_=n.sqrt(v)}catch(q){let V=q instanceof Error?": "+q.message:"";throw new Error("bad point: is not on curve, sqrt error"+V)}f();let K=n.isOdd(_);return(A&1)===1!==K&&(_=n.neg(_)),{x:I,y:_}}else if(b===y&&A===4){let I=n.BYTES,v=n.fromBytes(L.subarray(0,I)),_=n.fromBytes(L.subarray(I,I*2));if(!g(v,_))throw new Error("bad point: is not on curve");return{x:v,y:_}}else throw new Error(`bad point: got length ${b}, expected compressed=${m} or uncompressed=${y}`)}let d=t.toBytes||h,p=t.fromBytes||l;function w(C){let m=n.sqr(C),y=n.mul(m,C);return n.add(n.add(y,n.mul(C,o.a)),o.b)}function g(C,m){let y=n.sqr(m),b=w(C);return n.eql(y,b)}if(!g(o.Gx,o.Gy))throw new Error("bad curve params: generator point");let x=n.mul(n.pow(o.a,mn),Qu),B=n.mul(n.sqr(o.b),BigInt(27));if(n.is0(n.add(x,B)))throw new Error("bad curve params: a or b");function E(C,m,y=!1){if(!n.isValid(m)||y&&n.is0(m))throw new Error(`bad point coordinate ${C}`);return m}function R(C){if(!(C instanceof S))throw new Error("ProjectivePoint expected")}function k(C){if(!c||!c.basises)throw new Error("no endo");return Ju(C,c.basises,s.ORDER)}let O=Ve((C,m)=>{let{X:y,Y:b,Z:A}=C;if(n.eql(A,n.ONE))return{x:y,y:b};let L=C.is0();m==null&&(m=L?n.ONE:n.inv(A));let I=n.mul(y,m),v=n.mul(b,m),_=n.mul(A,m);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(_,n.ONE))throw new Error("invZ was invalid");return{x:I,y:v}}),M=Ve(C=>{if(C.is0()){if(t.allowInfinityPoint&&!n.is0(C.Y))return;throw new Error("bad point: ZERO")}let{x:m,y}=C.toAffine();if(!n.isValid(m)||!n.isValid(y))throw new Error("bad point: x or y not field elements");if(!g(m,y))throw new Error("bad point: equation left != right");if(!C.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function P(C,m,y,b,A){return y=new S(n.mul(y.X,C),y.Y,y.Z),m=Er(b,m),y=Er(A,y),m.add(y)}class S{constructor(m,y,b){this.X=E("x",m),this.Y=E("y",y,!0),this.Z=E("z",b),Object.freeze(this)}static CURVE(){return o}static fromAffine(m){let{x:y,y:b}=m||{};if(!m||!n.isValid(y)||!n.isValid(b))throw new Error("invalid affine point");if(m instanceof S)throw new Error("projective point not allowed");return n.is0(y)&&n.is0(b)?S.ZERO:new S(y,b,n.ONE)}static fromBytes(m){let y=S.fromAffine(p(Et(m,void 0,"point")));return y.assertValidity(),y}static fromHex(m){return S.fromBytes($("pointHex",m))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,y=!0){return U.createCache(this,m),y||this.multiply(mn),this}assertValidity(){M(this)}hasEvenY(){let{y:m}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(m)}equals(m){R(m);let{X:y,Y:b,Z:A}=this,{X:L,Y:I,Z:v}=m,_=n.eql(n.mul(y,v),n.mul(L,A)),K=n.eql(n.mul(b,v),n.mul(I,A));return _&&K}negate(){return new S(this.X,n.neg(this.Y),this.Z)}double(){let{a:m,b:y}=o,b=n.mul(y,mn),{X:A,Y:L,Z:I}=this,v=n.ZERO,_=n.ZERO,K=n.ZERO,D=n.mul(A,A),q=n.mul(L,L),V=n.mul(I,I),H=n.mul(A,L);return H=n.add(H,H),K=n.mul(A,I),K=n.add(K,K),v=n.mul(m,K),_=n.mul(b,V),_=n.add(v,_),v=n.sub(q,_),_=n.add(q,_),_=n.mul(v,_),v=n.mul(H,v),K=n.mul(b,K),V=n.mul(m,V),H=n.sub(D,V),H=n.mul(m,H),H=n.add(H,K),K=n.add(D,D),D=n.add(K,D),D=n.add(D,V),D=n.mul(D,H),_=n.add(_,D),V=n.mul(L,I),V=n.add(V,V),D=n.mul(V,H),v=n.sub(v,D),K=n.mul(V,q),K=n.add(K,K),K=n.add(K,K),new S(v,_,K)}add(m){R(m);let{X:y,Y:b,Z:A}=this,{X:L,Y:I,Z:v}=m,_=n.ZERO,K=n.ZERO,D=n.ZERO,q=o.a,V=n.mul(o.b,mn),H=n.mul(y,L),F=n.mul(b,I),Z=n.mul(A,v),Q=n.add(y,b),z=n.add(L,I);Q=n.mul(Q,z),z=n.add(H,F),Q=n.sub(Q,z),z=n.add(y,A);let st=n.add(L,v);return z=n.mul(z,st),st=n.add(H,Z),z=n.sub(z,st),st=n.add(b,A),_=n.add(I,v),st=n.mul(st,_),_=n.add(F,Z),st=n.sub(st,_),D=n.mul(q,z),_=n.mul(V,Z),D=n.add(_,D),_=n.sub(F,D),D=n.add(F,D),K=n.mul(_,D),F=n.add(H,H),F=n.add(F,H),Z=n.mul(q,Z),z=n.mul(V,z),F=n.add(F,Z),Z=n.sub(H,Z),Z=n.mul(q,Z),z=n.add(z,Z),H=n.mul(F,z),K=n.add(K,H),H=n.mul(st,z),_=n.mul(Q,_),_=n.sub(_,H),H=n.mul(Q,F),D=n.mul(st,D),D=n.add(D,H),new S(_,K,D)}subtract(m){return this.add(m.negate())}is0(){return this.equals(S.ZERO)}multiply(m){let{endo:y}=t;if(!s.isValidNot0(m))throw new Error("invalid scalar: out of range");let b,A,L=I=>U.cached(this,I,v=>Vt(S,v));if(y){let{k1neg:I,k1:v,k2neg:_,k2:K}=k(m),{p:D,f:q}=L(v),{p:V,f:H}=L(K);A=q.add(H),b=P(y.beta,D,V,I,_)}else{let{p:I,f:v}=L(m);b=I,A=v}return Vt(S,[b,A])[0]}multiplyUnsafe(m){let{endo:y}=t,b=this;if(!s.isValid(m))throw new Error("invalid scalar: out of range");if(m===Wt||b.is0())return S.ZERO;if(m===Je)return b;if(U.hasCache(this))return this.multiply(m);if(y){let{k1neg:A,k1:L,k2neg:I,k2:v}=k(m),{p1:_,p2:K}=ra(S,b,L,v);return P(y.beta,_,K,A,I)}else return U.unsafe(b,m)}multiplyAndAddUnsafe(m,y,b){let A=this.multiplyUnsafe(y).add(m.multiplyUnsafe(b));return A.is0()?void 0:A}toAffine(m){return O(this,m)}isTorsionFree(){let{isTorsionFree:m}=t;return i===Je?!0:m?m(S,this):U.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:m}=t;return i===Je?this:m?m(S,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(m=!0){return Ht(m,"isCompressed"),this.assertValidity(),d(S,this,m)}toHex(m=!0){return At(this.toBytes(m))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(m=!0){return this.toBytes(m)}_setWindowSize(m){this.precompute(m)}static normalizeZ(m){return Vt(S,m)}static msm(m,y){return Ge(S,s,m,y)}static fromPrivateKey(m){return S.BASE.multiply(Xe(s,m))}}S.BASE=new S(o.Gx,o.Gy,n.ONE),S.ZERO=new S(n.ZERO,n.ONE,n.ZERO),S.Fp=n,S.Fn=s;let T=s.BITS,U=new ze(S,t.endo?Math.ceil(T/2):T);return S.BASE.precompute(8),S}function Da(e){return Uint8Array.of(e?2:3)}function Pa(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function eh(e,t={}){let{Fn:r}=e,n=t.randomBytes||re,s=Object.assign(Pa(e.Fp,r),{seed:vs(r.ORDER)});function o(d){try{return!!Xe(r,d)}catch{return!1}}function i(d,p){let{publicKey:w,publicKeyUncompressed:g}=s;try{let x=d.length;return p===!0&&x!==w||p===!1&&x!==g?!1:!!e.fromBytes(d)}catch{return!1}}function a(d=n(s.seed)){return As(Et(d,s.seed,"seed"),r.ORDER)}function c(d,p=!0){return e.BASE.multiply(Xe(r,d)).toBytes(p)}function u(d){let p=a(d);return{secretKey:p,publicKey:c(p)}}function f(d){if(typeof d=="bigint")return!1;if(d instanceof e)return!0;let{secretKey:p,publicKey:w,publicKeyUncompressed:g}=s;if(r.allowedLengths||p===w)return;let x=$("key",d).length;return x===w||x===g}function h(d,p,w=!0){if(f(d)===!0)throw new Error("first arg must be private key");if(f(p)===!1)throw new Error("second arg must be public key");let g=Xe(r,d);return e.fromHex(p).multiply(g).toBytes(w)}return Object.freeze({getPublicKey:c,getSharedSecret:h,keygen:u,Point:e,utils:{isValidSecretKey:o,isValidPublicKey:i,randomSecretKey:a,isValidPrivateKey:o,randomPrivateKey:a,normPrivateKeyToScalar:d=>Xe(r,d),precompute(d=8,p=e.BASE){return p.precompute(d,!1)}},lengths:s})}function rh(e,t,r={}){me(t),Dt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||re,s=r.hmac||((y,...b)=>Ye(t,y,gt(...b))),{Fp:o,Fn:i}=e,{ORDER:a,BITS:c}=i,{keygen:u,getPublicKey:f,getSharedSecret:h,utils:l,lengths:d}=eh(e,r),p={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},w="compact";function g(y){let b=a>>Je;return y>b}function x(y,b){if(!i.isValidNot0(b))throw new Error(`invalid signature ${y}: out of range 1..Point.Fn.ORDER`);return b}function B(y,b){ho(b);let A=d.signature,L=b==="compact"?A:b==="recovered"?A+1:void 0;return Et(y,L,`${b} signature`)}class E{constructor(b,A,L){this.r=x("r",b),this.s=x("s",A),L!=null&&(this.recovery=L),Object.freeze(this)}static fromBytes(b,A=w){B(b,A);let L;if(A==="der"){let{r:K,s:D}=Zt.toSig(Et(b));return new E(K,D)}A==="recovered"&&(L=b[0],A="compact",b=b.subarray(1));let I=i.BYTES,v=b.subarray(0,I),_=b.subarray(I,I*2);return new E(i.fromBytes(v),i.fromBytes(_),L)}static fromHex(b,A){return this.fromBytes(ye(b),A)}addRecoveryBit(b){return new E(this.r,this.s,b)}recoverPublicKey(b){let A=o.ORDER,{r:L,s:I,recovery:v}=this;if(v==null||![0,1,2,3].includes(v))throw new Error("recovery id invalid");if(a*Ua<A&&v>1)throw new Error("recovery id is ambiguous for h>1 curve");let K=v===2||v===3?L+a:L;if(!o.isValid(K))throw new Error("recovery id 2 or 3 invalid");let D=o.toBytes(K),q=e.fromBytes(gt(Da((v&1)===0),D)),V=i.inv(K),H=k($("msgHash",b)),F=i.create(-H*V),Z=i.create(I*V),Q=e.BASE.multiplyUnsafe(F).add(q.multiplyUnsafe(Z));if(Q.is0())throw new Error("point at infinify");return Q.assertValidity(),Q}hasHighS(){return g(this.s)}toBytes(b=w){if(ho(b),b==="der")return ye(Zt.hexFromSig(this));let A=i.toBytes(this.r),L=i.toBytes(this.s);if(b==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return gt(Uint8Array.of(this.recovery),A,L)}return gt(A,L)}toHex(b){return At(this.toBytes(b))}assertValidity(){}static fromCompact(b){return E.fromBytes($("sig",b),"compact")}static fromDER(b){return E.fromBytes($("sig",b),"der")}normalizeS(){return this.hasHighS()?new E(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return At(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return At(this.toBytes("compact"))}}let R=r.bits2int||function(b){if(b.length>8192)throw new Error("input is too large");let A=qe(b),L=b.length*8-c;return L>0?A>>BigInt(L):A},k=r.bits2int_modN||function(b){return i.create(R(b))},O=ce(c);function M(y){return ae("num < 2^"+c,y,Wt,O),i.toBytes(y)}function P(y,b){return Et(y,void 0,"message"),b?Et(t(y),void 0,"prehashed message"):y}function S(y,b,A){if(["recovered","canonical"].some(F=>F in A))throw new Error("sign() legacy options not supported");let{lowS:L,prehash:I,extraEntropy:v}=uo(A,p);y=P(y,I);let _=k(y),K=Xe(i,b),D=[M(K),M(_)];if(v!=null&&v!==!1){let F=v===!0?n(d.secretKey):v;D.push($("extraEntropy",F))}let q=gt(...D),V=_;function H(F){let Z=R(F);if(!i.isValidNot0(Z))return;let Q=i.inv(Z),z=e.BASE.multiply(Z).toAffine(),st=i.create(z.x);if(st===Wt)return;let Ie=i.create(Q*i.create(V+st*K));if(Ie===Wt)return;let ir=(z.x===st?0:2)|Number(z.y&Je),ar=Ie;return L&&g(Ie)&&(ar=i.neg(Ie),ir^=1),new E(st,ar,ir)}return{seed:q,k2sig:H}}function T(y,b,A={}){y=$("message",y);let{seed:L,k2sig:I}=S(y,b,A);return Hi(t.outputLen,i.BYTES,s)(L,I)}function U(y){let b,A=typeof y=="string"||Mt(y),L=!A&&y!==null&&typeof y=="object"&&typeof y.r=="bigint"&&typeof y.s=="bigint";if(!A&&!L)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(L)b=new E(y.r,y.s);else if(A){try{b=E.fromBytes($("sig",y),"der")}catch(I){if(!(I instanceof Zt.Err))throw I}if(!b)try{b=E.fromBytes($("sig",y),"compact")}catch{return!1}}return b||!1}function C(y,b,A,L={}){let{lowS:I,prehash:v,format:_}=uo(L,p);if(A=$("publicKey",A),b=P($("message",b),v),"strict"in L)throw new Error("options.strict was renamed to lowS");let K=_===void 0?U(y):E.fromBytes($("sig",y),_);if(K===!1)return!1;try{let D=e.fromBytes(A);if(I&&K.hasHighS())return!1;let{r:q,s:V}=K,H=k(b),F=i.inv(V),Z=i.create(H*F),Q=i.create(q*F),z=e.BASE.multiplyUnsafe(Z).add(D.multiplyUnsafe(Q));return z.is0()?!1:i.create(z.x)===q}catch{return!1}}function m(y,b,A={}){let{prehash:L}=uo(A,p);return b=P(b,L),E.fromBytes(y,"recovered").recoverPublicKey(b).toBytes()}return Object.freeze({keygen:u,getPublicKey:f,getSharedSecret:h,utils:l,lengths:d,Point:e,sign:T,verify:C,recoverPublicKey:m,Signature:E,hash:t})}function nh(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,s=St(t.n,{BITS:e.nBitLength,allowedLengths:n,modFromBytes:e.wrapPrivateKey}),o={Fp:r,Fn:s,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:o}}function sh(e){let{CURVE:t,curveOpts:r}=nh(e),n={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,hash:e.hash,ecdsaOpts:n}}function oh(e,t){let r=t.Point;return Object.assign({},t,{ProjectivePoint:r,CURVE:Object.assign({},e,tn(r.Fn.ORDER,r.Fn.BITS))})}function Na(e){let{CURVE:t,curveOpts:r,hash:n,ecdsaOpts:s}=sh(e),o=th(t,r),i=rh(o,n,s);return oh(e,i)}function ka(e,t){let r=n=>Na({...e,hash:n});return{...r(t),create:r}}var mo={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},ih={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Ma=BigInt(2);function ah(e){let t=mo.p,r=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,f=u*u*e%t,h=J(f,r,t)*f%t,l=J(h,r,t)*f%t,d=J(l,Ma,t)*u%t,p=J(d,s,t)*d%t,w=J(p,o,t)*p%t,g=J(w,a,t)*w%t,x=J(g,c,t)*g%t,B=J(x,a,t)*w%t,E=J(B,r,t)*f%t,R=J(E,i,t)*p%t,k=J(R,n,t)*u%t,O=J(k,Ma,t);if(!po.eql(po.sqr(O),e))throw new Error("Cannot find square root");return O}var po=St(mo.p,{sqrt:ah}),Qe=ka({...mo,Fp:po,lowS:!0,endo:ih},ie);function Oa(e,t,r,n){let s=jr.digest(r instanceof Uint8Array?r:r.subarray());if(an(s))return s.then(({digest:o})=>(n?.signal?.throwIfAborted(),Qe.verify(t,o,e))).catch(o=>{throw o.name==="AbortError"?o:new Br(String(o))});try{return n?.signal?.throwIfAborted(),Qe.verify(t,s.digest,e)}catch(o){throw new Br(String(o))}}var yn=class{type="secp256k1";raw;_key;constructor(t){this._key=qa(t),this.raw=Ha(this._key)}toMultihash(){return Rt.digest(te(this))}toCID(){return ht.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:yt(this.raw,t.raw)}verify(t,r,n){return Oa(this._key,r,t,n)}};function Va(e){return new yn(e)}function Ha(e){return Qe.ProjectivePoint.fromHex(e).toRawBytes(!0)}function qa(e){try{return Qe.ProjectivePoint.fromHex(e),e}catch(t){throw new Te(String(t))}}function Kr(e,t){let{Type:r,Data:n}=$t.decode(e),s=n??new Uint8Array;switch(r){case at.RSA:return ao(s,t);case at.Ed25519:return da(s);case at.secp256k1:return Va(s);case at.ECDSA:return xi(s);default:throw new Ce}}function te(e){return $t.encode({Type:at[e.type],Data:e.raw})}var Fa=Symbol.for("nodejs.util.inspect.custom"),ch=114,Rr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Nn]=!0;toString(){return this.string==null&&(this.string=rt.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ht.createV1(ch,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return yt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return yt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Fa](){return`PeerId(${this.toString()})`}},gn=class extends Rr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},bn=class extends Rr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},xn=class extends Rr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},fh=2336,yo=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Rt.digest(Y(this.url))}[Fa](){return`PeerId(${this.url})`}[Nn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ht.createV1(fh,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=j(t)),t.toString()===this.toString())}};function go(e){if(e.type==="Ed25519")return new bn({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new xn({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new gn({multihash:e.toCID().multihash,publicKey:e});throw new Ce}function wn(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var En=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},tr=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new En(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let r=this.head;this.head=r.next=new En(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var bo=class extends Error{type;code;constructor(t,r){super(t??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Sn(e={}){return uh(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}},e)}function uh(e,t){t=t??{};let r=t.onEnd,n=new tr,s,o,i,a=wn(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((g,x)=>{o=B=>{o=null,n.push(B);try{g(e(n))}catch(E){x(E)}return s}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=wn()})}},u=g=>o!=null?o(g):(n.push(g),s),f=g=>(n=new tr,o!=null?o({error:g}):(n.push({error:g}),s)),h=g=>{if(i)return s;if(t?.objectMode!==!0&&g?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:g})},l=g=>i?s:(i=!0,g!=null?f(g):u({done:!0})),d=()=>(n=new tr,l(),{done:!0}),p=g=>(l(g),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:d,throw:p,push:h,end:l,get readableLength(){return n.size},onEmpty:async g=>{let x=g?.signal;if(x?.throwIfAborted(),n.isEmpty())return;let B,E;x!=null&&(B=new Promise((R,k)=>{E=()=>{k(new bo)},x.addEventListener("abort",E)}));try{await Promise.race([a.promise,B])}finally{E!=null&&x!=null&&x?.removeEventListener("abort",E)}}},r==null)return s;let w=s;return s={[Symbol.asyncIterator](){return this},next(){return w.next()},throw(g){return w.throw(g),r!=null&&(r(g),r=void 0),{done:!0}},return(){return w.return(),r!=null&&(r(),r=void 0),{done:!0}},push:h,end(g){return w.end(g),r!=null&&(r(g),r=void 0),s},get readableLength(){return w.readableLength},onEmpty:g=>w.onEmpty(g)},s}var xo=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},wo=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},za=e=>globalThis.DOMException===void 0?new wo(e):new DOMException(e),Ga=e=>{let t=e.reason===void 0?za("This operation was aborted."):e.reason;return t instanceof Error?t:za(t)};function Eo(e,t){let{milliseconds:r,fallback:n,message:s,customTimers:o={setTimeout,clearTimeout}}=t,i,a,u=new Promise((f,h)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(t.signal){let{signal:d}=t;d.aborted&&h(Ga(d)),a=()=>{h(Ga(d))},d.addEventListener("abort",a,{once:!0})}if(r===Number.POSITIVE_INFINITY){e.then(f,h);return}let l=new xo;i=o.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(d){h(d)}return}typeof e.cancel=="function"&&e.cancel(),s===!1?f():s instanceof Error?h(s):(l.message=s??`Promise timed out after ${r} milliseconds`,h(l))},r),(async()=>{try{f(await e)}catch(d){h(d)}})()}).finally(()=>{u.clear(),a&&t.signal&&t.signal.removeEventListener("abort",a)});return u.clear=()=>{o.clearTimeout.call(void 0,i),i=void 0},u}var hh=e=>{let t=e.addEventListener||e.on||e.addListener,r=e.removeEventListener||e.off||e.removeListener;if(!t||!r)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(e),removeListener:r.bind(e)}};function lh(e,t,r){let n,s=new Promise((o,i)=>{if(r={rejectionEvents:["error"],multiArgs:!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=[t].flat(),c=[],{addListener:u,removeListener:f}=hh(e),h=(...d)=>{let p=r.multiArgs?d:d[0];r.filter&&!r.filter(p)||(c.push(p),r.count===c.length&&(n(),o(c)))},l=d=>{n(),i(d)};n=()=>{for(let d of a)f(d,h);for(let d of r.rejectionEvents)f(d,l)};for(let d of a)u(d,h);for(let d of r.rejectionEvents)u(d,l);r.signal&&r.signal.addEventListener("abort",()=>{l(r.signal.reason)},{once:!0}),r.resolveImmediately&&o(c)});if(s.cancel=n,typeof r.timeout=="number"){let o=Eo(s,{milliseconds:r.timeout});return o.cancel=n,o}return s}function ja(e,t,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=lh(e,t,r),s=n.then(o=>o[0]);return s.cancel=n.cancel,s}var Le=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function dh(e){return e.reason}async function $a(e,t,r){if(t==null)return e;let n=r?.translateError??dh;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let s;try{return await Promise.race([e,new Promise((o,i)=>{s=()=>{i(n(t))},t.addEventListener("abort",s)})])}finally{s!=null&&t.removeEventListener("abort",s)}}var ph=Math.pow(2,20)*4,vn=class extends Fr{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;constructor(t){super(),this.status="open",this.log=t.log,this.direction=t.direction??"outbound",this.inactivityTimeout=t.inactivityTimeout??12e4,this.maxReadBufferLength=t.maxReadBufferLength??ph,this.maxWriteBufferLength=t.maxWriteBufferLength,this.maxMessageSize=t.maxMessageSize,this.readBuffer=new G,this.writeBuffer=new G,this.readStatus="readable",this.remoteReadStatus="readable",this.writeStatus="writable",this.remoteWriteStatus="writable",this.sendingData=!1,this.writableNeedsDrain=!1,this.timeline={open:Date.now()},this.processSendQueue=this.processSendQueue.bind(this);let r=()=>{this.writableNeedsDrain&&(this.log.trace("drain event received, continue sending data"),this.writableNeedsDrain=!1,this.processSendQueue())};this.addEventListener("drain",r)}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let t=Sn(),r=o=>{t.push(o.data)};this.addEventListener("message",r);let n=o=>{t.end(o.error)};this.addEventListener("close",n);let s=()=>{t.end()};this.addEventListener("remoteCloseWrite",s);try{yield*t}finally{this.removeEventListener("message",r),this.removeEventListener("close",n),this.removeEventListener("remoteCloseWrite",s)}}isReadable(){return this.status==="open"}send(t){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new he(`Cannot write to a stream that is ${this.writeStatus}`);return this.log.trace("append %d bytes to write buffer",t.byteLength),this.writeBuffer.append(t),this.processSendQueue()}abort(t){if(!(this.status==="aborted"||this.status==="reset"||this.status==="closed")){this.log.error("abort with error - %e",t),this.status="aborted",this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle")),this.writeStatus="closed",this.remoteWriteStatus="closed",this.readStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now();try{this.sendReset(t)}catch(r){this.log("failed to send reset to remote - %e",r)}this.dispatchEvent(new qr(t))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new he("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 he("Cannot resume a stream that is closing/closed");this.readStatus!=="readable"&&(this.readStatus="readable",this.dispatchReadBuffer(),this.sendResume())}push(t){if(this.readStatus==="closed"||this.readStatus==="closing")throw new he(`Cannot push data onto a stream that is ${this.readStatus}`);if(t.byteLength!==0){if(this.readBuffer.append(t),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}onData(t){if(t.byteLength!==0){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("ignoring data - read status %s",this.readStatus);return}this.readBuffer.append(t),this.dispatchReadBuffer()}}addEventListener(...t){super.addEventListener.apply(this,t),t[0]==="message"&&this.readBuffer.byteLength>0&&queueMicrotask(()=>{this.dispatchReadBuffer()})}onRemoteReset(){this.log("remote reset"),this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed");let t=new Or;this.dispatchEvent(new Vr(t))}onTransportClosed(t){this.log("transport closed"),this.readStatus==="readable"&&this.readBuffer.byteLength===0&&(this.log("close readable end after transport closed and read buffer is empty"),this.readStatus="closed"),this.remoteReadStatus!=="closed"&&(this.remoteReadStatus="closed"),this.remoteWriteStatus!=="closed"&&(this.remoteWriteStatus="closed"),this.writeStatus!=="closed"&&(this.writeStatus="closed"),t!=null?this.abort(t):(this.status==="open"||this.status==="closing")&&(this.timeline.close=Date.now(),this.status="closed",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.dispatchEvent(new Ke))}onRemoteCloseWrite(){this.remoteWriteStatus!=="closed"&&(this.log.trace("on remote close write"),this.remoteWriteStatus="closed",this.safeDispatchEvent("remoteCloseWrite"),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;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let t=!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){t=!1;break}let o=this.writeBuffer.sublist(0,s),i=new G(o);this.writeBuffer.consume(o.byteLength);let a=this.sendData(o);if(t=a.canSendMore,n+=a.sentBytes,a.sentBytes!==i.byteLength&&(i.consume(a.sentBytes),this.writeBuffer.prepend(i)),!t)break}return t||(this.log.trace("sent %d/%d bytes, pausing sending because underlying stream is full, %d bytes left in the write buffer",n,r,this.writeBuffer.byteLength),this.writableNeedsDrain=!0,this.checkWriteBufferLength()),this.writeBuffer.byteLength===0&&this.safeDispatchEvent("idle"),t}finally{this.sendingData=!1}}dispatchReadBuffer(){try{if(this.listenerCount("message")===0){this.log.trace("not dispatching pause buffer as there are no listeners for the message event");return}if(this.readBuffer.byteLength===0){this.log.trace("not dispatching pause buffer as there is no data to dispatch");return}if(this.readStatus==="paused"){this.log.trace("not dispatching pause buffer we are paused");return}if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("dropping %d bytes because the readable end is %s",this.readBuffer.byteLength,this.readStatus),this.readBuffer.consume(this.readBuffer.byteLength);return}let t=this.readBuffer.sublist();this.readBuffer.consume(t.byteLength),this.dispatchEvent(new Hr(t))}finally{this.readBuffer.byteLength===0&&this.remoteWriteStatus==="closed"&&(this.log("close readable end after dispatching read buffer and remote writable end is closed"),this.readStatus="closed"),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new cr(`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 cr(`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 mh=4194304,An=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Ur=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},vo=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Ao=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function yh(e){return typeof e?.closeRead=="function"}function gh(e){return typeof e?.close=="function"}function So(e){return yh(e)?e.readStatus==="closing"||e.readStatus==="closed":gh(e)?e.status!=="open":!1}function bh(e){return e?.addEventListener!=null&&e?.removeEventListener!=null&&e?.send!=null&&e?.push!=null&&e?.log!=null}function xh(e,t){let r=t?.maxBufferSize??mh,n=new G,s=Promise.withResolvers(),o=!1;if(!bh(e))throw new tt("Argument should be a Stream or a Multiaddr");let i=f=>{if(n.append(f.data),n.byteLength>r){let h=n.byteLength;n.consume(n.byteLength),s.reject(new Error(`Read buffer overflow - ${h} > ${r}`))}s.resolve()};e.addEventListener("message",i);let a=f=>{f.error!=null?s.reject(f.error):s.resolve()};e.addEventListener("close",a);let c=()=>{s.resolve()};e.addEventListener("remoteCloseWrite",c);let u={readBuffer:n,async read(f){if(o===!0)throw new An("Stream was unwrapped");if(So(e)){if(f?.bytes==null)return null;if(n.byteLength<f.bytes)throw e.log.error("closed after reading %d/%d bytes",n.byteLength,f.bytes),new Le(`Unexpected EOF - stream closed after reading ${n.byteLength}/${f.bytes} bytes`)}let h=f?.bytes??1;for(;;){if(n.byteLength>=h){s.resolve();break}if(await $a(s.promise,f?.signal),So(e)){if(n.byteLength===0&&f?.bytes==null)return null;break}s=Promise.withResolvers()}let l=f?.bytes??n.byteLength;if(n.byteLength<l){if(So(e))throw e.log.error("closed while reading %d/%d bytes",n.byteLength,l),new Le(`Unexpected EOF - stream closed while reading ${n.byteLength}/${l} bytes`);return u.read(f)}let d=n.sublist(0,l);return n.consume(l),d},async write(f,h){if(o===!0)throw new An("Stream was unwrapped");e.send(f)||await ja(e,"drain",{signal:h?.signal,rejectionEvents:["close"]})},unwrap(){return o||(o=!0,e.removeEventListener("message",i),e.removeEventListener("close",a),e.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(e.log("stream unwrapped with %d unread bytes",n.byteLength),e.push(n))),e}};return u}function Bo(e,t={}){let r=xh(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=Tt(t.maxDataLength));let n=t?.lengthDecoder??fn,s=t?.lengthEncoder??pa;return{async read(i){let a=-1,c=new G;for(;;){let f=await r.read({...i,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(h){if(h instanceof RangeError)continue;throw h}if(a<0)throw new Ur("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new Ao(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new vo(`Message length too long - ${a} > ${t.maxDataLength}`);let u=await r.read({...i,bytes:a});if(u==null)throw e.log.error("tried to read %d bytes but the stream closed",a),new Le(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw e.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new Le(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await r.write(new G(s(i.byteLength),i),a)},async writeV(i,a){let c=new G(...i.flatMap(u=>[s(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}var wh=1024*1024*4,Eh=1024*1024*4,Bn=class{buffer;maxBufferSize;lengthDecoder;maxDataLength;encodingLength;constructor(t={}){this.buffer=new G,this.maxBufferSize=t.maxBufferSize??wh,this.maxDataLength=t.maxDataLength??Eh,this.lengthDecoder=t.lengthDecoder??fn,this.encodingLength=t.encodingLength??Tt}*decode(t){if(this.buffer.append(t),this.buffer.byteLength>this.maxBufferSize)throw new tt(`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 Ur("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 er=!!globalThis.process?.env?.DUMP_SESSION_KEYS,Lo=16;function Wa(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Ln(e){if(typeof e!="boolean")throw new Error(`boolean expected, not ${e}`)}function _n(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function mt(e,...t){if(!Wa(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function _o(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Ya(e,t){mt(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Yt(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function Xt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Sh(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}var vh=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Ah(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function In(e){if(typeof e=="string")e=Ah(e);else if(Wa(e))e=Tn(e);else throw new Error("Uint8Array expected, got "+typeof e);return e}function Xa(e,t){if(t==null||typeof t!="object")throw new Error("options must be defined");return Object.assign(e,t)}function Ja(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}var Io=(e,t)=>{function r(n,...s){if(mt(n),!vh)throw new Error("Non little-endian hardware is not yet supported");if(e.nonceLength!==void 0){let f=s[0];if(!f)throw new Error("nonce / iv required");e.varSizeNonce?mt(f):mt(f,e.nonceLength)}let o=e.tagLength;o&&s[1]!==void 0&&mt(s[1]);let i=t(n,...s),a=(f,h)=>{if(h!==void 0){if(f!==2)throw new Error("cipher output not supported");mt(h)}},c=!1;return{encrypt(f,h){if(c)throw new Error("cannot encrypt() twice with same key + nonce");return c=!0,mt(f),a(i.encrypt.length,h),i.encrypt(f,h)},decrypt(f,h){if(mt(f),o&&f.length<o)throw new Error("invalid ciphertext length: smaller than tagLength="+o);return a(i.decrypt.length,h),i.decrypt(f,h)}}}return Object.assign(r,e),r};function To(e,t,r=!0){if(t===void 0)return new Uint8Array(e);if(t.length!==e)throw new Error("invalid output length, expected "+e+", got: "+t.length);if(r&&!Bh(t))throw new Error("invalid output, must be aligned");return t}function Za(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let s=BigInt(32),o=BigInt(4294967295),i=Number(r>>s&o),a=Number(r&o),c=n?4:0,u=n?0:4;e.setUint32(t+c,i,n),e.setUint32(t+u,a,n)}function Qa(e,t,r){Ln(r);let n=new Uint8Array(16),s=Sh(n);return Za(s,0,BigInt(t),r),Za(s,8,BigInt(e),r),n}function Bh(e){return e.byteOffset%4===0}function Tn(e){return Uint8Array.from(e)}var ec=e=>Uint8Array.from(e.split("").map(t=>t.charCodeAt(0))),Lh=ec("expand 16-byte k"),_h=ec("expand 32-byte k"),Ih=Yt(Lh),Th=Yt(_h);function N(e,t){return e<<t|e>>>32-t}function Co(e){return e.byteOffset%4===0}var Cn=64,Ch=16,rc=2**32-1,tc=new Uint32Array;function Kh(e,t,r,n,s,o,i,a){let c=s.length,u=new Uint8Array(Cn),f=Yt(u),h=Co(s)&&Co(o),l=h?Yt(s):tc,d=h?Yt(o):tc;for(let p=0;p<c;i++){if(e(t,r,n,f,i,a),i>=rc)throw new Error("arx: counter overflow");let w=Math.min(Cn,c-p);if(h&&w===Cn){let g=p/4;if(p%4!==0)throw new Error("arx: invalid block position");for(let x=0,B;x<Ch;x++)B=g+x,d[B]=l[B]^f[x];p+=Cn;continue}for(let g=0,x;g<w;g++)x=p+g,o[x]=s[x]^u[g];p+=w}}function Ko(e,t){let{allowShortKeys:r,extendNonceFn:n,counterLength:s,counterRight:o,rounds:i}=Xa({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if(typeof e!="function")throw new Error("core must be a function");return _n(s),_n(i),Ln(o),Ln(r),(a,c,u,f,h=0)=>{mt(a),mt(c),mt(u);let l=u.length;if(f===void 0&&(f=new Uint8Array(l)),mt(f),_n(h),h<0||h>=rc)throw new Error("arx: counter overflow");if(f.length<l)throw new Error(`arx: output (${f.length}) is shorter than data (${l})`);let d=[],p=a.length,w,g;if(p===32)d.push(w=Tn(a)),g=Th;else if(p===16&&r)w=new Uint8Array(32),w.set(a),w.set(a,16),g=Ih,d.push(w);else throw new Error(`arx: invalid 32-byte key, got length=${p}`);Co(c)||d.push(c=Tn(c));let x=Yt(w);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(g,x,Yt(c.subarray(0,16)),x),c=c.subarray(16)}let B=16-s;if(B!==c.length)throw new Error(`arx: nonce must be ${B} or 16 bytes`);if(B!==12){let R=new Uint8Array(12);R.set(c,o?0:12-c.length),c=R,d.push(c)}let E=Yt(c);return Kh(e,g,x,E,u,f,h,i),Xt(...d),f}}var ut=(e,t)=>e[t++]&255|(e[t++]&255)<<8,Ro=class{constructor(t){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,t=In(t),mt(t,32);let r=ut(t,0),n=ut(t,2),s=ut(t,4),o=ut(t,6),i=ut(t,8),a=ut(t,10),c=ut(t,12),u=ut(t,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]=ut(t,16+2*f)}process(t,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],h=i[4],l=i[5],d=i[6],p=i[7],w=i[8],g=i[9],x=ut(t,r+0),B=ut(t,r+2),E=ut(t,r+4),R=ut(t,r+6),k=ut(t,r+8),O=ut(t,r+10),M=ut(t,r+12),P=ut(t,r+14),S=o[0]+(x&8191),T=o[1]+((x>>>13|B<<3)&8191),U=o[2]+((B>>>10|E<<6)&8191),C=o[3]+((E>>>7|R<<9)&8191),m=o[4]+((R>>>4|k<<12)&8191),y=o[5]+(k>>>1&8191),b=o[6]+((k>>>14|O<<2)&8191),A=o[7]+((O>>>11|M<<5)&8191),L=o[8]+((M>>>8|P<<8)&8191),I=o[9]+(P>>>5|s),v=0,_=v+S*a+T*(5*g)+U*(5*w)+C*(5*p)+m*(5*d);v=_>>>13,_&=8191,_+=y*(5*l)+b*(5*h)+A*(5*f)+L*(5*u)+I*(5*c),v+=_>>>13,_&=8191;let K=v+S*c+T*a+U*(5*g)+C*(5*w)+m*(5*p);v=K>>>13,K&=8191,K+=y*(5*d)+b*(5*l)+A*(5*h)+L*(5*f)+I*(5*u),v+=K>>>13,K&=8191;let D=v+S*u+T*c+U*a+C*(5*g)+m*(5*w);v=D>>>13,D&=8191,D+=y*(5*p)+b*(5*d)+A*(5*l)+L*(5*h)+I*(5*f),v+=D>>>13,D&=8191;let q=v+S*f+T*u+U*c+C*a+m*(5*g);v=q>>>13,q&=8191,q+=y*(5*w)+b*(5*p)+A*(5*d)+L*(5*l)+I*(5*h),v+=q>>>13,q&=8191;let V=v+S*h+T*f+U*u+C*c+m*a;v=V>>>13,V&=8191,V+=y*(5*g)+b*(5*w)+A*(5*p)+L*(5*d)+I*(5*l),v+=V>>>13,V&=8191;let H=v+S*l+T*h+U*f+C*u+m*c;v=H>>>13,H&=8191,H+=y*a+b*(5*g)+A*(5*w)+L*(5*p)+I*(5*d),v+=H>>>13,H&=8191;let F=v+S*d+T*l+U*h+C*f+m*u;v=F>>>13,F&=8191,F+=y*c+b*a+A*(5*g)+L*(5*w)+I*(5*p),v+=F>>>13,F&=8191;let Z=v+S*p+T*d+U*l+C*h+m*f;v=Z>>>13,Z&=8191,Z+=y*u+b*c+A*a+L*(5*g)+I*(5*w),v+=Z>>>13,Z&=8191;let Q=v+S*w+T*p+U*d+C*l+m*h;v=Q>>>13,Q&=8191,Q+=y*f+b*u+A*c+L*a+I*(5*g),v+=Q>>>13,Q&=8191;let z=v+S*g+T*w+U*p+C*d+m*l;v=z>>>13,z&=8191,z+=y*h+b*f+A*u+L*c+I*a,v+=z>>>13,z&=8191,v=(v<<2)+v|0,v=v+_|0,_=v&8191,v=v>>>13,K+=v,o[0]=_,o[1]=K,o[2]=D,o[3]=q,o[4]=V,o[5]=H,o[6]=F,o[7]=Z,o[8]=Q,o[9]=z}finalize(){let{h:t,pad:r}=this,n=new Uint16Array(10),s=t[1]>>>13;t[1]&=8191;for(let a=2;a<10;a++)t[a]+=s,s=t[a]>>>13,t[a]&=8191;t[0]+=s*5,s=t[0]>>>13,t[0]&=8191,t[1]+=s,s=t[1]>>>13,t[1]&=8191,t[2]+=s,n[0]=t[0]+5,s=n[0]>>>13,n[0]&=8191;for(let a=1;a<10;a++)n[a]=t[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++)t[a]=t[a]&o|n[a];t[0]=(t[0]|t[1]<<13)&65535,t[1]=(t[1]>>>3|t[2]<<10)&65535,t[2]=(t[2]>>>6|t[3]<<7)&65535,t[3]=(t[3]>>>9|t[4]<<4)&65535,t[4]=(t[4]>>>12|t[5]<<1|t[6]<<14)&65535,t[5]=(t[6]>>>2|t[7]<<11)&65535,t[6]=(t[7]>>>5|t[8]<<8)&65535,t[7]=(t[8]>>>8|t[9]<<5)&65535;let i=t[0]+r[0];t[0]=i&65535;for(let a=1;a<8;a++)i=(t[a]+r[a]|0)+(i>>>16)|0,t[a]=i&65535;Xt(n)}update(t){_o(this),t=In(t),mt(t);let{buffer:r,blockLen:n}=this,s=t.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(t,o);continue}r.set(t.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(){Xt(this.h,this.r,this.buffer,this.pad)}digestInto(t){_o(this),Ya(t,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++)t[o++]=n[i]>>>0,t[o++]=n[i]>>>8;return t}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}};function Rh(e){let t=(n,s)=>e(s).update(In(n)).digest(),r=e(new Uint8Array(32));return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=n=>e(n),t}var nc=Rh(e=>new Ro(e));function ic(e,t,r,n,s,o=20){let i=e[0],a=e[1],c=e[2],u=e[3],f=t[0],h=t[1],l=t[2],d=t[3],p=t[4],w=t[5],g=t[6],x=t[7],B=s,E=r[0],R=r[1],k=r[2],O=i,M=a,P=c,S=u,T=f,U=h,C=l,m=d,y=p,b=w,A=g,L=x,I=B,v=E,_=R,K=k;for(let q=0;q<o;q+=2)O=O+T|0,I=N(I^O,16),y=y+I|0,T=N(T^y,12),O=O+T|0,I=N(I^O,8),y=y+I|0,T=N(T^y,7),M=M+U|0,v=N(v^M,16),b=b+v|0,U=N(U^b,12),M=M+U|0,v=N(v^M,8),b=b+v|0,U=N(U^b,7),P=P+C|0,_=N(_^P,16),A=A+_|0,C=N(C^A,12),P=P+C|0,_=N(_^P,8),A=A+_|0,C=N(C^A,7),S=S+m|0,K=N(K^S,16),L=L+K|0,m=N(m^L,12),S=S+m|0,K=N(K^S,8),L=L+K|0,m=N(m^L,7),O=O+U|0,K=N(K^O,16),A=A+K|0,U=N(U^A,12),O=O+U|0,K=N(K^O,8),A=A+K|0,U=N(U^A,7),M=M+C|0,I=N(I^M,16),L=L+I|0,C=N(C^L,12),M=M+C|0,I=N(I^M,8),L=L+I|0,C=N(C^L,7),P=P+m|0,v=N(v^P,16),y=y+v|0,m=N(m^y,12),P=P+m|0,v=N(v^P,8),y=y+v|0,m=N(m^y,7),S=S+T|0,_=N(_^S,16),b=b+_|0,T=N(T^b,12),S=S+T|0,_=N(_^S,8),b=b+_|0,T=N(T^b,7);let D=0;n[D++]=i+O|0,n[D++]=a+M|0,n[D++]=c+P|0,n[D++]=u+S|0,n[D++]=f+T|0,n[D++]=h+U|0,n[D++]=l+C|0,n[D++]=d+m|0,n[D++]=p+y|0,n[D++]=w+b|0,n[D++]=g+A|0,n[D++]=x+L|0,n[D++]=B+I|0,n[D++]=E+v|0,n[D++]=R+_|0,n[D++]=k+K|0}function Uh(e,t,r,n){let s=e[0],o=e[1],i=e[2],a=e[3],c=t[0],u=t[1],f=t[2],h=t[3],l=t[4],d=t[5],p=t[6],w=t[7],g=r[0],x=r[1],B=r[2],E=r[3];for(let k=0;k<20;k+=2)s=s+c|0,g=N(g^s,16),l=l+g|0,c=N(c^l,12),s=s+c|0,g=N(g^s,8),l=l+g|0,c=N(c^l,7),o=o+u|0,x=N(x^o,16),d=d+x|0,u=N(u^d,12),o=o+u|0,x=N(x^o,8),d=d+x|0,u=N(u^d,7),i=i+f|0,B=N(B^i,16),p=p+B|0,f=N(f^p,12),i=i+f|0,B=N(B^i,8),p=p+B|0,f=N(f^p,7),a=a+h|0,E=N(E^a,16),w=w+E|0,h=N(h^w,12),a=a+h|0,E=N(E^a,8),w=w+E|0,h=N(h^w,7),s=s+u|0,E=N(E^s,16),p=p+E|0,u=N(u^p,12),s=s+u|0,E=N(E^s,8),p=p+E|0,u=N(u^p,7),o=o+f|0,g=N(g^o,16),w=w+g|0,f=N(f^w,12),o=o+f|0,g=N(g^o,8),w=w+g|0,f=N(f^w,7),i=i+h|0,x=N(x^i,16),l=l+x|0,h=N(h^l,12),i=i+h|0,x=N(x^i,8),l=l+x|0,h=N(h^l,7),a=a+c|0,B=N(B^a,16),d=d+B|0,c=N(c^d,12),a=a+c|0,B=N(B^a,8),d=d+B|0,c=N(c^d,7);let R=0;n[R++]=s,n[R++]=o,n[R++]=i,n[R++]=a,n[R++]=g,n[R++]=x,n[R++]=B,n[R++]=E}var Dh=Ko(ic,{counterRight:!1,counterLength:4,allowShortKeys:!1}),Ph=Ko(ic,{counterRight:!1,counterLength:8,extendNonceFn:Uh,allowShortKeys:!1});var Nh=new Uint8Array(16),sc=(e,t)=>{e.update(t);let r=t.length%16;r&&e.update(Nh.subarray(r))},kh=new Uint8Array(32);function oc(e,t,r,n,s){let o=e(t,r,kh),i=nc.create(o);s&&sc(i,s),sc(i,n);let a=Qa(n.length,s?s.length:0,!0);i.update(a);let c=i.digest();return Xt(o,a),c}var ac=e=>(t,r,n)=>({encrypt(o,i){let a=o.length;i=To(a+16,i,!1),i.set(o);let c=i.subarray(0,-16);e(t,r,c,c,1);let u=oc(e,t,r,c,n);return i.set(u,a),Xt(u),i},decrypt(o,i){i=To(o.length-16,i,!1);let a=o.subarray(0,-16),c=o.subarray(-16),u=oc(e,t,r,a,n);if(!Ja(c,u))throw new Error("invalid tag");return i.set(o.subarray(0,-16)),e(t,r,i,i,1),Xt(u),i}}),Uo=Io({blockSize:64,nonceLength:12,tagLength:16},ac(Dh)),lg=Io({blockSize:64,nonceLength:24,tagLength:16},ac(Ph));function fc(e,t,r){return me(e),r===void 0&&(r=new Uint8Array(e.outputLen)),Ye(e,ee(r),ee(t))}var Do=Uint8Array.from([0]),cc=Uint8Array.of();function uc(e,t,r,n=32){me(e),pe(n);let s=e.outputLen;if(n>255*s)throw new Error("Length should be <= 255*HashLen");let o=Math.ceil(n/s);r===void 0&&(r=cc);let i=new Uint8Array(o*s),a=Ye.create(e,t),c=a._cloneInto(),u=new Uint8Array(a.outputLen);for(let f=0;f<o;f++)Do[0]=f+1,c.update(f===0?cc:u).update(r).update(Do).digestInto(u),i.set(u,s*f),a._cloneInto(c);return a.destroy(),c.destroy(),_t(u,Do),i.slice(0,n)}var Kn={hashSHA256(e){return ie(e.subarray())},getHKDF(e,t){let r=fc(ie,t,e),s=uc(ie,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 e=Ar.utils.randomSecretKey();return{publicKey:Ar.getPublicKey(e),privateKey:e}},generateX25519KeyPairFromSeed(e){return{publicKey:Ar.getPublicKey(e),privateKey:e}},generateX25519SharedKey(e,t){return Ar.getSharedSecret(e.subarray(),t.subarray())},chaCha20Poly1305Encrypt(e,t,r,n){return Uo(n,t,r).encrypt(e.subarray())},chaCha20Poly1305Decrypt(e,t,r,n,s){return Uo(n,t,r).decrypt(e.subarray(),s)}};var hc=Kn;function lc(e){return{generateKeypair:e.generateX25519KeyPair,dh:(t,r)=>e.generateX25519SharedKey(t.privateKey,r).subarray(0,32),encrypt:e.chaCha20Poly1305Encrypt,decrypt:e.chaCha20Poly1305Decrypt,hash:e.hashSHA256,hkdf:e.getHKDF}}var rr=e=>{let t=ct(2);return t[0]=e>>8,t[1]=e,t};rr.bytes=2;var nr=e=>{if(e.length<2)throw RangeError("Could not decode int16BE");if(e instanceof Uint8Array){let t=0;return t+=e[0]<<8,t+=e[1],t}return e.getUint16(0)};nr.bytes=2;function dc(e){return{xxHandshakeSuccesses:e.registerCounter("libp2p_noise_xxhandshake_successes_total",{help:"Total count of noise xxHandshakes successes_"}),xxHandshakeErrors:e.registerCounter("libp2p_noise_xxhandshake_error_total",{help:"Total count of noise xxHandshakes errors"}),encryptedPackets:e.registerCounter("libp2p_noise_encrypted_packets_total",{help:"Total count of noise encrypted packets successfully"}),decryptedPackets:e.registerCounter("libp2p_noise_decrypted_packets_total",{help:"Total count of noise decrypted packets"}),decryptErrors:e.registerCounter("libp2p_noise_decrypt_errors_total",{help:"Total count of noise decrypt errors"})}}function Po(e,t){!t.enabled||!er||(e?(t(`LOCAL_STATIC_PUBLIC_KEY ${j(e.publicKey,"hex")}`),t(`LOCAL_STATIC_PRIVATE_KEY ${j(e.privateKey,"hex")}`)):t("Missing local static keys."))}function No(e,t){!t.enabled||!er||(e?(t(`LOCAL_PUBLIC_EPHEMERAL_KEY ${j(e.publicKey,"hex")}`),t(`LOCAL_PRIVATE_EPHEMERAL_KEY ${j(e.privateKey,"hex")}`)):t("Missing local ephemeral keys."))}function pc(e,t){!t.enabled||!er||t(e?`REMOTE_STATIC_PUBLIC_KEY ${j(e.subarray(),"hex")}`:"Missing remote static public key.")}function ko(e,t){!t.enabled||!er||t(e?`REMOTE_EPHEMERAL_PUBLIC_KEY ${j(e.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function Mo(e,t,r){!r.enabled||!er||(r(`CIPHER_STATE_1 ${e.n.getUint64()} ${e.k&&j(e.k,"hex")}`),r(`CIPHER_STATE_2 ${t.n.getUint64()} ${t.k&&j(t.k,"hex")}`))}var sr=class e extends Error{code;constructor(t="Invalid crypto exchange"){super(t),this.code=e.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var Mh=0,Oh=4294967295,Hh="Cipher state has reached maximum n, a new handshake must be performed",Rn=class{n;bytes;view;constructor(t=Mh){this.n=t,this.bytes=nt(12),this.view=new DataView(this.bytes.buffer,this.bytes.byteOffset,this.bytes.byteLength),this.view.setUint32(4,t,!0)}increment(){this.n++,this.view.setUint32(4,this.n,!0)}getBytes(){return this.bytes}getUint64(){return this.n}assertValue(){if(this.n>Oh)throw new Error(Hh)}};var _e=nt(0),or=class{k;n;crypto;constructor(t,r=void 0,n=0){this.crypto=t,this.k=r,this.n=new Rn(n)}hasKey(){return!!this.k}encryptWithAd(t,r){if(!this.hasKey())return r;this.n.assertValue();let n=this.crypto.encrypt(r,this.n.getBytes(),t,this.k);return this.n.increment(),n}decryptWithAd(t,r,n){if(!this.hasKey())return r;this.n.assertValue();let s=this.crypto.decrypt(r,this.n.getBytes(),t,this.k,n);return this.n.increment(),s}},Oo=class{cs;ck;h;crypto;constructor(t,r){this.crypto=t;let n=Y(r,"utf-8");this.h=qh(t,n),this.ck=this.h,this.cs=new or(t)}mixKey(t){let[r,n]=this.crypto.hkdf(this.ck,t);this.ck=r,this.cs=new or(this.crypto,n)}mixHash(t){this.h=this.crypto.hash(new G(this.h,t))}encryptAndHash(t){let r=this.cs.encryptWithAd(this.h,t);return this.mixHash(r),r}decryptAndHash(t){let r=this.cs.decryptWithAd(this.h,t);return this.mixHash(t),r}split(){let[t,r]=this.crypto.hkdf(this.ck,_e);return[new or(this.crypto,t),new or(this.crypto,r)]}},Ho=class{ss;s;e;rs;re;initiator;crypto;constructor(t){let{crypto:r,protocolName:n,prologue:s,initiator:o,s:i,e:a,rs:c,re:u}=t;this.crypto=r,this.ss=new Oo(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 t=this.crypto.generateKeypair();return this.ss.mixHash(t.publicKey),this.e=t,t.publicKey}writeS(){if(!this.s)throw new Error("static keypair is not set");return this.ss.encryptAndHash(this.s.publicKey)}writeEE(){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.re))}writeES(){if(this.initiator){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}else{if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}}writeSE(){if(this.initiator){if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}else{if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}}readE(t,r=0){if(this.re)throw new Error("remote ephemeral public key is already set");if(t.byteLength<r+32)throw new Error("message is not long enough");this.re=t.sublist(r,r+32),this.ss.mixHash(this.re)}readS(t,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(t.byteLength<r+n)throw new Error("message is not long enough");let s=t.sublist(r,r+n);return this.rs=this.ss.decryptAndHash(s),n}readEE(){this.writeEE()}readES(){this.writeES()}readSE(){this.writeSE()}},Dr=class extends Ho{writeMessageA(t){return new G(this.writeE(),this.ss.encryptAndHash(t))}writeMessageB(t){let r=this.writeE();this.writeEE();let n=this.writeS();return this.writeES(),new G(r,n,this.ss.encryptAndHash(t))}writeMessageC(t){let r=this.writeS();return this.writeSE(),new G(r,this.ss.encryptAndHash(t))}readMessageA(t){try{return this.readE(t),this.ss.decryptAndHash(t.sublist(32))}catch(r){throw new sr(`handshake stage 0 validation fail: ${r.message}`)}}readMessageB(t){try{this.readE(t),this.readEE();let r=this.readS(t,32);return this.readES(),this.ss.decryptAndHash(t.sublist(32+r))}catch(r){throw new sr(`handshake stage 1 validation fail: ${r.message}`)}}readMessageC(t){try{let r=this.readS(t);return this.readSE(),this.ss.decryptAndHash(t.sublist(r))}catch(r){throw new sr(`handshake stage 2 validation fail: ${r.message}`)}}};function qh(e,t){if(t.length<=32){let r=nt(32);return r.set(t),r}else return e.hash(t)}var Un;(function(e){let t;e.codec=()=>(t==null&&(t=Be((r,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),r.webtransportCerthashes!=null)for(let o of r.webtransportCerthashes)n.uint32(10),n.bytes(o);if(r.streamMuxers!=null)for(let o of r.streamMuxers)n.uint32(18),n.string(o);s.lengthDelimited!==!1&&n.ldelim()},(r,n,s={})=>{let o={webtransportCerthashes:[],streamMuxers:[]},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{if(s.limits?.webtransportCerthashes!=null&&o.webtransportCerthashes.length===s.limits.webtransportCerthashes)throw new Ir('Decode error - map field "webtransportCerthashes" had too many elements');o.webtransportCerthashes.push(r.bytes());break}case 2:{if(s.limits?.streamMuxers!=null&&o.streamMuxers.length===s.limits.streamMuxers)throw new Ir('Decode error - map field "streamMuxers" had too many elements');o.streamMuxers.push(r.string());break}default:{r.skipType(a&7);break}}}return o})),t),e.encode=r=>Ae(r,e.codec()),e.decode=(r,n)=>Se(r,e.codec(),n)})(Un||(Un={}));var Pr;(function(e){let t;e.codec=()=>(t==null&&(t=Be((r,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),r.identityKey!=null&&r.identityKey.byteLength>0&&(n.uint32(10),n.bytes(r.identityKey)),r.identitySig!=null&&r.identitySig.byteLength>0&&(n.uint32(18),n.bytes(r.identitySig)),r.extensions!=null&&(n.uint32(34),Un.codec().encode(r.extensions,n)),s.lengthDelimited!==!1&&n.ldelim()},(r,n,s={})=>{let o={identityKey:nt(0),identitySig:nt(0)},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{o.identityKey=r.bytes();break}case 2:{o.identitySig=r.bytes();break}case 4:{o.extensions=Un.codec().decode(r,r.uint32(),{limits:s.limits?.extensions});break}default:{r.skipType(a&7);break}}}return o})),t),e.encode=r=>Ae(r,e.codec()),e.decode=(r,n)=>Se(r,e.codec(),n)})(Pr||(Pr={}));async function Vo(e,t,r){let n=await e.sign(yc(t));return Pr.encode({identityKey:te(e.publicKey),identitySig:n,extensions:r})}async function Fo(e,t,r){try{let n=Pr.decode(e),s=Kr(n.identityKey);if(r?.equals(s)===!1)throw new Error(`Payload identity key ${s} does not match expected remote identity key ${r}`);if(!t)throw new Error("Remote static does not exist");let o=yc(t);if(!await s.verify(o,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new kr(n.message)}}function yc(e){let t=Y("noise-libp2p-static-key:");return e instanceof Uint8Array?le([t,e],t.length+e.length):(e.prepend(t),e)}var qo=class extends vn{stream;handshake;metrics;decoder;constructor(t,r,n){super({log:t.log,inactivityTimeout:t.inactivityTimeout,maxReadBufferLength:t.maxReadBufferLength,direction:t.direction}),this.stream=t,this.handshake=r,this.metrics=n,this.decoder=new Bn({lengthDecoder:nr,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(t){let r=new G;for(let n=0;n<t.byteLength;n+=65519){let s=n+65519;s>t.byteLength&&(s=t.byteLength);let o;t instanceof Uint8Array?o=this.handshake.encrypt(t.subarray(n,s)):o=this.handshake.encrypt(t.sublist(n,s)),this.metrics?.encryptedPackets.increment(),r.append(rr(o.byteLength)),r.append(o)}return r}decrypt(t){let r=new G;for(let n=0;n<t.byteLength;n+=65535){let s=n+65535;if(s>t.byteLength&&(s=t.byteLength),s-Lo<n)throw new Error("Invalid chunk");let o;t instanceof Uint8Array?o=t.subarray(n,s):o=t.sublist(n,s);let i=t.subarray(n,s-Lo);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(t){return this.stream.close(t)}sendPause(){this.stream.pause()}sendResume(){this.stream.resume()}sendReset(t){this.stream.abort(t)}sendData(t){return{sentBytes:t.byteLength,canSendMore:this.stream.send(this.encrypt(t))}}};function zo(e,t,r){return new qo(e,t,r)}async function gc(e,t){let{log:r,connection:n,crypto:s,privateKey:o,prologue:i,s:a,remoteIdentityKey:c,extensions:u}=e,f=await Vo(o,a.publicKey,u),h=new Dr({crypto:s,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:i,s:a});Po(h.s,r),r.trace("Stage 0 - Initiator starting to send first message."),await n.write(h.writeMessageA(_e),t),r.trace("Stage 0 - Initiator finished sending first message."),No(h.e,r),r.trace("Stage 1 - Initiator waiting to receive first message from responder...");let l=h.readMessageB(await n.read(t));r.trace("Stage 1 - Initiator received the message."),ko(h.re,r),pc(h.rs,r),r.trace("Initiator going to check remote's signature...");let d=await Fo(l,h.rs,c);r.trace("All good with the signature!"),r.trace("Stage 2 - Initiator sending third handshake message."),await n.write(h.writeMessageC(f),t),r.trace("Stage 2 - Initiator sent message with signed payload.");let[p,w]=h.ss.split();return Mo(p,w,r),{payload:d,encrypt:g=>p.encryptWithAd(_e,g),decrypt:(g,x)=>w.decryptWithAd(_e,g,x)}}async function bc(e,t){let{log:r,connection:n,crypto:s,privateKey:o,prologue:i,s:a,remoteIdentityKey:c,extensions:u}=e,f=await Vo(o,a.publicKey,u),h=new Dr({crypto:s,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:i,s:a});Po(h.s,r),r.trace("Stage 0 - Responder waiting to receive first message."),h.readMessageA(await n.read(t)),r.trace("Stage 0 - Responder received first message."),ko(h.re,r),r.trace("Stage 1 - Responder sending out first message with signed payload and static key."),await n.write(h.writeMessageB(f),t),r.trace("Stage 1 - Responder sent the second handshake message with signed payload."),No(h.e,r),r.trace("Stage 2 - Responder waiting for third handshake message...");let l=h.readMessageC(await n.read(t));r.trace("Stage 2 - Responder received the message, finished handshake.");let d=await Fo(l,h.rs,c),[p,w]=h.ss.split();return Mo(p,w,r),{payload:d,encrypt:g=>w.encryptWithAd(_e,g),decrypt:(g,x)=>p.decryptWithAd(_e,g,x)}}var Dn=class{protocol="/noise";crypto;prologue;staticKey;extensions;metrics;components;log;constructor(t,r={}){let{staticNoiseKey:n,extensions:s,crypto:o,prologueBytes:i}=r,{metrics:a}=t;this.components=t,this.log=t.logger.forComponent("libp2p:noise");let c=o??hc;this.crypto=lc(c),this.extensions={webtransportCerthashes:[],...s},this.metrics=a?dc(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=i??nt(0)}[Symbol.toStringTag]="@libp2p/noise";[$o]=["@libp2p/connection-encryption","@libp2p/noise"];async secureOutbound(t,r){let n=t.log?.newScope("noise")??this.log,s=Bo(t,{lengthEncoder:rr,lengthDecoder:nr,maxDataLength:65535}),o=await this.performHandshakeInitiator(s,this.components.privateKey,n,r?.remotePeer?.publicKey,r),i=Kr(o.payload.identityKey);return{connection:zo(s.unwrap(),o,this.metrics),remoteExtensions:o.payload.extensions,remotePeer:go(i),streamMuxer:r?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(o.payload.extensions?.streamMuxers)}}getStreamMuxer(t){if(t==null||t.length===0)return;let r=this.components.upgrader.getStreamMuxers();if(r!=null)for(let n of t){let s=r.get(n);if(s!=null)return s}if(t.length)throw new Mr("Early muxer negotiation was requested but the initiator and responder had no common muxers")}async secureInbound(t,r){let n=t.log?.newScope("noise")??this.log,s=Bo(t,{lengthEncoder:rr,lengthDecoder:nr,maxDataLength:65535}),o=await this.performHandshakeResponder(s,this.components.privateKey,n,r?.remotePeer?.publicKey,r),i=Kr(o.payload.identityKey);return{connection:zo(s.unwrap(),o,this.metrics),remoteExtensions:o.payload.extensions,remotePeer:go(i),streamMuxer:r?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(o.payload.extensions?.streamMuxers)}}async performHandshakeInitiator(t,r,n,s,o){let i,a=o?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{i=await gc({connection:t,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(t,r,n,s,o){let i,a=o?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{i=await bc({connection:t,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 Vh(e={}){return t=>new Dn(t,e)}return vc(Fh);})();
2
+ "use strict";var Libp2PNoise=(()=>{var xn=Object.defineProperty;var ec=Object.getOwnPropertyDescriptor;var rc=Object.getOwnPropertyNames;var nc=Object.prototype.hasOwnProperty;var gt=(e,t)=>{for(var r in t)xn(e,r,{get:t[r],enumerable:!0})},sc=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of rc(t))!nc.call(e,s)&&s!==r&&xn(e,s,{get:()=>t[s],enumerable:!(n=ec(t,s))||n.enumerable});return e};var oc=e=>sc(xn({},"__esModule",{value:!0}),e);var lh={};gt(lh,{noise:()=>hh,pureJsCrypto:()=>mn});var Lr=class extends Error{static name="UnexpectedPeerError";constructor(t="Unexpected Peer"){super(t),this.name="UnexpectedPeerError"}},Ir=class extends Error{static name="InvalidCryptoExchangeError";constructor(t="Invalid crypto exchange"){super(t),this.name="InvalidCryptoExchangeError"}},Q=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},xe=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var _r=class extends Error{static name="StreamResetError";constructor(t="The stream has been reset"){super(t),this.name="StreamResetError"}};var ee=class extends Error{static name="StreamStateError";constructor(t="The stream is in an invalid state"){super(t),this.name="StreamStateError"}},We=class extends Error{static name="StreamBufferError";constructor(t="The stream buffer was full"){super(t),this.name="StreamBufferError"}};var we=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Rr=class extends Event{data;constructor(t,r){super("message",r),this.data=t}},Ee=class extends Event{error;local;constructor(t,r,n){super("close",n),this.error=r,this.local=t}},Tr=class extends Ee{constructor(t,r){super(!0,t,r)}},Kr=class extends Ee{constructor(t,r){super(!1,t,r)}};var wn=Symbol.for("@libp2p/peer-id");var Cr=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let r=this.#t.get(t);return r==null?0:r.length}addEventListener(t,r,n){super.addEventListener(t,r,n);let s=this.#t.get(t);s==null&&(s=[],this.#t.set(t,s)),s.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,r,n){super.removeEventListener(t.toString(),r??null,n);let s=this.#t.get(t);s!=null&&(s=s.filter(({callback:o})=>o!==r),this.#t.set(t,s))}dispatchEvent(t){let r=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:s})=>!s),this.#t.set(t.type,n)),r}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var To=Symbol.for("@libp2p/service-capabilities"),bh=Symbol.for("@libp2p/service-dependencies");var Bn={};gt(Bn,{base58btc:()=>rt,base58flickr:()=>lc});var zh=new Uint8Array(0);function Ko(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Dt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function Co(e){return new TextEncoder().encode(e)}function Do(e){return new TextDecoder().decode(e)}function ic(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var s=0;s<e.length;s++){var o=e.charAt(s),i=o.charCodeAt(0);if(r[i]!==255)throw new TypeError(o+" is ambiguous");r[i]=s}var a=e.length,c=e.charAt(0),h=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function u(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var S=0,l=0,g=0,B=d.length;g!==B&&d[g]===0;)g++,S++;for(var w=(B-g)*f+1>>>0,K=new Uint8Array(w);g!==B;){for(var P=d[g],M=0,O=w-1;(P!==0||M<l)&&O!==-1;O--,M++)P+=256*K[O]>>>0,K[O]=P%a>>>0,P=P/a>>>0;if(P!==0)throw new Error("Non-zero carry");l=M,g++}for(var L=w-l;L!==w&&K[L]===0;)L++;for(var A=c.repeat(S);L<w;++L)A+=e.charAt(K[L]);return A}function b(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var S=0;if(d[S]!==" "){for(var l=0,g=0;d[S]===c;)l++,S++;for(var B=(d.length-S)*h+1>>>0,w=new Uint8Array(B);d[S];){var K=r[d.charCodeAt(S)];if(K===255)return;for(var P=0,M=B-1;(K!==0||P<g)&&M!==-1;M--,P++)K+=a*w[M]>>>0,w[M]=K%256>>>0,K=K/256>>>0;if(K!==0)throw new Error("Non-zero carry");g=P,S++}if(d[S]!==" "){for(var O=B-g;O!==B&&w[O]===0;)O++;for(var L=new Uint8Array(l+(B-O)),A=l;O!==B;)L[A++]=w[O++];return L}}}function y(d){var S=b(d);if(S)return S;throw new Error(`Non-${t} character`)}return{encode:u,decodeUnsafe:b,decode:y}}var ac=ic,cc=ac,No=cc;var En=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Sn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,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(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return ko(this,t)}},An=class{decoders;constructor(t){this.decoders=t}or(t){return ko(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function ko(e,t){return new An({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var vn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,s){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=s,this.encoder=new En(t,r,n),this.decoder=new Sn(t,r,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Se({name:e,prefix:t,encode:r,decode:n}){return new vn(e,t,r,n)}function zt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:s}=No(r,e);return Se({prefix:t,name:e,encode:n,decode:o=>Dt(s(o))})}function fc(e,t,r,n){let s=e.length;for(;e[s-1]==="=";)--s;let o=new Uint8Array(s*r/8|0),i=0,a=0,c=0;for(let h=0;h<s;++h){let f=t[e[h]];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 uc(e,t,r){let n=t[t.length-1]==="=",s=(1<<r)-1,o="",i=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],i+=8;i>r;)i-=r,o+=t[s&a>>i];if(i!==0&&(o+=t[s&a<<r-i]),n)for(;(o.length*r&7)!==0;)o+="=";return o}function hc(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function tt({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let s=hc(n);return Se({prefix:t,name:e,encode(o){return uc(o,n,r)},decode(o){return fc(o,s,r,e)}})}var rt=zt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),lc=zt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ln={};gt(Ln,{base32:()=>Ae,base32hex:()=>yc,base32hexpad:()=>bc,base32hexpadupper:()=>xc,base32hexupper:()=>gc,base32pad:()=>pc,base32padupper:()=>mc,base32upper:()=>dc,base32z:()=>wc});var Ae=tt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),dc=tt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),pc=tt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),mc=tt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),yc=tt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),gc=tt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),bc=tt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),xc=tt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),wc=tt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var In={};gt(In,{base36:()=>Xe,base36upper:()=>Ec});var Xe=zt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ec=zt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Sc=Oo,Po=128,Ac=127,vc=~Ac,Bc=Math.pow(2,31);function Oo(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Bc;)t[r++]=e&255|Po,e/=128;for(;e&vc;)t[r++]=e&255|Po,e>>>=7;return t[r]=e|0,Oo.bytes=r-n+1,t}var Lc=_n,Ic=128,Mo=127;function _n(e,n){var r=0,n=n||0,s=0,o=n,i,a=e.length;do{if(o>=a)throw _n.bytes=0,new RangeError("Could not decode varint");i=e[o++],r+=s<28?(i&Mo)<<s:(i&Mo)*Math.pow(2,s),s+=7}while(i>=Ic);return _n.bytes=o-n,r}var _c=Math.pow(2,7),Rc=Math.pow(2,14),Tc=Math.pow(2,21),Kc=Math.pow(2,28),Cc=Math.pow(2,35),Dc=Math.pow(2,42),Uc=Math.pow(2,49),Nc=Math.pow(2,56),kc=Math.pow(2,63),Pc=function(e){return e<_c?1:e<Rc?2:e<Tc?3:e<Kc?4:e<Cc?5:e<Dc?6:e<Uc?7:e<Nc?8:e<kc?9:10},Mc={encode:Sc,decode:Lc,encodingLength:Pc},Oc=Mc,Je=Oc;function Qe(e,t=0){return[Je.decode(e,t),Je.decode.bytes]}function ve(e,t,r=0){return Je.encode(e,t,r),t}function Be(e){return Je.encodingLength(e)}function It(e,t){let r=t.byteLength,n=Be(e),s=n+Be(r),o=new Uint8Array(s+r);return ve(e,o,0),ve(r,o,n),o.set(t,s),new Le(e,r,t,o)}function Rn(e){let t=Dt(e),[r,n]=Qe(t),[s,o]=Qe(t.subarray(n)),i=t.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new Le(r,s,i,t)}function Ho(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Ko(e.bytes,r.bytes)}}var Le=class{code;size;digest;bytes;constructor(t,r,n,s){this.code=t,this.size=r,this.digest=n,this.bytes=s}};function qo(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return qc(r,Tn(e),t??rt.encoder);default:return Vc(r,Tn(e),t??Ae.encoder)}}var Vo=new WeakMap;function Tn(e){let t=Vo.get(e);if(t==null){let r=new Map;return Vo.set(e,r),r}return t}var lt=class e{code;version;multihash;bytes;"/";constructor(t,r,n,s){this.code=r,this.version=t,this.multihash=n,this.bytes=s,this["/"]=s}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==tr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Fc)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.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:t,digest:r}=this.multihash,n=It(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&Ho(t.multihash,n.multihash)}toString(t){return qo(this,t)}toJSON(){return{"/":qo(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:s,multihash:o,bytes:i}=r;return new e(n,s,o,i??Fo(n,s,o.bytes))}else if(r[zc]===!0){let{version:n,multihash:s,code:o}=r,i=Rn(s);return e.create(n,o,i)}else return null}static create(t,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(t){case 0:{if(r!==tr)throw new Error(`Version 0 CID must use dag-pb (code: ${tr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let s=Fo(t,r,n.bytes);return new e(t,r,n,s)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,tr,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,s=Dt(t.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 Le(r.multihashCode,r.digestSize,o,s);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[u,b]=Qe(t.subarray(r));return r+=b,u},s=n(),o=tr;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(),h=r+c,f=h-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:f,size:h}}static parse(t,r){let[n,s]=Hc(t,r),o=e.decode(s);if(o.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Tn(o).set(n,t),o}};function Hc(e,t){switch(e[0]){case"Q":{let r=t??rt;return[rt.prefix,r.decode(`${rt.prefix}${e}`)]}case rt.prefix:{let r=t??rt;return[rt.prefix,r.decode(e)]}case Ae.prefix:{let r=t??Ae;return[Ae.prefix,r.decode(e)]}case Xe.prefix:{let r=t??Xe;return[Xe.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function qc(e,t,r){let{prefix:n}=r;if(n!==rt.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let s=t.get(n);if(s==null){let o=r.encode(e).slice(1);return t.set(n,o),o}else return s}function Vc(e,t,r){let{prefix:n}=r,s=t.get(n);if(s==null){let o=r.encode(e);return t.set(n,o),o}else return s}var tr=112,Fc=18;function Fo(e,t,r){let n=Be(e),s=n+Be(t),o=new Uint8Array(s+r.byteLength);return ve(e,o,0),ve(t,o,n),o.set(r,s),o}var zc=Symbol.for("@ipld/js-cid/CID");var Kn={};gt(Kn,{identity:()=>_t});var zo=0,Gc="identity",Go=Dt;function $c(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return It(zo,Go(e))}var _t={code:zo,name:Gc,encode:Go,digest:$c};function mt(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function st(e=0){return new Uint8Array(e)}function ft(e=0){return new Uint8Array(e)}function re(e,t){t==null&&(t=e.reduce((s,o)=>s+o.length,0));let r=ft(t),n=0;for(let s of e)r.set(s,n),n+=s.length;return r}var Zo=Symbol.for("@achingbrain/uint8arraylist");function $o(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let s=r+n.byteLength;if(t<s)return{buf:n,index:t-r};r=s}throw new RangeError("index is out of bounds")}function Ur(e){return!!e?.[Zo]}var $=class e{bufs;length;[Zo]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Ur(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Ur(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(t){let r=$o(this.bufs,t);return r.buf[r.index]}set(t,r){let n=$o(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(Ur(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:s}=this._subList(t,r);return re(n,s)}subarray(t,r){let{bufs:n,length:s}=this._subList(t,r);return n.length===1?n[0]:re(n,s)}sublist(t,r){let{bufs:n,length:s}=this._subList(t,r),o=new e;return o.length=s,o.bufs=[...n],o}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===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,t>=c)continue;let h=t>=a&&t<c,f=r>a&&r<=c;if(h&&f){if(t===a&&r===c){n.push(i);break}let u=t-a;n.push(i.subarray(u,u+(r-t)));break}if(h){if(t===0){n.push(i);continue}n.push(i.subarray(t-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-t}}indexOf(t,r=0){if(!Ur(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.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 u=0;u<o;u++)i[u]=-1;for(let u=0;u<s;u++)i[n[u]]=u;let a=i,c=this.byteLength-n.byteLength,h=n.byteLength-1,f;for(let u=r;u<=c;u+=f){f=0;for(let b=h;b>=0;b--){let y=this.get(u+b);if(n[b]!==y){f=Math.max(1,b-a[y]);break}}if(f===0)return u}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=ft(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let s=st(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,r,n),this.write(s,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let s=st(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,r,n),this.write(s,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let s=st(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,r,n),this.write(s,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=ft(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let s=st(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,r,n),this.write(s,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let s=st(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,r,n),this.write(s,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let s=st(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,r,n),this.write(s,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let s=st(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,r,n),this.write(s,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let s=st(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,r,n),this.write(s,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!mt(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((s,o)=>s+o.byteLength,0)),n.length=r,n}};var Cn={};gt(Cn,{base10:()=>jc});var jc=zt({prefix:"9",name:"base10",alphabet:"0123456789"});var Dn={};gt(Dn,{base16:()=>Yc,base16upper:()=>Wc});var Yc=tt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Wc=tt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Un={};gt(Un,{base2:()=>Xc});var Xc=tt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Nn={};gt(Nn,{base256emoji:()=>rf});var jo=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}"),Jc=jo.reduce((e,t,r)=>(e[r]=t,e),[]),Qc=jo.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function tf(e){return e.reduce((t,r)=>(t+=Jc[r],t),"")}function ef(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let s=Qc[n];if(s==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(s)}return new Uint8Array(t)}var rf=Se({prefix:"\u{1F680}",name:"base256emoji",encode:tf,decode:ef});var kn={};gt(kn,{base64:()=>nf,base64pad:()=>sf,base64url:()=>of,base64urlpad:()=>af});var nf=tt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),sf=tt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),of=tt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),af=tt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Pn={};gt(Pn,{base8:()=>cf});var cf=tt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Mn={};gt(Mn,{identity:()=>ff});var ff=Se({prefix:"\0",name:"identity",encode:e=>Do(e),decode:e=>Co(e)});var Ll=new TextEncoder,Il=new TextDecoder;var qn={};gt(qn,{sha256:()=>Nr,sha512:()=>df});var lf=20;function Hn({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:s}){return new On(e,t,r,n,s)}var On=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,s,o){this.name=t,this.code=r,this.encode=n,this.minDigestLength=s??lf,this.maxDigestLength=o}digest(t,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(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Yo(n,this.code,r?.truncate):n.then(s=>Yo(s,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Yo(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return It(t,e)}function Xo(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Nr=Hn({name:"sha2-256",code:18,encode:Xo("SHA-256")}),df=Hn({name:"sha2-512",code:19,encode:Xo("SHA-512")});var Vn={...Mn,...Un,...Pn,...Cn,...Dn,...Ln,...In,...Bn,...kn,...Nn},Ol={...qn,...Kn};function Qo(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Jo=Qo("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Fn=Qo("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=ft(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),pf={utf8:Jo,"utf-8":Jo,hex:Vn.base16,latin1:Fn,ascii:Fn,binary:Fn,...Vn},kr=pf;function W(e,t="utf8"){let r=kr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function Z(e,t="utf8"){let r=kr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var mf=parseInt("11111",2),zn=parseInt("10000000",2),yf=parseInt("01111111",2),ti={0:er,1:er,2:gf,3:wf,4:Ef,5:xf,6:bf,16:er,22:er,48:er};function Ut(e,t={offset:0}){let r=e[t.offset]&mf;if(t.offset++,ti[r]!=null)return ti[r](e,t);throw new Error("No decoder for tag "+r)}function rr(e,t){let r=0;if((e[t.offset]&zn)===zn){let n=e[t.offset]&yf,s="0x";t.offset++;for(let o=0;o<n;o++,t.offset++)s+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(s,16)}else r=e[t.offset],t.offset++;return r}function er(e,t){rr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Ut(e,t);if(n===null)break;r.push(n)}return r}function gf(e,t){let r=rr(e,t),n=t.offset,s=t.offset+r,o=[];for(let i=n;i<s;i++)i===n&&e[i]===0||o.push(e[i]);return t.offset+=r,Uint8Array.from(o)}function bf(e,t){let r=rr(e,t),n=t.offset+r,s=e[t.offset];t.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(;t.offset<n;){let h=e[t.offset];if(t.offset++,c.push(h&127),h<128){c.reverse();let f=0;for(let u=0;u<c.length;u++)f+=c[u]<<u*7;a+=`.${f}`,c=[]}}return a}function xf(e,t){return t.offset++,null}function wf(e,t){let r=rr(e,t),n=e[t.offset];t.offset++;let s=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return s}function Ef(e,t){let r=rr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Sf(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new $;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Gn(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Sf(e.byteLength);return new $(Uint8Array.from([t.byteLength|zn]),t)}function bt(e){let t=new $,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new $(Uint8Array.from([2]),Gn(t),t)}function Pr(e){let t=Uint8Array.from([0]),r=new $(t,e);return new $(Uint8Array.from([3]),Gn(r),r)}function Gt(e,t=48){let r=new $;for(let n of e)r.append(n);return new $(Uint8Array.from([t]),Gn(r),r)}async function ei(e,t,r,n){let s=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let o=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},s,t,r.subarray());return n?.signal?.throwIfAborted(),o}var Af=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),vf=Uint8Array.from([6,5,43,129,4,0,34]),Bf=Uint8Array.from([6,5,43,129,4,0,35]),Lf={ext:!0,kty:"EC",crv:"P-256"},If={ext:!0,kty:"EC",crv:"P-384"},_f={ext:!0,kty:"EC",crv:"P-521"},$n=32,Zn=48,jn=66;function ri(e){let t=Ut(e);return ni(t)}function ni(e){let t=e[1][1][0],r=1,n,s;if(t.byteLength===$n*2+1)return n=Z(t.subarray(r,r+$n),"base64url"),s=Z(t.subarray(r+$n),"base64url"),new _e({...Lf,key_ops:["verify"],x:n,y:s});if(t.byteLength===Zn*2+1)return n=Z(t.subarray(r,r+Zn),"base64url"),s=Z(t.subarray(r+Zn),"base64url"),new _e({...If,key_ops:["verify"],x:n,y:s});if(t.byteLength===jn*2+1)return n=Z(t.subarray(r,r+jn),"base64url"),s=Z(t.subarray(r+jn),"base64url"),new _e({..._f,key_ops:["verify"],x:n,y:s});throw new Q(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function si(e){return Gt([bt(Uint8Array.from([1])),Gt([Rf(e.crv)],160),Gt([Pr(new $(Uint8Array.from([4]),W(e.x??"","base64url"),W(e.y??"","base64url")))],161)]).subarray()}function Rf(e){if(e==="P-256")return Af;if(e==="P-384")return vf;if(e==="P-521")return Bf;throw new Q(`Invalid curve ${e}`)}var _e=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=si(this.jwk)),this._raw}toMultihash(){return _t.digest($t(this))}toCID(){return lt.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:mt(this.raw,t.raw)}async verify(t,r,n){return ei(this.jwk,r,t,n)}};function ne(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Et(e,t=""){if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new Error(`${r}expected integer >= 0, got ${e}`)}}function H(e,t,r=""){let n=ne(e),s=e?.length,o=t!==void 0;if(!n||o&&s!==t){let i=r&&`"${r}" `,a=o?` of length ${t}`:"",c=n?`length=${s}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return e}function se(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash must wrapped by utils.createHasher");Et(e.outputLen),Et(e.blockLen)}function Re(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function ii(e,t){H(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function At(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Mr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function vt(e,t){return e<<32-t|e>>>t}var ai=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Tf=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function kt(e){if(H(e),ai)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Tf[e[r]];return t}var Nt={_0:48,_9:57,A:65,F:70,a:97,f:102};function oi(e){if(e>=Nt._0&&e<=Nt._9)return e-Nt._0;if(e>=Nt.A&&e<=Nt.F)return e-(Nt.A-10);if(e>=Nt.a&&e<=Nt.f)return e-(Nt.a-10)}function Pt(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(ai)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let s=0,o=0;s<r;s++,o+=2){let i=oi(e.charCodeAt(o)),a=oi(e.charCodeAt(o+1));if(i===void 0||a===void 0){let c=e[o]+e[o+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+o)}n[s]=i*16+a}return n}function xt(...e){let t=0;for(let n=0;n<e.length;n++){let s=e[n];H(s),t+=s.length}let r=new Uint8Array(t);for(let n=0,s=0;n<e.length;n++){let o=e[n];r.set(o,s),s+=o.length}return r}function Yn(e,t={}){let r=(s,o)=>e(o).update(s).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=s=>e(s),Object.assign(r,t),Object.freeze(r)}function Zt(e=32){let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(e))}var Wn=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function ci(e,t,r){return e&t^~e&r}function fi(e,t,r){return e&t^e&r^t&r}var nr=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,s){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(t),this.view=Mr(this.buffer)}update(t){Re(this),H(t);let{view:r,buffer:n,blockLen:s}=this,o=t.length;for(let i=0;i<o;){let a=Math.min(s-this.pos,o-i);if(a===s){let c=Mr(t);for(;s<=o-i;i+=s)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===s&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Re(this),ii(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:s,isLE:o}=this,{pos:i}=this;r[i++]=128,At(this.buffer.subarray(i)),this.padOffset>s-i&&(this.process(n,0),i=0);for(let u=i;u<s;u++)r[u]=0;n.setBigUint64(s-8,BigInt(this.length*8),o),this.process(n,0);let a=Mr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let h=c/4,f=this.get();if(h>f.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<h;u++)a.setUint32(4*u,f[u],o)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:r,buffer:n,length:s,finished:o,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=o,t.length=s,t.pos=a,s%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Mt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ut=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Or=BigInt(4294967295),ui=BigInt(32);function Kf(e,t=!1){return t?{h:Number(e&Or),l:Number(e>>ui&Or)}:{h:Number(e>>ui&Or)|0,l:Number(e&Or)|0}}function hi(e,t=!1){let r=e.length,n=new Uint32Array(r),s=new Uint32Array(r);for(let o=0;o<r;o++){let{h:i,l:a}=Kf(e[o],t);[n[o],s[o]]=[i,a]}return[n,s]}var Xn=(e,t,r)=>e>>>r,Jn=(e,t,r)=>e<<32-r|t>>>r,oe=(e,t,r)=>e>>>r|t<<32-r,ie=(e,t,r)=>e<<32-r|t>>>r,sr=(e,t,r)=>e<<64-r|t>>>r-32,or=(e,t,r)=>e>>>r-32|t<<64-r;function Rt(e,t,r,n){let s=(t>>>0)+(n>>>0);return{h:e+r+(s/2**32|0)|0,l:s|0}}var li=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),di=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,pi=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),mi=(e,t,r,n,s)=>t+r+n+s+(e/2**32|0)|0,yi=(e,t,r,n,s)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(s>>>0),gi=(e,t,r,n,s,o)=>t+r+n+s+o+(e/2**32|0)|0;var Df=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]),jt=new Uint32Array(64),Qn=class extends nr{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:r,C:n,D:s,E:o,F:i,G:a,H:c}=this;return[t,r,n,s,o,i,a,c]}set(t,r,n,s,o,i,a,c){this.A=t|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}process(t,r){for(let u=0;u<16;u++,r+=4)jt[u]=t.getUint32(r,!1);for(let u=16;u<64;u++){let b=jt[u-15],y=jt[u-2],d=vt(b,7)^vt(b,18)^b>>>3,S=vt(y,17)^vt(y,19)^y>>>10;jt[u]=S+jt[u-7]+d+jt[u-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:h,H:f}=this;for(let u=0;u<64;u++){let b=vt(a,6)^vt(a,11)^vt(a,25),y=f+b+ci(a,c,h)+Df[u]+jt[u]|0,S=(vt(n,2)^vt(n,13)^vt(n,22))+fi(n,s,o)|0;f=h,h=c,c=a,a=i+y|0,i=o,o=s,s=n,n=y+S|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,h=h+this.G|0,f=f+this.H|0,this.set(n,s,o,i,a,c,h,f)}roundClean(){At(jt)}destroy(){this.set(0,0,0,0,0,0,0,0),At(this.buffer)}},ts=class extends Qn{A=Mt[0]|0;B=Mt[1]|0;C=Mt[2]|0;D=Mt[3]|0;E=Mt[4]|0;F=Mt[5]|0;G=Mt[6]|0;H=Mt[7]|0;constructor(){super(32)}};var bi=hi(["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(e=>BigInt(e))),Uf=bi[0],Nf=bi[1],Yt=new Uint32Array(80),Wt=new Uint32Array(80),es=class extends nr{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:r,Bh:n,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:h,El:f,Fh:u,Fl:b,Gh:y,Gl:d,Hh:S,Hl:l}=this;return[t,r,n,s,o,i,a,c,h,f,u,b,y,d,S,l]}set(t,r,n,s,o,i,a,c,h,f,u,b,y,d,S,l){this.Ah=t|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=h|0,this.El=f|0,this.Fh=u|0,this.Fl=b|0,this.Gh=y|0,this.Gl=d|0,this.Hh=S|0,this.Hl=l|0}process(t,r){for(let w=0;w<16;w++,r+=4)Yt[w]=t.getUint32(r),Wt[w]=t.getUint32(r+=4);for(let w=16;w<80;w++){let K=Yt[w-15]|0,P=Wt[w-15]|0,M=oe(K,P,1)^oe(K,P,8)^Xn(K,P,7),O=ie(K,P,1)^ie(K,P,8)^Jn(K,P,7),L=Yt[w-2]|0,A=Wt[w-2]|0,U=oe(L,A,19)^sr(L,A,61)^Xn(L,A,6),k=ie(L,A,19)^or(L,A,61)^Jn(L,A,6),T=pi(O,k,Wt[w-7],Wt[w-16]),x=mi(T,M,U,Yt[w-7],Yt[w-16]);Yt[w]=x|0,Wt[w]=T|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:h,Dl:f,Eh:u,El:b,Fh:y,Fl:d,Gh:S,Gl:l,Hh:g,Hl:B}=this;for(let w=0;w<80;w++){let K=oe(u,b,14)^oe(u,b,18)^sr(u,b,41),P=ie(u,b,14)^ie(u,b,18)^or(u,b,41),M=u&y^~u&S,O=b&d^~b&l,L=yi(B,P,O,Nf[w],Wt[w]),A=gi(L,g,K,M,Uf[w],Yt[w]),U=L|0,k=oe(n,s,28)^sr(n,s,34)^sr(n,s,39),T=ie(n,s,28)^or(n,s,34)^or(n,s,39),x=n&o^n&a^o&a,p=s&i^s&c^i&c;g=S|0,B=l|0,S=y|0,l=d|0,y=u|0,d=b|0,{h:u,l:b}=Rt(h|0,f|0,A|0,U|0),h=a|0,f=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let m=li(U,T,p);n=di(m,A,k,x),s=m|0}({h:n,l:s}=Rt(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=Rt(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=Rt(this.Ch|0,this.Cl|0,a|0,c|0),{h,l:f}=Rt(this.Dh|0,this.Dl|0,h|0,f|0),{h:u,l:b}=Rt(this.Eh|0,this.El|0,u|0,b|0),{h:y,l:d}=Rt(this.Fh|0,this.Fl|0,y|0,d|0),{h:S,l}=Rt(this.Gh|0,this.Gl|0,S|0,l|0),{h:g,l:B}=Rt(this.Hh|0,this.Hl|0,g|0,B|0),this.set(n,s,o,i,a,c,h,f,u,b,y,d,S,l,g,B)}roundClean(){At(Yt,Wt)}destroy(){At(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},rs=class extends es{Ah=ut[0]|0;Al=ut[1]|0;Bh=ut[2]|0;Bl=ut[3]|0;Ch=ut[4]|0;Cl=ut[5]|0;Dh=ut[6]|0;Dl=ut[7]|0;Eh=ut[8]|0;El=ut[9]|0;Fh=ut[10]|0;Fl=ut[11]|0;Gh=ut[12]|0;Gl=ut[13]|0;Hh=ut[14]|0;Hl=ut[15]|0;constructor(){super(64)}};var Tt=Yn(()=>new ts,Wn(1));var xi=Yn(()=>new rs,Wn(3));var ss=BigInt(0),ns=BigInt(1);function Ot(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function wi(e){if(typeof e=="bigint"){if(!Hr(e))throw new Error("positive bigint expected, got "+e)}else Et(e);return e}function ir(e){let t=wi(e).toString(16);return t.length&1?"0"+t:t}function Ei(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?ss:BigInt("0x"+e)}function Te(e){return Ei(kt(e))}function Kt(e){return Ei(kt(ae(H(e)).reverse()))}function qr(e,t){Et(t),e=wi(e);let r=Pt(e.toString(16).padStart(t*2,"0"));if(r.length!==t)throw new Error("number too large");return r}function ar(e,t){return qr(e,t).reverse()}function ae(e){return Uint8Array.from(e)}var Hr=e=>typeof e=="bigint"&&ss<=e;function kf(e,t,r){return Hr(e)&&Hr(t)&&Hr(r)&&t<=e&&e<r}function Xt(e,t,r,n){if(!kf(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function os(e){let t;for(t=0;e>ss;e>>=ns,t+=1);return t}var cr=e=>(ns<<BigInt(e))-ns;function Si(e,t,r){if(Et(e,"hashLen"),Et(t,"qByteLen"),typeof r!="function")throw new Error("hmacFn must be a function");let n=l=>new Uint8Array(l),s=Uint8Array.of(),o=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(e),h=n(e),f=0,u=()=>{c.fill(1),h.fill(0),f=0},b=(...l)=>r(h,xt(c,...l)),y=(l=s)=>{h=b(o,l),c=b(),l.length!==0&&(h=b(i,l),c=b())},d=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let l=0,g=[];for(;l<t;){c=b();let B=c.slice();g.push(B),l+=c.length}return xt(...g)};return(l,g)=>{u(),y(l);let B;for(;!(B=g(d()));)y();return u(),B}}function Ct(e,t={},r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,i,a){let c=e[o];if(a&&c===void 0)return;let h=typeof c;if(h!==i||c===null)throw new Error(`param "${o}" is invalid: expected ${i}, got ${h}`)}let s=(o,i)=>Object.entries(o).forEach(([a,c])=>n(a,c,i));s(t,!1),s(r,!0)}function Ke(e){let t=new WeakMap;return(r,...n)=>{let s=t.get(r);if(s!==void 0)return s;let o=e(r,...n);return t.set(r,o),o}}var yt=BigInt(0),ot=BigInt(1),ce=BigInt(2),Bi=BigInt(3),Li=BigInt(4),Ii=BigInt(5),Pf=BigInt(7),_i=BigInt(8),Mf=BigInt(9),Ri=BigInt(16);function J(e,t){let r=e%t;return r>=yt?r:t+r}function X(e,t,r){let n=e;for(;t-- >yt;)n*=n,n%=r;return n}function Ai(e,t){if(e===yt)throw new Error("invert: expected non-zero number");if(t<=yt)throw new Error("invert: expected positive modulus, got "+t);let r=J(e,t),n=t,s=yt,o=ot,i=ot,a=yt;for(;r!==yt;){let h=n/r,f=n%r,u=s-i*h,b=o-a*h;n=r,r=f,s=i,o=a,i=u,a=b}if(n!==ot)throw new Error("invert: does not exist");return J(s,t)}function as(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function Ti(e,t){let r=(e.ORDER+ot)/Li,n=e.pow(t,r);return as(e,n,t),n}function Of(e,t){let r=(e.ORDER-Ii)/_i,n=e.mul(t,ce),s=e.pow(n,r),o=e.mul(t,s),i=e.mul(e.mul(o,ce),s),a=e.mul(o,e.sub(i,e.ONE));return as(e,a,t),a}function Hf(e){let t=Ce(e),r=Ki(e),n=r(t,t.neg(t.ONE)),s=r(t,n),o=r(t,t.neg(n)),i=(e+Pf)/Ri;return(a,c)=>{let h=a.pow(c,i),f=a.mul(h,n),u=a.mul(h,s),b=a.mul(h,o),y=a.eql(a.sqr(f),c),d=a.eql(a.sqr(u),c);h=a.cmov(h,f,y),f=a.cmov(b,u,d);let S=a.eql(a.sqr(f),c),l=a.cmov(h,f,S);return as(a,l,c),l}}function Ki(e){if(e<Bi)throw new Error("sqrt is not defined for small field");let t=e-ot,r=0;for(;t%ce===yt;)t/=ce,r++;let n=ce,s=Ce(e);for(;vi(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Ti;let o=s.pow(n,t),i=(t+ot)/ce;return function(c,h){if(c.is0(h))return h;if(vi(c,h)!==1)throw new Error("Cannot find square root");let f=r,u=c.mul(c.ONE,o),b=c.pow(h,t),y=c.pow(h,i);for(;!c.eql(b,c.ONE);){if(c.is0(b))return c.ZERO;let d=1,S=c.sqr(b);for(;!c.eql(S,c.ONE);)if(d++,S=c.sqr(S),d===f)throw new Error("Cannot find square root");let l=ot<<BigInt(f-d-1),g=c.pow(u,l);f=d,u=c.sqr(g),b=c.mul(b,u),y=c.mul(y,g)}return y}}function qf(e){return e%Li===Bi?Ti:e%_i===Ii?Of:e%Ri===Mf?Hf(e):Ki(e)}var Ci=(e,t)=>(J(e,t)&ot)===ot,Vf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function cs(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=Vf.reduce((n,s)=>(n[s]="function",n),t);return Ct(e,r),e}function Ff(e,t,r){if(r<yt)throw new Error("invalid exponent, negatives unsupported");if(r===yt)return e.ONE;if(r===ot)return t;let n=e.ONE,s=t;for(;r>yt;)r&ot&&(n=e.mul(n,s)),s=e.sqr(s),r>>=ot;return n}function fr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),s=t.reduce((i,a,c)=>e.is0(a)?i:(n[c]=i,e.mul(i,a)),e.ONE),o=e.inv(s);return t.reduceRight((i,a,c)=>e.is0(a)?i:(n[c]=e.mul(i,n[c]),e.mul(i,a)),o),n}function vi(e,t){let r=(e.ORDER-ot)/ce,n=e.pow(t,r),s=e.eql(n,e.ONE),o=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!s&&!o&&!i)throw new Error("invalid Legendre symbol result");return s?1:o?0:-1}function zf(e,t){t!==void 0&&Et(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}var is=class{ORDER;BITS;BYTES;isLE;ZERO=yt;ONE=ot;_lengths;_sqrt;_mod;constructor(t,r={}){if(t<=yt)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&(this.sqrt=r.sqrt),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=r.allowedLengths?.slice()),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:s,nByteLength:o}=zf(t,n);if(o>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=s,this.BYTES=o,this._sqrt=void 0,Object.preventExtensions(this)}create(t){return J(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return yt<=t&&t<this.ORDER}is0(t){return t===yt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&ot)===ot}neg(t){return J(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return J(t*t,this.ORDER)}add(t,r){return J(t+r,this.ORDER)}sub(t,r){return J(t-r,this.ORDER)}mul(t,r){return J(t*r,this.ORDER)}pow(t,r){return Ff(this,t,r)}div(t,r){return J(t*Ai(r,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,r){return t+r}subN(t,r){return t-r}mulN(t,r){return t*r}inv(t){return Ai(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=qf(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?ar(t,this.BYTES):qr(t,this.BYTES)}fromBytes(t,r=!1){H(t);let{_lengths:n,BYTES:s,isLE:o,ORDER:i,_mod:a}=this;if(n){if(!n.includes(t.length)||t.length>s)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let h=new Uint8Array(s);h.set(t,o?0:h.length-t.length),t=h}if(t.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+t.length);let c=o?Kt(t):Te(t);if(a&&(c=J(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return fr(this,t)}cmov(t,r,n){return n?r:t}};function Ce(e,t={}){return new is(e,t)}function Di(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function fs(e){let t=Di(e);return t+Math.ceil(t/2)}function us(e,t,r=!1){H(e);let n=e.length,s=Di(t),o=fs(t);if(n<16||n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);let i=r?Kt(e):Te(e),a=J(i,t-ot)+ot;return r?ar(a,s):qr(a,s)}var De=BigInt(0),fe=BigInt(1);function ur(e,t){let r=t.negate();return e?r:t}function ue(e,t){let r=fr(e.Fp,t.map(n=>n.Z));return t.map((n,s)=>e.fromAffine(n.toAffine(r[s])))}function Pi(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function hs(e,t){Pi(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),s=2**e,o=cr(e),i=BigInt(e);return{windows:r,windowSize:n,mask:o,maxNumber:s,shiftBy:i}}function Ui(e,t,r){let{windowSize:n,mask:s,maxNumber:o,shiftBy:i}=r,a=Number(e&s),c=e>>i;a>n&&(a-=o,c+=fe);let h=t*n,f=h+Math.abs(a)-1,u=a===0,b=a<0,y=t%2!==0;return{nextN:c,offset:f,isZero:u,isNeg:b,isNegF:y,offsetF:h}}var ls=new WeakMap,Mi=new WeakMap;function ds(e){return Mi.get(e)||1}function Ni(e){if(e!==De)throw new Error("invalid wNAF")}var Ue=class{BASE;ZERO;Fn;bits;constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let s=t;for(;r>De;)r&fe&&(n=n.add(s)),s=s.double(),r>>=fe;return n}precomputeWindow(t,r){let{windows:n,windowSize:s}=hs(r,this.bits),o=[],i=t,a=i;for(let c=0;c<n;c++){a=i,o.push(a);for(let h=1;h<s;h++)a=a.add(i),o.push(a);i=a.double()}return o}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let s=this.ZERO,o=this.BASE,i=hs(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:h,isZero:f,isNeg:u,isNegF:b,offsetF:y}=Ui(n,a,i);n=c,f?o=o.add(ur(b,r[y])):s=s.add(ur(u,r[h]))}return Ni(n),{p:s,f:o}}wNAFUnsafe(t,r,n,s=this.ZERO){let o=hs(t,this.bits);for(let i=0;i<o.windows&&n!==De;i++){let{nextN:a,offset:c,isZero:h,isNeg:f}=Ui(n,i,o);if(n=a,!h){let u=r[c];s=s.add(f?u.negate():u)}}return Ni(n),s}getPrecomputes(t,r,n){let s=ls.get(r);return s||(s=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(s=n(s)),ls.set(r,s))),s}cached(t,r,n){let s=ds(t);return this.wNAF(s,this.getPrecomputes(s,t,n),r)}unsafe(t,r,n,s){let o=ds(t);return o===1?this._unsafeLadder(t,r,s):this.wNAFUnsafe(o,this.getPrecomputes(o,t,n),r,s)}createCache(t,r){Pi(r,this.bits),Mi.set(t,r),ls.delete(t)}hasCache(t){return ds(t)!==1}};function Oi(e,t,r,n){let s=t,o=e.ZERO,i=e.ZERO;for(;r>De||n>De;)r&fe&&(o=o.add(s)),n&fe&&(i=i.add(s)),s=s.double(),r>>=fe,n>>=fe;return{p1:o,p2:i}}function ki(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return cs(t),t}else return Ce(e,{isLE:r})}function Vr(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let c of["p","n","h"]){let h=t[c];if(!(typeof h=="bigint"&&h>De))throw new Error(`CURVE.${c} must be positive bigint`)}let s=ki(t.p,r.Fp,n),o=ki(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let c of a)if(!s.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:s,Fn:o}}function Ne(e,t){return function(n){let s=e(n);return{secretKey:s,publicKey:t(s)}}}var Jt=BigInt(0),it=BigInt(1),ps=BigInt(2),Gf=BigInt(8);function $f(e,t,r,n){let s=e.sqr(r),o=e.sqr(n),i=e.add(e.mul(t.a,s),o),a=e.add(e.ONE,e.mul(t.d,e.mul(s,o)));return e.eql(i,a)}function Hi(e,t={}){let r=Vr("edwards",e,t,t.FpFnLE),{Fp:n,Fn:s}=r,o=r.CURVE,{h:i}=o;Ct(t,{},{uvRatio:"function"});let a=ps<<BigInt(s.BYTES*8)-it,c=l=>n.create(l),h=t.uvRatio||((l,g)=>{try{return{isValid:!0,value:n.sqrt(n.div(l,g))}}catch{return{isValid:!1,value:Jt}}});if(!$f(n,o,o.Gx,o.Gy))throw new Error("bad curve params: generator point");function f(l,g,B=!1){let w=B?it:Jt;return Xt("coordinate "+l,g,w,a),g}function u(l){if(!(l instanceof d))throw new Error("EdwardsPoint expected")}let b=Ke((l,g)=>{let{X:B,Y:w,Z:K}=l,P=l.is0();g==null&&(g=P?Gf:n.inv(K));let M=c(B*g),O=c(w*g),L=n.mul(K,g);if(P)return{x:Jt,y:it};if(L!==it)throw new Error("invZ was invalid");return{x:M,y:O}}),y=Ke(l=>{let{a:g,d:B}=o;if(l.is0())throw new Error("bad point: ZERO");let{X:w,Y:K,Z:P,T:M}=l,O=c(w*w),L=c(K*K),A=c(P*P),U=c(A*A),k=c(O*g),T=c(A*c(k+L)),x=c(U+c(B*c(O*L)));if(T!==x)throw new Error("bad point: equation left != right (1)");let p=c(w*K),m=c(P*M);if(p!==m)throw new Error("bad point: equation left != right (2)");return!0});class d{static BASE=new d(o.Gx,o.Gy,it,c(o.Gx*o.Gy));static ZERO=new d(Jt,it,it,Jt);static Fp=n;static Fn=s;X;Y;Z;T;constructor(g,B,w,K){this.X=f("x",g),this.Y=f("y",B),this.Z=f("z",w,!0),this.T=f("t",K),Object.freeze(this)}static CURVE(){return o}static fromAffine(g){if(g instanceof d)throw new Error("extended point not allowed");let{x:B,y:w}=g||{};return f("x",B),f("y",w),new d(B,w,it,c(B*w))}static fromBytes(g,B=!1){let w=n.BYTES,{a:K,d:P}=o;g=ae(H(g,w,"point")),Ot(B,"zip215");let M=ae(g),O=g[w-1];M[w-1]=O&-129;let L=Kt(M),A=B?a:n.ORDER;Xt("point.y",L,Jt,A);let U=c(L*L),k=c(U-it),T=c(P*U-K),{isValid:x,value:p}=h(k,T);if(!x)throw new Error("bad point: invalid y coordinate");let m=(p&it)===it,v=(O&128)!==0;if(!B&&p===Jt&&v)throw new Error("bad point: x=0 and x_0=1");return v!==m&&(p=c(-p)),d.fromAffine({x:p,y:L})}static fromHex(g,B=!1){return d.fromBytes(Pt(g),B)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,B=!0){return S.createCache(this,g),B||this.multiply(ps),this}assertValidity(){y(this)}equals(g){u(g);let{X:B,Y:w,Z:K}=this,{X:P,Y:M,Z:O}=g,L=c(B*O),A=c(P*K),U=c(w*O),k=c(M*K);return L===A&&U===k}is0(){return this.equals(d.ZERO)}negate(){return new d(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:g}=o,{X:B,Y:w,Z:K}=this,P=c(B*B),M=c(w*w),O=c(ps*c(K*K)),L=c(g*P),A=B+w,U=c(c(A*A)-P-M),k=L+M,T=k-O,x=L-M,p=c(U*T),m=c(k*x),v=c(U*x),_=c(T*k);return new d(p,m,_,v)}add(g){u(g);let{a:B,d:w}=o,{X:K,Y:P,Z:M,T:O}=this,{X:L,Y:A,Z:U,T:k}=g,T=c(K*L),x=c(P*A),p=c(O*w*k),m=c(M*U),v=c((K+P)*(L+A)-T-x),_=m-p,I=m+p,E=c(x-B*T),R=c(v*_),C=c(I*E),D=c(v*E),F=c(_*I);return new d(R,C,F,D)}subtract(g){return this.add(g.negate())}multiply(g){if(!s.isValidNot0(g))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:B,f:w}=S.cached(this,g,K=>ue(d,K));return ue(d,[B,w])[0]}multiplyUnsafe(g,B=d.ZERO){if(!s.isValid(g))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return g===Jt?d.ZERO:this.is0()||g===it?this:S.unsafe(this,g,w=>ue(d,w),B)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return S.unsafe(this,o.n).is0()}toAffine(g){return b(this,g)}clearCofactor(){return i===it?this:this.multiplyUnsafe(i)}toBytes(){let{x:g,y:B}=this.toAffine(),w=n.toBytes(B);return w[w.length-1]|=g&it?128:0,w}toHex(){return kt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let S=new Ue(d,s.BITS);return d.BASE.precompute(8),d}function qi(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');Ct(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:s,Fp:o,Fn:i}=e,a=r.randomBytes||Zt,c=r.adjustScalarBytes||(L=>L),h=r.domain||((L,A,U)=>{if(Ot(U,"phflag"),A.length||U)throw new Error("Contexts/pre-hash are not supported");return L});function f(L){return i.create(Kt(L))}function u(L){let A=w.secretKey;H(L,w.secretKey,"secretKey");let U=H(t(L),2*A,"hashedSecretKey"),k=c(U.slice(0,A)),T=U.slice(A,2*A),x=f(k);return{head:k,prefix:T,scalar:x}}function b(L){let{head:A,prefix:U,scalar:k}=u(L),T=s.multiply(k),x=T.toBytes();return{head:A,prefix:U,scalar:k,point:T,pointBytes:x}}function y(L){return b(L).pointBytes}function d(L=Uint8Array.of(),...A){let U=xt(...A);return f(t(h(U,H(L,void 0,"context"),!!n)))}function S(L,A,U={}){L=H(L,void 0,"message"),n&&(L=n(L));let{prefix:k,scalar:T,pointBytes:x}=b(A),p=d(U.context,k,L),m=s.multiply(p).toBytes(),v=d(U.context,m,x,L),_=i.create(p+v*T);if(!i.isValid(_))throw new Error("sign failed: invalid s");let I=xt(m,i.toBytes(_));return H(I,w.signature,"result")}let l={zip215:!0};function g(L,A,U,k=l){let{context:T,zip215:x}=k,p=w.signature;L=H(L,p,"signature"),A=H(A,void 0,"message"),U=H(U,w.publicKey,"publicKey"),x!==void 0&&Ot(x,"zip215"),n&&(A=n(A));let m=p/2,v=L.subarray(0,m),_=Kt(L.subarray(m,p)),I,E,R;try{I=e.fromBytes(U,x),E=e.fromBytes(v,x),R=s.multiplyUnsafe(_)}catch{return!1}if(!x&&I.isSmallOrder())return!1;let C=d(T,E.toBytes(),I.toBytes(),A);return E.add(I.multiplyUnsafe(C)).subtract(R).clearCofactor().is0()}let B=o.BYTES,w={secretKey:B,publicKey:B,signature:2*B,seed:B};function K(L=a(w.seed)){return H(L,w.seed,"seed")}function P(L){return ne(L)&&L.length===i.BYTES}function M(L,A){try{return!!e.fromBytes(L,A)}catch{return!1}}let O={getExtendedPublicKey:b,randomSecretKey:K,isValidSecretKey:P,isValidPublicKey:M,toMontgomery(L){let{y:A}=e.fromBytes(L),U=w.publicKey,k=U===32;if(!k&&U!==57)throw new Error("only defined for 25519 and 448");let T=k?o.div(it+A,it-A):o.div(A-it,A+it);return o.toBytes(T)},toMontgomerySecret(L){let A=w.secretKey;H(L,A);let U=t(L.subarray(0,A));return c(U).subarray(0,A)}};return Object.freeze({keygen:Ne(K,y),getPublicKey:y,sign:S,verify:g,utils:O,Point:e,lengths:w})}var hr=BigInt(0),ke=BigInt(1),Fr=BigInt(2);function Zf(e){return Ct(e,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...e})}function Vi(e){let t=Zf(e),{P:r,type:n,adjustScalarBytes:s,powPminus2:o,randomBytes:i}=t,a=n==="x25519";if(!a&&n!=="x448")throw new Error("invalid type");let c=i||Zt,h=a?255:448,f=a?32:56,u=BigInt(a?9:5),b=BigInt(a?121665:39081),y=a?Fr**BigInt(254):Fr**BigInt(447),d=a?BigInt(8)*Fr**BigInt(251)-ke:BigInt(4)*Fr**BigInt(445)-ke,S=y+d+ke,l=p=>J(p,r),g=B(u);function B(p){return ar(l(p),f)}function w(p){let m=ae(H(p,f,"uCoordinate"));return a&&(m[31]&=127),l(Kt(m))}function K(p){return Kt(s(ae(H(p,f,"scalar"))))}function P(p,m){let v=U(w(m),K(p));if(v===hr)throw new Error("invalid private or public key received");return B(v)}function M(p){return P(p,g)}let O=M,L=P;function A(p,m,v){let _=l(p*(m-v));return m=l(m-_),v=l(v+_),{x_2:m,x_3:v}}function U(p,m){Xt("u",p,hr,r),Xt("scalar",m,y,S);let v=m,_=p,I=ke,E=hr,R=p,C=ke,D=hr;for(let V=BigInt(h-1);V>=hr;V--){let q=v>>V&ke;D^=q,{x_2:I,x_3:R}=A(D,I,R),{x_2:E,x_3:C}=A(D,E,C),D=q;let z=I+E,Y=l(z*z),et=I-E,G=l(et*et),nt=Y-G,be=R+C,Br=R-C,Ye=l(Br*z),Io=l(be*et),_o=Ye+Io,Ro=Ye-Io;R=l(_o*_o),C=l(_*l(Ro*Ro)),I=l(Y*G),E=l(nt*(Y+l(b*nt)))}({x_2:I,x_3:R}=A(D,I,R)),{x_2:E,x_3:C}=A(D,E,C);let F=o(E);return l(I*F)}let k={secretKey:f,publicKey:f,seed:f},T=(p=c(f))=>(H(p,k.seed,"seed"),p),x={randomSecretKey:T};return Object.freeze({keygen:Ne(T,O),getSharedSecret:L,getPublicKey:O,scalarMult:P,scalarMultBase:M,utils:x,GuBytes:g.slice(),lengths:k})}var jf=BigInt(1),Fi=BigInt(2),Yf=BigInt(3),Wf=BigInt(5),Xf=BigInt(8),zr=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Jf={p:zr,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Xf,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Gi(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),s=BigInt(80),o=zr,a=e*e%o*e%o,c=X(a,Fi,o)*a%o,h=X(c,jf,o)*e%o,f=X(h,Wf,o)*h%o,u=X(f,t,o)*f%o,b=X(u,r,o)*u%o,y=X(b,n,o)*b%o,d=X(y,s,o)*y%o,S=X(d,s,o)*y%o,l=X(S,t,o)*f%o;return{pow_p_5_8:X(l,Fi,o)*e%o,b2:a}}function $i(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var zi=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Qf(e,t){let r=zr,n=J(t*t*t,r),s=J(n*n*t,r),o=Gi(e*s).pow_p_5_8,i=J(e*n*o,r),a=J(t*i*i,r),c=i,h=J(i*zi,r),f=a===e,u=a===J(-e,r),b=a===J(-e*zi,r);return f&&(i=c),(u||b)&&(i=h),Ci(i,r)&&(i=J(-i,r)),{isValid:f||u,value:i}}var tu=Hi(Jf,{uvRatio:Qf});function eu(e){return qi(tu,xi,Object.assign({adjustScalarBytes:$i},e))}var Zi=eu({});var lr=(()=>{let e=zr;return Vi({P:e,type:"x25519",powPminus2:t=>{let{pow_p_5_8:r,b2:n}=Gi(t);return J(X(r,Yf,e)*n,e)},adjustScalarBytes:$i})})();var dr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Gr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var ji={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new Gr("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var St=ji;var $r=32;var ms,ru=(async()=>{try{return await St.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function nu(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await St.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await St.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function su(e,t,r){return Zi.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Yi(e,t,r){return ms==null&&(ms=await ru),ms?nu(e,t,r):su(e,t,r)}function Zr(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var jr=class{type="Ed25519";raw;constructor(t){this.raw=ys(t,$r)}toMultihash(){return _t.digest($t(this))}toCID(){return lt.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:mt(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let s=Yi(this.raw,r,t);return Zr(s)?s.then(o=>(n?.signal?.throwIfAborted(),o)):s}};function Xi(e){return e=ys(e,$r),new jr(e)}function ys(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new Q(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var iu=Math.pow(2,7),au=Math.pow(2,14),cu=Math.pow(2,21),gs=Math.pow(2,28),bs=Math.pow(2,35),xs=Math.pow(2,42),ws=Math.pow(2,49),j=128,dt=127;function Bt(e){if(e<iu)return 1;if(e<au)return 2;if(e<cu)return 3;if(e<gs)return 4;if(e<bs)return 5;if(e<xs)return 6;if(e<ws)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Es(e,t,r=0){switch(Bt(e)){case 8:t[r++]=e&255|j,e/=128;case 7:t[r++]=e&255|j,e/=128;case 6:t[r++]=e&255|j,e/=128;case 5:t[r++]=e&255|j,e/=128;case 4:t[r++]=e&255|j,e>>>=7;case 3:t[r++]=e&255|j,e>>>=7;case 2:t[r++]=e&255|j,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function fu(e,t,r=0){switch(Bt(e)){case 8:t.set(r++,e&255|j),e/=128;case 7:t.set(r++,e&255|j),e/=128;case 6:t.set(r++,e&255|j),e/=128;case 5:t.set(r++,e&255|j),e/=128;case 4:t.set(r++,e&255|j),e>>>=7;case 3:t.set(r++,e&255|j),e>>>=7;case 2:t.set(r++,e&255|j),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function Ss(e,t){let r=e[t],n=0;if(n+=r&dt,r<j||(r=e[t+1],n+=(r&dt)<<7,r<j)||(r=e[t+2],n+=(r&dt)<<14,r<j)||(r=e[t+3],n+=(r&dt)<<21,r<j)||(r=e[t+4],n+=(r&dt)*gs,r<j)||(r=e[t+5],n+=(r&dt)*bs,r<j)||(r=e[t+6],n+=(r&dt)*xs,r<j)||(r=e[t+7],n+=(r&dt)*ws,r<j))return n;throw new RangeError("Could not decode varint")}function uu(e,t){let r=e.get(t),n=0;if(n+=r&dt,r<j||(r=e.get(t+1),n+=(r&dt)<<7,r<j)||(r=e.get(t+2),n+=(r&dt)<<14,r<j)||(r=e.get(t+3),n+=(r&dt)<<21,r<j)||(r=e.get(t+4),n+=(r&dt)*gs,r<j)||(r=e.get(t+5),n+=(r&dt)*bs,r<j)||(r=e.get(t+6),n+=(r&dt)*xs,r<j)||(r=e.get(t+7),n+=(r&dt)*ws,r<j))return n;throw new RangeError("Could not decode varint")}function Ji(e,t,r=0){return t==null&&(t=ft(Bt(e))),t instanceof Uint8Array?Es(e,t,r):fu(e,t,r)}function Yr(e,t=0){return e instanceof Uint8Array?Ss(e,t):uu(e,t)}var As=new Float32Array([-0]),Qt=new Uint8Array(As.buffer);function ta(e,t,r){As[0]=e,t[r]=Qt[0],t[r+1]=Qt[1],t[r+2]=Qt[2],t[r+3]=Qt[3]}function ea(e,t){return Qt[0]=e[t],Qt[1]=e[t+1],Qt[2]=e[t+2],Qt[3]=e[t+3],As[0]}var vs=new Float64Array([-0]),pt=new Uint8Array(vs.buffer);function ra(e,t,r){vs[0]=e,t[r]=pt[0],t[r+1]=pt[1],t[r+2]=pt[2],t[r+3]=pt[3],t[r+4]=pt[4],t[r+5]=pt[5],t[r+6]=pt[6],t[r+7]=pt[7]}function na(e,t){return pt[0]=e[t],pt[1]=e[t+1],pt[2]=e[t+2],pt[3]=e[t+3],pt[4]=e[t+4],pt[5]=e[t+5],pt[6]=e[t+6],pt[7]=e[t+7],vs[0]}var hu=BigInt(Number.MAX_SAFE_INTEGER),lu=BigInt(Number.MIN_SAFE_INTEGER),wt=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&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(t=!1){if(t)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(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return he;if(t<hu&&t>lu)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,s=t-(n<<32n);return r&&(n=~n|0n,s=~s|0n,++s>sa&&(s=0n,++n>sa&&(n=0n))),new e(Number(s),Number(n))}static fromNumber(t){if(t===0)return he;let r=t<0;r&&(t=-t);let n=t>>>0,s=(t-n)/4294967296>>>0;return r&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new e(n,s)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):he}},he=new wt(0,0);he.toBigInt=function(){return 0n};he.zzEncode=he.zzDecode=function(){return this};he.length=function(){return 1};var sa=4294967296n;function oa(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function ia(e,t,r){if(r-t<1)return"";let s,o=[],i=0,a;for(;t<r;)a=e[t++],a<128?o[i++]=a:a>191&&a<224?o[i++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,o[i++]=55296+(a>>10),o[i++]=56320+(a&1023)):o[i++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&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 Bs(e,t,r){let n=r,s,o;for(let i=0;i<e.length;++i)s=e.charCodeAt(i),s<128?t[r++]=s:s<2048?(t[r++]=s>>6|192,t[r++]=s&63|128):(s&64512)===55296&&((o=e.charCodeAt(i+1))&64512)===56320?(s=65536+((s&1023)<<10)+(o&1023),++i,t[r++]=s>>18|240,t[r++]=s>>12&63|128,t[r++]=s>>6&63|128,t[r++]=s&63|128):(t[r++]=s>>12|224,t[r++]=s>>6&63|128,t[r++]=s&63|128);return r-n}function Lt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Wr(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Ls=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Lt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Lt(this,4);return Wr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Lt(this,4);return Wr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Lt(this,4);let t=ea(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Lt(this,4);let t=na(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Lt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return ia(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Lt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Lt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new wt(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Lt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Lt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Lt(this,8);let t=Wr(this.buf,this.pos+=4),r=Wr(this.buf,this.pos+=4);return new wt(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Ss(this.buf,this.pos);return this.pos+=Bt(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Is(e){return new Ls(e instanceof Uint8Array?e:e.subarray())}function le(e,t,r){let n=Is(e);return t.decode(n,void 0,r)}function _s(e){let t=e??8192,r=t>>>1,n,s=t;return function(i){if(i<1||i>r)return ft(i);s+i>t&&(n=ft(t),s=0);let a=n.subarray(s,s+=i);return(s&7)!==0&&(s=(s|7)+1),a}}var de=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Rs(){}var Ks=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},du=_s();function pu(e){return globalThis.Buffer!=null?ft(e):du(e)}var mr=class{len;head;tail;states;constructor(){this.len=0,this.head=new de(Rs,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new de(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Cs((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Xr,10,wt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=wt.fromBigInt(t);return this._push(Xr,r.length(),r)}uint64Number(t){return this._push(Es,Bt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=wt.fromBigInt(t).zzEncode();return this._push(Xr,r.length(),r)}sint64Number(t){let r=wt.fromNumber(t).zzEncode();return this._push(Xr,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Ts,1,t?1:0)}fixed32(t){return this._push(pr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=wt.fromBigInt(t);return this._push(pr,4,r.lo)._push(pr,4,r.hi)}fixed64Number(t){let r=wt.fromNumber(t);return this._push(pr,4,r.lo)._push(pr,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(ta,4,t)}double(t){return this._push(ra,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Ts,1,0):this.uint32(r)._push(yu,r,t)}string(t){let r=oa(t);return r!==0?this.uint32(r)._push(Bs,r,t):this._push(Ts,1,0)}fork(){return this.states=new Ks(this),this.head=this.tail=new de(Rs,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 de(Rs,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=pu(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Ts(e,t,r){t[r]=e&255}function mu(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Cs=class extends de{next;constructor(t,r){super(mu,t,r),this.next=void 0}};function Xr(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function pr(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function yu(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(mr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(gu,t,e),this},mr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(bu,t,e),this});function gu(e,t,r){t.set(e,r)}function bu(e,t,r){e.length<40?Bs(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(W(e),r)}function Ds(){return new mr}function pe(e,t){let r=Ds();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var Pe;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(Pe||(Pe={}));function Jr(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function Us(e){function t(s){if(e[s.toString()]==null)throw new Error("Invalid enum value");return e[s]}let r=function(o,i){let a=t(o);i.int32(a)},n=function(o){let i=o.int32();return t(i)};return Jr("enum",Pe.VARINT,r,n)}function me(e,t){return Jr("message",Pe.LENGTH_DELIMITED,e,t)}var yr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var at;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(at||(at={}));var Ns;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Ns||(Ns={}));(function(e){e.codec=()=>Us(Ns)})(at||(at={}));var Ht;(function(e){let t;e.codec=()=>(t==null&&(t=me((r,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),at.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),s.lengthDelimited!==!1&&n.ldelim()},(r,n,s={})=>{let o={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{o.Type=at.codec().decode(r);break}case 2:{o.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return o})),t),e.encode=r=>pe(r,e.codec()),e.decode=(r,n)=>le(r,e.codec(),n)})(Ht||(Ht={}));var ks;(function(e){let t;e.codec=()=>(t==null&&(t=me((r,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),at.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),s.lengthDelimited!==!1&&n.ldelim()},(r,n,s={})=>{let o={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{o.Type=at.codec().decode(r);break}case 2:{o.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return o})),t),e.encode=r=>pe(r,e.codec()),e.decode=(r,n)=>le(r,e.codec(),n)})(ks||(ks={}));var br={};gt(br,{MAX_RSA_KEY_SIZE:()=>Ps,generateRSAKeyPair:()=>la,jwkToJWKKeyPair:()=>da,jwkToPkcs1:()=>Su,jwkToPkix:()=>qs,jwkToRSAPrivateKey:()=>Gs,pkcs1MessageToJwk:()=>Os,pkcs1MessageToRSAPrivateKey:()=>Vs,pkcs1ToJwk:()=>Eu,pkcs1ToRSAPrivateKey:()=>ha,pkixMessageToJwk:()=>Hs,pkixMessageToRSAPublicKey:()=>zs,pkixToJwk:()=>Au,pkixToRSAPublicKey:()=>Fs});var Me=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=br.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return lt.createV1(114,this._multihash)}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:mt(this.raw,t.raw)}verify(t,r,n){return ua(this.jwk,r,t,n)}},gr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=br.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:mt(this.raw,t.raw)}sign(t,r){return fa(this.jwk,t,r)}};var Ps=8192,Ms=18,xu=1062,wu=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Eu(e){let t=Ut(e);return Os(t)}function Os(e){return{n:Z(e[1],"base64url"),e:Z(e[2],"base64url"),d:Z(e[3],"base64url"),p:Z(e[4],"base64url"),q:Z(e[5],"base64url"),dp:Z(e[6],"base64url"),dq:Z(e[7],"base64url"),qi:Z(e[8],"base64url"),kty:"RSA"}}function Su(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new Q("JWK was missing components");return Gt([bt(Uint8Array.from([0])),bt(W(e.n,"base64url")),bt(W(e.e,"base64url")),bt(W(e.d,"base64url")),bt(W(e.p,"base64url")),bt(W(e.q,"base64url")),bt(W(e.dp,"base64url")),bt(W(e.dq,"base64url")),bt(W(e.qi,"base64url"))]).subarray()}function Au(e){let t=Ut(e,{offset:0});return Hs(t)}function Hs(e){let t=Ut(e[1],{offset:0});return{kty:"RSA",n:Z(t[0],"base64url"),e:Z(t[1],"base64url")}}function qs(e){if(e.n==null||e.e==null)throw new Q("JWK was missing components");return Gt([wu,Pr(Gt([bt(W(e.n,"base64url")),bt(W(e.e,"base64url"))]))]).subarray()}function ha(e){let t=Ut(e);return Vs(t)}function Vs(e){let t=Os(e);return Gs(t)}function Fs(e,t){if(e.byteLength>=xu)throw new xe("Key size is too large");let r=Ut(e,{offset:0});return zs(r,e,t)}function zs(e,t,r){let n=Hs(e);if(r==null){let s=Tt(Ht.encode({Type:at.RSA,Data:t}));r=It(Ms,s)}return new Me(n,r)}function Gs(e){if(ma(e)>Ps)throw new Q("Key size is too large");let t=da(e),r=Tt(Ht.encode({Type:at.RSA,Data:qs(t.publicKey)})),n=It(Ms,r);return new gr(t.privateKey,new Me(t.publicKey,n))}async function la(e){if(e>Ps)throw new Q("Key size is too large");let t=await pa(e),r=Tt(Ht.encode({Type:at.RSA,Data:qs(t.publicKey)})),n=It(Ms,r);return new gr(t.privateKey,new Me(t.publicKey,n))}function da(e){if(e==null)throw new Q("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function pa(e,t){let r=await St.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await vu(r,t);return{privateKey:n[0],publicKey:n[1]}}async function fa(e,t,r){let n=await St.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let s=await St.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(s,0,s.byteLength)}async function ua(e,t,r,n){let s=await St.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let o=await St.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},s,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),o}async function vu(e,t){if(e.privateKey==null||e.publicKey==null)throw new Q("Private and public key are required");let r=await Promise.all([St.get().subtle.exportKey("jwk",e.privateKey),St.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function ma(e){if(e.kty!=="RSA")throw new Q("invalid key type");if(e.n==null)throw new Q("invalid key modulus");return W(e.n,"base64url").length*8}var Qr=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,r){if(se(t),H(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,s=new Uint8Array(n);s.set(r.length>n?t.create().update(r).digest():r);for(let o=0;o<s.length;o++)s[o]^=54;this.iHash.update(s),this.oHash=t.create();for(let o=0;o<s.length;o++)s[o]^=106;this.oHash.update(s),At(s)}update(t){return Re(this),this.iHash.update(t),this}digestInto(t){Re(this),H(t,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:s,destroyed:o,blockLen:i,outputLen:a}=this;return t=t,t.finished=s,t.destroyed=o,t.blockLen=i,t.outputLen=a,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Oe=(e,t,r)=>new Qr(e,t).update(r).digest();Oe.create=(e,t)=>new Qr(e,t);var ya=(e,t)=>(e+(e>=0?t:-t)/ga)/t;function Bu(e,t,r){let[[n,s],[o,i]]=t,a=ya(i*e,r),c=ya(-s*e,r),h=e-a*n-c*o,f=-a*s-c*i,u=h<qt,b=f<qt;u&&(h=-h),b&&(f=-f);let y=cr(Math.ceil(os(r)/2))+He;if(h<qt||h>=y||f<qt||f>=y)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:u,k1:h,k2neg:b,k2:f}}function Zs(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function $s(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return Ot(r.lowS,"lowS"),Ot(r.prehash,"prehash"),r.format!==void 0&&Zs(r.format),r}var js=class extends Error{constructor(t=""){super(t)}},te={Err:js,_tlv:{encode:(e,t)=>{let{Err:r}=te;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,s=ir(n);if(s.length/2&128)throw new r("tlv.encode: long form length too big");let o=n>127?ir(s.length/2|128):"";return ir(e)+o+s+t},decode(e,t){let{Err:r}=te,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let s=t[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 h=t.subarray(n,n+c);if(h.length!==c)throw new r("tlv.decode: length bytes not complete");if(h[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of h)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=te;if(e<qt)throw new t("integer: negative integers are not allowed");let r=ir(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=te;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Te(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=te,s=H(e,void 0,"signature"),{v:o,l:i}=n.decode(48,s);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,o),{v:h,l:f}=n.decode(2,c);if(f.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(h)}},hexFromSig(e){let{_tlv:t,_int:r}=te,n=t.encode(2,r.encode(e.r)),s=t.encode(2,r.encode(e.s)),o=n+s;return t.encode(48,o)}},qt=BigInt(0),He=BigInt(1),ga=BigInt(2),tn=BigInt(3),Lu=BigInt(4);function ba(e,t={}){let r=Vr("weierstrass",e,t),{Fp:n,Fn:s}=r,o=r.CURVE,{h:i,n:a}=o;Ct(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c}=t;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 h=wa(n,s);function f(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function u(T,x,p){let{x:m,y:v}=x.toAffine(),_=n.toBytes(m);if(Ot(p,"isCompressed"),p){f();let I=!n.isOdd(v);return xt(xa(I),_)}else return xt(Uint8Array.of(4),_,n.toBytes(v))}function b(T){H(T,void 0,"Point");let{publicKey:x,publicKeyUncompressed:p}=h,m=T.length,v=T[0],_=T.subarray(1);if(m===x&&(v===2||v===3)){let I=n.fromBytes(_);if(!n.isValid(I))throw new Error("bad point: is not on curve, wrong x");let E=S(I),R;try{R=n.sqrt(E)}catch(F){let V=F instanceof Error?": "+F.message:"";throw new Error("bad point: is not on curve, sqrt error"+V)}f();let C=n.isOdd(R);return(v&1)===1!==C&&(R=n.neg(R)),{x:I,y:R}}else if(m===p&&v===4){let I=n.BYTES,E=n.fromBytes(_.subarray(0,I)),R=n.fromBytes(_.subarray(I,I*2));if(!l(E,R))throw new Error("bad point: is not on curve");return{x:E,y:R}}else throw new Error(`bad point: got length ${m}, expected compressed=${x} or uncompressed=${p}`)}let y=t.toBytes||u,d=t.fromBytes||b;function S(T){let x=n.sqr(T),p=n.mul(x,T);return n.add(n.add(p,n.mul(T,o.a)),o.b)}function l(T,x){let p=n.sqr(x),m=S(T);return n.eql(p,m)}if(!l(o.Gx,o.Gy))throw new Error("bad curve params: generator point");let g=n.mul(n.pow(o.a,tn),Lu),B=n.mul(n.sqr(o.b),BigInt(27));if(n.is0(n.add(g,B)))throw new Error("bad curve params: a or b");function w(T,x,p=!1){if(!n.isValid(x)||p&&n.is0(x))throw new Error(`bad point coordinate ${T}`);return x}function K(T){if(!(T instanceof A))throw new Error("Weierstrass Point expected")}function P(T){if(!c||!c.basises)throw new Error("no endo");return Bu(T,c.basises,s.ORDER)}let M=Ke((T,x)=>{let{X:p,Y:m,Z:v}=T;if(n.eql(v,n.ONE))return{x:p,y:m};let _=T.is0();x==null&&(x=_?n.ONE:n.inv(v));let I=n.mul(p,x),E=n.mul(m,x),R=n.mul(v,x);if(_)return{x:n.ZERO,y:n.ZERO};if(!n.eql(R,n.ONE))throw new Error("invZ was invalid");return{x:I,y:E}}),O=Ke(T=>{if(T.is0()){if(t.allowInfinityPoint&&!n.is0(T.Y))return;throw new Error("bad point: ZERO")}let{x,y:p}=T.toAffine();if(!n.isValid(x)||!n.isValid(p))throw new Error("bad point: x or y not field elements");if(!l(x,p))throw new Error("bad point: equation left != right");if(!T.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function L(T,x,p,m,v){return p=new A(n.mul(p.X,T),p.Y,p.Z),x=ur(m,x),p=ur(v,p),x.add(p)}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(x,p,m){this.X=w("x",x),this.Y=w("y",p,!0),this.Z=w("z",m),Object.freeze(this)}static CURVE(){return o}static fromAffine(x){let{x:p,y:m}=x||{};if(!x||!n.isValid(p)||!n.isValid(m))throw new Error("invalid affine point");if(x instanceof A)throw new Error("projective point not allowed");return n.is0(p)&&n.is0(m)?A.ZERO:new A(p,m,n.ONE)}static fromBytes(x){let p=A.fromAffine(d(H(x,void 0,"point")));return p.assertValidity(),p}static fromHex(x){return A.fromBytes(Pt(x))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(x=8,p=!0){return k.createCache(this,x),p||this.multiply(tn),this}assertValidity(){O(this)}hasEvenY(){let{y:x}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(x)}equals(x){K(x);let{X:p,Y:m,Z:v}=this,{X:_,Y:I,Z:E}=x,R=n.eql(n.mul(p,E),n.mul(_,v)),C=n.eql(n.mul(m,E),n.mul(I,v));return R&&C}negate(){return new A(this.X,n.neg(this.Y),this.Z)}double(){let{a:x,b:p}=o,m=n.mul(p,tn),{X:v,Y:_,Z:I}=this,E=n.ZERO,R=n.ZERO,C=n.ZERO,D=n.mul(v,v),F=n.mul(_,_),V=n.mul(I,I),q=n.mul(v,_);return q=n.add(q,q),C=n.mul(v,I),C=n.add(C,C),E=n.mul(x,C),R=n.mul(m,V),R=n.add(E,R),E=n.sub(F,R),R=n.add(F,R),R=n.mul(E,R),E=n.mul(q,E),C=n.mul(m,C),V=n.mul(x,V),q=n.sub(D,V),q=n.mul(x,q),q=n.add(q,C),C=n.add(D,D),D=n.add(C,D),D=n.add(D,V),D=n.mul(D,q),R=n.add(R,D),V=n.mul(_,I),V=n.add(V,V),D=n.mul(V,q),E=n.sub(E,D),C=n.mul(V,F),C=n.add(C,C),C=n.add(C,C),new A(E,R,C)}add(x){K(x);let{X:p,Y:m,Z:v}=this,{X:_,Y:I,Z:E}=x,R=n.ZERO,C=n.ZERO,D=n.ZERO,F=o.a,V=n.mul(o.b,tn),q=n.mul(p,_),z=n.mul(m,I),Y=n.mul(v,E),et=n.add(p,m),G=n.add(_,I);et=n.mul(et,G),G=n.add(q,z),et=n.sub(et,G),G=n.add(p,v);let nt=n.add(_,E);return G=n.mul(G,nt),nt=n.add(q,Y),G=n.sub(G,nt),nt=n.add(m,v),R=n.add(I,E),nt=n.mul(nt,R),R=n.add(z,Y),nt=n.sub(nt,R),D=n.mul(F,G),R=n.mul(V,Y),D=n.add(R,D),R=n.sub(z,D),D=n.add(z,D),C=n.mul(R,D),z=n.add(q,q),z=n.add(z,q),Y=n.mul(F,Y),G=n.mul(V,G),z=n.add(z,Y),Y=n.sub(q,Y),Y=n.mul(F,Y),G=n.add(G,Y),q=n.mul(z,G),C=n.add(C,q),q=n.mul(nt,G),R=n.mul(et,R),R=n.sub(R,q),q=n.mul(et,z),D=n.mul(nt,D),D=n.add(D,q),new A(R,C,D)}subtract(x){return this.add(x.negate())}is0(){return this.equals(A.ZERO)}multiply(x){let{endo:p}=t;if(!s.isValidNot0(x))throw new Error("invalid scalar: out of range");let m,v,_=I=>k.cached(this,I,E=>ue(A,E));if(p){let{k1neg:I,k1:E,k2neg:R,k2:C}=P(x),{p:D,f:F}=_(E),{p:V,f:q}=_(C);v=F.add(q),m=L(p.beta,D,V,I,R)}else{let{p:I,f:E}=_(x);m=I,v=E}return ue(A,[m,v])[0]}multiplyUnsafe(x){let{endo:p}=t,m=this;if(!s.isValid(x))throw new Error("invalid scalar: out of range");if(x===qt||m.is0())return A.ZERO;if(x===He)return m;if(k.hasCache(this))return this.multiply(x);if(p){let{k1neg:v,k1:_,k2neg:I,k2:E}=P(x),{p1:R,p2:C}=Oi(A,m,_,E);return L(p.beta,R,C,v,I)}else return k.unsafe(m,x)}toAffine(x){return M(this,x)}isTorsionFree(){let{isTorsionFree:x}=t;return i===He?!0:x?x(A,this):k.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:x}=t;return i===He?this:x?x(A,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(x=!0){return Ot(x,"isCompressed"),this.assertValidity(),y(A,this,x)}toHex(x=!0){return kt(this.toBytes(x))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let U=s.BITS,k=new Ue(A,t.endo?Math.ceil(U/2):U);return A.BASE.precompute(8),A}function xa(e){return Uint8Array.of(e?2:3)}function wa(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Iu(e,t={}){let{Fn:r}=e,n=t.randomBytes||Zt,s=Object.assign(wa(e.Fp,r),{seed:fs(r.ORDER)});function o(y){try{let d=r.fromBytes(y);return r.isValidNot0(d)}catch{return!1}}function i(y,d){let{publicKey:S,publicKeyUncompressed:l}=s;try{let g=y.length;return d===!0&&g!==S||d===!1&&g!==l?!1:!!e.fromBytes(y)}catch{return!1}}function a(y=n(s.seed)){return us(H(y,s.seed,"seed"),r.ORDER)}function c(y,d=!0){return e.BASE.multiply(r.fromBytes(y)).toBytes(d)}function h(y){let{secretKey:d,publicKey:S,publicKeyUncompressed:l}=s;if(!ne(y)||"_lengths"in r&&r._lengths||d===S)return;let g=H(y,void 0,"key").length;return g===S||g===l}function f(y,d,S=!0){if(h(y)===!0)throw new Error("first arg must be private key");if(h(d)===!1)throw new Error("second arg must be public key");let l=r.fromBytes(y);return e.fromBytes(d).multiply(l).toBytes(S)}let u={isValidSecretKey:o,isValidPublicKey:i,randomSecretKey:a},b=Ne(a,c);return Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:b,Point:e,utils:u,lengths:s})}function Ea(e,t,r={}){se(t),Ct(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let n=r.randomBytes||Zt,s=r.hmac||((p,m)=>Oe(t,p,m)),{Fp:o,Fn:i}=e,{ORDER:a,BITS:c}=i,{keygen:h,getPublicKey:f,getSharedSecret:u,utils:b,lengths:y}=Iu(e,r),d={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},S=a*ga<o.ORDER;function l(p){let m=a>>He;return p>m}function g(p,m){if(!i.isValidNot0(m))throw new Error(`invalid signature ${p}: out of range 1..Point.Fn.ORDER`);return m}function B(){if(S)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function w(p,m){Zs(m);let v=y.signature,_=m==="compact"?v:m==="recovered"?v+1:void 0;return H(p,_)}class K{r;s;recovery;constructor(m,v,_){if(this.r=g("r",m),this.s=g("s",v),_!=null){if(B(),![0,1,2,3].includes(_))throw new Error("invalid recovery id");this.recovery=_}Object.freeze(this)}static fromBytes(m,v=d.format){w(m,v);let _;if(v==="der"){let{r:C,s:D}=te.toSig(H(m));return new K(C,D)}v==="recovered"&&(_=m[0],v="compact",m=m.subarray(1));let I=y.signature/2,E=m.subarray(0,I),R=m.subarray(I,I*2);return new K(i.fromBytes(E),i.fromBytes(R),_)}static fromHex(m,v){return this.fromBytes(Pt(m),v)}assertRecovery(){let{recovery:m}=this;if(m==null)throw new Error("invalid recovery id: must be present");return m}addRecoveryBit(m){return new K(this.r,this.s,m)}recoverPublicKey(m){let{r:v,s:_}=this,I=this.assertRecovery(),E=I===2||I===3?v+a:v;if(!o.isValid(E))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let R=o.toBytes(E),C=e.fromBytes(xt(xa((I&1)===0),R)),D=i.inv(E),F=M(H(m,void 0,"msgHash")),V=i.create(-F*D),q=i.create(_*D),z=e.BASE.multiplyUnsafe(V).add(C.multiplyUnsafe(q));if(z.is0())throw new Error("invalid recovery: point at infinify");return z.assertValidity(),z}hasHighS(){return l(this.s)}toBytes(m=d.format){if(Zs(m),m==="der")return Pt(te.hexFromSig(this));let{r:v,s:_}=this,I=i.toBytes(v),E=i.toBytes(_);return m==="recovered"?(B(),xt(Uint8Array.of(this.assertRecovery()),I,E)):xt(I,E)}toHex(m){return kt(this.toBytes(m))}}let P=r.bits2int||function(m){if(m.length>8192)throw new Error("input is too large");let v=Te(m),_=m.length*8-c;return _>0?v>>BigInt(_):v},M=r.bits2int_modN||function(m){return i.create(P(m))},O=cr(c);function L(p){return Xt("num < 2^"+c,p,qt,O),i.toBytes(p)}function A(p,m){return H(p,void 0,"message"),m?H(t(p),void 0,"prehashed message"):p}function U(p,m,v){let{lowS:_,prehash:I,extraEntropy:E}=$s(v,d);p=A(p,I);let R=M(p),C=i.fromBytes(m);if(!i.isValidNot0(C))throw new Error("invalid private key");let D=[L(C),L(R)];if(E!=null&&E!==!1){let z=E===!0?n(y.secretKey):E;D.push(H(z,void 0,"extraEntropy"))}let F=xt(...D),V=R;function q(z){let Y=P(z);if(!i.isValidNot0(Y))return;let et=i.inv(Y),G=e.BASE.multiply(Y).toAffine(),nt=i.create(G.x);if(nt===qt)return;let be=i.create(et*i.create(V+nt*C));if(be===qt)return;let Br=(G.x===nt?0:2)|Number(G.y&He),Ye=be;return _&&l(be)&&(Ye=i.neg(be),Br^=1),new K(nt,Ye,S?void 0:Br)}return{seed:F,k2sig:q}}function k(p,m,v={}){let{seed:_,k2sig:I}=U(p,m,v);return Si(t.outputLen,i.BYTES,s)(_,I).toBytes(v.format)}function T(p,m,v,_={}){let{lowS:I,prehash:E,format:R}=$s(_,d);if(v=H(v,void 0,"publicKey"),m=A(m,E),!ne(p)){let C=p instanceof K?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+C)}w(p,R);try{let C=K.fromBytes(p,R),D=e.fromBytes(v);if(I&&C.hasHighS())return!1;let{r:F,s:V}=C,q=M(m),z=i.inv(V),Y=i.create(q*z),et=i.create(F*z),G=e.BASE.multiplyUnsafe(Y).add(D.multiplyUnsafe(et));return G.is0()?!1:i.create(G.x)===F}catch{return!1}}function x(p,m,v={}){let{prehash:_}=$s(v,d);return m=A(m,_),K.fromBytes(p,"recovered").recoverPublicKey(m).toBytes()}return Object.freeze({keygen:h,getPublicKey:f,getSharedSecret:u,utils:b,lengths:y,Point:e,sign:k,verify:T,recoverPublicKey:x,Signature:K,hash:t})}var Ws={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},_u={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Sa=BigInt(2);function Ru(e){let t=Ws.p,r=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),h=e*e*e%t,f=h*h*e%t,u=X(f,r,t)*f%t,b=X(u,r,t)*f%t,y=X(b,Sa,t)*h%t,d=X(y,s,t)*y%t,S=X(d,o,t)*d%t,l=X(S,a,t)*S%t,g=X(l,c,t)*l%t,B=X(g,a,t)*S%t,w=X(B,r,t)*f%t,K=X(w,i,t)*d%t,P=X(K,n,t)*h%t,M=X(P,Sa,t);if(!Ys.eql(Ys.sqr(M),e))throw new Error("Cannot find square root");return M}var Ys=Ce(Ws.p,{sqrt:Ru}),Tu=ba(Ws,{Fp:Ys,endo:_u}),qe=Ea(Tu,Tt);function Aa(e,t,r,n){let s=Nr.digest(r instanceof Uint8Array?r:r.subarray());if(Zr(s))return s.then(({digest:o})=>(n?.signal?.throwIfAborted(),qe.verify(t,o,e,{prehash:!1,format:"der"}))).catch(o=>{throw o.name==="AbortError"?o:new dr(String(o))});try{return n?.signal?.throwIfAborted(),qe.verify(t,s.digest,e,{prehash:!1,format:"der"})}catch(o){throw new dr(String(o))}}var en=class{type="secp256k1";raw;_key;constructor(t){this._key=Ba(t),this.raw=va(this._key)}toMultihash(){return _t.digest($t(this))}toCID(){return lt.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:mt(this.raw,t.raw)}verify(t,r,n){return Aa(this._key,r,t,n)}};function La(e){return new en(e)}function va(e){return qe.Point.fromBytes(e).toBytes()}function Ba(e){try{return qe.Point.fromBytes(e),e}catch(t){throw new xe(String(t))}}function xr(e,t){let{Type:r,Data:n}=Ht.decode(e),s=n??new Uint8Array;switch(r){case at.RSA:return Fs(s,t);case at.Ed25519:return Xi(s);case at.secp256k1:return La(s);case at.ECDSA:return ri(s);default:throw new we}}function $t(e){return Ht.encode({Type:at[e.type],Data:e.raw})}var Ia=Symbol.for("nodejs.util.inspect.custom"),Ku=114,wr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[wn]=!0;toString(){return this.string==null&&(this.string=rt.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return lt.createV1(Ku,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return mt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return mt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Ia](){return`PeerId(${this.toString()})`}},rn=class extends wr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},nn=class extends wr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},sn=class extends wr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Cu=2336,Xs=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=_t.digest(W(this.url))}[Ia](){return`PeerId(${this.url})`}[wn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return lt.createV1(Cu,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=Z(t)),t.toString()===this.toString())}};function Js(e){if(e.type==="Ed25519")return new nn({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new sn({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new rn({multihash:e.toCID().multihash,publicKey:e});throw new we}function on(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var an=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},Ve=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new an(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let r=this.head;this.head=r.next=new an(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var Qs=class extends Error{type;code;constructor(t,r){super(t??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function cn(e={}){return Du(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}},e)}function Du(e,t){t=t??{};let r=t.onEnd,n=new Ve,s,o,i,a=on(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((l,g)=>{o=B=>{o=null,n.push(B);try{l(e(n))}catch(w){g(w)}return s}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=on()})}},h=l=>o!=null?o(l):(n.push(l),s),f=l=>(n=new Ve,o!=null?o({error:l}):(n.push({error:l}),s)),u=l=>{if(i)return s;if(t?.objectMode!==!0&&l?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return h({done:!1,value:l})},b=l=>i?s:(i=!0,l!=null?f(l):h({done:!0})),y=()=>(n=new Ve,b(),{done:!0}),d=l=>(b(l),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:y,throw:d,push:u,end:b,get readableLength(){return n.size},onEmpty:async l=>{let g=l?.signal;if(g?.throwIfAborted(),n.isEmpty())return;let B,w;g!=null&&(B=new Promise((K,P)=>{w=()=>{P(new Qs)},g.addEventListener("abort",w)}));try{await Promise.race([a.promise,B])}finally{w!=null&&g!=null&&g?.removeEventListener("abort",w)}}},r==null)return s;let S=s;return s={[Symbol.asyncIterator](){return this},next(){return S.next()},throw(l){return S.throw(l),r!=null&&(r(l),r=void 0),{done:!0}},return(){return S.return(),r!=null&&(r(),r=void 0),{done:!0}},push:u,end(l){return S.end(l),r!=null&&(r(l),r=void 0),s},get readableLength(){return S.readableLength},onEmpty:l=>S.onEmpty(l)},s}var to=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},eo=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},_a=e=>globalThis.DOMException===void 0?new eo(e):new DOMException(e),Ra=e=>{let t=e.reason===void 0?_a("This operation was aborted."):e.reason;return t instanceof Error?t:_a(t)};function ro(e,t){let{milliseconds:r,fallback:n,message:s,customTimers:o={setTimeout,clearTimeout}}=t,i,a,h=new Promise((f,u)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(t.signal){let{signal:y}=t;y.aborted&&u(Ra(y)),a=()=>{u(Ra(y))},y.addEventListener("abort",a,{once:!0})}if(r===Number.POSITIVE_INFINITY){e.then(f,u);return}let b=new to;i=o.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(y){u(y)}return}typeof e.cancel=="function"&&e.cancel(),s===!1?f():s instanceof Error?u(s):(b.message=s??`Promise timed out after ${r} milliseconds`,u(b))},r),(async()=>{try{f(await e)}catch(y){u(y)}})()}).finally(()=>{h.clear(),a&&t.signal&&t.signal.removeEventListener("abort",a)});return h.clear=()=>{o.clearTimeout.call(void 0,i),i=void 0},h}var Uu=e=>{let t=e.addEventListener||e.on||e.addListener,r=e.removeEventListener||e.off||e.removeListener;if(!t||!r)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(e),removeListener:r.bind(e)}};function Nu(e,t,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=[t].flat(),c=[],{addListener:h,removeListener:f}=Uu(e),u=async(...y)=>{let d=r.multiArgs?y:y[0];if(r.filter)try{if(!await r.filter(d))return}catch(S){n(),i(S);return}c.push(d),r.count===c.length&&(n(),o(c))},b=(...y)=>{n(),i(r.rejectionMultiArgs?y:y[0])};n=()=>{for(let y of a)f(y,u);for(let y of r.rejectionEvents)a.includes(y)||f(y,b)};for(let y of a)h(y,u);for(let y of r.rejectionEvents)a.includes(y)||h(y,b);r.signal&&r.signal.addEventListener("abort",()=>{b(r.signal.reason)},{once:!0}),r.resolveImmediately&&o(c)});if(s.cancel=n,typeof r.timeout=="number"){let o=ro(s,{milliseconds:r.timeout});return o.cancel=()=>{n(),o.clear()},o}return s}function Ta(e,t,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Nu(e,t,r),s=n.then(o=>o[0]);return s.cancel=n.cancel,s}var ye=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function ku(e){return e.reason}async function Ka(e,t,r){if(t==null)return e;let n=r?.translateError??ku;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let s;try{return await Promise.race([e,new Promise((o,i)=>{s=()=>{i(n(t))},t.addEventListener("abort",s)})])}finally{s!=null&&t.removeEventListener("abort",s)}}var Pu=Math.pow(2,20)*4,fn=class extends Cr{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;constructor(t){super(),this.status="open",this.log=t.log,this.direction=t.direction??"outbound",this.inactivityTimeout=t.inactivityTimeout??12e4,this.maxReadBufferLength=t.maxReadBufferLength??Pu,this.maxWriteBufferLength=t.maxWriteBufferLength,this.maxMessageSize=t.maxMessageSize,this.readBuffer=new $,this.writeBuffer=new $,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,this.processSendQueue())};this.addEventListener("drain",r)}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let t=cn(),r=o=>{t.push(o.data)};this.addEventListener("message",r);let n=o=>{t.end(o.error)};this.addEventListener("close",n);let s=()=>{t.end()};this.addEventListener("remoteCloseWrite",s);try{yield*t}finally{this.removeEventListener("message",r),this.removeEventListener("close",n),this.removeEventListener("remoteCloseWrite",s)}}isReadable(){return this.status==="open"}send(t){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new ee(`Cannot write to a stream that is ${this.writeStatus}`);return this.log.trace("append %d bytes to write buffer",t.byteLength),this.writeBuffer.append(t),this.processSendQueue()}abort(t){if(!(this.status==="aborted"||this.status==="reset"||this.status==="closed")){this.log.error("abort with error - %e",t),this.status="aborted",this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle")),this.writeStatus="closed",this.remoteWriteStatus="closed",this.readStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now();try{this.sendReset(t)}catch(r){this.log("failed to send reset to remote - %e",r)}this.dispatchEvent(new Tr(t))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new ee("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 ee("Cannot resume a stream that is closing/closed");this.readStatus!=="readable"&&(this.readStatus="readable",this.dispatchReadBuffer(),this.sendResume())}push(t){if(this.readStatus==="closed"||this.readStatus==="closing")throw new ee(`Cannot push data onto a stream that is ${this.readStatus}`);if(t.byteLength!==0){if(this.readBuffer.append(t),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}onData(t){if(t.byteLength!==0){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("ignoring data - read status %s",this.readStatus);return}this.readBuffer.append(t),this.dispatchReadBuffer()}}addEventListener(...t){super.addEventListener.apply(this,t),t[0]==="message"&&this.readBuffer.byteLength>0&&queueMicrotask(()=>{this.dispatchReadBuffer()})}onRemoteReset(){this.log("remote reset"),this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed");let t=new _r;this.dispatchEvent(new Kr(t))}onTransportClosed(t){this.log("transport closed"),this.readStatus==="readable"&&this.readBuffer.byteLength===0&&(this.log("close readable end after transport closed and read buffer is empty"),this.readStatus="closed"),this.remoteReadStatus!=="closed"&&(this.remoteReadStatus="closed"),this.remoteWriteStatus!=="closed"&&(this.remoteWriteStatus="closed"),this.writeStatus!=="closed"&&(this.writeStatus="closed"),t!=null?this.abort(t):(this.status==="open"||this.status==="closing")&&(this.timeline.close=Date.now(),this.status="closed",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.dispatchEvent(new Ee))}onRemoteCloseWrite(){this.remoteWriteStatus!=="closed"&&(this.log.trace("on remote close write"),this.remoteWriteStatus="closed",this.safeDispatchEvent("remoteCloseWrite"),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;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let t=!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){t=!1;break}let o=this.writeBuffer.sublist(0,s),i=new $(o);this.writeBuffer.consume(o.byteLength);let a=this.sendData(o);if(t=a.canSendMore,n+=a.sentBytes,a.sentBytes!==i.byteLength&&(i.consume(a.sentBytes),this.writeBuffer.prepend(i)),!t)break}return t||(this.log.trace("sent %d/%d bytes, pausing sending because underlying stream is full, %d bytes left in the write buffer",n,r,this.writeBuffer.byteLength),this.writableNeedsDrain=!0,this.checkWriteBufferLength()),this.writeBuffer.byteLength===0&&this.safeDispatchEvent("idle"),t}finally{this.sendingData=!1}}dispatchReadBuffer(){try{if(this.listenerCount("message")===0){this.log.trace("not dispatching pause buffer as there are no listeners for the message event");return}if(this.readBuffer.byteLength===0){this.log.trace("not dispatching pause buffer as there is no data to dispatch");return}if(this.readStatus==="paused"){this.log.trace("not dispatching pause buffer we are paused");return}if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("dropping %d bytes because the readable end is %s",this.readBuffer.byteLength,this.readStatus),this.readBuffer.consume(this.readBuffer.byteLength);return}let t=this.readBuffer.sublist();this.readBuffer.consume(t.byteLength),this.dispatchEvent(new Rr(t))}finally{this.readBuffer.byteLength===0&&this.remoteWriteStatus==="closed"&&(this.log("close readable end after dispatching read buffer and remote writable end is closed"),this.readStatus="closed"),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new We(`Read buffer length of ${this.readBuffer.byteLength} exceeded limit of ${this.maxReadBufferLength}, read status is ${this.readStatus}`))}checkWriteBufferLength(){this.maxWriteBufferLength!=null&&this.writeBuffer.byteLength>this.maxWriteBufferLength&&this.abort(new We(`Write buffer length of ${this.writeBuffer.byteLength} exceeded limit of ${this.maxWriteBufferLength}, write status is ${this.writeStatus}`))}onMuxerNeedsDrain(){this.writableNeedsDrain=!0}onMuxerDrain(){this.safeDispatchEvent("drain")}};var Mu=4194304,un=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Er=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},so=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},oo=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Ou(e){return typeof e?.closeRead=="function"}function Hu(e){return typeof e?.close=="function"}function no(e){return Ou(e)?e.readStatus==="closing"||e.readStatus==="closed":Hu(e)?e.status!=="open":!1}function qu(e){return e?.addEventListener!=null&&e?.removeEventListener!=null&&e?.send!=null&&e?.push!=null&&e?.log!=null}function Vu(e,t){let r=t?.maxBufferSize??Mu,n=new $,s,o=!1;if(!qu(e))throw new Q("Argument should be a Stream or a Multiaddr");let i=f=>{if(n.append(f.data),n.byteLength>r){let u=n.byteLength;n.consume(n.byteLength),s?.reject(new Error(`Read buffer overflow - ${u} > ${r}`))}s?.resolve()};e.addEventListener("message",i);let a=f=>{f.error!=null?s?.reject(f.error):s?.resolve()};e.addEventListener("close",a);let c=()=>{s?.resolve()};e.addEventListener("remoteCloseWrite",c);let h={readBuffer:n,async read(f){if(o===!0)throw new un("Stream was unwrapped");if(no(e)){if(f?.bytes==null)return null;if(n.byteLength<f.bytes)throw e.log.error("closed after reading %d/%d bytes",n.byteLength,f.bytes),new ye(`Unexpected EOF - stream closed after reading ${n.byteLength}/${f.bytes} bytes`)}let u=f?.bytes??1;for(s=Promise.withResolvers();;){if(n.byteLength>=u){s.resolve();break}if(await Ka(s.promise,f?.signal),no(e)){if(n.byteLength===0&&f?.bytes==null)return null;break}s=Promise.withResolvers()}let b=f?.bytes??n.byteLength;if(n.byteLength<b){if(no(e))throw e.log.error("closed while reading %d/%d bytes",n.byteLength,b),new ye(`Unexpected EOF - stream closed while reading ${n.byteLength}/${b} bytes`);return h.read(f)}let y=n.sublist(0,b);return n.consume(b),y},async write(f,u){if(o===!0)throw new un("Stream was unwrapped");e.send(f)||await Ta(e,"drain",{signal:u?.signal,rejectionEvents:["close"]})},unwrap(){return o||(o=!0,e.removeEventListener("message",i),e.removeEventListener("close",a),e.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(e.log("stream unwrapped with %d unread bytes",n.byteLength),e.push(n))),e}};return h}function io(e,t={}){let r=Vu(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=Bt(t.maxDataLength));let n=t?.lengthDecoder??Yr,s=t?.lengthEncoder??Ji;return{async read(i){let a=-1,c=new $;for(;;){let f=await r.read({...i,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(u){if(u instanceof RangeError)continue;throw u}if(a<0)throw new Er("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new oo(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new so(`Message length too long - ${a} > ${t.maxDataLength}`);let h=await r.read({...i,bytes:a});if(h==null)throw e.log.error("tried to read %d bytes but the stream closed",a),new ye(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(h.byteLength!==a)throw e.log.error("read %d/%d bytes before the stream closed",h.byteLength,a),new ye(`Unexpected EOF - read ${h.byteLength}/${a} bytes before the stream closed`);return h},async write(i,a){await r.write(new $(s(i.byteLength),i),a)},async writeV(i,a){let c=new $(...i.flatMap(h=>[s(h.byteLength),h]));await r.write(c,a)},unwrap(){return r.unwrap()}}}var Fu=1024*1024*4,zu=1024*1024*4,hn=class{buffer;maxBufferSize;lengthDecoder;maxDataLength;encodingLength;constructor(t={}){this.buffer=new $,this.maxBufferSize=t.maxBufferSize??Fu,this.maxDataLength=t.maxDataLength??zu,this.lengthDecoder=t.lengthDecoder??Yr,this.encodingLength=t.encodingLength??Bt}*decode(t){if(this.buffer.append(t),this.buffer.byteLength>this.maxBufferSize)throw new Q(`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 Er("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 Fe=!!globalThis.process?.env?.DUMP_SESSION_KEYS,ao=16;function Gu(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function ln(e){if(typeof e!="boolean")throw new Error(`boolean expected, not ${e}`)}function dn(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function ct(e,t,r=""){let n=Gu(e),s=e?.length,o=t!==void 0;if(!n||o&&s!==t){let i=r&&`"${r}" `,a=o?` of length ${t}`:"",c=n?`length=${s}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return e}function co(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Ca(e,t){ct(e,void 0,"output");let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Vt(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function Ft(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function $u(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}var Zu=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Da(e,t){if(t==null||typeof t!="object")throw new Error("options must be defined");return Object.assign(e,t)}function Ua(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}var fo=(e,t)=>{function r(n,...s){if(ct(n,void 0,"key"),!Zu)throw new Error("Non little-endian hardware is not yet supported");if(e.nonceLength!==void 0){let f=s[0];ct(f,e.varSizeNonce?void 0:e.nonceLength,"nonce")}let o=e.tagLength;o&&s[1]!==void 0&&ct(s[1],void 0,"AAD");let i=t(n,...s),a=(f,u)=>{if(u!==void 0){if(f!==2)throw new Error("cipher output not supported");ct(u,void 0,"output")}},c=!1;return{encrypt(f,u){if(c)throw new Error("cannot encrypt() twice with same key + nonce");return c=!0,ct(f),a(i.encrypt.length,u),i.encrypt(f,u)},decrypt(f,u){if(ct(f),o&&f.length<o)throw new Error('"ciphertext" expected length bigger than tagLength='+o);return a(i.decrypt.length,u),i.decrypt(f,u)}}}return Object.assign(r,e),r};function uo(e,t,r=!0){if(t===void 0)return new Uint8Array(e);if(t.length!==e)throw new Error('"output" expected Uint8Array of length '+e+", got: "+t.length);if(r&&!ju(t))throw new Error("invalid output, must be aligned");return t}function Na(e,t,r){ln(r);let n=new Uint8Array(16),s=$u(n);return s.setBigUint64(0,BigInt(t),r),s.setBigUint64(8,BigInt(e),r),n}function ju(e){return e.byteOffset%4===0}function ze(e){return Uint8Array.from(e)}var Pa=e=>Uint8Array.from(e.split(""),t=>t.charCodeAt(0)),Yu=Pa("expand 16-byte k"),Wu=Pa("expand 32-byte k"),Xu=Vt(Yu),Ju=Vt(Wu);function N(e,t){return e<<t|e>>>32-t}function ho(e){return e.byteOffset%4===0}var pn=64,Qu=16,Ma=2**32-1,ka=Uint32Array.of();function th(e,t,r,n,s,o,i,a){let c=s.length,h=new Uint8Array(pn),f=Vt(h),u=ho(s)&&ho(o),b=u?Vt(s):ka,y=u?Vt(o):ka;for(let d=0;d<c;i++){if(e(t,r,n,f,i,a),i>=Ma)throw new Error("arx: counter overflow");let S=Math.min(pn,c-d);if(u&&S===pn){let l=d/4;if(d%4!==0)throw new Error("arx: invalid block position");for(let g=0,B;g<Qu;g++)B=l+g,y[B]=b[B]^f[g];d+=pn;continue}for(let l=0,g;l<S;l++)g=d+l,o[g]=s[g]^h[l];d+=S}}function lo(e,t){let{allowShortKeys:r,extendNonceFn:n,counterLength:s,counterRight:o,rounds:i}=Da({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if(typeof e!="function")throw new Error("core must be a function");return dn(s),dn(i),ln(o),ln(r),(a,c,h,f,u=0)=>{ct(a,void 0,"key"),ct(c,void 0,"nonce"),ct(h,void 0,"data");let b=h.length;if(f===void 0&&(f=new Uint8Array(b)),ct(f,void 0,"output"),dn(u),u<0||u>=Ma)throw new Error("arx: counter overflow");if(f.length<b)throw new Error(`arx: output (${f.length}) is shorter than data (${b})`);let y=[],d=a.length,S,l;if(d===32)y.push(S=ze(a)),l=Ju;else if(d===16&&r)S=new Uint8Array(32),S.set(a),S.set(a,16),l=Xu,y.push(S);else throw ct(a,32,"arx key"),new Error("invalid key size");ho(c)||y.push(c=ze(c));let g=Vt(S);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(l,g,Vt(c.subarray(0,16)),g),c=c.subarray(16)}let B=16-s;if(B!==c.length)throw new Error(`arx: nonce must be ${B} or 16 bytes`);if(B!==12){let K=new Uint8Array(12);K.set(c,o?0:12-c.length),c=K,y.push(c)}let w=Vt(c);return th(e,l,g,w,h,f,u,i),Ft(...y),f}}function ht(e,t){return e[t++]&255|(e[t++]&255)<<8}var po=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;constructor(t){t=ze(ct(t,32,"key"));let r=ht(t,0),n=ht(t,2),s=ht(t,4),o=ht(t,6),i=ht(t,8),a=ht(t,10),c=ht(t,12),h=ht(t,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|h<<8)&8191,this.r[9]=h>>>5&127;for(let f=0;f<8;f++)this.pad[f]=ht(t,16+2*f)}process(t,r,n=!1){let s=n?0:2048,{h:o,r:i}=this,a=i[0],c=i[1],h=i[2],f=i[3],u=i[4],b=i[5],y=i[6],d=i[7],S=i[8],l=i[9],g=ht(t,r+0),B=ht(t,r+2),w=ht(t,r+4),K=ht(t,r+6),P=ht(t,r+8),M=ht(t,r+10),O=ht(t,r+12),L=ht(t,r+14),A=o[0]+(g&8191),U=o[1]+((g>>>13|B<<3)&8191),k=o[2]+((B>>>10|w<<6)&8191),T=o[3]+((w>>>7|K<<9)&8191),x=o[4]+((K>>>4|P<<12)&8191),p=o[5]+(P>>>1&8191),m=o[6]+((P>>>14|M<<2)&8191),v=o[7]+((M>>>11|O<<5)&8191),_=o[8]+((O>>>8|L<<8)&8191),I=o[9]+(L>>>5|s),E=0,R=E+A*a+U*(5*l)+k*(5*S)+T*(5*d)+x*(5*y);E=R>>>13,R&=8191,R+=p*(5*b)+m*(5*u)+v*(5*f)+_*(5*h)+I*(5*c),E+=R>>>13,R&=8191;let C=E+A*c+U*a+k*(5*l)+T*(5*S)+x*(5*d);E=C>>>13,C&=8191,C+=p*(5*y)+m*(5*b)+v*(5*u)+_*(5*f)+I*(5*h),E+=C>>>13,C&=8191;let D=E+A*h+U*c+k*a+T*(5*l)+x*(5*S);E=D>>>13,D&=8191,D+=p*(5*d)+m*(5*y)+v*(5*b)+_*(5*u)+I*(5*f),E+=D>>>13,D&=8191;let F=E+A*f+U*h+k*c+T*a+x*(5*l);E=F>>>13,F&=8191,F+=p*(5*S)+m*(5*d)+v*(5*y)+_*(5*b)+I*(5*u),E+=F>>>13,F&=8191;let V=E+A*u+U*f+k*h+T*c+x*a;E=V>>>13,V&=8191,V+=p*(5*l)+m*(5*S)+v*(5*d)+_*(5*y)+I*(5*b),E+=V>>>13,V&=8191;let q=E+A*b+U*u+k*f+T*h+x*c;E=q>>>13,q&=8191,q+=p*a+m*(5*l)+v*(5*S)+_*(5*d)+I*(5*y),E+=q>>>13,q&=8191;let z=E+A*y+U*b+k*u+T*f+x*h;E=z>>>13,z&=8191,z+=p*c+m*a+v*(5*l)+_*(5*S)+I*(5*d),E+=z>>>13,z&=8191;let Y=E+A*d+U*y+k*b+T*u+x*f;E=Y>>>13,Y&=8191,Y+=p*h+m*c+v*a+_*(5*l)+I*(5*S),E+=Y>>>13,Y&=8191;let et=E+A*S+U*d+k*y+T*b+x*u;E=et>>>13,et&=8191,et+=p*f+m*h+v*c+_*a+I*(5*l),E+=et>>>13,et&=8191;let G=E+A*l+U*S+k*d+T*y+x*b;E=G>>>13,G&=8191,G+=p*u+m*f+v*h+_*c+I*a,E+=G>>>13,G&=8191,E=(E<<2)+E|0,E=E+R|0,R=E&8191,E=E>>>13,C+=E,o[0]=R,o[1]=C,o[2]=D,o[3]=F,o[4]=V,o[5]=q,o[6]=z,o[7]=Y,o[8]=et,o[9]=G}finalize(){let{h:t,pad:r}=this,n=new Uint16Array(10),s=t[1]>>>13;t[1]&=8191;for(let a=2;a<10;a++)t[a]+=s,s=t[a]>>>13,t[a]&=8191;t[0]+=s*5,s=t[0]>>>13,t[0]&=8191,t[1]+=s,s=t[1]>>>13,t[1]&=8191,t[2]+=s,n[0]=t[0]+5,s=n[0]>>>13,n[0]&=8191;for(let a=1;a<10;a++)n[a]=t[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++)t[a]=t[a]&o|n[a];t[0]=(t[0]|t[1]<<13)&65535,t[1]=(t[1]>>>3|t[2]<<10)&65535,t[2]=(t[2]>>>6|t[3]<<7)&65535,t[3]=(t[3]>>>9|t[4]<<4)&65535,t[4]=(t[4]>>>12|t[5]<<1|t[6]<<14)&65535,t[5]=(t[6]>>>2|t[7]<<11)&65535,t[6]=(t[7]>>>5|t[8]<<8)&65535,t[7]=(t[8]>>>8|t[9]<<5)&65535;let i=t[0]+r[0];t[0]=i&65535;for(let a=1;a<8;a++)i=(t[a]+r[a]|0)+(i>>>16)|0,t[a]=i&65535;Ft(n)}update(t){co(this),ct(t),t=ze(t);let{buffer:r,blockLen:n}=this,s=t.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(t,o);continue}r.set(t.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(){Ft(this.h,this.r,this.buffer,this.pad)}digestInto(t){co(this),Ca(t,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++)t[o++]=n[i]>>>0,t[o++]=n[i]>>>8;return t}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}};function eh(e){let t=(n,s)=>e(s).update(n).digest(),r=e(new Uint8Array(32));return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=n=>e(n),t}var Oa=eh(e=>new po(e));function Va(e,t,r,n,s,o=20){let i=e[0],a=e[1],c=e[2],h=e[3],f=t[0],u=t[1],b=t[2],y=t[3],d=t[4],S=t[5],l=t[6],g=t[7],B=s,w=r[0],K=r[1],P=r[2],M=i,O=a,L=c,A=h,U=f,k=u,T=b,x=y,p=d,m=S,v=l,_=g,I=B,E=w,R=K,C=P;for(let F=0;F<o;F+=2)M=M+U|0,I=N(I^M,16),p=p+I|0,U=N(U^p,12),M=M+U|0,I=N(I^M,8),p=p+I|0,U=N(U^p,7),O=O+k|0,E=N(E^O,16),m=m+E|0,k=N(k^m,12),O=O+k|0,E=N(E^O,8),m=m+E|0,k=N(k^m,7),L=L+T|0,R=N(R^L,16),v=v+R|0,T=N(T^v,12),L=L+T|0,R=N(R^L,8),v=v+R|0,T=N(T^v,7),A=A+x|0,C=N(C^A,16),_=_+C|0,x=N(x^_,12),A=A+x|0,C=N(C^A,8),_=_+C|0,x=N(x^_,7),M=M+k|0,C=N(C^M,16),v=v+C|0,k=N(k^v,12),M=M+k|0,C=N(C^M,8),v=v+C|0,k=N(k^v,7),O=O+T|0,I=N(I^O,16),_=_+I|0,T=N(T^_,12),O=O+T|0,I=N(I^O,8),_=_+I|0,T=N(T^_,7),L=L+x|0,E=N(E^L,16),p=p+E|0,x=N(x^p,12),L=L+x|0,E=N(E^L,8),p=p+E|0,x=N(x^p,7),A=A+U|0,R=N(R^A,16),m=m+R|0,U=N(U^m,12),A=A+U|0,R=N(R^A,8),m=m+R|0,U=N(U^m,7);let D=0;n[D++]=i+M|0,n[D++]=a+O|0,n[D++]=c+L|0,n[D++]=h+A|0,n[D++]=f+U|0,n[D++]=u+k|0,n[D++]=b+T|0,n[D++]=y+x|0,n[D++]=d+p|0,n[D++]=S+m|0,n[D++]=l+v|0,n[D++]=g+_|0,n[D++]=B+I|0,n[D++]=w+E|0,n[D++]=K+R|0,n[D++]=P+C|0}function rh(e,t,r,n){let s=e[0],o=e[1],i=e[2],a=e[3],c=t[0],h=t[1],f=t[2],u=t[3],b=t[4],y=t[5],d=t[6],S=t[7],l=r[0],g=r[1],B=r[2],w=r[3];for(let P=0;P<20;P+=2)s=s+c|0,l=N(l^s,16),b=b+l|0,c=N(c^b,12),s=s+c|0,l=N(l^s,8),b=b+l|0,c=N(c^b,7),o=o+h|0,g=N(g^o,16),y=y+g|0,h=N(h^y,12),o=o+h|0,g=N(g^o,8),y=y+g|0,h=N(h^y,7),i=i+f|0,B=N(B^i,16),d=d+B|0,f=N(f^d,12),i=i+f|0,B=N(B^i,8),d=d+B|0,f=N(f^d,7),a=a+u|0,w=N(w^a,16),S=S+w|0,u=N(u^S,12),a=a+u|0,w=N(w^a,8),S=S+w|0,u=N(u^S,7),s=s+h|0,w=N(w^s,16),d=d+w|0,h=N(h^d,12),s=s+h|0,w=N(w^s,8),d=d+w|0,h=N(h^d,7),o=o+f|0,l=N(l^o,16),S=S+l|0,f=N(f^S,12),o=o+f|0,l=N(l^o,8),S=S+l|0,f=N(f^S,7),i=i+u|0,g=N(g^i,16),b=b+g|0,u=N(u^b,12),i=i+u|0,g=N(g^i,8),b=b+g|0,u=N(u^b,7),a=a+c|0,B=N(B^a,16),y=y+B|0,c=N(c^y,12),a=a+c|0,B=N(B^a,8),y=y+B|0,c=N(c^y,7);let K=0;n[K++]=s,n[K++]=o,n[K++]=i,n[K++]=a,n[K++]=l,n[K++]=g,n[K++]=B,n[K++]=w}var nh=lo(Va,{counterRight:!1,counterLength:4,allowShortKeys:!1}),sh=lo(Va,{counterRight:!1,counterLength:8,extendNonceFn:rh,allowShortKeys:!1});var oh=new Uint8Array(16),Ha=(e,t)=>{e.update(t);let r=t.length%16;r&&e.update(oh.subarray(r))},ih=new Uint8Array(32);function qa(e,t,r,n,s){s!==void 0&&ct(s,void 0,"AAD");let o=e(t,r,ih),i=Na(n.length,s?s.length:0,!0),a=Oa.create(o);s&&Ha(a,s),Ha(a,n),a.update(i);let c=a.digest();return Ft(o,i),c}var Fa=e=>(t,r,n)=>({encrypt(o,i){let a=o.length;i=uo(a+16,i,!1),i.set(o);let c=i.subarray(0,-16);e(t,r,c,c,1);let h=qa(e,t,r,c,n);return i.set(h,a),Ft(h),i},decrypt(o,i){i=uo(o.length-16,i,!1);let a=o.subarray(0,-16),c=o.subarray(-16),h=qa(e,t,r,a,n);if(!Ua(c,h))throw new Error("invalid tag");return i.set(o.subarray(0,-16)),e(t,r,i,i,1),Ft(h),i}}),mo=fo({blockSize:64,nonceLength:12,tagLength:16},Fa(nh)),Ty=fo({blockSize:64,nonceLength:24,tagLength:16},Fa(sh));function Ga(e,t,r){return se(e),r===void 0&&(r=new Uint8Array(e.outputLen)),Oe(e,r,t)}var yo=Uint8Array.of(0),za=Uint8Array.of();function $a(e,t,r,n=32){se(e),Et(n,"length");let s=e.outputLen;if(n>255*s)throw new Error("Length must be <= 255*HashLen");let o=Math.ceil(n/s);r===void 0?r=za:H(r,void 0,"info");let i=new Uint8Array(o*s),a=Oe.create(e,t),c=a._cloneInto(),h=new Uint8Array(a.outputLen);for(let f=0;f<o;f++)yo[0]=f+1,c.update(f===0?za:h).update(r).update(yo).digestInto(h),i.set(h,s*f),a._cloneInto(c);return a.destroy(),c.destroy(),At(h,yo),i.slice(0,n)}var mn={hashSHA256(e){return Tt(e.subarray())},getHKDF(e,t){let r=Ga(Tt,t,e),s=$a(Tt,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 e=lr.utils.randomSecretKey();return{publicKey:lr.getPublicKey(e),privateKey:e}},generateX25519KeyPairFromSeed(e){return{publicKey:lr.getPublicKey(e),privateKey:e}},generateX25519SharedKey(e,t){return lr.getSharedSecret(e.subarray(),t.subarray())},chaCha20Poly1305Encrypt(e,t,r,n){return mo(n,t,r).encrypt(e.subarray())},chaCha20Poly1305Decrypt(e,t,r,n,s){return mo(n,t,r).decrypt(e.subarray(),s)}};var Za=mn;function ja(e){return{generateKeypair:e.generateX25519KeyPair,dh:(t,r)=>e.generateX25519SharedKey(t.privateKey,r).subarray(0,32),encrypt:e.chaCha20Poly1305Encrypt,decrypt:e.chaCha20Poly1305Decrypt,hash:e.hashSHA256,hkdf:e.getHKDF}}var Ge=e=>{let t=ft(2);return t[0]=e>>8,t[1]=e,t};Ge.bytes=2;var $e=e=>{if(e.length<2)throw RangeError("Could not decode int16BE");if(e instanceof Uint8Array){let t=0;return t+=e[0]<<8,t+=e[1],t}return e.getUint16(0)};$e.bytes=2;function Ya(e){return{xxHandshakeSuccesses:e.registerCounter("libp2p_noise_xxhandshake_successes_total",{help:"Total count of noise xxHandshakes successes_"}),xxHandshakeErrors:e.registerCounter("libp2p_noise_xxhandshake_error_total",{help:"Total count of noise xxHandshakes errors"}),encryptedPackets:e.registerCounter("libp2p_noise_encrypted_packets_total",{help:"Total count of noise encrypted packets successfully"}),decryptedPackets:e.registerCounter("libp2p_noise_decrypted_packets_total",{help:"Total count of noise decrypted packets"}),decryptErrors:e.registerCounter("libp2p_noise_decrypt_errors_total",{help:"Total count of noise decrypt errors"})}}function go(e,t){!t.enabled||!Fe||(e?(t(`LOCAL_STATIC_PUBLIC_KEY ${Z(e.publicKey,"hex")}`),t(`LOCAL_STATIC_PRIVATE_KEY ${Z(e.privateKey,"hex")}`)):t("Missing local static keys."))}function bo(e,t){!t.enabled||!Fe||(e?(t(`LOCAL_PUBLIC_EPHEMERAL_KEY ${Z(e.publicKey,"hex")}`),t(`LOCAL_PRIVATE_EPHEMERAL_KEY ${Z(e.privateKey,"hex")}`)):t("Missing local ephemeral keys."))}function Wa(e,t){!t.enabled||!Fe||t(e?`REMOTE_STATIC_PUBLIC_KEY ${Z(e.subarray(),"hex")}`:"Missing remote static public key.")}function xo(e,t){!t.enabled||!Fe||t(e?`REMOTE_EPHEMERAL_PUBLIC_KEY ${Z(e.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function wo(e,t,r){!r.enabled||!Fe||(r(`CIPHER_STATE_1 ${e.n.getUint64()} ${e.k&&Z(e.k,"hex")}`),r(`CIPHER_STATE_2 ${t.n.getUint64()} ${t.k&&Z(t.k,"hex")}`))}var Ze=class e extends Error{code;constructor(t="Invalid crypto exchange"){super(t),this.code=e.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var ah=0,ch=4294967295,fh="Cipher state has reached maximum n, a new handshake must be performed",yn=class{n;bytes;view;constructor(t=ah){this.n=t,this.bytes=st(12),this.view=new DataView(this.bytes.buffer,this.bytes.byteOffset,this.bytes.byteLength),this.view.setUint32(4,t,!0)}increment(){this.n++,this.view.setUint32(4,this.n,!0)}getBytes(){return this.bytes}getUint64(){return this.n}assertValue(){if(this.n>ch)throw new Error(fh)}};var ge=st(0),je=class{k;n;crypto;constructor(t,r=void 0,n=0){this.crypto=t,this.k=r,this.n=new yn(n)}hasKey(){return!!this.k}encryptWithAd(t,r){if(!this.hasKey())return r;this.n.assertValue();let n=this.crypto.encrypt(r,this.n.getBytes(),t,this.k);return this.n.increment(),n}decryptWithAd(t,r,n){if(!this.hasKey())return r;this.n.assertValue();let s=this.crypto.decrypt(r,this.n.getBytes(),t,this.k,n);return this.n.increment(),s}},Eo=class{cs;ck;h;crypto;constructor(t,r){this.crypto=t;let n=W(r,"utf-8");this.h=uh(t,n),this.ck=this.h,this.cs=new je(t)}mixKey(t){let[r,n]=this.crypto.hkdf(this.ck,t);this.ck=r,this.cs=new je(this.crypto,n)}mixHash(t){this.h=this.crypto.hash(new $(this.h,t))}encryptAndHash(t){let r=this.cs.encryptWithAd(this.h,t);return this.mixHash(r),r}decryptAndHash(t){let r=this.cs.decryptWithAd(this.h,t);return this.mixHash(t),r}split(){let[t,r]=this.crypto.hkdf(this.ck,ge);return[new je(this.crypto,t),new je(this.crypto,r)]}},So=class{ss;s;e;rs;re;initiator;crypto;constructor(t){let{crypto:r,protocolName:n,prologue:s,initiator:o,s:i,e:a,rs:c,re:h}=t;this.crypto=r,this.ss=new Eo(r,n),this.ss.mixHash(s),this.initiator=o,this.s=i,this.e=a,this.rs=c,this.re=h}writeE(){if(this.e)throw new Error("ephemeral keypair is already set");let t=this.crypto.generateKeypair();return this.ss.mixHash(t.publicKey),this.e=t,t.publicKey}writeS(){if(!this.s)throw new Error("static keypair is not set");return this.ss.encryptAndHash(this.s.publicKey)}writeEE(){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.re))}writeES(){if(this.initiator){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}else{if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}}writeSE(){if(this.initiator){if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}else{if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}}readE(t,r=0){if(this.re)throw new Error("remote ephemeral public key is already set");if(t.byteLength<r+32)throw new Error("message is not long enough");this.re=t.sublist(r,r+32),this.ss.mixHash(this.re)}readS(t,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(t.byteLength<r+n)throw new Error("message is not long enough");let s=t.sublist(r,r+n);return this.rs=this.ss.decryptAndHash(s),n}readEE(){this.writeEE()}readES(){this.writeES()}readSE(){this.writeSE()}},Sr=class extends So{writeMessageA(t){return new $(this.writeE(),this.ss.encryptAndHash(t))}writeMessageB(t){let r=this.writeE();this.writeEE();let n=this.writeS();return this.writeES(),new $(r,n,this.ss.encryptAndHash(t))}writeMessageC(t){let r=this.writeS();return this.writeSE(),new $(r,this.ss.encryptAndHash(t))}readMessageA(t){try{return this.readE(t),this.ss.decryptAndHash(t.sublist(32))}catch(r){throw new Ze(`handshake stage 0 validation fail: ${r.message}`)}}readMessageB(t){try{this.readE(t),this.readEE();let r=this.readS(t,32);return this.readES(),this.ss.decryptAndHash(t.sublist(32+r))}catch(r){throw new Ze(`handshake stage 1 validation fail: ${r.message}`)}}readMessageC(t){try{let r=this.readS(t);return this.readSE(),this.ss.decryptAndHash(t.sublist(r))}catch(r){throw new Ze(`handshake stage 2 validation fail: ${r.message}`)}}};function uh(e,t){if(t.length<=32){let r=st(32);return r.set(t),r}else return e.hash(t)}var gn;(function(e){let t;e.codec=()=>(t==null&&(t=me((r,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),r.webtransportCerthashes!=null)for(let o of r.webtransportCerthashes)n.uint32(10),n.bytes(o);if(r.streamMuxers!=null)for(let o of r.streamMuxers)n.uint32(18),n.string(o);s.lengthDelimited!==!1&&n.ldelim()},(r,n,s={})=>{let o={webtransportCerthashes:[],streamMuxers:[]},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{if(s.limits?.webtransportCerthashes!=null&&o.webtransportCerthashes.length===s.limits.webtransportCerthashes)throw new yr('Decode error - map field "webtransportCerthashes" had too many elements');o.webtransportCerthashes.push(r.bytes());break}case 2:{if(s.limits?.streamMuxers!=null&&o.streamMuxers.length===s.limits.streamMuxers)throw new yr('Decode error - map field "streamMuxers" had too many elements');o.streamMuxers.push(r.string());break}default:{r.skipType(a&7);break}}}return o})),t),e.encode=r=>pe(r,e.codec()),e.decode=(r,n)=>le(r,e.codec(),n)})(gn||(gn={}));var Ar;(function(e){let t;e.codec=()=>(t==null&&(t=me((r,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),r.identityKey!=null&&r.identityKey.byteLength>0&&(n.uint32(10),n.bytes(r.identityKey)),r.identitySig!=null&&r.identitySig.byteLength>0&&(n.uint32(18),n.bytes(r.identitySig)),r.extensions!=null&&(n.uint32(34),gn.codec().encode(r.extensions,n)),s.lengthDelimited!==!1&&n.ldelim()},(r,n,s={})=>{let o={identityKey:st(0),identitySig:st(0)},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{o.identityKey=r.bytes();break}case 2:{o.identitySig=r.bytes();break}case 4:{o.extensions=gn.codec().decode(r,r.uint32(),{limits:s.limits?.extensions});break}default:{r.skipType(a&7);break}}}return o})),t),e.encode=r=>pe(r,e.codec()),e.decode=(r,n)=>le(r,e.codec(),n)})(Ar||(Ar={}));async function vo(e,t,r){let n=await e.sign(Ja(t));return Ar.encode({identityKey:$t(e.publicKey),identitySig:n,extensions:r})}async function Bo(e,t,r){try{let n=Ar.decode(e),s=xr(n.identityKey);if(r?.equals(s)===!1)throw new Error(`Payload identity key ${s} does not match expected remote identity key ${r}`);if(!t)throw new Error("Remote static does not exist");let o=Ja(t);if(!await s.verify(o,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new Lr(n.message)}}function Ja(e){let t=W("noise-libp2p-static-key:");return e instanceof Uint8Array?re([t,e],t.length+e.length):(e.prepend(t),e)}var Ao=class extends fn{stream;handshake;metrics;decoder;constructor(t,r,n){super({log:t.log,inactivityTimeout:t.inactivityTimeout,maxReadBufferLength:t.maxReadBufferLength,direction:t.direction}),this.stream=t,this.handshake=r,this.metrics=n,this.decoder=new hn({lengthDecoder:$e,maxBufferSize:16*1024*1024,encodingLength:()=>2});let s=c=>{try{for(let h of this.decoder.decode(c.data))this.onData(this.decrypt(h))}catch(h){this.abort(h)}};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(t){let r=new $;for(let n=0;n<t.byteLength;n+=65519){let s=n+65519;s>t.byteLength&&(s=t.byteLength);let o;t instanceof Uint8Array?o=this.handshake.encrypt(t.subarray(n,s)):o=this.handshake.encrypt(t.sublist(n,s)),this.metrics?.encryptedPackets.increment(),r.append(Ge(o.byteLength)),r.append(o)}return r}decrypt(t){let r=new $;for(let n=0;n<t.byteLength;n+=65535){let s=n+65535;if(s>t.byteLength&&(s=t.byteLength),s-ao<n)throw new Error("Invalid chunk");let o;t instanceof Uint8Array?o=t.subarray(n,s):o=t.sublist(n,s);let i=t.subarray(n,s-ao);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(t){return this.stream.close(t)}sendPause(){this.stream.pause()}sendResume(){this.stream.resume()}sendReset(t){this.stream.abort(t)}sendData(t){return{sentBytes:t.byteLength,canSendMore:this.stream.send(this.encrypt(t))}}};function Lo(e,t,r){return new Ao(e,t,r)}async function Qa(e,t){let{log:r,connection:n,crypto:s,privateKey:o,prologue:i,s:a,remoteIdentityKey:c,extensions:h}=e,f=await vo(o,a.publicKey,h),u=new Sr({crypto:s,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:i,s:a});go(u.s,r),r.trace("Stage 0 - Initiator starting to send first message."),await n.write(u.writeMessageA(ge),t),r.trace("Stage 0 - Initiator finished sending first message."),bo(u.e,r),r.trace("Stage 1 - Initiator waiting to receive first message from responder...");let b=u.readMessageB(await n.read(t));r.trace("Stage 1 - Initiator received the message."),xo(u.re,r),Wa(u.rs,r),r.trace("Initiator going to check remote's signature...");let y=await Bo(b,u.rs,c);r.trace("All good with the signature!"),r.trace("Stage 2 - Initiator sending third handshake message."),await n.write(u.writeMessageC(f),t),r.trace("Stage 2 - Initiator sent message with signed payload.");let[d,S]=u.ss.split();return wo(d,S,r),{payload:y,encrypt:l=>d.encryptWithAd(ge,l),decrypt:(l,g)=>S.decryptWithAd(ge,l,g)}}async function tc(e,t){let{log:r,connection:n,crypto:s,privateKey:o,prologue:i,s:a,remoteIdentityKey:c,extensions:h}=e,f=await vo(o,a.publicKey,h),u=new Sr({crypto:s,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:i,s:a});go(u.s,r),r.trace("Stage 0 - Responder waiting to receive first message."),u.readMessageA(await n.read(t)),r.trace("Stage 0 - Responder received first message."),xo(u.re,r),r.trace("Stage 1 - Responder sending out first message with signed payload and static key."),await n.write(u.writeMessageB(f),t),r.trace("Stage 1 - Responder sent the second handshake message with signed payload."),bo(u.e,r),r.trace("Stage 2 - Responder waiting for third handshake message...");let b=u.readMessageC(await n.read(t));r.trace("Stage 2 - Responder received the message, finished handshake.");let y=await Bo(b,u.rs,c),[d,S]=u.ss.split();return wo(d,S,r),{payload:y,encrypt:l=>S.encryptWithAd(ge,l),decrypt:(l,g)=>d.decryptWithAd(ge,l,g)}}var bn=class{protocol="/noise";crypto;prologue;staticKey;extensions;metrics;components;log;constructor(t,r={}){let{staticNoiseKey:n,extensions:s,crypto:o,prologueBytes:i}=r,{metrics:a}=t;this.components=t,this.log=t.logger.forComponent("libp2p:noise");let c=o??Za;this.crypto=ja(c),this.extensions={webtransportCerthashes:[],...s},this.metrics=a?Ya(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=i??st(0)}[Symbol.toStringTag]="@libp2p/noise";[To]=["@libp2p/connection-encryption","@libp2p/noise"];async secureOutbound(t,r){let n=t.log?.newScope("noise")??this.log,s=io(t,{lengthEncoder:Ge,lengthDecoder:$e,maxDataLength:65535}),o=await this.performHandshakeInitiator(s,this.components.privateKey,n,r?.remotePeer?.publicKey,r),i=xr(o.payload.identityKey);return{connection:Lo(s.unwrap(),o,this.metrics),remoteExtensions:o.payload.extensions,remotePeer:Js(i),streamMuxer:r?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(o.payload.extensions?.streamMuxers)}}getStreamMuxer(t){if(t==null||t.length===0)return;let r=this.components.upgrader.getStreamMuxers();if(r!=null)for(let n of t){let s=r.get(n);if(s!=null)return s}if(t.length)throw new Ir("Early muxer negotiation was requested but the initiator and responder had no common muxers")}async secureInbound(t,r){let n=t.log?.newScope("noise")??this.log,s=io(t,{lengthEncoder:Ge,lengthDecoder:$e,maxDataLength:65535}),o=await this.performHandshakeResponder(s,this.components.privateKey,n,r?.remotePeer?.publicKey,r),i=xr(o.payload.identityKey);return{connection:Lo(s.unwrap(),o,this.metrics),remoteExtensions:o.payload.extensions,remotePeer:Js(i),streamMuxer:r?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(o.payload.extensions?.streamMuxers)}}async performHandshakeInitiator(t,r,n,s,o){let i,a=o?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{i=await Qa({connection:t,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(t,r,n,s,o){let i,a=o?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{i=await tc({connection:t,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 hh(e={}){return t=>new bn(t,e)}return oc(lh);})();
3
3
  /*! Bundled license information:
4
4
 
5
- @noble/hashes/esm/utils.js:
5
+ @noble/hashes/utils.js:
6
6
  (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
7
7
 
8
- @noble/curves/esm/utils.js:
9
- @noble/curves/esm/abstract/modular.js:
10
- @noble/curves/esm/abstract/curve.js:
11
- @noble/curves/esm/abstract/edwards.js:
12
- @noble/curves/esm/abstract/montgomery.js:
13
- @noble/curves/esm/ed25519.js:
14
- @noble/curves/esm/abstract/weierstrass.js:
15
- @noble/curves/esm/_shortw_utils.js:
16
- @noble/curves/esm/secp256k1.js:
8
+ @noble/curves/utils.js:
9
+ @noble/curves/abstract/modular.js:
10
+ @noble/curves/abstract/curve.js:
11
+ @noble/curves/abstract/edwards.js:
12
+ @noble/curves/abstract/montgomery.js:
13
+ @noble/curves/ed25519.js:
14
+ @noble/curves/abstract/weierstrass.js:
15
+ @noble/curves/secp256k1.js:
17
16
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
18
17
 
19
- @noble/ciphers/esm/utils.js:
18
+ @noble/ciphers/utils.js:
20
19
  (*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) *)
21
20
  */
22
21
  return Libp2PNoise}));