@libp2p/noise 16.1.4-fb19b055d → 17.0.1-5cb617ae2
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/README.md +31 -35
- package/dist/index.min.js +11 -14
- package/dist/index.min.js.map +4 -4
- package/dist/src/crypto/index.browser.js +1 -1
- package/dist/src/crypto/index.d.ts +5 -1
- package/dist/src/crypto/index.d.ts.map +1 -1
- package/dist/src/crypto/index.js +4 -3
- package/dist/src/crypto/index.js.map +1 -1
- package/dist/src/crypto/js.d.ts +1 -1
- package/dist/src/crypto/js.js +4 -4
- package/dist/src/crypto/js.js.map +1 -1
- package/dist/src/crypto.d.ts +1 -1
- package/dist/src/index.d.ts +25 -14
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +23 -12
- package/dist/src/index.js.map +1 -1
- package/dist/src/logger.d.ts +2 -2
- package/dist/src/logger.js +1 -1
- package/dist/src/noise.d.ts +3 -3
- package/dist/src/noise.js +6 -6
- package/dist/src/nonce.js +1 -1
- package/dist/src/nonce.js.map +1 -1
- package/dist/src/performHandshake.d.ts +1 -1
- package/dist/src/performHandshake.js +3 -3
- package/dist/src/proto/payload.d.ts +34 -4
- package/dist/src/proto/payload.d.ts.map +1 -1
- package/dist/src/proto/payload.js +95 -13
- package/dist/src/proto/payload.js.map +1 -1
- package/dist/src/protocol.d.ts +3 -3
- package/dist/src/protocol.d.ts.map +1 -1
- package/dist/src/protocol.js +2 -2
- package/dist/src/types.d.ts +2 -2
- package/dist/src/utils.d.ts +2 -2
- package/dist/src/utils.js +1 -1
- package/package.json +64 -38
- package/src/crypto/index.browser.ts +1 -1
- package/src/crypto/index.ts +8 -5
- package/src/crypto/js.ts +6 -6
- package/src/crypto.ts +1 -1
- package/src/index.ts +26 -15
- package/src/logger.ts +3 -3
- package/src/noise.ts +10 -10
- package/src/nonce.ts +1 -1
- package/src/performHandshake.ts +4 -4
- package/src/proto/payload.ts +133 -9
- package/src/protocol.ts +3 -3
- package/src/types.ts +2 -2
- package/src/utils.ts +2 -2
package/dist/index.min.js
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
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 Jn=Object.defineProperty;var Hc=Object.getOwnPropertyDescriptor;var qc=Object.getOwnPropertyNames;var zc=Object.prototype.hasOwnProperty;var Ae=(t,e)=>{for(var r in e)Jn(t,r,{get:e[r],enumerable:!0})},jc=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of qc(e))!zc.call(t,s)&&s!==r&&Jn(t,s,{get:()=>e[s],enumerable:!(n=Hc(e,s))||n.enumerable});return t};var Vc=t=>jc(Jn({},"__esModule",{value:!0}),t);var gl={};Ae(gl,{noise:()=>yl,pureJsCrypto:()=>Wn});var zr=class extends Error{static name="UnexpectedPeerError";constructor(e="Unexpected Peer"){super(e),this.name="UnexpectedPeerError"}},jr=class extends Error{static name="InvalidCryptoExchangeError";constructor(e="Invalid crypto exchange"){super(e),this.name="InvalidCryptoExchangeError"}},ie=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Kt=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var Vr=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var et=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},mt=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var Ut=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var $r=class extends Event{data;constructor(e,r){super("message",r),this.data=e}},Pt=class extends Event{error;local;constructor(e,r,n){super("close",n),this.error=r,this.local=e}},Yr=class extends Pt{constructor(e,r){super(!0,e,r)}},Wr=class extends Pt{constructor(e,r){super(!1,e,r)}};var Qn=Symbol.for("@libp2p/peer-id");function $c(t){return typeof t?.handleEvent=="function"}function Yc(t){return t===!0||t===!1}function Wc(t){return Yc(t)?t:t?.capture??!1}function es(t){let e={capture:Wc(t),once:!!t?.once};return t?.passive!=null&&(e.passive=t?.passive),t?.signal!=null&&(e.signal=t?.signal),e}function ii(t,e){return es(t).capture===es(e).capture}var Gr=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){let s=es(n);if(s?.signal?.aborted===!0)return;let o=f=>{s.once&&this.removeEventListener(e,r,s),$c(r)?r.handleEvent(f):r(f)},i=this.#e.get(e);if(i==null&&(i=[],this.#e.set(e,i)),i.some(f=>f.callback!==r?!1:ii(f.options,s)))return;super.addEventListener(e,o,s);let c=()=>{this.removeEventListener(e,r,s)};s.signal?.addEventListener("abort",c),i.push({callback:r,wrapper:o,options:s,onAbort:c})}removeEventListener(e,r,n){let s=this.#e.get(e);if(s==null){super.removeEventListener(e,r??null,n);return}this.#e.set(e,s.filter(o=>o.callback===r&&ii(o.options,n)?(super.removeEventListener(e,o.wrapper,n),o.options?.signal?.removeEventListener("abort",o.onAbort),!1):!0))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var ai=Symbol.for("@libp2p/service-capabilities");var os={};Ae(os,{base58btc:()=>fe,base58flickr:()=>rf});var Wl=new Uint8Array(0);function fi(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Te(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return yt(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return yt(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function ui(t){let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}var ci=4096;function hi(t){let e=t.length;if(e<=ci)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.subarray(n,n+=ci));return r}function Gc(t){return t?.buffer instanceof ArrayBuffer}function yt(t){return Gc(t)?t:t.slice()}function Zc(t,e,r){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),s=0;s<n.length;s++)n[s]=255;for(var o=0;o<t.length;o++){var i=t.charAt(o),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=o,r){var c=i.toLowerCase().charCodeAt(0),f=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=o),f!==a&&(n[f]=o)}}var u=t.length,h=t.charAt(0),p=Math.log(u)/Math.log(256),d=Math.log(256)/Math.log(u);function w(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var E=0,b=0,R=0,T=x.length;R!==T&&x[R]===0;)R++,E++;for(var O=(T-R)*d+1>>>0,N=new Uint8Array(O);R!==T;){for(var K=x[R],_=0,C=O-1;(K!==0||_<b)&&C!==-1;C--,_++)K+=256*N[C]>>>0,N[C]=K%u>>>0,K=K/u>>>0;if(K!==0)throw new Error("Non-zero carry");b=_,R++}for(var F=O-b;F!==O&&N[F]===0;)F++;for(var M=h.repeat(E);F<O;++F)M+=t.charAt(N[F]);return M}function g(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var E=0;if(x[E]!==" "){for(var b=0,R=0;x[E]===h;)b++,E++;for(var T=(x.length-E)*p+1>>>0,O=new Uint8Array(T);x[E];){var N=n[x.charCodeAt(E)];if(N===255)return;for(var K=0,_=T-1;(N!==0||K<R)&&_!==-1;_--,K++)N+=u*O[_]>>>0,O[_]=N%256>>>0,N=N/256>>>0;if(N!==0)throw new Error("Non-zero carry");R=K,E++}if(x[E]!==" "){for(var C=T-R;C!==T&&O[C]===0;)C++;for(var F=new Uint8Array(b+(T-C)),M=b;C!==T;)F[M++]=O[C++];return F}}}function y(x){var E=g(x);if(E)return E;throw new Error(`Non-${e} character`)}return{encode:w,decodeUnsafe:g,decode:y}}var Xc=Zc,Jc=Xc,di=Jc;var ts=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},rs=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let s=r.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return pi(this,e)}},ns=class{decoders;constructor(e){this.decoders=e}or(e){return pi(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function pi(t,e){return new ns({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var ss=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,s){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=s,this.encoder=new ts(e,r,n),this.decoder=new rs(e,r,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Nt({name:t,prefix:e,encode:r,decode:n}){return new ss(t,e,r,n)}function tt({name:t,prefix:e,alphabet:r,caseInsensitive:n=!1}){let{encode:s,decode:o}=di(r,t,n);return Nt({prefix:e,name:t,encode:s,decode:i=>Te(o(i))})}function Qc(t,e,r,n){let s=t.length;for(;t[s-1]==="=";)--s;let o=new Uint8Array(s*r/8|0),i=0,a=0,c=0;for(let f=0;f<s;++f){let u=e[t[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|u,i+=r,i>=8&&(i-=8,o[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return o}function ef(t,e,r){let n=e[e.length-1]==="=",s=(1<<r)-1,o="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,o+=e[s&a>>i];if(i!==0&&(o+=e[s&a<<r-i]),n)for(;(o.length*r&7)!==0;)o+="=";return o}function tf(t,e){let r={};for(let n=0;n<t.length;++n)if(r[t[n]]=n,e){let s=t[n].toLowerCase(),o=t[n].toUpperCase();s!==t[n]&&(r[s]=n),o!==t[n]&&(r[o]=n)}return r}function ae({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:s=!1}){let o=tf(n,s);return Nt({prefix:e,name:t,encode(i){return ef(i,n,r)},decode(i){return Qc(i,o,r,t)}})}var fe=tt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),rf=tt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var is={};Ae(is,{base32:()=>Mt,base32hex:()=>af,base32hexpad:()=>ff,base32hexpadupper:()=>uf,base32hexupper:()=>cf,base32pad:()=>sf,base32padupper:()=>of,base32upper:()=>nf,base32z:()=>hf});var Mt=ae({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),nf=ae({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),sf=ae({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),of=ae({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),af=ae({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),cf=ae({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),ff=ae({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),uf=ae({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),hf=ae({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var as={};Ae(as,{base36:()=>cr,base36upper:()=>lf});var cr=tt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),lf=tt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var df=gi,mi=128,pf=127,mf=~pf,yf=Math.pow(2,31);function gi(t,e,r){e=e||[],r=r||0;for(var n=r;t>=yf;)e[r++]=t&255|mi,t/=128;for(;t&mf;)e[r++]=t&255|mi,t>>>=7;return e[r]=t|0,gi.bytes=r-n+1,e}var gf=cs,bf=128,yi=127;function cs(t,n){var r=0,n=n||0,s=0,o=n,i,a=t.length;do{if(o>=a)throw cs.bytes=0,new RangeError("Could not decode varint");i=t[o++],r+=s<28?(i&yi)<<s:(i&yi)*Math.pow(2,s),s+=7}while(i>=bf);return cs.bytes=o-n,r}var wf=Math.pow(2,7),xf=Math.pow(2,14),Ef=Math.pow(2,21),Sf=Math.pow(2,28),Af=Math.pow(2,35),vf=Math.pow(2,42),Bf=Math.pow(2,49),Lf=Math.pow(2,56),If=Math.pow(2,63),Tf=function(t){return t<wf?1:t<xf?2:t<Ef?3:t<Sf?4:t<Af?5:t<vf?6:t<Bf?7:t<Lf?8:t<If?9:10},_f={encode:df,decode:gf,encodingLength:Tf},Rf=_f,fr=Rf;function ur(t,e=0){let r=fr.decode(t,e),n=fr.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&t[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function Ft(t,e,r=0){return fr.encode(t,e,r),e}function Ht(t){return fr.encodingLength(t)}function Ne(t,e){let r=e.byteLength,n=Ht(t),s=n+Ht(r),o=new Uint8Array(s+r);return Ft(t,o,0),Ft(r,o,n),o.set(e,s),new qt(t,r,e,o)}function fs(t){let e=Te(t),[r,n]=ur(e),[s,o]=ur(e.subarray(n)),i=e.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new qt(r,s,i,e)}function bi(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&fi(t.bytes,r.bytes)}}var qt=class{code;size;digest;bytes;constructor(e,r,n,s){this.code=e,this.size=r,this.digest=yt(n),this.bytes=yt(s)}};function wi(t,e){let{bytes:r,version:n}=t;return n===0?Df(r,us(t),e??fe.encoder):Of(r,us(t),e??Mt.encoder)}var xi=new WeakMap;function us(t){let e=xi.get(t);if(e==null){let r=new Map;return xi.set(t,r),r}return e}var ye=class t{code;version;multihash;bytes;"/";constructor(e,r,n,s){this.code=r,this.version=e,this.multihash=n,this.bytes=yt(s),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==hr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==kf)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=Ne(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&bi(e.multihash,n.multihash)}toString(e){return wi(this,e)}toJSON(){return{"/":wi(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:s,multihash:o,bytes:i}=r;return new t(n,s,o,i??Ei(n,s,o.bytes))}else if(r[Kf]===!0){let{version:n,multihash:s,code:o}=r,i=fs(s);return t.create(n,o,i)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==hr)throw new Error(`Version 0 CID must use dag-pb (code: ${hr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let s=Ei(e,r,n.bytes);return new t(e,r,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,hr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,s=Te(e.subarray(n,n+r.multihashSize));if(s.byteLength!==r.multihashSize)throw new Error("Incorrect length");let o=s.subarray(r.multihashSize-r.digestSize),i=new qt(r.multihashCode,r.digestSize,o,s);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[h,p]=ur(e.subarray(r));return r+=p,h},s=n(),o=hr;if(s===18?(s=0,r=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=r,a=n(),c=n(),f=r+c,u=f-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(e,r){let[n,s]=Cf(e,r),o=t.decode(s);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return us(o).set(n,e),o}};function Cf(t,e){switch(t[0]){case"Q":{let r=e??fe;return[fe.prefix,r.decode(`${fe.prefix}${t}`)]}case fe.prefix:{let r=e??fe;return[fe.prefix,r.decode(t)]}case Mt.prefix:{let r=e??Mt;return[Mt.prefix,r.decode(t)]}case cr.prefix:{let r=e??cr;return[cr.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function Df(t,e,r){let{prefix:n}=r;if(n!==fe.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let s=e.get(n);if(s==null){let o=r.encode(t).slice(1);return e.set(n,o),o}else return s}function Of(t,e,r){let{prefix:n}=r,s=e.get(n);if(s==null){let o=r.encode(t);return e.set(n,o),o}else return s}var hr=112,kf=18;function Ei(t,e,r){let n=Ht(t),s=n+Ht(e),o=new Uint8Array(s+r.byteLength);return Ft(t,o,0),Ft(e,o,n),o.set(r,s),o}var Kf=Symbol.for("@ipld/js-cid/CID");var hs={};Ae(hs,{identity:()=>Me});var Si=0,Uf="identity",Ai=Te;function Pf(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return Ne(Si,Ai(t))}var Me={code:Si,name:Uf,encode:Ai,digest:Pf};function xe(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Nf(t){return t.buffer instanceof ArrayBuffer}function Le(t){return Nf(t)?t:t.slice()}async function vi(t,e,r,n){let s=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let o=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},s,Le(e),Le(r.subarray()));return n?.signal?.throwIfAborted(),o}function he(t=0){return new Uint8Array(t)}function pe(t=0){return new Uint8Array(t)}function Mf(t){return t?.buffer instanceof ArrayBuffer}function ls(t){if(Mf(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function gt(t,e){e==null&&(e=t.reduce((s,o)=>s+o.length,0));let r=pe(e),n=0;for(let s of t)r.set(s,n),n+=s.length;return ls(r)}var Li=Symbol.for("@achingbrain/uint8arraylist");function Bi(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let s=r+n.byteLength;if(e<s)return{buf:n,index:e-r};r=s}throw new RangeError("index is out of bounds")}function Xr(t){return!!t?.[Li]}var G=class t{bufs;length;[Li]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Xr(n)){r+=n.byteLength;for(let s of n.bufs)this.bufs.push(s)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Xr(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(e){let r=Bi(this.bufs,e);return r.buf[r.index]}set(e,r){let n=Bi(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(Xr(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:s}=this._subList(e,r);return gt(n,s)}subarray(e,r){let{bufs:n,length:s}=this._subList(e,r);return n.length===1?n[0]:gt(n,s)}sublist(e,r){let{bufs:n,length:s}=this._subList(e,r),o=new t;return o.length=s,o.bufs=n,o}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],s=0;for(let o=0;o<this.bufs.length;o++){let i=this.bufs[o],a=s,c=a+i.byteLength;if(s=c,e>=c)continue;let f=e>=a&&e<c,u=r>a&&r<=c;if(f&&u){if(e===a&&r===c){n.push(i);break}let h=e-a;n.push(i.subarray(h,h+(r-e)));break}if(f){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(u){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!Xr(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let o=256,i=new Int32Array(o);for(let h=0;h<o;h++)i[h]=-1;for(let h=0;h<s;h++)i[n[h]]=h;let a=i,c=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let h=r;h<=c;h+=u){u=0;for(let p=f;p>=0;p--){let d=this.get(h+p);if(n[p]!==d){u=Math.max(1,p-a[d]);break}}if(u===0)return h}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=pe(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let s=he(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,r,n),this.write(s,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let s=he(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,r,n),this.write(s,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let s=he(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,r,n),this.write(s,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=pe(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let s=he(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,r,n),this.write(s,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let s=he(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,r,n),this.write(s,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let s=he(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,r,n),this.write(s,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let s=he(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,r,n),this.write(s,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let s=he(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,r,n),this.write(s,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!xe(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((s,o)=>s+o.byteLength,0)),n.length=r,n}};var ds={};Ae(ds,{base10:()=>Ff});var Ff=tt({prefix:"9",name:"base10",alphabet:"0123456789"});var ps={};Ae(ps,{base16:()=>Hf,base16upper:()=>qf});var Hf=ae({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),qf=ae({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var ms={};Ae(ms,{base2:()=>zf});var zf=ae({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ys={};Ae(ys,{base256emoji:()=>Wf});var Ii=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),jf=Ii.reduce((t,e,r)=>(t[r]=e,t),[]),Vf=Ii.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function $f(t){return t.reduce((e,r)=>(e+=jf[r],e),"")}function Yf(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let s=Vf[n];if(s==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(s)}return new Uint8Array(e)}var Wf=Nt({prefix:"\u{1F680}",name:"base256emoji",encode:$f,decode:Yf});var gs={};Ae(gs,{base64:()=>Gf,base64pad:()=>Zf,base64url:()=>Xf,base64urlpad:()=>Jf});var Gf=ae({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Zf=ae({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Xf=ae({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Jf=ae({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var bs={};Ae(bs,{base8:()=>Qf});var Qf=ae({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ws={};Ae(ws,{identity:()=>eu});var eu=Nt({prefix:"\0",name:"identity",encode:t=>hi(Te(t)),decode:t=>Te(ui(t))});var Od=new TextEncoder,kd=new TextDecoder;var Ss={};Ae(Ss,{sha256:()=>Jr,sha512:()=>su});var nu=20;function Es({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:s}){return new xs(t,e,r,n,s)}var xs=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,s,o){this.name=e,this.code=r,this.encode=n,this.minDigestLength=s??nu,this.maxDigestLength=o}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?Ti(n,this.code,r?.truncate):n.then(s=>Ti(s,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ti(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return Ne(e,t)}function Ri(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Jr=Es({name:"sha2-256",code:18,encode:Ri("SHA-256")}),su=Es({name:"sha2-512",code:19,encode:Ri("SHA-512")});var As={...ws,...ms,...bs,...ds,...ps,...is,...as,...os,...gs,...ys},$d={...Ss,...hs};function Di(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Ci=Di("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),vs=Di("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=pe(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),ou={utf8:Ci,"utf-8":Ci,hex:As.base16,latin1:vs,ascii:vs,binary:vs,...As},Qr=ou;function re(t,e="utf8"){let r=Qr[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function Z(t,e="utf8"){let r=Qr[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var iu=parseInt("11111",2),Bs=parseInt("10000000",2),au=parseInt("01111111",2),Oi={0:lr,1:lr,2:cu,3:hu,4:lu,5:uu,6:fu,16:lr,22:lr,48:lr};function $e(t,e={offset:0}){let r=t[e.offset]&iu;if(e.offset++,Oi[r]!=null)return Oi[r](t,e);throw new Error("No decoder for tag "+r)}function dr(t,e){let r=0;if((t[e.offset]&Bs)===Bs){let n=t[e.offset]&au,s="0x";e.offset++;for(let o=0;o<n;o++,e.offset++){if(e.offset>=t.byteLength)throw new Error("invalid DER element length");s+=t[e.offset].toString(16).padStart(2,"0")}r=parseInt(s,16)}else r=t[e.offset],e.offset++;if(!Number.isInteger(r)||r<0||r>t.byteLength-e.offset)throw new Error("invalid DER element length");return r}function lr(t,e){dr(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=$e(t,e);if(n===null)break;r.push(n)}return r}function cu(t,e){let r=dr(t,e),n=e.offset,s=e.offset+r,o=[];for(let i=n;i<s;i++)i===n&&t[i]===0||o.push(t[i]);return e.offset+=r,Uint8Array.from(o)}function fu(t,e){let r=dr(t,e),n=e.offset+r,s=t[e.offset];e.offset++;let o=0,i=0;s<40?(o=0,i=s):s<80?(o=1,i=s-40):(o=2,i=s-80);let a=`${o}.${i}`,c=[];for(;e.offset<n;){let f=t[e.offset];if(e.offset++,c.push(f&127),f<128){c.reverse();let u=0;for(let h=0;h<c.length;h++)u+=c[h]<<h*7;a+=`.${u}`,c=[]}}return a}function uu(t,e){return e.offset++,null}function hu(t,e){let r=dr(t,e),n=t[e.offset];e.offset++;let s=t.subarray(e.offset,e.offset+r-1);if(e.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return s}function lu(t,e){let r=dr(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function du(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new G;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function Ls(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=du(t.byteLength);return new G(Uint8Array.from([e.byteLength|Bs]),e)}function ve(t){let e=new G,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new G(Uint8Array.from([2]),Ls(e),e)}function en(t){let e=Uint8Array.from([0]),r=new G(e,t);return new G(Uint8Array.from([3]),Ls(r),r)}function rt(t,e=48){let r=new G;for(let n of t)r.append(n);return new G(Uint8Array.from([e]),Ls(r),r)}var pu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),mu=Uint8Array.from([6,5,43,129,4,0,34]),yu=Uint8Array.from([6,5,43,129,4,0,35]),gu={ext:!0,kty:"EC",crv:"P-256"},bu={ext:!0,kty:"EC",crv:"P-384"},wu={ext:!0,kty:"EC",crv:"P-521"},Is=32,Ts=48,_s=66;function ki(t){let e=$e(t);return Ki(e)}function Ki(t){let e=t[1][1][0],r=1,n,s;if(e.byteLength===Is*2+1)return n=Z(e.subarray(r,r+Is),"base64url"),s=Z(e.subarray(r+Is),"base64url"),new jt({...gu,key_ops:["verify"],x:n,y:s});if(e.byteLength===Ts*2+1)return n=Z(e.subarray(r,r+Ts),"base64url"),s=Z(e.subarray(r+Ts),"base64url"),new jt({...bu,key_ops:["verify"],x:n,y:s});if(e.byteLength===_s*2+1)return n=Z(e.subarray(r,r+_s),"base64url"),s=Z(e.subarray(r+_s),"base64url"),new jt({...wu,key_ops:["verify"],x:n,y:s});throw new ie(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Ui(t){return rt([ve(Uint8Array.from([1])),rt([xu(t.crv)],160),rt([en(new G(Uint8Array.from([4]),re(t.x??"","base64url"),re(t.y??"","base64url")))],161)]).subarray()}function xu(t){if(t==="P-256")return pu;if(t==="P-384")return mu;if(t==="P-521")return yu;throw new ie(`Invalid curve ${t}`)}var jt=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Ui(this.jwk)),this._raw}toMultihash(){return Me.digest(nt(this))}toCID(){return ye.createV1(114,this.toMultihash())}toString(){return fe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:xe(this.raw,e.raw)}async verify(e,r,n){return vi(this.jwk,r,e,n)}};var tn=BigInt(4294967295),Pi=BigInt(32);function Eu(t,e=!1){return e?{h:Number(t&tn),l:Number(t>>Pi&tn)}:{h:Number(t>>Pi&tn)|0,l:Number(t&tn)|0}}function Ni(t,e=!1){let r=t.length,n=new Uint32Array(r),s=new Uint32Array(r);for(let o=0;o<r;o++){let{h:i,l:a}=Eu(t[o],e);[n[o],s[o]]=[i,a]}return[n,s]}var Su=t=>t/2**32|0,Au=t=>t>>>0;function Mi(t,e,r,n){let s=Su(r),o=Au(r);t.setUint32(e,n?o:s,n),t.setUint32(e+4,n?s:o,n)}var Rs=(t,e,r)=>t>>>r,Cs=(t,e,r)=>t<<32-r|e>>>r,bt=(t,e,r)=>t>>>r|e<<32-r,wt=(t,e,r)=>t<<32-r|e>>>r,pr=(t,e,r)=>t<<64-r|e>>>r-32,mr=(t,e,r)=>t>>>r-32|e<<64-r;function Fe(t,e,r,n){let s=(e>>>0)+(n>>>0);return{h:t+r+(s/2**32|0)|0,l:s|0}}var Fi=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Hi=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,qi=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),zi=(t,e,r,n,s)=>e+r+n+s+(t/2**32|0)|0,ji=(t,e,r,n,s)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(s>>>0),Vi=(t,e,r,n,s,o)=>e+r+n+s+o+(t/2**32|0)|0;function rn(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var Ds=t=>t?`"${t}" `:"";function Oe(t,e=""){if(typeof t!="number")throw new TypeError(Ds(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(Ds(e)+"expected integer >= 0, got "+t);return t}function Ee(t,e,r=""){if(rn(t)&&(e===void 0||t.length===e))return t;e!==void 0&&Oe(e,"length");let n=rn(t),s=e!==void 0?` of length ${e}`:"",o=n?`length=${t.length}`:`type=${typeof t}`,i=Ds(r)+"expected Uint8Array"+s+", got "+o;throw n?new RangeError(i):new TypeError(i)}function xt(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(Oe(t.outputLen),Oe(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var Bu=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)},$i=(t,e)=>{Bu(t,e);let r=Object.getPrototypeOf(t);if(r!==Object.prototype&&r!==null)throw new TypeError(`"${e}" expected plain object`);if(Object.hasOwn(t,"__proto__"))throw new TypeError(`"${e}.__proto__" is not allowed`)};function Vt(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function nn(t,e){Ee(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function _e(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function sn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function ke(t,e){return t<<32-e|t>>>e}var Wi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Lu=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function on(t){if(Ee(t),Wi)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=Lu[t[r]];return e}function Yi(t){return t>=48&&t<=57?t-48:t>=65&&t<=70?t-55:t>=97&&t<=102?t-87:void 0}function an(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(Wi)try{return Uint8Array.fromHex(t)}catch(s){throw s instanceof SyntaxError?new RangeError(s.message):s}let e=t.length,r=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let s=0,o=0;s<r;s++,o+=2){let i=Yi(t.charCodeAt(o)),a=Yi(t.charCodeAt(o+1));if(i===void 0||a===void 0){let c=t[o]+t[o+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+o)}n[s]=i*16+a}return n}function Os(...t){let e=0;for(let n=0;n<t.length;n++){let s=t[n];Ee(s),e+=s.length}let r=new Uint8Array(e);for(let n=0,s=0;n<t.length;n++){let o=t[n];r.set(o,s),s+=o.length}return r}function Iu(t,e,r="opts"){return $i(t,"defaults"),e!==void 0&&$i(e,r),Object.assign(Object.create(null),t,e)}function ks(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=Iu({},e,"info");let r=(s,o)=>t(o).update(s).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=s=>t(s),Object.assign(r,e),Object.freeze(r)}function Gi(t=32){Oe(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var Ks=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Zi(t,e,r){return t&e^~t&r}function Xi(t,e,r){return t&e^t&r^e&r}var yr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,s){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(e),this.view=sn(this.buffer)}update(e){Vt(this),Ee(e);let{view:r,buffer:n,blockLen:s}=this,o=e.length,i=!1;for(let a=0;a<o;){let c=Math.min(s-this.pos,o-a);if(c===s){let f=sn(e);for(;s<=o-a;a+=s)this.process(f,a);i=!0;continue}n.set(a===0&&c===o?e:e.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===s&&(this.process(r,0),this.pos=0,i=!0)}return this.length+=e.length,i&&this.roundClean(),this}digestInto(e){Vt(this),nn(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:s,isLE:o}=this,{pos:i}=this;r[i++]=128,r.fill(0,i),this.padOffset>s-i&&(this.process(n,0),r.fill(0)),Mi(n,s-8,this.length*8,o),this.process(n,0),this.roundClean();let a=e===r?n:sn(e),c=this.outputLen,f=c/4,u=this.get();if(c%4||f>u.length)throw new Error("invalid outputLen");for(let h=0;h<f;h++)a.setUint32(4*h,u[h],o)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:r,length:n,finished:s,destroyed:o,pos:i}=this;return e.destroyed=o,e.finished=s,e.length=n,e.pos=i,i&&e.buffer.set(r),e}clone(){return this._cloneInto()}},Ji=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Qi=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Tu=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),st=new Uint32Array(64),Us=class extends yr{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(e,r){super(64,e,8,!1),this.A=r[0]|0,this.B=r[1]|0,this.C=r[2]|0,this.D=r[3]|0,this.E=r[4]|0,this.F=r[5]|0,this.G=r[6]|0,this.H=r[7]|0}get(){let{A:e,B:r,C:n,D:s,E:o,F:i,G:a,H:c}=this;return[e,r,n,s,o,i,a,c]}set(e,r,n,s,o,i,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let h=0;h<16;h++,r+=4)st[h]=e.getUint32(r,!1);for(let h=16;h<64;h++){let p=st[h-15],d=st[h-2],w=ke(p,7)^ke(p,18)^p>>>3,g=ke(d,17)^ke(d,19)^d>>>10;st[h]=g+st[h-7]+w+st[h-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:f,H:u}=this;for(let h=0;h<64;h++){let p=ke(a,6)^ke(a,11)^ke(a,25),d=u+p+Zi(a,c,f)+Tu[h]+st[h]|0,g=(ke(n,2)^ke(n,13)^ke(n,22))+Xi(n,s,o)|0;u=f,f=c,c=a,a=i+d|0,i=o,o=s,s=n,n=d+g|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,s,o,i,a,c,f,u)}roundClean(){_e(st)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),_e(this.buffer)}},Ps=class extends Us{constructor(){super(32,Ji)}};var ea=Ni(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),_u=ea[0],Ru=ea[1],ot=new Uint32Array(80),it=new Uint32Array(80),Ns=class extends yr{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(e,r){super(128,e,16,!1),this.Ah=r[0]|0,this.Al=r[1]|0,this.Bh=r[2]|0,this.Bl=r[3]|0,this.Ch=r[4]|0,this.Cl=r[5]|0,this.Dh=r[6]|0,this.Dl=r[7]|0,this.Eh=r[8]|0,this.El=r[9]|0,this.Fh=r[10]|0,this.Fl=r[11]|0,this.Gh=r[12]|0,this.Gl=r[13]|0,this.Hh=r[14]|0,this.Hl=r[15]|0}get(){let{Ah:e,Al:r,Bh:n,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:f,El:u,Fh:h,Fl:p,Gh:d,Gl:w,Hh:g,Hl:y}=this;return[e,r,n,s,o,i,a,c,f,u,h,p,d,w,g,y]}set(e,r,n,s,o,i,a,c,f,u,h,p,d,w,g,y){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=s|0,this.Ch=o|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=h|0,this.Fl=p|0,this.Gh=d|0,this.Gl=w|0,this.Hh=g|0,this.Hl=y|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let b=0;b<16;b++,r+=4)ot[b]=e.getUint32(r),it[b]=e.getUint32(r+=4);for(let b=16;b<80;b++){let R=ot[b-15]|0,T=it[b-15]|0,O=bt(R,T,1)^bt(R,T,8)^Rs(R,T,7),N=wt(R,T,1)^wt(R,T,8)^Cs(R,T,7),K=ot[b-2]|0,_=it[b-2]|0,C=bt(K,_,19)^pr(K,_,61)^Rs(K,_,6),F=wt(K,_,19)^mr(K,_,61)^Cs(K,_,6),M=qi(N,F,it[b-7],it[b-16]),j=zi(M,O,C,ot[b-7],ot[b-16]);ot[b]=j|0,it[b]=M|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:f,Dl:u,Eh:h,El:p,Fh:d,Fl:w,Gh:g,Gl:y,Hh:x,Hl:E}=this;for(let b=0;b<80;b++){let R=bt(h,p,14)^bt(h,p,18)^pr(h,p,41),T=wt(h,p,14)^wt(h,p,18)^mr(h,p,41),O=h&d^~h&g,N=p&w^~p&y,K=ji(E,T,N,Ru[b],it[b]),_=Vi(K,x,R,O,_u[b],ot[b]),C=K|0,F=bt(n,s,28)^pr(n,s,34)^pr(n,s,39),M=wt(n,s,28)^mr(n,s,34)^mr(n,s,39),j=n&o^n&a^o&a,B=s&i^s&c^i&c;x=g|0,E=y|0,g=d|0,y=w|0,d=h|0,w=p|0,{h,l:p}=Fe(f|0,u|0,_|0,C|0),f=a|0,u=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let k=Fi(C,M,B);n=Hi(k,_,F,j),s=k|0}({h:n,l:s}=Fe(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=Fe(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=Fe(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=Fe(this.Dh|0,this.Dl|0,f|0,u|0),{h,l:p}=Fe(this.Eh|0,this.El|0,h|0,p|0),{h:d,l:w}=Fe(this.Fh|0,this.Fl|0,d|0,w|0),{h:g,l:y}=Fe(this.Gh|0,this.Gl|0,g|0,y|0),{h:x,l:E}=Fe(this.Hh|0,this.Hl|0,x|0,E|0),this.set(n,s,o,i,a,c,f,u,h,p,d,w,g,y,x,E)}roundClean(){_e(ot,it)}destroy(){this.destroyed=!0,_e(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Ms=class extends Ns{constructor(){super(64,Qi)}};var He=ks(()=>new Ps,Ks(1));var Fs=ks(()=>new Ms,Ks(3));function fn(t,e,r=()=>{}){if(!Array.isArray(t))throw new TypeError(`"${e}" expected array, got type=${typeof t}`);for(let n=0;n<t.length;n++)r(t[n],`${e}[${n}]`);return t}var Y=(t,e,r)=>Ee(t,e,r),Hs=Oe;function ra(t,e=""){if(typeof t!="string"){let r=e&&`"${e}" `;throw new TypeError(r+"expected string, got type="+typeof t)}return t}function at(t,e="object"){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof t}`);return t}function Et(t,e){if(typeof t!="function")throw new TypeError(`"${e}" is invalid: expected function, got ${typeof t}`);return t}var gr=on,Re=(...t)=>Os(...t),$t=t=>an(t),ft=rn,Ye=t=>Gi(t),cn=BigInt(0),ta=BigInt(1),Cu=t=>t?`"${t}" `:"";function Be(t,e=""){if(typeof t!="boolean")throw new TypeError(Cu(e)+"expected boolean, got type="+typeof t);return t}function un(t){if(typeof t=="bigint"){if(!ct(t))throw new RangeError("positive bigint expected, got "+t)}else Hs(t);return t}function We(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(r+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new RangeError(r+"expected safe integer, got "+t)}}function br(t){let e=un(t).toString(16);return e.length&1?"0"+e:e}function na(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?cn:BigInt("0x"+t)}function qe(t){return na(on(t))}function ze(t){return na(on(ut(Ee(t)).reverse()))}function hn(t,e){if(Oe(e),e===0)throw new Error("zero output length is invalid");t=un(t);let r=e*2,n=t.toString(16);if(n.length>r)throw new RangeError("number is too large");return an(n.padStart(r,"0"))}function wr(t,e){return hn(t,e).reverse()}function ut(t){return Uint8Array.from(Y(t))}function ct(t){return typeof t=="bigint"&&cn<=t}function qs(t,e,r){return ct(t)&&ct(e)&&ct(r)&&e<=t&&t<r}function je(t,e,r,n){if(!qs(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Yt(t){if(t<cn)throw new Error("expected non-negative bigint, got "+t);return t===cn?0:t.toString(2).length}var xr=t=>(We(t,"n"),(ta<<BigInt(t))-ta);function sa(t,e,r){if(Oe(t,"hashLen"),Oe(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=y=>new Uint8Array(y),s=Uint8Array.of(),o=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(t),f=n(t),u=0,h=()=>{c.fill(1),f.fill(0),u=0},p=(...y)=>r(f,Re(c,...y)),d=(y=s)=>{f=p(o,y),c=p(),y.length!==0&&(f=p(i,y),c=p())},w=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let y=0,x=[];for(;y<e;){c=p();let E=c.slice();x.push(E),y+=c.length}return Re(...x)};return(y,x)=>{h(),d(y);let E;for(;(E=x(w()))===void 0;)d();return h(),E}}function ge(t,e={},r={},n="object"){at(t,n),at(e,"fields"),at(r,"optFields");function s(i,a,c){let f=n==="object"?`param "${String(i)}"`:`"${n}.${String(i)}"`,u=t[i];if(!Object.hasOwn(t,i)&&(c?u!==void 0:a!=="function"))throw new TypeError(`${f} is invalid: expected own property`);if(c&&u===void 0)return;let h=typeof u;if(h!==a||u===null)throw new TypeError(`${f} is invalid: expected ${a}, got ${h}`)}let o=(i,a)=>Object.entries(i).forEach(([c,f])=>s(c,f,a));o(e,!1),o(r,!0)}var de=BigInt(0),X=BigInt(1),ht=BigInt(2),aa=BigInt(3),zs=BigInt(4),ca=BigInt(5),Du=BigInt(7),fa=BigInt(8),Ou=BigInt(9),ku=BigInt(15),ua=BigInt(16),Ku=BigInt("0x10000000000000000");function Q(t,e){if(e<=de)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=de?r:e+r}function ha(t,e,r){if(r<=X)throw new Error("pow: expected modulus > 1, got "+r);if(typeof e!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof e);if(e<de)throw new Error("invalid exponent, negatives unsupported");if(e===de)return X;if(e===X)return t;let n=t%r;if(n<de&&(n+=r),e<Ku){let a=X;for(;e>de;)e&X&&(a=a*n%r),n=n*n%r,e>>=X;return a}let s=[];for(;e>de;)s.push(Number(e&ku)),e>>=zs;let o=new Array(16);o[0]=X,o[1]=n;for(let a=2;a<16;a++)o[a]=o[a-1]*n%r;let i=o[s[s.length-1]];for(let a=s.length-2;a>=0;a--){i=i*i%r,i=i*i%r,i=i*i%r,i=i*i%r;let c=s[a];c!==0&&(i=i*o[c]%r)}return i}function se(t,e,r){if(r<=X)throw new Error("pow2: expected modulus > 1, got "+r);if(e<de)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >de;)n*=n,n%=r;return n}function oa(t,e){if(t===de)throw new Error("invert: expected non-zero number");if(e<=X)throw new Error("invert: expected modulus > 1, got "+e);let r=Q(t,e),n=e,s=de,o=X;for(;r!==de;){let a=n/r,c=n-r*a,f=s-o*a;n=r,r=c,s=o,o=f}if(n!==X)throw new Error("invert: does not exist");return Q(s,e)}function la(t,e){if(e<=X)throw new Error("invertCt: expected prime modulus > 1, got "+e);let r=Q(t,e);if(r===de)throw new Error("invertCt: expected non-zero number");let n=ha(r,e-ht,e);if(Q(r*n,e)!==X)throw new Error("invertCt: does not exist");return n}function js(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function Vs(t,e){if((t&X)===de)throw new Error(e+": expected odd modulus, got "+t)}function da(t,e){let r=t,n=(r.ORDER+X)/zs,s=r.pow(e,n);return js(r,s,e),s}function Uu(t,e){let r=t,n=(r.ORDER-ca)/fa,s=r.mul(e,ht),o=r.pow(s,n),i=r.mul(e,o),a=r.mul(r.mul(i,ht),o),c=r.mul(i,r.sub(a,r.ONE));return js(r,c,e),c}function Pu(t){let e=Gt(t),r=pa(t),n=r(e,e.neg(e.ONE)),s=r(e,n),o=r(e,e.neg(n)),i=(t+Du)/ua;return((a,c)=>{let f=a,u=f.pow(c,i),h=f.mul(u,n),p=f.mul(u,s),d=f.mul(u,o),w=f.eql(f.sqr(h),c),g=f.eql(f.sqr(p),c);u=f.cmov(u,h,w),h=f.cmov(d,p,g);let y=f.eql(f.sqr(h),c),x=f.cmov(u,h,y);return js(f,x,c),x})}function pa(t){if(t<aa)throw new Error("sqrt is not defined for small field");Vs(t,"tonelliShanks");let e=t-X,r=0;for(;e%ht===de;)e/=ht,r++;let n=ht,s=Gt(t);for(;Er(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return da;let o=s.pow(n,e),i=(e+X)/ht;return function(c,f){let u=c;if(u.is0(f))return f;if(Er(u,f)!==1)throw new Error("Cannot find square root");let h=r,p=u.mul(u.ONE,o),d=u.pow(f,e),w=u.pow(f,i);for(;!u.eql(d,u.ONE);){if(u.is0(d))throw new Error("Cannot find square root: probably non-prime P");let g=1,y=u.sqr(d);for(;!u.eql(y,u.ONE);)if(g++,y=u.sqr(y),g===h)throw new Error("Cannot find square root");let x=X<<BigInt(h-g-1),E=u.pow(p,x);h=g,p=u.sqr(E),d=u.mul(d,p),w=u.mul(w,E)}return w}}function Nu(t){return Vs(t,"Fp.sqrt"),t%zs===aa?da:t%fa===ca?Uu:t%ua===Ou?Pu(t):pa(t)}var ma=(t,e)=>(Q(t,e)&X)===X,Mu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Wt(t){if(at(t,"field"),typeof t.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof t.ORDER);We(t.BYTES,"BYTES"),We(t.BITS,"BITS");for(let e of Mu)Et(t[e],"field."+e);if(t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=X)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function dn(t,e,r=!1){Wt(t),fn(e,"nums"),Be(r,"passZero");let n=t,s=new Array(e.length).fill(r?n.ZERO:void 0),o=e.reduce((a,c,f)=>n.is0(c)?a:(s[f]=a,n.mul(a,c)),n.ONE),i=n.inv(o);return e.reduceRight((a,c,f)=>n.is0(c)?a:(s[f]=n.mul(a,s[f]),n.mul(a,c)),i),s}function Er(t,e){Wt(t);let r=t;Vs(r.ORDER,"FpLegendre");let n=(r.ORDER-X)/ht,s=r.pow(e,n),o=r.eql(s,r.ONE),i=r.eql(s,r.ZERO),a=r.eql(s,r.neg(r.ONE));if(!o&&!i&&!a)throw new Error("invalid Legendre symbol result");return o?1:i?0:-1}function Fu(t,e){if(e!==void 0&&Hs(e),t<=de)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=Yt(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected nBitLength (${e}) >= bitLen(n) (${r})`);let n=e!==void 0?e:r,s=Math.ceil(n/8);return{nBitLength:n,nByteLength:s}}var ia=new WeakMap,ln=class{ORDER;BITS;BYTES;isLE;ZERO=de;ONE=X;_lengths;_mod;constructor(e,r={}){if(e<=X)throw new Error("invalid field: expected ORDER > 1, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:s,nByteLength:o}=Fu(e,n);if(o>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=s,this.BYTES=o,Object.freeze(this)}create(e){return Q(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return de<=e&&e<this.ORDER}is0(e){return e===de}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&X)===X}neg(e){return Q(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return Q(e*e,this.ORDER)}add(e,r){return Q(e+r,this.ORDER)}sub(e,r){return Q(e-r,this.ORDER)}mul(e,r){return Q(e*r,this.ORDER)}pow(e,r){return ha(e,r,this.ORDER)}div(e,r){return Q(e*oa(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return oa(e,this.ORDER)}sqrt(e){let r=ia.get(this);return r||ia.set(this,r=Nu(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?wr(e,this.BYTES):hn(e,this.BYTES)}fromBytes(e,r=!1){Y(e);let{_lengths:n,BYTES:s,isLE:o,ORDER:i,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>s)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let f=new Uint8Array(s);f.set(e,o?0:f.length-e.length),e=f}if(e.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+e.length);let c=o?ze(e):qe(e);if(a&&(c=Q(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return dn(this,e,!0)}cmov(e,r,n){return Be(n,"condition"),n?r:e}};function Gt(t,e={}){return Object.freeze(ln.prototype),new ln(t,e)}function ya(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=X)throw new Error("field order must be greater than 1");let e=Yt(t-X);return Math.ceil(e/8)}function pn(t){let e=ya(t);return e+Math.ceil(e/2)}function mn(t,e,r=!1){Y(t);let n=t.length,s=ya(e),o=Math.max(pn(e),16);if(n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);let i=r?ze(t):qe(t),a=Q(i,e-X)+X;return r?wr(a,s):hn(a,s)}var Ws=BigInt(0),Sr=BigInt(1),Hu=BigInt(4),$s=16,ga=128,qu=5,ba=2**31;function lt(t){let e=t;if(typeof e!="function")throw new TypeError('"Point" expected constructor, got type='+typeof t);Et(e.fromAffine,"Point.fromAffine"),Et(e.fromBytes,"Point.fromBytes"),Et(e.fromHex,"Point.fromHex"),at(e.BASE,"Point.BASE"),at(e.ZERO,"Point.ZERO"),Wt(e.Fp),Wt(e.Fn)}function yn(t,e){lt(t),xa(e,t);let r=dn(t.Fp,e.map(n=>n.Z));return e.map((n,s)=>t.fromAffine(n.toAffine(r[s])))}function zu(t,e,r=1){if(!Number.isSafeInteger(t)||t<r||t>e)throw new Error("invalid window size, expected ["+r+".."+e+"], got W="+t)}function ju(t,e){let r=t*(4*e+128);if(r>ba)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+ba/2**20+" MiB")}function Gs(t,e){if(t!==void 0){Et(t,"randomBytes");try{let r=t(e);if(!ft(r)||r.length!==e)return}catch{return}return t}}function xa(t,e){fn(t,"points"),t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function Vu(t,e,r){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,s)=>{if(!(r===void 0?e.isValid(n):ct(n)&&n<r))throw new Error("invalid scalar at index "+s)})}var Ea=new WeakMap;function Ys(t){return Ea.get(t)||1}function $u(t,e){let r=t.double(),n=[t];for(let s=1;s<e;s++)n.push(n[s-1].add(r));return n}function Yu(t,e){let r=2**e,n=r/2,s=BigInt(r-1),o=[];for(;t>Ws;){let i=0;t&Sr&&(i=Number(t&s),i>=n&&(i-=r),t-=BigInt(i)),o.push(i),t>>=Sr}return o}function Wu(t,e,r){let n=2**e,s=n/2,o=BigInt(n-1),i=BigInt(e),a=[];for(let c=0;c<r;c++){let f=Number(t&o);t>>=i,f>s&&(f-=n,t+=Sr),a.push(f)}if(t!==Ws)throw new Error("invalid wnaf");return a}function Gu(t,e,r){let n=0;for(let o of r)n=Math.max(n,o.length);let s=t;for(let o=n-1;o>=0;o--){o!==n-1&&(s=s.double());for(let i=0;i<r.length;i++){let a=r[i][o];if(a){let c=e[i][Math.abs(a)-1>>1];s=s.add(a<0?c.negate():c)}}}return s}var Zt=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(e,r){lt(e),this.randomBytes=Gs(r,$s),this.Point=e,this.BASE=e.BASE,this.ZERO=e.ZERO,this.bits=e.Fn.BITS}buildWnafTable(e,r,n){let s=Math.ceil(n/r)+1,o=2**(r-1),i=[],a=e;for(let c=0;c<s;c++){let f=a;for(let u=0;u<o;u++)i.push(f),f=f.add(a);a=i[i.length-1].double()}return{W:r,bits:n,windows:s,comp:i}}wnafCachedCT(e,r){let{W:n,windows:s,comp:o}=e,i=2**(n-1),a=Wu(r,n,s),c=this.ZERO,f=this.BASE;for(let u=0;u<s;u++){let h=a[u],p=u*i,d=Math.abs(h)-1,w=o[p];for(let y=1;y<i;y++)w=y===d?o[p+y]:w;let g=w.negate();h===0?f=f.add(o[p]):c=c.add(h<0?g:w)}return{p:c,f}}getWnafPrecomputes(e,r,n,s){let o=this.wnafPrecomputes.get(r),i=o?.find(a=>a.W===e&&a.bits===n);return i||(i=this.buildWnafTable(r,e,n),typeof s=="function"&&(i={...i,comp:s(i.comp)}),o||(o=[],this.wnafPrecomputes.set(r,o)),o.push(i)),i}assertPoint(e){if(!(e instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof e)}validateMulInput(e,r){if(this.assertPoint(e),!qs(r,Sr,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(e,r,n,s){let o=Ys(e);return o===1?this.fixedWindowCT(e,r,n):this.wnafCachedCT(this.getWnafPrecomputes(o,e,n,s),r)}mulCT(e,r,n){return this.validateMulInput(e,r),this.runCT(e,r,this.bits,n)}mulCTBlinded(e,r,n){if(this.validateMulInput(e,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let s=this.Point.Fn.BITS+ga,o=this.randomBytes($s);if(!ft(o)||o.length!==$s)throw new Error("randomBytes returned invalid byte array");o[0]=o[0]&63|128;let i=r+qe(o)*this.Point.Fn.ORDER;return this.runCT(e,i,s,n)}fixedWindowCT(e,r,n){let s=qu,o=1<<s,i=xr(s),a=new Array(o);a[0]=this.ZERO;for(let u=1;u<o;u++)a[u]=a[u-1].add(e);let c=Math.ceil(n/s),f=this.ZERO;for(let u=c-1;u>=0;u--){if(u!==c-1)for(let d=0;d<s;d++)f=f.double();let h=Number(r>>BigInt(u*s)&i),p=a[0];for(let d=1;d<o;d++)p=d===h?a[d]:p;f=f.add(p)}return{p:f,f}}shouldBlind(e,r){return this.randomBytes===void 0?!1:r===Sr?!0:e!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(e,r,n,s){return this.shouldBlind(e,n)?this.mulCTBlinded(e,r,s):this.mulCT(e,r,s)}mulUnsafe(e,r,n){if(this.assertPoint(e),!ct(r))throw new Error("invalid scalar");let s=Ys(e);if(s===1||r>=this.Point.Fn.ORDER)return gn(this.Point,[e],[r],!0);let o=this.getWnafPrecomputes(s,e,this.bits,n);return this.wnafCachedCT(o,r).p}setWindowSize(e,r){this.assertPoint(e),zu(r,this.bits);let n=Math.ceil((this.bits+ga)/r)+1;ju(n*2**(r-1),this.Point.Fp.BYTES),Ea.set(e,r),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return Ys(e)!==1}};function gn(t,e,r,n=!1){if(lt(t),xa(e,t),Be(n,"allowOversized"),Vu(r,t.Fn,n?t.Fn.ORDER**Hu:void 0),e.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let s=e.map(i=>$u(i,4)),o=r.map(i=>Yu(i,4));return Gu(t.ZERO,s,o)}function wa(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Wt(e),e}else return Gt(t,{isLE:r})}function bn(t,e,r={},n){if(t!=="weierstrass"&&t!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);ge(r);for(let c of["p","n","h"]){let f=e[c];if(!(ct(f)&&f!==Ws))throw new Error(`CURVE.${c} must be positive bigint`)}let s=wa(e.p,r.Fp,n),o=wa(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!s.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:s,Fn:o}}function Xt(t,e){return function(n){let s=t(n);return{secretKey:s,publicKey:e(s)}}}var wn=BigInt(0),xn=BigInt(1),En=BigInt(2),Zu=BigInt(4),Sa=BigInt(8);function Xu(t,e,r,n){let s=t.sqr(r),o=t.sqr(n),i=t.add(t.mul(e.a,s),o),a=t.add(t.ONE,t.mul(e.d,t.mul(s,o)));return t.eql(i,a)}function Aa(t,e={}){ge(e,{},{},"extraOpts");let r=e,n=bn("edwards",t,r,r.FpFnLE),{Fp:s,Fn:o}=n,i=n.CURVE,{h:a}=i;if(Er(s,i.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(Er(s,i.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");ge(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?Ye:r.randomBytes,f=En<<BigInt(s.BYTES*8)-xn;function u(E){if(!s.isOdd)throw new Error("Field does not have .isOdd()");return s.isOdd(E)}let h=r.uvRatio===void 0?(E,b)=>{try{return{isValid:!0,value:s.sqrt(s.div(E,b))}}catch{return{isValid:!1,value:wn}}}:r.uvRatio;if(!Xu(s,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");let p=s.eql(i.a,s.neg(s.ONE))?E=>s.neg(E):s.eql(i.a,s.ONE)?E=>E:E=>s.mul(i.a,E);function d(E,b,R=!1){let T=R?xn:wn;return je("coordinate "+E,b,T,f),b}function w(E){if(!(E instanceof g))throw new Error("EdwardsPoint expected")}class g{static BASE=new g(i.Gx,i.Gy,s.ONE,s.mul(i.Gx,i.Gy));static ZERO=new g(s.ZERO,s.ONE,s.ONE,s.ZERO);static Fp=s;static Fn=o;X;Y;Z;T;constructor(b,R,T,O){this.X=d("x",b),this.Y=d("y",R),this.Z=d("z",T,!0),this.T=d("t",O),Object.freeze(this)}static CURVE(){return i}static fromAffine(b){if(b instanceof g)throw new Error("extended point not allowed");let{x:R,y:T}=b||{};return d("x",R),d("y",T),new g(R,T,s.ONE,s.mul(R,T))}static fromBytes(b,R=!1){let T=s.BYTES,{a:O,d:N}=i;b=ut(Y(b,T,"point")),Be(R,"zip215");let K=ut(b),_=b[T-1];K[T-1]=_&-129;let C=ze(K),F=R?f:s.ORDER;je("point.y",C,wn,F);let M=s.sqr(C),j=s.sub(M,s.ONE),B=s.sub(s.mulN(N,M),O),{isValid:k,value:L}=h(j,B);if(!k)throw new Error("bad point: invalid y coordinate");let v=u(L),H=(_&128)!==0;if(!R&&s.is0(L)&&H)throw new Error("bad point: x=0 and x_0=1");return H!==v&&(L=s.neg(L)),g.fromAffine({x:L,y:C})}static fromHex(b,R=!1){return g.fromBytes($t(b),R)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=6,R=!0){return x.setWindowSize(this,b),R||this.multiply(En),this}assertValidity(){let b=this,{a:R,d:T}=i;if(b.is0())throw new Error("bad point: ZERO");let{X:O,Y:N,Z:K,T:_}=b,C=s.sqr(O),F=s.sqr(N),M=s.sqr(K),j=s.sqr(M),B=s.mul(C,R),k=s.mul(s.add(B,F),M),L=s.add(j,s.mul(T,s.mul(C,F)));if(!s.eql(k,L))throw new Error("bad point: equation left != right (1)");let v=s.mul(O,N),H=s.mul(K,_);if(!s.eql(v,H))throw new Error("bad point: equation left != right (2)")}equals(b){w(b);let{X:R,Y:T,Z:O}=this,{X:N,Y:K,Z:_}=b,C=s.mul(R,_),F=s.mul(N,O),M=s.mul(T,_),j=s.mul(K,O);return s.eql(C,F)&&s.eql(M,j)}is0(){return this.equals(g.ZERO)}negate(){return new g(s.neg(this.X),this.Y,this.Z,s.neg(this.T))}double(){let{X:b,Y:R,Z:T}=this,O=s.sqr(b),N=s.sqr(R),K=s.mul(s.sqr(T),En),_=p(O),C=s.addN(b,R),F=s.sub(s.subN(s.sqr(C),O),N),M=s.addN(_,N),j=s.subN(M,K),B=s.subN(_,N),k=s.mul(F,j),L=s.mul(M,B),v=s.mul(F,B),H=s.mul(j,M);return new g(k,L,H,v)}add(b){w(b);let{d:R}=i,{X:T,Y:O,Z:N,T:K}=this,{X:_,Y:C,Z:F,T:M}=b,j=s.mul(T,_),B=s.mul(O,C),k=s.mul(s.mulN(K,R),M),L=s.mul(N,F),v=s.sub(s.subN(s.mulN(s.addN(T,O),s.addN(_,C)),j),B),H=s.subN(L,k),I=s.addN(L,k),S=s.sub(B,p(j)),l=s.mul(v,H),m=s.mul(I,S),A=s.mul(v,S),D=s.mul(H,I);return new g(l,m,D,A)}subtract(b){return w(b),this.add(b.negate())}multiply(b){if(!o.isValidNot0(b))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:R,f:T}=x.mulSecret(this,b,a,y);return y([R,T])[0]}multiplyUnsafe(b){if(!o.isValid(b))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return b===wn?g.ZERO:this.is0()||b===xn?this:x.mulUnsafe(this,b,y)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return x.mulUnsafe(this,i.n).is0()}toAffine(b){let R=this,T=b;if(T!=null&&typeof T!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof T);let{X:O,Y:N,Z:K}=R,_=R.is0();T==null&&(T=_?s.create(Sa):s.inv(K));let C=s.mul(O,T),F=s.mul(N,T),M=s.mul(K,T);if(_)return{x:s.ZERO,y:s.ONE};if(!s.eql(M,s.ONE))throw new Error("invZ was invalid");return{x:C,y:F}}clearCofactor(){return a===xn?this:a===En?this.double():a===Zu?this.double().double():a===Sa?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:b,y:R}=this.toAffine(),T=s.toBytes(R);return T[T.length-1]|=u(b)?128:0,T}toHex(){return gr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let y=E=>yn(g,E),x=new Zt(g,c);return x.bits>=6&&g.BASE.precompute(6),Object.freeze(g.prototype),Object.freeze(g),g}function va(t,e,r={}){if(lt(t),typeof e!="function")throw new Error('"hash" function param is required');let n=e,s=r;ge(s,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:o}=s,{BASE:i,Fp:a,Fn:c}=t,f=n.outputLen,u=2*a.BYTES;if(f!==void 0&&(We(f,"hash.outputLen"),f!==u))throw new Error(`hash.outputLen must be ${u}, got ${f}`);let h=s.randomBytes===void 0?Ye:s.randomBytes,p=s.toMontgomery,d=s.toMontgomerySecret,w=s.adjustScalarBytes===void 0?B=>B:s.adjustScalarBytes,g=s.domain===void 0?(B,k,L)=>{if(Be(L,"phflag"),k.length||L)throw new Error("Contexts/pre-hash are not supported");return B}:s.domain;function y(B){return c.create(ze(B))}function x(B){let k=_.secretKey;Y(B,_.secretKey,"secretKey");let L=Y(n(B),2*k,"hashedSecretKey"),v=w(L.slice(0,k)),H=L.slice(k,2*k),I=y(v);return{head:v,prefix:H,scalar:I}}function E(B){let{head:k,prefix:L,scalar:v}=x(B),H=i.multiply(v),I=H.toBytes();return{head:k,prefix:L,scalar:v,point:H,pointBytes:I}}function b(B){return E(B).pointBytes}function R(B=Uint8Array.of(),...k){let L=Re(...k);return y(n(g(L,Y(B,void 0,"context"),!!o)))}function T(B,k,L={}){ge(L,{},{},"options"),B=ut(Y(B,void 0,"message")),o&&(B=o(B));let{prefix:v,scalar:H,pointBytes:I}=E(k),S=R(L.context,v,B),l=i.multiply(S).toBytes(),m=R(L.context,l,I,B),A=c.create(S+m*H);if(!c.isValid(A))throw new Error("sign failed: invalid s");let D=Re(l,c.toBytes(A));return Y(D,_.signature,"result")}let O={zip215:s.zip215};function N(B,k,L,v=O){ge(v);let{context:H}=v,I=v.zip215===void 0?!!O.zip215:v.zip215,S=_.signature;B=Y(B,S,"signature"),k=Y(k,void 0,"message"),L=Y(L,_.publicKey,"publicKey"),I!==void 0&&Be(I,"zip215"),o&&(k=o(k));let l=S/2,m=B.subarray(0,l),A=ze(B.subarray(l,S)),D,U,P;try{D=t.fromBytes(L,I),U=t.fromBytes(m,I),P=i.multiplyUnsafe(A)}catch{return!1}if(!I&&D.isSmallOrder())return!1;let q=R(H,m,L,k);return U.add(D.multiplyUnsafe(q)).subtract(P).clearCofactor().is0()}let K=a.BYTES,_={secretKey:K,publicKey:K,signature:2*K,seed:K};function C(B){return B=B===void 0?h(_.seed):B,Y(B,_.seed,"seed")}function F(B){return ft(B)&&B.length===_.secretKey}function M(B,k){try{return!!t.fromBytes(B,k===void 0?O.zip215:k)}catch{return!1}}let j={getExtendedPublicKey:E,randomSecretKey:C,isValidSecretKey:F,isValidPublicKey:M,toMontgomery(B){if(p===void 0)throw new Error("Montgomery conversion is not supported for this curve");return p(t.fromBytes(B))},toMontgomerySecret(B){if(d===void 0)throw new Error("Montgomery conversion is not supported for this curve");return d(B)}};return Object.freeze(_),Object.freeze(j),Object.freeze({keygen:Xt(C,b),getPublicKey:b,sign:T,verify:N,utils:j,Point:t,lengths:_})}var St=BigInt(0),Ce=BigInt(1),Sn=BigInt(2);function Ba(t,e){return t+e-(e>>Ce<<Ce)}function Ju(t){let e=BigInt(6)*t;return(r,n,s)=>{let o=n+s,a=((e+s-n)*r+n)%t;return{x_2:a,x_3:o-a}}}function Qu(t){return ge(t,{P:"bigint",type:"string",adjustScalarBytes:"function",powPminus2:"function"},{randomBytes:"function",scalarMultBase:"function"}),Object.freeze({...t})}function La(t){let e=Qu(t),{P:r,type:n,adjustScalarBytes:s,powPminus2:o,randomBytes:i}=e,a=e.scalarMultBase,c=n==="x25519";if(!c&&n!=="x448")throw new Error("invalid type");let f=i===void 0?Ye:i,u=c?255:448,h=Ju(r),p=c?32:56,d=BigInt(c?9:5),w=BigInt(c?121665:39081),g=c?Sn**BigInt(254):Sn**BigInt(447),y=c?BigInt(8)*(Sn**BigInt(251)-Ce):BigInt(4)*(Sn**BigInt(445)-Ce),x=g+y+Ce,E=L=>Q(L,r),b=R(d);function R(L){return wr(E(L),p)}function T(L){let v=ut(Y(L,p,"uCoordinate"));return c&&(v[31]&=127),E(ze(v))}function O(L){return ze(s(ut(Y(L,p,"scalar"))))}let N=new Set(c?[St,Ce,r-Ce,BigInt("325606250916557431795983626356110631294008115727848805560023387167927233504"),BigInt("39382357235489614581723060781553021112529911719440698176882885853963445705823")]:[St,Ce,r-Ce]);function K(L,v){let H=T(v);if(N.has(H))throw new Error("invalid private or public key received");let I=M(H,O(L));if(I===St)throw new Error("invalid private or public key received");return R(I)}function _(L){if(a===void 0)return K(L,b);let v=O(L);je("scalar",v,g,x);let H=E(a(v));if(H===St)throw new Error("invalid private or public key received");return R(H)}let C=_,F=K;function M(L,v){je("u",L,St,r),je("scalar",v,g,x);let H=v,I=L,S=Ce,l=St,m=L,A=Ce,D=H^H>>Ce;for(let q=BigInt(u-1);q>=St;q--){let z=Ba(r,D>>q);({x_2:S,x_3:m}=h(z,S,m)),{x_2:l,x_3:A}=h(z,l,A);let V=S+l,$=E(V*V),ne=S-l,ee=E(ne*ne),ce=$-ee,Se=m+A,te=m-A,oe=E(te*V),kt=E(Se*ne),ar=oe+kt,Qe=oe-kt;m=E(ar*ar),A=E(I*E(Qe*Qe)),S=E($*ee),l=E(ce*($+E(w*ce)))}let U=Ba(r,H);({x_2:S,x_3:m}=h(U,S,m)),{x_2:l,x_3:A}=h(U,l,A);let P=o(l);return E(S*P)}let j={secretKey:p,publicKey:p,seed:p},B=L=>(L=L===void 0?f(p):L,Y(L,j.seed,"seed"),L),k={randomSecretKey:B};return Object.freeze(j),Object.freeze(k),Object.freeze({keygen:Xt(B,C),getSharedSecret:F,getPublicKey:C,scalarMult:K,scalarMultBase:_,utils:k,GuBytes:b.slice(),lengths:j})}var Ia=BigInt(0),Zs=BigInt(1),Ta=BigInt(2),eh=BigInt(3),th=BigInt(5),rh=BigInt(8),An=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),nh={p:An,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:rh,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Ca(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),s=BigInt(80),o=An,a=t*t%o*t%o,c=se(a,Ta,o)*a%o,f=se(c,Zs,o)*t%o,u=se(f,th,o)*f%o,h=se(u,e,o)*u%o,p=se(h,r,o)*h%o,d=se(p,n,o)*p%o,w=se(d,s,o)*d%o,g=se(w,s,o)*d%o,y=se(g,e,o)*u%o;return{pow_p_5_8:se(y,Ta,o)*t%o,b2:a}}function Xs(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var _a=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function sh(t,e){let r=An,n=Q(e*e*e,r),s=Q(n*n*e,r),o=Ca(t*s).pow_p_5_8,i=Q(t*n*o,r),a=Q(e*i*i,r),c=i,f=Q(i*_a,r),u=a===t,h=a===Q(-t,r),p=a===Q(-t*_a,r);return u&&(i=c),(h||p)&&(i=f),ma(i,r)&&(i=Q(-i,r)),{isValid:u||h,value:i}}var Ar=Aa(nh,{uvRatio:sh}),Ra=Ar.Fp;function oh(t){let{y:e}=t;return Ra.toBytes(Ra.div(Zs+e,Zs-e))}function ih(t){let e=Ar.Fp.BYTES;return Ee(t,e),Xs(Fs(t.subarray(0,e))).subarray(0,e)}function ah(t){return va(Ar,Fs,Object.assign({adjustScalarBytes:Xs,toMontgomery:oh,toMontgomerySecret:ih,zip215:!0},t))}var Da=ah({});var vr=(()=>{let t=An,e=r=>{let{pow_p_5_8:n,b2:s}=Ca(r);return Q(se(n,eh,t)*s,t)};return La({P:t,type:"x25519",powPminus2:e,adjustScalarBytes:Xs,scalarMultBase:r=>{let n=Q(r,Ar.Fn.ORDER);if(n===Ia)return Ia;let s=Ar.BASE.multiply(n);return Q((s.Z+s.Y)*e(Q(s.Z-s.Y,t)),t)}})})();var Br=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},vn=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var De={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new vn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return e}};var Bn=32;var Js,ch=(async()=>{try{return await De.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function fh(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await De.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await De.get().subtle.verify({name:"Ed25519"},n,Le(e),Le(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function uh(t,e,r){return Da.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function Oa(t,e,r){return Js==null&&(Js=await ch),Js?fh(t,e,r):uh(t,e,r)}function Ln(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var In=class{type="Ed25519";raw;constructor(e){this.raw=Qs(e,Bn)}toMultihash(){return Me.digest(nt(this))}toCID(){return ye.createV1(114,this.toMultihash())}toString(){return fe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:xe(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let s=Oa(this.raw,r,e);return Ln(s)?s.then(o=>(n?.signal?.throwIfAborted(),o)):s}};function Ka(t){return t=Qs(t,Bn),new In(t)}function Qs(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new ie(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}var lh=Math.pow(2,7),dh=Math.pow(2,14),ph=Math.pow(2,21),eo=Math.pow(2,28),to=Math.pow(2,35),ro=Math.pow(2,42),no=Math.pow(2,49),J=128,be=127;function Ke(t){if(t<lh)return 1;if(t<dh)return 2;if(t<ph)return 3;if(t<eo)return 4;if(t<to)return 5;if(t<ro)return 6;if(t<no)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function so(t,e,r=0){switch(Ke(t)){case 8:e[r++]=t&255|J,t/=128;case 7:e[r++]=t&255|J,t/=128;case 6:e[r++]=t&255|J,t/=128;case 5:e[r++]=t&255|J,t/=128;case 4:e[r++]=t&255|J,t>>>=7;case 3:e[r++]=t&255|J,t>>>=7;case 2:e[r++]=t&255|J,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function mh(t,e,r=0){switch(Ke(t)){case 8:e.set(r++,t&255|J),t/=128;case 7:e.set(r++,t&255|J),t/=128;case 6:e.set(r++,t&255|J),t/=128;case 5:e.set(r++,t&255|J),t/=128;case 4:e.set(r++,t&255|J),t>>>=7;case 3:e.set(r++,t&255|J),t>>>=7;case 2:e.set(r++,t&255|J),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function oo(t,e){let r=t[e],n=0;if(n+=r&be,r<J||(r=t[e+1],n+=(r&be)<<7,r<J)||(r=t[e+2],n+=(r&be)<<14,r<J)||(r=t[e+3],n+=(r&be)<<21,r<J)||(r=t[e+4],n+=(r&be)*eo,r<J)||(r=t[e+5],n+=(r&be)*to,r<J)||(r=t[e+6],n+=(r&be)*ro,r<J)||(r=t[e+7],n+=(r&be)*no,r<J))return n;throw new RangeError("Could not decode varint")}function yh(t,e){let r=t.get(e),n=0;if(n+=r&be,r<J||(r=t.get(e+1),n+=(r&be)<<7,r<J)||(r=t.get(e+2),n+=(r&be)<<14,r<J)||(r=t.get(e+3),n+=(r&be)<<21,r<J)||(r=t.get(e+4),n+=(r&be)*eo,r<J)||(r=t.get(e+5),n+=(r&be)*to,r<J)||(r=t.get(e+6),n+=(r&be)*ro,r<J)||(r=t.get(e+7),n+=(r&be)*no,r<J))return n;throw new RangeError("Could not decode varint")}function Ua(t,e,r=0){return e==null&&(e=pe(Ke(t))),e instanceof Uint8Array?so(t,e,r):mh(t,e,r)}function Tn(t,e=0){return t instanceof Uint8Array?oo(t,e):yh(t,e)}var io=new Float32Array([-0]),dt=new Uint8Array(io.buffer);function Na(t,e,r){io[0]=t,e[r]=dt[0],e[r+1]=dt[1],e[r+2]=dt[2],e[r+3]=dt[3]}function Ma(t,e){return dt[0]=t[e],dt[1]=t[e+1],dt[2]=t[e+2],dt[3]=t[e+3],io[0]}var ao=new Float64Array([-0]),we=new Uint8Array(ao.buffer);function Fa(t,e,r){ao[0]=t,e[r]=we[0],e[r+1]=we[1],e[r+2]=we[2],e[r+3]=we[3],e[r+4]=we[4],e[r+5]=we[5],e[r+6]=we[6],e[r+7]=we[7]}function Ha(t,e){return we[0]=t[e],we[1]=t[e+1],we[2]=t[e+2],we[3]=t[e+3],we[4]=t[e+4],we[5]=t[e+5],we[6]=t[e+6],we[7]=t[e+7],ao[0]}var gh=BigInt(Number.MAX_SAFE_INTEGER),bh=BigInt(Number.MIN_SAFE_INTEGER),Ie=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return At;if(e<gh&&e>bh)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,s=e-(n<<32n);return r&&(n=~n|0n,s=~s|0n,++s>qa&&(s=0n,++n>qa&&(n=0n))),new t(Number(s),Number(n))}static fromNumber(e){if(e===0)return At;let r=e<0;r&&(e=-e);let n=e>>>0,s=(e-n)/4294967296>>>0;return r&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new t(n,s)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):At}},At=new Ie(0,0);At.toBigInt=function(){return 0n};At.zzEncode=At.zzDecode=function(){return this};At.length=function(){return 1};var qa=4294967296n;function za(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function ja(t,e,r){if(r-e<1)return"";let s,o=[],i=0,a;for(;e<r;)a=t[e++],a<128?o[i++]=a:a>191&&a<224?o[i++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,o[i++]=55296+(a>>10),o[i++]=56320+(a&1023)):o[i++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,i>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,o)),i=0);return s!=null?(i>0&&s.push(String.fromCharCode.apply(String,o.slice(0,i))),s.join("")):String.fromCharCode.apply(String,o.slice(0,i))}function co(t,e,r){let n=r,s,o;for(let i=0;i<t.length;++i)s=t.charCodeAt(i),s<128?e[r++]=s:s<2048?(e[r++]=s>>6|192,e[r++]=s&63|128):(s&64512)===55296&&((o=t.charCodeAt(i+1))&64512)===56320?(s=65536+((s&1023)<<10)+(o&1023),++i,e[r++]=s>>18|240,e[r++]=s>>12&63|128,e[r++]=s>>6&63|128,e[r++]=s&63|128):(e[r++]=s>>12|224,e[r++]=s>>6&63|128,e[r++]=s&63|128);return r-n}function Ue(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function _n(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var fo=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=Le(e),this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Ue(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ue(this,4);return _n(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ue(this,4);return _n(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ue(this,4);let e=Ma(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ue(this,4);let e=Ha(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw Ue(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return ja(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ue(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ue(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Ie(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Ue(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw Ue(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ue(this,8);let e=_n(this.buf,this.pos+=4),r=_n(this.buf,this.pos+=4);return new Ie(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=oo(this.buf,this.pos);return this.pos+=Ke(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Lr(t){return new fo(t instanceof Uint8Array?t:t.subarray())}function vt(t,e,r){let n=Lr(t);return e.decode(n,void 0,r)}function uo(t){let e=t??8192,r=e>>>1,n,s=e;return function(i){if(i<1||i>r)return pe(i);s+i>e&&(n=pe(e),s=0);let a=n.subarray(s,s+=i);return(s&7)!==0&&(s=(s|7)+1),a}}var Bt=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function ho(){}var po=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},wh=uo();function xh(t){return globalThis.Buffer!=null?pe(t):wh(t)}var Tr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Bt(ho,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Bt(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new mo((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(Rn,10,Ie.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Ie.fromBigInt(e);return this._push(Rn,r.length(),r)}uint64Number(e){return this._push(so,Ke(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=Ie.fromBigInt(e).zzEncode();return this._push(Rn,r.length(),r)}sint64Number(e){let r=Ie.fromNumber(e).zzEncode();return this._push(Rn,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(lo,1,e?1:0)}fixed32(e){return this._push(Ir,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Ie.fromBigInt(e);return this._push(Ir,4,r.lo)._push(Ir,4,r.hi)}fixed64Number(e){let r=Ie.fromNumber(e);return this._push(Ir,4,r.lo)._push(Ir,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(Na,4,e)}double(e){return this._push(Fa,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(lo,1,0):this.uint32(r)._push(Sh,r,e)}string(e){let r=za(e);return r!==0?this.uint32(r)._push(co,r,e):this._push(lo,1,0)}fork(){return this.states=new po(this),this.head=this.tail=new Bt(ho,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Bt(ho,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=xh(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function lo(t,e,r){e[r]=t&255}function Eh(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var mo=class extends Bt{next;constructor(e,r){super(Eh,e,r),this.next=void 0}};function Rn(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function Ir(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function Sh(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(Tr.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(Ah,e,t),this},Tr.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(vh,e,t),this});function Ah(t,e,r){e.set(t,r)}function vh(t,e,r){t.length<40?co(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(re(t),r)}function yo(){return new Tr}function Lt(t,e){let r=yo();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*It(t,e,r){let n=Lr(t);yield*e.stream(n,void 0,"$",r)}var Cn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Dn(t,e,r,n,s){return{name:t,type:e,encode:r,decode:n,stream:s}}function go(t){function e(o){if(t[o.toString()]==null)throw new Error("Invalid enum value");return t[o]}let r=function(i,a){let c=e(i);a.int32(c)},n=function(i){let a=i.int32();return e(a)},s=function*(i){let a=i.int32();yield e(a)};return Dn("enum",Cn.VARINT,r,n,s)}function Tt(t,e,r){return Dn("message",Cn.LENGTH_DELIMITED,t,e,r)}var _t=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var le;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(le||(le={}));var bo;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(bo||(bo={}));(function(t){t.codec=()=>go(bo)})(le||(le={}));var Ge;(function(t){let e;t.codec=()=>(e==null&&(e=Tt((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.Type!=null&&(i.uint32(8),le.codec().encode(o.Type,i)),o.Data!=null&&(i.uint32(18),i.bytes(o.Data)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={},f=i==null?o.len:o.pos+i;for(;o.pos<f;){let u=o.uint32();switch(u>>>3){case 1:{c.Type=le.codec().decode(o);break}case 2:{c.Data=o.bytes();break}default:{o.skipType(u&7);break}}}return c},function*(o,i,a,c={}){let f=i==null?o.len:o.pos+i;for(;o.pos<f;){let u=o.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:le.codec().decode(o)};break}case 2:{yield{field:`${a}.Data`,value:o.bytes()};break}default:{o.skipType(u&7);break}}}})),e);function r(o){return Lt(o,t.codec())}t.encode=r;function n(o,i){return vt(o,t.codec(),i)}t.decode=n;function s(o,i){return It(o,t.codec(),i)}t.stream=s})(Ge||(Ge={}));var wo;(function(t){let e;t.codec=()=>(e==null&&(e=Tt((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.Type!=null&&(i.uint32(8),le.codec().encode(o.Type,i)),o.Data!=null&&(i.uint32(18),i.bytes(o.Data)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={},f=i==null?o.len:o.pos+i;for(;o.pos<f;){let u=o.uint32();switch(u>>>3){case 1:{c.Type=le.codec().decode(o);break}case 2:{c.Data=o.bytes();break}default:{o.skipType(u&7);break}}}return c},function*(o,i,a,c={}){let f=i==null?o.len:o.pos+i;for(;o.pos<f;){let u=o.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:le.codec().decode(o)};break}case 2:{yield{field:`${a}.Data`,value:o.bytes()};break}default:{o.skipType(u&7);break}}}})),e);function r(o){return Lt(o,t.codec())}t.encode=r;function n(o,i){return vt(o,t.codec(),i)}t.decode=n;function s(o,i){return It(o,t.codec(),i)}t.stream=s})(wo||(wo={}));var Rr={};Ae(Rr,{MAX_RSA_KEY_SIZE:()=>xo,generateRSAKeyPair:()=>Za,jwkToJWKKeyPair:()=>Xa,jwkToPkcs1:()=>Th,jwkToPkix:()=>vo,jwkToRSAPrivateKey:()=>To,pkcs1MessageToJwk:()=>So,pkcs1MessageToRSAPrivateKey:()=>Bo,pkcs1ToJwk:()=>Ih,pkcs1ToRSAPrivateKey:()=>Ga,pkixMessageToJwk:()=>Ao,pkixMessageToRSAPublicKey:()=>Io,pkixToJwk:()=>_h,pkixToRSAPublicKey:()=>Lo});var Jt=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Rr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ye.createV1(114,this._multihash)}toString(){return fe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:xe(this.raw,e.raw)}verify(e,r,n){return Wa(this.jwk,r,e,n)}},_r=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Rr.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:xe(this.raw,e.raw)}sign(e,r){return Ya(this.jwk,e,r)}};var xo=8192,Eo=18,Bh=1062,Lh=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Ih(t){let e=$e(t);return So(e)}function So(t){return{n:Z(t[1],"base64url"),e:Z(t[2],"base64url"),d:Z(t[3],"base64url"),p:Z(t[4],"base64url"),q:Z(t[5],"base64url"),dp:Z(t[6],"base64url"),dq:Z(t[7],"base64url"),qi:Z(t[8],"base64url"),kty:"RSA"}}function Th(t){if(t.n==null||t.e==null||t.d==null||t.p==null||t.q==null||t.dp==null||t.dq==null||t.qi==null)throw new ie("JWK was missing components");return rt([ve(Uint8Array.from([0])),ve(re(t.n,"base64url")),ve(re(t.e,"base64url")),ve(re(t.d,"base64url")),ve(re(t.p,"base64url")),ve(re(t.q,"base64url")),ve(re(t.dp,"base64url")),ve(re(t.dq,"base64url")),ve(re(t.qi,"base64url"))]).subarray()}function _h(t){let e=$e(t,{offset:0});return Ao(e)}function Ao(t){let e=$e(t[1],{offset:0});return{kty:"RSA",n:Z(e[0],"base64url"),e:Z(e[1],"base64url")}}function vo(t){if(t.n==null||t.e==null)throw new ie("JWK was missing components");return rt([Lh,en(rt([ve(re(t.n,"base64url")),ve(re(t.e,"base64url"))]))]).subarray()}function Ga(t){let e=$e(t);return Bo(e)}function Bo(t){let e=So(t);return To(e)}function Lo(t,e){if(t.byteLength>=Bh)throw new Kt("Key size is too large");let r=$e(t,{offset:0});return Io(r,t,e)}function Io(t,e,r){let n=Ao(t);if(r==null){let s=He(Ge.encode({Type:le.RSA,Data:e}));r=Ne(Eo,s)}return new Jt(n,r)}function To(t){if(Qa(t)>xo)throw new ie("Key size is too large");let e=Xa(t),r=He(Ge.encode({Type:le.RSA,Data:vo(e.publicKey)})),n=Ne(Eo,r);return new _r(e.privateKey,new Jt(e.publicKey,n))}async function Za(t){if(t>xo)throw new ie("Key size is too large");let e=await Ja(t),r=He(Ge.encode({Type:le.RSA,Data:vo(e.publicKey)})),n=Ne(Eo,r);return new _r(e.privateKey,new Jt(e.publicKey,n))}function Xa(t){if(t==null)throw new ie("Missing key parameter");return{privateKey:t,publicKey:{kty:t.kty,n:t.n,e:t.e}}}async function Ja(t,e){let r=await De.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:t,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);e?.signal?.throwIfAborted();let n=await Rh(r,e);return{privateKey:n[0],publicKey:n[1]}}async function Ya(t,e,r){let n=await De.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let s=await De.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,Le(e instanceof Uint8Array?e:e.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(s,0,s.byteLength)}async function Wa(t,e,r,n){let s=await De.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let o=await De.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},s,Le(e),Le(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),o}async function Rh(t,e){if(t.privateKey==null||t.publicKey==null)throw new ie("Private and public key are required");let r=await Promise.all([De.get().subtle.exportKey("jwk",t.privateKey),De.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function Qa(t){if(t.kty!=="RSA")throw new ie("invalid key type");if(t.n==null)throw new ie("invalid key modulus");return re(t.n,"base64url").length*8}var On=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(xt(e),Ee(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,s=new Uint8Array(n);s.set(r.length>n?e.create().update(r).digest():r);for(let o=0;o<s.length;o++)s[o]^=54;this.iHash.update(s),this.oHash=e.create();for(let o=0;o<s.length;o++)s[o]^=106;this.oHash.update(s),_e(s)}update(e){return Vt(this),this.iHash.update(e),this}digestInto(e){Vt(this),nn(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:s,destroyed:o,blockLen:i,outputLen:a,canXOF:c}=this;return e=e,e.finished=s,e.destroyed=o,e.blockLen=i,e.outputLen=a,e.canXOF=c,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Cr=(()=>{let t=((e,r,n)=>new On(e,r).update(n).digest());return t.create=(e,r)=>new On(e,r),t})();var Ch=BigInt(0),_o=class extends Error{constructor(e=""){super(e)}},Ze={Err:_o,_tlv:{encode:(t,e)=>{let{Err:r}=Ze;if(We(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(ra(e,"data"),e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,s=br(n);if(s.length/2&128)throw new r("tlv.encode: long form length too big");let o=n>127?br(s.length/2|128):"";return br(t)+o+s+e},decode(t,e){let{Err:r}=Ze;e=Y(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.decode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let s=e[n++],o=!!(s&128),i=0;if(!o)i=s;else{let c=s&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let f=e.subarray(n,n+c);if(f.length!==c)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of f)i=i<<8|u;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+i)}}},_int:{encode(t){let{Err:e}=Ze;if(un(t),t<Ch)throw new e("integer: negative integers are not allowed");let r=br(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=Ze;if(t.length<1)throw new e("invalid signature integer: empty");if(t[0]&128)throw new e("invalid signature integer: negative");if(t.length>1&&t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return qe(t)}},toSig(t,e){let{Err:r,_int:n,_tlv:s}=Ze;if(e!==void 0&&(We(e,"maxScalarBytes"),e<1))throw new r("invalid signature: maxScalarBytes must be positive");let o=Y(t,void 0,"signature"),{v:i,l:a}=s.decode(48,o);if(a.length)throw new r("invalid signature: left bytes after parsing");let{v:c,l:f}=s.decode(2,i),{v:u,l:h}=s.decode(2,f);if(h.length)throw new r("invalid signature: left bytes after parsing");if(e!==void 0&&(c.length>e||u.length>e))throw new r("invalid signature: integer too large");return{r:n.decode(c),s:n.decode(u)}},hexFromSig(t){let{_tlv:e,_int:r}=Ze;ge(t,{r:"bigint",s:"bigint"},{},"sig");let n=e.encode(2,r.encode(t.r)),s=e.encode(2,r.encode(t.s)),o=n+s;return e.encode(48,o)}},kn=(Object.freeze(Ze._tlv),Object.freeze(Ze._int),Object.freeze(Ze));var ec=(t,e)=>(t+(t>=0?e:-e)/tc)/e;function Dh(t,e,r){je("scalar",t,Xe,r);let[[n,s],[o,i]]=e,a=ec(i*t,r),c=ec(-s*t,r),f=t-a*n-c*o,u=-a*s-c*i,h=f<Xe,p=u<Xe;h&&(f=-f),p&&(u=-u);let d=xr(Math.ceil(Yt(r)/2))+Rt;if(f<Xe||f>=d||u<Xe||u>=d)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:h,k1:f,k2neg:p,k2:u}}function Do(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Ro(t,e){ge(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Be(r.lowS,"lowS"),Be(r.prehash,"prehash"),r.format!==void 0&&Do(r.format),r}var Xe=BigInt(0),Rt=BigInt(1),tc=BigInt(2),Co=BigInt(3),Oh=BigInt(4);function rc(t,e={}){let r=bn("weierstrass",t,e),n=r.Fp,s=r.Fn,o=r.CURVE,{h:i,n:a}=o;ge(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:f,clearCofactor:u,isTorsionFree:h,fromBytes:p,toBytes:d}=e,w=e.randomBytes===void 0?Ye:e.randomBytes;if(c&&(!n.is0(o.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let g=c?{beta:c.beta,basises:c.basises.map(S=>[...S])}:void 0,y=sc(n,s);function x(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function E(S,l,m){if(l.is0()){if(!f)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x:A,y:D}=l.toAffine(),U=n.toBytes(A);if(Be(m,"isCompressed"),m){x();let P=!n.isOdd(D);return Re(nc(P),U)}else return Re(Uint8Array.of(4),U,n.toBytes(D))}function b(S){Y(S,void 0,"Point");let{publicKey:l,publicKeyUncompressed:m}=y,A=S.length,D=S[0],U=S.subarray(1);if(f&&A===1&&D===0)return{x:n.ZERO,y:n.ZERO};if(A===l&&(D===2||D===3)){let P=n.fromBytes(U);if(!n.isValid(P))throw new Error("bad point: is not on curve, wrong x");let q=K(P),z;try{z=n.sqrt(q)}catch(ne){let ee=ne instanceof Error?": "+ne.message:"";throw new Error("bad point: is not on curve, sqrt error"+ee)}x();let V=n.isOdd(z);return(D&1)===1!==V&&(z=n.neg(z)),{x:P,y:z}}else if(A===m&&D===4){let P=n.BYTES,q=n.fromBytes(U.subarray(0,P)),z=n.fromBytes(U.subarray(P,P*2));if(!_(q,z))throw new Error("bad point: is not on curve");return{x:q,y:z}}else throw new Error(`bad point: got length ${A}, expected compressed=${l} or uncompressed=${m}`)}let R=d===void 0?E:d,T=p===void 0?b:p,O=n.mul(o.b,Co),N=n.is0(o.a)?S=>n.ZERO:S=>n.mul(o.a,S);function K(S){let l=n.sqr(S),m=n.mul(l,S);return n.add(n.add(m,n.mul(S,o.a)),o.b)}function _(S,l){let m=n.sqr(l),A=K(S);return n.eql(m,A)}if(!_(o.Gx,o.Gy))throw new Error("bad curve params: generator point");let C=n.mul(n.pow(o.a,Co),Oh),F=n.mul(n.sqr(o.b),BigInt(27));if(n.is0(n.add(C,F)))throw new Error("bad curve params: a or b");function M(S,l,m=!1){if(!n.isValid(l)||m&&n.is0(l))throw new Error(`bad point coordinate ${S}`);return typeof l=="object"&&l!==null?n.create(l):l}function j(S){if(!(S instanceof v))throw new Error("Weierstrass Point expected")}function B(S){if(!g||!g.basises)throw new Error("no endo");return Dh(S,g.basises,s.ORDER)}function k(S,l,m,A){if(!s.isValid(A))throw new RangeError("invalid scalar: out of range");if(g){let{k1neg:D,k1:U,k2neg:P,k2:q}=B(A),z=new v(n.mul(m.X,g.beta),m.Y,m.Z);S.push(D?m.negate():m,P?z.negate():z),l.push(U,q)}else S.push(m),l.push(A)}let L=new WeakSet;class v{static BASE=new v(o.Gx,o.Gy,n.ONE);static ZERO=new v(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=s;X;Y;Z;constructor(l,m,A){this.X=M("x",l),this.Y=M("y",m,!0),this.Z=M("z",A),Object.freeze(this)}static CURVE(){return o}static fromAffine(l){let{x:m,y:A}=l||{};if(!l||!n.isValid(m)||!n.isValid(A))throw new Error("invalid affine point");if(l instanceof v)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(A)?v.ZERO:new v(m,A,n.ONE)}static fromBytes(l){let m=v.fromAffine(T(Y(l,void 0,"point")));return m.assertValidity(),m}static fromHex(l){return v.fromBytes($t(l))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(l=6,m=!0){return I.setWindowSize(this,l),m||this.multiply(Co),this}assertValidity(){let l=this;if(l.is0()){if(f&&n.is0(l.X)&&n.eql(l.Y,n.ONE)&&n.is0(l.Z))return;throw new Error("bad point: ZERO")}if(L.has(l))return;let{x:m,y:A}=l.toAffine();if(!n.isValid(m)||!n.isValid(A))throw new Error("bad point: x or y not field elements");if(!_(m,A))throw new Error("bad point: equation left != right");if(!l.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");L.add(l)}hasEvenY(){let{y:l}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(l)}equals(l){j(l);let{X:m,Y:A,Z:D}=this,{X:U,Y:P,Z:q}=l,z=n.eql(n.mul(m,q),n.mul(U,D)),V=n.eql(n.mul(A,q),n.mul(P,D));return z&&V}negate(){return new v(this.X,n.neg(this.Y),this.Z)}double(){let{X:l,Y:m,Z:A}=this,D=n.ZERO,U=n.ZERO,P=n.ZERO,q=n.mul(l,l),z=n.mul(m,m),V=n.mul(A,A),$=n.mul(l,m);return $=n.add($,$),P=n.mul(l,A),P=n.add(P,P),D=N(P),U=n.mul(O,V),U=n.add(D,U),D=n.sub(z,U),U=n.add(z,U),U=n.mul(D,U),D=n.mul($,D),P=n.mul(O,P),V=N(V),$=n.sub(q,V),$=N($),$=n.add($,P),P=n.add(q,q),q=n.add(P,q),q=n.add(q,V),q=n.mul(q,$),U=n.add(U,q),V=n.mul(m,A),V=n.add(V,V),q=n.mul(V,$),D=n.sub(D,q),P=n.mul(V,z),P=n.add(P,P),P=n.add(P,P),new v(D,U,P)}add(l){j(l);let{X:m,Y:A,Z:D}=this,{X:U,Y:P,Z:q}=l,z=n.ZERO,V=n.ZERO,$=n.ZERO,ne=n.mul(m,U),ee=n.mul(A,P),ce=n.mul(D,q),Se=n.add(m,A),te=n.add(U,P);Se=n.mul(Se,te),te=n.add(ne,ee),Se=n.sub(Se,te),te=n.add(m,D);let oe=n.add(U,q);return te=n.mul(te,oe),oe=n.add(ne,ce),te=n.sub(te,oe),oe=n.add(A,D),z=n.add(P,q),oe=n.mul(oe,z),z=n.add(ee,ce),oe=n.sub(oe,z),$=N(te),z=n.mul(O,ce),$=n.add(z,$),z=n.sub(ee,$),$=n.add(ee,$),V=n.mul(z,$),ee=n.add(ne,ne),ee=n.add(ee,ne),ce=N(ce),te=n.mul(O,te),ee=n.add(ee,ce),ce=n.sub(ne,ce),ce=N(ce),te=n.add(te,ce),ne=n.mul(ee,te),V=n.add(V,ne),ne=n.mul(oe,te),z=n.mul(Se,z),z=n.sub(z,ne),ne=n.mul(Se,ee),$=n.mul(oe,$),$=n.add($,ne),new v(z,V,$)}subtract(l){return j(l),this.add(l.negate())}is0(){return this.equals(v.ZERO)}multiply(l){if(!s.isValidNot0(l))throw new RangeError("invalid scalar: out of range");let{p:m,f:A}=I.mulSecret(this,l,i,H);return H([m,A])[0]}multiplyUnsafe(l){let m=this,A=l;if(!s.isValid(A))throw new RangeError("invalid scalar: out of range");if(A===Xe||m.is0())return v.ZERO;if(A===Rt)return m;if(I.hasWindowSize(this))return I.mulUnsafe(m,A,H);let D=[],U=[];return k(D,U,m,A),gn(v,D,U)}mulAddUnsafe(l,m,A){j(m);let D=[],U=[];return k(D,U,this,l),k(D,U,m,A),gn(v,D,U)}toAffine(l){let m=this,A=l;if(A!=null&&!n.isValid(A))throw new RangeError('"invertedZ" expected valid field element');let{X:D,Y:U,Z:P}=m;if(n.eql(P,n.ONE))return{x:D,y:U};let q=m.is0();A==null&&(A=q?n.ONE:n.inv(P));let z=n.mul(D,A),V=n.mul(U,A),$=n.mul(P,A);if(q)return{x:n.ZERO,y:n.ZERO};if(!n.eql($,n.ONE))throw new Error("invZ was invalid");return{x:z,y:V}}isTorsionFree(){return i===Rt?!0:h?h(v,this):I.mulUnsafe(this,a).is0()}clearCofactor(){return i===Rt?this:u?u(v,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===Rt?this.is0():this.clearCofactor().is0()}toBytes(l=!0){return Be(l,"isCompressed"),this.assertValidity(),R(v,this,l)}toHex(l=!0){return gr(this.toBytes(l))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let H=S=>yn(v,S),I=new Zt(v,w);return I.bits>=6&&v.BASE.precompute(6),Object.freeze(v.prototype),Object.freeze(v),v}function nc(t){return Uint8Array.of(t?2:3)}function sc(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function kh(t,e={}){lt(t);let{Fn:r}=t,n=e.randomBytes===void 0?Ye:e.randomBytes,s=Object.assign(sc(t.Fp,r),{seed:Math.max(pn(r.ORDER),16)});function o(d){try{let w=r.fromBytes(d);return r.isValidNot0(w)}catch{return!1}}function i(d,w){let{publicKey:g,publicKeyUncompressed:y}=s;try{let x=d.length;return w===!0&&x!==g||w===!1&&x!==y?!1:!t.fromBytes(d).is0()}catch{return!1}}function a(d){return d=d===void 0?n(s.seed):d,mn(Y(d,s.seed,"seed"),r.ORDER)}function c(d,w=!0){return t.BASE.multiply(r.fromBytes(d)).toBytes(w)}function f(d){let{secretKey:w,publicKey:g,publicKeyUncompressed:y}=s,x=r._lengths;if(!ft(d))return;let E=Y(d,void 0,"key").length,b=E===g||E===y,R=E===w||!!x?.includes(E);if(!(b&&R))return b}function u(d,w,g=!0){if(f(d)===!0)throw new Error("first arg must be private key");if(f(w)===!1)throw new Error("second arg must be public key");let y=r.fromBytes(d),x=t.fromBytes(w);if(x.is0())throw new Error("invalid public key: point at infinity");return x.multiply(y).toBytes(g)}let h={isValidSecretKey:o,isValidPublicKey:i,randomSecretKey:a},p=Xt(a,c);return Object.freeze(h),Object.freeze(s),Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:p,Point:t,utils:h,lengths:s})}function oc(t,e,r={}){lt(t);let n=e;xt(n),ge(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let s=Object.assign({},r),o=s.randomBytes===void 0?Ye:s.randomBytes,i=s.hmac===void 0?(S,l)=>Cr(n,S,l):s.hmac,{Fp:a,Fn:c}=t,{ORDER:f,BITS:u}=c,h=pn(f),p=Gs(o,h),{keygen:d,getPublicKey:w,getSharedSecret:g,utils:y,lengths:x}=kh(t,s),E={prehash:!0,lowS:typeof s.lowS=="boolean"?s.lowS:!0,format:"compact",extraEntropy:!1},b=f*tc+Rt<a.ORDER;function R(S){let l=f>>Rt;return S>l}function T(S,l){if(!c.isValidNot0(l))throw new Error(`invalid signature ${S}: out of range 1..Point.Fn.ORDER`);return l}function O(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function N(S,l,m){return O(),(S===m?0:2)|Number(a.isOdd(l))}function K(){if(b)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function _(S,l){Do(l);let m=x.signature,A=l==="compact"?m:l==="recovered"?m+1:void 0;return Y(S,A)}class C{r;s;recovery;constructor(l,m,A){if(this.r=T("r",l),this.s=T("s",m),A!=null){if(K(),![0,1,2,3].includes(A))throw new Error("invalid recovery id");this.recovery=A}Object.freeze(this)}static fromBytes(l,m=E.format){_(l,m);let A;if(m==="der"){if(l.length>2*c.BYTES+16)throw new kn.Err("invalid signature: DER signature too long");let{r:q,s:z}=kn.toSig(Y(l),c.BYTES+1);return new C(q,z)}m==="recovered"&&(A=l[0],m="compact",l=l.subarray(1));let D=x.signature/2,U=l.subarray(0,D),P=l.subarray(D,D*2);return new C(c.fromBytes(U),c.fromBytes(P),A)}static fromHex(l,m){return this.fromBytes($t(l),m)}assertRecovery(){let{recovery:l}=this;if(l==null)throw new Error("invalid recovery id: must be present");return l}addRecoveryBit(l){return new C(this.r,this.s,l)}recoverPublicKey(l){let{r:m,s:A}=this,D=this.assertRecovery(),U=D===2||D===3?m+f:m;if(!a.isValid(U))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let P=a.toBytes(U),q=t.fromBytes(Re(nc((D&1)===0),P)),z=c.inv(U),V=M(Y(l,void 0,"msgHash")),$=c.create(-V*z),ne=c.create(A*z),ee=t.BASE.mulAddUnsafe($,q,ne);if(ee.is0())throw new Error("invalid recovery: point at infinify");return ee.assertValidity(),ee}hasHighS(){return R(this.s)}toBytes(l=E.format){if(Do(l),l==="der")return $t(kn.hexFromSig(this));let{r:m,s:A}=this,D=c.toBytes(m),U=c.toBytes(A);return l==="recovered"?(K(),Re(Uint8Array.of(this.assertRecovery()),D,U)):Re(D,U)}toHex(l){return gr(this.toBytes(l))}}Object.freeze(C.prototype),Object.freeze(C);let F=s.bits2int===void 0?function(l){if(l.length>8192)throw new Error("input is too large");let m=qe(l),A=l.length*8-u;return A>0?m>>BigInt(A):m}:s.bits2int,M=s.bits2int_modN===void 0?function(l){return c.create(F(l))}:s.bits2int_modN,j=xr(u);function B(S){return je("num < 2^"+u,S,Xe,j),c.toBytes(S)}function k(S,l){return Y(S,void 0,"message"),l?Y(n(S),void 0,"prehashed message"):S}function L(S,l,m){let{lowS:A,prehash:D,extraEntropy:U}=Ro(m,E);S=k(S,D);let P=M(S),q=c.fromBytes(l);if(!c.isValidNot0(q))throw new Error("invalid private key");let z=[B(q),B(P)];if(U!=null&&U!==!1){let ee=U===!0?o(x.secretKey):U;z.push(Y(ee,void 0,"extraEntropy"))}let V=Re(...z),$=P;function ne(ee){let ce=F(ee);if(!c.isValidNot0(ce))return;let Se=t.BASE.multiply(ce).toAffine(),te=c.create(Se.x);if(te===Xe)return;let oe;if(p!==void 0){let Qe=qe(mn(p(h),f)),Nc=c.inv(c.mul(Qe,ce)),Mc=c.mul(Qe,$),Fc=c.mul(Qe,q);oe=c.create(Nc*c.create(Mc+Fc*te))}else{let Qe=la(ce,f);oe=c.create(Qe*c.create($+te*q))}if(oe===Xe)return;let kt=N(Se.x,Se.y,te),ar=oe;return A&&R(oe)&&(ar=c.neg(oe),kt^=1),new C(te,ar,b?void 0:kt)}return{seed:V,k2sig:ne}}function v(S,l,m={}){let{seed:A,k2sig:D}=L(S,l,m);return sa(n.outputLen,c.BYTES,i)(A,D).toBytes(m.format)}function H(S,l,m,A={}){let{lowS:D,prehash:U,format:P}=Ro(A,E);if(m=Y(m,void 0,"publicKey"),l=k(l,U),!ft(S)){let q=S instanceof C?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+q)}_(S,P);try{let q=C.fromBytes(S,P),z=t.fromBytes(m);if(z.is0()||D&&q.hasHighS())return!1;let{r:V,s:$}=q,ne=M(l),ee=c.inv($),ce=c.create(ne*ee),Se=c.create(V*ee),te=t.BASE.mulAddUnsafe(ce,z,Se);if(te.is0())return!1;let oe=te.toAffine();return!(c.create(oe.x)!==V||P==="recovered"&&q.recovery!==N(oe.x,oe.y,V))}catch{return!1}}function I(S,l,m={}){let{prehash:A}=Ro(m,E);return l=k(l,A),C.fromBytes(S,"recovered").recoverPublicKey(l).toBytes()}return Object.freeze({keygen:d,getPublicKey:w,getSharedSecret:g,utils:y,lengths:x,Point:t,sign:v,verify:H,recoverPublicKey:I,Signature:C,hash:n})}var ko={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Kh={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var ic=BigInt(2);function Uh(t){let e=ko.p,r=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),f=t*t*t%e,u=f*f*t%e,h=se(u,r,e)*u%e,p=se(h,r,e)*u%e,d=se(p,ic,e)*f%e,w=se(d,s,e)*d%e,g=se(w,o,e)*w%e,y=se(g,a,e)*g%e,x=se(y,c,e)*y%e,E=se(x,a,e)*g%e,b=se(E,r,e)*u%e,R=se(b,i,e)*w%e,T=se(R,n,e)*f%e,O=se(T,ic,e);if(!Oo.eql(Oo.sqr(O),t))throw new Error("Cannot find square root");return O}var Oo=Gt(ko.p,{sqrt:Uh}),Ph=rc(ko,{Fp:Oo,endo:Kh}),Qt=oc(Ph,He);function ac(t,e,r,n){let s=Jr.digest(r instanceof Uint8Array?r:r.subarray());if(Ln(s))return s.then(({digest:o})=>(n?.signal?.throwIfAborted(),Qt.verify(e,o,t,{prehash:!1,format:"der"}))).catch(o=>{throw o.name==="AbortError"?o:new Br(String(o))});try{return n?.signal?.throwIfAborted(),Qt.verify(e,s.digest,t,{prehash:!1,format:"der"})}catch(o){throw new Br(String(o))}}var Kn=class{type="secp256k1";raw;_key;constructor(e){this._key=fc(e),this.raw=cc(this._key)}toMultihash(){return Me.digest(nt(this))}toCID(){return ye.createV1(114,this.toMultihash())}toString(){return fe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:xe(this.raw,e.raw)}verify(e,r,n){return ac(this._key,r,e,n)}};function uc(t){return new Kn(t)}function cc(t){return Qt.Point.fromBytes(t).toBytes()}function fc(t){try{return Qt.Point.fromBytes(t),t}catch(e){throw new Kt(String(e))}}function Dr(t,e){let{Type:r,Data:n}=Ge.decode(t),s=n??new Uint8Array;switch(r){case le.RSA:return Lo(s,e);case le.Ed25519:return Ka(s);case le.secp256k1:return uc(s);case le.ECDSA:return ki(s);default:throw new Ut}}function nt(t){return Ge.encode({Type:le[t.type],Data:t.raw})}var hc=Symbol.for("nodejs.util.inspect.custom"),Nh=114,Or=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Qn]=!0;toString(){return this.string==null&&(this.string=fe.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ye.createV1(Nh,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return xe(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return xe(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[hc](){return`PeerId(${this.toString()})`}},Un=class extends Or{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Pn=class extends Or{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Nn=class extends Or{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},Mh=2336,Ko=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Me.digest(re(this.url))}[hc](){return`PeerId(${this.url})`}[Qn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ye.createV1(Mh,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=Z(e)),e.toString()===this.toString())}};function Uo(t){if(t.type==="Ed25519")return new Pn({multihash:t.toCID().multihash,publicKey:t});if(t.type==="secp256k1")return new Nn({multihash:t.toCID().multihash,publicKey:t});if(t.type==="RSA")return new Un({multihash:t.toCID().multihash,publicKey:t});throw new Ut}function Mn(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Fn=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},er=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Fn(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let r=this.head;this.head=r.next=new Fn(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Po=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Hn(t={}){return Fh(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},t)}function Fh(t,e){e=e??{};let r=e.onEnd,n=new er,s,o,i,a=Mn(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((y,x)=>{o=E=>{o=null,n.push(E);try{y(t(n))}catch(b){x(b)}return s}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Mn()})}},f=y=>o!=null?o(y):(n.push(y),s),u=y=>(n=new er,o!=null?o({error:y}):(n.push({error:y}),s)),h=y=>{if(i)return s;if(e?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:y})},p=y=>i?s:(i=!0,y!=null?u(y):f({done:!0})),d=()=>(n=new er,p(),{done:!0}),w=y=>(p(y),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:d,throw:w,push:h,end:p,get readableLength(){return n.size},onEmpty:async y=>{let x=y?.signal;if(x?.throwIfAborted(),n.isEmpty())return;let E,b;x!=null&&(E=new Promise((R,T)=>{b=()=>{T(new Po)},x.addEventListener("abort",b)}));try{await Promise.race([a.promise,E])}finally{b!=null&&x!=null&&x?.removeEventListener("abort",b)}}},r==null)return s;let g=s;return s={[Symbol.asyncIterator](){return this},next(){return g.next()},throw(y){return g.throw(y),r!=null&&(r(y),r=void 0),{done:!0}},return(){return g.return(),r!=null&&(r(),r=void 0),{done:!0}},push:h,end(y){return g.end(y),r!=null&&(r(y),r=void 0),s},get readableLength(){return g.readableLength},onEmpty:y=>g.onEmpty(y)},s}var No=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},lc=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function Mo(t,e){let{milliseconds:r,fallback:n,message:s,customTimers:o={setTimeout,clearTimeout},signal:i}=e,a,c,u=new Promise((h,p)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){p(lc(i));return}if(i&&(c=()=>{p(lc(i))},i.addEventListener("abort",c,{once:!0})),t.then(h,p),r===Number.POSITIVE_INFINITY)return;let d=new No;a=o.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(w){p(w)}return}typeof t.cancel=="function"&&t.cancel(),s===!1?h():s instanceof Error?p(s):(d.message=s??`Promise timed out after ${r} milliseconds`,p(d))},r)}).finally(()=>{u.clear(),c&&i&&i.removeEventListener("abort",c)});return u.clear=()=>{o.clearTimeout.call(void 0,a),a=void 0},u}var Hh=t=>{let e=t.addEventListener||t.on||t.addListener,r=t.removeEventListener||t.off||t.removeListener;if(!e||!r)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(t),removeListener:r.bind(t)}};function qh(t,e,r){let n,s=new Promise((o,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:f,removeListener:u}=Hh(t),h=async(...d)=>{let w=r.multiArgs?d:d[0];if(r.filter)try{if(!await r.filter(w))return}catch(g){n(),i(g);return}c.push(w),r.count===c.length&&(n(),o(c))},p=(...d)=>{n(),i(r.rejectionMultiArgs?d:d[0])};n=()=>{for(let d of a)u(d,h);for(let d of r.rejectionEvents)a.includes(d)||u(d,p)};for(let d of a)f(d,h);for(let d of r.rejectionEvents)a.includes(d)||f(d,p);r.signal&&r.signal.addEventListener("abort",()=>{p(r.signal.reason)},{once:!0}),r.resolveImmediately&&o(c)});if(s.cancel=n,typeof r.timeout=="number"){let o=Mo(s,{milliseconds:r.timeout});return o.cancel=()=>{n(),o.clear()},o}return s}function dc(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=qh(t,e,r),s=n.then(o=>o[0]);return s.cancel=n.cancel,s}var Ct=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};var qn=class extends Error{static name="StreamClosedError";name="StreamClosedError"};function zh(t){return t.reason}function kr(t,e,r){if(e==null||t==null)return t;let n=r?.translateError??zh;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let s;return Promise.race([t,new Promise((o,i)=>{s=()=>{i(n(e))},e.addEventListener("abort",s)})]).finally(()=>{s!=null&&e.removeEventListener("abort",s)})}var jh=Math.pow(2,20)*4,zn=class extends Gr{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;#e=!1;onDrainPromise;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??jh,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new G,this.writeBuffer=new G,this.readStatus="readable",this.remoteReadStatus="readable",this.writeStatus="writable",this.remoteWriteStatus="writable",this.sendingData=!1,this.writableNeedsDrain=!1,this.timeline={open:Date.now()},this.processSendQueue=this.processSendQueue.bind(this);let r=()=>{this.writableNeedsDrain&&(this.log.trace("drain event received, continue sending data"),this.writableNeedsDrain=!1,queueMicrotask(()=>{try{this.processSendQueue()}catch(s){this.log.error("processSendQueue threw - %e",s)}})),this.onDrainPromise?.resolve()};this.addEventListener("drain",r);let n=s=>{this.onDrainPromise?.reject(s.error??new qn)};this.addEventListener("close",n)}get readBufferLength(){return this.readBuffer.byteLength}get readableEnded(){return this.#e}get writeBufferLength(){return this.writeBuffer.byteLength}async onDrain(e){return this.writableNeedsDrain!==!0?Promise.resolve():(this.onDrainPromise==null&&(this.onDrainPromise=Promise.withResolvers()),kr(this.onDrainPromise.promise,e?.signal))}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=Hn(),r=o=>{e.push(o.data)};this.addEventListener("message",r);let n=o=>{e.end(o.error)};this.addEventListener("close",n);let s=()=>{e.end()};this.addEventListener("remoteCloseWrite",s);try{yield*e}finally{this.removeEventListener("message",r),this.removeEventListener("close",n),this.removeEventListener("remoteCloseWrite",s)}}isReadable(){return this.status==="open"}send(e){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new et(`Cannot write to a stream that is ${this.writeStatus}`);return this.log.trace("append %d bytes to write buffer",e.byteLength),this.writeBuffer.append(e),this.processSendQueue()}abort(e){if(!(this.status==="aborted"||this.status==="reset"||this.status==="closed")){this.log.error("abort with error - %e",e),this.status="aborted",this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle")),this.writeStatus="closed",this.remoteWriteStatus="closed",this.readStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.maybeDispatchEnd();try{this.sendReset(e)}catch(r){this.log.error("failed to send reset to remote - %e",r)}this.dispatchEvent(new Yr(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new et("Cannot pause a stream that is closing/closed");this.readStatus!=="paused"&&(this.readStatus="paused",this.sendPause())}resume(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new et("Cannot resume a stream that is closing/closed");this.readStatus!=="readable"&&(this.readStatus="readable",this.dispatchReadBuffer(),this.sendResume())}push(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new et(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.append(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}unshift(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new et(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.prepend(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}onData(e){if(e.byteLength!==0){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("ignoring data - read status %s",this.readStatus);return}this.readBuffer.append(e),this.dispatchReadBuffer()}}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="message"&&this.readBuffer.byteLength>0&&queueMicrotask(()=>{this.dispatchReadBuffer()})}onRemoteReset(){this.log("remote reset"),this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed",this.maybeDispatchEnd()),this.dispatchEvent(new Wr(new Vr))}onTransportClosed(e){this.log("transport closed"),this.readStatus==="readable"&&this.readBuffer.byteLength===0&&(this.log("close readable end after transport closed and read buffer is empty"),this.readStatus="closed"),this.remoteReadStatus!=="closed"&&(this.remoteReadStatus="closed"),this.remoteWriteStatus!=="closed"&&(this.remoteWriteStatus="closed"),this.writeStatus!=="closed"&&(this.writeStatus="closed"),e!=null?this.abort(e):(this.status==="open"||this.status==="closing")&&(this.timeline.close=Date.now(),this.status="closed",this.maybeDispatchEnd(),this.dispatchEvent(new Pt))}onRemoteCloseWrite(){this.remoteWriteStatus!=="closed"&&(this.log.trace("on remote close write"),this.remoteWriteStatus="closed",this.safeDispatchEvent("remoteCloseWrite"),this.maybeDispatchEnd(),this.writeStatus==="closed"&&this.onTransportClosed())}onRemoteCloseRead(){this.log.trace("on remote close read"),this.remoteReadStatus="closed",this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle"))}processSendQueue(){if(this.writableNeedsDrain)return this.log.trace("not processing send queue as drain is required"),this.checkWriteBufferLength(),!1;if(this.writeBuffer.byteLength===0)return this.log.trace("not processing send queue as no bytes to send"),!0;if(this.sendingData)return this.log.trace("not processing send queue as already sending data"),!0;if(this.writeStatus!=="writable"&&this.writeStatus!=="closing")return this.log.trace("not processing send queue as stream is %s",this.writeStatus),!1;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let e=!0,r=this.writeBuffer.byteLength,n=0;for(;this.writeBuffer.byteLength>0;){let s=Math.min(this.maxMessageSize??this.writeBuffer.byteLength,this.writeBuffer.byteLength);if(s===0){e=!1;break}let o=this.writeBuffer.sublist(0,s),i=new G(o);this.writeBuffer.consume(o.byteLength);let a;try{a=this.sendData(o)}catch(c){throw this.writeBuffer.prepend(i),this.abort(c),c}if(e=a.canSendMore,n+=a.sentBytes,a.sentBytes!==i.byteLength&&(i.consume(a.sentBytes),this.writeBuffer.prepend(i)),!e)break}return e||(this.log.trace("sent %d/%d bytes, pausing sending because underlying stream is full, %d bytes left in the write buffer",n,r,this.writeBuffer.byteLength),this.writableNeedsDrain=!0,this.checkWriteBufferLength()),this.writeBuffer.byteLength===0&&this.safeDispatchEvent("idle"),e}finally{this.sendingData=!1}}maybeDispatchEnd(){this.#e||this.readBuffer.byteLength>0||this.remoteWriteStatus!=="closed"&&this.readStatus!=="closed"||(this.#e=!0,this.safeDispatchEvent("end"))}dispatchReadBuffer(){try{if(this.listenerCount("message")===0){this.log.trace("not dispatching pause buffer as there are no listeners for the message event");return}if(this.readBuffer.byteLength===0){this.log.trace("not dispatching pause buffer as there is no data to dispatch");return}if(this.readStatus==="paused"){this.log.trace("not dispatching pause buffer we are paused");return}if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("dropping %d bytes because the readable end is %s",this.readBuffer.byteLength,this.readStatus),this.readBuffer.consume(this.readBuffer.byteLength);return}let e=this.readBuffer.sublist();this.readBuffer.consume(e.byteLength),this.dispatchEvent(new $r(e))}finally{this.readBuffer.byteLength===0&&this.remoteWriteStatus==="closed"&&(this.log("close readable end after dispatching read buffer and remote writable end is closed"),this.readStatus="closed",this.maybeDispatchEnd()),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new mt(`Read buffer length of ${this.readBuffer.byteLength} exceeded limit of ${this.maxReadBufferLength}, read status is ${this.readStatus}`))}checkWriteBufferLength(){this.maxWriteBufferLength!=null&&this.writeBuffer.byteLength>this.maxWriteBufferLength&&this.abort(new mt(`Write buffer length of ${this.writeBuffer.byteLength} exceeded limit of ${this.maxWriteBufferLength}, write status is ${this.writeStatus}`))}onMuxerNeedsDrain(){this.writableNeedsDrain=!0}onMuxerDrain(){this.safeDispatchEvent("drain")}};var Vh=4194304,jn=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Kr=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Ho=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},qo=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function $h(t){return typeof t?.closeRead=="function"}function Yh(t){return typeof t?.close=="function"}function Fo(t){return $h(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:Yh(t)?t.status!=="open":!1}function Wh(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function Gh(t,e){let r=e?.maxBufferSize??Vh,n=new G,s,o=!1,i;if(!Wh(t))throw new ie("Argument should be a Stream or a Multiaddr");let a=h=>{if(i==null){if(n.append(h.data),n.byteLength>r){let p=n.byteLength;n.consume(p);let d=new mt(`Read buffer overflow - ${p} > ${r}`);i=d,s?.reject(d),queueMicrotask(()=>{t.abort(d)});return}s?.resolve()}};t.addEventListener("message",a);let c=h=>{h.error!=null?s?.reject(h.error):s?.resolve()};t.addEventListener("close",c);let f=()=>{s?.resolve()};t.addEventListener("remoteCloseWrite",f);let u={readBuffer:n,async read(h){if(o===!0)throw new jn("Stream was unwrapped");if(i!=null)throw i;if(Fo(t)){if(n.byteLength===0&&h?.bytes==null)return null;if(h?.bytes!=null&&n.byteLength<h.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,h.bytes),new Ct(`Unexpected EOF - stream closed after reading ${n.byteLength}/${h.bytes} bytes`)}let p=h?.bytes??1;for(s=Promise.withResolvers();;){if(n.byteLength>=p){s.resolve();break}if(await kr(s.promise,h?.signal),Fo(t)){if(n.byteLength===0&&h?.bytes==null)return null;break}s=Promise.withResolvers()}let d=h?.bytes??n.byteLength;if(n.byteLength<d){if(Fo(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,d),new Ct(`Unexpected EOF - stream closed while reading ${n.byteLength}/${d} bytes`);return u.read(h)}let w=n.sublist(0,d);return n.consume(d),w},async write(h,p){if(o===!0)throw new jn("Stream was unwrapped");t.send(h)||await dc(t,"drain",{signal:p?.signal,rejectionEvents:["close"]})},unwrap(){return o||(o=!0,t.removeEventListener("message",a),t.removeEventListener("close",c),t.removeEventListener("remoteCloseWrite",f),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.unshift(n))),t}};return u}function zo(t,e={}){let r=Gh(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Ke(e.maxDataLength));let n=e?.lengthDecoder??Tn,s=e?.lengthEncoder??Ua;return{async read(i){let a=-1,c=new G;for(;;){let u=await r.read({...i,bytes:1});if(u==null)break;c.append(u);try{a=n(c)}catch(h){if(h instanceof RangeError)continue;throw h}if(a<0)throw new Kr("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new qo(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new Ho(`Message length too long - ${a} > ${e.maxDataLength}`);let f=await r.read({...i,bytes:a});if(f==null)throw t.log.error("tried to read %d bytes but the stream closed",a),new Ct(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(f.byteLength!==a)throw t.log.error("read %d/%d bytes before the stream closed",f.byteLength,a),new Ct(`Unexpected EOF - read ${f.byteLength}/${a} bytes before the stream closed`);return f},async write(i,a){await r.write(new G(s(i.byteLength),i),a)},async writeV(i,a){let c=new G(...i.flatMap(f=>[s(f.byteLength),f]));await r.write(c,a)},unwrap(){return r.unwrap()}}}var Zh=1024*1024*4,Xh=1024*1024*4,Vn=class{buffer;maxBufferSize;lengthDecoder;maxDataLength;encodingLength;constructor(e={}){this.buffer=new G,this.maxBufferSize=e.maxBufferSize??Zh,this.maxDataLength=e.maxDataLength??Xh,this.lengthDecoder=e.lengthDecoder??Tn,this.encodingLength=e.encodingLength??Ke}*decode(e){if(this.buffer.append(e),this.buffer.byteLength>this.maxBufferSize)throw new ie(`Buffer length limit exceeded - ${this.buffer.byteLength}/${this.maxBufferSize}`);for(;;){let r;try{r=this.lengthDecoder(this.buffer)}catch(o){if(o instanceof RangeError)break;throw o}if(r<0||r>this.maxDataLength)throw new Kr("Invalid message length");let n=this.encodingLength(r),s=n+r;if(this.buffer.byteLength>=s){let o=this.buffer.sublist(n,s);this.buffer.consume(s),o.byteLength>0&&(yield o)}else break}}};var tr=!!globalThis.process?.env?.DUMP_SESSION_KEYS,jo=16;function Vo(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var $n=t=>t?`"${t}" `:"";function Yn(t,e=""){if(typeof t!="boolean")throw new TypeError($n(e)+"expected boolean, got type="+typeof t);return t}function Dt(t,e=""){if(typeof t!="number")throw new TypeError($n(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError($n(e)+"expected integer >= 0, got "+t);return t}function ue(t,e,r=""){if(Vo(t)&&(e===void 0||t.length===e))return t;e!==void 0&&Dt(e,"length");let n=Vo(t),s=e!==void 0?` of length ${e}`:"",o=n?`length=${t.length}`:`type=${typeof t}`,i=$n(r)+"expected Uint8Array"+s+", got "+o;throw n?new RangeError(i):new TypeError(i)}var pc=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof t}`)};function $o(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function mc(t,e){ue(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function Ve(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function Pe(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Jh(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}var pt=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Qh(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function el(t){for(let e=0;e<t.length;e++)t[e]=Qh(t[e]);return t}var Je=pt?t=>t:el;function tl(t,e){return!t.byteLength||!e.byteLength?!1:t.buffer===e.buffer&&t.byteOffset<e.byteOffset+e.byteLength&&e.byteOffset<t.byteOffset+t.byteLength}function yc(t,e){if(tl(t,e)&&t.byteOffset<e.byteOffset)throw new Error("complex overlap of input and output is not supported")}function gc(t,e){return pc(t,"defaults"),pc(e,"opts"),Object.assign(t,e)}function bc(t,e){if(t=ue(t),e=ue(e),t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function wc(t,e,r){let n=e,s=r||(()=>[]),o=(a,c)=>n(c,...s(a)).update(a).digest(),i=n(new Uint8Array(t),...s(new Uint8Array(0)));return o.outputLen=i.outputLen,o.blockLen=i.blockLen,o.create=(a,...c)=>n(a,...c),o}var xc=(t,e)=>{function r(n,...s){if(ue(n,void 0,"key"),t.nonceLength!==void 0){let h=s[0];ue(h,t.varSizeNonce?void 0:t.nonceLength,"nonce")}let o=t.tagLength,i=t.nonceLength!==void 0?1:0;if(!t.withAAD){for(let h=i;h<s.length;h++)if(Vo(s[h]))throw new Error("AAD not supported")}t.withAAD&&s[i]!==void 0&&ue(s[i],void 0,"AAD");let a=e(n,...s),c=(h,p)=>{if(p!==void 0){if(h!==2)throw new Error("cipher output not supported");ue(p,void 0,"output")}},f=!1;return{encrypt(h,p){if(f)throw new Error("cannot encrypt() twice with same key + nonce");return f=!0,ue(h,void 0,"data"),c(a.encrypt.length,p),a.encrypt(h,p)},decrypt(h,p){if(ue(h,void 0,"data"),o&&h.length<o)throw new Error('"ciphertext" expected length >= tagLength='+o);return c(a.decrypt.length,p),a.decrypt(h,p)}}}return Object.assign(r,t),r};function Ur(t,e,r=!0){if(e===void 0)return new Uint8Array(t);if(ue(e,t,"output"),r&&!Pr(e))throw new Error("invalid output, must be aligned");return e}function Ec(t,e,r){Dt(t),Dt(e),Yn(r);let n=new Uint8Array(16),s=Jh(n);return s.setBigUint64(0,BigInt(e),r),s.setBigUint64(8,BigInt(t),r),n}function Pr(t){return t.byteOffset%4===0}function rr(t){return Uint8Array.from(ue(t))}var Ac=t=>Uint8Array.from(t.split(""),e=>e.charCodeAt(0)),rl=Je(Ve(Ac("expand 16-byte k"))),nl=Je(Ve(Ac("expand 32-byte k")));function W(t,e){return t<<e|t>>>32-e}var Nr=64,sl=16,Yo=2**32-1,Sc=Uint32Array.of();function ol(t,e,r,n,s,o,i,a){let c=s.length,f=new Uint8Array(Nr),u=Ve(f),h=pt&&Pr(s)&&Pr(o),p=h?Ve(s):Sc,d=h?Ve(o):Sc;if(!pt){for(let w=0;w<c;i++){if(t(e,r,n,u,i,a),Je(u),i>=Yo)throw new Error("arx: counter overflow");let g=Math.min(Nr,c-w);for(let y=0,x;y<g;y++)x=w+y,o[x]=s[x]^f[y];w+=g}return}for(let w=0;w<c;i++){if(t(e,r,n,u,i,a),i>=Yo)throw new Error("arx: counter overflow");let g=Math.min(Nr,c-w);if(h&&g===Nr){let y=w/4;if(w%4!==0)throw new Error("arx: invalid block position");for(let x=0,E;x<sl;x++)E=y+x,d[E]=p[E]^u[x];w+=Nr;continue}for(let y=0,x;y<g;y++)x=w+y,o[x]=s[x]^f[y];w+=g}}function vc(t,e){let{allowShortKeys:r,extendNonceFn:n,counterLength:s,counterRight:o,rounds:i}=gc({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof t!="function")throw new Error("core must be a function");return Dt(s),Dt(i),Yn(o),Yn(r),(a,c,f,u,h=0)=>{ue(a,void 0,"key"),ue(c,void 0,"nonce"),ue(f,void 0,"data");let p=f.length,d=u!==void 0;if(u=Ur(p,u,!1),d&&yc(f,u),Dt(h),h<0||h>=Yo)throw new Error("arx: counter overflow");let w=[],g=a.length,y,x;if(g===32)w.push(y=rr(a)),x=nl;else if(g===16&&r)y=new Uint8Array(32),y.set(a),y.set(a,16),x=rl,w.push(y);else throw ue(a,32,"arx key"),new Error("invalid key size");(!pt||!Pr(c))&&w.push(c=rr(c));let E=Ve(y);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");let T=c.subarray(0,16);if(pt)n(x,E,Ve(T),E);else{let O=Je(Uint32Array.from(x));n(O,E,Ve(T),E),Pe(O),Je(E)}c=c.subarray(16)}else pt||Je(E);let b=16-s;if(b!==c.length)throw new Error(`arx: nonce must be ${b} or 16 bytes`);if(b!==12){let T=new Uint8Array(12);T.set(c,o?0:12-c.length),c=T,w.push(c)}let R=Je(Ve(c));try{return ol(t,x,E,R,f,u,h,i),u}finally{Pe(...w)}}}function me(t,e){return t[e++]&255|(t[e++]&255)<<8}var Wo=class{blockLen=16;outputLen=16;buffer=new Uint8Array(16);r=new Uint16Array(10);h=new Uint16Array(10);pad=new Uint16Array(8);pos=0;finished=!1;destroyed=!1;constructor(e){e=rr(ue(e,32,"key"));let r=me(e,0),n=me(e,2),s=me(e,4),o=me(e,6),i=me(e,8),a=me(e,10),c=me(e,12),f=me(e,14);this.r[0]=r&8191,this.r[1]=(r>>>13|n<<3)&8191,this.r[2]=(n>>>10|s<<6)&7939,this.r[3]=(s>>>7|o<<9)&8191,this.r[4]=(o>>>4|i<<12)&255,this.r[5]=i>>>1&8190,this.r[6]=(i>>>14|a<<2)&8191,this.r[7]=(a>>>11|c<<5)&8065,this.r[8]=(c>>>8|f<<8)&8191,this.r[9]=f>>>5&127;for(let u=0;u<8;u++)this.pad[u]=me(e,16+2*u)}process(e,r,n=!1){let s=n?0:2048,{h:o,r:i}=this,a=i[0],c=i[1],f=i[2],u=i[3],h=i[4],p=i[5],d=i[6],w=i[7],g=i[8],y=i[9],x=me(e,r+0),E=me(e,r+2),b=me(e,r+4),R=me(e,r+6),T=me(e,r+8),O=me(e,r+10),N=me(e,r+12),K=me(e,r+14),_=o[0]+(x&8191),C=o[1]+((x>>>13|E<<3)&8191),F=o[2]+((E>>>10|b<<6)&8191),M=o[3]+((b>>>7|R<<9)&8191),j=o[4]+((R>>>4|T<<12)&8191),B=o[5]+(T>>>1&8191),k=o[6]+((T>>>14|O<<2)&8191),L=o[7]+((O>>>11|N<<5)&8191),v=o[8]+((N>>>8|K<<8)&8191),H=o[9]+(K>>>5|s),I=0,S=I+_*a+C*(5*y)+F*(5*g)+M*(5*w)+j*(5*d);I=S>>>13,S&=8191,S+=B*(5*p)+k*(5*h)+L*(5*u)+v*(5*f)+H*(5*c),I+=S>>>13,S&=8191;let l=I+_*c+C*a+F*(5*y)+M*(5*g)+j*(5*w);I=l>>>13,l&=8191,l+=B*(5*d)+k*(5*p)+L*(5*h)+v*(5*u)+H*(5*f),I+=l>>>13,l&=8191;let m=I+_*f+C*c+F*a+M*(5*y)+j*(5*g);I=m>>>13,m&=8191,m+=B*(5*w)+k*(5*d)+L*(5*p)+v*(5*h)+H*(5*u),I+=m>>>13,m&=8191;let A=I+_*u+C*f+F*c+M*a+j*(5*y);I=A>>>13,A&=8191,A+=B*(5*g)+k*(5*w)+L*(5*d)+v*(5*p)+H*(5*h),I+=A>>>13,A&=8191;let D=I+_*h+C*u+F*f+M*c+j*a;I=D>>>13,D&=8191,D+=B*(5*y)+k*(5*g)+L*(5*w)+v*(5*d)+H*(5*p),I+=D>>>13,D&=8191;let U=I+_*p+C*h+F*u+M*f+j*c;I=U>>>13,U&=8191,U+=B*a+k*(5*y)+L*(5*g)+v*(5*w)+H*(5*d),I+=U>>>13,U&=8191;let P=I+_*d+C*p+F*h+M*u+j*f;I=P>>>13,P&=8191,P+=B*c+k*a+L*(5*y)+v*(5*g)+H*(5*w),I+=P>>>13,P&=8191;let q=I+_*w+C*d+F*p+M*h+j*u;I=q>>>13,q&=8191,q+=B*f+k*c+L*a+v*(5*y)+H*(5*g),I+=q>>>13,q&=8191;let z=I+_*g+C*w+F*d+M*p+j*h;I=z>>>13,z&=8191,z+=B*u+k*f+L*c+v*a+H*(5*y),I+=z>>>13,z&=8191;let V=I+_*y+C*g+F*w+M*d+j*p;I=V>>>13,V&=8191,V+=B*h+k*u+L*f+v*c+H*a,I+=V>>>13,V&=8191,I=(I<<2)+I|0,I=I+S|0,S=I&8191,I=I>>>13,l+=I,o[0]=S,o[1]=l,o[2]=m,o[3]=A,o[4]=D,o[5]=U,o[6]=P,o[7]=q,o[8]=z,o[9]=V}finalize(){let{h:e,pad:r}=this,n=new Uint16Array(10),s=e[1]>>>13;e[1]&=8191;for(let a=2;a<10;a++)e[a]+=s,s=e[a]>>>13,e[a]&=8191;e[0]+=s*5,s=e[0]>>>13,e[0]&=8191,e[1]+=s,s=e[1]>>>13,e[1]&=8191,e[2]+=s,n[0]=e[0]+5,s=n[0]>>>13,n[0]&=8191;for(let a=1;a<10;a++)n[a]=e[a]+s,s=n[a]>>>13,n[a]&=8191;n[9]-=8192;let o=(s^1)-1;for(let a=0;a<10;a++)n[a]&=o;o=~o;for(let a=0;a<10;a++)e[a]=e[a]&o|n[a];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let i=e[0]+r[0];e[0]=i&65535;for(let a=1;a<8;a++)i=(e[a]+r[a]|0)+(i>>>16)|0,e[a]=i&65535;Pe(n)}update(e){$o(this),ue(e),e=rr(e);let{buffer:r,blockLen:n}=this,s=e.length;for(let o=0;o<s;){let i=Math.min(n-this.pos,s-o);if(i===n){for(;n<=s-o;o+=n)this.process(e,o);continue}r.set(e.subarray(o,o+i),this.pos),this.pos+=i,o+=i,this.pos===n&&(this.process(r,0,!1),this.pos=0)}return this}destroy(){this.destroyed=!0,Pe(this.h,this.r,this.buffer,this.pad)}digestInto(e){$o(this),mc(e,this),this.finished=!0;let{buffer:r,h:n}=this,{pos:s}=this;if(s){for(r[s++]=1;s<16;s++)r[s]=0;this.process(r,0,!0)}this.finalize();let o=0;for(let i=0;i<8;i++)e[o++]=n[i]>>>0,e[o++]=n[i]>>>8}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}},Bc=wc(32,t=>new Wo(t));function il(t,e,r,n,s,o=20){let i=t[0],a=t[1],c=t[2],f=t[3],u=e[0],h=e[1],p=e[2],d=e[3],w=e[4],g=e[5],y=e[6],x=e[7],E=s,b=r[0],R=r[1],T=r[2],O=i,N=a,K=c,_=f,C=u,F=h,M=p,j=d,B=w,k=g,L=y,v=x,H=E,I=b,S=R,l=T;for(let A=0;A<o;A+=2)O=O+C|0,H=W(H^O,16),B=B+H|0,C=W(C^B,12),O=O+C|0,H=W(H^O,8),B=B+H|0,C=W(C^B,7),N=N+F|0,I=W(I^N,16),k=k+I|0,F=W(F^k,12),N=N+F|0,I=W(I^N,8),k=k+I|0,F=W(F^k,7),K=K+M|0,S=W(S^K,16),L=L+S|0,M=W(M^L,12),K=K+M|0,S=W(S^K,8),L=L+S|0,M=W(M^L,7),_=_+j|0,l=W(l^_,16),v=v+l|0,j=W(j^v,12),_=_+j|0,l=W(l^_,8),v=v+l|0,j=W(j^v,7),O=O+F|0,l=W(l^O,16),L=L+l|0,F=W(F^L,12),O=O+F|0,l=W(l^O,8),L=L+l|0,F=W(F^L,7),N=N+M|0,H=W(H^N,16),v=v+H|0,M=W(M^v,12),N=N+M|0,H=W(H^N,8),v=v+H|0,M=W(M^v,7),K=K+j|0,I=W(I^K,16),B=B+I|0,j=W(j^B,12),K=K+j|0,I=W(I^K,8),B=B+I|0,j=W(j^B,7),_=_+C|0,S=W(S^_,16),k=k+S|0,C=W(C^k,12),_=_+C|0,S=W(S^_,8),k=k+S|0,C=W(C^k,7);let m=0;n[m++]=i+O|0,n[m++]=a+N|0,n[m++]=c+K|0,n[m++]=f+_|0,n[m++]=u+C|0,n[m++]=h+F|0,n[m++]=p+M|0,n[m++]=d+j|0,n[m++]=w+B|0,n[m++]=g+k|0,n[m++]=y+L|0,n[m++]=x+v|0,n[m++]=E+H|0,n[m++]=b+I|0,n[m++]=R+S|0,n[m++]=T+l|0}var al=vc(il,{counterRight:!1,counterLength:4,allowShortKeys:!1});var cl=new Uint8Array(16),Lc=(t,e)=>{t.update(e);let r=e.length%16;r&&t.update(cl.subarray(r))},fl=new Uint8Array(32);function Ic(t,e,r,n,s){s!==void 0&&ue(s,void 0,"AAD");let o=t(e,r,fl),i=Ec(n.length,s?s.length:0,!0),a=Bc.create(o);s&&Lc(a,s),Lc(a,n),a.update(i);let c=a.digest();return Pe(o,i),c}var ul=t=>(e,r,n)=>({encrypt(o,i){let a=o.length;i=Ur(a+16,i,!1),i.set(o);let c=i.subarray(0,-16);t(e,r,c,c,1);let f=Ic(t,e,r,c,n);return i.set(f,a),Pe(f),i},decrypt(o,i){i=Ur(o.length-16,i,!1);let a=o.subarray(0,-16),c=o.subarray(-16),f=Ic(t,e,r,a,n);if(!bc(c,f))throw Pe(f),new Error("invalid tag");return i.set(o.subarray(0,-16)),t(e,r,i,i,1),Pe(f),i}}),Go=xc({blockSize:64,nonceLength:12,tagLength:16,withAAD:!0},ul(al));function Tc(t,e,r){return xt(t),r===void 0&&(r=new Uint8Array(t.outputLen)),Cr(t,r,e)}var Mr=Uint8Array.of(0),hl=Uint8Array.of();function _c(t,e,r,n=32,s){xt(t),Oe(n,"length"),Ee(e,void 0,"prk");let o=t.outputLen;if(e.length<o)throw new Error('"prk" must be at least HashLen octets');if(n>255*o)throw new Error("Length must be <= 255*HashLen");let i=Math.ceil(n/o);if(r===void 0?r=hl:Ee(r,void 0,"info"),!i)return s&&_e(e),new Uint8Array;let a=s&&i===1?e:new Uint8Array(i*o),{iHash:c,oHash:f}=Cr.create(t,e),u=s?e:new Uint8Array(o),h=i>1?s?.iHash||t.create():void 0;for(let d=0;d<i-1;d++){Mr[0]=d+1;let w=c._cloneInto(h);d&&w.update(u),w.update(r).update(Mr).digestInto(u),f._cloneInto(h).update(u).digestInto(u),a.set(u,o*d)}if(Mr[0]=i,i>1&&c.update(u),c.update(r).update(Mr).digestInto(u),f.update(u).digestInto(u),a.set(u,o*(i-1)),c.destroy(),f.destroy(),h?.destroy(),u!==a&&_e(u),_e(Mr),n===a.length)return a;let p=a.slice(0,n);return _e(a),p}var Wn={hashSHA256(t){return He(t.subarray())},getHKDF(t,e){let r=Tc(He,e,t),s=_c(He,r,void 0,96),o=s.subarray(0,32),i=s.subarray(32,64),a=s.subarray(64,96);return[o,i,a]},generateX25519KeyPair(){let t=vr.utils.randomSecretKey();return{publicKey:vr.getPublicKey(t),privateKey:t}},generateX25519KeyPairFromSeed(t){return{publicKey:vr.getPublicKey(t),privateKey:t}},generateX25519SharedKey(t,e){return vr.getSharedSecret(t.subarray(),e.subarray())},chaCha20Poly1305Encrypt(t,e,r,n){return Go(n,e,r).encrypt(t.subarray())},chaCha20Poly1305Decrypt(t,e,r,n,s){return Go(n,e,r).decrypt(t.subarray(),s)}};var Rc=Wn;function Cc(t){return{generateKeypair:t.generateX25519KeyPair,dh:(e,r)=>t.generateX25519SharedKey(e.privateKey,r).subarray(0,32),encrypt:t.chaCha20Poly1305Encrypt,decrypt:t.chaCha20Poly1305Decrypt,hash:t.hashSHA256,hkdf:t.getHKDF}}var nr=t=>{let e=pe(2);return e[0]=t>>8,e[1]=t,e};nr.bytes=2;var sr=t=>{if(t.length<2)throw RangeError("Could not decode int16BE");if(t instanceof Uint8Array){let e=0;return e+=t[0]<<8,e+=t[1],e}return t.getUint16(0)};sr.bytes=2;function Dc(t){return{xxHandshakeSuccesses:t.registerCounter("libp2p_noise_xxhandshake_successes_total",{help:"Total count of noise xxHandshakes successes_"}),xxHandshakeErrors:t.registerCounter("libp2p_noise_xxhandshake_error_total",{help:"Total count of noise xxHandshakes errors"}),encryptedPackets:t.registerCounter("libp2p_noise_encrypted_packets_total",{help:"Total count of noise encrypted packets successfully"}),decryptedPackets:t.registerCounter("libp2p_noise_decrypted_packets_total",{help:"Total count of noise decrypted packets"}),decryptErrors:t.registerCounter("libp2p_noise_decrypt_errors_total",{help:"Total count of noise decrypt errors"})}}function Zo(t,e){!e.enabled||!tr||(t?(e(`LOCAL_STATIC_PUBLIC_KEY ${Z(t.publicKey,"hex")}`),e(`LOCAL_STATIC_PRIVATE_KEY ${Z(t.privateKey,"hex")}`)):e("Missing local static keys."))}function Xo(t,e){!e.enabled||!tr||(t?(e(`LOCAL_PUBLIC_EPHEMERAL_KEY ${Z(t.publicKey,"hex")}`),e(`LOCAL_PRIVATE_EPHEMERAL_KEY ${Z(t.privateKey,"hex")}`)):e("Missing local ephemeral keys."))}function Oc(t,e){!e.enabled||!tr||e(t?`REMOTE_STATIC_PUBLIC_KEY ${Z(t.subarray(),"hex")}`:"Missing remote static public key.")}function Jo(t,e){!e.enabled||!tr||e(t?`REMOTE_EPHEMERAL_PUBLIC_KEY ${Z(t.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function Qo(t,e,r){!r.enabled||!tr||(r(`CIPHER_STATE_1 ${t.n.getUint64()} ${t.k&&Z(t.k,"hex")}`),r(`CIPHER_STATE_2 ${e.n.getUint64()} ${e.k&&Z(e.k,"hex")}`))}var or=class t extends Error{code;constructor(e="Invalid crypto exchange"){super(e),this.code=t.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var ll=0,dl=4294967295,pl="Cipherstate has reached maximum n, a new handshake must be performed",Gn=class{n;bytes;view;constructor(e=ll){this.n=e,this.bytes=he(12),this.view=new DataView(this.bytes.buffer,this.bytes.byteOffset,this.bytes.byteLength),this.view.setUint32(4,e,!0)}increment(){this.n++,this.view.setUint32(4,this.n,!0)}getBytes(){return this.bytes}getUint64(){return this.n}assertValue(){if(this.n>dl)throw new Error(pl)}};var Ot=he(0),ir=class{k;n;crypto;constructor(e,r=void 0,n=0){this.crypto=e,this.k=r,this.n=new Gn(n)}hasKey(){return!!this.k}encryptWithAd(e,r){if(!this.hasKey())return r;this.n.assertValue();let n=this.crypto.encrypt(r,this.n.getBytes(),e,this.k);return this.n.increment(),n}decryptWithAd(e,r,n){if(!this.hasKey())return r;this.n.assertValue();let s=this.crypto.decrypt(r,this.n.getBytes(),e,this.k,n);return this.n.increment(),s}},ei=class{cs;ck;h;crypto;constructor(e,r){this.crypto=e;let n=re(r,"utf-8");this.h=ml(e,n),this.ck=this.h,this.cs=new ir(e)}mixKey(e){let[r,n]=this.crypto.hkdf(this.ck,e);this.ck=r,this.cs=new ir(this.crypto,n)}mixHash(e){this.h=this.crypto.hash(new G(this.h,e))}encryptAndHash(e){let r=this.cs.encryptWithAd(this.h,e);return this.mixHash(r),r}decryptAndHash(e){let r=this.cs.decryptWithAd(this.h,e);return this.mixHash(e),r}split(){let[e,r]=this.crypto.hkdf(this.ck,Ot);return[new ir(this.crypto,e),new ir(this.crypto,r)]}},ti=class{ss;s;e;rs;re;initiator;crypto;constructor(e){let{crypto:r,protocolName:n,prologue:s,initiator:o,s:i,e:a,rs:c,re:f}=e;this.crypto=r,this.ss=new ei(r,n),this.ss.mixHash(s),this.initiator=o,this.s=i,this.e=a,this.rs=c,this.re=f}writeE(){if(this.e)throw new Error("ephemeral keypair is already set");let e=this.crypto.generateKeypair();return this.ss.mixHash(e.publicKey),this.e=e,e.publicKey}writeS(){if(!this.s)throw new Error("static keypair is not set");return this.ss.encryptAndHash(this.s.publicKey)}writeEE(){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.re))}writeES(){if(this.initiator){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}else{if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}}writeSE(){if(this.initiator){if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}else{if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}}readE(e,r=0){if(this.re)throw new Error("remote ephemeral public key is already set");if(e.byteLength<r+32)throw new Error("message is not long enough");this.re=e.sublist(r,r+32),this.ss.mixHash(this.re)}readS(e,r=0){if(this.rs)throw new Error("remote static public key is already set");let n=32+(this.ss.cs.hasKey()?16:0);if(e.byteLength<r+n)throw new Error("message is not long enough");let s=e.sublist(r,r+n);return this.rs=this.ss.decryptAndHash(s),n}readEE(){this.writeEE()}readES(){this.writeES()}readSE(){this.writeSE()}},Fr=class extends ti{writeMessageA(e){return new G(this.writeE(),this.ss.encryptAndHash(e))}writeMessageB(e){let r=this.writeE();this.writeEE();let n=this.writeS();return this.writeES(),new G(r,n,this.ss.encryptAndHash(e))}writeMessageC(e){let r=this.writeS();return this.writeSE(),new G(r,this.ss.encryptAndHash(e))}readMessageA(e){try{return this.readE(e),this.ss.decryptAndHash(e.sublist(32))}catch(r){throw new or(`handshake stage 0 validation fail: ${r.message}`)}}readMessageB(e){try{this.readE(e),this.readEE();let r=this.readS(e,32);return this.readES(),this.ss.decryptAndHash(e.sublist(32+r))}catch(r){throw new or(`handshake stage 1 validation fail: ${r.message}`)}}readMessageC(e){try{let r=this.readS(e);return this.readSE(),this.ss.decryptAndHash(e.sublist(r))}catch(r){throw new or(`handshake stage 2 validation fail: ${r.message}`)}}};function ml(t,e){if(e.length<=32){let r=he(32);return r.set(e),r}else return t.hash(e)}var Hr;(function(t){let e;t.codec=()=>(e==null&&(e=Tt((o,i,a={})=>{if(a.lengthDelimited!==!1&&i.fork(),o.webtransportCerthashes!=null&&o.webtransportCerthashes.length>0)for(let c of o.webtransportCerthashes)i.uint32(10),i.bytes(c);if(o.streamMuxers!=null&&o.streamMuxers.length>0)for(let c of o.streamMuxers)i.uint32(18),i.string(c);a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={webtransportCerthashes:[],streamMuxers:[]},f=i==null?o.len:o.pos+i;for(;o.pos<f;){let u=o.uint32();switch(u>>>3){case 1:{if(a.limits?.webtransportCerthashes!=null&&c.webtransportCerthashes.length===a.limits.webtransportCerthashes)throw new _t('Decode error - repeated field "webtransportCerthashes" had too many elements');c.webtransportCerthashes.push(o.bytes());break}case 2:{if(a.limits?.streamMuxers!=null&&c.streamMuxers.length===a.limits.streamMuxers)throw new _t('Decode error - repeated field "streamMuxers" had too many elements');c.streamMuxers.push(o.string());break}default:{o.skipType(u&7);break}}}return c},function*(o,i,a,c={}){let f={webtransportCerthashes:0,streamMuxers:0},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let h=o.uint32();switch(h>>>3){case 1:{if(c.limits?.webtransportCerthashes!=null&&f.webtransportCerthashes===c.limits.webtransportCerthashes)throw new _t('Streaming decode error - repeated field "webtransportCerthashes" had too many elements');yield{field:`${a}.webtransportCerthashes[]`,index:f.webtransportCerthashes,value:o.bytes()},f.webtransportCerthashes++;break}case 2:{if(c.limits?.streamMuxers!=null&&f.streamMuxers===c.limits.streamMuxers)throw new _t('Streaming decode error - repeated field "streamMuxers" had too many elements');yield{field:`${a}.streamMuxers[]`,index:f.streamMuxers,value:o.string()},f.streamMuxers++;break}default:{o.skipType(h&7);break}}}})),e);function r(o){return Lt(o,t.codec())}t.encode=r;function n(o,i){return vt(o,t.codec(),i)}t.decode=n;function s(o,i){return It(o,t.codec(),i)}t.stream=s})(Hr||(Hr={}));var qr;(function(t){let e;t.codec=()=>(e==null&&(e=Tt((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.identityKey!=null&&o.identityKey.byteLength>0&&(i.uint32(10),i.bytes(o.identityKey)),o.identitySig!=null&&o.identitySig.byteLength>0&&(i.uint32(18),i.bytes(o.identitySig)),o.extensions!=null&&(i.uint32(34),Hr.codec().encode(o.extensions,i)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={identityKey:he(0),identitySig:he(0)},f=i==null?o.len:o.pos+i;for(;o.pos<f;){let u=o.uint32();switch(u>>>3){case 1:{c.identityKey=o.bytes();break}case 2:{c.identitySig=o.bytes();break}case 4:{c.extensions=Hr.codec().decode(o,o.uint32(),{limits:a.limits?.extensions});break}default:{o.skipType(u&7);break}}}return c},function*(o,i,a,c={}){let f=i==null?o.len:o.pos+i;for(;o.pos<f;){let u=o.uint32();switch(u>>>3){case 1:{yield{field:`${a}.identityKey`,value:o.bytes()};break}case 2:{yield{field:`${a}.identitySig`,value:o.bytes()};break}case 4:{yield*Hr.codec().stream(o,o.uint32(),`${a}.extensions`,{limits:c.limits?.extensions});break}default:{o.skipType(u&7);break}}}})),e);function r(o){return Lt(o,t.codec())}t.encode=r;function n(o,i){return vt(o,t.codec(),i)}t.decode=n;function s(o,i){return It(o,t.codec(),i)}t.stream=s})(qr||(qr={}));async function ni(t,e,r){let n=await t.sign(Kc(e));return qr.encode({identityKey:nt(t.publicKey),identitySig:n,extensions:r})}async function si(t,e,r){try{let n=qr.decode(t),s=Dr(n.identityKey);if(r?.equals(s)===!1)throw new Error(`Payload identity key ${s} does not match expected remote identity key ${r}`);if(!e)throw new Error("Remote static does not exist");let o=Kc(e);if(!await s.verify(o,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new zr(n.message)}}function Kc(t){let e=re("noise-libp2p-static-key:");return t instanceof Uint8Array?gt([e,t],e.length+t.length):(t.prepend(e),t)}var ri=class extends zn{stream;handshake;metrics;decoder;constructor(e,r,n){super({log:e.log,inactivityTimeout:e.inactivityTimeout,maxReadBufferLength:e.maxReadBufferLength,direction:e.direction}),this.stream=e,this.handshake=r,this.metrics=n,this.decoder=new Vn({lengthDecoder:sr,maxBufferSize:16*1024*1024,encodingLength:()=>2});let s=c=>{try{for(let f of this.decoder.decode(c.data))this.onData(this.decrypt(f))}catch(f){this.abort(f)}};this.stream.addEventListener("message",s);let o=c=>{c.error!=null?c.local===!0?this.abort(c.error):this.onRemoteReset():this.onTransportClosed()};this.stream.addEventListener("close",o);let i=()=>{this.safeDispatchEvent("drain")};this.stream.addEventListener("drain",i);let a=()=>{this.onRemoteCloseWrite()};this.stream.addEventListener("remoteCloseWrite",a)}encrypt(e){let r=new G;for(let n=0;n<e.byteLength;n+=65519){let s=n+65519;s>e.byteLength&&(s=e.byteLength);let o;e instanceof Uint8Array?o=this.handshake.encrypt(e.subarray(n,s)):o=this.handshake.encrypt(e.sublist(n,s)),this.metrics?.encryptedPackets.increment(),r.append(nr(o.byteLength)),r.append(o)}return r}decrypt(e){let r=new G;for(let n=0;n<e.byteLength;n+=65535){let s=n+65535;if(s>e.byteLength&&(s=e.byteLength),s-jo<n)throw new Error("Invalid chunk");let o;e instanceof Uint8Array?o=e.subarray(n,s):o=e.sublist(n,s);let i=e.subarray(n,s-jo);try{let a=this.handshake.decrypt(o,i);this.metrics?.decryptedPackets.increment(),r.append(a)}catch(a){throw this.metrics?.decryptErrors.increment(),a}}return r}close(e){return this.stream.close(e)}sendPause(){this.stream.pause()}sendResume(){this.stream.resume()}sendReset(e){this.stream.abort(e)}sendData(e){return{sentBytes:e.byteLength,canSendMore:this.stream.send(this.encrypt(e))}}};function oi(t,e,r){return new ri(t,e,r)}async function Uc(t,e){let{log:r,connection:n,crypto:s,privateKey:o,prologue:i,s:a,remoteIdentityKey:c,extensions:f}=t,u=await ni(o,a.publicKey,f),h=new Fr({crypto:s,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:i,s:a});Zo(h.s,r),r.trace("Stage 0 - Initiator starting to send first message."),await n.write(h.writeMessageA(Ot),e),r.trace("Stage 0 - Initiator finished sending first message."),Xo(h.e,r),r.trace("Stage 1 - Initiator waiting to receive first message from responder...");let p=h.readMessageB(await n.read(e));r.trace("Stage 1 - Initiator received the message."),Jo(h.re,r),Oc(h.rs,r),r.trace("Initiator going to check remote's signature...");let d=await si(p,h.rs,c);r.trace("All good with the signature!"),r.trace("Stage 2 - Initiator sending third handshake message."),await n.write(h.writeMessageC(u),e),r.trace("Stage 2 - Initiator sent message with signed payload.");let[w,g]=h.ss.split();return Qo(w,g,r),{payload:d,encrypt:y=>w.encryptWithAd(Ot,y),decrypt:(y,x)=>g.decryptWithAd(Ot,y,x)}}async function Pc(t,e){let{log:r,connection:n,crypto:s,privateKey:o,prologue:i,s:a,remoteIdentityKey:c,extensions:f}=t,u=await ni(o,a.publicKey,f),h=new Fr({crypto:s,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:i,s:a});Zo(h.s,r),r.trace("Stage 0 - Responder waiting to receive first message."),h.readMessageA(await n.read(e)),r.trace("Stage 0 - Responder received first message."),Jo(h.re,r),r.trace("Stage 1 - Responder sending out first message with signed payload and static key."),await n.write(h.writeMessageB(u),e),r.trace("Stage 1 - Responder sent the second handshake message with signed payload."),Xo(h.e,r),r.trace("Stage 2 - Responder waiting for third handshake message...");let p=h.readMessageC(await n.read(e));r.trace("Stage 2 - Responder received the message, finished handshake.");let d=await si(p,h.rs,c),[w,g]=h.ss.split();return Qo(w,g,r),{payload:d,encrypt:y=>g.encryptWithAd(Ot,y),decrypt:(y,x)=>w.decryptWithAd(Ot,y,x)}}var Xn=class{protocol="/noise";crypto;prologue;staticKey;extensions;metrics;components;log;constructor(e,r={}){let{staticNoiseKey:n,extensions:s,crypto:o,prologueBytes:i}=r,{metrics:a}=e;this.components=e,this.log=e.logger.forComponent("libp2p:noise");let c=o??Rc;this.crypto=Cc(c),this.extensions={webtransportCerthashes:[],...s},this.metrics=a?Dc(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=i??he(0)}[Symbol.toStringTag]="@libp2p/noise";[ai]=["@libp2p/connection-encryption","@libp2p/noise"];async secureOutbound(e,r){let n=e.log?.newScope("noise")??this.log,s=zo(e,{lengthEncoder:nr,lengthDecoder:sr,maxDataLength:65535}),o=await this.performHandshakeInitiator(s,this.components.privateKey,n,r?.remotePeer?.publicKey,r),i=Dr(o.payload.identityKey);return{connection:oi(s.unwrap(),o,this.metrics),remoteExtensions:o.payload.extensions,remotePeer:Uo(i),streamMuxer:r?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(o.payload.extensions?.streamMuxers)}}getStreamMuxer(e){if(e==null||e.length===0)return;let r=this.components.upgrader.getStreamMuxers();if(r!=null)for(let n of e){let s=r.get(n);if(s!=null)return s}if(e.length)throw new jr("Early muxer negotiation was requested but the initiator and responder had no common muxers")}async secureInbound(e,r){let n=e.log?.newScope("noise")??this.log,s=zo(e,{lengthEncoder:nr,lengthDecoder:sr,maxDataLength:65535}),o=await this.performHandshakeResponder(s,this.components.privateKey,n,r?.remotePeer?.publicKey,r),i=Dr(o.payload.identityKey);return{connection:oi(s.unwrap(),o,this.metrics),remoteExtensions:o.payload.extensions,remotePeer:Uo(i),streamMuxer:r?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(o.payload.extensions?.streamMuxers)}}async performHandshakeInitiator(e,r,n,s,o){let i,a=o?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{i=await Uc({connection:e,privateKey:r,remoteIdentityKey:s,log:n.newScope("xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:{streamMuxers:a,webtransportCerthashes:[],...this.extensions}},o),this.metrics?.xxHandshakeSuccesses.increment()}catch(c){throw this.metrics?.xxHandshakeErrors.increment(),c}return i}async performHandshakeResponder(e,r,n,s,o){let i,a=o?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{i=await Pc({connection:e,privateKey:r,remoteIdentityKey:s,log:n.newScope("xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:{streamMuxers:a,webtransportCerthashes:[],...this.extensions}},o),this.metrics?.xxHandshakeSuccesses.increment()}catch(c){throw this.metrics?.xxHandshakeErrors.increment(),c}return i}};function yl(t={}){return e=>new Xn(e,t)}return Vc(gl);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
|
-
@noble/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
@noble/curves/
|
|
9
|
-
@noble/curves/
|
|
10
|
-
@noble/curves/
|
|
11
|
-
@noble/curves/
|
|
12
|
-
@noble/curves/
|
|
13
|
-
@noble/curves/
|
|
14
|
-
@noble/curves/esm/abstract/weierstrass.js:
|
|
15
|
-
@noble/curves/esm/_shortw_utils.js:
|
|
16
|
-
@noble/curves/esm/secp256k1.js:
|
|
5
|
+
@noble/curves/utils.js:
|
|
6
|
+
@noble/curves/abstract/modular.js:
|
|
7
|
+
@noble/curves/abstract/curve.js:
|
|
8
|
+
@noble/curves/abstract/edwards.js:
|
|
9
|
+
@noble/curves/abstract/montgomery.js:
|
|
10
|
+
@noble/curves/ed25519.js:
|
|
11
|
+
@noble/curves/abstract/der.js:
|
|
12
|
+
@noble/curves/abstract/weierstrass.js:
|
|
13
|
+
@noble/curves/secp256k1.js:
|
|
17
14
|
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
18
15
|
|
|
19
|
-
@noble/ciphers/
|
|
16
|
+
@noble/ciphers/utils.js:
|
|
20
17
|
(*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) *)
|
|
21
18
|
*/
|
|
22
19
|
return Libp2PNoise}));
|