@libp2p/noise 17.0.1-71e8ee163 → 17.0.2

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