@libp2p/webrtc 4.0.22 → 4.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PWebrtc = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PWebrtc=(()=>{var Pp=Object.create;var vs=Object.defineProperty;var Mp=Object.getOwnPropertyDescriptor;var Fp=Object.getOwnPropertyNames;var Vp=Object.getPrototypeOf,Hp=Object.prototype.hasOwnProperty;var te=(r,e)=>()=>(r&&(e=r(r=0)),e);var Ve=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),J=(r,e)=>{for(var t in e)vs(r,t,{get:e[t],enumerable:!0})},Qu=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Fp(e))!Hp.call(r,s)&&s!==t&&vs(r,s,{get:()=>e[s],enumerable:!(n=Mp(e,s))||n.enumerable});return r};var As=(r,e,t)=>(t=r!=null?Pp(Vp(r)):{},Qu(e||!r||!r.__esModule?vs(t,"default",{value:r,enumerable:!0}):t,r)),Ds=r=>Qu(vs({},"__esModule",{value:!0}),r);var mf=Ve((Wv,pf)=>{"use strict";function df(r,e){for(let t in e)Object.defineProperty(r,t,{value:e[t],enumerable:!0,configurable:!0});return r}function Wg(r,e,t){if(!r||typeof r=="string")throw new TypeError("Please pass an Error to err-code");t||(t={}),typeof e=="object"&&(t=e,e=""),e&&(t.code=e);try{return df(r,t)}catch{t.message=r.message,t.stack=r.stack;let s=function(){};return s.prototype=Object.create(Object.getPrototypeOf(r)),df(new s,t)}}pf.exports=Wg});var mh=Ve(fn=>{"use strict";var Ly="[object ArrayBuffer]",Pt=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===Ly}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,t){let n=r.toUint8Array(e),s=r.toUint8Array(t);if(n.length!==s.byteLength)return!1;for(let o=0;o<n.length;o++)if(n[o]!==s[o])return!1;return!0}static concat(...e){let t;Array.isArray(e[0])&&!(e[1]instanceof Function)||Array.isArray(e[0])&&e[1]instanceof Function?t=e[0]:e[e.length-1]instanceof Function?t=e.slice(0,e.length-1):t=e;let n=0;for(let i of t)n+=i.byteLength;let s=new Uint8Array(n),o=0;for(let i of t){let a=this.toUint8Array(i);s.set(a,o),o+=a.length}return e[e.length-1]instanceof Function?this.toView(s,e[e.length-1]):s.buffer}},_c="string",Uy=/^[0-9a-f]+$/i,Oy=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Py=/^[a-zA-Z0-9-_]+$/,So=class{static fromString(e){let t=unescape(encodeURIComponent(e)),n=new Uint8Array(t.length);for(let s=0;s<t.length;s++)n[s]=t.charCodeAt(s);return n.buffer}static toString(e){let t=Pt.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return decodeURIComponent(escape(n))}},Ze=class{static toString(e,t=!1){let n=Pt.toArrayBuffer(e),s=new DataView(n),o="";for(let i=0;i<n.byteLength;i+=2){let a=s.getUint16(i,t);o+=String.fromCharCode(a)}return o}static fromString(e,t=!1){let n=new ArrayBuffer(e.length*2),s=new DataView(n);for(let o=0;o<e.length;o++)s.setUint16(o*2,e.charCodeAt(o),t);return n}},ko=class r{static isHex(e){return typeof e===_c&&Uy.test(e)}static isBase64(e){return typeof e===_c&&Oy.test(e)}static isBase64Url(e){return typeof e===_c&&Py.test(e)}static ToString(e,t="utf8"){let n=Pt.toUint8Array(e);switch(t.toLowerCase()){case"utf8":return this.ToUtf8String(n);case"binary":return this.ToBinary(n);case"hex":return this.ToHex(n);case"base64":return this.ToBase64(n);case"base64url":return this.ToBase64Url(n);case"utf16le":return Ze.toString(n,!0);case"utf16":case"utf16be":return Ze.toString(n);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromString(e,t="utf8"){if(!e)return new ArrayBuffer(0);switch(t.toLowerCase()){case"utf8":return this.FromUtf8String(e);case"binary":return this.FromBinary(e);case"hex":return this.FromHex(e);case"base64":return this.FromBase64(e);case"base64url":return this.FromBase64Url(e);case"utf16le":return Ze.fromString(e,!0);case"utf16":case"utf16be":return Ze.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=Pt.toUint8Array(e);if(typeof btoa<"u"){let n=this.ToString(t,"binary");return btoa(n)}else return Buffer.from(t).toString("base64")}static FromBase64(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64(t))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(t)):new Uint8Array(Buffer.from(t,"base64")).buffer}static FromBase64Url(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64Url(t))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(t.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(e){return this.ToBase64(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.FromBinary(e);case"utf8":return So.fromString(e);case"utf16":case"utf16be":return Ze.fromString(e);case"utf16le":case"usc2":return Ze.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return So.toString(e);case"utf16":case"utf16be":return Ze.toString(e);case"utf16le":case"usc2":return Ze.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){let t=e.length,n=new Uint8Array(t);for(let s=0;s<t;s++)n[s]=e.charCodeAt(s);return n.buffer}static ToBinary(e){let t=Pt.toUint8Array(e),n="";for(let s=0;s<t.length;s++)n+=String.fromCharCode(t[s]);return n}static ToHex(e){let t=Pt.toUint8Array(e),n="",s=t.length;for(let o=0;o<s;o++){let i=t[o];i<16&&(n+="0"),n+=i.toString(16)}return n}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);let n=new Uint8Array(t.length/2);for(let s=0;s<t.length;s=s+2){let o=t.slice(s,s+2);n[s/2]=parseInt(o,16)}return n.buffer}static ToUtf16String(e,t=!1){return Ze.toString(e,t)}static FromUtf16String(e,t=!1){return Ze.fromString(e,t)}static Base64Padding(e){let t=4-e.length%4;if(t<4)for(let n=0;n<t;n++)e+="=";return e}static formatString(e){return e?.replace(/[\n\r\t ]/g,"")||""}};ko.DEFAULT_UTF8_ENCODING="utf8";function My(r,...e){let t=arguments[0];for(let n=1;n<arguments.length;n++){let s=arguments[n];for(let o in s)t[o]=s[o]}return t}function Fy(...r){let e=r.map(s=>s.byteLength).reduce((s,o)=>s+o),t=new Uint8Array(e),n=0;return r.map(s=>new Uint8Array(s)).forEach(s=>{for(let o of s)t[n++]=o}),t.buffer}function Vy(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let s=0;s<r.byteLength;s++)if(t[s]!==n[s])return!1;return!0}fn.BufferSourceConverter=Pt;fn.Convert=ko;fn.assign=My;fn.combine=Fy;fn.isEqual=Vy});var e0=Ve((ok,Qd)=>{"use strict";function qw(r){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),t=0;t<e.length;t++)e[t]=255;for(var n=0;n<r.length;n++){var s=r.charAt(n),o=s.charCodeAt(0);if(e[o]!==255)throw new TypeError(s+" is ambiguous");e[o]=n}var i=r.length,a=r.charAt(0),c=Math.log(i)/Math.log(256),u=Math.log(256)/Math.log(i);function l(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var d=0,h=0,p=0,y=g.length;p!==y&&g[p]===0;)p++,d++;for(var x=(y-p)*u+1>>>0,b=new Uint8Array(x);p!==y;){for(var v=g[p],E=0,A=x-1;(v!==0||E<h)&&A!==-1;A--,E++)v+=256*b[A]>>>0,b[A]=v%i>>>0,v=v/i>>>0;if(v!==0)throw new Error("Non-zero carry");h=E,p++}for(var S=x-h;S!==x&&b[S]===0;)S++;for(var D=a.repeat(d);S<x;++S)D+=r.charAt(b[S]);return D}function f(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var d=0;if(g[d]!==" "){for(var h=0,p=0;g[d]===a;)h++,d++;for(var y=(g.length-d)*c+1>>>0,x=new Uint8Array(y);g[d];){var b=e[g.charCodeAt(d)];if(b===255)return;for(var v=0,E=y-1;(b!==0||v<p)&&E!==-1;E--,v++)b+=i*x[E]>>>0,x[E]=b%256>>>0,b=b/256>>>0;if(b!==0)throw new Error("Non-zero carry");p=v,d++}if(g[d]!==" "){for(var A=y-p;A!==y&&x[A]===0;)A++;for(var S=new Uint8Array(h+(y-A)),D=h;A!==y;)S[D++]=x[A++];return S}}}function m(g){var d=f(g);if(d)return d;throw new Error("Non-base"+i+" character")}return{encode:l,decodeUnsafe:f,decode:m}}Qd.exports=qw});var Ai=Ve((ik,t0)=>{"use strict";var Ww=new TextDecoder,zw=r=>Ww.decode(r),Gw=new TextEncoder,jw=r=>Gw.encode(r);function Yw(r,e){let t=new Uint8Array(e),n=0;for(let s of r)t.set(s,n),n+=s.length;return t}t0.exports={decodeText:zw,encodeText:jw,concat:Yw}});var n0=Ve((ak,r0)=>{"use strict";var{encodeText:Zw}=Ai(),hu=class{constructor(e,t,n,s){this.name=e,this.code=t,this.codeBuf=Zw(this.code),this.alphabet=s,this.codec=n(s)}encode(e){return this.codec.encode(e)}decode(e){for(let t of e)if(this.alphabet&&this.alphabet.indexOf(t)<0)throw new Error(`invalid character '${t}' in '${e}'`);return this.codec.decode(e)}};r0.exports=hu});var o0=Ve((ck,s0)=>{"use strict";var Xw=(r,e,t)=>{let n={};for(let u=0;u<e.length;++u)n[e[u]]=u;let s=r.length;for(;r[s-1]==="=";)--s;let o=new Uint8Array(s*t/8|0),i=0,a=0,c=0;for(let u=0;u<s;++u){let l=n[r[u]];if(l===void 0)throw new SyntaxError("Invalid character "+r[u]);a=a<<t|l,i+=t,i>=8&&(i-=8,o[c++]=255&a>>i)}if(i>=t||255&a<<8-i)throw new SyntaxError("Unexpected end of data");return o},Jw=(r,e,t)=>{let n=e[e.length-1]==="=",s=(1<<t)-1,o="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>t;)i-=t,o+=e[s&a>>i];if(i&&(o+=e[s&a<<t-i]),n)for(;o.length*t&7;)o+="=";return o},Qw=r=>e=>({encode(t){return Jw(t,e,r)},decode(t){return Xw(t,e,r)}});s0.exports={rfc4648:Qw}});var u0=Ve((uk,c0)=>{"use strict";var ms=e0(),ex=n0(),{rfc4648:Ne}=o0(),{decodeText:tx,encodeText:rx}=Ai(),nx=()=>({encode:tx,decode:rx}),i0=[["identity","\0",nx,""],["base2","0",Ne(1),"01"],["base8","7",Ne(3),"01234567"],["base10","9",ms,"0123456789"],["base16","f",Ne(4),"0123456789abcdef"],["base16upper","F",Ne(4),"0123456789ABCDEF"],["base32hex","v",Ne(5),"0123456789abcdefghijklmnopqrstuv"],["base32hexupper","V",Ne(5),"0123456789ABCDEFGHIJKLMNOPQRSTUV"],["base32hexpad","t",Ne(5),"0123456789abcdefghijklmnopqrstuv="],["base32hexpadupper","T",Ne(5),"0123456789ABCDEFGHIJKLMNOPQRSTUV="],["base32","b",Ne(5),"abcdefghijklmnopqrstuvwxyz234567"],["base32upper","B",Ne(5),"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"],["base32pad","c",Ne(5),"abcdefghijklmnopqrstuvwxyz234567="],["base32padupper","C",Ne(5),"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567="],["base32z","h",Ne(5),"ybndrfg8ejkmcpqxot1uwisza345h769"],["base36","k",ms,"0123456789abcdefghijklmnopqrstuvwxyz"],["base36upper","K",ms,"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"],["base58btc","z",ms,"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"],["base58flickr","Z",ms,"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"],["base64","m",Ne(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"],["base64pad","M",Ne(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="],["base64url","u",Ne(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"],["base64urlpad","U",Ne(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_="]],a0=i0.reduce((r,e)=>(r[e[0]]=new ex(e[0],e[1],e[2],e[3]),r),{}),sx=i0.reduce((r,e)=>(r[e[1]]=a0[e[0]],r),{});c0.exports={names:a0,codes:sx}});var h0=Ve((Wt,f0)=>{"use strict";var vn=u0(),{encodeText:ox,decodeText:Di,concat:l0}=Ai();function ix(r,e){if(!e)throw new Error("requires an encoded Uint8Array");let{name:t,codeBuf:n}=Pr(r);return lx(t,e),l0([n,e],n.length+e.length)}function ax(r,e){let t=Pr(r),n=ox(t.encode(e));return l0([t.codeBuf,n],t.codeBuf.length+n.length)}function cx(r){r instanceof Uint8Array&&(r=Di(r));let e=r[0];return["f","F","v","V","t","T","b","B","c","C","h","k","K"].includes(e)&&(r=r.toLowerCase()),Pr(r[0]).decode(r.substring(1))}function ux(r){if(r instanceof Uint8Array&&(r=Di(r)),Object.prototype.toString.call(r)!=="[object String]")return!1;try{return Pr(r[0]).name}catch{return!1}}function lx(r,e){Pr(r).decode(Di(e))}function Pr(r){if(Object.prototype.hasOwnProperty.call(vn.names,r))return vn.names[r];if(Object.prototype.hasOwnProperty.call(vn.codes,r))return vn.codes[r];throw new Error(`Unsupported encoding: ${r}`)}function fx(r){return r instanceof Uint8Array&&(r=Di(r)),Pr(r[0])}Wt=f0.exports=ix;Wt.encode=ax;Wt.decode=cx;Wt.isEncoded=ux;Wt.encoding=Pr;Wt.encodingFromData=fx;var hx=Object.freeze(vn.names),dx=Object.freeze(vn.codes);Wt.names=hx;Wt.codes=dx});var g0=Ve((lk,m0)=>{m0.exports=p0;var d0=128,px=127,mx=~px,gx=Math.pow(2,31);function p0(r,e,t){e=e||[],t=t||0;for(var n=t;r>=gx;)e[t++]=r&255|d0,r/=128;for(;r&mx;)e[t++]=r&255|d0,r>>>=7;return e[t]=r|0,p0.bytes=t-n+1,e}});var w0=Ve((fk,y0)=>{y0.exports=du;var bx=128,b0=127;function du(r,n){var t=0,n=n||0,s=0,o=n,i,a=r.length;do{if(o>=a)throw du.bytes=0,new RangeError("Could not decode varint");i=r[o++],t+=s<28?(i&b0)<<s:(i&b0)*Math.pow(2,s),s+=7}while(i>=bx);return du.bytes=o-n,t}});var E0=Ve((hk,x0)=>{var yx=Math.pow(2,7),wx=Math.pow(2,14),xx=Math.pow(2,21),Ex=Math.pow(2,28),vx=Math.pow(2,35),Ax=Math.pow(2,42),Dx=Math.pow(2,49),Bx=Math.pow(2,56),Sx=Math.pow(2,63);x0.exports=function(r){return r<yx?1:r<wx?2:r<xx?3:r<Ex?4:r<vx?5:r<Ax?6:r<Dx?7:r<Bx?8:r<Sx?9:10}});var A0=Ve((dk,v0)=>{v0.exports={encode:g0(),decode:w0(),encodingLength:E0()}});var B0=Ve((pk,D0)=>{"use strict";var kx=Object.freeze({identity:0,sha1:17,"sha2-256":18,"sha2-512":19,"sha3-512":20,"sha3-384":21,"sha3-256":22,"sha3-224":23,"shake-128":24,"shake-256":25,"keccak-224":26,"keccak-256":27,"keccak-384":28,"keccak-512":29,blake3:30,"murmur3-128":34,"murmur3-32":35,"dbl-sha2-256":86,md4:212,md5:213,bmt:214,"sha2-256-trunc254-padded":4114,"ripemd-128":4178,"ripemd-160":4179,"ripemd-256":4180,"ripemd-320":4181,x11:4352,kangarootwelve:7425,"sm3-256":21325,"blake2b-8":45569,"blake2b-16":45570,"blake2b-24":45571,"blake2b-32":45572,"blake2b-40":45573,"blake2b-48":45574,"blake2b-56":45575,"blake2b-64":45576,"blake2b-72":45577,"blake2b-80":45578,"blake2b-88":45579,"blake2b-96":45580,"blake2b-104":45581,"blake2b-112":45582,"blake2b-120":45583,"blake2b-128":45584,"blake2b-136":45585,"blake2b-144":45586,"blake2b-152":45587,"blake2b-160":45588,"blake2b-168":45589,"blake2b-176":45590,"blake2b-184":45591,"blake2b-192":45592,"blake2b-200":45593,"blake2b-208":45594,"blake2b-216":45595,"blake2b-224":45596,"blake2b-232":45597,"blake2b-240":45598,"blake2b-248":45599,"blake2b-256":45600,"blake2b-264":45601,"blake2b-272":45602,"blake2b-280":45603,"blake2b-288":45604,"blake2b-296":45605,"blake2b-304":45606,"blake2b-312":45607,"blake2b-320":45608,"blake2b-328":45609,"blake2b-336":45610,"blake2b-344":45611,"blake2b-352":45612,"blake2b-360":45613,"blake2b-368":45614,"blake2b-376":45615,"blake2b-384":45616,"blake2b-392":45617,"blake2b-400":45618,"blake2b-408":45619,"blake2b-416":45620,"blake2b-424":45621,"blake2b-432":45622,"blake2b-440":45623,"blake2b-448":45624,"blake2b-456":45625,"blake2b-464":45626,"blake2b-472":45627,"blake2b-480":45628,"blake2b-488":45629,"blake2b-496":45630,"blake2b-504":45631,"blake2b-512":45632,"blake2s-8":45633,"blake2s-16":45634,"blake2s-24":45635,"blake2s-32":45636,"blake2s-40":45637,"blake2s-48":45638,"blake2s-56":45639,"blake2s-64":45640,"blake2s-72":45641,"blake2s-80":45642,"blake2s-88":45643,"blake2s-96":45644,"blake2s-104":45645,"blake2s-112":45646,"blake2s-120":45647,"blake2s-128":45648,"blake2s-136":45649,"blake2s-144":45650,"blake2s-152":45651,"blake2s-160":45652,"blake2s-168":45653,"blake2s-176":45654,"blake2s-184":45655,"blake2s-192":45656,"blake2s-200":45657,"blake2s-208":45658,"blake2s-216":45659,"blake2s-224":45660,"blake2s-232":45661,"blake2s-240":45662,"blake2s-248":45663,"blake2s-256":45664,"skein256-8":45825,"skein256-16":45826,"skein256-24":45827,"skein256-32":45828,"skein256-40":45829,"skein256-48":45830,"skein256-56":45831,"skein256-64":45832,"skein256-72":45833,"skein256-80":45834,"skein256-88":45835,"skein256-96":45836,"skein256-104":45837,"skein256-112":45838,"skein256-120":45839,"skein256-128":45840,"skein256-136":45841,"skein256-144":45842,"skein256-152":45843,"skein256-160":45844,"skein256-168":45845,"skein256-176":45846,"skein256-184":45847,"skein256-192":45848,"skein256-200":45849,"skein256-208":45850,"skein256-216":45851,"skein256-224":45852,"skein256-232":45853,"skein256-240":45854,"skein256-248":45855,"skein256-256":45856,"skein512-8":45857,"skein512-16":45858,"skein512-24":45859,"skein512-32":45860,"skein512-40":45861,"skein512-48":45862,"skein512-56":45863,"skein512-64":45864,"skein512-72":45865,"skein512-80":45866,"skein512-88":45867,"skein512-96":45868,"skein512-104":45869,"skein512-112":45870,"skein512-120":45871,"skein512-128":45872,"skein512-136":45873,"skein512-144":45874,"skein512-152":45875,"skein512-160":45876,"skein512-168":45877,"skein512-176":45878,"skein512-184":45879,"skein512-192":45880,"skein512-200":45881,"skein512-208":45882,"skein512-216":45883,"skein512-224":45884,"skein512-232":45885,"skein512-240":45886,"skein512-248":45887,"skein512-256":45888,"skein512-264":45889,"skein512-272":45890,"skein512-280":45891,"skein512-288":45892,"skein512-296":45893,"skein512-304":45894,"skein512-312":45895,"skein512-320":45896,"skein512-328":45897,"skein512-336":45898,"skein512-344":45899,"skein512-352":45900,"skein512-360":45901,"skein512-368":45902,"skein512-376":45903,"skein512-384":45904,"skein512-392":45905,"skein512-400":45906,"skein512-408":45907,"skein512-416":45908,"skein512-424":45909,"skein512-432":45910,"skein512-440":45911,"skein512-448":45912,"skein512-456":45913,"skein512-464":45914,"skein512-472":45915,"skein512-480":45916,"skein512-488":45917,"skein512-496":45918,"skein512-504":45919,"skein512-512":45920,"skein1024-8":45921,"skein1024-16":45922,"skein1024-24":45923,"skein1024-32":45924,"skein1024-40":45925,"skein1024-48":45926,"skein1024-56":45927,"skein1024-64":45928,"skein1024-72":45929,"skein1024-80":45930,"skein1024-88":45931,"skein1024-96":45932,"skein1024-104":45933,"skein1024-112":45934,"skein1024-120":45935,"skein1024-128":45936,"skein1024-136":45937,"skein1024-144":45938,"skein1024-152":45939,"skein1024-160":45940,"skein1024-168":45941,"skein1024-176":45942,"skein1024-184":45943,"skein1024-192":45944,"skein1024-200":45945,"skein1024-208":45946,"skein1024-216":45947,"skein1024-224":45948,"skein1024-232":45949,"skein1024-240":45950,"skein1024-248":45951,"skein1024-256":45952,"skein1024-264":45953,"skein1024-272":45954,"skein1024-280":45955,"skein1024-288":45956,"skein1024-296":45957,"skein1024-304":45958,"skein1024-312":45959,"skein1024-320":45960,"skein1024-328":45961,"skein1024-336":45962,"skein1024-344":45963,"skein1024-352":45964,"skein1024-360":45965,"skein1024-368":45966,"skein1024-376":45967,"skein1024-384":45968,"skein1024-392":45969,"skein1024-400":45970,"skein1024-408":45971,"skein1024-416":45972,"skein1024-424":45973,"skein1024-432":45974,"skein1024-440":45975,"skein1024-448":45976,"skein1024-456":45977,"skein1024-464":45978,"skein1024-472":45979,"skein1024-480":45980,"skein1024-488":45981,"skein1024-496":45982,"skein1024-504":45983,"skein1024-512":45984,"skein1024-520":45985,"skein1024-528":45986,"skein1024-536":45987,"skein1024-544":45988,"skein1024-552":45989,"skein1024-560":45990,"skein1024-568":45991,"skein1024-576":45992,"skein1024-584":45993,"skein1024-592":45994,"skein1024-600":45995,"skein1024-608":45996,"skein1024-616":45997,"skein1024-624":45998,"skein1024-632":45999,"skein1024-640":46e3,"skein1024-648":46001,"skein1024-656":46002,"skein1024-664":46003,"skein1024-672":46004,"skein1024-680":46005,"skein1024-688":46006,"skein1024-696":46007,"skein1024-704":46008,"skein1024-712":46009,"skein1024-720":46010,"skein1024-728":46011,"skein1024-736":46012,"skein1024-744":46013,"skein1024-752":46014,"skein1024-760":46015,"skein1024-768":46016,"skein1024-776":46017,"skein1024-784":46018,"skein1024-792":46019,"skein1024-800":46020,"skein1024-808":46021,"skein1024-816":46022,"skein1024-824":46023,"skein1024-832":46024,"skein1024-840":46025,"skein1024-848":46026,"skein1024-856":46027,"skein1024-864":46028,"skein1024-872":46029,"skein1024-880":46030,"skein1024-888":46031,"skein1024-896":46032,"skein1024-904":46033,"skein1024-912":46034,"skein1024-920":46035,"skein1024-928":46036,"skein1024-936":46037,"skein1024-944":46038,"skein1024-952":46039,"skein1024-960":46040,"skein1024-968":46041,"skein1024-976":46042,"skein1024-984":46043,"skein1024-992":46044,"skein1024-1000":46045,"skein1024-1008":46046,"skein1024-1016":46047,"skein1024-1024":46048,"poseidon-bls12_381-a2-fc1":46081,"poseidon-bls12_381-a2-fc1-sc":46082});D0.exports={names:kx}});function Cx(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var s=0;s<r.length;s++){var o=r.charAt(s),i=o.charCodeAt(0);if(t[i]!==255)throw new TypeError(o+" is ambiguous");t[i]=s}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var h=0,p=0,y=0,x=d.length;y!==x&&d[y]===0;)y++,h++;for(var b=(x-y)*l+1>>>0,v=new Uint8Array(b);y!==x;){for(var E=d[y],A=0,S=b-1;(E!==0||A<p)&&S!==-1;S--,A++)E+=256*v[S]>>>0,v[S]=E%a>>>0,E=E/a>>>0;if(E!==0)throw new Error("Non-zero carry");p=A,y++}for(var D=b-p;D!==b&&v[D]===0;)D++;for(var _=c.repeat(h);D<b;++D)_+=r.charAt(v[D]);return _}function m(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var h=0;if(d[h]!==" "){for(var p=0,y=0;d[h]===c;)p++,h++;for(var x=(d.length-h)*u+1>>>0,b=new Uint8Array(x);d[h];){var v=t[d.charCodeAt(h)];if(v===255)return;for(var E=0,A=x-1;(v!==0||E<y)&&A!==-1;A--,E++)v+=a*b[A]>>>0,b[A]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");y=E,h++}if(d[h]!==" "){for(var S=x-y;S!==x&&b[S]===0;)S++;for(var D=new Uint8Array(p+(x-S)),_=p;S!==x;)D[_++]=b[S++];return D}}}function g(d){var h=m(d);if(h)return h;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:m,decode:g}}var Ix,Tx,S0,k0=te(()=>{Ix=Cx,Tx=Ix,S0=Tx});var gk,C0,zt,I0,T0,lr=te(()=>{gk=new Uint8Array(0),C0=(r,e)=>{if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0},zt=r=>{if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")},I0=r=>new TextEncoder().encode(r),T0=r=>new TextDecoder().decode(r)});var pu,mu,gu,R0,bu,An,fr,_x,Rx,de,dt=te(()=>{k0();lr();pu=class{constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},mu=class{constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return R0(this,e)}},gu=class{constructor(e){this.decoders=e}or(e){return R0(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},R0=(r,e)=>new gu({...r.decoders||{[r.prefix]:r},...e.decoders||{[e.prefix]:e}}),bu=class{constructor(e,t,n,s){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=s,this.encoder=new pu(e,t,n),this.decoder=new mu(e,t,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},An=({name:r,prefix:e,encode:t,decode:n})=>new bu(r,e,t,n),fr=({prefix:r,name:e,alphabet:t})=>{let{encode:n,decode:s}=S0(t,e);return An({prefix:r,name:e,encode:n,decode:o=>zt(s(o))})},_x=(r,e,t,n)=>{let s={};for(let l=0;l<e.length;++l)s[e[l]]=l;let o=r.length;for(;r[o-1]==="=";)--o;let i=new Uint8Array(o*t/8|0),a=0,c=0,u=0;for(let l=0;l<o;++l){let f=s[r[l]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|f,a+=t,a>=8&&(a-=8,i[u++]=255&c>>a)}if(a>=t||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return i},Rx=(r,e,t)=>{let n=e[e.length-1]==="=",s=(1<<t)-1,o="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>t;)i-=t,o+=e[s&a>>i];if(i&&(o+=e[s&a<<t-i]),n)for(;o.length*t&7;)o+="=";return o},de=({name:r,prefix:e,bitsPerChar:t,alphabet:n})=>An({prefix:e,name:r,encode(s){return Rx(s,n,t)},decode(s){return _x(s,n,t,r)}})});var yu={};J(yu,{identity:()=>Nx});var Nx,N0=te(()=>{dt();lr();Nx=An({prefix:"\0",name:"identity",encode:r=>T0(r),decode:r=>I0(r)})});var wu={};J(wu,{base2:()=>Lx});var Lx,L0=te(()=>{dt();Lx=de({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1})});var xu={};J(xu,{base8:()=>Ux});var Ux,U0=te(()=>{dt();Ux=de({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3})});var Eu={};J(Eu,{base10:()=>Ox});var Ox,O0=te(()=>{dt();Ox=fr({prefix:"9",name:"base10",alphabet:"0123456789"})});var vu={};J(vu,{base16:()=>Px,base16upper:()=>Mx});var Px,Mx,P0=te(()=>{dt();Px=de({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Mx=de({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4})});var Au={};J(Au,{base32:()=>Dn,base32hex:()=>Kx,base32hexpad:()=>qx,base32hexpadupper:()=>Wx,base32hexupper:()=>$x,base32pad:()=>Vx,base32padupper:()=>Hx,base32upper:()=>Fx,base32z:()=>zx});var Dn,Fx,Vx,Hx,Kx,$x,qx,Wx,zx,Du=te(()=>{dt();Dn=de({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Fx=de({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Vx=de({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Hx=de({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Kx=de({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),$x=de({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),qx=de({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Wx=de({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),zx=de({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5})});var Bu={};J(Bu,{base36:()=>Gx,base36upper:()=>jx});var Gx,jx,M0=te(()=>{dt();Gx=fr({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),jx=fr({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"})});var Su={};J(Su,{base58btc:()=>Dt,base58flickr:()=>Yx});var Dt,Yx,ku=te(()=>{dt();Dt=fr({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Yx=fr({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"})});var Cu={};J(Cu,{base64:()=>Zx,base64pad:()=>Xx,base64url:()=>Jx,base64urlpad:()=>Qx});var Zx,Xx,Jx,Qx,F0=te(()=>{dt();Zx=de({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Xx=de({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Jx=de({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Qx=de({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6})});var Iu={};J(Iu,{base256emoji:()=>s2});function r2(r){return r.reduce((e,t)=>(e+=e2[t],e),"")}function n2(r){let e=[];for(let t of r){let n=t2[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var V0,e2,t2,s2,H0=te(()=>{dt();V0=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}"),e2=V0.reduce((r,e,t)=>(r[t]=e,r),[]),t2=V0.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);s2=An({prefix:"\u{1F680}",name:"base256emoji",encode:r2,decode:n2})});function q0(r,e,t){e=e||[],t=t||0;for(var n=t;r>=c2;)e[t++]=r&255|K0,r/=128;for(;r&a2;)e[t++]=r&255|K0,r>>>=7;return e[t]=r|0,q0.bytes=t-n+1,e}function Tu(r,n){var t=0,n=n||0,s=0,o=n,i,a=r.length;do{if(o>=a)throw Tu.bytes=0,new RangeError("Could not decode varint");i=r[o++],t+=s<28?(i&$0)<<s:(i&$0)*Math.pow(2,s),s+=7}while(i>=l2);return Tu.bytes=o-n,t}var o2,K0,i2,a2,c2,u2,l2,$0,f2,h2,d2,p2,m2,g2,b2,y2,w2,x2,E2,v2,gs,W0=te(()=>{o2=q0,K0=128,i2=127,a2=~i2,c2=Math.pow(2,31);u2=Tu,l2=128,$0=127;f2=Math.pow(2,7),h2=Math.pow(2,14),d2=Math.pow(2,21),p2=Math.pow(2,28),m2=Math.pow(2,35),g2=Math.pow(2,42),b2=Math.pow(2,49),y2=Math.pow(2,56),w2=Math.pow(2,63),x2=function(r){return r<f2?1:r<h2?2:r<d2?3:r<p2?4:r<m2?5:r<g2?6:r<b2?7:r<y2?8:r<w2?9:10},E2={encode:o2,decode:u2,encodingLength:x2},v2=E2,gs=v2});var bs,Bn,Sn,Si=te(()=>{W0();bs=(r,e=0)=>[gs.decode(r,e),gs.decode.bytes],Bn=(r,e,t=0)=>(gs.encode(r,e,t),e),Sn=r=>gs.encodingLength(r)});var Mr,z0,G0,kn,ws=te(()=>{lr();Si();Mr=(r,e)=>{let t=e.byteLength,n=Sn(r),s=n+Sn(t),o=new Uint8Array(s+t);return Bn(r,o,0),Bn(t,o,n),o.set(e,s),new kn(r,t,e,o)},z0=r=>{let e=zt(r),[t,n]=bs(e),[s,o]=bs(e.subarray(n)),i=e.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new kn(t,s,i,e)},G0=(r,e)=>r===e?!0:r.code===e.code&&r.size===e.size&&C0(r.bytes,e.bytes),kn=class{constructor(e,t,n,s){this.code=e,this.size=t,this.digest=n,this.bytes=s}}});var Ru,_u,Nu=te(()=>{ws();Ru=({name:r,code:e,encode:t})=>new _u(r,e,t),_u=class{constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?Mr(this.code,t):t.then(n=>Mr(this.code,n))}else throw Error("Unknown type, must be binary type")}}});var Lu={};J(Lu,{sha256:()=>A2,sha512:()=>D2});var Y0,A2,D2,Z0=te(()=>{Nu();Y0=r=>async e=>new Uint8Array(await crypto.subtle.digest(r,e)),A2=Ru({name:"sha2-256",code:18,encode:Y0("SHA-256")}),D2=Ru({name:"sha2-512",code:19,encode:Y0("SHA-512")})});var Uu={};J(Uu,{identity:()=>k2});var X0,B2,J0,S2,k2,Q0=te(()=>{lr();ws();X0=0,B2="identity",J0=zt,S2=r=>Mr(X0,J0(r)),k2={code:X0,name:B2,encode:J0,digest:S2}});var ep=te(()=>{lr()});var Pk,Mk,tp=te(()=>{Pk=new TextEncoder,Mk=new TextDecoder});var Ii,T2,_2,R2,xs,N2,rp,np,ki,Ci,L2,U2,O2,sp=te(()=>{Si();ws();ku();Du();lr();Ii=class r{constructor(e,t,n,s){this.code=t,this.version=e,this.multihash=n,this.bytes=s,this.byteOffset=s.byteOffset,this.byteLength=s.byteLength,this.asCID=this,this._baseCache=new Map,Object.defineProperties(this,{byteOffset:Ci,byteLength:Ci,code:ki,version:ki,multihash:ki,bytes:ki,_baseCache:Ci,asCID:Ci})}toV0(){switch(this.version){case 0:return this;default:{let{code:e,multihash:t}=this;if(e!==xs)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==N2)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=Mr(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}equals(e){return e&&this.code===e.code&&this.version===e.version&&G0(this.multihash,e.multihash)}toString(e){let{bytes:t,version:n,_baseCache:s}=this;switch(n){case 0:return _2(t,s,e||Dt.encoder);default:return R2(t,s,e||Dn.encoder)}}toJSON(){return{code:this.code,version:this.version,hash:this.multihash.bytes}}get[Symbol.toStringTag](){return"CID"}[Symbol.for("nodejs.util.inspect.custom")](){return"CID("+this.toString()+")"}static isCID(e){return U2(/^0\.0/,O2),!!(e&&(e[np]||e.asCID===e))}get toBaseEncodedString(){throw new Error("Deprecated, use .toString()")}get codec(){throw new Error('"codec" property is deprecated, use integer "code" property instead')}get buffer(){throw new Error("Deprecated .buffer property, use .bytes to get Uint8Array instead")}get multibaseName(){throw new Error('"multibaseName" property is deprecated')}get prefix(){throw new Error('"prefix" property is deprecated')}static asCID(e){if(e instanceof r)return e;if(e!=null&&e.asCID===e){let{version:t,code:n,multihash:s,bytes:o}=e;return new r(t,n,s,o||rp(t,n,s.bytes))}else if(e!=null&&e[np]===!0){let{version:t,multihash:n,code:s}=e,o=z0(n);return r.create(t,s,o)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");switch(e){case 0:{if(t!==xs)throw new Error(`Version 0 CID must use dag-pb (code: ${xs}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let s=rp(e,t,n.bytes);return new r(e,t,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,xs,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,s=zt(e.subarray(n,n+t.multihashSize));if(s.byteLength!==t.multihashSize)throw new Error("Incorrect length");let o=s.subarray(t.multihashSize-t.digestSize),i=new kn(t.multihashCode,t.digestSize,o,s);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[f,m]=bs(e.subarray(t));return t+=m,f},s=n(),o=xs;if(s===18?(s=0,t=0):s===1&&(o=n()),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=t,a=n(),c=n(),u=t+c,l=u-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,t){let[n,s]=T2(e,t),o=r.decode(s);return o._baseCache.set(n,e),o}},T2=(r,e)=>{switch(r[0]){case"Q":{let t=e||Dt;return[Dt.prefix,t.decode(`${Dt.prefix}${r}`)]}case Dt.prefix:{let t=e||Dt;return[Dt.prefix,t.decode(r)]}case Dn.prefix:{let t=e||Dn;return[Dn.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}},_2=(r,e,t)=>{let{prefix:n}=t;if(n!==Dt.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let s=e.get(n);if(s==null){let o=t.encode(r).slice(1);return e.set(n,o),o}else return s},R2=(r,e,t)=>{let{prefix:n}=t,s=e.get(n);if(s==null){let o=t.encode(r);return e.set(n,o),o}else return s},xs=112,N2=18,rp=(r,e,t)=>{let n=Sn(r),s=n+Sn(e),o=new Uint8Array(s+t.byteLength);return Bn(r,o,0),Bn(e,o,n),o.set(t,s),o},np=Symbol.for("@ipld/js-cid/CID"),ki={writable:!1,configurable:!1,enumerable:!0},Ci={writable:!1,enumerable:!1,configurable:!1},L2="0.0.0-dev",U2=(r,e)=>{if(r.test(L2))console.warn(e);else throw new Error(e)},O2=`CID.isCID(v) is deprecated and will be removed in the next major release.
2
+ "use strict";var Libp2PWebrtc=(()=>{var Fp=Object.create;var Ds=Object.defineProperty;var Vp=Object.getOwnPropertyDescriptor;var Hp=Object.getOwnPropertyNames;var Kp=Object.getPrototypeOf,$p=Object.prototype.hasOwnProperty;var re=(r,e)=>()=>(r&&(e=r(r=0)),e);var Ke=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),J=(r,e)=>{for(var t in e)Ds(r,t,{get:e[t],enumerable:!0})},tl=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Hp(e))!$p.call(r,s)&&s!==t&&Ds(r,s,{get:()=>e[s],enumerable:!(n=Vp(e,s))||n.enumerable});return r};var Bs=(r,e,t)=>(t=r!=null?Fp(Kp(r)):{},tl(e||!r||!r.__esModule?Ds(t,"default",{value:r,enumerable:!0}):t,r)),Ss=r=>tl(Ds({},"__esModule",{value:!0}),r);var gf=Ke((jv,mf)=>{"use strict";function pf(r,e){for(let t in e)Object.defineProperty(r,t,{value:e[t],enumerable:!0,configurable:!0});return r}function Yg(r,e,t){if(!r||typeof r=="string")throw new TypeError("Please pass an Error to err-code");t||(t={}),typeof e=="object"&&(t=e,e=""),e&&(t.code=e);try{return pf(r,t)}catch{t.message=r.message,t.stack=r.stack;let s=function(){};return s.prototype=Object.create(Object.getPrototypeOf(r)),pf(new s,t)}}mf.exports=Yg});var bh=Ke(pn=>{"use strict";var Py="[object ArrayBuffer]",Pt=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===Py}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,t){let n=r.toUint8Array(e),s=r.toUint8Array(t);if(n.length!==s.byteLength)return!1;for(let o=0;o<n.length;o++)if(n[o]!==s[o])return!1;return!0}static concat(...e){let t;Array.isArray(e[0])&&!(e[1]instanceof Function)||Array.isArray(e[0])&&e[1]instanceof Function?t=e[0]:e[e.length-1]instanceof Function?t=e.slice(0,e.length-1):t=e;let n=0;for(let i of t)n+=i.byteLength;let s=new Uint8Array(n),o=0;for(let i of t){let a=this.toUint8Array(i);s.set(a,o),o+=a.length}return e[e.length-1]instanceof Function?this.toView(s,e[e.length-1]):s.buffer}},Nc="string",My=/^[0-9a-f]+$/i,Fy=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Vy=/^[a-zA-Z0-9-_]+$/,Io=class{static fromString(e){let t=unescape(encodeURIComponent(e)),n=new Uint8Array(t.length);for(let s=0;s<t.length;s++)n[s]=t.charCodeAt(s);return n.buffer}static toString(e){let t=Pt.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return decodeURIComponent(escape(n))}},Je=class{static toString(e,t=!1){let n=Pt.toArrayBuffer(e),s=new DataView(n),o="";for(let i=0;i<n.byteLength;i+=2){let a=s.getUint16(i,t);o+=String.fromCharCode(a)}return o}static fromString(e,t=!1){let n=new ArrayBuffer(e.length*2),s=new DataView(n);for(let o=0;o<e.length;o++)s.setUint16(o*2,e.charCodeAt(o),t);return n}},To=class r{static isHex(e){return typeof e===Nc&&My.test(e)}static isBase64(e){return typeof e===Nc&&Fy.test(e)}static isBase64Url(e){return typeof e===Nc&&Vy.test(e)}static ToString(e,t="utf8"){let n=Pt.toUint8Array(e);switch(t.toLowerCase()){case"utf8":return this.ToUtf8String(n);case"binary":return this.ToBinary(n);case"hex":return this.ToHex(n);case"base64":return this.ToBase64(n);case"base64url":return this.ToBase64Url(n);case"utf16le":return Je.toString(n,!0);case"utf16":case"utf16be":return Je.toString(n);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromString(e,t="utf8"){if(!e)return new ArrayBuffer(0);switch(t.toLowerCase()){case"utf8":return this.FromUtf8String(e);case"binary":return this.FromBinary(e);case"hex":return this.FromHex(e);case"base64":return this.FromBase64(e);case"base64url":return this.FromBase64Url(e);case"utf16le":return Je.fromString(e,!0);case"utf16":case"utf16be":return Je.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=Pt.toUint8Array(e);if(typeof btoa<"u"){let n=this.ToString(t,"binary");return btoa(n)}else return Buffer.from(t).toString("base64")}static FromBase64(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64(t))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(t)):new Uint8Array(Buffer.from(t,"base64")).buffer}static FromBase64Url(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64Url(t))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(t.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(e){return this.ToBase64(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.FromBinary(e);case"utf8":return Io.fromString(e);case"utf16":case"utf16be":return Je.fromString(e);case"utf16le":case"usc2":return Je.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return Io.toString(e);case"utf16":case"utf16be":return Je.toString(e);case"utf16le":case"usc2":return Je.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){let t=e.length,n=new Uint8Array(t);for(let s=0;s<t;s++)n[s]=e.charCodeAt(s);return n.buffer}static ToBinary(e){let t=Pt.toUint8Array(e),n="";for(let s=0;s<t.length;s++)n+=String.fromCharCode(t[s]);return n}static ToHex(e){let t=Pt.toUint8Array(e),n="",s=t.length;for(let o=0;o<s;o++){let i=t[o];i<16&&(n+="0"),n+=i.toString(16)}return n}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);let n=new Uint8Array(t.length/2);for(let s=0;s<t.length;s=s+2){let o=t.slice(s,s+2);n[s/2]=parseInt(o,16)}return n.buffer}static ToUtf16String(e,t=!1){return Je.toString(e,t)}static FromUtf16String(e,t=!1){return Je.fromString(e,t)}static Base64Padding(e){let t=4-e.length%4;if(t<4)for(let n=0;n<t;n++)e+="=";return e}static formatString(e){return e?.replace(/[\n\r\t ]/g,"")||""}};To.DEFAULT_UTF8_ENCODING="utf8";function Hy(r,...e){let t=arguments[0];for(let n=1;n<arguments.length;n++){let s=arguments[n];for(let o in s)t[o]=s[o]}return t}function Ky(...r){let e=r.map(s=>s.byteLength).reduce((s,o)=>s+o),t=new Uint8Array(e),n=0;return r.map(s=>new Uint8Array(s)).forEach(s=>{for(let o of s)t[n++]=o}),t.buffer}function $y(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let s=0;s<r.byteLength;s++)if(t[s]!==n[s])return!1;return!0}pn.BufferSourceConverter=Pt;pn.Convert=To;pn.assign=Hy;pn.combine=Ky;pn.isEqual=$y});var r0=Ke((lk,t0)=>{"use strict";function Ww(r){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),t=0;t<e.length;t++)e[t]=255;for(var n=0;n<r.length;n++){var s=r.charAt(n),o=s.charCodeAt(0);if(e[o]!==255)throw new TypeError(s+" is ambiguous");e[o]=n}var i=r.length,a=r.charAt(0),c=Math.log(i)/Math.log(256),u=Math.log(256)/Math.log(i);function l(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var d=0,h=0,p=0,y=g.length;p!==y&&g[p]===0;)p++,d++;for(var x=(y-p)*u+1>>>0,b=new Uint8Array(x);p!==y;){for(var v=g[p],E=0,A=x-1;(v!==0||E<h)&&A!==-1;A--,E++)v+=256*b[A]>>>0,b[A]=v%i>>>0,v=v/i>>>0;if(v!==0)throw new Error("Non-zero carry");h=E,p++}for(var S=x-h;S!==x&&b[S]===0;)S++;for(var D=a.repeat(d);S<x;++S)D+=r.charAt(b[S]);return D}function f(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var d=0;if(g[d]!==" "){for(var h=0,p=0;g[d]===a;)h++,d++;for(var y=(g.length-d)*c+1>>>0,x=new Uint8Array(y);g[d];){var b=e[g.charCodeAt(d)];if(b===255)return;for(var v=0,E=y-1;(b!==0||v<p)&&E!==-1;E--,v++)b+=i*x[E]>>>0,x[E]=b%256>>>0,b=b/256>>>0;if(b!==0)throw new Error("Non-zero carry");p=v,d++}if(g[d]!==" "){for(var A=y-p;A!==y&&x[A]===0;)A++;for(var S=new Uint8Array(h+(y-A)),D=h;A!==y;)S[D++]=x[A++];return S}}}function m(g){var d=f(g);if(d)return d;throw new Error("Non-base"+i+" character")}return{encode:l,decodeUnsafe:f,decode:m}}t0.exports=Ww});var Si=Ke((fk,n0)=>{"use strict";var zw=new TextDecoder,Gw=r=>zw.decode(r),jw=new TextEncoder,Yw=r=>jw.encode(r);function Zw(r,e){let t=new Uint8Array(e),n=0;for(let s of r)t.set(s,n),n+=s.length;return t}n0.exports={decodeText:Gw,encodeText:Yw,concat:Zw}});var o0=Ke((hk,s0)=>{"use strict";var{encodeText:Xw}=Si(),pu=class{constructor(e,t,n,s){this.name=e,this.code=t,this.codeBuf=Xw(this.code),this.alphabet=s,this.codec=n(s)}encode(e){return this.codec.encode(e)}decode(e){for(let t of e)if(this.alphabet&&this.alphabet.indexOf(t)<0)throw new Error(`invalid character '${t}' in '${e}'`);return this.codec.decode(e)}};s0.exports=pu});var a0=Ke((dk,i0)=>{"use strict";var Jw=(r,e,t)=>{let n={};for(let u=0;u<e.length;++u)n[e[u]]=u;let s=r.length;for(;r[s-1]==="=";)--s;let o=new Uint8Array(s*t/8|0),i=0,a=0,c=0;for(let u=0;u<s;++u){let l=n[r[u]];if(l===void 0)throw new SyntaxError("Invalid character "+r[u]);a=a<<t|l,i+=t,i>=8&&(i-=8,o[c++]=255&a>>i)}if(i>=t||255&a<<8-i)throw new SyntaxError("Unexpected end of data");return o},Qw=(r,e,t)=>{let n=e[e.length-1]==="=",s=(1<<t)-1,o="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>t;)i-=t,o+=e[s&a>>i];if(i&&(o+=e[s&a<<t-i]),n)for(;o.length*t&7;)o+="=";return o},ex=r=>e=>({encode(t){return Qw(t,e,r)},decode(t){return Jw(t,e,r)}});i0.exports={rfc4648:ex}});var f0=Ke((pk,l0)=>{"use strict";var bs=r0(),tx=o0(),{rfc4648:Le}=a0(),{decodeText:rx,encodeText:nx}=Si(),sx=()=>({encode:rx,decode:nx}),c0=[["identity","\0",sx,""],["base2","0",Le(1),"01"],["base8","7",Le(3),"01234567"],["base10","9",bs,"0123456789"],["base16","f",Le(4),"0123456789abcdef"],["base16upper","F",Le(4),"0123456789ABCDEF"],["base32hex","v",Le(5),"0123456789abcdefghijklmnopqrstuv"],["base32hexupper","V",Le(5),"0123456789ABCDEFGHIJKLMNOPQRSTUV"],["base32hexpad","t",Le(5),"0123456789abcdefghijklmnopqrstuv="],["base32hexpadupper","T",Le(5),"0123456789ABCDEFGHIJKLMNOPQRSTUV="],["base32","b",Le(5),"abcdefghijklmnopqrstuvwxyz234567"],["base32upper","B",Le(5),"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"],["base32pad","c",Le(5),"abcdefghijklmnopqrstuvwxyz234567="],["base32padupper","C",Le(5),"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567="],["base32z","h",Le(5),"ybndrfg8ejkmcpqxot1uwisza345h769"],["base36","k",bs,"0123456789abcdefghijklmnopqrstuvwxyz"],["base36upper","K",bs,"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"],["base58btc","z",bs,"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"],["base58flickr","Z",bs,"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"],["base64","m",Le(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"],["base64pad","M",Le(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="],["base64url","u",Le(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"],["base64urlpad","U",Le(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_="]],u0=c0.reduce((r,e)=>(r[e[0]]=new tx(e[0],e[1],e[2],e[3]),r),{}),ox=c0.reduce((r,e)=>(r[e[1]]=u0[e[0]],r),{});l0.exports={names:u0,codes:ox}});var p0=Ke((Wt,d0)=>{"use strict";var Bn=f0(),{encodeText:ix,decodeText:ki,concat:h0}=Si();function ax(r,e){if(!e)throw new Error("requires an encoded Uint8Array");let{name:t,codeBuf:n}=Mr(r);return fx(t,e),h0([n,e],n.length+e.length)}function cx(r,e){let t=Mr(r),n=ix(t.encode(e));return h0([t.codeBuf,n],t.codeBuf.length+n.length)}function ux(r){r instanceof Uint8Array&&(r=ki(r));let e=r[0];return["f","F","v","V","t","T","b","B","c","C","h","k","K"].includes(e)&&(r=r.toLowerCase()),Mr(r[0]).decode(r.substring(1))}function lx(r){if(r instanceof Uint8Array&&(r=ki(r)),Object.prototype.toString.call(r)!=="[object String]")return!1;try{return Mr(r[0]).name}catch{return!1}}function fx(r,e){Mr(r).decode(ki(e))}function Mr(r){if(Object.prototype.hasOwnProperty.call(Bn.names,r))return Bn.names[r];if(Object.prototype.hasOwnProperty.call(Bn.codes,r))return Bn.codes[r];throw new Error(`Unsupported encoding: ${r}`)}function hx(r){return r instanceof Uint8Array&&(r=ki(r)),Mr(r[0])}Wt=d0.exports=ax;Wt.encode=cx;Wt.decode=ux;Wt.isEncoded=lx;Wt.encoding=Mr;Wt.encodingFromData=hx;var dx=Object.freeze(Bn.names),px=Object.freeze(Bn.codes);Wt.names=dx;Wt.codes=px});var y0=Ke((mk,b0)=>{b0.exports=g0;var m0=128,mx=127,gx=~mx,bx=Math.pow(2,31);function g0(r,e,t){e=e||[],t=t||0;for(var n=t;r>=bx;)e[t++]=r&255|m0,r/=128;for(;r&gx;)e[t++]=r&255|m0,r>>>=7;return e[t]=r|0,g0.bytes=t-n+1,e}});var E0=Ke((gk,x0)=>{x0.exports=mu;var yx=128,w0=127;function mu(r,n){var t=0,n=n||0,s=0,o=n,i,a=r.length;do{if(o>=a)throw mu.bytes=0,new RangeError("Could not decode varint");i=r[o++],t+=s<28?(i&w0)<<s:(i&w0)*Math.pow(2,s),s+=7}while(i>=yx);return mu.bytes=o-n,t}});var A0=Ke((bk,v0)=>{var wx=Math.pow(2,7),xx=Math.pow(2,14),Ex=Math.pow(2,21),vx=Math.pow(2,28),Ax=Math.pow(2,35),Dx=Math.pow(2,42),Bx=Math.pow(2,49),Sx=Math.pow(2,56),kx=Math.pow(2,63);v0.exports=function(r){return r<wx?1:r<xx?2:r<Ex?3:r<vx?4:r<Ax?5:r<Dx?6:r<Bx?7:r<Sx?8:r<kx?9:10}});var B0=Ke((yk,D0)=>{D0.exports={encode:y0(),decode:E0(),encodingLength:A0()}});var k0=Ke((wk,S0)=>{"use strict";var Cx=Object.freeze({identity:0,sha1:17,"sha2-256":18,"sha2-512":19,"sha3-512":20,"sha3-384":21,"sha3-256":22,"sha3-224":23,"shake-128":24,"shake-256":25,"keccak-224":26,"keccak-256":27,"keccak-384":28,"keccak-512":29,blake3:30,"murmur3-128":34,"murmur3-32":35,"dbl-sha2-256":86,md4:212,md5:213,bmt:214,"sha2-256-trunc254-padded":4114,"ripemd-128":4178,"ripemd-160":4179,"ripemd-256":4180,"ripemd-320":4181,x11:4352,kangarootwelve:7425,"sm3-256":21325,"blake2b-8":45569,"blake2b-16":45570,"blake2b-24":45571,"blake2b-32":45572,"blake2b-40":45573,"blake2b-48":45574,"blake2b-56":45575,"blake2b-64":45576,"blake2b-72":45577,"blake2b-80":45578,"blake2b-88":45579,"blake2b-96":45580,"blake2b-104":45581,"blake2b-112":45582,"blake2b-120":45583,"blake2b-128":45584,"blake2b-136":45585,"blake2b-144":45586,"blake2b-152":45587,"blake2b-160":45588,"blake2b-168":45589,"blake2b-176":45590,"blake2b-184":45591,"blake2b-192":45592,"blake2b-200":45593,"blake2b-208":45594,"blake2b-216":45595,"blake2b-224":45596,"blake2b-232":45597,"blake2b-240":45598,"blake2b-248":45599,"blake2b-256":45600,"blake2b-264":45601,"blake2b-272":45602,"blake2b-280":45603,"blake2b-288":45604,"blake2b-296":45605,"blake2b-304":45606,"blake2b-312":45607,"blake2b-320":45608,"blake2b-328":45609,"blake2b-336":45610,"blake2b-344":45611,"blake2b-352":45612,"blake2b-360":45613,"blake2b-368":45614,"blake2b-376":45615,"blake2b-384":45616,"blake2b-392":45617,"blake2b-400":45618,"blake2b-408":45619,"blake2b-416":45620,"blake2b-424":45621,"blake2b-432":45622,"blake2b-440":45623,"blake2b-448":45624,"blake2b-456":45625,"blake2b-464":45626,"blake2b-472":45627,"blake2b-480":45628,"blake2b-488":45629,"blake2b-496":45630,"blake2b-504":45631,"blake2b-512":45632,"blake2s-8":45633,"blake2s-16":45634,"blake2s-24":45635,"blake2s-32":45636,"blake2s-40":45637,"blake2s-48":45638,"blake2s-56":45639,"blake2s-64":45640,"blake2s-72":45641,"blake2s-80":45642,"blake2s-88":45643,"blake2s-96":45644,"blake2s-104":45645,"blake2s-112":45646,"blake2s-120":45647,"blake2s-128":45648,"blake2s-136":45649,"blake2s-144":45650,"blake2s-152":45651,"blake2s-160":45652,"blake2s-168":45653,"blake2s-176":45654,"blake2s-184":45655,"blake2s-192":45656,"blake2s-200":45657,"blake2s-208":45658,"blake2s-216":45659,"blake2s-224":45660,"blake2s-232":45661,"blake2s-240":45662,"blake2s-248":45663,"blake2s-256":45664,"skein256-8":45825,"skein256-16":45826,"skein256-24":45827,"skein256-32":45828,"skein256-40":45829,"skein256-48":45830,"skein256-56":45831,"skein256-64":45832,"skein256-72":45833,"skein256-80":45834,"skein256-88":45835,"skein256-96":45836,"skein256-104":45837,"skein256-112":45838,"skein256-120":45839,"skein256-128":45840,"skein256-136":45841,"skein256-144":45842,"skein256-152":45843,"skein256-160":45844,"skein256-168":45845,"skein256-176":45846,"skein256-184":45847,"skein256-192":45848,"skein256-200":45849,"skein256-208":45850,"skein256-216":45851,"skein256-224":45852,"skein256-232":45853,"skein256-240":45854,"skein256-248":45855,"skein256-256":45856,"skein512-8":45857,"skein512-16":45858,"skein512-24":45859,"skein512-32":45860,"skein512-40":45861,"skein512-48":45862,"skein512-56":45863,"skein512-64":45864,"skein512-72":45865,"skein512-80":45866,"skein512-88":45867,"skein512-96":45868,"skein512-104":45869,"skein512-112":45870,"skein512-120":45871,"skein512-128":45872,"skein512-136":45873,"skein512-144":45874,"skein512-152":45875,"skein512-160":45876,"skein512-168":45877,"skein512-176":45878,"skein512-184":45879,"skein512-192":45880,"skein512-200":45881,"skein512-208":45882,"skein512-216":45883,"skein512-224":45884,"skein512-232":45885,"skein512-240":45886,"skein512-248":45887,"skein512-256":45888,"skein512-264":45889,"skein512-272":45890,"skein512-280":45891,"skein512-288":45892,"skein512-296":45893,"skein512-304":45894,"skein512-312":45895,"skein512-320":45896,"skein512-328":45897,"skein512-336":45898,"skein512-344":45899,"skein512-352":45900,"skein512-360":45901,"skein512-368":45902,"skein512-376":45903,"skein512-384":45904,"skein512-392":45905,"skein512-400":45906,"skein512-408":45907,"skein512-416":45908,"skein512-424":45909,"skein512-432":45910,"skein512-440":45911,"skein512-448":45912,"skein512-456":45913,"skein512-464":45914,"skein512-472":45915,"skein512-480":45916,"skein512-488":45917,"skein512-496":45918,"skein512-504":45919,"skein512-512":45920,"skein1024-8":45921,"skein1024-16":45922,"skein1024-24":45923,"skein1024-32":45924,"skein1024-40":45925,"skein1024-48":45926,"skein1024-56":45927,"skein1024-64":45928,"skein1024-72":45929,"skein1024-80":45930,"skein1024-88":45931,"skein1024-96":45932,"skein1024-104":45933,"skein1024-112":45934,"skein1024-120":45935,"skein1024-128":45936,"skein1024-136":45937,"skein1024-144":45938,"skein1024-152":45939,"skein1024-160":45940,"skein1024-168":45941,"skein1024-176":45942,"skein1024-184":45943,"skein1024-192":45944,"skein1024-200":45945,"skein1024-208":45946,"skein1024-216":45947,"skein1024-224":45948,"skein1024-232":45949,"skein1024-240":45950,"skein1024-248":45951,"skein1024-256":45952,"skein1024-264":45953,"skein1024-272":45954,"skein1024-280":45955,"skein1024-288":45956,"skein1024-296":45957,"skein1024-304":45958,"skein1024-312":45959,"skein1024-320":45960,"skein1024-328":45961,"skein1024-336":45962,"skein1024-344":45963,"skein1024-352":45964,"skein1024-360":45965,"skein1024-368":45966,"skein1024-376":45967,"skein1024-384":45968,"skein1024-392":45969,"skein1024-400":45970,"skein1024-408":45971,"skein1024-416":45972,"skein1024-424":45973,"skein1024-432":45974,"skein1024-440":45975,"skein1024-448":45976,"skein1024-456":45977,"skein1024-464":45978,"skein1024-472":45979,"skein1024-480":45980,"skein1024-488":45981,"skein1024-496":45982,"skein1024-504":45983,"skein1024-512":45984,"skein1024-520":45985,"skein1024-528":45986,"skein1024-536":45987,"skein1024-544":45988,"skein1024-552":45989,"skein1024-560":45990,"skein1024-568":45991,"skein1024-576":45992,"skein1024-584":45993,"skein1024-592":45994,"skein1024-600":45995,"skein1024-608":45996,"skein1024-616":45997,"skein1024-624":45998,"skein1024-632":45999,"skein1024-640":46e3,"skein1024-648":46001,"skein1024-656":46002,"skein1024-664":46003,"skein1024-672":46004,"skein1024-680":46005,"skein1024-688":46006,"skein1024-696":46007,"skein1024-704":46008,"skein1024-712":46009,"skein1024-720":46010,"skein1024-728":46011,"skein1024-736":46012,"skein1024-744":46013,"skein1024-752":46014,"skein1024-760":46015,"skein1024-768":46016,"skein1024-776":46017,"skein1024-784":46018,"skein1024-792":46019,"skein1024-800":46020,"skein1024-808":46021,"skein1024-816":46022,"skein1024-824":46023,"skein1024-832":46024,"skein1024-840":46025,"skein1024-848":46026,"skein1024-856":46027,"skein1024-864":46028,"skein1024-872":46029,"skein1024-880":46030,"skein1024-888":46031,"skein1024-896":46032,"skein1024-904":46033,"skein1024-912":46034,"skein1024-920":46035,"skein1024-928":46036,"skein1024-936":46037,"skein1024-944":46038,"skein1024-952":46039,"skein1024-960":46040,"skein1024-968":46041,"skein1024-976":46042,"skein1024-984":46043,"skein1024-992":46044,"skein1024-1000":46045,"skein1024-1008":46046,"skein1024-1016":46047,"skein1024-1024":46048,"poseidon-bls12_381-a2-fc1":46081,"poseidon-bls12_381-a2-fc1-sc":46082});S0.exports={names:Cx}});function Ix(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var s=0;s<r.length;s++){var o=r.charAt(s),i=o.charCodeAt(0);if(t[i]!==255)throw new TypeError(o+" is ambiguous");t[i]=s}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var h=0,p=0,y=0,x=d.length;y!==x&&d[y]===0;)y++,h++;for(var b=(x-y)*l+1>>>0,v=new Uint8Array(b);y!==x;){for(var E=d[y],A=0,S=b-1;(E!==0||A<p)&&S!==-1;S--,A++)E+=256*v[S]>>>0,v[S]=E%a>>>0,E=E/a>>>0;if(E!==0)throw new Error("Non-zero carry");p=A,y++}for(var D=b-p;D!==b&&v[D]===0;)D++;for(var _=c.repeat(h);D<b;++D)_+=r.charAt(v[D]);return _}function m(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var h=0;if(d[h]!==" "){for(var p=0,y=0;d[h]===c;)p++,h++;for(var x=(d.length-h)*u+1>>>0,b=new Uint8Array(x);d[h];){var v=t[d.charCodeAt(h)];if(v===255)return;for(var E=0,A=x-1;(v!==0||E<y)&&A!==-1;A--,E++)v+=a*b[A]>>>0,b[A]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");y=E,h++}if(d[h]!==" "){for(var S=x-y;S!==x&&b[S]===0;)S++;for(var D=new Uint8Array(p+(x-S)),_=p;S!==x;)D[_++]=b[S++];return D}}}function g(d){var h=m(d);if(h)return h;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:m,decode:g}}var Tx,_x,C0,I0=re(()=>{Tx=Ix,_x=Tx,C0=_x});var Ek,T0,zt,_0,R0,fr=re(()=>{Ek=new Uint8Array(0),T0=(r,e)=>{if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0},zt=r=>{if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")},_0=r=>new TextEncoder().encode(r),R0=r=>new TextDecoder().decode(r)});var gu,bu,yu,L0,wu,Sn,hr,Rx,Nx,me,pt=re(()=>{I0();fr();gu=class{constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},bu=class{constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return L0(this,e)}},yu=class{constructor(e){this.decoders=e}or(e){return L0(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},L0=(r,e)=>new yu({...r.decoders||{[r.prefix]:r},...e.decoders||{[e.prefix]:e}}),wu=class{constructor(e,t,n,s){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=s,this.encoder=new gu(e,t,n),this.decoder=new bu(e,t,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},Sn=({name:r,prefix:e,encode:t,decode:n})=>new wu(r,e,t,n),hr=({prefix:r,name:e,alphabet:t})=>{let{encode:n,decode:s}=C0(t,e);return Sn({prefix:r,name:e,encode:n,decode:o=>zt(s(o))})},Rx=(r,e,t,n)=>{let s={};for(let l=0;l<e.length;++l)s[e[l]]=l;let o=r.length;for(;r[o-1]==="=";)--o;let i=new Uint8Array(o*t/8|0),a=0,c=0,u=0;for(let l=0;l<o;++l){let f=s[r[l]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|f,a+=t,a>=8&&(a-=8,i[u++]=255&c>>a)}if(a>=t||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return i},Nx=(r,e,t)=>{let n=e[e.length-1]==="=",s=(1<<t)-1,o="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>t;)i-=t,o+=e[s&a>>i];if(i&&(o+=e[s&a<<t-i]),n)for(;o.length*t&7;)o+="=";return o},me=({name:r,prefix:e,bitsPerChar:t,alphabet:n})=>Sn({prefix:e,name:r,encode(s){return Nx(s,n,t)},decode(s){return Rx(s,n,t,r)}})});var xu={};J(xu,{identity:()=>Lx});var Lx,U0=re(()=>{pt();fr();Lx=Sn({prefix:"\0",name:"identity",encode:r=>R0(r),decode:r=>_0(r)})});var Eu={};J(Eu,{base2:()=>Ux});var Ux,O0=re(()=>{pt();Ux=me({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1})});var vu={};J(vu,{base8:()=>Ox});var Ox,P0=re(()=>{pt();Ox=me({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3})});var Au={};J(Au,{base10:()=>Px});var Px,M0=re(()=>{pt();Px=hr({prefix:"9",name:"base10",alphabet:"0123456789"})});var Du={};J(Du,{base16:()=>Mx,base16upper:()=>Fx});var Mx,Fx,F0=re(()=>{pt();Mx=me({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Fx=me({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4})});var Bu={};J(Bu,{base32:()=>kn,base32hex:()=>$x,base32hexpad:()=>Wx,base32hexpadupper:()=>zx,base32hexupper:()=>qx,base32pad:()=>Hx,base32padupper:()=>Kx,base32upper:()=>Vx,base32z:()=>Gx});var kn,Vx,Hx,Kx,$x,qx,Wx,zx,Gx,Su=re(()=>{pt();kn=me({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Vx=me({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Hx=me({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Kx=me({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),$x=me({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),qx=me({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Wx=me({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),zx=me({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Gx=me({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5})});var ku={};J(ku,{base36:()=>jx,base36upper:()=>Yx});var jx,Yx,V0=re(()=>{pt();jx=hr({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Yx=hr({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"})});var Cu={};J(Cu,{base58btc:()=>Dt,base58flickr:()=>Zx});var Dt,Zx,Iu=re(()=>{pt();Dt=hr({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Zx=hr({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"})});var Tu={};J(Tu,{base64:()=>Xx,base64pad:()=>Jx,base64url:()=>Qx,base64urlpad:()=>e2});var Xx,Jx,Qx,e2,H0=re(()=>{pt();Xx=me({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Jx=me({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Qx=me({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),e2=me({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6})});var _u={};J(_u,{base256emoji:()=>o2});function n2(r){return r.reduce((e,t)=>(e+=t2[t],e),"")}function s2(r){let e=[];for(let t of r){let n=r2[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var K0,t2,r2,o2,$0=re(()=>{pt();K0=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}"),t2=K0.reduce((r,e,t)=>(r[t]=e,r),[]),r2=K0.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);o2=Sn({prefix:"\u{1F680}",name:"base256emoji",encode:n2,decode:s2})});function z0(r,e,t){e=e||[],t=t||0;for(var n=t;r>=u2;)e[t++]=r&255|q0,r/=128;for(;r&c2;)e[t++]=r&255|q0,r>>>=7;return e[t]=r|0,z0.bytes=t-n+1,e}function Ru(r,n){var t=0,n=n||0,s=0,o=n,i,a=r.length;do{if(o>=a)throw Ru.bytes=0,new RangeError("Could not decode varint");i=r[o++],t+=s<28?(i&W0)<<s:(i&W0)*Math.pow(2,s),s+=7}while(i>=f2);return Ru.bytes=o-n,t}var i2,q0,a2,c2,u2,l2,f2,W0,h2,d2,p2,m2,g2,b2,y2,w2,x2,E2,v2,A2,ys,G0=re(()=>{i2=z0,q0=128,a2=127,c2=~a2,u2=Math.pow(2,31);l2=Ru,f2=128,W0=127;h2=Math.pow(2,7),d2=Math.pow(2,14),p2=Math.pow(2,21),m2=Math.pow(2,28),g2=Math.pow(2,35),b2=Math.pow(2,42),y2=Math.pow(2,49),w2=Math.pow(2,56),x2=Math.pow(2,63),E2=function(r){return r<h2?1:r<d2?2:r<p2?3:r<m2?4:r<g2?5:r<b2?6:r<y2?7:r<w2?8:r<x2?9:10},v2={encode:i2,decode:l2,encodingLength:E2},A2=v2,ys=A2});var ws,Cn,In,Ii=re(()=>{G0();ws=(r,e=0)=>[ys.decode(r,e),ys.decode.bytes],Cn=(r,e,t=0)=>(ys.encode(r,e,t),e),In=r=>ys.encodingLength(r)});var Fr,j0,Y0,Tn,Es=re(()=>{fr();Ii();Fr=(r,e)=>{let t=e.byteLength,n=In(r),s=n+In(t),o=new Uint8Array(s+t);return Cn(r,o,0),Cn(t,o,n),o.set(e,s),new Tn(r,t,e,o)},j0=r=>{let e=zt(r),[t,n]=ws(e),[s,o]=ws(e.subarray(n)),i=e.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new Tn(t,s,i,e)},Y0=(r,e)=>r===e?!0:r.code===e.code&&r.size===e.size&&T0(r.bytes,e.bytes),Tn=class{constructor(e,t,n,s){this.code=e,this.size=t,this.digest=n,this.bytes=s}}});var Lu,Nu,Uu=re(()=>{Es();Lu=({name:r,code:e,encode:t})=>new Nu(r,e,t),Nu=class{constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?Fr(this.code,t):t.then(n=>Fr(this.code,n))}else throw Error("Unknown type, must be binary type")}}});var Ou={};J(Ou,{sha256:()=>D2,sha512:()=>B2});var X0,D2,B2,J0=re(()=>{Uu();X0=r=>async e=>new Uint8Array(await crypto.subtle.digest(r,e)),D2=Lu({name:"sha2-256",code:18,encode:X0("SHA-256")}),B2=Lu({name:"sha2-512",code:19,encode:X0("SHA-512")})});var Pu={};J(Pu,{identity:()=>C2});var Q0,S2,ep,k2,C2,tp=re(()=>{fr();Es();Q0=0,S2="identity",ep=zt,k2=r=>Fr(Q0,ep(r)),C2={code:Q0,name:S2,encode:ep,digest:k2}});var rp=re(()=>{fr()});var Kk,$k,np=re(()=>{Kk=new TextEncoder,$k=new TextDecoder});var Ri,_2,R2,N2,vs,L2,sp,op,Ti,_i,U2,O2,P2,ip=re(()=>{Ii();Es();Iu();Su();fr();Ri=class r{constructor(e,t,n,s){this.code=t,this.version=e,this.multihash=n,this.bytes=s,this.byteOffset=s.byteOffset,this.byteLength=s.byteLength,this.asCID=this,this._baseCache=new Map,Object.defineProperties(this,{byteOffset:_i,byteLength:_i,code:Ti,version:Ti,multihash:Ti,bytes:Ti,_baseCache:_i,asCID:_i})}toV0(){switch(this.version){case 0:return this;default:{let{code:e,multihash:t}=this;if(e!==vs)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==L2)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=Fr(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}equals(e){return e&&this.code===e.code&&this.version===e.version&&Y0(this.multihash,e.multihash)}toString(e){let{bytes:t,version:n,_baseCache:s}=this;switch(n){case 0:return R2(t,s,e||Dt.encoder);default:return N2(t,s,e||kn.encoder)}}toJSON(){return{code:this.code,version:this.version,hash:this.multihash.bytes}}get[Symbol.toStringTag](){return"CID"}[Symbol.for("nodejs.util.inspect.custom")](){return"CID("+this.toString()+")"}static isCID(e){return O2(/^0\.0/,P2),!!(e&&(e[op]||e.asCID===e))}get toBaseEncodedString(){throw new Error("Deprecated, use .toString()")}get codec(){throw new Error('"codec" property is deprecated, use integer "code" property instead')}get buffer(){throw new Error("Deprecated .buffer property, use .bytes to get Uint8Array instead")}get multibaseName(){throw new Error('"multibaseName" property is deprecated')}get prefix(){throw new Error('"prefix" property is deprecated')}static asCID(e){if(e instanceof r)return e;if(e!=null&&e.asCID===e){let{version:t,code:n,multihash:s,bytes:o}=e;return new r(t,n,s,o||sp(t,n,s.bytes))}else if(e!=null&&e[op]===!0){let{version:t,multihash:n,code:s}=e,o=j0(n);return r.create(t,s,o)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");switch(e){case 0:{if(t!==vs)throw new Error(`Version 0 CID must use dag-pb (code: ${vs}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let s=sp(e,t,n.bytes);return new r(e,t,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,vs,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,s=zt(e.subarray(n,n+t.multihashSize));if(s.byteLength!==t.multihashSize)throw new Error("Incorrect length");let o=s.subarray(t.multihashSize-t.digestSize),i=new Tn(t.multihashCode,t.digestSize,o,s);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[f,m]=ws(e.subarray(t));return t+=m,f},s=n(),o=vs;if(s===18?(s=0,t=0):s===1&&(o=n()),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=t,a=n(),c=n(),u=t+c,l=u-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,t){let[n,s]=_2(e,t),o=r.decode(s);return o._baseCache.set(n,e),o}},_2=(r,e)=>{switch(r[0]){case"Q":{let t=e||Dt;return[Dt.prefix,t.decode(`${Dt.prefix}${r}`)]}case Dt.prefix:{let t=e||Dt;return[Dt.prefix,t.decode(r)]}case kn.prefix:{let t=e||kn;return[kn.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}},R2=(r,e,t)=>{let{prefix:n}=t;if(n!==Dt.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let s=e.get(n);if(s==null){let o=t.encode(r).slice(1);return e.set(n,o),o}else return s},N2=(r,e,t)=>{let{prefix:n}=t,s=e.get(n);if(s==null){let o=t.encode(r);return e.set(n,o),o}else return s},vs=112,L2=18,sp=(r,e,t)=>{let n=In(r),s=n+In(e),o=new Uint8Array(s+t.byteLength);return Cn(r,o,0),Cn(e,o,n),o.set(t,s),o},op=Symbol.for("@ipld/js-cid/CID"),Ti={writable:!1,configurable:!1,enumerable:!0},_i={writable:!1,enumerable:!1,configurable:!1},U2="0.0.0-dev",O2=(r,e)=>{if(r.test(U2))console.warn(e);else throw new Error(e)},P2=`CID.isCID(v) is deprecated and will be removed in the next major release.
3
3
  Following code pattern:
4
4
 
5
5
  if (CID.isCID(value)) {
@@ -13,12 +13,12 @@ if (cid) {
13
13
  // Make sure to use cid instead of value
14
14
  doSomethingWithCID(cid)
15
15
  }
16
- `});var op=te(()=>{sp();Si();lr();Nu();ws()});var Ou,zk,ip=te(()=>{N0();L0();U0();O0();P0();Du();M0();ku();F0();H0();Z0();Q0();ep();tp();op();Ou={...yu,...wu,...xu,...Eu,...vu,...Au,...Bu,...Su,...Cu,...Iu},zk={...Lu,...Uu}});function Cn(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}var Ti=te(()=>{});function _i(r=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?Cn(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}var Pu=te(()=>{Ti()});function cp(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var ap,Mu,P2,Ri,Fu=te(()=>{ip();Pu();ap=cp("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Mu=cp("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=_i(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),P2={utf8:ap,"utf-8":ap,hex:Ou.base16,latin1:Mu,ascii:Mu,binary:Mu,...Ou},Ri=P2});var up={};J(up,{toString:()=>M2});function M2(r,e="utf8"){let t=Ri[e];if(!t)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var lp=te(()=>{Fu()});var fp={};J(fp,{fromString:()=>F2});function F2(r,e="utf8"){let t=Ri[e];if(!t)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?Cn(globalThis.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}var hp=te(()=>{Fu();Ti()});var dp={};J(dp,{concat:()=>V2});function V2(r,e){e||(e=r.reduce((s,o)=>s+o.length,0));let t=_i(e),n=0;for(let s of r)t.set(s,n),n+=s.length;return Cn(t)}var pp=te(()=>{Pu();Ti()});var Hu=Ve((o6,xp)=>{"use strict";var mp=h0(),In=A0(),{names:Es}=B0(),{toString:Ni}=(lp(),Ds(up)),{fromString:H2}=(hp(),Ds(fp)),{concat:K2}=(pp(),Ds(dp)),Tn={};for(let r in Es){let e=r;Tn[Es[e]]=e}Object.freeze(Tn);function $2(r){if(!(r instanceof Uint8Array))throw new Error("must be passed a Uint8Array");return Ni(r,"base16")}function q2(r){return H2(r,"base16")}function W2(r){if(!(r instanceof Uint8Array))throw new Error("must be passed a Uint8Array");return Ni(mp.encode("base58btc",r)).slice(1)}function z2(r){let e=r instanceof Uint8Array?Ni(r):r;return mp.decode("z"+e)}function gp(r){if(!(r instanceof Uint8Array))throw new Error("multihash must be a Uint8Array");if(r.length<2)throw new Error("multihash too short. must be > 2 bytes.");let e=In.decode(r);if(!yp(e))throw new Error(`multihash unknown function code: 0x${e.toString(16)}`);r=r.slice(In.decode.bytes);let t=In.decode(r);if(t<0)throw new Error(`multihash invalid length: ${t}`);if(r=r.slice(In.decode.bytes),r.length!==t)throw new Error(`multihash length inconsistent: 0x${Ni(r,"base16")}`);return{code:e,name:Tn[e],length:t,digest:r}}function G2(r,e,t){if(!r||e===void 0)throw new Error("multihash encode requires at least two args: digest, code");let n=bp(e);if(!(r instanceof Uint8Array))throw new Error("digest should be a Uint8Array");if(t==null&&(t=r.length),t&&r.length!==t)throw new Error("digest length should be equal to specified length.");let s=In.encode(n),o=In.encode(t);return K2([s,o,r],s.length+o.length+r.length)}function bp(r){let e=r;if(typeof r=="string"){if(Es[r]===void 0)throw new Error(`Unrecognized hash function named: ${r}`);e=Es[r]}if(typeof e!="number")throw new Error(`Hash function code should be a number. Got: ${e}`);if(Tn[e]===void 0&&!Vu(e))throw new Error(`Unrecognized function code: ${e}`);return e}function Vu(r){return r>0&&r<16}function yp(r){return!!(Vu(r)||Tn[r])}function wp(r){gp(r)}function j2(r){return wp(r),r.subarray(0,2)}xp.exports={names:Es,codes:Tn,toHexString:$2,fromHexString:q2,toB58String:W2,fromB58String:z2,decode:gp,encode:G2,coerceCode:bp,isAppCode:Vu,validate:wp,prefix:j2,isValidCode:yp}});var s1={};J(s1,{webRTC:()=>n1,webRTCDirect:()=>r1});var el=Symbol.for("@libp2p/peer-id");var Bs=Symbol.for("@libp2p/transport");var tl;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(tl||(tl={}));var N=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var Ss=(r,...e)=>{try{[...e]}catch{}};var ks=class extends EventTarget{#e=new Map;constructor(){super(),Ss(1/0,this)}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let s=this.#e.get(e);s==null&&(s=[],this.#e.set(e,s)),s.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let s=this.#e.get(e);s!=null&&(s=s.filter(({callback:o})=>o!==t),this.#e.set(e,s))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:s})=>!s),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new Kp(e,t))}},Pi=class extends Event{detail;constructor(e,t){super(e,t),this.detail=t?.detail}},Kp=globalThis.CustomEvent??Pi;var Ki={};J(Ki,{base58btc:()=>pe,base58flickr:()=>jp});var h1=new Uint8Array(0);function rl(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function St(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function nl(r){return new TextEncoder().encode(r)}function sl(r){return new TextDecoder().decode(r)}function $p(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var s=0;s<r.length;s++){var o=r.charAt(s),i=o.charCodeAt(0);if(t[i]!==255)throw new TypeError(o+" is ambiguous");t[i]=s}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var h=0,p=0,y=0,x=d.length;y!==x&&d[y]===0;)y++,h++;for(var b=(x-y)*l+1>>>0,v=new Uint8Array(b);y!==x;){for(var E=d[y],A=0,S=b-1;(E!==0||A<p)&&S!==-1;S--,A++)E+=256*v[S]>>>0,v[S]=E%a>>>0,E=E/a>>>0;if(E!==0)throw new Error("Non-zero carry");p=A,y++}for(var D=b-p;D!==b&&v[D]===0;)D++;for(var _=c.repeat(h);D<b;++D)_+=r.charAt(v[D]);return _}function m(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var h=0;if(d[h]!==" "){for(var p=0,y=0;d[h]===c;)p++,h++;for(var x=(d.length-h)*u+1>>>0,b=new Uint8Array(x);d[h];){var v=t[d.charCodeAt(h)];if(v===255)return;for(var E=0,A=x-1;(v!==0||E<y)&&A!==-1;A--,E++)v+=a*b[A]>>>0,b[A]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");y=E,h++}if(d[h]!==" "){for(var S=x-y;S!==x&&b[S]===0;)S++;for(var D=new Uint8Array(p+(x-S)),_=p;S!==x;)D[_++]=b[S++];return D}}}function g(d){var h=m(d);if(h)return h;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:m,decode:g}}var qp=$p,Wp=qp,il=Wp;var Mi=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Fi=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return al(this,e)}},Vi=class{decoders;constructor(e){this.decoders=e}or(e){return al(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function al(r,e){return new Vi({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Hi=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,s){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=s,this.encoder=new Mi(e,t,n),this.decoder=new Fi(e,t,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Fr({name:r,prefix:e,encode:t,decode:n}){return new Hi(r,e,t,n)}function Gt({name:r,prefix:e,alphabet:t}){let{encode:n,decode:s}=il(t,r);return Fr({prefix:e,name:r,encode:n,decode:o=>St(s(o))})}function zp(r,e,t,n){let s={};for(let l=0;l<e.length;++l)s[e[l]]=l;let o=r.length;for(;r[o-1]==="=";)--o;let i=new Uint8Array(o*t/8|0),a=0,c=0,u=0;for(let l=0;l<o;++l){let f=s[r[l]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|f,a+=t,a>=8&&(a-=8,i[u++]=255&c>>a)}if(a>=t||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return i}function Gp(r,e,t){let n=e[e.length-1]==="=",s=(1<<t)-1,o="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>t;)i-=t,o+=e[s&a>>i];if(i!==0&&(o+=e[s&a<<t-i]),n)for(;o.length*t&7;)o+="=";return o}function fe({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return Fr({prefix:e,name:r,encode(s){return Gp(s,n,t)},decode(s){return zp(s,n,t,r)}})}var pe=Gt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),jp=Gt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var $i={};J($i,{base10:()=>Yp});var Yp=Gt({prefix:"9",name:"base10",alphabet:"0123456789"});var qi={};J(qi,{base16:()=>Zp,base16upper:()=>Xp});var Zp=fe({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Xp=fe({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Wi={};J(Wi,{base2:()=>Jp});var Jp=fe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var zi={};J(zi,{base256emoji:()=>nm});var cl=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}"),Qp=cl.reduce((r,e,t)=>(r[t]=e,r),[]),em=cl.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function tm(r){return r.reduce((e,t)=>(e+=Qp[t],e),"")}function rm(r){let e=[];for(let t of r){let n=em[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var nm=Fr({prefix:"\u{1F680}",name:"base256emoji",encode:tm,decode:rm});var Gi={};J(Gi,{base32:()=>kt,base32hex:()=>am,base32hexpad:()=>um,base32hexpadupper:()=>lm,base32hexupper:()=>cm,base32pad:()=>om,base32padupper:()=>im,base32upper:()=>sm,base32z:()=>fm});var kt=fe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),sm=fe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),om=fe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),im=fe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),am=fe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),cm=fe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),um=fe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),lm=fe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),fm=fe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ji={};J(ji,{base36:()=>hm,base36upper:()=>dm});var hm=Gt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),dm=Gt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Xi={};J(Xi,{base64:()=>Yi,base64pad:()=>pm,base64url:()=>Zi,base64urlpad:()=>mm});var Yi=fe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),pm=fe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Zi=fe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),mm=fe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ji={};J(Ji,{base8:()=>gm});var gm=fe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Qi={};J(Qi,{identity:()=>bm});var bm=Fr({prefix:"\0",name:"identity",encode:r=>sl(r),decode:r=>nl(r)});var C1=new TextEncoder,I1=new TextDecoder;var ta={};J(ta,{identity:()=>jt});var xm=fl,ul=128,Em=127,vm=~Em,Am=Math.pow(2,31);function fl(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Am;)e[t++]=r&255|ul,r/=128;for(;r&vm;)e[t++]=r&255|ul,r>>>=7;return e[t]=r|0,fl.bytes=t-n+1,e}var Dm=ea,Bm=128,ll=127;function ea(r,n){var t=0,n=n||0,s=0,o=n,i,a=r.length;do{if(o>=a)throw ea.bytes=0,new RangeError("Could not decode varint");i=r[o++],t+=s<28?(i&ll)<<s:(i&ll)*Math.pow(2,s),s+=7}while(i>=Bm);return ea.bytes=o-n,t}var Sm=Math.pow(2,7),km=Math.pow(2,14),Cm=Math.pow(2,21),Im=Math.pow(2,28),Tm=Math.pow(2,35),_m=Math.pow(2,42),Rm=Math.pow(2,49),Nm=Math.pow(2,56),Lm=Math.pow(2,63),Um=function(r){return r<Sm?1:r<km?2:r<Cm?3:r<Im?4:r<Tm?5:r<_m?6:r<Rm?7:r<Nm?8:r<Lm?9:10},Om={encode:xm,decode:Dm,encodingLength:Um},Pm=Om,Rn=Pm;function Nn(r,e=0){return[Rn.decode(r,e),Rn.decode.bytes]}function Vr(r,e,t=0){return Rn.encode(r,e,t),e}function Hr(r){return Rn.encodingLength(r)}function pt(r,e){let t=e.byteLength,n=Hr(r),s=n+Hr(t),o=new Uint8Array(s+t);return Vr(r,o,0),Vr(t,o,n),o.set(e,s),new Kr(r,t,e,o)}function dr(r){let e=St(r),[t,n]=Nn(e),[s,o]=Nn(e.subarray(n)),i=e.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new Kr(t,s,i,e)}function hl(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&rl(r.bytes,t.bytes)}}var Kr=class{code;size;digest;bytes;constructor(e,t,n,s){this.code=e,this.size=t,this.digest=n,this.bytes=s}};var dl=0,Mm="identity",pl=St;function Fm(r){return pt(dl,pl(r))}var jt={code:dl,name:Mm,encode:pl,digest:Fm};var sa={};J(sa,{sha256:()=>Te,sha512:()=>Vm});function na({name:r,code:e,encode:t}){return new ra(r,e,t)}var ra=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?pt(this.code,t):t.then(n=>pt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function gl(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Te=na({name:"sha2-256",code:18,encode:gl("SHA-256")}),Vm=na({name:"sha2-512",code:19,encode:gl("SHA-512")});function bl(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Km(t,oa(r),e??pe.encoder);default:return $m(t,oa(r),e??kt.encoder)}}var yl=new WeakMap;function oa(r){let e=yl.get(r);if(e==null){let t=new Map;return yl.set(r,t),t}return e}var Je=class r{code;version;multihash;bytes;"/";constructor(e,t,n,s){this.code=t,this.version=e,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:e,multihash:t}=this;if(e!==Ln)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==qm)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=pt(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&hl(e.multihash,n.multihash)}toString(e){return bl(this,e)}toJSON(){return{"/":bl(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:s,multihash:o,bytes:i}=t;return new r(n,s,o,i??wl(n,s,o.bytes))}else if(t[Wm]===!0){let{version:n,multihash:s,code:o}=t,i=dr(s);return r.create(n,o,i)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==Ln)throw new Error(`Version 0 CID must use dag-pb (code: ${Ln}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let s=wl(e,t,n.bytes);return new r(e,t,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Ln,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,s=St(e.subarray(n,n+t.multihashSize));if(s.byteLength!==t.multihashSize)throw new Error("Incorrect length");let o=s.subarray(t.multihashSize-t.digestSize),i=new Kr(t.multihashCode,t.digestSize,o,s);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[f,m]=Nn(e.subarray(t));return t+=m,f},s=n(),o=Ln;if(s===18?(s=0,t=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=t,a=n(),c=n(),u=t+c,l=u-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,t){let[n,s]=Hm(e,t),o=r.decode(s);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return oa(o).set(n,e),o}};function Hm(r,e){switch(r[0]){case"Q":{let t=e??pe;return[pe.prefix,t.decode(`${pe.prefix}${r}`)]}case pe.prefix:{let t=e??pe;return[pe.prefix,t.decode(r)]}case kt.prefix:{let t=e??kt;return[kt.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Km(r,e,t){let{prefix:n}=t;if(n!==pe.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let s=e.get(n);if(s==null){let o=t.encode(r).slice(1);return e.set(n,o),o}else return s}function $m(r,e,t){let{prefix:n}=t,s=e.get(n);if(s==null){let o=t.encode(r);return e.set(n,o),o}else return s}var Ln=112,qm=18;function wl(r,e,t){let n=Hr(r),s=n+Hr(e),o=new Uint8Array(s+t.byteLength);return Vr(r,o,0),Vr(e,o,n),o.set(t,s),o}var Wm=Symbol.for("@ipld/js-cid/CID");var mt={...Qi,...Wi,...Ji,...$i,...qi,...Gi,...ji,...Ki,...Xi,...zi},Z1={...sa,...ta};function ve(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}var zm=Symbol.for("nodejs.util.inspect.custom"),xl=Object.values(mt).map(r=>r.decoder).reduce((r,e)=>r.or(e),mt.identity.decoder),El=114,ia=36,aa=37,Un=class{type;multihash;privateKey;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,this.privateKey=e.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[el]=!0;toString(){return this.string==null&&(this.string=pe.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return Je.createV1(El,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return ve(this.multihash.bytes,e);if(typeof e=="string")return mr(e).equals(this);if(e?.multihash?.bytes!=null)return ve(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[zm](){return`PeerId(${this.toString()})`}},$r=class extends Un{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},qr=class extends Un{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}},Wr=class extends Un{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}};function mr(r,e){if(e=e??xl,r.charAt(0)==="1"||r.charAt(0)==="Q"){let t=dr(pe.decode(`z${r}`));return r.startsWith("12D")?new qr({multihash:t}):r.startsWith("16U")?new Wr({multihash:t}):new $r({multihash:t})}return Gm(xl.decode(r))}function Gm(r){try{let e=dr(r);if(e.code===jt.code){if(e.digest.length===ia)return new qr({multihash:e});if(e.digest.length===aa)return new Wr({multihash:e})}if(e.code===Te.code)return new $r({multihash:e})}catch{return jm(Je.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function jm(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==El)throw new Error("Supplied PeerID CID is invalid");let e=r.multihash;if(e.code===Te.code)return new $r({multihash:r.multihash});if(e.code===jt.code){if(e.digest.length===ia)return new qr({multihash:r.multihash});if(e.digest.length===aa)return new Wr({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function ca(r,e){return r.length===ia?new qr({multihash:pt(jt.code,r),privateKey:e}):r.length===aa?new Wr({multihash:pt(jt.code,r),privateKey:e}):new $r({multihash:await Te.digest(r),publicKey:r,privateKey:e})}function Ae(r=0){return new Uint8Array(r)}function De(r=0){return new Uint8Array(r)}function Al(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var vl=Al("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ua=Al("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=De(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Zm={utf8:vl,"utf-8":vl,hex:mt.base16,latin1:ua,ascii:ua,binary:ua,...mt},Is=Zm;function z(r,e="utf8"){let t=Is[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var Xm=Math.pow(2,7),Jm=Math.pow(2,14),Qm=Math.pow(2,21),la=Math.pow(2,28),fa=Math.pow(2,35),ha=Math.pow(2,42),da=Math.pow(2,49),re=128,Ue=127;function ye(r){if(r<Xm)return 1;if(r<Jm)return 2;if(r<Qm)return 3;if(r<la)return 4;if(r<fa)return 5;if(r<ha)return 6;if(r<da)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function pa(r,e,t=0){switch(ye(r)){case 8:e[t++]=r&255|re,r/=128;case 7:e[t++]=r&255|re,r/=128;case 6:e[t++]=r&255|re,r/=128;case 5:e[t++]=r&255|re,r/=128;case 4:e[t++]=r&255|re,r>>>=7;case 3:e[t++]=r&255|re,r>>>=7;case 2:e[t++]=r&255|re,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function eg(r,e,t=0){switch(ye(r)){case 8:e.set(t++,r&255|re),r/=128;case 7:e.set(t++,r&255|re),r/=128;case 6:e.set(t++,r&255|re),r/=128;case 5:e.set(t++,r&255|re),r/=128;case 4:e.set(t++,r&255|re),r>>>=7;case 3:e.set(t++,r&255|re),r>>>=7;case 2:e.set(t++,r&255|re),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function ma(r,e){let t=r[e],n=0;if(n+=t&Ue,t<re||(t=r[e+1],n+=(t&Ue)<<7,t<re)||(t=r[e+2],n+=(t&Ue)<<14,t<re)||(t=r[e+3],n+=(t&Ue)<<21,t<re)||(t=r[e+4],n+=(t&Ue)*la,t<re)||(t=r[e+5],n+=(t&Ue)*fa,t<re)||(t=r[e+6],n+=(t&Ue)*ha,t<re)||(t=r[e+7],n+=(t&Ue)*da,t<re))return n;throw new RangeError("Could not decode varint")}function tg(r,e){let t=r.get(e),n=0;if(n+=t&Ue,t<re||(t=r.get(e+1),n+=(t&Ue)<<7,t<re)||(t=r.get(e+2),n+=(t&Ue)<<14,t<re)||(t=r.get(e+3),n+=(t&Ue)<<21,t<re)||(t=r.get(e+4),n+=(t&Ue)*la,t<re)||(t=r.get(e+5),n+=(t&Ue)*fa,t<re)||(t=r.get(e+6),n+=(t&Ue)*ha,t<re)||(t=r.get(e+7),n+=(t&Ue)*da,t<re))return n;throw new RangeError("Could not decode varint")}function gt(r,e,t=0){return e==null&&(e=De(ye(r))),e instanceof Uint8Array?pa(r,e,t):eg(r,e,t)}function Qe(r,e=0){return r instanceof Uint8Array?ma(r,e):tg(r,e)}function we(r,e){e==null&&(e=r.reduce((s,o)=>s+o.length,0));let t=De(e),n=0;for(let s of r)t.set(s,n),n+=s.length;return t}var Ts=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,s){return this.readAtomically(()=>{let o=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*s)-1;for(;;){let l=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let m=Number.parseInt(f,e);if(!Number.isNaN(m))return m});if(l===void 0)break;if(o*=e,o+=l,o>u||(i+=1,t!==void 0&&i>t))return}if(i!==0)return!n&&c&&i>1?void 0:o})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let s=n*2;if(n<t.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return t[s]=i[0],t[s+1]=i[1],t[s+2]=i[2],t[s+3]=i[3],[s+4,!0]}let o=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(o===void 0)return[s,!1];t[s]=o>>8,t[s+1]=o&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,s]=e(t);if(n===16)return t;if(s||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let o=new Uint8Array(14),i=16-(n+2),[a]=e(o.subarray(0,i));return t.set(o.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Dl=45,ng=15,zr=new Ts;function ga(r){if(!(r.length>ng))return zr.new(r).parseWith(()=>zr.readIPv4Addr())}function ba(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Dl))return zr.new(r).parseWith(()=>zr.readIPv6Addr())}function _s(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Dl))return zr.new(r).parseWith(()=>zr.readIPAddr())}var SE=parseInt("0xFFFF",16),kE=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Q(r,e="utf8"){let t=Is[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function Rs(r){return!!ga(r)}function Ns(r){return!!ba(r)}function Ls(r){return!!_s(r)}var kl=Rs,cg=Ns,ya=function(r){let e=0;if(r=r.toString().trim(),kl(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(cg(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let o=kl(t[n]),i;o&&(i=ya(t[n]),t[n]=z(i.slice(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,z(i.slice(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let o=[n,1];for(n=9-t.length;n>0;n--)o.push("0");t.splice.apply(t,o)}let s=new Uint8Array(e+16);for(n=0;n<t.length;n++){let o=parseInt(t[n],16);s[e++]=o>>8&255,s[e++]=o&255}return s}throw new Error("invalid ip address")},Cl=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let s=[];for(let o=0;o<t;o++)s.push(r[e+o]);return s.join(".")}if(t===16){let s=[];for(let o=0;o<t;o+=2)s.push(n.getUint16(e+o).toString(16));return s.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var Gr={},wa={},lg=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[777,-1,"memory"]];lg.forEach(r=>{let e=fg(...r);wa[e.code]=e,Gr[e.name]=e});function fg(r,e,t,n,s){return{code:r,size:e,name:t,resolvable:!!n,path:!!s}}function ne(r){if(typeof r=="number"){if(wa[r]!=null)return wa[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Gr[r]!=null)return Gr[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var h8=ne("ip4"),d8=ne("ip6"),p8=ne("ipcidr");function Ea(r,e){switch(ne(r).code){case 4:case 41:return dg(e);case 42:return _l(e);case 6:case 273:case 33:case 132:return Nl(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return _l(e);case 421:return bg(e);case 444:return Rl(e);case 445:return Rl(e);case 466:return gg(e);default:return z(e,"base16")}}function va(r,e){switch(ne(r).code){case 4:return Il(e);case 41:return Il(e);case 42:return Tl(e);case 6:case 273:case 33:case 132:return Aa(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Tl(e);case 421:return pg(e);case 444:return yg(e);case 445:return wg(e);case 466:return mg(e);default:return Q(e,"base16")}}var xa=Object.values(mt).map(r=>r.decoder),hg=function(){let r=xa[0].or(xa[1]);return xa.slice(2).forEach(e=>r=r.or(e)),r}();function Il(r){if(!Ls(r))throw new Error("invalid ip address");return ya(r)}function dg(r){let e=Cl(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!Ls(e))throw new Error("invalid ip address");return e}function Aa(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function Nl(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Tl(r){let e=Q(r),t=Uint8Array.from(gt(e.length));return we([t,e],t.length+e.length)}function _l(r){let e=Qe(r);if(r=r.slice(ye(e)),r.length!==e)throw new Error("inconsistent lengths");return z(r)}function pg(r){let e;r[0]==="Q"||r[0]==="1"?e=dr(pe.decode(`z${r}`)).bytes:e=Je.parse(r).multihash.bytes;let t=Uint8Array.from(gt(e.length));return we([t,e],t.length+e.length)}function mg(r){let e=hg.decode(r),t=Uint8Array.from(gt(e.length));return we([t,e],t.length+e.length)}function gg(r){let e=Qe(r),t=r.slice(ye(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+z(t,"base64url")}function bg(r){let e=Qe(r),t=r.slice(ye(e));if(t.length!==e)throw new Error("inconsistent lengths");return z(t,"base58btc")}function yg(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=kt.decode("b"+e[0]),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let s=Aa(n);return we([t,s],t.length+s.length)}function wg(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let t=kt.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let s=Aa(n);return we([t,s],t.length+s.length)}function Rl(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=z(e,"base32"),s=Nl(t);return`${n}:${s}`}function Ll(r){r=Da(r);let e=[],t=[],n=null,s=r.split("/").slice(1);if(s.length===1&&s[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let o=0;o<s.length;o++){let i=s[o],a=ne(i);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(o++,o>=s.length)throw Ol("invalid address: "+r);if(a.path===!0){n=Da(s.slice(o).join("/")),e.push([a.code,va(a.code,n)]),t.push([a.code,n]);break}let c=va(a.code,s[o]);e.push([a.code,c]),t.push([a.code,Ea(a.code,c)])}return{string:Ul(t),bytes:Sa(e),tuples:e,stringTuples:t,path:n}}function Ba(r){let e=[],t=[],n=null,s=0;for(;s<r.length;){let o=Qe(r,s),i=ye(o),a=ne(o),c=xg(a,r.slice(s+i));if(c===0){e.push([o]),t.push([o]),s+=i;continue}let u=r.slice(s+i,s+i+c);if(s+=c+i,s>r.length)throw Ol("Invalid address Uint8Array: "+z(r,"base16"));e.push([o,u]);let l=Ea(o,u);if(t.push([o,l]),a.path===!0){n=l;break}}return{bytes:Uint8Array.from(r),string:Ul(t),tuples:e,stringTuples:t,path:n}}function Ul(r){let e=[];return r.map(t=>{let n=ne(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),Da(e.join("/"))}function Sa(r){return we(r.map(e=>{let t=ne(e[0]),n=Uint8Array.from(gt(t.code));return e.length>1&&e[1]!=null&&(n=we([n,e[1]])),n}))}function xg(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=Qe(e instanceof Uint8Array?e:Uint8Array.from(e));return t+ye(t)}}function Da(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function Ol(r){return new Error("Error parsing address: "+r)}var Eg=Symbol.for("nodejs.util.inspect.custom"),ka=Symbol.for("@multiformats/js-multiaddr/multiaddr"),vg=[ne("dns").code,ne("dns4").code,ne("dns6").code,ne("dnsaddr").code],Us=class r{bytes;#e;#t;#r;#n;[ka]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=Ba(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=Ll(e)}else if(Ml(e))t=Ba(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#r=t.stringTuples,this.#n=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,s,o="",i=ne("tcp"),a=ne("udp"),c=ne("ip4"),u=ne("ip6"),l=ne("dns6"),f=ne("ip6zone");for(let[g,d]of this.stringTuples())g===f.code&&(o=`%${d??""}`),vg.includes(g)&&(t=i.name,s=443,n=`${d??""}${o}`,e=g===l.code?6:4),(g===i.code||g===a.code)&&(t=ne(g).name,s=parseInt(d??"")),(g===c.code||g===u.code)&&(t=ne(g).name,n=`${d??""}${o}`,e=g===u.code?6:4);if(e==null||t==null||n==null||s==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:s}}protos(){return this.#t.map(([e])=>Object.assign({},ne(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>ne(e).name)}tuples(){return this.#t}stringTuples(){return this.#r}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),s=n.lastIndexOf(t);if(s<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,s))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(Sa(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,s])=>{n===Gr.p2p.code&&e.push([n,s]),n===Gr["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?z(pe.decode(`z${n}`),"base58btc"):z(Je.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return ve(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(o=>o.resolvable);if(t==null)return[this];let n=Pl.get(t.name);if(n==null)throw new N(`no available resolver for ${t.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,e)).map(o=>et(o))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[Eg](){return`Multiaddr(${this.#e})`}};var Pl=new Map;function Ml(r){return!!r?.[ka]}function et(r){return new Us(r)}var Ag=r=>r.toString().split("/").slice(1),Pn=r=>({match:e=>e.length<1?!1:r(e[0])?e.slice(1):!1,pattern:"fn"}),me=r=>({match:e=>Pn(t=>t===r).match(e),pattern:r}),Ms=()=>({match:r=>Pn(e=>typeof e=="string").match(r),pattern:"{string}"}),Fl=()=>({match:r=>Pn(e=>!isNaN(parseInt(e))).match(r),pattern:"{number}"}),Ge=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{pe.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),Os=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{Zi.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),bt=r=>({match:e=>{let t=r.match(e);return t===!1?e:t},pattern:`optional(${r.pattern})`}),yt=(...r)=>({match:e=>{let t;for(let n of r){let s=n.match(e);s!==!1&&(t==null||s.length<t.length)&&(t=s)}return t??!1},pattern:`or(${r.map(e=>e.pattern).join(", ")})`}),ge=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e},pattern:`and(${r.map(e=>e.pattern).join(", ")})`});function Be(...r){function e(s){let o=Ag(s);for(let i of r){let a=i.match(o);if(a===!1)return!1;o=a}return o}function t(s){return e(s)!==!1}function n(s){let o=e(s);return o===!1?!1:o.length===0}return{matches:t,exactMatch:n}}var Ia=ge(me("dns4"),Ms()),Ta=ge(me("dns6"),Ms()),_a=ge(me("dnsaddr"),Ms()),Vl=ge(me("dns"),Ms()),$8=Be(Ia),q8=Be(Ta),W8=Be(_a),z8=Be(yt(Vl,_a,Ia,Ta)),Hl=ge(me("ip4"),Pn(Rs)),Kl=ge(me("ip6"),Pn(Ns)),$l=yt(Hl,Kl),Mn=yt($l,Vl,Ia,Ta,_a),G8=Be(Mn),j8=Be(Hl),Y8=Be(Kl),Z8=Be($l),Fs=ge(Mn,me("tcp"),Fl()),Fn=ge(Mn,me("udp"),Fl()),Dg=yt(Fs,Fn),X8=Be(Fs),J8=Be(Fn),Ra=ge(Fn,me("quic")),Vs=ge(Fn,me("quic-v1")),Bg=yt(Ra,Vs),Q8=Be(Ra),ev=Be(Vs),Ca=yt(Mn,Fs,Fn,Ra,Vs),ql=yt(ge(Ca,me("ws"),bt(Ge()))),tv=Be(ql),Wl=yt(ge(Ca,me("wss"),bt(Ge())),ge(Ca,me("tls"),me("ws"),bt(Ge()))),rv=Be(Wl),zl=ge(Dg,me("webrtc-direct"),Os(),bt(Os()),bt(Ge())),Gl=Be(zl),jl=ge(Vs,me("webtransport"),Os(),Os(),bt(Ge())),nv=Be(jl),Ps=yt(ql,Wl,ge(Fs,bt(Ge())),ge(Bg,bt(Ge())),ge(Mn,bt(Ge())),zl,jl,Ge()),sv=Be(Ps),Sg=ge(Ps,me("p2p-circuit"),Ge()),ov=Be(Sg),kg=yt(ge(Ps,me("p2p-circuit"),me("webrtc"),Ge()),ge(Ps,me("webrtc"),bt(Ge())),me("webrtc")),Yl=Be(kg);var qe;(function(r){r.ERR_ALREADY_ABORTED="ERR_ALREADY_ABORTED",r.ERR_DATA_CHANNEL="ERR_DATA_CHANNEL",r.ERR_CONNECTION_CLOSED="ERR_CONNECTION_CLOSED",r.ERR_HASH_NOT_SUPPORTED="ERR_HASH_NOT_SUPPORTED",r.ERR_INVALID_MULTIADDR="ERR_INVALID_MULTIADDR",r.ERR_INVALID_FINGERPRINT="ERR_INVALID_FINGERPRINT",r.ERR_INVALID_PARAMETERS="ERR_INVALID_PARAMETERS",r.ERR_NOT_IMPLEMENTED="ERR_NOT_IMPLEMENTED",r.ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS="ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS",r.ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS="ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS"})(qe||(qe={}));var Yt=class extends N{constructor(e,t){super(`WebRTC transport error: ${e}`,t??""),this.name="WebRTCTransportError"}};var Na=class extends Yt{constructor(e,t){super(`[stream: ${e}] data channel error: ${t}`,qe.ERR_DATA_CHANNEL),this.name="WebRTC/DataChannelError"}};function Fa(r,e){return new Na(r,e)}var La=class extends Yt{constructor(e){super(`There was a problem with the Multiaddr which was passed in: ${e}`,qe.ERR_INVALID_MULTIADDR),this.name="WebRTC/InappropriateMultiaddrError"}};function Hs(r){return new La(r)}var Ua=class extends Yt{constructor(e){super(`There was a problem with a provided argument: ${e}`,qe.ERR_INVALID_PARAMETERS),this.name="WebRTC/InvalidArgumentError"}};function Vn(r){return new Ua(r)}var Oa=class extends Yt{constructor(e,t){super(`Invalid fingerprint "${e}" within ${t}`,qe.ERR_INVALID_FINGERPRINT),this.name="WebRTC/InvalidFingerprintError"}};function Va(r,e){return new Oa(r,e)}var Pa=class extends Yt{constructor(e){super(`A method (${e}) was called though it has been intentionally left unimplemented.`,qe.ERR_NOT_IMPLEMENTED),this.name="WebRTC/UnimplementedError"}};function Zl(r){return new Pa(r)}var Ma=class extends Yt{constructor(e){super(`unsupported hash algorithm: ${e}`,qe.ERR_HASH_NOT_SUPPORTED),this.name="WebRTC/UnsupportedHashAlgorithmError"}};function Xl(r){return new Ma(r)}var Jl=function(r,e,t){if(t||arguments.length===2)for(var n=0,s=e.length,o;n<s;n++)(o||!(n in e))&&(o||(o=Array.prototype.slice.call(e,0,n)),o[n]=e[n]);return r.concat(o||Array.prototype.slice.call(e))},Cg=function(){function r(e,t,n){this.name=e,this.version=t,this.os=n,this.type="browser"}return r}();var Ig=function(){function r(e){this.version=e,this.type="node",this.name="node",this.os=process.platform}return r}();var Tg=function(){function r(e,t,n,s){this.name=e,this.version=t,this.os=n,this.bot=s,this.type="bot-device"}return r}();var _g=function(){function r(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null}return r}();var Rg=function(){function r(){this.type="react-native",this.name="react-native",this.version=null,this.os=null}return r}();var Ng=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,Lg=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,Ql=3,Ug=[["aol",/AOLShield\/([0-9\._]+)/],["edge",/Edge\/([0-9\._]+)/],["edge-ios",/EdgiOS\/([0-9\._]+)/],["yandexbrowser",/YaBrowser\/([0-9\._]+)/],["kakaotalk",/KAKAOTALK\s([0-9\.]+)/],["samsung",/SamsungBrowser\/([0-9\.]+)/],["silk",/\bSilk\/([0-9._-]+)\b/],["miui",/MiuiBrowser\/([0-9\.]+)$/],["beaker",/BeakerBrowser\/([0-9\.]+)/],["edge-chromium",/EdgA?\/([0-9\.]+)/],["chromium-webview",/(?!Chrom.*OPR)wv\).*Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["chrome",/(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["phantomjs",/PhantomJS\/([0-9\.]+)(:?\s|$)/],["crios",/CriOS\/([0-9\.]+)(:?\s|$)/],["firefox",/Firefox\/([0-9\.]+)(?:\s|$)/],["fxios",/FxiOS\/([0-9\.]+)/],["opera-mini",/Opera Mini.*Version\/([0-9\.]+)/],["opera",/Opera\/([0-9\.]+)(?:\s|$)/],["opera",/OPR\/([0-9\.]+)(:?\s|$)/],["pie",/^Microsoft Pocket Internet Explorer\/(\d+\.\d+)$/],["pie",/^Mozilla\/\d\.\d+\s\(compatible;\s(?:MSP?IE|MSInternet Explorer) (\d+\.\d+);.*Windows CE.*\)$/],["netfront",/^Mozilla\/\d\.\d+.*NetFront\/(\d.\d)/],["ie",/Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/],["ie",/MSIE\s([0-9\.]+);.*Trident\/[4-7].0/],["ie",/MSIE\s(7\.0)/],["bb10",/BB10;\sTouch.*Version\/([0-9\.]+)/],["android",/Android\s([0-9\.]+)/],["ios",/Version\/([0-9\._]+).*Mobile.*Safari.*/],["safari",/Version\/([0-9\._]+).*Safari/],["facebook",/FB[AS]V\/([0-9\.]+)/],["instagram",/Instagram\s([0-9\.]+)/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Mobile/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Gecko\)$/],["curl",/^curl\/([0-9\.]+)$/],["searchbot",Ng]],ef=[["iOS",/iP(hone|od|ad)/],["Android OS",/Android/],["BlackBerry OS",/BlackBerry|BB10/],["Windows Mobile",/IEMobile/],["Amazon OS",/Kindle/],["Windows 3.11",/Win16/],["Windows 95",/(Windows 95)|(Win95)|(Windows_95)/],["Windows 98",/(Windows 98)|(Win98)/],["Windows 2000",/(Windows NT 5.0)|(Windows 2000)/],["Windows XP",/(Windows NT 5.1)|(Windows XP)/],["Windows Server 2003",/(Windows NT 5.2)/],["Windows Vista",/(Windows NT 6.0)/],["Windows 7",/(Windows NT 6.1)/],["Windows 8",/(Windows NT 6.2)/],["Windows 8.1",/(Windows NT 6.3)/],["Windows 10",/(Windows NT 10.0)/],["Windows ME",/Windows ME/],["Windows CE",/Windows CE|WinCE|Microsoft Pocket Internet Explorer/],["Open BSD",/OpenBSD/],["Sun OS",/SunOS/],["Chrome OS",/CrOS/],["Linux",/(Linux)|(X11)/],["Mac OS",/(Mac_PowerPC)|(Macintosh)/],["QNX",/QNX/],["BeOS",/BeOS/],["OS/2",/OS\/2/]];function rf(r){return r?tf(r):typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"?new Rg:typeof navigator<"u"?tf(navigator.userAgent):Mg()}function Og(r){return r!==""&&Ug.reduce(function(e,t){var n=t[0],s=t[1];if(e)return e;var o=s.exec(r);return!!o&&[n,o]},!1)}function tf(r){var e=Og(r);if(!e)return null;var t=e[0],n=e[1];if(t==="searchbot")return new _g;var s=n[1]&&n[1].split(".").join("_").split("_").slice(0,3);s?s.length<Ql&&(s=Jl(Jl([],s,!0),Fg(Ql-s.length),!0)):s=[];var o=s.join("."),i=Pg(r),a=Lg.exec(r);return a&&a[1]?new Tg(t,o,i,a[1]):new Cg(t,o,i)}function Pg(r){for(var e=0,t=ef.length;e<t;e++){var n=ef[e],s=n[0],o=n[1],i=o.exec(r);if(i)return s}return null}function Mg(){var r=typeof process<"u"&&process.version;return r?new Ig(process.version.slice(1)):null}function Fg(r){for(var e=[],t=0;t<r;t++)e.push("0");return e}function he(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var jr=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Ha=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},nf=r=>globalThis.DOMException===void 0?new Ha(r):new DOMException(r),sf=r=>{let e=r.reason===void 0?nf("This operation was aborted."):r.reason;return e instanceof Error?e:nf(e)};function gr(r,e){let{milliseconds:t,fallback:n,message:s,customTimers:o={setTimeout,clearTimeout}}=e,i,c=new Promise((u,l)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:m}=e;m.aborted&&l(sf(m)),m.addEventListener("abort",()=>{l(sf(m))})}if(t===Number.POSITIVE_INFINITY){r.then(u,l);return}let f=new jr;i=o.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(m){l(m)}return}typeof r.cancel=="function"&&r.cancel(),s===!1?u():s instanceof Error?l(s):(f.message=s??`Promise timed out after ${t} milliseconds`,l(f))},t),(async()=>{try{u(await r)}catch(m){l(m)}})()}).finally(()=>{c.clear()});return c.clear=()=>{o.clearTimeout.call(void 0,i),i=void 0},c}var of=rf(),Hn=of!=null&&of.name==="firefox",Ks=async function*(){},$s=async r=>{},Vg=30*1e3;function af(r,e,t=Vg,n){r.readyState==="open"&&Promise.resolve().then(async()=>{if(r.bufferedAmount>0){n.log("%s drain channel with %d buffered bytes",e,r.bufferedAmount);let s=he(),o=!1;r.bufferedAmountLowThreshold=0;let i=()=>{o||(n.log("%s drain channel closed before drain",e),s.resolve())};r.addEventListener("close",i,{once:!0}),r.addEventListener("bufferedamountlow",()=>{o=!0,r.removeEventListener("close",i),s.resolve()}),await gr(s.promise,{milliseconds:t})}}).then(async()=>{r.readyState==="open"&&r.close()}).catch(s=>{n.log.error("error closing outbound stream",s)})}var br=class{log;peerConnection;remoteAddr;timeline;metrics;source=Ks();sink=$s;constructor(e,t){this.log=e.logger.forComponent("libp2p:webrtc:maconn"),this.remoteAddr=t.remoteAddr,this.timeline=t.timeline,this.peerConnection=t.peerConnection;let n=this.peerConnection.connectionState;this.peerConnection.onconnectionstatechange=()=>{this.log.trace("peer connection state change",this.peerConnection.connectionState,"initial state",n),(this.peerConnection.connectionState==="disconnected"||this.peerConnection.connectionState==="failed"||this.peerConnection.connectionState==="closed")&&(this.timeline.close=Date.now())}}async close(e){this.log.trace("closing connection"),this.peerConnection.close(),this.timeline.close=Date.now(),this.metrics?.increment({close:!0})}abort(e){this.log.error("closing connection due to error",e),this.peerConnection.close(),this.timeline.close=Date.now(),this.metrics?.increment({abort:!0})}};var qs=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||e-1&e)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},Yr=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new qs(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let t=this.head;this.head=t.next=new qs(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Ka=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Zt(r={}){return Hg(t=>{let n=t.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function Hg(r,e){e=e??{};let t=e.onEnd,n=new Yr,s,o,i,a=he(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((p,y)=>{o=x=>{o=null,n.push(x);try{p(r(n))}catch(b){y(b)}return s}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=he()})}},u=p=>o!=null?o(p):(n.push(p),s),l=p=>(n=new Yr,o!=null?o({error:p}):(n.push({error:p}),s)),f=p=>{if(i)return s;if(e?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:p})},m=p=>i?s:(i=!0,p!=null?l(p):u({done:!0})),g=()=>(n=new Yr,m(),{done:!0}),d=p=>(m(p),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:g,throw:d,push:f,end:m,get readableLength(){return n.size},onEmpty:async p=>{let y=p?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let x,b;y!=null&&(x=new Promise((v,E)=>{b=()=>{E(new Ka)},y.addEventListener("abort",b)}));try{await Promise.race([a.promise,x])}finally{b!=null&&y!=null&&y?.removeEventListener("abort",b)}}},t==null)return s;let h=s;return s={[Symbol.asyncIterator](){return this},next(){return h.next()},throw(p){return h.throw(p),t!=null&&(t(p),t=void 0),{done:!0}},return(){return h.return(),t!=null&&(t(),t=void 0),{done:!0}},push:f,end(p){return h.end(p),t!=null&&(t(p),t=void 0),s},get readableLength(){return h.readableLength},onEmpty:p=>h.onEmpty(p)},s}var Ws=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=t??"ABORT_ERR"}};async function Ct(r,e,t){if(e==null)return r;if(e.aborted)return Promise.reject(new Ws(t?.errorMessage,t?.errorCode));let n,s=new Ws(t?.errorMessage,t?.errorCode);try{return await Promise.race([r,new Promise((o,i)=>{n=()=>{i(s)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var uf=Symbol.for("@achingbrain/uint8arraylist");function cf(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let s=t+n.byteLength;if(e<s)return{buf:n,index:e-t};t=s}throw new RangeError("index is out of bounds")}function zs(r){return!!r?.[uf]}var ce=class r{bufs;length;[uf]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if(zs(n))t+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if(zs(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=cf(this.bufs,e);return t.buf[t.index]}set(e,t){let n=cf(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if(zs(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:s}=this._subList(e,t);return we(n,s)}subarray(e,t){let{bufs:n,length:s}=this._subList(e,t);return n.length===1?n[0]:we(n,s)}sublist(e,t){let{bufs:n,length:s}=this._subList(e,t),o=new r;return o.length=s,o.bufs=[...n],o}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let n=[],s=0;for(let o=0;o<this.bufs.length;o++){let i=this.bufs[o],a=s,c=a+i.byteLength;if(s=c,e>=c)continue;let u=e>=a&&e<c,l=t>a&&t<=c;if(u&&l){if(e===a&&t===c){n.push(i);break}let f=e-a;n.push(i.subarray(f,f+(t-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(l){if(t===c){n.push(i);break}n.push(i.subarray(0,t-a));break}n.push(i)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!zs(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;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 f=0;f<o;f++)i[f]=-1;for(let f=0;f<s;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let f=t;f<=c;f+=l){l=0;for(let m=u;m>=0;m--){let g=this.get(f+m);if(n[m]!==g){l=Math.max(1,m-a[g]);break}}if(l===0)return f}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=De(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let s=Ae(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,t,n),this.write(s,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let s=Ae(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,t,n),this.write(s,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let s=Ae(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,t,n),this.write(s,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=De(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let s=Ae(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,t,n),this.write(s,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let s=Ae(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,t,n),this.write(s,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let s=Ae(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,t,n),this.write(s,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let s=Ae(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,t,n),this.write(s,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let s=Ae(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,t,n),this.write(s,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!ve(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((s,o)=>s+o.byteLength,0)),n.length=t,n}};function lf(r){if(r!=null){if(typeof r[Symbol.iterator]=="function")return r[Symbol.iterator]();if(typeof r[Symbol.asyncIterator]=="function")return r[Symbol.asyncIterator]();if(typeof r.next=="function")return r}throw new Error("argument is not an iterator or iterable")}function ff(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function hf(r,e){let t=lf(r).return?.();ff(t)&&t.catch(n=>{e.error("could not cause iterator to return",n)})}var Kg="ERR_STREAM_RESET",$g="ERR_SINK_INVALID_STATE",qg=5e3;function $a(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Gs=class{id;direction;timeline;protocol;metadata;source;status;readStatus;writeStatus;log;sinkController;sinkEnd;closed;endErr;streamSource;onEnd;onCloseRead;onCloseWrite;onReset;onAbort;sendCloseWriteTimeout;sendingData;constructor(e){this.sinkController=new AbortController,this.sinkEnd=he(),this.closed=he(),this.log=e.log,this.status="open",this.readStatus="ready",this.writeStatus="ready",this.id=e.id,this.metadata=e.metadata??{},this.direction=e.direction,this.timeline={open:Date.now()},this.sendCloseWriteTimeout=e.sendCloseWriteTimeout??qg,this.onEnd=e.onEnd,this.onCloseRead=e?.onCloseRead,this.onCloseWrite=e?.onCloseWrite,this.onReset=e?.onReset,this.onAbort=e?.onAbort,this.source=this.streamSource=Zt({onEnd:t=>{t!=null?this.log.trace("source ended with error",t):this.log.trace("source ended"),this.onSourceEnd(t)}}),this.sink=this.sink.bind(this)}async sink(e){if(this.writeStatus!=="ready")throw new N(`writable end state is "${this.writeStatus}" not "ready"`,$g);try{this.writeStatus="writing";let t={signal:this.sinkController.signal};if(this.direction==="outbound"){let s=this.sendNewStream(t);$a(s)&&await s}let n=()=>{hf(e,this.log)};try{this.sinkController.signal.addEventListener("abort",n),this.log.trace("sink reading from source");for await(let s of e){s=s instanceof Uint8Array?new ce(s):s;let o=this.sendData(s,t);$a(o)&&(this.sendingData=he(),await o,this.sendingData.resolve(),this.sendingData=void 0)}}finally{this.sinkController.signal.removeEventListener("abort",n)}this.log.trace('sink finished reading from source, write status is "%s"',this.writeStatus),this.writeStatus==="writing"&&(this.writeStatus="closing",this.log.trace("send close write to remote"),await this.sendCloseWrite({signal:AbortSignal.timeout(this.sendCloseWriteTimeout)}),this.writeStatus="closed"),this.onSinkEnd()}catch(t){throw this.log.trace("sink ended with error, calling abort with error",t),this.abort(t),t}finally{this.log.trace("resolve sink end"),this.sinkEnd.resolve()}}onSourceEnd(e){this.timeline.closeRead==null&&(this.timeline.closeRead=Date.now(),this.readStatus="closed",e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseRead?.(),this.timeline.closeWrite!=null?(this.log.trace("source and sink ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("source ended, waiting for sink to end"))}onSinkEnd(e){this.timeline.closeWrite==null&&(this.timeline.closeWrite=Date.now(),this.writeStatus="closed",e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseWrite?.(),this.timeline.closeRead!=null?(this.log.trace("sink and source ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("sink ended, waiting for source to end"))}async close(e){this.log.trace("closing gracefully"),this.status="closing",await Ct(Promise.all([this.closeWrite(e),this.closeRead(e),this.closed.promise]),e?.signal),this.status="closed",this.log.trace("closed gracefully")}async closeRead(e={}){if(this.readStatus==="closing"||this.readStatus==="closed")return;this.log.trace('closing readable end of stream with starting read status "%s"',this.readStatus);let t=this.readStatus;this.readStatus="closing",this.status!=="reset"&&this.status!=="aborted"&&this.timeline.closeRead==null&&(this.log.trace("send close read to remote"),await this.sendCloseRead(e)),t==="ready"&&(this.log.trace("ending internal source queue with %d queued bytes",this.streamSource.readableLength),this.streamSource.end()),this.log.trace("closed readable end of stream")}async closeWrite(e={}){this.writeStatus==="closing"||this.writeStatus==="closed"||(this.log.trace('closing writable end of stream with starting write status "%s"',this.writeStatus),this.writeStatus==="ready"&&(this.log.trace("sink was never sunk, sink an empty array"),await Ct(this.sink([]),e.signal)),this.writeStatus==="writing"&&(this.sendingData!=null&&await Ct(this.sendingData.promise,e.signal),this.log.trace("aborting source passed to .sink"),this.sinkController.abort(),await Ct(this.sinkEnd.promise,e.signal)),this.writeStatus="closed",this.log.trace("closed writable end of stream"))}abort(e){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;this.log("abort with error",e),this.log("try to send reset to remote");let t=this.sendReset();$a(t)&&t.catch(n=>{this.log.error("error sending reset message",n)}),this.status="aborted",this.timeline.abort=Date.now(),this._closeSinkAndSource(e),this.onAbort?.(e)}reset(){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;let e=new N("stream reset",Kg);this.status="reset",this.timeline.reset=Date.now(),this._closeSinkAndSource(e),this.onReset?.()}_closeSinkAndSource(e){this._closeSink(e),this._closeSource(e)}_closeSink(e){this.writeStatus==="writing"&&(this.log.trace("end sink source"),this.sinkController.abort()),this.onSinkEnd(e)}_closeSource(e){this.readStatus!=="closing"&&this.readStatus!=="closed"&&(this.log.trace("ending source with %d bytes to be read by consumer",this.streamSource.readableLength),this.readStatus="closing",this.streamSource.end(e))}remoteCloseWrite(){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("received remote close write but local source is already closed");return}this.log.trace("remote close write"),this._closeSource()}remoteCloseRead(){if(this.writeStatus==="closing"||this.writeStatus==="closed"){this.log("received remote close read but local sink is already closed");return}this.log.trace("remote close read"),this._closeSink()}destroy(){if(this.status==="closed"||this.status==="aborted"||this.status==="reset"){this.log("received destroy but we are already closed");return}this.log.trace("stream destroyed"),this._closeSinkAndSource()}sourcePush(e){this.streamSource.push(e)}sourceReadableLength(){return this.streamSource.readableLength}};function js(r){return r[Symbol.asyncIterator]!=null}var Ys=r=>{let e=ye(r),t=De(e);return gt(r,t),Ys.bytes=e,t};Ys.bytes=0;function Kn(r,e){e=e??{};let t=e.lengthEncoder??Ys;function*n(s){let o=t(s.byteLength);o instanceof Uint8Array?yield o:yield*o,s instanceof Uint8Array?yield s:yield*s}return js(r)?async function*(){for await(let s of r)yield*n(s)}():function*(){for(let s of r)yield*n(s)}()}Kn.single=(r,e)=>{e=e??{};let t=e.lengthEncoder??Ys;return new ce(t(r.byteLength),r)};var Zr=As(mf(),1);var zg=8,Gg=1024*1024*4,yr;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(yr||(yr={}));var qa=r=>{let e=Qe(r);return qa.bytes=ye(e),e};qa.bytes=0;function wr(r,e){let t=new ce,n=yr.LENGTH,s=-1,o=e?.lengthDecoder??qa,i=e?.maxLengthLength??zg,a=e?.maxDataLength??Gg;function*c(){for(;t.byteLength>0;){if(n===yr.LENGTH)try{if(s=o(t),s<0)throw(0,Zr.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(s>a)throw(0,Zr.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let u=o.bytes;t.consume(u),e?.onLength!=null&&e.onLength(s),n=yr.DATA}catch(u){if(u instanceof RangeError){if(t.byteLength>i)throw(0,Zr.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw u}if(n===yr.DATA){if(t.byteLength<s)break;let u=t.sublist(0,s);t.consume(s),e?.onData!=null&&e.onData(u),yield u,n=yr.LENGTH}}}return js(r)?async function*(){for await(let u of r)t.append(u),yield*c();if(t.byteLength>0)throw(0,Zr.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(let u of r)t.append(u),yield*c();if(t.byteLength>0)throw(0,Zr.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}wr.fromReader=(r,e)=>{let t=1,n=async function*(){for(;;)try{let{done:o,value:i}=await r.next(t);if(o===!0)return;i!=null&&(yield i)}catch(o){if(o.code==="ERR_UNDER_READ")return{done:!0,value:null};throw o}finally{t=1}}();return wr(n,{...e??{},onLength:o=>{t=o}})};var Yg=r=>{let e=r.addEventListener||r.on||r.addListener,t=r.removeEventListener||r.off||r.removeListener;if(!e||!t)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(r),removeListener:t.bind(r)}};function Zg(r,e,t){let n,s=new Promise((o,i)=>{if(t={rejectionEvents:["error"],multiArgs:!1,resolveImmediately:!1,...t},!(t.count>=0&&(t.count===Number.POSITIVE_INFINITY||Number.isInteger(t.count))))throw new TypeError("The `count` option should be at least 0 or more");t.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:u,removeListener:l}=Yg(r),f=(...g)=>{let d=t.multiArgs?g:g[0];t.filter&&!t.filter(d)||(c.push(d),t.count===c.length&&(n(),o(c)))},m=g=>{n(),i(g)};n=()=>{for(let g of a)l(g,f);for(let g of t.rejectionEvents)l(g,m)};for(let g of a)u(g,f);for(let g of t.rejectionEvents)u(g,m);t.signal&&t.signal.addEventListener("abort",()=>{m(t.signal.reason)},{once:!0}),t.resolveImmediately&&o(c)});if(s.cancel=n,typeof t.timeout=="number"){let o=gr(s,{milliseconds:t.timeout});return o.cancel=n,o}return s}function Wa(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=Zg(r,e,t),s=n.then(o=>o[0]);return s.cancel=n.cancel,s}var za=new Float32Array([-0]),Xt=new Uint8Array(za.buffer);function gf(r,e,t){za[0]=r,e[t]=Xt[0],e[t+1]=Xt[1],e[t+2]=Xt[2],e[t+3]=Xt[3]}function bf(r,e){return Xt[0]=r[e],Xt[1]=r[e+1],Xt[2]=r[e+2],Xt[3]=r[e+3],za[0]}var Ga=new Float64Array([-0]),Oe=new Uint8Array(Ga.buffer);function yf(r,e,t){Ga[0]=r,e[t]=Oe[0],e[t+1]=Oe[1],e[t+2]=Oe[2],e[t+3]=Oe[3],e[t+4]=Oe[4],e[t+5]=Oe[5],e[t+6]=Oe[6],e[t+7]=Oe[7]}function wf(r,e){return Oe[0]=r[e],Oe[1]=r[e+1],Oe[2]=r[e+2],Oe[3]=r[e+3],Oe[4]=r[e+4],Oe[5]=r[e+5],Oe[6]=r[e+6],Oe[7]=r[e+7],Ga[0]}var Xg=BigInt(Number.MAX_SAFE_INTEGER),Jg=BigInt(Number.MIN_SAFE_INTEGER),We=class r{lo;hi;constructor(e,t){this.lo=e|0,this.hi=t|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(t+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(BigInt(t)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return xr;if(e<Xg&&e>Jg)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,s=e-(n<<32n);return t&&(n=~n|0n,s=~s|0n,++s>xf&&(s=0n,++n>xf&&(n=0n))),new r(Number(s),Number(n))}static fromNumber(e){if(e===0)return xr;let t=e<0;t&&(e=-e);let n=e>>>0,s=(e-n)/4294967296>>>0;return t&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new r(n,s)}static from(e){return typeof e=="number"?r.fromNumber(e):typeof e=="bigint"?r.fromBigInt(e):typeof e=="string"?r.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new r(e.low>>>0,e.high>>>0):xr}},xr=new We(0,0);xr.toBigInt=function(){return 0n};xr.zzEncode=xr.zzDecode=function(){return this};xr.length=function(){return 1};var xf=4294967296n;function Ef(r){let e=0,t=0;for(let n=0;n<r.length;++n)t=r.charCodeAt(n),t<128?e+=1:t<2048?e+=2:(t&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function vf(r,e,t){if(t-e<1)return"";let s,o=[],i=0,a;for(;e<t;)a=r[e++],a<128?o[i++]=a:a>191&&a<224?o[i++]=(a&31)<<6|r[e++]&63:a>239&&a<365?(a=((a&7)<<18|(r[e++]&63)<<12|(r[e++]&63)<<6|r[e++]&63)-65536,o[i++]=55296+(a>>10),o[i++]=56320+(a&1023)):o[i++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,i>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,o)),i=0);return s!=null?(i>0&&s.push(String.fromCharCode.apply(String,o.slice(0,i))),s.join("")):String.fromCharCode.apply(String,o.slice(0,i))}function ja(r,e,t){let n=t,s,o;for(let i=0;i<r.length;++i)s=r.charCodeAt(i),s<128?e[t++]=s:s<2048?(e[t++]=s>>6|192,e[t++]=s&63|128):(s&64512)===55296&&((o=r.charCodeAt(i+1))&64512)===56320?(s=65536+((s&1023)<<10)+(o&1023),++i,e[t++]=s>>18|240,e[t++]=s>>12&63|128,e[t++]=s>>6&63|128,e[t++]=s&63|128):(e[t++]=s>>12|224,e[t++]=s>>6&63|128,e[t++]=s&63|128);return t-n}function tt(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function Zs(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Ya=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,tt(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw tt(this,4);return Zs(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw tt(this,4);return Zs(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw tt(this,4);let e=bf(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw tt(this,4);let e=wf(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),t=this.pos,n=this.pos+e;if(n>this.len)throw tt(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return vf(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw tt(this,e);this.pos+=e}else do if(this.pos>=this.len)throw tt(this);while(this.buf[this.pos++]&128);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new We(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw tt(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<t*7)>>>0,e}if(this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw tt(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw tt(this,8);let e=Zs(this.buf,this.pos+=4),t=Zs(this.buf,this.pos+=4);return new We(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=ma(this.buf,this.pos);return this.pos+=ye(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Za(r){return new Ya(r instanceof Uint8Array?r:r.subarray())}function rt(r,e,t){let n=Za(r);return e.decode(n,void 0,t)}function Xa(r){let e=r??8192,t=e>>>1,n,s=e;return function(i){if(i<1||i>t)return De(i);s+i>e&&(n=De(e),s=0);let a=n.subarray(s,s+=i);return s&7&&(s=(s|7)+1),a}}var Er=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function Ja(){}var ec=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Qg=Xa();function eb(r){return globalThis.Buffer!=null?De(r):Qg(r)}var qn=class{len;head;tail;states;constructor(){this.len=0,this.head=new Er(Ja,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new Er(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new tc((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(Xs,10,We.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=We.fromBigInt(e);return this._push(Xs,t.length(),t)}uint64Number(e){return this._push(pa,ye(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=We.fromBigInt(e).zzEncode();return this._push(Xs,t.length(),t)}sint64Number(e){let t=We.fromNumber(e).zzEncode();return this._push(Xs,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Qa,1,e?1:0)}fixed32(e){return this._push($n,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=We.fromBigInt(e);return this._push($n,4,t.lo)._push($n,4,t.hi)}fixed64Number(e){let t=We.fromNumber(e);return this._push($n,4,t.lo)._push($n,4,t.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(gf,4,e)}double(e){return this._push(yf,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Qa,1,0):this.uint32(t)._push(rb,t,e)}string(e){let t=Ef(e);return t!==0?this.uint32(t)._push(ja,t,e):this._push(Qa,1,0)}fork(){return this.states=new ec(this),this.head=this.tail=new Er(Ja,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 Er(Ja,0,0),this.len=0),this}ldelim(){let e=this.head,t=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=t,this.len+=n),this}finish(){let e=this.head.next,t=eb(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function Qa(r,e,t){e[t]=r&255}function tb(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var tc=class extends Er{next;constructor(e,t){super(tb,e,t),this.next=void 0}};function Xs(r,e,t){for(;r.hi!==0;)e[t++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)e[t++]=r.lo&127|128,r.lo=r.lo>>>7;e[t++]=r.lo}function $n(r,e,t){e[t]=r&255,e[t+1]=r>>>8&255,e[t+2]=r>>>16&255,e[t+3]=r>>>24}function rb(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(qn.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(nb,e,r),this},qn.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(sb,e,r),this});function nb(r,e,t){e.set(r,t)}function sb(r,e,t){r.length<40?ja(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(Q(r),t)}function rc(){return new qn}function nt(r,e){let t=rc();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var Xr;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(Xr||(Xr={}));function Js(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function vr(r){function e(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let t=function(o,i){let a=e(o);i.int32(a)},n=function(o){let i=o.int32();return e(i)};return Js("enum",Xr.VARINT,t,n)}function st(r,e){return Js("message",Xr.LENGTH_DELIMITED,r,e)}var He;(function(r){let e;(function(s){s.FIN="FIN",s.STOP_SENDING="STOP_SENDING",s.RESET="RESET",s.FIN_ACK="FIN_ACK"})(e=r.Flag||(r.Flag={}));let t;(function(s){s[s.FIN=0]="FIN",s[s.STOP_SENDING=1]="STOP_SENDING",s[s.RESET=2]="RESET",s[s.FIN_ACK=3]="FIN_ACK"})(t||(t={})),function(s){s.codec=()=>vr(t)}(e=r.Flag||(r.Flag={}));let n;r.codec=()=>(n==null&&(n=st((s,o,i={})=>{i.lengthDelimited!==!1&&o.fork(),s.flag!=null&&(o.uint32(8),r.Flag.codec().encode(s.flag,o)),s.message!=null&&(o.uint32(18),o.bytes(s.message)),i.lengthDelimited!==!1&&o.ldelim()},(s,o)=>{let i={},a=o==null?s.len:s.pos+o;for(;s.pos<a;){let c=s.uint32();switch(c>>>3){case 1:i.flag=r.Flag.codec().decode(s);break;case 2:i.message=s.bytes();break;default:s.skipType(c&7);break}}return i})),n),r.encode=s=>nt(s,r.codec()),r.decode=s=>rt(s,r.codec())})(He||(He={}));var ob=16*1024*1024,ib=30*1e3,ab=5,cb=2,ub=16*1024,lb=5e3,fb=5e3,nc=class extends Gs{channel;incomingData;maxBufferedAmount;bufferedAmountLowEventTimeout;maxMessageSize;receiveFinAck;finAckTimeout;openTimeout;constructor(e){let t=e.onEnd;switch(e.onEnd=s=>{this.log.trace("readable and writeable ends closed",this.status),Promise.resolve(async()=>{if(!(this.timeline.abort!=null||this.timeline.reset!==null))try{await gr(this.receiveFinAck.promise,{milliseconds:this.finAckTimeout})}catch(o){this.log.error("error receiving FIN_ACK",o)}}).then(()=>{this.incomingData.end(),t?.(s)}).catch(o=>{this.log.error("error ending stream",o)})},super(e),this.channel=e.channel,this.channel.binaryType="arraybuffer",this.incomingData=Zt(),this.bufferedAmountLowEventTimeout=e.bufferedAmountLowEventTimeout??ib,this.maxBufferedAmount=e.maxBufferedAmount??ob,this.maxMessageSize=(e.maxMessageSize??ub)-ab-cb,this.receiveFinAck=he(),this.finAckTimeout=e.closeTimeout??lb,this.openTimeout=e.openTimeout??fb,this.channel.readyState){case"open":this.timeline.open=new Date().getTime();break;case"closed":case"closing":(this.timeline.close===void 0||this.timeline.close===0)&&(this.timeline.close=Date.now());break;case"connecting":break;default:throw this.log.error("unknown datachannel state %s",this.channel.readyState),new N("Unknown datachannel state","ERR_INVALID_STATE")}this.channel.onopen=s=>{this.timeline.open=new Date().getTime()},this.channel.onclose=s=>{this.receiveFinAck.resolve(),this.close().catch(o=>{this.log.error("error closing stream after channel closed",o)})},this.channel.onerror=s=>{let o=s.error;this.abort(o)},this.channel.onmessage=async s=>{let{data:o}=s;o===null||o.byteLength===0||this.incomingData.push(new Uint8Array(o,0,o.byteLength))};let n=this;Promise.resolve().then(async()=>{for await(let s of wr(this.incomingData)){let o=n.processIncomingProtobuf(s);o!=null&&n.sourcePush(new ce(o))}}).catch(s=>{this.log.error("error processing incoming data channel messages",s)})}sendNewStream(){}async _sendMessage(e,t=!0){if(t&&this.channel.bufferedAmount>this.maxBufferedAmount)try{this.log('channel buffer is %d, wait for "bufferedamountlow" event',this.channel.bufferedAmount),await Wa(this.channel,"bufferedamountlow",{timeout:this.bufferedAmountLowEventTimeout})}catch(n){throw n instanceof jr?new N(`Timed out waiting for DataChannel buffer to clear after ${this.bufferedAmountLowEventTimeout}ms`,"ERR_BUFFER_CLEAR_TIMEOUT"):n}if(this.channel.readyState==="closed"||this.channel.readyState==="closing")throw new N(`Invalid datachannel state - ${this.channel.readyState}`,"ERR_INVALID_STATE");this.channel.readyState!=="open"&&(this.log('channel state is "%s" and not "open", waiting for "open" event before sending data',this.channel.readyState),await Wa(this.channel,"open",{timeout:this.openTimeout}),this.log('channel state is now "%s", sending data',this.channel.readyState)),this.channel.send(e.subarray())}async sendData(e){for(e=e.sublist();e.byteLength>0;){let t=Math.min(e.byteLength,this.maxMessageSize),n=e.subarray(0,t),s=He.encode({message:n}),o=Kn.single(s);await this._sendMessage(o),e.consume(t)}}async sendReset(){await this._sendFlag(He.Flag.RESET)}async sendCloseWrite(e){if(await this._sendFlag(He.Flag.FIN)){this.log.trace("awaiting FIN_ACK");try{await Ct(this.receiveFinAck.promise,e?.signal,{errorMessage:"sending close-write was aborted before FIN_ACK was received",errorCode:"ERR_FIN_ACK_NOT_RECEIVED"})}catch(n){this.log.error("failed to await FIN_ACK",n)}}else this.log.trace("sending FIN failed, not awaiting FIN_ACK");this.receiveFinAck.resolve()}async sendCloseRead(){await this._sendFlag(He.Flag.STOP_SENDING)}processIncomingProtobuf(e){let t=He.decode(e);if(t.flag!==void 0&&(this.log.trace('incoming flag %s, write status "%s", read status "%s"',t.flag,this.writeStatus,this.readStatus),t.flag===He.Flag.FIN&&(this.remoteCloseWrite(),this.log.trace("sending FIN_ACK"),this._sendFlag(He.Flag.FIN_ACK).catch(n=>{this.log.error("error sending FIN_ACK immediately",n)})),t.flag===He.Flag.RESET&&this.reset(),t.flag===He.Flag.STOP_SENDING&&this.remoteCloseRead(),t.flag===He.Flag.FIN_ACK&&(this.log.trace("received FIN_ACK"),this.receiveFinAck.resolve())),this.readStatus==="ready")return t.message}async _sendFlag(e){if(this.channel.readyState!=="open")return this.log.trace('not sending flag %s because channel is "%s" and not "open"',this.channel.readyState,e.toString()),!1;this.log.trace("sending flag %s",e.toString());let t=He.encode({flag:e}),n=Kn.single(t);try{return await this._sendMessage(n,!1),!0}catch(s){this.log.error("could not send flag %s",e.toString(),s)}return!1}};function Jr(r){let{channel:e,direction:t}=r;return new nc({id:t==="inbound"?`i${e.id}`:`r${e.id}`,log:r.logger.forComponent(`libp2p:webrtc:stream:${t}:${e.id}`),...r})}var Df="/webrtc",Ar=class{protocol;peerConnection;bufferedStreams=[];metrics;dataChannelOptions;components;log;constructor(e,t){this.components=e,this.peerConnection=t.peerConnection,this.metrics=t.metrics,this.protocol=t.protocol??Df,this.dataChannelOptions=t.dataChannelOptions??{},this.log=e.logger.forComponent("libp2p:webrtc:datachannelmuxerfactory"),this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace('incoming early datachannel with channel id %d and label "%s"',n.id),n.label==="init"){this.log.trace("closing early init channel"),n.close();return}let s={},o=Jr({channel:n,direction:"inbound",onEnd:i=>{s.onEnd(i)},logger:e.logger,...this.dataChannelOptions});s.stream=o,s.channel=n,s.onEnd=()=>{this.bufferedStreams=this.bufferedStreams.filter(i=>i.stream.id!==o.id)},this.bufferedStreams.push(s)}}createStreamMuxer(e){return new sc(this.components,{...e,peerConnection:this.peerConnection,dataChannelOptions:this.dataChannelOptions,metrics:this.metrics,streams:this.bufferedStreams,protocol:this.protocol})}},sc=class{init;streams;protocol;log;peerConnection;dataChannelOptions;metrics;logger;constructor(e,t){this.init=t,this.log=e.logger.forComponent("libp2p:webrtc:muxer"),this.logger=e.logger,this.streams=t.streams.map(n=>n.stream),this.peerConnection=t.peerConnection,this.protocol=t.protocol??Df,this.metrics=t.metrics,this.dataChannelOptions=t.dataChannelOptions??{},this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace("incoming datachannel with channel id %d",n.id),n.label==="init"){this.log.trace("closing init channel"),n.close();return}let s=Jr({channel:n,direction:"inbound",onEnd:()=>{this.log("incoming channel %s ended with state %s",n.id,n.readyState),this.#e(s,n)},logger:this.logger,...this.dataChannelOptions});this.streams.push(s),this.metrics?.increment({incoming_stream:!0}),t?.onIncomingStream?.(s)},this.init.streams.length>0&&queueMicrotask(()=>{this.init.streams.forEach(n=>{n.onEnd=()=>{this.log("incoming early channel %s ended with state %s",n.channel.id,n.channel.readyState),this.#e(n.stream,n.channel)},this.metrics?.increment({incoming_stream:!0}),this.init?.onIncomingStream?.(n.stream)})})}#e(e,t){this.log.trace("stream %s %s %s onEnd",e.direction,e.id,e.protocol),af(t,`${e.direction} ${e.id} ${e.protocol}`,this.dataChannelOptions.drainTimeout,{log:this.log}),this.streams=this.streams.filter(n=>n.id!==e.id),this.metrics?.increment({stream_end:!0}),this.init?.onStreamEnd?.(e)}async close(e){try{await Promise.all(this.streams.map(async t=>t.close(e)))}catch(t){this.abort(t)}}abort(e){for(let t of this.streams)t.abort(e)}source=Ks();sink=$s;newStream(){let e=this.peerConnection.createDataChannel("");this.log.trace("opened outgoing datachannel with channel id %s",e.id);let t=Jr({channel:e,direction:"outbound",onEnd:()=>{this.log("outgoing channel %s ended with state %s",e.id,e.readyState),this.#e(t,e)},logger:this.logger,...this.dataChannelOptions});return this.streams.push(t),this.metrics?.increment({outgoing_stream:!0}),t}};var Qr=globalThis.RTCPeerConnection,Qs=globalThis.RTCSessionDescription,Bf=globalThis.RTCIceCandidate;var oc=class{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=he(),this.haveNext=he()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=he(),e}async throw(e){return this.ended=!0,e!=null&&this.haveNext.reject(e),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return await this._push(void 0),e}async push(e,t){await this._push(e,t)}async end(e,t){e!=null?await this.throw(e):await this._push(void 0,t)}async _push(e,t){if(e!=null&&this.ended)throw new Error("Cannot push value onto an ended pushable");if(this.nextResult!=null&&(await this.readNext.promise,this.nextResult!=null))throw new Error("NeedNext promise resolved but nextResult was not consumed");e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=he(),await Ct(this.readNext.promise,t?.signal,t)}};function Sf(){return new oc}var eo=class extends Error{code;constructor(e,t){super(e),this.code=t}},ic=class extends eo{type;constructor(e){super(e,"ABORT_ERR"),this.type="aborted"}};function kf(r,e){let t=Sf();r.sink(t).catch(async i=>{await t.end(i)}),r.sink=async i=>{for await(let a of i)await t.push(a);await t.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let s=new ce;return{read:async(i,a)=>{a?.signal?.throwIfAborted();let c,u=new Promise((l,f)=>{c=()=>{f(new ic("Read aborted"))},a?.signal?.addEventListener("abort",c)});try{if(i==null){let{done:f,value:m}=await Promise.race([n.next(),u]);return f===!0?new ce:m}for(;s.byteLength<i;){let{value:f,done:m}=await Promise.race([n.next(),u]);if(m===!0)throw new eo("unexpected end of input","ERR_UNEXPECTED_EOF");s.append(f)}let l=s.sublist(0,i);return s.consume(i),l}finally{c!=null&&a?.signal?.removeEventListener("abort",c)}},write:async(i,a)=>{a?.signal?.throwIfAborted(),i instanceof Uint8Array?await t.push(i,a):await t.push(i.subarray(),a)},unwrap:()=>{if(s.byteLength>0){let i=r.source;r.source=async function*(){e?.yieldBytes===!1?yield s:yield*s,yield*i}()}return r}}}var to=class extends Error{code;constructor(e,t){super(e),this.code=t}};function Wn(r,e={}){let t=kf(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=ye(e.maxDataLength));let n=e?.lengthDecoder??Qe,s=e?.lengthEncoder??gt;return{read:async i=>{let a=-1,c=new ce;for(;;){c.append(await t.read(1,i));try{a=n(c)}catch(u){if(u instanceof RangeError)continue;throw u}if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new to("message length length too long","ERR_MSG_LENGTH_TOO_LONG");if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new to("message length too long","ERR_MSG_DATA_TOO_LONG");return t.read(a,i)},write:async(i,a)=>{await t.write(new ce(s(i.byteLength),i),a)},writeV:async(i,a)=>{let c=new ce(...i.flatMap(u=>[s(u.byteLength),u]));await t.write(c,a)},unwrap:()=>t.unwrap()}}function ro(r,e){let t=Wn(r,e),n={read:async(s,o)=>{let i=await t.read(o);return s.decode(i)},write:async(s,o,i)=>{await t.write(o.encode(s),i)},writeV:async(s,o,i)=>{await t.writeV(s.map(a=>o.encode(a)),i)},pb:s=>({read:async o=>n.read(s,o),write:async(o,i)=>n.write(o,s,i),writeV:async(o,i)=>n.writeV(o,s,i),unwrap:()=>n}),unwrap:()=>t.unwrap()};return n}var Ke;(function(r){let e;(function(s){s.SDP_OFFER="SDP_OFFER",s.SDP_ANSWER="SDP_ANSWER",s.ICE_CANDIDATE="ICE_CANDIDATE"})(e=r.Type||(r.Type={}));let t;(function(s){s[s.SDP_OFFER=0]="SDP_OFFER",s[s.SDP_ANSWER=1]="SDP_ANSWER",s[s.ICE_CANDIDATE=2]="ICE_CANDIDATE"})(t||(t={})),function(s){s.codec=()=>vr(t)}(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=st((s,o,i={})=>{i.lengthDelimited!==!1&&o.fork(),s.type!=null&&(o.uint32(8),r.Type.codec().encode(s.type,o)),s.data!=null&&(o.uint32(18),o.string(s.data)),i.lengthDelimited!==!1&&o.ldelim()},(s,o)=>{let i={},a=o==null?s.len:s.pos+o;for(;s.pos<a;){let c=s.uint32();switch(c>>>3){case 1:i.type=r.Type.codec().decode(s);break;case 2:i.data=s.string();break;default:s.skipType(c&7);break}}return i})),n),r.encode=s=>nt(s,r.codec()),r.decode=s=>rt(s,r.codec())})(Ke||(Ke={}));var no=async(r,e,t)=>{try{let n=he();for(db(r,n);;){let s=await Promise.race([n.promise,e.read({signal:t.signal})]);if(s==null)break;if(s.type!==Ke.Type.ICE_CANDIDATE)throw new N("ICE candidate message expected","ERR_NOT_ICE_CANDIDATE");let o=JSON.parse(s.data??"null");if(o===""||o===null){t.log.trace("end-of-candidates received");continue}let i=new Bf(o);t.log.trace("%s received new ICE candidate",t.direction,i);try{await r.addIceCandidate(i)}catch(a){t.log.error("%s bad candidate received",t.direction,o,a)}}}catch(n){if(t.log.error("%s error parsing ICE candidate",t.direction,n),t.signal?.aborted===!0)throw n}};function hb(r){return Hn?r.iceConnectionState:r.connectionState}function db(r,e){r[Hn?"oniceconnectionstatechange":"onconnectionstatechange"]=t=>{switch(hb(r)){case"connected":e.resolve();break;case"failed":case"disconnected":case"closed":e.reject(new N("RTCPeerConnection was closed","ERR_CONNECTION_CLOSED_BEFORE_CONNECTED"));break;default:break}}}async function Cf({peerConnection:r,signal:e,metrics:t,multiaddr:n,connectionManager:s,transportManager:o,log:i}){let{baseAddr:a}=If(n);t?.dialerEvents.increment({open:!0}),i.trace("dialing base address: %a",a);let c=a.getPeerId();if(c==null)throw new N("Relay peer was missing","ERR_INVALID_ADDRESS");let u=s.getConnections(mr(c)),l,f=!1;u.length===0?(l=await o.dial(a,{signal:e}),f=!0):l=u[0];try{let m=await l.newStream(so,{signal:e,runOnTransientConnection:!0}),g=ro(m).pb(Ke);try{let d=r.createDataChannel("init");r.onicecandidate=({candidate:x})=>{let b=JSON.stringify(x?.toJSON()??null);i.trace("initiator sending ICE candidate %s",b),g.write({type:Ke.Type.ICE_CANDIDATE,data:b},{signal:e}).catch(v=>{i.error("error sending ICE candidate",v)})},r.onicecandidateerror=x=>{i.error("initiator ICE candidate error",x)};let h=await r.createOffer().catch(x=>{throw i.error("could not execute createOffer",x),new N("Failed to set createOffer","ERR_SDP_HANDSHAKE_FAILED")});i.trace("initiator send SDP offer %s",h.sdp),await g.write({type:Ke.Type.SDP_OFFER,data:h.sdp},{signal:e}),await r.setLocalDescription(h).catch(x=>{throw i.error("could not execute setLocalDescription",x),new N("Failed to set localDescription","ERR_SDP_HANDSHAKE_FAILED")});let p=await g.read({signal:e});if(p.type!==Ke.Type.SDP_ANSWER)throw new N("Remote should send an SDP answer","ERR_SDP_HANDSHAKE_FAILED");i.trace("initiator receive SDP answer %s",p.data);let y=new Qs({type:"answer",sdp:p.data});return await r.setRemoteDescription(y).catch(x=>{throw i.error("could not execute setRemoteDescription",x),new N("Failed to set remoteDescription","ERR_SDP_HANDSHAKE_FAILED")}),i.trace("initiator read candidates until connected"),await no(r,g,{direction:"initiator",signal:e,log:i}),i.trace("initiator connected, closing init channel"),d.close(),i.trace("initiator closing signalling stream"),await g.unwrap().unwrap().close({signal:e}),i.trace("initiator connected to remote address %s",n),{remoteAddress:n}}catch(d){throw r.close(),m.abort(d),d}finally{r.onicecandidate=null,r.onicecandidateerror=null}}finally{if(f)try{await l.close({signal:e})}catch(m){l.abort(m)}}}var pb=L("dns4"),mb=L("dns6"),gb=L("dnsaddr"),Dr=be(L("dns"),gb,pb,mb),ao=be(L("ip4"),L("ip6")),en=be(K(ao,L("tcp")),K(Dr,L("tcp"))),co=K(ao,L("udp")),bb=K(co,L("utp")),yb=K(co,L("quic")),wb=K(co,L("quic-v1")),ac=be(K(en,L("ws")),K(Dr,L("ws"))),oo=be(K(ac,L("p2p")),ac),cc=be(K(en,L("wss")),K(Dr,L("wss")),K(en,L("tls"),L("ws")),K(Dr,L("tls"),L("ws"))),io=be(K(cc,L("p2p")),cc),uc=be(K(en,L("http")),K(ao,L("http")),K(Dr,L("http"))),lc=be(K(en,L("https")),K(ao,L("https")),K(Dr,L("https"))),Tf=K(co,L("webrtc-direct"),L("certhash")),Nf=be(K(Tf,L("p2p")),Tf),_f=K(wb,L("webtransport"),L("certhash"),L("certhash")),Lf=be(K(_f,L("p2p")),_f),Uf=be(K(oo,L("p2p-webrtc-star"),L("p2p")),K(io,L("p2p-webrtc-star"),L("p2p")),K(oo,L("p2p-webrtc-star")),K(io,L("p2p-webrtc-star"))),vA=be(K(oo,L("p2p-websocket-star"),L("p2p")),K(io,L("p2p-websocket-star"),L("p2p")),K(oo,L("p2p-websocket-star")),K(io,L("p2p-websocket-star"))),Of=be(K(uc,L("p2p-webrtc-direct"),L("p2p")),K(lc,L("p2p-webrtc-direct"),L("p2p")),K(uc,L("p2p-webrtc-direct")),K(lc,L("p2p-webrtc-direct"))),Br=be(ac,cc,uc,lc,Uf,Of,en,bb,yb,Dr,Nf,Lf),AA=be(K(Br,L("p2p-stardust"),L("p2p")),K(Br,L("p2p-stardust"))),Jt=be(K(Br,L("p2p")),Uf,Of,Nf,Lf,L("p2p")),Rf=be(K(Jt,L("p2p-circuit"),Jt),K(Jt,L("p2p-circuit")),K(L("p2p-circuit"),Jt),K(Br,L("p2p-circuit")),K(L("p2p-circuit"),Br),L("p2p-circuit")),Pf=()=>be(K(Rf,Pf),Rf),It=Pf(),DA=be(K(It,Jt,It),K(Jt,It),K(It,Jt),It,Jt);var BA=be(K(It,L("webrtc"),L("p2p")),K(It,L("webrtc")),K(Br,L("webrtc"),L("p2p")),K(Br,L("webrtc")),L("webrtc"));function Mf(r){function e(t){let n;try{n=et(t)}catch{return!1}let s=r(n.protoNames());return s===null?!1:s===!0||s===!1?s:s.length===0}return e}function K(...r){function e(t){if(t.length<r.length)return null;let n=t;return r.some(s=>(n=typeof s=="function"?s().partialMatch(t):s.partialMatch(t),Array.isArray(n)&&(t=n),n===null)),n}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Mf(e),partialMatch:e}}function be(...r){function e(n){let s=null;return r.some(o=>{let i=typeof o=="function"?o().partialMatch(n):o.partialMatch(n);return i!=null?(s=i,!0):!1}),s}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Mf(e),partialMatch:e}}function L(r){let e=r;function t(s){let o;try{o=et(s)}catch{return!1}let i=o.protoNames();return i.length===1&&i[0]===e}function n(s){return s.length===0?null:s[0]===e?s.slice(1):null}return{toString:function(){return e},matches:t,partialMatch:n}}var uo=class extends ks{peerId;transportManager;shutdownController;constructor(e,t){super(),this.peerId=e.peerId,this.transportManager=e.transportManager,this.shutdownController=t.shutdownController}async listen(){this.safeDispatchEvent("listening",{})}getAddrs(){return this.transportManager.getListeners().filter(e=>e!==this).map(e=>e.getAddrs().filter(t=>It.matches(t)).map(t=>t.encapsulate(`/webrtc/p2p/${this.peerId}`))).flat()}async close(){this.shutdownController.abort(),this.safeDispatchEvent("close",{})}};async function Ff({peerConnection:r,stream:e,signal:t,connection:n,log:s}){s.trace("new inbound signaling stream");let o=ro(e).pb(Ke);try{r.onicecandidate=({candidate:l})=>{let f=JSON.stringify(l?.toJSON()??null);s.trace("recipient sending ICE candidate %s",f),o.write({type:Ke.Type.ICE_CANDIDATE,data:f},{signal:t}).catch(m=>{s.error("error sending ICE candidate",m)})};let a=await o.read({signal:t});if(a.type!==Ke.Type.SDP_OFFER)throw new N(`expected message type SDP_OFFER, received: ${a.type??"undefined"} `,"ERR_SDP_HANDSHAKE_FAILED");s.trace("recipient receive SDP offer %s",a.data);let c=new Qs({type:"offer",sdp:a.data});await r.setRemoteDescription(c).catch(l=>{throw s.error("could not execute setRemoteDescription",l),new N("Failed to set remoteDescription","ERR_SDP_HANDSHAKE_FAILED")});let u=await r.createAnswer().catch(l=>{throw s.error("could not execute createAnswer",l),new N("Failed to create answer","ERR_SDP_HANDSHAKE_FAILED")});s.trace("recipient send SDP answer %s",u.sdp),await o.write({type:Ke.Type.SDP_ANSWER,data:u.sdp},{signal:t}),await r.setLocalDescription(u).catch(l=>{throw s.error("could not execute setLocalDescription",l),new N("Failed to set localDescription","ERR_SDP_HANDSHAKE_FAILED")}),s.trace("recipient read candidates until connected"),await no(r,o,{direction:"recipient",signal:t,log:s})}catch(a){if(r.connectionState!=="connected")throw s.error("error while handling signaling stream from peer %a",n.remoteAddr,a),r.close(),a;s("error while handling signaling stream from peer %a, ignoring as the RTCPeerConnection is already connected",n.remoteAddr,a)}let i=et(`/webrtc/p2p/${n.remoteAddr.getPeerId()}`);return s.trace("recipient connected to remote address %s",i),{remoteAddress:i}}var xb="/webrtc",Eb="/p2p-circuit",so="/webrtc-signaling/0.0.1",vb=30*1e3,lo=class{components;init;log;_started=!1;metrics;shutdownController;constructor(e,t={}){this.components=e,this.init=t,this.log=e.logger.forComponent("libp2p:webrtc"),this.shutdownController=new AbortController,Ss(1/0,this.shutdownController.signal),e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_webrtc_dialer_events_total",{label:"event",help:"Total count of WebRTC dialer events by type"}),listenerEvents:e.metrics.registerCounterGroup("libp2p_webrtc_listener_events_total",{label:"event",help:"Total count of WebRTC listener events by type"})})}isStarted(){return this._started}async start(){await this.components.registrar.handle(so,e=>{this._onProtocol(e).catch(t=>{this.log.error("failed to handle incoming connect from %p",e.connection.remotePeer,t)})},{runOnTransientConnection:!0}),this._started=!0}async stop(){await this.components.registrar.unhandle(so),this._started=!1}createListener(e){return new uo(this.components,{shutdownController:this.shutdownController})}[Symbol.toStringTag]="@libp2p/webrtc";[Bs]=!0;filter(e){return e.filter(Yl.exactMatch)}async dial(e,t){this.log.trace("dialing address: %a",e);let n=new Qr(this.init.rtcConfiguration),s=new Ar(this.components,{peerConnection:n,dataChannelOptions:this.init.dataChannel}),{remoteAddress:o}=await Cf({peerConnection:n,multiaddr:e,dataChannelOptions:this.init.dataChannel,signal:t.signal,connectionManager:this.components.connectionManager,transportManager:this.components.transportManager,log:this.log}),i=new br(this.components,{peerConnection:n,timeline:{open:Date.now()},remoteAddr:o,metrics:this.metrics?.dialerEvents}),a=await t.upgrader.upgradeOutbound(i,{skipProtection:!0,skipEncryption:!0,muxerFactory:s});return this._closeOnShutdown(n,i),a}async _onProtocol({connection:e,stream:t}){let n=AbortSignal.timeout(this.init.inboundConnectionTimeout??vb),s=new Qr(this.init.rtcConfiguration),o=new Ar(this.components,{peerConnection:s,dataChannelOptions:this.init.dataChannel});try{let{remoteAddress:i}=await Ff({peerConnection:s,connection:e,stream:t,signal:n,log:this.log}),a=new br(this.components,{peerConnection:s,timeline:{open:new Date().getTime()},remoteAddr:i,metrics:this.metrics?.listenerEvents});this._closeOnShutdown(s,a),await this.components.upgrader.upgradeInbound(a,{skipEncryption:!0,skipProtection:!0,muxerFactory:o}),await t.close({signal:n})}catch(i){throw t.abort(i),i}}_closeOnShutdown(e,t){let n=()=>{t.close().catch(s=>{this.log.error("could not close WebRTCMultiaddrConnection",s)})};this.shutdownController.signal.addEventListener("abort",n),e.addEventListener("close",()=>{this.shutdownController.signal.removeEventListener("abort",n)})}};function If(r){let e=r.toString().split(xb+"/");if(e.length!==2)throw new N("webrtc protocol was not present in multiaddr",qe.ERR_INVALID_MULTIADDR);if(!e[0].includes(Eb))throw new N("p2p-circuit protocol was not present in multiaddr",qe.ERR_INVALID_MULTIADDR);let t=et(e[0]),s=et("/"+e[1]).getPeerId();if(s==null)throw new N("destination peer id was missing",qe.ERR_INVALID_MULTIADDR);let o=t.protos().pop();if(o===void 0)throw new N("invalid multiaddr",qe.ERR_INVALID_MULTIADDR);return o.name!=="p2p"&&(t=t.encapsulate(`/p2p/${s}`)),{baseAddr:t,peerId:mr(s)}}var Ic={};J(Ic,{Ed25519PrivateKey:()=>Tr,Ed25519PublicKey:()=>Xn,generateKeyPair:()=>_y,generateKeyPairFromSeed:()=>ph,unmarshalEd25519PrivateKey:()=>Iy,unmarshalEd25519PublicKey:()=>Ty});function je(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Qt(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`Wrong positive integer: ${r}`)}function Ab(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function fc(r,...e){if(!Ab(r))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(r.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${r.length}`)}function Sr(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Qt(r.outputLen),Qt(r.blockLen)}function tn(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function Vf(r,e){fc(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var fo=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Hf(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var nn=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),ot=(r,e)=>r<<32-e|r>>>e,Db=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Db)throw new Error("Non little-endian hardware is not supported");var Bb=async()=>{};async function Kf(r,e,t){let n=Date.now();for(let s=0;s<r;s++){t(s);let o=Date.now()-n;o>=0&&o<e||(await Bb(),n+=o)}}function hc(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function it(r){if(typeof r=="string"&&(r=hc(r)),!Hf(r))throw new Error(`expected Uint8Array, got ${typeof r}`);return r}function ho(...r){let e=0;for(let n=0;n<r.length;n++){let s=r[n];if(!Hf(s))throw new Error("Uint8Array expected");e+=s.length}let t=new Uint8Array(e);for(let n=0,s=0;n<r.length;n++){let o=r[n];t.set(o,s),s+=o.length}return t}var rn=class{clone(){return this._cloneInto()}},Sb={}.toString;function $f(r,e){if(e!==void 0&&Sb.call(e)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(r,e)}function po(r){let e=n=>r().update(it(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function kr(r=32){if(fo&&typeof fo.getRandomValues=="function")return fo.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function kb(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let s=BigInt(32),o=BigInt(4294967295),i=Number(t>>s&o),a=Number(t&o),c=n?4:0,u=n?0:4;r.setUint32(e+c,i,n),r.setUint32(e+u,a,n)}var sn=class extends rn{constructor(e,t,n,s){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=nn(this.buffer)}update(e){tn(this);let{view:t,buffer:n,blockLen:s}=this;e=it(e);let o=e.length;for(let i=0;i<o;){let a=Math.min(s-this.pos,o-i);if(a===s){let c=nn(e);for(;s<=o-i;i+=s)this.process(c,i);continue}n.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===s&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){tn(this),Vf(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:s,isLE:o}=this,{pos:i}=this;t[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>s-i&&(this.process(n,0),i=0);for(let f=i;f<s;f++)t[f]=0;kb(n,s-8,BigInt(this.length*8),o),this.process(n,0);let a=nn(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)a.setUint32(4*f,l[f],o)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:s,finished:o,destroyed:i,pos:a}=this;return e.length=s,e.pos=a,e.finished=o,e.destroyed=i,s%t&&e.buffer.set(n),e}};var mo=BigInt(4294967295),dc=BigInt(32);function qf(r,e=!1){return e?{h:Number(r&mo),l:Number(r>>dc&mo)}:{h:Number(r>>dc&mo)|0,l:Number(r&mo)|0}}function Cb(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let s=0;s<r.length;s++){let{h:o,l:i}=qf(r[s],e);[t[s],n[s]]=[o,i]}return[t,n]}var Ib=(r,e)=>BigInt(r>>>0)<<dc|BigInt(e>>>0),Tb=(r,e,t)=>r>>>t,_b=(r,e,t)=>r<<32-t|e>>>t,Rb=(r,e,t)=>r>>>t|e<<32-t,Nb=(r,e,t)=>r<<32-t|e>>>t,Lb=(r,e,t)=>r<<64-t|e>>>t-32,Ub=(r,e,t)=>r>>>t-32|e<<64-t,Ob=(r,e)=>e,Pb=(r,e)=>r,Mb=(r,e,t)=>r<<t|e>>>32-t,Fb=(r,e,t)=>e<<t|r>>>32-t,Vb=(r,e,t)=>e<<t-32|r>>>64-t,Hb=(r,e,t)=>r<<t-32|e>>>64-t;function Kb(r,e,t,n){let s=(e>>>0)+(n>>>0);return{h:r+t+(s/2**32|0)|0,l:s|0}}var $b=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),qb=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,Wb=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),zb=(r,e,t,n,s)=>e+t+n+s+(r/2**32|0)|0,Gb=(r,e,t,n,s)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(s>>>0),jb=(r,e,t,n,s,o)=>e+t+n+s+o+(r/2**32|0)|0;var Yb={fromBig:qf,split:Cb,toBig:Ib,shrSH:Tb,shrSL:_b,rotrSH:Rb,rotrSL:Nb,rotrBH:Lb,rotrBL:Ub,rotr32H:Ob,rotr32L:Pb,rotlSH:Mb,rotlSL:Fb,rotlBH:Vb,rotlBL:Hb,add:Kb,add3L:$b,add3H:qb,add4L:Wb,add4H:zb,add5H:jb,add5L:Gb},Y=Yb;var[Zb,Xb]=Y.split(["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(r=>BigInt(r))),er=new Uint32Array(80),tr=new Uint32Array(80),pc=class extends sn{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:e,Al:t,Bh:n,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:u,El:l,Fh:f,Fl:m,Gh:g,Gl:d,Hh:h,Hl:p}=this;return[e,t,n,s,o,i,a,c,u,l,f,m,g,d,h,p]}set(e,t,n,s,o,i,a,c,u,l,f,m,g,d,h,p){this.Ah=e|0,this.Al=t|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=l|0,this.Fh=f|0,this.Fl=m|0,this.Gh=g|0,this.Gl=d|0,this.Hh=h|0,this.Hl=p|0}process(e,t){for(let b=0;b<16;b++,t+=4)er[b]=e.getUint32(t),tr[b]=e.getUint32(t+=4);for(let b=16;b<80;b++){let v=er[b-15]|0,E=tr[b-15]|0,A=Y.rotrSH(v,E,1)^Y.rotrSH(v,E,8)^Y.shrSH(v,E,7),S=Y.rotrSL(v,E,1)^Y.rotrSL(v,E,8)^Y.shrSL(v,E,7),D=er[b-2]|0,_=tr[b-2]|0,U=Y.rotrSH(D,_,19)^Y.rotrBH(D,_,61)^Y.shrSH(D,_,6),R=Y.rotrSL(D,_,19)^Y.rotrBL(D,_,61)^Y.shrSL(D,_,6),H=Y.add4L(S,R,tr[b-7],tr[b-16]),V=Y.add4H(H,A,U,er[b-7],er[b-16]);er[b]=V|0,tr[b]=H|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:u,Dl:l,Eh:f,El:m,Fh:g,Fl:d,Gh:h,Gl:p,Hh:y,Hl:x}=this;for(let b=0;b<80;b++){let v=Y.rotrSH(f,m,14)^Y.rotrSH(f,m,18)^Y.rotrBH(f,m,41),E=Y.rotrSL(f,m,14)^Y.rotrSL(f,m,18)^Y.rotrBL(f,m,41),A=f&g^~f&h,S=m&d^~m&p,D=Y.add5L(x,E,S,Xb[b],tr[b]),_=Y.add5H(D,y,v,A,Zb[b],er[b]),U=D|0,R=Y.rotrSH(n,s,28)^Y.rotrBH(n,s,34)^Y.rotrBH(n,s,39),H=Y.rotrSL(n,s,28)^Y.rotrBL(n,s,34)^Y.rotrBL(n,s,39),V=n&o^n&a^o&a,G=s&i^s&c^i&c;y=h|0,x=p|0,h=g|0,p=d|0,g=f|0,d=m|0,{h:f,l:m}=Y.add(u|0,l|0,_|0,U|0),u=a|0,l=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let B=Y.add3L(U,H,G);n=Y.add3H(B,_,R,V),s=B|0}({h:n,l:s}=Y.add(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=Y.add(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=Y.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=Y.add(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:m}=Y.add(this.Eh|0,this.El|0,f|0,m|0),{h:g,l:d}=Y.add(this.Fh|0,this.Fl|0,g|0,d|0),{h,l:p}=Y.add(this.Gh|0,this.Gl|0,h|0,p|0),{h:y,l:x}=Y.add(this.Hh|0,this.Hl|0,y|0,x|0),this.set(n,s,o,i,a,c,u,l,f,m,g,d,h,p,y,x)}roundClean(){er.fill(0),tr.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var on=po(()=>new pc);var bo={};J(bo,{bitGet:()=>sy,bitLen:()=>ny,bitMask:()=>zn,bitSet:()=>oy,bytesToHex:()=>_t,bytesToNumberBE:()=>Rt,bytesToNumberLE:()=>ct,concatBytes:()=>Lt,createHmacDrbg:()=>bc,ensureBytes:()=>ie,equalBytes:()=>ty,hexToBytes:()=>Cr,hexToNumber:()=>gc,isBytes:()=>at,numberToBytesBE:()=>rr,numberToBytesLE:()=>Nt,numberToHexUnpadded:()=>jf,numberToVarBytesBE:()=>ey,utf8ToBytes:()=>ry,validateObject:()=>Ye});var Gf=BigInt(0),go=BigInt(1),Jb=BigInt(2);function at(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var Qb=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function _t(r){if(!at(r))throw new Error("Uint8Array expected");let e="";for(let t=0;t<r.length;t++)e+=Qb[r[t]];return e}function jf(r){let e=r.toString(16);return e.length&1?`0${e}`:e}function gc(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var Tt={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function Wf(r){if(r>=Tt._0&&r<=Tt._9)return r-Tt._0;if(r>=Tt._A&&r<=Tt._F)return r-(Tt._A-10);if(r>=Tt._a&&r<=Tt._f)return r-(Tt._a-10)}function Cr(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let e=r.length,t=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let s=0,o=0;s<t;s++,o+=2){let i=Wf(r.charCodeAt(o)),a=Wf(r.charCodeAt(o+1));if(i===void 0||a===void 0){let c=r[o]+r[o+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+o)}n[s]=i*16+a}return n}function Rt(r){return gc(_t(r))}function ct(r){if(!at(r))throw new Error("Uint8Array expected");return gc(_t(Uint8Array.from(r).reverse()))}function rr(r,e){return Cr(r.toString(16).padStart(e*2,"0"))}function Nt(r,e){return rr(r,e).reverse()}function ey(r){return Cr(jf(r))}function ie(r,e,t){let n;if(typeof e=="string")try{n=Cr(e)}catch(o){throw new Error(`${r} must be valid hex string, got "${e}". Cause: ${o}`)}else if(at(e))n=Uint8Array.from(e);else throw new Error(`${r} must be hex string or Uint8Array`);let s=n.length;if(typeof t=="number"&&s!==t)throw new Error(`${r} expected ${t} bytes, got ${s}`);return n}function Lt(...r){let e=0;for(let s=0;s<r.length;s++){let o=r[s];if(!at(o))throw new Error("Uint8Array expected");e+=o.length}let t=new Uint8Array(e),n=0;for(let s=0;s<r.length;s++){let o=r[s];t.set(o,n),n+=o.length}return t}function ty(r,e){if(r.length!==e.length)return!1;let t=0;for(let n=0;n<r.length;n++)t|=r[n]^e[n];return t===0}function ry(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function ny(r){let e;for(e=0;r>Gf;r>>=go,e+=1);return e}function sy(r,e){return r>>BigInt(e)&go}var oy=(r,e,t)=>r|(t?go:Gf)<<BigInt(e),zn=r=>(Jb<<BigInt(r-1))-go,mc=r=>new Uint8Array(r),zf=r=>Uint8Array.from(r);function bc(r,e,t){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof t!="function")throw new Error("hmacFn must be a function");let n=mc(r),s=mc(r),o=0,i=()=>{n.fill(1),s.fill(0),o=0},a=(...f)=>t(s,n,...f),c=(f=mc())=>{s=a(zf([0]),f),n=a(),f.length!==0&&(s=a(zf([1]),f),n=a())},u=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,m=[];for(;f<e;){n=a();let g=n.slice();m.push(g),f+=n.length}return Lt(...m)};return(f,m)=>{i(),c(f);let g;for(;!(g=m(u()));)c();return i(),g}}var iy={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||at(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,e)=>e.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function Ye(r,e,t={}){let n=(s,o,i)=>{let a=iy[o];if(typeof a!="function")throw new Error(`Invalid validator "${o}", expected function`);let c=r[s];if(!(i&&c===void 0)&&!a(c,r))throw new Error(`Invalid param ${String(s)}=${c} (${typeof c}), expected ${o}`)};for(let[s,o]of Object.entries(e))n(s,o,!1);for(let[s,o]of Object.entries(t))n(s,o,!0);return r}var Se=BigInt(0),ue=BigInt(1),Ir=BigInt(2),ay=BigInt(3),yc=BigInt(4),Yf=BigInt(5),Zf=BigInt(8),cy=BigInt(9),uy=BigInt(16);function ee(r,e){let t=r%e;return t>=Se?t:e+t}function wc(r,e,t){if(t<=Se||e<Se)throw new Error("Expected power/modulo > 0");if(t===ue)return Se;let n=ue;for(;e>Se;)e&ue&&(n=n*r%t),r=r*r%t,e>>=ue;return n}function ae(r,e,t){let n=r;for(;e-- >Se;)n*=n,n%=t;return n}function yo(r,e){if(r===Se||e<=Se)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=ee(r,e),n=e,s=Se,o=ue,i=ue,a=Se;for(;t!==Se;){let u=n/t,l=n%t,f=s-i*u,m=o-a*u;n=t,t=l,s=i,o=a,i=f,a=m}if(n!==ue)throw new Error("invert: does not exist");return ee(s,e)}function ly(r){let e=(r-ue)/Ir,t,n,s;for(t=r-ue,n=0;t%Ir===Se;t/=Ir,n++);for(s=Ir;s<r&&wc(s,e,r)!==r-ue;s++);if(n===1){let i=(r+ue)/yc;return function(c,u){let l=c.pow(u,i);if(!c.eql(c.sqr(l),u))throw new Error("Cannot find square root");return l}}let o=(t+ue)/Ir;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let u=n,l=a.pow(a.mul(a.ONE,s),t),f=a.pow(c,o),m=a.pow(c,t);for(;!a.eql(m,a.ONE);){if(a.eql(m,a.ZERO))return a.ZERO;let g=1;for(let h=a.sqr(m);g<u&&!a.eql(h,a.ONE);g++)h=a.sqr(h);let d=a.pow(l,ue<<BigInt(u-g-1));l=a.sqr(d),f=a.mul(f,d),m=a.mul(m,l),u=g}return f}}function fy(r){if(r%yc===ay){let e=(r+ue)/yc;return function(n,s){let o=n.pow(s,e);if(!n.eql(n.sqr(o),s))throw new Error("Cannot find square root");return o}}if(r%Zf===Yf){let e=(r-Yf)/Zf;return function(n,s){let o=n.mul(s,Ir),i=n.pow(o,e),a=n.mul(s,i),c=n.mul(n.mul(a,Ir),i),u=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(u),s))throw new Error("Cannot find square root");return u}}return r%uy,ly(r)}var Xf=(r,e)=>(ee(r,e)&ue)===ue,hy=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function xc(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=hy.reduce((n,s)=>(n[s]="function",n),e);return Ye(r,t)}function dy(r,e,t){if(t<Se)throw new Error("Expected power > 0");if(t===Se)return r.ONE;if(t===ue)return e;let n=r.ONE,s=e;for(;t>Se;)t&ue&&(n=r.mul(n,s)),s=r.sqr(s),t>>=ue;return n}function py(r,e){let t=new Array(e.length),n=e.reduce((o,i,a)=>r.is0(i)?o:(t[a]=o,r.mul(o,i)),r.ONE),s=r.inv(n);return e.reduceRight((o,i,a)=>r.is0(i)?o:(t[a]=r.mul(o,t[a]),r.mul(o,i)),s),t}function Ec(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function wo(r,e,t=!1,n={}){if(r<=Se)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:s,nByteLength:o}=Ec(r,e);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let i=fy(r),a=Object.freeze({ORDER:r,BITS:s,BYTES:o,MASK:zn(s),ZERO:Se,ONE:ue,create:c=>ee(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return Se<=c&&c<r},is0:c=>c===Se,isOdd:c=>(c&ue)===ue,neg:c=>ee(-c,r),eql:(c,u)=>c===u,sqr:c=>ee(c*c,r),add:(c,u)=>ee(c+u,r),sub:(c,u)=>ee(c-u,r),mul:(c,u)=>ee(c*u,r),pow:(c,u)=>dy(a,c,u),div:(c,u)=>ee(c*yo(u,r),r),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>yo(c,r),sqrt:n.sqrt||(c=>i(a,c)),invertBatch:c=>py(a,c),cmov:(c,u,l)=>l?u:c,toBytes:c=>t?Nt(c,o):rr(c,o),fromBytes:c=>{if(c.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);return t?ct(c):Rt(c)}});return Object.freeze(a)}function Jf(r,e){if(!r.isOdd)throw new Error("Field doesn't have isOdd");let t=r.sqrt(e);return r.isOdd(t)?r.neg(t):t}function Qf(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let e=r.toString(2).length;return Math.ceil(e/8)}function vc(r){let e=Qf(r);return e+Math.ceil(e/2)}function eh(r,e,t=!1){let n=r.length,s=Qf(e),o=vc(e);if(n<16||n<o||n>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${n}`);let i=t?Rt(r):ct(r),a=ee(i,e-ue)+ue;return t?Nt(a,s):rr(a,s)}var gy=BigInt(0),Ac=BigInt(1);function xo(r,e){let t=(s,o)=>{let i=o.negate();return s?i:o},n=s=>{let o=Math.ceil(e/s)+1,i=2**(s-1);return{windows:o,windowSize:i}};return{constTimeNegate:t,unsafeLadder(s,o){let i=r.ZERO,a=s;for(;o>gy;)o&Ac&&(i=i.add(a)),a=a.double(),o>>=Ac;return i},precomputeWindow(s,o){let{windows:i,windowSize:a}=n(o),c=[],u=s,l=u;for(let f=0;f<i;f++){l=u,c.push(l);for(let m=1;m<a;m++)l=l.add(u),c.push(l);u=l.double()}return c},wNAF(s,o,i){let{windows:a,windowSize:c}=n(s),u=r.ZERO,l=r.BASE,f=BigInt(2**s-1),m=2**s,g=BigInt(s);for(let d=0;d<a;d++){let h=d*c,p=Number(i&f);i>>=g,p>c&&(p-=m,i+=Ac);let y=h,x=h+Math.abs(p)-1,b=d%2!==0,v=p<0;p===0?l=l.add(t(b,o[y])):u=u.add(t(v,o[x]))}return{p:u,f:l}},wNAFCached(s,o,i,a){let c=s._WINDOW_SIZE||1,u=o.get(s);return u||(u=this.precomputeWindow(s,c),c!==1&&o.set(s,a(u))),this.wNAF(c,u,i)}}}function Gn(r){return xc(r.Fp),Ye(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Ec(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var ut=BigInt(0),ze=BigInt(1),Eo=BigInt(2),by=BigInt(8),yy={zip215:!0};function wy(r){let e=Gn(r);return Ye(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function vo(r){let e=wy(r),{Fp:t,n,prehash:s,hash:o,randomBytes:i,nByteLength:a,h:c}=e,u=Eo<<BigInt(a*8)-ze,l=t.create,f=e.uvRatio||((k,w)=>{try{return{isValid:!0,value:t.sqrt(k*t.inv(w))}}catch{return{isValid:!1,value:ut}}}),m=e.adjustScalarBytes||(k=>k),g=e.domain||((k,w,C)=>{if(w.length||C)throw new Error("Contexts/pre-hash are not supported");return k}),d=k=>typeof k=="bigint"&&ut<k,h=(k,w)=>d(k)&&d(w)&&k<w,p=k=>k===ut||h(k,u);function y(k,w){if(h(k,w))return k;throw new Error(`Expected valid scalar < ${w}, got ${typeof k} ${k}`)}function x(k){return k===ut?k:y(k,n)}let b=new Map;function v(k){if(!(k instanceof E))throw new Error("ExtendedPoint expected")}class E{constructor(w,C,T,O){if(this.ex=w,this.ey=C,this.ez=T,this.et=O,!p(w))throw new Error("x required");if(!p(C))throw new Error("y required");if(!p(T))throw new Error("z required");if(!p(O))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(w){if(w instanceof E)throw new Error("extended point not allowed");let{x:C,y:T}=w||{};if(!p(C)||!p(T))throw new Error("invalid affine point");return new E(C,T,ze,l(C*T))}static normalizeZ(w){let C=t.invertBatch(w.map(T=>T.ez));return w.map((T,O)=>T.toAffine(C[O])).map(E.fromAffine)}_setWindowSize(w){this._WINDOW_SIZE=w,b.delete(this)}assertValidity(){let{a:w,d:C}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:T,ey:O,ez:$,et:q}=this,Z=l(T*T),W=l(O*O),j=l($*$),oe=l(j*j),se=l(Z*w),Ce=l(j*l(se+W)),Ie=l(oe+l(C*l(Z*W)));if(Ce!==Ie)throw new Error("bad point: equation left != right (1)");let Ee=l(T*O),Le=l($*q);if(Ee!==Le)throw new Error("bad point: equation left != right (2)")}equals(w){v(w);let{ex:C,ey:T,ez:O}=this,{ex:$,ey:q,ez:Z}=w,W=l(C*Z),j=l($*O),oe=l(T*Z),se=l(q*O);return W===j&&oe===se}is0(){return this.equals(E.ZERO)}negate(){return new E(l(-this.ex),this.ey,this.ez,l(-this.et))}double(){let{a:w}=e,{ex:C,ey:T,ez:O}=this,$=l(C*C),q=l(T*T),Z=l(Eo*l(O*O)),W=l(w*$),j=C+T,oe=l(l(j*j)-$-q),se=W+q,Ce=se-Z,Ie=W-q,Ee=l(oe*Ce),Le=l(se*Ie),Bt=l(oe*Ie),hr=l(Ce*se);return new E(Ee,Le,hr,Bt)}add(w){v(w);let{a:C,d:T}=e,{ex:O,ey:$,ez:q,et:Z}=this,{ex:W,ey:j,ez:oe,et:se}=w;if(C===BigInt(-1)){let zu=l(($-O)*(j+W)),Gu=l(($+O)*(j-W)),Oi=l(Gu-zu);if(Oi===ut)return this.double();let ju=l(q*Eo*se),Yu=l(Z*Eo*oe),Zu=Yu+ju,Xu=Gu+zu,Ju=Yu-ju,Np=l(Zu*Oi),Lp=l(Xu*Ju),Up=l(Zu*Ju),Op=l(Oi*Xu);return new E(Np,Lp,Op,Up)}let Ce=l(O*W),Ie=l($*j),Ee=l(Z*T*se),Le=l(q*oe),Bt=l((O+$)*(W+j)-Ce-Ie),hr=Le-Ee,_n=Le+Ee,Wu=l(Ie-C*Ce),Ip=l(Bt*hr),Tp=l(_n*Wu),_p=l(Bt*Wu),Rp=l(hr*_n);return new E(Ip,Tp,Rp,_p)}subtract(w){return this.add(w.negate())}wNAF(w){return D.wNAFCached(this,b,w,E.normalizeZ)}multiply(w){let{p:C,f:T}=this.wNAF(y(w,n));return E.normalizeZ([C,T])[0]}multiplyUnsafe(w){let C=x(w);return C===ut?S:this.equals(S)||C===ze?this:this.equals(A)?this.wNAF(C).p:D.unsafeLadder(this,C)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return D.unsafeLadder(this,n).is0()}toAffine(w){let{ex:C,ey:T,ez:O}=this,$=this.is0();w==null&&(w=$?by:t.inv(O));let q=l(C*w),Z=l(T*w),W=l(O*w);if($)return{x:ut,y:ze};if(W!==ze)throw new Error("invZ was invalid");return{x:q,y:Z}}clearCofactor(){let{h:w}=e;return w===ze?this:this.multiplyUnsafe(w)}static fromHex(w,C=!1){let{d:T,a:O}=e,$=t.BYTES;w=ie("pointHex",w,$);let q=w.slice(),Z=w[$-1];q[$-1]=Z&-129;let W=ct(q);W===ut||(C?y(W,u):y(W,t.ORDER));let j=l(W*W),oe=l(j-ze),se=l(T*j-O),{isValid:Ce,value:Ie}=f(oe,se);if(!Ce)throw new Error("Point.fromHex: invalid y coordinate");let Ee=(Ie&ze)===ze,Le=(Z&128)!==0;if(!C&&Ie===ut&&Le)throw new Error("Point.fromHex: x=0 and x_0=1");return Le!==Ee&&(Ie=l(-Ie)),E.fromAffine({x:Ie,y:W})}static fromPrivateKey(w){return R(w).point}toRawBytes(){let{x:w,y:C}=this.toAffine(),T=Nt(C,t.BYTES);return T[T.length-1]|=w&ze?128:0,T}toHex(){return _t(this.toRawBytes())}}E.BASE=new E(e.Gx,e.Gy,ze,l(e.Gx*e.Gy)),E.ZERO=new E(ut,ze,ze,ut);let{BASE:A,ZERO:S}=E,D=xo(E,a*8);function _(k){return ee(k,n)}function U(k){return _(ct(k))}function R(k){let w=a;k=ie("private key",k,w);let C=ie("hashed private key",o(k),2*w),T=m(C.slice(0,w)),O=C.slice(w,2*w),$=U(T),q=A.multiply($),Z=q.toRawBytes();return{head:T,prefix:O,scalar:$,point:q,pointBytes:Z}}function H(k){return R(k).pointBytes}function V(k=new Uint8Array,...w){let C=Lt(...w);return U(o(g(C,ie("context",k),!!s)))}function G(k,w,C={}){k=ie("message",k),s&&(k=s(k));let{prefix:T,scalar:O,pointBytes:$}=R(w),q=V(C.context,T,k),Z=A.multiply(q).toRawBytes(),W=V(C.context,Z,$,k),j=_(q+W*O);x(j);let oe=Lt(Z,Nt(j,t.BYTES));return ie("result",oe,a*2)}let B=yy;function I(k,w,C,T=B){let{context:O,zip215:$}=T,q=t.BYTES;k=ie("signature",k,2*q),w=ie("message",w),s&&(w=s(w));let Z=ct(k.slice(q,2*q)),W,j,oe;try{W=E.fromHex(C,$),j=E.fromHex(k.slice(0,q),$),oe=A.multiplyUnsafe(Z)}catch{return!1}if(!$&&W.isSmallOrder())return!1;let se=V(O,j.toRawBytes(),W.toRawBytes(),w);return j.add(W.multiplyUnsafe(se)).subtract(oe).clearCofactor().equals(E.ZERO)}return A._setWindowSize(8),{CURVE:e,getPublicKey:H,sign:G,verify:I,ExtendedPoint:E,utils:{getExtendedPublicKey:R,randomPrivateKey:()=>i(t.BYTES),precompute(k=8,w=E.BASE){return w._setWindowSize(k),w.multiply(BigInt(3)),w}}}}var jn=BigInt(0),Dc=BigInt(1);function xy(r){return Ye(r,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...r})}function th(r){let e=xy(r),{P:t}=e,n=b=>ee(b,t),s=e.montgomeryBits,o=Math.ceil(s/8),i=e.nByteLength,a=e.adjustScalarBytes||(b=>b),c=e.powPminus2||(b=>wc(b,t-BigInt(2),t));function u(b,v,E){let A=n(b*(v-E));return v=n(v-A),E=n(E+A),[v,E]}function l(b){if(typeof b=="bigint"&&jn<=b&&b<t)return b;throw new Error("Expected valid scalar 0 < scalar < CURVE.P")}let f=(e.a-BigInt(2))/BigInt(4);function m(b,v){let E=l(b),A=l(v),S=E,D=Dc,_=jn,U=E,R=Dc,H=jn,V;for(let B=BigInt(s-1);B>=jn;B--){let I=A>>B&Dc;H^=I,V=u(H,D,U),D=V[0],U=V[1],V=u(H,_,R),_=V[0],R=V[1],H=I;let P=D+_,k=n(P*P),w=D-_,C=n(w*w),T=k-C,O=U+R,$=U-R,q=n($*P),Z=n(O*w),W=q+Z,j=q-Z;U=n(W*W),R=n(S*n(j*j)),D=n(k*C),_=n(T*(k+n(f*T)))}V=u(H,D,U),D=V[0],U=V[1],V=u(H,_,R),_=V[0],R=V[1];let G=c(_);return n(D*G)}function g(b){return Nt(n(b),o)}function d(b){let v=ie("u coordinate",b,o);return i===32&&(v[31]&=127),ct(v)}function h(b){let v=ie("scalar",b),E=v.length;if(E!==o&&E!==i)throw new Error(`Expected ${o} or ${i} bytes, got ${E}`);return ct(a(v))}function p(b,v){let E=d(v),A=h(b),S=m(E,A);if(S===jn)throw new Error("Invalid private or public key received");return g(S)}let y=g(e.Gu);function x(b){return p(b,y)}return{scalarMult:p,scalarMultBase:x,getSharedSecret:(b,v)=>p(b,v),getPublicKey:b=>x(b),utils:{randomPrivateKey:()=>e.randomBytes(e.nByteLength)},GuBytes:y}}var Yn=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),rh=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),CD=BigInt(0),Ey=BigInt(1),Bc=BigInt(2),vy=BigInt(5),nh=BigInt(10),Ay=BigInt(20),Dy=BigInt(40),sh=BigInt(80);function oh(r){let e=Yn,n=r*r%e*r%e,s=ae(n,Bc,e)*n%e,o=ae(s,Ey,e)*r%e,i=ae(o,vy,e)*o%e,a=ae(i,nh,e)*i%e,c=ae(a,Ay,e)*a%e,u=ae(c,Dy,e)*c%e,l=ae(u,sh,e)*u%e,f=ae(l,sh,e)*u%e,m=ae(f,nh,e)*i%e;return{pow_p_5_8:ae(m,Bc,e)*r%e,b2:n}}function ih(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function By(r,e){let t=Yn,n=ee(e*e*e,t),s=ee(n*n*e,t),o=oh(r*s).pow_p_5_8,i=ee(r*n*o,t),a=ee(e*i*i,t),c=i,u=ee(i*rh,t),l=a===r,f=a===ee(-r,t),m=a===ee(-r*rh,t);return l&&(i=c),(f||m)&&(i=u),Xf(i,t)&&(i=ee(-i,t)),{isValid:l||f,value:i}}var Ut=wo(Yn,void 0,!0),Sc={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Ut,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:on,randomBytes:kr,adjustScalarBytes:ih,uvRatio:By},an=vo(Sc);function ah(r,e,t){if(e.length>255)throw new Error("Context is too big");return ho(hc("SigEd25519 no Ed25519 collisions"),new Uint8Array([t?1:0,e.length]),e,r)}var ID=vo({...Sc,domain:ah}),TD=vo({...Sc,domain:ah,prehash:on}),Zn=th({P:Yn,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:r=>{let e=Yn,{pow_p_5_8:t,b2:n}=oh(r);return ee(ae(t,BigInt(3),e)*n,e)},adjustScalarBytes:ih,randomBytes:kr});var Sy=(Ut.ORDER+BigInt(3))/BigInt(8),_D=Ut.pow(Bc,Sy),RD=Ut.sqrt(Ut.neg(Ut.ONE)),ND=(Ut.ORDER-BigInt(5))/BigInt(8),LD=BigInt(486662);var UD=Jf(Ut,Ut.neg(BigInt(486664)));var OD=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),PD=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),MD=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),FD=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var VD=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var cn=32,Ot=64,Ao=32;function ch(){let r=an.utils.randomPrivateKey(),e=an.getPublicKey(r);return{privateKey:hh(r,e),publicKey:e}}function uh(r){if(r.length!==Ao)throw new TypeError('"seed" must be 32 bytes in length.');if(!(r instanceof Uint8Array))throw new TypeError('"seed" must be a node.js Buffer, or Uint8Array.');let e=r,t=an.getPublicKey(e);return{privateKey:hh(e,t),publicKey:t}}function lh(r,e){let t=r.subarray(0,Ao);return an.sign(e instanceof Uint8Array?e:e.subarray(),t)}function fh(r,e,t){return an.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}function hh(r,e){let t=new Uint8Array(Ot);for(let n=0;n<Ao;n++)t[n]=r[n],t[Ao+n]=e[n];return t}var Me={get(r=globalThis){let e=r.crypto;if(e==null||e.subtle==null)throw Object.assign(new Error("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"),{code:"ERR_MISSING_WEB_CRYPTO"});return e}};var kc={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function dh(r){let e=r?.algorithm??"AES-GCM",t=r?.keyLength??16,n=r?.nonceLength??12,s=r?.digest??"SHA-256",o=r?.saltLength??16,i=r?.iterations??32767,a=Me.get();t*=8;async function c(f,m){let g=a.getRandomValues(new Uint8Array(o)),d=a.getRandomValues(new Uint8Array(n)),h={name:e,iv:d};typeof m=="string"&&(m=Q(m));let p;if(m.length===0){p=await a.subtle.importKey("jwk",kc,{name:"AES-GCM"},!0,["encrypt"]);try{let x={name:"PBKDF2",salt:g,iterations:i,hash:{name:s}},b=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);p=await a.subtle.deriveKey(x,b,{name:e,length:t},!0,["encrypt"])}catch{p=await a.subtle.importKey("jwk",kc,{name:"AES-GCM"},!0,["encrypt"])}}else{let x={name:"PBKDF2",salt:g,iterations:i,hash:{name:s}},b=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);p=await a.subtle.deriveKey(x,b,{name:e,length:t},!0,["encrypt"])}let y=await a.subtle.encrypt(h,p,f);return we([g,h.iv,new Uint8Array(y)])}async function u(f,m){let g=f.subarray(0,o),d=f.subarray(o,o+n),h=f.subarray(o+n),p={name:e,iv:d};typeof m=="string"&&(m=Q(m));let y;if(m.length===0)try{let b={name:"PBKDF2",salt:g,iterations:i,hash:{name:s}},v=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(b,v,{name:e,length:t},!0,["decrypt"])}catch{y=await a.subtle.importKey("jwk",kc,{name:"AES-GCM"},!0,["decrypt"])}else{let b={name:"PBKDF2",salt:g,iterations:i,hash:{name:s}},v=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(b,v,{name:e,length:t},!0,["decrypt"])}let x=await a.subtle.decrypt(p,y,h);return new Uint8Array(x)}return{encrypt:c,decrypt:u}}async function un(r,e){let n=await dh().encrypt(r,e);return Yi.encode(n)}var le;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1"})(le||(le={}));var Cc;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1"})(Cc||(Cc={}));(function(r){r.codec=()=>vr(Cc)})(le||(le={}));var wt;(function(r){let e;r.codec=()=>(e==null&&(e=st((t,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),le.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),s.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let s={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let i=t.uint32();switch(i>>>3){case 1:s.Type=le.codec().decode(t);break;case 2:s.Data=t.bytes();break;default:t.skipType(i&7);break}}return s})),e),r.encode=t=>nt(t,r.codec()),r.decode=t=>rt(t,r.codec())})(wt||(wt={}));var xt;(function(r){let e;r.codec=()=>(e==null&&(e=st((t,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),le.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),s.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let s={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let i=t.uint32();switch(i>>>3){case 1:s.Type=le.codec().decode(t);break;case 2:s.Data=t.bytes();break;default:t.skipType(i&7);break}}return s})),e),r.encode=t=>nt(t,r.codec()),r.decode=t=>rt(t,r.codec())})(xt||(xt={}));var Xn=class{_key;constructor(e){this._key=ln(e,cn)}verify(e,t){return fh(this._key,t,e)}marshal(){return this._key}get bytes(){return wt.encode({Type:le.Ed25519,Data:this.marshal()}).subarray()}equals(e){return ve(this.bytes,e.bytes)}hash(){let e=Te.digest(this.bytes);return je(e)?e.then(({bytes:t})=>t):e.bytes}},Tr=class{_key;_publicKey;constructor(e,t){this._key=ln(e,Ot),this._publicKey=ln(t,cn)}sign(e){return lh(this._key,e)}get public(){return new Xn(this._publicKey)}marshal(){return this._key}get bytes(){return xt.encode({Type:le.Ed25519,Data:this.marshal()}).subarray()}equals(e){return ve(this.bytes,e.bytes)}async hash(){let e=Te.digest(this.bytes),t;return je(e)?{bytes:t}=await e:t=e.bytes,t}async id(){let e=jt.digest(this.public.bytes);return pe.encode(e.bytes).substring(1)}async export(e,t="libp2p-key"){if(t==="libp2p-key")return un(this.bytes,e);throw new N(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function Iy(r){if(r.length>Ot){r=ln(r,Ot+cn);let n=r.subarray(0,Ot),s=r.subarray(Ot,r.length);return new Tr(n,s)}r=ln(r,Ot);let e=r.subarray(0,Ot),t=r.subarray(cn);return new Tr(e,t)}function Ty(r){return r=ln(r,cn),new Xn(r)}async function _y(){let{privateKey:r,publicKey:e}=ch();return new Tr(r,e)}async function ph(r){let{privateKey:e,publicKey:t}=uh(r);return new Tr(e,t)}function ln(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new N(`Key must be a Uint8Array of length ${e}, got ${r.length}`,"ERR_INVALID_KEY_TYPE");return r}var Fc={};J(Fc,{MAX_RSA_KEY_SIZE:()=>cs,RsaPrivateKey:()=>mn,RsaPublicKey:()=>as,fromJwk:()=>sw,generateKeyPair:()=>ow,unmarshalRsaPrivateKey:()=>Pc,unmarshalRsaPublicKey:()=>nw});function _r(r){if(isNaN(r)||r<=0)throw new N("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return kr(r)}var ar={};J(ar,{exportToPem:()=>Jy,importFromPem:()=>Qy,jwkToPkcs1:()=>jy,jwkToPkix:()=>Zy,pkcs1ToJwk:()=>Gy,pkixToJwk:()=>Yy});var Bo=class extends rn{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,Sr(e);let n=it(t);if(this.iHash=e.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?e.create().update(n).digest():n);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=e.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),o.fill(0)}update(e){return tn(this),this.iHash.update(e),this}digestInto(e){tn(this),fc(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:t,iHash:n,finished:s,destroyed:o,blockLen:i,outputLen:a}=this;return e=e,e.finished=s,e.destroyed=o,e.blockLen=i,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},nr=(r,e,t)=>new Bo(r,e).update(t).digest();nr.create=(r,e)=>new Bo(r,e);function Ry(r,e,t,n){Sr(r);let s=$f({dkLen:32,asyncTick:10},n),{c:o,dkLen:i,asyncTick:a}=s;if(Qt(o),Qt(i),Qt(a),o<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=it(e),u=it(t),l=new Uint8Array(i),f=nr.create(r,c),m=f._cloneInto().update(u);return{c:o,dkLen:i,asyncTick:a,DK:l,PRF:f,PRFSalt:m}}function Ny(r,e,t,n,s){return r.destroy(),e.destroy(),n&&n.destroy(),s.fill(0),t}async function Tc(r,e,t,n){let{c:s,dkLen:o,asyncTick:i,DK:a,PRF:c,PRFSalt:u}=Ry(r,e,t,n),l,f=new Uint8Array(4),m=nn(f),g=new Uint8Array(c.outputLen);for(let d=1,h=0;h<o;d++,h+=c.outputLen){let p=a.subarray(h,h+c.outputLen);m.setInt32(0,d,!1),(l=u._cloneInto(l)).update(f).digestInto(g),p.set(g.subarray(0,p.length)),await Kf(s-1,i,()=>{c._cloneInto(l).update(g).digestInto(g);for(let y=0;y<p.length;y++)p[y]^=g[y]})}return Ny(c,u,a,l,g)}var X=As(mh());function Rr(r,e){let t=0;if(r.length===1)return r[0];for(let n=r.length-1;n>=0;n--)t+=r[r.length-1-n]*Math.pow(2,e*n);return t}function sr(r,e,t=-1){let n=t,s=r,o=0,i=Math.pow(2,e);for(let a=1;a<8;a++){if(r<i){let c;if(n<0)c=new ArrayBuffer(a),o=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),o=n}let u=new Uint8Array(c);for(let l=a-1;l>=0;l--){let f=Math.pow(2,l*e);u[o-l-1]=Math.floor(s/f),s-=u[o-l-1]*f}return c}i*=Math.pow(2,e)}return new ArrayBuffer(0)}function Co(...r){let e=0,t=0;for(let o of r)e+=o.length;let n=new ArrayBuffer(e),s=new Uint8Array(n);for(let o of r)s.set(o,t),t+=o.length;return s}function Rc(){let r=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){let a=r[0]===255&&r[1]&128,c=r[0]===0&&(r[1]&128)===0;(a||c)&&this.warnings.push("Needlessly long format")}let e=new ArrayBuffer(this.valueHex.byteLength),t=new Uint8Array(e);for(let a=0;a<this.valueHex.byteLength;a++)t[a]=0;t[0]=r[0]&128;let n=Rr(t,8),s=new ArrayBuffer(this.valueHex.byteLength),o=new Uint8Array(s);for(let a=0;a<this.valueHex.byteLength;a++)o[a]=r[a];return o[0]&=127,Rr(o,8)-n}function gh(r){let e=r<0?r*-1:r,t=128;for(let n=1;n<8;n++){if(e<=t){if(r<0){let i=t-e,a=sr(i,8,n),c=new Uint8Array(a);return c[0]|=128,a}let s=sr(e,8,n),o=new Uint8Array(s);if(o[0]&128){let i=s.slice(0),a=new Uint8Array(i);s=new ArrayBuffer(s.byteLength+1),o=new Uint8Array(s);for(let c=0;c<i.byteLength;c++)o[c+1]=a[c];o[0]=0}return s}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function bh(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let s=0;s<t.length;s++)if(t[s]!==n[s])return!1;return!0}function $e(r,e){let t=r.toString(10);if(e<t.length)return"";let n=e-t.length,s=new Array(n);for(let i=0;i<n;i++)s[i]="0";return s.join("").concat(t)}var p4=Math.log(2);function Io(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Nc(r){let e=0,t=0;for(let s=0;s<r.length;s++){let o=r[s];e+=o.byteLength}let n=new Uint8Array(e);for(let s=0;s<r.length;s++){let o=r[s];n.set(new Uint8Array(o),t),t+=o.byteLength}return n.buffer}function Ht(r,e,t,n){return e instanceof Uint8Array?e.byteLength?t<0?(r.error="Wrong parameter: inputOffset less than zero",!1):n<0?(r.error="Wrong parameter: inputLength less than zero",!1):e.byteLength-t-n<0?(r.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):!0:(r.error="Wrong parameter: inputBuffer has zero length",!1):(r.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}var Qn=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return Nc(this.items)}},Jn=[new Uint8Array([1])],yh="0123456789";var dn="",ft=new ArrayBuffer(0),Lc=new Uint8Array(0),es="EndOfContent",xh="OCTET STRING",Eh="BIT STRING";function Kt(r){var e;return e=class extends r{constructor(...n){var s;super(...n);let o=n[0]||{};this.isHexOnly=(s=o.isHexOnly)!==null&&s!==void 0?s:!1,this.valueHexView=o.valueHex?X.BufferSourceConverter.toUint8Array(o.valueHex):Lc}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}fromBER(n,s,o){let i=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!Ht(this,i,s,o))return-1;let a=s+o;return this.valueHexView=i.subarray(s,a),this.valueHexView.length?(this.blockLength=o,a):(this.warnings.push("Zero buffer length"),s)}toBER(n=!1){return this.isHexOnly?n?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",ft)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:X.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var Mt=class{constructor({blockLength:e=0,error:t=dn,warnings:n=[],valueBeforeDecode:s=Lc}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=X.BufferSourceConverter.toUint8Array(s)}static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:X.Convert.ToHex(this.valueBeforeDecodeView)}}};Mt.NAME="baseBlock";var Pe=class extends Mt{fromBER(e,t,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(e,t){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}};Pe.NAME="valueBlock";var To=class extends Kt(Mt){constructor({idBlock:e={}}={}){var t,n,s,o;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?X.BufferSourceConverter.toUint8Array(e.valueHex):Lc,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(s=e.tagNumber)!==null&&s!==void 0?s:-1,this.isConstructed=(o=e.isConstructed)!==null&&o!==void 0?o:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",ft}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let s=new Uint8Array(1);if(!e){let o=this.tagNumber;o&=31,t|=o,s[0]=t}return s.buffer}if(!this.isHexOnly){let s=sr(this.tagNumber,7),o=new Uint8Array(s),i=s.byteLength,a=new Uint8Array(i+1);if(a[0]=t|31,!e){for(let c=0;c<i-1;c++)a[c+1]=o[c]|128;a[i]=o[i-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let s=this.valueHexView;for(let o=0;o<s.length-1;o++)n[o+1]=s[o]|128;n[this.valueHexView.byteLength]=s[s.length-1]}return n.buffer}fromBER(e,t,n){let s=X.BufferSourceConverter.toUint8Array(e);if(!Ht(this,s,t,n))return-1;let o=s.subarray(t,t+n);if(o.length===0)return this.error="Zero buffer length",-1;switch(o[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(o[0]&32)===32,this.isHexOnly=!1;let a=o[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,u=this.valueHexView=new Uint8Array(255),l=255;for(;o[c]&128;){if(u[c-1]=o[c]&127,c++,c>=o.length)return this.error="End of input reached before message was fully decoded",-1;if(c===l){l+=255;let m=new Uint8Array(l);for(let g=0;g<u.length;g++)m[g]=u[g];u=this.valueHexView=new Uint8Array(l)}}this.blockLength=c+1,u[c-1]=o[c]&127;let f=new Uint8Array(c);for(let m=0;m<c;m++)f[m]=u[m];u=this.valueHexView=new Uint8Array(c),u.set(f),this.blockLength<=9?this.tagNumber=Rr(u,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(this.tagClass===1&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return t+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}};To.NAME="identificationBlock";var _o=class extends Mt{constructor({lenBlock:e={}}={}){var t,n,s;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0?t:!1,this.longFormUsed=(n=e.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(s=e.length)!==null&&s!==void 0?s:0}fromBER(e,t,n){let s=X.BufferSourceConverter.toUint8Array(e);if(!Ht(this,s,t,n))return-1;let o=s.subarray(t,t+n);if(o.length===0)return this.error="Zero buffer length",-1;if(o[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=o[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(o[0]&128),this.longFormUsed===!1)return this.length=o[0],this.blockLength=1,t+this.blockLength;let i=o[0]&127;if(i>8)return this.error="Too big integer",-1;if(i+1>o.length)return this.error="End of input reached before message was fully decoded",-1;let a=t+1,c=s.subarray(a,a+i);return c[i-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=Rr(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=i+1,t+this.blockLength}toBER(e=!1){let t,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=128),t;if(this.longFormUsed){let s=sr(this.length,8);if(s.byteLength>127)return this.error="Too big length",ft;if(t=new ArrayBuffer(s.byteLength+1),e)return t;let o=new Uint8Array(s);n=new Uint8Array(t),n[0]=s.byteLength|128;for(let i=0;i<s.byteLength;i++)n[i+1]=o[i];return t}return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};_o.NAME="lengthBlock";var M={},_e=class extends Mt{constructor({name:e=dn,optional:t=!1,primitiveSchema:n,...s}={},o){super(s),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new To(s),this.lenBlock=new _o(s),this.valueBlock=o?new o(s):new Pe(s)}fromBER(e,t,n){let s=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),s)}toBER(e,t){let n=t||new Qn;t||vh(this);let s=this.idBlock.toBER(e);if(n.write(s),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,n),n.write(new ArrayBuffer(2));else{let o=this.valueBlock.toBER(e);this.lenBlock.length=o.byteLength;let i=this.lenBlock.toBER(e);n.write(i),n.write(o)}return t?ft:n.final()}toJSON(){let e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return e==="ascii"?this.onAsciiEncoding():X.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${X.Convert.ToHex(this.valueBlock.valueBeforeDecodeView)}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;let t=this.toBER(),n=e.toBER();return bh(t,n)}};_e.NAME="BaseBlock";function vh(r){if(r instanceof M.Constructed)for(let e of r.valueBlock.value)vh(e)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var Ro=class extends _e{constructor({value:e=dn,...t}={},n){super(t,n),e&&this.fromString(e)}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}fromBER(e,t,n){let s=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),s)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};Ro.NAME="BaseStringBlock";var No=class extends Kt(Pe){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};No.NAME="PrimitiveValueBlock";var Ah,Lo=class extends _e{constructor(e={}){super(e,No),this.idBlock.isConstructed=!1}};Ah=Lo;M.Primitive=Ah;Lo.NAME="PRIMITIVE";function Ky(r,e){if(r instanceof e)return r;let t=new e;return t.idBlock=r.idBlock,t.lenBlock=r.lenBlock,t.warnings=r.warnings,t.valueBeforeDecodeView=r.valueBeforeDecodeView,t}function di(r,e=0,t=r.length){let n=e,s=new _e({},Pe),o=new Mt;if(!Ht(o,r,e,t))return s.error=o.error,{offset:-1,result:s};if(!r.subarray(e,e+t).length)return s.error="Zero buffer length",{offset:-1,result:s};let a=s.idBlock.fromBER(r,e,t);if(s.idBlock.warnings.length&&s.warnings.concat(s.idBlock.warnings),a===-1)return s.error=s.idBlock.error,{offset:-1,result:s};if(e=a,t-=s.idBlock.blockLength,a=s.lenBlock.fromBER(r,e,t),s.lenBlock.warnings.length&&s.warnings.concat(s.lenBlock.warnings),a===-1)return s.error=s.lenBlock.error,{offset:-1,result:s};if(e=a,t-=s.lenBlock.blockLength,!s.idBlock.isConstructed&&s.lenBlock.isIndefiniteForm)return s.error="Indefinite length form used for primitive encoding form",{offset:-1,result:s};let c=_e;switch(s.idBlock.tagClass){case 1:if(s.idBlock.tagNumber>=37&&s.idBlock.isHexOnly===!1)return s.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:s};switch(s.idBlock.tagNumber){case 0:if(s.idBlock.isConstructed&&s.lenBlock.length>0)return s.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:s};c=M.EndOfContent;break;case 1:c=M.Boolean;break;case 2:c=M.Integer;break;case 3:c=M.BitString;break;case 4:c=M.OctetString;break;case 5:c=M.Null;break;case 6:c=M.ObjectIdentifier;break;case 10:c=M.Enumerated;break;case 12:c=M.Utf8String;break;case 13:c=M.RelativeObjectIdentifier;break;case 14:c=M.TIME;break;case 15:return s.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:s};case 16:c=M.Sequence;break;case 17:c=M.Set;break;case 18:c=M.NumericString;break;case 19:c=M.PrintableString;break;case 20:c=M.TeletexString;break;case 21:c=M.VideotexString;break;case 22:c=M.IA5String;break;case 23:c=M.UTCTime;break;case 24:c=M.GeneralizedTime;break;case 25:c=M.GraphicString;break;case 26:c=M.VisibleString;break;case 27:c=M.GeneralString;break;case 28:c=M.UniversalString;break;case 29:c=M.CharacterString;break;case 30:c=M.BmpString;break;case 31:c=M.DATE;break;case 32:c=M.TimeOfDay;break;case 33:c=M.DateTime;break;case 34:c=M.Duration;break;default:{let u=s.idBlock.isConstructed?new M.Constructed:new M.Primitive;u.idBlock=s.idBlock,u.lenBlock=s.lenBlock,u.warnings=s.warnings,s=u}}break;case 2:case 3:case 4:default:c=s.idBlock.isConstructed?M.Constructed:M.Primitive}return s=Ky(s,c),a=s.fromBER(r,e,s.lenBlock.isIndefiniteForm?t:s.lenBlock.length),s.valueBeforeDecodeView=r.subarray(n,n+s.blockLength),{offset:a,result:s}}function pn(r){if(!r.byteLength){let e=new _e({},Pe);return e.error="Input buffer has zero length",{offset:-1,result:e}}return di(X.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function $y(r,e){return r?1:e}var Et=class extends Pe{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let s=X.BufferSourceConverter.toUint8Array(e);if(!Ht(this,s,t,n))return-1;if(this.valueBeforeDecodeView=s.subarray(t,t+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let o=t;for(;$y(this.isIndefiniteForm,n)>0;){let i=di(s,o,n);if(i.offset===-1)return this.error=i.result.error,this.warnings.concat(i.result.warnings),-1;if(o=i.offset,this.blockLength+=i.result.blockLength,n-=i.result.blockLength,this.value.push(i.result),this.isIndefiniteForm&&i.result.constructor.NAME===es)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===es?this.value.pop():this.warnings.push("No EndOfContent block encoded")),o}toBER(e,t){let n=t||new Qn;for(let s=0;s<this.value.length;s++)this.value[s].toBER(e,n);return t?ft:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};Et.NAME="ConstructedValueBlock";var Dh,or=class extends _e{constructor(e={}){super(e,Et),this.idBlock.isConstructed=!0}fromBER(e,t,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let s=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),s)}onAsciiEncoding(){let e=[];for(let n of this.valueBlock.value)e.push(n.toString("ascii").split(`
16
+ `});var ap=re(()=>{ip();Ii();fr();Uu();Es()});var Mu,Xk,cp=re(()=>{U0();O0();P0();M0();F0();Su();V0();Iu();H0();$0();J0();tp();rp();np();ap();Mu={...xu,...Eu,...vu,...Au,...Du,...Bu,...ku,...Cu,...Tu,..._u},Xk={...Ou,...Pu}});function _n(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}var Ni=re(()=>{});function Li(r=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?_n(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}var Fu=re(()=>{Ni()});function lp(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var up,Vu,M2,Ui,Hu=re(()=>{cp();Fu();up=lp("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Vu=lp("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=Li(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),M2={utf8:up,"utf-8":up,hex:Mu.base16,latin1:Vu,ascii:Vu,binary:Vu,...Mu},Ui=M2});var fp={};J(fp,{toString:()=>F2});function F2(r,e="utf8"){let t=Ui[e];if(!t)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var hp=re(()=>{Hu()});var dp={};J(dp,{fromString:()=>V2});function V2(r,e="utf8"){let t=Ui[e];if(!t)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?_n(globalThis.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}var pp=re(()=>{Hu();Ni()});var mp={};J(mp,{concat:()=>H2});function H2(r,e){e||(e=r.reduce((s,o)=>s+o.length,0));let t=Li(e),n=0;for(let s of r)t.set(s,n),n+=s.length;return _n(t)}var gp=re(()=>{Fu();Ni()});var $u=Ke((l6,vp)=>{"use strict";var bp=p0(),Rn=B0(),{names:As}=k0(),{toString:Oi}=(hp(),Ss(fp)),{fromString:K2}=(pp(),Ss(dp)),{concat:$2}=(gp(),Ss(mp)),Nn={};for(let r in As){let e=r;Nn[As[e]]=e}Object.freeze(Nn);function q2(r){if(!(r instanceof Uint8Array))throw new Error("must be passed a Uint8Array");return Oi(r,"base16")}function W2(r){return K2(r,"base16")}function z2(r){if(!(r instanceof Uint8Array))throw new Error("must be passed a Uint8Array");return Oi(bp.encode("base58btc",r)).slice(1)}function G2(r){let e=r instanceof Uint8Array?Oi(r):r;return bp.decode("z"+e)}function yp(r){if(!(r instanceof Uint8Array))throw new Error("multihash must be a Uint8Array");if(r.length<2)throw new Error("multihash too short. must be > 2 bytes.");let e=Rn.decode(r);if(!xp(e))throw new Error(`multihash unknown function code: 0x${e.toString(16)}`);r=r.slice(Rn.decode.bytes);let t=Rn.decode(r);if(t<0)throw new Error(`multihash invalid length: ${t}`);if(r=r.slice(Rn.decode.bytes),r.length!==t)throw new Error(`multihash length inconsistent: 0x${Oi(r,"base16")}`);return{code:e,name:Nn[e],length:t,digest:r}}function j2(r,e,t){if(!r||e===void 0)throw new Error("multihash encode requires at least two args: digest, code");let n=wp(e);if(!(r instanceof Uint8Array))throw new Error("digest should be a Uint8Array");if(t==null&&(t=r.length),t&&r.length!==t)throw new Error("digest length should be equal to specified length.");let s=Rn.encode(n),o=Rn.encode(t);return $2([s,o,r],s.length+o.length+r.length)}function wp(r){let e=r;if(typeof r=="string"){if(As[r]===void 0)throw new Error(`Unrecognized hash function named: ${r}`);e=As[r]}if(typeof e!="number")throw new Error(`Hash function code should be a number. Got: ${e}`);if(Nn[e]===void 0&&!Ku(e))throw new Error(`Unrecognized function code: ${e}`);return e}function Ku(r){return r>0&&r<16}function xp(r){return!!(Ku(r)||Nn[r])}function Ep(r){yp(r)}function Y2(r){return Ep(r),r.subarray(0,2)}vp.exports={names:As,codes:Nn,toHexString:q2,fromHexString:W2,toB58String:z2,fromB58String:G2,decode:yp,encode:j2,coerceCode:wp,isAppCode:Ku,validate:Ep,prefix:Y2,isValidCode:xp}});var o1={};J(o1,{webRTC:()=>s1,webRTCDirect:()=>n1});var rl=Symbol.for("@libp2p/peer-id");var ks=Symbol.for("@libp2p/transport");var nl;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(nl||(nl={}));var L=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var Cs=(r,...e)=>{try{[...e]}catch{}};var Is=class extends EventTarget{#e=new Map;constructor(){super(),Cs(1/0,this)}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let s=this.#e.get(e);s==null&&(s=[],this.#e.set(e,s)),s.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let s=this.#e.get(e);s!=null&&(s=s.filter(({callback:o})=>o!==t),this.#e.set(e,s))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:s})=>!s),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new qp(e,t))}},Vi=class extends Event{detail;constructor(e,t){super(e,t),this.detail=t?.detail}},qp=globalThis.CustomEvent??Vi;var Wi={};J(Wi,{base58btc:()=>ge,base58flickr:()=>Zp});var d1=new Uint8Array(0);function sl(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function St(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function ol(r){return new TextEncoder().encode(r)}function il(r){return new TextDecoder().decode(r)}function Wp(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var s=0;s<r.length;s++){var o=r.charAt(s),i=o.charCodeAt(0);if(t[i]!==255)throw new TypeError(o+" is ambiguous");t[i]=s}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var h=0,p=0,y=0,x=d.length;y!==x&&d[y]===0;)y++,h++;for(var b=(x-y)*l+1>>>0,v=new Uint8Array(b);y!==x;){for(var E=d[y],A=0,S=b-1;(E!==0||A<p)&&S!==-1;S--,A++)E+=256*v[S]>>>0,v[S]=E%a>>>0,E=E/a>>>0;if(E!==0)throw new Error("Non-zero carry");p=A,y++}for(var D=b-p;D!==b&&v[D]===0;)D++;for(var _=c.repeat(h);D<b;++D)_+=r.charAt(v[D]);return _}function m(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var h=0;if(d[h]!==" "){for(var p=0,y=0;d[h]===c;)p++,h++;for(var x=(d.length-h)*u+1>>>0,b=new Uint8Array(x);d[h];){var v=t[d.charCodeAt(h)];if(v===255)return;for(var E=0,A=x-1;(v!==0||E<y)&&A!==-1;A--,E++)v+=a*b[A]>>>0,b[A]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");y=E,h++}if(d[h]!==" "){for(var S=x-y;S!==x&&b[S]===0;)S++;for(var D=new Uint8Array(p+(x-S)),_=p;S!==x;)D[_++]=b[S++];return D}}}function g(d){var h=m(d);if(h)return h;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:m,decode:g}}var zp=Wp,Gp=zp,cl=Gp;var Hi=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Ki=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return ul(this,e)}},$i=class{decoders;constructor(e){this.decoders=e}or(e){return ul(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function ul(r,e){return new $i({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var qi=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,s){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=s,this.encoder=new Hi(e,t,n),this.decoder=new Ki(e,t,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Vr({name:r,prefix:e,encode:t,decode:n}){return new qi(r,e,t,n)}function Gt({name:r,prefix:e,alphabet:t}){let{encode:n,decode:s}=cl(t,r);return Vr({prefix:e,name:r,encode:n,decode:o=>St(s(o))})}function jp(r,e,t,n){let s={};for(let l=0;l<e.length;++l)s[e[l]]=l;let o=r.length;for(;r[o-1]==="=";)--o;let i=new Uint8Array(o*t/8|0),a=0,c=0,u=0;for(let l=0;l<o;++l){let f=s[r[l]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|f,a+=t,a>=8&&(a-=8,i[u++]=255&c>>a)}if(a>=t||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return i}function Yp(r,e,t){let n=e[e.length-1]==="=",s=(1<<t)-1,o="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>t;)i-=t,o+=e[s&a>>i];if(i!==0&&(o+=e[s&a<<t-i]),n)for(;o.length*t&7;)o+="=";return o}function de({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return Vr({prefix:e,name:r,encode(s){return Yp(s,n,t)},decode(s){return jp(s,n,t,r)}})}var ge=Gt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Zp=Gt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var zi={};J(zi,{base10:()=>Xp});var Xp=Gt({prefix:"9",name:"base10",alphabet:"0123456789"});var Gi={};J(Gi,{base16:()=>Jp,base16upper:()=>Qp});var Jp=de({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Qp=de({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ji={};J(ji,{base2:()=>em});var em=de({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Yi={};J(Yi,{base256emoji:()=>om});var ll=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}"),tm=ll.reduce((r,e,t)=>(r[t]=e,r),[]),rm=ll.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function nm(r){return r.reduce((e,t)=>(e+=tm[t],e),"")}function sm(r){let e=[];for(let t of r){let n=rm[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var om=Vr({prefix:"\u{1F680}",name:"base256emoji",encode:nm,decode:sm});var Zi={};J(Zi,{base32:()=>kt,base32hex:()=>um,base32hexpad:()=>fm,base32hexpadupper:()=>hm,base32hexupper:()=>lm,base32pad:()=>am,base32padupper:()=>cm,base32upper:()=>im,base32z:()=>dm});var kt=de({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),im=de({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),am=de({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),cm=de({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),um=de({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),lm=de({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),fm=de({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),hm=de({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),dm=de({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Xi={};J(Xi,{base36:()=>pm,base36upper:()=>mm});var pm=Gt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),mm=Gt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ea={};J(ea,{base64:()=>Ji,base64pad:()=>gm,base64url:()=>Qi,base64urlpad:()=>bm});var Ji=de({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),gm=de({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Qi=de({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),bm=de({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ta={};J(ta,{base8:()=>ym});var ym=de({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ra={};J(ra,{identity:()=>wm});var wm=Vr({prefix:"\0",name:"identity",encode:r=>il(r),decode:r=>ol(r)});var I1=new TextEncoder,T1=new TextDecoder;var sa={};J(sa,{identity:()=>jt});var vm=dl,fl=128,Am=127,Dm=~Am,Bm=Math.pow(2,31);function dl(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Bm;)e[t++]=r&255|fl,r/=128;for(;r&Dm;)e[t++]=r&255|fl,r>>>=7;return e[t]=r|0,dl.bytes=t-n+1,e}var Sm=na,km=128,hl=127;function na(r,n){var t=0,n=n||0,s=0,o=n,i,a=r.length;do{if(o>=a)throw na.bytes=0,new RangeError("Could not decode varint");i=r[o++],t+=s<28?(i&hl)<<s:(i&hl)*Math.pow(2,s),s+=7}while(i>=km);return na.bytes=o-n,t}var Cm=Math.pow(2,7),Im=Math.pow(2,14),Tm=Math.pow(2,21),_m=Math.pow(2,28),Rm=Math.pow(2,35),Nm=Math.pow(2,42),Lm=Math.pow(2,49),Um=Math.pow(2,56),Om=Math.pow(2,63),Pm=function(r){return r<Cm?1:r<Im?2:r<Tm?3:r<_m?4:r<Rm?5:r<Nm?6:r<Lm?7:r<Um?8:r<Om?9:10},Mm={encode:vm,decode:Sm,encodingLength:Pm},Fm=Mm,Un=Fm;function On(r,e=0){return[Un.decode(r,e),Un.decode.bytes]}function Hr(r,e,t=0){return Un.encode(r,e,t),e}function Kr(r){return Un.encodingLength(r)}function mt(r,e){let t=e.byteLength,n=Kr(r),s=n+Kr(t),o=new Uint8Array(s+t);return Hr(r,o,0),Hr(t,o,n),o.set(e,s),new $r(r,t,e,o)}function pr(r){let e=St(r),[t,n]=On(e),[s,o]=On(e.subarray(n)),i=e.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new $r(t,s,i,e)}function pl(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&sl(r.bytes,t.bytes)}}var $r=class{code;size;digest;bytes;constructor(e,t,n,s){this.code=e,this.size=t,this.digest=n,this.bytes=s}};var ml=0,Vm="identity",gl=St;function Hm(r){return mt(ml,gl(r))}var jt={code:ml,name:Vm,encode:gl,digest:Hm};var aa={};J(aa,{sha256:()=>Te,sha512:()=>Km});function ia({name:r,code:e,encode:t}){return new oa(r,e,t)}var oa=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?mt(this.code,t):t.then(n=>mt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function yl(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Te=ia({name:"sha2-256",code:18,encode:yl("SHA-256")}),Km=ia({name:"sha2-512",code:19,encode:yl("SHA-512")});function wl(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return qm(t,ca(r),e??ge.encoder);default:return Wm(t,ca(r),e??kt.encoder)}}var xl=new WeakMap;function ca(r){let e=xl.get(r);if(e==null){let t=new Map;return xl.set(r,t),t}return e}var et=class r{code;version;multihash;bytes;"/";constructor(e,t,n,s){this.code=t,this.version=e,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:e,multihash:t}=this;if(e!==Pn)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==zm)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=mt(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&pl(e.multihash,n.multihash)}toString(e){return wl(this,e)}toJSON(){return{"/":wl(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:s,multihash:o,bytes:i}=t;return new r(n,s,o,i??El(n,s,o.bytes))}else if(t[Gm]===!0){let{version:n,multihash:s,code:o}=t,i=pr(s);return r.create(n,o,i)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==Pn)throw new Error(`Version 0 CID must use dag-pb (code: ${Pn}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let s=El(e,t,n.bytes);return new r(e,t,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Pn,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,s=St(e.subarray(n,n+t.multihashSize));if(s.byteLength!==t.multihashSize)throw new Error("Incorrect length");let o=s.subarray(t.multihashSize-t.digestSize),i=new $r(t.multihashCode,t.digestSize,o,s);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[f,m]=On(e.subarray(t));return t+=m,f},s=n(),o=Pn;if(s===18?(s=0,t=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=t,a=n(),c=n(),u=t+c,l=u-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,t){let[n,s]=$m(e,t),o=r.decode(s);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ca(o).set(n,e),o}};function $m(r,e){switch(r[0]){case"Q":{let t=e??ge;return[ge.prefix,t.decode(`${ge.prefix}${r}`)]}case ge.prefix:{let t=e??ge;return[ge.prefix,t.decode(r)]}case kt.prefix:{let t=e??kt;return[kt.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function qm(r,e,t){let{prefix:n}=t;if(n!==ge.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let s=e.get(n);if(s==null){let o=t.encode(r).slice(1);return e.set(n,o),o}else return s}function Wm(r,e,t){let{prefix:n}=t,s=e.get(n);if(s==null){let o=t.encode(r);return e.set(n,o),o}else return s}var Pn=112,zm=18;function El(r,e,t){let n=Kr(r),s=n+Kr(e),o=new Uint8Array(s+t.byteLength);return Hr(r,o,0),Hr(e,o,n),o.set(t,s),o}var Gm=Symbol.for("@ipld/js-cid/CID");var gt={...ra,...ji,...ta,...zi,...Gi,...Zi,...Xi,...Wi,...ea,...Yi},X1={...aa,...sa};function Ae(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}var jm=Symbol.for("nodejs.util.inspect.custom"),vl=Object.values(gt).map(r=>r.decoder).reduce((r,e)=>r.or(e),gt.identity.decoder),Al=114,ua=36,la=37,Mn=class{type;multihash;privateKey;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,this.privateKey=e.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[rl]=!0;toString(){return this.string==null&&(this.string=ge.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return et.createV1(Al,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return Ae(this.multihash.bytes,e);if(typeof e=="string")return gr(e).equals(this);if(e?.multihash?.bytes!=null)return Ae(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[jm](){return`PeerId(${this.toString()})`}},qr=class extends Mn{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Wr=class extends Mn{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}},zr=class extends Mn{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}};function gr(r,e){if(e=e??vl,r.charAt(0)==="1"||r.charAt(0)==="Q"){let t=pr(ge.decode(`z${r}`));return r.startsWith("12D")?new Wr({multihash:t}):r.startsWith("16U")?new zr({multihash:t}):new qr({multihash:t})}return Ym(vl.decode(r))}function Ym(r){try{let e=pr(r);if(e.code===jt.code){if(e.digest.length===ua)return new Wr({multihash:e});if(e.digest.length===la)return new zr({multihash:e})}if(e.code===Te.code)return new qr({multihash:e})}catch{return Zm(et.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function Zm(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==Al)throw new Error("Supplied PeerID CID is invalid");let e=r.multihash;if(e.code===Te.code)return new qr({multihash:r.multihash});if(e.code===jt.code){if(e.digest.length===ua)return new Wr({multihash:r.multihash});if(e.digest.length===la)return new zr({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function fa(r,e){return r.length===ua?new Wr({multihash:mt(jt.code,r),privateKey:e}):r.length===la?new zr({multihash:mt(jt.code,r),privateKey:e}):new qr({multihash:await Te.digest(r),publicKey:r,privateKey:e})}function De(r=0){return new Uint8Array(r)}function Be(r=0){return new Uint8Array(r)}function Bl(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Dl=Bl("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ha=Bl("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=Be(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Jm={utf8:Dl,"utf-8":Dl,hex:gt.base16,latin1:ha,ascii:ha,binary:ha,...gt},_s=Jm;function z(r,e="utf8"){let t=_s[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var Qm=Math.pow(2,7),eg=Math.pow(2,14),tg=Math.pow(2,21),da=Math.pow(2,28),pa=Math.pow(2,35),ma=Math.pow(2,42),ga=Math.pow(2,49),ne=128,Oe=127;function we(r){if(r<Qm)return 1;if(r<eg)return 2;if(r<tg)return 3;if(r<da)return 4;if(r<pa)return 5;if(r<ma)return 6;if(r<ga)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ba(r,e,t=0){switch(we(r)){case 8:e[t++]=r&255|ne,r/=128;case 7:e[t++]=r&255|ne,r/=128;case 6:e[t++]=r&255|ne,r/=128;case 5:e[t++]=r&255|ne,r/=128;case 4:e[t++]=r&255|ne,r>>>=7;case 3:e[t++]=r&255|ne,r>>>=7;case 2:e[t++]=r&255|ne,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function rg(r,e,t=0){switch(we(r)){case 8:e.set(t++,r&255|ne),r/=128;case 7:e.set(t++,r&255|ne),r/=128;case 6:e.set(t++,r&255|ne),r/=128;case 5:e.set(t++,r&255|ne),r/=128;case 4:e.set(t++,r&255|ne),r>>>=7;case 3:e.set(t++,r&255|ne),r>>>=7;case 2:e.set(t++,r&255|ne),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function ya(r,e){let t=r[e],n=0;if(n+=t&Oe,t<ne||(t=r[e+1],n+=(t&Oe)<<7,t<ne)||(t=r[e+2],n+=(t&Oe)<<14,t<ne)||(t=r[e+3],n+=(t&Oe)<<21,t<ne)||(t=r[e+4],n+=(t&Oe)*da,t<ne)||(t=r[e+5],n+=(t&Oe)*pa,t<ne)||(t=r[e+6],n+=(t&Oe)*ma,t<ne)||(t=r[e+7],n+=(t&Oe)*ga,t<ne))return n;throw new RangeError("Could not decode varint")}function ng(r,e){let t=r.get(e),n=0;if(n+=t&Oe,t<ne||(t=r.get(e+1),n+=(t&Oe)<<7,t<ne)||(t=r.get(e+2),n+=(t&Oe)<<14,t<ne)||(t=r.get(e+3),n+=(t&Oe)<<21,t<ne)||(t=r.get(e+4),n+=(t&Oe)*da,t<ne)||(t=r.get(e+5),n+=(t&Oe)*pa,t<ne)||(t=r.get(e+6),n+=(t&Oe)*ma,t<ne)||(t=r.get(e+7),n+=(t&Oe)*ga,t<ne))return n;throw new RangeError("Could not decode varint")}function bt(r,e,t=0){return e==null&&(e=Be(we(r))),e instanceof Uint8Array?ba(r,e,t):rg(r,e,t)}function tt(r,e=0){return r instanceof Uint8Array?ya(r,e):ng(r,e)}function xe(r,e){e==null&&(e=r.reduce((s,o)=>s+o.length,0));let t=Be(e),n=0;for(let s of r)t.set(s,n),n+=s.length;return t}var Rs=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,s){return this.readAtomically(()=>{let o=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*s)-1;for(;;){let l=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let m=Number.parseInt(f,e);if(!Number.isNaN(m))return m});if(l===void 0)break;if(o*=e,o+=l,o>u||(i+=1,t!==void 0&&i>t))return}if(i!==0)return!n&&c&&i>1?void 0:o})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let s=n*2;if(n<t.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return t[s]=i[0],t[s+1]=i[1],t[s+2]=i[2],t[s+3]=i[3],[s+4,!0]}let o=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(o===void 0)return[s,!1];t[s]=o>>8,t[s+1]=o&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,s]=e(t);if(n===16)return t;if(s||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let o=new Uint8Array(14),i=16-(n+2),[a]=e(o.subarray(0,i));return t.set(o.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Sl=45,og=15,Gr=new Rs;function wa(r){if(!(r.length>og))return Gr.new(r).parseWith(()=>Gr.readIPv4Addr())}function xa(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Sl))return Gr.new(r).parseWith(()=>Gr.readIPv6Addr())}function Ns(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Sl))return Gr.new(r).parseWith(()=>Gr.readIPAddr())}var kE=parseInt("0xFFFF",16),CE=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Q(r,e="utf8"){let t=_s[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function Ls(r){return!!wa(r)}function Us(r){return!!xa(r)}function Os(r){return!!Ns(r)}var Il=Ls,lg=Us,Ea=function(r){let e=0;if(r=r.toString().trim(),Il(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(lg(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let o=Il(t[n]),i;o&&(i=Ea(t[n]),t[n]=z(i.slice(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,z(i.slice(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let o=[n,1];for(n=9-t.length;n>0;n--)o.push("0");t.splice.apply(t,o)}let s=new Uint8Array(e+16);for(n=0;n<t.length;n++){let o=parseInt(t[n],16);s[e++]=o>>8&255,s[e++]=o&255}return s}throw new Error("invalid ip address")},Tl=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let s=[];for(let o=0;o<t;o++)s.push(r[e+o]);return s.join(".")}if(t===16){let s=[];for(let o=0;o<t;o+=2)s.push(n.getUint16(e+o).toString(16));return s.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var jr={},va={},hg=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[777,-1,"memory"]];hg.forEach(r=>{let e=dg(...r);va[e.code]=e,jr[e.name]=e});function dg(r,e,t,n,s){return{code:r,size:e,name:t,resolvable:!!n,path:!!s}}function se(r){if(typeof r=="number"){if(va[r]!=null)return va[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(jr[r]!=null)return jr[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var d8=se("ip4"),p8=se("ip6"),m8=se("ipcidr");function Da(r,e){switch(se(r).code){case 4:case 41:return mg(e);case 42:return Nl(e);case 6:case 273:case 33:case 132:return Ul(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Nl(e);case 421:return wg(e);case 444:return Ll(e);case 445:return Ll(e);case 466:return yg(e);default:return z(e,"base16")}}function Ba(r,e){switch(se(r).code){case 4:return _l(e);case 41:return _l(e);case 42:return Rl(e);case 6:case 273:case 33:case 132:return Sa(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Rl(e);case 421:return gg(e);case 444:return xg(e);case 445:return Eg(e);case 466:return bg(e);default:return Q(e,"base16")}}var Aa=Object.values(gt).map(r=>r.decoder),pg=function(){let r=Aa[0].or(Aa[1]);return Aa.slice(2).forEach(e=>r=r.or(e)),r}();function _l(r){if(!Os(r))throw new Error("invalid ip address");return Ea(r)}function mg(r){let e=Tl(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!Os(e))throw new Error("invalid ip address");return e}function Sa(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function Ul(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Rl(r){let e=Q(r),t=Uint8Array.from(bt(e.length));return xe([t,e],t.length+e.length)}function Nl(r){let e=tt(r);if(r=r.slice(we(e)),r.length!==e)throw new Error("inconsistent lengths");return z(r)}function gg(r){let e;r[0]==="Q"||r[0]==="1"?e=pr(ge.decode(`z${r}`)).bytes:e=et.parse(r).multihash.bytes;let t=Uint8Array.from(bt(e.length));return xe([t,e],t.length+e.length)}function bg(r){let e=pg.decode(r),t=Uint8Array.from(bt(e.length));return xe([t,e],t.length+e.length)}function yg(r){let e=tt(r),t=r.slice(we(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+z(t,"base64url")}function wg(r){let e=tt(r),t=r.slice(we(e));if(t.length!==e)throw new Error("inconsistent lengths");return z(t,"base58btc")}function xg(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=kt.decode("b"+e[0]),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let s=Sa(n);return xe([t,s],t.length+s.length)}function Eg(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let t=kt.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let s=Sa(n);return xe([t,s],t.length+s.length)}function Ll(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=z(e,"base32"),s=Ul(t);return`${n}:${s}`}function Ol(r){r=ka(r);let e=[],t=[],n=null,s=r.split("/").slice(1);if(s.length===1&&s[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let o=0;o<s.length;o++){let i=s[o],a=se(i);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(o++,o>=s.length)throw Ml("invalid address: "+r);if(a.path===!0){n=ka(s.slice(o).join("/")),e.push([a.code,Ba(a.code,n)]),t.push([a.code,n]);break}let c=Ba(a.code,s[o]);e.push([a.code,c]),t.push([a.code,Da(a.code,c)])}return{string:Pl(t),bytes:Ia(e),tuples:e,stringTuples:t,path:n}}function Ca(r){let e=[],t=[],n=null,s=0;for(;s<r.length;){let o=tt(r,s),i=we(o),a=se(o),c=vg(a,r.slice(s+i));if(c===0){e.push([o]),t.push([o]),s+=i;continue}let u=r.slice(s+i,s+i+c);if(s+=c+i,s>r.length)throw Ml("Invalid address Uint8Array: "+z(r,"base16"));e.push([o,u]);let l=Da(o,u);if(t.push([o,l]),a.path===!0){n=l;break}}return{bytes:Uint8Array.from(r),string:Pl(t),tuples:e,stringTuples:t,path:n}}function Pl(r){let e=[];return r.map(t=>{let n=se(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),ka(e.join("/"))}function Ia(r){return xe(r.map(e=>{let t=se(e[0]),n=Uint8Array.from(bt(t.code));return e.length>1&&e[1]!=null&&(n=xe([n,e[1]])),n}))}function vg(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=tt(e instanceof Uint8Array?e:Uint8Array.from(e));return t+we(t)}}function ka(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function Ml(r){return new Error("Error parsing address: "+r)}var Ag=Symbol.for("nodejs.util.inspect.custom"),Ta=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Dg=[se("dns").code,se("dns4").code,se("dns6").code,se("dnsaddr").code],Ps=class r{bytes;#e;#t;#r;#n;[Ta]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=Ca(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=Ol(e)}else if(Vl(e))t=Ca(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#r=t.stringTuples,this.#n=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,s,o="",i=se("tcp"),a=se("udp"),c=se("ip4"),u=se("ip6"),l=se("dns6"),f=se("ip6zone");for(let[g,d]of this.stringTuples())g===f.code&&(o=`%${d??""}`),Dg.includes(g)&&(t=i.name,s=443,n=`${d??""}${o}`,e=g===l.code?6:4),(g===i.code||g===a.code)&&(t=se(g).name,s=parseInt(d??"")),(g===c.code||g===u.code)&&(t=se(g).name,n=`${d??""}${o}`,e=g===u.code?6:4);if(e==null||t==null||n==null||s==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:s}}protos(){return this.#t.map(([e])=>Object.assign({},se(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>se(e).name)}tuples(){return this.#t}stringTuples(){return this.#r}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),s=n.lastIndexOf(t);if(s<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,s))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(Ia(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,s])=>{n===jr.p2p.code&&e.push([n,s]),n===jr["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?z(ge.decode(`z${n}`),"base58btc"):z(et.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return Ae(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(o=>o.resolvable);if(t==null)return[this];let n=Fl.get(t.name);if(n==null)throw new L(`no available resolver for ${t.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,e)).map(o=>rt(o))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[Ag](){return`Multiaddr(${this.#e})`}};var Fl=new Map;function Vl(r){return!!r?.[Ta]}function rt(r){return new Ps(r)}var Bg=r=>r.toString().split("/").slice(1),Vn=r=>({match:e=>e.length<1?!1:r(e[0])?e.slice(1):!1,pattern:"fn"}),ee=r=>({match:e=>Vn(t=>t===r).match(e),pattern:r}),Vs=()=>({match:r=>Vn(e=>typeof e=="string").match(r),pattern:"{string}"}),Hs=()=>({match:r=>Vn(e=>!isNaN(parseInt(e))).match(r),pattern:"{number}"}),_e=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{ge.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),Ms=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{Qi.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),Fe=r=>({match:e=>{let t=r.match(e);return t===!1?e:t},pattern:`optional(${r.pattern})`}),ze=(...r)=>({match:e=>{let t;for(let n of r){let s=n.match(e);s!==!1&&(t==null||s.length<t.length)&&(t=s)}return t??!1},pattern:`or(${r.map(e=>e.pattern).join(", ")})`}),ie=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e},pattern:`and(${r.map(e=>e.pattern).join(", ")})`});function be(...r){function e(s){let o=Bg(s);for(let i of r){let a=i.match(o);if(a===!1)return!1;o=a}return o}function t(s){return e(s)!==!1}function n(s){let o=e(s);return o===!1?!1:o.length===0}return{matches:t,exactMatch:n}}var Ra=ie(ee("dns4"),Vs()),Na=ie(ee("dns6"),Vs()),La=ie(ee("dnsaddr"),Vs()),Hl=ie(ee("dns"),Vs()),q8=be(Ra),W8=be(Na),z8=be(La),G8=be(ze(Hl,La,Ra,Na)),Kl=ie(ee("ip4"),Vn(Ls)),$l=ie(ee("ip6"),Vn(Us)),ql=ze(Kl,$l),yt=ze(ql,Hl,Ra,Na,La),j8=be(yt),Y8=be(Kl),Z8=be($l),X8=be(ql),Ks=ie(yt,ee("tcp"),Hs()),Hn=ie(yt,ee("udp"),Hs()),Sg=ze(Ks,Hn),J8=be(Ks),Q8=be(Hn),Ua=ie(Hn,ee("quic")),$s=ie(Hn,ee("quic-v1")),kg=ze(Ua,$s),ev=be(Ua),tv=be($s),_a=ze(yt,Ks,Hn,Ua,$s),Wl=ze(ie(_a,ee("ws"),Fe(_e()))),rv=be(Wl),zl=ze(ie(_a,ee("wss"),Fe(_e())),ie(_a,ee("tls"),ee("ws"),Fe(_e()))),nv=be(zl),Gl=ie(Sg,ee("webrtc-direct"),Ms(),Fe(Ms()),Fe(_e())),jl=be(Gl),Yl=ie($s,ee("webtransport"),Ms(),Ms(),Fe(_e())),sv=be(Yl),Fs=ze(Wl,zl,ie(Ks,Fe(_e())),ie(kg,Fe(_e())),ie(yt,Fe(_e())),Gl,Yl,_e()),ov=be(Fs),Cg=ie(Fs,ee("p2p-circuit"),_e()),iv=be(Cg),Ig=ze(ie(Fs,ee("p2p-circuit"),ee("webrtc"),_e()),ie(Fs,ee("webrtc"),Fe(_e())),ee("webrtc")),Zl=be(Ig),Tg=ze(ie(yt,ee("tcp"),Hs(),ee("http"),Fe(_e())),ie(yt,ee("http"),Fe(_e()))),av=be(Tg),_g=ze(ie(yt,ee("tcp"),ze(ie(ee("443"),ee("http")),ie(Hs(),ee("https"))),Fe(_e())),ie(yt,ee("tls"),ee("http"),Fe(_e())),ie(yt,ee("https"),Fe(_e()))),cv=be(_g);var Ge;(function(r){r.ERR_ALREADY_ABORTED="ERR_ALREADY_ABORTED",r.ERR_DATA_CHANNEL="ERR_DATA_CHANNEL",r.ERR_CONNECTION_CLOSED="ERR_CONNECTION_CLOSED",r.ERR_HASH_NOT_SUPPORTED="ERR_HASH_NOT_SUPPORTED",r.ERR_INVALID_MULTIADDR="ERR_INVALID_MULTIADDR",r.ERR_INVALID_FINGERPRINT="ERR_INVALID_FINGERPRINT",r.ERR_INVALID_PARAMETERS="ERR_INVALID_PARAMETERS",r.ERR_NOT_IMPLEMENTED="ERR_NOT_IMPLEMENTED",r.ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS="ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS",r.ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS="ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS"})(Ge||(Ge={}));var Yt=class extends L{constructor(e,t){super(`WebRTC transport error: ${e}`,t??""),this.name="WebRTCTransportError"}};var Oa=class extends Yt{constructor(e,t){super(`[stream: ${e}] data channel error: ${t}`,Ge.ERR_DATA_CHANNEL),this.name="WebRTC/DataChannelError"}};function Ka(r,e){return new Oa(r,e)}var Pa=class extends Yt{constructor(e){super(`There was a problem with the Multiaddr which was passed in: ${e}`,Ge.ERR_INVALID_MULTIADDR),this.name="WebRTC/InappropriateMultiaddrError"}};function qs(r){return new Pa(r)}var Ma=class extends Yt{constructor(e){super(`There was a problem with a provided argument: ${e}`,Ge.ERR_INVALID_PARAMETERS),this.name="WebRTC/InvalidArgumentError"}};function Kn(r){return new Ma(r)}var Fa=class extends Yt{constructor(e,t){super(`Invalid fingerprint "${e}" within ${t}`,Ge.ERR_INVALID_FINGERPRINT),this.name="WebRTC/InvalidFingerprintError"}};function $a(r,e){return new Fa(r,e)}var Va=class extends Yt{constructor(e){super(`A method (${e}) was called though it has been intentionally left unimplemented.`,Ge.ERR_NOT_IMPLEMENTED),this.name="WebRTC/UnimplementedError"}};function Xl(r){return new Va(r)}var Ha=class extends Yt{constructor(e){super(`unsupported hash algorithm: ${e}`,Ge.ERR_HASH_NOT_SUPPORTED),this.name="WebRTC/UnsupportedHashAlgorithmError"}};function Jl(r){return new Ha(r)}var Ql=function(r,e,t){if(t||arguments.length===2)for(var n=0,s=e.length,o;n<s;n++)(o||!(n in e))&&(o||(o=Array.prototype.slice.call(e,0,n)),o[n]=e[n]);return r.concat(o||Array.prototype.slice.call(e))},Rg=function(){function r(e,t,n){this.name=e,this.version=t,this.os=n,this.type="browser"}return r}();var Ng=function(){function r(e){this.version=e,this.type="node",this.name="node",this.os=process.platform}return r}();var Lg=function(){function r(e,t,n,s){this.name=e,this.version=t,this.os=n,this.bot=s,this.type="bot-device"}return r}();var Ug=function(){function r(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null}return r}();var Og=function(){function r(){this.type="react-native",this.name="react-native",this.version=null,this.os=null}return r}();var Pg=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,Mg=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,ef=3,Fg=[["aol",/AOLShield\/([0-9\._]+)/],["edge",/Edge\/([0-9\._]+)/],["edge-ios",/EdgiOS\/([0-9\._]+)/],["yandexbrowser",/YaBrowser\/([0-9\._]+)/],["kakaotalk",/KAKAOTALK\s([0-9\.]+)/],["samsung",/SamsungBrowser\/([0-9\.]+)/],["silk",/\bSilk\/([0-9._-]+)\b/],["miui",/MiuiBrowser\/([0-9\.]+)$/],["beaker",/BeakerBrowser\/([0-9\.]+)/],["edge-chromium",/EdgA?\/([0-9\.]+)/],["chromium-webview",/(?!Chrom.*OPR)wv\).*Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["chrome",/(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["phantomjs",/PhantomJS\/([0-9\.]+)(:?\s|$)/],["crios",/CriOS\/([0-9\.]+)(:?\s|$)/],["firefox",/Firefox\/([0-9\.]+)(?:\s|$)/],["fxios",/FxiOS\/([0-9\.]+)/],["opera-mini",/Opera Mini.*Version\/([0-9\.]+)/],["opera",/Opera\/([0-9\.]+)(?:\s|$)/],["opera",/OPR\/([0-9\.]+)(:?\s|$)/],["pie",/^Microsoft Pocket Internet Explorer\/(\d+\.\d+)$/],["pie",/^Mozilla\/\d\.\d+\s\(compatible;\s(?:MSP?IE|MSInternet Explorer) (\d+\.\d+);.*Windows CE.*\)$/],["netfront",/^Mozilla\/\d\.\d+.*NetFront\/(\d.\d)/],["ie",/Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/],["ie",/MSIE\s([0-9\.]+);.*Trident\/[4-7].0/],["ie",/MSIE\s(7\.0)/],["bb10",/BB10;\sTouch.*Version\/([0-9\.]+)/],["android",/Android\s([0-9\.]+)/],["ios",/Version\/([0-9\._]+).*Mobile.*Safari.*/],["safari",/Version\/([0-9\._]+).*Safari/],["facebook",/FB[AS]V\/([0-9\.]+)/],["instagram",/Instagram\s([0-9\.]+)/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Mobile/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Gecko\)$/],["curl",/^curl\/([0-9\.]+)$/],["searchbot",Pg]],tf=[["iOS",/iP(hone|od|ad)/],["Android OS",/Android/],["BlackBerry OS",/BlackBerry|BB10/],["Windows Mobile",/IEMobile/],["Amazon OS",/Kindle/],["Windows 3.11",/Win16/],["Windows 95",/(Windows 95)|(Win95)|(Windows_95)/],["Windows 98",/(Windows 98)|(Win98)/],["Windows 2000",/(Windows NT 5.0)|(Windows 2000)/],["Windows XP",/(Windows NT 5.1)|(Windows XP)/],["Windows Server 2003",/(Windows NT 5.2)/],["Windows Vista",/(Windows NT 6.0)/],["Windows 7",/(Windows NT 6.1)/],["Windows 8",/(Windows NT 6.2)/],["Windows 8.1",/(Windows NT 6.3)/],["Windows 10",/(Windows NT 10.0)/],["Windows ME",/Windows ME/],["Windows CE",/Windows CE|WinCE|Microsoft Pocket Internet Explorer/],["Open BSD",/OpenBSD/],["Sun OS",/SunOS/],["Chrome OS",/CrOS/],["Linux",/(Linux)|(X11)/],["Mac OS",/(Mac_PowerPC)|(Macintosh)/],["QNX",/QNX/],["BeOS",/BeOS/],["OS/2",/OS\/2/]];function nf(r){return r?rf(r):typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"?new Og:typeof navigator<"u"?rf(navigator.userAgent):Kg()}function Vg(r){return r!==""&&Fg.reduce(function(e,t){var n=t[0],s=t[1];if(e)return e;var o=s.exec(r);return!!o&&[n,o]},!1)}function rf(r){var e=Vg(r);if(!e)return null;var t=e[0],n=e[1];if(t==="searchbot")return new Ug;var s=n[1]&&n[1].split(".").join("_").split("_").slice(0,3);s?s.length<ef&&(s=Ql(Ql([],s,!0),$g(ef-s.length),!0)):s=[];var o=s.join("."),i=Hg(r),a=Mg.exec(r);return a&&a[1]?new Lg(t,o,i,a[1]):new Rg(t,o,i)}function Hg(r){for(var e=0,t=tf.length;e<t;e++){var n=tf[e],s=n[0],o=n[1],i=o.exec(r);if(i)return s}return null}function Kg(){var r=typeof process<"u"&&process.version;return r?new Ng(process.version.slice(1)):null}function $g(r){for(var e=[],t=0;t<r;t++)e.push("0");return e}function pe(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Yr=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},qa=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},sf=r=>globalThis.DOMException===void 0?new qa(r):new DOMException(r),of=r=>{let e=r.reason===void 0?sf("This operation was aborted."):r.reason;return e instanceof Error?e:sf(e)};function br(r,e){let{milliseconds:t,fallback:n,message:s,customTimers:o={setTimeout,clearTimeout}}=e,i,c=new Promise((u,l)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:m}=e;m.aborted&&l(of(m)),m.addEventListener("abort",()=>{l(of(m))})}if(t===Number.POSITIVE_INFINITY){r.then(u,l);return}let f=new Yr;i=o.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(m){l(m)}return}typeof r.cancel=="function"&&r.cancel(),s===!1?u():s instanceof Error?l(s):(f.message=s??`Promise timed out after ${t} milliseconds`,l(f))},t),(async()=>{try{u(await r)}catch(m){l(m)}})()}).finally(()=>{c.clear()});return c.clear=()=>{o.clearTimeout.call(void 0,i),i=void 0},c}var af=nf(),$n=af!=null&&af.name==="firefox",Ws=async function*(){},zs=async r=>{},qg=30*1e3;function cf(r,e,t=qg,n){r.readyState==="open"&&Promise.resolve().then(async()=>{if(r.bufferedAmount>0){n.log("%s drain channel with %d buffered bytes",e,r.bufferedAmount);let s=pe(),o=!1;r.bufferedAmountLowThreshold=0;let i=()=>{o||(n.log("%s drain channel closed before drain",e),s.resolve())};r.addEventListener("close",i,{once:!0}),r.addEventListener("bufferedamountlow",()=>{o=!0,r.removeEventListener("close",i),s.resolve()}),await br(s.promise,{milliseconds:t})}}).then(async()=>{r.readyState==="open"&&r.close()}).catch(s=>{n.log.error("error closing outbound stream",s)})}var yr=class{log;peerConnection;remoteAddr;timeline;metrics;source=Ws();sink=zs;constructor(e,t){this.log=e.logger.forComponent("libp2p:webrtc:maconn"),this.remoteAddr=t.remoteAddr,this.timeline=t.timeline,this.peerConnection=t.peerConnection;let n=this.peerConnection.connectionState;this.peerConnection.onconnectionstatechange=()=>{this.log.trace("peer connection state change",this.peerConnection.connectionState,"initial state",n),(this.peerConnection.connectionState==="disconnected"||this.peerConnection.connectionState==="failed"||this.peerConnection.connectionState==="closed")&&(this.timeline.close=Date.now())}}async close(e){this.log.trace("closing connection"),this.peerConnection.close(),this.timeline.close=Date.now(),this.metrics?.increment({close:!0})}abort(e){this.log.error("closing connection due to error",e),this.peerConnection.close(),this.timeline.close=Date.now(),this.metrics?.increment({abort:!0})}};var Gs=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||e-1&e)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},Zr=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Gs(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let t=this.head;this.head=t.next=new Gs(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Wa=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Zt(r={}){return Wg(t=>{let n=t.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function Wg(r,e){e=e??{};let t=e.onEnd,n=new Zr,s,o,i,a=pe(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((p,y)=>{o=x=>{o=null,n.push(x);try{p(r(n))}catch(b){y(b)}return s}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=pe()})}},u=p=>o!=null?o(p):(n.push(p),s),l=p=>(n=new Zr,o!=null?o({error:p}):(n.push({error:p}),s)),f=p=>{if(i)return s;if(e?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:p})},m=p=>i?s:(i=!0,p!=null?l(p):u({done:!0})),g=()=>(n=new Zr,m(),{done:!0}),d=p=>(m(p),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:g,throw:d,push:f,end:m,get readableLength(){return n.size},onEmpty:async p=>{let y=p?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let x,b;y!=null&&(x=new Promise((v,E)=>{b=()=>{E(new Wa)},y.addEventListener("abort",b)}));try{await Promise.race([a.promise,x])}finally{b!=null&&y!=null&&y?.removeEventListener("abort",b)}}},t==null)return s;let h=s;return s={[Symbol.asyncIterator](){return this},next(){return h.next()},throw(p){return h.throw(p),t!=null&&(t(p),t=void 0),{done:!0}},return(){return h.return(),t!=null&&(t(),t=void 0),{done:!0}},push:f,end(p){return h.end(p),t!=null&&(t(p),t=void 0),s},get readableLength(){return h.readableLength},onEmpty:p=>h.onEmpty(p)},s}var js=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=t??"ABORT_ERR"}};async function Ct(r,e,t){if(e==null)return r;if(e.aborted)return Promise.reject(new js(t?.errorMessage,t?.errorCode));let n,s=new js(t?.errorMessage,t?.errorCode);try{return await Promise.race([r,new Promise((o,i)=>{n=()=>{i(s)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var lf=Symbol.for("@achingbrain/uint8arraylist");function uf(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let s=t+n.byteLength;if(e<s)return{buf:n,index:e-t};t=s}throw new RangeError("index is out of bounds")}function Ys(r){return!!r?.[lf]}var le=class r{bufs;length;[lf]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if(Ys(n))t+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if(Ys(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=uf(this.bufs,e);return t.buf[t.index]}set(e,t){let n=uf(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if(Ys(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:s}=this._subList(e,t);return xe(n,s)}subarray(e,t){let{bufs:n,length:s}=this._subList(e,t);return n.length===1?n[0]:xe(n,s)}sublist(e,t){let{bufs:n,length:s}=this._subList(e,t),o=new r;return o.length=s,o.bufs=[...n],o}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let n=[],s=0;for(let o=0;o<this.bufs.length;o++){let i=this.bufs[o],a=s,c=a+i.byteLength;if(s=c,e>=c)continue;let u=e>=a&&e<c,l=t>a&&t<=c;if(u&&l){if(e===a&&t===c){n.push(i);break}let f=e-a;n.push(i.subarray(f,f+(t-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(l){if(t===c){n.push(i);break}n.push(i.subarray(0,t-a));break}n.push(i)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!Ys(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;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 f=0;f<o;f++)i[f]=-1;for(let f=0;f<s;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let f=t;f<=c;f+=l){l=0;for(let m=u;m>=0;m--){let g=this.get(f+m);if(n[m]!==g){l=Math.max(1,m-a[g]);break}}if(l===0)return f}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=Be(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let s=De(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,t,n),this.write(s,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let s=De(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,t,n),this.write(s,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let s=De(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,t,n),this.write(s,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=Be(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let s=De(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,t,n),this.write(s,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let s=De(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,t,n),this.write(s,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let s=De(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,t,n),this.write(s,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let s=De(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,t,n),this.write(s,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let s=De(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,t,n),this.write(s,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!Ae(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((s,o)=>s+o.byteLength,0)),n.length=t,n}};function ff(r){if(r!=null){if(typeof r[Symbol.iterator]=="function")return r[Symbol.iterator]();if(typeof r[Symbol.asyncIterator]=="function")return r[Symbol.asyncIterator]();if(typeof r.next=="function")return r}throw new Error("argument is not an iterator or iterable")}function hf(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function df(r,e){let t=ff(r).return?.();hf(t)&&t.catch(n=>{e.error("could not cause iterator to return",n)})}var zg="ERR_STREAM_RESET",Gg="ERR_SINK_INVALID_STATE",jg=5e3;function za(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Zs=class{id;direction;timeline;protocol;metadata;source;status;readStatus;writeStatus;log;sinkController;sinkEnd;closed;endErr;streamSource;onEnd;onCloseRead;onCloseWrite;onReset;onAbort;sendCloseWriteTimeout;sendingData;constructor(e){this.sinkController=new AbortController,this.sinkEnd=pe(),this.closed=pe(),this.log=e.log,this.status="open",this.readStatus="ready",this.writeStatus="ready",this.id=e.id,this.metadata=e.metadata??{},this.direction=e.direction,this.timeline={open:Date.now()},this.sendCloseWriteTimeout=e.sendCloseWriteTimeout??jg,this.onEnd=e.onEnd,this.onCloseRead=e?.onCloseRead,this.onCloseWrite=e?.onCloseWrite,this.onReset=e?.onReset,this.onAbort=e?.onAbort,this.source=this.streamSource=Zt({onEnd:t=>{t!=null?this.log.trace("source ended with error",t):this.log.trace("source ended"),this.onSourceEnd(t)}}),this.sink=this.sink.bind(this)}async sink(e){if(this.writeStatus!=="ready")throw new L(`writable end state is "${this.writeStatus}" not "ready"`,Gg);try{this.writeStatus="writing";let t={signal:this.sinkController.signal};if(this.direction==="outbound"){let s=this.sendNewStream(t);za(s)&&await s}let n=()=>{df(e,this.log)};try{this.sinkController.signal.addEventListener("abort",n),this.log.trace("sink reading from source");for await(let s of e){s=s instanceof Uint8Array?new le(s):s;let o=this.sendData(s,t);za(o)&&(this.sendingData=pe(),await o,this.sendingData.resolve(),this.sendingData=void 0)}}finally{this.sinkController.signal.removeEventListener("abort",n)}this.log.trace('sink finished reading from source, write status is "%s"',this.writeStatus),this.writeStatus==="writing"&&(this.writeStatus="closing",this.log.trace("send close write to remote"),await this.sendCloseWrite({signal:AbortSignal.timeout(this.sendCloseWriteTimeout)}),this.writeStatus="closed"),this.onSinkEnd()}catch(t){throw this.log.trace("sink ended with error, calling abort with error",t),this.abort(t),t}finally{this.log.trace("resolve sink end"),this.sinkEnd.resolve()}}onSourceEnd(e){this.timeline.closeRead==null&&(this.timeline.closeRead=Date.now(),this.readStatus="closed",e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseRead?.(),this.timeline.closeWrite!=null?(this.log.trace("source and sink ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("source ended, waiting for sink to end"))}onSinkEnd(e){this.timeline.closeWrite==null&&(this.timeline.closeWrite=Date.now(),this.writeStatus="closed",e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseWrite?.(),this.timeline.closeRead!=null?(this.log.trace("sink and source ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("sink ended, waiting for source to end"))}async close(e){this.log.trace("closing gracefully"),this.status="closing",await Ct(Promise.all([this.closeWrite(e),this.closeRead(e),this.closed.promise]),e?.signal),this.status="closed",this.log.trace("closed gracefully")}async closeRead(e={}){if(this.readStatus==="closing"||this.readStatus==="closed")return;this.log.trace('closing readable end of stream with starting read status "%s"',this.readStatus);let t=this.readStatus;this.readStatus="closing",this.status!=="reset"&&this.status!=="aborted"&&this.timeline.closeRead==null&&(this.log.trace("send close read to remote"),await this.sendCloseRead(e)),t==="ready"&&(this.log.trace("ending internal source queue with %d queued bytes",this.streamSource.readableLength),this.streamSource.end()),this.log.trace("closed readable end of stream")}async closeWrite(e={}){this.writeStatus==="closing"||this.writeStatus==="closed"||(this.log.trace('closing writable end of stream with starting write status "%s"',this.writeStatus),this.writeStatus==="ready"&&(this.log.trace("sink was never sunk, sink an empty array"),await Ct(this.sink([]),e.signal)),this.writeStatus==="writing"&&(this.sendingData!=null&&await Ct(this.sendingData.promise,e.signal),this.log.trace("aborting source passed to .sink"),this.sinkController.abort(),await Ct(this.sinkEnd.promise,e.signal)),this.writeStatus="closed",this.log.trace("closed writable end of stream"))}abort(e){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;this.log("abort with error",e),this.log("try to send reset to remote");let t=this.sendReset();za(t)&&t.catch(n=>{this.log.error("error sending reset message",n)}),this.status="aborted",this.timeline.abort=Date.now(),this._closeSinkAndSource(e),this.onAbort?.(e)}reset(){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;let e=new L("stream reset",zg);this.status="reset",this.timeline.reset=Date.now(),this._closeSinkAndSource(e),this.onReset?.()}_closeSinkAndSource(e){this._closeSink(e),this._closeSource(e)}_closeSink(e){this.writeStatus==="writing"&&(this.log.trace("end sink source"),this.sinkController.abort()),this.onSinkEnd(e)}_closeSource(e){this.readStatus!=="closing"&&this.readStatus!=="closed"&&(this.log.trace("ending source with %d bytes to be read by consumer",this.streamSource.readableLength),this.readStatus="closing",this.streamSource.end(e))}remoteCloseWrite(){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("received remote close write but local source is already closed");return}this.log.trace("remote close write"),this._closeSource()}remoteCloseRead(){if(this.writeStatus==="closing"||this.writeStatus==="closed"){this.log("received remote close read but local sink is already closed");return}this.log.trace("remote close read"),this._closeSink()}destroy(){if(this.status==="closed"||this.status==="aborted"||this.status==="reset"){this.log("received destroy but we are already closed");return}this.log.trace("stream destroyed"),this._closeSinkAndSource()}sourcePush(e){this.streamSource.push(e)}sourceReadableLength(){return this.streamSource.readableLength}};function Xs(r){return r[Symbol.asyncIterator]!=null}var Js=r=>{let e=we(r),t=Be(e);return bt(r,t),Js.bytes=e,t};Js.bytes=0;function qn(r,e){e=e??{};let t=e.lengthEncoder??Js;function*n(s){let o=t(s.byteLength);o instanceof Uint8Array?yield o:yield*o,s instanceof Uint8Array?yield s:yield*s}return Xs(r)?async function*(){for await(let s of r)yield*n(s)}():function*(){for(let s of r)yield*n(s)}()}qn.single=(r,e)=>{e=e??{};let t=e.lengthEncoder??Js;return new le(t(r.byteLength),r)};var Xr=Bs(gf(),1);var Zg=8,Xg=1024*1024*4,wr;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(wr||(wr={}));var Ga=r=>{let e=tt(r);return Ga.bytes=we(e),e};Ga.bytes=0;function xr(r,e){let t=new le,n=wr.LENGTH,s=-1,o=e?.lengthDecoder??Ga,i=e?.maxLengthLength??Zg,a=e?.maxDataLength??Xg;function*c(){for(;t.byteLength>0;){if(n===wr.LENGTH)try{if(s=o(t),s<0)throw(0,Xr.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(s>a)throw(0,Xr.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let u=o.bytes;t.consume(u),e?.onLength!=null&&e.onLength(s),n=wr.DATA}catch(u){if(u instanceof RangeError){if(t.byteLength>i)throw(0,Xr.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw u}if(n===wr.DATA){if(t.byteLength<s)break;let u=t.sublist(0,s);t.consume(s),e?.onData!=null&&e.onData(u),yield u,n=wr.LENGTH}}}return Xs(r)?async function*(){for await(let u of r)t.append(u),yield*c();if(t.byteLength>0)throw(0,Xr.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(let u of r)t.append(u),yield*c();if(t.byteLength>0)throw(0,Xr.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}xr.fromReader=(r,e)=>{let t=1,n=async function*(){for(;;)try{let{done:o,value:i}=await r.next(t);if(o===!0)return;i!=null&&(yield i)}catch(o){if(o.code==="ERR_UNDER_READ")return{done:!0,value:null};throw o}finally{t=1}}();return xr(n,{...e??{},onLength:o=>{t=o}})};var Qg=r=>{let e=r.addEventListener||r.on||r.addListener,t=r.removeEventListener||r.off||r.removeListener;if(!e||!t)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(r),removeListener:t.bind(r)}};function eb(r,e,t){let n,s=new Promise((o,i)=>{if(t={rejectionEvents:["error"],multiArgs:!1,resolveImmediately:!1,...t},!(t.count>=0&&(t.count===Number.POSITIVE_INFINITY||Number.isInteger(t.count))))throw new TypeError("The `count` option should be at least 0 or more");t.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:u,removeListener:l}=Qg(r),f=(...g)=>{let d=t.multiArgs?g:g[0];t.filter&&!t.filter(d)||(c.push(d),t.count===c.length&&(n(),o(c)))},m=g=>{n(),i(g)};n=()=>{for(let g of a)l(g,f);for(let g of t.rejectionEvents)l(g,m)};for(let g of a)u(g,f);for(let g of t.rejectionEvents)u(g,m);t.signal&&t.signal.addEventListener("abort",()=>{m(t.signal.reason)},{once:!0}),t.resolveImmediately&&o(c)});if(s.cancel=n,typeof t.timeout=="number"){let o=br(s,{milliseconds:t.timeout});return o.cancel=n,o}return s}function ja(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=eb(r,e,t),s=n.then(o=>o[0]);return s.cancel=n.cancel,s}var Ya=new Float32Array([-0]),Xt=new Uint8Array(Ya.buffer);function bf(r,e,t){Ya[0]=r,e[t]=Xt[0],e[t+1]=Xt[1],e[t+2]=Xt[2],e[t+3]=Xt[3]}function yf(r,e){return Xt[0]=r[e],Xt[1]=r[e+1],Xt[2]=r[e+2],Xt[3]=r[e+3],Ya[0]}var Za=new Float64Array([-0]),Pe=new Uint8Array(Za.buffer);function wf(r,e,t){Za[0]=r,e[t]=Pe[0],e[t+1]=Pe[1],e[t+2]=Pe[2],e[t+3]=Pe[3],e[t+4]=Pe[4],e[t+5]=Pe[5],e[t+6]=Pe[6],e[t+7]=Pe[7]}function xf(r,e){return Pe[0]=r[e],Pe[1]=r[e+1],Pe[2]=r[e+2],Pe[3]=r[e+3],Pe[4]=r[e+4],Pe[5]=r[e+5],Pe[6]=r[e+6],Pe[7]=r[e+7],Za[0]}var tb=BigInt(Number.MAX_SAFE_INTEGER),rb=BigInt(Number.MIN_SAFE_INTEGER),je=class r{lo;hi;constructor(e,t){this.lo=e|0,this.hi=t|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(t+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(BigInt(t)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Er;if(e<tb&&e>rb)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,s=e-(n<<32n);return t&&(n=~n|0n,s=~s|0n,++s>Ef&&(s=0n,++n>Ef&&(n=0n))),new r(Number(s),Number(n))}static fromNumber(e){if(e===0)return Er;let t=e<0;t&&(e=-e);let n=e>>>0,s=(e-n)/4294967296>>>0;return t&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new r(n,s)}static from(e){return typeof e=="number"?r.fromNumber(e):typeof e=="bigint"?r.fromBigInt(e):typeof e=="string"?r.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new r(e.low>>>0,e.high>>>0):Er}},Er=new je(0,0);Er.toBigInt=function(){return 0n};Er.zzEncode=Er.zzDecode=function(){return this};Er.length=function(){return 1};var Ef=4294967296n;function vf(r){let e=0,t=0;for(let n=0;n<r.length;++n)t=r.charCodeAt(n),t<128?e+=1:t<2048?e+=2:(t&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function Af(r,e,t){if(t-e<1)return"";let s,o=[],i=0,a;for(;e<t;)a=r[e++],a<128?o[i++]=a:a>191&&a<224?o[i++]=(a&31)<<6|r[e++]&63:a>239&&a<365?(a=((a&7)<<18|(r[e++]&63)<<12|(r[e++]&63)<<6|r[e++]&63)-65536,o[i++]=55296+(a>>10),o[i++]=56320+(a&1023)):o[i++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,i>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,o)),i=0);return s!=null?(i>0&&s.push(String.fromCharCode.apply(String,o.slice(0,i))),s.join("")):String.fromCharCode.apply(String,o.slice(0,i))}function Xa(r,e,t){let n=t,s,o;for(let i=0;i<r.length;++i)s=r.charCodeAt(i),s<128?e[t++]=s:s<2048?(e[t++]=s>>6|192,e[t++]=s&63|128):(s&64512)===55296&&((o=r.charCodeAt(i+1))&64512)===56320?(s=65536+((s&1023)<<10)+(o&1023),++i,e[t++]=s>>18|240,e[t++]=s>>12&63|128,e[t++]=s>>6&63|128,e[t++]=s&63|128):(e[t++]=s>>12|224,e[t++]=s>>6&63|128,e[t++]=s&63|128);return t-n}function nt(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function Qs(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Ja=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,nt(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw nt(this,4);return Qs(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw nt(this,4);return Qs(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw nt(this,4);let e=yf(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw nt(this,4);let e=xf(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),t=this.pos,n=this.pos+e;if(n>this.len)throw nt(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return Af(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw nt(this,e);this.pos+=e}else do if(this.pos>=this.len)throw nt(this);while(this.buf[this.pos++]&128);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new je(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw nt(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<t*7)>>>0,e}if(this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw nt(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw nt(this,8);let e=Qs(this.buf,this.pos+=4),t=Qs(this.buf,this.pos+=4);return new je(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=ya(this.buf,this.pos);return this.pos+=we(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Qa(r){return new Ja(r instanceof Uint8Array?r:r.subarray())}function st(r,e,t){let n=Qa(r);return e.decode(n,void 0,t)}function ec(r){let e=r??8192,t=e>>>1,n,s=e;return function(i){if(i<1||i>t)return Be(i);s+i>e&&(n=Be(e),s=0);let a=n.subarray(s,s+=i);return s&7&&(s=(s|7)+1),a}}var vr=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function tc(){}var nc=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},nb=ec();function sb(r){return globalThis.Buffer!=null?Be(r):nb(r)}var zn=class{len;head;tail;states;constructor(){this.len=0,this.head=new vr(tc,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new vr(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new sc((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(eo,10,je.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=je.fromBigInt(e);return this._push(eo,t.length(),t)}uint64Number(e){return this._push(ba,we(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=je.fromBigInt(e).zzEncode();return this._push(eo,t.length(),t)}sint64Number(e){let t=je.fromNumber(e).zzEncode();return this._push(eo,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(rc,1,e?1:0)}fixed32(e){return this._push(Wn,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=je.fromBigInt(e);return this._push(Wn,4,t.lo)._push(Wn,4,t.hi)}fixed64Number(e){let t=je.fromNumber(e);return this._push(Wn,4,t.lo)._push(Wn,4,t.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(bf,4,e)}double(e){return this._push(wf,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(rc,1,0):this.uint32(t)._push(ib,t,e)}string(e){let t=vf(e);return t!==0?this.uint32(t)._push(Xa,t,e):this._push(rc,1,0)}fork(){return this.states=new nc(this),this.head=this.tail=new vr(tc,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 vr(tc,0,0),this.len=0),this}ldelim(){let e=this.head,t=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=t,this.len+=n),this}finish(){let e=this.head.next,t=sb(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function rc(r,e,t){e[t]=r&255}function ob(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var sc=class extends vr{next;constructor(e,t){super(ob,e,t),this.next=void 0}};function eo(r,e,t){for(;r.hi!==0;)e[t++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)e[t++]=r.lo&127|128,r.lo=r.lo>>>7;e[t++]=r.lo}function Wn(r,e,t){e[t]=r&255,e[t+1]=r>>>8&255,e[t+2]=r>>>16&255,e[t+3]=r>>>24}function ib(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(zn.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(ab,e,r),this},zn.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(cb,e,r),this});function ab(r,e,t){e.set(r,t)}function cb(r,e,t){r.length<40?Xa(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(Q(r),t)}function oc(){return new zn}function ot(r,e){let t=oc();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var Jr;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(Jr||(Jr={}));function to(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function Ar(r){function e(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let t=function(o,i){let a=e(o);i.int32(a)},n=function(o){let i=o.int32();return e(i)};return to("enum",Jr.VARINT,t,n)}function it(r,e){return to("message",Jr.LENGTH_DELIMITED,r,e)}var $e;(function(r){let e;(function(s){s.FIN="FIN",s.STOP_SENDING="STOP_SENDING",s.RESET="RESET",s.FIN_ACK="FIN_ACK"})(e=r.Flag||(r.Flag={}));let t;(function(s){s[s.FIN=0]="FIN",s[s.STOP_SENDING=1]="STOP_SENDING",s[s.RESET=2]="RESET",s[s.FIN_ACK=3]="FIN_ACK"})(t||(t={})),function(s){s.codec=()=>Ar(t)}(e=r.Flag||(r.Flag={}));let n;r.codec=()=>(n==null&&(n=it((s,o,i={})=>{i.lengthDelimited!==!1&&o.fork(),s.flag!=null&&(o.uint32(8),r.Flag.codec().encode(s.flag,o)),s.message!=null&&(o.uint32(18),o.bytes(s.message)),i.lengthDelimited!==!1&&o.ldelim()},(s,o)=>{let i={},a=o==null?s.len:s.pos+o;for(;s.pos<a;){let c=s.uint32();switch(c>>>3){case 1:i.flag=r.Flag.codec().decode(s);break;case 2:i.message=s.bytes();break;default:s.skipType(c&7);break}}return i})),n),r.encode=s=>ot(s,r.codec()),r.decode=s=>st(s,r.codec())})($e||($e={}));var ub=16*1024*1024,lb=30*1e3,fb=5,hb=2,db=16*1024,pb=5e3,mb=5e3,ic=class extends Zs{channel;incomingData;maxBufferedAmount;bufferedAmountLowEventTimeout;maxMessageSize;receiveFinAck;finAckTimeout;openTimeout;constructor(e){let t=e.onEnd;switch(e.onEnd=s=>{this.log.trace("readable and writeable ends closed",this.status),Promise.resolve(async()=>{if(!(this.timeline.abort!=null||this.timeline.reset!==null))try{await br(this.receiveFinAck.promise,{milliseconds:this.finAckTimeout})}catch(o){this.log.error("error receiving FIN_ACK",o)}}).then(()=>{this.incomingData.end(),t?.(s)}).catch(o=>{this.log.error("error ending stream",o)})},super(e),this.channel=e.channel,this.channel.binaryType="arraybuffer",this.incomingData=Zt(),this.bufferedAmountLowEventTimeout=e.bufferedAmountLowEventTimeout??lb,this.maxBufferedAmount=e.maxBufferedAmount??ub,this.maxMessageSize=(e.maxMessageSize??db)-fb-hb,this.receiveFinAck=pe(),this.finAckTimeout=e.closeTimeout??pb,this.openTimeout=e.openTimeout??mb,this.channel.readyState){case"open":this.timeline.open=new Date().getTime();break;case"closed":case"closing":(this.timeline.close===void 0||this.timeline.close===0)&&(this.timeline.close=Date.now());break;case"connecting":break;default:throw this.log.error("unknown datachannel state %s",this.channel.readyState),new L("Unknown datachannel state","ERR_INVALID_STATE")}this.channel.onopen=s=>{this.timeline.open=new Date().getTime()},this.channel.onclose=s=>{this.receiveFinAck.resolve(),this.close().catch(o=>{this.log.error("error closing stream after channel closed",o)})},this.channel.onerror=s=>{let o=s.error;this.abort(o)},this.channel.onmessage=async s=>{let{data:o}=s;o===null||o.byteLength===0||this.incomingData.push(new Uint8Array(o,0,o.byteLength))};let n=this;Promise.resolve().then(async()=>{for await(let s of xr(this.incomingData)){let o=n.processIncomingProtobuf(s);o!=null&&n.sourcePush(new le(o))}}).catch(s=>{this.log.error("error processing incoming data channel messages",s)})}sendNewStream(){}async _sendMessage(e,t=!0){if(t&&this.channel.bufferedAmount>this.maxBufferedAmount)try{this.log('channel buffer is %d, wait for "bufferedamountlow" event',this.channel.bufferedAmount),await ja(this.channel,"bufferedamountlow",{timeout:this.bufferedAmountLowEventTimeout})}catch(n){throw n instanceof Yr?new L(`Timed out waiting for DataChannel buffer to clear after ${this.bufferedAmountLowEventTimeout}ms`,"ERR_BUFFER_CLEAR_TIMEOUT"):n}if(this.channel.readyState==="closed"||this.channel.readyState==="closing")throw new L(`Invalid datachannel state - ${this.channel.readyState}`,"ERR_INVALID_STATE");this.channel.readyState!=="open"&&(this.log('channel state is "%s" and not "open", waiting for "open" event before sending data',this.channel.readyState),await ja(this.channel,"open",{timeout:this.openTimeout}),this.log('channel state is now "%s", sending data',this.channel.readyState)),this.channel.send(e.subarray())}async sendData(e){for(e=e.sublist();e.byteLength>0;){let t=Math.min(e.byteLength,this.maxMessageSize),n=e.subarray(0,t),s=$e.encode({message:n}),o=qn.single(s);await this._sendMessage(o),e.consume(t)}}async sendReset(){await this._sendFlag($e.Flag.RESET)}async sendCloseWrite(e){if(await this._sendFlag($e.Flag.FIN)){this.log.trace("awaiting FIN_ACK");try{await Ct(this.receiveFinAck.promise,e?.signal,{errorMessage:"sending close-write was aborted before FIN_ACK was received",errorCode:"ERR_FIN_ACK_NOT_RECEIVED"})}catch(n){this.log.error("failed to await FIN_ACK",n)}}else this.log.trace("sending FIN failed, not awaiting FIN_ACK");this.receiveFinAck.resolve()}async sendCloseRead(){await this._sendFlag($e.Flag.STOP_SENDING)}processIncomingProtobuf(e){let t=$e.decode(e);if(t.flag!==void 0&&(this.log.trace('incoming flag %s, write status "%s", read status "%s"',t.flag,this.writeStatus,this.readStatus),t.flag===$e.Flag.FIN&&(this.remoteCloseWrite(),this.log.trace("sending FIN_ACK"),this._sendFlag($e.Flag.FIN_ACK).catch(n=>{this.log.error("error sending FIN_ACK immediately",n)})),t.flag===$e.Flag.RESET&&this.reset(),t.flag===$e.Flag.STOP_SENDING&&this.remoteCloseRead(),t.flag===$e.Flag.FIN_ACK&&(this.log.trace("received FIN_ACK"),this.receiveFinAck.resolve())),this.readStatus==="ready")return t.message}async _sendFlag(e){if(this.channel.readyState!=="open")return this.log.trace('not sending flag %s because channel is "%s" and not "open"',this.channel.readyState,e.toString()),!1;this.log.trace("sending flag %s",e.toString());let t=$e.encode({flag:e}),n=qn.single(t);try{return await this._sendMessage(n,!1),!0}catch(s){this.log.error("could not send flag %s",e.toString(),s)}return!1}};function Qr(r){let{channel:e,direction:t}=r;return new ic({id:t==="inbound"?`i${e.id}`:`r${e.id}`,log:r.logger.forComponent(`libp2p:webrtc:stream:${t}:${e.id}`),...r})}var Bf="/webrtc",Dr=class{protocol;peerConnection;bufferedStreams=[];metrics;dataChannelOptions;components;log;constructor(e,t){this.components=e,this.peerConnection=t.peerConnection,this.metrics=t.metrics,this.protocol=t.protocol??Bf,this.dataChannelOptions=t.dataChannelOptions??{},this.log=e.logger.forComponent("libp2p:webrtc:datachannelmuxerfactory"),this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace('incoming early datachannel with channel id %d and label "%s"',n.id),n.label==="init"){this.log.trace("closing early init channel"),n.close();return}let s={},o=Qr({channel:n,direction:"inbound",onEnd:i=>{s.onEnd(i)},logger:e.logger,...this.dataChannelOptions});s.stream=o,s.channel=n,s.onEnd=()=>{this.bufferedStreams=this.bufferedStreams.filter(i=>i.stream.id!==o.id)},this.bufferedStreams.push(s)}}createStreamMuxer(e){return new ac(this.components,{...e,peerConnection:this.peerConnection,dataChannelOptions:this.dataChannelOptions,metrics:this.metrics,streams:this.bufferedStreams,protocol:this.protocol})}},ac=class{init;streams;protocol;log;peerConnection;dataChannelOptions;metrics;logger;constructor(e,t){this.init=t,this.log=e.logger.forComponent("libp2p:webrtc:muxer"),this.logger=e.logger,this.streams=t.streams.map(n=>n.stream),this.peerConnection=t.peerConnection,this.protocol=t.protocol??Bf,this.metrics=t.metrics,this.dataChannelOptions=t.dataChannelOptions??{},this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace("incoming datachannel with channel id %d",n.id),n.label==="init"){this.log.trace("closing init channel"),n.close();return}let s=Qr({channel:n,direction:"inbound",onEnd:()=>{this.log("incoming channel %s ended with state %s",n.id,n.readyState),this.#e(s,n)},logger:this.logger,...this.dataChannelOptions});this.streams.push(s),this.metrics?.increment({incoming_stream:!0}),t?.onIncomingStream?.(s)},this.init.streams.length>0&&queueMicrotask(()=>{this.init.streams.forEach(n=>{n.onEnd=()=>{this.log("incoming early channel %s ended with state %s",n.channel.id,n.channel.readyState),this.#e(n.stream,n.channel)},this.metrics?.increment({incoming_stream:!0}),this.init?.onIncomingStream?.(n.stream)})})}#e(e,t){this.log.trace("stream %s %s %s onEnd",e.direction,e.id,e.protocol),cf(t,`${e.direction} ${e.id} ${e.protocol}`,this.dataChannelOptions.drainTimeout,{log:this.log}),this.streams=this.streams.filter(n=>n.id!==e.id),this.metrics?.increment({stream_end:!0}),this.init?.onStreamEnd?.(e)}async close(e){try{await Promise.all(this.streams.map(async t=>t.close(e)))}catch(t){this.abort(t)}}abort(e){for(let t of this.streams)t.abort(e)}source=Ws();sink=zs;newStream(){let e=this.peerConnection.createDataChannel("");this.log.trace("opened outgoing datachannel with channel id %s",e.id);let t=Qr({channel:e,direction:"outbound",onEnd:()=>{this.log("outgoing channel %s ended with state %s",e.id,e.readyState),this.#e(t,e)},logger:this.logger,...this.dataChannelOptions});return this.streams.push(t),this.metrics?.increment({outgoing_stream:!0}),t}};var en=globalThis.RTCPeerConnection,ro=globalThis.RTCSessionDescription,Sf=globalThis.RTCIceCandidate;var cc=class{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=pe(),this.haveNext=pe()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=pe(),e}async throw(e){return this.ended=!0,e!=null&&this.haveNext.reject(e),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return await this._push(void 0),e}async push(e,t){await this._push(e,t)}async end(e,t){e!=null?await this.throw(e):await this._push(void 0,t)}async _push(e,t){if(e!=null&&this.ended)throw new Error("Cannot push value onto an ended pushable");if(this.nextResult!=null&&(await this.readNext.promise,this.nextResult!=null))throw new Error("NeedNext promise resolved but nextResult was not consumed");e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=pe(),await Ct(this.readNext.promise,t?.signal,t)}};function kf(){return new cc}var no=class extends Error{code;constructor(e,t){super(e),this.code=t}},uc=class extends no{type;constructor(e){super(e,"ABORT_ERR"),this.type="aborted"}};function Cf(r,e){let t=kf();r.sink(t).catch(async i=>{await t.end(i)}),r.sink=async i=>{for await(let a of i)await t.push(a);await t.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let s=new le;return{read:async(i,a)=>{a?.signal?.throwIfAborted();let c,u=new Promise((l,f)=>{c=()=>{f(new uc("Read aborted"))},a?.signal?.addEventListener("abort",c)});try{if(i==null){let{done:f,value:m}=await Promise.race([n.next(),u]);return f===!0?new le:m}for(;s.byteLength<i;){let{value:f,done:m}=await Promise.race([n.next(),u]);if(m===!0)throw new no("unexpected end of input","ERR_UNEXPECTED_EOF");s.append(f)}let l=s.sublist(0,i);return s.consume(i),l}finally{c!=null&&a?.signal?.removeEventListener("abort",c)}},write:async(i,a)=>{a?.signal?.throwIfAborted(),i instanceof Uint8Array?await t.push(i,a):await t.push(i.subarray(),a)},unwrap:()=>{if(s.byteLength>0){let i=r.source;r.source=async function*(){e?.yieldBytes===!1?yield s:yield*s,yield*i}()}return r}}}var so=class extends Error{code;constructor(e,t){super(e),this.code=t}};function Gn(r,e={}){let t=Cf(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=we(e.maxDataLength));let n=e?.lengthDecoder??tt,s=e?.lengthEncoder??bt;return{read:async i=>{let a=-1,c=new le;for(;;){c.append(await t.read(1,i));try{a=n(c)}catch(u){if(u instanceof RangeError)continue;throw u}if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new so("message length length too long","ERR_MSG_LENGTH_TOO_LONG");if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new so("message length too long","ERR_MSG_DATA_TOO_LONG");return t.read(a,i)},write:async(i,a)=>{await t.write(new le(s(i.byteLength),i),a)},writeV:async(i,a)=>{let c=new le(...i.flatMap(u=>[s(u.byteLength),u]));await t.write(c,a)},unwrap:()=>t.unwrap()}}function oo(r,e){let t=Gn(r,e),n={read:async(s,o)=>{let i=await t.read(o);return s.decode(i)},write:async(s,o,i)=>{await t.write(o.encode(s),i)},writeV:async(s,o,i)=>{await t.writeV(s.map(a=>o.encode(a)),i)},pb:s=>({read:async o=>n.read(s,o),write:async(o,i)=>n.write(o,s,i),writeV:async(o,i)=>n.writeV(o,s,i),unwrap:()=>n}),unwrap:()=>t.unwrap()};return n}var qe;(function(r){let e;(function(s){s.SDP_OFFER="SDP_OFFER",s.SDP_ANSWER="SDP_ANSWER",s.ICE_CANDIDATE="ICE_CANDIDATE"})(e=r.Type||(r.Type={}));let t;(function(s){s[s.SDP_OFFER=0]="SDP_OFFER",s[s.SDP_ANSWER=1]="SDP_ANSWER",s[s.ICE_CANDIDATE=2]="ICE_CANDIDATE"})(t||(t={})),function(s){s.codec=()=>Ar(t)}(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=it((s,o,i={})=>{i.lengthDelimited!==!1&&o.fork(),s.type!=null&&(o.uint32(8),r.Type.codec().encode(s.type,o)),s.data!=null&&(o.uint32(18),o.string(s.data)),i.lengthDelimited!==!1&&o.ldelim()},(s,o)=>{let i={},a=o==null?s.len:s.pos+o;for(;s.pos<a;){let c=s.uint32();switch(c>>>3){case 1:i.type=r.Type.codec().decode(s);break;case 2:i.data=s.string();break;default:s.skipType(c&7);break}}return i})),n),r.encode=s=>ot(s,r.codec()),r.decode=s=>st(s,r.codec())})(qe||(qe={}));var io=async(r,e,t)=>{try{let n=pe();for(bb(r,n);;){let s=await Promise.race([n.promise,e.read({signal:t.signal})]);if(s==null)break;if(s.type!==qe.Type.ICE_CANDIDATE)throw new L("ICE candidate message expected","ERR_NOT_ICE_CANDIDATE");let o=JSON.parse(s.data??"null");if(o===""||o===null){t.log.trace("end-of-candidates received");continue}let i=new Sf(o);t.log.trace("%s received new ICE candidate",t.direction,i);try{await r.addIceCandidate(i)}catch(a){t.log.error("%s bad candidate received",t.direction,o,a)}}}catch(n){if(t.log.error("%s error parsing ICE candidate",t.direction,n),t.signal?.aborted===!0)throw n}};function gb(r){return $n?r.iceConnectionState:r.connectionState}function bb(r,e){r[$n?"oniceconnectionstatechange":"onconnectionstatechange"]=t=>{switch(gb(r)){case"connected":e.resolve();break;case"failed":case"disconnected":case"closed":e.reject(new L("RTCPeerConnection was closed","ERR_CONNECTION_CLOSED_BEFORE_CONNECTED"));break;default:break}}}async function If({peerConnection:r,signal:e,metrics:t,multiaddr:n,connectionManager:s,transportManager:o,log:i}){let{baseAddr:a}=Tf(n);t?.dialerEvents.increment({open:!0}),i.trace("dialing base address: %a",a);let c=a.getPeerId();if(c==null)throw new L("Relay peer was missing","ERR_INVALID_ADDRESS");let u=s.getConnections(gr(c)),l,f=!1;u.length===0?(l=await o.dial(a,{signal:e}),f=!0):l=u[0];try{let m=await l.newStream(ao,{signal:e,runOnTransientConnection:!0}),g=oo(m).pb(qe);try{let d=r.createDataChannel("init");r.onicecandidate=({candidate:x})=>{let b=JSON.stringify(x?.toJSON()??null);i.trace("initiator sending ICE candidate %s",b),g.write({type:qe.Type.ICE_CANDIDATE,data:b},{signal:e}).catch(v=>{i.error("error sending ICE candidate",v)})},r.onicecandidateerror=x=>{i.error("initiator ICE candidate error",x)};let h=await r.createOffer().catch(x=>{throw i.error("could not execute createOffer",x),new L("Failed to set createOffer","ERR_SDP_HANDSHAKE_FAILED")});i.trace("initiator send SDP offer %s",h.sdp),await g.write({type:qe.Type.SDP_OFFER,data:h.sdp},{signal:e}),await r.setLocalDescription(h).catch(x=>{throw i.error("could not execute setLocalDescription",x),new L("Failed to set localDescription","ERR_SDP_HANDSHAKE_FAILED")});let p=await g.read({signal:e});if(p.type!==qe.Type.SDP_ANSWER)throw new L("Remote should send an SDP answer","ERR_SDP_HANDSHAKE_FAILED");i.trace("initiator receive SDP answer %s",p.data);let y=new ro({type:"answer",sdp:p.data});return await r.setRemoteDescription(y).catch(x=>{throw i.error("could not execute setRemoteDescription",x),new L("Failed to set remoteDescription","ERR_SDP_HANDSHAKE_FAILED")}),i.trace("initiator read candidates until connected"),await io(r,g,{direction:"initiator",signal:e,log:i}),i.trace("initiator connected, closing init channel"),d.close(),i.trace("initiator closing signalling stream"),await g.unwrap().unwrap().close({signal:e}),i.trace("initiator connected to remote address %s",n),{remoteAddress:n}}catch(d){throw r.close(),m.abort(d),d}finally{r.onicecandidate=null,r.onicecandidateerror=null}}finally{if(f)try{await l.close({signal:e})}catch(m){l.abort(m)}}}var yb=U("dns4"),wb=U("dns6"),xb=U("dnsaddr"),Br=ye(U("dns"),xb,yb,wb),lo=ye(U("ip4"),U("ip6")),tn=ye(K(lo,U("tcp")),K(Br,U("tcp"))),fo=K(lo,U("udp")),Eb=K(fo,U("utp")),vb=K(fo,U("quic")),Ab=K(fo,U("quic-v1")),lc=ye(K(tn,U("ws")),K(Br,U("ws"))),co=ye(K(lc,U("p2p")),lc),fc=ye(K(tn,U("wss")),K(Br,U("wss")),K(tn,U("tls"),U("ws")),K(Br,U("tls"),U("ws"))),uo=ye(K(fc,U("p2p")),fc),hc=ye(K(tn,U("http")),K(lo,U("http")),K(Br,U("http"))),dc=ye(K(tn,U("https")),K(lo,U("https")),K(Br,U("https"))),_f=K(fo,U("webrtc-direct"),U("certhash")),Lf=ye(K(_f,U("p2p")),_f),Rf=K(Ab,U("webtransport"),U("certhash"),U("certhash")),Uf=ye(K(Rf,U("p2p")),Rf),Of=ye(K(co,U("p2p-webrtc-star"),U("p2p")),K(uo,U("p2p-webrtc-star"),U("p2p")),K(co,U("p2p-webrtc-star")),K(uo,U("p2p-webrtc-star"))),BA=ye(K(co,U("p2p-websocket-star"),U("p2p")),K(uo,U("p2p-websocket-star"),U("p2p")),K(co,U("p2p-websocket-star")),K(uo,U("p2p-websocket-star"))),Pf=ye(K(hc,U("p2p-webrtc-direct"),U("p2p")),K(dc,U("p2p-webrtc-direct"),U("p2p")),K(hc,U("p2p-webrtc-direct")),K(dc,U("p2p-webrtc-direct"))),Sr=ye(lc,fc,hc,dc,Of,Pf,tn,Eb,vb,Br,Lf,Uf),SA=ye(K(Sr,U("p2p-stardust"),U("p2p")),K(Sr,U("p2p-stardust"))),Jt=ye(K(Sr,U("p2p")),Of,Pf,Lf,Uf,U("p2p")),Nf=ye(K(Jt,U("p2p-circuit"),Jt),K(Jt,U("p2p-circuit")),K(U("p2p-circuit"),Jt),K(Sr,U("p2p-circuit")),K(U("p2p-circuit"),Sr),U("p2p-circuit")),Mf=()=>ye(K(Nf,Mf),Nf),It=Mf(),kA=ye(K(It,Jt,It),K(Jt,It),K(It,Jt),It,Jt);var CA=ye(K(It,U("webrtc"),U("p2p")),K(It,U("webrtc")),K(Sr,U("webrtc"),U("p2p")),K(Sr,U("webrtc")),U("webrtc"));function Ff(r){function e(t){let n;try{n=rt(t)}catch{return!1}let s=r(n.protoNames());return s===null?!1:s===!0||s===!1?s:s.length===0}return e}function K(...r){function e(t){if(t.length<r.length)return null;let n=t;return r.some(s=>(n=typeof s=="function"?s().partialMatch(t):s.partialMatch(t),Array.isArray(n)&&(t=n),n===null)),n}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Ff(e),partialMatch:e}}function ye(...r){function e(n){let s=null;return r.some(o=>{let i=typeof o=="function"?o().partialMatch(n):o.partialMatch(n);return i!=null?(s=i,!0):!1}),s}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Ff(e),partialMatch:e}}function U(r){let e=r;function t(s){let o;try{o=rt(s)}catch{return!1}let i=o.protoNames();return i.length===1&&i[0]===e}function n(s){return s.length===0?null:s[0]===e?s.slice(1):null}return{toString:function(){return e},matches:t,partialMatch:n}}var ho=class extends Is{peerId;transportManager;shutdownController;constructor(e,t){super(),this.peerId=e.peerId,this.transportManager=e.transportManager,this.shutdownController=t.shutdownController}async listen(){this.safeDispatchEvent("listening",{})}getAddrs(){return this.transportManager.getListeners().filter(e=>e!==this).map(e=>e.getAddrs().filter(t=>It.matches(t)).map(t=>t.encapsulate(`/webrtc/p2p/${this.peerId}`))).flat()}async close(){this.shutdownController.abort(),this.safeDispatchEvent("close",{})}};async function Vf({peerConnection:r,stream:e,signal:t,connection:n,log:s}){s.trace("new inbound signaling stream");let o=oo(e).pb(qe);try{r.onicecandidate=({candidate:l})=>{let f=JSON.stringify(l?.toJSON()??null);s.trace("recipient sending ICE candidate %s",f),o.write({type:qe.Type.ICE_CANDIDATE,data:f},{signal:t}).catch(m=>{s.error("error sending ICE candidate",m)})};let a=await o.read({signal:t});if(a.type!==qe.Type.SDP_OFFER)throw new L(`expected message type SDP_OFFER, received: ${a.type??"undefined"} `,"ERR_SDP_HANDSHAKE_FAILED");s.trace("recipient receive SDP offer %s",a.data);let c=new ro({type:"offer",sdp:a.data});await r.setRemoteDescription(c).catch(l=>{throw s.error("could not execute setRemoteDescription",l),new L("Failed to set remoteDescription","ERR_SDP_HANDSHAKE_FAILED")});let u=await r.createAnswer().catch(l=>{throw s.error("could not execute createAnswer",l),new L("Failed to create answer","ERR_SDP_HANDSHAKE_FAILED")});s.trace("recipient send SDP answer %s",u.sdp),await o.write({type:qe.Type.SDP_ANSWER,data:u.sdp},{signal:t}),await r.setLocalDescription(u).catch(l=>{throw s.error("could not execute setLocalDescription",l),new L("Failed to set localDescription","ERR_SDP_HANDSHAKE_FAILED")}),s.trace("recipient read candidates until connected"),await io(r,o,{direction:"recipient",signal:t,log:s})}catch(a){if(r.connectionState!=="connected")throw s.error("error while handling signaling stream from peer %a",n.remoteAddr,a),r.close(),a;s("error while handling signaling stream from peer %a, ignoring as the RTCPeerConnection is already connected",n.remoteAddr,a)}let i=rt(`/webrtc/p2p/${n.remoteAddr.getPeerId()}`);return s.trace("recipient connected to remote address %s",i),{remoteAddress:i}}var Db="/webrtc",Bb="/p2p-circuit",ao="/webrtc-signaling/0.0.1",Sb=30*1e3,po=class{components;init;log;_started=!1;metrics;shutdownController;constructor(e,t={}){this.components=e,this.init=t,this.log=e.logger.forComponent("libp2p:webrtc"),this.shutdownController=new AbortController,Cs(1/0,this.shutdownController.signal),e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_webrtc_dialer_events_total",{label:"event",help:"Total count of WebRTC dialer events by type"}),listenerEvents:e.metrics.registerCounterGroup("libp2p_webrtc_listener_events_total",{label:"event",help:"Total count of WebRTC listener events by type"})})}isStarted(){return this._started}async start(){await this.components.registrar.handle(ao,e=>{this._onProtocol(e).catch(t=>{this.log.error("failed to handle incoming connect from %p",e.connection.remotePeer,t)})},{runOnTransientConnection:!0}),this._started=!0}async stop(){await this.components.registrar.unhandle(ao),this._started=!1}createListener(e){return new ho(this.components,{shutdownController:this.shutdownController})}[Symbol.toStringTag]="@libp2p/webrtc";[ks]=!0;filter(e){return e.filter(Zl.exactMatch)}async dial(e,t){this.log.trace("dialing address: %a",e);let n=new en(this.init.rtcConfiguration),s=new Dr(this.components,{peerConnection:n,dataChannelOptions:this.init.dataChannel}),{remoteAddress:o}=await If({peerConnection:n,multiaddr:e,dataChannelOptions:this.init.dataChannel,signal:t.signal,connectionManager:this.components.connectionManager,transportManager:this.components.transportManager,log:this.log}),i=new yr(this.components,{peerConnection:n,timeline:{open:Date.now()},remoteAddr:o,metrics:this.metrics?.dialerEvents}),a=await t.upgrader.upgradeOutbound(i,{skipProtection:!0,skipEncryption:!0,muxerFactory:s});return this._closeOnShutdown(n,i),a}async _onProtocol({connection:e,stream:t}){let n=AbortSignal.timeout(this.init.inboundConnectionTimeout??Sb),s=new en(this.init.rtcConfiguration),o=new Dr(this.components,{peerConnection:s,dataChannelOptions:this.init.dataChannel});try{let{remoteAddress:i}=await Vf({peerConnection:s,connection:e,stream:t,signal:n,log:this.log}),a=new yr(this.components,{peerConnection:s,timeline:{open:new Date().getTime()},remoteAddr:i,metrics:this.metrics?.listenerEvents});this._closeOnShutdown(s,a),await this.components.upgrader.upgradeInbound(a,{skipEncryption:!0,skipProtection:!0,muxerFactory:o}),await t.close({signal:n})}catch(i){throw t.abort(i),i}}_closeOnShutdown(e,t){let n=()=>{t.close().catch(s=>{this.log.error("could not close WebRTCMultiaddrConnection",s)})};this.shutdownController.signal.addEventListener("abort",n),e.addEventListener("close",()=>{this.shutdownController.signal.removeEventListener("abort",n)})}};function Tf(r){let e=r.toString().split(Db+"/");if(e.length!==2)throw new L("webrtc protocol was not present in multiaddr",Ge.ERR_INVALID_MULTIADDR);if(!e[0].includes(Bb))throw new L("p2p-circuit protocol was not present in multiaddr",Ge.ERR_INVALID_MULTIADDR);let t=rt(e[0]),s=rt("/"+e[1]).getPeerId();if(s==null)throw new L("destination peer id was missing",Ge.ERR_INVALID_MULTIADDR);let o=t.protos().pop();if(o===void 0)throw new L("invalid multiaddr",Ge.ERR_INVALID_MULTIADDR);return o.name!=="p2p"&&(t=t.encapsulate(`/p2p/${s}`)),{baseAddr:t,peerId:gr(s)}}var _c={};J(_c,{Ed25519PrivateKey:()=>_r,Ed25519PublicKey:()=>Qn,generateKeyPair:()=>Ly,generateKeyPairFromSeed:()=>gh,unmarshalEd25519PrivateKey:()=>Ry,unmarshalEd25519PublicKey:()=>Ny});function Ze(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Qt(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function kb(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function rn(r,...e){if(!kb(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${r.length}`)}function kr(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Qt(r.outputLen),Qt(r.blockLen)}function nn(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function Hf(r,e){rn(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var mo=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var on=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),at=(r,e)=>r<<32-e|r>>>e;var a4=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var Cb=async()=>{};async function Kf(r,e,t){let n=Date.now();for(let s=0;s<r;s++){t(s);let o=Date.now()-n;o>=0&&o<e||(await Cb(),n+=o)}}function pc(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function ct(r){return typeof r=="string"&&(r=pc(r)),rn(r),r}function go(...r){let e=0;for(let n=0;n<r.length;n++){let s=r[n];rn(s),e+=s.length}let t=new Uint8Array(e);for(let n=0,s=0;n<r.length;n++){let o=r[n];t.set(o,s),s+=o.length}return t}var sn=class{clone(){return this._cloneInto()}},Ib={}.toString;function $f(r,e){if(e!==void 0&&Ib.call(e)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(r,e)}function bo(r){let e=n=>r().update(ct(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function Cr(r=32){if(mo&&typeof mo.getRandomValues=="function")return mo.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function Tb(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let s=BigInt(32),o=BigInt(4294967295),i=Number(t>>s&o),a=Number(t&o),c=n?4:0,u=n?0:4;r.setUint32(e+c,i,n),r.setUint32(e+u,a,n)}var qf=(r,e,t)=>r&e^~r&t,Wf=(r,e,t)=>r&e^r&t^e&t,an=class extends sn{constructor(e,t,n,s){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=on(this.buffer)}update(e){nn(this);let{view:t,buffer:n,blockLen:s}=this;e=ct(e);let o=e.length;for(let i=0;i<o;){let a=Math.min(s-this.pos,o-i);if(a===s){let c=on(e);for(;s<=o-i;i+=s)this.process(c,i);continue}n.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===s&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){nn(this),Hf(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:s,isLE:o}=this,{pos:i}=this;t[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>s-i&&(this.process(n,0),i=0);for(let f=i;f<s;f++)t[f]=0;Tb(n,s-8,BigInt(this.length*8),o),this.process(n,0);let a=on(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)a.setUint32(4*f,l[f],o)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:s,finished:o,destroyed:i,pos:a}=this;return e.length=s,e.pos=a,e.finished=o,e.destroyed=i,s%t&&e.buffer.set(n),e}};var yo=BigInt(4294967295),mc=BigInt(32);function zf(r,e=!1){return e?{h:Number(r&yo),l:Number(r>>mc&yo)}:{h:Number(r>>mc&yo)|0,l:Number(r&yo)|0}}function _b(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let s=0;s<r.length;s++){let{h:o,l:i}=zf(r[s],e);[t[s],n[s]]=[o,i]}return[t,n]}var Rb=(r,e)=>BigInt(r>>>0)<<mc|BigInt(e>>>0),Nb=(r,e,t)=>r>>>t,Lb=(r,e,t)=>r<<32-t|e>>>t,Ub=(r,e,t)=>r>>>t|e<<32-t,Ob=(r,e,t)=>r<<32-t|e>>>t,Pb=(r,e,t)=>r<<64-t|e>>>t-32,Mb=(r,e,t)=>r>>>t-32|e<<64-t,Fb=(r,e)=>e,Vb=(r,e)=>r,Hb=(r,e,t)=>r<<t|e>>>32-t,Kb=(r,e,t)=>e<<t|r>>>32-t,$b=(r,e,t)=>e<<t-32|r>>>64-t,qb=(r,e,t)=>r<<t-32|e>>>64-t;function Wb(r,e,t,n){let s=(e>>>0)+(n>>>0);return{h:r+t+(s/2**32|0)|0,l:s|0}}var zb=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),Gb=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,jb=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),Yb=(r,e,t,n,s)=>e+t+n+s+(r/2**32|0)|0,Zb=(r,e,t,n,s)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(s>>>0),Xb=(r,e,t,n,s,o)=>e+t+n+s+o+(r/2**32|0)|0;var Jb={fromBig:zf,split:_b,toBig:Rb,shrSH:Nb,shrSL:Lb,rotrSH:Ub,rotrSL:Ob,rotrBH:Pb,rotrBL:Mb,rotr32H:Fb,rotr32L:Vb,rotlSH:Hb,rotlSL:Kb,rotlBH:$b,rotlBL:qb,add:Wb,add3L:zb,add3H:Gb,add4L:jb,add4H:Yb,add5H:Xb,add5L:Zb},Z=Jb;var[Qb,ey]=Z.split(["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(r=>BigInt(r))),er=new Uint32Array(80),tr=new Uint32Array(80),gc=class extends an{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:e,Al:t,Bh:n,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:u,El:l,Fh:f,Fl:m,Gh:g,Gl:d,Hh:h,Hl:p}=this;return[e,t,n,s,o,i,a,c,u,l,f,m,g,d,h,p]}set(e,t,n,s,o,i,a,c,u,l,f,m,g,d,h,p){this.Ah=e|0,this.Al=t|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=l|0,this.Fh=f|0,this.Fl=m|0,this.Gh=g|0,this.Gl=d|0,this.Hh=h|0,this.Hl=p|0}process(e,t){for(let b=0;b<16;b++,t+=4)er[b]=e.getUint32(t),tr[b]=e.getUint32(t+=4);for(let b=16;b<80;b++){let v=er[b-15]|0,E=tr[b-15]|0,A=Z.rotrSH(v,E,1)^Z.rotrSH(v,E,8)^Z.shrSH(v,E,7),S=Z.rotrSL(v,E,1)^Z.rotrSL(v,E,8)^Z.shrSL(v,E,7),D=er[b-2]|0,_=tr[b-2]|0,O=Z.rotrSH(D,_,19)^Z.rotrBH(D,_,61)^Z.shrSH(D,_,6),R=Z.rotrSL(D,_,19)^Z.rotrBL(D,_,61)^Z.shrSL(D,_,6),H=Z.add4L(S,R,tr[b-7],tr[b-16]),V=Z.add4H(H,A,O,er[b-7],er[b-16]);er[b]=V|0,tr[b]=H|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:u,Dl:l,Eh:f,El:m,Fh:g,Fl:d,Gh:h,Gl:p,Hh:y,Hl:x}=this;for(let b=0;b<80;b++){let v=Z.rotrSH(f,m,14)^Z.rotrSH(f,m,18)^Z.rotrBH(f,m,41),E=Z.rotrSL(f,m,14)^Z.rotrSL(f,m,18)^Z.rotrBL(f,m,41),A=f&g^~f&h,S=m&d^~m&p,D=Z.add5L(x,E,S,ey[b],tr[b]),_=Z.add5H(D,y,v,A,Qb[b],er[b]),O=D|0,R=Z.rotrSH(n,s,28)^Z.rotrBH(n,s,34)^Z.rotrBH(n,s,39),H=Z.rotrSL(n,s,28)^Z.rotrBL(n,s,34)^Z.rotrBL(n,s,39),V=n&o^n&a^o&a,G=s&i^s&c^i&c;y=h|0,x=p|0,h=g|0,p=d|0,g=f|0,d=m|0,{h:f,l:m}=Z.add(u|0,l|0,_|0,O|0),u=a|0,l=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let B=Z.add3L(O,H,G);n=Z.add3H(B,_,R,V),s=B|0}({h:n,l:s}=Z.add(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=Z.add(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=Z.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=Z.add(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:m}=Z.add(this.Eh|0,this.El|0,f|0,m|0),{h:g,l:d}=Z.add(this.Fh|0,this.Fl|0,g|0,d|0),{h,l:p}=Z.add(this.Gh|0,this.Gl|0,h|0,p|0),{h:y,l:x}=Z.add(this.Hh|0,this.Hl|0,y|0,x|0),this.set(n,s,o,i,a,c,u,l,f,m,g,d,h,p,y,x)}roundClean(){er.fill(0),tr.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var cn=bo(()=>new gc);var xo={};J(xo,{abytes:()=>un,bitGet:()=>ay,bitLen:()=>iy,bitMask:()=>jn,bitSet:()=>cy,bytesToHex:()=>_t,bytesToNumberBE:()=>Rt,bytesToNumberLE:()=>ut,concatBytes:()=>Lt,createHmacDrbg:()=>wc,ensureBytes:()=>ce,equalBytes:()=>sy,hexToBytes:()=>Ir,hexToNumber:()=>yc,isBytes:()=>rr,numberToBytesBE:()=>nr,numberToBytesLE:()=>Nt,numberToHexUnpadded:()=>Zf,numberToVarBytesBE:()=>ny,utf8ToBytes:()=>oy,validateObject:()=>Xe});var Yf=BigInt(0),wo=BigInt(1),ty=BigInt(2);function rr(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function un(r){if(!rr(r))throw new Error("Uint8Array expected")}var ry=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function _t(r){un(r);let e="";for(let t=0;t<r.length;t++)e+=ry[r[t]];return e}function Zf(r){let e=r.toString(16);return e.length&1?`0${e}`:e}function yc(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var Tt={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function Gf(r){if(r>=Tt._0&&r<=Tt._9)return r-Tt._0;if(r>=Tt._A&&r<=Tt._F)return r-(Tt._A-10);if(r>=Tt._a&&r<=Tt._f)return r-(Tt._a-10)}function Ir(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let e=r.length,t=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let s=0,o=0;s<t;s++,o+=2){let i=Gf(r.charCodeAt(o)),a=Gf(r.charCodeAt(o+1));if(i===void 0||a===void 0){let c=r[o]+r[o+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+o)}n[s]=i*16+a}return n}function Rt(r){return yc(_t(r))}function ut(r){return un(r),yc(_t(Uint8Array.from(r).reverse()))}function nr(r,e){return Ir(r.toString(16).padStart(e*2,"0"))}function Nt(r,e){return nr(r,e).reverse()}function ny(r){return Ir(Zf(r))}function ce(r,e,t){let n;if(typeof e=="string")try{n=Ir(e)}catch(o){throw new Error(`${r} must be valid hex string, got "${e}". Cause: ${o}`)}else if(rr(e))n=Uint8Array.from(e);else throw new Error(`${r} must be hex string or Uint8Array`);let s=n.length;if(typeof t=="number"&&s!==t)throw new Error(`${r} expected ${t} bytes, got ${s}`);return n}function Lt(...r){let e=0;for(let n=0;n<r.length;n++){let s=r[n];un(s),e+=s.length}let t=new Uint8Array(e);for(let n=0,s=0;n<r.length;n++){let o=r[n];t.set(o,s),s+=o.length}return t}function sy(r,e){if(r.length!==e.length)return!1;let t=0;for(let n=0;n<r.length;n++)t|=r[n]^e[n];return t===0}function oy(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function iy(r){let e;for(e=0;r>Yf;r>>=wo,e+=1);return e}function ay(r,e){return r>>BigInt(e)&wo}function cy(r,e,t){return r|(t?wo:Yf)<<BigInt(e)}var jn=r=>(ty<<BigInt(r-1))-wo,bc=r=>new Uint8Array(r),jf=r=>Uint8Array.from(r);function wc(r,e,t){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof t!="function")throw new Error("hmacFn must be a function");let n=bc(r),s=bc(r),o=0,i=()=>{n.fill(1),s.fill(0),o=0},a=(...f)=>t(s,n,...f),c=(f=bc())=>{s=a(jf([0]),f),n=a(),f.length!==0&&(s=a(jf([1]),f),n=a())},u=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,m=[];for(;f<e;){n=a();let g=n.slice();m.push(g),f+=n.length}return Lt(...m)};return(f,m)=>{i(),c(f);let g;for(;!(g=m(u()));)c();return i(),g}}var uy={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||rr(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,e)=>e.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function Xe(r,e,t={}){let n=(s,o,i)=>{let a=uy[o];if(typeof a!="function")throw new Error(`Invalid validator "${o}", expected function`);let c=r[s];if(!(i&&c===void 0)&&!a(c,r))throw new Error(`Invalid param ${String(s)}=${c} (${typeof c}), expected ${o}`)};for(let[s,o]of Object.entries(e))n(s,o,!1);for(let[s,o]of Object.entries(t))n(s,o,!0);return r}var Se=BigInt(0),fe=BigInt(1),Tr=BigInt(2),ly=BigInt(3),xc=BigInt(4),Xf=BigInt(5),Jf=BigInt(8),fy=BigInt(9),hy=BigInt(16);function te(r,e){let t=r%e;return t>=Se?t:e+t}function Ec(r,e,t){if(t<=Se||e<Se)throw new Error("Expected power/modulo > 0");if(t===fe)return Se;let n=fe;for(;e>Se;)e&fe&&(n=n*r%t),r=r*r%t,e>>=fe;return n}function ue(r,e,t){let n=r;for(;e-- >Se;)n*=n,n%=t;return n}function Eo(r,e){if(r===Se||e<=Se)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=te(r,e),n=e,s=Se,o=fe,i=fe,a=Se;for(;t!==Se;){let u=n/t,l=n%t,f=s-i*u,m=o-a*u;n=t,t=l,s=i,o=a,i=f,a=m}if(n!==fe)throw new Error("invert: does not exist");return te(s,e)}function dy(r){let e=(r-fe)/Tr,t,n,s;for(t=r-fe,n=0;t%Tr===Se;t/=Tr,n++);for(s=Tr;s<r&&Ec(s,e,r)!==r-fe;s++);if(n===1){let i=(r+fe)/xc;return function(c,u){let l=c.pow(u,i);if(!c.eql(c.sqr(l),u))throw new Error("Cannot find square root");return l}}let o=(t+fe)/Tr;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let u=n,l=a.pow(a.mul(a.ONE,s),t),f=a.pow(c,o),m=a.pow(c,t);for(;!a.eql(m,a.ONE);){if(a.eql(m,a.ZERO))return a.ZERO;let g=1;for(let h=a.sqr(m);g<u&&!a.eql(h,a.ONE);g++)h=a.sqr(h);let d=a.pow(l,fe<<BigInt(u-g-1));l=a.sqr(d),f=a.mul(f,d),m=a.mul(m,l),u=g}return f}}function py(r){if(r%xc===ly){let e=(r+fe)/xc;return function(n,s){let o=n.pow(s,e);if(!n.eql(n.sqr(o),s))throw new Error("Cannot find square root");return o}}if(r%Jf===Xf){let e=(r-Xf)/Jf;return function(n,s){let o=n.mul(s,Tr),i=n.pow(o,e),a=n.mul(s,i),c=n.mul(n.mul(a,Tr),i),u=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(u),s))throw new Error("Cannot find square root");return u}}return r%hy,dy(r)}var Qf=(r,e)=>(te(r,e)&fe)===fe,my=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function vc(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=my.reduce((n,s)=>(n[s]="function",n),e);return Xe(r,t)}function gy(r,e,t){if(t<Se)throw new Error("Expected power > 0");if(t===Se)return r.ONE;if(t===fe)return e;let n=r.ONE,s=e;for(;t>Se;)t&fe&&(n=r.mul(n,s)),s=r.sqr(s),t>>=fe;return n}function by(r,e){let t=new Array(e.length),n=e.reduce((o,i,a)=>r.is0(i)?o:(t[a]=o,r.mul(o,i)),r.ONE),s=r.inv(n);return e.reduceRight((o,i,a)=>r.is0(i)?o:(t[a]=r.mul(o,t[a]),r.mul(o,i)),s),t}function Ac(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function vo(r,e,t=!1,n={}){if(r<=Se)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:s,nByteLength:o}=Ac(r,e);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let i=py(r),a=Object.freeze({ORDER:r,BITS:s,BYTES:o,MASK:jn(s),ZERO:Se,ONE:fe,create:c=>te(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return Se<=c&&c<r},is0:c=>c===Se,isOdd:c=>(c&fe)===fe,neg:c=>te(-c,r),eql:(c,u)=>c===u,sqr:c=>te(c*c,r),add:(c,u)=>te(c+u,r),sub:(c,u)=>te(c-u,r),mul:(c,u)=>te(c*u,r),pow:(c,u)=>gy(a,c,u),div:(c,u)=>te(c*Eo(u,r),r),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>Eo(c,r),sqrt:n.sqrt||(c=>i(a,c)),invertBatch:c=>by(a,c),cmov:(c,u,l)=>l?u:c,toBytes:c=>t?Nt(c,o):nr(c,o),fromBytes:c=>{if(c.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);return t?ut(c):Rt(c)}});return Object.freeze(a)}function eh(r,e){if(!r.isOdd)throw new Error("Field doesn't have isOdd");let t=r.sqrt(e);return r.isOdd(t)?r.neg(t):t}function th(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let e=r.toString(2).length;return Math.ceil(e/8)}function Dc(r){let e=th(r);return e+Math.ceil(e/2)}function rh(r,e,t=!1){let n=r.length,s=th(e),o=Dc(e);if(n<16||n<o||n>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${n}`);let i=t?Rt(r):ut(r),a=te(i,e-fe)+fe;return t?Nt(a,s):nr(a,s)}var wy=BigInt(0),Bc=BigInt(1);function Ao(r,e){let t=(s,o)=>{let i=o.negate();return s?i:o},n=s=>{let o=Math.ceil(e/s)+1,i=2**(s-1);return{windows:o,windowSize:i}};return{constTimeNegate:t,unsafeLadder(s,o){let i=r.ZERO,a=s;for(;o>wy;)o&Bc&&(i=i.add(a)),a=a.double(),o>>=Bc;return i},precomputeWindow(s,o){let{windows:i,windowSize:a}=n(o),c=[],u=s,l=u;for(let f=0;f<i;f++){l=u,c.push(l);for(let m=1;m<a;m++)l=l.add(u),c.push(l);u=l.double()}return c},wNAF(s,o,i){let{windows:a,windowSize:c}=n(s),u=r.ZERO,l=r.BASE,f=BigInt(2**s-1),m=2**s,g=BigInt(s);for(let d=0;d<a;d++){let h=d*c,p=Number(i&f);i>>=g,p>c&&(p-=m,i+=Bc);let y=h,x=h+Math.abs(p)-1,b=d%2!==0,v=p<0;p===0?l=l.add(t(b,o[y])):u=u.add(t(v,o[x]))}return{p:u,f:l}},wNAFCached(s,o,i,a){let c=s._WINDOW_SIZE||1,u=o.get(s);return u||(u=this.precomputeWindow(s,c),c!==1&&o.set(s,a(u))),this.wNAF(c,u,i)}}}function Yn(r){return vc(r.Fp),Xe(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Ac(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var lt=BigInt(0),Ye=BigInt(1),Do=BigInt(2),xy=BigInt(8),Ey={zip215:!0};function vy(r){let e=Yn(r);return Xe(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function Bo(r){let e=vy(r),{Fp:t,n,prehash:s,hash:o,randomBytes:i,nByteLength:a,h:c}=e,u=Do<<BigInt(a*8)-Ye,l=t.create,f=e.uvRatio||((k,w)=>{try{return{isValid:!0,value:t.sqrt(k*t.inv(w))}}catch{return{isValid:!1,value:lt}}}),m=e.adjustScalarBytes||(k=>k),g=e.domain||((k,w,C)=>{if(w.length||C)throw new Error("Contexts/pre-hash are not supported");return k}),d=k=>typeof k=="bigint"&&lt<k,h=(k,w)=>d(k)&&d(w)&&k<w,p=k=>k===lt||h(k,u);function y(k,w){if(h(k,w))return k;throw new Error(`Expected valid scalar < ${w}, got ${typeof k} ${k}`)}function x(k){return k===lt?k:y(k,n)}let b=new Map;function v(k){if(!(k instanceof E))throw new Error("ExtendedPoint expected")}class E{constructor(w,C,T,N){if(this.ex=w,this.ey=C,this.ez=T,this.et=N,!p(w))throw new Error("x required");if(!p(C))throw new Error("y required");if(!p(T))throw new Error("z required");if(!p(N))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(w){if(w instanceof E)throw new Error("extended point not allowed");let{x:C,y:T}=w||{};if(!p(C)||!p(T))throw new Error("invalid affine point");return new E(C,T,Ye,l(C*T))}static normalizeZ(w){let C=t.invertBatch(w.map(T=>T.ez));return w.map((T,N)=>T.toAffine(C[N])).map(E.fromAffine)}_setWindowSize(w){this._WINDOW_SIZE=w,b.delete(this)}assertValidity(){let{a:w,d:C}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:T,ey:N,ez:$,et:q}=this,Y=l(T*T),W=l(N*N),j=l($*$),ae=l(j*j),oe=l(Y*w),Ce=l(j*l(oe+W)),Ie=l(ae+l(C*l(Y*W)));if(Ce!==Ie)throw new Error("bad point: equation left != right (1)");let ve=l(T*N),Ue=l($*q);if(ve!==Ue)throw new Error("bad point: equation left != right (2)")}equals(w){v(w);let{ex:C,ey:T,ez:N}=this,{ex:$,ey:q,ez:Y}=w,W=l(C*Y),j=l($*N),ae=l(T*Y),oe=l(q*N);return W===j&&ae===oe}is0(){return this.equals(E.ZERO)}negate(){return new E(l(-this.ex),this.ey,this.ez,l(-this.et))}double(){let{a:w}=e,{ex:C,ey:T,ez:N}=this,$=l(C*C),q=l(T*T),Y=l(Do*l(N*N)),W=l(w*$),j=C+T,ae=l(l(j*j)-$-q),oe=W+q,Ce=oe-Y,Ie=W-q,ve=l(ae*Ce),Ue=l(oe*Ie),Bt=l(ae*Ie),dr=l(Ce*oe);return new E(ve,Ue,dr,Bt)}add(w){v(w);let{a:C,d:T}=e,{ex:N,ey:$,ez:q,et:Y}=this,{ex:W,ey:j,ez:ae,et:oe}=w;if(C===BigInt(-1)){let ju=l(($-N)*(j+W)),Yu=l(($+N)*(j-W)),Fi=l(Yu-ju);if(Fi===lt)return this.double();let Zu=l(q*Do*oe),Xu=l(Y*Do*ae),Ju=Xu+Zu,Qu=Yu+ju,el=Xu-Zu,Up=l(Ju*Fi),Op=l(Qu*el),Pp=l(Ju*el),Mp=l(Fi*Qu);return new E(Up,Op,Mp,Pp)}let Ce=l(N*W),Ie=l($*j),ve=l(Y*T*oe),Ue=l(q*ae),Bt=l((N+$)*(W+j)-Ce-Ie),dr=Ue-ve,Ln=Ue+ve,Gu=l(Ie-C*Ce),_p=l(Bt*dr),Rp=l(Ln*Gu),Np=l(Bt*Gu),Lp=l(dr*Ln);return new E(_p,Rp,Lp,Np)}subtract(w){return this.add(w.negate())}wNAF(w){return D.wNAFCached(this,b,w,E.normalizeZ)}multiply(w){let{p:C,f:T}=this.wNAF(y(w,n));return E.normalizeZ([C,T])[0]}multiplyUnsafe(w){let C=x(w);return C===lt?S:this.equals(S)||C===Ye?this:this.equals(A)?this.wNAF(C).p:D.unsafeLadder(this,C)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return D.unsafeLadder(this,n).is0()}toAffine(w){let{ex:C,ey:T,ez:N}=this,$=this.is0();w==null&&(w=$?xy:t.inv(N));let q=l(C*w),Y=l(T*w),W=l(N*w);if($)return{x:lt,y:Ye};if(W!==Ye)throw new Error("invZ was invalid");return{x:q,y:Y}}clearCofactor(){let{h:w}=e;return w===Ye?this:this.multiplyUnsafe(w)}static fromHex(w,C=!1){let{d:T,a:N}=e,$=t.BYTES;w=ce("pointHex",w,$);let q=w.slice(),Y=w[$-1];q[$-1]=Y&-129;let W=ut(q);W===lt||(C?y(W,u):y(W,t.ORDER));let j=l(W*W),ae=l(j-Ye),oe=l(T*j-N),{isValid:Ce,value:Ie}=f(ae,oe);if(!Ce)throw new Error("Point.fromHex: invalid y coordinate");let ve=(Ie&Ye)===Ye,Ue=(Y&128)!==0;if(!C&&Ie===lt&&Ue)throw new Error("Point.fromHex: x=0 and x_0=1");return Ue!==ve&&(Ie=l(-Ie)),E.fromAffine({x:Ie,y:W})}static fromPrivateKey(w){return R(w).point}toRawBytes(){let{x:w,y:C}=this.toAffine(),T=Nt(C,t.BYTES);return T[T.length-1]|=w&Ye?128:0,T}toHex(){return _t(this.toRawBytes())}}E.BASE=new E(e.Gx,e.Gy,Ye,l(e.Gx*e.Gy)),E.ZERO=new E(lt,Ye,Ye,lt);let{BASE:A,ZERO:S}=E,D=Ao(E,a*8);function _(k){return te(k,n)}function O(k){return _(ut(k))}function R(k){let w=a;k=ce("private key",k,w);let C=ce("hashed private key",o(k),2*w),T=m(C.slice(0,w)),N=C.slice(w,2*w),$=O(T),q=A.multiply($),Y=q.toRawBytes();return{head:T,prefix:N,scalar:$,point:q,pointBytes:Y}}function H(k){return R(k).pointBytes}function V(k=new Uint8Array,...w){let C=Lt(...w);return O(o(g(C,ce("context",k),!!s)))}function G(k,w,C={}){k=ce("message",k),s&&(k=s(k));let{prefix:T,scalar:N,pointBytes:$}=R(w),q=V(C.context,T,k),Y=A.multiply(q).toRawBytes(),W=V(C.context,Y,$,k),j=_(q+W*N);x(j);let ae=Lt(Y,Nt(j,t.BYTES));return ce("result",ae,a*2)}let B=Ey;function I(k,w,C,T=B){let{context:N,zip215:$}=T,q=t.BYTES;k=ce("signature",k,2*q),w=ce("message",w),s&&(w=s(w));let Y=ut(k.slice(q,2*q)),W,j,ae;try{W=E.fromHex(C,$),j=E.fromHex(k.slice(0,q),$),ae=A.multiplyUnsafe(Y)}catch{return!1}if(!$&&W.isSmallOrder())return!1;let oe=V(N,j.toRawBytes(),W.toRawBytes(),w);return j.add(W.multiplyUnsafe(oe)).subtract(ae).clearCofactor().equals(E.ZERO)}return A._setWindowSize(8),{CURVE:e,getPublicKey:H,sign:G,verify:I,ExtendedPoint:E,utils:{getExtendedPublicKey:R,randomPrivateKey:()=>i(t.BYTES),precompute(k=8,w=E.BASE){return w._setWindowSize(k),w.multiply(BigInt(3)),w}}}}var Zn=BigInt(0),Sc=BigInt(1);function Ay(r){return Xe(r,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...r})}function nh(r){let e=Ay(r),{P:t}=e,n=b=>te(b,t),s=e.montgomeryBits,o=Math.ceil(s/8),i=e.nByteLength,a=e.adjustScalarBytes||(b=>b),c=e.powPminus2||(b=>Ec(b,t-BigInt(2),t));function u(b,v,E){let A=n(b*(v-E));return v=n(v-A),E=n(E+A),[v,E]}function l(b){if(typeof b=="bigint"&&Zn<=b&&b<t)return b;throw new Error("Expected valid scalar 0 < scalar < CURVE.P")}let f=(e.a-BigInt(2))/BigInt(4);function m(b,v){let E=l(b),A=l(v),S=E,D=Sc,_=Zn,O=E,R=Sc,H=Zn,V;for(let B=BigInt(s-1);B>=Zn;B--){let I=A>>B&Sc;H^=I,V=u(H,D,O),D=V[0],O=V[1],V=u(H,_,R),_=V[0],R=V[1],H=I;let P=D+_,k=n(P*P),w=D-_,C=n(w*w),T=k-C,N=O+R,$=O-R,q=n($*P),Y=n(N*w),W=q+Y,j=q-Y;O=n(W*W),R=n(S*n(j*j)),D=n(k*C),_=n(T*(k+n(f*T)))}V=u(H,D,O),D=V[0],O=V[1],V=u(H,_,R),_=V[0],R=V[1];let G=c(_);return n(D*G)}function g(b){return Nt(n(b),o)}function d(b){let v=ce("u coordinate",b,o);return i===32&&(v[31]&=127),ut(v)}function h(b){let v=ce("scalar",b),E=v.length;if(E!==o&&E!==i)throw new Error(`Expected ${o} or ${i} bytes, got ${E}`);return ut(a(v))}function p(b,v){let E=d(v),A=h(b),S=m(E,A);if(S===Zn)throw new Error("Invalid private or public key received");return g(S)}let y=g(e.Gu);function x(b){return p(b,y)}return{scalarMult:p,scalarMultBase:x,getSharedSecret:(b,v)=>p(b,v),getPublicKey:b=>x(b),utils:{randomPrivateKey:()=>e.randomBytes(e.nByteLength)},GuBytes:y}}var Xn=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),sh=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),N4=BigInt(0),Dy=BigInt(1),kc=BigInt(2),By=BigInt(5),oh=BigInt(10),Sy=BigInt(20),ky=BigInt(40),ih=BigInt(80);function ah(r){let e=Xn,n=r*r%e*r%e,s=ue(n,kc,e)*n%e,o=ue(s,Dy,e)*r%e,i=ue(o,By,e)*o%e,a=ue(i,oh,e)*i%e,c=ue(a,Sy,e)*a%e,u=ue(c,ky,e)*c%e,l=ue(u,ih,e)*u%e,f=ue(l,ih,e)*u%e,m=ue(f,oh,e)*i%e;return{pow_p_5_8:ue(m,kc,e)*r%e,b2:n}}function ch(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Cy(r,e){let t=Xn,n=te(e*e*e,t),s=te(n*n*e,t),o=ah(r*s).pow_p_5_8,i=te(r*n*o,t),a=te(e*i*i,t),c=i,u=te(i*sh,t),l=a===r,f=a===te(-r,t),m=a===te(-r*sh,t);return l&&(i=c),(f||m)&&(i=u),Qf(i,t)&&(i=te(-i,t)),{isValid:l||f,value:i}}var Ut=vo(Xn,void 0,!0),Cc={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Ut,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:cn,randomBytes:Cr,adjustScalarBytes:ch,uvRatio:Cy},ln=Bo(Cc);function uh(r,e,t){if(e.length>255)throw new Error("Context is too big");return go(pc("SigEd25519 no Ed25519 collisions"),new Uint8Array([t?1:0,e.length]),e,r)}var L4=Bo({...Cc,domain:uh}),U4=Bo({...Cc,domain:uh,prehash:cn}),Jn=nh({P:Xn,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:r=>{let e=Xn,{pow_p_5_8:t,b2:n}=ah(r);return te(ue(t,BigInt(3),e)*n,e)},adjustScalarBytes:ch,randomBytes:Cr});var Iy=(Ut.ORDER+BigInt(3))/BigInt(8),O4=Ut.pow(kc,Iy),P4=Ut.sqrt(Ut.neg(Ut.ONE)),M4=(Ut.ORDER-BigInt(5))/BigInt(8),F4=BigInt(486662);var V4=eh(Ut,Ut.neg(BigInt(486664)));var H4=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),K4=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),$4=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),q4=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var W4=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var fn=32,Ot=64,So=32;function lh(){let r=ln.utils.randomPrivateKey(),e=ln.getPublicKey(r);return{privateKey:ph(r,e),publicKey:e}}function fh(r){if(r.length!==So)throw new TypeError('"seed" must be 32 bytes in length.');if(!(r instanceof Uint8Array))throw new TypeError('"seed" must be a node.js Buffer, or Uint8Array.');let e=r,t=ln.getPublicKey(e);return{privateKey:ph(e,t),publicKey:t}}function hh(r,e){let t=r.subarray(0,So);return ln.sign(e instanceof Uint8Array?e:e.subarray(),t)}function dh(r,e,t){return ln.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}function ph(r,e){let t=new Uint8Array(Ot);for(let n=0;n<So;n++)t[n]=r[n],t[So+n]=e[n];return t}var Ve={get(r=globalThis){let e=r.crypto;if(e==null||e.subtle==null)throw Object.assign(new Error("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"),{code:"ERR_MISSING_WEB_CRYPTO"});return e}};var Ic={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function mh(r){let e=r?.algorithm??"AES-GCM",t=r?.keyLength??16,n=r?.nonceLength??12,s=r?.digest??"SHA-256",o=r?.saltLength??16,i=r?.iterations??32767,a=Ve.get();t*=8;async function c(f,m){let g=a.getRandomValues(new Uint8Array(o)),d=a.getRandomValues(new Uint8Array(n)),h={name:e,iv:d};typeof m=="string"&&(m=Q(m));let p;if(m.length===0){p=await a.subtle.importKey("jwk",Ic,{name:"AES-GCM"},!0,["encrypt"]);try{let x={name:"PBKDF2",salt:g,iterations:i,hash:{name:s}},b=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);p=await a.subtle.deriveKey(x,b,{name:e,length:t},!0,["encrypt"])}catch{p=await a.subtle.importKey("jwk",Ic,{name:"AES-GCM"},!0,["encrypt"])}}else{let x={name:"PBKDF2",salt:g,iterations:i,hash:{name:s}},b=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);p=await a.subtle.deriveKey(x,b,{name:e,length:t},!0,["encrypt"])}let y=await a.subtle.encrypt(h,p,f);return xe([g,h.iv,new Uint8Array(y)])}async function u(f,m){let g=f.subarray(0,o),d=f.subarray(o,o+n),h=f.subarray(o+n),p={name:e,iv:d};typeof m=="string"&&(m=Q(m));let y;if(m.length===0)try{let b={name:"PBKDF2",salt:g,iterations:i,hash:{name:s}},v=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(b,v,{name:e,length:t},!0,["decrypt"])}catch{y=await a.subtle.importKey("jwk",Ic,{name:"AES-GCM"},!0,["decrypt"])}else{let b={name:"PBKDF2",salt:g,iterations:i,hash:{name:s}},v=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(b,v,{name:e,length:t},!0,["decrypt"])}let x=await a.subtle.decrypt(p,y,h);return new Uint8Array(x)}return{encrypt:c,decrypt:u}}async function hn(r,e){let n=await mh().encrypt(r,e);return Ji.encode(n)}var he;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1"})(he||(he={}));var Tc;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1"})(Tc||(Tc={}));(function(r){r.codec=()=>Ar(Tc)})(he||(he={}));var wt;(function(r){let e;r.codec=()=>(e==null&&(e=it((t,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),he.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),s.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let s={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let i=t.uint32();switch(i>>>3){case 1:s.Type=he.codec().decode(t);break;case 2:s.Data=t.bytes();break;default:t.skipType(i&7);break}}return s})),e),r.encode=t=>ot(t,r.codec()),r.decode=t=>st(t,r.codec())})(wt||(wt={}));var xt;(function(r){let e;r.codec=()=>(e==null&&(e=it((t,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),he.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),s.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let s={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let i=t.uint32();switch(i>>>3){case 1:s.Type=he.codec().decode(t);break;case 2:s.Data=t.bytes();break;default:t.skipType(i&7);break}}return s})),e),r.encode=t=>ot(t,r.codec()),r.decode=t=>st(t,r.codec())})(xt||(xt={}));var Qn=class{_key;constructor(e){this._key=dn(e,fn)}verify(e,t){return dh(this._key,t,e)}marshal(){return this._key}get bytes(){return wt.encode({Type:he.Ed25519,Data:this.marshal()}).subarray()}equals(e){return Ae(this.bytes,e.bytes)}hash(){let e=Te.digest(this.bytes);return Ze(e)?e.then(({bytes:t})=>t):e.bytes}},_r=class{_key;_publicKey;constructor(e,t){this._key=dn(e,Ot),this._publicKey=dn(t,fn)}sign(e){return hh(this._key,e)}get public(){return new Qn(this._publicKey)}marshal(){return this._key}get bytes(){return xt.encode({Type:he.Ed25519,Data:this.marshal()}).subarray()}equals(e){return Ae(this.bytes,e.bytes)}async hash(){let e=Te.digest(this.bytes),t;return Ze(e)?{bytes:t}=await e:t=e.bytes,t}async id(){let e=jt.digest(this.public.bytes);return ge.encode(e.bytes).substring(1)}async export(e,t="libp2p-key"){if(t==="libp2p-key")return hn(this.bytes,e);throw new L(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function Ry(r){if(r.length>Ot){r=dn(r,Ot+fn);let n=r.subarray(0,Ot),s=r.subarray(Ot,r.length);return new _r(n,s)}r=dn(r,Ot);let e=r.subarray(0,Ot),t=r.subarray(fn);return new _r(e,t)}function Ny(r){return r=dn(r,fn),new Qn(r)}async function Ly(){let{privateKey:r,publicKey:e}=lh();return new _r(r,e)}async function gh(r){let{privateKey:e,publicKey:t}=fh(r);return new _r(e,t)}function dn(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new L(`Key must be a Uint8Array of length ${e}, got ${r.length}`,"ERR_INVALID_KEY_TYPE");return r}var Hc={};J(Hc,{MAX_RSA_KEY_SIZE:()=>ls,RsaPrivateKey:()=>yn,RsaPublicKey:()=>us,fromJwk:()=>aw,generateKeyPair:()=>cw,unmarshalRsaPrivateKey:()=>Fc,unmarshalRsaPublicKey:()=>iw});function Rr(r){if(isNaN(r)||r<=0)throw new L("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return Cr(r)}var cr={};J(cr,{exportToPem:()=>tw,importFromPem:()=>rw,jwkToPkcs1:()=>Xy,jwkToPkix:()=>Qy,pkcs1ToJwk:()=>Zy,pkixToJwk:()=>Jy});var Co=class extends sn{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,kr(e);let n=ct(t);if(this.iHash=e.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?e.create().update(n).digest():n);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=e.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),o.fill(0)}update(e){return nn(this),this.iHash.update(e),this}digestInto(e){nn(this),rn(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:t,iHash:n,finished:s,destroyed:o,blockLen:i,outputLen:a}=this;return e=e,e.finished=s,e.destroyed=o,e.blockLen=i,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},sr=(r,e,t)=>new Co(r,e).update(t).digest();sr.create=(r,e)=>new Co(r,e);function Uy(r,e,t,n){kr(r);let s=$f({dkLen:32,asyncTick:10},n),{c:o,dkLen:i,asyncTick:a}=s;if(Qt(o),Qt(i),Qt(a),o<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=ct(e),u=ct(t),l=new Uint8Array(i),f=sr.create(r,c),m=f._cloneInto().update(u);return{c:o,dkLen:i,asyncTick:a,DK:l,PRF:f,PRFSalt:m}}function Oy(r,e,t,n,s){return r.destroy(),e.destroy(),n&&n.destroy(),s.fill(0),t}async function Rc(r,e,t,n){let{c:s,dkLen:o,asyncTick:i,DK:a,PRF:c,PRFSalt:u}=Uy(r,e,t,n),l,f=new Uint8Array(4),m=on(f),g=new Uint8Array(c.outputLen);for(let d=1,h=0;h<o;d++,h+=c.outputLen){let p=a.subarray(h,h+c.outputLen);m.setInt32(0,d,!1),(l=u._cloneInto(l)).update(f).digestInto(g),p.set(g.subarray(0,p.length)),await Kf(s-1,i,()=>{c._cloneInto(l).update(g).digestInto(g);for(let y=0;y<p.length;y++)p[y]^=g[y]})}return Oy(c,u,a,l,g)}var X=Bs(bh());function Nr(r,e){let t=0;if(r.length===1)return r[0];for(let n=r.length-1;n>=0;n--)t+=r[r.length-1-n]*Math.pow(2,e*n);return t}function or(r,e,t=-1){let n=t,s=r,o=0,i=Math.pow(2,e);for(let a=1;a<8;a++){if(r<i){let c;if(n<0)c=new ArrayBuffer(a),o=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),o=n}let u=new Uint8Array(c);for(let l=a-1;l>=0;l--){let f=Math.pow(2,l*e);u[o-l-1]=Math.floor(s/f),s-=u[o-l-1]*f}return c}i*=Math.pow(2,e)}return new ArrayBuffer(0)}function _o(...r){let e=0,t=0;for(let o of r)e+=o.length;let n=new ArrayBuffer(e),s=new Uint8Array(n);for(let o of r)s.set(o,t),t+=o.length;return s}function Lc(){let r=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){let a=r[0]===255&&r[1]&128,c=r[0]===0&&(r[1]&128)===0;(a||c)&&this.warnings.push("Needlessly long format")}let e=new ArrayBuffer(this.valueHex.byteLength),t=new Uint8Array(e);for(let a=0;a<this.valueHex.byteLength;a++)t[a]=0;t[0]=r[0]&128;let n=Nr(t,8),s=new ArrayBuffer(this.valueHex.byteLength),o=new Uint8Array(s);for(let a=0;a<this.valueHex.byteLength;a++)o[a]=r[a];return o[0]&=127,Nr(o,8)-n}function yh(r){let e=r<0?r*-1:r,t=128;for(let n=1;n<8;n++){if(e<=t){if(r<0){let i=t-e,a=or(i,8,n),c=new Uint8Array(a);return c[0]|=128,a}let s=or(e,8,n),o=new Uint8Array(s);if(o[0]&128){let i=s.slice(0),a=new Uint8Array(i);s=new ArrayBuffer(s.byteLength+1),o=new Uint8Array(s);for(let c=0;c<i.byteLength;c++)o[c+1]=a[c];o[0]=0}return s}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function wh(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let s=0;s<t.length;s++)if(t[s]!==n[s])return!1;return!0}function We(r,e){let t=r.toString(10);if(e<t.length)return"";let n=e-t.length,s=new Array(n);for(let i=0;i<n;i++)s[i]="0";return s.join("").concat(t)}var wD=Math.log(2);function Ro(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Uc(r){let e=0,t=0;for(let s=0;s<r.length;s++){let o=r[s];e+=o.byteLength}let n=new Uint8Array(e);for(let s=0;s<r.length;s++){let o=r[s];n.set(new Uint8Array(o),t),t+=o.byteLength}return n.buffer}function Ht(r,e,t,n){return e instanceof Uint8Array?e.byteLength?t<0?(r.error="Wrong parameter: inputOffset less than zero",!1):n<0?(r.error="Wrong parameter: inputLength less than zero",!1):e.byteLength-t-n<0?(r.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):!0:(r.error="Wrong parameter: inputBuffer has zero length",!1):(r.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}var ts=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return Uc(this.items)}},es=[new Uint8Array([1])],xh="0123456789";var gn="",ht=new ArrayBuffer(0),Oc=new Uint8Array(0),rs="EndOfContent",vh="OCTET STRING",Ah="BIT STRING";function Kt(r){var e;return e=class extends r{constructor(...n){var s;super(...n);let o=n[0]||{};this.isHexOnly=(s=o.isHexOnly)!==null&&s!==void 0?s:!1,this.valueHexView=o.valueHex?X.BufferSourceConverter.toUint8Array(o.valueHex):Oc}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}fromBER(n,s,o){let i=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!Ht(this,i,s,o))return-1;let a=s+o;return this.valueHexView=i.subarray(s,a),this.valueHexView.length?(this.blockLength=o,a):(this.warnings.push("Zero buffer length"),s)}toBER(n=!1){return this.isHexOnly?n?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",ht)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:X.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var Mt=class{constructor({blockLength:e=0,error:t=gn,warnings:n=[],valueBeforeDecode:s=Oc}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=X.BufferSourceConverter.toUint8Array(s)}static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:X.Convert.ToHex(this.valueBeforeDecodeView)}}};Mt.NAME="baseBlock";var Me=class extends Mt{fromBER(e,t,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(e,t){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}};Me.NAME="valueBlock";var No=class extends Kt(Mt){constructor({idBlock:e={}}={}){var t,n,s,o;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?X.BufferSourceConverter.toUint8Array(e.valueHex):Oc,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(s=e.tagNumber)!==null&&s!==void 0?s:-1,this.isConstructed=(o=e.isConstructed)!==null&&o!==void 0?o:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",ht}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let s=new Uint8Array(1);if(!e){let o=this.tagNumber;o&=31,t|=o,s[0]=t}return s.buffer}if(!this.isHexOnly){let s=or(this.tagNumber,7),o=new Uint8Array(s),i=s.byteLength,a=new Uint8Array(i+1);if(a[0]=t|31,!e){for(let c=0;c<i-1;c++)a[c+1]=o[c]|128;a[i]=o[i-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let s=this.valueHexView;for(let o=0;o<s.length-1;o++)n[o+1]=s[o]|128;n[this.valueHexView.byteLength]=s[s.length-1]}return n.buffer}fromBER(e,t,n){let s=X.BufferSourceConverter.toUint8Array(e);if(!Ht(this,s,t,n))return-1;let o=s.subarray(t,t+n);if(o.length===0)return this.error="Zero buffer length",-1;switch(o[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(o[0]&32)===32,this.isHexOnly=!1;let a=o[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,u=this.valueHexView=new Uint8Array(255),l=255;for(;o[c]&128;){if(u[c-1]=o[c]&127,c++,c>=o.length)return this.error="End of input reached before message was fully decoded",-1;if(c===l){l+=255;let m=new Uint8Array(l);for(let g=0;g<u.length;g++)m[g]=u[g];u=this.valueHexView=new Uint8Array(l)}}this.blockLength=c+1,u[c-1]=o[c]&127;let f=new Uint8Array(c);for(let m=0;m<c;m++)f[m]=u[m];u=this.valueHexView=new Uint8Array(c),u.set(f),this.blockLength<=9?this.tagNumber=Nr(u,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(this.tagClass===1&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return t+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}};No.NAME="identificationBlock";var Lo=class extends Mt{constructor({lenBlock:e={}}={}){var t,n,s;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0?t:!1,this.longFormUsed=(n=e.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(s=e.length)!==null&&s!==void 0?s:0}fromBER(e,t,n){let s=X.BufferSourceConverter.toUint8Array(e);if(!Ht(this,s,t,n))return-1;let o=s.subarray(t,t+n);if(o.length===0)return this.error="Zero buffer length",-1;if(o[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=o[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(o[0]&128),this.longFormUsed===!1)return this.length=o[0],this.blockLength=1,t+this.blockLength;let i=o[0]&127;if(i>8)return this.error="Too big integer",-1;if(i+1>o.length)return this.error="End of input reached before message was fully decoded",-1;let a=t+1,c=s.subarray(a,a+i);return c[i-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=Nr(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=i+1,t+this.blockLength}toBER(e=!1){let t,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=128),t;if(this.longFormUsed){let s=or(this.length,8);if(s.byteLength>127)return this.error="Too big length",ht;if(t=new ArrayBuffer(s.byteLength+1),e)return t;let o=new Uint8Array(s);n=new Uint8Array(t),n[0]=s.byteLength|128;for(let i=0;i<s.byteLength;i++)n[i+1]=o[i];return t}return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};Lo.NAME="lengthBlock";var M={},Re=class extends Mt{constructor({name:e=gn,optional:t=!1,primitiveSchema:n,...s}={},o){super(s),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new No(s),this.lenBlock=new Lo(s),this.valueBlock=o?new o(s):new Me(s)}fromBER(e,t,n){let s=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),s)}toBER(e,t){let n=t||new ts;t||Dh(this);let s=this.idBlock.toBER(e);if(n.write(s),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,n),n.write(new ArrayBuffer(2));else{let o=this.valueBlock.toBER(e);this.lenBlock.length=o.byteLength;let i=this.lenBlock.toBER(e);n.write(i),n.write(o)}return t?ht:n.final()}toJSON(){let e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return e==="ascii"?this.onAsciiEncoding():X.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${X.Convert.ToHex(this.valueBlock.valueBeforeDecodeView)}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;let t=this.toBER(),n=e.toBER();return wh(t,n)}};Re.NAME="BaseBlock";function Dh(r){if(r instanceof M.Constructed)for(let e of r.valueBlock.value)Dh(e)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var Uo=class extends Re{constructor({value:e=gn,...t}={},n){super(t,n),e&&this.fromString(e)}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}fromBER(e,t,n){let s=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),s)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};Uo.NAME="BaseStringBlock";var Oo=class extends Kt(Me){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};Oo.NAME="PrimitiveValueBlock";var Bh,Po=class extends Re{constructor(e={}){super(e,Oo),this.idBlock.isConstructed=!1}};Bh=Po;M.Primitive=Bh;Po.NAME="PRIMITIVE";function Wy(r,e){if(r instanceof e)return r;let t=new e;return t.idBlock=r.idBlock,t.lenBlock=r.lenBlock,t.warnings=r.warnings,t.valueBeforeDecodeView=r.valueBeforeDecodeView,t}function gi(r,e=0,t=r.length){let n=e,s=new Re({},Me),o=new Mt;if(!Ht(o,r,e,t))return s.error=o.error,{offset:-1,result:s};if(!r.subarray(e,e+t).length)return s.error="Zero buffer length",{offset:-1,result:s};let a=s.idBlock.fromBER(r,e,t);if(s.idBlock.warnings.length&&s.warnings.concat(s.idBlock.warnings),a===-1)return s.error=s.idBlock.error,{offset:-1,result:s};if(e=a,t-=s.idBlock.blockLength,a=s.lenBlock.fromBER(r,e,t),s.lenBlock.warnings.length&&s.warnings.concat(s.lenBlock.warnings),a===-1)return s.error=s.lenBlock.error,{offset:-1,result:s};if(e=a,t-=s.lenBlock.blockLength,!s.idBlock.isConstructed&&s.lenBlock.isIndefiniteForm)return s.error="Indefinite length form used for primitive encoding form",{offset:-1,result:s};let c=Re;switch(s.idBlock.tagClass){case 1:if(s.idBlock.tagNumber>=37&&s.idBlock.isHexOnly===!1)return s.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:s};switch(s.idBlock.tagNumber){case 0:if(s.idBlock.isConstructed&&s.lenBlock.length>0)return s.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:s};c=M.EndOfContent;break;case 1:c=M.Boolean;break;case 2:c=M.Integer;break;case 3:c=M.BitString;break;case 4:c=M.OctetString;break;case 5:c=M.Null;break;case 6:c=M.ObjectIdentifier;break;case 10:c=M.Enumerated;break;case 12:c=M.Utf8String;break;case 13:c=M.RelativeObjectIdentifier;break;case 14:c=M.TIME;break;case 15:return s.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:s};case 16:c=M.Sequence;break;case 17:c=M.Set;break;case 18:c=M.NumericString;break;case 19:c=M.PrintableString;break;case 20:c=M.TeletexString;break;case 21:c=M.VideotexString;break;case 22:c=M.IA5String;break;case 23:c=M.UTCTime;break;case 24:c=M.GeneralizedTime;break;case 25:c=M.GraphicString;break;case 26:c=M.VisibleString;break;case 27:c=M.GeneralString;break;case 28:c=M.UniversalString;break;case 29:c=M.CharacterString;break;case 30:c=M.BmpString;break;case 31:c=M.DATE;break;case 32:c=M.TimeOfDay;break;case 33:c=M.DateTime;break;case 34:c=M.Duration;break;default:{let u=s.idBlock.isConstructed?new M.Constructed:new M.Primitive;u.idBlock=s.idBlock,u.lenBlock=s.lenBlock,u.warnings=s.warnings,s=u}}break;case 2:case 3:case 4:default:c=s.idBlock.isConstructed?M.Constructed:M.Primitive}return s=Wy(s,c),a=s.fromBER(r,e,s.lenBlock.isIndefiniteForm?t:s.lenBlock.length),s.valueBeforeDecodeView=r.subarray(n,n+s.blockLength),{offset:a,result:s}}function bn(r){if(!r.byteLength){let e=new Re({},Me);return e.error="Input buffer has zero length",{offset:-1,result:e}}return gi(X.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function zy(r,e){return r?1:e}var Et=class extends Me{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let s=X.BufferSourceConverter.toUint8Array(e);if(!Ht(this,s,t,n))return-1;if(this.valueBeforeDecodeView=s.subarray(t,t+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let o=t;for(;zy(this.isIndefiniteForm,n)>0;){let i=gi(s,o,n);if(i.offset===-1)return this.error=i.result.error,this.warnings.concat(i.result.warnings),-1;if(o=i.offset,this.blockLength+=i.result.blockLength,n-=i.result.blockLength,this.value.push(i.result),this.isIndefiniteForm&&i.result.constructor.NAME===rs)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===rs?this.value.pop():this.warnings.push("No EndOfContent block encoded")),o}toBER(e,t){let n=t||new ts;for(let s=0;s<this.value.length;s++)this.value[s].toBER(e,n);return t?ht:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};Et.NAME="ConstructedValueBlock";var Sh,ir=class extends Re{constructor(e={}){super(e,Et),this.idBlock.isConstructed=!0}fromBER(e,t,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let s=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),s)}onAsciiEncoding(){let e=[];for(let n of this.valueBlock.value)e.push(n.toString("ascii").split(`
17
17
  `).map(s=>` ${s}`).join(`
18
18
  `));let t=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return e.length?`${t} :
19
19
  ${e.join(`
20
- `)}`:`${t} :`}};Dh=or;M.Constructed=Dh;or.NAME="CONSTRUCTED";var Uo=class extends Pe{fromBER(e,t,n){return t}toBER(e){return ft}};Uo.override="EndOfContentValueBlock";var Bh,Oo=class extends _e{constructor(e={}){super(e,Uo),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};Bh=Oo;M.EndOfContent=Bh;Oo.NAME=es;var Sh,ir=class extends _e{constructor(e={}){super(e,Pe),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,t,n){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=n,t+n>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+n}toBER(e,t){let n=new ArrayBuffer(2);if(!e){let s=new Uint8Array(n);s[0]=5,s[1]=0}return t&&t.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};Sh=ir;M.Null=Sh;ir.NAME="NULL";var Po=class extends Kt(Pe){constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=X.BufferSourceConverter.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}get value(){for(let e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}fromBER(e,t,n){let s=X.BufferSourceConverter.toUint8Array(e);return Ht(this,s,t,n)?(this.valueHexView=s.subarray(t,t+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,Rc.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};Po.NAME="BooleanValueBlock";var kh,Mo=class extends _e{constructor(e={}){super(e,Po),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};kh=Mo;M.Boolean=kh;Mo.NAME="BOOLEAN";var Fo=class extends Kt(Et){constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,n){let s=0;if(this.isConstructed){if(this.isHexOnly=!1,s=Et.prototype.fromBER.call(this,e,t,n),s===-1)return s;for(let o=0;o<this.value.length;o++){let i=this.value[o].constructor.NAME;if(i===es){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(i!==xh)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,s=super.fromBER(e,t,n),this.blockLength=n;return s}toBER(e,t){return this.isConstructed?Et.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};Fo.NAME="OctetStringValueBlock";var Ch,Ft=class r extends _e{constructor({idBlock:e={},lenBlock:t={},...n}={}){var s,o;(s=n.isConstructed)!==null&&s!==void 0||(n.isConstructed=!!(!((o=n.value)===null||o===void 0)&&o.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},Fo),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,n){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,n===0)return this.idBlock.error.length===0&&(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length===0&&(this.blockLength+=this.lenBlock.blockLength),t;if(!this.valueBlock.isConstructed){let o=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+n);try{if(o.byteLength){let i=di(o,0,o.byteLength);i.offset!==-1&&i.offset===n&&(this.valueBlock.value=[i.result])}}catch{}}return super.fromBER(e,t,n)}onAsciiEncoding(){return this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length?or.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${X.Convert.ToHex(this.valueBlock.valueHexView)}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let e=[];for(let t of this.valueBlock.value)t instanceof r&&e.push(t.valueBlock.valueHexView);return X.BufferSourceConverter.concat(e)}};Ch=Ft;M.OctetString=Ch;Ft.NAME=xh;var Vo=class extends Kt(Et){constructor({unusedBits:e=0,isConstructed:t=!1,...n}={}){super(n),this.unusedBits=e,this.isConstructed=t,this.blockLength=this.valueHexView.byteLength}fromBER(e,t,n){if(!n)return t;let s=-1;if(this.isConstructed){if(s=Et.prototype.fromBER.call(this,e,t,n),s===-1)return s;for(let a of this.value){let c=a.constructor.NAME;if(c===es){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==Eh)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let u=a.valueBlock;if(this.unusedBits>0&&u.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=u.unusedBits}return s}let o=X.BufferSourceConverter.toUint8Array(e);if(!Ht(this,o,t,n))return-1;let i=o.subarray(t,t+n);if(this.unusedBits=i[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let a=i.subarray(1);try{if(a.byteLength){let c=di(a,0,a.byteLength);c.offset!==-1&&c.offset===n-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=i.subarray(1),this.blockLength=i.length,t+n}toBER(e,t){if(this.isConstructed)return Et.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return ft;let n=new Uint8Array(this.valueHexView.length+1);return n[0]=this.unusedBits,n.set(this.valueHexView,1),n.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}};Vo.NAME="BitStringValueBlock";var Ih,hn=class extends _e{constructor({idBlock:e={},lenBlock:t={},...n}={}){var s,o;(s=n.isConstructed)!==null&&s!==void 0||(n.isConstructed=!!(!((o=n.value)===null||o===void 0)&&o.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},Vo),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,t,n){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,t,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return or.prototype.onAsciiEncoding.call(this);{let e=[],t=this.valueBlock.valueHexView;for(let s of t)e.push(s.toString(2).padStart(8,"0"));let n=e.join("");return`${this.constructor.NAME} : ${n.substring(0,n.length-this.valueBlock.unusedBits)}`}}};Ih=hn;M.BitString=Ih;hn.NAME=Eh;var Th;function qy(r,e){let t=new Uint8Array([0]),n=new Uint8Array(r),s=new Uint8Array(e),o=n.slice(0),i=o.length-1,a=s.slice(0),c=a.length-1,u=0,l=c<i?i:c,f=0;for(let m=l;m>=0;m--,f++){switch(!0){case f<a.length:u=o[i-f]+a[c-f]+t[0];break;default:u=o[i-f]+t[0]}switch(t[0]=u/10,!0){case f>=o.length:o=Co(new Uint8Array([u%10]),o);break;default:o[i-f]=u%10}}return t[0]>0&&(o=Co(t,o)),o}function wh(r){if(r>=Jn.length)for(let e=Jn.length;e<=r;e++){let t=new Uint8Array([0]),n=Jn[e-1].slice(0);for(let s=n.length-1;s>=0;s--){let o=new Uint8Array([(n[s]<<1)+t[0]]);t[0]=o[0]/10,n[s]=o[0]%10}t[0]>0&&(n=Co(t,n)),Jn.push(n)}return Jn[r]}function Wy(r,e){let t=0,n=new Uint8Array(r),s=new Uint8Array(e),o=n.slice(0),i=o.length-1,a=s.slice(0),c=a.length-1,u,l=0;for(let f=c;f>=0;f--,l++)switch(u=o[i-l]-a[c-l]-t,!0){case u<0:t=1,o[i-l]=u+10;break;default:t=0,o[i-l]=u}if(t>0)for(let f=i-c+1;f>=0;f--,l++)if(u=o[i-l]-t,u<0)t=1,o[i-l]=u+10;else{t=0,o[i-l]=u;break}return o.slice()}var ts=class extends Kt(Pe){constructor({value:e,...t}={}){super(t),this._valueDec=0,t.valueHex&&this.setValueHex(),e!==void 0&&(this.valueDec=e)}setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=Rc.call(this)))}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(gh(e))}get valueDec(){return this._valueDec}fromDER(e,t,n,s=0){let o=this.fromBER(e,t,n);if(o===-1)return o;let i=this.valueHexView;return i[0]===0&&i[1]&128?this.valueHexView=i.subarray(1):s!==0&&i.length<s&&(s-i.length>1&&(s=i.length+1),this.valueHexView=i.subarray(s-i.length)),o}toDER(e=!1){let t=this.valueHexView;switch(!0){case(t[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(t,1),this.valueHexView=n}break;case(t[0]===0&&(t[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,t,n){let s=super.fromBER(e,t,n);return s===-1||this.setValueHex(),s}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let e=this.valueHexView.length*8-1,t=new Uint8Array(this.valueHexView.length*8/3),n=0,s,o=this.valueHexView,i="",a=!1;for(let c=o.byteLength-1;c>=0;c--){s=o[c];for(let u=0;u<8;u++){if((s&1)===1)switch(n){case e:t=Wy(wh(n),t),i="-";break;default:t=qy(t,wh(n))}n++,s>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(i+=yh.charAt(t[c]));return a===!1&&(i+=yh.charAt(0)),i}};Th=ts;ts.NAME="IntegerValueBlock";Object.defineProperty(Th.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var _h,xe=class r extends _e{constructor(e={}){super(e,ts),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Io(),BigInt(this.valueBlock.toString())}static fromBigInt(e){Io();let t=BigInt(e),n=new Qn,s=t.toString(16).replace(/^-/,""),o=new Uint8Array(X.Convert.FromHex(s));if(t<0){let a=new Uint8Array(o.length+(o[0]&128?1:0));a[0]|=128;let u=BigInt(`0x${X.Convert.ToHex(a)}`)+t,l=X.BufferSourceConverter.toUint8Array(X.Convert.FromHex(u.toString(16)));l[0]|=128,n.write(l)}else o[0]&128&&n.write(new Uint8Array([0])),n.write(o);return new r({valueHex:n.final()})}convertToDER(){let e=new r({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new r({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};_h=xe;M.Integer=_h;xe.NAME="INTEGER";var Rh,Ho=class extends xe{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};Rh=Ho;M.Enumerated=Rh;Ho.NAME="ENUMERATED";var rs=class extends Kt(Pe){constructor({valueDec:e=-1,isFirstSid:t=!1,...n}={}){super(n),this.valueDec=e,this.isFirstSid=t}fromBER(e,t,n){if(!n)return t;let s=X.BufferSourceConverter.toUint8Array(e);if(!Ht(this,s,t,n))return-1;let o=s.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=o[a]&127,this.blockLength++,!!(o[a]&128));a++);let i=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)i[a]=this.valueHexView[a];return this.valueHexView=i,o[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Rr(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){Io();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;let n=new Uint8Array(t.length/7);for(let s=0;s<n.length;s++)n[s]=parseInt(t.slice(s*7,s*7+7),2)+(s+1<n.length?128:0);this.fromBER(n.buffer,0,n.length)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let s=this.valueHexView,o=new Uint8Array(this.blockLength);for(let i=0;i<this.blockLength-1;i++)o[i]=s[i]|128;return o[this.blockLength-1]=s[this.blockLength-1],o.buffer}let t=sr(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",ft;let n=new Uint8Array(t.byteLength);if(!e){let s=new Uint8Array(t),o=t.byteLength-1;for(let i=0;i<o;i++)n[i]=s[i]|128;n[o]=s[o]}return n}toString(){let e="";if(this.isHexOnly)e=X.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let t=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",t-=40):(e="2.",t-=80),e+=t.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};rs.NAME="sidBlock";var Ko=class extends Pe{constructor({value:e=dn,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let s=t;for(;n>0;){let o=new rs;if(s=o.fromBER(e,s,n),s===-1)return this.blockLength=0,this.error=o.error,s;this.value.length===0&&(o.isFirstSid=!0),this.blockLength+=o.blockLength,n-=o.blockLength,this.value.push(o)}return s}toBER(e){let t=[];for(let n=0;n<this.value.length;n++){let s=this.value[n].toBER(e);if(s.byteLength===0)return this.error=this.value[n].error,ft;t.push(s)}return Nc(t)}fromString(e){this.value=[];let t=0,n=0,s="",o=!1;do if(n=e.indexOf(".",t),n===-1?s=e.substring(t):s=e.substring(t,n),t=n+1,o){let i=this.value[0],a=0;switch(i.valueDec){case 0:break;case 1:a=40;break;case 2:a=80;break;default:this.value=[];return}let c=parseInt(s,10);if(isNaN(c))return;i.valueDec=c+a,o=!1}else{let i=new rs;if(s>Number.MAX_SAFE_INTEGER){Io();let a=BigInt(s);i.valueBigInt=a}else if(i.valueDec=parseInt(s,10),isNaN(i.valueDec))return;this.value.length||(i.isFirstSid=!0,o=!0),this.value.push(i)}while(n!==-1)}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let s=this.value[n].toString();n!==0&&(e=`${e}.`),t?(s=`{${s}}`,this.value[n].isFirstSid?e=`2.{${s} - 80}`:e+=s):e+=s}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};Ko.NAME="ObjectIdentifierValueBlock";var Nh,lt=class extends _e{constructor(e={}){super(e,Ko),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};Nh=lt;M.ObjectIdentifier=Nh;lt.NAME="OBJECT IDENTIFIER";var ns=class extends Kt(Mt){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let s=X.BufferSourceConverter.toUint8Array(e);if(!Ht(this,s,t,n))return-1;let o=s.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=o[a]&127,this.blockLength++,!!(o[a]&128));a++);let i=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)i[a]=this.valueHexView[a];return this.valueHexView=i,o[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Rr(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let s=this.valueHexView,o=new Uint8Array(this.blockLength);for(let i=0;i<this.blockLength-1;i++)o[i]=s[i]|128;return o[this.blockLength-1]=s[this.blockLength-1],o.buffer}let t=sr(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",ft;let n=new Uint8Array(t.byteLength);if(!e){let s=new Uint8Array(t),o=t.byteLength-1;for(let i=0;i<o;i++)n[i]=s[i]|128;n[o]=s[o]}return n.buffer}toString(){let e="";return this.isHexOnly?e=X.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};ns.NAME="relativeSidBlock";var $o=class extends Pe{constructor({value:e=dn,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let s=t;for(;n>0;){let o=new ns;if(s=o.fromBER(e,s,n),s===-1)return this.blockLength=0,this.error=o.error,s;this.blockLength+=o.blockLength,n-=o.blockLength,this.value.push(o)}return s}toBER(e,t){let n=[];for(let s=0;s<this.value.length;s++){let o=this.value[s].toBER(e);if(o.byteLength===0)return this.error=this.value[s].error,ft;n.push(o)}return Nc(n)}fromString(e){this.value=[];let t=0,n=0,s="";do{n=e.indexOf(".",t),n===-1?s=e.substring(t):s=e.substring(t,n),t=n+1;let o=new ns;if(o.valueDec=parseInt(s,10),isNaN(o.valueDec))return!0;this.value.push(o)}while(n!==-1);return!0}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let s=this.value[n].toString();n!==0&&(e=`${e}.`),t&&(s=`{${s}}`),e+=s}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};$o.NAME="RelativeObjectIdentifierValueBlock";var Lh,qo=class extends _e{constructor(e={}){super(e,$o),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};Lh=qo;M.RelativeObjectIdentifier=Lh;qo.NAME="RelativeObjectIdentifier";var Uh,ke=class extends or{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};Uh=ke;M.Sequence=Uh;ke.NAME="SEQUENCE";var Oh,Wo=class extends or{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};Oh=Wo;M.Set=Oh;Wo.NAME="SET";var zo=class extends Kt(Pe){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=dn}toJSON(){return{...super.toJSON(),value:this.value}}};zo.NAME="StringValueBlock";var Go=class extends zo{};Go.NAME="SimpleStringValueBlock";var Fe=class extends Ro{constructor({...e}={}){super(e,Go)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,X.BufferSourceConverter.toUint8Array(e))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t);for(let s=0;s<t;s++)n[s]=e.charCodeAt(s);this.valueBlock.value=e}};Fe.NAME="SIMPLE STRING";var jo=class extends Fe{fromBuffer(e){this.valueBlock.valueHexView=X.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=X.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=X.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(X.Convert.FromUtf8String(e)),this.valueBlock.value=e}};jo.NAME="Utf8StringValueBlock";var Ph,Vt=class extends jo{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};Ph=Vt;M.Utf8String=Ph;Vt.NAME="UTF8String";var Yo=class extends Fe{fromBuffer(e){this.valueBlock.value=X.Convert.ToUtf16String(e),this.valueBlock.valueHexView=X.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(X.Convert.FromUtf16String(e))}};Yo.NAME="BmpStringValueBlock";var Mh,Zo=class extends Yo{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};Mh=Zo;M.BmpString=Mh;Zo.NAME="BMPString";var Xo=class extends Fe{fromBuffer(e){let t=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),n=new Uint8Array(t);for(let s=0;s<n.length;s+=4)n[s]=n[s+3],n[s+1]=n[s+2],n[s+2]=0,n[s+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(t))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t*4);for(let s=0;s<t;s++){let o=sr(e.charCodeAt(s),8),i=new Uint8Array(o);if(i.length>4)continue;let a=4-i.length;for(let c=i.length-1;c>=0;c--)n[s*4+c+a]=i[c]}this.valueBlock.value=e}};Xo.NAME="UniversalStringValueBlock";var Fh,Jo=class extends Xo{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};Fh=Jo;M.UniversalString=Fh;Jo.NAME="UniversalString";var Vh,Qo=class extends Fe{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};Vh=Qo;M.NumericString=Vh;Qo.NAME="NumericString";var Hh,ei=class extends Fe{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};Hh=ei;M.PrintableString=Hh;ei.NAME="PrintableString";var Kh,ti=class extends Fe{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};Kh=ti;M.TeletexString=Kh;ti.NAME="TeletexString";var $h,ri=class extends Fe{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};$h=ri;M.VideotexString=$h;ri.NAME="VideotexString";var qh,ni=class extends Fe{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};qh=ni;M.IA5String=qh;ni.NAME="IA5String";var Wh,si=class extends Fe{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};Wh=si;M.GraphicString=Wh;si.NAME="GraphicString";var zh,ss=class extends Fe{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};zh=ss;M.VisibleString=zh;ss.NAME="VisibleString";var Gh,oi=class extends Fe{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};Gh=oi;M.GeneralString=Gh;oi.NAME="GeneralString";var jh,ii=class extends Fe{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};jh=ii;M.CharacterString=jh;ii.NAME="CharacterString";var Yh,os=class extends ss{constructor({value:e,valueDate:t,...n}={}){if(super(n),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let s=0;s<e.length;s++)this.valueBlock.valueHexView[s]=e.charCodeAt(s)}t&&(this.fromDate(t),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,X.BufferSourceConverter.toUint8Array(e)))}toBuffer(){let e=this.toString(),t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let s=0;s<e.length;s++)n[s]=e.charCodeAt(s);return t}fromDate(e){this.year=e.getUTCFullYear(),this.month=e.getUTCMonth()+1,this.day=e.getUTCDate(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(e){let n=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(e);if(n===null){this.error="Wrong input string for conversion";return}let s=parseInt(n[1],10);s>=50?this.year=1900+s:this.year=2e3+s,this.month=parseInt(n[2],10),this.day=parseInt(n[3],10),this.hour=parseInt(n[4],10),this.minute=parseInt(n[5],10),this.second=parseInt(n[6],10)}toString(e="iso"){if(e==="iso"){let t=new Array(7);return t[0]=$e(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=$e(this.month,2),t[2]=$e(this.day,2),t[3]=$e(this.hour,2),t[4]=$e(this.minute,2),t[5]=$e(this.second,2),t[6]="Z",t.join("")}return super.toString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}};Yh=os;M.UTCTime=Yh;os.NAME="UTCTime";var Zh,ai=class extends os{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond))}fromString(e){let t=!1,n="",s="",o=0,i,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),t=!0;else{let f=new Number(e[e.length-1]);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");n=e}if(t){if(n.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(n.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let f=1,m=n.indexOf("+"),g="";if(m===-1&&(m=n.indexOf("-"),f=-1),m!==-1){if(g=n.substring(m+1),n=n.substring(0,m),g.length!==2&&g.length!==4)throw new Error("Wrong input string for conversion");let d=parseInt(g.substring(0,2),10);if(isNaN(d.valueOf()))throw new Error("Wrong input string for conversion");if(a=f*d,g.length===4){if(d=parseInt(g.substring(2,4),10),isNaN(d.valueOf()))throw new Error("Wrong input string for conversion");c=f*d}}}let u=n.indexOf(".");if(u===-1&&(u=n.indexOf(",")),u!==-1){let f=new Number(`0${n.substring(u)}`);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");o=f.valueOf(),s=n.substring(0,u)}else s=n;switch(!0){case s.length===8:if(i=/(\d{4})(\d{2})(\d{2})/ig,u!==-1)throw new Error("Wrong input string for conversion");break;case s.length===10:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let f=60*o;this.minute=Math.floor(f),f=60*(f-this.minute),this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case s.length===12:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let f=60*o;this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case s.length===14:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let f=1e3*o;this.millisecond=Math.floor(f)}break;default:throw new Error("Wrong input string for conversion")}let l=i.exec(s);if(l===null)throw new Error("Wrong input string for conversion");for(let f=1;f<l.length;f++)switch(f){case 1:this.year=parseInt(l[f],10);break;case 2:this.month=parseInt(l[f],10);break;case 3:this.day=parseInt(l[f],10);break;case 4:this.hour=parseInt(l[f],10)+a;break;case 5:this.minute=parseInt(l[f],10)+c;break;case 6:this.second=parseInt(l[f],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){let f=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=f.getUTCFullYear(),this.month=f.getUTCMonth(),this.day=f.getUTCDay(),this.hour=f.getUTCHours(),this.minute=f.getUTCMinutes(),this.second=f.getUTCSeconds(),this.millisecond=f.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let t=[];return t.push($e(this.year,4)),t.push($e(this.month,2)),t.push($e(this.day,2)),t.push($e(this.hour,2)),t.push($e(this.minute,2)),t.push($e(this.second,2)),this.millisecond!==0&&(t.push("."),t.push($e(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};Zh=ai;M.GeneralizedTime=Zh;ai.NAME="GeneralizedTime";var Xh,ci=class extends Vt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};Xh=ci;M.DATE=Xh;ci.NAME="DATE";var Jh,ui=class extends Vt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};Jh=ui;M.TimeOfDay=Jh;ui.NAME="TimeOfDay";var Qh,li=class extends Vt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};Qh=li;M.DateTime=Qh;li.NAME="DateTime";var ed,fi=class extends Vt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};ed=fi;M.Duration=ed;fi.NAME="Duration";var td,hi=class extends Vt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};td=hi;M.TIME=td;hi.NAME="TIME";function Gy(r){let{result:e}=pn(r),t=e.valueBlock.value;return{n:z(vt(t[1].toBigInt()),"base64url"),e:z(vt(t[2].toBigInt()),"base64url"),d:z(vt(t[3].toBigInt()),"base64url"),p:z(vt(t[4].toBigInt()),"base64url"),q:z(vt(t[5].toBigInt()),"base64url"),dp:z(vt(t[6].toBigInt()),"base64url"),dq:z(vt(t[7].toBigInt()),"base64url"),qi:z(vt(t[8].toBigInt()),"base64url"),kty:"RSA",alg:"RS256"}}function jy(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new N("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new ke({value:[new xe({value:0}),xe.fromBigInt(At(Q(r.n,"base64url"))),xe.fromBigInt(At(Q(r.e,"base64url"))),xe.fromBigInt(At(Q(r.d,"base64url"))),xe.fromBigInt(At(Q(r.p,"base64url"))),xe.fromBigInt(At(Q(r.q,"base64url"))),xe.fromBigInt(At(Q(r.dp,"base64url"))),xe.fromBigInt(At(Q(r.dq,"base64url"))),xe.fromBigInt(At(Q(r.qi,"base64url")))]}).toBER();return new Uint8Array(t,0,t.byteLength)}function Yy(r){let{result:e}=pn(r),t=e.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:z(vt(t[0].toBigInt()),"base64url"),e:z(vt(t[1].toBigInt()),"base64url")}}function Zy(r){if(r.n==null||r.e==null)throw new N("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new ke({value:[new ke({value:[new lt({value:"1.2.840.113549.1.1.1"}),new ir]}),new hn({valueHex:new ke({value:[xe.fromBigInt(At(Q(r.n,"base64url"))),xe.fromBigInt(At(Q(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(t,0,t.byteLength)}function vt(r){let e=r.toString(16);e.length%2>0&&(e=`0${e}`);let t=e.length/2,n=new Uint8Array(t),s=0,o=0;for(;s<t;)n[s]=parseInt(e.slice(o,o+2),16),s+=1,o+=2;return n}function At(r){let e=[];return r.forEach(function(t){let n=t.toString(16);n.length%2>0&&(n=`0${n}`),e.push(n)}),BigInt("0x"+e.join(""))}var Xy=16,Uc=32,Oc=1e4;async function Jy(r,e){let t=Me.get(),s=new ke({value:[new xe({value:0}),new ke({value:[new lt({value:"1.2.840.113549.1.1.1"}),new ir]}),new Ft({valueHex:r.marshal()})]}).toBER(),o=new Uint8Array(s,0,s.byteLength),i=_r(Xy),a=await Tc(on,e,i,{c:Oc,dkLen:Uc}),c=_r(16),u=await t.subtle.importKey("raw",a,"AES-CBC",!1,["encrypt"]),l=await t.subtle.encrypt({name:"AES-CBC",iv:c},u,o),f=new ke({value:[new Ft({valueHex:i}),new xe({value:Oc}),new xe({value:Uc}),new ke({value:[new lt({value:"1.2.840.113549.2.11"}),new ir]})]}),m=new ke({value:[new lt({value:"1.2.840.113549.1.5.13"}),new ke({value:[new ke({value:[new lt({value:"1.2.840.113549.1.5.12"}),f]}),new ke({value:[new lt({value:"2.16.840.1.101.3.4.1.42"}),new Ft({valueHex:c})]})]})]}),d=new ke({value:[m,new Ft({valueHex:l})]}).toBER(),h=new Uint8Array(d,0,d.byteLength);return["-----BEGIN ENCRYPTED PRIVATE KEY-----",...z(h,"base64pad").split(/(.{64})/).filter(Boolean),"-----END ENCRYPTED PRIVATE KEY-----"].join(`
21
- `)}async function Qy(r,e){let t=Me.get(),n;if(r.includes("-----BEGIN ENCRYPTED PRIVATE KEY-----")){let s=Q(r.replace("-----BEGIN ENCRYPTED PRIVATE KEY-----","").replace("-----END ENCRYPTED PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:o}=pn(s),{iv:i,salt:a,iterations:c,keySize:u,cipherText:l}=ew(o),f=await Tc(on,e,a,{c,dkLen:u}),m=await t.subtle.importKey("raw",f,"AES-CBC",!1,["decrypt"]),g=is(await t.subtle.decrypt({name:"AES-CBC",iv:i},m,l)),{result:d}=pn(g);n=rd(d)}else if(r.includes("-----BEGIN PRIVATE KEY-----")){let s=Q(r.replace("-----BEGIN PRIVATE KEY-----","").replace("-----END PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:o}=pn(s);n=rd(o)}else throw new N("Could not parse private key from PEM data","ERR_INVALID_PARAMETERS");return Pc(n)}function ew(r){let e=r.valueBlock.value[0];if(e.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.13")throw new N("Only pkcs5PBES2 encrypted private keys are supported","ERR_INVALID_PARAMS");let n=e.valueBlock.value[1].valueBlock.value[0];if(n.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.12")throw new N("Only pkcs5PBKDF2 key derivation functions are supported","ERR_INVALID_PARAMS");let o=n.valueBlock.value[1],i=is(o.valueBlock.value[0].getValue()),a=Oc,c=Uc;if(o.valueBlock.value.length===3)a=Number(o.valueBlock.value[1].toBigInt()),c=Number(o.valueBlock.value[2].toBigInt());else if(o.valueBlock.value.length===2)throw new N("Could not derive key size and iterations from PEM file - please use @libp2p/rsa to re-import your key","ERR_INVALID_PARAMS");let u=e.valueBlock.value[1].valueBlock.value[1],l=u.valueBlock.value[0].toString();if(l!=="OBJECT IDENTIFIER : 1.2.840.113549.3.7"){if(l!=="OBJECT IDENTIFIER : 1.3.14.3.2.7"){if(l!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.2"){if(l!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.22"){if(l!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.42")throw new N("Only AES-CBC encryption schemes are supported","ERR_INVALID_PARAMS")}}}}let f=is(u.valueBlock.value[1].getValue());return{cipherText:is(r.valueBlock.value[1].getValue()),salt:i,iterations:a,keySize:c,iv:f}}function rd(r){return is(r.valueBlock.value[2].getValue())}function is(r){return new Uint8Array(r,0,r.byteLength)}async function nd(r){let e=await Me.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),t=await id(e);return{privateKey:t[0],publicKey:t[1]}}async function Mc(r){let t=[await Me.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),await tw(r)],n=await id({privateKey:t[0],publicKey:t[1]});return{privateKey:n[0],publicKey:n[1]}}async function sd(r,e){let t=await Me.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await Me.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},t,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(n,0,n.byteLength)}async function od(r,e,t){let n=await Me.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return Me.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,e,t instanceof Uint8Array?t:t.subarray())}async function id(r){if(r.privateKey==null||r.publicKey==null)throw new N("Private and public key are required","ERR_INVALID_PARAMETERS");return Promise.all([Me.get().subtle.exportKey("jwk",r.privateKey),Me.get().subtle.exportKey("jwk",r.publicKey)])}async function tw(r){return Me.get().subtle.importKey("jwk",{kty:r.kty,n:r.n,e:r.e},{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])}function pi(r){if(r.kty!=="RSA")throw new N("invalid key type","ERR_INVALID_KEY_TYPE");if(r.n==null)throw new N("invalid key modulus","ERR_INVALID_KEY_MODULUS");return Q(r.n,"base64url").length*8}var cs=8192,as=class{_key;constructor(e){this._key=e}verify(e,t){return od(this._key,t,e)}marshal(){return ar.jwkToPkix(this._key)}get bytes(){return wt.encode({Type:le.RSA,Data:this.marshal()}).subarray()}equals(e){return ve(this.bytes,e.bytes)}hash(){let e=Te.digest(this.bytes);return je(e)?e.then(({bytes:t})=>t):e.bytes}},mn=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t}genSecret(){return _r(16)}sign(e){return sd(this._key,e)}get public(){if(this._publicKey==null)throw new N("public key not provided","ERR_PUBKEY_NOT_PROVIDED");return new as(this._publicKey)}marshal(){return ar.jwkToPkcs1(this._key)}get bytes(){return xt.encode({Type:le.RSA,Data:this.marshal()}).subarray()}equals(e){return ve(this.bytes,e.bytes)}hash(){let e=Te.digest(this.bytes);return je(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return z(e,"base58btc")}async export(e,t="pkcs-8"){if(t==="pkcs-8")return ar.exportToPem(this,e);if(t==="libp2p-key")return un(this.bytes,e);throw new N(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};async function Pc(r){let e=ar.pkcs1ToJwk(r);if(pi(e)>cs)throw new N("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await Mc(e);return new mn(t.privateKey,t.publicKey)}function nw(r){let e=ar.pkixToJwk(r);if(pi(e)>cs)throw new N("key size is too large","ERR_KEY_SIZE_TOO_LARGE");return new as(e)}async function sw(r){if(pi(r)>cs)throw new N("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await Mc(r);return new mn(e.privateKey,e.publicKey)}async function ow(r){if(r>cs)throw new N("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await nd(r);return new mn(e.privateKey,e.publicKey)}var qc={};J(qc,{Secp256k1PrivateKey:()=>ls,Secp256k1PublicKey:()=>us,generateKeyPair:()=>xw,unmarshalSecp256k1PrivateKey:()=>yw,unmarshalSecp256k1PublicKey:()=>ww});var iw=(r,e,t)=>r&e^~r&t,aw=(r,e,t)=>r&e^r&t^e&t,cw=new Uint32Array([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]),cr=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ur=new Uint32Array(64),Vc=class extends sn{constructor(){super(64,32,8,!1),this.A=cr[0]|0,this.B=cr[1]|0,this.C=cr[2]|0,this.D=cr[3]|0,this.E=cr[4]|0,this.F=cr[5]|0,this.G=cr[6]|0,this.H=cr[7]|0}get(){let{A:e,B:t,C:n,D:s,E:o,F:i,G:a,H:c}=this;return[e,t,n,s,o,i,a,c]}set(e,t,n,s,o,i,a,c){this.A=e|0,this.B=t|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(e,t){for(let f=0;f<16;f++,t+=4)ur[f]=e.getUint32(t,!1);for(let f=16;f<64;f++){let m=ur[f-15],g=ur[f-2],d=ot(m,7)^ot(m,18)^m>>>3,h=ot(g,17)^ot(g,19)^g>>>10;ur[f]=h+ur[f-7]+d+ur[f-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){let m=ot(a,6)^ot(a,11)^ot(a,25),g=l+m+iw(a,c,u)+cw[f]+ur[f]|0,h=(ot(n,2)^ot(n,13)^ot(n,22))+aw(n,s,o)|0;l=u,u=c,c=a,a=i+g|0,i=o,o=s,s=n,n=g+h|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,l=l+this.H|0,this.set(n,s,o,i,a,c,u,l)}roundClean(){ur.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var gn=po(()=>new Vc);function uw(r){let e=Gn(r);Ye(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:t,Fp:n,a:s}=e;if(t){if(!n.eql(s,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof t!="object"||typeof t.beta!="bigint"||typeof t.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}var{bytesToNumberBE:lw,hexToBytes:fw}=bo,Nr={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(r){let{Err:e}=Nr;if(r.length<2||r[0]!==2)throw new e("Invalid signature integer tag");let t=r[1],n=r.subarray(2,t+2);if(!t||n.length!==t)throw new e("Invalid signature integer: wrong length");if(n[0]&128)throw new e("Invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new e("Invalid signature integer: unnecessary leading zero");return{d:lw(n),l:r.subarray(t+2)}},toSig(r){let{Err:e}=Nr,t=typeof r=="string"?fw(r):r;if(!at(t))throw new Error("ui8a expected");let n=t.length;if(n<2||t[0]!=48)throw new e("Invalid signature tag");if(t[1]!==n-2)throw new e("Invalid signature: incorrect length");let{d:s,l:o}=Nr._parseInt(t.subarray(2)),{d:i,l:a}=Nr._parseInt(o);if(a.length)throw new e("Invalid signature: left bytes after parsing");return{r:s,s:i}},hexFromSig(r){let e=u=>Number.parseInt(u[0],16)&8?"00"+u:u,t=u=>{let l=u.toString(16);return l.length&1?`0${l}`:l},n=e(t(r.s)),s=e(t(r.r)),o=n.length/2,i=s.length/2,a=t(o),c=t(i);return`30${t(i+o+4)}02${c}${s}02${a}${n}`}},$t=BigInt(0),Xe=BigInt(1),V4=BigInt(2),ad=BigInt(3),H4=BigInt(4);function hw(r){let e=uw(r),{Fp:t}=e,n=e.toBytes||((d,h,p)=>{let y=h.toAffine();return Lt(Uint8Array.from([4]),t.toBytes(y.x),t.toBytes(y.y))}),s=e.fromBytes||(d=>{let h=d.subarray(1),p=t.fromBytes(h.subarray(0,t.BYTES)),y=t.fromBytes(h.subarray(t.BYTES,2*t.BYTES));return{x:p,y}});function o(d){let{a:h,b:p}=e,y=t.sqr(d),x=t.mul(y,d);return t.add(t.add(x,t.mul(d,h)),p)}if(!t.eql(t.sqr(e.Gy),o(e.Gx)))throw new Error("bad generator point: equation left != right");function i(d){return typeof d=="bigint"&&$t<d&&d<e.n}function a(d){if(!i(d))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(d){let{allowedPrivateKeyLengths:h,nByteLength:p,wrapPrivateKey:y,n:x}=e;if(h&&typeof d!="bigint"){if(at(d)&&(d=_t(d)),typeof d!="string"||!h.includes(d.length))throw new Error("Invalid key");d=d.padStart(p*2,"0")}let b;try{b=typeof d=="bigint"?d:Rt(ie("private key",d,p))}catch{throw new Error(`private key must be ${p} bytes, hex or bigint, not ${typeof d}`)}return y&&(b=ee(b,x)),a(b),b}let u=new Map;function l(d){if(!(d instanceof f))throw new Error("ProjectivePoint expected")}class f{constructor(h,p,y){if(this.px=h,this.py=p,this.pz=y,h==null||!t.isValid(h))throw new Error("x required");if(p==null||!t.isValid(p))throw new Error("y required");if(y==null||!t.isValid(y))throw new Error("z required")}static fromAffine(h){let{x:p,y}=h||{};if(!h||!t.isValid(p)||!t.isValid(y))throw new Error("invalid affine point");if(h instanceof f)throw new Error("projective point not allowed");let x=b=>t.eql(b,t.ZERO);return x(p)&&x(y)?f.ZERO:new f(p,y,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let p=t.invertBatch(h.map(y=>y.pz));return h.map((y,x)=>y.toAffine(p[x])).map(f.fromAffine)}static fromHex(h){let p=f.fromAffine(s(ie("pointHex",h)));return p.assertValidity(),p}static fromPrivateKey(h){return f.BASE.multiply(c(h))}_setWindowSize(h){this._WINDOW_SIZE=h,u.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!t.is0(this.py))return;throw new Error("bad point: ZERO")}let{x:h,y:p}=this.toAffine();if(!t.isValid(h)||!t.isValid(p))throw new Error("bad point: x or y not FE");let y=t.sqr(p),x=o(h);if(!t.eql(y,x))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:h}=this.toAffine();if(t.isOdd)return!t.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){l(h);let{px:p,py:y,pz:x}=this,{px:b,py:v,pz:E}=h,A=t.eql(t.mul(p,E),t.mul(b,x)),S=t.eql(t.mul(y,E),t.mul(v,x));return A&&S}negate(){return new f(this.px,t.neg(this.py),this.pz)}double(){let{a:h,b:p}=e,y=t.mul(p,ad),{px:x,py:b,pz:v}=this,E=t.ZERO,A=t.ZERO,S=t.ZERO,D=t.mul(x,x),_=t.mul(b,b),U=t.mul(v,v),R=t.mul(x,b);return R=t.add(R,R),S=t.mul(x,v),S=t.add(S,S),E=t.mul(h,S),A=t.mul(y,U),A=t.add(E,A),E=t.sub(_,A),A=t.add(_,A),A=t.mul(E,A),E=t.mul(R,E),S=t.mul(y,S),U=t.mul(h,U),R=t.sub(D,U),R=t.mul(h,R),R=t.add(R,S),S=t.add(D,D),D=t.add(S,D),D=t.add(D,U),D=t.mul(D,R),A=t.add(A,D),U=t.mul(b,v),U=t.add(U,U),D=t.mul(U,R),E=t.sub(E,D),S=t.mul(U,_),S=t.add(S,S),S=t.add(S,S),new f(E,A,S)}add(h){l(h);let{px:p,py:y,pz:x}=this,{px:b,py:v,pz:E}=h,A=t.ZERO,S=t.ZERO,D=t.ZERO,_=e.a,U=t.mul(e.b,ad),R=t.mul(p,b),H=t.mul(y,v),V=t.mul(x,E),G=t.add(p,y),B=t.add(b,v);G=t.mul(G,B),B=t.add(R,H),G=t.sub(G,B),B=t.add(p,x);let I=t.add(b,E);return B=t.mul(B,I),I=t.add(R,V),B=t.sub(B,I),I=t.add(y,x),A=t.add(v,E),I=t.mul(I,A),A=t.add(H,V),I=t.sub(I,A),D=t.mul(_,B),A=t.mul(U,V),D=t.add(A,D),A=t.sub(H,D),D=t.add(H,D),S=t.mul(A,D),H=t.add(R,R),H=t.add(H,R),V=t.mul(_,V),B=t.mul(U,B),H=t.add(H,V),V=t.sub(R,V),V=t.mul(_,V),B=t.add(B,V),R=t.mul(H,B),S=t.add(S,R),R=t.mul(I,B),A=t.mul(G,A),A=t.sub(A,R),R=t.mul(G,H),D=t.mul(I,D),D=t.add(D,R),new f(A,S,D)}subtract(h){return this.add(h.negate())}is0(){return this.equals(f.ZERO)}wNAF(h){return g.wNAFCached(this,u,h,p=>{let y=t.invertBatch(p.map(x=>x.pz));return p.map((x,b)=>x.toAffine(y[b])).map(f.fromAffine)})}multiplyUnsafe(h){let p=f.ZERO;if(h===$t)return p;if(a(h),h===Xe)return this;let{endo:y}=e;if(!y)return g.unsafeLadder(this,h);let{k1neg:x,k1:b,k2neg:v,k2:E}=y.splitScalar(h),A=p,S=p,D=this;for(;b>$t||E>$t;)b&Xe&&(A=A.add(D)),E&Xe&&(S=S.add(D)),D=D.double(),b>>=Xe,E>>=Xe;return x&&(A=A.negate()),v&&(S=S.negate()),S=new f(t.mul(S.px,y.beta),S.py,S.pz),A.add(S)}multiply(h){a(h);let p=h,y,x,{endo:b}=e;if(b){let{k1neg:v,k1:E,k2neg:A,k2:S}=b.splitScalar(p),{p:D,f:_}=this.wNAF(E),{p:U,f:R}=this.wNAF(S);D=g.constTimeNegate(v,D),U=g.constTimeNegate(A,U),U=new f(t.mul(U.px,b.beta),U.py,U.pz),y=D.add(U),x=_.add(R)}else{let{p:v,f:E}=this.wNAF(p);y=v,x=E}return f.normalizeZ([y,x])[0]}multiplyAndAddUnsafe(h,p,y){let x=f.BASE,b=(E,A)=>A===$t||A===Xe||!E.equals(x)?E.multiplyUnsafe(A):E.multiply(A),v=b(this,p).add(b(h,y));return v.is0()?void 0:v}toAffine(h){let{px:p,py:y,pz:x}=this,b=this.is0();h==null&&(h=b?t.ONE:t.inv(x));let v=t.mul(p,h),E=t.mul(y,h),A=t.mul(x,h);if(b)return{x:t.ZERO,y:t.ZERO};if(!t.eql(A,t.ONE))throw new Error("invZ was invalid");return{x:v,y:E}}isTorsionFree(){let{h,isTorsionFree:p}=e;if(h===Xe)return!0;if(p)return p(f,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:p}=e;return h===Xe?this:p?p(f,this):this.multiplyUnsafe(e.h)}toRawBytes(h=!0){return this.assertValidity(),n(f,this,h)}toHex(h=!0){return _t(this.toRawBytes(h))}}f.BASE=new f(e.Gx,e.Gy,t.ONE),f.ZERO=new f(t.ZERO,t.ONE,t.ZERO);let m=e.nBitLength,g=xo(f,e.endo?Math.ceil(m/2):m);return{CURVE:e,ProjectivePoint:f,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:i}}function dw(r){let e=Gn(r);return Ye(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function cd(r){let e=dw(r),{Fp:t,n}=e,s=t.BYTES+1,o=2*t.BYTES+1;function i(B){return $t<B&&B<t.ORDER}function a(B){return ee(B,n)}function c(B){return yo(B,n)}let{ProjectivePoint:u,normPrivateKeyToScalar:l,weierstrassEquation:f,isWithinCurveOrder:m}=hw({...e,toBytes(B,I,P){let k=I.toAffine(),w=t.toBytes(k.x),C=Lt;return P?C(Uint8Array.from([I.hasEvenY()?2:3]),w):C(Uint8Array.from([4]),w,t.toBytes(k.y))},fromBytes(B){let I=B.length,P=B[0],k=B.subarray(1);if(I===s&&(P===2||P===3)){let w=Rt(k);if(!i(w))throw new Error("Point is not on curve");let C=f(w),T=t.sqrt(C),O=(T&Xe)===Xe;return(P&1)===1!==O&&(T=t.neg(T)),{x:w,y:T}}else if(I===o&&P===4){let w=t.fromBytes(k.subarray(0,t.BYTES)),C=t.fromBytes(k.subarray(t.BYTES,2*t.BYTES));return{x:w,y:C}}else throw new Error(`Point of length ${I} was invalid. Expected ${s} compressed bytes or ${o} uncompressed bytes`)}}),g=B=>_t(rr(B,e.nByteLength));function d(B){let I=n>>Xe;return B>I}function h(B){return d(B)?a(-B):B}let p=(B,I,P)=>Rt(B.slice(I,P));class y{constructor(I,P,k){this.r=I,this.s=P,this.recovery=k,this.assertValidity()}static fromCompact(I){let P=e.nByteLength;return I=ie("compactSignature",I,P*2),new y(p(I,0,P),p(I,P,2*P))}static fromDER(I){let{r:P,s:k}=Nr.toSig(ie("DER",I));return new y(P,k)}assertValidity(){if(!m(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!m(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(I){return new y(this.r,this.s,I)}recoverPublicKey(I){let{r:P,s:k,recovery:w}=this,C=S(ie("msgHash",I));if(w==null||![0,1,2,3].includes(w))throw new Error("recovery id invalid");let T=w===2||w===3?P+e.n:P;if(T>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let O=w&1?"03":"02",$=u.fromHex(O+g(T)),q=c(T),Z=a(-C*q),W=a(k*q),j=u.BASE.multiplyAndAddUnsafe($,Z,W);if(!j)throw new Error("point at infinify");return j.assertValidity(),j}hasHighS(){return d(this.s)}normalizeS(){return this.hasHighS()?new y(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return Cr(this.toDERHex())}toDERHex(){return Nr.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Cr(this.toCompactHex())}toCompactHex(){return g(this.r)+g(this.s)}}let x={isValidPrivateKey(B){try{return l(B),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let B=vc(e.n);return eh(e.randomBytes(B),e.n)},precompute(B=8,I=u.BASE){return I._setWindowSize(B),I.multiply(BigInt(3)),I}};function b(B,I=!0){return u.fromPrivateKey(B).toRawBytes(I)}function v(B){let I=at(B),P=typeof B=="string",k=(I||P)&&B.length;return I?k===s||k===o:P?k===2*s||k===2*o:B instanceof u}function E(B,I,P=!0){if(v(B))throw new Error("first arg must be private key");if(!v(I))throw new Error("second arg must be public key");return u.fromHex(I).multiply(l(B)).toRawBytes(P)}let A=e.bits2int||function(B){let I=Rt(B),P=B.length*8-e.nBitLength;return P>0?I>>BigInt(P):I},S=e.bits2int_modN||function(B){return a(A(B))},D=zn(e.nBitLength);function _(B){if(typeof B!="bigint")throw new Error("bigint expected");if(!($t<=B&&B<D))throw new Error(`bigint expected < 2^${e.nBitLength}`);return rr(B,e.nByteLength)}function U(B,I,P=R){if(["recovered","canonical"].some(se=>se in P))throw new Error("sign() legacy options not supported");let{hash:k,randomBytes:w}=e,{lowS:C,prehash:T,extraEntropy:O}=P;C==null&&(C=!0),B=ie("msgHash",B),T&&(B=ie("prehashed msgHash",k(B)));let $=S(B),q=l(I),Z=[_(q),_($)];if(O!=null){let se=O===!0?w(t.BYTES):O;Z.push(ie("extraEntropy",se))}let W=Lt(...Z),j=$;function oe(se){let Ce=A(se);if(!m(Ce))return;let Ie=c(Ce),Ee=u.BASE.multiply(Ce).toAffine(),Le=a(Ee.x);if(Le===$t)return;let Bt=a(Ie*a(j+Le*q));if(Bt===$t)return;let hr=(Ee.x===Le?0:2)|Number(Ee.y&Xe),_n=Bt;return C&&d(Bt)&&(_n=h(Bt),hr^=1),new y(Le,_n,hr)}return{seed:W,k2sig:oe}}let R={lowS:e.lowS,prehash:!1},H={lowS:e.lowS,prehash:!1};function V(B,I,P=R){let{seed:k,k2sig:w}=U(B,I,P),C=e;return bc(C.hash.outputLen,C.nByteLength,C.hmac)(k,w)}u.BASE._setWindowSize(8);function G(B,I,P,k=H){let w=B;if(I=ie("msgHash",I),P=ie("publicKey",P),"strict"in k)throw new Error("options.strict was renamed to lowS");let{lowS:C,prehash:T}=k,O,$;try{if(typeof w=="string"||at(w))try{O=y.fromDER(w)}catch(Ee){if(!(Ee instanceof Nr.Err))throw Ee;O=y.fromCompact(w)}else if(typeof w=="object"&&typeof w.r=="bigint"&&typeof w.s=="bigint"){let{r:Ee,s:Le}=w;O=new y(Ee,Le)}else throw new Error("PARSE");$=u.fromHex(P)}catch(Ee){if(Ee.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(C&&O.hasHighS())return!1;T&&(I=e.hash(I));let{r:q,s:Z}=O,W=S(I),j=c(Z),oe=a(W*j),se=a(q*j),Ce=u.BASE.multiplyAndAddUnsafe($,oe,se)?.toAffine();return Ce?a(Ce.x)===q:!1}return{CURVE:e,getPublicKey:b,getSharedSecret:E,sign:V,verify:G,ProjectivePoint:u,Signature:y,utils:x}}function pw(r){return{hash:r,hmac:(e,...t)=>nr(r,e,ho(...t)),randomBytes:kr}}function ud(r,e){let t=n=>cd({...r,...pw(n)});return Object.freeze({...t(e),create:t})}var hd=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),ld=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),mw=BigInt(1),Hc=BigInt(2),fd=(r,e)=>(r+e/Hc)/e;function gw(r){let e=hd,t=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%e,l=u*u*r%e,f=ae(l,t,e)*l%e,m=ae(f,t,e)*l%e,g=ae(m,Hc,e)*u%e,d=ae(g,s,e)*g%e,h=ae(d,o,e)*d%e,p=ae(h,a,e)*h%e,y=ae(p,c,e)*p%e,x=ae(y,a,e)*h%e,b=ae(x,t,e)*l%e,v=ae(b,i,e)*d%e,E=ae(v,n,e)*u%e,A=ae(E,Hc,e);if(!Kc.eql(Kc.sqr(A),r))throw new Error("Cannot find square root");return A}var Kc=wo(hd,void 0,void 0,{sqrt:gw}),ht=ud({a:BigInt(0),b:BigInt(7),Fp:Kc,n:ld,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=ld,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-mw*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=t,i=BigInt("0x100000000000000000000000000000000"),a=fd(o*r,e),c=fd(-n*r,e),u=ee(r-a*t-c*s,e),l=ee(-a*n-c*o,e),f=u>i,m=l>i;if(f&&(u=e-u),m&&(l=e-l),u>i||l>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:u,k2neg:m,k2:l}}}},gn),Z4=BigInt(0);var X4=ht.ProjectivePoint;function dd(){return ht.utils.randomPrivateKey()}function pd(r,e){let t=Te.digest(e instanceof Uint8Array?e:e.subarray());if(je(t))return t.then(({digest:n})=>ht.sign(n,r).toDERRawBytes()).catch(n=>{throw new N(String(n),"ERR_INVALID_INPUT")});try{return ht.sign(t.digest,r).toDERRawBytes()}catch(n){throw new N(String(n),"ERR_INVALID_INPUT")}}function md(r,e,t){let n=Te.digest(t instanceof Uint8Array?t:t.subarray());if(je(n))return n.then(({digest:s})=>ht.verify(e,s,r)).catch(s=>{throw new N(String(s),"ERR_INVALID_INPUT")});try{return ht.verify(e,n.digest,r)}catch(s){throw new N(String(s),"ERR_INVALID_INPUT")}}function gd(r){return ht.ProjectivePoint.fromHex(r).toRawBytes(!0)}function bd(r){try{ht.getPublicKey(r,!0)}catch(e){throw new N(String(e),"ERR_INVALID_PRIVATE_KEY")}}function $c(r){try{ht.ProjectivePoint.fromHex(r)}catch(e){throw new N(String(e),"ERR_INVALID_PUBLIC_KEY")}}function yd(r){try{return ht.getPublicKey(r,!0)}catch(e){throw new N(String(e),"ERR_INVALID_PRIVATE_KEY")}}var us=class{_key;constructor(e){$c(e),this._key=e}verify(e,t){return md(this._key,t,e)}marshal(){return gd(this._key)}get bytes(){return wt.encode({Type:le.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return ve(this.bytes,e.bytes)}async hash(){let e=Te.digest(this.bytes),t;return je(e)?{bytes:t}=await e:t=e.bytes,t}},ls=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t??yd(e),bd(this._key),$c(this._publicKey)}sign(e){return pd(this._key,e)}get public(){return new us(this._publicKey)}marshal(){return this._key}get bytes(){return xt.encode({Type:le.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return ve(this.bytes,e.bytes)}hash(){let e=Te.digest(this.bytes);return je(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return z(e,"base58btc")}async export(e,t="libp2p-key"){if(t==="libp2p-key")return un(this.bytes,e);throw new N(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function yw(r){return new ls(r)}function ww(r){return new us(r)}async function xw(){let r=dd();return new ls(r)}var Lr={rsa:Fc,ed25519:Ic,secp256k1:qc};function wd(r){let e=Object.keys(Lr).join(" / ");return new N(`invalid or unsupported key type ${r}. Must be ${e}`,"ERR_UNSUPPORTED_KEY_TYPE")}function xd(r){let e=wt.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case le.RSA:return Lr.rsa.unmarshalRsaPublicKey(t);case le.Ed25519:return Lr.ed25519.unmarshalEd25519PublicKey(t);case le.Secp256k1:return Lr.secp256k1.unmarshalSecp256k1PublicKey(t);default:throw wd(e.Type??"unknown")}}async function Wc(r){let e=xt.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case le.RSA:return Lr.rsa.unmarshalRsaPrivateKey(t);case le.Ed25519:return Lr.ed25519.unmarshalEd25519PrivateKey(t);case le.Secp256k1:return Lr.secp256k1.unmarshalSecp256k1PrivateKey(t);default:throw wd(e.Type??"RSA")}}function zc(){let r=he(),e=!1;return{sink:async t=>{if(e)throw new Error("already piped");e=!0,r.resolve(t)},source:async function*(){yield*await r.promise}()}}function Ed(){let r=zc(),e=zc();return[{source:r.source,sink:e.sink},{source:e.source,sink:r.sink}]}function Ew(r){return r[Symbol.asyncIterator]!=null}function vw(...r){let e=[];for(let t of r)Ew(t)||e.push(t);return e.length===r.length?function*(){for(let t of e)yield*t}():async function*(){let t=Zt({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let s of n)t.push(s)})),t.end()}catch(n){t.end(n)}}),yield*t}()}var vd=vw;function Ad(r,...e){if(r==null)throw new Error("Empty pipeline");if(Gc(r)){let n=r;r=()=>n.source}else if(Bd(r)||Dd(r)){let n=r;r=()=>n}let t=[r,...e];if(t.length>1&&Gc(t[t.length-1])&&(t[t.length-1]=t[t.length-1].sink),t.length>2)for(let n=1;n<t.length-1;n++)Gc(t[n])&&(t[n]=Dw(t[n]));return Aw(...t)}var Aw=(...r)=>{let e;for(;r.length>0;)e=r.shift()(e);return e},Dd=r=>r?.[Symbol.asyncIterator]!=null,Bd=r=>r?.[Symbol.iterator]!=null,Gc=r=>r==null?!1:r.sink!=null&&r.source!=null,Dw=r=>e=>{let t=r.sink(e);if(t?.then!=null){let n=Zt({objectMode:!0});t.then(()=>{n.end()},i=>{n.end(i)});let s,o=r.source;if(Dd(o))s=async function*(){yield*o,n.end()};else if(Bd(o))s=function*(){yield*o,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return vd(n,s())}return r.source};var bn=!!globalThis.process?.env?.DUMP_SESSION_KEYS;var qt=r=>new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4));function Sd(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var kd=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Bw=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Bw)throw new Error("Non little-endian hardware is not supported");function mi(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function gi(r){if(typeof r=="string")r=mi(r);else if(Sd(r))r=r.slice();else throw new Error(`expected Uint8Array, got ${typeof r}`);return r}var Sw=r=>Object.prototype.toString.call(r)==="[object Object]"&&r.constructor===Object;function Cd(r,e){if(e!==void 0&&(typeof e!="object"||!Sw(e)))throw new Error("options must be object or undefined");return Object.assign(r,e)}function Ur(r,e){if(!Sd(r))throw new Error("Uint8Array expected");if(typeof e=="number"&&r.length!==e)throw new Error(`Uint8Array length ${e} expected`)}function Id(r,e){if(r.length!==e.length)return!1;let t=0;for(let n=0;n<r.length;n++)t|=r[n]^e[n];return t===0}var jc=(r,e)=>(Object.assign(e,r),e);function Yc(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let s=BigInt(32),o=BigInt(4294967295),i=Number(t>>s&o),a=Number(t&o),c=n?4:0,u=n?0:4;r.setUint32(e+c,i,n),r.setUint32(e+u,a,n)}function bi(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`wrong positive integer: ${r}`)}function Zc(r){if(typeof r!="boolean")throw new Error(`boolean expected, not ${r}`)}function kw(r){return r!=null&&typeof r=="object"&&(r instanceof Uint8Array||r.constructor.name==="Uint8Array")}function yn(r,...e){if(!kw(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${r.length}`)}function Xc(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function Td(r,e){yn(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var Re=(r,e)=>r[e++]&255|(r[e++]&255)<<8,Jc=class{constructor(e){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,e=gi(e),Ur(e,32);let t=Re(e,0),n=Re(e,2),s=Re(e,4),o=Re(e,6),i=Re(e,8),a=Re(e,10),c=Re(e,12),u=Re(e,14);this.r[0]=t&8191,this.r[1]=(t>>>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 l=0;l<8;l++)this.pad[l]=Re(e,16+2*l)}process(e,t,n=!1){let s=n?0:2048,{h:o,r:i}=this,a=i[0],c=i[1],u=i[2],l=i[3],f=i[4],m=i[5],g=i[6],d=i[7],h=i[8],p=i[9],y=Re(e,t+0),x=Re(e,t+2),b=Re(e,t+4),v=Re(e,t+6),E=Re(e,t+8),A=Re(e,t+10),S=Re(e,t+12),D=Re(e,t+14),_=o[0]+(y&8191),U=o[1]+((y>>>13|x<<3)&8191),R=o[2]+((x>>>10|b<<6)&8191),H=o[3]+((b>>>7|v<<9)&8191),V=o[4]+((v>>>4|E<<12)&8191),G=o[5]+(E>>>1&8191),B=o[6]+((E>>>14|A<<2)&8191),I=o[7]+((A>>>11|S<<5)&8191),P=o[8]+((S>>>8|D<<8)&8191),k=o[9]+(D>>>5|s),w=0,C=w+_*a+U*(5*p)+R*(5*h)+H*(5*d)+V*(5*g);w=C>>>13,C&=8191,C+=G*(5*m)+B*(5*f)+I*(5*l)+P*(5*u)+k*(5*c),w+=C>>>13,C&=8191;let T=w+_*c+U*a+R*(5*p)+H*(5*h)+V*(5*d);w=T>>>13,T&=8191,T+=G*(5*g)+B*(5*m)+I*(5*f)+P*(5*l)+k*(5*u),w+=T>>>13,T&=8191;let O=w+_*u+U*c+R*a+H*(5*p)+V*(5*h);w=O>>>13,O&=8191,O+=G*(5*d)+B*(5*g)+I*(5*m)+P*(5*f)+k*(5*l),w+=O>>>13,O&=8191;let $=w+_*l+U*u+R*c+H*a+V*(5*p);w=$>>>13,$&=8191,$+=G*(5*h)+B*(5*d)+I*(5*g)+P*(5*m)+k*(5*f),w+=$>>>13,$&=8191;let q=w+_*f+U*l+R*u+H*c+V*a;w=q>>>13,q&=8191,q+=G*(5*p)+B*(5*h)+I*(5*d)+P*(5*g)+k*(5*m),w+=q>>>13,q&=8191;let Z=w+_*m+U*f+R*l+H*u+V*c;w=Z>>>13,Z&=8191,Z+=G*a+B*(5*p)+I*(5*h)+P*(5*d)+k*(5*g),w+=Z>>>13,Z&=8191;let W=w+_*g+U*m+R*f+H*l+V*u;w=W>>>13,W&=8191,W+=G*c+B*a+I*(5*p)+P*(5*h)+k*(5*d),w+=W>>>13,W&=8191;let j=w+_*d+U*g+R*m+H*f+V*l;w=j>>>13,j&=8191,j+=G*u+B*c+I*a+P*(5*p)+k*(5*h),w+=j>>>13,j&=8191;let oe=w+_*h+U*d+R*g+H*m+V*f;w=oe>>>13,oe&=8191,oe+=G*l+B*u+I*c+P*a+k*(5*p),w+=oe>>>13,oe&=8191;let se=w+_*p+U*h+R*d+H*g+V*m;w=se>>>13,se&=8191,se+=G*f+B*l+I*u+P*c+k*a,w+=se>>>13,se&=8191,w=(w<<2)+w|0,w=w+C|0,C=w&8191,w=w>>>13,T+=w,o[0]=C,o[1]=T,o[2]=O,o[3]=$,o[4]=q,o[5]=Z,o[6]=W,o[7]=j,o[8]=oe,o[9]=se}finalize(){let{h:e,pad:t}=this,n=new Uint16Array(10),s=e[1]>>>13;e[1]&=8191;for(let a=2;a<10;a++)e[a]+=s,s=e[a]>>>13,e[a]&=8191;e[0]+=s*5,s=e[0]>>>13,e[0]&=8191,e[1]+=s,s=e[1]>>>13,e[1]&=8191,e[2]+=s,n[0]=e[0]+5,s=n[0]>>>13,n[0]&=8191;for(let a=1;a<10;a++)n[a]=e[a]+s,s=n[a]>>>13,n[a]&=8191;n[9]-=8192;let o=(s^1)-1;for(let a=0;a<10;a++)n[a]&=o;o=~o;for(let a=0;a<10;a++)e[a]=e[a]&o|n[a];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let i=e[0]+t[0];e[0]=i&65535;for(let a=1;a<8;a++)i=(e[a]+t[a]|0)+(i>>>16)|0,e[a]=i&65535}update(e){Xc(this);let{buffer:t,blockLen:n}=this;e=gi(e);let s=e.length;for(let o=0;o<s;){let i=Math.min(n-this.pos,s-o);if(i===n){for(;n<=s-o;o+=n)this.process(e,o);continue}t.set(e.subarray(o,o+i),this.pos),this.pos+=i,o+=i,this.pos===n&&(this.process(t,0,!1),this.pos=0)}return this}destroy(){this.h.fill(0),this.r.fill(0),this.buffer.fill(0),this.pad.fill(0)}digestInto(e){Xc(this),Td(e,this),this.finished=!0;let{buffer:t,h:n}=this,{pos:s}=this;if(s){for(t[s++]=1;s<16;s++)t[s]=0;this.process(t,0,!0)}this.finalize();let o=0;for(let i=0;i<8;i++)e[o++]=n[i]>>>0,e[o++]=n[i]>>>8;return e}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}};function Cw(r){let e=(n,s)=>r(s).update(gi(n)).digest(),t=r(new Uint8Array(32));return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=n=>r(n),e}var _d=Cw(r=>new Jc(r));var Iw=mi("expand 16-byte k"),Tw=mi("expand 32-byte k"),_w=qt(Iw),Rw=qt(Tw);function F(r,e){return r<<e|r>>>32-e}function Qc(r){return r.byteOffset%4===0}var yi=64,Nw=16,Nd=2**32-1,Rd=new Uint32Array;function Lw(r,e,t,n,s,o,i,a){let c=s.length,u=new Uint8Array(yi),l=qt(u),f=Qc(s)&&Qc(o),m=f?qt(s):Rd,g=f?qt(o):Rd;for(let d=0;d<c;i++){if(r(e,t,n,l,i,a),i>=Nd)throw new Error("arx: counter overflow");let h=Math.min(yi,c-d);if(f&&h===yi){let p=d/4;if(d%4!==0)throw new Error("arx: invalid block position");for(let y=0,x;y<Nw;y++)x=p+y,g[x]=m[x]^l[y];d+=yi;continue}for(let p=0,y;p<h;p++)y=d+p,o[y]=s[y]^u[p];d+=h}}function eu(r,e){let{allowShortKeys:t,extendNonceFn:n,counterLength:s,counterRight:o,rounds:i}=Cd({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof r!="function")throw new Error("core must be a function");return bi(s),bi(i),Zc(o),Zc(t),(a,c,u,l,f=0)=>{yn(a),yn(c),yn(u);let m=u.length;if(l||(l=new Uint8Array(m)),yn(l),bi(f),f<0||f>=Nd)throw new Error("arx: counter overflow");if(l.length<m)throw new Error(`arx: output (${l.length}) is shorter than data (${m})`);let g=[],d=a.length,h,p;if(d===32)h=a.slice(),g.push(h),p=Rw;else if(d===16&&t)h=new Uint8Array(32),h.set(a),h.set(a,16),p=_w,g.push(h);else throw new Error(`arx: invalid 32-byte key, got length=${d}`);Qc(c)||(c=c.slice(),g.push(c));let y=qt(h);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(p,y,qt(c.subarray(0,16)),y),c=c.subarray(16)}let x=16-s;if(x!==c.length)throw new Error(`arx: nonce must be ${x} or 16 bytes`);if(x!==12){let v=new Uint8Array(12);v.set(c,o?0:12-c.length),c=v,g.push(c)}let b=qt(c);for(Lw(r,p,y,b,u,l,f,i);g.length>0;)g.pop().fill(0);return l}}function Od(r,e,t,n,s,o=20){let i=r[0],a=r[1],c=r[2],u=r[3],l=e[0],f=e[1],m=e[2],g=e[3],d=e[4],h=e[5],p=e[6],y=e[7],x=s,b=t[0],v=t[1],E=t[2],A=i,S=a,D=c,_=u,U=l,R=f,H=m,V=g,G=d,B=h,I=p,P=y,k=x,w=b,C=v,T=E;for(let $=0;$<o;$+=2)A=A+U|0,k=F(k^A,16),G=G+k|0,U=F(U^G,12),A=A+U|0,k=F(k^A,8),G=G+k|0,U=F(U^G,7),S=S+R|0,w=F(w^S,16),B=B+w|0,R=F(R^B,12),S=S+R|0,w=F(w^S,8),B=B+w|0,R=F(R^B,7),D=D+H|0,C=F(C^D,16),I=I+C|0,H=F(H^I,12),D=D+H|0,C=F(C^D,8),I=I+C|0,H=F(H^I,7),_=_+V|0,T=F(T^_,16),P=P+T|0,V=F(V^P,12),_=_+V|0,T=F(T^_,8),P=P+T|0,V=F(V^P,7),A=A+R|0,T=F(T^A,16),I=I+T|0,R=F(R^I,12),A=A+R|0,T=F(T^A,8),I=I+T|0,R=F(R^I,7),S=S+H|0,k=F(k^S,16),P=P+k|0,H=F(H^P,12),S=S+H|0,k=F(k^S,8),P=P+k|0,H=F(H^P,7),D=D+V|0,w=F(w^D,16),G=G+w|0,V=F(V^G,12),D=D+V|0,w=F(w^D,8),G=G+w|0,V=F(V^G,7),_=_+U|0,C=F(C^_,16),B=B+C|0,U=F(U^B,12),_=_+U|0,C=F(C^_,8),B=B+C|0,U=F(U^B,7);let O=0;n[O++]=i+A|0,n[O++]=a+S|0,n[O++]=c+D|0,n[O++]=u+_|0,n[O++]=l+U|0,n[O++]=f+R|0,n[O++]=m+H|0,n[O++]=g+V|0,n[O++]=d+G|0,n[O++]=h+B|0,n[O++]=p+I|0,n[O++]=y+P|0,n[O++]=x+k|0,n[O++]=b+w|0,n[O++]=v+C|0,n[O++]=E+T|0}function Uw(r,e,t,n){let s=r[0],o=r[1],i=r[2],a=r[3],c=e[0],u=e[1],l=e[2],f=e[3],m=e[4],g=e[5],d=e[6],h=e[7],p=t[0],y=t[1],x=t[2],b=t[3];for(let E=0;E<20;E+=2)s=s+c|0,p=F(p^s,16),m=m+p|0,c=F(c^m,12),s=s+c|0,p=F(p^s,8),m=m+p|0,c=F(c^m,7),o=o+u|0,y=F(y^o,16),g=g+y|0,u=F(u^g,12),o=o+u|0,y=F(y^o,8),g=g+y|0,u=F(u^g,7),i=i+l|0,x=F(x^i,16),d=d+x|0,l=F(l^d,12),i=i+l|0,x=F(x^i,8),d=d+x|0,l=F(l^d,7),a=a+f|0,b=F(b^a,16),h=h+b|0,f=F(f^h,12),a=a+f|0,b=F(b^a,8),h=h+b|0,f=F(f^h,7),s=s+u|0,b=F(b^s,16),d=d+b|0,u=F(u^d,12),s=s+u|0,b=F(b^s,8),d=d+b|0,u=F(u^d,7),o=o+l|0,p=F(p^o,16),h=h+p|0,l=F(l^h,12),o=o+l|0,p=F(p^o,8),h=h+p|0,l=F(l^h,7),i=i+f|0,y=F(y^i,16),m=m+y|0,f=F(f^m,12),i=i+f|0,y=F(y^i,8),m=m+y|0,f=F(f^m,7),a=a+c|0,x=F(x^a,16),g=g+x|0,c=F(c^g,12),a=a+c|0,x=F(x^a,8),g=g+x|0,c=F(c^g,7);let v=0;n[v++]=s,n[v++]=o,n[v++]=i,n[v++]=a,n[v++]=p,n[v++]=y,n[v++]=x,n[v++]=b}var Ow=eu(Od,{counterRight:!1,counterLength:4,allowShortKeys:!1}),Pw=eu(Od,{counterRight:!1,counterLength:8,extendNonceFn:Uw,allowShortKeys:!1});var Mw=new Uint8Array(16),Ld=(r,e)=>{r.update(e);let t=e.length%16;t&&r.update(Mw.subarray(t))},Fw=new Uint8Array(32);function Ud(r,e,t,n,s){let o=r(e,t,Fw),i=_d.create(o);s&&Ld(i,s),Ld(i,n);let a=new Uint8Array(16),c=kd(a);Yc(c,0,BigInt(s?s.length:0),!0),Yc(c,8,BigInt(n.length),!0),i.update(a);let u=i.digest();return o.fill(0),u}var Pd=r=>(e,t,n)=>(Ur(e,32),Ur(t),{encrypt:(o,i)=>{let a=o.length,c=a+16;i?Ur(i,c):i=new Uint8Array(c),r(e,t,o,i,1);let u=Ud(r,e,t,i.subarray(0,-16),n);return i.set(u,a),i},decrypt:(o,i)=>{let a=o.length,c=a-16;if(a<16)throw new Error("encrypted data must be at least 16 bytes");i?Ur(i,c):i=new Uint8Array(c);let u=o.subarray(0,-16),l=o.subarray(-16),f=Ud(r,e,t,u,n);if(!Id(l,f))throw new Error("invalid tag");return r(e,t,u,i,1),i}}),tu=jc({blockSize:64,nonceLength:12,tagLength:16},Pd(Ow)),RB=jc({blockSize:64,nonceLength:24,tagLength:16},Pd(Pw));function Fd(r,e,t){return Sr(r),t===void 0&&(t=new Uint8Array(r.outputLen)),nr(r,it(t),it(e))}var ru=new Uint8Array([0]),Md=new Uint8Array;function Vd(r,e,t,n=32){if(Sr(r),Qt(n),n>255*r.outputLen)throw new Error("Length should be <= 255*HashLen");let s=Math.ceil(n/r.outputLen);t===void 0&&(t=Md);let o=new Uint8Array(s*r.outputLen),i=nr.create(r,e),a=i._cloneInto(),c=new Uint8Array(i.outputLen);for(let u=0;u<s;u++)ru[0]=u+1,a.update(u===0?Md:c).update(t).update(ru).digestInto(c),o.set(c,r.outputLen*u),i._cloneInto(a);return i.destroy(),a.destroy(),c.fill(0),ru.fill(0),o.slice(0,n)}var nu={hashSHA256(r){return gn(r.subarray())},getHKDF(r,e){let t=Fd(gn,e,r),s=Vd(gn,t,void 0,96),o=s.subarray(0,32),i=s.subarray(32,64),a=s.subarray(64,96);return[o,i,a]},generateX25519KeyPair(){let r=Zn.utils.randomPrivateKey();return{publicKey:Zn.getPublicKey(r),privateKey:r}},generateX25519KeyPairFromSeed(r){return{publicKey:Zn.getPublicKey(r),privateKey:r}},generateX25519SharedKey(r,e){return Zn.getSharedSecret(r.subarray(),e.subarray())},chaCha20Poly1305Encrypt(r,e,t,n){return tu(n,e,t).encrypt(r.subarray())},chaCha20Poly1305Decrypt(r,e,t,n,s){return tu(n,e,t).decrypt(r.subarray(),s)}};var Hd=nu;function Kd(r){return{generateKeypair:r.generateX25519KeyPair,dh:(e,t)=>r.generateX25519SharedKey(e.privateKey,t).subarray(0,32),encrypt:r.chaCha20Poly1305Encrypt,decrypt:r.chaCha20Poly1305Decrypt,hash:r.hashSHA256,hkdf:r.getHKDF}}var wn=r=>{let e=De(2);return e[0]=r>>8,e[1]=r,e};wn.bytes=2;var fs=r=>{if(r.length<2)throw RangeError("Could not decode int16BE");if(r instanceof Uint8Array){let e=0;return e+=r[0]<<8,e+=r[1],e}return r.getUint16(0)};fs.bytes=2;function $d(r){return{xxHandshakeSuccesses:r.registerCounter("libp2p_noise_xxhandshake_successes_total",{help:"Total count of noise xxHandshakes successes_"}),xxHandshakeErrors:r.registerCounter("libp2p_noise_xxhandshake_error_total",{help:"Total count of noise xxHandshakes errors"}),encryptedPackets:r.registerCounter("libp2p_noise_encrypted_packets_total",{help:"Total count of noise encrypted packets successfully"}),decryptedPackets:r.registerCounter("libp2p_noise_decrypted_packets_total",{help:"Total count of noise decrypted packets"}),decryptErrors:r.registerCounter("libp2p_noise_decrypt_errors_total",{help:"Total count of noise decrypt errors"})}}function su(r,e){!e.enabled||!bn||(r?(e(`LOCAL_STATIC_PUBLIC_KEY ${z(r.publicKey,"hex")}`),e(`LOCAL_STATIC_PRIVATE_KEY ${z(r.privateKey,"hex")}`)):e("Missing local static keys."))}function ou(r,e){!e.enabled||!bn||(r?(e(`LOCAL_PUBLIC_EPHEMERAL_KEY ${z(r.publicKey,"hex")}`),e(`LOCAL_PRIVATE_EPHEMERAL_KEY ${z(r.privateKey,"hex")}`)):e("Missing local ephemeral keys."))}function qd(r,e){!e.enabled||!bn||e(r?`REMOTE_STATIC_PUBLIC_KEY ${z(r.subarray(),"hex")}`:"Missing remote static public key.")}function iu(r,e){!e.enabled||!bn||e(r?`REMOTE_EPHEMERAL_PUBLIC_KEY ${z(r.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function au(r,e,t){!t.enabled||!bn||(t(`CIPHER_STATE_1 ${r.n.getUint64()} ${r.k&&z(r.k,"hex")}`),t(`CIPHER_STATE_2 ${e.n.getUint64()} ${e.k&&z(e.k,"hex")}`))}var wi=class r extends Error{code;constructor(e="Unexpected Peer"){super(e),this.code=r.code}static code="ERR_UNEXPECTED_PEER"},xn=class r extends Error{code;constructor(e="Invalid crypto exchange"){super(e),this.code=r.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var Vw=0,Hw=4294967295,Kw="Cipherstate has reached maximum n, a new handshake must be performed",xi=class{n;bytes;view;constructor(e=Vw){this.n=e,this.bytes=Ae(12),this.view=new DataView(this.bytes.buffer,this.bytes.byteOffset,this.bytes.byteLength),this.view.setUint32(4,e,!0)}increment(){this.n++,this.view.setUint32(4,this.n,!0)}getBytes(){return this.bytes}getUint64(){return this.n}assertValue(){if(this.n>Hw)throw new Error(Kw)}};var Or=Ae(0),En=class{k;n;crypto;constructor(e,t=void 0,n=0){this.crypto=e,this.k=t,this.n=new xi(n)}hasKey(){return!!this.k}encryptWithAd(e,t){if(!this.hasKey())return t;this.n.assertValue();let n=this.crypto.encrypt(t,this.n.getBytes(),e,this.k);return this.n.increment(),n}decryptWithAd(e,t,n){if(!this.hasKey())return t;this.n.assertValue();let s=this.crypto.decrypt(t,this.n.getBytes(),e,this.k,n);return this.n.increment(),s}},cu=class{cs;ck;h;crypto;constructor(e,t){this.crypto=e;let n=Q(t,"utf-8");this.h=$w(e,n),this.ck=this.h,this.cs=new En(e)}mixKey(e){let[t,n]=this.crypto.hkdf(this.ck,e);this.ck=t,this.cs=new En(this.crypto,n)}mixHash(e){this.h=this.crypto.hash(new ce(this.h,e))}encryptAndHash(e){let t=this.cs.encryptWithAd(this.h,e);return this.mixHash(t),t}decryptAndHash(e){let t=this.cs.decryptWithAd(this.h,e);return this.mixHash(e),t}split(){let[e,t]=this.crypto.hkdf(this.ck,Or);return[new En(this.crypto,e),new En(this.crypto,t)]}},uu=class{ss;s;e;rs;re;initiator;crypto;constructor(e){let{crypto:t,protocolName:n,prologue:s,initiator:o,s:i,e:a,rs:c,re:u}=e;this.crypto=t,this.ss=new cu(t,n),this.ss.mixHash(s),this.initiator=o,this.s=i,this.e=a,this.rs=c,this.re=u}writeE(){if(this.e)throw new Error("ephemeral keypair is already set");let e=this.crypto.generateKeypair();return this.ss.mixHash(e.publicKey),this.e=e,e.publicKey}writeS(){if(!this.s)throw new Error("static keypair is not set");return this.ss.encryptAndHash(this.s.publicKey)}writeEE(){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.re))}writeES(){if(this.initiator){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}else{if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}}writeSE(){if(this.initiator){if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}else{if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}}readE(e,t=0){if(this.re)throw new Error("remote ephemeral public key is already set");if(e.byteLength<t+32)throw new Error("message is not long enough");this.re=e.sublist(t,t+32),this.ss.mixHash(this.re)}readS(e,t=0){if(this.rs)throw new Error("remote static public key is already set");let n=32+(this.ss.cs.hasKey()?16:0);if(e.byteLength<t+n)throw new Error("message is not long enough");let s=e.sublist(t,t+n);return this.rs=this.ss.decryptAndHash(s),n}readEE(){this.writeEE()}readES(){this.writeES()}readSE(){this.writeSE()}},hs=class extends uu{writeMessageA(e){return new ce(this.writeE(),this.ss.encryptAndHash(e))}writeMessageB(e){let t=this.writeE();this.writeEE();let n=this.writeS();return this.writeES(),new ce(t,n,this.ss.encryptAndHash(e))}writeMessageC(e){let t=this.writeS();return this.writeSE(),new ce(t,this.ss.encryptAndHash(e))}readMessageA(e){try{return this.readE(e),this.ss.decryptAndHash(e.sublist(32))}catch(t){throw new xn(`handshake stage 0 validation fail: ${t.message}`)}}readMessageB(e){try{this.readE(e),this.readEE();let t=this.readS(e,32);return this.readES(),this.ss.decryptAndHash(e.sublist(32+t))}catch(t){throw new xn(`handshake stage 1 validation fail: ${t.message}`)}}readMessageC(e){try{let t=this.readS(e);return this.readSE(),this.ss.decryptAndHash(e.sublist(t))}catch(t){throw new xn(`handshake stage 2 validation fail: ${t.message}`)}}};function $w(r,e){if(e.length<=32){let t=Ae(32);return t.set(e),t}else return r.hash(e)}var Ei;(function(r){let e;r.codec=()=>(e==null&&(e=st((t,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),t.webtransportCerthashes!=null)for(let o of t.webtransportCerthashes)n.uint32(10),n.bytes(o);s.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let s={webtransportCerthashes:[]},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let i=t.uint32();switch(i>>>3){case 1:{s.webtransportCerthashes.push(t.bytes());break}default:{t.skipType(i&7);break}}}return s})),e),r.encode=t=>nt(t,r.codec()),r.decode=t=>rt(t,r.codec())})(Ei||(Ei={}));var ds;(function(r){let e;r.codec=()=>(e==null&&(e=st((t,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),t.identityKey!=null&&t.identityKey.byteLength>0&&(n.uint32(10),n.bytes(t.identityKey)),t.identitySig!=null&&t.identitySig.byteLength>0&&(n.uint32(18),n.bytes(t.identitySig)),t.extensions!=null&&(n.uint32(34),Ei.codec().encode(t.extensions,n)),s.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let s={identityKey:Ae(0),identitySig:Ae(0)},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let i=t.uint32();switch(i>>>3){case 1:{s.identityKey=t.bytes();break}case 2:{s.identitySig=t.bytes();break}case 4:{s.extensions=Ei.codec().decode(t,t.uint32());break}default:{t.skipType(i&7);break}}}return s})),e),r.encode=t=>nt(t,r.codec()),r.decode=t=>rt(t,r.codec())})(ds||(ds={}));async function lu(r,e,t){let n=await r.sign(Wd(e));return ds.encode({identityKey:r.public.bytes,identitySig:n,extensions:t})}async function fu(r,e,t){try{let n=ds.decode(r);if(t){let i=t.subarray();if(!ve(i,n.identityKey))throw new Error(`Payload identity key ${z(n.identityKey,"hex")} does not match expected remote identity key ${z(i,"hex")}`)}if(!e)throw new Error("Remote static does not exist");let s=Wd(e);if(!await xd(n.identityKey).verify(s,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new wi(n.message)}}function Wd(r){let e=Q("noise-libp2p-static-key:");return r instanceof Uint8Array?we([e,r],e.length+r.length):(r.prepend(e),r)}async function zd(r){let{log:e,connection:t,crypto:n,privateKey:s,prologue:o,s:i,remoteIdentityKey:a,extensions:c}=r,u=await lu(s,i.publicKey,c),l=new hs({crypto:n,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:o,s:i});su(l.s,e),e.trace("Stage 0 - Initiator starting to send first message."),await t.write(l.writeMessageA(Or)),e.trace("Stage 0 - Initiator finished sending first message."),ou(l.e,e),e.trace("Stage 1 - Initiator waiting to receive first message from responder...");let f=l.readMessageB(await t.read());e.trace("Stage 1 - Initiator received the message."),iu(l.re,e),qd(l.rs,e),e.trace("Initiator going to check remote's signature...");let m=await fu(f,l.rs,a);e.trace("All good with the signature!"),e.trace("Stage 2 - Initiator sending third handshake message."),await t.write(l.writeMessageC(u)),e.trace("Stage 2 - Initiator sent message with signed payload.");let[g,d]=l.ss.split();return au(g,d,e),{payload:m,encrypt:h=>g.encryptWithAd(Or,h),decrypt:(h,p)=>d.decryptWithAd(Or,h,p)}}async function Gd(r){let{log:e,connection:t,crypto:n,privateKey:s,prologue:o,s:i,remoteIdentityKey:a,extensions:c}=r,u=await lu(s,i.publicKey,c),l=new hs({crypto:n,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:o,s:i});su(l.s,e),e.trace("Stage 0 - Responder waiting to receive first message."),l.readMessageA(await t.read()),e.trace("Stage 0 - Responder received first message."),iu(l.re,e),e.trace("Stage 1 - Responder sending out first message with signed payload and static key."),await t.write(l.writeMessageB(u)),e.trace("Stage 1 - Responder sent the second handshake message with signed payload."),ou(l.e,e),e.trace("Stage 2 - Responder waiting for third handshake message...");let f=l.readMessageC(await t.read());e.trace("Stage 2 - Responder received the message, finished handshake.");let m=await fu(f,l.rs,a),[g,d]=l.ss.split();return au(g,d,e),{payload:m,encrypt:h=>d.encryptWithAd(Or,h),decrypt:(h,p)=>g.decryptWithAd(Or,h,p)}}var Yd=16;function Zd(r,e){return async function*(t){for await(let n of t)for(let s=0;s<n.length;s+=65519){let o=s+65519;o>n.length&&(o=n.length);let i;n instanceof Uint8Array?i=r.encrypt(n.subarray(s,o)):i=r.encrypt(n.sublist(s,o)),e?.encryptedPackets.increment(),yield new ce(wn(i.byteLength),i)}}}function Xd(r,e){return async function*(t){for await(let n of t)for(let s=0;s<n.length;s+=65535){let o=s+65535;if(o>n.length&&(o=n.length),o-Yd<s)throw new Error("Invalid chunk");let i=n.sublist(s,o),a=n.subarray(s,o-Yd);try{let c=r.decrypt(i,a);e?.decryptedPackets.increment(),yield c}catch(c){throw e?.decryptErrors.increment(),c}}}}var vi=class{protocol="/noise";crypto;prologue;staticKey;extensions;metrics;components;constructor(e,t={}){let{staticNoiseKey:n,extensions:s,crypto:o,prologueBytes:i}=t,{metrics:a}=e;this.components=e;let c=o??Hd;this.crypto=Kd(c),this.extensions=s,this.metrics=a?$d(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=i??Ae(0)}async secureOutbound(e,t,n){let s=Wn(t,{lengthEncoder:wn,lengthDecoder:fs,maxDataLength:65535});if(!e.privateKey)throw new N("local peerId does not contain private key","ERR_NO_PRIVATE_KEY");let o=await Wc(e.privateKey),i=n?.publicKey,a=await this.performHandshakeInitiator(s,o,i),c=await this.createSecureConnection(s,a);return t.source=c.source,t.sink=c.sink,{conn:t,remoteExtensions:a.payload.extensions,remotePeer:await ca(a.payload.identityKey)}}async secureInbound(e,t,n){let s=Wn(t,{lengthEncoder:wn,lengthDecoder:fs,maxDataLength:65535});if(!e.privateKey)throw new N("local peerId does not contain private key","ERR_NO_PRIVATE_KEY");let o=await Wc(e.privateKey),i=n?.publicKey,a=await this.performHandshakeResponder(s,o,i),c=await this.createSecureConnection(s,a);return t.source=c.source,t.sink=c.sink,{conn:t,remoteExtensions:a.payload.extensions,remotePeer:await ca(a.payload.identityKey)}}async performHandshakeInitiator(e,t,n){let s;try{s=await zd({connection:e,privateKey:t,remoteIdentityKey:n,log:this.components.logger.forComponent("libp2p:noise:xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:this.extensions}),this.metrics?.xxHandshakeSuccesses.increment()}catch(o){throw this.metrics?.xxHandshakeErrors.increment(),o}return s}async performHandshakeResponder(e,t,n){let s;try{s=await Gd({connection:e,privateKey:t,remoteIdentityKey:n,log:this.components.logger.forComponent("libp2p:noise:xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:this.extensions}),this.metrics?.xxHandshakeSuccesses.increment()}catch(o){throw this.metrics?.xxHandshakeErrors.increment(),o}return s}async createSecureConnection(e,t){let[n,s]=Ed(),o=e.unwrap();return await Ad(n,Zd(t,this.metrics),o,i=>wr(i,{lengthDecoder:fs}),Xd(t,this.metrics),n),s}};function Jd(r={}){return e=>new vi(e,r)}var Cp=As(Hu(),1);var Ep=As(Hu(),1);var Ku=Object.values(mt).map(r=>r.decoder).reduce((r,e)=>r.or(e));function vp(r,e){let t=r.getConfiguration().certificates?.at(0);if(t==null||t.getFingerprints==null){e.log.trace("fetching fingerprint from local SDP");let s=r.localDescription;return s==null?void 0:Z2(s.sdp)}if(e.log.trace("fetching fingerprint from local certificate"),t.getFingerprints().length===0)return;let n=t.getFingerprints()[0].value;if(n==null)throw Va("","no fingerprint on local certificate");return n}var Y2=/^a=fingerprint:(?:\w+-[0-9]+)\s(?<fingerprint>(:?[0-9a-fA-F]{2})+)$/m;function Z2(r){return r.match(Y2)?.groups?.fingerprint}function X2(r){for(let e of r.protoNames())if(e.startsWith("ip"))return e.toUpperCase();return"IP6"}function Li(r){let t=r.stringTuples().filter(n=>n[0]===Bp).map(n=>n[1])[0];if(t===void 0||t==="")throw Hs(`Couldn't find a certhash component of multiaddr: ${r.toString()}`);return t}function $u(r){let e=Ku.decode(r);return Ep.decode(e)}function J2(r){let e=$u(Li(r)),t=qu(e.name),n=e.digest.reduce((o,i)=>o+i.toString(16).padStart(2,"0"),""),s=n.match(/.{1,2}/g);if(s==null)throw Va(n,r.toString());return[`${t.toUpperCase()} ${s.join(":").toUpperCase()}`,n]}function qu(r){switch(r){case"sha1":return"sha-1";case"sha2-256":return"sha-256";case"sha2-512":return"sha-512";default:throw Xl(r)}}function Q2(r,e){let{host:t,port:n}=r.toOptions(),s=X2(r),[o]=J2(r);return`v=0
20
+ `)}`:`${t} :`}};Sh=ir;M.Constructed=Sh;ir.NAME="CONSTRUCTED";var Mo=class extends Me{fromBER(e,t,n){return t}toBER(e){return ht}};Mo.override="EndOfContentValueBlock";var kh,Fo=class extends Re{constructor(e={}){super(e,Mo),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};kh=Fo;M.EndOfContent=kh;Fo.NAME=rs;var Ch,ar=class extends Re{constructor(e={}){super(e,Me),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,t,n){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=n,t+n>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+n}toBER(e,t){let n=new ArrayBuffer(2);if(!e){let s=new Uint8Array(n);s[0]=5,s[1]=0}return t&&t.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};Ch=ar;M.Null=Ch;ar.NAME="NULL";var Vo=class extends Kt(Me){constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=X.BufferSourceConverter.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}get value(){for(let e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}fromBER(e,t,n){let s=X.BufferSourceConverter.toUint8Array(e);return Ht(this,s,t,n)?(this.valueHexView=s.subarray(t,t+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,Lc.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};Vo.NAME="BooleanValueBlock";var Ih,Ho=class extends Re{constructor(e={}){super(e,Vo),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};Ih=Ho;M.Boolean=Ih;Ho.NAME="BOOLEAN";var Ko=class extends Kt(Et){constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,n){let s=0;if(this.isConstructed){if(this.isHexOnly=!1,s=Et.prototype.fromBER.call(this,e,t,n),s===-1)return s;for(let o=0;o<this.value.length;o++){let i=this.value[o].constructor.NAME;if(i===rs){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(i!==vh)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,s=super.fromBER(e,t,n),this.blockLength=n;return s}toBER(e,t){return this.isConstructed?Et.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};Ko.NAME="OctetStringValueBlock";var Th,Ft=class r extends Re{constructor({idBlock:e={},lenBlock:t={},...n}={}){var s,o;(s=n.isConstructed)!==null&&s!==void 0||(n.isConstructed=!!(!((o=n.value)===null||o===void 0)&&o.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},Ko),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,n){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,n===0)return this.idBlock.error.length===0&&(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length===0&&(this.blockLength+=this.lenBlock.blockLength),t;if(!this.valueBlock.isConstructed){let o=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+n);try{if(o.byteLength){let i=gi(o,0,o.byteLength);i.offset!==-1&&i.offset===n&&(this.valueBlock.value=[i.result])}}catch{}}return super.fromBER(e,t,n)}onAsciiEncoding(){return this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length?ir.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${X.Convert.ToHex(this.valueBlock.valueHexView)}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let e=[];for(let t of this.valueBlock.value)t instanceof r&&e.push(t.valueBlock.valueHexView);return X.BufferSourceConverter.concat(e)}};Th=Ft;M.OctetString=Th;Ft.NAME=vh;var $o=class extends Kt(Et){constructor({unusedBits:e=0,isConstructed:t=!1,...n}={}){super(n),this.unusedBits=e,this.isConstructed=t,this.blockLength=this.valueHexView.byteLength}fromBER(e,t,n){if(!n)return t;let s=-1;if(this.isConstructed){if(s=Et.prototype.fromBER.call(this,e,t,n),s===-1)return s;for(let a of this.value){let c=a.constructor.NAME;if(c===rs){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==Ah)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let u=a.valueBlock;if(this.unusedBits>0&&u.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=u.unusedBits}return s}let o=X.BufferSourceConverter.toUint8Array(e);if(!Ht(this,o,t,n))return-1;let i=o.subarray(t,t+n);if(this.unusedBits=i[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let a=i.subarray(1);try{if(a.byteLength){let c=gi(a,0,a.byteLength);c.offset!==-1&&c.offset===n-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=i.subarray(1),this.blockLength=i.length,t+n}toBER(e,t){if(this.isConstructed)return Et.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return ht;let n=new Uint8Array(this.valueHexView.length+1);return n[0]=this.unusedBits,n.set(this.valueHexView,1),n.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}};$o.NAME="BitStringValueBlock";var _h,mn=class extends Re{constructor({idBlock:e={},lenBlock:t={},...n}={}){var s,o;(s=n.isConstructed)!==null&&s!==void 0||(n.isConstructed=!!(!((o=n.value)===null||o===void 0)&&o.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},$o),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,t,n){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,t,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return ir.prototype.onAsciiEncoding.call(this);{let e=[],t=this.valueBlock.valueHexView;for(let s of t)e.push(s.toString(2).padStart(8,"0"));let n=e.join("");return`${this.constructor.NAME} : ${n.substring(0,n.length-this.valueBlock.unusedBits)}`}}};_h=mn;M.BitString=_h;mn.NAME=Ah;var Rh;function Gy(r,e){let t=new Uint8Array([0]),n=new Uint8Array(r),s=new Uint8Array(e),o=n.slice(0),i=o.length-1,a=s.slice(0),c=a.length-1,u=0,l=c<i?i:c,f=0;for(let m=l;m>=0;m--,f++){switch(!0){case f<a.length:u=o[i-f]+a[c-f]+t[0];break;default:u=o[i-f]+t[0]}switch(t[0]=u/10,!0){case f>=o.length:o=_o(new Uint8Array([u%10]),o);break;default:o[i-f]=u%10}}return t[0]>0&&(o=_o(t,o)),o}function Eh(r){if(r>=es.length)for(let e=es.length;e<=r;e++){let t=new Uint8Array([0]),n=es[e-1].slice(0);for(let s=n.length-1;s>=0;s--){let o=new Uint8Array([(n[s]<<1)+t[0]]);t[0]=o[0]/10,n[s]=o[0]%10}t[0]>0&&(n=_o(t,n)),es.push(n)}return es[r]}function jy(r,e){let t=0,n=new Uint8Array(r),s=new Uint8Array(e),o=n.slice(0),i=o.length-1,a=s.slice(0),c=a.length-1,u,l=0;for(let f=c;f>=0;f--,l++)switch(u=o[i-l]-a[c-l]-t,!0){case u<0:t=1,o[i-l]=u+10;break;default:t=0,o[i-l]=u}if(t>0)for(let f=i-c+1;f>=0;f--,l++)if(u=o[i-l]-t,u<0)t=1,o[i-l]=u+10;else{t=0,o[i-l]=u;break}return o.slice()}var ns=class extends Kt(Me){constructor({value:e,...t}={}){super(t),this._valueDec=0,t.valueHex&&this.setValueHex(),e!==void 0&&(this.valueDec=e)}setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=Lc.call(this)))}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(yh(e))}get valueDec(){return this._valueDec}fromDER(e,t,n,s=0){let o=this.fromBER(e,t,n);if(o===-1)return o;let i=this.valueHexView;return i[0]===0&&i[1]&128?this.valueHexView=i.subarray(1):s!==0&&i.length<s&&(s-i.length>1&&(s=i.length+1),this.valueHexView=i.subarray(s-i.length)),o}toDER(e=!1){let t=this.valueHexView;switch(!0){case(t[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(t,1),this.valueHexView=n}break;case(t[0]===0&&(t[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,t,n){let s=super.fromBER(e,t,n);return s===-1||this.setValueHex(),s}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let e=this.valueHexView.length*8-1,t=new Uint8Array(this.valueHexView.length*8/3),n=0,s,o=this.valueHexView,i="",a=!1;for(let c=o.byteLength-1;c>=0;c--){s=o[c];for(let u=0;u<8;u++){if((s&1)===1)switch(n){case e:t=jy(Eh(n),t),i="-";break;default:t=Gy(t,Eh(n))}n++,s>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(i+=xh.charAt(t[c]));return a===!1&&(i+=xh.charAt(0)),i}};Rh=ns;ns.NAME="IntegerValueBlock";Object.defineProperty(Rh.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var Nh,Ee=class r extends Re{constructor(e={}){super(e,ns),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Ro(),BigInt(this.valueBlock.toString())}static fromBigInt(e){Ro();let t=BigInt(e),n=new ts,s=t.toString(16).replace(/^-/,""),o=new Uint8Array(X.Convert.FromHex(s));if(t<0){let a=new Uint8Array(o.length+(o[0]&128?1:0));a[0]|=128;let u=BigInt(`0x${X.Convert.ToHex(a)}`)+t,l=X.BufferSourceConverter.toUint8Array(X.Convert.FromHex(u.toString(16)));l[0]|=128,n.write(l)}else o[0]&128&&n.write(new Uint8Array([0])),n.write(o);return new r({valueHex:n.final()})}convertToDER(){let e=new r({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new r({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};Nh=Ee;M.Integer=Nh;Ee.NAME="INTEGER";var Lh,qo=class extends Ee{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};Lh=qo;M.Enumerated=Lh;qo.NAME="ENUMERATED";var ss=class extends Kt(Me){constructor({valueDec:e=-1,isFirstSid:t=!1,...n}={}){super(n),this.valueDec=e,this.isFirstSid=t}fromBER(e,t,n){if(!n)return t;let s=X.BufferSourceConverter.toUint8Array(e);if(!Ht(this,s,t,n))return-1;let o=s.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=o[a]&127,this.blockLength++,!!(o[a]&128));a++);let i=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)i[a]=this.valueHexView[a];return this.valueHexView=i,o[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Nr(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){Ro();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;let n=new Uint8Array(t.length/7);for(let s=0;s<n.length;s++)n[s]=parseInt(t.slice(s*7,s*7+7),2)+(s+1<n.length?128:0);this.fromBER(n.buffer,0,n.length)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let s=this.valueHexView,o=new Uint8Array(this.blockLength);for(let i=0;i<this.blockLength-1;i++)o[i]=s[i]|128;return o[this.blockLength-1]=s[this.blockLength-1],o.buffer}let t=or(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",ht;let n=new Uint8Array(t.byteLength);if(!e){let s=new Uint8Array(t),o=t.byteLength-1;for(let i=0;i<o;i++)n[i]=s[i]|128;n[o]=s[o]}return n}toString(){let e="";if(this.isHexOnly)e=X.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let t=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",t-=40):(e="2.",t-=80),e+=t.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};ss.NAME="sidBlock";var Wo=class extends Me{constructor({value:e=gn,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let s=t;for(;n>0;){let o=new ss;if(s=o.fromBER(e,s,n),s===-1)return this.blockLength=0,this.error=o.error,s;this.value.length===0&&(o.isFirstSid=!0),this.blockLength+=o.blockLength,n-=o.blockLength,this.value.push(o)}return s}toBER(e){let t=[];for(let n=0;n<this.value.length;n++){let s=this.value[n].toBER(e);if(s.byteLength===0)return this.error=this.value[n].error,ht;t.push(s)}return Uc(t)}fromString(e){this.value=[];let t=0,n=0,s="",o=!1;do if(n=e.indexOf(".",t),n===-1?s=e.substring(t):s=e.substring(t,n),t=n+1,o){let i=this.value[0],a=0;switch(i.valueDec){case 0:break;case 1:a=40;break;case 2:a=80;break;default:this.value=[];return}let c=parseInt(s,10);if(isNaN(c))return;i.valueDec=c+a,o=!1}else{let i=new ss;if(s>Number.MAX_SAFE_INTEGER){Ro();let a=BigInt(s);i.valueBigInt=a}else if(i.valueDec=parseInt(s,10),isNaN(i.valueDec))return;this.value.length||(i.isFirstSid=!0,o=!0),this.value.push(i)}while(n!==-1)}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let s=this.value[n].toString();n!==0&&(e=`${e}.`),t?(s=`{${s}}`,this.value[n].isFirstSid?e=`2.{${s} - 80}`:e+=s):e+=s}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};Wo.NAME="ObjectIdentifierValueBlock";var Uh,ft=class extends Re{constructor(e={}){super(e,Wo),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};Uh=ft;M.ObjectIdentifier=Uh;ft.NAME="OBJECT IDENTIFIER";var os=class extends Kt(Mt){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let s=X.BufferSourceConverter.toUint8Array(e);if(!Ht(this,s,t,n))return-1;let o=s.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=o[a]&127,this.blockLength++,!!(o[a]&128));a++);let i=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)i[a]=this.valueHexView[a];return this.valueHexView=i,o[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Nr(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let s=this.valueHexView,o=new Uint8Array(this.blockLength);for(let i=0;i<this.blockLength-1;i++)o[i]=s[i]|128;return o[this.blockLength-1]=s[this.blockLength-1],o.buffer}let t=or(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",ht;let n=new Uint8Array(t.byteLength);if(!e){let s=new Uint8Array(t),o=t.byteLength-1;for(let i=0;i<o;i++)n[i]=s[i]|128;n[o]=s[o]}return n.buffer}toString(){let e="";return this.isHexOnly?e=X.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};os.NAME="relativeSidBlock";var zo=class extends Me{constructor({value:e=gn,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let s=t;for(;n>0;){let o=new os;if(s=o.fromBER(e,s,n),s===-1)return this.blockLength=0,this.error=o.error,s;this.blockLength+=o.blockLength,n-=o.blockLength,this.value.push(o)}return s}toBER(e,t){let n=[];for(let s=0;s<this.value.length;s++){let o=this.value[s].toBER(e);if(o.byteLength===0)return this.error=this.value[s].error,ht;n.push(o)}return Uc(n)}fromString(e){this.value=[];let t=0,n=0,s="";do{n=e.indexOf(".",t),n===-1?s=e.substring(t):s=e.substring(t,n),t=n+1;let o=new os;if(o.valueDec=parseInt(s,10),isNaN(o.valueDec))return!0;this.value.push(o)}while(n!==-1);return!0}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let s=this.value[n].toString();n!==0&&(e=`${e}.`),t&&(s=`{${s}}`),e+=s}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};zo.NAME="RelativeObjectIdentifierValueBlock";var Oh,Go=class extends Re{constructor(e={}){super(e,zo),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};Oh=Go;M.RelativeObjectIdentifier=Oh;Go.NAME="RelativeObjectIdentifier";var Ph,ke=class extends ir{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};Ph=ke;M.Sequence=Ph;ke.NAME="SEQUENCE";var Mh,jo=class extends ir{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};Mh=jo;M.Set=Mh;jo.NAME="SET";var Yo=class extends Kt(Me){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=gn}toJSON(){return{...super.toJSON(),value:this.value}}};Yo.NAME="StringValueBlock";var Zo=class extends Yo{};Zo.NAME="SimpleStringValueBlock";var He=class extends Uo{constructor({...e}={}){super(e,Zo)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,X.BufferSourceConverter.toUint8Array(e))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t);for(let s=0;s<t;s++)n[s]=e.charCodeAt(s);this.valueBlock.value=e}};He.NAME="SIMPLE STRING";var Xo=class extends He{fromBuffer(e){this.valueBlock.valueHexView=X.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=X.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=X.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(X.Convert.FromUtf8String(e)),this.valueBlock.value=e}};Xo.NAME="Utf8StringValueBlock";var Fh,Vt=class extends Xo{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};Fh=Vt;M.Utf8String=Fh;Vt.NAME="UTF8String";var Jo=class extends He{fromBuffer(e){this.valueBlock.value=X.Convert.ToUtf16String(e),this.valueBlock.valueHexView=X.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(X.Convert.FromUtf16String(e))}};Jo.NAME="BmpStringValueBlock";var Vh,Qo=class extends Jo{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};Vh=Qo;M.BmpString=Vh;Qo.NAME="BMPString";var ei=class extends He{fromBuffer(e){let t=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),n=new Uint8Array(t);for(let s=0;s<n.length;s+=4)n[s]=n[s+3],n[s+1]=n[s+2],n[s+2]=0,n[s+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(t))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t*4);for(let s=0;s<t;s++){let o=or(e.charCodeAt(s),8),i=new Uint8Array(o);if(i.length>4)continue;let a=4-i.length;for(let c=i.length-1;c>=0;c--)n[s*4+c+a]=i[c]}this.valueBlock.value=e}};ei.NAME="UniversalStringValueBlock";var Hh,ti=class extends ei{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};Hh=ti;M.UniversalString=Hh;ti.NAME="UniversalString";var Kh,ri=class extends He{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};Kh=ri;M.NumericString=Kh;ri.NAME="NumericString";var $h,ni=class extends He{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};$h=ni;M.PrintableString=$h;ni.NAME="PrintableString";var qh,si=class extends He{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};qh=si;M.TeletexString=qh;si.NAME="TeletexString";var Wh,oi=class extends He{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};Wh=oi;M.VideotexString=Wh;oi.NAME="VideotexString";var zh,ii=class extends He{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};zh=ii;M.IA5String=zh;ii.NAME="IA5String";var Gh,ai=class extends He{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};Gh=ai;M.GraphicString=Gh;ai.NAME="GraphicString";var jh,is=class extends He{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};jh=is;M.VisibleString=jh;is.NAME="VisibleString";var Yh,ci=class extends He{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};Yh=ci;M.GeneralString=Yh;ci.NAME="GeneralString";var Zh,ui=class extends He{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};Zh=ui;M.CharacterString=Zh;ui.NAME="CharacterString";var Xh,as=class extends is{constructor({value:e,valueDate:t,...n}={}){if(super(n),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let s=0;s<e.length;s++)this.valueBlock.valueHexView[s]=e.charCodeAt(s)}t&&(this.fromDate(t),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,X.BufferSourceConverter.toUint8Array(e)))}toBuffer(){let e=this.toString(),t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let s=0;s<e.length;s++)n[s]=e.charCodeAt(s);return t}fromDate(e){this.year=e.getUTCFullYear(),this.month=e.getUTCMonth()+1,this.day=e.getUTCDate(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(e){let n=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(e);if(n===null){this.error="Wrong input string for conversion";return}let s=parseInt(n[1],10);s>=50?this.year=1900+s:this.year=2e3+s,this.month=parseInt(n[2],10),this.day=parseInt(n[3],10),this.hour=parseInt(n[4],10),this.minute=parseInt(n[5],10),this.second=parseInt(n[6],10)}toString(e="iso"){if(e==="iso"){let t=new Array(7);return t[0]=We(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=We(this.month,2),t[2]=We(this.day,2),t[3]=We(this.hour,2),t[4]=We(this.minute,2),t[5]=We(this.second,2),t[6]="Z",t.join("")}return super.toString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}};Xh=as;M.UTCTime=Xh;as.NAME="UTCTime";var Jh,li=class extends as{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond))}fromString(e){let t=!1,n="",s="",o=0,i,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),t=!0;else{let f=new Number(e[e.length-1]);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");n=e}if(t){if(n.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(n.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let f=1,m=n.indexOf("+"),g="";if(m===-1&&(m=n.indexOf("-"),f=-1),m!==-1){if(g=n.substring(m+1),n=n.substring(0,m),g.length!==2&&g.length!==4)throw new Error("Wrong input string for conversion");let d=parseInt(g.substring(0,2),10);if(isNaN(d.valueOf()))throw new Error("Wrong input string for conversion");if(a=f*d,g.length===4){if(d=parseInt(g.substring(2,4),10),isNaN(d.valueOf()))throw new Error("Wrong input string for conversion");c=f*d}}}let u=n.indexOf(".");if(u===-1&&(u=n.indexOf(",")),u!==-1){let f=new Number(`0${n.substring(u)}`);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");o=f.valueOf(),s=n.substring(0,u)}else s=n;switch(!0){case s.length===8:if(i=/(\d{4})(\d{2})(\d{2})/ig,u!==-1)throw new Error("Wrong input string for conversion");break;case s.length===10:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let f=60*o;this.minute=Math.floor(f),f=60*(f-this.minute),this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case s.length===12:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let f=60*o;this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case s.length===14:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let f=1e3*o;this.millisecond=Math.floor(f)}break;default:throw new Error("Wrong input string for conversion")}let l=i.exec(s);if(l===null)throw new Error("Wrong input string for conversion");for(let f=1;f<l.length;f++)switch(f){case 1:this.year=parseInt(l[f],10);break;case 2:this.month=parseInt(l[f],10);break;case 3:this.day=parseInt(l[f],10);break;case 4:this.hour=parseInt(l[f],10)+a;break;case 5:this.minute=parseInt(l[f],10)+c;break;case 6:this.second=parseInt(l[f],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){let f=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=f.getUTCFullYear(),this.month=f.getUTCMonth(),this.day=f.getUTCDay(),this.hour=f.getUTCHours(),this.minute=f.getUTCMinutes(),this.second=f.getUTCSeconds(),this.millisecond=f.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let t=[];return t.push(We(this.year,4)),t.push(We(this.month,2)),t.push(We(this.day,2)),t.push(We(this.hour,2)),t.push(We(this.minute,2)),t.push(We(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(We(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};Jh=li;M.GeneralizedTime=Jh;li.NAME="GeneralizedTime";var Qh,fi=class extends Vt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};Qh=fi;M.DATE=Qh;fi.NAME="DATE";var ed,hi=class extends Vt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};ed=hi;M.TimeOfDay=ed;hi.NAME="TimeOfDay";var td,di=class extends Vt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};td=di;M.DateTime=td;di.NAME="DateTime";var rd,pi=class extends Vt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};rd=pi;M.Duration=rd;pi.NAME="Duration";var nd,mi=class extends Vt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};nd=mi;M.TIME=nd;mi.NAME="TIME";function Zy(r){let{result:e}=bn(r),t=e.valueBlock.value;return{n:z(vt(t[1].toBigInt()),"base64url"),e:z(vt(t[2].toBigInt()),"base64url"),d:z(vt(t[3].toBigInt()),"base64url"),p:z(vt(t[4].toBigInt()),"base64url"),q:z(vt(t[5].toBigInt()),"base64url"),dp:z(vt(t[6].toBigInt()),"base64url"),dq:z(vt(t[7].toBigInt()),"base64url"),qi:z(vt(t[8].toBigInt()),"base64url"),kty:"RSA",alg:"RS256"}}function Xy(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new L("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new ke({value:[new Ee({value:0}),Ee.fromBigInt(At(Q(r.n,"base64url"))),Ee.fromBigInt(At(Q(r.e,"base64url"))),Ee.fromBigInt(At(Q(r.d,"base64url"))),Ee.fromBigInt(At(Q(r.p,"base64url"))),Ee.fromBigInt(At(Q(r.q,"base64url"))),Ee.fromBigInt(At(Q(r.dp,"base64url"))),Ee.fromBigInt(At(Q(r.dq,"base64url"))),Ee.fromBigInt(At(Q(r.qi,"base64url")))]}).toBER();return new Uint8Array(t,0,t.byteLength)}function Jy(r){let{result:e}=bn(r),t=e.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:z(vt(t[0].toBigInt()),"base64url"),e:z(vt(t[1].toBigInt()),"base64url")}}function Qy(r){if(r.n==null||r.e==null)throw new L("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new ke({value:[new ke({value:[new ft({value:"1.2.840.113549.1.1.1"}),new ar]}),new mn({valueHex:new ke({value:[Ee.fromBigInt(At(Q(r.n,"base64url"))),Ee.fromBigInt(At(Q(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(t,0,t.byteLength)}function vt(r){let e=r.toString(16);e.length%2>0&&(e=`0${e}`);let t=e.length/2,n=new Uint8Array(t),s=0,o=0;for(;s<t;)n[s]=parseInt(e.slice(o,o+2),16),s+=1,o+=2;return n}function At(r){let e=[];return r.forEach(function(t){let n=t.toString(16);n.length%2>0&&(n=`0${n}`),e.push(n)}),BigInt("0x"+e.join(""))}var ew=16,Pc=32,Mc=1e4;async function tw(r,e){let t=Ve.get(),s=new ke({value:[new Ee({value:0}),new ke({value:[new ft({value:"1.2.840.113549.1.1.1"}),new ar]}),new Ft({valueHex:r.marshal()})]}).toBER(),o=new Uint8Array(s,0,s.byteLength),i=Rr(ew),a=await Rc(cn,e,i,{c:Mc,dkLen:Pc}),c=Rr(16),u=await t.subtle.importKey("raw",a,"AES-CBC",!1,["encrypt"]),l=await t.subtle.encrypt({name:"AES-CBC",iv:c},u,o),f=new ke({value:[new Ft({valueHex:i}),new Ee({value:Mc}),new Ee({value:Pc}),new ke({value:[new ft({value:"1.2.840.113549.2.11"}),new ar]})]}),m=new ke({value:[new ft({value:"1.2.840.113549.1.5.13"}),new ke({value:[new ke({value:[new ft({value:"1.2.840.113549.1.5.12"}),f]}),new ke({value:[new ft({value:"2.16.840.1.101.3.4.1.42"}),new Ft({valueHex:c})]})]})]}),d=new ke({value:[m,new Ft({valueHex:l})]}).toBER(),h=new Uint8Array(d,0,d.byteLength);return["-----BEGIN ENCRYPTED PRIVATE KEY-----",...z(h,"base64pad").split(/(.{64})/).filter(Boolean),"-----END ENCRYPTED PRIVATE KEY-----"].join(`
21
+ `)}async function rw(r,e){let t=Ve.get(),n;if(r.includes("-----BEGIN ENCRYPTED PRIVATE KEY-----")){let s=Q(r.replace("-----BEGIN ENCRYPTED PRIVATE KEY-----","").replace("-----END ENCRYPTED PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:o}=bn(s),{iv:i,salt:a,iterations:c,keySize:u,cipherText:l}=nw(o),f=await Rc(cn,e,a,{c,dkLen:u}),m=await t.subtle.importKey("raw",f,"AES-CBC",!1,["decrypt"]),g=cs(await t.subtle.decrypt({name:"AES-CBC",iv:i},m,l)),{result:d}=bn(g);n=sd(d)}else if(r.includes("-----BEGIN PRIVATE KEY-----")){let s=Q(r.replace("-----BEGIN PRIVATE KEY-----","").replace("-----END PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:o}=bn(s);n=sd(o)}else throw new L("Could not parse private key from PEM data","ERR_INVALID_PARAMETERS");return Fc(n)}function nw(r){let e=r.valueBlock.value[0];if(e.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.13")throw new L("Only pkcs5PBES2 encrypted private keys are supported","ERR_INVALID_PARAMS");let n=e.valueBlock.value[1].valueBlock.value[0];if(n.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.12")throw new L("Only pkcs5PBKDF2 key derivation functions are supported","ERR_INVALID_PARAMS");let o=n.valueBlock.value[1],i=cs(o.valueBlock.value[0].getValue()),a=Mc,c=Pc;if(o.valueBlock.value.length===3)a=Number(o.valueBlock.value[1].toBigInt()),c=Number(o.valueBlock.value[2].toBigInt());else if(o.valueBlock.value.length===2)throw new L("Could not derive key size and iterations from PEM file - please use @libp2p/rsa to re-import your key","ERR_INVALID_PARAMS");let u=e.valueBlock.value[1].valueBlock.value[1],l=u.valueBlock.value[0].toString();if(l!=="OBJECT IDENTIFIER : 1.2.840.113549.3.7"){if(l!=="OBJECT IDENTIFIER : 1.3.14.3.2.7"){if(l!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.2"){if(l!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.22"){if(l!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.42")throw new L("Only AES-CBC encryption schemes are supported","ERR_INVALID_PARAMS")}}}}let f=cs(u.valueBlock.value[1].getValue());return{cipherText:cs(r.valueBlock.value[1].getValue()),salt:i,iterations:a,keySize:c,iv:f}}function sd(r){return cs(r.valueBlock.value[2].getValue())}function cs(r){return new Uint8Array(r,0,r.byteLength)}async function od(r){let e=await Ve.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),t=await cd(e);return{privateKey:t[0],publicKey:t[1]}}async function Vc(r){let t=[await Ve.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),await sw(r)],n=await cd({privateKey:t[0],publicKey:t[1]});return{privateKey:n[0],publicKey:n[1]}}async function id(r,e){let t=await Ve.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await Ve.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},t,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(n,0,n.byteLength)}async function ad(r,e,t){let n=await Ve.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return Ve.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,e,t instanceof Uint8Array?t:t.subarray())}async function cd(r){if(r.privateKey==null||r.publicKey==null)throw new L("Private and public key are required","ERR_INVALID_PARAMETERS");return Promise.all([Ve.get().subtle.exportKey("jwk",r.privateKey),Ve.get().subtle.exportKey("jwk",r.publicKey)])}async function sw(r){return Ve.get().subtle.importKey("jwk",{kty:r.kty,n:r.n,e:r.e},{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])}function bi(r){if(r.kty!=="RSA")throw new L("invalid key type","ERR_INVALID_KEY_TYPE");if(r.n==null)throw new L("invalid key modulus","ERR_INVALID_KEY_MODULUS");return Q(r.n,"base64url").length*8}var ls=8192,us=class{_key;constructor(e){this._key=e}verify(e,t){return ad(this._key,t,e)}marshal(){return cr.jwkToPkix(this._key)}get bytes(){return wt.encode({Type:he.RSA,Data:this.marshal()}).subarray()}equals(e){return Ae(this.bytes,e.bytes)}hash(){let e=Te.digest(this.bytes);return Ze(e)?e.then(({bytes:t})=>t):e.bytes}},yn=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t}genSecret(){return Rr(16)}sign(e){return id(this._key,e)}get public(){if(this._publicKey==null)throw new L("public key not provided","ERR_PUBKEY_NOT_PROVIDED");return new us(this._publicKey)}marshal(){return cr.jwkToPkcs1(this._key)}get bytes(){return xt.encode({Type:he.RSA,Data:this.marshal()}).subarray()}equals(e){return Ae(this.bytes,e.bytes)}hash(){let e=Te.digest(this.bytes);return Ze(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return z(e,"base58btc")}async export(e,t="pkcs-8"){if(t==="pkcs-8")return cr.exportToPem(this,e);if(t==="libp2p-key")return hn(this.bytes,e);throw new L(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};async function Fc(r){let e=cr.pkcs1ToJwk(r);if(bi(e)>ls)throw new L("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await Vc(e);return new yn(t.privateKey,t.publicKey)}function iw(r){let e=cr.pkixToJwk(r);if(bi(e)>ls)throw new L("key size is too large","ERR_KEY_SIZE_TOO_LARGE");return new us(e)}async function aw(r){if(bi(r)>ls)throw new L("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await Vc(r);return new yn(e.privateKey,e.publicKey)}async function cw(r){if(r>ls)throw new L("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await od(r);return new yn(e.privateKey,e.publicKey)}var zc={};J(zc,{Secp256k1PrivateKey:()=>hs,Secp256k1PublicKey:()=>fs,generateKeyPair:()=>Ew,unmarshalSecp256k1PrivateKey:()=>ww,unmarshalSecp256k1PublicKey:()=>xw});var uw=new Uint32Array([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]),ur=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),lr=new Uint32Array(64),Kc=class extends an{constructor(){super(64,32,8,!1),this.A=ur[0]|0,this.B=ur[1]|0,this.C=ur[2]|0,this.D=ur[3]|0,this.E=ur[4]|0,this.F=ur[5]|0,this.G=ur[6]|0,this.H=ur[7]|0}get(){let{A:e,B:t,C:n,D:s,E:o,F:i,G:a,H:c}=this;return[e,t,n,s,o,i,a,c]}set(e,t,n,s,o,i,a,c){this.A=e|0,this.B=t|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(e,t){for(let f=0;f<16;f++,t+=4)lr[f]=e.getUint32(t,!1);for(let f=16;f<64;f++){let m=lr[f-15],g=lr[f-2],d=at(m,7)^at(m,18)^m>>>3,h=at(g,17)^at(g,19)^g>>>10;lr[f]=h+lr[f-7]+d+lr[f-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){let m=at(a,6)^at(a,11)^at(a,25),g=l+m+qf(a,c,u)+uw[f]+lr[f]|0,h=(at(n,2)^at(n,13)^at(n,22))+Wf(n,s,o)|0;l=u,u=c,c=a,a=i+g|0,i=o,o=s,s=n,n=g+h|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,l=l+this.H|0,this.set(n,s,o,i,a,c,u,l)}roundClean(){lr.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var wn=bo(()=>new Kc);function lw(r){let e=Yn(r);Xe(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:t,Fp:n,a:s}=e;if(t){if(!n.eql(s,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof t!="object"||typeof t.beta!="bigint"||typeof t.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}var{bytesToNumberBE:fw,hexToBytes:hw}=xo,Lr={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(r){let{Err:e}=Lr;if(r.length<2||r[0]!==2)throw new e("Invalid signature integer tag");let t=r[1],n=r.subarray(2,t+2);if(!t||n.length!==t)throw new e("Invalid signature integer: wrong length");if(n[0]&128)throw new e("Invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new e("Invalid signature integer: unnecessary leading zero");return{d:fw(n),l:r.subarray(t+2)}},toSig(r){let{Err:e}=Lr,t=typeof r=="string"?hw(r):r;un(t);let n=t.length;if(n<2||t[0]!=48)throw new e("Invalid signature tag");if(t[1]!==n-2)throw new e("Invalid signature: incorrect length");let{d:s,l:o}=Lr._parseInt(t.subarray(2)),{d:i,l:a}=Lr._parseInt(o);if(a.length)throw new e("Invalid signature: left bytes after parsing");return{r:s,s:i}},hexFromSig(r){let e=u=>Number.parseInt(u[0],16)&8?"00"+u:u,t=u=>{let l=u.toString(16);return l.length&1?`0${l}`:l},n=e(t(r.s)),s=e(t(r.r)),o=n.length/2,i=s.length/2,a=t(o),c=t(i);return`30${t(i+o+4)}02${c}${s}02${a}${n}`}},$t=BigInt(0),Qe=BigInt(1),WD=BigInt(2),ud=BigInt(3),zD=BigInt(4);function dw(r){let e=lw(r),{Fp:t}=e,n=e.toBytes||((d,h,p)=>{let y=h.toAffine();return Lt(Uint8Array.from([4]),t.toBytes(y.x),t.toBytes(y.y))}),s=e.fromBytes||(d=>{let h=d.subarray(1),p=t.fromBytes(h.subarray(0,t.BYTES)),y=t.fromBytes(h.subarray(t.BYTES,2*t.BYTES));return{x:p,y}});function o(d){let{a:h,b:p}=e,y=t.sqr(d),x=t.mul(y,d);return t.add(t.add(x,t.mul(d,h)),p)}if(!t.eql(t.sqr(e.Gy),o(e.Gx)))throw new Error("bad generator point: equation left != right");function i(d){return typeof d=="bigint"&&$t<d&&d<e.n}function a(d){if(!i(d))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(d){let{allowedPrivateKeyLengths:h,nByteLength:p,wrapPrivateKey:y,n:x}=e;if(h&&typeof d!="bigint"){if(rr(d)&&(d=_t(d)),typeof d!="string"||!h.includes(d.length))throw new Error("Invalid key");d=d.padStart(p*2,"0")}let b;try{b=typeof d=="bigint"?d:Rt(ce("private key",d,p))}catch{throw new Error(`private key must be ${p} bytes, hex or bigint, not ${typeof d}`)}return y&&(b=te(b,x)),a(b),b}let u=new Map;function l(d){if(!(d instanceof f))throw new Error("ProjectivePoint expected")}class f{constructor(h,p,y){if(this.px=h,this.py=p,this.pz=y,h==null||!t.isValid(h))throw new Error("x required");if(p==null||!t.isValid(p))throw new Error("y required");if(y==null||!t.isValid(y))throw new Error("z required")}static fromAffine(h){let{x:p,y}=h||{};if(!h||!t.isValid(p)||!t.isValid(y))throw new Error("invalid affine point");if(h instanceof f)throw new Error("projective point not allowed");let x=b=>t.eql(b,t.ZERO);return x(p)&&x(y)?f.ZERO:new f(p,y,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let p=t.invertBatch(h.map(y=>y.pz));return h.map((y,x)=>y.toAffine(p[x])).map(f.fromAffine)}static fromHex(h){let p=f.fromAffine(s(ce("pointHex",h)));return p.assertValidity(),p}static fromPrivateKey(h){return f.BASE.multiply(c(h))}_setWindowSize(h){this._WINDOW_SIZE=h,u.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!t.is0(this.py))return;throw new Error("bad point: ZERO")}let{x:h,y:p}=this.toAffine();if(!t.isValid(h)||!t.isValid(p))throw new Error("bad point: x or y not FE");let y=t.sqr(p),x=o(h);if(!t.eql(y,x))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:h}=this.toAffine();if(t.isOdd)return!t.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){l(h);let{px:p,py:y,pz:x}=this,{px:b,py:v,pz:E}=h,A=t.eql(t.mul(p,E),t.mul(b,x)),S=t.eql(t.mul(y,E),t.mul(v,x));return A&&S}negate(){return new f(this.px,t.neg(this.py),this.pz)}double(){let{a:h,b:p}=e,y=t.mul(p,ud),{px:x,py:b,pz:v}=this,E=t.ZERO,A=t.ZERO,S=t.ZERO,D=t.mul(x,x),_=t.mul(b,b),O=t.mul(v,v),R=t.mul(x,b);return R=t.add(R,R),S=t.mul(x,v),S=t.add(S,S),E=t.mul(h,S),A=t.mul(y,O),A=t.add(E,A),E=t.sub(_,A),A=t.add(_,A),A=t.mul(E,A),E=t.mul(R,E),S=t.mul(y,S),O=t.mul(h,O),R=t.sub(D,O),R=t.mul(h,R),R=t.add(R,S),S=t.add(D,D),D=t.add(S,D),D=t.add(D,O),D=t.mul(D,R),A=t.add(A,D),O=t.mul(b,v),O=t.add(O,O),D=t.mul(O,R),E=t.sub(E,D),S=t.mul(O,_),S=t.add(S,S),S=t.add(S,S),new f(E,A,S)}add(h){l(h);let{px:p,py:y,pz:x}=this,{px:b,py:v,pz:E}=h,A=t.ZERO,S=t.ZERO,D=t.ZERO,_=e.a,O=t.mul(e.b,ud),R=t.mul(p,b),H=t.mul(y,v),V=t.mul(x,E),G=t.add(p,y),B=t.add(b,v);G=t.mul(G,B),B=t.add(R,H),G=t.sub(G,B),B=t.add(p,x);let I=t.add(b,E);return B=t.mul(B,I),I=t.add(R,V),B=t.sub(B,I),I=t.add(y,x),A=t.add(v,E),I=t.mul(I,A),A=t.add(H,V),I=t.sub(I,A),D=t.mul(_,B),A=t.mul(O,V),D=t.add(A,D),A=t.sub(H,D),D=t.add(H,D),S=t.mul(A,D),H=t.add(R,R),H=t.add(H,R),V=t.mul(_,V),B=t.mul(O,B),H=t.add(H,V),V=t.sub(R,V),V=t.mul(_,V),B=t.add(B,V),R=t.mul(H,B),S=t.add(S,R),R=t.mul(I,B),A=t.mul(G,A),A=t.sub(A,R),R=t.mul(G,H),D=t.mul(I,D),D=t.add(D,R),new f(A,S,D)}subtract(h){return this.add(h.negate())}is0(){return this.equals(f.ZERO)}wNAF(h){return g.wNAFCached(this,u,h,p=>{let y=t.invertBatch(p.map(x=>x.pz));return p.map((x,b)=>x.toAffine(y[b])).map(f.fromAffine)})}multiplyUnsafe(h){let p=f.ZERO;if(h===$t)return p;if(a(h),h===Qe)return this;let{endo:y}=e;if(!y)return g.unsafeLadder(this,h);let{k1neg:x,k1:b,k2neg:v,k2:E}=y.splitScalar(h),A=p,S=p,D=this;for(;b>$t||E>$t;)b&Qe&&(A=A.add(D)),E&Qe&&(S=S.add(D)),D=D.double(),b>>=Qe,E>>=Qe;return x&&(A=A.negate()),v&&(S=S.negate()),S=new f(t.mul(S.px,y.beta),S.py,S.pz),A.add(S)}multiply(h){a(h);let p=h,y,x,{endo:b}=e;if(b){let{k1neg:v,k1:E,k2neg:A,k2:S}=b.splitScalar(p),{p:D,f:_}=this.wNAF(E),{p:O,f:R}=this.wNAF(S);D=g.constTimeNegate(v,D),O=g.constTimeNegate(A,O),O=new f(t.mul(O.px,b.beta),O.py,O.pz),y=D.add(O),x=_.add(R)}else{let{p:v,f:E}=this.wNAF(p);y=v,x=E}return f.normalizeZ([y,x])[0]}multiplyAndAddUnsafe(h,p,y){let x=f.BASE,b=(E,A)=>A===$t||A===Qe||!E.equals(x)?E.multiplyUnsafe(A):E.multiply(A),v=b(this,p).add(b(h,y));return v.is0()?void 0:v}toAffine(h){let{px:p,py:y,pz:x}=this,b=this.is0();h==null&&(h=b?t.ONE:t.inv(x));let v=t.mul(p,h),E=t.mul(y,h),A=t.mul(x,h);if(b)return{x:t.ZERO,y:t.ZERO};if(!t.eql(A,t.ONE))throw new Error("invZ was invalid");return{x:v,y:E}}isTorsionFree(){let{h,isTorsionFree:p}=e;if(h===Qe)return!0;if(p)return p(f,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:p}=e;return h===Qe?this:p?p(f,this):this.multiplyUnsafe(e.h)}toRawBytes(h=!0){return this.assertValidity(),n(f,this,h)}toHex(h=!0){return _t(this.toRawBytes(h))}}f.BASE=new f(e.Gx,e.Gy,t.ONE),f.ZERO=new f(t.ZERO,t.ONE,t.ZERO);let m=e.nBitLength,g=Ao(f,e.endo?Math.ceil(m/2):m);return{CURVE:e,ProjectivePoint:f,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:i}}function pw(r){let e=Yn(r);return Xe(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function ld(r){let e=pw(r),{Fp:t,n}=e,s=t.BYTES+1,o=2*t.BYTES+1;function i(B){return $t<B&&B<t.ORDER}function a(B){return te(B,n)}function c(B){return Eo(B,n)}let{ProjectivePoint:u,normPrivateKeyToScalar:l,weierstrassEquation:f,isWithinCurveOrder:m}=dw({...e,toBytes(B,I,P){let k=I.toAffine(),w=t.toBytes(k.x),C=Lt;return P?C(Uint8Array.from([I.hasEvenY()?2:3]),w):C(Uint8Array.from([4]),w,t.toBytes(k.y))},fromBytes(B){let I=B.length,P=B[0],k=B.subarray(1);if(I===s&&(P===2||P===3)){let w=Rt(k);if(!i(w))throw new Error("Point is not on curve");let C=f(w),T;try{T=t.sqrt(C)}catch(q){let Y=q instanceof Error?": "+q.message:"";throw new Error("Point is not on curve"+Y)}let N=(T&Qe)===Qe;return(P&1)===1!==N&&(T=t.neg(T)),{x:w,y:T}}else if(I===o&&P===4){let w=t.fromBytes(k.subarray(0,t.BYTES)),C=t.fromBytes(k.subarray(t.BYTES,2*t.BYTES));return{x:w,y:C}}else throw new Error(`Point of length ${I} was invalid. Expected ${s} compressed bytes or ${o} uncompressed bytes`)}}),g=B=>_t(nr(B,e.nByteLength));function d(B){let I=n>>Qe;return B>I}function h(B){return d(B)?a(-B):B}let p=(B,I,P)=>Rt(B.slice(I,P));class y{constructor(I,P,k){this.r=I,this.s=P,this.recovery=k,this.assertValidity()}static fromCompact(I){let P=e.nByteLength;return I=ce("compactSignature",I,P*2),new y(p(I,0,P),p(I,P,2*P))}static fromDER(I){let{r:P,s:k}=Lr.toSig(ce("DER",I));return new y(P,k)}assertValidity(){if(!m(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!m(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(I){return new y(this.r,this.s,I)}recoverPublicKey(I){let{r:P,s:k,recovery:w}=this,C=S(ce("msgHash",I));if(w==null||![0,1,2,3].includes(w))throw new Error("recovery id invalid");let T=w===2||w===3?P+e.n:P;if(T>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let N=w&1?"03":"02",$=u.fromHex(N+g(T)),q=c(T),Y=a(-C*q),W=a(k*q),j=u.BASE.multiplyAndAddUnsafe($,Y,W);if(!j)throw new Error("point at infinify");return j.assertValidity(),j}hasHighS(){return d(this.s)}normalizeS(){return this.hasHighS()?new y(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return Ir(this.toDERHex())}toDERHex(){return Lr.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Ir(this.toCompactHex())}toCompactHex(){return g(this.r)+g(this.s)}}let x={isValidPrivateKey(B){try{return l(B),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let B=Dc(e.n);return rh(e.randomBytes(B),e.n)},precompute(B=8,I=u.BASE){return I._setWindowSize(B),I.multiply(BigInt(3)),I}};function b(B,I=!0){return u.fromPrivateKey(B).toRawBytes(I)}function v(B){let I=rr(B),P=typeof B=="string",k=(I||P)&&B.length;return I?k===s||k===o:P?k===2*s||k===2*o:B instanceof u}function E(B,I,P=!0){if(v(B))throw new Error("first arg must be private key");if(!v(I))throw new Error("second arg must be public key");return u.fromHex(I).multiply(l(B)).toRawBytes(P)}let A=e.bits2int||function(B){let I=Rt(B),P=B.length*8-e.nBitLength;return P>0?I>>BigInt(P):I},S=e.bits2int_modN||function(B){return a(A(B))},D=jn(e.nBitLength);function _(B){if(typeof B!="bigint")throw new Error("bigint expected");if(!($t<=B&&B<D))throw new Error(`bigint expected < 2^${e.nBitLength}`);return nr(B,e.nByteLength)}function O(B,I,P=R){if(["recovered","canonical"].some(oe=>oe in P))throw new Error("sign() legacy options not supported");let{hash:k,randomBytes:w}=e,{lowS:C,prehash:T,extraEntropy:N}=P;C==null&&(C=!0),B=ce("msgHash",B),T&&(B=ce("prehashed msgHash",k(B)));let $=S(B),q=l(I),Y=[_(q),_($)];if(N!=null&&N!==!1){let oe=N===!0?w(t.BYTES):N;Y.push(ce("extraEntropy",oe))}let W=Lt(...Y),j=$;function ae(oe){let Ce=A(oe);if(!m(Ce))return;let Ie=c(Ce),ve=u.BASE.multiply(Ce).toAffine(),Ue=a(ve.x);if(Ue===$t)return;let Bt=a(Ie*a(j+Ue*q));if(Bt===$t)return;let dr=(ve.x===Ue?0:2)|Number(ve.y&Qe),Ln=Bt;return C&&d(Bt)&&(Ln=h(Bt),dr^=1),new y(Ue,Ln,dr)}return{seed:W,k2sig:ae}}let R={lowS:e.lowS,prehash:!1},H={lowS:e.lowS,prehash:!1};function V(B,I,P=R){let{seed:k,k2sig:w}=O(B,I,P),C=e;return wc(C.hash.outputLen,C.nByteLength,C.hmac)(k,w)}u.BASE._setWindowSize(8);function G(B,I,P,k=H){let w=B;if(I=ce("msgHash",I),P=ce("publicKey",P),"strict"in k)throw new Error("options.strict was renamed to lowS");let{lowS:C,prehash:T}=k,N,$;try{if(typeof w=="string"||rr(w))try{N=y.fromDER(w)}catch(ve){if(!(ve instanceof Lr.Err))throw ve;N=y.fromCompact(w)}else if(typeof w=="object"&&typeof w.r=="bigint"&&typeof w.s=="bigint"){let{r:ve,s:Ue}=w;N=new y(ve,Ue)}else throw new Error("PARSE");$=u.fromHex(P)}catch(ve){if(ve.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(C&&N.hasHighS())return!1;T&&(I=e.hash(I));let{r:q,s:Y}=N,W=S(I),j=c(Y),ae=a(W*j),oe=a(q*j),Ce=u.BASE.multiplyAndAddUnsafe($,ae,oe)?.toAffine();return Ce?a(Ce.x)===q:!1}return{CURVE:e,getPublicKey:b,getSharedSecret:E,sign:V,verify:G,ProjectivePoint:u,Signature:y,utils:x}}function mw(r){return{hash:r,hmac:(e,...t)=>sr(r,e,go(...t)),randomBytes:Cr}}function fd(r,e){let t=n=>ld({...r,...mw(n)});return Object.freeze({...t(e),create:t})}var pd=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),hd=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),gw=BigInt(1),$c=BigInt(2),dd=(r,e)=>(r+e/$c)/e;function bw(r){let e=pd,t=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%e,l=u*u*r%e,f=ue(l,t,e)*l%e,m=ue(f,t,e)*l%e,g=ue(m,$c,e)*u%e,d=ue(g,s,e)*g%e,h=ue(d,o,e)*d%e,p=ue(h,a,e)*h%e,y=ue(p,c,e)*p%e,x=ue(y,a,e)*h%e,b=ue(x,t,e)*l%e,v=ue(b,i,e)*d%e,E=ue(v,n,e)*u%e,A=ue(E,$c,e);if(!qc.eql(qc.sqr(A),r))throw new Error("Cannot find square root");return A}var qc=vo(pd,void 0,void 0,{sqrt:bw}),dt=fd({a:BigInt(0),b:BigInt(7),Fp:qc,n:hd,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=hd,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-gw*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=t,i=BigInt("0x100000000000000000000000000000000"),a=dd(o*r,e),c=dd(-n*r,e),u=te(r-a*t-c*s,e),l=te(-a*n-c*o,e),f=u>i,m=l>i;if(f&&(u=e-u),m&&(l=e-l),u>i||l>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:u,k2neg:m,k2:l}}}},wn),tB=BigInt(0);var rB=dt.ProjectivePoint;function md(){return dt.utils.randomPrivateKey()}function gd(r,e){let t=Te.digest(e instanceof Uint8Array?e:e.subarray());if(Ze(t))return t.then(({digest:n})=>dt.sign(n,r).toDERRawBytes()).catch(n=>{throw new L(String(n),"ERR_INVALID_INPUT")});try{return dt.sign(t.digest,r).toDERRawBytes()}catch(n){throw new L(String(n),"ERR_INVALID_INPUT")}}function bd(r,e,t){let n=Te.digest(t instanceof Uint8Array?t:t.subarray());if(Ze(n))return n.then(({digest:s})=>dt.verify(e,s,r)).catch(s=>{throw new L(String(s),"ERR_INVALID_INPUT")});try{return dt.verify(e,n.digest,r)}catch(s){throw new L(String(s),"ERR_INVALID_INPUT")}}function yd(r){return dt.ProjectivePoint.fromHex(r).toRawBytes(!0)}function wd(r){try{dt.getPublicKey(r,!0)}catch(e){throw new L(String(e),"ERR_INVALID_PRIVATE_KEY")}}function Wc(r){try{dt.ProjectivePoint.fromHex(r)}catch(e){throw new L(String(e),"ERR_INVALID_PUBLIC_KEY")}}function xd(r){try{return dt.getPublicKey(r,!0)}catch(e){throw new L(String(e),"ERR_INVALID_PRIVATE_KEY")}}var fs=class{_key;constructor(e){Wc(e),this._key=e}verify(e,t){return bd(this._key,t,e)}marshal(){return yd(this._key)}get bytes(){return wt.encode({Type:he.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return Ae(this.bytes,e.bytes)}async hash(){let e=Te.digest(this.bytes),t;return Ze(e)?{bytes:t}=await e:t=e.bytes,t}},hs=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t??xd(e),wd(this._key),Wc(this._publicKey)}sign(e){return gd(this._key,e)}get public(){return new fs(this._publicKey)}marshal(){return this._key}get bytes(){return xt.encode({Type:he.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return Ae(this.bytes,e.bytes)}hash(){let e=Te.digest(this.bytes);return Ze(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return z(e,"base58btc")}async export(e,t="libp2p-key"){if(t==="libp2p-key")return hn(this.bytes,e);throw new L(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function ww(r){return new hs(r)}function xw(r){return new fs(r)}async function Ew(){let r=md();return new hs(r)}var Ur={rsa:Hc,ed25519:_c,secp256k1:zc};function Ed(r){let e=Object.keys(Ur).join(" / ");return new L(`invalid or unsupported key type ${r}. Must be ${e}`,"ERR_UNSUPPORTED_KEY_TYPE")}function vd(r){let e=wt.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case he.RSA:return Ur.rsa.unmarshalRsaPublicKey(t);case he.Ed25519:return Ur.ed25519.unmarshalEd25519PublicKey(t);case he.Secp256k1:return Ur.secp256k1.unmarshalSecp256k1PublicKey(t);default:throw Ed(e.Type??"unknown")}}async function Gc(r){let e=xt.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case he.RSA:return Ur.rsa.unmarshalRsaPrivateKey(t);case he.Ed25519:return Ur.ed25519.unmarshalEd25519PrivateKey(t);case he.Secp256k1:return Ur.secp256k1.unmarshalSecp256k1PrivateKey(t);default:throw Ed(e.Type??"RSA")}}function jc(){let r=pe(),e=!1;return{sink:async t=>{if(e)throw new Error("already piped");e=!0,r.resolve(t)},source:async function*(){yield*await r.promise}()}}function Ad(){let r=jc(),e=jc();return[{source:r.source,sink:e.sink},{source:e.source,sink:r.sink}]}function vw(r){return r[Symbol.asyncIterator]!=null}function Aw(...r){let e=[];for(let t of r)vw(t)||e.push(t);return e.length===r.length?function*(){for(let t of e)yield*t}():async function*(){let t=Zt({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let s of n)t.push(s)})),t.end()}catch(n){t.end(n)}}),yield*t}()}var Dd=Aw;function Bd(r,...e){if(r==null)throw new Error("Empty pipeline");if(Yc(r)){let n=r;r=()=>n.source}else if(kd(r)||Sd(r)){let n=r;r=()=>n}let t=[r,...e];if(t.length>1&&Yc(t[t.length-1])&&(t[t.length-1]=t[t.length-1].sink),t.length>2)for(let n=1;n<t.length-1;n++)Yc(t[n])&&(t[n]=Bw(t[n]));return Dw(...t)}var Dw=(...r)=>{let e;for(;r.length>0;)e=r.shift()(e);return e},Sd=r=>r?.[Symbol.asyncIterator]!=null,kd=r=>r?.[Symbol.iterator]!=null,Yc=r=>r==null?!1:r.sink!=null&&r.source!=null,Bw=r=>e=>{let t=r.sink(e);if(t?.then!=null){let n=Zt({objectMode:!0});t.then(()=>{n.end()},i=>{n.end(i)});let s,o=r.source;if(Sd(o))s=async function*(){yield*o,n.end()};else if(kd(o))s=function*(){yield*o,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return Dd(n,s())}return r.source};var xn=!!globalThis.process?.env?.DUMP_SESSION_KEYS;var qt=r=>new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4));function Cd(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var Id=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Sw=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Sw)throw new Error("Non little-endian hardware is not supported");function yi(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function wi(r){if(typeof r=="string")r=yi(r);else if(Cd(r))r=r.slice();else throw new Error(`expected Uint8Array, got ${typeof r}`);return r}var kw=r=>Object.prototype.toString.call(r)==="[object Object]"&&r.constructor===Object;function Td(r,e){if(e!==void 0&&(typeof e!="object"||!kw(e)))throw new Error("options must be object or undefined");return Object.assign(r,e)}function Or(r,e){if(!Cd(r))throw new Error("Uint8Array expected");if(typeof e=="number"&&r.length!==e)throw new Error(`Uint8Array length ${e} expected`)}function _d(r,e){if(r.length!==e.length)return!1;let t=0;for(let n=0;n<r.length;n++)t|=r[n]^e[n];return t===0}var Zc=(r,e)=>(Object.assign(e,r),e);function Xc(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let s=BigInt(32),o=BigInt(4294967295),i=Number(t>>s&o),a=Number(t&o),c=n?4:0,u=n?0:4;r.setUint32(e+c,i,n),r.setUint32(e+u,a,n)}function xi(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`wrong positive integer: ${r}`)}function Jc(r){if(typeof r!="boolean")throw new Error(`boolean expected, not ${r}`)}function Cw(r){return r!=null&&typeof r=="object"&&(r instanceof Uint8Array||r.constructor.name==="Uint8Array")}function En(r,...e){if(!Cw(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${r.length}`)}function Qc(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function Rd(r,e){En(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var Ne=(r,e)=>r[e++]&255|(r[e++]&255)<<8,eu=class{constructor(e){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,e=wi(e),Or(e,32);let t=Ne(e,0),n=Ne(e,2),s=Ne(e,4),o=Ne(e,6),i=Ne(e,8),a=Ne(e,10),c=Ne(e,12),u=Ne(e,14);this.r[0]=t&8191,this.r[1]=(t>>>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 l=0;l<8;l++)this.pad[l]=Ne(e,16+2*l)}process(e,t,n=!1){let s=n?0:2048,{h:o,r:i}=this,a=i[0],c=i[1],u=i[2],l=i[3],f=i[4],m=i[5],g=i[6],d=i[7],h=i[8],p=i[9],y=Ne(e,t+0),x=Ne(e,t+2),b=Ne(e,t+4),v=Ne(e,t+6),E=Ne(e,t+8),A=Ne(e,t+10),S=Ne(e,t+12),D=Ne(e,t+14),_=o[0]+(y&8191),O=o[1]+((y>>>13|x<<3)&8191),R=o[2]+((x>>>10|b<<6)&8191),H=o[3]+((b>>>7|v<<9)&8191),V=o[4]+((v>>>4|E<<12)&8191),G=o[5]+(E>>>1&8191),B=o[6]+((E>>>14|A<<2)&8191),I=o[7]+((A>>>11|S<<5)&8191),P=o[8]+((S>>>8|D<<8)&8191),k=o[9]+(D>>>5|s),w=0,C=w+_*a+O*(5*p)+R*(5*h)+H*(5*d)+V*(5*g);w=C>>>13,C&=8191,C+=G*(5*m)+B*(5*f)+I*(5*l)+P*(5*u)+k*(5*c),w+=C>>>13,C&=8191;let T=w+_*c+O*a+R*(5*p)+H*(5*h)+V*(5*d);w=T>>>13,T&=8191,T+=G*(5*g)+B*(5*m)+I*(5*f)+P*(5*l)+k*(5*u),w+=T>>>13,T&=8191;let N=w+_*u+O*c+R*a+H*(5*p)+V*(5*h);w=N>>>13,N&=8191,N+=G*(5*d)+B*(5*g)+I*(5*m)+P*(5*f)+k*(5*l),w+=N>>>13,N&=8191;let $=w+_*l+O*u+R*c+H*a+V*(5*p);w=$>>>13,$&=8191,$+=G*(5*h)+B*(5*d)+I*(5*g)+P*(5*m)+k*(5*f),w+=$>>>13,$&=8191;let q=w+_*f+O*l+R*u+H*c+V*a;w=q>>>13,q&=8191,q+=G*(5*p)+B*(5*h)+I*(5*d)+P*(5*g)+k*(5*m),w+=q>>>13,q&=8191;let Y=w+_*m+O*f+R*l+H*u+V*c;w=Y>>>13,Y&=8191,Y+=G*a+B*(5*p)+I*(5*h)+P*(5*d)+k*(5*g),w+=Y>>>13,Y&=8191;let W=w+_*g+O*m+R*f+H*l+V*u;w=W>>>13,W&=8191,W+=G*c+B*a+I*(5*p)+P*(5*h)+k*(5*d),w+=W>>>13,W&=8191;let j=w+_*d+O*g+R*m+H*f+V*l;w=j>>>13,j&=8191,j+=G*u+B*c+I*a+P*(5*p)+k*(5*h),w+=j>>>13,j&=8191;let ae=w+_*h+O*d+R*g+H*m+V*f;w=ae>>>13,ae&=8191,ae+=G*l+B*u+I*c+P*a+k*(5*p),w+=ae>>>13,ae&=8191;let oe=w+_*p+O*h+R*d+H*g+V*m;w=oe>>>13,oe&=8191,oe+=G*f+B*l+I*u+P*c+k*a,w+=oe>>>13,oe&=8191,w=(w<<2)+w|0,w=w+C|0,C=w&8191,w=w>>>13,T+=w,o[0]=C,o[1]=T,o[2]=N,o[3]=$,o[4]=q,o[5]=Y,o[6]=W,o[7]=j,o[8]=ae,o[9]=oe}finalize(){let{h:e,pad:t}=this,n=new Uint16Array(10),s=e[1]>>>13;e[1]&=8191;for(let a=2;a<10;a++)e[a]+=s,s=e[a]>>>13,e[a]&=8191;e[0]+=s*5,s=e[0]>>>13,e[0]&=8191,e[1]+=s,s=e[1]>>>13,e[1]&=8191,e[2]+=s,n[0]=e[0]+5,s=n[0]>>>13,n[0]&=8191;for(let a=1;a<10;a++)n[a]=e[a]+s,s=n[a]>>>13,n[a]&=8191;n[9]-=8192;let o=(s^1)-1;for(let a=0;a<10;a++)n[a]&=o;o=~o;for(let a=0;a<10;a++)e[a]=e[a]&o|n[a];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let i=e[0]+t[0];e[0]=i&65535;for(let a=1;a<8;a++)i=(e[a]+t[a]|0)+(i>>>16)|0,e[a]=i&65535}update(e){Qc(this);let{buffer:t,blockLen:n}=this;e=wi(e);let s=e.length;for(let o=0;o<s;){let i=Math.min(n-this.pos,s-o);if(i===n){for(;n<=s-o;o+=n)this.process(e,o);continue}t.set(e.subarray(o,o+i),this.pos),this.pos+=i,o+=i,this.pos===n&&(this.process(t,0,!1),this.pos=0)}return this}destroy(){this.h.fill(0),this.r.fill(0),this.buffer.fill(0),this.pad.fill(0)}digestInto(e){Qc(this),Rd(e,this),this.finished=!0;let{buffer:t,h:n}=this,{pos:s}=this;if(s){for(t[s++]=1;s<16;s++)t[s]=0;this.process(t,0,!0)}this.finalize();let o=0;for(let i=0;i<8;i++)e[o++]=n[i]>>>0,e[o++]=n[i]>>>8;return e}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}};function Iw(r){let e=(n,s)=>r(s).update(wi(n)).digest(),t=r(new Uint8Array(32));return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=n=>r(n),e}var Nd=Iw(r=>new eu(r));var Tw=yi("expand 16-byte k"),_w=yi("expand 32-byte k"),Rw=qt(Tw),Nw=qt(_w);function F(r,e){return r<<e|r>>>32-e}function tu(r){return r.byteOffset%4===0}var Ei=64,Lw=16,Ud=2**32-1,Ld=new Uint32Array;function Uw(r,e,t,n,s,o,i,a){let c=s.length,u=new Uint8Array(Ei),l=qt(u),f=tu(s)&&tu(o),m=f?qt(s):Ld,g=f?qt(o):Ld;for(let d=0;d<c;i++){if(r(e,t,n,l,i,a),i>=Ud)throw new Error("arx: counter overflow");let h=Math.min(Ei,c-d);if(f&&h===Ei){let p=d/4;if(d%4!==0)throw new Error("arx: invalid block position");for(let y=0,x;y<Lw;y++)x=p+y,g[x]=m[x]^l[y];d+=Ei;continue}for(let p=0,y;p<h;p++)y=d+p,o[y]=s[y]^u[p];d+=h}}function ru(r,e){let{allowShortKeys:t,extendNonceFn:n,counterLength:s,counterRight:o,rounds:i}=Td({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof r!="function")throw new Error("core must be a function");return xi(s),xi(i),Jc(o),Jc(t),(a,c,u,l,f=0)=>{En(a),En(c),En(u);let m=u.length;if(l||(l=new Uint8Array(m)),En(l),xi(f),f<0||f>=Ud)throw new Error("arx: counter overflow");if(l.length<m)throw new Error(`arx: output (${l.length}) is shorter than data (${m})`);let g=[],d=a.length,h,p;if(d===32)h=a.slice(),g.push(h),p=Nw;else if(d===16&&t)h=new Uint8Array(32),h.set(a),h.set(a,16),p=Rw,g.push(h);else throw new Error(`arx: invalid 32-byte key, got length=${d}`);tu(c)||(c=c.slice(),g.push(c));let y=qt(h);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(p,y,qt(c.subarray(0,16)),y),c=c.subarray(16)}let x=16-s;if(x!==c.length)throw new Error(`arx: nonce must be ${x} or 16 bytes`);if(x!==12){let v=new Uint8Array(12);v.set(c,o?0:12-c.length),c=v,g.push(c)}let b=qt(c);for(Uw(r,p,y,b,u,l,f,i);g.length>0;)g.pop().fill(0);return l}}function Md(r,e,t,n,s,o=20){let i=r[0],a=r[1],c=r[2],u=r[3],l=e[0],f=e[1],m=e[2],g=e[3],d=e[4],h=e[5],p=e[6],y=e[7],x=s,b=t[0],v=t[1],E=t[2],A=i,S=a,D=c,_=u,O=l,R=f,H=m,V=g,G=d,B=h,I=p,P=y,k=x,w=b,C=v,T=E;for(let $=0;$<o;$+=2)A=A+O|0,k=F(k^A,16),G=G+k|0,O=F(O^G,12),A=A+O|0,k=F(k^A,8),G=G+k|0,O=F(O^G,7),S=S+R|0,w=F(w^S,16),B=B+w|0,R=F(R^B,12),S=S+R|0,w=F(w^S,8),B=B+w|0,R=F(R^B,7),D=D+H|0,C=F(C^D,16),I=I+C|0,H=F(H^I,12),D=D+H|0,C=F(C^D,8),I=I+C|0,H=F(H^I,7),_=_+V|0,T=F(T^_,16),P=P+T|0,V=F(V^P,12),_=_+V|0,T=F(T^_,8),P=P+T|0,V=F(V^P,7),A=A+R|0,T=F(T^A,16),I=I+T|0,R=F(R^I,12),A=A+R|0,T=F(T^A,8),I=I+T|0,R=F(R^I,7),S=S+H|0,k=F(k^S,16),P=P+k|0,H=F(H^P,12),S=S+H|0,k=F(k^S,8),P=P+k|0,H=F(H^P,7),D=D+V|0,w=F(w^D,16),G=G+w|0,V=F(V^G,12),D=D+V|0,w=F(w^D,8),G=G+w|0,V=F(V^G,7),_=_+O|0,C=F(C^_,16),B=B+C|0,O=F(O^B,12),_=_+O|0,C=F(C^_,8),B=B+C|0,O=F(O^B,7);let N=0;n[N++]=i+A|0,n[N++]=a+S|0,n[N++]=c+D|0,n[N++]=u+_|0,n[N++]=l+O|0,n[N++]=f+R|0,n[N++]=m+H|0,n[N++]=g+V|0,n[N++]=d+G|0,n[N++]=h+B|0,n[N++]=p+I|0,n[N++]=y+P|0,n[N++]=x+k|0,n[N++]=b+w|0,n[N++]=v+C|0,n[N++]=E+T|0}function Ow(r,e,t,n){let s=r[0],o=r[1],i=r[2],a=r[3],c=e[0],u=e[1],l=e[2],f=e[3],m=e[4],g=e[5],d=e[6],h=e[7],p=t[0],y=t[1],x=t[2],b=t[3];for(let E=0;E<20;E+=2)s=s+c|0,p=F(p^s,16),m=m+p|0,c=F(c^m,12),s=s+c|0,p=F(p^s,8),m=m+p|0,c=F(c^m,7),o=o+u|0,y=F(y^o,16),g=g+y|0,u=F(u^g,12),o=o+u|0,y=F(y^o,8),g=g+y|0,u=F(u^g,7),i=i+l|0,x=F(x^i,16),d=d+x|0,l=F(l^d,12),i=i+l|0,x=F(x^i,8),d=d+x|0,l=F(l^d,7),a=a+f|0,b=F(b^a,16),h=h+b|0,f=F(f^h,12),a=a+f|0,b=F(b^a,8),h=h+b|0,f=F(f^h,7),s=s+u|0,b=F(b^s,16),d=d+b|0,u=F(u^d,12),s=s+u|0,b=F(b^s,8),d=d+b|0,u=F(u^d,7),o=o+l|0,p=F(p^o,16),h=h+p|0,l=F(l^h,12),o=o+l|0,p=F(p^o,8),h=h+p|0,l=F(l^h,7),i=i+f|0,y=F(y^i,16),m=m+y|0,f=F(f^m,12),i=i+f|0,y=F(y^i,8),m=m+y|0,f=F(f^m,7),a=a+c|0,x=F(x^a,16),g=g+x|0,c=F(c^g,12),a=a+c|0,x=F(x^a,8),g=g+x|0,c=F(c^g,7);let v=0;n[v++]=s,n[v++]=o,n[v++]=i,n[v++]=a,n[v++]=p,n[v++]=y,n[v++]=x,n[v++]=b}var Pw=ru(Md,{counterRight:!1,counterLength:4,allowShortKeys:!1}),Mw=ru(Md,{counterRight:!1,counterLength:8,extendNonceFn:Ow,allowShortKeys:!1});var Fw=new Uint8Array(16),Od=(r,e)=>{r.update(e);let t=e.length%16;t&&r.update(Fw.subarray(t))},Vw=new Uint8Array(32);function Pd(r,e,t,n,s){let o=r(e,t,Vw),i=Nd.create(o);s&&Od(i,s),Od(i,n);let a=new Uint8Array(16),c=Id(a);Xc(c,0,BigInt(s?s.length:0),!0),Xc(c,8,BigInt(n.length),!0),i.update(a);let u=i.digest();return o.fill(0),u}var Fd=r=>(e,t,n)=>(Or(e,32),Or(t),{encrypt:(o,i)=>{let a=o.length,c=a+16;i?Or(i,c):i=new Uint8Array(c),r(e,t,o,i,1);let u=Pd(r,e,t,i.subarray(0,-16),n);return i.set(u,a),i},decrypt:(o,i)=>{let a=o.length,c=a-16;if(a<16)throw new Error("encrypted data must be at least 16 bytes");i?Or(i,c):i=new Uint8Array(c);let u=o.subarray(0,-16),l=o.subarray(-16),f=Pd(r,e,t,u,n);if(!_d(l,f))throw new Error("invalid tag");return r(e,t,u,i,1),i}}),nu=Zc({blockSize:64,nonceLength:12,tagLength:16},Fd(Pw)),PB=Zc({blockSize:64,nonceLength:24,tagLength:16},Fd(Mw));function Hd(r,e,t){return kr(r),t===void 0&&(t=new Uint8Array(r.outputLen)),sr(r,ct(t),ct(e))}var su=new Uint8Array([0]),Vd=new Uint8Array;function Kd(r,e,t,n=32){if(kr(r),Qt(n),n>255*r.outputLen)throw new Error("Length should be <= 255*HashLen");let s=Math.ceil(n/r.outputLen);t===void 0&&(t=Vd);let o=new Uint8Array(s*r.outputLen),i=sr.create(r,e),a=i._cloneInto(),c=new Uint8Array(i.outputLen);for(let u=0;u<s;u++)su[0]=u+1,a.update(u===0?Vd:c).update(t).update(su).digestInto(c),o.set(c,r.outputLen*u),i._cloneInto(a);return i.destroy(),a.destroy(),c.fill(0),su.fill(0),o.slice(0,n)}var ou={hashSHA256(r){return wn(r.subarray())},getHKDF(r,e){let t=Hd(wn,e,r),s=Kd(wn,t,void 0,96),o=s.subarray(0,32),i=s.subarray(32,64),a=s.subarray(64,96);return[o,i,a]},generateX25519KeyPair(){let r=Jn.utils.randomPrivateKey();return{publicKey:Jn.getPublicKey(r),privateKey:r}},generateX25519KeyPairFromSeed(r){return{publicKey:Jn.getPublicKey(r),privateKey:r}},generateX25519SharedKey(r,e){return Jn.getSharedSecret(r.subarray(),e.subarray())},chaCha20Poly1305Encrypt(r,e,t,n){return nu(n,e,t).encrypt(r.subarray())},chaCha20Poly1305Decrypt(r,e,t,n,s){return nu(n,e,t).decrypt(r.subarray(),s)}};var $d=ou;function qd(r){return{generateKeypair:r.generateX25519KeyPair,dh:(e,t)=>r.generateX25519SharedKey(e.privateKey,t).subarray(0,32),encrypt:r.chaCha20Poly1305Encrypt,decrypt:r.chaCha20Poly1305Decrypt,hash:r.hashSHA256,hkdf:r.getHKDF}}var vn=r=>{let e=Be(2);return e[0]=r>>8,e[1]=r,e};vn.bytes=2;var ds=r=>{if(r.length<2)throw RangeError("Could not decode int16BE");if(r instanceof Uint8Array){let e=0;return e+=r[0]<<8,e+=r[1],e}return r.getUint16(0)};ds.bytes=2;function Wd(r){return{xxHandshakeSuccesses:r.registerCounter("libp2p_noise_xxhandshake_successes_total",{help:"Total count of noise xxHandshakes successes_"}),xxHandshakeErrors:r.registerCounter("libp2p_noise_xxhandshake_error_total",{help:"Total count of noise xxHandshakes errors"}),encryptedPackets:r.registerCounter("libp2p_noise_encrypted_packets_total",{help:"Total count of noise encrypted packets successfully"}),decryptedPackets:r.registerCounter("libp2p_noise_decrypted_packets_total",{help:"Total count of noise decrypted packets"}),decryptErrors:r.registerCounter("libp2p_noise_decrypt_errors_total",{help:"Total count of noise decrypt errors"})}}function iu(r,e){!e.enabled||!xn||(r?(e(`LOCAL_STATIC_PUBLIC_KEY ${z(r.publicKey,"hex")}`),e(`LOCAL_STATIC_PRIVATE_KEY ${z(r.privateKey,"hex")}`)):e("Missing local static keys."))}function au(r,e){!e.enabled||!xn||(r?(e(`LOCAL_PUBLIC_EPHEMERAL_KEY ${z(r.publicKey,"hex")}`),e(`LOCAL_PRIVATE_EPHEMERAL_KEY ${z(r.privateKey,"hex")}`)):e("Missing local ephemeral keys."))}function zd(r,e){!e.enabled||!xn||e(r?`REMOTE_STATIC_PUBLIC_KEY ${z(r.subarray(),"hex")}`:"Missing remote static public key.")}function cu(r,e){!e.enabled||!xn||e(r?`REMOTE_EPHEMERAL_PUBLIC_KEY ${z(r.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function uu(r,e,t){!t.enabled||!xn||(t(`CIPHER_STATE_1 ${r.n.getUint64()} ${r.k&&z(r.k,"hex")}`),t(`CIPHER_STATE_2 ${e.n.getUint64()} ${e.k&&z(e.k,"hex")}`))}var vi=class r extends Error{code;constructor(e="Unexpected Peer"){super(e),this.code=r.code}static code="ERR_UNEXPECTED_PEER"},An=class r extends Error{code;constructor(e="Invalid crypto exchange"){super(e),this.code=r.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var Hw=0,Kw=4294967295,$w="Cipherstate has reached maximum n, a new handshake must be performed",Ai=class{n;bytes;view;constructor(e=Hw){this.n=e,this.bytes=De(12),this.view=new DataView(this.bytes.buffer,this.bytes.byteOffset,this.bytes.byteLength),this.view.setUint32(4,e,!0)}increment(){this.n++,this.view.setUint32(4,this.n,!0)}getBytes(){return this.bytes}getUint64(){return this.n}assertValue(){if(this.n>Kw)throw new Error($w)}};var Pr=De(0),Dn=class{k;n;crypto;constructor(e,t=void 0,n=0){this.crypto=e,this.k=t,this.n=new Ai(n)}hasKey(){return!!this.k}encryptWithAd(e,t){if(!this.hasKey())return t;this.n.assertValue();let n=this.crypto.encrypt(t,this.n.getBytes(),e,this.k);return this.n.increment(),n}decryptWithAd(e,t,n){if(!this.hasKey())return t;this.n.assertValue();let s=this.crypto.decrypt(t,this.n.getBytes(),e,this.k,n);return this.n.increment(),s}},lu=class{cs;ck;h;crypto;constructor(e,t){this.crypto=e;let n=Q(t,"utf-8");this.h=qw(e,n),this.ck=this.h,this.cs=new Dn(e)}mixKey(e){let[t,n]=this.crypto.hkdf(this.ck,e);this.ck=t,this.cs=new Dn(this.crypto,n)}mixHash(e){this.h=this.crypto.hash(new le(this.h,e))}encryptAndHash(e){let t=this.cs.encryptWithAd(this.h,e);return this.mixHash(t),t}decryptAndHash(e){let t=this.cs.decryptWithAd(this.h,e);return this.mixHash(e),t}split(){let[e,t]=this.crypto.hkdf(this.ck,Pr);return[new Dn(this.crypto,e),new Dn(this.crypto,t)]}},fu=class{ss;s;e;rs;re;initiator;crypto;constructor(e){let{crypto:t,protocolName:n,prologue:s,initiator:o,s:i,e:a,rs:c,re:u}=e;this.crypto=t,this.ss=new lu(t,n),this.ss.mixHash(s),this.initiator=o,this.s=i,this.e=a,this.rs=c,this.re=u}writeE(){if(this.e)throw new Error("ephemeral keypair is already set");let e=this.crypto.generateKeypair();return this.ss.mixHash(e.publicKey),this.e=e,e.publicKey}writeS(){if(!this.s)throw new Error("static keypair is not set");return this.ss.encryptAndHash(this.s.publicKey)}writeEE(){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.re))}writeES(){if(this.initiator){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}else{if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}}writeSE(){if(this.initiator){if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}else{if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}}readE(e,t=0){if(this.re)throw new Error("remote ephemeral public key is already set");if(e.byteLength<t+32)throw new Error("message is not long enough");this.re=e.sublist(t,t+32),this.ss.mixHash(this.re)}readS(e,t=0){if(this.rs)throw new Error("remote static public key is already set");let n=32+(this.ss.cs.hasKey()?16:0);if(e.byteLength<t+n)throw new Error("message is not long enough");let s=e.sublist(t,t+n);return this.rs=this.ss.decryptAndHash(s),n}readEE(){this.writeEE()}readES(){this.writeES()}readSE(){this.writeSE()}},ps=class extends fu{writeMessageA(e){return new le(this.writeE(),this.ss.encryptAndHash(e))}writeMessageB(e){let t=this.writeE();this.writeEE();let n=this.writeS();return this.writeES(),new le(t,n,this.ss.encryptAndHash(e))}writeMessageC(e){let t=this.writeS();return this.writeSE(),new le(t,this.ss.encryptAndHash(e))}readMessageA(e){try{return this.readE(e),this.ss.decryptAndHash(e.sublist(32))}catch(t){throw new An(`handshake stage 0 validation fail: ${t.message}`)}}readMessageB(e){try{this.readE(e),this.readEE();let t=this.readS(e,32);return this.readES(),this.ss.decryptAndHash(e.sublist(32+t))}catch(t){throw new An(`handshake stage 1 validation fail: ${t.message}`)}}readMessageC(e){try{let t=this.readS(e);return this.readSE(),this.ss.decryptAndHash(e.sublist(t))}catch(t){throw new An(`handshake stage 2 validation fail: ${t.message}`)}}};function qw(r,e){if(e.length<=32){let t=De(32);return t.set(e),t}else return r.hash(e)}var Di;(function(r){let e;r.codec=()=>(e==null&&(e=it((t,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),t.webtransportCerthashes!=null)for(let o of t.webtransportCerthashes)n.uint32(10),n.bytes(o);s.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let s={webtransportCerthashes:[]},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let i=t.uint32();switch(i>>>3){case 1:{s.webtransportCerthashes.push(t.bytes());break}default:{t.skipType(i&7);break}}}return s})),e),r.encode=t=>ot(t,r.codec()),r.decode=t=>st(t,r.codec())})(Di||(Di={}));var ms;(function(r){let e;r.codec=()=>(e==null&&(e=it((t,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),t.identityKey!=null&&t.identityKey.byteLength>0&&(n.uint32(10),n.bytes(t.identityKey)),t.identitySig!=null&&t.identitySig.byteLength>0&&(n.uint32(18),n.bytes(t.identitySig)),t.extensions!=null&&(n.uint32(34),Di.codec().encode(t.extensions,n)),s.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let s={identityKey:De(0),identitySig:De(0)},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let i=t.uint32();switch(i>>>3){case 1:{s.identityKey=t.bytes();break}case 2:{s.identitySig=t.bytes();break}case 4:{s.extensions=Di.codec().decode(t,t.uint32());break}default:{t.skipType(i&7);break}}}return s})),e),r.encode=t=>ot(t,r.codec()),r.decode=t=>st(t,r.codec())})(ms||(ms={}));async function hu(r,e,t){let n=await r.sign(Gd(e));return ms.encode({identityKey:r.public.bytes,identitySig:n,extensions:t})}async function du(r,e,t){try{let n=ms.decode(r);if(t){let i=t.subarray();if(!Ae(i,n.identityKey))throw new Error(`Payload identity key ${z(n.identityKey,"hex")} does not match expected remote identity key ${z(i,"hex")}`)}if(!e)throw new Error("Remote static does not exist");let s=Gd(e);if(!await vd(n.identityKey).verify(s,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new vi(n.message)}}function Gd(r){let e=Q("noise-libp2p-static-key:");return r instanceof Uint8Array?xe([e,r],e.length+r.length):(r.prepend(e),r)}async function jd(r){let{log:e,connection:t,crypto:n,privateKey:s,prologue:o,s:i,remoteIdentityKey:a,extensions:c}=r,u=await hu(s,i.publicKey,c),l=new ps({crypto:n,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:o,s:i});iu(l.s,e),e.trace("Stage 0 - Initiator starting to send first message."),await t.write(l.writeMessageA(Pr)),e.trace("Stage 0 - Initiator finished sending first message."),au(l.e,e),e.trace("Stage 1 - Initiator waiting to receive first message from responder...");let f=l.readMessageB(await t.read());e.trace("Stage 1 - Initiator received the message."),cu(l.re,e),zd(l.rs,e),e.trace("Initiator going to check remote's signature...");let m=await du(f,l.rs,a);e.trace("All good with the signature!"),e.trace("Stage 2 - Initiator sending third handshake message."),await t.write(l.writeMessageC(u)),e.trace("Stage 2 - Initiator sent message with signed payload.");let[g,d]=l.ss.split();return uu(g,d,e),{payload:m,encrypt:h=>g.encryptWithAd(Pr,h),decrypt:(h,p)=>d.decryptWithAd(Pr,h,p)}}async function Yd(r){let{log:e,connection:t,crypto:n,privateKey:s,prologue:o,s:i,remoteIdentityKey:a,extensions:c}=r,u=await hu(s,i.publicKey,c),l=new ps({crypto:n,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:o,s:i});iu(l.s,e),e.trace("Stage 0 - Responder waiting to receive first message."),l.readMessageA(await t.read()),e.trace("Stage 0 - Responder received first message."),cu(l.re,e),e.trace("Stage 1 - Responder sending out first message with signed payload and static key."),await t.write(l.writeMessageB(u)),e.trace("Stage 1 - Responder sent the second handshake message with signed payload."),au(l.e,e),e.trace("Stage 2 - Responder waiting for third handshake message...");let f=l.readMessageC(await t.read());e.trace("Stage 2 - Responder received the message, finished handshake.");let m=await du(f,l.rs,a),[g,d]=l.ss.split();return uu(g,d,e),{payload:m,encrypt:h=>d.encryptWithAd(Pr,h),decrypt:(h,p)=>g.decryptWithAd(Pr,h,p)}}var Xd=16;function Jd(r,e){return async function*(t){for await(let n of t)for(let s=0;s<n.length;s+=65519){let o=s+65519;o>n.length&&(o=n.length);let i;n instanceof Uint8Array?i=r.encrypt(n.subarray(s,o)):i=r.encrypt(n.sublist(s,o)),e?.encryptedPackets.increment(),yield new le(vn(i.byteLength),i)}}}function Qd(r,e){return async function*(t){for await(let n of t)for(let s=0;s<n.length;s+=65535){let o=s+65535;if(o>n.length&&(o=n.length),o-Xd<s)throw new Error("Invalid chunk");let i=n.sublist(s,o),a=n.subarray(s,o-Xd);try{let c=r.decrypt(i,a);e?.decryptedPackets.increment(),yield c}catch(c){throw e?.decryptErrors.increment(),c}}}}var Bi=class{protocol="/noise";crypto;prologue;staticKey;extensions;metrics;components;constructor(e,t={}){let{staticNoiseKey:n,extensions:s,crypto:o,prologueBytes:i}=t,{metrics:a}=e;this.components=e;let c=o??$d;this.crypto=qd(c),this.extensions=s,this.metrics=a?Wd(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=i??De(0)}async secureOutbound(e,t,n){let s=Gn(t,{lengthEncoder:vn,lengthDecoder:ds,maxDataLength:65535});if(!e.privateKey)throw new L("local peerId does not contain private key","ERR_NO_PRIVATE_KEY");let o=await Gc(e.privateKey),i=n?.publicKey,a=await this.performHandshakeInitiator(s,o,i),c=await this.createSecureConnection(s,a);return t.source=c.source,t.sink=c.sink,{conn:t,remoteExtensions:a.payload.extensions,remotePeer:await fa(a.payload.identityKey)}}async secureInbound(e,t,n){let s=Gn(t,{lengthEncoder:vn,lengthDecoder:ds,maxDataLength:65535});if(!e.privateKey)throw new L("local peerId does not contain private key","ERR_NO_PRIVATE_KEY");let o=await Gc(e.privateKey),i=n?.publicKey,a=await this.performHandshakeResponder(s,o,i),c=await this.createSecureConnection(s,a);return t.source=c.source,t.sink=c.sink,{conn:t,remoteExtensions:a.payload.extensions,remotePeer:await fa(a.payload.identityKey)}}async performHandshakeInitiator(e,t,n){let s;try{s=await jd({connection:e,privateKey:t,remoteIdentityKey:n,log:this.components.logger.forComponent("libp2p:noise:xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:this.extensions}),this.metrics?.xxHandshakeSuccesses.increment()}catch(o){throw this.metrics?.xxHandshakeErrors.increment(),o}return s}async performHandshakeResponder(e,t,n){let s;try{s=await Yd({connection:e,privateKey:t,remoteIdentityKey:n,log:this.components.logger.forComponent("libp2p:noise:xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:this.extensions}),this.metrics?.xxHandshakeSuccesses.increment()}catch(o){throw this.metrics?.xxHandshakeErrors.increment(),o}return s}async createSecureConnection(e,t){let[n,s]=Ad(),o=e.unwrap();return await Bd(n,Jd(t,this.metrics),o,i=>xr(i,{lengthDecoder:ds}),Qd(t,this.metrics),n),s}};function e0(r={}){return e=>new Bi(e,r)}var Tp=Bs($u(),1);var Ap=Bs($u(),1);var qu=Object.values(gt).map(r=>r.decoder).reduce((r,e)=>r.or(e));function Dp(r,e){let t=r.getConfiguration().certificates?.at(0);if(t==null||t.getFingerprints==null){e.log.trace("fetching fingerprint from local SDP");let s=r.localDescription;return s==null?void 0:X2(s.sdp)}if(e.log.trace("fetching fingerprint from local certificate"),t.getFingerprints().length===0)return;let n=t.getFingerprints()[0].value;if(n==null)throw $a("","no fingerprint on local certificate");return n}var Z2=/^a=fingerprint:(?:\w+-[0-9]+)\s(?<fingerprint>(:?[0-9a-fA-F]{2})+)$/m;function X2(r){return r.match(Z2)?.groups?.fingerprint}function J2(r){for(let e of r.protoNames())if(e.startsWith("ip"))return e.toUpperCase();return"IP6"}function Pi(r){let t=r.stringTuples().filter(n=>n[0]===kp).map(n=>n[1])[0];if(t===void 0||t==="")throw qs(`Couldn't find a certhash component of multiaddr: ${r.toString()}`);return t}function Wu(r){let e=qu.decode(r);return Ap.decode(e)}function Q2(r){let e=Wu(Pi(r)),t=zu(e.name),n=e.digest.reduce((o,i)=>o+i.toString(16).padStart(2,"0"),""),s=n.match(/.{1,2}/g);if(s==null)throw $a(n,r.toString());return[`${t.toUpperCase()} ${s.join(":").toUpperCase()}`,n]}function zu(r){switch(r){case"sha1":return"sha-1";case"sha2-256":return"sha-256";case"sha2-512":return"sha-512";default:throw Jl(r)}}function e1(r,e){let{host:t,port:n}=r.toOptions(),s=J2(r),[o]=Q2(r);return`v=0
22
22
  o=- 0 0 IN ${s} ${t}
23
23
  s=-
24
24
  c=IN ${s} ${t}
@@ -33,11 +33,11 @@ a=fingerprint:${o}
33
33
  a=sctp-port:5000
34
34
  a=max-message-size:16384
35
35
  a=candidate:1467250027 1 UDP 1467250027 ${t} ${n} typ host\r
36
- `}function Ap(r,e){return{type:"answer",sdp:Q2(r,e)}}function Dp(r,e){if(r.sdp===void 0)throw Vn("Can't munge a missing SDP");return r.sdp=r.sdp.replace(/\na=ice-ufrag:[^\n]*\n/,`
36
+ `}function Bp(r,e){return{type:"answer",sdp:e1(r,e)}}function Sp(r,e){if(r.sdp===void 0)throw Kn("Can't munge a missing SDP");return r.sdp=r.sdp.replace(/\na=ice-ufrag:[^\n]*\n/,`
37
37
  a=ice-ufrag:`+e+`
38
38
  `).replace(/\na=ice-pwd:[^\n]*\n/,`
39
39
  a=ice-pwd:`+e+`
40
- `),r}var Sp=Array.from("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),kp=r=>[...Array(r)].map(()=>Sp.at(Math.floor(Math.random()*Sp.length))).join("");var t1=1e4,A6=ne("webrtc-direct").code,Bp=ne("certhash").code,Ui=class{log;metrics;components;init;constructor(e,t={}){this.log=e.logger.forComponent("libp2p:webrtc-direct"),this.components=e,this.init=t,e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_webrtc-direct_dialer_events_total",{label:"event",help:"Total count of WebRTC-direct dial events by type"})})}async dial(e,t){let n=await this._connect(e,t);return this.log("dialing address: %a",e),n}createListener(e){throw Zl("WebRTCTransport.createListener")}filter(e){return e.filter(Gl.exactMatch)}[Symbol.toStringTag]="@libp2p/webrtc-direct";[Bs]=!0;async _connect(e,t){let n=new AbortController,s=n.signal,o=e.getPeerId();if(o===null)throw Hs("we need to have the remote's PeerId");let i=mr(o),a=$u(Li(e)),c=await Qr.generateCertificate({name:"ECDSA",namedCurve:"P-256",hash:qu(a.name)}),u=new Qr({certificates:[c]});try{let l=new Promise((D,_)=>{let U=u.createDataChannel("",{negotiated:!0,id:0}),R=setTimeout(()=>{let H=`Data channel was never opened: state: ${U.readyState}`;this.log.error(H),this.metrics?.dialerEvents.increment({open_error:!0}),_(Fa("data",H))},t1);U.onopen=H=>{clearTimeout(R),D(U)},U.onerror=H=>{clearTimeout(R);let G=`Error opening a data channel for handshaking: ${H.target?.toString()??"not specified"}`;this.log.error(G),this.metrics?.dialerEvents.increment({unknown_error:!0}),_(Fa("data",G))}}),f="libp2p+webrtc+v1/"+kp(32),m=await u.createOffer(),g=Dp(m,f);await u.setLocalDescription(g);let d=Ap(e,f);await u.setRemoteDescription(d);let h=await l,p=this.components.peerId,y=this.generateNoisePrologue(u,a.code,e),x=Jd({prologueBytes:y})(this.components),b=Jr({channel:h,direction:"inbound",logger:this.components.logger,...this.init.dataChannel??{}}),v={...b,sink:b.sink.bind(b),source:async function*(){for await(let D of b.source)for(let _ of D)yield _}()},E=new br(this.components,{peerConnection:u,remoteAddr:e,timeline:{open:Date.now()},metrics:this.metrics?.dialerEvents}),A=Hn?"iceconnectionstatechange":"connectionstatechange";u.addEventListener(A,()=>{switch(u.connectionState){case"failed":case"disconnected":case"closed":E.close().catch(D=>{this.log.error("error closing connection",D)}).finally(()=>{n.abort()});break;default:break}},{signal:s}),this.metrics?.dialerEvents.increment({peer_connection:!0});let S=new Ar(this.components,{peerConnection:u,metrics:this.metrics?.dialerEvents,dataChannelOptions:this.init.dataChannel});return await x.secureInbound(p,v,i),await t.upgrader.upgradeOutbound(E,{skipProtection:!0,skipEncryption:!0,muxerFactory:S})}catch(l){throw u.close(),l}}generateNoisePrologue(e,t,n){if(e.getConfiguration().certificates?.length===0)throw Vn("no local certificate");let s=vp(e,{log:this.log});if(s==null)throw Vn("no local fingerprint found");let o=s.trim().toLowerCase().replaceAll(":",""),i=Q(o,"hex"),a=Cp.encode(i,t),c=Ku.decode(Li(n)),u=Q("libp2p-webrtc-noise:");return we([u,a,c])}};function r1(r){return e=>new Ui(e,r)}function n1(r){return e=>new lo(e,r)}return Ds(s1);})();
40
+ `),r}var Cp=Array.from("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),Ip=r=>[...Array(r)].map(()=>Cp.at(Math.floor(Math.random()*Cp.length))).join("");var r1=1e4,C6=se("webrtc-direct").code,kp=se("certhash").code,Mi=class{log;metrics;components;init;constructor(e,t={}){this.log=e.logger.forComponent("libp2p:webrtc-direct"),this.components=e,this.init=t,e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_webrtc-direct_dialer_events_total",{label:"event",help:"Total count of WebRTC-direct dial events by type"})})}async dial(e,t){let n=await this._connect(e,t);return this.log("dialing address: %a",e),n}createListener(e){throw Xl("WebRTCTransport.createListener")}filter(e){return e.filter(jl.exactMatch)}[Symbol.toStringTag]="@libp2p/webrtc-direct";[ks]=!0;async _connect(e,t){let n=new AbortController,s=n.signal,o=e.getPeerId();if(o===null)throw qs("we need to have the remote's PeerId");let i=gr(o),a=Wu(Pi(e)),c=await en.generateCertificate({name:"ECDSA",namedCurve:"P-256",hash:zu(a.name)}),u=new en({certificates:[c]});try{let l=new Promise((D,_)=>{let O=u.createDataChannel("",{negotiated:!0,id:0}),R=setTimeout(()=>{let H=`Data channel was never opened: state: ${O.readyState}`;this.log.error(H),this.metrics?.dialerEvents.increment({open_error:!0}),_(Ka("data",H))},r1);O.onopen=H=>{clearTimeout(R),D(O)},O.onerror=H=>{clearTimeout(R);let G=`Error opening a data channel for handshaking: ${H.target?.toString()??"not specified"}`;this.log.error(G),this.metrics?.dialerEvents.increment({unknown_error:!0}),_(Ka("data",G))}}),f="libp2p+webrtc+v1/"+Ip(32),m=await u.createOffer(),g=Sp(m,f);await u.setLocalDescription(g);let d=Bp(e,f);await u.setRemoteDescription(d);let h=await l,p=this.components.peerId,y=this.generateNoisePrologue(u,a.code,e),x=e0({prologueBytes:y})(this.components),b=Qr({channel:h,direction:"inbound",logger:this.components.logger,...this.init.dataChannel??{}}),v={...b,sink:b.sink.bind(b),source:async function*(){for await(let D of b.source)for(let _ of D)yield _}()},E=new yr(this.components,{peerConnection:u,remoteAddr:e,timeline:{open:Date.now()},metrics:this.metrics?.dialerEvents}),A=$n?"iceconnectionstatechange":"connectionstatechange";u.addEventListener(A,()=>{switch(u.connectionState){case"failed":case"disconnected":case"closed":E.close().catch(D=>{this.log.error("error closing connection",D)}).finally(()=>{n.abort()});break;default:break}},{signal:s}),this.metrics?.dialerEvents.increment({peer_connection:!0});let S=new Dr(this.components,{peerConnection:u,metrics:this.metrics?.dialerEvents,dataChannelOptions:this.init.dataChannel});return await x.secureInbound(p,v,i),await t.upgrader.upgradeOutbound(E,{skipProtection:!0,skipEncryption:!0,muxerFactory:S})}catch(l){throw u.close(),l}}generateNoisePrologue(e,t,n){if(e.getConfiguration().certificates?.length===0)throw Kn("no local certificate");let s=Dp(e,{log:this.log});if(s==null)throw Kn("no local fingerprint found");let o=s.trim().toLowerCase().replaceAll(":",""),i=Q(o,"hex"),a=Tp.encode(i,t),c=qu.decode(Pi(n)),u=Q("libp2p-webrtc-noise:");return xe([u,a,c])}};function n1(r){return e=>new Mi(e,r)}function s1(r){return e=>new po(e,r)}return Ss(o1);})();
41
41
  /*! Bundled license information:
42
42
 
43
43
  pvtsutils/build/index.js: