@libp2p/noise 16.1.4-a02cb0461 → 16.1.4-e8398d97e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +2 -2
- package/package.json +15 -15
package/dist/index.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PNoise = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PNoise=(()=>{var Pn=Object.defineProperty;var xc=Object.getOwnPropertyDescriptor;var wc=Object.getOwnPropertyNames;var Ec=Object.prototype.hasOwnProperty;var xt=(e,t)=>{for(var r in t)Pn(e,r,{get:t[r],enumerable:!0})},Sc=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of wc(t))!Ec.call(e,s)&&s!==r&&Pn(e,s,{get:()=>t[s],enumerable:!(n=xc(t,s))||n.enumerable});return e};var vc=e=>Sc(Pn({},"__esModule",{value:!0}),e);var Fh={};xt(Fh,{noise:()=>Vh,pureJsCrypto:()=>Kn});var kr=class extends Error{static name="UnexpectedPeerError";constructor(t="Unexpected Peer"){super(t),this.name="UnexpectedPeerError"}},Mr=class extends Error{static name="InvalidCryptoExchangeError";constructor(t="Invalid crypto exchange"){super(t),this.name="InvalidCryptoExchangeError"}},tt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Te=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Or=class extends Error{static name="StreamResetError";constructor(t="The stream has been reset"){super(t),this.name="StreamResetError"}};var he=class extends Error{static name="StreamStateError";constructor(t="The stream is in an invalid state"){super(t),this.name="StreamStateError"}},cr=class extends Error{static name="StreamBufferError";constructor(t="The stream buffer was full"){super(t),this.name="StreamBufferError"}};var Ce=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Hr=class extends Event{data;constructor(t,r){super("message",r),this.data=t}},Ke=class extends Event{error;local;constructor(t,r,n){super("close",n),this.error=r,this.local=t}},qr=class extends Ke{constructor(t,r){super(!0,t,r)}},Vr=class extends Ke{constructor(t,r){super(!1,t,r)}};var Nn=Symbol.for("@libp2p/peer-id");var Fr=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let r=this.#t.get(t);return r==null?0:r.length}addEventListener(t,r,n){super.addEventListener(t,r,n);let s=this.#t.get(t);s==null&&(s=[],this.#t.set(t,s)),s.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,r,n){super.removeEventListener(t.toString(),r??null,n);let s=this.#t.get(t);s!=null&&(s=s.filter(({callback:o})=>o!==r),this.#t.set(t,s))}dispatchEvent(t){let r=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:s})=>!s),this.#t.set(t.type,n)),r}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var $o=Symbol.for("@libp2p/service-capabilities"),Wh=Symbol.for("@libp2p/service-dependencies");var qn={};xt(qn,{base58btc:()=>rt,base58flickr:()=>Cc});var Sl=new Uint8Array(0);function Zo(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Pt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function Wo(e){return new TextEncoder().encode(e)}function Yo(e){return new TextDecoder().decode(e)}function Ac(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var s=0;s<e.length;s++){var o=e.charAt(s),i=o.charCodeAt(0);if(r[i]!==255)throw new TypeError(o+" is ambiguous");r[i]=s}var a=e.length,c=e.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function h(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var w=0,g=0,x=0,B=p.length;x!==B&&p[x]===0;)x++,w++;for(var E=(B-x)*f+1>>>0,R=new Uint8Array(E);x!==B;){for(var k=p[x],O=0,M=E-1;(k!==0||O<g)&&M!==-1;M--,O++)k+=256*R[M]>>>0,R[M]=k%a>>>0,k=k/a>>>0;if(k!==0)throw new Error("Non-zero carry");g=O,x++}for(var P=E-g;P!==E&&R[P]===0;)P++;for(var S=c.repeat(w);P<E;++P)S+=e.charAt(R[P]);return S}function l(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var w=0;if(p[w]!==" "){for(var g=0,x=0;p[w]===c;)g++,w++;for(var B=(p.length-w)*u+1>>>0,E=new Uint8Array(B);p[w];){var R=r[p.charCodeAt(w)];if(R===255)return;for(var k=0,O=B-1;(R!==0||k<x)&&O!==-1;O--,k++)R+=a*E[O]>>>0,E[O]=R%256>>>0,R=R/256>>>0;if(R!==0)throw new Error("Non-zero carry");x=k,w++}if(p[w]!==" "){for(var M=B-x;M!==B&&E[M]===0;)M++;for(var P=new Uint8Array(g+(B-M)),S=g;M!==B;)P[S++]=E[M++];return P}}}function d(p){var w=l(p);if(w)return w;throw new Error(`Non-${t} character`)}return{encode:h,decodeUnsafe:l,decode:d}}var Bc=Ac,Lc=Bc,Jo=Lc;var kn=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Mn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let s=r.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Qo(this,t)}},On=class{decoders;constructor(t){this.decoders=t}or(t){return Qo(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Qo(e,t){return new On({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Hn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,s){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=s,this.encoder=new kn(t,r,n),this.decoder=new Mn(t,r,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Re({name:e,prefix:t,encode:r,decode:n}){return new Hn(e,t,r,n)}function Jt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:s}=Jo(r,e);return Re({prefix:t,name:e,encode:n,decode:o=>Pt(s(o))})}function _c(e,t,r,n){let s=e.length;for(;e[s-1]==="=";)--s;let o=new Uint8Array(s*r/8|0),i=0,a=0,c=0;for(let u=0;u<s;++u){let f=t[e[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,o[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return o}function Ic(e,t,r){let n=t[t.length-1]==="=",s=(1<<r)-1,o="",i=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],i+=8;i>r;)i-=r,o+=t[s&a>>i];if(i!==0&&(o+=t[s&a<<r-i]),n)for(;(o.length*r&7)!==0;)o+="=";return o}function Tc(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function et({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let s=Tc(n);return Re({prefix:t,name:e,encode(o){return Ic(o,n,r)},decode(o){return _c(o,s,r,e)}})}var rt=Jt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Cc=Jt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Vn={};xt(Vn,{base32:()=>Ue,base32hex:()=>Dc,base32hexpad:()=>Nc,base32hexpadupper:()=>kc,base32hexupper:()=>Pc,base32pad:()=>Rc,base32padupper:()=>Uc,base32upper:()=>Kc,base32z:()=>Mc});var Ue=et({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Kc=et({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Rc=et({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Uc=et({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Dc=et({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Pc=et({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Nc=et({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),kc=et({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Mc=et({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Fn={};xt(Fn,{base36:()=>fr,base36upper:()=>Oc});var fr=Jt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Oc=Jt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Hc=ri,ti=128,qc=127,Vc=~qc,Fc=Math.pow(2,31);function ri(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Fc;)t[r++]=e&255|ti,e/=128;for(;e&Vc;)t[r++]=e&255|ti,e>>>=7;return t[r]=e|0,ri.bytes=r-n+1,t}var zc=zn,Gc=128,ei=127;function zn(e,n){var r=0,n=n||0,s=0,o=n,i,a=e.length;do{if(o>=a)throw zn.bytes=0,new RangeError("Could not decode varint");i=e[o++],r+=s<28?(i&ei)<<s:(i&ei)*Math.pow(2,s),s+=7}while(i>=Gc);return zn.bytes=o-n,r}var jc=Math.pow(2,7),$c=Math.pow(2,14),Zc=Math.pow(2,21),Wc=Math.pow(2,28),Yc=Math.pow(2,35),Xc=Math.pow(2,42),Jc=Math.pow(2,49),Qc=Math.pow(2,56),tf=Math.pow(2,63),ef=function(e){return e<jc?1:e<$c?2:e<Zc?3:e<Wc?4:e<Yc?5:e<Xc?6:e<Jc?7:e<Qc?8:e<tf?9:10},rf={encode:Hc,decode:zc,encodingLength:ef},nf=rf,ur=nf;function hr(e,t=0){return[ur.decode(e,t),ur.decode.bytes]}function De(e,t,r=0){return ur.encode(e,t,r),t}function Pe(e){return ur.encodingLength(e)}function Kt(e,t){let r=t.byteLength,n=Pe(e),s=n+Pe(r),o=new Uint8Array(s+r);return De(e,o,0),De(r,o,n),o.set(t,s),new Ne(e,r,t,o)}function Gn(e){let t=Pt(e),[r,n]=hr(t),[s,o]=hr(t.subarray(n)),i=t.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new Ne(r,s,i,t)}function ni(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Zo(e.bytes,r.bytes)}}var Ne=class{code;size;digest;bytes;constructor(t,r,n,s){this.code=t,this.size=r,this.digest=n,this.bytes=s}};function si(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return of(r,jn(e),t??rt.encoder);default:return af(r,jn(e),t??Ue.encoder)}}var oi=new WeakMap;function jn(e){let t=oi.get(e);if(t==null){let r=new Map;return oi.set(e,r),r}return t}var ht=class e{code;version;multihash;bytes;"/";constructor(t,r,n,s){this.code=r,this.version=t,this.multihash=n,this.bytes=s,this["/"]=s}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==lr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==cf)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=Kt(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&ni(t.multihash,n.multihash)}toString(t){return si(this,t)}toJSON(){return{"/":si(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:s,multihash:o,bytes:i}=r;return new e(n,s,o,i??ii(n,s,o.bytes))}else if(r[ff]===!0){let{version:n,multihash:s,code:o}=r,i=Gn(s);return e.create(n,o,i)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==lr)throw new Error(`Version 0 CID must use dag-pb (code: ${lr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let s=ii(t,r,n.bytes);return new e(t,r,n,s)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,lr,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,s=Pt(t.subarray(n,n+r.multihashSize));if(s.byteLength!==r.multihashSize)throw new Error("Incorrect length");let o=s.subarray(r.multihashSize-r.digestSize),i=new Ne(r.multihashCode,r.digestSize,o,s);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[h,l]=hr(t.subarray(r));return r+=l,h},s=n(),o=lr;if(s===18?(s=0,r=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(t,r){let[n,s]=sf(t,r),o=e.decode(s);if(o.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return jn(o).set(n,t),o}};function sf(e,t){switch(e[0]){case"Q":{let r=t??rt;return[rt.prefix,r.decode(`${rt.prefix}${e}`)]}case rt.prefix:{let r=t??rt;return[rt.prefix,r.decode(e)]}case Ue.prefix:{let r=t??Ue;return[Ue.prefix,r.decode(e)]}case fr.prefix:{let r=t??fr;return[fr.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function of(e,t,r){let{prefix:n}=r;if(n!==rt.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let s=t.get(n);if(s==null){let o=r.encode(e).slice(1);return t.set(n,o),o}else return s}function af(e,t,r){let{prefix:n}=r,s=t.get(n);if(s==null){let o=r.encode(e);return t.set(n,o),o}else return s}var lr=112,cf=18;function ii(e,t,r){let n=Pe(e),s=n+Pe(t),o=new Uint8Array(s+r.byteLength);return De(e,o,0),De(t,o,n),o.set(r,s),o}var ff=Symbol.for("@ipld/js-cid/CID");var $n={};xt($n,{identity:()=>Rt});var ai=0,uf="identity",ci=Pt;function hf(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return Kt(ai,ci(e))}var Rt={code:ai,name:uf,encode:ci,digest:hf};function yt(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function nt(e=0){return new Uint8Array(e)}function ct(e=0){return new Uint8Array(e)}function le(e,t){t==null&&(t=e.reduce((s,o)=>s+o.length,0));let r=ct(t),n=0;for(let s of e)r.set(s,n),n+=s.length;return r}var ui=Symbol.for("@achingbrain/uint8arraylist");function fi(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let s=r+n.byteLength;if(t<s)return{buf:n,index:t-r};r=s}throw new RangeError("index is out of bounds")}function Gr(e){return!!e?.[ui]}var G=class e{bufs;length;[ui]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Gr(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Gr(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=fi(this.bufs,t);return r.buf[r.index]}set(t,r){let n=fi(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(Gr(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:s}=this._subList(t,r);return le(n,s)}subarray(t,r){let{bufs:n,length:s}=this._subList(t,r);return n.length===1?n[0]:le(n,s)}sublist(t,r){let{bufs:n,length:s}=this._subList(t,r),o=new e;return o.length=s,o.bufs=[...n],o}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],s=0;for(let o=0;o<this.bufs.length;o++){let i=this.bufs[o],a=s,c=a+i.byteLength;if(s=c,t>=c)continue;let u=t>=a&&t<c,f=r>a&&r<=c;if(u&&f){if(t===a&&r===c){n.push(i);break}let h=t-a;n.push(i.subarray(h,h+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Gr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let o=256,i=new Int32Array(o);for(let h=0;h<o;h++)i[h]=-1;for(let h=0;h<s;h++)i[n[h]]=h;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let h=r;h<=c;h+=f){f=0;for(let l=u;l>=0;l--){let d=this.get(h+l);if(n[l]!==d){f=Math.max(1,l-a[d]);break}}if(f===0)return h}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=ct(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let s=nt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,r,n),this.write(s,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let s=nt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,r,n),this.write(s,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let s=nt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,r,n),this.write(s,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=ct(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let s=nt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,r,n),this.write(s,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let s=nt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,r,n),this.write(s,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let s=nt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,r,n),this.write(s,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let s=nt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,r,n),this.write(s,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let s=nt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,r,n),this.write(s,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!yt(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((s,o)=>s+o.byteLength,0)),n.length=r,n}};var Zn={};xt(Zn,{base10:()=>df});var df=Jt({prefix:"9",name:"base10",alphabet:"0123456789"});var Wn={};xt(Wn,{base16:()=>pf,base16upper:()=>mf});var pf=et({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),mf=et({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Yn={};xt(Yn,{base2:()=>yf});var yf=et({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Xn={};xt(Xn,{base256emoji:()=>Ef});var hi=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),gf=hi.reduce((e,t,r)=>(e[r]=t,e),[]),bf=hi.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function xf(e){return e.reduce((t,r)=>(t+=gf[r],t),"")}function wf(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let s=bf[n];if(s==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(s)}return new Uint8Array(t)}var Ef=Re({prefix:"\u{1F680}",name:"base256emoji",encode:xf,decode:wf});var Jn={};xt(Jn,{base64:()=>Sf,base64pad:()=>vf,base64url:()=>Af,base64urlpad:()=>Bf});var Sf=et({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),vf=et({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Af=et({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Bf=et({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Qn={};xt(Qn,{base8:()=>Lf});var Lf=et({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ts={};xt(ts,{identity:()=>_f});var _f=Re({prefix:"\0",name:"identity",encode:e=>Yo(e),decode:e=>Wo(e)});var sd=new TextEncoder,od=new TextDecoder;var ns={};xt(ns,{sha256:()=>jr,sha512:()=>Kf});var Cf=20;function rs({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:s}){return new es(e,t,r,n,s)}var es=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,s,o){this.name=t,this.code=r,this.encode=n,this.minDigestLength=s??Cf,this.maxDigestLength=o}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?li(n,this.code,r?.truncate):n.then(s=>li(s,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function li(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Kt(t,e)}function pi(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var jr=rs({name:"sha2-256",code:18,encode:pi("SHA-256")}),Kf=rs({name:"sha2-512",code:19,encode:pi("SHA-512")});var ss={...ts,...Yn,...Qn,...Zn,...Wn,...Vn,...Fn,...qn,...Jn,...Xn},gd={...ns,...$n};function yi(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var mi=yi("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),os=yi("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=ct(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Rf={utf8:mi,"utf-8":mi,hex:ss.base16,latin1:os,ascii:os,binary:os,...ss},$r=Rf;function Y(e,t="utf8"){let r=$r[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function j(e,t="utf8"){let r=$r[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Uf=parseInt("11111",2),is=parseInt("10000000",2),Df=parseInt("01111111",2),gi={0:dr,1:dr,2:Pf,3:Mf,4:Of,5:kf,6:Nf,16:dr,22:dr,48:dr};function Nt(e,t={offset:0}){let r=e[t.offset]&Uf;if(t.offset++,gi[r]!=null)return gi[r](e,t);throw new Error("No decoder for tag "+r)}function pr(e,t){let r=0;if((e[t.offset]&is)===is){let n=e[t.offset]&Df,s="0x";t.offset++;for(let o=0;o<n;o++,t.offset++)s+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(s,16)}else r=e[t.offset],t.offset++;return r}function dr(e,t){pr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Nt(e,t);if(n===null)break;r.push(n)}return r}function Pf(e,t){let r=pr(e,t),n=t.offset,s=t.offset+r,o=[];for(let i=n;i<s;i++)i===n&&e[i]===0||o.push(e[i]);return t.offset+=r,Uint8Array.from(o)}function Nf(e,t){let r=pr(e,t),n=t.offset+r,s=e[t.offset];t.offset++;let o=0,i=0;s<40?(o=0,i=s):s<80?(o=1,i=s-40):(o=2,i=s-80);let a=`${o}.${i}`,c=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let h=0;h<c.length;h++)f+=c[h]<<h*7;a+=`.${f}`,c=[]}}return a}function kf(e,t){return t.offset++,null}function Mf(e,t){let r=pr(e,t),n=e[t.offset];t.offset++;let s=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return s}function Of(e,t){let r=pr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Hf(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new G;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function as(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Hf(e.byteLength);return new G(Uint8Array.from([t.byteLength|is]),t)}function wt(e){let t=new G,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new G(Uint8Array.from([2]),as(t),t)}function Zr(e){let t=Uint8Array.from([0]),r=new G(t,e);return new G(Uint8Array.from([3]),as(r),r)}function Qt(e,t=48){let r=new G;for(let n of e)r.append(n);return new G(Uint8Array.from([t]),as(r),r)}async function bi(e,t,r,n){let s=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let o=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},s,t,r.subarray());return n?.signal?.throwIfAborted(),o}var qf=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Vf=Uint8Array.from([6,5,43,129,4,0,34]),Ff=Uint8Array.from([6,5,43,129,4,0,35]),zf={ext:!0,kty:"EC",crv:"P-256"},Gf={ext:!0,kty:"EC",crv:"P-384"},jf={ext:!0,kty:"EC",crv:"P-521"},cs=32,fs=48,us=66;function xi(e){let t=Nt(e);return wi(t)}function wi(e){let t=e[1][1][0],r=1,n,s;if(t.byteLength===cs*2+1)return n=j(t.subarray(r,r+cs),"base64url"),s=j(t.subarray(r+cs),"base64url"),new Me({...zf,key_ops:["verify"],x:n,y:s});if(t.byteLength===fs*2+1)return n=j(t.subarray(r,r+fs),"base64url"),s=j(t.subarray(r+fs),"base64url"),new Me({...Gf,key_ops:["verify"],x:n,y:s});if(t.byteLength===us*2+1)return n=j(t.subarray(r,r+us),"base64url"),s=j(t.subarray(r+us),"base64url"),new Me({...jf,key_ops:["verify"],x:n,y:s});throw new tt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Ei(e){return Qt([wt(Uint8Array.from([1])),Qt([$f(e.crv)],160),Qt([Zr(new G(Uint8Array.from([4]),Y(e.x??"","base64url"),Y(e.y??"","base64url")))],161)]).subarray()}function $f(e){if(e==="P-256")return qf;if(e==="P-384")return Vf;if(e==="P-521")return Ff;throw new tt(`Invalid curve ${e}`)}var Me=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Ei(this.jwk)),this._raw}toMultihash(){return Rt.digest(te(this))}toCID(){return ht.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:yt(this.raw,t.raw)}async verify(t,r,n){return bi(this.jwk,r,t,n)}};var de=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Mt(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function pe(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function lt(e,...t){if(!Mt(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function me(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");pe(e.outputLen),pe(e.blockLen)}function He(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function vi(e,t){lt(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function _t(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Wr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function It(e,t){return e<<32-t|e>>>t}var Ai=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Zf=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function At(e){if(lt(e),Ai)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Zf[e[r]];return t}var kt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Si(e){if(e>=kt._0&&e<=kt._9)return e-kt._0;if(e>=kt.A&&e<=kt.F)return e-(kt.A-10);if(e>=kt.a&&e<=kt.f)return e-(kt.a-10)}function ye(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Ai)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let s=0,o=0;s<r;s++,o+=2){let i=Si(e.charCodeAt(o)),a=Si(e.charCodeAt(o+1));if(i===void 0||a===void 0){let c=e[o]+e[o+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+o)}n[s]=i*16+a}return n}function hs(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function ee(e){return typeof e=="string"&&(e=hs(e)),lt(e),e}function gt(...e){let t=0;for(let n=0;n<e.length;n++){let s=e[n];lt(s),t+=s.length}let r=new Uint8Array(t);for(let n=0,s=0;n<e.length;n++){let o=e[n];r.set(o,s),s+=o.length}return r}var Oe=class{};function ls(e){let t=n=>e().update(ee(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function re(e=32){if(de&&typeof de.getRandomValues=="function")return de.getRandomValues(new Uint8Array(e));if(de&&typeof de.randomBytes=="function")return Uint8Array.from(de.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function Wf(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let s=BigInt(32),o=BigInt(4294967295),i=Number(r>>s&o),a=Number(r&o),c=n?4:0,u=n?0:4;e.setUint32(t+c,i,n),e.setUint32(t+u,a,n)}function Bi(e,t,r){return e&t^~e&r}function Li(e,t,r){return e&t^e&r^t&r}var mr=class extends Oe{constructor(t,r,n,s){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(t),this.view=Wr(this.buffer)}update(t){He(this),t=ee(t),lt(t);let{view:r,buffer:n,blockLen:s}=this,o=t.length;for(let i=0;i<o;){let a=Math.min(s-this.pos,o-i);if(a===s){let c=Wr(t);for(;s<=o-i;i+=s)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===s&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){He(this),vi(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:s,isLE:o}=this,{pos:i}=this;r[i++]=128,_t(this.buffer.subarray(i)),this.padOffset>s-i&&(this.process(n,0),i=0);for(let h=i;h<s;h++)r[h]=0;Wf(n,s-8,BigInt(this.length*8),o),this.process(n,0);let a=Wr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<u;h++)a.setUint32(4*h,f[h],o)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:s,finished:o,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=o,t.length=s,t.pos=a,s%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Ot=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ft=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Yr=BigInt(4294967295),_i=BigInt(32);function Yf(e,t=!1){return t?{h:Number(e&Yr),l:Number(e>>_i&Yr)}:{h:Number(e>>_i&Yr)|0,l:Number(e&Yr)|0}}function Ii(e,t=!1){let r=e.length,n=new Uint32Array(r),s=new Uint32Array(r);for(let o=0;o<r;o++){let{h:i,l:a}=Yf(e[o],t);[n[o],s[o]]=[i,a]}return[n,s]}var ds=(e,t,r)=>e>>>r,ps=(e,t,r)=>e<<32-r|t>>>r,ge=(e,t,r)=>e>>>r|t<<32-r,be=(e,t,r)=>e<<32-r|t>>>r,yr=(e,t,r)=>e<<64-r|t>>>r-32,gr=(e,t,r)=>e>>>r-32|t<<64-r;function Ut(e,t,r,n){let s=(t>>>0)+(n>>>0);return{h:e+r+(s/2**32|0)|0,l:s|0}}var Ti=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Ci=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Ki=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Ri=(e,t,r,n,s)=>t+r+n+s+(e/2**32|0)|0,Ui=(e,t,r,n,s)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(s>>>0),Di=(e,t,r,n,s,o)=>t+r+n+s+o+(e/2**32|0)|0;var Jf=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),ne=new Uint32Array(64),Xr=class extends mr{constructor(t=32){super(64,t,8,!1),this.A=Ot[0]|0,this.B=Ot[1]|0,this.C=Ot[2]|0,this.D=Ot[3]|0,this.E=Ot[4]|0,this.F=Ot[5]|0,this.G=Ot[6]|0,this.H=Ot[7]|0}get(){let{A:t,B:r,C:n,D:s,E:o,F:i,G:a,H:c}=this;return[t,r,n,s,o,i,a,c]}set(t,r,n,s,o,i,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,r){for(let h=0;h<16;h++,r+=4)ne[h]=t.getUint32(r,!1);for(let h=16;h<64;h++){let l=ne[h-15],d=ne[h-2],p=It(l,7)^It(l,18)^l>>>3,w=It(d,17)^It(d,19)^d>>>10;ne[h]=w+ne[h-7]+p+ne[h-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:u,H:f}=this;for(let h=0;h<64;h++){let l=It(a,6)^It(a,11)^It(a,25),d=f+l+Bi(a,c,u)+Jf[h]+ne[h]|0,w=(It(n,2)^It(n,13)^It(n,22))+Li(n,s,o)|0;f=u,u=c,c=a,a=i+d|0,i=o,o=s,s=n,n=d+w|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,s,o,i,a,c,u,f)}roundClean(){_t(ne)}destroy(){this.set(0,0,0,0,0,0,0,0),_t(this.buffer)}};var Pi=Ii(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),Qf=Pi[0],tu=Pi[1],se=new Uint32Array(80),oe=new Uint32Array(80),ms=class extends mr{constructor(t=64){super(128,t,16,!1),this.Ah=ft[0]|0,this.Al=ft[1]|0,this.Bh=ft[2]|0,this.Bl=ft[3]|0,this.Ch=ft[4]|0,this.Cl=ft[5]|0,this.Dh=ft[6]|0,this.Dl=ft[7]|0,this.Eh=ft[8]|0,this.El=ft[9]|0,this.Fh=ft[10]|0,this.Fl=ft[11]|0,this.Gh=ft[12]|0,this.Gl=ft[13]|0,this.Hh=ft[14]|0,this.Hl=ft[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:h,Fl:l,Gh:d,Gl:p,Hh:w,Hl:g}=this;return[t,r,n,s,o,i,a,c,u,f,h,l,d,p,w,g]}set(t,r,n,s,o,i,a,c,u,f,h,l,d,p,w,g){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=s|0,this.Ch=o|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=h|0,this.Fl=l|0,this.Gh=d|0,this.Gl=p|0,this.Hh=w|0,this.Hl=g|0}process(t,r){for(let E=0;E<16;E++,r+=4)se[E]=t.getUint32(r),oe[E]=t.getUint32(r+=4);for(let E=16;E<80;E++){let R=se[E-15]|0,k=oe[E-15]|0,O=ge(R,k,1)^ge(R,k,8)^ds(R,k,7),M=be(R,k,1)^be(R,k,8)^ps(R,k,7),P=se[E-2]|0,S=oe[E-2]|0,T=ge(P,S,19)^yr(P,S,61)^ds(P,S,6),U=be(P,S,19)^gr(P,S,61)^ps(P,S,6),C=Ki(M,U,oe[E-7],oe[E-16]),m=Ri(C,O,T,se[E-7],se[E-16]);se[E]=m|0,oe[E]=C|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:h,El:l,Fh:d,Fl:p,Gh:w,Gl:g,Hh:x,Hl:B}=this;for(let E=0;E<80;E++){let R=ge(h,l,14)^ge(h,l,18)^yr(h,l,41),k=be(h,l,14)^be(h,l,18)^gr(h,l,41),O=h&d^~h&w,M=l&p^~l&g,P=Ui(B,k,M,tu[E],oe[E]),S=Di(P,x,R,O,Qf[E],se[E]),T=P|0,U=ge(n,s,28)^yr(n,s,34)^yr(n,s,39),C=be(n,s,28)^gr(n,s,34)^gr(n,s,39),m=n&o^n&a^o&a,y=s&i^s&c^i&c;x=w|0,B=g|0,w=d|0,g=p|0,d=h|0,p=l|0,{h,l}=Ut(u|0,f|0,S|0,T|0),u=a|0,f=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let b=Ti(T,C,y);n=Ci(b,S,U,m),s=b|0}({h:n,l:s}=Ut(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=Ut(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=Ut(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Ut(this.Dh|0,this.Dl|0,u|0,f|0),{h,l}=Ut(this.Eh|0,this.El|0,h|0,l|0),{h:d,l:p}=Ut(this.Fh|0,this.Fl|0,d|0,p|0),{h:w,l:g}=Ut(this.Gh|0,this.Gl|0,w|0,g|0),{h:x,l:B}=Ut(this.Hh|0,this.Hl|0,x|0,B|0),this.set(n,s,o,i,a,c,u,f,h,l,d,p,w,g,x,B)}roundClean(){_t(se,oe)}destroy(){_t(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var ie=ls(()=>new Xr);var Ni=ls(()=>new ms);var bs=BigInt(0),gs=BigInt(1);function Ht(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}"`;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function Et(e,t,r=""){let n=Mt(e),s=e?.length,o=t!==void 0;if(!n||o&&s!==t){let i=r&&`"${r}" `,a=o?` of length ${t}`:"",c=n?`length=${s}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return e}function br(e){let t=e.toString(16);return t.length&1?"0"+t:t}function ki(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?bs:BigInt("0x"+e)}function qe(e){return ki(At(e))}function Bt(e){return lt(e),ki(At(Uint8Array.from(e).reverse()))}function Jr(e,t){return ye(e.toString(16).padStart(t*2,"0"))}function xr(e,t){return Jr(e,t).reverse()}function $(e,t,r){let n;if(typeof t=="string")try{n=ye(t)}catch(o){throw new Error(e+" must be hex string or Uint8Array, cause: "+o)}else if(Mt(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let s=n.length;if(typeof r=="number"&&s!==r)throw new Error(e+" of length "+r+" expected, got "+s);return n}function Mi(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function xs(e){return Uint8Array.from(e)}var ys=e=>typeof e=="bigint"&&bs<=e;function Oi(e,t,r){return ys(e)&&ys(t)&&ys(r)&&t<=e&&e<r}function ae(e,t,r,n){if(!Oi(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Qr(e){let t;for(t=0;e>bs;e>>=gs,t+=1);return t}var ce=e=>(gs<<BigInt(e))-gs;function Hi(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=d=>new Uint8Array(d),s=d=>Uint8Array.of(d),o=n(e),i=n(e),a=0,c=()=>{o.fill(1),i.fill(0),a=0},u=(...d)=>r(i,o,...d),f=(d=n(0))=>{i=u(s(0),d),o=u(),d.length!==0&&(i=u(s(1),d),o=u())},h=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let d=0,p=[];for(;d<t;){o=u();let w=o.slice();p.push(w),d+=o.length}return gt(...p)};return(d,p)=>{c(),f(d);let w;for(;!(w=p(h()));)f();return c(),w}}function Dt(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(s,o,i){let a=e[s];if(i&&a===void 0)return;let c=typeof a;if(c!==o||a===null)throw new Error(`param "${s}" is invalid: expected ${o}, got ${c}`)}Object.entries(t).forEach(([s,o])=>n(s,o,!1)),Object.entries(r).forEach(([s,o])=>n(s,o,!0))}var ws=()=>{throw new Error("not implemented")};function Ve(e){let t=new WeakMap;return(r,...n)=>{let s=t.get(r);if(s!==void 0)return s;let o=e(r,...n);return t.set(r,o),o}}var bt=BigInt(0),ot=BigInt(1),xe=BigInt(2),Fi=BigInt(3),zi=BigInt(4),Gi=BigInt(5),eu=BigInt(7),ji=BigInt(8),ru=BigInt(9),$i=BigInt(16);function X(e,t){let r=e%t;return r>=bt?r:t+r}function J(e,t,r){let n=e;for(;t-- >bt;)n*=n,n%=r;return n}function qi(e,t){if(e===bt)throw new Error("invert: expected non-zero number");if(t<=bt)throw new Error("invert: expected positive modulus, got "+t);let r=X(e,t),n=t,s=bt,o=ot,i=ot,a=bt;for(;r!==bt;){let u=n/r,f=n%r,h=s-i*u,l=o-a*u;n=r,r=f,s=i,o=a,i=h,a=l}if(n!==ot)throw new Error("invert: does not exist");return X(s,t)}function Es(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function Zi(e,t){let r=(e.ORDER+ot)/zi,n=e.pow(t,r);return Es(e,n,t),n}function nu(e,t){let r=(e.ORDER-Gi)/ji,n=e.mul(t,xe),s=e.pow(n,r),o=e.mul(t,s),i=e.mul(e.mul(o,xe),s),a=e.mul(o,e.sub(i,e.ONE));return Es(e,a,t),a}function su(e){let t=St(e),r=Wi(e),n=r(t,t.neg(t.ONE)),s=r(t,n),o=r(t,t.neg(n)),i=(e+eu)/$i;return(a,c)=>{let u=a.pow(c,i),f=a.mul(u,n),h=a.mul(u,s),l=a.mul(u,o),d=a.eql(a.sqr(f),c),p=a.eql(a.sqr(h),c);u=a.cmov(u,f,d),f=a.cmov(l,h,p);let w=a.eql(a.sqr(f),c),g=a.cmov(u,f,w);return Es(a,g,c),g}}function Wi(e){if(e<Fi)throw new Error("sqrt is not defined for small field");let t=e-ot,r=0;for(;t%xe===bt;)t/=xe,r++;let n=xe,s=St(e);for(;Vi(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Zi;let o=s.pow(n,t),i=(t+ot)/xe;return function(c,u){if(c.is0(u))return u;if(Vi(c,u)!==1)throw new Error("Cannot find square root");let f=r,h=c.mul(c.ONE,o),l=c.pow(u,t),d=c.pow(u,i);for(;!c.eql(l,c.ONE);){if(c.is0(l))return c.ZERO;let p=1,w=c.sqr(l);for(;!c.eql(w,c.ONE);)if(p++,w=c.sqr(w),p===f)throw new Error("Cannot find square root");let g=ot<<BigInt(f-p-1),x=c.pow(h,g);f=p,h=c.sqr(x),l=c.mul(l,h),d=c.mul(d,x)}return d}}function ou(e){return e%zi===Fi?Zi:e%ji===Gi?nu:e%$i===ru?su(e):Wi(e)}var qt=(e,t)=>(X(e,t)&ot)===ot,iu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ss(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=iu.reduce((n,s)=>(n[s]="function",n),t);return Dt(e,r),e}function au(e,t,r){if(r<bt)throw new Error("invalid exponent, negatives unsupported");if(r===bt)return e.ONE;if(r===ot)return t;let n=e.ONE,s=t;for(;r>bt;)r&ot&&(n=e.mul(n,s)),s=e.sqr(s),r>>=ot;return n}function wr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),s=t.reduce((i,a,c)=>e.is0(a)?i:(n[c]=i,e.mul(i,a)),e.ONE),o=e.inv(s);return t.reduceRight((i,a,c)=>e.is0(a)?i:(n[c]=e.mul(i,n[c]),e.mul(i,a)),o),n}function Vi(e,t){let r=(e.ORDER-ot)/xe,n=e.pow(t,r),s=e.eql(n,e.ONE),o=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!s&&!o&&!i)throw new Error("invalid Legendre symbol result");return s?1:o?0:-1}function tn(e,t){t!==void 0&&pe(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function St(e,t,r=!1,n={}){if(e<=bt)throw new Error("invalid field: expected ORDER > 0, got "+e);let s,o,i=!1,a;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let l=t;l.BITS&&(s=l.BITS),l.sqrt&&(o=l.sqrt),typeof l.isLE=="boolean"&&(r=l.isLE),typeof l.modFromBytes=="boolean"&&(i=l.modFromBytes),a=l.allowedLengths}else typeof t=="number"&&(s=t),n.sqrt&&(o=n.sqrt);let{nBitLength:c,nByteLength:u}=tn(e,s);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let f,h=Object.freeze({ORDER:e,isLE:r,BITS:c,BYTES:u,MASK:ce(c),ZERO:bt,ONE:ot,allowedLengths:a,create:l=>X(l,e),isValid:l=>{if(typeof l!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof l);return bt<=l&&l<e},is0:l=>l===bt,isValidNot0:l=>!h.is0(l)&&h.isValid(l),isOdd:l=>(l&ot)===ot,neg:l=>X(-l,e),eql:(l,d)=>l===d,sqr:l=>X(l*l,e),add:(l,d)=>X(l+d,e),sub:(l,d)=>X(l-d,e),mul:(l,d)=>X(l*d,e),pow:(l,d)=>au(h,l,d),div:(l,d)=>X(l*qi(d,e),e),sqrN:l=>l*l,addN:(l,d)=>l+d,subN:(l,d)=>l-d,mulN:(l,d)=>l*d,inv:l=>qi(l,e),sqrt:o||(l=>(f||(f=ou(e)),f(h,l))),toBytes:l=>r?xr(l,u):Jr(l,u),fromBytes:(l,d=!0)=>{if(a){if(!a.includes(l.length)||l.length>u)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+l.length);let w=new Uint8Array(u);w.set(l,r?0:w.length-l.length),l=w}if(l.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+l.length);let p=r?Bt(l):qe(l);if(i&&(p=X(p,e)),!d&&!h.isValid(p))throw new Error("invalid field element: outside of range 0..ORDER");return p},invertBatch:l=>wr(h,l),cmov:(l,d,p)=>p?d:l});return Object.freeze(h)}function Yi(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function vs(e){let t=Yi(e);return t+Math.ceil(t/2)}function As(e,t,r=!1){let n=e.length,s=Yi(t),o=vs(t);if(n<16||n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);let i=r?Bt(e):qe(e),a=X(i,t-ot)+ot;return r?xr(a,s):Jr(a,s)}var Fe=BigInt(0),we=BigInt(1);function Er(e,t){let r=t.negate();return e?r:t}function Vt(e,t){let r=wr(e.Fp,t.map(n=>n.Z));return t.map((n,s)=>e.fromAffine(n.toAffine(r[s])))}function ta(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Bs(e,t){ta(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),s=2**e,o=ce(e),i=BigInt(e);return{windows:r,windowSize:n,mask:o,maxNumber:s,shiftBy:i}}function Xi(e,t,r){let{windowSize:n,mask:s,maxNumber:o,shiftBy:i}=r,a=Number(e&s),c=e>>i;a>n&&(a-=o,c+=we);let u=t*n,f=u+Math.abs(a)-1,h=a===0,l=a<0,d=t%2!==0;return{nextN:c,offset:f,isZero:h,isNeg:l,isNegF:d,offsetF:u}}function cu(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function fu(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var Ls=new WeakMap,ea=new WeakMap;function _s(e){return ea.get(e)||1}function Ji(e){if(e!==Fe)throw new Error("invalid wNAF")}var ze=class{constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let s=t;for(;r>Fe;)r&we&&(n=n.add(s)),s=s.double(),r>>=we;return n}precomputeWindow(t,r){let{windows:n,windowSize:s}=Bs(r,this.bits),o=[],i=t,a=i;for(let c=0;c<n;c++){a=i,o.push(a);for(let u=1;u<s;u++)a=a.add(i),o.push(a);i=a.double()}return o}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let s=this.ZERO,o=this.BASE,i=Bs(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:f,isNeg:h,isNegF:l,offsetF:d}=Xi(n,a,i);n=c,f?o=o.add(Er(l,r[d])):s=s.add(Er(h,r[u]))}return Ji(n),{p:s,f:o}}wNAFUnsafe(t,r,n,s=this.ZERO){let o=Bs(t,this.bits);for(let i=0;i<o.windows&&n!==Fe;i++){let{nextN:a,offset:c,isZero:u,isNeg:f}=Xi(n,i,o);if(n=a,!u){let h=r[c];s=s.add(f?h.negate():h)}}return Ji(n),s}getPrecomputes(t,r,n){let s=Ls.get(r);return s||(s=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(s=n(s)),Ls.set(r,s))),s}cached(t,r,n){let s=_s(t);return this.wNAF(s,this.getPrecomputes(s,t,n),r)}unsafe(t,r,n,s){let o=_s(t);return o===1?this._unsafeLadder(t,r,s):this.wNAFUnsafe(o,this.getPrecomputes(o,t,n),r,s)}createCache(t,r){ta(r,this.bits),ea.set(t,r),Ls.delete(t)}hasCache(t){return _s(t)!==1}};function ra(e,t,r,n){let s=t,o=e.ZERO,i=e.ZERO;for(;r>Fe||n>Fe;)r&we&&(o=o.add(s)),n&we&&(i=i.add(s)),s=s.double(),r>>=we,n>>=we;return{p1:o,p2:i}}function Ge(e,t,r,n){cu(r,e),fu(n,t);let s=r.length,o=n.length;if(s!==o)throw new Error("arrays of points and scalars must have equal length");let i=e.ZERO,a=Qr(BigInt(s)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let u=ce(c),f=new Array(Number(u)+1).fill(i),h=Math.floor((t.BITS-1)/c)*c,l=i;for(let d=h;d>=0;d-=c){f.fill(i);for(let w=0;w<o;w++){let g=n[w],x=Number(g>>BigInt(d)&u);f[x]=f[x].add(r[w])}let p=i;for(let w=f.length-1,g=i;w>0;w--)g=g.add(f[w]),p=p.add(g);if(l=l.add(p),d!==0)for(let w=0;w<c;w++)l=l.double()}return l}function Qi(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Ss(t),t}else return St(e,{isLE:r})}function en(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let c of["p","n","h"]){let u=t[c];if(!(typeof u=="bigint"&&u>Fe))throw new Error(`CURVE.${c} must be positive bigint`)}let s=Qi(t.p,r.Fp,n),o=Qi(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let c of a)if(!s.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:s,Fn:o}}var fe=BigInt(0),it=BigInt(1),Is=BigInt(2),uu=BigInt(8);function hu(e,t,r,n){let s=e.sqr(r),o=e.sqr(n),i=e.add(e.mul(t.a,s),o),a=e.add(e.ONE,e.mul(t.d,e.mul(s,o)));return e.eql(i,a)}function lu(e,t={}){let r=en("edwards",e,t,t.FpFnLE),{Fp:n,Fn:s}=r,o=r.CURVE,{h:i}=o;Dt(t,{},{uvRatio:"function"});let a=Is<<BigInt(s.BYTES*8)-it,c=g=>n.create(g),u=t.uvRatio||((g,x)=>{try{return{isValid:!0,value:n.sqrt(n.div(g,x))}}catch{return{isValid:!1,value:fe}}});if(!hu(n,o,o.Gx,o.Gy))throw new Error("bad curve params: generator point");function f(g,x,B=!1){let E=B?it:fe;return ae("coordinate "+g,x,E,a),x}function h(g){if(!(g instanceof p))throw new Error("ExtendedPoint expected")}let l=Ve((g,x)=>{let{X:B,Y:E,Z:R}=g,k=g.is0();x==null&&(x=k?uu:n.inv(R));let O=c(B*x),M=c(E*x),P=n.mul(R,x);if(k)return{x:fe,y:it};if(P!==it)throw new Error("invZ was invalid");return{x:O,y:M}}),d=Ve(g=>{let{a:x,d:B}=o;if(g.is0())throw new Error("bad point: ZERO");let{X:E,Y:R,Z:k,T:O}=g,M=c(E*E),P=c(R*R),S=c(k*k),T=c(S*S),U=c(M*x),C=c(S*c(U+P)),m=c(T+c(B*c(M*P)));if(C!==m)throw new Error("bad point: equation left != right (1)");let y=c(E*R),b=c(k*O);if(y!==b)throw new Error("bad point: equation left != right (2)");return!0});class p{constructor(x,B,E,R){this.X=f("x",x),this.Y=f("y",B),this.Z=f("z",E,!0),this.T=f("t",R),Object.freeze(this)}static CURVE(){return o}static fromAffine(x){if(x instanceof p)throw new Error("extended point not allowed");let{x:B,y:E}=x||{};return f("x",B),f("y",E),new p(B,E,it,c(B*E))}static fromBytes(x,B=!1){let E=n.BYTES,{a:R,d:k}=o;x=xs(Et(x,E,"point")),Ht(B,"zip215");let O=xs(x),M=x[E-1];O[E-1]=M&-129;let P=Bt(O),S=B?a:n.ORDER;ae("point.y",P,fe,S);let T=c(P*P),U=c(T-it),C=c(k*T-R),{isValid:m,value:y}=u(U,C);if(!m)throw new Error("bad point: invalid y coordinate");let b=(y&it)===it,A=(M&128)!==0;if(!B&&y===fe&&A)throw new Error("bad point: x=0 and x_0=1");return A!==b&&(y=c(-y)),p.fromAffine({x:y,y:P})}static fromHex(x,B=!1){return p.fromBytes($("point",x),B)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(x=8,B=!0){return w.createCache(this,x),B||this.multiply(Is),this}assertValidity(){d(this)}equals(x){h(x);let{X:B,Y:E,Z:R}=this,{X:k,Y:O,Z:M}=x,P=c(B*M),S=c(k*R),T=c(E*M),U=c(O*R);return P===S&&T===U}is0(){return this.equals(p.ZERO)}negate(){return new p(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:x}=o,{X:B,Y:E,Z:R}=this,k=c(B*B),O=c(E*E),M=c(Is*c(R*R)),P=c(x*k),S=B+E,T=c(c(S*S)-k-O),U=P+O,C=U-M,m=P-O,y=c(T*C),b=c(U*m),A=c(T*m),L=c(C*U);return new p(y,b,L,A)}add(x){h(x);let{a:B,d:E}=o,{X:R,Y:k,Z:O,T:M}=this,{X:P,Y:S,Z:T,T:U}=x,C=c(R*P),m=c(k*S),y=c(M*E*U),b=c(O*T),A=c((R+k)*(P+S)-C-m),L=b-y,I=b+y,v=c(m-B*C),_=c(A*L),K=c(I*v),D=c(A*v),q=c(L*I);return new p(_,K,q,D)}subtract(x){return this.add(x.negate())}multiply(x){if(!s.isValidNot0(x))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:B,f:E}=w.cached(this,x,R=>Vt(p,R));return Vt(p,[B,E])[0]}multiplyUnsafe(x,B=p.ZERO){if(!s.isValid(x))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return x===fe?p.ZERO:this.is0()||x===it?this:w.unsafe(this,x,E=>Vt(p,E),B)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return w.unsafe(this,o.n).is0()}toAffine(x){return l(this,x)}clearCofactor(){return i===it?this:this.multiplyUnsafe(i)}toBytes(){let{x,y:B}=this.toAffine(),E=n.toBytes(B);return E[E.length-1]|=x&it?128:0,E}toHex(){return At(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(x){return Vt(p,x)}static msm(x,B){return Ge(p,s,x,B)}_setWindowSize(x){this.precompute(x)}toRawBytes(){return this.toBytes()}}p.BASE=new p(o.Gx,o.Gy,it,c(o.Gx*o.Gy)),p.ZERO=new p(fe,it,it,fe),p.Fp=n,p.Fn=s;let w=new ze(p,s.BITS);return p.BASE.precompute(8),p}var rn=class{constructor(t){this.ep=t}static fromBytes(t){ws()}static fromHex(t){ws()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return At(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,r){return this.init(this.ep.precompute(t,r))}toRawBytes(){return this.toBytes()}};function du(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');Dt(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:s,Fp:o,Fn:i}=e,a=r.randomBytes||re,c=r.adjustScalarBytes||(S=>S),u=r.domain||((S,T,U)=>{if(Ht(U,"phflag"),T.length||U)throw new Error("Contexts/pre-hash are not supported");return S});function f(S){return i.create(Bt(S))}function h(S){let T=E.secretKey;S=$("private key",S,T);let U=$("hashed private key",t(S),2*T),C=c(U.slice(0,T)),m=U.slice(T,2*T),y=f(C);return{head:C,prefix:m,scalar:y}}function l(S){let{head:T,prefix:U,scalar:C}=h(S),m=s.multiply(C),y=m.toBytes();return{head:T,prefix:U,scalar:C,point:m,pointBytes:y}}function d(S){return l(S).pointBytes}function p(S=Uint8Array.of(),...T){let U=gt(...T);return f(t(u(U,$("context",S),!!n)))}function w(S,T,U={}){S=$("message",S),n&&(S=n(S));let{prefix:C,scalar:m,pointBytes:y}=l(T),b=p(U.context,C,S),A=s.multiply(b).toBytes(),L=p(U.context,A,y,S),I=i.create(b+L*m);if(!i.isValid(I))throw new Error("sign failed: invalid s");let v=gt(A,i.toBytes(I));return Et(v,E.signature,"result")}let g={zip215:!0};function x(S,T,U,C=g){let{context:m,zip215:y}=C,b=E.signature;S=$("signature",S,b),T=$("message",T),U=$("publicKey",U,E.publicKey),y!==void 0&&Ht(y,"zip215"),n&&(T=n(T));let A=b/2,L=S.subarray(0,A),I=Bt(S.subarray(A,b)),v,_,K;try{v=e.fromBytes(U,y),_=e.fromBytes(L,y),K=s.multiplyUnsafe(I)}catch{return!1}if(!y&&v.isSmallOrder())return!1;let D=p(m,_.toBytes(),v.toBytes(),T);return _.add(v.multiplyUnsafe(D)).subtract(K).clearCofactor().is0()}let B=o.BYTES,E={secretKey:B,publicKey:B,signature:2*B,seed:B};function R(S=a(E.seed)){return Et(S,E.seed,"seed")}function k(S){let T=P.randomSecretKey(S);return{secretKey:T,publicKey:d(T)}}function O(S){return Mt(S)&&S.length===i.BYTES}function M(S,T){try{return!!e.fromBytes(S,T)}catch{return!1}}let P={getExtendedPublicKey:l,randomSecretKey:R,isValidSecretKey:O,isValidPublicKey:M,toMontgomery(S){let{y:T}=e.fromBytes(S),U=E.publicKey,C=U===32;if(!C&&U!==57)throw new Error("only defined for 25519 and 448");let m=C?o.div(it+T,it-T):o.div(T-it,T+it);return o.toBytes(m)},toMontgomerySecret(S){let T=E.secretKey;Et(S,T);let U=t(S.subarray(0,T));return c(U).subarray(0,T)},randomPrivateKey:R,precompute(S=8,T=e.BASE){return T.precompute(S,!1)}};return Object.freeze({keygen:k,getPublicKey:d,sign:w,verify:x,utils:P,Point:e,lengths:E})}function pu(e){let t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=St(t.n,e.nBitLength,!0),s={Fp:r,Fn:n,uvRatio:e.uvRatio},o={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:s,hash:e.hash,eddsaOpts:o}}function mu(e,t){let r=t.Point;return Object.assign({},t,{ExtendedPoint:r,CURVE:e,nBitLength:r.Fn.BITS,nByteLength:r.Fn.BYTES})}function na(e){let{CURVE:t,curveOpts:r,hash:n,eddsaOpts:s}=pu(e),o=lu(t,r),i=du(o,n,s);return mu(e,i)}var Sr=BigInt(0),je=BigInt(1),nn=BigInt(2);function yu(e){return Dt(e,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...e})}function sa(e){let t=yu(e),{P:r,type:n,adjustScalarBytes:s,powPminus2:o,randomBytes:i}=t,a=n==="x25519";if(!a&&n!=="x448")throw new Error("invalid type");let c=i||re,u=a?255:448,f=a?32:56,h=BigInt(a?9:5),l=BigInt(a?121665:39081),d=a?nn**BigInt(254):nn**BigInt(447),p=a?BigInt(8)*nn**BigInt(251)-je:BigInt(4)*nn**BigInt(445)-je,w=d+p+je,g=m=>X(m,r),x=B(h);function B(m){return xr(g(m),f)}function E(m){let y=$("u coordinate",m,f);return a&&(y[31]&=127),g(Bt(y))}function R(m){return Bt(s($("scalar",m,f)))}function k(m,y){let b=P(E(y),R(m));if(b===Sr)throw new Error("invalid private or public key received");return B(b)}function O(m){return k(m,x)}function M(m,y,b){let A=g(m*(y-b));return y=g(y-A),b=g(b+A),{x_2:y,x_3:b}}function P(m,y){ae("u",m,Sr,r),ae("scalar",y,d,w);let b=y,A=m,L=je,I=Sr,v=m,_=je,K=Sr;for(let q=BigInt(u-1);q>=Sr;q--){let V=b>>q&je;K^=V,{x_2:L,x_3:v}=M(K,L,v),{x_2:I,x_3:_}=M(K,I,_),K=V;let H=L+I,F=g(H*H),Z=L-I,Q=g(Z*Z),z=F-Q,st=v+_,Ie=v-_,ir=g(Ie*H),ar=g(st*Z),Go=ir+ar,jo=ir-ar;v=g(Go*Go),_=g(A*g(jo*jo)),L=g(F*Q),I=g(z*(F+g(l*z)))}({x_2:L,x_3:v}=M(K,L,v)),{x_2:I,x_3:_}=M(K,I,_);let D=o(I);return g(L*D)}let S={secretKey:f,publicKey:f,seed:f},T=(m=c(f))=>(lt(m,S.seed),m);function U(m){let y=T(m);return{secretKey:y,publicKey:O(y)}}return{keygen:U,getSharedSecret:(m,y)=>k(m,y),getPublicKey:m=>O(m),scalarMult:k,scalarMultBase:O,utils:{randomSecretKey:T,randomPrivateKey:T},GuBytes:x.slice(),lengths:S}}var gu=BigInt(0),zt=BigInt(1),oa=BigInt(2),bu=BigInt(3),xu=BigInt(5),wu=BigInt(8),$e=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),vr={p:$e,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:wu,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function ca(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),s=BigInt(80),o=$e,a=e*e%o*e%o,c=J(a,oa,o)*a%o,u=J(c,zt,o)*e%o,f=J(u,xu,o)*u%o,h=J(f,t,o)*f%o,l=J(h,r,o)*h%o,d=J(l,n,o)*l%o,p=J(d,s,o)*d%o,w=J(p,s,o)*d%o,g=J(w,t,o)*f%o;return{pow_p_5_8:J(g,oa,o)*e%o,b2:a}}function fa(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Ts=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Rs(e,t){let r=$e,n=X(t*t*t,r),s=X(n*n*t,r),o=ca(e*s).pow_p_5_8,i=X(e*n*o,r),a=X(t*i*i,r),c=i,u=X(i*Ts,r),f=a===e,h=a===X(-e,r),l=a===X(-e*Ts,r);return f&&(i=c),(h||l)&&(i=u),qt(i,r)&&(i=X(-i,r)),{isValid:f||h,value:i}}var Ft=St(vr.p,{isLE:!0}),Eu=St(vr.n,{isLE:!0}),Su={...vr,Fp:Ft,hash:Ni,adjustScalarBytes:fa,uvRatio:Rs},Gt=na(Su);var Ar=(()=>{let e=Ft.ORDER;return sa({P:e,type:"x25519",powPminus2:t=>{let{pow_p_5_8:r,b2:n}=ca(t);return X(J(r,bu,e)*n,e)},adjustScalarBytes:fa})})();var Cs=Ts,vu=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Au=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Bu=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Lu=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),ia=e=>Rs(zt,e),_u=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Ks=e=>Gt.Point.Fp.create(Bt(e)&_u);function aa(e){let{d:t}=vr,r=$e,n=x=>Ft.create(x),s=n(Cs*e*e),o=n((s+zt)*Bu),i=BigInt(-1),a=n((i-t*s)*n(s+t)),{isValid:c,value:u}=Rs(o,a),f=n(u*e);qt(f,r)||(f=n(-f)),c||(u=f),c||(i=s);let h=n(i*(s-zt)*Lu-a),l=u*u,d=n((u+u)*a),p=n(h*vu),w=n(zt-l),g=n(zt+l);return new Gt.Point(n(d*g),n(w*p),n(p*g),n(d*w))}function Iu(e){lt(e,64);let t=Ks(e.subarray(0,32)),r=aa(t),n=Ks(e.subarray(32,64)),s=aa(n);return new jt(r.add(s))}var jt=class e extends rn{constructor(t){super(t)}static fromAffine(t){return new e(Gt.Point.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static hashToCurve(t){return Iu($("ristrettoHash",t,64))}static fromBytes(t){lt(t,32);let{a:r,d:n}=vr,s=$e,o=R=>Ft.create(R),i=Ks(t);if(!Mi(Ft.toBytes(i),t)||qt(i,s))throw new Error("invalid ristretto255 encoding 1");let a=o(i*i),c=o(zt+r*a),u=o(zt-r*a),f=o(c*c),h=o(u*u),l=o(r*n*f-h),{isValid:d,value:p}=ia(o(l*h)),w=o(p*u),g=o(p*w*l),x=o((i+i)*w);qt(x,s)&&(x=o(-x));let B=o(c*g),E=o(x*B);if(!d||qt(E,s)||B===gu)throw new Error("invalid ristretto255 encoding 2");return new e(new Gt.Point(x,B,zt,E))}static fromHex(t){return e.fromBytes($("ristrettoHex",t,32))}static msm(t,r){return Ge(e,Gt.Point.Fn,t,r)}toBytes(){let{X:t,Y:r,Z:n,T:s}=this.ep,o=$e,i=g=>Ft.create(g),a=i(i(n+r)*i(n-r)),c=i(t*r),u=i(c*c),{value:f}=ia(i(a*u)),h=i(f*a),l=i(f*c),d=i(h*l*s),p;if(qt(s*d,o)){let g=i(r*Cs),x=i(t*Cs);t=g,r=x,p=i(h*Au)}else p=l;qt(t*d,o)&&(r=i(-r));let w=i((n-r)*p);return qt(w,o)&&(w=i(-w)),Ft.toBytes(w)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:s,Y:o}=t.ep,i=u=>Ft.create(u),a=i(r*o)===i(n*s),c=i(n*o)===i(r*s);return a||c}is0(){return this.equals(e.ZERO)}};jt.BASE=new jt(Gt.Point.BASE);jt.ZERO=new jt(Gt.Point.ZERO);jt.Fp=Ft;jt.Fn=Eu;var Br=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},sn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var ua={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new sn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var Lt=ua;var on=32;var Us,Tu=(async()=>{try{return await Lt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Cu(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Lt.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Lt.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Ku(e,t,r){return Gt.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function ha(e,t,r){return Us==null&&(Us=await Tu),Us?Cu(e,t,r):Ku(e,t,r)}function an(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var cn=class{type="Ed25519";raw;constructor(t){this.raw=Ds(t,on)}toMultihash(){return Rt.digest(te(this))}toCID(){return ht.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:yt(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let s=ha(this.raw,r,t);return an(s)?s.then(o=>(n?.signal?.throwIfAborted(),o)):s}};function da(e){return e=Ds(e,on),new cn(e)}function Ds(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new tt(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Uu=Math.pow(2,7),Du=Math.pow(2,14),Pu=Math.pow(2,21),Ps=Math.pow(2,28),Ns=Math.pow(2,35),ks=Math.pow(2,42),Ms=Math.pow(2,49),W=128,dt=127;function Tt(e){if(e<Uu)return 1;if(e<Du)return 2;if(e<Pu)return 3;if(e<Ps)return 4;if(e<Ns)return 5;if(e<ks)return 6;if(e<Ms)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Os(e,t,r=0){switch(Tt(e)){case 8:t[r++]=e&255|W,e/=128;case 7:t[r++]=e&255|W,e/=128;case 6:t[r++]=e&255|W,e/=128;case 5:t[r++]=e&255|W,e/=128;case 4:t[r++]=e&255|W,e>>>=7;case 3:t[r++]=e&255|W,e>>>=7;case 2:t[r++]=e&255|W,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Nu(e,t,r=0){switch(Tt(e)){case 8:t.set(r++,e&255|W),e/=128;case 7:t.set(r++,e&255|W),e/=128;case 6:t.set(r++,e&255|W),e/=128;case 5:t.set(r++,e&255|W),e/=128;case 4:t.set(r++,e&255|W),e>>>=7;case 3:t.set(r++,e&255|W),e>>>=7;case 2:t.set(r++,e&255|W),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function Hs(e,t){let r=e[t],n=0;if(n+=r&dt,r<W||(r=e[t+1],n+=(r&dt)<<7,r<W)||(r=e[t+2],n+=(r&dt)<<14,r<W)||(r=e[t+3],n+=(r&dt)<<21,r<W)||(r=e[t+4],n+=(r&dt)*Ps,r<W)||(r=e[t+5],n+=(r&dt)*Ns,r<W)||(r=e[t+6],n+=(r&dt)*ks,r<W)||(r=e[t+7],n+=(r&dt)*Ms,r<W))return n;throw new RangeError("Could not decode varint")}function ku(e,t){let r=e.get(t),n=0;if(n+=r&dt,r<W||(r=e.get(t+1),n+=(r&dt)<<7,r<W)||(r=e.get(t+2),n+=(r&dt)<<14,r<W)||(r=e.get(t+3),n+=(r&dt)<<21,r<W)||(r=e.get(t+4),n+=(r&dt)*Ps,r<W)||(r=e.get(t+5),n+=(r&dt)*Ns,r<W)||(r=e.get(t+6),n+=(r&dt)*ks,r<W)||(r=e.get(t+7),n+=(r&dt)*Ms,r<W))return n;throw new RangeError("Could not decode varint")}function pa(e,t,r=0){return t==null&&(t=ct(Tt(e))),t instanceof Uint8Array?Os(e,t,r):Nu(e,t,r)}function fn(e,t=0){return e instanceof Uint8Array?Hs(e,t):ku(e,t)}var qs=new Float32Array([-0]),ue=new Uint8Array(qs.buffer);function ya(e,t,r){qs[0]=e,t[r]=ue[0],t[r+1]=ue[1],t[r+2]=ue[2],t[r+3]=ue[3]}function ga(e,t){return ue[0]=e[t],ue[1]=e[t+1],ue[2]=e[t+2],ue[3]=e[t+3],qs[0]}var Vs=new Float64Array([-0]),pt=new Uint8Array(Vs.buffer);function ba(e,t,r){Vs[0]=e,t[r]=pt[0],t[r+1]=pt[1],t[r+2]=pt[2],t[r+3]=pt[3],t[r+4]=pt[4],t[r+5]=pt[5],t[r+6]=pt[6],t[r+7]=pt[7]}function xa(e,t){return pt[0]=e[t],pt[1]=e[t+1],pt[2]=e[t+2],pt[3]=e[t+3],pt[4]=e[t+4],pt[5]=e[t+5],pt[6]=e[t+6],pt[7]=e[t+7],Vs[0]}var Mu=BigInt(Number.MAX_SAFE_INTEGER),Ou=BigInt(Number.MIN_SAFE_INTEGER),vt=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return Ee;if(t<Mu&&t>Ou)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,s=t-(n<<32n);return r&&(n=~n|0n,s=~s|0n,++s>wa&&(s=0n,++n>wa&&(n=0n))),new e(Number(s),Number(n))}static fromNumber(t){if(t===0)return Ee;let r=t<0;r&&(t=-t);let n=t>>>0,s=(t-n)/4294967296>>>0;return r&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new e(n,s)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):Ee}},Ee=new vt(0,0);Ee.toBigInt=function(){return 0n};Ee.zzEncode=Ee.zzDecode=function(){return this};Ee.length=function(){return 1};var wa=4294967296n;function Ea(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Sa(e,t,r){if(r-t<1)return"";let s,o=[],i=0,a;for(;t<r;)a=e[t++],a<128?o[i++]=a:a>191&&a<224?o[i++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,o[i++]=55296+(a>>10),o[i++]=56320+(a&1023)):o[i++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,o)),i=0);return s!=null?(i>0&&s.push(String.fromCharCode.apply(String,o.slice(0,i))),s.join("")):String.fromCharCode.apply(String,o.slice(0,i))}function Fs(e,t,r){let n=r,s,o;for(let i=0;i<e.length;++i)s=e.charCodeAt(i),s<128?t[r++]=s:s<2048?(t[r++]=s>>6|192,t[r++]=s&63|128):(s&64512)===55296&&((o=e.charCodeAt(i+1))&64512)===56320?(s=65536+((s&1023)<<10)+(o&1023),++i,t[r++]=s>>18|240,t[r++]=s>>12&63|128,t[r++]=s>>6&63|128,t[r++]=s&63|128):(t[r++]=s>>12|224,t[r++]=s>>6&63|128,t[r++]=s&63|128);return r-n}function Ct(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function un(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var zs=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Ct(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ct(this,4);return un(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ct(this,4);return un(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ct(this,4);let t=ga(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Ct(this,4);let t=xa(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Ct(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Sa(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Ct(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Ct(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new vt(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Ct(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Ct(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ct(this,8);let t=un(this.buf,this.pos+=4),r=un(this.buf,this.pos+=4);return new vt(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Hs(this.buf,this.pos);return this.pos+=Tt(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Gs(e){return new zs(e instanceof Uint8Array?e:e.subarray())}function Se(e,t,r){let n=Gs(e);return t.decode(n,void 0,r)}function js(e){let t=e??8192,r=t>>>1,n,s=t;return function(i){if(i<1||i>r)return ct(i);s+i>t&&(n=ct(t),s=0);let a=n.subarray(s,s+=i);return(s&7)!==0&&(s=(s|7)+1),a}}var ve=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function $s(){}var Ws=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Hu=js();function qu(e){return globalThis.Buffer!=null?ct(e):Hu(e)}var _r=class{len;head;tail;states;constructor(){this.len=0,this.head=new ve($s,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new ve(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Ys((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(hn,10,vt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=vt.fromBigInt(t);return this._push(hn,r.length(),r)}uint64Number(t){return this._push(Os,Tt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=vt.fromBigInt(t).zzEncode();return this._push(hn,r.length(),r)}sint64Number(t){let r=vt.fromNumber(t).zzEncode();return this._push(hn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Zs,1,t?1:0)}fixed32(t){return this._push(Lr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=vt.fromBigInt(t);return this._push(Lr,4,r.lo)._push(Lr,4,r.hi)}fixed64Number(t){let r=vt.fromNumber(t);return this._push(Lr,4,r.lo)._push(Lr,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(ya,4,t)}double(t){return this._push(ba,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Zs,1,0):this.uint32(r)._push(Fu,r,t)}string(t){let r=Ea(t);return r!==0?this.uint32(r)._push(Fs,r,t):this._push(Zs,1,0)}fork(){return this.states=new Ws(this),this.head=this.tail=new ve($s,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new ve($s,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=qu(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Zs(e,t,r){t[r]=e&255}function Vu(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Ys=class extends ve{next;constructor(t,r){super(Vu,t,r),this.next=void 0}};function hn(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function Lr(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function Fu(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(_r.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(zu,t,e),this},_r.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Gu,t,e),this});function zu(e,t,r){t.set(e,r)}function Gu(e,t,r){e.length<40?Fs(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(Y(e),r)}function Xs(){return new _r}function Ae(e,t){let r=Xs();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var Ze;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(Ze||(Ze={}));function ln(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function Js(e){function t(s){if(e[s.toString()]==null)throw new Error("Invalid enum value");return e[s]}let r=function(o,i){let a=t(o);i.int32(a)},n=function(o){let i=o.int32();return t(i)};return ln("enum",Ze.VARINT,r,n)}function Be(e,t){return ln("message",Ze.LENGTH_DELIMITED,e,t)}var Ir=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var at;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(at||(at={}));var Qs;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Qs||(Qs={}));(function(e){e.codec=()=>Js(Qs)})(at||(at={}));var $t;(function(e){let t;e.codec=()=>(t==null&&(t=Be((r,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),at.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),s.lengthDelimited!==!1&&n.ldelim()},(r,n,s={})=>{let o={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{o.Type=at.codec().decode(r);break}case 2:{o.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return o})),t),e.encode=r=>Ae(r,e.codec()),e.decode=(r,n)=>Se(r,e.codec(),n)})($t||($t={}));var to;(function(e){let t;e.codec=()=>(t==null&&(t=Be((r,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),at.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),s.lengthDelimited!==!1&&n.ldelim()},(r,n,s={})=>{let o={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{o.Type=at.codec().decode(r);break}case 2:{o.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return o})),t),e.encode=r=>Ae(r,e.codec()),e.decode=(r,n)=>Se(r,e.codec(),n)})(to||(to={}));var Cr={};xt(Cr,{MAX_RSA_KEY_SIZE:()=>eo,generateRSAKeyPair:()=>Ia,jwkToJWKKeyPair:()=>Ta,jwkToPkcs1:()=>Wu,jwkToPkix:()=>oo,jwkToRSAPrivateKey:()=>fo,pkcs1MessageToJwk:()=>no,pkcs1MessageToRSAPrivateKey:()=>io,pkcs1ToJwk:()=>Zu,pkcs1ToRSAPrivateKey:()=>_a,pkixMessageToJwk:()=>so,pkixMessageToRSAPublicKey:()=>co,pkixToJwk:()=>Yu,pkixToRSAPublicKey:()=>ao});var dn=ie;var We=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Cr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ht.createV1(114,this._multihash)}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:yt(this.raw,t.raw)}verify(t,r,n){return La(this.jwk,r,t,n)}},Tr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Cr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:yt(this.raw,t.raw)}sign(t,r){return Ba(this.jwk,t,r)}};var eo=8192,ro=18,ju=1062,$u=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Zu(e){let t=Nt(e);return no(t)}function no(e){return{n:j(e[1],"base64url"),e:j(e[2],"base64url"),d:j(e[3],"base64url"),p:j(e[4],"base64url"),q:j(e[5],"base64url"),dp:j(e[6],"base64url"),dq:j(e[7],"base64url"),qi:j(e[8],"base64url"),kty:"RSA"}}function Wu(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new tt("JWK was missing components");return Qt([wt(Uint8Array.from([0])),wt(Y(e.n,"base64url")),wt(Y(e.e,"base64url")),wt(Y(e.d,"base64url")),wt(Y(e.p,"base64url")),wt(Y(e.q,"base64url")),wt(Y(e.dp,"base64url")),wt(Y(e.dq,"base64url")),wt(Y(e.qi,"base64url"))]).subarray()}function Yu(e){let t=Nt(e,{offset:0});return so(t)}function so(e){let t=Nt(e[1],{offset:0});return{kty:"RSA",n:j(t[0],"base64url"),e:j(t[1],"base64url")}}function oo(e){if(e.n==null||e.e==null)throw new tt("JWK was missing components");return Qt([$u,Zr(Qt([wt(Y(e.n,"base64url")),wt(Y(e.e,"base64url"))]))]).subarray()}function _a(e){let t=Nt(e);return io(t)}function io(e){let t=no(e);return fo(t)}function ao(e,t){if(e.byteLength>=ju)throw new Te("Key size is too large");let r=Nt(e,{offset:0});return co(r,e,t)}function co(e,t,r){let n=so(e);if(r==null){let s=dn($t.encode({Type:at.RSA,Data:t}));r=Kt(ro,s)}return new We(n,r)}function fo(e){if(Ka(e)>eo)throw new tt("Key size is too large");let t=Ta(e),r=dn($t.encode({Type:at.RSA,Data:oo(t.publicKey)})),n=Kt(ro,r);return new Tr(t.privateKey,new We(t.publicKey,n))}async function Ia(e){if(e>eo)throw new tt("Key size is too large");let t=await Ca(e),r=dn($t.encode({Type:at.RSA,Data:oo(t.publicKey)})),n=Kt(ro,r);return new Tr(t.privateKey,new We(t.publicKey,n))}function Ta(e){if(e==null)throw new tt("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function Ca(e,t){let r=await Lt.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await Xu(r,t);return{privateKey:n[0],publicKey:n[1]}}async function Ba(e,t,r){let n=await Lt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let s=await Lt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(s,0,s.byteLength)}async function La(e,t,r,n){let s=await Lt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let o=await Lt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},s,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),o}async function Xu(e,t){if(e.privateKey==null||e.publicKey==null)throw new tt("Private and public key are required");let r=await Promise.all([Lt.get().subtle.exportKey("jwk",e.privateKey),Lt.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function Ka(e){if(e.kty!=="RSA")throw new tt("invalid key type");if(e.n==null)throw new tt("invalid key modulus");return Y(e.n,"base64url").length*8}var pn=class extends Oe{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,me(t);let n=ee(r);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let s=this.blockLen,o=new Uint8Array(s);o.set(n.length>s?t.create().update(n).digest():n);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=t.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),_t(o)}update(t){return He(this),this.iHash.update(t),this}digestInto(t){He(this),lt(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:s,destroyed:o,blockLen:i,outputLen:a}=this;return t=t,t.finished=s,t.destroyed=o,t.blockLen=i,t.outputLen=a,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ye=(e,t,r)=>new pn(e,t).update(r).digest();Ye.create=(e,t)=>new pn(e,t);var Ra=(e,t)=>(e+(e>=0?t:-t)/Ua)/t;function Ju(e,t,r){let[[n,s],[o,i]]=t,a=Ra(i*e,r),c=Ra(-s*e,r),u=e-a*n-c*o,f=-a*s-c*i,h=u<Wt,l=f<Wt;h&&(u=-u),l&&(f=-f);let d=ce(Math.ceil(Qr(r)/2))+Je;if(u<Wt||u>=d||f<Wt||f>=d)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:h,k1:u,k2neg:l,k2:f}}function ho(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function uo(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return Ht(r.lowS,"lowS"),Ht(r.prehash,"prehash"),r.format!==void 0&&ho(r.format),r}var lo=class extends Error{constructor(t=""){super(t)}},Zt={Err:lo,_tlv:{encode:(e,t)=>{let{Err:r}=Zt;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,s=br(n);if(s.length/2&128)throw new r("tlv.encode: long form length too big");let o=n>127?br(s.length/2|128):"";return br(e)+o+s+t},decode(e,t){let{Err:r}=Zt,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let s=t[n++],o=!!(s&128),i=0;if(!o)i=s;else{let c=s&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=Zt;if(e<Wt)throw new t("integer: negative integers are not allowed");let r=br(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=Zt;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return qe(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Zt,s=$("signature",e),{v:o,l:i}=n.decode(48,s);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,o),{v:u,l:f}=n.decode(2,c);if(f.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=Zt,n=t.encode(2,r.encode(e.r)),s=t.encode(2,r.encode(e.s)),o=n+s;return t.encode(48,o)}},Wt=BigInt(0),Je=BigInt(1),Ua=BigInt(2),mn=BigInt(3),Qu=BigInt(4);function Xe(e,t){let{BYTES:r}=e,n;if(typeof t=="bigint")n=t;else{let s=$("private key",t);try{n=e.fromBytes(s)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof t}`)}}if(!e.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function th(e,t={}){let r=en("weierstrass",e,t),{Fp:n,Fn:s}=r,o=r.CURVE,{h:i,n:a}=o;Dt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:c}=t;if(c&&(!n.is0(o.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=Pa(n,s);function f(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function h(C,m,y){let{x:b,y:A}=m.toAffine(),L=n.toBytes(b);if(Ht(y,"isCompressed"),y){f();let I=!n.isOdd(A);return gt(Da(I),L)}else return gt(Uint8Array.of(4),L,n.toBytes(A))}function l(C){Et(C,void 0,"Point");let{publicKey:m,publicKeyUncompressed:y}=u,b=C.length,A=C[0],L=C.subarray(1);if(b===m&&(A===2||A===3)){let I=n.fromBytes(L);if(!n.isValid(I))throw new Error("bad point: is not on curve, wrong x");let v=w(I),_;try{_=n.sqrt(v)}catch(q){let V=q instanceof Error?": "+q.message:"";throw new Error("bad point: is not on curve, sqrt error"+V)}f();let K=n.isOdd(_);return(A&1)===1!==K&&(_=n.neg(_)),{x:I,y:_}}else if(b===y&&A===4){let I=n.BYTES,v=n.fromBytes(L.subarray(0,I)),_=n.fromBytes(L.subarray(I,I*2));if(!g(v,_))throw new Error("bad point: is not on curve");return{x:v,y:_}}else throw new Error(`bad point: got length ${b}, expected compressed=${m} or uncompressed=${y}`)}let d=t.toBytes||h,p=t.fromBytes||l;function w(C){let m=n.sqr(C),y=n.mul(m,C);return n.add(n.add(y,n.mul(C,o.a)),o.b)}function g(C,m){let y=n.sqr(m),b=w(C);return n.eql(y,b)}if(!g(o.Gx,o.Gy))throw new Error("bad curve params: generator point");let x=n.mul(n.pow(o.a,mn),Qu),B=n.mul(n.sqr(o.b),BigInt(27));if(n.is0(n.add(x,B)))throw new Error("bad curve params: a or b");function E(C,m,y=!1){if(!n.isValid(m)||y&&n.is0(m))throw new Error(`bad point coordinate ${C}`);return m}function R(C){if(!(C instanceof S))throw new Error("ProjectivePoint expected")}function k(C){if(!c||!c.basises)throw new Error("no endo");return Ju(C,c.basises,s.ORDER)}let O=Ve((C,m)=>{let{X:y,Y:b,Z:A}=C;if(n.eql(A,n.ONE))return{x:y,y:b};let L=C.is0();m==null&&(m=L?n.ONE:n.inv(A));let I=n.mul(y,m),v=n.mul(b,m),_=n.mul(A,m);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(_,n.ONE))throw new Error("invZ was invalid");return{x:I,y:v}}),M=Ve(C=>{if(C.is0()){if(t.allowInfinityPoint&&!n.is0(C.Y))return;throw new Error("bad point: ZERO")}let{x:m,y}=C.toAffine();if(!n.isValid(m)||!n.isValid(y))throw new Error("bad point: x or y not field elements");if(!g(m,y))throw new Error("bad point: equation left != right");if(!C.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function P(C,m,y,b,A){return y=new S(n.mul(y.X,C),y.Y,y.Z),m=Er(b,m),y=Er(A,y),m.add(y)}class S{constructor(m,y,b){this.X=E("x",m),this.Y=E("y",y,!0),this.Z=E("z",b),Object.freeze(this)}static CURVE(){return o}static fromAffine(m){let{x:y,y:b}=m||{};if(!m||!n.isValid(y)||!n.isValid(b))throw new Error("invalid affine point");if(m instanceof S)throw new Error("projective point not allowed");return n.is0(y)&&n.is0(b)?S.ZERO:new S(y,b,n.ONE)}static fromBytes(m){let y=S.fromAffine(p(Et(m,void 0,"point")));return y.assertValidity(),y}static fromHex(m){return S.fromBytes($("pointHex",m))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,y=!0){return U.createCache(this,m),y||this.multiply(mn),this}assertValidity(){M(this)}hasEvenY(){let{y:m}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(m)}equals(m){R(m);let{X:y,Y:b,Z:A}=this,{X:L,Y:I,Z:v}=m,_=n.eql(n.mul(y,v),n.mul(L,A)),K=n.eql(n.mul(b,v),n.mul(I,A));return _&&K}negate(){return new S(this.X,n.neg(this.Y),this.Z)}double(){let{a:m,b:y}=o,b=n.mul(y,mn),{X:A,Y:L,Z:I}=this,v=n.ZERO,_=n.ZERO,K=n.ZERO,D=n.mul(A,A),q=n.mul(L,L),V=n.mul(I,I),H=n.mul(A,L);return H=n.add(H,H),K=n.mul(A,I),K=n.add(K,K),v=n.mul(m,K),_=n.mul(b,V),_=n.add(v,_),v=n.sub(q,_),_=n.add(q,_),_=n.mul(v,_),v=n.mul(H,v),K=n.mul(b,K),V=n.mul(m,V),H=n.sub(D,V),H=n.mul(m,H),H=n.add(H,K),K=n.add(D,D),D=n.add(K,D),D=n.add(D,V),D=n.mul(D,H),_=n.add(_,D),V=n.mul(L,I),V=n.add(V,V),D=n.mul(V,H),v=n.sub(v,D),K=n.mul(V,q),K=n.add(K,K),K=n.add(K,K),new S(v,_,K)}add(m){R(m);let{X:y,Y:b,Z:A}=this,{X:L,Y:I,Z:v}=m,_=n.ZERO,K=n.ZERO,D=n.ZERO,q=o.a,V=n.mul(o.b,mn),H=n.mul(y,L),F=n.mul(b,I),Z=n.mul(A,v),Q=n.add(y,b),z=n.add(L,I);Q=n.mul(Q,z),z=n.add(H,F),Q=n.sub(Q,z),z=n.add(y,A);let st=n.add(L,v);return z=n.mul(z,st),st=n.add(H,Z),z=n.sub(z,st),st=n.add(b,A),_=n.add(I,v),st=n.mul(st,_),_=n.add(F,Z),st=n.sub(st,_),D=n.mul(q,z),_=n.mul(V,Z),D=n.add(_,D),_=n.sub(F,D),D=n.add(F,D),K=n.mul(_,D),F=n.add(H,H),F=n.add(F,H),Z=n.mul(q,Z),z=n.mul(V,z),F=n.add(F,Z),Z=n.sub(H,Z),Z=n.mul(q,Z),z=n.add(z,Z),H=n.mul(F,z),K=n.add(K,H),H=n.mul(st,z),_=n.mul(Q,_),_=n.sub(_,H),H=n.mul(Q,F),D=n.mul(st,D),D=n.add(D,H),new S(_,K,D)}subtract(m){return this.add(m.negate())}is0(){return this.equals(S.ZERO)}multiply(m){let{endo:y}=t;if(!s.isValidNot0(m))throw new Error("invalid scalar: out of range");let b,A,L=I=>U.cached(this,I,v=>Vt(S,v));if(y){let{k1neg:I,k1:v,k2neg:_,k2:K}=k(m),{p:D,f:q}=L(v),{p:V,f:H}=L(K);A=q.add(H),b=P(y.beta,D,V,I,_)}else{let{p:I,f:v}=L(m);b=I,A=v}return Vt(S,[b,A])[0]}multiplyUnsafe(m){let{endo:y}=t,b=this;if(!s.isValid(m))throw new Error("invalid scalar: out of range");if(m===Wt||b.is0())return S.ZERO;if(m===Je)return b;if(U.hasCache(this))return this.multiply(m);if(y){let{k1neg:A,k1:L,k2neg:I,k2:v}=k(m),{p1:_,p2:K}=ra(S,b,L,v);return P(y.beta,_,K,A,I)}else return U.unsafe(b,m)}multiplyAndAddUnsafe(m,y,b){let A=this.multiplyUnsafe(y).add(m.multiplyUnsafe(b));return A.is0()?void 0:A}toAffine(m){return O(this,m)}isTorsionFree(){let{isTorsionFree:m}=t;return i===Je?!0:m?m(S,this):U.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:m}=t;return i===Je?this:m?m(S,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(m=!0){return Ht(m,"isCompressed"),this.assertValidity(),d(S,this,m)}toHex(m=!0){return At(this.toBytes(m))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(m=!0){return this.toBytes(m)}_setWindowSize(m){this.precompute(m)}static normalizeZ(m){return Vt(S,m)}static msm(m,y){return Ge(S,s,m,y)}static fromPrivateKey(m){return S.BASE.multiply(Xe(s,m))}}S.BASE=new S(o.Gx,o.Gy,n.ONE),S.ZERO=new S(n.ZERO,n.ONE,n.ZERO),S.Fp=n,S.Fn=s;let T=s.BITS,U=new ze(S,t.endo?Math.ceil(T/2):T);return S.BASE.precompute(8),S}function Da(e){return Uint8Array.of(e?2:3)}function Pa(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function eh(e,t={}){let{Fn:r}=e,n=t.randomBytes||re,s=Object.assign(Pa(e.Fp,r),{seed:vs(r.ORDER)});function o(d){try{return!!Xe(r,d)}catch{return!1}}function i(d,p){let{publicKey:w,publicKeyUncompressed:g}=s;try{let x=d.length;return p===!0&&x!==w||p===!1&&x!==g?!1:!!e.fromBytes(d)}catch{return!1}}function a(d=n(s.seed)){return As(Et(d,s.seed,"seed"),r.ORDER)}function c(d,p=!0){return e.BASE.multiply(Xe(r,d)).toBytes(p)}function u(d){let p=a(d);return{secretKey:p,publicKey:c(p)}}function f(d){if(typeof d=="bigint")return!1;if(d instanceof e)return!0;let{secretKey:p,publicKey:w,publicKeyUncompressed:g}=s;if(r.allowedLengths||p===w)return;let x=$("key",d).length;return x===w||x===g}function h(d,p,w=!0){if(f(d)===!0)throw new Error("first arg must be private key");if(f(p)===!1)throw new Error("second arg must be public key");let g=Xe(r,d);return e.fromHex(p).multiply(g).toBytes(w)}return Object.freeze({getPublicKey:c,getSharedSecret:h,keygen:u,Point:e,utils:{isValidSecretKey:o,isValidPublicKey:i,randomSecretKey:a,isValidPrivateKey:o,randomPrivateKey:a,normPrivateKeyToScalar:d=>Xe(r,d),precompute(d=8,p=e.BASE){return p.precompute(d,!1)}},lengths:s})}function rh(e,t,r={}){me(t),Dt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||re,s=r.hmac||((y,...b)=>Ye(t,y,gt(...b))),{Fp:o,Fn:i}=e,{ORDER:a,BITS:c}=i,{keygen:u,getPublicKey:f,getSharedSecret:h,utils:l,lengths:d}=eh(e,r),p={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},w="compact";function g(y){let b=a>>Je;return y>b}function x(y,b){if(!i.isValidNot0(b))throw new Error(`invalid signature ${y}: out of range 1..Point.Fn.ORDER`);return b}function B(y,b){ho(b);let A=d.signature,L=b==="compact"?A:b==="recovered"?A+1:void 0;return Et(y,L,`${b} signature`)}class E{constructor(b,A,L){this.r=x("r",b),this.s=x("s",A),L!=null&&(this.recovery=L),Object.freeze(this)}static fromBytes(b,A=w){B(b,A);let L;if(A==="der"){let{r:K,s:D}=Zt.toSig(Et(b));return new E(K,D)}A==="recovered"&&(L=b[0],A="compact",b=b.subarray(1));let I=i.BYTES,v=b.subarray(0,I),_=b.subarray(I,I*2);return new E(i.fromBytes(v),i.fromBytes(_),L)}static fromHex(b,A){return this.fromBytes(ye(b),A)}addRecoveryBit(b){return new E(this.r,this.s,b)}recoverPublicKey(b){let A=o.ORDER,{r:L,s:I,recovery:v}=this;if(v==null||![0,1,2,3].includes(v))throw new Error("recovery id invalid");if(a*Ua<A&&v>1)throw new Error("recovery id is ambiguous for h>1 curve");let K=v===2||v===3?L+a:L;if(!o.isValid(K))throw new Error("recovery id 2 or 3 invalid");let D=o.toBytes(K),q=e.fromBytes(gt(Da((v&1)===0),D)),V=i.inv(K),H=k($("msgHash",b)),F=i.create(-H*V),Z=i.create(I*V),Q=e.BASE.multiplyUnsafe(F).add(q.multiplyUnsafe(Z));if(Q.is0())throw new Error("point at infinify");return Q.assertValidity(),Q}hasHighS(){return g(this.s)}toBytes(b=w){if(ho(b),b==="der")return ye(Zt.hexFromSig(this));let A=i.toBytes(this.r),L=i.toBytes(this.s);if(b==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return gt(Uint8Array.of(this.recovery),A,L)}return gt(A,L)}toHex(b){return At(this.toBytes(b))}assertValidity(){}static fromCompact(b){return E.fromBytes($("sig",b),"compact")}static fromDER(b){return E.fromBytes($("sig",b),"der")}normalizeS(){return this.hasHighS()?new E(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return At(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return At(this.toBytes("compact"))}}let R=r.bits2int||function(b){if(b.length>8192)throw new Error("input is too large");let A=qe(b),L=b.length*8-c;return L>0?A>>BigInt(L):A},k=r.bits2int_modN||function(b){return i.create(R(b))},O=ce(c);function M(y){return ae("num < 2^"+c,y,Wt,O),i.toBytes(y)}function P(y,b){return Et(y,void 0,"message"),b?Et(t(y),void 0,"prehashed message"):y}function S(y,b,A){if(["recovered","canonical"].some(F=>F in A))throw new Error("sign() legacy options not supported");let{lowS:L,prehash:I,extraEntropy:v}=uo(A,p);y=P(y,I);let _=k(y),K=Xe(i,b),D=[M(K),M(_)];if(v!=null&&v!==!1){let F=v===!0?n(d.secretKey):v;D.push($("extraEntropy",F))}let q=gt(...D),V=_;function H(F){let Z=R(F);if(!i.isValidNot0(Z))return;let Q=i.inv(Z),z=e.BASE.multiply(Z).toAffine(),st=i.create(z.x);if(st===Wt)return;let Ie=i.create(Q*i.create(V+st*K));if(Ie===Wt)return;let ir=(z.x===st?0:2)|Number(z.y&Je),ar=Ie;return L&&g(Ie)&&(ar=i.neg(Ie),ir^=1),new E(st,ar,ir)}return{seed:q,k2sig:H}}function T(y,b,A={}){y=$("message",y);let{seed:L,k2sig:I}=S(y,b,A);return Hi(t.outputLen,i.BYTES,s)(L,I)}function U(y){let b,A=typeof y=="string"||Mt(y),L=!A&&y!==null&&typeof y=="object"&&typeof y.r=="bigint"&&typeof y.s=="bigint";if(!A&&!L)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(L)b=new E(y.r,y.s);else if(A){try{b=E.fromBytes($("sig",y),"der")}catch(I){if(!(I instanceof Zt.Err))throw I}if(!b)try{b=E.fromBytes($("sig",y),"compact")}catch{return!1}}return b||!1}function C(y,b,A,L={}){let{lowS:I,prehash:v,format:_}=uo(L,p);if(A=$("publicKey",A),b=P($("message",b),v),"strict"in L)throw new Error("options.strict was renamed to lowS");let K=_===void 0?U(y):E.fromBytes($("sig",y),_);if(K===!1)return!1;try{let D=e.fromBytes(A);if(I&&K.hasHighS())return!1;let{r:q,s:V}=K,H=k(b),F=i.inv(V),Z=i.create(H*F),Q=i.create(q*F),z=e.BASE.multiplyUnsafe(Z).add(D.multiplyUnsafe(Q));return z.is0()?!1:i.create(z.x)===q}catch{return!1}}function m(y,b,A={}){let{prehash:L}=uo(A,p);return b=P(b,L),E.fromBytes(y,"recovered").recoverPublicKey(b).toBytes()}return Object.freeze({keygen:u,getPublicKey:f,getSharedSecret:h,utils:l,lengths:d,Point:e,sign:T,verify:C,recoverPublicKey:m,Signature:E,hash:t})}function nh(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,s=St(t.n,{BITS:e.nBitLength,allowedLengths:n,modFromBytes:e.wrapPrivateKey}),o={Fp:r,Fn:s,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:o}}function sh(e){let{CURVE:t,curveOpts:r}=nh(e),n={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,hash:e.hash,ecdsaOpts:n}}function oh(e,t){let r=t.Point;return Object.assign({},t,{ProjectivePoint:r,CURVE:Object.assign({},e,tn(r.Fn.ORDER,r.Fn.BITS))})}function Na(e){let{CURVE:t,curveOpts:r,hash:n,ecdsaOpts:s}=sh(e),o=th(t,r),i=rh(o,n,s);return oh(e,i)}function ka(e,t){let r=n=>Na({...e,hash:n});return{...r(t),create:r}}var mo={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},ih={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Ma=BigInt(2);function ah(e){let t=mo.p,r=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,f=u*u*e%t,h=J(f,r,t)*f%t,l=J(h,r,t)*f%t,d=J(l,Ma,t)*u%t,p=J(d,s,t)*d%t,w=J(p,o,t)*p%t,g=J(w,a,t)*w%t,x=J(g,c,t)*g%t,B=J(x,a,t)*w%t,E=J(B,r,t)*f%t,R=J(E,i,t)*p%t,k=J(R,n,t)*u%t,O=J(k,Ma,t);if(!po.eql(po.sqr(O),e))throw new Error("Cannot find square root");return O}var po=St(mo.p,{sqrt:ah}),Qe=ka({...mo,Fp:po,lowS:!0,endo:ih},ie);function Oa(e,t,r,n){let s=jr.digest(r instanceof Uint8Array?r:r.subarray());if(an(s))return s.then(({digest:o})=>(n?.signal?.throwIfAborted(),Qe.verify(t,o,e))).catch(o=>{throw o.name==="AbortError"?o:new Br(String(o))});try{return n?.signal?.throwIfAborted(),Qe.verify(t,s.digest,e)}catch(o){throw new Br(String(o))}}var yn=class{type="secp256k1";raw;_key;constructor(t){this._key=qa(t),this.raw=Ha(this._key)}toMultihash(){return Rt.digest(te(this))}toCID(){return ht.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:yt(this.raw,t.raw)}verify(t,r,n){return Oa(this._key,r,t,n)}};function Va(e){return new yn(e)}function Ha(e){return Qe.ProjectivePoint.fromHex(e).toRawBytes(!0)}function qa(e){try{return Qe.ProjectivePoint.fromHex(e),e}catch(t){throw new Te(String(t))}}function Kr(e,t){let{Type:r,Data:n}=$t.decode(e),s=n??new Uint8Array;switch(r){case at.RSA:return ao(s,t);case at.Ed25519:return da(s);case at.secp256k1:return Va(s);case at.ECDSA:return xi(s);default:throw new Ce}}function te(e){return $t.encode({Type:at[e.type],Data:e.raw})}var Fa=Symbol.for("nodejs.util.inspect.custom"),ch=114,Rr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Nn]=!0;toString(){return this.string==null&&(this.string=rt.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ht.createV1(ch,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return yt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return yt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Fa](){return`PeerId(${this.toString()})`}},gn=class extends Rr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},bn=class extends Rr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},xn=class extends Rr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},fh=2336,yo=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Rt.digest(Y(this.url))}[Fa](){return`PeerId(${this.url})`}[Nn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ht.createV1(fh,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=j(t)),t.toString()===this.toString())}};function go(e){if(e.type==="Ed25519")return new bn({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new xn({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new gn({multihash:e.toCID().multihash,publicKey:e});throw new Ce}function wn(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var En=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},tr=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new En(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let r=this.head;this.head=r.next=new En(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var bo=class extends Error{type;code;constructor(t,r){super(t??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Sn(e={}){return uh(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},e)}function uh(e,t){t=t??{};let r=t.onEnd,n=new tr,s,o,i,a=wn(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((g,x)=>{o=B=>{o=null,n.push(B);try{g(e(n))}catch(E){x(E)}return s}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=wn()})}},u=g=>o!=null?o(g):(n.push(g),s),f=g=>(n=new tr,o!=null?o({error:g}):(n.push({error:g}),s)),h=g=>{if(i)return s;if(t?.objectMode!==!0&&g?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:g})},l=g=>i?s:(i=!0,g!=null?f(g):u({done:!0})),d=()=>(n=new tr,l(),{done:!0}),p=g=>(l(g),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:d,throw:p,push:h,end:l,get readableLength(){return n.size},onEmpty:async g=>{let x=g?.signal;if(x?.throwIfAborted(),n.isEmpty())return;let B,E;x!=null&&(B=new Promise((R,k)=>{E=()=>{k(new bo)},x.addEventListener("abort",E)}));try{await Promise.race([a.promise,B])}finally{E!=null&&x!=null&&x?.removeEventListener("abort",E)}}},r==null)return s;let w=s;return s={[Symbol.asyncIterator](){return this},next(){return w.next()},throw(g){return w.throw(g),r!=null&&(r(g),r=void 0),{done:!0}},return(){return w.return(),r!=null&&(r(),r=void 0),{done:!0}},push:h,end(g){return w.end(g),r!=null&&(r(g),r=void 0),s},get readableLength(){return w.readableLength},onEmpty:g=>w.onEmpty(g)},s}var xo=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},wo=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},za=e=>globalThis.DOMException===void 0?new wo(e):new DOMException(e),Ga=e=>{let t=e.reason===void 0?za("This operation was aborted."):e.reason;return t instanceof Error?t:za(t)};function Eo(e,t){let{milliseconds:r,fallback:n,message:s,customTimers:o={setTimeout,clearTimeout}}=t,i,a,u=new Promise((f,h)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(t.signal){let{signal:d}=t;d.aborted&&h(Ga(d)),a=()=>{h(Ga(d))},d.addEventListener("abort",a,{once:!0})}if(r===Number.POSITIVE_INFINITY){e.then(f,h);return}let l=new xo;i=o.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(d){h(d)}return}typeof e.cancel=="function"&&e.cancel(),s===!1?f():s instanceof Error?h(s):(l.message=s??`Promise timed out after ${r} milliseconds`,h(l))},r),(async()=>{try{f(await e)}catch(d){h(d)}})()}).finally(()=>{u.clear(),a&&t.signal&&t.signal.removeEventListener("abort",a)});return u.clear=()=>{o.clearTimeout.call(void 0,i),i=void 0},u}var hh=e=>{let t=e.addEventListener||e.on||e.addListener,r=e.removeEventListener||e.off||e.removeListener;if(!t||!r)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(e),removeListener:r.bind(e)}};function lh(e,t,r){let n,s=new Promise((o,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:u,removeListener:f}=hh(e),h=(...d)=>{let p=r.multiArgs?d:d[0];r.filter&&!r.filter(p)||(c.push(p),r.count===c.length&&(n(),o(c)))},l=d=>{n(),i(d)};n=()=>{for(let d of a)f(d,h);for(let d of r.rejectionEvents)f(d,l)};for(let d of a)u(d,h);for(let d of r.rejectionEvents)u(d,l);r.signal&&r.signal.addEventListener("abort",()=>{l(r.signal.reason)},{once:!0}),r.resolveImmediately&&o(c)});if(s.cancel=n,typeof r.timeout=="number"){let o=Eo(s,{milliseconds:r.timeout});return o.cancel=n,o}return s}function ja(e,t,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=lh(e,t,r),s=n.then(o=>o[0]);return s.cancel=n.cancel,s}var Le=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function dh(e){return e.reason}async function $a(e,t,r){if(t==null)return e;let n=r?.translateError??dh;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let s;try{return await Promise.race([e,new Promise((o,i)=>{s=()=>{i(n(t))},t.addEventListener("abort",s)})])}finally{s!=null&&t.removeEventListener("abort",s)}}var ph=Math.pow(2,20)*4,vn=class extends Fr{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;constructor(t){super(),this.status="open",this.log=t.log,this.direction=t.direction??"outbound",this.inactivityTimeout=t.inactivityTimeout??12e4,this.maxReadBufferLength=t.maxReadBufferLength??ph,this.maxWriteBufferLength=t.maxWriteBufferLength,this.maxMessageSize=t.maxMessageSize,this.readBuffer=new G,this.writeBuffer=new G,this.readStatus="readable",this.remoteReadStatus="readable",this.writeStatus="writable",this.remoteWriteStatus="writable",this.sendingData=!1,this.writableNeedsDrain=!1,this.timeline={open:Date.now()},this.processSendQueue=this.processSendQueue.bind(this);let r=()=>{this.log.trace("drain event received, continue sending data"),this.writableNeedsDrain=!1,this.processSendQueue()};this.addEventListener("drain",r)}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let t=Sn(),r=o=>{t.push(o.data)};this.addEventListener("message",r);let n=o=>{t.end(o.error)};this.addEventListener("close",n);let s=()=>{t.end()};this.addEventListener("remoteCloseWrite",s);try{yield*t}finally{this.removeEventListener("message",r),this.removeEventListener("close",n),this.removeEventListener("remoteCloseWrite",s)}}isReadable(){return this.status==="open"}send(t){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new he(`Cannot write to a stream that is ${this.writeStatus}`);return this.log.trace("append %d bytes to write buffer",t.byteLength),this.writeBuffer.append(t),this.processSendQueue()}abort(t){if(!(this.status==="aborted"||this.status==="reset"||this.status==="closed")){this.log.error("abort with error - %e",t),this.status="aborted",this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle")),this.writeStatus="closed",this.remoteWriteStatus="closed",this.readStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now();try{this.sendReset(t)}catch(r){this.log("failed to send reset to remote - %e",r)}this.dispatchEvent(new qr(t))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new he("Cannot pause a stream that is closing/closed");this.readStatus!=="paused"&&(this.readStatus="paused",this.sendPause())}resume(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new he("Cannot resume a stream that is closing/closed");this.readStatus!=="readable"&&(this.readStatus="readable",this.dispatchReadBuffer(),this.sendResume())}push(t){if(this.readStatus==="closed"||this.readStatus==="closing")throw new he(`Cannot push data onto a stream that is ${this.readStatus}`);if(t.byteLength!==0){if(this.readBuffer.append(t),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}onData(t){if(t.byteLength!==0){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("ignoring data - read status %s",this.readStatus);return}this.readBuffer.append(t),this.dispatchReadBuffer()}}addEventListener(...t){super.addEventListener.apply(this,t),t[0]==="message"&&this.readBuffer.byteLength>0&&queueMicrotask(()=>{this.dispatchReadBuffer()})}onRemoteReset(){this.log("remote reset"),this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed");let t=new Or;this.dispatchEvent(new Vr(t))}onTransportClosed(t){this.log("transport closed"),this.readStatus==="readable"&&this.readBuffer.byteLength===0&&(this.readStatus="closed"),this.remoteReadStatus!=="closed"&&(this.remoteReadStatus="closed"),this.remoteWriteStatus!=="closed"&&(this.remoteWriteStatus="closed"),this.writeStatus!=="closed"&&(this.writeStatus="closed"),t!=null?this.abort(t):(this.status==="open"||this.status==="closing")&&(this.timeline.close=Date.now(),this.status="closed",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.dispatchEvent(new Ke))}onRemoteCloseWrite(){this.remoteWriteStatus!=="closed"&&(this.log.trace("on remote close write"),this.remoteWriteStatus="closed",this.safeDispatchEvent("remoteCloseWrite"),this.writeStatus==="closed"&&this.onTransportClosed())}onRemoteCloseRead(){this.log.trace("on remote close read"),this.remoteReadStatus="closed",this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle"))}processSendQueue(){if(this.writableNeedsDrain)return this.log.trace("not processing send queue as drain is required"),this.checkWriteBufferLength(),!1;if(this.writeBuffer.byteLength===0)return this.log.trace("not processing send queue as no bytes to send"),!0;if(this.sendingData)return this.log.trace("not processing send queue as already sending data"),!0;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let t=!0,r=this.writeBuffer.byteLength,n=0;for(;this.writeBuffer.byteLength>0;){let s=Math.min(this.maxMessageSize??this.writeBuffer.byteLength,this.writeBuffer.byteLength);if(s===0){t=!1;break}let o=this.writeBuffer.sublist(0,s),i=new G(o);this.writeBuffer.consume(o.byteLength);let a=this.sendData(o);if(t=a.canSendMore,n+=a.sentBytes,a.sentBytes!==i.byteLength&&(i.consume(a.sentBytes),this.writeBuffer.prepend(i)),!t)break}return t||(this.log.trace("sent %d/%d bytes, pausing sending because underlying stream is full, %d bytes left in the write buffer",n,r,this.writeBuffer.byteLength),this.writableNeedsDrain=!0,this.checkWriteBufferLength()),this.writeBuffer.byteLength===0&&this.safeDispatchEvent("idle"),t}finally{this.sendingData=!1}}dispatchReadBuffer(){try{if(this.listenerCount("message")===0){this.log.trace("not dispatching pause buffer as there are no listeners for the message event");return}if(this.readBuffer.byteLength===0){this.log.trace("not dispatching pause buffer as there is no data to dispatch");return}if(this.readStatus==="paused"){this.log.trace("not dispatching pause buffer we are paused");return}if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("dropping %d bytes because the readable end is %s",this.readBuffer.byteLength,this.readStatus),this.readBuffer.consume(this.readBuffer.byteLength);return}let t=this.readBuffer.sublist();this.readBuffer.consume(t.byteLength),this.dispatchEvent(new Hr(t))}finally{this.remoteWriteStatus==="closed"&&(this.readStatus="closed"),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new cr(`Read buffer length of ${this.readBuffer.byteLength} exceeded limit of ${this.maxReadBufferLength}, read status is ${this.readStatus}`))}checkWriteBufferLength(){this.maxWriteBufferLength!=null&&this.writeBuffer.byteLength>this.maxWriteBufferLength&&this.abort(new cr(`Write buffer length of ${this.writeBuffer.byteLength} exceeded limit of ${this.maxWriteBufferLength}, write status is ${this.writeStatus}`))}onMuxerNeedsDrain(){this.writableNeedsDrain=!0}onMuxerDrain(){this.safeDispatchEvent("drain")}};var mh=4194304,An=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Ur=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},vo=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Ao=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function yh(e){return typeof e?.closeRead=="function"}function gh(e){return typeof e?.close=="function"}function So(e){return yh(e)?e.readStatus==="closing"||e.readStatus==="closed":gh(e)?e.status!=="open":!1}function bh(e){return e?.addEventListener!=null&&e?.removeEventListener!=null&&e?.send!=null&&e?.push!=null&&e?.log!=null}function xh(e,t){let r=t?.maxBufferSize??mh,n=new G,s=Promise.withResolvers(),o=!1;if(!bh(e))throw new tt("Argument should be a Stream or a Multiaddr");let i=f=>{if(t?.stopPropagation,n.append(f.data),n.byteLength>r){let h=n.byteLength;n.consume(n.byteLength),s.reject(new Error(`Read buffer overflow - ${h} > ${r}`))}s.resolve()};e.addEventListener("message",i);let a=f=>{f.error!=null?s.reject(f.error):s.resolve()};e.addEventListener("close",a);let c=()=>{s.resolve()};e.addEventListener("remoteCloseWrite",c);let u={readBuffer:n,async read(f){if(o===!0)throw new An("Stream was unwrapped");if(So(e)){if(f?.bytes==null)return null;if(n.byteLength<f.bytes)throw new Le(`Unexpected EOF - stream closed after reading ${n.byteLength}/${f.bytes} bytes`)}let h=f?.bytes??1;for(;;){if(n.byteLength>=h){s.resolve();break}if(await $a(s.promise,f?.signal),So(e)){if(n.byteLength===0&&f?.bytes==null)return null;break}s=Promise.withResolvers()}let l=f?.bytes??n.byteLength;if(n.byteLength<l){if(So(e))throw new Le(`Unexpected EOF - stream closed while reading ${n.byteLength}/${l} bytes`);return u.read(f)}let d=n.sublist(0,l);return n.consume(l),d},async write(f,h){if(o===!0)throw new An("Stream was unwrapped");e.send(f)||await ja(e,"drain",{signal:h?.signal,rejectionEvents:["close"]})},unwrap(){return o||(o=!0,e.removeEventListener("message",i),e.removeEventListener("close",a),e.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(e.log("stream unwrapped with %d unread bytes",n.byteLength),e.push(n))),e}};return u}function Bo(e,t={}){let r=xh(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=Tt(t.maxDataLength));let n=t?.lengthDecoder??fn,s=t?.lengthEncoder??pa;return{async read(i){let a=-1,c=new G;for(;;){let f=await r.read({...i,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(h){if(h instanceof RangeError)continue;throw h}if(a<0)throw new Ur("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new Ao(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new vo(`Message length too long - ${a} > ${t.maxDataLength}`);let u=await r.read({...i,bytes:a});if(u==null)throw new Le(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw new Le(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await r.write(new G(s(i.byteLength),i),a)},async writeV(i,a){let c=new G(...i.flatMap(u=>[s(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}var wh=1024*1024*4,Eh=1024*1024*4,Bn=class{buffer;maxBufferSize;lengthDecoder;maxDataLength;encodingLength;constructor(t={}){this.buffer=new G,this.maxBufferSize=t.maxBufferSize??wh,this.maxDataLength=t.maxDataLength??Eh,this.lengthDecoder=t.lengthDecoder??fn,this.encodingLength=t.encodingLength??Tt}*decode(t){if(this.buffer.append(t),this.buffer.byteLength>this.maxBufferSize)throw new tt(`Buffer length limit exceeded - ${this.buffer.byteLength}/${this.maxBufferSize}`);for(;;){let r;try{r=this.lengthDecoder(this.buffer)}catch(o){if(o instanceof RangeError)break;throw o}if(r<0||r>this.maxDataLength)throw new Ur("Invalid message length");let n=this.encodingLength(r),s=n+r;if(this.buffer.byteLength>=s){let o=this.buffer.sublist(n,s);this.buffer.consume(s),o.byteLength>0&&(yield o)}else break}}};var er=!!globalThis.process?.env?.DUMP_SESSION_KEYS,Lo=16;function Wa(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Ln(e){if(typeof e!="boolean")throw new Error(`boolean expected, not ${e}`)}function _n(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function mt(e,...t){if(!Wa(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function _o(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Ya(e,t){mt(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Yt(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function Xt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Sh(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}var vh=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Ah(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function In(e){if(typeof e=="string")e=Ah(e);else if(Wa(e))e=Tn(e);else throw new Error("Uint8Array expected, got "+typeof e);return e}function Xa(e,t){if(t==null||typeof t!="object")throw new Error("options must be defined");return Object.assign(e,t)}function Ja(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}var Io=(e,t)=>{function r(n,...s){if(mt(n),!vh)throw new Error("Non little-endian hardware is not yet supported");if(e.nonceLength!==void 0){let f=s[0];if(!f)throw new Error("nonce / iv required");e.varSizeNonce?mt(f):mt(f,e.nonceLength)}let o=e.tagLength;o&&s[1]!==void 0&&mt(s[1]);let i=t(n,...s),a=(f,h)=>{if(h!==void 0){if(f!==2)throw new Error("cipher output not supported");mt(h)}},c=!1;return{encrypt(f,h){if(c)throw new Error("cannot encrypt() twice with same key + nonce");return c=!0,mt(f),a(i.encrypt.length,h),i.encrypt(f,h)},decrypt(f,h){if(mt(f),o&&f.length<o)throw new Error("invalid ciphertext length: smaller than tagLength="+o);return a(i.decrypt.length,h),i.decrypt(f,h)}}}return Object.assign(r,e),r};function To(e,t,r=!0){if(t===void 0)return new Uint8Array(e);if(t.length!==e)throw new Error("invalid output length, expected "+e+", got: "+t.length);if(r&&!Bh(t))throw new Error("invalid output, must be aligned");return t}function Za(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let s=BigInt(32),o=BigInt(4294967295),i=Number(r>>s&o),a=Number(r&o),c=n?4:0,u=n?0:4;e.setUint32(t+c,i,n),e.setUint32(t+u,a,n)}function Qa(e,t,r){Ln(r);let n=new Uint8Array(16),s=Sh(n);return Za(s,0,BigInt(t),r),Za(s,8,BigInt(e),r),n}function Bh(e){return e.byteOffset%4===0}function Tn(e){return Uint8Array.from(e)}var ec=e=>Uint8Array.from(e.split("").map(t=>t.charCodeAt(0))),Lh=ec("expand 16-byte k"),_h=ec("expand 32-byte k"),Ih=Yt(Lh),Th=Yt(_h);function N(e,t){return e<<t|e>>>32-t}function Co(e){return e.byteOffset%4===0}var Cn=64,Ch=16,rc=2**32-1,tc=new Uint32Array;function Kh(e,t,r,n,s,o,i,a){let c=s.length,u=new Uint8Array(Cn),f=Yt(u),h=Co(s)&&Co(o),l=h?Yt(s):tc,d=h?Yt(o):tc;for(let p=0;p<c;i++){if(e(t,r,n,f,i,a),i>=rc)throw new Error("arx: counter overflow");let w=Math.min(Cn,c-p);if(h&&w===Cn){let g=p/4;if(p%4!==0)throw new Error("arx: invalid block position");for(let x=0,B;x<Ch;x++)B=g+x,d[B]=l[B]^f[x];p+=Cn;continue}for(let g=0,x;g<w;g++)x=p+g,o[x]=s[x]^u[g];p+=w}}function Ko(e,t){let{allowShortKeys:r,extendNonceFn:n,counterLength:s,counterRight:o,rounds:i}=Xa({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if(typeof e!="function")throw new Error("core must be a function");return _n(s),_n(i),Ln(o),Ln(r),(a,c,u,f,h=0)=>{mt(a),mt(c),mt(u);let l=u.length;if(f===void 0&&(f=new Uint8Array(l)),mt(f),_n(h),h<0||h>=rc)throw new Error("arx: counter overflow");if(f.length<l)throw new Error(`arx: output (${f.length}) is shorter than data (${l})`);let d=[],p=a.length,w,g;if(p===32)d.push(w=Tn(a)),g=Th;else if(p===16&&r)w=new Uint8Array(32),w.set(a),w.set(a,16),g=Ih,d.push(w);else throw new Error(`arx: invalid 32-byte key, got length=${p}`);Co(c)||d.push(c=Tn(c));let x=Yt(w);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(g,x,Yt(c.subarray(0,16)),x),c=c.subarray(16)}let B=16-s;if(B!==c.length)throw new Error(`arx: nonce must be ${B} or 16 bytes`);if(B!==12){let R=new Uint8Array(12);R.set(c,o?0:12-c.length),c=R,d.push(c)}let E=Yt(c);return Kh(e,g,x,E,u,f,h,i),Xt(...d),f}}var ut=(e,t)=>e[t++]&255|(e[t++]&255)<<8,Ro=class{constructor(t){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,t=In(t),mt(t,32);let r=ut(t,0),n=ut(t,2),s=ut(t,4),o=ut(t,6),i=ut(t,8),a=ut(t,10),c=ut(t,12),u=ut(t,14);this.r[0]=r&8191,this.r[1]=(r>>>13|n<<3)&8191,this.r[2]=(n>>>10|s<<6)&7939,this.r[3]=(s>>>7|o<<9)&8191,this.r[4]=(o>>>4|i<<12)&255,this.r[5]=i>>>1&8190,this.r[6]=(i>>>14|a<<2)&8191,this.r[7]=(a>>>11|c<<5)&8065,this.r[8]=(c>>>8|u<<8)&8191,this.r[9]=u>>>5&127;for(let f=0;f<8;f++)this.pad[f]=ut(t,16+2*f)}process(t,r,n=!1){let s=n?0:2048,{h:o,r:i}=this,a=i[0],c=i[1],u=i[2],f=i[3],h=i[4],l=i[5],d=i[6],p=i[7],w=i[8],g=i[9],x=ut(t,r+0),B=ut(t,r+2),E=ut(t,r+4),R=ut(t,r+6),k=ut(t,r+8),O=ut(t,r+10),M=ut(t,r+12),P=ut(t,r+14),S=o[0]+(x&8191),T=o[1]+((x>>>13|B<<3)&8191),U=o[2]+((B>>>10|E<<6)&8191),C=o[3]+((E>>>7|R<<9)&8191),m=o[4]+((R>>>4|k<<12)&8191),y=o[5]+(k>>>1&8191),b=o[6]+((k>>>14|O<<2)&8191),A=o[7]+((O>>>11|M<<5)&8191),L=o[8]+((M>>>8|P<<8)&8191),I=o[9]+(P>>>5|s),v=0,_=v+S*a+T*(5*g)+U*(5*w)+C*(5*p)+m*(5*d);v=_>>>13,_&=8191,_+=y*(5*l)+b*(5*h)+A*(5*f)+L*(5*u)+I*(5*c),v+=_>>>13,_&=8191;let K=v+S*c+T*a+U*(5*g)+C*(5*w)+m*(5*p);v=K>>>13,K&=8191,K+=y*(5*d)+b*(5*l)+A*(5*h)+L*(5*f)+I*(5*u),v+=K>>>13,K&=8191;let D=v+S*u+T*c+U*a+C*(5*g)+m*(5*w);v=D>>>13,D&=8191,D+=y*(5*p)+b*(5*d)+A*(5*l)+L*(5*h)+I*(5*f),v+=D>>>13,D&=8191;let q=v+S*f+T*u+U*c+C*a+m*(5*g);v=q>>>13,q&=8191,q+=y*(5*w)+b*(5*p)+A*(5*d)+L*(5*l)+I*(5*h),v+=q>>>13,q&=8191;let V=v+S*h+T*f+U*u+C*c+m*a;v=V>>>13,V&=8191,V+=y*(5*g)+b*(5*w)+A*(5*p)+L*(5*d)+I*(5*l),v+=V>>>13,V&=8191;let H=v+S*l+T*h+U*f+C*u+m*c;v=H>>>13,H&=8191,H+=y*a+b*(5*g)+A*(5*w)+L*(5*p)+I*(5*d),v+=H>>>13,H&=8191;let F=v+S*d+T*l+U*h+C*f+m*u;v=F>>>13,F&=8191,F+=y*c+b*a+A*(5*g)+L*(5*w)+I*(5*p),v+=F>>>13,F&=8191;let Z=v+S*p+T*d+U*l+C*h+m*f;v=Z>>>13,Z&=8191,Z+=y*u+b*c+A*a+L*(5*g)+I*(5*w),v+=Z>>>13,Z&=8191;let Q=v+S*w+T*p+U*d+C*l+m*h;v=Q>>>13,Q&=8191,Q+=y*f+b*u+A*c+L*a+I*(5*g),v+=Q>>>13,Q&=8191;let z=v+S*g+T*w+U*p+C*d+m*l;v=z>>>13,z&=8191,z+=y*h+b*f+A*u+L*c+I*a,v+=z>>>13,z&=8191,v=(v<<2)+v|0,v=v+_|0,_=v&8191,v=v>>>13,K+=v,o[0]=_,o[1]=K,o[2]=D,o[3]=q,o[4]=V,o[5]=H,o[6]=F,o[7]=Z,o[8]=Q,o[9]=z}finalize(){let{h:t,pad:r}=this,n=new Uint16Array(10),s=t[1]>>>13;t[1]&=8191;for(let a=2;a<10;a++)t[a]+=s,s=t[a]>>>13,t[a]&=8191;t[0]+=s*5,s=t[0]>>>13,t[0]&=8191,t[1]+=s,s=t[1]>>>13,t[1]&=8191,t[2]+=s,n[0]=t[0]+5,s=n[0]>>>13,n[0]&=8191;for(let a=1;a<10;a++)n[a]=t[a]+s,s=n[a]>>>13,n[a]&=8191;n[9]-=8192;let o=(s^1)-1;for(let a=0;a<10;a++)n[a]&=o;o=~o;for(let a=0;a<10;a++)t[a]=t[a]&o|n[a];t[0]=(t[0]|t[1]<<13)&65535,t[1]=(t[1]>>>3|t[2]<<10)&65535,t[2]=(t[2]>>>6|t[3]<<7)&65535,t[3]=(t[3]>>>9|t[4]<<4)&65535,t[4]=(t[4]>>>12|t[5]<<1|t[6]<<14)&65535,t[5]=(t[6]>>>2|t[7]<<11)&65535,t[6]=(t[7]>>>5|t[8]<<8)&65535,t[7]=(t[8]>>>8|t[9]<<5)&65535;let i=t[0]+r[0];t[0]=i&65535;for(let a=1;a<8;a++)i=(t[a]+r[a]|0)+(i>>>16)|0,t[a]=i&65535;Xt(n)}update(t){_o(this),t=In(t),mt(t);let{buffer:r,blockLen:n}=this,s=t.length;for(let o=0;o<s;){let i=Math.min(n-this.pos,s-o);if(i===n){for(;n<=s-o;o+=n)this.process(t,o);continue}r.set(t.subarray(o,o+i),this.pos),this.pos+=i,o+=i,this.pos===n&&(this.process(r,0,!1),this.pos=0)}return this}destroy(){Xt(this.h,this.r,this.buffer,this.pad)}digestInto(t){_o(this),Ya(t,this),this.finished=!0;let{buffer:r,h:n}=this,{pos:s}=this;if(s){for(r[s++]=1;s<16;s++)r[s]=0;this.process(r,0,!0)}this.finalize();let o=0;for(let i=0;i<8;i++)t[o++]=n[i]>>>0,t[o++]=n[i]>>>8;return t}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}};function Rh(e){let t=(n,s)=>e(s).update(In(n)).digest(),r=e(new Uint8Array(32));return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=n=>e(n),t}var nc=Rh(e=>new Ro(e));function ic(e,t,r,n,s,o=20){let i=e[0],a=e[1],c=e[2],u=e[3],f=t[0],h=t[1],l=t[2],d=t[3],p=t[4],w=t[5],g=t[6],x=t[7],B=s,E=r[0],R=r[1],k=r[2],O=i,M=a,P=c,S=u,T=f,U=h,C=l,m=d,y=p,b=w,A=g,L=x,I=B,v=E,_=R,K=k;for(let q=0;q<o;q+=2)O=O+T|0,I=N(I^O,16),y=y+I|0,T=N(T^y,12),O=O+T|0,I=N(I^O,8),y=y+I|0,T=N(T^y,7),M=M+U|0,v=N(v^M,16),b=b+v|0,U=N(U^b,12),M=M+U|0,v=N(v^M,8),b=b+v|0,U=N(U^b,7),P=P+C|0,_=N(_^P,16),A=A+_|0,C=N(C^A,12),P=P+C|0,_=N(_^P,8),A=A+_|0,C=N(C^A,7),S=S+m|0,K=N(K^S,16),L=L+K|0,m=N(m^L,12),S=S+m|0,K=N(K^S,8),L=L+K|0,m=N(m^L,7),O=O+U|0,K=N(K^O,16),A=A+K|0,U=N(U^A,12),O=O+U|0,K=N(K^O,8),A=A+K|0,U=N(U^A,7),M=M+C|0,I=N(I^M,16),L=L+I|0,C=N(C^L,12),M=M+C|0,I=N(I^M,8),L=L+I|0,C=N(C^L,7),P=P+m|0,v=N(v^P,16),y=y+v|0,m=N(m^y,12),P=P+m|0,v=N(v^P,8),y=y+v|0,m=N(m^y,7),S=S+T|0,_=N(_^S,16),b=b+_|0,T=N(T^b,12),S=S+T|0,_=N(_^S,8),b=b+_|0,T=N(T^b,7);let D=0;n[D++]=i+O|0,n[D++]=a+M|0,n[D++]=c+P|0,n[D++]=u+S|0,n[D++]=f+T|0,n[D++]=h+U|0,n[D++]=l+C|0,n[D++]=d+m|0,n[D++]=p+y|0,n[D++]=w+b|0,n[D++]=g+A|0,n[D++]=x+L|0,n[D++]=B+I|0,n[D++]=E+v|0,n[D++]=R+_|0,n[D++]=k+K|0}function Uh(e,t,r,n){let s=e[0],o=e[1],i=e[2],a=e[3],c=t[0],u=t[1],f=t[2],h=t[3],l=t[4],d=t[5],p=t[6],w=t[7],g=r[0],x=r[1],B=r[2],E=r[3];for(let k=0;k<20;k+=2)s=s+c|0,g=N(g^s,16),l=l+g|0,c=N(c^l,12),s=s+c|0,g=N(g^s,8),l=l+g|0,c=N(c^l,7),o=o+u|0,x=N(x^o,16),d=d+x|0,u=N(u^d,12),o=o+u|0,x=N(x^o,8),d=d+x|0,u=N(u^d,7),i=i+f|0,B=N(B^i,16),p=p+B|0,f=N(f^p,12),i=i+f|0,B=N(B^i,8),p=p+B|0,f=N(f^p,7),a=a+h|0,E=N(E^a,16),w=w+E|0,h=N(h^w,12),a=a+h|0,E=N(E^a,8),w=w+E|0,h=N(h^w,7),s=s+u|0,E=N(E^s,16),p=p+E|0,u=N(u^p,12),s=s+u|0,E=N(E^s,8),p=p+E|0,u=N(u^p,7),o=o+f|0,g=N(g^o,16),w=w+g|0,f=N(f^w,12),o=o+f|0,g=N(g^o,8),w=w+g|0,f=N(f^w,7),i=i+h|0,x=N(x^i,16),l=l+x|0,h=N(h^l,12),i=i+h|0,x=N(x^i,8),l=l+x|0,h=N(h^l,7),a=a+c|0,B=N(B^a,16),d=d+B|0,c=N(c^d,12),a=a+c|0,B=N(B^a,8),d=d+B|0,c=N(c^d,7);let R=0;n[R++]=s,n[R++]=o,n[R++]=i,n[R++]=a,n[R++]=g,n[R++]=x,n[R++]=B,n[R++]=E}var Dh=Ko(ic,{counterRight:!1,counterLength:4,allowShortKeys:!1}),Ph=Ko(ic,{counterRight:!1,counterLength:8,extendNonceFn:Uh,allowShortKeys:!1});var Nh=new Uint8Array(16),sc=(e,t)=>{e.update(t);let r=t.length%16;r&&e.update(Nh.subarray(r))},kh=new Uint8Array(32);function oc(e,t,r,n,s){let o=e(t,r,kh),i=nc.create(o);s&&sc(i,s),sc(i,n);let a=Qa(n.length,s?s.length:0,!0);i.update(a);let c=i.digest();return Xt(o,a),c}var ac=e=>(t,r,n)=>({encrypt(o,i){let a=o.length;i=To(a+16,i,!1),i.set(o);let c=i.subarray(0,-16);e(t,r,c,c,1);let u=oc(e,t,r,c,n);return i.set(u,a),Xt(u),i},decrypt(o,i){i=To(o.length-16,i,!1);let a=o.subarray(0,-16),c=o.subarray(-16),u=oc(e,t,r,a,n);if(!Ja(c,u))throw new Error("invalid tag");return i.set(o.subarray(0,-16)),e(t,r,i,i,1),Xt(u),i}}),Uo=Io({blockSize:64,nonceLength:12,tagLength:16},ac(Dh)),dg=Io({blockSize:64,nonceLength:24,tagLength:16},ac(Ph));function fc(e,t,r){return me(e),r===void 0&&(r=new Uint8Array(e.outputLen)),Ye(e,ee(r),ee(t))}var Do=Uint8Array.from([0]),cc=Uint8Array.of();function uc(e,t,r,n=32){me(e),pe(n);let s=e.outputLen;if(n>255*s)throw new Error("Length should be <= 255*HashLen");let o=Math.ceil(n/s);r===void 0&&(r=cc);let i=new Uint8Array(o*s),a=Ye.create(e,t),c=a._cloneInto(),u=new Uint8Array(a.outputLen);for(let f=0;f<o;f++)Do[0]=f+1,c.update(f===0?cc:u).update(r).update(Do).digestInto(u),i.set(u,s*f),a._cloneInto(c);return a.destroy(),c.destroy(),_t(u,Do),i.slice(0,n)}var Kn={hashSHA256(e){return ie(e.subarray())},getHKDF(e,t){let r=fc(ie,t,e),s=uc(ie,r,void 0,96),o=s.subarray(0,32),i=s.subarray(32,64),a=s.subarray(64,96);return[o,i,a]},generateX25519KeyPair(){let e=Ar.utils.randomSecretKey();return{publicKey:Ar.getPublicKey(e),privateKey:e}},generateX25519KeyPairFromSeed(e){return{publicKey:Ar.getPublicKey(e),privateKey:e}},generateX25519SharedKey(e,t){return Ar.getSharedSecret(e.subarray(),t.subarray())},chaCha20Poly1305Encrypt(e,t,r,n){return Uo(n,t,r).encrypt(e.subarray())},chaCha20Poly1305Decrypt(e,t,r,n,s){return Uo(n,t,r).decrypt(e.subarray(),s)}};var hc=Kn;function lc(e){return{generateKeypair:e.generateX25519KeyPair,dh:(t,r)=>e.generateX25519SharedKey(t.privateKey,r).subarray(0,32),encrypt:e.chaCha20Poly1305Encrypt,decrypt:e.chaCha20Poly1305Decrypt,hash:e.hashSHA256,hkdf:e.getHKDF}}var rr=e=>{let t=ct(2);return t[0]=e>>8,t[1]=e,t};rr.bytes=2;var nr=e=>{if(e.length<2)throw RangeError("Could not decode int16BE");if(e instanceof Uint8Array){let t=0;return t+=e[0]<<8,t+=e[1],t}return e.getUint16(0)};nr.bytes=2;function dc(e){return{xxHandshakeSuccesses:e.registerCounter("libp2p_noise_xxhandshake_successes_total",{help:"Total count of noise xxHandshakes successes_"}),xxHandshakeErrors:e.registerCounter("libp2p_noise_xxhandshake_error_total",{help:"Total count of noise xxHandshakes errors"}),encryptedPackets:e.registerCounter("libp2p_noise_encrypted_packets_total",{help:"Total count of noise encrypted packets successfully"}),decryptedPackets:e.registerCounter("libp2p_noise_decrypted_packets_total",{help:"Total count of noise decrypted packets"}),decryptErrors:e.registerCounter("libp2p_noise_decrypt_errors_total",{help:"Total count of noise decrypt errors"})}}function Po(e,t){!t.enabled||!er||(e?(t(`LOCAL_STATIC_PUBLIC_KEY ${j(e.publicKey,"hex")}`),t(`LOCAL_STATIC_PRIVATE_KEY ${j(e.privateKey,"hex")}`)):t("Missing local static keys."))}function No(e,t){!t.enabled||!er||(e?(t(`LOCAL_PUBLIC_EPHEMERAL_KEY ${j(e.publicKey,"hex")}`),t(`LOCAL_PRIVATE_EPHEMERAL_KEY ${j(e.privateKey,"hex")}`)):t("Missing local ephemeral keys."))}function pc(e,t){!t.enabled||!er||t(e?`REMOTE_STATIC_PUBLIC_KEY ${j(e.subarray(),"hex")}`:"Missing remote static public key.")}function ko(e,t){!t.enabled||!er||t(e?`REMOTE_EPHEMERAL_PUBLIC_KEY ${j(e.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function Mo(e,t,r){!r.enabled||!er||(r(`CIPHER_STATE_1 ${e.n.getUint64()} ${e.k&&j(e.k,"hex")}`),r(`CIPHER_STATE_2 ${t.n.getUint64()} ${t.k&&j(t.k,"hex")}`))}var sr=class e extends Error{code;constructor(t="Invalid crypto exchange"){super(t),this.code=e.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var Mh=0,Oh=4294967295,Hh="Cipher state has reached maximum n, a new handshake must be performed",Rn=class{n;bytes;view;constructor(t=Mh){this.n=t,this.bytes=nt(12),this.view=new DataView(this.bytes.buffer,this.bytes.byteOffset,this.bytes.byteLength),this.view.setUint32(4,t,!0)}increment(){this.n++,this.view.setUint32(4,this.n,!0)}getBytes(){return this.bytes}getUint64(){return this.n}assertValue(){if(this.n>Oh)throw new Error(Hh)}};var _e=nt(0),or=class{k;n;crypto;constructor(t,r=void 0,n=0){this.crypto=t,this.k=r,this.n=new Rn(n)}hasKey(){return!!this.k}encryptWithAd(t,r){if(!this.hasKey())return r;this.n.assertValue();let n=this.crypto.encrypt(r,this.n.getBytes(),t,this.k);return this.n.increment(),n}decryptWithAd(t,r,n){if(!this.hasKey())return r;this.n.assertValue();let s=this.crypto.decrypt(r,this.n.getBytes(),t,this.k,n);return this.n.increment(),s}},Oo=class{cs;ck;h;crypto;constructor(t,r){this.crypto=t;let n=Y(r,"utf-8");this.h=qh(t,n),this.ck=this.h,this.cs=new or(t)}mixKey(t){let[r,n]=this.crypto.hkdf(this.ck,t);this.ck=r,this.cs=new or(this.crypto,n)}mixHash(t){this.h=this.crypto.hash(new G(this.h,t))}encryptAndHash(t){let r=this.cs.encryptWithAd(this.h,t);return this.mixHash(r),r}decryptAndHash(t){let r=this.cs.decryptWithAd(this.h,t);return this.mixHash(t),r}split(){let[t,r]=this.crypto.hkdf(this.ck,_e);return[new or(this.crypto,t),new or(this.crypto,r)]}},Ho=class{ss;s;e;rs;re;initiator;crypto;constructor(t){let{crypto:r,protocolName:n,prologue:s,initiator:o,s:i,e:a,rs:c,re:u}=t;this.crypto=r,this.ss=new Oo(r,n),this.ss.mixHash(s),this.initiator=o,this.s=i,this.e=a,this.rs=c,this.re=u}writeE(){if(this.e)throw new Error("ephemeral keypair is already set");let t=this.crypto.generateKeypair();return this.ss.mixHash(t.publicKey),this.e=t,t.publicKey}writeS(){if(!this.s)throw new Error("static keypair is not set");return this.ss.encryptAndHash(this.s.publicKey)}writeEE(){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.re))}writeES(){if(this.initiator){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}else{if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}}writeSE(){if(this.initiator){if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}else{if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}}readE(t,r=0){if(this.re)throw new Error("remote ephemeral public key is already set");if(t.byteLength<r+32)throw new Error("message is not long enough");this.re=t.sublist(r,r+32),this.ss.mixHash(this.re)}readS(t,r=0){if(this.rs)throw new Error("remote static public key is already set");let n=32+(this.ss.cs.hasKey()?16:0);if(t.byteLength<r+n)throw new Error("message is not long enough");let s=t.sublist(r,r+n);return this.rs=this.ss.decryptAndHash(s),n}readEE(){this.writeEE()}readES(){this.writeES()}readSE(){this.writeSE()}},Dr=class extends Ho{writeMessageA(t){return new G(this.writeE(),this.ss.encryptAndHash(t))}writeMessageB(t){let r=this.writeE();this.writeEE();let n=this.writeS();return this.writeES(),new G(r,n,this.ss.encryptAndHash(t))}writeMessageC(t){let r=this.writeS();return this.writeSE(),new G(r,this.ss.encryptAndHash(t))}readMessageA(t){try{return this.readE(t),this.ss.decryptAndHash(t.sublist(32))}catch(r){throw new sr(`handshake stage 0 validation fail: ${r.message}`)}}readMessageB(t){try{this.readE(t),this.readEE();let r=this.readS(t,32);return this.readES(),this.ss.decryptAndHash(t.sublist(32+r))}catch(r){throw new sr(`handshake stage 1 validation fail: ${r.message}`)}}readMessageC(t){try{let r=this.readS(t);return this.readSE(),this.ss.decryptAndHash(t.sublist(r))}catch(r){throw new sr(`handshake stage 2 validation fail: ${r.message}`)}}};function qh(e,t){if(t.length<=32){let r=nt(32);return r.set(t),r}else return e.hash(t)}var Un;(function(e){let t;e.codec=()=>(t==null&&(t=Be((r,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),r.webtransportCerthashes!=null)for(let o of r.webtransportCerthashes)n.uint32(10),n.bytes(o);if(r.streamMuxers!=null)for(let o of r.streamMuxers)n.uint32(18),n.string(o);s.lengthDelimited!==!1&&n.ldelim()},(r,n,s={})=>{let o={webtransportCerthashes:[],streamMuxers:[]},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{if(s.limits?.webtransportCerthashes!=null&&o.webtransportCerthashes.length===s.limits.webtransportCerthashes)throw new Ir('Decode error - map field "webtransportCerthashes" had too many elements');o.webtransportCerthashes.push(r.bytes());break}case 2:{if(s.limits?.streamMuxers!=null&&o.streamMuxers.length===s.limits.streamMuxers)throw new Ir('Decode error - map field "streamMuxers" had too many elements');o.streamMuxers.push(r.string());break}default:{r.skipType(a&7);break}}}return o})),t),e.encode=r=>Ae(r,e.codec()),e.decode=(r,n)=>Se(r,e.codec(),n)})(Un||(Un={}));var Pr;(function(e){let t;e.codec=()=>(t==null&&(t=Be((r,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),r.identityKey!=null&&r.identityKey.byteLength>0&&(n.uint32(10),n.bytes(r.identityKey)),r.identitySig!=null&&r.identitySig.byteLength>0&&(n.uint32(18),n.bytes(r.identitySig)),r.extensions!=null&&(n.uint32(34),Un.codec().encode(r.extensions,n)),s.lengthDelimited!==!1&&n.ldelim()},(r,n,s={})=>{let o={identityKey:nt(0),identitySig:nt(0)},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{o.identityKey=r.bytes();break}case 2:{o.identitySig=r.bytes();break}case 4:{o.extensions=Un.codec().decode(r,r.uint32(),{limits:s.limits?.extensions});break}default:{r.skipType(a&7);break}}}return o})),t),e.encode=r=>Ae(r,e.codec()),e.decode=(r,n)=>Se(r,e.codec(),n)})(Pr||(Pr={}));async function Vo(e,t,r){let n=await e.sign(yc(t));return Pr.encode({identityKey:te(e.publicKey),identitySig:n,extensions:r})}async function Fo(e,t,r){try{let n=Pr.decode(e),s=Kr(n.identityKey);if(r?.equals(s)===!1)throw new Error(`Payload identity key ${s} does not match expected remote identity key ${r}`);if(!t)throw new Error("Remote static does not exist");let o=yc(t);if(!await s.verify(o,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new kr(n.message)}}function yc(e){let t=Y("noise-libp2p-static-key:");return e instanceof Uint8Array?le([t,e],t.length+e.length):(e.prepend(t),e)}var qo=class extends vn{stream;handshake;metrics;decoder;constructor(t,r,n){super({log:t.log,inactivityTimeout:t.inactivityTimeout,maxReadBufferLength:t.maxReadBufferLength,direction:t.direction}),this.stream=t,this.handshake=r,this.metrics=n,this.decoder=new Bn({lengthDecoder:nr,maxBufferSize:16*1024*1024,encodingLength:()=>2});let s=c=>{try{for(let u of this.decoder.decode(c.data))this.onData(this.decrypt(u))}catch(u){this.abort(u)}};this.stream.addEventListener("message",s);let o=c=>{c.error!=null?c.local===!0?this.abort(c.error):this.onRemoteReset():this.onTransportClosed()};this.stream.addEventListener("close",o);let i=()=>{this.safeDispatchEvent("drain")};this.stream.addEventListener("drain",i);let a=()=>{this.onRemoteCloseWrite()};this.stream.addEventListener("remoteCloseWrite",a)}encrypt(t){let r=new G;for(let n=0;n<t.byteLength;n+=65519){let s=n+65519;s>t.byteLength&&(s=t.byteLength);let o;t instanceof Uint8Array?o=this.handshake.encrypt(t.subarray(n,s)):o=this.handshake.encrypt(t.sublist(n,s)),this.metrics?.encryptedPackets.increment(),r.append(rr(o.byteLength)),r.append(o)}return r}decrypt(t){let r=new G;for(let n=0;n<t.byteLength;n+=65535){let s=n+65535;if(s>t.byteLength&&(s=t.byteLength),s-Lo<n)throw new Error("Invalid chunk");let o;t instanceof Uint8Array?o=t.subarray(n,s):o=t.sublist(n,s);let i=t.subarray(n,s-Lo);try{let a=this.handshake.decrypt(o,i);this.metrics?.decryptedPackets.increment(),r.append(a)}catch(a){throw this.metrics?.decryptErrors.increment(),a}}return r}close(t){return this.stream.close(t)}sendPause(){this.stream.pause()}sendResume(){this.stream.resume()}sendReset(t){this.stream.abort(t)}sendData(t){return{sentBytes:t.byteLength,canSendMore:this.stream.send(this.encrypt(t))}}};function zo(e,t,r){return new qo(e,t,r)}async function gc(e,t){let{log:r,connection:n,crypto:s,privateKey:o,prologue:i,s:a,remoteIdentityKey:c,extensions:u}=e,f=await Vo(o,a.publicKey,u),h=new Dr({crypto:s,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:i,s:a});Po(h.s,r),r.trace("Stage 0 - Initiator starting to send first message."),await n.write(h.writeMessageA(_e),t),r.trace("Stage 0 - Initiator finished sending first message."),No(h.e,r),r.trace("Stage 1 - Initiator waiting to receive first message from responder...");let l=h.readMessageB(await n.read(t));r.trace("Stage 1 - Initiator received the message."),ko(h.re,r),pc(h.rs,r),r.trace("Initiator going to check remote's signature...");let d=await Fo(l,h.rs,c);r.trace("All good with the signature!"),r.trace("Stage 2 - Initiator sending third handshake message."),await n.write(h.writeMessageC(f),t),r.trace("Stage 2 - Initiator sent message with signed payload.");let[p,w]=h.ss.split();return Mo(p,w,r),{payload:d,encrypt:g=>p.encryptWithAd(_e,g),decrypt:(g,x)=>w.decryptWithAd(_e,g,x)}}async function bc(e,t){let{log:r,connection:n,crypto:s,privateKey:o,prologue:i,s:a,remoteIdentityKey:c,extensions:u}=e,f=await Vo(o,a.publicKey,u),h=new Dr({crypto:s,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:i,s:a});Po(h.s,r),r.trace("Stage 0 - Responder waiting to receive first message."),h.readMessageA(await n.read(t)),r.trace("Stage 0 - Responder received first message."),ko(h.re,r),r.trace("Stage 1 - Responder sending out first message with signed payload and static key."),await n.write(h.writeMessageB(f),t),r.trace("Stage 1 - Responder sent the second handshake message with signed payload."),No(h.e,r),r.trace("Stage 2 - Responder waiting for third handshake message...");let l=h.readMessageC(await n.read(t));r.trace("Stage 2 - Responder received the message, finished handshake.");let d=await Fo(l,h.rs,c),[p,w]=h.ss.split();return Mo(p,w,r),{payload:d,encrypt:g=>w.encryptWithAd(_e,g),decrypt:(g,x)=>p.decryptWithAd(_e,g,x)}}var Dn=class{protocol="/noise";crypto;prologue;staticKey;extensions;metrics;components;log;constructor(t,r={}){let{staticNoiseKey:n,extensions:s,crypto:o,prologueBytes:i}=r,{metrics:a}=t;this.components=t,this.log=t.logger.forComponent("libp2p:noise");let c=o??hc;this.crypto=lc(c),this.extensions={webtransportCerthashes:[],...s},this.metrics=a?dc(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=i??nt(0)}[Symbol.toStringTag]="@libp2p/noise";[$o]=["@libp2p/connection-encryption","@libp2p/noise"];async secureOutbound(t,r){let n=t.log?.newScope("noise")??this.log,s=Bo(t,{lengthEncoder:rr,lengthDecoder:nr,maxDataLength:65535}),o=await this.performHandshakeInitiator(s,this.components.privateKey,n,r?.remotePeer?.publicKey,r),i=Kr(o.payload.identityKey);return{connection:zo(s.unwrap(),o,this.metrics),remoteExtensions:o.payload.extensions,remotePeer:go(i),streamMuxer:r?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(o.payload.extensions?.streamMuxers)}}getStreamMuxer(t){if(t==null||t.length===0)return;let r=this.components.upgrader.getStreamMuxers();if(r!=null)for(let n of t){let s=r.get(n);if(s!=null)return s}if(t.length)throw new Mr("Early muxer negotiation was requested but the initiator and responder had no common muxers")}async secureInbound(t,r){let n=t.log?.newScope("noise")??this.log,s=Bo(t,{lengthEncoder:rr,lengthDecoder:nr,maxDataLength:65535}),o=await this.performHandshakeResponder(s,this.components.privateKey,n,r?.remotePeer?.publicKey,r),i=Kr(o.payload.identityKey);return{connection:zo(s.unwrap(),o,this.metrics),remoteExtensions:o.payload.extensions,remotePeer:go(i),streamMuxer:r?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(o.payload.extensions?.streamMuxers)}}async performHandshakeInitiator(t,r,n,s,o){let i,a=o?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{i=await gc({connection:t,privateKey:r,remoteIdentityKey:s,log:n.newScope("xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:{streamMuxers:a,webtransportCerthashes:[],...this.extensions}},o),this.metrics?.xxHandshakeSuccesses.increment()}catch(c){throw this.metrics?.xxHandshakeErrors.increment(),c}return i}async performHandshakeResponder(t,r,n,s,o){let i,a=o?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{i=await bc({connection:t,privateKey:r,remoteIdentityKey:s,log:n.newScope("xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:{streamMuxers:a,webtransportCerthashes:[],...this.extensions}},o),this.metrics?.xxHandshakeSuccesses.increment()}catch(c){throw this.metrics?.xxHandshakeErrors.increment(),c}return i}};function Vh(e={}){return t=>new Dn(t,e)}return vc(Fh);})();
|
|
2
|
+
"use strict";var Libp2PNoise=(()=>{var Pn=Object.defineProperty;var xc=Object.getOwnPropertyDescriptor;var wc=Object.getOwnPropertyNames;var Ec=Object.prototype.hasOwnProperty;var xt=(e,t)=>{for(var r in t)Pn(e,r,{get:t[r],enumerable:!0})},Sc=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of wc(t))!Ec.call(e,s)&&s!==r&&Pn(e,s,{get:()=>t[s],enumerable:!(n=xc(t,s))||n.enumerable});return e};var vc=e=>Sc(Pn({},"__esModule",{value:!0}),e);var Fh={};xt(Fh,{noise:()=>Vh,pureJsCrypto:()=>Kn});var kr=class extends Error{static name="UnexpectedPeerError";constructor(t="Unexpected Peer"){super(t),this.name="UnexpectedPeerError"}},Mr=class extends Error{static name="InvalidCryptoExchangeError";constructor(t="Invalid crypto exchange"){super(t),this.name="InvalidCryptoExchangeError"}},tt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Te=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Or=class extends Error{static name="StreamResetError";constructor(t="The stream has been reset"){super(t),this.name="StreamResetError"}};var he=class extends Error{static name="StreamStateError";constructor(t="The stream is in an invalid state"){super(t),this.name="StreamStateError"}},cr=class extends Error{static name="StreamBufferError";constructor(t="The stream buffer was full"){super(t),this.name="StreamBufferError"}};var Ce=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Hr=class extends Event{data;constructor(t,r){super("message",r),this.data=t}},Ke=class extends Event{error;local;constructor(t,r,n){super("close",n),this.error=r,this.local=t}},qr=class extends Ke{constructor(t,r){super(!0,t,r)}},Vr=class extends Ke{constructor(t,r){super(!1,t,r)}};var Nn=Symbol.for("@libp2p/peer-id");var Fr=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let r=this.#t.get(t);return r==null?0:r.length}addEventListener(t,r,n){super.addEventListener(t,r,n);let s=this.#t.get(t);s==null&&(s=[],this.#t.set(t,s)),s.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,r,n){super.removeEventListener(t.toString(),r??null,n);let s=this.#t.get(t);s!=null&&(s=s.filter(({callback:o})=>o!==r),this.#t.set(t,s))}dispatchEvent(t){let r=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:s})=>!s),this.#t.set(t.type,n)),r}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var $o=Symbol.for("@libp2p/service-capabilities"),Wh=Symbol.for("@libp2p/service-dependencies");var qn={};xt(qn,{base58btc:()=>rt,base58flickr:()=>Cc});var El=new Uint8Array(0);function Zo(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Pt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function Wo(e){return new TextEncoder().encode(e)}function Yo(e){return new TextDecoder().decode(e)}function Ac(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var s=0;s<e.length;s++){var o=e.charAt(s),i=o.charCodeAt(0);if(r[i]!==255)throw new TypeError(o+" is ambiguous");r[i]=s}var a=e.length,c=e.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function h(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var w=0,g=0,x=0,B=p.length;x!==B&&p[x]===0;)x++,w++;for(var E=(B-x)*f+1>>>0,R=new Uint8Array(E);x!==B;){for(var k=p[x],O=0,M=E-1;(k!==0||O<g)&&M!==-1;M--,O++)k+=256*R[M]>>>0,R[M]=k%a>>>0,k=k/a>>>0;if(k!==0)throw new Error("Non-zero carry");g=O,x++}for(var P=E-g;P!==E&&R[P]===0;)P++;for(var S=c.repeat(w);P<E;++P)S+=e.charAt(R[P]);return S}function l(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var w=0;if(p[w]!==" "){for(var g=0,x=0;p[w]===c;)g++,w++;for(var B=(p.length-w)*u+1>>>0,E=new Uint8Array(B);p[w];){var R=r[p.charCodeAt(w)];if(R===255)return;for(var k=0,O=B-1;(R!==0||k<x)&&O!==-1;O--,k++)R+=a*E[O]>>>0,E[O]=R%256>>>0,R=R/256>>>0;if(R!==0)throw new Error("Non-zero carry");x=k,w++}if(p[w]!==" "){for(var M=B-x;M!==B&&E[M]===0;)M++;for(var P=new Uint8Array(g+(B-M)),S=g;M!==B;)P[S++]=E[M++];return P}}}function d(p){var w=l(p);if(w)return w;throw new Error(`Non-${t} character`)}return{encode:h,decodeUnsafe:l,decode:d}}var Bc=Ac,Lc=Bc,Jo=Lc;var kn=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Mn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let s=r.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Qo(this,t)}},On=class{decoders;constructor(t){this.decoders=t}or(t){return Qo(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Qo(e,t){return new On({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Hn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,s){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=s,this.encoder=new kn(t,r,n),this.decoder=new Mn(t,r,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Re({name:e,prefix:t,encode:r,decode:n}){return new Hn(e,t,r,n)}function Jt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:s}=Jo(r,e);return Re({prefix:t,name:e,encode:n,decode:o=>Pt(s(o))})}function _c(e,t,r,n){let s=e.length;for(;e[s-1]==="=";)--s;let o=new Uint8Array(s*r/8|0),i=0,a=0,c=0;for(let u=0;u<s;++u){let f=t[e[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,o[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return o}function Ic(e,t,r){let n=t[t.length-1]==="=",s=(1<<r)-1,o="",i=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],i+=8;i>r;)i-=r,o+=t[s&a>>i];if(i!==0&&(o+=t[s&a<<r-i]),n)for(;(o.length*r&7)!==0;)o+="=";return o}function Tc(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function et({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let s=Tc(n);return Re({prefix:t,name:e,encode(o){return Ic(o,n,r)},decode(o){return _c(o,s,r,e)}})}var rt=Jt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Cc=Jt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Vn={};xt(Vn,{base32:()=>Ue,base32hex:()=>Dc,base32hexpad:()=>Nc,base32hexpadupper:()=>kc,base32hexupper:()=>Pc,base32pad:()=>Rc,base32padupper:()=>Uc,base32upper:()=>Kc,base32z:()=>Mc});var Ue=et({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Kc=et({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Rc=et({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Uc=et({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Dc=et({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Pc=et({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Nc=et({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),kc=et({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Mc=et({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Fn={};xt(Fn,{base36:()=>fr,base36upper:()=>Oc});var fr=Jt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Oc=Jt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Hc=ri,ti=128,qc=127,Vc=~qc,Fc=Math.pow(2,31);function ri(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Fc;)t[r++]=e&255|ti,e/=128;for(;e&Vc;)t[r++]=e&255|ti,e>>>=7;return t[r]=e|0,ri.bytes=r-n+1,t}var zc=zn,Gc=128,ei=127;function zn(e,n){var r=0,n=n||0,s=0,o=n,i,a=e.length;do{if(o>=a)throw zn.bytes=0,new RangeError("Could not decode varint");i=e[o++],r+=s<28?(i&ei)<<s:(i&ei)*Math.pow(2,s),s+=7}while(i>=Gc);return zn.bytes=o-n,r}var jc=Math.pow(2,7),$c=Math.pow(2,14),Zc=Math.pow(2,21),Wc=Math.pow(2,28),Yc=Math.pow(2,35),Xc=Math.pow(2,42),Jc=Math.pow(2,49),Qc=Math.pow(2,56),tf=Math.pow(2,63),ef=function(e){return e<jc?1:e<$c?2:e<Zc?3:e<Wc?4:e<Yc?5:e<Xc?6:e<Jc?7:e<Qc?8:e<tf?9:10},rf={encode:Hc,decode:zc,encodingLength:ef},nf=rf,ur=nf;function hr(e,t=0){return[ur.decode(e,t),ur.decode.bytes]}function De(e,t,r=0){return ur.encode(e,t,r),t}function Pe(e){return ur.encodingLength(e)}function Kt(e,t){let r=t.byteLength,n=Pe(e),s=n+Pe(r),o=new Uint8Array(s+r);return De(e,o,0),De(r,o,n),o.set(t,s),new Ne(e,r,t,o)}function Gn(e){let t=Pt(e),[r,n]=hr(t),[s,o]=hr(t.subarray(n)),i=t.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new Ne(r,s,i,t)}function ni(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Zo(e.bytes,r.bytes)}}var Ne=class{code;size;digest;bytes;constructor(t,r,n,s){this.code=t,this.size=r,this.digest=n,this.bytes=s}};function si(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return of(r,jn(e),t??rt.encoder);default:return af(r,jn(e),t??Ue.encoder)}}var oi=new WeakMap;function jn(e){let t=oi.get(e);if(t==null){let r=new Map;return oi.set(e,r),r}return t}var ht=class e{code;version;multihash;bytes;"/";constructor(t,r,n,s){this.code=r,this.version=t,this.multihash=n,this.bytes=s,this["/"]=s}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==lr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==cf)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=Kt(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&ni(t.multihash,n.multihash)}toString(t){return si(this,t)}toJSON(){return{"/":si(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:s,multihash:o,bytes:i}=r;return new e(n,s,o,i??ii(n,s,o.bytes))}else if(r[ff]===!0){let{version:n,multihash:s,code:o}=r,i=Gn(s);return e.create(n,o,i)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==lr)throw new Error(`Version 0 CID must use dag-pb (code: ${lr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let s=ii(t,r,n.bytes);return new e(t,r,n,s)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,lr,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,s=Pt(t.subarray(n,n+r.multihashSize));if(s.byteLength!==r.multihashSize)throw new Error("Incorrect length");let o=s.subarray(r.multihashSize-r.digestSize),i=new Ne(r.multihashCode,r.digestSize,o,s);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[h,l]=hr(t.subarray(r));return r+=l,h},s=n(),o=lr;if(s===18?(s=0,r=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(t,r){let[n,s]=sf(t,r),o=e.decode(s);if(o.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return jn(o).set(n,t),o}};function sf(e,t){switch(e[0]){case"Q":{let r=t??rt;return[rt.prefix,r.decode(`${rt.prefix}${e}`)]}case rt.prefix:{let r=t??rt;return[rt.prefix,r.decode(e)]}case Ue.prefix:{let r=t??Ue;return[Ue.prefix,r.decode(e)]}case fr.prefix:{let r=t??fr;return[fr.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function of(e,t,r){let{prefix:n}=r;if(n!==rt.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let s=t.get(n);if(s==null){let o=r.encode(e).slice(1);return t.set(n,o),o}else return s}function af(e,t,r){let{prefix:n}=r,s=t.get(n);if(s==null){let o=r.encode(e);return t.set(n,o),o}else return s}var lr=112,cf=18;function ii(e,t,r){let n=Pe(e),s=n+Pe(t),o=new Uint8Array(s+r.byteLength);return De(e,o,0),De(t,o,n),o.set(r,s),o}var ff=Symbol.for("@ipld/js-cid/CID");var $n={};xt($n,{identity:()=>Rt});var ai=0,uf="identity",ci=Pt;function hf(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return Kt(ai,ci(e))}var Rt={code:ai,name:uf,encode:ci,digest:hf};function yt(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function nt(e=0){return new Uint8Array(e)}function ct(e=0){return new Uint8Array(e)}function le(e,t){t==null&&(t=e.reduce((s,o)=>s+o.length,0));let r=ct(t),n=0;for(let s of e)r.set(s,n),n+=s.length;return r}var ui=Symbol.for("@achingbrain/uint8arraylist");function fi(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let s=r+n.byteLength;if(t<s)return{buf:n,index:t-r};r=s}throw new RangeError("index is out of bounds")}function Gr(e){return!!e?.[ui]}var G=class e{bufs;length;[ui]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Gr(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Gr(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=fi(this.bufs,t);return r.buf[r.index]}set(t,r){let n=fi(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(Gr(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:s}=this._subList(t,r);return le(n,s)}subarray(t,r){let{bufs:n,length:s}=this._subList(t,r);return n.length===1?n[0]:le(n,s)}sublist(t,r){let{bufs:n,length:s}=this._subList(t,r),o=new e;return o.length=s,o.bufs=[...n],o}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],s=0;for(let o=0;o<this.bufs.length;o++){let i=this.bufs[o],a=s,c=a+i.byteLength;if(s=c,t>=c)continue;let u=t>=a&&t<c,f=r>a&&r<=c;if(u&&f){if(t===a&&r===c){n.push(i);break}let h=t-a;n.push(i.subarray(h,h+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Gr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let o=256,i=new Int32Array(o);for(let h=0;h<o;h++)i[h]=-1;for(let h=0;h<s;h++)i[n[h]]=h;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let h=r;h<=c;h+=f){f=0;for(let l=u;l>=0;l--){let d=this.get(h+l);if(n[l]!==d){f=Math.max(1,l-a[d]);break}}if(f===0)return h}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=ct(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let s=nt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,r,n),this.write(s,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let s=nt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,r,n),this.write(s,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let s=nt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,r,n),this.write(s,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=ct(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let s=nt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,r,n),this.write(s,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let s=nt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,r,n),this.write(s,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let s=nt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,r,n),this.write(s,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let s=nt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,r,n),this.write(s,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let s=nt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,r,n),this.write(s,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!yt(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((s,o)=>s+o.byteLength,0)),n.length=r,n}};var Zn={};xt(Zn,{base10:()=>df});var df=Jt({prefix:"9",name:"base10",alphabet:"0123456789"});var Wn={};xt(Wn,{base16:()=>pf,base16upper:()=>mf});var pf=et({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),mf=et({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Yn={};xt(Yn,{base2:()=>yf});var yf=et({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Xn={};xt(Xn,{base256emoji:()=>Ef});var hi=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),gf=hi.reduce((e,t,r)=>(e[r]=t,e),[]),bf=hi.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function xf(e){return e.reduce((t,r)=>(t+=gf[r],t),"")}function wf(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let s=bf[n];if(s==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(s)}return new Uint8Array(t)}var Ef=Re({prefix:"\u{1F680}",name:"base256emoji",encode:xf,decode:wf});var Jn={};xt(Jn,{base64:()=>Sf,base64pad:()=>vf,base64url:()=>Af,base64urlpad:()=>Bf});var Sf=et({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),vf=et({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Af=et({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Bf=et({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Qn={};xt(Qn,{base8:()=>Lf});var Lf=et({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ts={};xt(ts,{identity:()=>_f});var _f=Re({prefix:"\0",name:"identity",encode:e=>Yo(e),decode:e=>Wo(e)});var nd=new TextEncoder,sd=new TextDecoder;var ns={};xt(ns,{sha256:()=>jr,sha512:()=>Kf});var Cf=20;function rs({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:s}){return new es(e,t,r,n,s)}var es=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,s,o){this.name=t,this.code=r,this.encode=n,this.minDigestLength=s??Cf,this.maxDigestLength=o}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?li(n,this.code,r?.truncate):n.then(s=>li(s,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function li(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Kt(t,e)}function pi(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var jr=rs({name:"sha2-256",code:18,encode:pi("SHA-256")}),Kf=rs({name:"sha2-512",code:19,encode:pi("SHA-512")});var ss={...ts,...Yn,...Qn,...Zn,...Wn,...Vn,...Fn,...qn,...Jn,...Xn},yd={...ns,...$n};function yi(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var mi=yi("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),os=yi("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=ct(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Rf={utf8:mi,"utf-8":mi,hex:ss.base16,latin1:os,ascii:os,binary:os,...ss},$r=Rf;function Y(e,t="utf8"){let r=$r[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function j(e,t="utf8"){let r=$r[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Uf=parseInt("11111",2),is=parseInt("10000000",2),Df=parseInt("01111111",2),gi={0:dr,1:dr,2:Pf,3:Mf,4:Of,5:kf,6:Nf,16:dr,22:dr,48:dr};function Nt(e,t={offset:0}){let r=e[t.offset]&Uf;if(t.offset++,gi[r]!=null)return gi[r](e,t);throw new Error("No decoder for tag "+r)}function pr(e,t){let r=0;if((e[t.offset]&is)===is){let n=e[t.offset]&Df,s="0x";t.offset++;for(let o=0;o<n;o++,t.offset++)s+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(s,16)}else r=e[t.offset],t.offset++;return r}function dr(e,t){pr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Nt(e,t);if(n===null)break;r.push(n)}return r}function Pf(e,t){let r=pr(e,t),n=t.offset,s=t.offset+r,o=[];for(let i=n;i<s;i++)i===n&&e[i]===0||o.push(e[i]);return t.offset+=r,Uint8Array.from(o)}function Nf(e,t){let r=pr(e,t),n=t.offset+r,s=e[t.offset];t.offset++;let o=0,i=0;s<40?(o=0,i=s):s<80?(o=1,i=s-40):(o=2,i=s-80);let a=`${o}.${i}`,c=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let h=0;h<c.length;h++)f+=c[h]<<h*7;a+=`.${f}`,c=[]}}return a}function kf(e,t){return t.offset++,null}function Mf(e,t){let r=pr(e,t),n=e[t.offset];t.offset++;let s=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return s}function Of(e,t){let r=pr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Hf(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new G;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function as(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Hf(e.byteLength);return new G(Uint8Array.from([t.byteLength|is]),t)}function wt(e){let t=new G,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new G(Uint8Array.from([2]),as(t),t)}function Zr(e){let t=Uint8Array.from([0]),r=new G(t,e);return new G(Uint8Array.from([3]),as(r),r)}function Qt(e,t=48){let r=new G;for(let n of e)r.append(n);return new G(Uint8Array.from([t]),as(r),r)}async function bi(e,t,r,n){let s=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let o=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},s,t,r.subarray());return n?.signal?.throwIfAborted(),o}var qf=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Vf=Uint8Array.from([6,5,43,129,4,0,34]),Ff=Uint8Array.from([6,5,43,129,4,0,35]),zf={ext:!0,kty:"EC",crv:"P-256"},Gf={ext:!0,kty:"EC",crv:"P-384"},jf={ext:!0,kty:"EC",crv:"P-521"},cs=32,fs=48,us=66;function xi(e){let t=Nt(e);return wi(t)}function wi(e){let t=e[1][1][0],r=1,n,s;if(t.byteLength===cs*2+1)return n=j(t.subarray(r,r+cs),"base64url"),s=j(t.subarray(r+cs),"base64url"),new Me({...zf,key_ops:["verify"],x:n,y:s});if(t.byteLength===fs*2+1)return n=j(t.subarray(r,r+fs),"base64url"),s=j(t.subarray(r+fs),"base64url"),new Me({...Gf,key_ops:["verify"],x:n,y:s});if(t.byteLength===us*2+1)return n=j(t.subarray(r,r+us),"base64url"),s=j(t.subarray(r+us),"base64url"),new Me({...jf,key_ops:["verify"],x:n,y:s});throw new tt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Ei(e){return Qt([wt(Uint8Array.from([1])),Qt([$f(e.crv)],160),Qt([Zr(new G(Uint8Array.from([4]),Y(e.x??"","base64url"),Y(e.y??"","base64url")))],161)]).subarray()}function $f(e){if(e==="P-256")return qf;if(e==="P-384")return Vf;if(e==="P-521")return Ff;throw new tt(`Invalid curve ${e}`)}var Me=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Ei(this.jwk)),this._raw}toMultihash(){return Rt.digest(te(this))}toCID(){return ht.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:yt(this.raw,t.raw)}async verify(t,r,n){return bi(this.jwk,r,t,n)}};var de=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Mt(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function pe(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function lt(e,...t){if(!Mt(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function me(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");pe(e.outputLen),pe(e.blockLen)}function He(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function vi(e,t){lt(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function _t(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Wr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function It(e,t){return e<<32-t|e>>>t}var Ai=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Zf=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function At(e){if(lt(e),Ai)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Zf[e[r]];return t}var kt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Si(e){if(e>=kt._0&&e<=kt._9)return e-kt._0;if(e>=kt.A&&e<=kt.F)return e-(kt.A-10);if(e>=kt.a&&e<=kt.f)return e-(kt.a-10)}function ye(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Ai)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let s=0,o=0;s<r;s++,o+=2){let i=Si(e.charCodeAt(o)),a=Si(e.charCodeAt(o+1));if(i===void 0||a===void 0){let c=e[o]+e[o+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+o)}n[s]=i*16+a}return n}function hs(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function ee(e){return typeof e=="string"&&(e=hs(e)),lt(e),e}function gt(...e){let t=0;for(let n=0;n<e.length;n++){let s=e[n];lt(s),t+=s.length}let r=new Uint8Array(t);for(let n=0,s=0;n<e.length;n++){let o=e[n];r.set(o,s),s+=o.length}return r}var Oe=class{};function ls(e){let t=n=>e().update(ee(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function re(e=32){if(de&&typeof de.getRandomValues=="function")return de.getRandomValues(new Uint8Array(e));if(de&&typeof de.randomBytes=="function")return Uint8Array.from(de.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function Wf(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let s=BigInt(32),o=BigInt(4294967295),i=Number(r>>s&o),a=Number(r&o),c=n?4:0,u=n?0:4;e.setUint32(t+c,i,n),e.setUint32(t+u,a,n)}function Bi(e,t,r){return e&t^~e&r}function Li(e,t,r){return e&t^e&r^t&r}var mr=class extends Oe{constructor(t,r,n,s){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(t),this.view=Wr(this.buffer)}update(t){He(this),t=ee(t),lt(t);let{view:r,buffer:n,blockLen:s}=this,o=t.length;for(let i=0;i<o;){let a=Math.min(s-this.pos,o-i);if(a===s){let c=Wr(t);for(;s<=o-i;i+=s)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===s&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){He(this),vi(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:s,isLE:o}=this,{pos:i}=this;r[i++]=128,_t(this.buffer.subarray(i)),this.padOffset>s-i&&(this.process(n,0),i=0);for(let h=i;h<s;h++)r[h]=0;Wf(n,s-8,BigInt(this.length*8),o),this.process(n,0);let a=Wr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<u;h++)a.setUint32(4*h,f[h],o)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:s,finished:o,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=o,t.length=s,t.pos=a,s%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Ot=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ft=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Yr=BigInt(4294967295),_i=BigInt(32);function Yf(e,t=!1){return t?{h:Number(e&Yr),l:Number(e>>_i&Yr)}:{h:Number(e>>_i&Yr)|0,l:Number(e&Yr)|0}}function Ii(e,t=!1){let r=e.length,n=new Uint32Array(r),s=new Uint32Array(r);for(let o=0;o<r;o++){let{h:i,l:a}=Yf(e[o],t);[n[o],s[o]]=[i,a]}return[n,s]}var ds=(e,t,r)=>e>>>r,ps=(e,t,r)=>e<<32-r|t>>>r,ge=(e,t,r)=>e>>>r|t<<32-r,be=(e,t,r)=>e<<32-r|t>>>r,yr=(e,t,r)=>e<<64-r|t>>>r-32,gr=(e,t,r)=>e>>>r-32|t<<64-r;function Ut(e,t,r,n){let s=(t>>>0)+(n>>>0);return{h:e+r+(s/2**32|0)|0,l:s|0}}var Ti=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Ci=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Ki=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Ri=(e,t,r,n,s)=>t+r+n+s+(e/2**32|0)|0,Ui=(e,t,r,n,s)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(s>>>0),Di=(e,t,r,n,s,o)=>t+r+n+s+o+(e/2**32|0)|0;var Jf=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),ne=new Uint32Array(64),Xr=class extends mr{constructor(t=32){super(64,t,8,!1),this.A=Ot[0]|0,this.B=Ot[1]|0,this.C=Ot[2]|0,this.D=Ot[3]|0,this.E=Ot[4]|0,this.F=Ot[5]|0,this.G=Ot[6]|0,this.H=Ot[7]|0}get(){let{A:t,B:r,C:n,D:s,E:o,F:i,G:a,H:c}=this;return[t,r,n,s,o,i,a,c]}set(t,r,n,s,o,i,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,r){for(let h=0;h<16;h++,r+=4)ne[h]=t.getUint32(r,!1);for(let h=16;h<64;h++){let l=ne[h-15],d=ne[h-2],p=It(l,7)^It(l,18)^l>>>3,w=It(d,17)^It(d,19)^d>>>10;ne[h]=w+ne[h-7]+p+ne[h-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:u,H:f}=this;for(let h=0;h<64;h++){let l=It(a,6)^It(a,11)^It(a,25),d=f+l+Bi(a,c,u)+Jf[h]+ne[h]|0,w=(It(n,2)^It(n,13)^It(n,22))+Li(n,s,o)|0;f=u,u=c,c=a,a=i+d|0,i=o,o=s,s=n,n=d+w|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,s,o,i,a,c,u,f)}roundClean(){_t(ne)}destroy(){this.set(0,0,0,0,0,0,0,0),_t(this.buffer)}};var Pi=Ii(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),Qf=Pi[0],tu=Pi[1],se=new Uint32Array(80),oe=new Uint32Array(80),ms=class extends mr{constructor(t=64){super(128,t,16,!1),this.Ah=ft[0]|0,this.Al=ft[1]|0,this.Bh=ft[2]|0,this.Bl=ft[3]|0,this.Ch=ft[4]|0,this.Cl=ft[5]|0,this.Dh=ft[6]|0,this.Dl=ft[7]|0,this.Eh=ft[8]|0,this.El=ft[9]|0,this.Fh=ft[10]|0,this.Fl=ft[11]|0,this.Gh=ft[12]|0,this.Gl=ft[13]|0,this.Hh=ft[14]|0,this.Hl=ft[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:h,Fl:l,Gh:d,Gl:p,Hh:w,Hl:g}=this;return[t,r,n,s,o,i,a,c,u,f,h,l,d,p,w,g]}set(t,r,n,s,o,i,a,c,u,f,h,l,d,p,w,g){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=s|0,this.Ch=o|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=h|0,this.Fl=l|0,this.Gh=d|0,this.Gl=p|0,this.Hh=w|0,this.Hl=g|0}process(t,r){for(let E=0;E<16;E++,r+=4)se[E]=t.getUint32(r),oe[E]=t.getUint32(r+=4);for(let E=16;E<80;E++){let R=se[E-15]|0,k=oe[E-15]|0,O=ge(R,k,1)^ge(R,k,8)^ds(R,k,7),M=be(R,k,1)^be(R,k,8)^ps(R,k,7),P=se[E-2]|0,S=oe[E-2]|0,T=ge(P,S,19)^yr(P,S,61)^ds(P,S,6),U=be(P,S,19)^gr(P,S,61)^ps(P,S,6),C=Ki(M,U,oe[E-7],oe[E-16]),m=Ri(C,O,T,se[E-7],se[E-16]);se[E]=m|0,oe[E]=C|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:h,El:l,Fh:d,Fl:p,Gh:w,Gl:g,Hh:x,Hl:B}=this;for(let E=0;E<80;E++){let R=ge(h,l,14)^ge(h,l,18)^yr(h,l,41),k=be(h,l,14)^be(h,l,18)^gr(h,l,41),O=h&d^~h&w,M=l&p^~l&g,P=Ui(B,k,M,tu[E],oe[E]),S=Di(P,x,R,O,Qf[E],se[E]),T=P|0,U=ge(n,s,28)^yr(n,s,34)^yr(n,s,39),C=be(n,s,28)^gr(n,s,34)^gr(n,s,39),m=n&o^n&a^o&a,y=s&i^s&c^i&c;x=w|0,B=g|0,w=d|0,g=p|0,d=h|0,p=l|0,{h,l}=Ut(u|0,f|0,S|0,T|0),u=a|0,f=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let b=Ti(T,C,y);n=Ci(b,S,U,m),s=b|0}({h:n,l:s}=Ut(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=Ut(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=Ut(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Ut(this.Dh|0,this.Dl|0,u|0,f|0),{h,l}=Ut(this.Eh|0,this.El|0,h|0,l|0),{h:d,l:p}=Ut(this.Fh|0,this.Fl|0,d|0,p|0),{h:w,l:g}=Ut(this.Gh|0,this.Gl|0,w|0,g|0),{h:x,l:B}=Ut(this.Hh|0,this.Hl|0,x|0,B|0),this.set(n,s,o,i,a,c,u,f,h,l,d,p,w,g,x,B)}roundClean(){_t(se,oe)}destroy(){_t(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var ie=ls(()=>new Xr);var Ni=ls(()=>new ms);var bs=BigInt(0),gs=BigInt(1);function Ht(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}"`;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function Et(e,t,r=""){let n=Mt(e),s=e?.length,o=t!==void 0;if(!n||o&&s!==t){let i=r&&`"${r}" `,a=o?` of length ${t}`:"",c=n?`length=${s}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return e}function br(e){let t=e.toString(16);return t.length&1?"0"+t:t}function ki(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?bs:BigInt("0x"+e)}function qe(e){return ki(At(e))}function Bt(e){return lt(e),ki(At(Uint8Array.from(e).reverse()))}function Jr(e,t){return ye(e.toString(16).padStart(t*2,"0"))}function xr(e,t){return Jr(e,t).reverse()}function $(e,t,r){let n;if(typeof t=="string")try{n=ye(t)}catch(o){throw new Error(e+" must be hex string or Uint8Array, cause: "+o)}else if(Mt(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let s=n.length;if(typeof r=="number"&&s!==r)throw new Error(e+" of length "+r+" expected, got "+s);return n}function Mi(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function xs(e){return Uint8Array.from(e)}var ys=e=>typeof e=="bigint"&&bs<=e;function Oi(e,t,r){return ys(e)&&ys(t)&&ys(r)&&t<=e&&e<r}function ae(e,t,r,n){if(!Oi(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Qr(e){let t;for(t=0;e>bs;e>>=gs,t+=1);return t}var ce=e=>(gs<<BigInt(e))-gs;function Hi(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=d=>new Uint8Array(d),s=d=>Uint8Array.of(d),o=n(e),i=n(e),a=0,c=()=>{o.fill(1),i.fill(0),a=0},u=(...d)=>r(i,o,...d),f=(d=n(0))=>{i=u(s(0),d),o=u(),d.length!==0&&(i=u(s(1),d),o=u())},h=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let d=0,p=[];for(;d<t;){o=u();let w=o.slice();p.push(w),d+=o.length}return gt(...p)};return(d,p)=>{c(),f(d);let w;for(;!(w=p(h()));)f();return c(),w}}function Dt(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(s,o,i){let a=e[s];if(i&&a===void 0)return;let c=typeof a;if(c!==o||a===null)throw new Error(`param "${s}" is invalid: expected ${o}, got ${c}`)}Object.entries(t).forEach(([s,o])=>n(s,o,!1)),Object.entries(r).forEach(([s,o])=>n(s,o,!0))}var ws=()=>{throw new Error("not implemented")};function Ve(e){let t=new WeakMap;return(r,...n)=>{let s=t.get(r);if(s!==void 0)return s;let o=e(r,...n);return t.set(r,o),o}}var bt=BigInt(0),ot=BigInt(1),xe=BigInt(2),Fi=BigInt(3),zi=BigInt(4),Gi=BigInt(5),eu=BigInt(7),ji=BigInt(8),ru=BigInt(9),$i=BigInt(16);function X(e,t){let r=e%t;return r>=bt?r:t+r}function J(e,t,r){let n=e;for(;t-- >bt;)n*=n,n%=r;return n}function qi(e,t){if(e===bt)throw new Error("invert: expected non-zero number");if(t<=bt)throw new Error("invert: expected positive modulus, got "+t);let r=X(e,t),n=t,s=bt,o=ot,i=ot,a=bt;for(;r!==bt;){let u=n/r,f=n%r,h=s-i*u,l=o-a*u;n=r,r=f,s=i,o=a,i=h,a=l}if(n!==ot)throw new Error("invert: does not exist");return X(s,t)}function Es(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function Zi(e,t){let r=(e.ORDER+ot)/zi,n=e.pow(t,r);return Es(e,n,t),n}function nu(e,t){let r=(e.ORDER-Gi)/ji,n=e.mul(t,xe),s=e.pow(n,r),o=e.mul(t,s),i=e.mul(e.mul(o,xe),s),a=e.mul(o,e.sub(i,e.ONE));return Es(e,a,t),a}function su(e){let t=St(e),r=Wi(e),n=r(t,t.neg(t.ONE)),s=r(t,n),o=r(t,t.neg(n)),i=(e+eu)/$i;return(a,c)=>{let u=a.pow(c,i),f=a.mul(u,n),h=a.mul(u,s),l=a.mul(u,o),d=a.eql(a.sqr(f),c),p=a.eql(a.sqr(h),c);u=a.cmov(u,f,d),f=a.cmov(l,h,p);let w=a.eql(a.sqr(f),c),g=a.cmov(u,f,w);return Es(a,g,c),g}}function Wi(e){if(e<Fi)throw new Error("sqrt is not defined for small field");let t=e-ot,r=0;for(;t%xe===bt;)t/=xe,r++;let n=xe,s=St(e);for(;Vi(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Zi;let o=s.pow(n,t),i=(t+ot)/xe;return function(c,u){if(c.is0(u))return u;if(Vi(c,u)!==1)throw new Error("Cannot find square root");let f=r,h=c.mul(c.ONE,o),l=c.pow(u,t),d=c.pow(u,i);for(;!c.eql(l,c.ONE);){if(c.is0(l))return c.ZERO;let p=1,w=c.sqr(l);for(;!c.eql(w,c.ONE);)if(p++,w=c.sqr(w),p===f)throw new Error("Cannot find square root");let g=ot<<BigInt(f-p-1),x=c.pow(h,g);f=p,h=c.sqr(x),l=c.mul(l,h),d=c.mul(d,x)}return d}}function ou(e){return e%zi===Fi?Zi:e%ji===Gi?nu:e%$i===ru?su(e):Wi(e)}var qt=(e,t)=>(X(e,t)&ot)===ot,iu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ss(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=iu.reduce((n,s)=>(n[s]="function",n),t);return Dt(e,r),e}function au(e,t,r){if(r<bt)throw new Error("invalid exponent, negatives unsupported");if(r===bt)return e.ONE;if(r===ot)return t;let n=e.ONE,s=t;for(;r>bt;)r&ot&&(n=e.mul(n,s)),s=e.sqr(s),r>>=ot;return n}function wr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),s=t.reduce((i,a,c)=>e.is0(a)?i:(n[c]=i,e.mul(i,a)),e.ONE),o=e.inv(s);return t.reduceRight((i,a,c)=>e.is0(a)?i:(n[c]=e.mul(i,n[c]),e.mul(i,a)),o),n}function Vi(e,t){let r=(e.ORDER-ot)/xe,n=e.pow(t,r),s=e.eql(n,e.ONE),o=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!s&&!o&&!i)throw new Error("invalid Legendre symbol result");return s?1:o?0:-1}function tn(e,t){t!==void 0&&pe(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function St(e,t,r=!1,n={}){if(e<=bt)throw new Error("invalid field: expected ORDER > 0, got "+e);let s,o,i=!1,a;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let l=t;l.BITS&&(s=l.BITS),l.sqrt&&(o=l.sqrt),typeof l.isLE=="boolean"&&(r=l.isLE),typeof l.modFromBytes=="boolean"&&(i=l.modFromBytes),a=l.allowedLengths}else typeof t=="number"&&(s=t),n.sqrt&&(o=n.sqrt);let{nBitLength:c,nByteLength:u}=tn(e,s);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let f,h=Object.freeze({ORDER:e,isLE:r,BITS:c,BYTES:u,MASK:ce(c),ZERO:bt,ONE:ot,allowedLengths:a,create:l=>X(l,e),isValid:l=>{if(typeof l!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof l);return bt<=l&&l<e},is0:l=>l===bt,isValidNot0:l=>!h.is0(l)&&h.isValid(l),isOdd:l=>(l&ot)===ot,neg:l=>X(-l,e),eql:(l,d)=>l===d,sqr:l=>X(l*l,e),add:(l,d)=>X(l+d,e),sub:(l,d)=>X(l-d,e),mul:(l,d)=>X(l*d,e),pow:(l,d)=>au(h,l,d),div:(l,d)=>X(l*qi(d,e),e),sqrN:l=>l*l,addN:(l,d)=>l+d,subN:(l,d)=>l-d,mulN:(l,d)=>l*d,inv:l=>qi(l,e),sqrt:o||(l=>(f||(f=ou(e)),f(h,l))),toBytes:l=>r?xr(l,u):Jr(l,u),fromBytes:(l,d=!0)=>{if(a){if(!a.includes(l.length)||l.length>u)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+l.length);let w=new Uint8Array(u);w.set(l,r?0:w.length-l.length),l=w}if(l.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+l.length);let p=r?Bt(l):qe(l);if(i&&(p=X(p,e)),!d&&!h.isValid(p))throw new Error("invalid field element: outside of range 0..ORDER");return p},invertBatch:l=>wr(h,l),cmov:(l,d,p)=>p?d:l});return Object.freeze(h)}function Yi(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function vs(e){let t=Yi(e);return t+Math.ceil(t/2)}function As(e,t,r=!1){let n=e.length,s=Yi(t),o=vs(t);if(n<16||n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);let i=r?Bt(e):qe(e),a=X(i,t-ot)+ot;return r?xr(a,s):Jr(a,s)}var Fe=BigInt(0),we=BigInt(1);function Er(e,t){let r=t.negate();return e?r:t}function Vt(e,t){let r=wr(e.Fp,t.map(n=>n.Z));return t.map((n,s)=>e.fromAffine(n.toAffine(r[s])))}function ta(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Bs(e,t){ta(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),s=2**e,o=ce(e),i=BigInt(e);return{windows:r,windowSize:n,mask:o,maxNumber:s,shiftBy:i}}function Xi(e,t,r){let{windowSize:n,mask:s,maxNumber:o,shiftBy:i}=r,a=Number(e&s),c=e>>i;a>n&&(a-=o,c+=we);let u=t*n,f=u+Math.abs(a)-1,h=a===0,l=a<0,d=t%2!==0;return{nextN:c,offset:f,isZero:h,isNeg:l,isNegF:d,offsetF:u}}function cu(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function fu(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var Ls=new WeakMap,ea=new WeakMap;function _s(e){return ea.get(e)||1}function Ji(e){if(e!==Fe)throw new Error("invalid wNAF")}var ze=class{constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let s=t;for(;r>Fe;)r&we&&(n=n.add(s)),s=s.double(),r>>=we;return n}precomputeWindow(t,r){let{windows:n,windowSize:s}=Bs(r,this.bits),o=[],i=t,a=i;for(let c=0;c<n;c++){a=i,o.push(a);for(let u=1;u<s;u++)a=a.add(i),o.push(a);i=a.double()}return o}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let s=this.ZERO,o=this.BASE,i=Bs(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:f,isNeg:h,isNegF:l,offsetF:d}=Xi(n,a,i);n=c,f?o=o.add(Er(l,r[d])):s=s.add(Er(h,r[u]))}return Ji(n),{p:s,f:o}}wNAFUnsafe(t,r,n,s=this.ZERO){let o=Bs(t,this.bits);for(let i=0;i<o.windows&&n!==Fe;i++){let{nextN:a,offset:c,isZero:u,isNeg:f}=Xi(n,i,o);if(n=a,!u){let h=r[c];s=s.add(f?h.negate():h)}}return Ji(n),s}getPrecomputes(t,r,n){let s=Ls.get(r);return s||(s=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(s=n(s)),Ls.set(r,s))),s}cached(t,r,n){let s=_s(t);return this.wNAF(s,this.getPrecomputes(s,t,n),r)}unsafe(t,r,n,s){let o=_s(t);return o===1?this._unsafeLadder(t,r,s):this.wNAFUnsafe(o,this.getPrecomputes(o,t,n),r,s)}createCache(t,r){ta(r,this.bits),ea.set(t,r),Ls.delete(t)}hasCache(t){return _s(t)!==1}};function ra(e,t,r,n){let s=t,o=e.ZERO,i=e.ZERO;for(;r>Fe||n>Fe;)r&we&&(o=o.add(s)),n&we&&(i=i.add(s)),s=s.double(),r>>=we,n>>=we;return{p1:o,p2:i}}function Ge(e,t,r,n){cu(r,e),fu(n,t);let s=r.length,o=n.length;if(s!==o)throw new Error("arrays of points and scalars must have equal length");let i=e.ZERO,a=Qr(BigInt(s)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let u=ce(c),f=new Array(Number(u)+1).fill(i),h=Math.floor((t.BITS-1)/c)*c,l=i;for(let d=h;d>=0;d-=c){f.fill(i);for(let w=0;w<o;w++){let g=n[w],x=Number(g>>BigInt(d)&u);f[x]=f[x].add(r[w])}let p=i;for(let w=f.length-1,g=i;w>0;w--)g=g.add(f[w]),p=p.add(g);if(l=l.add(p),d!==0)for(let w=0;w<c;w++)l=l.double()}return l}function Qi(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Ss(t),t}else return St(e,{isLE:r})}function en(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let c of["p","n","h"]){let u=t[c];if(!(typeof u=="bigint"&&u>Fe))throw new Error(`CURVE.${c} must be positive bigint`)}let s=Qi(t.p,r.Fp,n),o=Qi(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let c of a)if(!s.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:s,Fn:o}}var fe=BigInt(0),it=BigInt(1),Is=BigInt(2),uu=BigInt(8);function hu(e,t,r,n){let s=e.sqr(r),o=e.sqr(n),i=e.add(e.mul(t.a,s),o),a=e.add(e.ONE,e.mul(t.d,e.mul(s,o)));return e.eql(i,a)}function lu(e,t={}){let r=en("edwards",e,t,t.FpFnLE),{Fp:n,Fn:s}=r,o=r.CURVE,{h:i}=o;Dt(t,{},{uvRatio:"function"});let a=Is<<BigInt(s.BYTES*8)-it,c=g=>n.create(g),u=t.uvRatio||((g,x)=>{try{return{isValid:!0,value:n.sqrt(n.div(g,x))}}catch{return{isValid:!1,value:fe}}});if(!hu(n,o,o.Gx,o.Gy))throw new Error("bad curve params: generator point");function f(g,x,B=!1){let E=B?it:fe;return ae("coordinate "+g,x,E,a),x}function h(g){if(!(g instanceof p))throw new Error("ExtendedPoint expected")}let l=Ve((g,x)=>{let{X:B,Y:E,Z:R}=g,k=g.is0();x==null&&(x=k?uu:n.inv(R));let O=c(B*x),M=c(E*x),P=n.mul(R,x);if(k)return{x:fe,y:it};if(P!==it)throw new Error("invZ was invalid");return{x:O,y:M}}),d=Ve(g=>{let{a:x,d:B}=o;if(g.is0())throw new Error("bad point: ZERO");let{X:E,Y:R,Z:k,T:O}=g,M=c(E*E),P=c(R*R),S=c(k*k),T=c(S*S),U=c(M*x),C=c(S*c(U+P)),m=c(T+c(B*c(M*P)));if(C!==m)throw new Error("bad point: equation left != right (1)");let y=c(E*R),b=c(k*O);if(y!==b)throw new Error("bad point: equation left != right (2)");return!0});class p{constructor(x,B,E,R){this.X=f("x",x),this.Y=f("y",B),this.Z=f("z",E,!0),this.T=f("t",R),Object.freeze(this)}static CURVE(){return o}static fromAffine(x){if(x instanceof p)throw new Error("extended point not allowed");let{x:B,y:E}=x||{};return f("x",B),f("y",E),new p(B,E,it,c(B*E))}static fromBytes(x,B=!1){let E=n.BYTES,{a:R,d:k}=o;x=xs(Et(x,E,"point")),Ht(B,"zip215");let O=xs(x),M=x[E-1];O[E-1]=M&-129;let P=Bt(O),S=B?a:n.ORDER;ae("point.y",P,fe,S);let T=c(P*P),U=c(T-it),C=c(k*T-R),{isValid:m,value:y}=u(U,C);if(!m)throw new Error("bad point: invalid y coordinate");let b=(y&it)===it,A=(M&128)!==0;if(!B&&y===fe&&A)throw new Error("bad point: x=0 and x_0=1");return A!==b&&(y=c(-y)),p.fromAffine({x:y,y:P})}static fromHex(x,B=!1){return p.fromBytes($("point",x),B)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(x=8,B=!0){return w.createCache(this,x),B||this.multiply(Is),this}assertValidity(){d(this)}equals(x){h(x);let{X:B,Y:E,Z:R}=this,{X:k,Y:O,Z:M}=x,P=c(B*M),S=c(k*R),T=c(E*M),U=c(O*R);return P===S&&T===U}is0(){return this.equals(p.ZERO)}negate(){return new p(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:x}=o,{X:B,Y:E,Z:R}=this,k=c(B*B),O=c(E*E),M=c(Is*c(R*R)),P=c(x*k),S=B+E,T=c(c(S*S)-k-O),U=P+O,C=U-M,m=P-O,y=c(T*C),b=c(U*m),A=c(T*m),L=c(C*U);return new p(y,b,L,A)}add(x){h(x);let{a:B,d:E}=o,{X:R,Y:k,Z:O,T:M}=this,{X:P,Y:S,Z:T,T:U}=x,C=c(R*P),m=c(k*S),y=c(M*E*U),b=c(O*T),A=c((R+k)*(P+S)-C-m),L=b-y,I=b+y,v=c(m-B*C),_=c(A*L),K=c(I*v),D=c(A*v),q=c(L*I);return new p(_,K,q,D)}subtract(x){return this.add(x.negate())}multiply(x){if(!s.isValidNot0(x))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:B,f:E}=w.cached(this,x,R=>Vt(p,R));return Vt(p,[B,E])[0]}multiplyUnsafe(x,B=p.ZERO){if(!s.isValid(x))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return x===fe?p.ZERO:this.is0()||x===it?this:w.unsafe(this,x,E=>Vt(p,E),B)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return w.unsafe(this,o.n).is0()}toAffine(x){return l(this,x)}clearCofactor(){return i===it?this:this.multiplyUnsafe(i)}toBytes(){let{x,y:B}=this.toAffine(),E=n.toBytes(B);return E[E.length-1]|=x&it?128:0,E}toHex(){return At(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(x){return Vt(p,x)}static msm(x,B){return Ge(p,s,x,B)}_setWindowSize(x){this.precompute(x)}toRawBytes(){return this.toBytes()}}p.BASE=new p(o.Gx,o.Gy,it,c(o.Gx*o.Gy)),p.ZERO=new p(fe,it,it,fe),p.Fp=n,p.Fn=s;let w=new ze(p,s.BITS);return p.BASE.precompute(8),p}var rn=class{constructor(t){this.ep=t}static fromBytes(t){ws()}static fromHex(t){ws()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return At(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,r){return this.init(this.ep.precompute(t,r))}toRawBytes(){return this.toBytes()}};function du(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');Dt(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:s,Fp:o,Fn:i}=e,a=r.randomBytes||re,c=r.adjustScalarBytes||(S=>S),u=r.domain||((S,T,U)=>{if(Ht(U,"phflag"),T.length||U)throw new Error("Contexts/pre-hash are not supported");return S});function f(S){return i.create(Bt(S))}function h(S){let T=E.secretKey;S=$("private key",S,T);let U=$("hashed private key",t(S),2*T),C=c(U.slice(0,T)),m=U.slice(T,2*T),y=f(C);return{head:C,prefix:m,scalar:y}}function l(S){let{head:T,prefix:U,scalar:C}=h(S),m=s.multiply(C),y=m.toBytes();return{head:T,prefix:U,scalar:C,point:m,pointBytes:y}}function d(S){return l(S).pointBytes}function p(S=Uint8Array.of(),...T){let U=gt(...T);return f(t(u(U,$("context",S),!!n)))}function w(S,T,U={}){S=$("message",S),n&&(S=n(S));let{prefix:C,scalar:m,pointBytes:y}=l(T),b=p(U.context,C,S),A=s.multiply(b).toBytes(),L=p(U.context,A,y,S),I=i.create(b+L*m);if(!i.isValid(I))throw new Error("sign failed: invalid s");let v=gt(A,i.toBytes(I));return Et(v,E.signature,"result")}let g={zip215:!0};function x(S,T,U,C=g){let{context:m,zip215:y}=C,b=E.signature;S=$("signature",S,b),T=$("message",T),U=$("publicKey",U,E.publicKey),y!==void 0&&Ht(y,"zip215"),n&&(T=n(T));let A=b/2,L=S.subarray(0,A),I=Bt(S.subarray(A,b)),v,_,K;try{v=e.fromBytes(U,y),_=e.fromBytes(L,y),K=s.multiplyUnsafe(I)}catch{return!1}if(!y&&v.isSmallOrder())return!1;let D=p(m,_.toBytes(),v.toBytes(),T);return _.add(v.multiplyUnsafe(D)).subtract(K).clearCofactor().is0()}let B=o.BYTES,E={secretKey:B,publicKey:B,signature:2*B,seed:B};function R(S=a(E.seed)){return Et(S,E.seed,"seed")}function k(S){let T=P.randomSecretKey(S);return{secretKey:T,publicKey:d(T)}}function O(S){return Mt(S)&&S.length===i.BYTES}function M(S,T){try{return!!e.fromBytes(S,T)}catch{return!1}}let P={getExtendedPublicKey:l,randomSecretKey:R,isValidSecretKey:O,isValidPublicKey:M,toMontgomery(S){let{y:T}=e.fromBytes(S),U=E.publicKey,C=U===32;if(!C&&U!==57)throw new Error("only defined for 25519 and 448");let m=C?o.div(it+T,it-T):o.div(T-it,T+it);return o.toBytes(m)},toMontgomerySecret(S){let T=E.secretKey;Et(S,T);let U=t(S.subarray(0,T));return c(U).subarray(0,T)},randomPrivateKey:R,precompute(S=8,T=e.BASE){return T.precompute(S,!1)}};return Object.freeze({keygen:k,getPublicKey:d,sign:w,verify:x,utils:P,Point:e,lengths:E})}function pu(e){let t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=St(t.n,e.nBitLength,!0),s={Fp:r,Fn:n,uvRatio:e.uvRatio},o={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:s,hash:e.hash,eddsaOpts:o}}function mu(e,t){let r=t.Point;return Object.assign({},t,{ExtendedPoint:r,CURVE:e,nBitLength:r.Fn.BITS,nByteLength:r.Fn.BYTES})}function na(e){let{CURVE:t,curveOpts:r,hash:n,eddsaOpts:s}=pu(e),o=lu(t,r),i=du(o,n,s);return mu(e,i)}var Sr=BigInt(0),je=BigInt(1),nn=BigInt(2);function yu(e){return Dt(e,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...e})}function sa(e){let t=yu(e),{P:r,type:n,adjustScalarBytes:s,powPminus2:o,randomBytes:i}=t,a=n==="x25519";if(!a&&n!=="x448")throw new Error("invalid type");let c=i||re,u=a?255:448,f=a?32:56,h=BigInt(a?9:5),l=BigInt(a?121665:39081),d=a?nn**BigInt(254):nn**BigInt(447),p=a?BigInt(8)*nn**BigInt(251)-je:BigInt(4)*nn**BigInt(445)-je,w=d+p+je,g=m=>X(m,r),x=B(h);function B(m){return xr(g(m),f)}function E(m){let y=$("u coordinate",m,f);return a&&(y[31]&=127),g(Bt(y))}function R(m){return Bt(s($("scalar",m,f)))}function k(m,y){let b=P(E(y),R(m));if(b===Sr)throw new Error("invalid private or public key received");return B(b)}function O(m){return k(m,x)}function M(m,y,b){let A=g(m*(y-b));return y=g(y-A),b=g(b+A),{x_2:y,x_3:b}}function P(m,y){ae("u",m,Sr,r),ae("scalar",y,d,w);let b=y,A=m,L=je,I=Sr,v=m,_=je,K=Sr;for(let q=BigInt(u-1);q>=Sr;q--){let V=b>>q&je;K^=V,{x_2:L,x_3:v}=M(K,L,v),{x_2:I,x_3:_}=M(K,I,_),K=V;let H=L+I,F=g(H*H),Z=L-I,Q=g(Z*Z),z=F-Q,st=v+_,Ie=v-_,ir=g(Ie*H),ar=g(st*Z),Go=ir+ar,jo=ir-ar;v=g(Go*Go),_=g(A*g(jo*jo)),L=g(F*Q),I=g(z*(F+g(l*z)))}({x_2:L,x_3:v}=M(K,L,v)),{x_2:I,x_3:_}=M(K,I,_);let D=o(I);return g(L*D)}let S={secretKey:f,publicKey:f,seed:f},T=(m=c(f))=>(lt(m,S.seed),m);function U(m){let y=T(m);return{secretKey:y,publicKey:O(y)}}return{keygen:U,getSharedSecret:(m,y)=>k(m,y),getPublicKey:m=>O(m),scalarMult:k,scalarMultBase:O,utils:{randomSecretKey:T,randomPrivateKey:T},GuBytes:x.slice(),lengths:S}}var gu=BigInt(0),zt=BigInt(1),oa=BigInt(2),bu=BigInt(3),xu=BigInt(5),wu=BigInt(8),$e=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),vr={p:$e,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:wu,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function ca(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),s=BigInt(80),o=$e,a=e*e%o*e%o,c=J(a,oa,o)*a%o,u=J(c,zt,o)*e%o,f=J(u,xu,o)*u%o,h=J(f,t,o)*f%o,l=J(h,r,o)*h%o,d=J(l,n,o)*l%o,p=J(d,s,o)*d%o,w=J(p,s,o)*d%o,g=J(w,t,o)*f%o;return{pow_p_5_8:J(g,oa,o)*e%o,b2:a}}function fa(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Ts=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Rs(e,t){let r=$e,n=X(t*t*t,r),s=X(n*n*t,r),o=ca(e*s).pow_p_5_8,i=X(e*n*o,r),a=X(t*i*i,r),c=i,u=X(i*Ts,r),f=a===e,h=a===X(-e,r),l=a===X(-e*Ts,r);return f&&(i=c),(h||l)&&(i=u),qt(i,r)&&(i=X(-i,r)),{isValid:f||h,value:i}}var Ft=St(vr.p,{isLE:!0}),Eu=St(vr.n,{isLE:!0}),Su={...vr,Fp:Ft,hash:Ni,adjustScalarBytes:fa,uvRatio:Rs},Gt=na(Su);var Ar=(()=>{let e=Ft.ORDER;return sa({P:e,type:"x25519",powPminus2:t=>{let{pow_p_5_8:r,b2:n}=ca(t);return X(J(r,bu,e)*n,e)},adjustScalarBytes:fa})})();var Cs=Ts,vu=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Au=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Bu=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Lu=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),ia=e=>Rs(zt,e),_u=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Ks=e=>Gt.Point.Fp.create(Bt(e)&_u);function aa(e){let{d:t}=vr,r=$e,n=x=>Ft.create(x),s=n(Cs*e*e),o=n((s+zt)*Bu),i=BigInt(-1),a=n((i-t*s)*n(s+t)),{isValid:c,value:u}=Rs(o,a),f=n(u*e);qt(f,r)||(f=n(-f)),c||(u=f),c||(i=s);let h=n(i*(s-zt)*Lu-a),l=u*u,d=n((u+u)*a),p=n(h*vu),w=n(zt-l),g=n(zt+l);return new Gt.Point(n(d*g),n(w*p),n(p*g),n(d*w))}function Iu(e){lt(e,64);let t=Ks(e.subarray(0,32)),r=aa(t),n=Ks(e.subarray(32,64)),s=aa(n);return new jt(r.add(s))}var jt=class e extends rn{constructor(t){super(t)}static fromAffine(t){return new e(Gt.Point.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static hashToCurve(t){return Iu($("ristrettoHash",t,64))}static fromBytes(t){lt(t,32);let{a:r,d:n}=vr,s=$e,o=R=>Ft.create(R),i=Ks(t);if(!Mi(Ft.toBytes(i),t)||qt(i,s))throw new Error("invalid ristretto255 encoding 1");let a=o(i*i),c=o(zt+r*a),u=o(zt-r*a),f=o(c*c),h=o(u*u),l=o(r*n*f-h),{isValid:d,value:p}=ia(o(l*h)),w=o(p*u),g=o(p*w*l),x=o((i+i)*w);qt(x,s)&&(x=o(-x));let B=o(c*g),E=o(x*B);if(!d||qt(E,s)||B===gu)throw new Error("invalid ristretto255 encoding 2");return new e(new Gt.Point(x,B,zt,E))}static fromHex(t){return e.fromBytes($("ristrettoHex",t,32))}static msm(t,r){return Ge(e,Gt.Point.Fn,t,r)}toBytes(){let{X:t,Y:r,Z:n,T:s}=this.ep,o=$e,i=g=>Ft.create(g),a=i(i(n+r)*i(n-r)),c=i(t*r),u=i(c*c),{value:f}=ia(i(a*u)),h=i(f*a),l=i(f*c),d=i(h*l*s),p;if(qt(s*d,o)){let g=i(r*Cs),x=i(t*Cs);t=g,r=x,p=i(h*Au)}else p=l;qt(t*d,o)&&(r=i(-r));let w=i((n-r)*p);return qt(w,o)&&(w=i(-w)),Ft.toBytes(w)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:s,Y:o}=t.ep,i=u=>Ft.create(u),a=i(r*o)===i(n*s),c=i(n*o)===i(r*s);return a||c}is0(){return this.equals(e.ZERO)}};jt.BASE=new jt(Gt.Point.BASE);jt.ZERO=new jt(Gt.Point.ZERO);jt.Fp=Ft;jt.Fn=Eu;var Br=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},sn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var ua={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new sn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var Lt=ua;var on=32;var Us,Tu=(async()=>{try{return await Lt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Cu(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Lt.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Lt.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Ku(e,t,r){return Gt.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function ha(e,t,r){return Us==null&&(Us=await Tu),Us?Cu(e,t,r):Ku(e,t,r)}function an(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var cn=class{type="Ed25519";raw;constructor(t){this.raw=Ds(t,on)}toMultihash(){return Rt.digest(te(this))}toCID(){return ht.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:yt(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let s=ha(this.raw,r,t);return an(s)?s.then(o=>(n?.signal?.throwIfAborted(),o)):s}};function da(e){return e=Ds(e,on),new cn(e)}function Ds(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new tt(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Uu=Math.pow(2,7),Du=Math.pow(2,14),Pu=Math.pow(2,21),Ps=Math.pow(2,28),Ns=Math.pow(2,35),ks=Math.pow(2,42),Ms=Math.pow(2,49),W=128,dt=127;function Tt(e){if(e<Uu)return 1;if(e<Du)return 2;if(e<Pu)return 3;if(e<Ps)return 4;if(e<Ns)return 5;if(e<ks)return 6;if(e<Ms)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Os(e,t,r=0){switch(Tt(e)){case 8:t[r++]=e&255|W,e/=128;case 7:t[r++]=e&255|W,e/=128;case 6:t[r++]=e&255|W,e/=128;case 5:t[r++]=e&255|W,e/=128;case 4:t[r++]=e&255|W,e>>>=7;case 3:t[r++]=e&255|W,e>>>=7;case 2:t[r++]=e&255|W,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Nu(e,t,r=0){switch(Tt(e)){case 8:t.set(r++,e&255|W),e/=128;case 7:t.set(r++,e&255|W),e/=128;case 6:t.set(r++,e&255|W),e/=128;case 5:t.set(r++,e&255|W),e/=128;case 4:t.set(r++,e&255|W),e>>>=7;case 3:t.set(r++,e&255|W),e>>>=7;case 2:t.set(r++,e&255|W),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function Hs(e,t){let r=e[t],n=0;if(n+=r&dt,r<W||(r=e[t+1],n+=(r&dt)<<7,r<W)||(r=e[t+2],n+=(r&dt)<<14,r<W)||(r=e[t+3],n+=(r&dt)<<21,r<W)||(r=e[t+4],n+=(r&dt)*Ps,r<W)||(r=e[t+5],n+=(r&dt)*Ns,r<W)||(r=e[t+6],n+=(r&dt)*ks,r<W)||(r=e[t+7],n+=(r&dt)*Ms,r<W))return n;throw new RangeError("Could not decode varint")}function ku(e,t){let r=e.get(t),n=0;if(n+=r&dt,r<W||(r=e.get(t+1),n+=(r&dt)<<7,r<W)||(r=e.get(t+2),n+=(r&dt)<<14,r<W)||(r=e.get(t+3),n+=(r&dt)<<21,r<W)||(r=e.get(t+4),n+=(r&dt)*Ps,r<W)||(r=e.get(t+5),n+=(r&dt)*Ns,r<W)||(r=e.get(t+6),n+=(r&dt)*ks,r<W)||(r=e.get(t+7),n+=(r&dt)*Ms,r<W))return n;throw new RangeError("Could not decode varint")}function pa(e,t,r=0){return t==null&&(t=ct(Tt(e))),t instanceof Uint8Array?Os(e,t,r):Nu(e,t,r)}function fn(e,t=0){return e instanceof Uint8Array?Hs(e,t):ku(e,t)}var qs=new Float32Array([-0]),ue=new Uint8Array(qs.buffer);function ya(e,t,r){qs[0]=e,t[r]=ue[0],t[r+1]=ue[1],t[r+2]=ue[2],t[r+3]=ue[3]}function ga(e,t){return ue[0]=e[t],ue[1]=e[t+1],ue[2]=e[t+2],ue[3]=e[t+3],qs[0]}var Vs=new Float64Array([-0]),pt=new Uint8Array(Vs.buffer);function ba(e,t,r){Vs[0]=e,t[r]=pt[0],t[r+1]=pt[1],t[r+2]=pt[2],t[r+3]=pt[3],t[r+4]=pt[4],t[r+5]=pt[5],t[r+6]=pt[6],t[r+7]=pt[7]}function xa(e,t){return pt[0]=e[t],pt[1]=e[t+1],pt[2]=e[t+2],pt[3]=e[t+3],pt[4]=e[t+4],pt[5]=e[t+5],pt[6]=e[t+6],pt[7]=e[t+7],Vs[0]}var Mu=BigInt(Number.MAX_SAFE_INTEGER),Ou=BigInt(Number.MIN_SAFE_INTEGER),vt=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return Ee;if(t<Mu&&t>Ou)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,s=t-(n<<32n);return r&&(n=~n|0n,s=~s|0n,++s>wa&&(s=0n,++n>wa&&(n=0n))),new e(Number(s),Number(n))}static fromNumber(t){if(t===0)return Ee;let r=t<0;r&&(t=-t);let n=t>>>0,s=(t-n)/4294967296>>>0;return r&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new e(n,s)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):Ee}},Ee=new vt(0,0);Ee.toBigInt=function(){return 0n};Ee.zzEncode=Ee.zzDecode=function(){return this};Ee.length=function(){return 1};var wa=4294967296n;function Ea(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Sa(e,t,r){if(r-t<1)return"";let s,o=[],i=0,a;for(;t<r;)a=e[t++],a<128?o[i++]=a:a>191&&a<224?o[i++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,o[i++]=55296+(a>>10),o[i++]=56320+(a&1023)):o[i++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,o)),i=0);return s!=null?(i>0&&s.push(String.fromCharCode.apply(String,o.slice(0,i))),s.join("")):String.fromCharCode.apply(String,o.slice(0,i))}function Fs(e,t,r){let n=r,s,o;for(let i=0;i<e.length;++i)s=e.charCodeAt(i),s<128?t[r++]=s:s<2048?(t[r++]=s>>6|192,t[r++]=s&63|128):(s&64512)===55296&&((o=e.charCodeAt(i+1))&64512)===56320?(s=65536+((s&1023)<<10)+(o&1023),++i,t[r++]=s>>18|240,t[r++]=s>>12&63|128,t[r++]=s>>6&63|128,t[r++]=s&63|128):(t[r++]=s>>12|224,t[r++]=s>>6&63|128,t[r++]=s&63|128);return r-n}function Ct(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function un(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var zs=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Ct(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ct(this,4);return un(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ct(this,4);return un(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ct(this,4);let t=ga(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Ct(this,4);let t=xa(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Ct(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Sa(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Ct(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Ct(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new vt(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Ct(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Ct(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ct(this,8);let t=un(this.buf,this.pos+=4),r=un(this.buf,this.pos+=4);return new vt(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Hs(this.buf,this.pos);return this.pos+=Tt(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Gs(e){return new zs(e instanceof Uint8Array?e:e.subarray())}function Se(e,t,r){let n=Gs(e);return t.decode(n,void 0,r)}function js(e){let t=e??8192,r=t>>>1,n,s=t;return function(i){if(i<1||i>r)return ct(i);s+i>t&&(n=ct(t),s=0);let a=n.subarray(s,s+=i);return(s&7)!==0&&(s=(s|7)+1),a}}var ve=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function $s(){}var Ws=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Hu=js();function qu(e){return globalThis.Buffer!=null?ct(e):Hu(e)}var _r=class{len;head;tail;states;constructor(){this.len=0,this.head=new ve($s,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new ve(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Ys((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(hn,10,vt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=vt.fromBigInt(t);return this._push(hn,r.length(),r)}uint64Number(t){return this._push(Os,Tt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=vt.fromBigInt(t).zzEncode();return this._push(hn,r.length(),r)}sint64Number(t){let r=vt.fromNumber(t).zzEncode();return this._push(hn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Zs,1,t?1:0)}fixed32(t){return this._push(Lr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=vt.fromBigInt(t);return this._push(Lr,4,r.lo)._push(Lr,4,r.hi)}fixed64Number(t){let r=vt.fromNumber(t);return this._push(Lr,4,r.lo)._push(Lr,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(ya,4,t)}double(t){return this._push(ba,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Zs,1,0):this.uint32(r)._push(Fu,r,t)}string(t){let r=Ea(t);return r!==0?this.uint32(r)._push(Fs,r,t):this._push(Zs,1,0)}fork(){return this.states=new Ws(this),this.head=this.tail=new ve($s,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new ve($s,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=qu(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Zs(e,t,r){t[r]=e&255}function Vu(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Ys=class extends ve{next;constructor(t,r){super(Vu,t,r),this.next=void 0}};function hn(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function Lr(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function Fu(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(_r.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(zu,t,e),this},_r.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Gu,t,e),this});function zu(e,t,r){t.set(e,r)}function Gu(e,t,r){e.length<40?Fs(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(Y(e),r)}function Xs(){return new _r}function Ae(e,t){let r=Xs();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var Ze;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(Ze||(Ze={}));function ln(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function Js(e){function t(s){if(e[s.toString()]==null)throw new Error("Invalid enum value");return e[s]}let r=function(o,i){let a=t(o);i.int32(a)},n=function(o){let i=o.int32();return t(i)};return ln("enum",Ze.VARINT,r,n)}function Be(e,t){return ln("message",Ze.LENGTH_DELIMITED,e,t)}var Ir=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var at;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(at||(at={}));var Qs;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Qs||(Qs={}));(function(e){e.codec=()=>Js(Qs)})(at||(at={}));var $t;(function(e){let t;e.codec=()=>(t==null&&(t=Be((r,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),at.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),s.lengthDelimited!==!1&&n.ldelim()},(r,n,s={})=>{let o={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{o.Type=at.codec().decode(r);break}case 2:{o.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return o})),t),e.encode=r=>Ae(r,e.codec()),e.decode=(r,n)=>Se(r,e.codec(),n)})($t||($t={}));var to;(function(e){let t;e.codec=()=>(t==null&&(t=Be((r,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),at.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),s.lengthDelimited!==!1&&n.ldelim()},(r,n,s={})=>{let o={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{o.Type=at.codec().decode(r);break}case 2:{o.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return o})),t),e.encode=r=>Ae(r,e.codec()),e.decode=(r,n)=>Se(r,e.codec(),n)})(to||(to={}));var Cr={};xt(Cr,{MAX_RSA_KEY_SIZE:()=>eo,generateRSAKeyPair:()=>Ia,jwkToJWKKeyPair:()=>Ta,jwkToPkcs1:()=>Wu,jwkToPkix:()=>oo,jwkToRSAPrivateKey:()=>fo,pkcs1MessageToJwk:()=>no,pkcs1MessageToRSAPrivateKey:()=>io,pkcs1ToJwk:()=>Zu,pkcs1ToRSAPrivateKey:()=>_a,pkixMessageToJwk:()=>so,pkixMessageToRSAPublicKey:()=>co,pkixToJwk:()=>Yu,pkixToRSAPublicKey:()=>ao});var dn=ie;var We=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Cr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ht.createV1(114,this._multihash)}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:yt(this.raw,t.raw)}verify(t,r,n){return La(this.jwk,r,t,n)}},Tr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Cr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:yt(this.raw,t.raw)}sign(t,r){return Ba(this.jwk,t,r)}};var eo=8192,ro=18,ju=1062,$u=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Zu(e){let t=Nt(e);return no(t)}function no(e){return{n:j(e[1],"base64url"),e:j(e[2],"base64url"),d:j(e[3],"base64url"),p:j(e[4],"base64url"),q:j(e[5],"base64url"),dp:j(e[6],"base64url"),dq:j(e[7],"base64url"),qi:j(e[8],"base64url"),kty:"RSA"}}function Wu(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new tt("JWK was missing components");return Qt([wt(Uint8Array.from([0])),wt(Y(e.n,"base64url")),wt(Y(e.e,"base64url")),wt(Y(e.d,"base64url")),wt(Y(e.p,"base64url")),wt(Y(e.q,"base64url")),wt(Y(e.dp,"base64url")),wt(Y(e.dq,"base64url")),wt(Y(e.qi,"base64url"))]).subarray()}function Yu(e){let t=Nt(e,{offset:0});return so(t)}function so(e){let t=Nt(e[1],{offset:0});return{kty:"RSA",n:j(t[0],"base64url"),e:j(t[1],"base64url")}}function oo(e){if(e.n==null||e.e==null)throw new tt("JWK was missing components");return Qt([$u,Zr(Qt([wt(Y(e.n,"base64url")),wt(Y(e.e,"base64url"))]))]).subarray()}function _a(e){let t=Nt(e);return io(t)}function io(e){let t=no(e);return fo(t)}function ao(e,t){if(e.byteLength>=ju)throw new Te("Key size is too large");let r=Nt(e,{offset:0});return co(r,e,t)}function co(e,t,r){let n=so(e);if(r==null){let s=dn($t.encode({Type:at.RSA,Data:t}));r=Kt(ro,s)}return new We(n,r)}function fo(e){if(Ka(e)>eo)throw new tt("Key size is too large");let t=Ta(e),r=dn($t.encode({Type:at.RSA,Data:oo(t.publicKey)})),n=Kt(ro,r);return new Tr(t.privateKey,new We(t.publicKey,n))}async function Ia(e){if(e>eo)throw new tt("Key size is too large");let t=await Ca(e),r=dn($t.encode({Type:at.RSA,Data:oo(t.publicKey)})),n=Kt(ro,r);return new Tr(t.privateKey,new We(t.publicKey,n))}function Ta(e){if(e==null)throw new tt("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function Ca(e,t){let r=await Lt.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await Xu(r,t);return{privateKey:n[0],publicKey:n[1]}}async function Ba(e,t,r){let n=await Lt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let s=await Lt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(s,0,s.byteLength)}async function La(e,t,r,n){let s=await Lt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let o=await Lt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},s,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),o}async function Xu(e,t){if(e.privateKey==null||e.publicKey==null)throw new tt("Private and public key are required");let r=await Promise.all([Lt.get().subtle.exportKey("jwk",e.privateKey),Lt.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function Ka(e){if(e.kty!=="RSA")throw new tt("invalid key type");if(e.n==null)throw new tt("invalid key modulus");return Y(e.n,"base64url").length*8}var pn=class extends Oe{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,me(t);let n=ee(r);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let s=this.blockLen,o=new Uint8Array(s);o.set(n.length>s?t.create().update(n).digest():n);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=t.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),_t(o)}update(t){return He(this),this.iHash.update(t),this}digestInto(t){He(this),lt(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:s,destroyed:o,blockLen:i,outputLen:a}=this;return t=t,t.finished=s,t.destroyed=o,t.blockLen=i,t.outputLen=a,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ye=(e,t,r)=>new pn(e,t).update(r).digest();Ye.create=(e,t)=>new pn(e,t);var Ra=(e,t)=>(e+(e>=0?t:-t)/Ua)/t;function Ju(e,t,r){let[[n,s],[o,i]]=t,a=Ra(i*e,r),c=Ra(-s*e,r),u=e-a*n-c*o,f=-a*s-c*i,h=u<Wt,l=f<Wt;h&&(u=-u),l&&(f=-f);let d=ce(Math.ceil(Qr(r)/2))+Je;if(u<Wt||u>=d||f<Wt||f>=d)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:h,k1:u,k2neg:l,k2:f}}function ho(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function uo(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return Ht(r.lowS,"lowS"),Ht(r.prehash,"prehash"),r.format!==void 0&&ho(r.format),r}var lo=class extends Error{constructor(t=""){super(t)}},Zt={Err:lo,_tlv:{encode:(e,t)=>{let{Err:r}=Zt;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,s=br(n);if(s.length/2&128)throw new r("tlv.encode: long form length too big");let o=n>127?br(s.length/2|128):"";return br(e)+o+s+t},decode(e,t){let{Err:r}=Zt,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let s=t[n++],o=!!(s&128),i=0;if(!o)i=s;else{let c=s&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=Zt;if(e<Wt)throw new t("integer: negative integers are not allowed");let r=br(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=Zt;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return qe(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Zt,s=$("signature",e),{v:o,l:i}=n.decode(48,s);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,o),{v:u,l:f}=n.decode(2,c);if(f.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=Zt,n=t.encode(2,r.encode(e.r)),s=t.encode(2,r.encode(e.s)),o=n+s;return t.encode(48,o)}},Wt=BigInt(0),Je=BigInt(1),Ua=BigInt(2),mn=BigInt(3),Qu=BigInt(4);function Xe(e,t){let{BYTES:r}=e,n;if(typeof t=="bigint")n=t;else{let s=$("private key",t);try{n=e.fromBytes(s)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof t}`)}}if(!e.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function th(e,t={}){let r=en("weierstrass",e,t),{Fp:n,Fn:s}=r,o=r.CURVE,{h:i,n:a}=o;Dt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:c}=t;if(c&&(!n.is0(o.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=Pa(n,s);function f(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function h(C,m,y){let{x:b,y:A}=m.toAffine(),L=n.toBytes(b);if(Ht(y,"isCompressed"),y){f();let I=!n.isOdd(A);return gt(Da(I),L)}else return gt(Uint8Array.of(4),L,n.toBytes(A))}function l(C){Et(C,void 0,"Point");let{publicKey:m,publicKeyUncompressed:y}=u,b=C.length,A=C[0],L=C.subarray(1);if(b===m&&(A===2||A===3)){let I=n.fromBytes(L);if(!n.isValid(I))throw new Error("bad point: is not on curve, wrong x");let v=w(I),_;try{_=n.sqrt(v)}catch(q){let V=q instanceof Error?": "+q.message:"";throw new Error("bad point: is not on curve, sqrt error"+V)}f();let K=n.isOdd(_);return(A&1)===1!==K&&(_=n.neg(_)),{x:I,y:_}}else if(b===y&&A===4){let I=n.BYTES,v=n.fromBytes(L.subarray(0,I)),_=n.fromBytes(L.subarray(I,I*2));if(!g(v,_))throw new Error("bad point: is not on curve");return{x:v,y:_}}else throw new Error(`bad point: got length ${b}, expected compressed=${m} or uncompressed=${y}`)}let d=t.toBytes||h,p=t.fromBytes||l;function w(C){let m=n.sqr(C),y=n.mul(m,C);return n.add(n.add(y,n.mul(C,o.a)),o.b)}function g(C,m){let y=n.sqr(m),b=w(C);return n.eql(y,b)}if(!g(o.Gx,o.Gy))throw new Error("bad curve params: generator point");let x=n.mul(n.pow(o.a,mn),Qu),B=n.mul(n.sqr(o.b),BigInt(27));if(n.is0(n.add(x,B)))throw new Error("bad curve params: a or b");function E(C,m,y=!1){if(!n.isValid(m)||y&&n.is0(m))throw new Error(`bad point coordinate ${C}`);return m}function R(C){if(!(C instanceof S))throw new Error("ProjectivePoint expected")}function k(C){if(!c||!c.basises)throw new Error("no endo");return Ju(C,c.basises,s.ORDER)}let O=Ve((C,m)=>{let{X:y,Y:b,Z:A}=C;if(n.eql(A,n.ONE))return{x:y,y:b};let L=C.is0();m==null&&(m=L?n.ONE:n.inv(A));let I=n.mul(y,m),v=n.mul(b,m),_=n.mul(A,m);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(_,n.ONE))throw new Error("invZ was invalid");return{x:I,y:v}}),M=Ve(C=>{if(C.is0()){if(t.allowInfinityPoint&&!n.is0(C.Y))return;throw new Error("bad point: ZERO")}let{x:m,y}=C.toAffine();if(!n.isValid(m)||!n.isValid(y))throw new Error("bad point: x or y not field elements");if(!g(m,y))throw new Error("bad point: equation left != right");if(!C.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function P(C,m,y,b,A){return y=new S(n.mul(y.X,C),y.Y,y.Z),m=Er(b,m),y=Er(A,y),m.add(y)}class S{constructor(m,y,b){this.X=E("x",m),this.Y=E("y",y,!0),this.Z=E("z",b),Object.freeze(this)}static CURVE(){return o}static fromAffine(m){let{x:y,y:b}=m||{};if(!m||!n.isValid(y)||!n.isValid(b))throw new Error("invalid affine point");if(m instanceof S)throw new Error("projective point not allowed");return n.is0(y)&&n.is0(b)?S.ZERO:new S(y,b,n.ONE)}static fromBytes(m){let y=S.fromAffine(p(Et(m,void 0,"point")));return y.assertValidity(),y}static fromHex(m){return S.fromBytes($("pointHex",m))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,y=!0){return U.createCache(this,m),y||this.multiply(mn),this}assertValidity(){M(this)}hasEvenY(){let{y:m}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(m)}equals(m){R(m);let{X:y,Y:b,Z:A}=this,{X:L,Y:I,Z:v}=m,_=n.eql(n.mul(y,v),n.mul(L,A)),K=n.eql(n.mul(b,v),n.mul(I,A));return _&&K}negate(){return new S(this.X,n.neg(this.Y),this.Z)}double(){let{a:m,b:y}=o,b=n.mul(y,mn),{X:A,Y:L,Z:I}=this,v=n.ZERO,_=n.ZERO,K=n.ZERO,D=n.mul(A,A),q=n.mul(L,L),V=n.mul(I,I),H=n.mul(A,L);return H=n.add(H,H),K=n.mul(A,I),K=n.add(K,K),v=n.mul(m,K),_=n.mul(b,V),_=n.add(v,_),v=n.sub(q,_),_=n.add(q,_),_=n.mul(v,_),v=n.mul(H,v),K=n.mul(b,K),V=n.mul(m,V),H=n.sub(D,V),H=n.mul(m,H),H=n.add(H,K),K=n.add(D,D),D=n.add(K,D),D=n.add(D,V),D=n.mul(D,H),_=n.add(_,D),V=n.mul(L,I),V=n.add(V,V),D=n.mul(V,H),v=n.sub(v,D),K=n.mul(V,q),K=n.add(K,K),K=n.add(K,K),new S(v,_,K)}add(m){R(m);let{X:y,Y:b,Z:A}=this,{X:L,Y:I,Z:v}=m,_=n.ZERO,K=n.ZERO,D=n.ZERO,q=o.a,V=n.mul(o.b,mn),H=n.mul(y,L),F=n.mul(b,I),Z=n.mul(A,v),Q=n.add(y,b),z=n.add(L,I);Q=n.mul(Q,z),z=n.add(H,F),Q=n.sub(Q,z),z=n.add(y,A);let st=n.add(L,v);return z=n.mul(z,st),st=n.add(H,Z),z=n.sub(z,st),st=n.add(b,A),_=n.add(I,v),st=n.mul(st,_),_=n.add(F,Z),st=n.sub(st,_),D=n.mul(q,z),_=n.mul(V,Z),D=n.add(_,D),_=n.sub(F,D),D=n.add(F,D),K=n.mul(_,D),F=n.add(H,H),F=n.add(F,H),Z=n.mul(q,Z),z=n.mul(V,z),F=n.add(F,Z),Z=n.sub(H,Z),Z=n.mul(q,Z),z=n.add(z,Z),H=n.mul(F,z),K=n.add(K,H),H=n.mul(st,z),_=n.mul(Q,_),_=n.sub(_,H),H=n.mul(Q,F),D=n.mul(st,D),D=n.add(D,H),new S(_,K,D)}subtract(m){return this.add(m.negate())}is0(){return this.equals(S.ZERO)}multiply(m){let{endo:y}=t;if(!s.isValidNot0(m))throw new Error("invalid scalar: out of range");let b,A,L=I=>U.cached(this,I,v=>Vt(S,v));if(y){let{k1neg:I,k1:v,k2neg:_,k2:K}=k(m),{p:D,f:q}=L(v),{p:V,f:H}=L(K);A=q.add(H),b=P(y.beta,D,V,I,_)}else{let{p:I,f:v}=L(m);b=I,A=v}return Vt(S,[b,A])[0]}multiplyUnsafe(m){let{endo:y}=t,b=this;if(!s.isValid(m))throw new Error("invalid scalar: out of range");if(m===Wt||b.is0())return S.ZERO;if(m===Je)return b;if(U.hasCache(this))return this.multiply(m);if(y){let{k1neg:A,k1:L,k2neg:I,k2:v}=k(m),{p1:_,p2:K}=ra(S,b,L,v);return P(y.beta,_,K,A,I)}else return U.unsafe(b,m)}multiplyAndAddUnsafe(m,y,b){let A=this.multiplyUnsafe(y).add(m.multiplyUnsafe(b));return A.is0()?void 0:A}toAffine(m){return O(this,m)}isTorsionFree(){let{isTorsionFree:m}=t;return i===Je?!0:m?m(S,this):U.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:m}=t;return i===Je?this:m?m(S,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(m=!0){return Ht(m,"isCompressed"),this.assertValidity(),d(S,this,m)}toHex(m=!0){return At(this.toBytes(m))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(m=!0){return this.toBytes(m)}_setWindowSize(m){this.precompute(m)}static normalizeZ(m){return Vt(S,m)}static msm(m,y){return Ge(S,s,m,y)}static fromPrivateKey(m){return S.BASE.multiply(Xe(s,m))}}S.BASE=new S(o.Gx,o.Gy,n.ONE),S.ZERO=new S(n.ZERO,n.ONE,n.ZERO),S.Fp=n,S.Fn=s;let T=s.BITS,U=new ze(S,t.endo?Math.ceil(T/2):T);return S.BASE.precompute(8),S}function Da(e){return Uint8Array.of(e?2:3)}function Pa(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function eh(e,t={}){let{Fn:r}=e,n=t.randomBytes||re,s=Object.assign(Pa(e.Fp,r),{seed:vs(r.ORDER)});function o(d){try{return!!Xe(r,d)}catch{return!1}}function i(d,p){let{publicKey:w,publicKeyUncompressed:g}=s;try{let x=d.length;return p===!0&&x!==w||p===!1&&x!==g?!1:!!e.fromBytes(d)}catch{return!1}}function a(d=n(s.seed)){return As(Et(d,s.seed,"seed"),r.ORDER)}function c(d,p=!0){return e.BASE.multiply(Xe(r,d)).toBytes(p)}function u(d){let p=a(d);return{secretKey:p,publicKey:c(p)}}function f(d){if(typeof d=="bigint")return!1;if(d instanceof e)return!0;let{secretKey:p,publicKey:w,publicKeyUncompressed:g}=s;if(r.allowedLengths||p===w)return;let x=$("key",d).length;return x===w||x===g}function h(d,p,w=!0){if(f(d)===!0)throw new Error("first arg must be private key");if(f(p)===!1)throw new Error("second arg must be public key");let g=Xe(r,d);return e.fromHex(p).multiply(g).toBytes(w)}return Object.freeze({getPublicKey:c,getSharedSecret:h,keygen:u,Point:e,utils:{isValidSecretKey:o,isValidPublicKey:i,randomSecretKey:a,isValidPrivateKey:o,randomPrivateKey:a,normPrivateKeyToScalar:d=>Xe(r,d),precompute(d=8,p=e.BASE){return p.precompute(d,!1)}},lengths:s})}function rh(e,t,r={}){me(t),Dt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||re,s=r.hmac||((y,...b)=>Ye(t,y,gt(...b))),{Fp:o,Fn:i}=e,{ORDER:a,BITS:c}=i,{keygen:u,getPublicKey:f,getSharedSecret:h,utils:l,lengths:d}=eh(e,r),p={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},w="compact";function g(y){let b=a>>Je;return y>b}function x(y,b){if(!i.isValidNot0(b))throw new Error(`invalid signature ${y}: out of range 1..Point.Fn.ORDER`);return b}function B(y,b){ho(b);let A=d.signature,L=b==="compact"?A:b==="recovered"?A+1:void 0;return Et(y,L,`${b} signature`)}class E{constructor(b,A,L){this.r=x("r",b),this.s=x("s",A),L!=null&&(this.recovery=L),Object.freeze(this)}static fromBytes(b,A=w){B(b,A);let L;if(A==="der"){let{r:K,s:D}=Zt.toSig(Et(b));return new E(K,D)}A==="recovered"&&(L=b[0],A="compact",b=b.subarray(1));let I=i.BYTES,v=b.subarray(0,I),_=b.subarray(I,I*2);return new E(i.fromBytes(v),i.fromBytes(_),L)}static fromHex(b,A){return this.fromBytes(ye(b),A)}addRecoveryBit(b){return new E(this.r,this.s,b)}recoverPublicKey(b){let A=o.ORDER,{r:L,s:I,recovery:v}=this;if(v==null||![0,1,2,3].includes(v))throw new Error("recovery id invalid");if(a*Ua<A&&v>1)throw new Error("recovery id is ambiguous for h>1 curve");let K=v===2||v===3?L+a:L;if(!o.isValid(K))throw new Error("recovery id 2 or 3 invalid");let D=o.toBytes(K),q=e.fromBytes(gt(Da((v&1)===0),D)),V=i.inv(K),H=k($("msgHash",b)),F=i.create(-H*V),Z=i.create(I*V),Q=e.BASE.multiplyUnsafe(F).add(q.multiplyUnsafe(Z));if(Q.is0())throw new Error("point at infinify");return Q.assertValidity(),Q}hasHighS(){return g(this.s)}toBytes(b=w){if(ho(b),b==="der")return ye(Zt.hexFromSig(this));let A=i.toBytes(this.r),L=i.toBytes(this.s);if(b==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return gt(Uint8Array.of(this.recovery),A,L)}return gt(A,L)}toHex(b){return At(this.toBytes(b))}assertValidity(){}static fromCompact(b){return E.fromBytes($("sig",b),"compact")}static fromDER(b){return E.fromBytes($("sig",b),"der")}normalizeS(){return this.hasHighS()?new E(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return At(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return At(this.toBytes("compact"))}}let R=r.bits2int||function(b){if(b.length>8192)throw new Error("input is too large");let A=qe(b),L=b.length*8-c;return L>0?A>>BigInt(L):A},k=r.bits2int_modN||function(b){return i.create(R(b))},O=ce(c);function M(y){return ae("num < 2^"+c,y,Wt,O),i.toBytes(y)}function P(y,b){return Et(y,void 0,"message"),b?Et(t(y),void 0,"prehashed message"):y}function S(y,b,A){if(["recovered","canonical"].some(F=>F in A))throw new Error("sign() legacy options not supported");let{lowS:L,prehash:I,extraEntropy:v}=uo(A,p);y=P(y,I);let _=k(y),K=Xe(i,b),D=[M(K),M(_)];if(v!=null&&v!==!1){let F=v===!0?n(d.secretKey):v;D.push($("extraEntropy",F))}let q=gt(...D),V=_;function H(F){let Z=R(F);if(!i.isValidNot0(Z))return;let Q=i.inv(Z),z=e.BASE.multiply(Z).toAffine(),st=i.create(z.x);if(st===Wt)return;let Ie=i.create(Q*i.create(V+st*K));if(Ie===Wt)return;let ir=(z.x===st?0:2)|Number(z.y&Je),ar=Ie;return L&&g(Ie)&&(ar=i.neg(Ie),ir^=1),new E(st,ar,ir)}return{seed:q,k2sig:H}}function T(y,b,A={}){y=$("message",y);let{seed:L,k2sig:I}=S(y,b,A);return Hi(t.outputLen,i.BYTES,s)(L,I)}function U(y){let b,A=typeof y=="string"||Mt(y),L=!A&&y!==null&&typeof y=="object"&&typeof y.r=="bigint"&&typeof y.s=="bigint";if(!A&&!L)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(L)b=new E(y.r,y.s);else if(A){try{b=E.fromBytes($("sig",y),"der")}catch(I){if(!(I instanceof Zt.Err))throw I}if(!b)try{b=E.fromBytes($("sig",y),"compact")}catch{return!1}}return b||!1}function C(y,b,A,L={}){let{lowS:I,prehash:v,format:_}=uo(L,p);if(A=$("publicKey",A),b=P($("message",b),v),"strict"in L)throw new Error("options.strict was renamed to lowS");let K=_===void 0?U(y):E.fromBytes($("sig",y),_);if(K===!1)return!1;try{let D=e.fromBytes(A);if(I&&K.hasHighS())return!1;let{r:q,s:V}=K,H=k(b),F=i.inv(V),Z=i.create(H*F),Q=i.create(q*F),z=e.BASE.multiplyUnsafe(Z).add(D.multiplyUnsafe(Q));return z.is0()?!1:i.create(z.x)===q}catch{return!1}}function m(y,b,A={}){let{prehash:L}=uo(A,p);return b=P(b,L),E.fromBytes(y,"recovered").recoverPublicKey(b).toBytes()}return Object.freeze({keygen:u,getPublicKey:f,getSharedSecret:h,utils:l,lengths:d,Point:e,sign:T,verify:C,recoverPublicKey:m,Signature:E,hash:t})}function nh(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,s=St(t.n,{BITS:e.nBitLength,allowedLengths:n,modFromBytes:e.wrapPrivateKey}),o={Fp:r,Fn:s,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:o}}function sh(e){let{CURVE:t,curveOpts:r}=nh(e),n={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,hash:e.hash,ecdsaOpts:n}}function oh(e,t){let r=t.Point;return Object.assign({},t,{ProjectivePoint:r,CURVE:Object.assign({},e,tn(r.Fn.ORDER,r.Fn.BITS))})}function Na(e){let{CURVE:t,curveOpts:r,hash:n,ecdsaOpts:s}=sh(e),o=th(t,r),i=rh(o,n,s);return oh(e,i)}function ka(e,t){let r=n=>Na({...e,hash:n});return{...r(t),create:r}}var mo={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},ih={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Ma=BigInt(2);function ah(e){let t=mo.p,r=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,f=u*u*e%t,h=J(f,r,t)*f%t,l=J(h,r,t)*f%t,d=J(l,Ma,t)*u%t,p=J(d,s,t)*d%t,w=J(p,o,t)*p%t,g=J(w,a,t)*w%t,x=J(g,c,t)*g%t,B=J(x,a,t)*w%t,E=J(B,r,t)*f%t,R=J(E,i,t)*p%t,k=J(R,n,t)*u%t,O=J(k,Ma,t);if(!po.eql(po.sqr(O),e))throw new Error("Cannot find square root");return O}var po=St(mo.p,{sqrt:ah}),Qe=ka({...mo,Fp:po,lowS:!0,endo:ih},ie);function Oa(e,t,r,n){let s=jr.digest(r instanceof Uint8Array?r:r.subarray());if(an(s))return s.then(({digest:o})=>(n?.signal?.throwIfAborted(),Qe.verify(t,o,e))).catch(o=>{throw o.name==="AbortError"?o:new Br(String(o))});try{return n?.signal?.throwIfAborted(),Qe.verify(t,s.digest,e)}catch(o){throw new Br(String(o))}}var yn=class{type="secp256k1";raw;_key;constructor(t){this._key=qa(t),this.raw=Ha(this._key)}toMultihash(){return Rt.digest(te(this))}toCID(){return ht.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:yt(this.raw,t.raw)}verify(t,r,n){return Oa(this._key,r,t,n)}};function Va(e){return new yn(e)}function Ha(e){return Qe.ProjectivePoint.fromHex(e).toRawBytes(!0)}function qa(e){try{return Qe.ProjectivePoint.fromHex(e),e}catch(t){throw new Te(String(t))}}function Kr(e,t){let{Type:r,Data:n}=$t.decode(e),s=n??new Uint8Array;switch(r){case at.RSA:return ao(s,t);case at.Ed25519:return da(s);case at.secp256k1:return Va(s);case at.ECDSA:return xi(s);default:throw new Ce}}function te(e){return $t.encode({Type:at[e.type],Data:e.raw})}var Fa=Symbol.for("nodejs.util.inspect.custom"),ch=114,Rr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Nn]=!0;toString(){return this.string==null&&(this.string=rt.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ht.createV1(ch,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return yt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return yt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Fa](){return`PeerId(${this.toString()})`}},gn=class extends Rr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},bn=class extends Rr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},xn=class extends Rr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},fh=2336,yo=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Rt.digest(Y(this.url))}[Fa](){return`PeerId(${this.url})`}[Nn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ht.createV1(fh,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=j(t)),t.toString()===this.toString())}};function go(e){if(e.type==="Ed25519")return new bn({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new xn({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new gn({multihash:e.toCID().multihash,publicKey:e});throw new Ce}function wn(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var En=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},tr=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new En(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let r=this.head;this.head=r.next=new En(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var bo=class extends Error{type;code;constructor(t,r){super(t??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Sn(e={}){return uh(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},e)}function uh(e,t){t=t??{};let r=t.onEnd,n=new tr,s,o,i,a=wn(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((g,x)=>{o=B=>{o=null,n.push(B);try{g(e(n))}catch(E){x(E)}return s}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=wn()})}},u=g=>o!=null?o(g):(n.push(g),s),f=g=>(n=new tr,o!=null?o({error:g}):(n.push({error:g}),s)),h=g=>{if(i)return s;if(t?.objectMode!==!0&&g?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:g})},l=g=>i?s:(i=!0,g!=null?f(g):u({done:!0})),d=()=>(n=new tr,l(),{done:!0}),p=g=>(l(g),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:d,throw:p,push:h,end:l,get readableLength(){return n.size},onEmpty:async g=>{let x=g?.signal;if(x?.throwIfAborted(),n.isEmpty())return;let B,E;x!=null&&(B=new Promise((R,k)=>{E=()=>{k(new bo)},x.addEventListener("abort",E)}));try{await Promise.race([a.promise,B])}finally{E!=null&&x!=null&&x?.removeEventListener("abort",E)}}},r==null)return s;let w=s;return s={[Symbol.asyncIterator](){return this},next(){return w.next()},throw(g){return w.throw(g),r!=null&&(r(g),r=void 0),{done:!0}},return(){return w.return(),r!=null&&(r(),r=void 0),{done:!0}},push:h,end(g){return w.end(g),r!=null&&(r(g),r=void 0),s},get readableLength(){return w.readableLength},onEmpty:g=>w.onEmpty(g)},s}var xo=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},wo=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},za=e=>globalThis.DOMException===void 0?new wo(e):new DOMException(e),Ga=e=>{let t=e.reason===void 0?za("This operation was aborted."):e.reason;return t instanceof Error?t:za(t)};function Eo(e,t){let{milliseconds:r,fallback:n,message:s,customTimers:o={setTimeout,clearTimeout}}=t,i,a,u=new Promise((f,h)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(t.signal){let{signal:d}=t;d.aborted&&h(Ga(d)),a=()=>{h(Ga(d))},d.addEventListener("abort",a,{once:!0})}if(r===Number.POSITIVE_INFINITY){e.then(f,h);return}let l=new xo;i=o.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(d){h(d)}return}typeof e.cancel=="function"&&e.cancel(),s===!1?f():s instanceof Error?h(s):(l.message=s??`Promise timed out after ${r} milliseconds`,h(l))},r),(async()=>{try{f(await e)}catch(d){h(d)}})()}).finally(()=>{u.clear(),a&&t.signal&&t.signal.removeEventListener("abort",a)});return u.clear=()=>{o.clearTimeout.call(void 0,i),i=void 0},u}var hh=e=>{let t=e.addEventListener||e.on||e.addListener,r=e.removeEventListener||e.off||e.removeListener;if(!t||!r)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(e),removeListener:r.bind(e)}};function lh(e,t,r){let n,s=new Promise((o,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:u,removeListener:f}=hh(e),h=(...d)=>{let p=r.multiArgs?d:d[0];r.filter&&!r.filter(p)||(c.push(p),r.count===c.length&&(n(),o(c)))},l=d=>{n(),i(d)};n=()=>{for(let d of a)f(d,h);for(let d of r.rejectionEvents)f(d,l)};for(let d of a)u(d,h);for(let d of r.rejectionEvents)u(d,l);r.signal&&r.signal.addEventListener("abort",()=>{l(r.signal.reason)},{once:!0}),r.resolveImmediately&&o(c)});if(s.cancel=n,typeof r.timeout=="number"){let o=Eo(s,{milliseconds:r.timeout});return o.cancel=n,o}return s}function ja(e,t,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=lh(e,t,r),s=n.then(o=>o[0]);return s.cancel=n.cancel,s}var Le=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function dh(e){return e.reason}async function $a(e,t,r){if(t==null)return e;let n=r?.translateError??dh;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let s;try{return await Promise.race([e,new Promise((o,i)=>{s=()=>{i(n(t))},t.addEventListener("abort",s)})])}finally{s!=null&&t.removeEventListener("abort",s)}}var ph=Math.pow(2,20)*4,vn=class extends Fr{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;constructor(t){super(),this.status="open",this.log=t.log,this.direction=t.direction??"outbound",this.inactivityTimeout=t.inactivityTimeout??12e4,this.maxReadBufferLength=t.maxReadBufferLength??ph,this.maxWriteBufferLength=t.maxWriteBufferLength,this.maxMessageSize=t.maxMessageSize,this.readBuffer=new G,this.writeBuffer=new G,this.readStatus="readable",this.remoteReadStatus="readable",this.writeStatus="writable",this.remoteWriteStatus="writable",this.sendingData=!1,this.writableNeedsDrain=!1,this.timeline={open:Date.now()},this.processSendQueue=this.processSendQueue.bind(this);let r=()=>{this.writableNeedsDrain&&(this.log.trace("drain event received, continue sending data"),this.writableNeedsDrain=!1,this.processSendQueue())};this.addEventListener("drain",r)}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let t=Sn(),r=o=>{t.push(o.data)};this.addEventListener("message",r);let n=o=>{t.end(o.error)};this.addEventListener("close",n);let s=()=>{t.end()};this.addEventListener("remoteCloseWrite",s);try{yield*t}finally{this.removeEventListener("message",r),this.removeEventListener("close",n),this.removeEventListener("remoteCloseWrite",s)}}isReadable(){return this.status==="open"}send(t){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new he(`Cannot write to a stream that is ${this.writeStatus}`);return this.log.trace("append %d bytes to write buffer",t.byteLength),this.writeBuffer.append(t),this.processSendQueue()}abort(t){if(!(this.status==="aborted"||this.status==="reset"||this.status==="closed")){this.log.error("abort with error - %e",t),this.status="aborted",this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle")),this.writeStatus="closed",this.remoteWriteStatus="closed",this.readStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now();try{this.sendReset(t)}catch(r){this.log("failed to send reset to remote - %e",r)}this.dispatchEvent(new qr(t))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new he("Cannot pause a stream that is closing/closed");this.readStatus!=="paused"&&(this.readStatus="paused",this.sendPause())}resume(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new he("Cannot resume a stream that is closing/closed");this.readStatus!=="readable"&&(this.readStatus="readable",this.dispatchReadBuffer(),this.sendResume())}push(t){if(this.readStatus==="closed"||this.readStatus==="closing")throw new he(`Cannot push data onto a stream that is ${this.readStatus}`);if(t.byteLength!==0){if(this.readBuffer.append(t),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}onData(t){if(t.byteLength!==0){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("ignoring data - read status %s",this.readStatus);return}this.readBuffer.append(t),this.dispatchReadBuffer()}}addEventListener(...t){super.addEventListener.apply(this,t),t[0]==="message"&&this.readBuffer.byteLength>0&&queueMicrotask(()=>{this.dispatchReadBuffer()})}onRemoteReset(){this.log("remote reset"),this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed");let t=new Or;this.dispatchEvent(new Vr(t))}onTransportClosed(t){this.log("transport closed"),this.readStatus==="readable"&&this.readBuffer.byteLength===0&&(this.log("close readable end after transport closed and read buffer is empty"),this.readStatus="closed"),this.remoteReadStatus!=="closed"&&(this.remoteReadStatus="closed"),this.remoteWriteStatus!=="closed"&&(this.remoteWriteStatus="closed"),this.writeStatus!=="closed"&&(this.writeStatus="closed"),t!=null?this.abort(t):(this.status==="open"||this.status==="closing")&&(this.timeline.close=Date.now(),this.status="closed",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.dispatchEvent(new Ke))}onRemoteCloseWrite(){this.remoteWriteStatus!=="closed"&&(this.log.trace("on remote close write"),this.remoteWriteStatus="closed",this.safeDispatchEvent("remoteCloseWrite"),this.writeStatus==="closed"&&this.onTransportClosed())}onRemoteCloseRead(){this.log.trace("on remote close read"),this.remoteReadStatus="closed",this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle"))}processSendQueue(){if(this.writableNeedsDrain)return this.log.trace("not processing send queue as drain is required"),this.checkWriteBufferLength(),!1;if(this.writeBuffer.byteLength===0)return this.log.trace("not processing send queue as no bytes to send"),!0;if(this.sendingData)return this.log.trace("not processing send queue as already sending data"),!0;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let t=!0,r=this.writeBuffer.byteLength,n=0;for(;this.writeBuffer.byteLength>0;){let s=Math.min(this.maxMessageSize??this.writeBuffer.byteLength,this.writeBuffer.byteLength);if(s===0){t=!1;break}let o=this.writeBuffer.sublist(0,s),i=new G(o);this.writeBuffer.consume(o.byteLength);let a=this.sendData(o);if(t=a.canSendMore,n+=a.sentBytes,a.sentBytes!==i.byteLength&&(i.consume(a.sentBytes),this.writeBuffer.prepend(i)),!t)break}return t||(this.log.trace("sent %d/%d bytes, pausing sending because underlying stream is full, %d bytes left in the write buffer",n,r,this.writeBuffer.byteLength),this.writableNeedsDrain=!0,this.checkWriteBufferLength()),this.writeBuffer.byteLength===0&&this.safeDispatchEvent("idle"),t}finally{this.sendingData=!1}}dispatchReadBuffer(){try{if(this.listenerCount("message")===0){this.log.trace("not dispatching pause buffer as there are no listeners for the message event");return}if(this.readBuffer.byteLength===0){this.log.trace("not dispatching pause buffer as there is no data to dispatch");return}if(this.readStatus==="paused"){this.log.trace("not dispatching pause buffer we are paused");return}if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("dropping %d bytes because the readable end is %s",this.readBuffer.byteLength,this.readStatus),this.readBuffer.consume(this.readBuffer.byteLength);return}let t=this.readBuffer.sublist();this.readBuffer.consume(t.byteLength),this.dispatchEvent(new Hr(t))}finally{this.readBuffer.byteLength===0&&this.remoteWriteStatus==="closed"&&(this.log("close readable end after dispatching read buffer and remote writable end is closed"),this.readStatus="closed"),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new cr(`Read buffer length of ${this.readBuffer.byteLength} exceeded limit of ${this.maxReadBufferLength}, read status is ${this.readStatus}`))}checkWriteBufferLength(){this.maxWriteBufferLength!=null&&this.writeBuffer.byteLength>this.maxWriteBufferLength&&this.abort(new cr(`Write buffer length of ${this.writeBuffer.byteLength} exceeded limit of ${this.maxWriteBufferLength}, write status is ${this.writeStatus}`))}onMuxerNeedsDrain(){this.writableNeedsDrain=!0}onMuxerDrain(){this.safeDispatchEvent("drain")}};var mh=4194304,An=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Ur=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},vo=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Ao=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function yh(e){return typeof e?.closeRead=="function"}function gh(e){return typeof e?.close=="function"}function So(e){return yh(e)?e.readStatus==="closing"||e.readStatus==="closed":gh(e)?e.status!=="open":!1}function bh(e){return e?.addEventListener!=null&&e?.removeEventListener!=null&&e?.send!=null&&e?.push!=null&&e?.log!=null}function xh(e,t){let r=t?.maxBufferSize??mh,n=new G,s=Promise.withResolvers(),o=!1;if(!bh(e))throw new tt("Argument should be a Stream or a Multiaddr");let i=f=>{if(n.append(f.data),n.byteLength>r){let h=n.byteLength;n.consume(n.byteLength),s.reject(new Error(`Read buffer overflow - ${h} > ${r}`))}s.resolve()};e.addEventListener("message",i);let a=f=>{f.error!=null?s.reject(f.error):s.resolve()};e.addEventListener("close",a);let c=()=>{s.resolve()};e.addEventListener("remoteCloseWrite",c);let u={readBuffer:n,async read(f){if(o===!0)throw new An("Stream was unwrapped");if(So(e)){if(f?.bytes==null)return null;if(n.byteLength<f.bytes)throw e.log.error("closed after reading %d/%d bytes",n.byteLength,f.bytes),new Le(`Unexpected EOF - stream closed after reading ${n.byteLength}/${f.bytes} bytes`)}let h=f?.bytes??1;for(;;){if(n.byteLength>=h){s.resolve();break}if(await $a(s.promise,f?.signal),So(e)){if(n.byteLength===0&&f?.bytes==null)return null;break}s=Promise.withResolvers()}let l=f?.bytes??n.byteLength;if(n.byteLength<l){if(So(e))throw e.log.error("closed while reading %d/%d bytes",n.byteLength,l),new Le(`Unexpected EOF - stream closed while reading ${n.byteLength}/${l} bytes`);return u.read(f)}let d=n.sublist(0,l);return n.consume(l),d},async write(f,h){if(o===!0)throw new An("Stream was unwrapped");e.send(f)||await ja(e,"drain",{signal:h?.signal,rejectionEvents:["close"]})},unwrap(){return o||(o=!0,e.removeEventListener("message",i),e.removeEventListener("close",a),e.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(e.log("stream unwrapped with %d unread bytes",n.byteLength),e.push(n))),e}};return u}function Bo(e,t={}){let r=xh(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=Tt(t.maxDataLength));let n=t?.lengthDecoder??fn,s=t?.lengthEncoder??pa;return{async read(i){let a=-1,c=new G;for(;;){let f=await r.read({...i,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(h){if(h instanceof RangeError)continue;throw h}if(a<0)throw new Ur("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new Ao(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new vo(`Message length too long - ${a} > ${t.maxDataLength}`);let u=await r.read({...i,bytes:a});if(u==null)throw e.log.error("tried to read %d bytes but the stream closed",a),new Le(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw e.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new Le(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await r.write(new G(s(i.byteLength),i),a)},async writeV(i,a){let c=new G(...i.flatMap(u=>[s(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}var wh=1024*1024*4,Eh=1024*1024*4,Bn=class{buffer;maxBufferSize;lengthDecoder;maxDataLength;encodingLength;constructor(t={}){this.buffer=new G,this.maxBufferSize=t.maxBufferSize??wh,this.maxDataLength=t.maxDataLength??Eh,this.lengthDecoder=t.lengthDecoder??fn,this.encodingLength=t.encodingLength??Tt}*decode(t){if(this.buffer.append(t),this.buffer.byteLength>this.maxBufferSize)throw new tt(`Buffer length limit exceeded - ${this.buffer.byteLength}/${this.maxBufferSize}`);for(;;){let r;try{r=this.lengthDecoder(this.buffer)}catch(o){if(o instanceof RangeError)break;throw o}if(r<0||r>this.maxDataLength)throw new Ur("Invalid message length");let n=this.encodingLength(r),s=n+r;if(this.buffer.byteLength>=s){let o=this.buffer.sublist(n,s);this.buffer.consume(s),o.byteLength>0&&(yield o)}else break}}};var er=!!globalThis.process?.env?.DUMP_SESSION_KEYS,Lo=16;function Wa(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Ln(e){if(typeof e!="boolean")throw new Error(`boolean expected, not ${e}`)}function _n(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function mt(e,...t){if(!Wa(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function _o(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Ya(e,t){mt(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Yt(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function Xt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Sh(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}var vh=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Ah(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function In(e){if(typeof e=="string")e=Ah(e);else if(Wa(e))e=Tn(e);else throw new Error("Uint8Array expected, got "+typeof e);return e}function Xa(e,t){if(t==null||typeof t!="object")throw new Error("options must be defined");return Object.assign(e,t)}function Ja(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}var Io=(e,t)=>{function r(n,...s){if(mt(n),!vh)throw new Error("Non little-endian hardware is not yet supported");if(e.nonceLength!==void 0){let f=s[0];if(!f)throw new Error("nonce / iv required");e.varSizeNonce?mt(f):mt(f,e.nonceLength)}let o=e.tagLength;o&&s[1]!==void 0&&mt(s[1]);let i=t(n,...s),a=(f,h)=>{if(h!==void 0){if(f!==2)throw new Error("cipher output not supported");mt(h)}},c=!1;return{encrypt(f,h){if(c)throw new Error("cannot encrypt() twice with same key + nonce");return c=!0,mt(f),a(i.encrypt.length,h),i.encrypt(f,h)},decrypt(f,h){if(mt(f),o&&f.length<o)throw new Error("invalid ciphertext length: smaller than tagLength="+o);return a(i.decrypt.length,h),i.decrypt(f,h)}}}return Object.assign(r,e),r};function To(e,t,r=!0){if(t===void 0)return new Uint8Array(e);if(t.length!==e)throw new Error("invalid output length, expected "+e+", got: "+t.length);if(r&&!Bh(t))throw new Error("invalid output, must be aligned");return t}function Za(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let s=BigInt(32),o=BigInt(4294967295),i=Number(r>>s&o),a=Number(r&o),c=n?4:0,u=n?0:4;e.setUint32(t+c,i,n),e.setUint32(t+u,a,n)}function Qa(e,t,r){Ln(r);let n=new Uint8Array(16),s=Sh(n);return Za(s,0,BigInt(t),r),Za(s,8,BigInt(e),r),n}function Bh(e){return e.byteOffset%4===0}function Tn(e){return Uint8Array.from(e)}var ec=e=>Uint8Array.from(e.split("").map(t=>t.charCodeAt(0))),Lh=ec("expand 16-byte k"),_h=ec("expand 32-byte k"),Ih=Yt(Lh),Th=Yt(_h);function N(e,t){return e<<t|e>>>32-t}function Co(e){return e.byteOffset%4===0}var Cn=64,Ch=16,rc=2**32-1,tc=new Uint32Array;function Kh(e,t,r,n,s,o,i,a){let c=s.length,u=new Uint8Array(Cn),f=Yt(u),h=Co(s)&&Co(o),l=h?Yt(s):tc,d=h?Yt(o):tc;for(let p=0;p<c;i++){if(e(t,r,n,f,i,a),i>=rc)throw new Error("arx: counter overflow");let w=Math.min(Cn,c-p);if(h&&w===Cn){let g=p/4;if(p%4!==0)throw new Error("arx: invalid block position");for(let x=0,B;x<Ch;x++)B=g+x,d[B]=l[B]^f[x];p+=Cn;continue}for(let g=0,x;g<w;g++)x=p+g,o[x]=s[x]^u[g];p+=w}}function Ko(e,t){let{allowShortKeys:r,extendNonceFn:n,counterLength:s,counterRight:o,rounds:i}=Xa({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if(typeof e!="function")throw new Error("core must be a function");return _n(s),_n(i),Ln(o),Ln(r),(a,c,u,f,h=0)=>{mt(a),mt(c),mt(u);let l=u.length;if(f===void 0&&(f=new Uint8Array(l)),mt(f),_n(h),h<0||h>=rc)throw new Error("arx: counter overflow");if(f.length<l)throw new Error(`arx: output (${f.length}) is shorter than data (${l})`);let d=[],p=a.length,w,g;if(p===32)d.push(w=Tn(a)),g=Th;else if(p===16&&r)w=new Uint8Array(32),w.set(a),w.set(a,16),g=Ih,d.push(w);else throw new Error(`arx: invalid 32-byte key, got length=${p}`);Co(c)||d.push(c=Tn(c));let x=Yt(w);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(g,x,Yt(c.subarray(0,16)),x),c=c.subarray(16)}let B=16-s;if(B!==c.length)throw new Error(`arx: nonce must be ${B} or 16 bytes`);if(B!==12){let R=new Uint8Array(12);R.set(c,o?0:12-c.length),c=R,d.push(c)}let E=Yt(c);return Kh(e,g,x,E,u,f,h,i),Xt(...d),f}}var ut=(e,t)=>e[t++]&255|(e[t++]&255)<<8,Ro=class{constructor(t){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,t=In(t),mt(t,32);let r=ut(t,0),n=ut(t,2),s=ut(t,4),o=ut(t,6),i=ut(t,8),a=ut(t,10),c=ut(t,12),u=ut(t,14);this.r[0]=r&8191,this.r[1]=(r>>>13|n<<3)&8191,this.r[2]=(n>>>10|s<<6)&7939,this.r[3]=(s>>>7|o<<9)&8191,this.r[4]=(o>>>4|i<<12)&255,this.r[5]=i>>>1&8190,this.r[6]=(i>>>14|a<<2)&8191,this.r[7]=(a>>>11|c<<5)&8065,this.r[8]=(c>>>8|u<<8)&8191,this.r[9]=u>>>5&127;for(let f=0;f<8;f++)this.pad[f]=ut(t,16+2*f)}process(t,r,n=!1){let s=n?0:2048,{h:o,r:i}=this,a=i[0],c=i[1],u=i[2],f=i[3],h=i[4],l=i[5],d=i[6],p=i[7],w=i[8],g=i[9],x=ut(t,r+0),B=ut(t,r+2),E=ut(t,r+4),R=ut(t,r+6),k=ut(t,r+8),O=ut(t,r+10),M=ut(t,r+12),P=ut(t,r+14),S=o[0]+(x&8191),T=o[1]+((x>>>13|B<<3)&8191),U=o[2]+((B>>>10|E<<6)&8191),C=o[3]+((E>>>7|R<<9)&8191),m=o[4]+((R>>>4|k<<12)&8191),y=o[5]+(k>>>1&8191),b=o[6]+((k>>>14|O<<2)&8191),A=o[7]+((O>>>11|M<<5)&8191),L=o[8]+((M>>>8|P<<8)&8191),I=o[9]+(P>>>5|s),v=0,_=v+S*a+T*(5*g)+U*(5*w)+C*(5*p)+m*(5*d);v=_>>>13,_&=8191,_+=y*(5*l)+b*(5*h)+A*(5*f)+L*(5*u)+I*(5*c),v+=_>>>13,_&=8191;let K=v+S*c+T*a+U*(5*g)+C*(5*w)+m*(5*p);v=K>>>13,K&=8191,K+=y*(5*d)+b*(5*l)+A*(5*h)+L*(5*f)+I*(5*u),v+=K>>>13,K&=8191;let D=v+S*u+T*c+U*a+C*(5*g)+m*(5*w);v=D>>>13,D&=8191,D+=y*(5*p)+b*(5*d)+A*(5*l)+L*(5*h)+I*(5*f),v+=D>>>13,D&=8191;let q=v+S*f+T*u+U*c+C*a+m*(5*g);v=q>>>13,q&=8191,q+=y*(5*w)+b*(5*p)+A*(5*d)+L*(5*l)+I*(5*h),v+=q>>>13,q&=8191;let V=v+S*h+T*f+U*u+C*c+m*a;v=V>>>13,V&=8191,V+=y*(5*g)+b*(5*w)+A*(5*p)+L*(5*d)+I*(5*l),v+=V>>>13,V&=8191;let H=v+S*l+T*h+U*f+C*u+m*c;v=H>>>13,H&=8191,H+=y*a+b*(5*g)+A*(5*w)+L*(5*p)+I*(5*d),v+=H>>>13,H&=8191;let F=v+S*d+T*l+U*h+C*f+m*u;v=F>>>13,F&=8191,F+=y*c+b*a+A*(5*g)+L*(5*w)+I*(5*p),v+=F>>>13,F&=8191;let Z=v+S*p+T*d+U*l+C*h+m*f;v=Z>>>13,Z&=8191,Z+=y*u+b*c+A*a+L*(5*g)+I*(5*w),v+=Z>>>13,Z&=8191;let Q=v+S*w+T*p+U*d+C*l+m*h;v=Q>>>13,Q&=8191,Q+=y*f+b*u+A*c+L*a+I*(5*g),v+=Q>>>13,Q&=8191;let z=v+S*g+T*w+U*p+C*d+m*l;v=z>>>13,z&=8191,z+=y*h+b*f+A*u+L*c+I*a,v+=z>>>13,z&=8191,v=(v<<2)+v|0,v=v+_|0,_=v&8191,v=v>>>13,K+=v,o[0]=_,o[1]=K,o[2]=D,o[3]=q,o[4]=V,o[5]=H,o[6]=F,o[7]=Z,o[8]=Q,o[9]=z}finalize(){let{h:t,pad:r}=this,n=new Uint16Array(10),s=t[1]>>>13;t[1]&=8191;for(let a=2;a<10;a++)t[a]+=s,s=t[a]>>>13,t[a]&=8191;t[0]+=s*5,s=t[0]>>>13,t[0]&=8191,t[1]+=s,s=t[1]>>>13,t[1]&=8191,t[2]+=s,n[0]=t[0]+5,s=n[0]>>>13,n[0]&=8191;for(let a=1;a<10;a++)n[a]=t[a]+s,s=n[a]>>>13,n[a]&=8191;n[9]-=8192;let o=(s^1)-1;for(let a=0;a<10;a++)n[a]&=o;o=~o;for(let a=0;a<10;a++)t[a]=t[a]&o|n[a];t[0]=(t[0]|t[1]<<13)&65535,t[1]=(t[1]>>>3|t[2]<<10)&65535,t[2]=(t[2]>>>6|t[3]<<7)&65535,t[3]=(t[3]>>>9|t[4]<<4)&65535,t[4]=(t[4]>>>12|t[5]<<1|t[6]<<14)&65535,t[5]=(t[6]>>>2|t[7]<<11)&65535,t[6]=(t[7]>>>5|t[8]<<8)&65535,t[7]=(t[8]>>>8|t[9]<<5)&65535;let i=t[0]+r[0];t[0]=i&65535;for(let a=1;a<8;a++)i=(t[a]+r[a]|0)+(i>>>16)|0,t[a]=i&65535;Xt(n)}update(t){_o(this),t=In(t),mt(t);let{buffer:r,blockLen:n}=this,s=t.length;for(let o=0;o<s;){let i=Math.min(n-this.pos,s-o);if(i===n){for(;n<=s-o;o+=n)this.process(t,o);continue}r.set(t.subarray(o,o+i),this.pos),this.pos+=i,o+=i,this.pos===n&&(this.process(r,0,!1),this.pos=0)}return this}destroy(){Xt(this.h,this.r,this.buffer,this.pad)}digestInto(t){_o(this),Ya(t,this),this.finished=!0;let{buffer:r,h:n}=this,{pos:s}=this;if(s){for(r[s++]=1;s<16;s++)r[s]=0;this.process(r,0,!0)}this.finalize();let o=0;for(let i=0;i<8;i++)t[o++]=n[i]>>>0,t[o++]=n[i]>>>8;return t}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}};function Rh(e){let t=(n,s)=>e(s).update(In(n)).digest(),r=e(new Uint8Array(32));return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=n=>e(n),t}var nc=Rh(e=>new Ro(e));function ic(e,t,r,n,s,o=20){let i=e[0],a=e[1],c=e[2],u=e[3],f=t[0],h=t[1],l=t[2],d=t[3],p=t[4],w=t[5],g=t[6],x=t[7],B=s,E=r[0],R=r[1],k=r[2],O=i,M=a,P=c,S=u,T=f,U=h,C=l,m=d,y=p,b=w,A=g,L=x,I=B,v=E,_=R,K=k;for(let q=0;q<o;q+=2)O=O+T|0,I=N(I^O,16),y=y+I|0,T=N(T^y,12),O=O+T|0,I=N(I^O,8),y=y+I|0,T=N(T^y,7),M=M+U|0,v=N(v^M,16),b=b+v|0,U=N(U^b,12),M=M+U|0,v=N(v^M,8),b=b+v|0,U=N(U^b,7),P=P+C|0,_=N(_^P,16),A=A+_|0,C=N(C^A,12),P=P+C|0,_=N(_^P,8),A=A+_|0,C=N(C^A,7),S=S+m|0,K=N(K^S,16),L=L+K|0,m=N(m^L,12),S=S+m|0,K=N(K^S,8),L=L+K|0,m=N(m^L,7),O=O+U|0,K=N(K^O,16),A=A+K|0,U=N(U^A,12),O=O+U|0,K=N(K^O,8),A=A+K|0,U=N(U^A,7),M=M+C|0,I=N(I^M,16),L=L+I|0,C=N(C^L,12),M=M+C|0,I=N(I^M,8),L=L+I|0,C=N(C^L,7),P=P+m|0,v=N(v^P,16),y=y+v|0,m=N(m^y,12),P=P+m|0,v=N(v^P,8),y=y+v|0,m=N(m^y,7),S=S+T|0,_=N(_^S,16),b=b+_|0,T=N(T^b,12),S=S+T|0,_=N(_^S,8),b=b+_|0,T=N(T^b,7);let D=0;n[D++]=i+O|0,n[D++]=a+M|0,n[D++]=c+P|0,n[D++]=u+S|0,n[D++]=f+T|0,n[D++]=h+U|0,n[D++]=l+C|0,n[D++]=d+m|0,n[D++]=p+y|0,n[D++]=w+b|0,n[D++]=g+A|0,n[D++]=x+L|0,n[D++]=B+I|0,n[D++]=E+v|0,n[D++]=R+_|0,n[D++]=k+K|0}function Uh(e,t,r,n){let s=e[0],o=e[1],i=e[2],a=e[3],c=t[0],u=t[1],f=t[2],h=t[3],l=t[4],d=t[5],p=t[6],w=t[7],g=r[0],x=r[1],B=r[2],E=r[3];for(let k=0;k<20;k+=2)s=s+c|0,g=N(g^s,16),l=l+g|0,c=N(c^l,12),s=s+c|0,g=N(g^s,8),l=l+g|0,c=N(c^l,7),o=o+u|0,x=N(x^o,16),d=d+x|0,u=N(u^d,12),o=o+u|0,x=N(x^o,8),d=d+x|0,u=N(u^d,7),i=i+f|0,B=N(B^i,16),p=p+B|0,f=N(f^p,12),i=i+f|0,B=N(B^i,8),p=p+B|0,f=N(f^p,7),a=a+h|0,E=N(E^a,16),w=w+E|0,h=N(h^w,12),a=a+h|0,E=N(E^a,8),w=w+E|0,h=N(h^w,7),s=s+u|0,E=N(E^s,16),p=p+E|0,u=N(u^p,12),s=s+u|0,E=N(E^s,8),p=p+E|0,u=N(u^p,7),o=o+f|0,g=N(g^o,16),w=w+g|0,f=N(f^w,12),o=o+f|0,g=N(g^o,8),w=w+g|0,f=N(f^w,7),i=i+h|0,x=N(x^i,16),l=l+x|0,h=N(h^l,12),i=i+h|0,x=N(x^i,8),l=l+x|0,h=N(h^l,7),a=a+c|0,B=N(B^a,16),d=d+B|0,c=N(c^d,12),a=a+c|0,B=N(B^a,8),d=d+B|0,c=N(c^d,7);let R=0;n[R++]=s,n[R++]=o,n[R++]=i,n[R++]=a,n[R++]=g,n[R++]=x,n[R++]=B,n[R++]=E}var Dh=Ko(ic,{counterRight:!1,counterLength:4,allowShortKeys:!1}),Ph=Ko(ic,{counterRight:!1,counterLength:8,extendNonceFn:Uh,allowShortKeys:!1});var Nh=new Uint8Array(16),sc=(e,t)=>{e.update(t);let r=t.length%16;r&&e.update(Nh.subarray(r))},kh=new Uint8Array(32);function oc(e,t,r,n,s){let o=e(t,r,kh),i=nc.create(o);s&&sc(i,s),sc(i,n);let a=Qa(n.length,s?s.length:0,!0);i.update(a);let c=i.digest();return Xt(o,a),c}var ac=e=>(t,r,n)=>({encrypt(o,i){let a=o.length;i=To(a+16,i,!1),i.set(o);let c=i.subarray(0,-16);e(t,r,c,c,1);let u=oc(e,t,r,c,n);return i.set(u,a),Xt(u),i},decrypt(o,i){i=To(o.length-16,i,!1);let a=o.subarray(0,-16),c=o.subarray(-16),u=oc(e,t,r,a,n);if(!Ja(c,u))throw new Error("invalid tag");return i.set(o.subarray(0,-16)),e(t,r,i,i,1),Xt(u),i}}),Uo=Io({blockSize:64,nonceLength:12,tagLength:16},ac(Dh)),lg=Io({blockSize:64,nonceLength:24,tagLength:16},ac(Ph));function fc(e,t,r){return me(e),r===void 0&&(r=new Uint8Array(e.outputLen)),Ye(e,ee(r),ee(t))}var Do=Uint8Array.from([0]),cc=Uint8Array.of();function uc(e,t,r,n=32){me(e),pe(n);let s=e.outputLen;if(n>255*s)throw new Error("Length should be <= 255*HashLen");let o=Math.ceil(n/s);r===void 0&&(r=cc);let i=new Uint8Array(o*s),a=Ye.create(e,t),c=a._cloneInto(),u=new Uint8Array(a.outputLen);for(let f=0;f<o;f++)Do[0]=f+1,c.update(f===0?cc:u).update(r).update(Do).digestInto(u),i.set(u,s*f),a._cloneInto(c);return a.destroy(),c.destroy(),_t(u,Do),i.slice(0,n)}var Kn={hashSHA256(e){return ie(e.subarray())},getHKDF(e,t){let r=fc(ie,t,e),s=uc(ie,r,void 0,96),o=s.subarray(0,32),i=s.subarray(32,64),a=s.subarray(64,96);return[o,i,a]},generateX25519KeyPair(){let e=Ar.utils.randomSecretKey();return{publicKey:Ar.getPublicKey(e),privateKey:e}},generateX25519KeyPairFromSeed(e){return{publicKey:Ar.getPublicKey(e),privateKey:e}},generateX25519SharedKey(e,t){return Ar.getSharedSecret(e.subarray(),t.subarray())},chaCha20Poly1305Encrypt(e,t,r,n){return Uo(n,t,r).encrypt(e.subarray())},chaCha20Poly1305Decrypt(e,t,r,n,s){return Uo(n,t,r).decrypt(e.subarray(),s)}};var hc=Kn;function lc(e){return{generateKeypair:e.generateX25519KeyPair,dh:(t,r)=>e.generateX25519SharedKey(t.privateKey,r).subarray(0,32),encrypt:e.chaCha20Poly1305Encrypt,decrypt:e.chaCha20Poly1305Decrypt,hash:e.hashSHA256,hkdf:e.getHKDF}}var rr=e=>{let t=ct(2);return t[0]=e>>8,t[1]=e,t};rr.bytes=2;var nr=e=>{if(e.length<2)throw RangeError("Could not decode int16BE");if(e instanceof Uint8Array){let t=0;return t+=e[0]<<8,t+=e[1],t}return e.getUint16(0)};nr.bytes=2;function dc(e){return{xxHandshakeSuccesses:e.registerCounter("libp2p_noise_xxhandshake_successes_total",{help:"Total count of noise xxHandshakes successes_"}),xxHandshakeErrors:e.registerCounter("libp2p_noise_xxhandshake_error_total",{help:"Total count of noise xxHandshakes errors"}),encryptedPackets:e.registerCounter("libp2p_noise_encrypted_packets_total",{help:"Total count of noise encrypted packets successfully"}),decryptedPackets:e.registerCounter("libp2p_noise_decrypted_packets_total",{help:"Total count of noise decrypted packets"}),decryptErrors:e.registerCounter("libp2p_noise_decrypt_errors_total",{help:"Total count of noise decrypt errors"})}}function Po(e,t){!t.enabled||!er||(e?(t(`LOCAL_STATIC_PUBLIC_KEY ${j(e.publicKey,"hex")}`),t(`LOCAL_STATIC_PRIVATE_KEY ${j(e.privateKey,"hex")}`)):t("Missing local static keys."))}function No(e,t){!t.enabled||!er||(e?(t(`LOCAL_PUBLIC_EPHEMERAL_KEY ${j(e.publicKey,"hex")}`),t(`LOCAL_PRIVATE_EPHEMERAL_KEY ${j(e.privateKey,"hex")}`)):t("Missing local ephemeral keys."))}function pc(e,t){!t.enabled||!er||t(e?`REMOTE_STATIC_PUBLIC_KEY ${j(e.subarray(),"hex")}`:"Missing remote static public key.")}function ko(e,t){!t.enabled||!er||t(e?`REMOTE_EPHEMERAL_PUBLIC_KEY ${j(e.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function Mo(e,t,r){!r.enabled||!er||(r(`CIPHER_STATE_1 ${e.n.getUint64()} ${e.k&&j(e.k,"hex")}`),r(`CIPHER_STATE_2 ${t.n.getUint64()} ${t.k&&j(t.k,"hex")}`))}var sr=class e extends Error{code;constructor(t="Invalid crypto exchange"){super(t),this.code=e.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var Mh=0,Oh=4294967295,Hh="Cipher state has reached maximum n, a new handshake must be performed",Rn=class{n;bytes;view;constructor(t=Mh){this.n=t,this.bytes=nt(12),this.view=new DataView(this.bytes.buffer,this.bytes.byteOffset,this.bytes.byteLength),this.view.setUint32(4,t,!0)}increment(){this.n++,this.view.setUint32(4,this.n,!0)}getBytes(){return this.bytes}getUint64(){return this.n}assertValue(){if(this.n>Oh)throw new Error(Hh)}};var _e=nt(0),or=class{k;n;crypto;constructor(t,r=void 0,n=0){this.crypto=t,this.k=r,this.n=new Rn(n)}hasKey(){return!!this.k}encryptWithAd(t,r){if(!this.hasKey())return r;this.n.assertValue();let n=this.crypto.encrypt(r,this.n.getBytes(),t,this.k);return this.n.increment(),n}decryptWithAd(t,r,n){if(!this.hasKey())return r;this.n.assertValue();let s=this.crypto.decrypt(r,this.n.getBytes(),t,this.k,n);return this.n.increment(),s}},Oo=class{cs;ck;h;crypto;constructor(t,r){this.crypto=t;let n=Y(r,"utf-8");this.h=qh(t,n),this.ck=this.h,this.cs=new or(t)}mixKey(t){let[r,n]=this.crypto.hkdf(this.ck,t);this.ck=r,this.cs=new or(this.crypto,n)}mixHash(t){this.h=this.crypto.hash(new G(this.h,t))}encryptAndHash(t){let r=this.cs.encryptWithAd(this.h,t);return this.mixHash(r),r}decryptAndHash(t){let r=this.cs.decryptWithAd(this.h,t);return this.mixHash(t),r}split(){let[t,r]=this.crypto.hkdf(this.ck,_e);return[new or(this.crypto,t),new or(this.crypto,r)]}},Ho=class{ss;s;e;rs;re;initiator;crypto;constructor(t){let{crypto:r,protocolName:n,prologue:s,initiator:o,s:i,e:a,rs:c,re:u}=t;this.crypto=r,this.ss=new Oo(r,n),this.ss.mixHash(s),this.initiator=o,this.s=i,this.e=a,this.rs=c,this.re=u}writeE(){if(this.e)throw new Error("ephemeral keypair is already set");let t=this.crypto.generateKeypair();return this.ss.mixHash(t.publicKey),this.e=t,t.publicKey}writeS(){if(!this.s)throw new Error("static keypair is not set");return this.ss.encryptAndHash(this.s.publicKey)}writeEE(){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.re))}writeES(){if(this.initiator){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}else{if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}}writeSE(){if(this.initiator){if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}else{if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}}readE(t,r=0){if(this.re)throw new Error("remote ephemeral public key is already set");if(t.byteLength<r+32)throw new Error("message is not long enough");this.re=t.sublist(r,r+32),this.ss.mixHash(this.re)}readS(t,r=0){if(this.rs)throw new Error("remote static public key is already set");let n=32+(this.ss.cs.hasKey()?16:0);if(t.byteLength<r+n)throw new Error("message is not long enough");let s=t.sublist(r,r+n);return this.rs=this.ss.decryptAndHash(s),n}readEE(){this.writeEE()}readES(){this.writeES()}readSE(){this.writeSE()}},Dr=class extends Ho{writeMessageA(t){return new G(this.writeE(),this.ss.encryptAndHash(t))}writeMessageB(t){let r=this.writeE();this.writeEE();let n=this.writeS();return this.writeES(),new G(r,n,this.ss.encryptAndHash(t))}writeMessageC(t){let r=this.writeS();return this.writeSE(),new G(r,this.ss.encryptAndHash(t))}readMessageA(t){try{return this.readE(t),this.ss.decryptAndHash(t.sublist(32))}catch(r){throw new sr(`handshake stage 0 validation fail: ${r.message}`)}}readMessageB(t){try{this.readE(t),this.readEE();let r=this.readS(t,32);return this.readES(),this.ss.decryptAndHash(t.sublist(32+r))}catch(r){throw new sr(`handshake stage 1 validation fail: ${r.message}`)}}readMessageC(t){try{let r=this.readS(t);return this.readSE(),this.ss.decryptAndHash(t.sublist(r))}catch(r){throw new sr(`handshake stage 2 validation fail: ${r.message}`)}}};function qh(e,t){if(t.length<=32){let r=nt(32);return r.set(t),r}else return e.hash(t)}var Un;(function(e){let t;e.codec=()=>(t==null&&(t=Be((r,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),r.webtransportCerthashes!=null)for(let o of r.webtransportCerthashes)n.uint32(10),n.bytes(o);if(r.streamMuxers!=null)for(let o of r.streamMuxers)n.uint32(18),n.string(o);s.lengthDelimited!==!1&&n.ldelim()},(r,n,s={})=>{let o={webtransportCerthashes:[],streamMuxers:[]},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{if(s.limits?.webtransportCerthashes!=null&&o.webtransportCerthashes.length===s.limits.webtransportCerthashes)throw new Ir('Decode error - map field "webtransportCerthashes" had too many elements');o.webtransportCerthashes.push(r.bytes());break}case 2:{if(s.limits?.streamMuxers!=null&&o.streamMuxers.length===s.limits.streamMuxers)throw new Ir('Decode error - map field "streamMuxers" had too many elements');o.streamMuxers.push(r.string());break}default:{r.skipType(a&7);break}}}return o})),t),e.encode=r=>Ae(r,e.codec()),e.decode=(r,n)=>Se(r,e.codec(),n)})(Un||(Un={}));var Pr;(function(e){let t;e.codec=()=>(t==null&&(t=Be((r,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),r.identityKey!=null&&r.identityKey.byteLength>0&&(n.uint32(10),n.bytes(r.identityKey)),r.identitySig!=null&&r.identitySig.byteLength>0&&(n.uint32(18),n.bytes(r.identitySig)),r.extensions!=null&&(n.uint32(34),Un.codec().encode(r.extensions,n)),s.lengthDelimited!==!1&&n.ldelim()},(r,n,s={})=>{let o={identityKey:nt(0),identitySig:nt(0)},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{o.identityKey=r.bytes();break}case 2:{o.identitySig=r.bytes();break}case 4:{o.extensions=Un.codec().decode(r,r.uint32(),{limits:s.limits?.extensions});break}default:{r.skipType(a&7);break}}}return o})),t),e.encode=r=>Ae(r,e.codec()),e.decode=(r,n)=>Se(r,e.codec(),n)})(Pr||(Pr={}));async function Vo(e,t,r){let n=await e.sign(yc(t));return Pr.encode({identityKey:te(e.publicKey),identitySig:n,extensions:r})}async function Fo(e,t,r){try{let n=Pr.decode(e),s=Kr(n.identityKey);if(r?.equals(s)===!1)throw new Error(`Payload identity key ${s} does not match expected remote identity key ${r}`);if(!t)throw new Error("Remote static does not exist");let o=yc(t);if(!await s.verify(o,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new kr(n.message)}}function yc(e){let t=Y("noise-libp2p-static-key:");return e instanceof Uint8Array?le([t,e],t.length+e.length):(e.prepend(t),e)}var qo=class extends vn{stream;handshake;metrics;decoder;constructor(t,r,n){super({log:t.log,inactivityTimeout:t.inactivityTimeout,maxReadBufferLength:t.maxReadBufferLength,direction:t.direction}),this.stream=t,this.handshake=r,this.metrics=n,this.decoder=new Bn({lengthDecoder:nr,maxBufferSize:16*1024*1024,encodingLength:()=>2});let s=c=>{try{for(let u of this.decoder.decode(c.data))this.onData(this.decrypt(u))}catch(u){this.abort(u)}};this.stream.addEventListener("message",s);let o=c=>{c.error!=null?c.local===!0?this.abort(c.error):this.onRemoteReset():this.onTransportClosed()};this.stream.addEventListener("close",o);let i=()=>{this.safeDispatchEvent("drain")};this.stream.addEventListener("drain",i);let a=()=>{this.onRemoteCloseWrite()};this.stream.addEventListener("remoteCloseWrite",a)}encrypt(t){let r=new G;for(let n=0;n<t.byteLength;n+=65519){let s=n+65519;s>t.byteLength&&(s=t.byteLength);let o;t instanceof Uint8Array?o=this.handshake.encrypt(t.subarray(n,s)):o=this.handshake.encrypt(t.sublist(n,s)),this.metrics?.encryptedPackets.increment(),r.append(rr(o.byteLength)),r.append(o)}return r}decrypt(t){let r=new G;for(let n=0;n<t.byteLength;n+=65535){let s=n+65535;if(s>t.byteLength&&(s=t.byteLength),s-Lo<n)throw new Error("Invalid chunk");let o;t instanceof Uint8Array?o=t.subarray(n,s):o=t.sublist(n,s);let i=t.subarray(n,s-Lo);try{let a=this.handshake.decrypt(o,i);this.metrics?.decryptedPackets.increment(),r.append(a)}catch(a){throw this.metrics?.decryptErrors.increment(),a}}return r}close(t){return this.stream.close(t)}sendPause(){this.stream.pause()}sendResume(){this.stream.resume()}sendReset(t){this.stream.abort(t)}sendData(t){return{sentBytes:t.byteLength,canSendMore:this.stream.send(this.encrypt(t))}}};function zo(e,t,r){return new qo(e,t,r)}async function gc(e,t){let{log:r,connection:n,crypto:s,privateKey:o,prologue:i,s:a,remoteIdentityKey:c,extensions:u}=e,f=await Vo(o,a.publicKey,u),h=new Dr({crypto:s,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:i,s:a});Po(h.s,r),r.trace("Stage 0 - Initiator starting to send first message."),await n.write(h.writeMessageA(_e),t),r.trace("Stage 0 - Initiator finished sending first message."),No(h.e,r),r.trace("Stage 1 - Initiator waiting to receive first message from responder...");let l=h.readMessageB(await n.read(t));r.trace("Stage 1 - Initiator received the message."),ko(h.re,r),pc(h.rs,r),r.trace("Initiator going to check remote's signature...");let d=await Fo(l,h.rs,c);r.trace("All good with the signature!"),r.trace("Stage 2 - Initiator sending third handshake message."),await n.write(h.writeMessageC(f),t),r.trace("Stage 2 - Initiator sent message with signed payload.");let[p,w]=h.ss.split();return Mo(p,w,r),{payload:d,encrypt:g=>p.encryptWithAd(_e,g),decrypt:(g,x)=>w.decryptWithAd(_e,g,x)}}async function bc(e,t){let{log:r,connection:n,crypto:s,privateKey:o,prologue:i,s:a,remoteIdentityKey:c,extensions:u}=e,f=await Vo(o,a.publicKey,u),h=new Dr({crypto:s,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:i,s:a});Po(h.s,r),r.trace("Stage 0 - Responder waiting to receive first message."),h.readMessageA(await n.read(t)),r.trace("Stage 0 - Responder received first message."),ko(h.re,r),r.trace("Stage 1 - Responder sending out first message with signed payload and static key."),await n.write(h.writeMessageB(f),t),r.trace("Stage 1 - Responder sent the second handshake message with signed payload."),No(h.e,r),r.trace("Stage 2 - Responder waiting for third handshake message...");let l=h.readMessageC(await n.read(t));r.trace("Stage 2 - Responder received the message, finished handshake.");let d=await Fo(l,h.rs,c),[p,w]=h.ss.split();return Mo(p,w,r),{payload:d,encrypt:g=>w.encryptWithAd(_e,g),decrypt:(g,x)=>p.decryptWithAd(_e,g,x)}}var Dn=class{protocol="/noise";crypto;prologue;staticKey;extensions;metrics;components;log;constructor(t,r={}){let{staticNoiseKey:n,extensions:s,crypto:o,prologueBytes:i}=r,{metrics:a}=t;this.components=t,this.log=t.logger.forComponent("libp2p:noise");let c=o??hc;this.crypto=lc(c),this.extensions={webtransportCerthashes:[],...s},this.metrics=a?dc(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=i??nt(0)}[Symbol.toStringTag]="@libp2p/noise";[$o]=["@libp2p/connection-encryption","@libp2p/noise"];async secureOutbound(t,r){let n=t.log?.newScope("noise")??this.log,s=Bo(t,{lengthEncoder:rr,lengthDecoder:nr,maxDataLength:65535}),o=await this.performHandshakeInitiator(s,this.components.privateKey,n,r?.remotePeer?.publicKey,r),i=Kr(o.payload.identityKey);return{connection:zo(s.unwrap(),o,this.metrics),remoteExtensions:o.payload.extensions,remotePeer:go(i),streamMuxer:r?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(o.payload.extensions?.streamMuxers)}}getStreamMuxer(t){if(t==null||t.length===0)return;let r=this.components.upgrader.getStreamMuxers();if(r!=null)for(let n of t){let s=r.get(n);if(s!=null)return s}if(t.length)throw new Mr("Early muxer negotiation was requested but the initiator and responder had no common muxers")}async secureInbound(t,r){let n=t.log?.newScope("noise")??this.log,s=Bo(t,{lengthEncoder:rr,lengthDecoder:nr,maxDataLength:65535}),o=await this.performHandshakeResponder(s,this.components.privateKey,n,r?.remotePeer?.publicKey,r),i=Kr(o.payload.identityKey);return{connection:zo(s.unwrap(),o,this.metrics),remoteExtensions:o.payload.extensions,remotePeer:go(i),streamMuxer:r?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(o.payload.extensions?.streamMuxers)}}async performHandshakeInitiator(t,r,n,s,o){let i,a=o?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{i=await gc({connection:t,privateKey:r,remoteIdentityKey:s,log:n.newScope("xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:{streamMuxers:a,webtransportCerthashes:[],...this.extensions}},o),this.metrics?.xxHandshakeSuccesses.increment()}catch(c){throw this.metrics?.xxHandshakeErrors.increment(),c}return i}async performHandshakeResponder(t,r,n,s,o){let i,a=o?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{i=await bc({connection:t,privateKey:r,remoteIdentityKey:s,log:n.newScope("xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:{streamMuxers:a,webtransportCerthashes:[],...this.extensions}},o),this.metrics?.xxHandshakeSuccesses.increment()}catch(c){throw this.metrics?.xxHandshakeErrors.increment(),c}return i}};function Vh(e={}){return t=>new Dn(t,e)}return vc(Fh);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/hashes/esm/utils.js:
|