@libp2p/autonat 1.0.13-ab466004b → 1.0.13-e1798aa26

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,10 +1,10 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PAutonat = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PAutonat=(()=>{var El=Object.create;var Yr=Object.defineProperty;var Bl=Object.getOwnPropertyDescriptor;var Al=Object.getOwnPropertyNames;var Sl=Object.getPrototypeOf,kl=Object.prototype.hasOwnProperty;var Es=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),lt=(r,t)=>{for(var e in t)Yr(r,e,{get:t[e],enumerable:!0})},Bi=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Al(t))!kl.call(r,s)&&s!==e&&Yr(r,s,{get:()=>t[s],enumerable:!(n=Bl(t,s))||n.enumerable});return r};var Bs=(r,t,e)=>(e=r!=null?El(Sl(r)):{},Bi(t||!r||!r.__esModule?Yr(e,"default",{value:r,enumerable:!0}):e,r)),Il=r=>Bi(Yr({},"__esModule",{value:!0}),r);var Ra=Es(hr=>{"use strict";var lh="[object ArrayBuffer]",ie=class r{static isArrayBuffer(t){return Object.prototype.toString.call(t)===lh}static toArrayBuffer(t){return this.isArrayBuffer(t)?t:t.byteLength===t.buffer.byteLength||t.byteOffset===0&&t.byteLength===t.buffer.byteLength?t.buffer:this.toUint8Array(t.buffer).slice(t.byteOffset,t.byteOffset+t.byteLength).buffer}static toUint8Array(t){return this.toView(t,Uint8Array)}static toView(t,e){if(t.constructor===e)return t;if(this.isArrayBuffer(t))return new e(t);if(this.isArrayBufferView(t))return new e(t.buffer,t.byteOffset,t.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(t){return this.isArrayBufferView(t)||this.isArrayBuffer(t)}static isArrayBufferView(t){return ArrayBuffer.isView(t)||t&&this.isArrayBuffer(t.buffer)}static isEqual(t,e){let n=r.toUint8Array(t),s=r.toUint8Array(e);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(...t){let e;Array.isArray(t[0])&&!(t[1]instanceof Function)||Array.isArray(t[0])&&t[1]instanceof Function?e=t[0]:t[t.length-1]instanceof Function?e=t.slice(0,t.length-1):e=t;let n=0;for(let i of e)n+=i.byteLength;let s=new Uint8Array(n),o=0;for(let i of e){let a=this.toUint8Array(i);s.set(a,o),o+=a.length}return t[t.length-1]instanceof Function?this.toView(s,t[t.length-1]):s.buffer}},Co="string",uh=/^[0-9a-f]+$/i,fh=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,hh=/^[a-zA-Z0-9-_]+$/,bn=class{static fromString(t){let e=unescape(encodeURIComponent(t)),n=new Uint8Array(e.length);for(let s=0;s<e.length;s++)n[s]=e.charCodeAt(s);return n.buffer}static toString(t){let e=ie.toUint8Array(t),n="";for(let o=0;o<e.length;o++)n+=String.fromCharCode(e[o]);return decodeURIComponent(escape(n))}},Lt=class{static toString(t,e=!1){let n=ie.toArrayBuffer(t),s=new DataView(n),o="";for(let i=0;i<n.byteLength;i+=2){let a=s.getUint16(i,e);o+=String.fromCharCode(a)}return o}static fromString(t,e=!1){let n=new ArrayBuffer(t.length*2),s=new DataView(n);for(let o=0;o<t.length;o++)s.setUint16(o*2,t.charCodeAt(o),e);return n}},wn=class r{static isHex(t){return typeof t===Co&&uh.test(t)}static isBase64(t){return typeof t===Co&&fh.test(t)}static isBase64Url(t){return typeof t===Co&&hh.test(t)}static ToString(t,e="utf8"){let n=ie.toUint8Array(t);switch(e.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 Lt.toString(n,!0);case"utf16":case"utf16be":return Lt.toString(n);default:throw new Error(`Unknown type of encoding '${e}'`)}}static FromString(t,e="utf8"){if(!t)return new ArrayBuffer(0);switch(e.toLowerCase()){case"utf8":return this.FromUtf8String(t);case"binary":return this.FromBinary(t);case"hex":return this.FromHex(t);case"base64":return this.FromBase64(t);case"base64url":return this.FromBase64Url(t);case"utf16le":return Lt.fromString(t,!0);case"utf16":case"utf16be":return Lt.fromString(t);default:throw new Error(`Unknown type of encoding '${e}'`)}}static ToBase64(t){let e=ie.toUint8Array(t);if(typeof btoa<"u"){let n=this.ToString(e,"binary");return btoa(n)}else return Buffer.from(e).toString("base64")}static FromBase64(t){let e=this.formatString(t);if(!e)return new ArrayBuffer(0);if(!r.isBase64(e))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(e)):new Uint8Array(Buffer.from(e,"base64")).buffer}static FromBase64Url(t){let e=this.formatString(t);if(!e)return new ArrayBuffer(0);if(!r.isBase64Url(e))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(e.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(t){return this.ToBase64(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(t,e=r.DEFAULT_UTF8_ENCODING){switch(e){case"ascii":return this.FromBinary(t);case"utf8":return bn.fromString(t);case"utf16":case"utf16be":return Lt.fromString(t);case"utf16le":case"usc2":return Lt.fromString(t,!0);default:throw new Error(`Unknown type of encoding '${e}'`)}}static ToUtf8String(t,e=r.DEFAULT_UTF8_ENCODING){switch(e){case"ascii":return this.ToBinary(t);case"utf8":return bn.toString(t);case"utf16":case"utf16be":return Lt.toString(t);case"utf16le":case"usc2":return Lt.toString(t,!0);default:throw new Error(`Unknown type of encoding '${e}'`)}}static FromBinary(t){let e=t.length,n=new Uint8Array(e);for(let s=0;s<e;s++)n[s]=t.charCodeAt(s);return n.buffer}static ToBinary(t){let e=ie.toUint8Array(t),n="";for(let s=0;s<e.length;s++)n+=String.fromCharCode(e[s]);return n}static ToHex(t){let e=ie.toUint8Array(t),n="",s=e.length;for(let o=0;o<s;o++){let i=e[o];i<16&&(n+="0"),n+=i.toString(16)}return n}static FromHex(t){let e=this.formatString(t);if(!e)return new ArrayBuffer(0);if(!r.isHex(e))throw new TypeError("Argument 'hexString' is not HEX encoded");e.length%2&&(e=`0${e}`);let n=new Uint8Array(e.length/2);for(let s=0;s<e.length;s=s+2){let o=e.slice(s,s+2);n[s/2]=parseInt(o,16)}return n.buffer}static ToUtf16String(t,e=!1){return Lt.toString(t,e)}static FromUtf16String(t,e=!1){return Lt.fromString(t,e)}static Base64Padding(t){let e=4-t.length%4;if(e<4)for(let n=0;n<e;n++)t+="=";return t}static formatString(t){return t?.replace(/[\n\r\t ]/g,"")||""}};wn.DEFAULT_UTF8_ENCODING="utf8";function dh(r,...t){let e=arguments[0];for(let n=1;n<arguments.length;n++){let s=arguments[n];for(let o in s)e[o]=s[o]}return e}function ph(...r){let t=r.map(s=>s.byteLength).reduce((s,o)=>s+o),e=new Uint8Array(t),n=0;return r.map(s=>new Uint8Array(s)).forEach(s=>{for(let o of s)e[n++]=o}),e.buffer}function gh(r,t){if(!(r&&t)||r.byteLength!==t.byteLength)return!1;let e=new Uint8Array(r),n=new Uint8Array(t);for(let s=0;s<r.byteLength;s++)if(e[s]!==n[s])return!1;return!0}hr.BufferSourceConverter=ie;hr.Convert=wn;hr.assign=dh;hr.combine=ph;hr.isEqual=gh});var Fc=Es(jr=>{(function(){var r,t,e,n,s,o,i,a;a=function(c){var l,f,u,h;return l=(c&255<<24)>>>24,f=(c&255<<16)>>>16,u=(c&65280)>>>8,h=c&255,[l,f,u,h].join(".")},i=function(c){var l,f,u,h,m,g;for(l=[],u=h=0;h<=3&&c.length!==0;u=++h){if(u>0){if(c[0]!==".")throw new Error("Invalid IP");c=c.substring(1)}g=t(c),m=g[0],f=g[1],c=c.substring(f),l.push(m)}if(c.length!==0)throw new Error("Invalid IP");switch(l.length){case 1:if(l[0]>4294967295)throw new Error("Invalid IP");return l[0]>>>0;case 2:if(l[0]>255||l[1]>16777215)throw new Error("Invalid IP");return(l[0]<<24|l[1])>>>0;case 3:if(l[0]>255||l[1]>255||l[2]>65535)throw new Error("Invalid IP");return(l[0]<<24|l[1]<<16|l[2])>>>0;case 4:if(l[0]>255||l[1]>255||l[2]>255||l[3]>255)throw new Error("Invalid IP");return(l[0]<<24|l[1]<<16|l[2]<<8|l[3])>>>0;default:throw new Error("Invalid IP")}},e=function(c){return c.charCodeAt(0)},n=e("0"),o=e("a"),s=e("A"),t=function(c){var l,f,u,h,m;for(h=0,l=10,f="9",u=0,c.length>1&&c[u]==="0"&&(c[u+1]==="x"||c[u+1]==="X"?(u+=2,l=16):"0"<=c[u+1]&&c[u+1]<="9"&&(u++,l=8,f="7")),m=u;u<c.length;){if("0"<=c[u]&&c[u]<=f)h=h*l+(e(c[u])-n)>>>0;else if(l===16)if("a"<=c[u]&&c[u]<="f")h=h*l+(10+e(c[u])-o)>>>0;else if("A"<=c[u]&&c[u]<="F")h=h*l+(10+e(c[u])-s)>>>0;else break;else break;if(h>4294967295)throw new Error("too large");u++}if(u===m)throw new Error("empty octet");return[h,u]},r=function(){function c(l,f){var u,h,m,g;if(typeof l!="string")throw new Error("Missing `net' parameter");if(f||(g=l.split("/",2),l=g[0],f=g[1]),f||(f=32),typeof f=="string"&&f.indexOf(".")>-1){try{this.maskLong=i(f)}catch(d){throw u=d,new Error("Invalid mask: "+f)}for(h=m=32;m>=0;h=--m)if(this.maskLong===4294967295<<32-h>>>0){this.bitmask=h;break}}else if(f||f===0)this.bitmask=parseInt(f,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(i(l)&this.maskLong)>>>0}catch(d){throw u=d,new Error("Invalid net address: "+l)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+f);this.size=Math.pow(2,32-this.bitmask),this.base=a(this.netLong),this.mask=a(this.maskLong),this.hostmask=a(~this.maskLong),this.first=this.bitmask<=30?a(this.netLong+1):this.base,this.last=this.bitmask<=30?a(this.netLong+this.size-2):a(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?a(this.netLong+this.size-1):void 0}return c.prototype.contains=function(l){return typeof l=="string"&&(l.indexOf("/")>0||l.split(".").length!==4)&&(l=new c(l)),l instanceof c?this.contains(l.base)&&this.contains(l.broadcast||l.last):(i(l)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},c.prototype.next=function(l){return l==null&&(l=1),new c(a(this.netLong+this.size*l),this.mask)},c.prototype.forEach=function(l){var f,u,h;for(h=i(this.first),u=i(this.last),f=0;h<=u;)l(a(h),h,f),f++,h++},c.prototype.toString=function(){return this.base+"/"+this.bitmask},c}(),jr.ip2long=i,jr.long2ip=a,jr.Netmask=r}).call(jr)});var ol=Es((Nb,sl)=>{"use strict";function nl(r,t){for(let e in t)Object.defineProperty(r,e,{value:t[e],enumerable:!0,configurable:!0});return r}function Ad(r,t,e){if(!r||typeof r=="string")throw new TypeError("Please pass an Error to err-code");e||(e={}),typeof t=="object"&&(e=t,t=""),t&&(e.code=t);try{return nl(r,e)}catch{e.message=r.message,e.stack=r.stack;let s=function(){};return s.prototype=Object.create(Object.getPrototypeOf(r)),nl(new s,e)}}sl.exports=Ad});var Kd={};lt(Kd,{autoNAT:()=>Md});var Ai=Symbol.for("@libp2p/peer-id");var U=class extends Error{code;props;constructor(t,e,n){super(t),this.code=e,this.name=n?.name??"CodeError",this.props=n??{}}};var As="ERR_TIMEOUT";var Ss=(r,...t)=>{try{[...t]}catch{}};var Ts={};lt(Ts,{base58btc:()=>at,base58flickr:()=>Ul});var jd=new Uint8Array(0);function Si(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function jt(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 ki(r){return new TextEncoder().encode(r)}function Ii(r){return new TextDecoder().decode(r)}function Rl(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var s=0;s<r.length;s++){var o=r.charAt(s),i=o.charCodeAt(0);if(e[i]!==255)throw new TypeError(o+" is ambiguous");e[i]=s}var a=r.length,c=r.charAt(0),l=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function u(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,p=0,y=0,v=g.length;y!==v&&g[y]===0;)y++,d++;for(var w=(v-y)*f+1>>>0,T=new Uint8Array(w);y!==v;){for(var x=g[y],A=0,R=w-1;(x!==0||A<p)&&R!==-1;R--,A++)x+=256*T[R]>>>0,T[R]=x%a>>>0,x=x/a>>>0;if(x!==0)throw new Error("Non-zero carry");p=A,y++}for(var N=w-p;N!==w&&T[N]===0;)N++;for(var q=c.repeat(d);N<w;++N)q+=r.charAt(T[N]);return q}function h(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 p=0,y=0;g[d]===c;)p++,d++;for(var v=(g.length-d)*l+1>>>0,w=new Uint8Array(v);g[d];){var T=e[g.charCodeAt(d)];if(T===255)return;for(var x=0,A=v-1;(T!==0||x<y)&&A!==-1;A--,x++)T+=a*w[A]>>>0,w[A]=T%256>>>0,T=T/256>>>0;if(T!==0)throw new Error("Non-zero carry");y=x,d++}if(g[d]!==" "){for(var R=v-y;R!==v&&w[R]===0;)R++;for(var N=new Uint8Array(p+(v-R)),q=p;R!==v;)N[q++]=w[R++];return N}}}function m(g){var d=h(g);if(d)return d;throw new Error(`Non-${t} character`)}return{encode:u,decodeUnsafe:h,decode:m}}var Nl=Rl,Tl=Nl,Ni=Tl;var ks=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Is=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Ti(this,t)}},Rs=class{decoders;constructor(t){this.decoders=t}or(t){return Ti(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ti(r,t){return new Rs({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Ns=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,s){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=s,this.encoder=new ks(t,e,n),this.decoder=new Is(t,e,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ze({name:r,prefix:t,encode:e,decode:n}){return new Ns(r,t,e,n)}function pe({name:r,prefix:t,alphabet:e}){let{encode:n,decode:s}=Ni(e,r);return ze({prefix:t,name:r,encode:n,decode:o=>jt(s(o))})}function Ll(r,t,e,n){let s={};for(let f=0;f<t.length;++f)s[t[f]]=f;let o=r.length;for(;r[o-1]==="=";)--o;let i=new Uint8Array(o*e/8|0),a=0,c=0,l=0;for(let f=0;f<o;++f){let u=s[r[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|u,a+=e,a>=8&&(a-=8,i[l++]=255&c>>a)}if(a>=e||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return i}function _l(r,t,e){let n=t[t.length-1]==="=",s=(1<<e)-1,o="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,o+=t[s&a>>i];if(i!==0&&(o+=t[s&a<<e-i]),n)for(;o.length*e&7;)o+="=";return o}function tt({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return ze({prefix:t,name:r,encode(s){return _l(s,n,e)},decode(s){return Ll(s,n,e,r)}})}var at=pe({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ul=pe({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ls={};lt(Ls,{base10:()=>Cl});var Cl=pe({prefix:"9",name:"base10",alphabet:"0123456789"});var _s={};lt(_s,{base16:()=>Dl,base16upper:()=>Pl});var Dl=tt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Pl=tt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Us={};lt(Us,{base2:()=>Ol});var Ol=tt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Cs={};lt(Cs,{base256emoji:()=>Kl});var Li=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}"),Vl=Li.reduce((r,t,e)=>(r[e]=t,r),[]),Fl=Li.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function Hl(r){return r.reduce((t,e)=>(t+=Vl[e],t),"")}function Ml(r){let t=[];for(let e of r){let n=Fl[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var Kl=ze({prefix:"\u{1F680}",name:"base256emoji",encode:Hl,decode:Ml});var Ds={};lt(Ds,{base32:()=>Wt,base32hex:()=>zl,base32hexpad:()=>Wl,base32hexpadupper:()=>Yl,base32hexupper:()=>jl,base32pad:()=>ql,base32padupper:()=>Gl,base32upper:()=>$l,base32z:()=>Zl});var Wt=tt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),$l=tt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),ql=tt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Gl=tt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),zl=tt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),jl=tt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Wl=tt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Yl=tt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Zl=tt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ps={};lt(Ps,{base36:()=>Jl,base36upper:()=>Xl});var Jl=pe({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Xl=pe({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Vs={};lt(Vs,{base64:()=>Os,base64pad:()=>Ql,base64url:()=>tu,base64urlpad:()=>eu});var Os=tt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ql=tt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),tu=tt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),eu=tt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Fs={};lt(Fs,{base8:()=>ru});var ru=tt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Hs={};lt(Hs,{identity:()=>nu});var nu=ze({prefix:"\0",name:"identity",encode:r=>Ii(r),decode:r=>ki(r)});var l0=new TextEncoder,u0=new TextDecoder;var Ks={};lt(Ks,{identity:()=>ge});var iu=Ci,_i=128,au=127,cu=~au,lu=Math.pow(2,31);function Ci(r,t,e){t=t||[],e=e||0;for(var n=e;r>=lu;)t[e++]=r&255|_i,r/=128;for(;r&cu;)t[e++]=r&255|_i,r>>>=7;return t[e]=r|0,Ci.bytes=e-n+1,t}var uu=Ms,fu=128,Ui=127;function Ms(r,n){var e=0,n=n||0,s=0,o=n,i,a=r.length;do{if(o>=a)throw Ms.bytes=0,new RangeError("Could not decode varint");i=r[o++],e+=s<28?(i&Ui)<<s:(i&Ui)*Math.pow(2,s),s+=7}while(i>=fu);return Ms.bytes=o-n,e}var hu=Math.pow(2,7),du=Math.pow(2,14),pu=Math.pow(2,21),gu=Math.pow(2,28),mu=Math.pow(2,35),yu=Math.pow(2,42),bu=Math.pow(2,49),wu=Math.pow(2,56),xu=Math.pow(2,63),vu=function(r){return r<hu?1:r<du?2:r<pu?3:r<gu?4:r<mu?5:r<yu?6:r<bu?7:r<wu?8:r<xu?9:10},Eu={encode:iu,decode:uu,encodingLength:vu},Bu=Eu,Ar=Bu;function Sr(r,t=0){return[Ar.decode(r,t),Ar.decode.bytes]}function je(r,t,e=0){return Ar.encode(r,t,e),t}function We(r){return Ar.encodingLength(r)}function Mt(r,t){let e=t.byteLength,n=We(r),s=n+We(e),o=new Uint8Array(s+e);return je(r,o,0),je(e,o,n),o.set(t,s),new Ye(r,e,t,o)}function Ce(r){let t=jt(r),[e,n]=Sr(t),[s,o]=Sr(t.subarray(n)),i=t.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new Ye(e,s,i,t)}function Di(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Si(r.bytes,e.bytes)}}var Ye=class{code;size;digest;bytes;constructor(t,e,n,s){this.code=t,this.size=e,this.digest=n,this.bytes=s}};var Pi=0,Au="identity",Oi=jt;function Su(r){return Mt(Pi,Oi(r))}var ge={code:Pi,name:Au,encode:Oi,digest:Su};var Gs={};lt(Gs,{sha256:()=>pt,sha512:()=>ku});function qs({name:r,code:t,encode:e}){return new $s(r,t,e)}var $s=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?Mt(this.code,e):e.then(n=>Mt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Fi(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var pt=qs({name:"sha2-256",code:18,encode:Fi("SHA-256")}),ku=qs({name:"sha2-512",code:19,encode:Fi("SHA-512")});function Hi(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Ru(e,zs(r),t??at.encoder);default:return Nu(e,zs(r),t??Wt.encoder)}}var Mi=new WeakMap;function zs(r){let t=Mi.get(r);if(t==null){let e=new Map;return Mi.set(r,e),e}return t}var Ut=class r{code;version;multihash;bytes;"/";constructor(t,e,n,s){this.code=e,this.version=t,this.multihash=n,this.bytes=s,this["/"]=s}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==kr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Tu)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=Mt(t,e);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(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&Di(t.multihash,n.multihash)}toString(t){return Hi(this,t)}toJSON(){return{"/":Hi(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:s,multihash:o,bytes:i}=e;return new r(n,s,o,i??Ki(n,s,o.bytes))}else if(e[Lu]===!0){let{version:n,multihash:s,code:o}=e,i=Ce(s);return r.create(n,o,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==kr)throw new Error(`Version 0 CID must use dag-pb (code: ${kr}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let s=Ki(t,e,n.bytes);return new r(t,e,n,s)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,kr,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,s=jt(t.subarray(n,n+e.multihashSize));if(s.byteLength!==e.multihashSize)throw new Error("Incorrect length");let o=s.subarray(e.multihashSize-e.digestSize),i=new Ye(e.multihashCode,e.digestSize,o,s);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[u,h]=Sr(t.subarray(e));return e+=h,u},s=n(),o=kr;if(s===18?(s=0,e=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=e,a=n(),c=n(),l=e+c,f=l-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:f,size:l}}static parse(t,e){let[n,s]=Iu(t,e),o=r.decode(s);if(o.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return zs(o).set(n,t),o}};function Iu(r,t){switch(r[0]){case"Q":{let e=t??at;return[at.prefix,e.decode(`${at.prefix}${r}`)]}case at.prefix:{let e=t??at;return[at.prefix,e.decode(r)]}case Wt.prefix:{let e=t??Wt;return[Wt.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Ru(r,t,e){let{prefix:n}=e;if(n!==at.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let s=t.get(n);if(s==null){let o=e.encode(r).slice(1);return t.set(n,o),o}else return s}function Nu(r,t,e){let{prefix:n}=e,s=t.get(n);if(s==null){let o=e.encode(r);return t.set(n,o),o}else return s}var kr=112,Tu=18;function Ki(r,t,e){let n=We(r),s=n+We(t),o=new Uint8Array(s+e.byteLength);return je(r,o,0),je(t,o,n),o.set(e,s),o}var Lu=Symbol.for("@ipld/js-cid/CID");var me={...Hs,...Us,...Fs,...Ls,..._s,...Ds,...Ps,...Ts,...Vs,...Cs},L0={...Gs,...Ks};function bt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}var _u=Symbol.for("nodejs.util.inspect.custom"),$i=Object.values(me).map(r=>r.decoder).reduce((r,t)=>r.or(t),me.identity.decoder),qi=114,js=36,Ws=37,Ir=class{type;multihash;privateKey;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,this.privateKey=t.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Ai]=!0;toString(){return this.string==null&&(this.string=at.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return Ut.createV1(qi,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return bt(this.multihash.bytes,t);if(typeof t=="string")return Uu(t).equals(this);if(t?.multihash?.bytes!=null)return bt(this.multihash.bytes,t.multihash.bytes);throw new Error("not valid Id")}[_u](){return`PeerId(${this.toString()})`}},Ze=class extends Ir{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Je=class extends Ir{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.multihash.digest}},Xe=class extends Ir{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.multihash.digest}};function Uu(r,t){if(t=t??$i,r.charAt(0)==="1"||r.charAt(0)==="Q"){let e=Ce(at.decode(`z${r}`));return r.startsWith("12D")?new Je({multihash:e}):r.startsWith("16U")?new Xe({multihash:e}):new Ze({multihash:e})}return Jr($i.decode(r))}function Jr(r){try{let t=Ce(r);if(t.code===ge.code){if(t.digest.length===js)return new Je({multihash:t});if(t.digest.length===Ws)return new Xe({multihash:t})}if(t.code===pt.code)return new Ze({multihash:t})}catch{return Cu(Ut.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function Cu(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==qi)throw new Error("Supplied PeerID CID is invalid");let t=r.multihash;if(t.code===pt.code)return new Ze({multihash:r.multihash});if(t.code===ge.code){if(t.digest.length===js)return new Je({multihash:r.multihash});if(t.digest.length===Ws)return new Xe({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function Gi(r,t){return r.length===js?new Je({multihash:Mt(ge.code,r),privateKey:t}):r.length===Ws?new Xe({multihash:Mt(ge.code,r),privateKey:t}):new Ze({multihash:await pt.digest(r),publicKey:r,privateKey:t})}var _o={};lt(_o,{Ed25519PrivateKey:()=>Me,Ed25519PublicKey:()=>_r,generateKeyPair:()=>ih,generateKeyPairFromSeed:()=>Ia,unmarshalEd25519PrivateKey:()=>sh,unmarshalEd25519PublicKey:()=>oh});function ye(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function Yt(r=0){return globalThis.Buffer?.alloc!=null?ye(globalThis.Buffer.alloc(r)):new Uint8Array(r)}function wt(r=0){return globalThis.Buffer?.allocUnsafe!=null?ye(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function Bt(r,t){if(globalThis.Buffer!=null)return ye(globalThis.Buffer.concat(r,t));t==null&&(t=r.reduce((s,o)=>s+o.length,0));let e=wt(t),n=0;for(let s of r)e.set(s,n),n+=s.length;return ye(e)}function ji(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var zi=ji("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Ys=ji("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=wt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Du={utf8:zi,"utf-8":zi,hex:me.base16,latin1:Ys,ascii:Ys,binary:Ys,...me},Xr=Du;function Z(r,t="utf8"){let e=Xr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?ye(globalThis.Buffer.from(r,"utf-8")):e.decoder.decode(`${e.prefix}${r}`)}function Tt(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Qe(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`Wrong positive integer: ${r}`)}function Pu(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Zs(r,...t){if(!Pu(r))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(r.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${r.length}`)}function Qr(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Qe(r.outputLen),Qe(r.blockLen)}function tr(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function Wi(r,t){Zs(r);let e=t.outputLen;if(r.length<e)throw new Error(`digestInto() expects output buffer of length at least ${e}`)}var tn=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Yi(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var rr=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Ct=(r,t)=>r<<32-t|r>>>t,Ou=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Ou)throw new Error("Non little-endian hardware is not supported");var Vu=async()=>{};async function Zi(r,t,e){let n=Date.now();for(let s=0;s<r;s++){e(s);let o=Date.now()-n;o>=0&&o<t||(await Vu(),n+=o)}}function Js(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function be(r){if(typeof r=="string"&&(r=Js(r)),!Yi(r))throw new Error(`expected Uint8Array, got ${typeof r}`);return r}function en(...r){let t=0;for(let n=0;n<r.length;n++){let s=r[n];if(!Yi(s))throw new Error("Uint8Array expected");t+=s.length}let e=new Uint8Array(t);for(let n=0,s=0;n<r.length;n++){let o=r[n];e.set(o,s),s+=o.length}return e}var er=class{clone(){return this._cloneInto()}},Fu={}.toString;function Ji(r,t){if(t!==void 0&&Fu.call(t)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(r,t)}function rn(r){let t=n=>r().update(be(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function nr(r=32){if(tn&&typeof tn.getRandomValues=="function")return tn.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function Hu(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let s=BigInt(32),o=BigInt(4294967295),i=Number(e>>s&o),a=Number(e&o),c=n?4:0,l=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+l,a,n)}var sr=class extends er{constructor(t,e,n,s){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=rr(this.buffer)}update(t){tr(this);let{view:e,buffer:n,blockLen:s}=this;t=be(t);let o=t.length;for(let i=0;i<o;){let a=Math.min(s-this.pos,o-i);if(a===s){let c=rr(t);for(;s<=o-i;i+=s)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===s&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){tr(this),Wi(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:s,isLE:o}=this,{pos:i}=this;e[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>s-i&&(this.process(n,0),i=0);for(let u=i;u<s;u++)e[u]=0;Hu(n,s-8,BigInt(this.length*8),o),this.process(n,0);let a=rr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=c/4,f=this.get();if(l>f.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<l;u++)a.setUint32(4*u,f[u],o)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:s,finished:o,destroyed:i,pos:a}=this;return t.length=s,t.pos=a,t.finished=o,t.destroyed=i,s%e&&t.buffer.set(n),t}};var nn=BigInt(4294967295),Xs=BigInt(32);function Xi(r,t=!1){return t?{h:Number(r&nn),l:Number(r>>Xs&nn)}:{h:Number(r>>Xs&nn)|0,l:Number(r&nn)|0}}function Mu(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let s=0;s<r.length;s++){let{h:o,l:i}=Xi(r[s],t);[e[s],n[s]]=[o,i]}return[e,n]}var Ku=(r,t)=>BigInt(r>>>0)<<Xs|BigInt(t>>>0),$u=(r,t,e)=>r>>>e,qu=(r,t,e)=>r<<32-e|t>>>e,Gu=(r,t,e)=>r>>>e|t<<32-e,zu=(r,t,e)=>r<<32-e|t>>>e,ju=(r,t,e)=>r<<64-e|t>>>e-32,Wu=(r,t,e)=>r>>>e-32|t<<64-e,Yu=(r,t)=>t,Zu=(r,t)=>r,Ju=(r,t,e)=>r<<e|t>>>32-e,Xu=(r,t,e)=>t<<e|r>>>32-e,Qu=(r,t,e)=>t<<e-32|r>>>64-e,tf=(r,t,e)=>r<<e-32|t>>>64-e;function ef(r,t,e,n){let s=(t>>>0)+(n>>>0);return{h:r+e+(s/2**32|0)|0,l:s|0}}var rf=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),nf=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,sf=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),of=(r,t,e,n,s)=>t+e+n+s+(r/2**32|0)|0,af=(r,t,e,n,s)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(s>>>0),cf=(r,t,e,n,s,o)=>t+e+n+s+o+(r/2**32|0)|0;var lf={fromBig:Xi,split:Mu,toBig:Ku,shrSH:$u,shrSL:qu,rotrSH:Gu,rotrSL:zu,rotrBH:ju,rotrBL:Wu,rotr32H:Yu,rotr32L:Zu,rotlSH:Ju,rotlSL:Xu,rotlBH:Qu,rotlBL:tf,add:ef,add3L:rf,add3H:nf,add4L:sf,add4H:of,add5H:cf,add5L:af},C=lf;var[uf,ff]=C.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))),we=new Uint32Array(80),xe=new Uint32Array(80),Qs=class extends sr{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:t,Al:e,Bh:n,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:l,El:f,Fh:u,Fl:h,Gh:m,Gl:g,Hh:d,Hl:p}=this;return[t,e,n,s,o,i,a,c,l,f,u,h,m,g,d,p]}set(t,e,n,s,o,i,a,c,l,f,u,h,m,g,d,p){this.Ah=t|0,this.Al=e|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=l|0,this.El=f|0,this.Fh=u|0,this.Fl=h|0,this.Gh=m|0,this.Gl=g|0,this.Hh=d|0,this.Hl=p|0}process(t,e){for(let w=0;w<16;w++,e+=4)we[w]=t.getUint32(e),xe[w]=t.getUint32(e+=4);for(let w=16;w<80;w++){let T=we[w-15]|0,x=xe[w-15]|0,A=C.rotrSH(T,x,1)^C.rotrSH(T,x,8)^C.shrSH(T,x,7),R=C.rotrSL(T,x,1)^C.rotrSL(T,x,8)^C.shrSL(T,x,7),N=we[w-2]|0,q=xe[w-2]|0,K=C.rotrSH(N,q,19)^C.rotrBH(N,q,61)^C.shrSH(N,q,6),P=C.rotrSL(N,q,19)^C.rotrBL(N,q,61)^C.shrSL(N,q,6),nt=C.add4L(R,P,xe[w-7],xe[w-16]),rt=C.add4H(nt,A,K,we[w-7],we[w-16]);we[w]=rt|0,xe[w]=nt|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:l,Dl:f,Eh:u,El:h,Fh:m,Fl:g,Gh:d,Gl:p,Hh:y,Hl:v}=this;for(let w=0;w<80;w++){let T=C.rotrSH(u,h,14)^C.rotrSH(u,h,18)^C.rotrBH(u,h,41),x=C.rotrSL(u,h,14)^C.rotrSL(u,h,18)^C.rotrBL(u,h,41),A=u&m^~u&d,R=h&g^~h&p,N=C.add5L(v,x,R,ff[w],xe[w]),q=C.add5H(N,y,T,A,uf[w],we[w]),K=N|0,P=C.rotrSH(n,s,28)^C.rotrBH(n,s,34)^C.rotrBH(n,s,39),nt=C.rotrSL(n,s,28)^C.rotrBL(n,s,34)^C.rotrBL(n,s,39),rt=n&o^n&a^o&a,Nt=s&i^s&c^i&c;y=d|0,v=p|0,d=m|0,p=g|0,m=u|0,g=h|0,{h:u,l:h}=C.add(l|0,f|0,q|0,K|0),l=a|0,f=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let E=C.add3L(K,nt,Nt);n=C.add3H(E,q,P,rt),s=E|0}({h:n,l:s}=C.add(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=C.add(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=C.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:f}=C.add(this.Dh|0,this.Dl|0,l|0,f|0),{h:u,l:h}=C.add(this.Eh|0,this.El|0,u|0,h|0),{h:m,l:g}=C.add(this.Fh|0,this.Fl|0,m|0,g|0),{h:d,l:p}=C.add(this.Gh|0,this.Gl|0,d|0,p|0),{h:y,l:v}=C.add(this.Hh|0,this.Hl|0,y|0,v|0),this.set(n,s,o,i,a,c,l,f,u,h,m,g,d,p,y,v)}roundClean(){we.fill(0),xe.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 or=rn(()=>new Qs);var on={};lt(on,{bitGet:()=>bf,bitLen:()=>yf,bitMask:()=>Rr,bitSet:()=>wf,bytesToHex:()=>Jt,bytesToNumberBE:()=>Xt,bytesToNumberLE:()=>ve,concatBytes:()=>Qt,createHmacDrbg:()=>ro,ensureBytes:()=>et,equalBytes:()=>gf,hexToBytes:()=>Pe,hexToNumber:()=>eo,isBytes:()=>Dt,numberToBytesBE:()=>Ee,numberToBytesLE:()=>Oe,numberToHexUnpadded:()=>ra,numberToVarBytesBE:()=>pf,utf8ToBytes:()=>mf,validateObject:()=>Kt});var ea=BigInt(0),sn=BigInt(1),hf=BigInt(2);function Dt(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var df=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Jt(r){if(!Dt(r))throw new Error("Uint8Array expected");let t="";for(let e=0;e<r.length;e++)t+=df[r[e]];return t}function ra(r){let t=r.toString(16);return t.length&1?`0${t}`:t}function eo(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var Zt={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function Qi(r){if(r>=Zt._0&&r<=Zt._9)return r-Zt._0;if(r>=Zt._A&&r<=Zt._F)return r-(Zt._A-10);if(r>=Zt._a&&r<=Zt._f)return r-(Zt._a-10)}function Pe(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let t=r.length,e=t/2;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let s=0,o=0;s<e;s++,o+=2){let i=Qi(r.charCodeAt(o)),a=Qi(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 Xt(r){return eo(Jt(r))}function ve(r){if(!Dt(r))throw new Error("Uint8Array expected");return eo(Jt(Uint8Array.from(r).reverse()))}function Ee(r,t){return Pe(r.toString(16).padStart(t*2,"0"))}function Oe(r,t){return Ee(r,t).reverse()}function pf(r){return Pe(ra(r))}function et(r,t,e){let n;if(typeof t=="string")try{n=Pe(t)}catch(o){throw new Error(`${r} must be valid hex string, got "${t}". Cause: ${o}`)}else if(Dt(t))n=Uint8Array.from(t);else throw new Error(`${r} must be hex string or Uint8Array`);let s=n.length;if(typeof e=="number"&&s!==e)throw new Error(`${r} expected ${e} bytes, got ${s}`);return n}function Qt(...r){let t=0;for(let s=0;s<r.length;s++){let o=r[s];if(!Dt(o))throw new Error("Uint8Array expected");t+=o.length}let e=new Uint8Array(t),n=0;for(let s=0;s<r.length;s++){let o=r[s];e.set(o,n),n+=o.length}return e}function gf(r,t){if(r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}function mf(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function yf(r){let t;for(t=0;r>ea;r>>=sn,t+=1);return t}function bf(r,t){return r>>BigInt(t)&sn}var wf=(r,t,e)=>r|(e?sn:ea)<<BigInt(t),Rr=r=>(hf<<BigInt(r-1))-sn,to=r=>new Uint8Array(r),ta=r=>Uint8Array.from(r);function ro(r,t,e){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof e!="function")throw new Error("hmacFn must be a function");let n=to(r),s=to(r),o=0,i=()=>{n.fill(1),s.fill(0),o=0},a=(...u)=>e(s,n,...u),c=(u=to())=>{s=a(ta([0]),u),n=a(),u.length!==0&&(s=a(ta([1]),u),n=a())},l=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let u=0,h=[];for(;u<t;){n=a();let m=n.slice();h.push(m),u+=n.length}return Qt(...h)};return(u,h)=>{i(),c(u);let m;for(;!(m=h(l()));)c();return i(),m}}var xf={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"||Dt(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function Kt(r,t,e={}){let n=(s,o,i)=>{let a=xf[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(t))n(s,o,!1);for(let[s,o]of Object.entries(e))n(s,o,!0);return r}var ct=BigInt(0),J=BigInt(1),Ve=BigInt(2),vf=BigInt(3),no=BigInt(4),na=BigInt(5),sa=BigInt(8),Ef=BigInt(9),Bf=BigInt(16);function Y(r,t){let e=r%t;return e>=ct?e:t+e}function Af(r,t,e){if(e<=ct||t<ct)throw new Error("Expected power/modulo > 0");if(e===J)return ct;let n=J;for(;t>ct;)t&J&&(n=n*r%e),r=r*r%e,t>>=J;return n}function X(r,t,e){let n=r;for(;t-- >ct;)n*=n,n%=e;return n}function an(r,t){if(r===ct||t<=ct)throw new Error(`invert: expected positive integers, got n=${r} mod=${t}`);let e=Y(r,t),n=t,s=ct,o=J,i=J,a=ct;for(;e!==ct;){let l=n/e,f=n%e,u=s-i*l,h=o-a*l;n=e,e=f,s=i,o=a,i=u,a=h}if(n!==J)throw new Error("invert: does not exist");return Y(s,t)}function Sf(r){let t=(r-J)/Ve,e,n,s;for(e=r-J,n=0;e%Ve===ct;e/=Ve,n++);for(s=Ve;s<r&&Af(s,t,r)!==r-J;s++);if(n===1){let i=(r+J)/no;return function(c,l){let f=c.pow(l,i);if(!c.eql(c.sqr(f),l))throw new Error("Cannot find square root");return f}}let o=(e+J)/Ve;return function(a,c){if(a.pow(c,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let l=n,f=a.pow(a.mul(a.ONE,s),e),u=a.pow(c,o),h=a.pow(c,e);for(;!a.eql(h,a.ONE);){if(a.eql(h,a.ZERO))return a.ZERO;let m=1;for(let d=a.sqr(h);m<l&&!a.eql(d,a.ONE);m++)d=a.sqr(d);let g=a.pow(f,J<<BigInt(l-m-1));f=a.sqr(g),u=a.mul(u,g),h=a.mul(h,f),l=m}return u}}function kf(r){if(r%no===vf){let t=(r+J)/no;return function(n,s){let o=n.pow(s,t);if(!n.eql(n.sqr(o),s))throw new Error("Cannot find square root");return o}}if(r%sa===na){let t=(r-na)/sa;return function(n,s){let o=n.mul(s,Ve),i=n.pow(o,t),a=n.mul(s,i),c=n.mul(n.mul(a,Ve),i),l=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(l),s))throw new Error("Cannot find square root");return l}}return r%Bf,Sf(r)}var oa=(r,t)=>(Y(r,t)&J)===J,If=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function so(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=If.reduce((n,s)=>(n[s]="function",n),t);return Kt(r,e)}function Rf(r,t,e){if(e<ct)throw new Error("Expected power > 0");if(e===ct)return r.ONE;if(e===J)return t;let n=r.ONE,s=t;for(;e>ct;)e&J&&(n=r.mul(n,s)),s=r.sqr(s),e>>=J;return n}function Nf(r,t){let e=new Array(t.length),n=t.reduce((o,i,a)=>r.is0(i)?o:(e[a]=o,r.mul(o,i)),r.ONE),s=r.inv(n);return t.reduceRight((o,i,a)=>r.is0(i)?o:(e[a]=r.mul(o,e[a]),r.mul(o,i)),s),e}function oo(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function cn(r,t,e=!1,n={}){if(r<=ct)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:s,nByteLength:o}=oo(r,t);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let i=kf(r),a=Object.freeze({ORDER:r,BITS:s,BYTES:o,MASK:Rr(s),ZERO:ct,ONE:J,create:c=>Y(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return ct<=c&&c<r},is0:c=>c===ct,isOdd:c=>(c&J)===J,neg:c=>Y(-c,r),eql:(c,l)=>c===l,sqr:c=>Y(c*c,r),add:(c,l)=>Y(c+l,r),sub:(c,l)=>Y(c-l,r),mul:(c,l)=>Y(c*l,r),pow:(c,l)=>Rf(a,c,l),div:(c,l)=>Y(c*an(l,r),r),sqrN:c=>c*c,addN:(c,l)=>c+l,subN:(c,l)=>c-l,mulN:(c,l)=>c*l,inv:c=>an(c,r),sqrt:n.sqrt||(c=>i(a,c)),invertBatch:c=>Nf(a,c),cmov:(c,l,f)=>f?l:c,toBytes:c=>e?Oe(c,o):Ee(c,o),fromBytes:c=>{if(c.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);return e?ve(c):Xt(c)}});return Object.freeze(a)}function ia(r,t){if(!r.isOdd)throw new Error("Field doesn't have isOdd");let e=r.sqrt(t);return r.isOdd(e)?r.neg(e):e}function aa(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function io(r){let t=aa(r);return t+Math.ceil(t/2)}function ca(r,t,e=!1){let n=r.length,s=aa(t),o=io(t);if(n<16||n<o||n>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${n}`);let i=e?Xt(r):ve(r),a=Y(i,t-J)+J;return e?Oe(a,s):Ee(a,s)}var Lf=BigInt(0),ao=BigInt(1);function ln(r,t){let e=(s,o)=>{let i=o.negate();return s?i:o},n=s=>{let o=Math.ceil(t/s)+1,i=2**(s-1);return{windows:o,windowSize:i}};return{constTimeNegate:e,unsafeLadder(s,o){let i=r.ZERO,a=s;for(;o>Lf;)o&ao&&(i=i.add(a)),a=a.double(),o>>=ao;return i},precomputeWindow(s,o){let{windows:i,windowSize:a}=n(o),c=[],l=s,f=l;for(let u=0;u<i;u++){f=l,c.push(f);for(let h=1;h<a;h++)f=f.add(l),c.push(f);l=f.double()}return c},wNAF(s,o,i){let{windows:a,windowSize:c}=n(s),l=r.ZERO,f=r.BASE,u=BigInt(2**s-1),h=2**s,m=BigInt(s);for(let g=0;g<a;g++){let d=g*c,p=Number(i&u);i>>=m,p>c&&(p-=h,i+=ao);let y=d,v=d+Math.abs(p)-1,w=g%2!==0,T=p<0;p===0?f=f.add(e(w,o[y])):l=l.add(e(T,o[v]))}return{p:l,f}},wNAFCached(s,o,i,a){let c=s._WINDOW_SIZE||1,l=o.get(s);return l||(l=this.precomputeWindow(s,c),c!==1&&o.set(s,a(l))),this.wNAF(c,l,i)}}}function Nr(r){return so(r.Fp),Kt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...oo(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Pt=BigInt(0),It=BigInt(1),un=BigInt(2),_f=BigInt(8),Uf={zip215:!0};function Cf(r){let t=Nr(r);return Kt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function fn(r){let t=Cf(r),{Fp:e,n,prehash:s,hash:o,randomBytes:i,nByteLength:a,h:c}=t,l=un<<BigInt(a*8)-It,f=e.create,u=t.uvRatio||((B,b)=>{try{return{isValid:!0,value:e.sqrt(B*e.inv(b))}}catch{return{isValid:!1,value:Pt}}}),h=t.adjustScalarBytes||(B=>B),m=t.domain||((B,b,k)=>{if(b.length||k)throw new Error("Contexts/pre-hash are not supported");return B}),g=B=>typeof B=="bigint"&&Pt<B,d=(B,b)=>g(B)&&g(b)&&B<b,p=B=>B===Pt||d(B,l);function y(B,b){if(d(B,b))return B;throw new Error(`Expected valid scalar < ${b}, got ${typeof B} ${B}`)}function v(B){return B===Pt?B:y(B,n)}let w=new Map;function T(B){if(!(B instanceof x))throw new Error("ExtendedPoint expected")}class x{constructor(b,k,L,_){if(this.ex=b,this.ey=k,this.ez=L,this.et=_,!p(b))throw new Error("x required");if(!p(k))throw new Error("y required");if(!p(L))throw new Error("z required");if(!p(_))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(b){if(b instanceof x)throw new Error("extended point not allowed");let{x:k,y:L}=b||{};if(!p(k)||!p(L))throw new Error("invalid affine point");return new x(k,L,It,f(k*L))}static normalizeZ(b){let k=e.invertBatch(b.map(L=>L.ez));return b.map((L,_)=>L.toAffine(k[_])).map(x.fromAffine)}_setWindowSize(b){this._WINDOW_SIZE=b,w.delete(this)}assertValidity(){let{a:b,d:k}=t;if(this.is0())throw new Error("bad point: ZERO");let{ex:L,ey:_,ez:V,et:F}=this,j=f(L*L),M=f(_*_),$=f(V*V),st=f($*$),Q=f(j*b),ht=f($*f(Q+M)),dt=f(st+f(k*f(j*M)));if(ht!==dt)throw new Error("bad point: equation left != right (1)");let it=f(L*_),yt=f(V*F);if(it!==yt)throw new Error("bad point: equation left != right (2)")}equals(b){T(b);let{ex:k,ey:L,ez:_}=this,{ex:V,ey:F,ez:j}=b,M=f(k*j),$=f(V*_),st=f(L*j),Q=f(F*_);return M===$&&st===Q}is0(){return this.equals(x.ZERO)}negate(){return new x(f(-this.ex),this.ey,this.ez,f(-this.et))}double(){let{a:b}=t,{ex:k,ey:L,ez:_}=this,V=f(k*k),F=f(L*L),j=f(un*f(_*_)),M=f(b*V),$=k+L,st=f(f($*$)-V-F),Q=M+F,ht=Q-j,dt=M-F,it=f(st*ht),yt=f(Q*dt),zt=f(st*dt),Ue=f(ht*Q);return new x(it,yt,Ue,zt)}add(b){T(b);let{a:k,d:L}=t,{ex:_,ey:V,ez:F,et:j}=this,{ex:M,ey:$,ez:st,et:Q}=b;if(k===BigInt(-1)){let mi=f((V-_)*($+M)),yi=f((V+_)*($-M)),vs=f(yi-mi);if(vs===Pt)return this.double();let bi=f(F*un*Q),wi=f(j*un*st),xi=wi+bi,vi=yi+mi,Ei=wi-bi,bl=f(xi*vs),wl=f(vi*Ei),xl=f(xi*Ei),vl=f(vs*vi);return new x(bl,wl,vl,xl)}let ht=f(_*M),dt=f(V*$),it=f(j*L*Q),yt=f(F*st),zt=f((_+V)*(M+$)-ht-dt),Ue=yt-it,Br=yt+it,gi=f(dt-k*ht),pl=f(zt*Ue),gl=f(Br*gi),ml=f(zt*gi),yl=f(Ue*Br);return new x(pl,gl,yl,ml)}subtract(b){return this.add(b.negate())}wNAF(b){return N.wNAFCached(this,w,b,x.normalizeZ)}multiply(b){let{p:k,f:L}=this.wNAF(y(b,n));return x.normalizeZ([k,L])[0]}multiplyUnsafe(b){let k=v(b);return k===Pt?R:this.equals(R)||k===It?this:this.equals(A)?this.wNAF(k).p:N.unsafeLadder(this,k)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return N.unsafeLadder(this,n).is0()}toAffine(b){let{ex:k,ey:L,ez:_}=this,V=this.is0();b==null&&(b=V?_f:e.inv(_));let F=f(k*b),j=f(L*b),M=f(_*b);if(V)return{x:Pt,y:It};if(M!==It)throw new Error("invZ was invalid");return{x:F,y:j}}clearCofactor(){let{h:b}=t;return b===It?this:this.multiplyUnsafe(b)}static fromHex(b,k=!1){let{d:L,a:_}=t,V=e.BYTES;b=et("pointHex",b,V);let F=b.slice(),j=b[V-1];F[V-1]=j&-129;let M=ve(F);M===Pt||(k?y(M,l):y(M,e.ORDER));let $=f(M*M),st=f($-It),Q=f(L*$-_),{isValid:ht,value:dt}=u(st,Q);if(!ht)throw new Error("Point.fromHex: invalid y coordinate");let it=(dt&It)===It,yt=(j&128)!==0;if(!k&&dt===Pt&&yt)throw new Error("Point.fromHex: x=0 and x_0=1");return yt!==it&&(dt=f(-dt)),x.fromAffine({x:dt,y:M})}static fromPrivateKey(b){return P(b).point}toRawBytes(){let{x:b,y:k}=this.toAffine(),L=Oe(k,e.BYTES);return L[L.length-1]|=b&It?128:0,L}toHex(){return Jt(this.toRawBytes())}}x.BASE=new x(t.Gx,t.Gy,It,f(t.Gx*t.Gy)),x.ZERO=new x(Pt,It,It,Pt);let{BASE:A,ZERO:R}=x,N=ln(x,a*8);function q(B){return Y(B,n)}function K(B){return q(ve(B))}function P(B){let b=a;B=et("private key",B,b);let k=et("hashed private key",o(B),2*b),L=h(k.slice(0,b)),_=k.slice(b,2*b),V=K(L),F=A.multiply(V),j=F.toRawBytes();return{head:L,prefix:_,scalar:V,point:F,pointBytes:j}}function nt(B){return P(B).pointBytes}function rt(B=new Uint8Array,...b){let k=Qt(...b);return K(o(m(k,et("context",B),!!s)))}function Nt(B,b,k={}){B=et("message",B),s&&(B=s(B));let{prefix:L,scalar:_,pointBytes:V}=P(b),F=rt(k.context,L,B),j=A.multiply(F).toRawBytes(),M=rt(k.context,j,V,B),$=q(F+M*_);v($);let st=Qt(j,Oe($,e.BYTES));return et("result",st,a*2)}let E=Uf;function I(B,b,k,L=E){let{context:_,zip215:V}=L,F=e.BYTES;B=et("signature",B,2*F),b=et("message",b),s&&(b=s(b));let j=ve(B.slice(F,2*F)),M,$,st;try{M=x.fromHex(k,V),$=x.fromHex(B.slice(0,F),V),st=A.multiplyUnsafe(j)}catch{return!1}if(!V&&M.isSmallOrder())return!1;let Q=rt(_,$.toRawBytes(),M.toRawBytes(),b);return $.add(M.multiplyUnsafe(Q)).subtract(st).clearCofactor().equals(x.ZERO)}return A._setWindowSize(8),{CURVE:t,getPublicKey:nt,sign:Nt,verify:I,ExtendedPoint:x,utils:{getExtendedPublicKey:P,randomPrivateKey:()=>i(e.BYTES),precompute(B=8,b=x.BASE){return b._setWindowSize(B),b.multiply(BigInt(3)),b}}}}var lo=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),la=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Ip=BigInt(0),Df=BigInt(1),co=BigInt(2),Pf=BigInt(5),ua=BigInt(10),Of=BigInt(20),Vf=BigInt(40),fa=BigInt(80);function Ff(r){let t=lo,n=r*r%t*r%t,s=X(n,co,t)*n%t,o=X(s,Df,t)*r%t,i=X(o,Pf,t)*o%t,a=X(i,ua,t)*i%t,c=X(a,Of,t)*a%t,l=X(c,Vf,t)*c%t,f=X(l,fa,t)*l%t,u=X(f,fa,t)*l%t,h=X(u,ua,t)*i%t;return{pow_p_5_8:X(h,co,t)*r%t,b2:n}}function Hf(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Mf(r,t){let e=lo,n=Y(t*t*t,e),s=Y(n*n*t,e),o=Ff(r*s).pow_p_5_8,i=Y(r*n*o,e),a=Y(t*i*i,e),c=i,l=Y(i*la,e),f=a===r,u=a===Y(-r,e),h=a===Y(-r*la,e);return f&&(i=c),(u||h)&&(i=l),oa(i,e)&&(i=Y(-i,e)),{isValid:f||u,value:i}}var te=cn(lo,void 0,!0),uo={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:te,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:or,randomBytes:nr,adjustScalarBytes:Hf,uvRatio:Mf},ir=fn(uo);function ha(r,t,e){if(t.length>255)throw new Error("Context is too big");return en(Js("SigEd25519 no Ed25519 collisions"),new Uint8Array([e?1:0,t.length]),t,r)}var Rp=fn({...uo,domain:ha}),Np=fn({...uo,domain:ha,prehash:or});var Kf=(te.ORDER+BigInt(3))/BigInt(8),Tp=te.pow(co,Kf),Lp=te.sqrt(te.neg(te.ONE)),_p=(te.ORDER-BigInt(5))/BigInt(8),Up=BigInt(486662);var Cp=ia(te,te.neg(BigInt(486664)));var Dp=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Pp=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Op=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Vp=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var Fp=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var ar=32,ee=64,hn=32;function da(){let r=ir.utils.randomPrivateKey(),t=ir.getPublicKey(r);return{privateKey:ya(r,t),publicKey:t}}function pa(r){if(r.length!==hn)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 t=r,e=ir.getPublicKey(t);return{privateKey:ya(t,e),publicKey:e}}function ga(r,t){let e=r.subarray(0,hn);return ir.sign(t instanceof Uint8Array?t:t.subarray(),e)}function ma(r,t,e){return ir.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}function ya(r,t){let e=new Uint8Array(ee);for(let n=0;n<hn;n++)e[n]=r[n],e[hn+n]=t[n];return e}var At={get(r=globalThis){let t=r.crypto;if(t==null||t.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 t}};var fo={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function ba(r){let t=r?.algorithm??"AES-GCM",e=r?.keyLength??16,n=r?.nonceLength??12,s=r?.digest??"SHA-256",o=r?.saltLength??16,i=r?.iterations??32767,a=At.get();e*=8;async function c(u,h){let m=a.getRandomValues(new Uint8Array(o)),g=a.getRandomValues(new Uint8Array(n)),d={name:t,iv:g};typeof h=="string"&&(h=Z(h));let p;if(h.length===0){p=await a.subtle.importKey("jwk",fo,{name:"AES-GCM"},!0,["encrypt"]);try{let v={name:"PBKDF2",salt:m,iterations:i,hash:{name:s}},w=await a.subtle.importKey("raw",h,{name:"PBKDF2"},!1,["deriveKey"]);p=await a.subtle.deriveKey(v,w,{name:t,length:e},!0,["encrypt"])}catch{p=await a.subtle.importKey("jwk",fo,{name:"AES-GCM"},!0,["encrypt"])}}else{let v={name:"PBKDF2",salt:m,iterations:i,hash:{name:s}},w=await a.subtle.importKey("raw",h,{name:"PBKDF2"},!1,["deriveKey"]);p=await a.subtle.deriveKey(v,w,{name:t,length:e},!0,["encrypt"])}let y=await a.subtle.encrypt(d,p,u);return Bt([m,d.iv,new Uint8Array(y)])}async function l(u,h){let m=u.subarray(0,o),g=u.subarray(o,o+n),d=u.subarray(o+n),p={name:t,iv:g};typeof h=="string"&&(h=Z(h));let y;if(h.length===0)try{let w={name:"PBKDF2",salt:m,iterations:i,hash:{name:s}},T=await a.subtle.importKey("raw",h,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(w,T,{name:t,length:e},!0,["decrypt"])}catch{y=await a.subtle.importKey("jwk",fo,{name:"AES-GCM"},!0,["decrypt"])}else{let w={name:"PBKDF2",salt:m,iterations:i,hash:{name:s}},T=await a.subtle.importKey("raw",h,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(w,T,{name:t,length:e},!0,["decrypt"])}let v=await a.subtle.decrypt(p,y,d);return new Uint8Array(v)}return{encrypt:c,decrypt:l}}async function cr(r,t){let n=await ba().encrypt(r,t);return Os.encode(n)}var Gf=Math.pow(2,7),zf=Math.pow(2,14),jf=Math.pow(2,21),ho=Math.pow(2,28),po=Math.pow(2,35),go=Math.pow(2,42),mo=Math.pow(2,49),G=128,xt=127;function ut(r){if(r<Gf)return 1;if(r<zf)return 2;if(r<jf)return 3;if(r<ho)return 4;if(r<po)return 5;if(r<go)return 6;if(r<mo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function yo(r,t,e=0){switch(ut(r)){case 8:t[e++]=r&255|G,r/=128;case 7:t[e++]=r&255|G,r/=128;case 6:t[e++]=r&255|G,r/=128;case 5:t[e++]=r&255|G,r/=128;case 4:t[e++]=r&255|G,r>>>=7;case 3:t[e++]=r&255|G,r>>>=7;case 2:t[e++]=r&255|G,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Wf(r,t,e=0){switch(ut(r)){case 8:t.set(e++,r&255|G),r/=128;case 7:t.set(e++,r&255|G),r/=128;case 6:t.set(e++,r&255|G),r/=128;case 5:t.set(e++,r&255|G),r/=128;case 4:t.set(e++,r&255|G),r>>>=7;case 3:t.set(e++,r&255|G),r>>>=7;case 2:t.set(e++,r&255|G),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function bo(r,t){let e=r[t],n=0;if(n+=e&xt,e<G||(e=r[t+1],n+=(e&xt)<<7,e<G)||(e=r[t+2],n+=(e&xt)<<14,e<G)||(e=r[t+3],n+=(e&xt)<<21,e<G)||(e=r[t+4],n+=(e&xt)*ho,e<G)||(e=r[t+5],n+=(e&xt)*po,e<G)||(e=r[t+6],n+=(e&xt)*go,e<G)||(e=r[t+7],n+=(e&xt)*mo,e<G))return n;throw new RangeError("Could not decode varint")}function Yf(r,t){let e=r.get(t),n=0;if(n+=e&xt,e<G||(e=r.get(t+1),n+=(e&xt)<<7,e<G)||(e=r.get(t+2),n+=(e&xt)<<14,e<G)||(e=r.get(t+3),n+=(e&xt)<<21,e<G)||(e=r.get(t+4),n+=(e&xt)*ho,e<G)||(e=r.get(t+5),n+=(e&xt)*po,e<G)||(e=r.get(t+6),n+=(e&xt)*go,e<G)||(e=r.get(t+7),n+=(e&xt)*mo,e<G))return n;throw new RangeError("Could not decode varint")}function Be(r,t,e=0){return t==null&&(t=wt(ut(r))),t instanceof Uint8Array?yo(r,t,e):Wf(r,t,e)}function re(r,t=0){return r instanceof Uint8Array?bo(r,t):Yf(r,t)}var wo=new Float32Array([-0]),Ae=new Uint8Array(wo.buffer);function wa(r,t,e){wo[0]=r,t[e]=Ae[0],t[e+1]=Ae[1],t[e+2]=Ae[2],t[e+3]=Ae[3]}function xa(r,t){return Ae[0]=r[t],Ae[1]=r[t+1],Ae[2]=r[t+2],Ae[3]=r[t+3],wo[0]}var xo=new Float64Array([-0]),vt=new Uint8Array(xo.buffer);function va(r,t,e){xo[0]=r,t[e]=vt[0],t[e+1]=vt[1],t[e+2]=vt[2],t[e+3]=vt[3],t[e+4]=vt[4],t[e+5]=vt[5],t[e+6]=vt[6],t[e+7]=vt[7]}function Ea(r,t){return vt[0]=r[t],vt[1]=r[t+1],vt[2]=r[t+2],vt[3]=r[t+3],vt[4]=r[t+4],vt[5]=r[t+5],vt[6]=r[t+6],vt[7]=r[t+7],xo[0]}var Zf=BigInt(Number.MAX_SAFE_INTEGER),Jf=BigInt(Number.MIN_SAFE_INTEGER),Rt=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return Fe;if(t<Zf&&t>Jf)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,s=t-(n<<32n);return e&&(n=~n|0n,s=~s|0n,++s>Ba&&(s=0n,++n>Ba&&(n=0n))),new r(Number(s),Number(n))}static fromNumber(t){if(t===0)return Fe;let e=t<0;e&&(t=-t);let n=t>>>0,s=(t-n)/4294967296>>>0;return e&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new r(n,s)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):Fe}},Fe=new Rt(0,0);Fe.toBigInt=function(){return 0n};Fe.zzEncode=Fe.zzDecode=function(){return this};Fe.length=function(){return 1};var Ba=4294967296n;function Aa(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Sa(r,t,e){if(e-t<1)return"";let s,o=[],i=0,a;for(;t<e;)a=r[t++],a<128?o[i++]=a:a>191&&a<224?o[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,o[i++]=55296+(a>>10),o[i++]=56320+(a&1023)):o[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,o)),i=0);return s!=null?(i>0&&s.push(String.fromCharCode.apply(String,o.slice(0,i))),s.join("")):String.fromCharCode.apply(String,o.slice(0,i))}function vo(r,t,e){let n=e,s,o;for(let i=0;i<r.length;++i)s=r.charCodeAt(i),s<128?t[e++]=s:s<2048?(t[e++]=s>>6|192,t[e++]=s&63|128):(s&64512)===55296&&((o=r.charCodeAt(i+1))&64512)===56320?(s=65536+((s&1023)<<10)+(o&1023),++i,t[e++]=s>>18|240,t[e++]=s>>12&63|128,t[e++]=s>>6&63|128,t[e++]=s&63|128):(t[e++]=s>>12|224,t[e++]=s>>6&63|128,t[e++]=s&63|128);return e-n}function Ot(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function pn(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Eo=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Ot(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ot(this,4);return pn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ot(this,4);return pn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ot(this,4);let t=xa(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Ot(this,4);let t=Ea(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw Ot(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Sa(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Ot(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Ot(this);while(this.buf[this.pos++]&128);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Rt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw Ot(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw Ot(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ot(this,8);let t=pn(this.buf,this.pos+=4),e=pn(this.buf,this.pos+=4);return new Rt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=bo(this.buf,this.pos);return this.pos+=ut(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Bo(r){return new Eo(r instanceof Uint8Array?r:r.subarray())}function ne(r,t,e){let n=Bo(r);return t.decode(n,void 0,e)}function Ao(r){let t=r??8192,e=t>>>1,n,s=t;return function(i){if(i<1||i>e)return wt(i);s+i>t&&(n=wt(t),s=0);let a=n.subarray(s,s+=i);return s&7&&(s=(s|7)+1),a}}var He=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function So(){}var Io=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Xf=Ao();function Qf(r){return globalThis.Buffer!=null?wt(r):Xf(r)}var Lr=class{len;head;tail;states;constructor(){this.len=0,this.head=new He(So,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new He(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Ro((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(gn,10,Rt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Rt.fromBigInt(t);return this._push(gn,e.length(),e)}uint64Number(t){return this._push(yo,ut(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=Rt.fromBigInt(t).zzEncode();return this._push(gn,e.length(),e)}sint64Number(t){let e=Rt.fromNumber(t).zzEncode();return this._push(gn,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ko,1,t?1:0)}fixed32(t){return this._push(Tr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Rt.fromBigInt(t);return this._push(Tr,4,e.lo)._push(Tr,4,e.hi)}fixed64Number(t){let e=Rt.fromNumber(t);return this._push(Tr,4,e.lo)._push(Tr,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(wa,4,t)}double(t){return this._push(va,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(ko,1,0):this.uint32(e)._push(eh,e,t)}string(t){let e=Aa(t);return e!==0?this.uint32(e)._push(vo,e,t):this._push(ko,1,0)}fork(){return this.states=new Io(this),this.head=this.tail=new He(So,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 He(So,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Qf(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function ko(r,t,e){t[e]=r&255}function th(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Ro=class extends He{next;constructor(t,e){super(th,t,e),this.next=void 0}};function gn(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function Tr(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function eh(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Lr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(rh,t,r),this},Lr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(nh,t,r),this});function rh(r,t,e){t.set(r,e)}function nh(r,t,e){r.length<40?vo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(Z(r),e)}function No(){return new Lr}function se(r,t){let e=No();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var lr;(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"})(lr||(lr={}));function mn(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function ur(r){function t(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let e=function(o,i){let a=t(o);i.int32(a)},n=function(o){let i=o.int32();return t(i)};return mn("enum",lr.VARINT,e,n)}function oe(r,t){return mn("message",lr.LENGTH_DELIMITED,r,t)}var gt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1"})(gt||(gt={}));var To;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1"})(To||(To={}));(function(r){r.codec=()=>ur(To)})(gt||(gt={}));var Se;(function(r){let t;r.codec=()=>(t==null&&(t=oe((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),gt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),s.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let s={},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let i=e.uint32();switch(i>>>3){case 1:s.Type=gt.codec().decode(e);break;case 2:s.Data=e.bytes();break;default:e.skipType(i&7);break}}return s})),t),r.encode=e=>se(e,r.codec()),r.decode=e=>ne(e,r.codec())})(Se||(Se={}));var ke;(function(r){let t;r.codec=()=>(t==null&&(t=oe((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),gt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),s.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let s={},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let i=e.uint32();switch(i>>>3){case 1:s.Type=gt.codec().decode(e);break;case 2:s.Data=e.bytes();break;default:e.skipType(i&7);break}}return s})),t),r.encode=e=>se(e,r.codec()),r.decode=e=>ne(e,r.codec())})(ke||(ke={}));var _r=class{_key;constructor(t){this._key=fr(t,ar)}verify(t,e){return ma(this._key,e,t)}marshal(){return this._key}get bytes(){return Se.encode({Type:gt.Ed25519,Data:this.marshal()}).subarray()}equals(t){return bt(this.bytes,t.bytes)}hash(){let t=pt.digest(this.bytes);return Tt(t)?t.then(({bytes:e})=>e):t.bytes}},Me=class{_key;_publicKey;constructor(t,e){this._key=fr(t,ee),this._publicKey=fr(e,ar)}sign(t){return ga(this._key,t)}get public(){return new _r(this._publicKey)}marshal(){return this._key}get bytes(){return ke.encode({Type:gt.Ed25519,Data:this.marshal()}).subarray()}equals(t){return bt(this.bytes,t.bytes)}async hash(){let t=pt.digest(this.bytes),e;return Tt(t)?{bytes:e}=await t:e=t.bytes,e}async id(){let t=ge.digest(this.public.bytes);return at.encode(t.bytes).substring(1)}async export(t,e="libp2p-key"){if(e==="libp2p-key")return cr(this.bytes,t);throw new U(`export format '${e}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function sh(r){if(r.length>ee){r=fr(r,ee+ar);let n=r.subarray(0,ee),s=r.subarray(ee,r.length);return new Me(n,s)}r=fr(r,ee);let t=r.subarray(0,ee),e=r.subarray(ar);return new Me(t,e)}function oh(r){return r=fr(r,ar),new _r(r)}async function ih(){let{privateKey:r,publicKey:t}=da();return new Me(r,t)}async function Ia(r){let{privateKey:t,publicKey:e}=pa(r);return new Me(t,e)}function fr(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new U(`Key must be a Uint8Array of length ${t}, got ${r.length}`,"ERR_INVALID_KEY_TYPE");return r}function z(r,t="utf8"){let e=Xr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):e.encoder.encode(r).substring(1)}var Ko={};lt(Ko,{MAX_RSA_KEY_SIZE:()=>qr,RsaPrivateKey:()=>mr,RsaPublicKey:()=>$r,fromJwk:()=>Uh,generateKeyPair:()=>Ch,unmarshalRsaPrivateKey:()=>Ho,unmarshalRsaPublicKey:()=>_h});function Ke(r){if(isNaN(r)||r<=0)throw new U("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return nr(r)}var Te={};lt(Te,{exportToPem:()=>Ih,importFromPem:()=>Rh,jwkToPkcs1:()=>Bh,jwkToPkix:()=>Sh,pkcs1ToJwk:()=>Eh,pkixToJwk:()=>Ah});var yn=class extends er{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Qr(t);let n=be(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let s=this.blockLen,o=new Uint8Array(s);o.set(n.length>s?t.create().update(n).digest():n);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=t.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),o.fill(0)}update(t){return tr(this),this.iHash.update(t),this}digestInto(t){tr(this),Zs(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:s,destroyed:o,blockLen:i,outputLen:a}=this;return t=t,t.finished=s,t.destroyed=o,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ur=(r,t,e)=>new yn(r,t).update(e).digest();Ur.create=(r,t)=>new yn(r,t);function ah(r,t,e,n){Qr(r);let s=Ji({dkLen:32,asyncTick:10},n),{c:o,dkLen:i,asyncTick:a}=s;if(Qe(o),Qe(i),Qe(a),o<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=be(t),l=be(e),f=new Uint8Array(i),u=Ur.create(r,c),h=u._cloneInto().update(l);return{c:o,dkLen:i,asyncTick:a,DK:f,PRF:u,PRFSalt:h}}function ch(r,t,e,n,s){return r.destroy(),t.destroy(),n&&n.destroy(),s.fill(0),e}async function Uo(r,t,e,n){let{c:s,dkLen:o,asyncTick:i,DK:a,PRF:c,PRFSalt:l}=ah(r,t,e,n),f,u=new Uint8Array(4),h=rr(u),m=new Uint8Array(c.outputLen);for(let g=1,d=0;d<o;g++,d+=c.outputLen){let p=a.subarray(d,d+c.outputLen);h.setInt32(0,g,!1),(f=l._cloneInto(f)).update(u).digestInto(m),p.set(m.subarray(0,p.length)),await Zi(s-1,i,()=>{c._cloneInto(f).update(m).digestInto(m);for(let y=0;y<p.length;y++)p[y]^=m[y]})}return ch(c,l,a,f,m)}var H=Bs(Ra());function $e(r,t){let e=0;if(r.length===1)return r[0];for(let n=r.length-1;n>=0;n--)e+=r[r.length-1-n]*Math.pow(2,t*n);return e}function Ie(r,t,e=-1){let n=e,s=r,o=0,i=Math.pow(2,t);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 l=new Uint8Array(c);for(let f=a-1;f>=0;f--){let u=Math.pow(2,f*t);l[o-f-1]=Math.floor(s/u),s-=l[o-f-1]*u}return c}i*=Math.pow(2,t)}return new ArrayBuffer(0)}function xn(...r){let t=0,e=0;for(let o of r)t+=o.length;let n=new ArrayBuffer(t),s=new Uint8Array(n);for(let o of r)s.set(o,e),e+=o.length;return s}function Do(){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 t=new ArrayBuffer(this.valueHex.byteLength),e=new Uint8Array(t);for(let a=0;a<this.valueHex.byteLength;a++)e[a]=0;e[0]=r[0]&128;let n=$e(e,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,$e(o,8)-n}function Na(r){let t=r<0?r*-1:r,e=128;for(let n=1;n<8;n++){if(t<=e){if(r<0){let i=e-t,a=Ie(i,8,n),c=new Uint8Array(a);return c[0]|=128,a}let s=Ie(t,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}e*=Math.pow(2,8)}return new ArrayBuffer(0)}function Ta(r,t){if(r.byteLength!==t.byteLength)return!1;let e=new Uint8Array(r),n=new Uint8Array(t);for(let s=0;s<e.length;s++)if(e[s]!==n[s])return!1;return!0}function kt(r,t){let e=r.toString(10);if(t<e.length)return"";let n=t-e.length,s=new Array(n);for(let i=0;i<n;i++)s[i]="0";return s.join("").concat(e)}var jg=Math.log(2);function vn(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Po(r){let t=0,e=0;for(let s=0;s<r.length;s++){let o=r[s];t+=o.byteLength}let n=new Uint8Array(t);for(let s=0;s<r.length;s++){let o=r[s];n.set(new Uint8Array(o),e),e+=o.byteLength}return n.buffer}function ue(r,t,e,n){return t instanceof Uint8Array?t.byteLength?e<0?(r.error="Wrong parameter: inputOffset less than zero",!1):n<0?(r.error="Wrong parameter: inputLength less than zero",!1):t.byteLength-e-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 Dr=class{constructor(){this.items=[]}write(t){this.items.push(t)}final(){return Po(this.items)}},Cr=[new Uint8Array([1])],La="0123456789";var pr="",Ft=new ArrayBuffer(0),Oo=new Uint8Array(0),Pr="EndOfContent",Ua="OCTET STRING",Ca="BIT STRING";function fe(r){var t;return t=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?H.BufferSourceConverter.toUint8Array(o.valueHex):Oo}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(!ue(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:H.Convert.ToHex(this.valueHexView)}}},t.NAME="hexBlock",t}var ae=class{constructor({blockLength:t=0,error:e=pr,warnings:n=[],valueBeforeDecode:s=Oo}={}){this.blockLength=t,this.error=e,this.warnings=n,this.valueBeforeDecodeView=H.BufferSourceConverter.toUint8Array(s)}static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(t){this.valueBeforeDecodeView=new Uint8Array(t)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:H.Convert.ToHex(this.valueBeforeDecodeView)}}};ae.NAME="baseBlock";var Et=class extends ae{fromBER(t,e,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(t,e){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}};Et.NAME="valueBlock";var En=class extends fe(ae){constructor({idBlock:t={}}={}){var e,n,s,o;super(),t?(this.isHexOnly=(e=t.isHexOnly)!==null&&e!==void 0?e:!1,this.valueHexView=t.valueHex?H.BufferSourceConverter.toUint8Array(t.valueHex):Oo,this.tagClass=(n=t.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(s=t.tagNumber)!==null&&s!==void 0?s:-1,this.isConstructed=(o=t.isConstructed)!==null&&o!==void 0?o:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(t=!1){let e=0;switch(this.tagClass){case 1:e|=0;break;case 2:e|=64;break;case 3:e|=128;break;case 4:e|=192;break;default:return this.error="Unknown tag class",Ft}if(this.isConstructed&&(e|=32),this.tagNumber<31&&!this.isHexOnly){let s=new Uint8Array(1);if(!t){let o=this.tagNumber;o&=31,e|=o,s[0]=e}return s.buffer}if(!this.isHexOnly){let s=Ie(this.tagNumber,7),o=new Uint8Array(s),i=s.byteLength,a=new Uint8Array(i+1);if(a[0]=e|31,!t){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]=e|31,!t){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(t,e,n){let s=H.BufferSourceConverter.toUint8Array(t);if(!ue(this,s,e,n))return-1;let o=s.subarray(e,e+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,l=this.valueHexView=new Uint8Array(255),f=255;for(;o[c]&128;){if(l[c-1]=o[c]&127,c++,c>=o.length)return this.error="End of input reached before message was fully decoded",-1;if(c===f){f+=255;let h=new Uint8Array(f);for(let m=0;m<l.length;m++)h[m]=l[m];l=this.valueHexView=new Uint8Array(f)}}this.blockLength=c+1,l[c-1]=o[c]&127;let u=new Uint8Array(c);for(let h=0;h<c;h++)u[h]=l[h];l=this.valueHexView=new Uint8Array(c),l.set(u),this.blockLength<=9?this.tagNumber=$e(l,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 e+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}};En.NAME="identificationBlock";var Bn=class extends ae{constructor({lenBlock:t={}}={}){var e,n,s;super(),this.isIndefiniteForm=(e=t.isIndefiniteForm)!==null&&e!==void 0?e:!1,this.longFormUsed=(n=t.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(s=t.length)!==null&&s!==void 0?s:0}fromBER(t,e,n){let s=H.BufferSourceConverter.toUint8Array(t);if(!ue(this,s,e,n))return-1;let o=s.subarray(e,e+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,e+this.blockLength;if(this.longFormUsed=!!(o[0]&128),this.longFormUsed===!1)return this.length=o[0],this.blockLength=1,e+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=e+1,c=s.subarray(a,a+i);return c[i-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=$e(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=i+1,e+this.blockLength}toBER(t=!1){let e,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return e=new ArrayBuffer(1),t===!1&&(n=new Uint8Array(e),n[0]=128),e;if(this.longFormUsed){let s=Ie(this.length,8);if(s.byteLength>127)return this.error="Too big length",Ft;if(e=new ArrayBuffer(s.byteLength+1),t)return e;let o=new Uint8Array(s);n=new Uint8Array(e),n[0]=s.byteLength|128;for(let i=0;i<s.byteLength;i++)n[i+1]=o[i];return e}return e=new ArrayBuffer(1),t===!1&&(n=new Uint8Array(e),n[0]=this.length),e}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};Bn.NAME="lengthBlock";var S={},mt=class extends ae{constructor({name:t=pr,optional:e=!1,primitiveSchema:n,...s}={},o){super(s),this.name=t,this.optional=e,n&&(this.primitiveSchema=n),this.idBlock=new En(s),this.lenBlock=new Bn(s),this.valueBlock=o?new o(s):new Et(s)}fromBER(t,e,n){let s=this.valueBlock.fromBER(t,e,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(t,e){let n=e||new Dr;e||Da(this);let s=this.idBlock.toBER(t);if(n.write(s),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(t,n),n.write(new ArrayBuffer(2));else{let o=this.valueBlock.toBER(t);this.lenBlock.length=o.byteLength;let i=this.lenBlock.toBER(t);n.write(i),n.write(o)}return e?Ft:n.final()}toJSON(){let t={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(t.primitiveSchema=this.primitiveSchema.toJSON()),t}toString(t="ascii"){return t==="ascii"?this.onAsciiEncoding():H.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${H.Convert.ToHex(this.valueBlock.valueBeforeDecodeView)}`}isEqual(t){if(this===t)return!0;if(!(t instanceof this.constructor))return!1;let e=this.toBER(),n=t.toBER();return Ta(e,n)}};mt.NAME="BaseBlock";function Da(r){if(r instanceof S.Constructed)for(let t of r.valueBlock.value)Da(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var An=class extends mt{constructor({value:t=pr,...e}={},n){super(e,n),t&&this.fromString(t)}getValue(){return this.valueBlock.value}setValue(t){this.valueBlock.value=t}fromBER(t,e,n){let s=this.valueBlock.fromBER(t,e,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}'`}};An.NAME="BaseStringBlock";var Sn=class extends fe(Et){constructor({isHexOnly:t=!0,...e}={}){super(e),this.isHexOnly=t}};Sn.NAME="PrimitiveValueBlock";var Pa,kn=class extends mt{constructor(t={}){super(t,Sn),this.idBlock.isConstructed=!1}};Pa=kn;S.Primitive=Pa;kn.NAME="PRIMITIVE";function yh(r,t){if(r instanceof t)return r;let e=new t;return e.idBlock=r.idBlock,e.lenBlock=r.lenBlock,e.warnings=r.warnings,e.valueBeforeDecodeView=r.valueBeforeDecodeView,e}function os(r,t=0,e=r.length){let n=t,s=new mt({},Et),o=new ae;if(!ue(o,r,t,e))return s.error=o.error,{offset:-1,result:s};if(!r.subarray(t,t+e).length)return s.error="Zero buffer length",{offset:-1,result:s};let a=s.idBlock.fromBER(r,t,e);if(s.idBlock.warnings.length&&s.warnings.concat(s.idBlock.warnings),a===-1)return s.error=s.idBlock.error,{offset:-1,result:s};if(t=a,e-=s.idBlock.blockLength,a=s.lenBlock.fromBER(r,t,e),s.lenBlock.warnings.length&&s.warnings.concat(s.lenBlock.warnings),a===-1)return s.error=s.lenBlock.error,{offset:-1,result:s};if(t=a,e-=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=mt;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=S.EndOfContent;break;case 1:c=S.Boolean;break;case 2:c=S.Integer;break;case 3:c=S.BitString;break;case 4:c=S.OctetString;break;case 5:c=S.Null;break;case 6:c=S.ObjectIdentifier;break;case 10:c=S.Enumerated;break;case 12:c=S.Utf8String;break;case 13:c=S.RelativeObjectIdentifier;break;case 14:c=S.TIME;break;case 15:return s.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:s};case 16:c=S.Sequence;break;case 17:c=S.Set;break;case 18:c=S.NumericString;break;case 19:c=S.PrintableString;break;case 20:c=S.TeletexString;break;case 21:c=S.VideotexString;break;case 22:c=S.IA5String;break;case 23:c=S.UTCTime;break;case 24:c=S.GeneralizedTime;break;case 25:c=S.GraphicString;break;case 26:c=S.VisibleString;break;case 27:c=S.GeneralString;break;case 28:c=S.UniversalString;break;case 29:c=S.CharacterString;break;case 30:c=S.BmpString;break;case 31:c=S.DATE;break;case 32:c=S.TimeOfDay;break;case 33:c=S.DateTime;break;case 34:c=S.Duration;break;default:{let l=s.idBlock.isConstructed?new S.Constructed:new S.Primitive;l.idBlock=s.idBlock,l.lenBlock=s.lenBlock,l.warnings=s.warnings,s=l}}break;case 2:case 3:case 4:default:c=s.idBlock.isConstructed?S.Constructed:S.Primitive}return s=yh(s,c),a=s.fromBER(r,t,s.lenBlock.isIndefiniteForm?e:s.lenBlock.length),s.valueBeforeDecodeView=r.subarray(n,n+s.blockLength),{offset:a,result:s}}function gr(r){if(!r.byteLength){let t=new mt({},Et);return t.error="Input buffer has zero length",{offset:-1,result:t}}return os(H.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function bh(r,t){return r?1:t}var $t=class extends Et{constructor({value:t=[],isIndefiniteForm:e=!1,...n}={}){super(n),this.value=t,this.isIndefiniteForm=e}fromBER(t,e,n){let s=H.BufferSourceConverter.toUint8Array(t);if(!ue(this,s,e,n))return-1;if(this.valueBeforeDecodeView=s.subarray(e,e+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),e;let o=e;for(;bh(this.isIndefiniteForm,n)>0;){let i=os(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===Pr)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===Pr?this.value.pop():this.warnings.push("No EndOfContent block encoded")),o}toBER(t,e){let n=e||new Dr;for(let s=0;s<this.value.length;s++)this.value[s].toBER(t,n);return e?Ft:n.final()}toJSON(){let t={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let e of this.value)t.value.push(e.toJSON());return t}};$t.NAME="ConstructedValueBlock";var Oa,Re=class extends mt{constructor(t={}){super(t,$t),this.idBlock.isConstructed=!0}fromBER(t,e,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let s=this.valueBlock.fromBER(t,e,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 t=[];for(let n of this.valueBlock.value)t.push(n.toString("ascii").split(`
2
+ "use strict";var Libp2PAutonat=(()=>{var El=Object.create;var Zr=Object.defineProperty;var Bl=Object.getOwnPropertyDescriptor;var Al=Object.getOwnPropertyNames;var Sl=Object.getPrototypeOf,kl=Object.prototype.hasOwnProperty;var Es=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),lt=(r,t)=>{for(var e in t)Zr(r,e,{get:t[e],enumerable:!0})},Bi=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Al(t))!kl.call(r,s)&&s!==e&&Zr(r,s,{get:()=>t[s],enumerable:!(n=Bl(t,s))||n.enumerable});return r};var Bs=(r,t,e)=>(e=r!=null?El(Sl(r)):{},Bi(t||!r||!r.__esModule?Zr(e,"default",{value:r,enumerable:!0}):e,r)),Il=r=>Bi(Zr({},"__esModule",{value:!0}),r);var Ra=Es(hr=>{"use strict";var lh="[object ArrayBuffer]",ie=class r{static isArrayBuffer(t){return Object.prototype.toString.call(t)===lh}static toArrayBuffer(t){return this.isArrayBuffer(t)?t:t.byteLength===t.buffer.byteLength||t.byteOffset===0&&t.byteLength===t.buffer.byteLength?t.buffer:this.toUint8Array(t.buffer).slice(t.byteOffset,t.byteOffset+t.byteLength).buffer}static toUint8Array(t){return this.toView(t,Uint8Array)}static toView(t,e){if(t.constructor===e)return t;if(this.isArrayBuffer(t))return new e(t);if(this.isArrayBufferView(t))return new e(t.buffer,t.byteOffset,t.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(t){return this.isArrayBufferView(t)||this.isArrayBuffer(t)}static isArrayBufferView(t){return ArrayBuffer.isView(t)||t&&this.isArrayBuffer(t.buffer)}static isEqual(t,e){let n=r.toUint8Array(t),s=r.toUint8Array(e);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(...t){let e;Array.isArray(t[0])&&!(t[1]instanceof Function)||Array.isArray(t[0])&&t[1]instanceof Function?e=t[0]:t[t.length-1]instanceof Function?e=t.slice(0,t.length-1):e=t;let n=0;for(let i of e)n+=i.byteLength;let s=new Uint8Array(n),o=0;for(let i of e){let a=this.toUint8Array(i);s.set(a,o),o+=a.length}return t[t.length-1]instanceof Function?this.toView(s,t[t.length-1]):s.buffer}},Co="string",uh=/^[0-9a-f]+$/i,fh=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,hh=/^[a-zA-Z0-9-_]+$/,wn=class{static fromString(t){let e=unescape(encodeURIComponent(t)),n=new Uint8Array(e.length);for(let s=0;s<e.length;s++)n[s]=e.charCodeAt(s);return n.buffer}static toString(t){let e=ie.toUint8Array(t),n="";for(let o=0;o<e.length;o++)n+=String.fromCharCode(e[o]);return decodeURIComponent(escape(n))}},Lt=class{static toString(t,e=!1){let n=ie.toArrayBuffer(t),s=new DataView(n),o="";for(let i=0;i<n.byteLength;i+=2){let a=s.getUint16(i,e);o+=String.fromCharCode(a)}return o}static fromString(t,e=!1){let n=new ArrayBuffer(t.length*2),s=new DataView(n);for(let o=0;o<t.length;o++)s.setUint16(o*2,t.charCodeAt(o),e);return n}},xn=class r{static isHex(t){return typeof t===Co&&uh.test(t)}static isBase64(t){return typeof t===Co&&fh.test(t)}static isBase64Url(t){return typeof t===Co&&hh.test(t)}static ToString(t,e="utf8"){let n=ie.toUint8Array(t);switch(e.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 Lt.toString(n,!0);case"utf16":case"utf16be":return Lt.toString(n);default:throw new Error(`Unknown type of encoding '${e}'`)}}static FromString(t,e="utf8"){if(!t)return new ArrayBuffer(0);switch(e.toLowerCase()){case"utf8":return this.FromUtf8String(t);case"binary":return this.FromBinary(t);case"hex":return this.FromHex(t);case"base64":return this.FromBase64(t);case"base64url":return this.FromBase64Url(t);case"utf16le":return Lt.fromString(t,!0);case"utf16":case"utf16be":return Lt.fromString(t);default:throw new Error(`Unknown type of encoding '${e}'`)}}static ToBase64(t){let e=ie.toUint8Array(t);if(typeof btoa<"u"){let n=this.ToString(e,"binary");return btoa(n)}else return Buffer.from(e).toString("base64")}static FromBase64(t){let e=this.formatString(t);if(!e)return new ArrayBuffer(0);if(!r.isBase64(e))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(e)):new Uint8Array(Buffer.from(e,"base64")).buffer}static FromBase64Url(t){let e=this.formatString(t);if(!e)return new ArrayBuffer(0);if(!r.isBase64Url(e))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(e.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(t){return this.ToBase64(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(t,e=r.DEFAULT_UTF8_ENCODING){switch(e){case"ascii":return this.FromBinary(t);case"utf8":return wn.fromString(t);case"utf16":case"utf16be":return Lt.fromString(t);case"utf16le":case"usc2":return Lt.fromString(t,!0);default:throw new Error(`Unknown type of encoding '${e}'`)}}static ToUtf8String(t,e=r.DEFAULT_UTF8_ENCODING){switch(e){case"ascii":return this.ToBinary(t);case"utf8":return wn.toString(t);case"utf16":case"utf16be":return Lt.toString(t);case"utf16le":case"usc2":return Lt.toString(t,!0);default:throw new Error(`Unknown type of encoding '${e}'`)}}static FromBinary(t){let e=t.length,n=new Uint8Array(e);for(let s=0;s<e;s++)n[s]=t.charCodeAt(s);return n.buffer}static ToBinary(t){let e=ie.toUint8Array(t),n="";for(let s=0;s<e.length;s++)n+=String.fromCharCode(e[s]);return n}static ToHex(t){let e=ie.toUint8Array(t),n="",s=e.length;for(let o=0;o<s;o++){let i=e[o];i<16&&(n+="0"),n+=i.toString(16)}return n}static FromHex(t){let e=this.formatString(t);if(!e)return new ArrayBuffer(0);if(!r.isHex(e))throw new TypeError("Argument 'hexString' is not HEX encoded");e.length%2&&(e=`0${e}`);let n=new Uint8Array(e.length/2);for(let s=0;s<e.length;s=s+2){let o=e.slice(s,s+2);n[s/2]=parseInt(o,16)}return n.buffer}static ToUtf16String(t,e=!1){return Lt.toString(t,e)}static FromUtf16String(t,e=!1){return Lt.fromString(t,e)}static Base64Padding(t){let e=4-t.length%4;if(e<4)for(let n=0;n<e;n++)t+="=";return t}static formatString(t){return t?.replace(/[\n\r\t ]/g,"")||""}};xn.DEFAULT_UTF8_ENCODING="utf8";function dh(r,...t){let e=arguments[0];for(let n=1;n<arguments.length;n++){let s=arguments[n];for(let o in s)e[o]=s[o]}return e}function ph(...r){let t=r.map(s=>s.byteLength).reduce((s,o)=>s+o),e=new Uint8Array(t),n=0;return r.map(s=>new Uint8Array(s)).forEach(s=>{for(let o of s)e[n++]=o}),e.buffer}function gh(r,t){if(!(r&&t)||r.byteLength!==t.byteLength)return!1;let e=new Uint8Array(r),n=new Uint8Array(t);for(let s=0;s<r.byteLength;s++)if(e[s]!==n[s])return!1;return!0}hr.BufferSourceConverter=ie;hr.Convert=xn;hr.assign=dh;hr.combine=ph;hr.isEqual=gh});var Fc=Es(Wr=>{(function(){var r,t,e,n,s,o,i,a;a=function(c){var l,f,u,h;return l=(c&255<<24)>>>24,f=(c&255<<16)>>>16,u=(c&65280)>>>8,h=c&255,[l,f,u,h].join(".")},i=function(c){var l,f,u,h,m,g;for(l=[],u=h=0;h<=3&&c.length!==0;u=++h){if(u>0){if(c[0]!==".")throw new Error("Invalid IP");c=c.substring(1)}g=t(c),m=g[0],f=g[1],c=c.substring(f),l.push(m)}if(c.length!==0)throw new Error("Invalid IP");switch(l.length){case 1:if(l[0]>4294967295)throw new Error("Invalid IP");return l[0]>>>0;case 2:if(l[0]>255||l[1]>16777215)throw new Error("Invalid IP");return(l[0]<<24|l[1])>>>0;case 3:if(l[0]>255||l[1]>255||l[2]>65535)throw new Error("Invalid IP");return(l[0]<<24|l[1]<<16|l[2])>>>0;case 4:if(l[0]>255||l[1]>255||l[2]>255||l[3]>255)throw new Error("Invalid IP");return(l[0]<<24|l[1]<<16|l[2]<<8|l[3])>>>0;default:throw new Error("Invalid IP")}},e=function(c){return c.charCodeAt(0)},n=e("0"),o=e("a"),s=e("A"),t=function(c){var l,f,u,h,m;for(h=0,l=10,f="9",u=0,c.length>1&&c[u]==="0"&&(c[u+1]==="x"||c[u+1]==="X"?(u+=2,l=16):"0"<=c[u+1]&&c[u+1]<="9"&&(u++,l=8,f="7")),m=u;u<c.length;){if("0"<=c[u]&&c[u]<=f)h=h*l+(e(c[u])-n)>>>0;else if(l===16)if("a"<=c[u]&&c[u]<="f")h=h*l+(10+e(c[u])-o)>>>0;else if("A"<=c[u]&&c[u]<="F")h=h*l+(10+e(c[u])-s)>>>0;else break;else break;if(h>4294967295)throw new Error("too large");u++}if(u===m)throw new Error("empty octet");return[h,u]},r=function(){function c(l,f){var u,h,m,g;if(typeof l!="string")throw new Error("Missing `net' parameter");if(f||(g=l.split("/",2),l=g[0],f=g[1]),f||(f=32),typeof f=="string"&&f.indexOf(".")>-1){try{this.maskLong=i(f)}catch(d){throw u=d,new Error("Invalid mask: "+f)}for(h=m=32;m>=0;h=--m)if(this.maskLong===4294967295<<32-h>>>0){this.bitmask=h;break}}else if(f||f===0)this.bitmask=parseInt(f,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(i(l)&this.maskLong)>>>0}catch(d){throw u=d,new Error("Invalid net address: "+l)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+f);this.size=Math.pow(2,32-this.bitmask),this.base=a(this.netLong),this.mask=a(this.maskLong),this.hostmask=a(~this.maskLong),this.first=this.bitmask<=30?a(this.netLong+1):this.base,this.last=this.bitmask<=30?a(this.netLong+this.size-2):a(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?a(this.netLong+this.size-1):void 0}return c.prototype.contains=function(l){return typeof l=="string"&&(l.indexOf("/")>0||l.split(".").length!==4)&&(l=new c(l)),l instanceof c?this.contains(l.base)&&this.contains(l.broadcast||l.last):(i(l)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},c.prototype.next=function(l){return l==null&&(l=1),new c(a(this.netLong+this.size*l),this.mask)},c.prototype.forEach=function(l){var f,u,h;for(h=i(this.first),u=i(this.last),f=0;h<=u;)l(a(h),h,f),f++,h++},c.prototype.toString=function(){return this.base+"/"+this.bitmask},c}(),Wr.ip2long=i,Wr.long2ip=a,Wr.Netmask=r}).call(Wr)});var ol=Es((Nb,sl)=>{"use strict";function nl(r,t){for(let e in t)Object.defineProperty(r,e,{value:t[e],enumerable:!0,configurable:!0});return r}function Ad(r,t,e){if(!r||typeof r=="string")throw new TypeError("Please pass an Error to err-code");e||(e={}),typeof t=="object"&&(e=t,t=""),t&&(e.code=t);try{return nl(r,e)}catch{e.message=r.message,e.stack=r.stack;let s=function(){};return s.prototype=Object.create(Object.getPrototypeOf(r)),nl(new s,e)}}sl.exports=Ad});var Kd={};lt(Kd,{autoNAT:()=>Md});var Ai=Symbol.for("@libp2p/peer-id");var U=class extends Error{code;props;constructor(t,e,n){super(t),this.code=e,this.name=n?.name??"CodeError",this.props=n??{}}};var As="ERR_TIMEOUT";var Ss=(r,...t)=>{try{[...t]}catch{}};var Ts={};lt(Ts,{base58btc:()=>at,base58flickr:()=>Ul});var jd=new Uint8Array(0);function Si(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function jt(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 ki(r){return new TextEncoder().encode(r)}function Ii(r){return new TextDecoder().decode(r)}function Rl(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var s=0;s<r.length;s++){var o=r.charAt(s),i=o.charCodeAt(0);if(e[i]!==255)throw new TypeError(o+" is ambiguous");e[i]=s}var a=r.length,c=r.charAt(0),l=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function u(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,p=0,y=0,v=g.length;y!==v&&g[y]===0;)y++,d++;for(var w=(v-y)*f+1>>>0,T=new Uint8Array(w);y!==v;){for(var x=g[y],A=0,R=w-1;(x!==0||A<p)&&R!==-1;R--,A++)x+=256*T[R]>>>0,T[R]=x%a>>>0,x=x/a>>>0;if(x!==0)throw new Error("Non-zero carry");p=A,y++}for(var N=w-p;N!==w&&T[N]===0;)N++;for(var q=c.repeat(d);N<w;++N)q+=r.charAt(T[N]);return q}function h(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 p=0,y=0;g[d]===c;)p++,d++;for(var v=(g.length-d)*l+1>>>0,w=new Uint8Array(v);g[d];){var T=e[g.charCodeAt(d)];if(T===255)return;for(var x=0,A=v-1;(T!==0||x<y)&&A!==-1;A--,x++)T+=a*w[A]>>>0,w[A]=T%256>>>0,T=T/256>>>0;if(T!==0)throw new Error("Non-zero carry");y=x,d++}if(g[d]!==" "){for(var R=v-y;R!==v&&w[R]===0;)R++;for(var N=new Uint8Array(p+(v-R)),q=p;R!==v;)N[q++]=w[R++];return N}}}function m(g){var d=h(g);if(d)return d;throw new Error(`Non-${t} character`)}return{encode:u,decodeUnsafe:h,decode:m}}var Nl=Rl,Tl=Nl,Ni=Tl;var ks=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Is=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Ti(this,t)}},Rs=class{decoders;constructor(t){this.decoders=t}or(t){return Ti(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ti(r,t){return new Rs({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Ns=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,s){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=s,this.encoder=new ks(t,e,n),this.decoder=new Is(t,e,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ze({name:r,prefix:t,encode:e,decode:n}){return new Ns(r,t,e,n)}function pe({name:r,prefix:t,alphabet:e}){let{encode:n,decode:s}=Ni(e,r);return ze({prefix:t,name:r,encode:n,decode:o=>jt(s(o))})}function Ll(r,t,e,n){let s={};for(let f=0;f<t.length;++f)s[t[f]]=f;let o=r.length;for(;r[o-1]==="=";)--o;let i=new Uint8Array(o*e/8|0),a=0,c=0,l=0;for(let f=0;f<o;++f){let u=s[r[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|u,a+=e,a>=8&&(a-=8,i[l++]=255&c>>a)}if(a>=e||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return i}function _l(r,t,e){let n=t[t.length-1]==="=",s=(1<<e)-1,o="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,o+=t[s&a>>i];if(i!==0&&(o+=t[s&a<<e-i]),n)for(;o.length*e&7;)o+="=";return o}function tt({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return ze({prefix:t,name:r,encode(s){return _l(s,n,e)},decode(s){return Ll(s,n,e,r)}})}var at=pe({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ul=pe({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ls={};lt(Ls,{base10:()=>Cl});var Cl=pe({prefix:"9",name:"base10",alphabet:"0123456789"});var _s={};lt(_s,{base16:()=>Dl,base16upper:()=>Pl});var Dl=tt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Pl=tt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Us={};lt(Us,{base2:()=>Ol});var Ol=tt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Cs={};lt(Cs,{base256emoji:()=>Kl});var Li=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}"),Vl=Li.reduce((r,t,e)=>(r[e]=t,r),[]),Fl=Li.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function Hl(r){return r.reduce((t,e)=>(t+=Vl[e],t),"")}function Ml(r){let t=[];for(let e of r){let n=Fl[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var Kl=ze({prefix:"\u{1F680}",name:"base256emoji",encode:Hl,decode:Ml});var Ds={};lt(Ds,{base32:()=>Wt,base32hex:()=>zl,base32hexpad:()=>Wl,base32hexpadupper:()=>Yl,base32hexupper:()=>jl,base32pad:()=>ql,base32padupper:()=>Gl,base32upper:()=>$l,base32z:()=>Zl});var Wt=tt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),$l=tt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),ql=tt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Gl=tt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),zl=tt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),jl=tt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Wl=tt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Yl=tt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Zl=tt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ps={};lt(Ps,{base36:()=>Jl,base36upper:()=>Xl});var Jl=pe({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Xl=pe({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Vs={};lt(Vs,{base64:()=>Os,base64pad:()=>Ql,base64url:()=>tu,base64urlpad:()=>eu});var Os=tt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ql=tt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),tu=tt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),eu=tt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Fs={};lt(Fs,{base8:()=>ru});var ru=tt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Hs={};lt(Hs,{identity:()=>nu});var nu=ze({prefix:"\0",name:"identity",encode:r=>Ii(r),decode:r=>ki(r)});var l0=new TextEncoder,u0=new TextDecoder;var Ks={};lt(Ks,{identity:()=>ge});var iu=Ci,_i=128,au=127,cu=~au,lu=Math.pow(2,31);function Ci(r,t,e){t=t||[],e=e||0;for(var n=e;r>=lu;)t[e++]=r&255|_i,r/=128;for(;r&cu;)t[e++]=r&255|_i,r>>>=7;return t[e]=r|0,Ci.bytes=e-n+1,t}var uu=Ms,fu=128,Ui=127;function Ms(r,n){var e=0,n=n||0,s=0,o=n,i,a=r.length;do{if(o>=a)throw Ms.bytes=0,new RangeError("Could not decode varint");i=r[o++],e+=s<28?(i&Ui)<<s:(i&Ui)*Math.pow(2,s),s+=7}while(i>=fu);return Ms.bytes=o-n,e}var hu=Math.pow(2,7),du=Math.pow(2,14),pu=Math.pow(2,21),gu=Math.pow(2,28),mu=Math.pow(2,35),yu=Math.pow(2,42),bu=Math.pow(2,49),wu=Math.pow(2,56),xu=Math.pow(2,63),vu=function(r){return r<hu?1:r<du?2:r<pu?3:r<gu?4:r<mu?5:r<yu?6:r<bu?7:r<wu?8:r<xu?9:10},Eu={encode:iu,decode:uu,encodingLength:vu},Bu=Eu,Sr=Bu;function kr(r,t=0){return[Sr.decode(r,t),Sr.decode.bytes]}function je(r,t,e=0){return Sr.encode(r,t,e),t}function We(r){return Sr.encodingLength(r)}function Mt(r,t){let e=t.byteLength,n=We(r),s=n+We(e),o=new Uint8Array(s+e);return je(r,o,0),je(e,o,n),o.set(t,s),new Ye(r,e,t,o)}function Ce(r){let t=jt(r),[e,n]=kr(t),[s,o]=kr(t.subarray(n)),i=t.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new Ye(e,s,i,t)}function Di(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Si(r.bytes,e.bytes)}}var Ye=class{code;size;digest;bytes;constructor(t,e,n,s){this.code=t,this.size=e,this.digest=n,this.bytes=s}};var Pi=0,Au="identity",Oi=jt;function Su(r){return Mt(Pi,Oi(r))}var ge={code:Pi,name:Au,encode:Oi,digest:Su};var Gs={};lt(Gs,{sha256:()=>pt,sha512:()=>ku});function qs({name:r,code:t,encode:e}){return new $s(r,t,e)}var $s=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?Mt(this.code,e):e.then(n=>Mt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Fi(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var pt=qs({name:"sha2-256",code:18,encode:Fi("SHA-256")}),ku=qs({name:"sha2-512",code:19,encode:Fi("SHA-512")});function Hi(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Ru(e,zs(r),t??at.encoder);default:return Nu(e,zs(r),t??Wt.encoder)}}var Mi=new WeakMap;function zs(r){let t=Mi.get(r);if(t==null){let e=new Map;return Mi.set(r,e),e}return t}var Ut=class r{code;version;multihash;bytes;"/";constructor(t,e,n,s){this.code=e,this.version=t,this.multihash=n,this.bytes=s,this["/"]=s}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==Ir)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Tu)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=Mt(t,e);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(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&Di(t.multihash,n.multihash)}toString(t){return Hi(this,t)}toJSON(){return{"/":Hi(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:s,multihash:o,bytes:i}=e;return new r(n,s,o,i??Ki(n,s,o.bytes))}else if(e[Lu]===!0){let{version:n,multihash:s,code:o}=e,i=Ce(s);return r.create(n,o,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==Ir)throw new Error(`Version 0 CID must use dag-pb (code: ${Ir}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let s=Ki(t,e,n.bytes);return new r(t,e,n,s)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Ir,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,s=jt(t.subarray(n,n+e.multihashSize));if(s.byteLength!==e.multihashSize)throw new Error("Incorrect length");let o=s.subarray(e.multihashSize-e.digestSize),i=new Ye(e.multihashCode,e.digestSize,o,s);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[u,h]=kr(t.subarray(e));return e+=h,u},s=n(),o=Ir;if(s===18?(s=0,e=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=e,a=n(),c=n(),l=e+c,f=l-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:f,size:l}}static parse(t,e){let[n,s]=Iu(t,e),o=r.decode(s);if(o.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return zs(o).set(n,t),o}};function Iu(r,t){switch(r[0]){case"Q":{let e=t??at;return[at.prefix,e.decode(`${at.prefix}${r}`)]}case at.prefix:{let e=t??at;return[at.prefix,e.decode(r)]}case Wt.prefix:{let e=t??Wt;return[Wt.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Ru(r,t,e){let{prefix:n}=e;if(n!==at.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let s=t.get(n);if(s==null){let o=e.encode(r).slice(1);return t.set(n,o),o}else return s}function Nu(r,t,e){let{prefix:n}=e,s=t.get(n);if(s==null){let o=e.encode(r);return t.set(n,o),o}else return s}var Ir=112,Tu=18;function Ki(r,t,e){let n=We(r),s=n+We(t),o=new Uint8Array(s+e.byteLength);return je(r,o,0),je(t,o,n),o.set(e,s),o}var Lu=Symbol.for("@ipld/js-cid/CID");var me={...Hs,...Us,...Fs,...Ls,..._s,...Ds,...Ps,...Ts,...Vs,...Cs},L0={...Gs,...Ks};function bt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}var _u=Symbol.for("nodejs.util.inspect.custom"),$i=Object.values(me).map(r=>r.decoder).reduce((r,t)=>r.or(t),me.identity.decoder),qi=114,js=36,Ws=37,Rr=class{type;multihash;privateKey;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,this.privateKey=t.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Ai]=!0;toString(){return this.string==null&&(this.string=at.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return Ut.createV1(qi,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return bt(this.multihash.bytes,t);if(typeof t=="string")return Uu(t).equals(this);if(t?.multihash?.bytes!=null)return bt(this.multihash.bytes,t.multihash.bytes);throw new Error("not valid Id")}[_u](){return`PeerId(${this.toString()})`}},Ze=class extends Rr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Je=class extends Rr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.multihash.digest}},Xe=class extends Rr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.multihash.digest}};function Uu(r,t){if(t=t??$i,r.charAt(0)==="1"||r.charAt(0)==="Q"){let e=Ce(at.decode(`z${r}`));return r.startsWith("12D")?new Je({multihash:e}):r.startsWith("16U")?new Xe({multihash:e}):new Ze({multihash:e})}return Xr($i.decode(r))}function Xr(r){try{let t=Ce(r);if(t.code===ge.code){if(t.digest.length===js)return new Je({multihash:t});if(t.digest.length===Ws)return new Xe({multihash:t})}if(t.code===pt.code)return new Ze({multihash:t})}catch{return Cu(Ut.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function Cu(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==qi)throw new Error("Supplied PeerID CID is invalid");let t=r.multihash;if(t.code===pt.code)return new Ze({multihash:r.multihash});if(t.code===ge.code){if(t.digest.length===js)return new Je({multihash:r.multihash});if(t.digest.length===Ws)return new Xe({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function Gi(r,t){return r.length===js?new Je({multihash:Mt(ge.code,r),privateKey:t}):r.length===Ws?new Xe({multihash:Mt(ge.code,r),privateKey:t}):new Ze({multihash:await pt.digest(r),publicKey:r,privateKey:t})}var _o={};lt(_o,{Ed25519PrivateKey:()=>Me,Ed25519PublicKey:()=>Ur,generateKeyPair:()=>ih,generateKeyPairFromSeed:()=>Ia,unmarshalEd25519PrivateKey:()=>sh,unmarshalEd25519PublicKey:()=>oh});function ye(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function Yt(r=0){return globalThis.Buffer?.alloc!=null?ye(globalThis.Buffer.alloc(r)):new Uint8Array(r)}function wt(r=0){return globalThis.Buffer?.allocUnsafe!=null?ye(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function Bt(r,t){if(globalThis.Buffer!=null)return ye(globalThis.Buffer.concat(r,t));t==null&&(t=r.reduce((s,o)=>s+o.length,0));let e=wt(t),n=0;for(let s of r)e.set(s,n),n+=s.length;return ye(e)}function ji(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var zi=ji("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Ys=ji("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=wt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Du={utf8:zi,"utf-8":zi,hex:me.base16,latin1:Ys,ascii:Ys,binary:Ys,...me},Qr=Du;function Z(r,t="utf8"){let e=Qr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?ye(globalThis.Buffer.from(r,"utf-8")):e.decoder.decode(`${e.prefix}${r}`)}function Tt(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Qe(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`Wrong positive integer: ${r}`)}function Pu(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Zs(r,...t){if(!Pu(r))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(r.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${r.length}`)}function tn(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Qe(r.outputLen),Qe(r.blockLen)}function tr(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function Wi(r,t){Zs(r);let e=t.outputLen;if(r.length<e)throw new Error(`digestInto() expects output buffer of length at least ${e}`)}var en=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Yi(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var rr=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Ct=(r,t)=>r<<32-t|r>>>t,Ou=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Ou)throw new Error("Non little-endian hardware is not supported");var Vu=async()=>{};async function Zi(r,t,e){let n=Date.now();for(let s=0;s<r;s++){e(s);let o=Date.now()-n;o>=0&&o<t||(await Vu(),n+=o)}}function Js(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function be(r){if(typeof r=="string"&&(r=Js(r)),!Yi(r))throw new Error(`expected Uint8Array, got ${typeof r}`);return r}function rn(...r){let t=0;for(let n=0;n<r.length;n++){let s=r[n];if(!Yi(s))throw new Error("Uint8Array expected");t+=s.length}let e=new Uint8Array(t);for(let n=0,s=0;n<r.length;n++){let o=r[n];e.set(o,s),s+=o.length}return e}var er=class{clone(){return this._cloneInto()}},Fu={}.toString;function Ji(r,t){if(t!==void 0&&Fu.call(t)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(r,t)}function nn(r){let t=n=>r().update(be(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function nr(r=32){if(en&&typeof en.getRandomValues=="function")return en.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function Hu(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let s=BigInt(32),o=BigInt(4294967295),i=Number(e>>s&o),a=Number(e&o),c=n?4:0,l=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+l,a,n)}var sr=class extends er{constructor(t,e,n,s){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=rr(this.buffer)}update(t){tr(this);let{view:e,buffer:n,blockLen:s}=this;t=be(t);let o=t.length;for(let i=0;i<o;){let a=Math.min(s-this.pos,o-i);if(a===s){let c=rr(t);for(;s<=o-i;i+=s)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===s&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){tr(this),Wi(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:s,isLE:o}=this,{pos:i}=this;e[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>s-i&&(this.process(n,0),i=0);for(let u=i;u<s;u++)e[u]=0;Hu(n,s-8,BigInt(this.length*8),o),this.process(n,0);let a=rr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=c/4,f=this.get();if(l>f.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<l;u++)a.setUint32(4*u,f[u],o)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:s,finished:o,destroyed:i,pos:a}=this;return t.length=s,t.pos=a,t.finished=o,t.destroyed=i,s%e&&t.buffer.set(n),t}};var sn=BigInt(4294967295),Xs=BigInt(32);function Xi(r,t=!1){return t?{h:Number(r&sn),l:Number(r>>Xs&sn)}:{h:Number(r>>Xs&sn)|0,l:Number(r&sn)|0}}function Mu(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let s=0;s<r.length;s++){let{h:o,l:i}=Xi(r[s],t);[e[s],n[s]]=[o,i]}return[e,n]}var Ku=(r,t)=>BigInt(r>>>0)<<Xs|BigInt(t>>>0),$u=(r,t,e)=>r>>>e,qu=(r,t,e)=>r<<32-e|t>>>e,Gu=(r,t,e)=>r>>>e|t<<32-e,zu=(r,t,e)=>r<<32-e|t>>>e,ju=(r,t,e)=>r<<64-e|t>>>e-32,Wu=(r,t,e)=>r>>>e-32|t<<64-e,Yu=(r,t)=>t,Zu=(r,t)=>r,Ju=(r,t,e)=>r<<e|t>>>32-e,Xu=(r,t,e)=>t<<e|r>>>32-e,Qu=(r,t,e)=>t<<e-32|r>>>64-e,tf=(r,t,e)=>r<<e-32|t>>>64-e;function ef(r,t,e,n){let s=(t>>>0)+(n>>>0);return{h:r+e+(s/2**32|0)|0,l:s|0}}var rf=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),nf=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,sf=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),of=(r,t,e,n,s)=>t+e+n+s+(r/2**32|0)|0,af=(r,t,e,n,s)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(s>>>0),cf=(r,t,e,n,s,o)=>t+e+n+s+o+(r/2**32|0)|0;var lf={fromBig:Xi,split:Mu,toBig:Ku,shrSH:$u,shrSL:qu,rotrSH:Gu,rotrSL:zu,rotrBH:ju,rotrBL:Wu,rotr32H:Yu,rotr32L:Zu,rotlSH:Ju,rotlSL:Xu,rotlBH:Qu,rotlBL:tf,add:ef,add3L:rf,add3H:nf,add4L:sf,add4H:of,add5H:cf,add5L:af},C=lf;var[uf,ff]=C.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))),we=new Uint32Array(80),xe=new Uint32Array(80),Qs=class extends sr{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:t,Al:e,Bh:n,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:l,El:f,Fh:u,Fl:h,Gh:m,Gl:g,Hh:d,Hl:p}=this;return[t,e,n,s,o,i,a,c,l,f,u,h,m,g,d,p]}set(t,e,n,s,o,i,a,c,l,f,u,h,m,g,d,p){this.Ah=t|0,this.Al=e|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=l|0,this.El=f|0,this.Fh=u|0,this.Fl=h|0,this.Gh=m|0,this.Gl=g|0,this.Hh=d|0,this.Hl=p|0}process(t,e){for(let w=0;w<16;w++,e+=4)we[w]=t.getUint32(e),xe[w]=t.getUint32(e+=4);for(let w=16;w<80;w++){let T=we[w-15]|0,x=xe[w-15]|0,A=C.rotrSH(T,x,1)^C.rotrSH(T,x,8)^C.shrSH(T,x,7),R=C.rotrSL(T,x,1)^C.rotrSL(T,x,8)^C.shrSL(T,x,7),N=we[w-2]|0,q=xe[w-2]|0,K=C.rotrSH(N,q,19)^C.rotrBH(N,q,61)^C.shrSH(N,q,6),P=C.rotrSL(N,q,19)^C.rotrBL(N,q,61)^C.shrSL(N,q,6),nt=C.add4L(R,P,xe[w-7],xe[w-16]),rt=C.add4H(nt,A,K,we[w-7],we[w-16]);we[w]=rt|0,xe[w]=nt|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:l,Dl:f,Eh:u,El:h,Fh:m,Fl:g,Gh:d,Gl:p,Hh:y,Hl:v}=this;for(let w=0;w<80;w++){let T=C.rotrSH(u,h,14)^C.rotrSH(u,h,18)^C.rotrBH(u,h,41),x=C.rotrSL(u,h,14)^C.rotrSL(u,h,18)^C.rotrBL(u,h,41),A=u&m^~u&d,R=h&g^~h&p,N=C.add5L(v,x,R,ff[w],xe[w]),q=C.add5H(N,y,T,A,uf[w],we[w]),K=N|0,P=C.rotrSH(n,s,28)^C.rotrBH(n,s,34)^C.rotrBH(n,s,39),nt=C.rotrSL(n,s,28)^C.rotrBL(n,s,34)^C.rotrBL(n,s,39),rt=n&o^n&a^o&a,Nt=s&i^s&c^i&c;y=d|0,v=p|0,d=m|0,p=g|0,m=u|0,g=h|0,{h:u,l:h}=C.add(l|0,f|0,q|0,K|0),l=a|0,f=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let E=C.add3L(K,nt,Nt);n=C.add3H(E,q,P,rt),s=E|0}({h:n,l:s}=C.add(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=C.add(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=C.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:f}=C.add(this.Dh|0,this.Dl|0,l|0,f|0),{h:u,l:h}=C.add(this.Eh|0,this.El|0,u|0,h|0),{h:m,l:g}=C.add(this.Fh|0,this.Fl|0,m|0,g|0),{h:d,l:p}=C.add(this.Gh|0,this.Gl|0,d|0,p|0),{h:y,l:v}=C.add(this.Hh|0,this.Hl|0,y|0,v|0),this.set(n,s,o,i,a,c,l,f,u,h,m,g,d,p,y,v)}roundClean(){we.fill(0),xe.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 or=nn(()=>new Qs);var an={};lt(an,{bitGet:()=>bf,bitLen:()=>yf,bitMask:()=>Nr,bitSet:()=>wf,bytesToHex:()=>Jt,bytesToNumberBE:()=>Xt,bytesToNumberLE:()=>ve,concatBytes:()=>Qt,createHmacDrbg:()=>ro,ensureBytes:()=>et,equalBytes:()=>gf,hexToBytes:()=>Pe,hexToNumber:()=>eo,isBytes:()=>Dt,numberToBytesBE:()=>Ee,numberToBytesLE:()=>Oe,numberToHexUnpadded:()=>ra,numberToVarBytesBE:()=>pf,utf8ToBytes:()=>mf,validateObject:()=>Kt});var ea=BigInt(0),on=BigInt(1),hf=BigInt(2);function Dt(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var df=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Jt(r){if(!Dt(r))throw new Error("Uint8Array expected");let t="";for(let e=0;e<r.length;e++)t+=df[r[e]];return t}function ra(r){let t=r.toString(16);return t.length&1?`0${t}`:t}function eo(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var Zt={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function Qi(r){if(r>=Zt._0&&r<=Zt._9)return r-Zt._0;if(r>=Zt._A&&r<=Zt._F)return r-(Zt._A-10);if(r>=Zt._a&&r<=Zt._f)return r-(Zt._a-10)}function Pe(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let t=r.length,e=t/2;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let s=0,o=0;s<e;s++,o+=2){let i=Qi(r.charCodeAt(o)),a=Qi(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 Xt(r){return eo(Jt(r))}function ve(r){if(!Dt(r))throw new Error("Uint8Array expected");return eo(Jt(Uint8Array.from(r).reverse()))}function Ee(r,t){return Pe(r.toString(16).padStart(t*2,"0"))}function Oe(r,t){return Ee(r,t).reverse()}function pf(r){return Pe(ra(r))}function et(r,t,e){let n;if(typeof t=="string")try{n=Pe(t)}catch(o){throw new Error(`${r} must be valid hex string, got "${t}". Cause: ${o}`)}else if(Dt(t))n=Uint8Array.from(t);else throw new Error(`${r} must be hex string or Uint8Array`);let s=n.length;if(typeof e=="number"&&s!==e)throw new Error(`${r} expected ${e} bytes, got ${s}`);return n}function Qt(...r){let t=0;for(let s=0;s<r.length;s++){let o=r[s];if(!Dt(o))throw new Error("Uint8Array expected");t+=o.length}let e=new Uint8Array(t),n=0;for(let s=0;s<r.length;s++){let o=r[s];e.set(o,n),n+=o.length}return e}function gf(r,t){if(r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}function mf(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function yf(r){let t;for(t=0;r>ea;r>>=on,t+=1);return t}function bf(r,t){return r>>BigInt(t)&on}var wf=(r,t,e)=>r|(e?on:ea)<<BigInt(t),Nr=r=>(hf<<BigInt(r-1))-on,to=r=>new Uint8Array(r),ta=r=>Uint8Array.from(r);function ro(r,t,e){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof e!="function")throw new Error("hmacFn must be a function");let n=to(r),s=to(r),o=0,i=()=>{n.fill(1),s.fill(0),o=0},a=(...u)=>e(s,n,...u),c=(u=to())=>{s=a(ta([0]),u),n=a(),u.length!==0&&(s=a(ta([1]),u),n=a())},l=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let u=0,h=[];for(;u<t;){n=a();let m=n.slice();h.push(m),u+=n.length}return Qt(...h)};return(u,h)=>{i(),c(u);let m;for(;!(m=h(l()));)c();return i(),m}}var xf={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"||Dt(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function Kt(r,t,e={}){let n=(s,o,i)=>{let a=xf[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(t))n(s,o,!1);for(let[s,o]of Object.entries(e))n(s,o,!0);return r}var ct=BigInt(0),J=BigInt(1),Ve=BigInt(2),vf=BigInt(3),no=BigInt(4),na=BigInt(5),sa=BigInt(8),Ef=BigInt(9),Bf=BigInt(16);function Y(r,t){let e=r%t;return e>=ct?e:t+e}function Af(r,t,e){if(e<=ct||t<ct)throw new Error("Expected power/modulo > 0");if(e===J)return ct;let n=J;for(;t>ct;)t&J&&(n=n*r%e),r=r*r%e,t>>=J;return n}function X(r,t,e){let n=r;for(;t-- >ct;)n*=n,n%=e;return n}function cn(r,t){if(r===ct||t<=ct)throw new Error(`invert: expected positive integers, got n=${r} mod=${t}`);let e=Y(r,t),n=t,s=ct,o=J,i=J,a=ct;for(;e!==ct;){let l=n/e,f=n%e,u=s-i*l,h=o-a*l;n=e,e=f,s=i,o=a,i=u,a=h}if(n!==J)throw new Error("invert: does not exist");return Y(s,t)}function Sf(r){let t=(r-J)/Ve,e,n,s;for(e=r-J,n=0;e%Ve===ct;e/=Ve,n++);for(s=Ve;s<r&&Af(s,t,r)!==r-J;s++);if(n===1){let i=(r+J)/no;return function(c,l){let f=c.pow(l,i);if(!c.eql(c.sqr(f),l))throw new Error("Cannot find square root");return f}}let o=(e+J)/Ve;return function(a,c){if(a.pow(c,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let l=n,f=a.pow(a.mul(a.ONE,s),e),u=a.pow(c,o),h=a.pow(c,e);for(;!a.eql(h,a.ONE);){if(a.eql(h,a.ZERO))return a.ZERO;let m=1;for(let d=a.sqr(h);m<l&&!a.eql(d,a.ONE);m++)d=a.sqr(d);let g=a.pow(f,J<<BigInt(l-m-1));f=a.sqr(g),u=a.mul(u,g),h=a.mul(h,f),l=m}return u}}function kf(r){if(r%no===vf){let t=(r+J)/no;return function(n,s){let o=n.pow(s,t);if(!n.eql(n.sqr(o),s))throw new Error("Cannot find square root");return o}}if(r%sa===na){let t=(r-na)/sa;return function(n,s){let o=n.mul(s,Ve),i=n.pow(o,t),a=n.mul(s,i),c=n.mul(n.mul(a,Ve),i),l=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(l),s))throw new Error("Cannot find square root");return l}}return r%Bf,Sf(r)}var oa=(r,t)=>(Y(r,t)&J)===J,If=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function so(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=If.reduce((n,s)=>(n[s]="function",n),t);return Kt(r,e)}function Rf(r,t,e){if(e<ct)throw new Error("Expected power > 0");if(e===ct)return r.ONE;if(e===J)return t;let n=r.ONE,s=t;for(;e>ct;)e&J&&(n=r.mul(n,s)),s=r.sqr(s),e>>=J;return n}function Nf(r,t){let e=new Array(t.length),n=t.reduce((o,i,a)=>r.is0(i)?o:(e[a]=o,r.mul(o,i)),r.ONE),s=r.inv(n);return t.reduceRight((o,i,a)=>r.is0(i)?o:(e[a]=r.mul(o,e[a]),r.mul(o,i)),s),e}function oo(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function ln(r,t,e=!1,n={}){if(r<=ct)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:s,nByteLength:o}=oo(r,t);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let i=kf(r),a=Object.freeze({ORDER:r,BITS:s,BYTES:o,MASK:Nr(s),ZERO:ct,ONE:J,create:c=>Y(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return ct<=c&&c<r},is0:c=>c===ct,isOdd:c=>(c&J)===J,neg:c=>Y(-c,r),eql:(c,l)=>c===l,sqr:c=>Y(c*c,r),add:(c,l)=>Y(c+l,r),sub:(c,l)=>Y(c-l,r),mul:(c,l)=>Y(c*l,r),pow:(c,l)=>Rf(a,c,l),div:(c,l)=>Y(c*cn(l,r),r),sqrN:c=>c*c,addN:(c,l)=>c+l,subN:(c,l)=>c-l,mulN:(c,l)=>c*l,inv:c=>cn(c,r),sqrt:n.sqrt||(c=>i(a,c)),invertBatch:c=>Nf(a,c),cmov:(c,l,f)=>f?l:c,toBytes:c=>e?Oe(c,o):Ee(c,o),fromBytes:c=>{if(c.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);return e?ve(c):Xt(c)}});return Object.freeze(a)}function ia(r,t){if(!r.isOdd)throw new Error("Field doesn't have isOdd");let e=r.sqrt(t);return r.isOdd(e)?r.neg(e):e}function aa(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function io(r){let t=aa(r);return t+Math.ceil(t/2)}function ca(r,t,e=!1){let n=r.length,s=aa(t),o=io(t);if(n<16||n<o||n>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${n}`);let i=e?Xt(r):ve(r),a=Y(i,t-J)+J;return e?Oe(a,s):Ee(a,s)}var Lf=BigInt(0),ao=BigInt(1);function un(r,t){let e=(s,o)=>{let i=o.negate();return s?i:o},n=s=>{let o=Math.ceil(t/s)+1,i=2**(s-1);return{windows:o,windowSize:i}};return{constTimeNegate:e,unsafeLadder(s,o){let i=r.ZERO,a=s;for(;o>Lf;)o&ao&&(i=i.add(a)),a=a.double(),o>>=ao;return i},precomputeWindow(s,o){let{windows:i,windowSize:a}=n(o),c=[],l=s,f=l;for(let u=0;u<i;u++){f=l,c.push(f);for(let h=1;h<a;h++)f=f.add(l),c.push(f);l=f.double()}return c},wNAF(s,o,i){let{windows:a,windowSize:c}=n(s),l=r.ZERO,f=r.BASE,u=BigInt(2**s-1),h=2**s,m=BigInt(s);for(let g=0;g<a;g++){let d=g*c,p=Number(i&u);i>>=m,p>c&&(p-=h,i+=ao);let y=d,v=d+Math.abs(p)-1,w=g%2!==0,T=p<0;p===0?f=f.add(e(w,o[y])):l=l.add(e(T,o[v]))}return{p:l,f}},wNAFCached(s,o,i,a){let c=s._WINDOW_SIZE||1,l=o.get(s);return l||(l=this.precomputeWindow(s,c),c!==1&&o.set(s,a(l))),this.wNAF(c,l,i)}}}function Tr(r){return so(r.Fp),Kt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...oo(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Pt=BigInt(0),It=BigInt(1),fn=BigInt(2),_f=BigInt(8),Uf={zip215:!0};function Cf(r){let t=Tr(r);return Kt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function hn(r){let t=Cf(r),{Fp:e,n,prehash:s,hash:o,randomBytes:i,nByteLength:a,h:c}=t,l=fn<<BigInt(a*8)-It,f=e.create,u=t.uvRatio||((B,b)=>{try{return{isValid:!0,value:e.sqrt(B*e.inv(b))}}catch{return{isValid:!1,value:Pt}}}),h=t.adjustScalarBytes||(B=>B),m=t.domain||((B,b,k)=>{if(b.length||k)throw new Error("Contexts/pre-hash are not supported");return B}),g=B=>typeof B=="bigint"&&Pt<B,d=(B,b)=>g(B)&&g(b)&&B<b,p=B=>B===Pt||d(B,l);function y(B,b){if(d(B,b))return B;throw new Error(`Expected valid scalar < ${b}, got ${typeof B} ${B}`)}function v(B){return B===Pt?B:y(B,n)}let w=new Map;function T(B){if(!(B instanceof x))throw new Error("ExtendedPoint expected")}class x{constructor(b,k,L,_){if(this.ex=b,this.ey=k,this.ez=L,this.et=_,!p(b))throw new Error("x required");if(!p(k))throw new Error("y required");if(!p(L))throw new Error("z required");if(!p(_))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(b){if(b instanceof x)throw new Error("extended point not allowed");let{x:k,y:L}=b||{};if(!p(k)||!p(L))throw new Error("invalid affine point");return new x(k,L,It,f(k*L))}static normalizeZ(b){let k=e.invertBatch(b.map(L=>L.ez));return b.map((L,_)=>L.toAffine(k[_])).map(x.fromAffine)}_setWindowSize(b){this._WINDOW_SIZE=b,w.delete(this)}assertValidity(){let{a:b,d:k}=t;if(this.is0())throw new Error("bad point: ZERO");let{ex:L,ey:_,ez:V,et:F}=this,j=f(L*L),M=f(_*_),$=f(V*V),st=f($*$),Q=f(j*b),ht=f($*f(Q+M)),dt=f(st+f(k*f(j*M)));if(ht!==dt)throw new Error("bad point: equation left != right (1)");let it=f(L*_),yt=f(V*F);if(it!==yt)throw new Error("bad point: equation left != right (2)")}equals(b){T(b);let{ex:k,ey:L,ez:_}=this,{ex:V,ey:F,ez:j}=b,M=f(k*j),$=f(V*_),st=f(L*j),Q=f(F*_);return M===$&&st===Q}is0(){return this.equals(x.ZERO)}negate(){return new x(f(-this.ex),this.ey,this.ez,f(-this.et))}double(){let{a:b}=t,{ex:k,ey:L,ez:_}=this,V=f(k*k),F=f(L*L),j=f(fn*f(_*_)),M=f(b*V),$=k+L,st=f(f($*$)-V-F),Q=M+F,ht=Q-j,dt=M-F,it=f(st*ht),yt=f(Q*dt),zt=f(st*dt),Ue=f(ht*Q);return new x(it,yt,Ue,zt)}add(b){T(b);let{a:k,d:L}=t,{ex:_,ey:V,ez:F,et:j}=this,{ex:M,ey:$,ez:st,et:Q}=b;if(k===BigInt(-1)){let mi=f((V-_)*($+M)),yi=f((V+_)*($-M)),vs=f(yi-mi);if(vs===Pt)return this.double();let bi=f(F*fn*Q),wi=f(j*fn*st),xi=wi+bi,vi=yi+mi,Ei=wi-bi,bl=f(xi*vs),wl=f(vi*Ei),xl=f(xi*Ei),vl=f(vs*vi);return new x(bl,wl,vl,xl)}let ht=f(_*M),dt=f(V*$),it=f(j*L*Q),yt=f(F*st),zt=f((_+V)*(M+$)-ht-dt),Ue=yt-it,Ar=yt+it,gi=f(dt-k*ht),pl=f(zt*Ue),gl=f(Ar*gi),ml=f(zt*gi),yl=f(Ue*Ar);return new x(pl,gl,yl,ml)}subtract(b){return this.add(b.negate())}wNAF(b){return N.wNAFCached(this,w,b,x.normalizeZ)}multiply(b){let{p:k,f:L}=this.wNAF(y(b,n));return x.normalizeZ([k,L])[0]}multiplyUnsafe(b){let k=v(b);return k===Pt?R:this.equals(R)||k===It?this:this.equals(A)?this.wNAF(k).p:N.unsafeLadder(this,k)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return N.unsafeLadder(this,n).is0()}toAffine(b){let{ex:k,ey:L,ez:_}=this,V=this.is0();b==null&&(b=V?_f:e.inv(_));let F=f(k*b),j=f(L*b),M=f(_*b);if(V)return{x:Pt,y:It};if(M!==It)throw new Error("invZ was invalid");return{x:F,y:j}}clearCofactor(){let{h:b}=t;return b===It?this:this.multiplyUnsafe(b)}static fromHex(b,k=!1){let{d:L,a:_}=t,V=e.BYTES;b=et("pointHex",b,V);let F=b.slice(),j=b[V-1];F[V-1]=j&-129;let M=ve(F);M===Pt||(k?y(M,l):y(M,e.ORDER));let $=f(M*M),st=f($-It),Q=f(L*$-_),{isValid:ht,value:dt}=u(st,Q);if(!ht)throw new Error("Point.fromHex: invalid y coordinate");let it=(dt&It)===It,yt=(j&128)!==0;if(!k&&dt===Pt&&yt)throw new Error("Point.fromHex: x=0 and x_0=1");return yt!==it&&(dt=f(-dt)),x.fromAffine({x:dt,y:M})}static fromPrivateKey(b){return P(b).point}toRawBytes(){let{x:b,y:k}=this.toAffine(),L=Oe(k,e.BYTES);return L[L.length-1]|=b&It?128:0,L}toHex(){return Jt(this.toRawBytes())}}x.BASE=new x(t.Gx,t.Gy,It,f(t.Gx*t.Gy)),x.ZERO=new x(Pt,It,It,Pt);let{BASE:A,ZERO:R}=x,N=un(x,a*8);function q(B){return Y(B,n)}function K(B){return q(ve(B))}function P(B){let b=a;B=et("private key",B,b);let k=et("hashed private key",o(B),2*b),L=h(k.slice(0,b)),_=k.slice(b,2*b),V=K(L),F=A.multiply(V),j=F.toRawBytes();return{head:L,prefix:_,scalar:V,point:F,pointBytes:j}}function nt(B){return P(B).pointBytes}function rt(B=new Uint8Array,...b){let k=Qt(...b);return K(o(m(k,et("context",B),!!s)))}function Nt(B,b,k={}){B=et("message",B),s&&(B=s(B));let{prefix:L,scalar:_,pointBytes:V}=P(b),F=rt(k.context,L,B),j=A.multiply(F).toRawBytes(),M=rt(k.context,j,V,B),$=q(F+M*_);v($);let st=Qt(j,Oe($,e.BYTES));return et("result",st,a*2)}let E=Uf;function I(B,b,k,L=E){let{context:_,zip215:V}=L,F=e.BYTES;B=et("signature",B,2*F),b=et("message",b),s&&(b=s(b));let j=ve(B.slice(F,2*F)),M,$,st;try{M=x.fromHex(k,V),$=x.fromHex(B.slice(0,F),V),st=A.multiplyUnsafe(j)}catch{return!1}if(!V&&M.isSmallOrder())return!1;let Q=rt(_,$.toRawBytes(),M.toRawBytes(),b);return $.add(M.multiplyUnsafe(Q)).subtract(st).clearCofactor().equals(x.ZERO)}return A._setWindowSize(8),{CURVE:t,getPublicKey:nt,sign:Nt,verify:I,ExtendedPoint:x,utils:{getExtendedPublicKey:P,randomPrivateKey:()=>i(e.BYTES),precompute(B=8,b=x.BASE){return b._setWindowSize(B),b.multiply(BigInt(3)),b}}}}var lo=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),la=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Ip=BigInt(0),Df=BigInt(1),co=BigInt(2),Pf=BigInt(5),ua=BigInt(10),Of=BigInt(20),Vf=BigInt(40),fa=BigInt(80);function Ff(r){let t=lo,n=r*r%t*r%t,s=X(n,co,t)*n%t,o=X(s,Df,t)*r%t,i=X(o,Pf,t)*o%t,a=X(i,ua,t)*i%t,c=X(a,Of,t)*a%t,l=X(c,Vf,t)*c%t,f=X(l,fa,t)*l%t,u=X(f,fa,t)*l%t,h=X(u,ua,t)*i%t;return{pow_p_5_8:X(h,co,t)*r%t,b2:n}}function Hf(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Mf(r,t){let e=lo,n=Y(t*t*t,e),s=Y(n*n*t,e),o=Ff(r*s).pow_p_5_8,i=Y(r*n*o,e),a=Y(t*i*i,e),c=i,l=Y(i*la,e),f=a===r,u=a===Y(-r,e),h=a===Y(-r*la,e);return f&&(i=c),(u||h)&&(i=l),oa(i,e)&&(i=Y(-i,e)),{isValid:f||u,value:i}}var te=ln(lo,void 0,!0),uo={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:te,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:or,randomBytes:nr,adjustScalarBytes:Hf,uvRatio:Mf},ir=hn(uo);function ha(r,t,e){if(t.length>255)throw new Error("Context is too big");return rn(Js("SigEd25519 no Ed25519 collisions"),new Uint8Array([e?1:0,t.length]),t,r)}var Rp=hn({...uo,domain:ha}),Np=hn({...uo,domain:ha,prehash:or});var Kf=(te.ORDER+BigInt(3))/BigInt(8),Tp=te.pow(co,Kf),Lp=te.sqrt(te.neg(te.ONE)),_p=(te.ORDER-BigInt(5))/BigInt(8),Up=BigInt(486662);var Cp=ia(te,te.neg(BigInt(486664)));var Dp=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Pp=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Op=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Vp=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var Fp=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var ar=32,ee=64,dn=32;function da(){let r=ir.utils.randomPrivateKey(),t=ir.getPublicKey(r);return{privateKey:ya(r,t),publicKey:t}}function pa(r){if(r.length!==dn)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 t=r,e=ir.getPublicKey(t);return{privateKey:ya(t,e),publicKey:e}}function ga(r,t){let e=r.subarray(0,dn);return ir.sign(t instanceof Uint8Array?t:t.subarray(),e)}function ma(r,t,e){return ir.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}function ya(r,t){let e=new Uint8Array(ee);for(let n=0;n<dn;n++)e[n]=r[n],e[dn+n]=t[n];return e}var At={get(r=globalThis){let t=r.crypto;if(t==null||t.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 t}};var fo={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function ba(r){let t=r?.algorithm??"AES-GCM",e=r?.keyLength??16,n=r?.nonceLength??12,s=r?.digest??"SHA-256",o=r?.saltLength??16,i=r?.iterations??32767,a=At.get();e*=8;async function c(u,h){let m=a.getRandomValues(new Uint8Array(o)),g=a.getRandomValues(new Uint8Array(n)),d={name:t,iv:g};typeof h=="string"&&(h=Z(h));let p;if(h.length===0){p=await a.subtle.importKey("jwk",fo,{name:"AES-GCM"},!0,["encrypt"]);try{let v={name:"PBKDF2",salt:m,iterations:i,hash:{name:s}},w=await a.subtle.importKey("raw",h,{name:"PBKDF2"},!1,["deriveKey"]);p=await a.subtle.deriveKey(v,w,{name:t,length:e},!0,["encrypt"])}catch{p=await a.subtle.importKey("jwk",fo,{name:"AES-GCM"},!0,["encrypt"])}}else{let v={name:"PBKDF2",salt:m,iterations:i,hash:{name:s}},w=await a.subtle.importKey("raw",h,{name:"PBKDF2"},!1,["deriveKey"]);p=await a.subtle.deriveKey(v,w,{name:t,length:e},!0,["encrypt"])}let y=await a.subtle.encrypt(d,p,u);return Bt([m,d.iv,new Uint8Array(y)])}async function l(u,h){let m=u.subarray(0,o),g=u.subarray(o,o+n),d=u.subarray(o+n),p={name:t,iv:g};typeof h=="string"&&(h=Z(h));let y;if(h.length===0)try{let w={name:"PBKDF2",salt:m,iterations:i,hash:{name:s}},T=await a.subtle.importKey("raw",h,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(w,T,{name:t,length:e},!0,["decrypt"])}catch{y=await a.subtle.importKey("jwk",fo,{name:"AES-GCM"},!0,["decrypt"])}else{let w={name:"PBKDF2",salt:m,iterations:i,hash:{name:s}},T=await a.subtle.importKey("raw",h,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(w,T,{name:t,length:e},!0,["decrypt"])}let v=await a.subtle.decrypt(p,y,d);return new Uint8Array(v)}return{encrypt:c,decrypt:l}}async function cr(r,t){let n=await ba().encrypt(r,t);return Os.encode(n)}var Gf=Math.pow(2,7),zf=Math.pow(2,14),jf=Math.pow(2,21),ho=Math.pow(2,28),po=Math.pow(2,35),go=Math.pow(2,42),mo=Math.pow(2,49),G=128,xt=127;function ut(r){if(r<Gf)return 1;if(r<zf)return 2;if(r<jf)return 3;if(r<ho)return 4;if(r<po)return 5;if(r<go)return 6;if(r<mo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function yo(r,t,e=0){switch(ut(r)){case 8:t[e++]=r&255|G,r/=128;case 7:t[e++]=r&255|G,r/=128;case 6:t[e++]=r&255|G,r/=128;case 5:t[e++]=r&255|G,r/=128;case 4:t[e++]=r&255|G,r>>>=7;case 3:t[e++]=r&255|G,r>>>=7;case 2:t[e++]=r&255|G,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Wf(r,t,e=0){switch(ut(r)){case 8:t.set(e++,r&255|G),r/=128;case 7:t.set(e++,r&255|G),r/=128;case 6:t.set(e++,r&255|G),r/=128;case 5:t.set(e++,r&255|G),r/=128;case 4:t.set(e++,r&255|G),r>>>=7;case 3:t.set(e++,r&255|G),r>>>=7;case 2:t.set(e++,r&255|G),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function bo(r,t){let e=r[t],n=0;if(n+=e&xt,e<G||(e=r[t+1],n+=(e&xt)<<7,e<G)||(e=r[t+2],n+=(e&xt)<<14,e<G)||(e=r[t+3],n+=(e&xt)<<21,e<G)||(e=r[t+4],n+=(e&xt)*ho,e<G)||(e=r[t+5],n+=(e&xt)*po,e<G)||(e=r[t+6],n+=(e&xt)*go,e<G)||(e=r[t+7],n+=(e&xt)*mo,e<G))return n;throw new RangeError("Could not decode varint")}function Yf(r,t){let e=r.get(t),n=0;if(n+=e&xt,e<G||(e=r.get(t+1),n+=(e&xt)<<7,e<G)||(e=r.get(t+2),n+=(e&xt)<<14,e<G)||(e=r.get(t+3),n+=(e&xt)<<21,e<G)||(e=r.get(t+4),n+=(e&xt)*ho,e<G)||(e=r.get(t+5),n+=(e&xt)*po,e<G)||(e=r.get(t+6),n+=(e&xt)*go,e<G)||(e=r.get(t+7),n+=(e&xt)*mo,e<G))return n;throw new RangeError("Could not decode varint")}function Be(r,t,e=0){return t==null&&(t=wt(ut(r))),t instanceof Uint8Array?yo(r,t,e):Wf(r,t,e)}function re(r,t=0){return r instanceof Uint8Array?bo(r,t):Yf(r,t)}var wo=new Float32Array([-0]),Ae=new Uint8Array(wo.buffer);function wa(r,t,e){wo[0]=r,t[e]=Ae[0],t[e+1]=Ae[1],t[e+2]=Ae[2],t[e+3]=Ae[3]}function xa(r,t){return Ae[0]=r[t],Ae[1]=r[t+1],Ae[2]=r[t+2],Ae[3]=r[t+3],wo[0]}var xo=new Float64Array([-0]),vt=new Uint8Array(xo.buffer);function va(r,t,e){xo[0]=r,t[e]=vt[0],t[e+1]=vt[1],t[e+2]=vt[2],t[e+3]=vt[3],t[e+4]=vt[4],t[e+5]=vt[5],t[e+6]=vt[6],t[e+7]=vt[7]}function Ea(r,t){return vt[0]=r[t],vt[1]=r[t+1],vt[2]=r[t+2],vt[3]=r[t+3],vt[4]=r[t+4],vt[5]=r[t+5],vt[6]=r[t+6],vt[7]=r[t+7],xo[0]}var Zf=BigInt(Number.MAX_SAFE_INTEGER),Jf=BigInt(Number.MIN_SAFE_INTEGER),Rt=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return Fe;if(t<Zf&&t>Jf)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,s=t-(n<<32n);return e&&(n=~n|0n,s=~s|0n,++s>Ba&&(s=0n,++n>Ba&&(n=0n))),new r(Number(s),Number(n))}static fromNumber(t){if(t===0)return Fe;let e=t<0;e&&(t=-t);let n=t>>>0,s=(t-n)/4294967296>>>0;return e&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new r(n,s)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):Fe}},Fe=new Rt(0,0);Fe.toBigInt=function(){return 0n};Fe.zzEncode=Fe.zzDecode=function(){return this};Fe.length=function(){return 1};var Ba=4294967296n;function Aa(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Sa(r,t,e){if(e-t<1)return"";let s,o=[],i=0,a;for(;t<e;)a=r[t++],a<128?o[i++]=a:a>191&&a<224?o[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,o[i++]=55296+(a>>10),o[i++]=56320+(a&1023)):o[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,o)),i=0);return s!=null?(i>0&&s.push(String.fromCharCode.apply(String,o.slice(0,i))),s.join("")):String.fromCharCode.apply(String,o.slice(0,i))}function vo(r,t,e){let n=e,s,o;for(let i=0;i<r.length;++i)s=r.charCodeAt(i),s<128?t[e++]=s:s<2048?(t[e++]=s>>6|192,t[e++]=s&63|128):(s&64512)===55296&&((o=r.charCodeAt(i+1))&64512)===56320?(s=65536+((s&1023)<<10)+(o&1023),++i,t[e++]=s>>18|240,t[e++]=s>>12&63|128,t[e++]=s>>6&63|128,t[e++]=s&63|128):(t[e++]=s>>12|224,t[e++]=s>>6&63|128,t[e++]=s&63|128);return e-n}function Ot(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function gn(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Eo=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Ot(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ot(this,4);return gn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ot(this,4);return gn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ot(this,4);let t=xa(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Ot(this,4);let t=Ea(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw Ot(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Sa(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Ot(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Ot(this);while(this.buf[this.pos++]&128);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Rt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw Ot(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw Ot(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ot(this,8);let t=gn(this.buf,this.pos+=4),e=gn(this.buf,this.pos+=4);return new Rt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=bo(this.buf,this.pos);return this.pos+=ut(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Bo(r){return new Eo(r instanceof Uint8Array?r:r.subarray())}function ne(r,t,e){let n=Bo(r);return t.decode(n,void 0,e)}function Ao(r){let t=r??8192,e=t>>>1,n,s=t;return function(i){if(i<1||i>e)return wt(i);s+i>t&&(n=wt(t),s=0);let a=n.subarray(s,s+=i);return s&7&&(s=(s|7)+1),a}}var He=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function So(){}var Io=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Xf=Ao();function Qf(r){return globalThis.Buffer!=null?wt(r):Xf(r)}var _r=class{len;head;tail;states;constructor(){this.len=0,this.head=new He(So,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new He(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Ro((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(mn,10,Rt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Rt.fromBigInt(t);return this._push(mn,e.length(),e)}uint64Number(t){return this._push(yo,ut(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=Rt.fromBigInt(t).zzEncode();return this._push(mn,e.length(),e)}sint64Number(t){let e=Rt.fromNumber(t).zzEncode();return this._push(mn,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ko,1,t?1:0)}fixed32(t){return this._push(Lr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Rt.fromBigInt(t);return this._push(Lr,4,e.lo)._push(Lr,4,e.hi)}fixed64Number(t){let e=Rt.fromNumber(t);return this._push(Lr,4,e.lo)._push(Lr,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(wa,4,t)}double(t){return this._push(va,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(ko,1,0):this.uint32(e)._push(eh,e,t)}string(t){let e=Aa(t);return e!==0?this.uint32(e)._push(vo,e,t):this._push(ko,1,0)}fork(){return this.states=new Io(this),this.head=this.tail=new He(So,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 He(So,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Qf(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function ko(r,t,e){t[e]=r&255}function th(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Ro=class extends He{next;constructor(t,e){super(th,t,e),this.next=void 0}};function mn(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function Lr(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function eh(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(_r.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(rh,t,r),this},_r.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(nh,t,r),this});function rh(r,t,e){t.set(r,e)}function nh(r,t,e){r.length<40?vo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(Z(r),e)}function No(){return new _r}function se(r,t){let e=No();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var lr;(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"})(lr||(lr={}));function yn(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function ur(r){function t(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let e=function(o,i){let a=t(o);i.int32(a)},n=function(o){let i=o.int32();return t(i)};return yn("enum",lr.VARINT,e,n)}function oe(r,t){return yn("message",lr.LENGTH_DELIMITED,r,t)}var gt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1"})(gt||(gt={}));var To;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1"})(To||(To={}));(function(r){r.codec=()=>ur(To)})(gt||(gt={}));var Se;(function(r){let t;r.codec=()=>(t==null&&(t=oe((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),gt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),s.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let s={},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let i=e.uint32();switch(i>>>3){case 1:s.Type=gt.codec().decode(e);break;case 2:s.Data=e.bytes();break;default:e.skipType(i&7);break}}return s})),t),r.encode=e=>se(e,r.codec()),r.decode=e=>ne(e,r.codec())})(Se||(Se={}));var ke;(function(r){let t;r.codec=()=>(t==null&&(t=oe((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),gt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),s.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let s={},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let i=e.uint32();switch(i>>>3){case 1:s.Type=gt.codec().decode(e);break;case 2:s.Data=e.bytes();break;default:e.skipType(i&7);break}}return s})),t),r.encode=e=>se(e,r.codec()),r.decode=e=>ne(e,r.codec())})(ke||(ke={}));var Ur=class{_key;constructor(t){this._key=fr(t,ar)}verify(t,e){return ma(this._key,e,t)}marshal(){return this._key}get bytes(){return Se.encode({Type:gt.Ed25519,Data:this.marshal()}).subarray()}equals(t){return bt(this.bytes,t.bytes)}hash(){let t=pt.digest(this.bytes);return Tt(t)?t.then(({bytes:e})=>e):t.bytes}},Me=class{_key;_publicKey;constructor(t,e){this._key=fr(t,ee),this._publicKey=fr(e,ar)}sign(t){return ga(this._key,t)}get public(){return new Ur(this._publicKey)}marshal(){return this._key}get bytes(){return ke.encode({Type:gt.Ed25519,Data:this.marshal()}).subarray()}equals(t){return bt(this.bytes,t.bytes)}async hash(){let t=pt.digest(this.bytes),e;return Tt(t)?{bytes:e}=await t:e=t.bytes,e}async id(){let t=ge.digest(this.public.bytes);return at.encode(t.bytes).substring(1)}async export(t,e="libp2p-key"){if(e==="libp2p-key")return cr(this.bytes,t);throw new U(`export format '${e}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function sh(r){if(r.length>ee){r=fr(r,ee+ar);let n=r.subarray(0,ee),s=r.subarray(ee,r.length);return new Me(n,s)}r=fr(r,ee);let t=r.subarray(0,ee),e=r.subarray(ar);return new Me(t,e)}function oh(r){return r=fr(r,ar),new Ur(r)}async function ih(){let{privateKey:r,publicKey:t}=da();return new Me(r,t)}async function Ia(r){let{privateKey:t,publicKey:e}=pa(r);return new Me(t,e)}function fr(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new U(`Key must be a Uint8Array of length ${t}, got ${r.length}`,"ERR_INVALID_KEY_TYPE");return r}function z(r,t="utf8"){let e=Qr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):e.encoder.encode(r).substring(1)}var Ko={};lt(Ko,{MAX_RSA_KEY_SIZE:()=>Gr,RsaPrivateKey:()=>mr,RsaPublicKey:()=>qr,fromJwk:()=>Uh,generateKeyPair:()=>Ch,unmarshalRsaPrivateKey:()=>Ho,unmarshalRsaPublicKey:()=>_h});function Ke(r){if(isNaN(r)||r<=0)throw new U("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return nr(r)}var Te={};lt(Te,{exportToPem:()=>Ih,importFromPem:()=>Rh,jwkToPkcs1:()=>Bh,jwkToPkix:()=>Sh,pkcs1ToJwk:()=>Eh,pkixToJwk:()=>Ah});var bn=class extends er{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,tn(t);let n=be(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let s=this.blockLen,o=new Uint8Array(s);o.set(n.length>s?t.create().update(n).digest():n);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=t.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),o.fill(0)}update(t){return tr(this),this.iHash.update(t),this}digestInto(t){tr(this),Zs(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:s,destroyed:o,blockLen:i,outputLen:a}=this;return t=t,t.finished=s,t.destroyed=o,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Cr=(r,t,e)=>new bn(r,t).update(e).digest();Cr.create=(r,t)=>new bn(r,t);function ah(r,t,e,n){tn(r);let s=Ji({dkLen:32,asyncTick:10},n),{c:o,dkLen:i,asyncTick:a}=s;if(Qe(o),Qe(i),Qe(a),o<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=be(t),l=be(e),f=new Uint8Array(i),u=Cr.create(r,c),h=u._cloneInto().update(l);return{c:o,dkLen:i,asyncTick:a,DK:f,PRF:u,PRFSalt:h}}function ch(r,t,e,n,s){return r.destroy(),t.destroy(),n&&n.destroy(),s.fill(0),e}async function Uo(r,t,e,n){let{c:s,dkLen:o,asyncTick:i,DK:a,PRF:c,PRFSalt:l}=ah(r,t,e,n),f,u=new Uint8Array(4),h=rr(u),m=new Uint8Array(c.outputLen);for(let g=1,d=0;d<o;g++,d+=c.outputLen){let p=a.subarray(d,d+c.outputLen);h.setInt32(0,g,!1),(f=l._cloneInto(f)).update(u).digestInto(m),p.set(m.subarray(0,p.length)),await Zi(s-1,i,()=>{c._cloneInto(f).update(m).digestInto(m);for(let y=0;y<p.length;y++)p[y]^=m[y]})}return ch(c,l,a,f,m)}var H=Bs(Ra());function $e(r,t){let e=0;if(r.length===1)return r[0];for(let n=r.length-1;n>=0;n--)e+=r[r.length-1-n]*Math.pow(2,t*n);return e}function Ie(r,t,e=-1){let n=e,s=r,o=0,i=Math.pow(2,t);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 l=new Uint8Array(c);for(let f=a-1;f>=0;f--){let u=Math.pow(2,f*t);l[o-f-1]=Math.floor(s/u),s-=l[o-f-1]*u}return c}i*=Math.pow(2,t)}return new ArrayBuffer(0)}function vn(...r){let t=0,e=0;for(let o of r)t+=o.length;let n=new ArrayBuffer(t),s=new Uint8Array(n);for(let o of r)s.set(o,e),e+=o.length;return s}function Do(){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 t=new ArrayBuffer(this.valueHex.byteLength),e=new Uint8Array(t);for(let a=0;a<this.valueHex.byteLength;a++)e[a]=0;e[0]=r[0]&128;let n=$e(e,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,$e(o,8)-n}function Na(r){let t=r<0?r*-1:r,e=128;for(let n=1;n<8;n++){if(t<=e){if(r<0){let i=e-t,a=Ie(i,8,n),c=new Uint8Array(a);return c[0]|=128,a}let s=Ie(t,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}e*=Math.pow(2,8)}return new ArrayBuffer(0)}function Ta(r,t){if(r.byteLength!==t.byteLength)return!1;let e=new Uint8Array(r),n=new Uint8Array(t);for(let s=0;s<e.length;s++)if(e[s]!==n[s])return!1;return!0}function kt(r,t){let e=r.toString(10);if(t<e.length)return"";let n=t-e.length,s=new Array(n);for(let i=0;i<n;i++)s[i]="0";return s.join("").concat(e)}var jg=Math.log(2);function En(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Po(r){let t=0,e=0;for(let s=0;s<r.length;s++){let o=r[s];t+=o.byteLength}let n=new Uint8Array(t);for(let s=0;s<r.length;s++){let o=r[s];n.set(new Uint8Array(o),e),e+=o.byteLength}return n.buffer}function ue(r,t,e,n){return t instanceof Uint8Array?t.byteLength?e<0?(r.error="Wrong parameter: inputOffset less than zero",!1):n<0?(r.error="Wrong parameter: inputLength less than zero",!1):t.byteLength-e-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 Pr=class{constructor(){this.items=[]}write(t){this.items.push(t)}final(){return Po(this.items)}},Dr=[new Uint8Array([1])],La="0123456789";var pr="",Ft=new ArrayBuffer(0),Oo=new Uint8Array(0),Or="EndOfContent",Ua="OCTET STRING",Ca="BIT STRING";function fe(r){var t;return t=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?H.BufferSourceConverter.toUint8Array(o.valueHex):Oo}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(!ue(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:H.Convert.ToHex(this.valueHexView)}}},t.NAME="hexBlock",t}var ae=class{constructor({blockLength:t=0,error:e=pr,warnings:n=[],valueBeforeDecode:s=Oo}={}){this.blockLength=t,this.error=e,this.warnings=n,this.valueBeforeDecodeView=H.BufferSourceConverter.toUint8Array(s)}static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(t){this.valueBeforeDecodeView=new Uint8Array(t)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:H.Convert.ToHex(this.valueBeforeDecodeView)}}};ae.NAME="baseBlock";var Et=class extends ae{fromBER(t,e,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(t,e){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}};Et.NAME="valueBlock";var Bn=class extends fe(ae){constructor({idBlock:t={}}={}){var e,n,s,o;super(),t?(this.isHexOnly=(e=t.isHexOnly)!==null&&e!==void 0?e:!1,this.valueHexView=t.valueHex?H.BufferSourceConverter.toUint8Array(t.valueHex):Oo,this.tagClass=(n=t.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(s=t.tagNumber)!==null&&s!==void 0?s:-1,this.isConstructed=(o=t.isConstructed)!==null&&o!==void 0?o:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(t=!1){let e=0;switch(this.tagClass){case 1:e|=0;break;case 2:e|=64;break;case 3:e|=128;break;case 4:e|=192;break;default:return this.error="Unknown tag class",Ft}if(this.isConstructed&&(e|=32),this.tagNumber<31&&!this.isHexOnly){let s=new Uint8Array(1);if(!t){let o=this.tagNumber;o&=31,e|=o,s[0]=e}return s.buffer}if(!this.isHexOnly){let s=Ie(this.tagNumber,7),o=new Uint8Array(s),i=s.byteLength,a=new Uint8Array(i+1);if(a[0]=e|31,!t){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]=e|31,!t){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(t,e,n){let s=H.BufferSourceConverter.toUint8Array(t);if(!ue(this,s,e,n))return-1;let o=s.subarray(e,e+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,l=this.valueHexView=new Uint8Array(255),f=255;for(;o[c]&128;){if(l[c-1]=o[c]&127,c++,c>=o.length)return this.error="End of input reached before message was fully decoded",-1;if(c===f){f+=255;let h=new Uint8Array(f);for(let m=0;m<l.length;m++)h[m]=l[m];l=this.valueHexView=new Uint8Array(f)}}this.blockLength=c+1,l[c-1]=o[c]&127;let u=new Uint8Array(c);for(let h=0;h<c;h++)u[h]=l[h];l=this.valueHexView=new Uint8Array(c),l.set(u),this.blockLength<=9?this.tagNumber=$e(l,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 e+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}};Bn.NAME="identificationBlock";var An=class extends ae{constructor({lenBlock:t={}}={}){var e,n,s;super(),this.isIndefiniteForm=(e=t.isIndefiniteForm)!==null&&e!==void 0?e:!1,this.longFormUsed=(n=t.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(s=t.length)!==null&&s!==void 0?s:0}fromBER(t,e,n){let s=H.BufferSourceConverter.toUint8Array(t);if(!ue(this,s,e,n))return-1;let o=s.subarray(e,e+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,e+this.blockLength;if(this.longFormUsed=!!(o[0]&128),this.longFormUsed===!1)return this.length=o[0],this.blockLength=1,e+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=e+1,c=s.subarray(a,a+i);return c[i-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=$e(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=i+1,e+this.blockLength}toBER(t=!1){let e,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return e=new ArrayBuffer(1),t===!1&&(n=new Uint8Array(e),n[0]=128),e;if(this.longFormUsed){let s=Ie(this.length,8);if(s.byteLength>127)return this.error="Too big length",Ft;if(e=new ArrayBuffer(s.byteLength+1),t)return e;let o=new Uint8Array(s);n=new Uint8Array(e),n[0]=s.byteLength|128;for(let i=0;i<s.byteLength;i++)n[i+1]=o[i];return e}return e=new ArrayBuffer(1),t===!1&&(n=new Uint8Array(e),n[0]=this.length),e}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};An.NAME="lengthBlock";var S={},mt=class extends ae{constructor({name:t=pr,optional:e=!1,primitiveSchema:n,...s}={},o){super(s),this.name=t,this.optional=e,n&&(this.primitiveSchema=n),this.idBlock=new Bn(s),this.lenBlock=new An(s),this.valueBlock=o?new o(s):new Et(s)}fromBER(t,e,n){let s=this.valueBlock.fromBER(t,e,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(t,e){let n=e||new Pr;e||Da(this);let s=this.idBlock.toBER(t);if(n.write(s),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(t,n),n.write(new ArrayBuffer(2));else{let o=this.valueBlock.toBER(t);this.lenBlock.length=o.byteLength;let i=this.lenBlock.toBER(t);n.write(i),n.write(o)}return e?Ft:n.final()}toJSON(){let t={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(t.primitiveSchema=this.primitiveSchema.toJSON()),t}toString(t="ascii"){return t==="ascii"?this.onAsciiEncoding():H.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${H.Convert.ToHex(this.valueBlock.valueBeforeDecodeView)}`}isEqual(t){if(this===t)return!0;if(!(t instanceof this.constructor))return!1;let e=this.toBER(),n=t.toBER();return Ta(e,n)}};mt.NAME="BaseBlock";function Da(r){if(r instanceof S.Constructed)for(let t of r.valueBlock.value)Da(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var Sn=class extends mt{constructor({value:t=pr,...e}={},n){super(e,n),t&&this.fromString(t)}getValue(){return this.valueBlock.value}setValue(t){this.valueBlock.value=t}fromBER(t,e,n){let s=this.valueBlock.fromBER(t,e,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}'`}};Sn.NAME="BaseStringBlock";var kn=class extends fe(Et){constructor({isHexOnly:t=!0,...e}={}){super(e),this.isHexOnly=t}};kn.NAME="PrimitiveValueBlock";var Pa,In=class extends mt{constructor(t={}){super(t,kn),this.idBlock.isConstructed=!1}};Pa=In;S.Primitive=Pa;In.NAME="PRIMITIVE";function yh(r,t){if(r instanceof t)return r;let e=new t;return e.idBlock=r.idBlock,e.lenBlock=r.lenBlock,e.warnings=r.warnings,e.valueBeforeDecodeView=r.valueBeforeDecodeView,e}function is(r,t=0,e=r.length){let n=t,s=new mt({},Et),o=new ae;if(!ue(o,r,t,e))return s.error=o.error,{offset:-1,result:s};if(!r.subarray(t,t+e).length)return s.error="Zero buffer length",{offset:-1,result:s};let a=s.idBlock.fromBER(r,t,e);if(s.idBlock.warnings.length&&s.warnings.concat(s.idBlock.warnings),a===-1)return s.error=s.idBlock.error,{offset:-1,result:s};if(t=a,e-=s.idBlock.blockLength,a=s.lenBlock.fromBER(r,t,e),s.lenBlock.warnings.length&&s.warnings.concat(s.lenBlock.warnings),a===-1)return s.error=s.lenBlock.error,{offset:-1,result:s};if(t=a,e-=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=mt;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=S.EndOfContent;break;case 1:c=S.Boolean;break;case 2:c=S.Integer;break;case 3:c=S.BitString;break;case 4:c=S.OctetString;break;case 5:c=S.Null;break;case 6:c=S.ObjectIdentifier;break;case 10:c=S.Enumerated;break;case 12:c=S.Utf8String;break;case 13:c=S.RelativeObjectIdentifier;break;case 14:c=S.TIME;break;case 15:return s.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:s};case 16:c=S.Sequence;break;case 17:c=S.Set;break;case 18:c=S.NumericString;break;case 19:c=S.PrintableString;break;case 20:c=S.TeletexString;break;case 21:c=S.VideotexString;break;case 22:c=S.IA5String;break;case 23:c=S.UTCTime;break;case 24:c=S.GeneralizedTime;break;case 25:c=S.GraphicString;break;case 26:c=S.VisibleString;break;case 27:c=S.GeneralString;break;case 28:c=S.UniversalString;break;case 29:c=S.CharacterString;break;case 30:c=S.BmpString;break;case 31:c=S.DATE;break;case 32:c=S.TimeOfDay;break;case 33:c=S.DateTime;break;case 34:c=S.Duration;break;default:{let l=s.idBlock.isConstructed?new S.Constructed:new S.Primitive;l.idBlock=s.idBlock,l.lenBlock=s.lenBlock,l.warnings=s.warnings,s=l}}break;case 2:case 3:case 4:default:c=s.idBlock.isConstructed?S.Constructed:S.Primitive}return s=yh(s,c),a=s.fromBER(r,t,s.lenBlock.isIndefiniteForm?e:s.lenBlock.length),s.valueBeforeDecodeView=r.subarray(n,n+s.blockLength),{offset:a,result:s}}function gr(r){if(!r.byteLength){let t=new mt({},Et);return t.error="Input buffer has zero length",{offset:-1,result:t}}return is(H.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function bh(r,t){return r?1:t}var $t=class extends Et{constructor({value:t=[],isIndefiniteForm:e=!1,...n}={}){super(n),this.value=t,this.isIndefiniteForm=e}fromBER(t,e,n){let s=H.BufferSourceConverter.toUint8Array(t);if(!ue(this,s,e,n))return-1;if(this.valueBeforeDecodeView=s.subarray(e,e+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),e;let o=e;for(;bh(this.isIndefiniteForm,n)>0;){let i=is(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===Or)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===Or?this.value.pop():this.warnings.push("No EndOfContent block encoded")),o}toBER(t,e){let n=e||new Pr;for(let s=0;s<this.value.length;s++)this.value[s].toBER(t,n);return e?Ft:n.final()}toJSON(){let t={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let e of this.value)t.value.push(e.toJSON());return t}};$t.NAME="ConstructedValueBlock";var Oa,Re=class extends mt{constructor(t={}){super(t,$t),this.idBlock.isConstructed=!0}fromBER(t,e,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let s=this.valueBlock.fromBER(t,e,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 t=[];for(let n of this.valueBlock.value)t.push(n.toString("ascii").split(`
3
3
  `).map(s=>` ${s}`).join(`
4
4
  `));let e=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return t.length?`${e} :
5
5
  ${t.join(`
6
- `)}`:`${e} :`}};Oa=Re;S.Constructed=Oa;Re.NAME="CONSTRUCTED";var In=class extends Et{fromBER(t,e,n){return e}toBER(t){return Ft}};In.override="EndOfContentValueBlock";var Va,Rn=class extends mt{constructor(t={}){super(t,In),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};Va=Rn;S.EndOfContent=Va;Rn.NAME=Pr;var Fa,Ne=class extends mt{constructor(t={}){super(t,Et),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(t,e,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,e+n>t.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):e+n}toBER(t,e){let n=new ArrayBuffer(2);if(!t){let s=new Uint8Array(n);s[0]=5,s[1]=0}return e&&e.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};Fa=Ne;S.Null=Fa;Ne.NAME="NULL";var Nn=class extends fe(Et){constructor({value:t,...e}={}){super(e),e.valueHex?this.valueHexView=H.BufferSourceConverter.toUint8Array(e.valueHex):this.valueHexView=new Uint8Array(1),t&&(this.value=t)}get value(){for(let t of this.valueHexView)if(t>0)return!0;return!1}set value(t){this.valueHexView[0]=t?255:0}fromBER(t,e,n){let s=H.BufferSourceConverter.toUint8Array(t);return ue(this,s,e,n)?(this.valueHexView=s.subarray(e,e+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,Do.call(this),this.blockLength=n,e+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};Nn.NAME="BooleanValueBlock";var Ha,Tn=class extends mt{constructor(t={}){super(t,Nn),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}getValue(){return this.valueBlock.value}setValue(t){this.valueBlock.value=t}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};Ha=Tn;S.Boolean=Ha;Tn.NAME="BOOLEAN";var Ln=class extends fe($t){constructor({isConstructed:t=!1,...e}={}){super(e),this.isConstructed=t}fromBER(t,e,n){let s=0;if(this.isConstructed){if(this.isHexOnly=!1,s=$t.prototype.fromBER.call(this,t,e,n),s===-1)return s;for(let o=0;o<this.value.length;o++){let i=this.value[o].constructor.NAME;if(i===Pr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(i!==Ua)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,s=super.fromBER(t,e,n),this.blockLength=n;return s}toBER(t,e){return this.isConstructed?$t.prototype.toBER.call(this,t,e):t?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};Ln.NAME="OctetStringValueBlock";var Ma,ce=class r extends mt{constructor({idBlock:t={},lenBlock:e={},...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,...t},lenBlock:{...e,isIndefiniteForm:!!n.isIndefiniteForm},...n},Ln),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(t,e,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),e;if(!this.valueBlock.isConstructed){let o=(t instanceof ArrayBuffer?new Uint8Array(t):t).subarray(e,e+n);try{if(o.byteLength){let i=os(o,0,o.byteLength);i.offset!==-1&&i.offset===n&&(this.valueBlock.value=[i.result])}}catch{}}return super.fromBER(t,e,n)}onAsciiEncoding(){return this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length?Re.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${H.Convert.ToHex(this.valueBlock.valueHexView)}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let t=[];for(let e of this.valueBlock.value)e instanceof r&&t.push(e.valueBlock.valueHexView);return H.BufferSourceConverter.concat(t)}};Ma=ce;S.OctetString=Ma;ce.NAME=Ua;var _n=class extends fe($t){constructor({unusedBits:t=0,isConstructed:e=!1,...n}={}){super(n),this.unusedBits=t,this.isConstructed=e,this.blockLength=this.valueHexView.byteLength}fromBER(t,e,n){if(!n)return e;let s=-1;if(this.isConstructed){if(s=$t.prototype.fromBER.call(this,t,e,n),s===-1)return s;for(let a of this.value){let c=a.constructor.NAME;if(c===Pr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==Ca)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let l=a.valueBlock;if(this.unusedBits>0&&l.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=l.unusedBits}return s}let o=H.BufferSourceConverter.toUint8Array(t);if(!ue(this,o,e,n))return-1;let i=o.subarray(e,e+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=os(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,e+n}toBER(t,e){if(this.isConstructed)return $t.prototype.toBER.call(this,t,e);if(t)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}}};_n.NAME="BitStringValueBlock";var Ka,dr=class extends mt{constructor({idBlock:t={},lenBlock:e={},...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,...t},lenBlock:{...e,isIndefiniteForm:!!n.isIndefiniteForm},...n},_n),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(t,e,n){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(t,e,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return Re.prototype.onAsciiEncoding.call(this);{let t=[],e=this.valueBlock.valueHexView;for(let s of e)t.push(s.toString(2).padStart(8,"0"));let n=t.join("");return`${this.constructor.NAME} : ${n.substring(0,n.length-this.valueBlock.unusedBits)}`}}};Ka=dr;S.BitString=Ka;dr.NAME=Ca;var $a;function wh(r,t){let e=new Uint8Array([0]),n=new Uint8Array(r),s=new Uint8Array(t),o=n.slice(0),i=o.length-1,a=s.slice(0),c=a.length-1,l=0,f=c<i?i:c,u=0;for(let h=f;h>=0;h--,u++){switch(!0){case u<a.length:l=o[i-u]+a[c-u]+e[0];break;default:l=o[i-u]+e[0]}switch(e[0]=l/10,!0){case u>=o.length:o=xn(new Uint8Array([l%10]),o);break;default:o[i-u]=l%10}}return e[0]>0&&(o=xn(e,o)),o}function _a(r){if(r>=Cr.length)for(let t=Cr.length;t<=r;t++){let e=new Uint8Array([0]),n=Cr[t-1].slice(0);for(let s=n.length-1;s>=0;s--){let o=new Uint8Array([(n[s]<<1)+e[0]]);e[0]=o[0]/10,n[s]=o[0]%10}e[0]>0&&(n=xn(e,n)),Cr.push(n)}return Cr[r]}function xh(r,t){let e=0,n=new Uint8Array(r),s=new Uint8Array(t),o=n.slice(0),i=o.length-1,a=s.slice(0),c=a.length-1,l,f=0;for(let u=c;u>=0;u--,f++)switch(l=o[i-f]-a[c-f]-e,!0){case l<0:e=1,o[i-f]=l+10;break;default:e=0,o[i-f]=l}if(e>0)for(let u=i-c+1;u>=0;u--,f++)if(l=o[i-f]-e,l<0)e=1,o[i-f]=l+10;else{e=0,o[i-f]=l;break}return o.slice()}var Or=class extends fe(Et){constructor({value:t,...e}={}){super(e),this._valueDec=0,e.valueHex&&this.setValueHex(),t!==void 0&&(this.valueDec=t)}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=Do.call(this)))}set valueDec(t){this._valueDec=t,this.isHexOnly=!1,this.valueHexView=new Uint8Array(Na(t))}get valueDec(){return this._valueDec}fromDER(t,e,n,s=0){let o=this.fromBER(t,e,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(t=!1){let e=this.valueHexView;switch(!0){case(e[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(e,1),this.valueHexView=n}break;case(e[0]===0&&(e[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(t)}fromBER(t,e,n){let s=super.fromBER(t,e,n);return s===-1||this.setValueHex(),s}toBER(t){return t?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let t=this.valueHexView.length*8-1,e=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 l=0;l<8;l++){if((s&1)===1)switch(n){case t:e=xh(_a(n),e),i="-";break;default:e=wh(e,_a(n))}n++,s>>=1}}for(let c=0;c<e.length;c++)e[c]&&(a=!0),a&&(i+=La.charAt(e[c]));return a===!1&&(i+=La.charAt(0)),i}};$a=Or;Or.NAME="IntegerValueBlock";Object.defineProperty($a.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var qa,ot=class r extends mt{constructor(t={}){super(t,Or),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return vn(),BigInt(this.valueBlock.toString())}static fromBigInt(t){vn();let e=BigInt(t),n=new Dr,s=e.toString(16).replace(/^-/,""),o=new Uint8Array(H.Convert.FromHex(s));if(e<0){let a=new Uint8Array(o.length+(o[0]&128?1:0));a[0]|=128;let l=BigInt(`0x${H.Convert.ToHex(a)}`)+e,f=H.BufferSourceConverter.toUint8Array(H.Convert.FromHex(l.toString(16)));f[0]|=128,n.write(f)}else o[0]&128&&n.write(new Uint8Array([0])),n.write(o);return new r({valueHex:n.final()})}convertToDER(){let t=new r({valueHex:this.valueBlock.valueHexView});return t.valueBlock.toDER(),t}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()}`}};qa=ot;S.Integer=qa;ot.NAME="INTEGER";var Ga,Un=class extends ot{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};Ga=Un;S.Enumerated=Ga;Un.NAME="ENUMERATED";var Vr=class extends fe(Et){constructor({valueDec:t=-1,isFirstSid:e=!1,...n}={}){super(n),this.valueDec=t,this.isFirstSid=e}fromBER(t,e,n){if(!n)return e;let s=H.BufferSourceConverter.toUint8Array(t);if(!ue(this,s,e,n))return-1;let o=s.subarray(e,e+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=$e(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),e+this.blockLength)}set valueBigInt(t){vn();let e=BigInt(t).toString(2);for(;e.length%7;)e="0"+e;let n=new Uint8Array(e.length/7);for(let s=0;s<n.length;s++)n[s]=parseInt(e.slice(s*7,s*7+7),2)+(s+1<n.length?128:0);this.fromBER(n.buffer,0,n.length)}toBER(t){if(this.isHexOnly){if(t)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 e=Ie(this.valueDec,7);if(e.byteLength===0)return this.error="Error during encoding SID value",Ft;let n=new Uint8Array(e.byteLength);if(!t){let s=new Uint8Array(e),o=e.byteLength-1;for(let i=0;i<o;i++)n[i]=s[i]|128;n[o]=s[o]}return n}toString(){let t="";if(this.isHexOnly)t=H.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let e=this.valueDec;this.valueDec<=39?t="0.":this.valueDec<=79?(t="1.",e-=40):(t="2.",e-=80),t+=e.toString()}else t=this.valueDec.toString();return t}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};Vr.NAME="sidBlock";var Cn=class extends Et{constructor({value:t=pr,...e}={}){super(e),this.value=[],t&&this.fromString(t)}fromBER(t,e,n){let s=e;for(;n>0;){let o=new Vr;if(s=o.fromBER(t,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(t){let e=[];for(let n=0;n<this.value.length;n++){let s=this.value[n].toBER(t);if(s.byteLength===0)return this.error=this.value[n].error,Ft;e.push(s)}return Po(e)}fromString(t){this.value=[];let e=0,n=0,s="",o=!1;do if(n=t.indexOf(".",e),n===-1?s=t.substring(e):s=t.substring(e,n),e=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 Vr;if(s>Number.MAX_SAFE_INTEGER){vn();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 t="",e=!1;for(let n=0;n<this.value.length;n++){e=this.value[n].isHexOnly;let s=this.value[n].toString();n!==0&&(t=`${t}.`),e?(s=`{${s}}`,this.value[n].isFirstSid?t=`2.{${s} - 80}`:t+=s):t+=s}return t}toJSON(){let t={...super.toJSON(),value:this.toString(),sidArray:[]};for(let e=0;e<this.value.length;e++)t.sidArray.push(this.value[e].toJSON());return t}};Cn.NAME="ObjectIdentifierValueBlock";var za,Vt=class extends mt{constructor(t={}){super(t,Cn),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}getValue(){return this.valueBlock.toString()}setValue(t){this.valueBlock.fromString(t)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};za=Vt;S.ObjectIdentifier=za;Vt.NAME="OBJECT IDENTIFIER";var Fr=class extends fe(ae){constructor({valueDec:t=0,...e}={}){super(e),this.valueDec=t}fromBER(t,e,n){if(n===0)return e;let s=H.BufferSourceConverter.toUint8Array(t);if(!ue(this,s,e,n))return-1;let o=s.subarray(e,e+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=$e(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),e+this.blockLength)}toBER(t){if(this.isHexOnly){if(t)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 e=Ie(this.valueDec,7);if(e.byteLength===0)return this.error="Error during encoding SID value",Ft;let n=new Uint8Array(e.byteLength);if(!t){let s=new Uint8Array(e),o=e.byteLength-1;for(let i=0;i<o;i++)n[i]=s[i]|128;n[o]=s[o]}return n.buffer}toString(){let t="";return this.isHexOnly?t=H.Convert.ToHex(this.valueHexView):t=this.valueDec.toString(),t}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};Fr.NAME="relativeSidBlock";var Dn=class extends Et{constructor({value:t=pr,...e}={}){super(e),this.value=[],t&&this.fromString(t)}fromBER(t,e,n){let s=e;for(;n>0;){let o=new Fr;if(s=o.fromBER(t,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(t,e){let n=[];for(let s=0;s<this.value.length;s++){let o=this.value[s].toBER(t);if(o.byteLength===0)return this.error=this.value[s].error,Ft;n.push(o)}return Po(n)}fromString(t){this.value=[];let e=0,n=0,s="";do{n=t.indexOf(".",e),n===-1?s=t.substring(e):s=t.substring(e,n),e=n+1;let o=new Fr;if(o.valueDec=parseInt(s,10),isNaN(o.valueDec))return!0;this.value.push(o)}while(n!==-1);return!0}toString(){let t="",e=!1;for(let n=0;n<this.value.length;n++){e=this.value[n].isHexOnly;let s=this.value[n].toString();n!==0&&(t=`${t}.`),e&&(s=`{${s}}`),t+=s}return t}toJSON(){let t={...super.toJSON(),value:this.toString(),sidArray:[]};for(let e=0;e<this.value.length;e++)t.sidArray.push(this.value[e].toJSON());return t}};Dn.NAME="RelativeObjectIdentifierValueBlock";var ja,Pn=class extends mt{constructor(t={}){super(t,Dn),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}getValue(){return this.valueBlock.toString()}setValue(t){this.valueBlock.fromString(t)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};ja=Pn;S.RelativeObjectIdentifier=ja;Pn.NAME="RelativeObjectIdentifier";var Wa,ft=class extends Re{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};Wa=ft;S.Sequence=Wa;ft.NAME="SEQUENCE";var Ya,On=class extends Re{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};Ya=On;S.Set=Ya;On.NAME="SET";var Vn=class extends fe(Et){constructor({...t}={}){super(t),this.isHexOnly=!0,this.value=pr}toJSON(){return{...super.toJSON(),value:this.value}}};Vn.NAME="StringValueBlock";var Fn=class extends Vn{};Fn.NAME="SimpleStringValueBlock";var St=class extends An{constructor({...t}={}){super(t,Fn)}fromBuffer(t){this.valueBlock.value=String.fromCharCode.apply(null,H.BufferSourceConverter.toUint8Array(t))}fromString(t){let e=t.length,n=this.valueBlock.valueHexView=new Uint8Array(e);for(let s=0;s<e;s++)n[s]=t.charCodeAt(s);this.valueBlock.value=t}};St.NAME="SIMPLE STRING";var Hn=class extends St{fromBuffer(t){this.valueBlock.valueHexView=H.BufferSourceConverter.toUint8Array(t);try{this.valueBlock.value=H.Convert.ToUtf8String(t)}catch(e){this.warnings.push(`Error during "decodeURIComponent": ${e}, using raw string`),this.valueBlock.value=H.Convert.ToBinary(t)}}fromString(t){this.valueBlock.valueHexView=new Uint8Array(H.Convert.FromUtf8String(t)),this.valueBlock.value=t}};Hn.NAME="Utf8StringValueBlock";var Za,le=class extends Hn{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};Za=le;S.Utf8String=Za;le.NAME="UTF8String";var Mn=class extends St{fromBuffer(t){this.valueBlock.value=H.Convert.ToUtf16String(t),this.valueBlock.valueHexView=H.BufferSourceConverter.toUint8Array(t)}fromString(t){this.valueBlock.value=t,this.valueBlock.valueHexView=new Uint8Array(H.Convert.FromUtf16String(t))}};Mn.NAME="BmpStringValueBlock";var Ja,Kn=class extends Mn{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};Ja=Kn;S.BmpString=Ja;Kn.NAME="BMPString";var $n=class extends St{fromBuffer(t){let e=ArrayBuffer.isView(t)?t.slice().buffer:t.slice(0),n=new Uint8Array(e);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(e))}fromString(t){let e=t.length,n=this.valueBlock.valueHexView=new Uint8Array(e*4);for(let s=0;s<e;s++){let o=Ie(t.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=t}};$n.NAME="UniversalStringValueBlock";var Xa,qn=class extends $n{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};Xa=qn;S.UniversalString=Xa;qn.NAME="UniversalString";var Qa,Gn=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};Qa=Gn;S.NumericString=Qa;Gn.NAME="NumericString";var tc,zn=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};tc=zn;S.PrintableString=tc;zn.NAME="PrintableString";var ec,jn=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};ec=jn;S.TeletexString=ec;jn.NAME="TeletexString";var rc,Wn=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};rc=Wn;S.VideotexString=rc;Wn.NAME="VideotexString";var nc,Yn=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};nc=Yn;S.IA5String=nc;Yn.NAME="IA5String";var sc,Zn=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};sc=Zn;S.GraphicString=sc;Zn.NAME="GraphicString";var oc,Hr=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};oc=Hr;S.VisibleString=oc;Hr.NAME="VisibleString";var ic,Jn=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};ic=Jn;S.GeneralString=ic;Jn.NAME="GeneralString";var ac,Xn=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};ac=Xn;S.CharacterString=ac;Xn.NAME="CharacterString";var cc,Mr=class extends Hr{constructor({value:t,valueDate:e,...n}={}){if(super(n),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,t){this.fromString(t),this.valueBlock.valueHexView=new Uint8Array(t.length);for(let s=0;s<t.length;s++)this.valueBlock.valueHexView[s]=t.charCodeAt(s)}e&&(this.fromDate(e),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(t){this.fromString(String.fromCharCode.apply(null,H.BufferSourceConverter.toUint8Array(t)))}toBuffer(){let t=this.toString(),e=new ArrayBuffer(t.length),n=new Uint8Array(e);for(let s=0;s<t.length;s++)n[s]=t.charCodeAt(s);return e}fromDate(t){this.year=t.getUTCFullYear(),this.month=t.getUTCMonth()+1,this.day=t.getUTCDate(),this.hour=t.getUTCHours(),this.minute=t.getUTCMinutes(),this.second=t.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(t){let n=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(t);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(t="iso"){if(t==="iso"){let e=new Array(7);return e[0]=kt(this.year<2e3?this.year-1900:this.year-2e3,2),e[1]=kt(this.month,2),e[2]=kt(this.day,2),e[3]=kt(this.hour,2),e[4]=kt(this.minute,2),e[5]=kt(this.second,2),e[6]="Z",e.join("")}return super.toString(t)}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}}};cc=Mr;S.UTCTime=cc;Mr.NAME="UTCTime";var lc,Qn=class extends Mr{constructor(t={}){var e;super(t),(e=this.millisecond)!==null&&e!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(t){super.fromDate(t),this.millisecond=t.getUTCMilliseconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond))}fromString(t){let e=!1,n="",s="",o=0,i,a=0,c=0;if(t[t.length-1]==="Z")n=t.substring(0,t.length-1),e=!0;else{let u=new Number(t[t.length-1]);if(isNaN(u.valueOf()))throw new Error("Wrong input string for conversion");n=t}if(e){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 u=1,h=n.indexOf("+"),m="";if(h===-1&&(h=n.indexOf("-"),u=-1),h!==-1){if(m=n.substring(h+1),n=n.substring(0,h),m.length!==2&&m.length!==4)throw new Error("Wrong input string for conversion");let g=parseInt(m.substring(0,2),10);if(isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");if(a=u*g,m.length===4){if(g=parseInt(m.substring(2,4),10),isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");c=u*g}}}let l=n.indexOf(".");if(l===-1&&(l=n.indexOf(",")),l!==-1){let u=new Number(`0${n.substring(l)}`);if(isNaN(u.valueOf()))throw new Error("Wrong input string for conversion");o=u.valueOf(),s=n.substring(0,l)}else s=n;switch(!0){case s.length===8:if(i=/(\d{4})(\d{2})(\d{2})/ig,l!==-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,l!==-1){let u=60*o;this.minute=Math.floor(u),u=60*(u-this.minute),this.second=Math.floor(u),u=1e3*(u-this.second),this.millisecond=Math.floor(u)}break;case s.length===12:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let u=60*o;this.second=Math.floor(u),u=1e3*(u-this.second),this.millisecond=Math.floor(u)}break;case s.length===14:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let u=1e3*o;this.millisecond=Math.floor(u)}break;default:throw new Error("Wrong input string for conversion")}let f=i.exec(s);if(f===null)throw new Error("Wrong input string for conversion");for(let u=1;u<f.length;u++)switch(u){case 1:this.year=parseInt(f[u],10);break;case 2:this.month=parseInt(f[u],10);break;case 3:this.day=parseInt(f[u],10);break;case 4:this.hour=parseInt(f[u],10)+a;break;case 5:this.minute=parseInt(f[u],10)+c;break;case 6:this.second=parseInt(f[u],10);break;default:throw new Error("Wrong input string for conversion")}if(e===!1){let u=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=u.getUTCFullYear(),this.month=u.getUTCMonth(),this.day=u.getUTCDay(),this.hour=u.getUTCHours(),this.minute=u.getUTCMinutes(),this.second=u.getUTCSeconds(),this.millisecond=u.getUTCMilliseconds()}}toString(t="iso"){if(t==="iso"){let e=[];return e.push(kt(this.year,4)),e.push(kt(this.month,2)),e.push(kt(this.day,2)),e.push(kt(this.hour,2)),e.push(kt(this.minute,2)),e.push(kt(this.second,2)),this.millisecond!==0&&(e.push("."),e.push(kt(this.millisecond,3))),e.push("Z"),e.join("")}return super.toString(t)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};lc=Qn;S.GeneralizedTime=lc;Qn.NAME="GeneralizedTime";var uc,ts=class extends le{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};uc=ts;S.DATE=uc;ts.NAME="DATE";var fc,es=class extends le{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};fc=es;S.TimeOfDay=fc;es.NAME="TimeOfDay";var hc,rs=class extends le{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};hc=rs;S.DateTime=hc;rs.NAME="DateTime";var dc,ns=class extends le{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};dc=ns;S.Duration=dc;ns.NAME="Duration";var pc,ss=class extends le{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};pc=ss;S.TIME=pc;ss.NAME="TIME";function Eh(r){let{result:t}=gr(r),e=t.valueBlock.value;return{n:z(qt(e[1].toBigInt()),"base64url"),e:z(qt(e[2].toBigInt()),"base64url"),d:z(qt(e[3].toBigInt()),"base64url"),p:z(qt(e[4].toBigInt()),"base64url"),q:z(qt(e[5].toBigInt()),"base64url"),dp:z(qt(e[6].toBigInt()),"base64url"),dq:z(qt(e[7].toBigInt()),"base64url"),qi:z(qt(e[8].toBigInt()),"base64url"),kty:"RSA",alg:"RS256"}}function Bh(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 U("JWK was missing components","ERR_INVALID_PARAMETERS");let e=new ft({value:[new ot({value:0}),ot.fromBigInt(Gt(Z(r.n,"base64url"))),ot.fromBigInt(Gt(Z(r.e,"base64url"))),ot.fromBigInt(Gt(Z(r.d,"base64url"))),ot.fromBigInt(Gt(Z(r.p,"base64url"))),ot.fromBigInt(Gt(Z(r.q,"base64url"))),ot.fromBigInt(Gt(Z(r.dp,"base64url"))),ot.fromBigInt(Gt(Z(r.dq,"base64url"))),ot.fromBigInt(Gt(Z(r.qi,"base64url")))]}).toBER();return new Uint8Array(e,0,e.byteLength)}function Ah(r){let{result:t}=gr(r),e=t.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:z(qt(e[0].toBigInt()),"base64url"),e:z(qt(e[1].toBigInt()),"base64url")}}function Sh(r){if(r.n==null||r.e==null)throw new U("JWK was missing components","ERR_INVALID_PARAMETERS");let e=new ft({value:[new ft({value:[new Vt({value:"1.2.840.113549.1.1.1"}),new Ne]}),new dr({valueHex:new ft({value:[ot.fromBigInt(Gt(Z(r.n,"base64url"))),ot.fromBigInt(Gt(Z(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(e,0,e.byteLength)}function qt(r){let t=r.toString(16);t.length%2>0&&(t=`0${t}`);let e=t.length/2,n=new Uint8Array(e),s=0,o=0;for(;s<e;)n[s]=parseInt(t.slice(o,o+2),16),s+=1,o+=2;return n}function Gt(r){let t=[];return r.forEach(function(e){let n=e.toString(16);n.length%2>0&&(n=`0${n}`),t.push(n)}),BigInt("0x"+t.join(""))}var kh=16,Vo=32,Fo=1e4;async function Ih(r,t){let e=At.get(),s=new ft({value:[new ot({value:0}),new ft({value:[new Vt({value:"1.2.840.113549.1.1.1"}),new Ne]}),new ce({valueHex:r.marshal()})]}).toBER(),o=new Uint8Array(s,0,s.byteLength),i=Ke(kh),a=await Uo(or,t,i,{c:Fo,dkLen:Vo}),c=Ke(16),l=await e.subtle.importKey("raw",a,"AES-CBC",!1,["encrypt"]),f=await e.subtle.encrypt({name:"AES-CBC",iv:c},l,o),u=new ft({value:[new ce({valueHex:i}),new ot({value:Fo}),new ot({value:Vo}),new ft({value:[new Vt({value:"1.2.840.113549.2.11"}),new Ne]})]}),h=new ft({value:[new Vt({value:"1.2.840.113549.1.5.13"}),new ft({value:[new ft({value:[new Vt({value:"1.2.840.113549.1.5.12"}),u]}),new ft({value:[new Vt({value:"2.16.840.1.101.3.4.1.42"}),new ce({valueHex:c})]})]})]}),g=new ft({value:[h,new ce({valueHex:f})]}).toBER(),d=new Uint8Array(g,0,g.byteLength);return["-----BEGIN ENCRYPTED PRIVATE KEY-----",...z(d,"base64pad").split(/(.{64})/).filter(Boolean),"-----END ENCRYPTED PRIVATE KEY-----"].join(`
7
- `)}async function Rh(r,t){let e=At.get(),n;if(r.includes("-----BEGIN ENCRYPTED PRIVATE KEY-----")){let s=Z(r.replace("-----BEGIN ENCRYPTED PRIVATE KEY-----","").replace("-----END ENCRYPTED PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:o}=gr(s),{iv:i,salt:a,iterations:c,keySize:l,cipherText:f}=Nh(o),u=await Uo(or,t,a,{c,dkLen:l}),h=await e.subtle.importKey("raw",u,"AES-CBC",!1,["decrypt"]),m=Kr(await e.subtle.decrypt({name:"AES-CBC",iv:i},h,f)),{result:g}=gr(m);n=gc(g)}else if(r.includes("-----BEGIN PRIVATE KEY-----")){let s=Z(r.replace("-----BEGIN PRIVATE KEY-----","").replace("-----END PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:o}=gr(s);n=gc(o)}else throw new U("Could not parse private key from PEM data","ERR_INVALID_PARAMETERS");return Ho(n)}function Nh(r){let t=r.valueBlock.value[0];if(t.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.13")throw new U("Only pkcs5PBES2 encrypted private keys are supported","ERR_INVALID_PARAMS");let n=t.valueBlock.value[1].valueBlock.value[0];if(n.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.12")throw new U("Only pkcs5PBKDF2 key derivation functions are supported","ERR_INVALID_PARAMS");let o=n.valueBlock.value[1],i=Kr(o.valueBlock.value[0].getValue()),a=Fo,c=Vo;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 U("Could not derive key size and iterations from PEM file - please use @libp2p/rsa to re-import your key","ERR_INVALID_PARAMS");let l=t.valueBlock.value[1].valueBlock.value[1],f=l.valueBlock.value[0].toString();if(f!=="OBJECT IDENTIFIER : 1.2.840.113549.3.7"){if(f!=="OBJECT IDENTIFIER : 1.3.14.3.2.7"){if(f!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.2"){if(f!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.22"){if(f!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.42")throw new U("Only AES-CBC encryption schemes are supported","ERR_INVALID_PARAMS")}}}}let u=Kr(l.valueBlock.value[1].getValue());return{cipherText:Kr(r.valueBlock.value[1].getValue()),salt:i,iterations:a,keySize:c,iv:u}}function gc(r){return Kr(r.valueBlock.value[2].getValue())}function Kr(r){return new Uint8Array(r,0,r.byteLength)}async function mc(r){let t=await At.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),e=await wc(t);return{privateKey:e[0],publicKey:e[1]}}async function Mo(r){let e=[await At.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),await Th(r)],n=await wc({privateKey:e[0],publicKey:e[1]});return{privateKey:n[0],publicKey:n[1]}}async function yc(r,t){let e=await At.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await At.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function bc(r,t,e){let n=await At.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return At.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function wc(r){if(r.privateKey==null||r.publicKey==null)throw new U("Private and public key are required","ERR_INVALID_PARAMETERS");return Promise.all([At.get().subtle.exportKey("jwk",r.privateKey),At.get().subtle.exportKey("jwk",r.publicKey)])}async function Th(r){return At.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 is(r){if(r.kty!=="RSA")throw new U("invalid key type","ERR_INVALID_KEY_TYPE");if(r.n==null)throw new U("invalid key modulus","ERR_INVALID_KEY_MODULUS");return Z(r.n,"base64url").length*8}var qr=8192,$r=class{_key;constructor(t){this._key=t}verify(t,e){return bc(this._key,e,t)}marshal(){return Te.jwkToPkix(this._key)}get bytes(){return Se.encode({Type:gt.RSA,Data:this.marshal()}).subarray()}equals(t){return bt(this.bytes,t.bytes)}hash(){let t=pt.digest(this.bytes);return Tt(t)?t.then(({bytes:e})=>e):t.bytes}},mr=class{_key;_publicKey;constructor(t,e){this._key=t,this._publicKey=e}genSecret(){return Ke(16)}sign(t){return yc(this._key,t)}get public(){if(this._publicKey==null)throw new U("public key not provided","ERR_PUBKEY_NOT_PROVIDED");return new $r(this._publicKey)}marshal(){return Te.jwkToPkcs1(this._key)}get bytes(){return ke.encode({Type:gt.RSA,Data:this.marshal()}).subarray()}equals(t){return bt(this.bytes,t.bytes)}hash(){let t=pt.digest(this.bytes);return Tt(t)?t.then(({bytes:e})=>e):t.bytes}async id(){let t=await this.public.hash();return z(t,"base58btc")}async export(t,e="pkcs-8"){if(e==="pkcs-8")return Te.exportToPem(this,t);if(e==="libp2p-key")return cr(this.bytes,t);throw new U(`export format '${e}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};async function Ho(r){let t=Te.pkcs1ToJwk(r);if(is(t)>qr)throw new U("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await Mo(t);return new mr(e.privateKey,e.publicKey)}function _h(r){let t=Te.pkixToJwk(r);if(is(t)>qr)throw new U("key size is too large","ERR_KEY_SIZE_TOO_LARGE");return new $r(t)}async function Uh(r){if(is(r)>qr)throw new U("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await Mo(r);return new mr(t.privateKey,t.publicKey)}async function Ch(r){if(r>qr)throw new U("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await mc(r);return new mr(t.privateKey,t.publicKey)}var jo={};lt(jo,{Secp256k1PrivateKey:()=>zr,Secp256k1PublicKey:()=>Gr,generateKeyPair:()=>Yh,unmarshalSecp256k1PrivateKey:()=>jh,unmarshalSecp256k1PublicKey:()=>Wh});var Dh=(r,t,e)=>r&t^~r&e,Ph=(r,t,e)=>r&t^r&e^t&e,Oh=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]),Le=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),_e=new Uint32Array(64),$o=class extends sr{constructor(){super(64,32,8,!1),this.A=Le[0]|0,this.B=Le[1]|0,this.C=Le[2]|0,this.D=Le[3]|0,this.E=Le[4]|0,this.F=Le[5]|0,this.G=Le[6]|0,this.H=Le[7]|0}get(){let{A:t,B:e,C:n,D:s,E:o,F:i,G:a,H:c}=this;return[t,e,n,s,o,i,a,c]}set(t,e,n,s,o,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let u=0;u<16;u++,e+=4)_e[u]=t.getUint32(e,!1);for(let u=16;u<64;u++){let h=_e[u-15],m=_e[u-2],g=Ct(h,7)^Ct(h,18)^h>>>3,d=Ct(m,17)^Ct(m,19)^m>>>10;_e[u]=d+_e[u-7]+g+_e[u-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:l,H:f}=this;for(let u=0;u<64;u++){let h=Ct(a,6)^Ct(a,11)^Ct(a,25),m=f+h+Dh(a,c,l)+Oh[u]+_e[u]|0,d=(Ct(n,2)^Ct(n,13)^Ct(n,22))+Ph(n,s,o)|0;f=l,l=c,c=a,a=i+m|0,i=o,o=s,s=n,n=m+d|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,l=l+this.G|0,f=f+this.H|0,this.set(n,s,o,i,a,c,l,f)}roundClean(){_e.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var xc=rn(()=>new $o);function Vh(r){let t=Nr(r);Kt(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:s}=t;if(e){if(!n.eql(s,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:Fh,hexToBytes:Hh}=on,qe={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(r){let{Err:t}=qe;if(r.length<2||r[0]!==2)throw new t("Invalid signature integer tag");let e=r[1],n=r.subarray(2,e+2);if(!e||n.length!==e)throw new t("Invalid signature integer: wrong length");if(n[0]&128)throw new t("Invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new t("Invalid signature integer: unnecessary leading zero");return{d:Fh(n),l:r.subarray(e+2)}},toSig(r){let{Err:t}=qe,e=typeof r=="string"?Hh(r):r;if(!Dt(e))throw new Error("ui8a expected");let n=e.length;if(n<2||e[0]!=48)throw new t("Invalid signature tag");if(e[1]!==n-2)throw new t("Invalid signature: incorrect length");let{d:s,l:o}=qe._parseInt(e.subarray(2)),{d:i,l:a}=qe._parseInt(o);if(a.length)throw new t("Invalid signature: left bytes after parsing");return{r:s,s:i}},hexFromSig(r){let t=l=>Number.parseInt(l[0],16)&8?"00"+l:l,e=l=>{let f=l.toString(16);return f.length&1?`0${f}`:f},n=t(e(r.s)),s=t(e(r.r)),o=n.length/2,i=s.length/2,a=e(o),c=e(i);return`30${e(i+o+4)}02${c}${s}02${a}${n}`}},he=BigInt(0),_t=BigInt(1),wm=BigInt(2),vc=BigInt(3),xm=BigInt(4);function Mh(r){let t=Vh(r),{Fp:e}=t,n=t.toBytes||((g,d,p)=>{let y=d.toAffine();return Qt(Uint8Array.from([4]),e.toBytes(y.x),e.toBytes(y.y))}),s=t.fromBytes||(g=>{let d=g.subarray(1),p=e.fromBytes(d.subarray(0,e.BYTES)),y=e.fromBytes(d.subarray(e.BYTES,2*e.BYTES));return{x:p,y}});function o(g){let{a:d,b:p}=t,y=e.sqr(g),v=e.mul(y,g);return e.add(e.add(v,e.mul(g,d)),p)}if(!e.eql(e.sqr(t.Gy),o(t.Gx)))throw new Error("bad generator point: equation left != right");function i(g){return typeof g=="bigint"&&he<g&&g<t.n}function a(g){if(!i(g))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(g){let{allowedPrivateKeyLengths:d,nByteLength:p,wrapPrivateKey:y,n:v}=t;if(d&&typeof g!="bigint"){if(Dt(g)&&(g=Jt(g)),typeof g!="string"||!d.includes(g.length))throw new Error("Invalid key");g=g.padStart(p*2,"0")}let w;try{w=typeof g=="bigint"?g:Xt(et("private key",g,p))}catch{throw new Error(`private key must be ${p} bytes, hex or bigint, not ${typeof g}`)}return y&&(w=Y(w,v)),a(w),w}let l=new Map;function f(g){if(!(g instanceof u))throw new Error("ProjectivePoint expected")}class u{constructor(d,p,y){if(this.px=d,this.py=p,this.pz=y,d==null||!e.isValid(d))throw new Error("x required");if(p==null||!e.isValid(p))throw new Error("y required");if(y==null||!e.isValid(y))throw new Error("z required")}static fromAffine(d){let{x:p,y}=d||{};if(!d||!e.isValid(p)||!e.isValid(y))throw new Error("invalid affine point");if(d instanceof u)throw new Error("projective point not allowed");let v=w=>e.eql(w,e.ZERO);return v(p)&&v(y)?u.ZERO:new u(p,y,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){let p=e.invertBatch(d.map(y=>y.pz));return d.map((y,v)=>y.toAffine(p[v])).map(u.fromAffine)}static fromHex(d){let p=u.fromAffine(s(et("pointHex",d)));return p.assertValidity(),p}static fromPrivateKey(d){return u.BASE.multiply(c(d))}_setWindowSize(d){this._WINDOW_SIZE=d,l.delete(this)}assertValidity(){if(this.is0()){if(t.allowInfinityPoint&&!e.is0(this.py))return;throw new Error("bad point: ZERO")}let{x:d,y:p}=this.toAffine();if(!e.isValid(d)||!e.isValid(p))throw new Error("bad point: x or y not FE");let y=e.sqr(p),v=o(d);if(!e.eql(y,v))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:d}=this.toAffine();if(e.isOdd)return!e.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){f(d);let{px:p,py:y,pz:v}=this,{px:w,py:T,pz:x}=d,A=e.eql(e.mul(p,x),e.mul(w,v)),R=e.eql(e.mul(y,x),e.mul(T,v));return A&&R}negate(){return new u(this.px,e.neg(this.py),this.pz)}double(){let{a:d,b:p}=t,y=e.mul(p,vc),{px:v,py:w,pz:T}=this,x=e.ZERO,A=e.ZERO,R=e.ZERO,N=e.mul(v,v),q=e.mul(w,w),K=e.mul(T,T),P=e.mul(v,w);return P=e.add(P,P),R=e.mul(v,T),R=e.add(R,R),x=e.mul(d,R),A=e.mul(y,K),A=e.add(x,A),x=e.sub(q,A),A=e.add(q,A),A=e.mul(x,A),x=e.mul(P,x),R=e.mul(y,R),K=e.mul(d,K),P=e.sub(N,K),P=e.mul(d,P),P=e.add(P,R),R=e.add(N,N),N=e.add(R,N),N=e.add(N,K),N=e.mul(N,P),A=e.add(A,N),K=e.mul(w,T),K=e.add(K,K),N=e.mul(K,P),x=e.sub(x,N),R=e.mul(K,q),R=e.add(R,R),R=e.add(R,R),new u(x,A,R)}add(d){f(d);let{px:p,py:y,pz:v}=this,{px:w,py:T,pz:x}=d,A=e.ZERO,R=e.ZERO,N=e.ZERO,q=t.a,K=e.mul(t.b,vc),P=e.mul(p,w),nt=e.mul(y,T),rt=e.mul(v,x),Nt=e.add(p,y),E=e.add(w,T);Nt=e.mul(Nt,E),E=e.add(P,nt),Nt=e.sub(Nt,E),E=e.add(p,v);let I=e.add(w,x);return E=e.mul(E,I),I=e.add(P,rt),E=e.sub(E,I),I=e.add(y,v),A=e.add(T,x),I=e.mul(I,A),A=e.add(nt,rt),I=e.sub(I,A),N=e.mul(q,E),A=e.mul(K,rt),N=e.add(A,N),A=e.sub(nt,N),N=e.add(nt,N),R=e.mul(A,N),nt=e.add(P,P),nt=e.add(nt,P),rt=e.mul(q,rt),E=e.mul(K,E),nt=e.add(nt,rt),rt=e.sub(P,rt),rt=e.mul(q,rt),E=e.add(E,rt),P=e.mul(nt,E),R=e.add(R,P),P=e.mul(I,E),A=e.mul(Nt,A),A=e.sub(A,P),P=e.mul(Nt,nt),N=e.mul(I,N),N=e.add(N,P),new u(A,R,N)}subtract(d){return this.add(d.negate())}is0(){return this.equals(u.ZERO)}wNAF(d){return m.wNAFCached(this,l,d,p=>{let y=e.invertBatch(p.map(v=>v.pz));return p.map((v,w)=>v.toAffine(y[w])).map(u.fromAffine)})}multiplyUnsafe(d){let p=u.ZERO;if(d===he)return p;if(a(d),d===_t)return this;let{endo:y}=t;if(!y)return m.unsafeLadder(this,d);let{k1neg:v,k1:w,k2neg:T,k2:x}=y.splitScalar(d),A=p,R=p,N=this;for(;w>he||x>he;)w&_t&&(A=A.add(N)),x&_t&&(R=R.add(N)),N=N.double(),w>>=_t,x>>=_t;return v&&(A=A.negate()),T&&(R=R.negate()),R=new u(e.mul(R.px,y.beta),R.py,R.pz),A.add(R)}multiply(d){a(d);let p=d,y,v,{endo:w}=t;if(w){let{k1neg:T,k1:x,k2neg:A,k2:R}=w.splitScalar(p),{p:N,f:q}=this.wNAF(x),{p:K,f:P}=this.wNAF(R);N=m.constTimeNegate(T,N),K=m.constTimeNegate(A,K),K=new u(e.mul(K.px,w.beta),K.py,K.pz),y=N.add(K),v=q.add(P)}else{let{p:T,f:x}=this.wNAF(p);y=T,v=x}return u.normalizeZ([y,v])[0]}multiplyAndAddUnsafe(d,p,y){let v=u.BASE,w=(x,A)=>A===he||A===_t||!x.equals(v)?x.multiplyUnsafe(A):x.multiply(A),T=w(this,p).add(w(d,y));return T.is0()?void 0:T}toAffine(d){let{px:p,py:y,pz:v}=this,w=this.is0();d==null&&(d=w?e.ONE:e.inv(v));let T=e.mul(p,d),x=e.mul(y,d),A=e.mul(v,d);if(w)return{x:e.ZERO,y:e.ZERO};if(!e.eql(A,e.ONE))throw new Error("invZ was invalid");return{x:T,y:x}}isTorsionFree(){let{h:d,isTorsionFree:p}=t;if(d===_t)return!0;if(p)return p(u,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:d,clearCofactor:p}=t;return d===_t?this:p?p(u,this):this.multiplyUnsafe(t.h)}toRawBytes(d=!0){return this.assertValidity(),n(u,this,d)}toHex(d=!0){return Jt(this.toRawBytes(d))}}u.BASE=new u(t.Gx,t.Gy,e.ONE),u.ZERO=new u(e.ZERO,e.ONE,e.ZERO);let h=t.nBitLength,m=ln(u,t.endo?Math.ceil(h/2):h);return{CURVE:t,ProjectivePoint:u,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:i}}function Kh(r){let t=Nr(r);return Kt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Ec(r){let t=Kh(r),{Fp:e,n}=t,s=e.BYTES+1,o=2*e.BYTES+1;function i(E){return he<E&&E<e.ORDER}function a(E){return Y(E,n)}function c(E){return an(E,n)}let{ProjectivePoint:l,normPrivateKeyToScalar:f,weierstrassEquation:u,isWithinCurveOrder:h}=Mh({...t,toBytes(E,I,O){let B=I.toAffine(),b=e.toBytes(B.x),k=Qt;return O?k(Uint8Array.from([I.hasEvenY()?2:3]),b):k(Uint8Array.from([4]),b,e.toBytes(B.y))},fromBytes(E){let I=E.length,O=E[0],B=E.subarray(1);if(I===s&&(O===2||O===3)){let b=Xt(B);if(!i(b))throw new Error("Point is not on curve");let k=u(b),L=e.sqrt(k),_=(L&_t)===_t;return(O&1)===1!==_&&(L=e.neg(L)),{x:b,y:L}}else if(I===o&&O===4){let b=e.fromBytes(B.subarray(0,e.BYTES)),k=e.fromBytes(B.subarray(e.BYTES,2*e.BYTES));return{x:b,y:k}}else throw new Error(`Point of length ${I} was invalid. Expected ${s} compressed bytes or ${o} uncompressed bytes`)}}),m=E=>Jt(Ee(E,t.nByteLength));function g(E){let I=n>>_t;return E>I}function d(E){return g(E)?a(-E):E}let p=(E,I,O)=>Xt(E.slice(I,O));class y{constructor(I,O,B){this.r=I,this.s=O,this.recovery=B,this.assertValidity()}static fromCompact(I){let O=t.nByteLength;return I=et("compactSignature",I,O*2),new y(p(I,0,O),p(I,O,2*O))}static fromDER(I){let{r:O,s:B}=qe.toSig(et("DER",I));return new y(O,B)}assertValidity(){if(!h(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!h(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:O,s:B,recovery:b}=this,k=R(et("msgHash",I));if(b==null||![0,1,2,3].includes(b))throw new Error("recovery id invalid");let L=b===2||b===3?O+t.n:O;if(L>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let _=b&1?"03":"02",V=l.fromHex(_+m(L)),F=c(L),j=a(-k*F),M=a(B*F),$=l.BASE.multiplyAndAddUnsafe(V,j,M);if(!$)throw new Error("point at infinify");return $.assertValidity(),$}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new y(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return Pe(this.toDERHex())}toDERHex(){return qe.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Pe(this.toCompactHex())}toCompactHex(){return m(this.r)+m(this.s)}}let v={isValidPrivateKey(E){try{return f(E),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let E=io(t.n);return ca(t.randomBytes(E),t.n)},precompute(E=8,I=l.BASE){return I._setWindowSize(E),I.multiply(BigInt(3)),I}};function w(E,I=!0){return l.fromPrivateKey(E).toRawBytes(I)}function T(E){let I=Dt(E),O=typeof E=="string",B=(I||O)&&E.length;return I?B===s||B===o:O?B===2*s||B===2*o:E instanceof l}function x(E,I,O=!0){if(T(E))throw new Error("first arg must be private key");if(!T(I))throw new Error("second arg must be public key");return l.fromHex(I).multiply(f(E)).toRawBytes(O)}let A=t.bits2int||function(E){let I=Xt(E),O=E.length*8-t.nBitLength;return O>0?I>>BigInt(O):I},R=t.bits2int_modN||function(E){return a(A(E))},N=Rr(t.nBitLength);function q(E){if(typeof E!="bigint")throw new Error("bigint expected");if(!(he<=E&&E<N))throw new Error(`bigint expected < 2^${t.nBitLength}`);return Ee(E,t.nByteLength)}function K(E,I,O=P){if(["recovered","canonical"].some(Q=>Q in O))throw new Error("sign() legacy options not supported");let{hash:B,randomBytes:b}=t,{lowS:k,prehash:L,extraEntropy:_}=O;k==null&&(k=!0),E=et("msgHash",E),L&&(E=et("prehashed msgHash",B(E)));let V=R(E),F=f(I),j=[q(F),q(V)];if(_!=null){let Q=_===!0?b(e.BYTES):_;j.push(et("extraEntropy",Q))}let M=Qt(...j),$=V;function st(Q){let ht=A(Q);if(!h(ht))return;let dt=c(ht),it=l.BASE.multiply(ht).toAffine(),yt=a(it.x);if(yt===he)return;let zt=a(dt*a($+yt*F));if(zt===he)return;let Ue=(it.x===yt?0:2)|Number(it.y&_t),Br=zt;return k&&g(zt)&&(Br=d(zt),Ue^=1),new y(yt,Br,Ue)}return{seed:M,k2sig:st}}let P={lowS:t.lowS,prehash:!1},nt={lowS:t.lowS,prehash:!1};function rt(E,I,O=P){let{seed:B,k2sig:b}=K(E,I,O),k=t;return ro(k.hash.outputLen,k.nByteLength,k.hmac)(B,b)}l.BASE._setWindowSize(8);function Nt(E,I,O,B=nt){let b=E;if(I=et("msgHash",I),O=et("publicKey",O),"strict"in B)throw new Error("options.strict was renamed to lowS");let{lowS:k,prehash:L}=B,_,V;try{if(typeof b=="string"||Dt(b))try{_=y.fromDER(b)}catch(it){if(!(it instanceof qe.Err))throw it;_=y.fromCompact(b)}else if(typeof b=="object"&&typeof b.r=="bigint"&&typeof b.s=="bigint"){let{r:it,s:yt}=b;_=new y(it,yt)}else throw new Error("PARSE");V=l.fromHex(O)}catch(it){if(it.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(k&&_.hasHighS())return!1;L&&(I=t.hash(I));let{r:F,s:j}=_,M=R(I),$=c(j),st=a(M*$),Q=a(F*$),ht=l.BASE.multiplyAndAddUnsafe(V,st,Q)?.toAffine();return ht?a(ht.x)===F:!1}return{CURVE:t,getPublicKey:w,getSharedSecret:x,sign:rt,verify:Nt,ProjectivePoint:l,Signature:y,utils:v}}function $h(r){return{hash:r,hmac:(t,...e)=>Ur(r,t,en(...e)),randomBytes:nr}}function Bc(r,t){let e=n=>Ec({...r,...$h(n)});return Object.freeze({...e(t),create:e})}var kc=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Ac=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),qh=BigInt(1),qo=BigInt(2),Sc=(r,t)=>(r+t/qo)/t;function Gh(r){let t=kc,e=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),l=r*r*r%t,f=l*l*r%t,u=X(f,e,t)*f%t,h=X(u,e,t)*f%t,m=X(h,qo,t)*l%t,g=X(m,s,t)*m%t,d=X(g,o,t)*g%t,p=X(d,a,t)*d%t,y=X(p,c,t)*p%t,v=X(y,a,t)*d%t,w=X(v,e,t)*f%t,T=X(w,i,t)*g%t,x=X(T,n,t)*l%t,A=X(x,qo,t);if(!Go.eql(Go.sqr(A),r))throw new Error("Cannot find square root");return A}var Go=cn(kc,void 0,void 0,{sqrt:Gh}),Ht=Bc({a:BigInt(0),b:BigInt(7),Fp:Go,n:Ac,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Ac,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-qh*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=e,i=BigInt("0x100000000000000000000000000000000"),a=Sc(o*r,t),c=Sc(-n*r,t),l=Y(r-a*e-c*s,t),f=Y(-a*n-c*o,t),u=l>i,h=f>i;if(u&&(l=t-l),h&&(f=t-f),l>i||f>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:u,k1:l,k2neg:h,k2:f}}}},xc),Nm=BigInt(0);var Tm=Ht.ProjectivePoint;function Ic(){return Ht.utils.randomPrivateKey()}function Rc(r,t){let e=pt.digest(t instanceof Uint8Array?t:t.subarray());if(Tt(e))return e.then(({digest:n})=>Ht.sign(n,r).toDERRawBytes()).catch(n=>{throw new U(String(n),"ERR_INVALID_INPUT")});try{return Ht.sign(e.digest,r).toDERRawBytes()}catch(n){throw new U(String(n),"ERR_INVALID_INPUT")}}function Nc(r,t,e){let n=pt.digest(e instanceof Uint8Array?e:e.subarray());if(Tt(n))return n.then(({digest:s})=>Ht.verify(t,s,r)).catch(s=>{throw new U(String(s),"ERR_INVALID_INPUT")});try{return Ht.verify(t,n.digest,r)}catch(s){throw new U(String(s),"ERR_INVALID_INPUT")}}function Tc(r){return Ht.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Lc(r){try{Ht.getPublicKey(r,!0)}catch(t){throw new U(String(t),"ERR_INVALID_PRIVATE_KEY")}}function zo(r){try{Ht.ProjectivePoint.fromHex(r)}catch(t){throw new U(String(t),"ERR_INVALID_PUBLIC_KEY")}}function _c(r){try{return Ht.getPublicKey(r,!0)}catch(t){throw new U(String(t),"ERR_INVALID_PRIVATE_KEY")}}var Gr=class{_key;constructor(t){zo(t),this._key=t}verify(t,e){return Nc(this._key,e,t)}marshal(){return Tc(this._key)}get bytes(){return Se.encode({Type:gt.Secp256k1,Data:this.marshal()}).subarray()}equals(t){return bt(this.bytes,t.bytes)}async hash(){let t=pt.digest(this.bytes),e;return Tt(t)?{bytes:e}=await t:e=t.bytes,e}},zr=class{_key;_publicKey;constructor(t,e){this._key=t,this._publicKey=e??_c(t),Lc(this._key),zo(this._publicKey)}sign(t){return Rc(this._key,t)}get public(){return new Gr(this._publicKey)}marshal(){return this._key}get bytes(){return ke.encode({Type:gt.Secp256k1,Data:this.marshal()}).subarray()}equals(t){return bt(this.bytes,t.bytes)}hash(){let t=pt.digest(this.bytes);return Tt(t)?t.then(({bytes:e})=>e):t.bytes}async id(){let t=await this.public.hash();return z(t,"base58btc")}async export(t,e="libp2p-key"){if(e==="libp2p-key")return cr(this.bytes,t);throw new U(`export format '${e}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function jh(r){return new zr(r)}function Wh(r){return new Gr(r)}async function Yh(){let r=Ic();return new zr(r)}var Uc={rsa:Ko,ed25519:_o,secp256k1:jo};function Zh(r){let t=Object.keys(Uc).join(" / ");return new U(`invalid or unsupported key type ${r}. Must be ${t}`,"ERR_UNSUPPORTED_KEY_TYPE")}function Wo(r){if(r=r.toLowerCase(),r==="rsa"||r==="ed25519"||r==="secp256k1")return Uc[r];throw Zh(r)}async function Cc(r,t){return Wo(r).generateKeyPair(t??2048)}function Dc(r,t){return t=(t??"rsa").toLowerCase(),Wo(t),r.bytes}function Pc(r,t){return t=(t??"rsa").toLowerCase(),Wo(t),r.bytes}var Oc=async()=>{let r=await Cc("Ed25519"),t=await Jh(r);if(t.type==="Ed25519")return t;throw new Error(`Generated unexpected PeerId type "${t.type}"`)};async function Jh(r){return Gi(Dc(r.public),Pc(r))}var as=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}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(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,s){return this.readAtomically(()=>{let o=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",l=2**(8*s)-1;for(;;){let f=this.readAtomically(()=>{let u=this.readChar();if(u===void 0)return;let h=Number.parseInt(u,t);if(!Number.isNaN(h))return h});if(f===void 0)break;if(o*=t,o+=f,o>l||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&c&&i>1?void 0:o})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let s=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[s]=i[0],e[s+1]=i[1],e[s+2]=i[2],e[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];e[s]=o>>8,e[s+1]=o&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,s]=t(e);if(n===16)return e;if(s||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let o=new Uint8Array(14),i=16-(n+2),[a]=t(o.subarray(0,i));return e.set(o.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Vc=45,Xh=15,yr=new as;function Yo(r){if(!(r.length>Xh))return yr.new(r).parseWith(()=>yr.readIPv4Addr())}function Zo(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Vc))return yr.new(r).parseWith(()=>yr.readIPv6Addr())}function cs(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Vc))return yr.new(r).parseWith(()=>yr.readIPAddr())}function ls(r){return!!Yo(r)}function us(r){return!!Zo(r)}function fs(r){return!!cs(r)}var Hc=Bs(Fc(),1),Qh=["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.0.0/29","192.0.0.8/32","192.0.0.9/32","192.0.0.10/32","192.0.0.170/32","192.0.0.171/32","192.0.2.0/24","192.31.196.0/24","192.52.193.0/24","192.88.99.0/24","192.168.0.0/16","192.175.48.0/24","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","240.0.0.0/4","255.255.255.255/32"],td=Qh.map(r=>new Hc.Netmask(r));function ed(r){for(let t of td)if(t.contains(r))return!0;return!1}function rd(r){return/^::$/.test(r)||/^::1$/.test(r)||/^::f{4}:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^::f{4}:0.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(r)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(r)||/^ff([0-9a-fA-F]{2,2}):/i.test(r)}function Jo(r){return ls(r)?ed(r):us(r)?rd(r):void 0}var uy=parseInt("0xFFFF",16),fy=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var $c=ls,ad=us,Xo=function(r){let t=0;if(r=r.toString().trim(),$c(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(ad(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let o=$c(e[n]),i;o&&(i=Xo(e[n]),e[n]=z(i.slice(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,z(i.slice(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let o=[n,1];for(n=9-e.length;n>0;n--)o.push("0");e.splice.apply(e,o)}let s=new Uint8Array(t+16);for(n=0;n<e.length;n++){let o=parseInt(e[n],16);s[t++]=o>>8&255,s[t++]=o&255}return s}throw new Error("invalid ip address")},qc=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let s=[];for(let o=0;o<e;o++)s.push(r[t+o]);return s.join(".")}if(e===16){let s=[];for(let o=0;o<e;o+=2)s.push(n.getUint16(t+o).toString(16));return s.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var br={},Qo={},ld=[[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"]];ld.forEach(r=>{let t=ud(...r);Qo[t.code]=t,br[t.name]=t});function ud(r,t,e,n,s){return{code:r,size:t,name:e,resolvable:!!n,path:!!s}}function W(r){if(typeof r=="number"){if(Qo[r]!=null)return Qo[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(br[r]!=null)return br[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var zy=W("ip4"),jy=W("ip6"),Wy=W("ipcidr");function ei(r,t){switch(W(r).code){case 4:case 41:return hd(t);case 42:return jc(t);case 6:case 273:case 33:case 132:return Yc(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return jc(t);case 421:return md(t);case 444:return Wc(t);case 445:return Wc(t);case 466:return gd(t);default:return z(t,"base16")}}function ri(r,t){switch(W(r).code){case 4:return Gc(t);case 41:return Gc(t);case 42:return zc(t);case 6:case 273:case 33:case 132:return ni(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return zc(t);case 421:return dd(t);case 444:return yd(t);case 445:return bd(t);case 466:return pd(t);default:return Z(t,"base16")}}var ti=Object.values(me).map(r=>r.decoder),fd=function(){let r=ti[0].or(ti[1]);return ti.slice(2).forEach(t=>r=r.or(t)),r}();function Gc(r){if(!fs(r))throw new Error("invalid ip address");return Xo(r)}function hd(r){let t=qc(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!fs(t))throw new Error("invalid ip address");return t}function ni(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Yc(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function zc(r){let t=Z(r),e=Uint8Array.from(Be(t.length));return Bt([e,t],e.length+t.length)}function jc(r){let t=re(r);if(r=r.slice(ut(t)),r.length!==t)throw new Error("inconsistent lengths");return z(r)}function dd(r){let t;r[0]==="Q"||r[0]==="1"?t=Ce(at.decode(`z${r}`)).bytes:t=Ut.parse(r).multihash.bytes;let e=Uint8Array.from(Be(t.length));return Bt([e,t],e.length+t.length)}function pd(r){let t=fd.decode(r),e=Uint8Array.from(Be(t.length));return Bt([e,t],e.length+t.length)}function gd(r){let t=re(r),e=r.slice(ut(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+z(e,"base64url")}function md(r){let t=re(r),e=r.slice(ut(t));if(e.length!==t)throw new Error("inconsistent lengths");return z(e,"base58btc")}function yd(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=Wt.decode("b"+t[0]),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let s=ni(n);return Bt([e,s],e.length+s.length)}function bd(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=Wt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let s=ni(n);return Bt([e,s],e.length+s.length)}function Wc(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=z(t,"base32"),s=Yc(e);return`${n}:${s}`}function Zc(r){r=si(r);let t=[],e=[],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=W(i);if(a.size===0){t.push([a.code]),e.push([a.code]);continue}if(o++,o>=s.length)throw Xc("invalid address: "+r);if(a.path===!0){n=si(s.slice(o).join("/")),t.push([a.code,ri(a.code,n)]),e.push([a.code,n]);break}let c=ri(a.code,s[o]);t.push([a.code,c]),e.push([a.code,ei(a.code,c)])}return{string:Jc(e),bytes:ii(t),tuples:t,stringTuples:e,path:n}}function oi(r){let t=[],e=[],n=null,s=0;for(;s<r.length;){let o=re(r,s),i=ut(o),a=W(o),c=wd(a,r.slice(s+i));if(c===0){t.push([o]),e.push([o]),s+=i;continue}let l=r.slice(s+i,s+i+c);if(s+=c+i,s>r.length)throw Xc("Invalid address Uint8Array: "+z(r,"base16"));t.push([o,l]);let f=ei(o,l);if(e.push([o,f]),a.path===!0){n=f;break}}return{bytes:Uint8Array.from(r),string:Jc(e),tuples:t,stringTuples:e,path:n}}function Jc(r){let t=[];return r.map(e=>{let n=W(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),si(t.join("/"))}function ii(r){return Bt(r.map(t=>{let e=W(t[0]),n=Uint8Array.from(Be(e.code));return t.length>1&&t[1]!=null&&(n=Bt([n,t[1]])),n}))}function wd(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=re(t instanceof Uint8Array?t:Uint8Array.from(t));return e+ut(e)}}function si(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}function Xc(r){return new Error("Error parsing address: "+r)}var xd=Symbol.for("nodejs.util.inspect.custom"),ai=Symbol.for("@multiformats/js-multiaddr/multiaddr"),vd=[W("dns").code,W("dns4").code,W("dns6").code,W("dnsaddr").code],hs=class r{bytes;#e;#t;#r;#n;[ai]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=oi(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Zc(t)}else if(tl(t))e=oi(t.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=e.bytes,this.#e=e.string,this.#t=e.tuples,this.#r=e.stringTuples,this.#n=e.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let t,e,n,s,o="",i=W("tcp"),a=W("udp"),c=W("ip4"),l=W("ip6"),f=W("dns6"),u=W("ip6zone");for(let[m,g]of this.stringTuples())m===u.code&&(o=`%${g??""}`),vd.includes(m)&&(e=i.name,s=443,n=`${g??""}${o}`,t=m===f.code?6:4),(m===i.code||m===a.code)&&(e=W(m).name,s=parseInt(g??"")),(m===c.code||m===l.code)&&(e=W(m).name,n=`${g??""}${o}`,t=m===l.code?6:4);if(t==null||e==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:t,host:n,transport:e,port:s}}protos(){return this.#t.map(([t])=>Object.assign({},W(t)))}protoCodes(){return this.#t.map(([t])=>t)}protoNames(){return this.#t.map(([t])=>W(t).name)}tuples(){return this.#t}stringTuples(){return this.#r}encapsulate(t){return t=new r(t),new r(this.toString()+t.toString())}decapsulate(t){let e=t.toString(),n=this.toString(),s=n.lastIndexOf(e);if(s<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,s))}decapsulateCode(t){let e=this.tuples();for(let n=e.length-1;n>=0;n--)if(e[n][0]===t)return new r(ii(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,s])=>{n===br.p2p.code&&t.push([n,s]),n===br["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?z(at.decode(`z${n}`),"base58btc"):z(Ut.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return bt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(o=>o.resolvable);if(e==null)return[this];let n=Qc.get(e.name);if(n==null)throw new U(`no available resolver for ${e.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,t)).map(o=>new r(o))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[xd](){return`Multiaddr(${this.#e})`}};var Qc=new Map;function tl(r){return!!r?.[ai]}function ds(r){return new hs(r)}function Ed(r){return r[Symbol.asyncIterator]!=null}function Bd(r){if(Ed(r))return(async()=>{for await(let t of r)return t})();for(let t of r)return t}var ci=Bd;var rl=Symbol.for("@achingbrain/uint8arraylist");function el(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let s=e+n.byteLength;if(t<s)return{buf:n,index:t-e};e=s}throw new RangeError("index is out of bounds")}function ps(r){return!!r?.[rl]}var wr=class r{bufs;length;[rl]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(ps(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(ps(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=el(this.bufs,t);return e.buf[e.index]}set(t,e){let n=el(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(ps(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:s}=this._subList(t,e);return Bt(n,s)}subarray(t,e){let{bufs:n,length:s}=this._subList(t,e);return n.length===1?n[0]:Bt(n,s)}sublist(t,e){let{bufs:n,length:s}=this._subList(t,e),o=new r;return o.length=s,o.bufs=[...n],o}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],s=0;for(let o=0;o<this.bufs.length;o++){let i=this.bufs[o],a=s,c=a+i.byteLength;if(s=c,t>=c)continue;let l=t>=a&&t<c,f=e>a&&e<=c;if(l&&f){if(t===a&&e===c){n.push(i);break}let u=t-a;n.push(i.subarray(u,u+(e-t)));break}if(l){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!ps(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let o=256,i=new Int32Array(o);for(let u=0;u<o;u++)i[u]=-1;for(let u=0;u<s;u++)i[n[u]]=u;let a=i,c=this.byteLength-n.byteLength,l=n.byteLength-1,f;for(let u=e;u<=c;u+=f){f=0;for(let h=l;h>=0;h--){let m=this.get(u+h);if(n[h]!==m){f=Math.max(1,h-a[m]);break}}if(f===0)return u}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=wt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let s=Yt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,e,n),this.write(s,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let s=Yt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,e,n),this.write(s,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let s=Yt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,e,n),this.write(s,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=wt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let s=Yt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,e,n),this.write(s,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let s=Yt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,e,n),this.write(s,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let s=Yt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,e,n),this.write(s,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let s=Yt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,e,n),this.write(s,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let s=Yt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,e,n),this.write(s,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!bt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((s,o)=>s+o.byteLength,0)),n.length=e,n}};function gs(r){return r[Symbol.asyncIterator]!=null}var ms=r=>{let t=ut(r),e=wt(t);return Be(r,e),ms.bytes=t,e};ms.bytes=0;function Wr(r,t){t=t??{};let e=t.lengthEncoder??ms;function*n(s){let o=e(s.byteLength);o instanceof Uint8Array?yield o:yield*o,s instanceof Uint8Array?yield s:yield*s}return gs(r)?async function*(){for await(let s of r)yield*n(s)}():function*(){for(let s of r)yield*n(s)}()}Wr.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??ms;return new wr(e(r.byteLength),r)};var xr=Bs(ol(),1);var Sd=8,kd=1024*1024*4,Ge;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(Ge||(Ge={}));var li=r=>{let t=re(r);return li.bytes=ut(t),t};li.bytes=0;function vr(r,t){let e=new wr,n=Ge.LENGTH,s=-1,o=t?.lengthDecoder??li,i=t?.maxLengthLength??Sd,a=t?.maxDataLength??kd;function*c(){for(;e.byteLength>0;){if(n===Ge.LENGTH)try{if(s=o(e),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 l=o.bytes;e.consume(l),t?.onLength!=null&&t.onLength(s),n=Ge.DATA}catch(l){if(l instanceof RangeError){if(e.byteLength>i)throw(0,xr.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw l}if(n===Ge.DATA){if(e.byteLength<s)break;let l=e.sublist(0,s);e.consume(s),t?.onData!=null&&t.onData(l),yield l,n=Ge.LENGTH}}}return gs(r)?async function*(){for await(let l of r)e.append(l),yield*c();if(e.byteLength>0)throw(0,xr.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(let l of r)e.append(l),yield*c();if(e.byteLength>0)throw(0,xr.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}vr.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:o,value:i}=await r.next(e);if(o===!0)return;i!=null&&(yield i)}catch(o){if(o.code==="ERR_UNDER_READ")return{done:!0,value:null};throw o}finally{e=1}}();return vr(n,{...t??{},onLength:o=>{e=o}})};function Rd(r){let[t,e]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>t.next(),push:s=>{n.push(s)},next:()=>n.length>0?{done:!1,value:n.shift()}:t.next(),[e](){return this}}}var il=Rd;function Nd(r){return r[Symbol.asyncIterator]!=null}function Td(r,t){if(Nd(r))return async function*(){for await(let a of r)yield t(a)}();let e=il(r),{value:n,done:s}=e.next();if(s===!0)return function*(){}();let o=t(n);if(typeof o.then=="function")return async function*(){yield await o;for await(let a of e)yield t(a)}();let i=t;return function*(){yield o;for(let a of e)yield i(a)}()}var al=Td;function de(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var ys=globalThis.CustomEvent??Event;async function*ui(r,t={}){let e=t.concurrency??1/0;e<1&&(e=1/0);let n=t.ordered==null?!1:t.ordered,s=new EventTarget,o=[],i=de(),a=de(),c=!1,l,f=!1;s.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let g of r){if(o.length===e&&(i=de(),await i.promise),f)break;let d={done:!1};o.push(d),g().then(p=>{d.done=!0,d.ok=!0,d.value=p,s.dispatchEvent(new ys("task-complete"))},p=>{d.done=!0,d.err=p,s.dispatchEvent(new ys("task-complete"))})}c=!0,s.dispatchEvent(new ys("task-complete"))}catch(g){l=g,s.dispatchEvent(new ys("task-complete"))}});function u(){return n?o[0]?.done:!!o.find(g=>g.done)}function*h(){for(;o.length>0&&o[0].done;){let g=o[0];if(o.shift(),g.ok)yield g.value;else throw f=!0,i.resolve(),g.err;i.resolve()}}function*m(){for(;u();)for(let g=0;g<o.length;g++)if(o[g].done){let d=o[g];if(o.splice(g,1),g--,d.ok)yield d.value;else throw f=!0,i.resolve(),d.err;i.resolve()}}for(;;){if(u()||(a=de(),await a.promise),l!=null)throw l;if(n?yield*h():yield*m(),c&&o.length===0)break}}var bs=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||t-1&t)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},Er=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new bs(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new bs(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var fi=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function ws(r={}){return Ld(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function Ld(r,t){t=t??{};let e=t.onEnd,n=new Er,s,o,i,a=de(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((p,y)=>{o=v=>{o=null,n.push(v);try{p(r(n))}catch(w){y(w)}return s}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=de()})}},l=p=>o!=null?o(p):(n.push(p),s),f=p=>(n=new Er,o!=null?o({error:p}):(n.push({error:p}),s)),u=p=>{if(i)return s;if(t?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:p})},h=p=>i?s:(i=!0,p!=null?f(p):l({done:!0})),m=()=>(n=new Er,h(),{done:!0}),g=p=>(h(p),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:m,throw:g,push:u,end:h,get readableLength(){return n.size},onEmpty:async p=>{let y=p?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let v,w;y!=null&&(v=new Promise((T,x)=>{w=()=>{x(new fi)},y.addEventListener("abort",w)}));try{await Promise.race([a.promise,v])}finally{w!=null&&y!=null&&y?.removeEventListener("abort",w)}}},e==null)return s;let d=s;return s={[Symbol.asyncIterator](){return this},next(){return d.next()},throw(p){return d.throw(p),e!=null&&(e(p),e=void 0),{done:!0}},return(){return d.return(),e!=null&&(e(),e=void 0),{done:!0}},push:u,end(p){return d.end(p),e!=null&&(e(p),e=void 0),s},get readableLength(){return d.readableLength},onEmpty:p=>d.onEmpty(p)},s}function _d(r){return r[Symbol.asyncIterator]!=null}function Ud(...r){let t=[];for(let e of r)_d(e)||t.push(e);return t.length===r.length?function*(){for(let e of t)yield*e}():async function*(){let e=ws({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let s of n)e.push(s)})),e.end()}catch(n){e.end(n)}}),yield*e}()}var cl=Ud;function di(r,...t){if(r==null)throw new Error("Empty pipeline");if(hi(r)){let n=r;r=()=>n.source}else if(ul(r)||ll(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&hi(e[e.length-1])&&(e[e.length-1]=e[e.length-1].sink),e.length>2)for(let n=1;n<e.length-1;n++)hi(e[n])&&(e[n]=Dd(e[n]));return Cd(...e)}var Cd=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},ll=r=>r?.[Symbol.asyncIterator]!=null,ul=r=>r?.[Symbol.iterator]!=null,hi=r=>r==null?!1:r.sink!=null&&r.source!=null,Dd=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=ws({objectMode:!0});e.then(()=>{n.end()},i=>{n.end(i)});let s,o=r.source;if(ll(o))s=async function*(){yield*o,n.end()};else if(ul(o))s=function*(){yield*o,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return cl(n,s())}return r.source};var fl="libp2p",hl="autonat",dl="1.0.0";var D;(function(r){let t;(function(l){l.DIAL="DIAL",l.DIAL_RESPONSE="DIAL_RESPONSE"})(t=r.MessageType||(r.MessageType={}));let e;(function(l){l[l.DIAL=0]="DIAL",l[l.DIAL_RESPONSE=1]="DIAL_RESPONSE"})(e||(e={})),function(l){l.codec=()=>ur(e)}(t=r.MessageType||(r.MessageType={}));let n;(function(l){l.OK="OK",l.E_DIAL_ERROR="E_DIAL_ERROR",l.E_DIAL_REFUSED="E_DIAL_REFUSED",l.E_BAD_REQUEST="E_BAD_REQUEST",l.E_INTERNAL_ERROR="E_INTERNAL_ERROR"})(n=r.ResponseStatus||(r.ResponseStatus={}));let s;(function(l){l[l.OK=0]="OK",l[l.E_DIAL_ERROR=100]="E_DIAL_ERROR",l[l.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",l[l.E_BAD_REQUEST=200]="E_BAD_REQUEST",l[l.E_INTERNAL_ERROR=300]="E_INTERNAL_ERROR"})(s||(s={})),function(l){l.codec=()=>ur(s)}(n=r.ResponseStatus||(r.ResponseStatus={}));let o;(function(l){let f;l.codec=()=>(f==null&&(f=oe((u,h,m={})=>{if(m.lengthDelimited!==!1&&h.fork(),u.id!=null&&(h.uint32(10),h.bytes(u.id)),u.addrs!=null)for(let g of u.addrs)h.uint32(18),h.bytes(g);m.lengthDelimited!==!1&&h.ldelim()},(u,h)=>{let m={addrs:[]},g=h==null?u.len:u.pos+h;for(;u.pos<g;){let d=u.uint32();switch(d>>>3){case 1:m.id=u.bytes();break;case 2:m.addrs.push(u.bytes());break;default:u.skipType(d&7);break}}return m})),f),l.encode=u=>se(u,l.codec()),l.decode=u=>ne(u,l.codec())})(o=r.PeerInfo||(r.PeerInfo={}));let i;(function(l){let f;l.codec=()=>(f==null&&(f=oe((u,h,m={})=>{m.lengthDelimited!==!1&&h.fork(),u.peer!=null&&(h.uint32(10),r.PeerInfo.codec().encode(u.peer,h)),m.lengthDelimited!==!1&&h.ldelim()},(u,h)=>{let m={},g=h==null?u.len:u.pos+h;for(;u.pos<g;){let d=u.uint32();switch(d>>>3){case 1:m.peer=r.PeerInfo.codec().decode(u,u.uint32());break;default:u.skipType(d&7);break}}return m})),f),l.encode=u=>se(u,l.codec()),l.decode=u=>ne(u,l.codec())})(i=r.Dial||(r.Dial={}));let a;(function(l){let f;l.codec=()=>(f==null&&(f=oe((u,h,m={})=>{m.lengthDelimited!==!1&&h.fork(),u.status!=null&&(h.uint32(8),r.ResponseStatus.codec().encode(u.status,h)),u.statusText!=null&&(h.uint32(18),h.string(u.statusText)),u.addr!=null&&(h.uint32(26),h.bytes(u.addr)),m.lengthDelimited!==!1&&h.ldelim()},(u,h)=>{let m={},g=h==null?u.len:u.pos+h;for(;u.pos<g;){let d=u.uint32();switch(d>>>3){case 1:m.status=r.ResponseStatus.codec().decode(u);break;case 2:m.statusText=u.string();break;case 3:m.addr=u.bytes();break;default:u.skipType(d&7);break}}return m})),f),l.encode=u=>se(u,l.codec()),l.decode=u=>ne(u,l.codec())})(a=r.DialResponse||(r.DialResponse={}));let c;r.codec=()=>(c==null&&(c=oe((l,f,u={})=>{u.lengthDelimited!==!1&&f.fork(),l.type!=null&&(f.uint32(8),r.MessageType.codec().encode(l.type,f)),l.dial!=null&&(f.uint32(18),r.Dial.codec().encode(l.dial,f)),l.dialResponse!=null&&(f.uint32(26),r.DialResponse.codec().encode(l.dialResponse,f)),u.lengthDelimited!==!1&&f.ldelim()},(l,f)=>{let u={},h=f==null?l.len:l.pos+f;for(;l.pos<h;){let m=l.uint32();switch(m>>>3){case 1:u.type=r.MessageType.codec().decode(l);break;case 2:u.dial=r.Dial.codec().decode(l,l.uint32());break;case 3:u.dialResponse=r.DialResponse.codec().decode(l,l.uint32());break;default:l.skipType(m&7);break}}return u})),c),r.encode=l=>se(l,r.codec()),r.decode=l=>ne(l,r.codec())})(D||(D={}));var pi=4,xs=class{components;startupDelay;refreshInterval;protocol;timeout;maxInboundStreams;maxOutboundStreams;verifyAddressTimeout;started;log;constructor(t,e){this.components=t,this.log=t.logger.forComponent("libp2p:autonat"),this.started=!1,this.protocol=`/${e.protocolPrefix??fl}/${hl}/${dl}`,this.timeout=e.timeout??3e4,this.maxInboundStreams=e.maxInboundStreams??1,this.maxOutboundStreams=e.maxOutboundStreams??1,this.startupDelay=e.startupDelay??5e3,this.refreshInterval=e.refreshInterval??6e4,this._verifyExternalAddresses=this._verifyExternalAddresses.bind(this)}isStarted(){return this.started}async start(){this.started||(await this.components.registrar.handle(this.protocol,t=>{this.handleIncomingAutonatStream(t).catch(e=>{this.log.error("error handling incoming autonat stream",e)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.verifyAddressTimeout=setTimeout(this._verifyExternalAddresses,this.startupDelay),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.protocol),clearTimeout(this.verifyAddressTimeout),this.started=!1}async handleIncomingAutonatStream(t){let e=AbortSignal.timeout(this.timeout),n=()=>{t.stream.abort(new U("handleIncomingAutonatStream timeout",As))};e.addEventListener("abort",n,{once:!0}),Ss(1/0,e);let s=this.components.addressManager.getAddresses().map(o=>o.toOptions().host);try{let o=this;await di(t.stream,i=>vr(i),async function*(i){let a=await ci(i);if(a==null){o.log("no message received"),yield D.encode({type:D.MessageType.DIAL_RESPONSE,dialResponse:{status:D.ResponseStatus.E_BAD_REQUEST,statusText:"No message was sent"}});return}let c;try{c=D.decode(a)}catch(d){o.log.error("could not decode message",d),yield D.encode({type:D.MessageType.DIAL_RESPONSE,dialResponse:{status:D.ResponseStatus.E_BAD_REQUEST,statusText:"Could not decode message"}});return}let l=c.dial;if(l==null){o.log.error("dial was missing from message"),yield D.encode({type:D.MessageType.DIAL_RESPONSE,dialResponse:{status:D.ResponseStatus.E_BAD_REQUEST,statusText:"No Dial message found in message"}});return}let f,u=l.peer;if(u==null||u.id==null){o.log.error("PeerId missing from message"),yield D.encode({type:D.MessageType.DIAL_RESPONSE,dialResponse:{status:D.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}});return}try{f=Jr(u.id)}catch(d){o.log.error("invalid PeerId",d),yield D.encode({type:D.MessageType.DIAL_RESPONSE,dialResponse:{status:D.ResponseStatus.E_BAD_REQUEST,statusText:"bad peer id"}});return}if(o.log("incoming request from %p",f),!t.connection.remotePeer.equals(f)){o.log("target peer %p did not equal sending peer %p",f,t.connection.remotePeer),yield D.encode({type:D.MessageType.DIAL_RESPONSE,dialResponse:{status:D.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}});return}let h=u.addrs.map(d=>ds(d)).filter(d=>{let p=d.toOptions().host===t.connection.remoteAddr.toOptions().host;return o.log.trace("request to dial %a was sent from %a is same host %s",d,t.connection.remoteAddr,p),p}).filter(d=>{let p=d.toOptions().host,y=!(Jo(p)??!1);return o.log.trace("host %s was public %s",p,y),y}).filter(d=>{let p=d.toOptions().host,y=!s.includes(p);return o.log.trace("host %s was not our host %s",p,y),y}).filter(d=>{let p=!!o.components.transportManager.transportForMultiaddr(d);return o.log.trace("transport for %a is supported %s",d,p),p}).map(d=>(d.getPeerId()==null&&(d=d.encapsulate(`/p2p/${f.toString()}`)),d));if(h.length===0){o.log("no valid multiaddrs for %p in message",f),yield D.encode({type:D.MessageType.DIAL_RESPONSE,dialResponse:{status:D.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}});return}o.log("dial multiaddrs %s for peer %p",h.map(d=>d.toString()).join(", "),f);let m="",g=h[0];for await(let d of h){let p;g=d;try{if(p=await o.components.connectionManager.openConnection(d,{signal:e}),!p.remoteAddr.equals(d))throw o.log.error("tried to dial %a but dialed %a",d,p.remoteAddr),new Error("Unexpected remote address");o.log("Success %p",f),yield D.encode({type:D.MessageType.DIAL_RESPONSE,dialResponse:{status:D.ResponseStatus.OK,addr:p.remoteAddr.decapsulateCode(W("p2p").code).bytes}});return}catch(y){o.log("could not dial %p",f,y),m=y.message}finally{p!=null&&await p.close()}}yield D.encode({type:D.MessageType.DIAL_RESPONSE,dialResponse:{status:D.ResponseStatus.E_DIAL_ERROR,statusText:m,addr:g.bytes}})},i=>Wr(i),t.stream)}catch(o){this.log.error("error handling incoming autonat stream",o)}finally{e.removeEventListener("abort",n)}}_verifyExternalAddresses(){this.verifyExternalAddresses().catch(t=>{this.log.error("error verifying external address",t)})}async verifyExternalAddresses(){if(clearTimeout(this.verifyAddressTimeout),!this.isStarted())return;let t=this.components.addressManager,e=t.getObservedAddrs().filter(o=>{let i=o.toOptions();return!(Jo(i.host)??!1)});if(e.length===0){this.log("no public addresses found, not requesting verification"),this.verifyAddressTimeout=setTimeout(this._verifyExternalAddresses,this.refreshInterval);return}let n=AbortSignal.timeout(this.timeout);Ss(1/0,n);let s=this;try{this.log("verify multiaddrs %s",e.map(u=>u.toString()).join(", "));let o=D.encode({type:D.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toBytes(),addrs:e.map(u=>u.bytes)}}}),a=(await Oc()).toBytes(),c={},l=[],f=async u=>{let h=()=>{};try{this.log("asking %p to verify multiaddr",u.id);let m=await s.components.connectionManager.openConnection(u.id,{signal:n}),g=await m.newStream(this.protocol,{signal:n});h=()=>{g.abort(new U("verifyAddress timeout",As))},n.addEventListener("abort",h,{once:!0});let d=await di([o],y=>Wr(y),g,y=>vr(y),async y=>ci(y));if(d==null){this.log("no response received from %p",m.remotePeer);return}let p=D.decode(d);if(p.type!==D.MessageType.DIAL_RESPONSE||p.dialResponse==null){this.log("invalid autonat response from %p",m.remotePeer);return}if(p.dialResponse.status===D.ResponseStatus.OK){let y=m.remoteAddr.toOptions(),v;if(y.family===4)v=y.host.split(".")[0];else if(y.family===6)v=y.host.split(":")[0];else{this.log('remote address "%s" was not IP4 or IP6?',y.host);return}if(l.includes(v)){this.log("already have response from network segment %d - %s",v,y.host);return}l.push(v)}return p.dialResponse}catch(m){this.log.error("error asking remote to verify multiaddr",m)}finally{n.removeEventListener("abort",h)}};for await(let u of ui(al(this.components.peerRouting.getClosestPeers(a,{signal:n}),h=>async()=>f(h)),{concurrency:pi}))try{if(u==null)continue;let h=u.addr==null?e[0]:ds(u.addr);if(this.log("autonat response for %a is %s",h,u.status),u.status===D.ResponseStatus.E_BAD_REQUEST||u.status===D.ResponseStatus.E_DIAL_REFUSED||u.addr==null&&e.length>1)continue;if(!e.some(g=>g.equals(h))){this.log("peer reported %a as %s but it was not in our observed address list",h,u.status);continue}let m=h.toString();if(c[m]==null&&(c[m]={success:0,failure:0}),u.status===D.ResponseStatus.OK?c[m].success++:u.status===D.ResponseStatus.E_DIAL_ERROR&&c[m].failure++,c[m].success===pi){this.log("%a is externally dialable",h),t.confirmObservedAddr(h);return}if(c[m].failure===pi){this.log("%a is not externally dialable",h),t.removeObservedAddr(h);return}}catch(h){this.log.error("could not verify external address",h)}}finally{this.verifyAddressTimeout=setTimeout(this._verifyExternalAddresses,this.refreshInterval)}}};function Md(r={}){return t=>new xs(t,r)}return Il(Kd);})();
6
+ `)}`:`${e} :`}};Oa=Re;S.Constructed=Oa;Re.NAME="CONSTRUCTED";var Rn=class extends Et{fromBER(t,e,n){return e}toBER(t){return Ft}};Rn.override="EndOfContentValueBlock";var Va,Nn=class extends mt{constructor(t={}){super(t,Rn),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};Va=Nn;S.EndOfContent=Va;Nn.NAME=Or;var Fa,Ne=class extends mt{constructor(t={}){super(t,Et),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(t,e,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,e+n>t.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):e+n}toBER(t,e){let n=new ArrayBuffer(2);if(!t){let s=new Uint8Array(n);s[0]=5,s[1]=0}return e&&e.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};Fa=Ne;S.Null=Fa;Ne.NAME="NULL";var Tn=class extends fe(Et){constructor({value:t,...e}={}){super(e),e.valueHex?this.valueHexView=H.BufferSourceConverter.toUint8Array(e.valueHex):this.valueHexView=new Uint8Array(1),t&&(this.value=t)}get value(){for(let t of this.valueHexView)if(t>0)return!0;return!1}set value(t){this.valueHexView[0]=t?255:0}fromBER(t,e,n){let s=H.BufferSourceConverter.toUint8Array(t);return ue(this,s,e,n)?(this.valueHexView=s.subarray(e,e+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,Do.call(this),this.blockLength=n,e+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};Tn.NAME="BooleanValueBlock";var Ha,Ln=class extends mt{constructor(t={}){super(t,Tn),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}getValue(){return this.valueBlock.value}setValue(t){this.valueBlock.value=t}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};Ha=Ln;S.Boolean=Ha;Ln.NAME="BOOLEAN";var _n=class extends fe($t){constructor({isConstructed:t=!1,...e}={}){super(e),this.isConstructed=t}fromBER(t,e,n){let s=0;if(this.isConstructed){if(this.isHexOnly=!1,s=$t.prototype.fromBER.call(this,t,e,n),s===-1)return s;for(let o=0;o<this.value.length;o++){let i=this.value[o].constructor.NAME;if(i===Or){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(i!==Ua)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,s=super.fromBER(t,e,n),this.blockLength=n;return s}toBER(t,e){return this.isConstructed?$t.prototype.toBER.call(this,t,e):t?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};_n.NAME="OctetStringValueBlock";var Ma,ce=class r extends mt{constructor({idBlock:t={},lenBlock:e={},...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,...t},lenBlock:{...e,isIndefiniteForm:!!n.isIndefiniteForm},...n},_n),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(t,e,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),e;if(!this.valueBlock.isConstructed){let o=(t instanceof ArrayBuffer?new Uint8Array(t):t).subarray(e,e+n);try{if(o.byteLength){let i=is(o,0,o.byteLength);i.offset!==-1&&i.offset===n&&(this.valueBlock.value=[i.result])}}catch{}}return super.fromBER(t,e,n)}onAsciiEncoding(){return this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length?Re.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${H.Convert.ToHex(this.valueBlock.valueHexView)}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let t=[];for(let e of this.valueBlock.value)e instanceof r&&t.push(e.valueBlock.valueHexView);return H.BufferSourceConverter.concat(t)}};Ma=ce;S.OctetString=Ma;ce.NAME=Ua;var Un=class extends fe($t){constructor({unusedBits:t=0,isConstructed:e=!1,...n}={}){super(n),this.unusedBits=t,this.isConstructed=e,this.blockLength=this.valueHexView.byteLength}fromBER(t,e,n){if(!n)return e;let s=-1;if(this.isConstructed){if(s=$t.prototype.fromBER.call(this,t,e,n),s===-1)return s;for(let a of this.value){let c=a.constructor.NAME;if(c===Or){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==Ca)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let l=a.valueBlock;if(this.unusedBits>0&&l.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=l.unusedBits}return s}let o=H.BufferSourceConverter.toUint8Array(t);if(!ue(this,o,e,n))return-1;let i=o.subarray(e,e+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=is(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,e+n}toBER(t,e){if(this.isConstructed)return $t.prototype.toBER.call(this,t,e);if(t)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}}};Un.NAME="BitStringValueBlock";var Ka,dr=class extends mt{constructor({idBlock:t={},lenBlock:e={},...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,...t},lenBlock:{...e,isIndefiniteForm:!!n.isIndefiniteForm},...n},Un),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(t,e,n){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(t,e,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return Re.prototype.onAsciiEncoding.call(this);{let t=[],e=this.valueBlock.valueHexView;for(let s of e)t.push(s.toString(2).padStart(8,"0"));let n=t.join("");return`${this.constructor.NAME} : ${n.substring(0,n.length-this.valueBlock.unusedBits)}`}}};Ka=dr;S.BitString=Ka;dr.NAME=Ca;var $a;function wh(r,t){let e=new Uint8Array([0]),n=new Uint8Array(r),s=new Uint8Array(t),o=n.slice(0),i=o.length-1,a=s.slice(0),c=a.length-1,l=0,f=c<i?i:c,u=0;for(let h=f;h>=0;h--,u++){switch(!0){case u<a.length:l=o[i-u]+a[c-u]+e[0];break;default:l=o[i-u]+e[0]}switch(e[0]=l/10,!0){case u>=o.length:o=vn(new Uint8Array([l%10]),o);break;default:o[i-u]=l%10}}return e[0]>0&&(o=vn(e,o)),o}function _a(r){if(r>=Dr.length)for(let t=Dr.length;t<=r;t++){let e=new Uint8Array([0]),n=Dr[t-1].slice(0);for(let s=n.length-1;s>=0;s--){let o=new Uint8Array([(n[s]<<1)+e[0]]);e[0]=o[0]/10,n[s]=o[0]%10}e[0]>0&&(n=vn(e,n)),Dr.push(n)}return Dr[r]}function xh(r,t){let e=0,n=new Uint8Array(r),s=new Uint8Array(t),o=n.slice(0),i=o.length-1,a=s.slice(0),c=a.length-1,l,f=0;for(let u=c;u>=0;u--,f++)switch(l=o[i-f]-a[c-f]-e,!0){case l<0:e=1,o[i-f]=l+10;break;default:e=0,o[i-f]=l}if(e>0)for(let u=i-c+1;u>=0;u--,f++)if(l=o[i-f]-e,l<0)e=1,o[i-f]=l+10;else{e=0,o[i-f]=l;break}return o.slice()}var Vr=class extends fe(Et){constructor({value:t,...e}={}){super(e),this._valueDec=0,e.valueHex&&this.setValueHex(),t!==void 0&&(this.valueDec=t)}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=Do.call(this)))}set valueDec(t){this._valueDec=t,this.isHexOnly=!1,this.valueHexView=new Uint8Array(Na(t))}get valueDec(){return this._valueDec}fromDER(t,e,n,s=0){let o=this.fromBER(t,e,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(t=!1){let e=this.valueHexView;switch(!0){case(e[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(e,1),this.valueHexView=n}break;case(e[0]===0&&(e[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(t)}fromBER(t,e,n){let s=super.fromBER(t,e,n);return s===-1||this.setValueHex(),s}toBER(t){return t?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let t=this.valueHexView.length*8-1,e=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 l=0;l<8;l++){if((s&1)===1)switch(n){case t:e=xh(_a(n),e),i="-";break;default:e=wh(e,_a(n))}n++,s>>=1}}for(let c=0;c<e.length;c++)e[c]&&(a=!0),a&&(i+=La.charAt(e[c]));return a===!1&&(i+=La.charAt(0)),i}};$a=Vr;Vr.NAME="IntegerValueBlock";Object.defineProperty($a.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var qa,ot=class r extends mt{constructor(t={}){super(t,Vr),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return En(),BigInt(this.valueBlock.toString())}static fromBigInt(t){En();let e=BigInt(t),n=new Pr,s=e.toString(16).replace(/^-/,""),o=new Uint8Array(H.Convert.FromHex(s));if(e<0){let a=new Uint8Array(o.length+(o[0]&128?1:0));a[0]|=128;let l=BigInt(`0x${H.Convert.ToHex(a)}`)+e,f=H.BufferSourceConverter.toUint8Array(H.Convert.FromHex(l.toString(16)));f[0]|=128,n.write(f)}else o[0]&128&&n.write(new Uint8Array([0])),n.write(o);return new r({valueHex:n.final()})}convertToDER(){let t=new r({valueHex:this.valueBlock.valueHexView});return t.valueBlock.toDER(),t}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()}`}};qa=ot;S.Integer=qa;ot.NAME="INTEGER";var Ga,Cn=class extends ot{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};Ga=Cn;S.Enumerated=Ga;Cn.NAME="ENUMERATED";var Fr=class extends fe(Et){constructor({valueDec:t=-1,isFirstSid:e=!1,...n}={}){super(n),this.valueDec=t,this.isFirstSid=e}fromBER(t,e,n){if(!n)return e;let s=H.BufferSourceConverter.toUint8Array(t);if(!ue(this,s,e,n))return-1;let o=s.subarray(e,e+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=$e(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),e+this.blockLength)}set valueBigInt(t){En();let e=BigInt(t).toString(2);for(;e.length%7;)e="0"+e;let n=new Uint8Array(e.length/7);for(let s=0;s<n.length;s++)n[s]=parseInt(e.slice(s*7,s*7+7),2)+(s+1<n.length?128:0);this.fromBER(n.buffer,0,n.length)}toBER(t){if(this.isHexOnly){if(t)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 e=Ie(this.valueDec,7);if(e.byteLength===0)return this.error="Error during encoding SID value",Ft;let n=new Uint8Array(e.byteLength);if(!t){let s=new Uint8Array(e),o=e.byteLength-1;for(let i=0;i<o;i++)n[i]=s[i]|128;n[o]=s[o]}return n}toString(){let t="";if(this.isHexOnly)t=H.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let e=this.valueDec;this.valueDec<=39?t="0.":this.valueDec<=79?(t="1.",e-=40):(t="2.",e-=80),t+=e.toString()}else t=this.valueDec.toString();return t}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};Fr.NAME="sidBlock";var Dn=class extends Et{constructor({value:t=pr,...e}={}){super(e),this.value=[],t&&this.fromString(t)}fromBER(t,e,n){let s=e;for(;n>0;){let o=new Fr;if(s=o.fromBER(t,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(t){let e=[];for(let n=0;n<this.value.length;n++){let s=this.value[n].toBER(t);if(s.byteLength===0)return this.error=this.value[n].error,Ft;e.push(s)}return Po(e)}fromString(t){this.value=[];let e=0,n=0,s="",o=!1;do if(n=t.indexOf(".",e),n===-1?s=t.substring(e):s=t.substring(e,n),e=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 Fr;if(s>Number.MAX_SAFE_INTEGER){En();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 t="",e=!1;for(let n=0;n<this.value.length;n++){e=this.value[n].isHexOnly;let s=this.value[n].toString();n!==0&&(t=`${t}.`),e?(s=`{${s}}`,this.value[n].isFirstSid?t=`2.{${s} - 80}`:t+=s):t+=s}return t}toJSON(){let t={...super.toJSON(),value:this.toString(),sidArray:[]};for(let e=0;e<this.value.length;e++)t.sidArray.push(this.value[e].toJSON());return t}};Dn.NAME="ObjectIdentifierValueBlock";var za,Vt=class extends mt{constructor(t={}){super(t,Dn),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}getValue(){return this.valueBlock.toString()}setValue(t){this.valueBlock.fromString(t)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};za=Vt;S.ObjectIdentifier=za;Vt.NAME="OBJECT IDENTIFIER";var Hr=class extends fe(ae){constructor({valueDec:t=0,...e}={}){super(e),this.valueDec=t}fromBER(t,e,n){if(n===0)return e;let s=H.BufferSourceConverter.toUint8Array(t);if(!ue(this,s,e,n))return-1;let o=s.subarray(e,e+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=$e(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),e+this.blockLength)}toBER(t){if(this.isHexOnly){if(t)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 e=Ie(this.valueDec,7);if(e.byteLength===0)return this.error="Error during encoding SID value",Ft;let n=new Uint8Array(e.byteLength);if(!t){let s=new Uint8Array(e),o=e.byteLength-1;for(let i=0;i<o;i++)n[i]=s[i]|128;n[o]=s[o]}return n.buffer}toString(){let t="";return this.isHexOnly?t=H.Convert.ToHex(this.valueHexView):t=this.valueDec.toString(),t}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};Hr.NAME="relativeSidBlock";var Pn=class extends Et{constructor({value:t=pr,...e}={}){super(e),this.value=[],t&&this.fromString(t)}fromBER(t,e,n){let s=e;for(;n>0;){let o=new Hr;if(s=o.fromBER(t,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(t,e){let n=[];for(let s=0;s<this.value.length;s++){let o=this.value[s].toBER(t);if(o.byteLength===0)return this.error=this.value[s].error,Ft;n.push(o)}return Po(n)}fromString(t){this.value=[];let e=0,n=0,s="";do{n=t.indexOf(".",e),n===-1?s=t.substring(e):s=t.substring(e,n),e=n+1;let o=new Hr;if(o.valueDec=parseInt(s,10),isNaN(o.valueDec))return!0;this.value.push(o)}while(n!==-1);return!0}toString(){let t="",e=!1;for(let n=0;n<this.value.length;n++){e=this.value[n].isHexOnly;let s=this.value[n].toString();n!==0&&(t=`${t}.`),e&&(s=`{${s}}`),t+=s}return t}toJSON(){let t={...super.toJSON(),value:this.toString(),sidArray:[]};for(let e=0;e<this.value.length;e++)t.sidArray.push(this.value[e].toJSON());return t}};Pn.NAME="RelativeObjectIdentifierValueBlock";var ja,On=class extends mt{constructor(t={}){super(t,Pn),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}getValue(){return this.valueBlock.toString()}setValue(t){this.valueBlock.fromString(t)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};ja=On;S.RelativeObjectIdentifier=ja;On.NAME="RelativeObjectIdentifier";var Wa,ft=class extends Re{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};Wa=ft;S.Sequence=Wa;ft.NAME="SEQUENCE";var Ya,Vn=class extends Re{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};Ya=Vn;S.Set=Ya;Vn.NAME="SET";var Fn=class extends fe(Et){constructor({...t}={}){super(t),this.isHexOnly=!0,this.value=pr}toJSON(){return{...super.toJSON(),value:this.value}}};Fn.NAME="StringValueBlock";var Hn=class extends Fn{};Hn.NAME="SimpleStringValueBlock";var St=class extends Sn{constructor({...t}={}){super(t,Hn)}fromBuffer(t){this.valueBlock.value=String.fromCharCode.apply(null,H.BufferSourceConverter.toUint8Array(t))}fromString(t){let e=t.length,n=this.valueBlock.valueHexView=new Uint8Array(e);for(let s=0;s<e;s++)n[s]=t.charCodeAt(s);this.valueBlock.value=t}};St.NAME="SIMPLE STRING";var Mn=class extends St{fromBuffer(t){this.valueBlock.valueHexView=H.BufferSourceConverter.toUint8Array(t);try{this.valueBlock.value=H.Convert.ToUtf8String(t)}catch(e){this.warnings.push(`Error during "decodeURIComponent": ${e}, using raw string`),this.valueBlock.value=H.Convert.ToBinary(t)}}fromString(t){this.valueBlock.valueHexView=new Uint8Array(H.Convert.FromUtf8String(t)),this.valueBlock.value=t}};Mn.NAME="Utf8StringValueBlock";var Za,le=class extends Mn{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};Za=le;S.Utf8String=Za;le.NAME="UTF8String";var Kn=class extends St{fromBuffer(t){this.valueBlock.value=H.Convert.ToUtf16String(t),this.valueBlock.valueHexView=H.BufferSourceConverter.toUint8Array(t)}fromString(t){this.valueBlock.value=t,this.valueBlock.valueHexView=new Uint8Array(H.Convert.FromUtf16String(t))}};Kn.NAME="BmpStringValueBlock";var Ja,$n=class extends Kn{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};Ja=$n;S.BmpString=Ja;$n.NAME="BMPString";var qn=class extends St{fromBuffer(t){let e=ArrayBuffer.isView(t)?t.slice().buffer:t.slice(0),n=new Uint8Array(e);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(e))}fromString(t){let e=t.length,n=this.valueBlock.valueHexView=new Uint8Array(e*4);for(let s=0;s<e;s++){let o=Ie(t.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=t}};qn.NAME="UniversalStringValueBlock";var Xa,Gn=class extends qn{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};Xa=Gn;S.UniversalString=Xa;Gn.NAME="UniversalString";var Qa,zn=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};Qa=zn;S.NumericString=Qa;zn.NAME="NumericString";var tc,jn=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};tc=jn;S.PrintableString=tc;jn.NAME="PrintableString";var ec,Wn=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};ec=Wn;S.TeletexString=ec;Wn.NAME="TeletexString";var rc,Yn=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};rc=Yn;S.VideotexString=rc;Yn.NAME="VideotexString";var nc,Zn=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};nc=Zn;S.IA5String=nc;Zn.NAME="IA5String";var sc,Jn=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};sc=Jn;S.GraphicString=sc;Jn.NAME="GraphicString";var oc,Mr=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};oc=Mr;S.VisibleString=oc;Mr.NAME="VisibleString";var ic,Xn=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};ic=Xn;S.GeneralString=ic;Xn.NAME="GeneralString";var ac,Qn=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};ac=Qn;S.CharacterString=ac;Qn.NAME="CharacterString";var cc,Kr=class extends Mr{constructor({value:t,valueDate:e,...n}={}){if(super(n),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,t){this.fromString(t),this.valueBlock.valueHexView=new Uint8Array(t.length);for(let s=0;s<t.length;s++)this.valueBlock.valueHexView[s]=t.charCodeAt(s)}e&&(this.fromDate(e),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(t){this.fromString(String.fromCharCode.apply(null,H.BufferSourceConverter.toUint8Array(t)))}toBuffer(){let t=this.toString(),e=new ArrayBuffer(t.length),n=new Uint8Array(e);for(let s=0;s<t.length;s++)n[s]=t.charCodeAt(s);return e}fromDate(t){this.year=t.getUTCFullYear(),this.month=t.getUTCMonth()+1,this.day=t.getUTCDate(),this.hour=t.getUTCHours(),this.minute=t.getUTCMinutes(),this.second=t.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(t){let n=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(t);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(t="iso"){if(t==="iso"){let e=new Array(7);return e[0]=kt(this.year<2e3?this.year-1900:this.year-2e3,2),e[1]=kt(this.month,2),e[2]=kt(this.day,2),e[3]=kt(this.hour,2),e[4]=kt(this.minute,2),e[5]=kt(this.second,2),e[6]="Z",e.join("")}return super.toString(t)}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}}};cc=Kr;S.UTCTime=cc;Kr.NAME="UTCTime";var lc,ts=class extends Kr{constructor(t={}){var e;super(t),(e=this.millisecond)!==null&&e!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(t){super.fromDate(t),this.millisecond=t.getUTCMilliseconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond))}fromString(t){let e=!1,n="",s="",o=0,i,a=0,c=0;if(t[t.length-1]==="Z")n=t.substring(0,t.length-1),e=!0;else{let u=new Number(t[t.length-1]);if(isNaN(u.valueOf()))throw new Error("Wrong input string for conversion");n=t}if(e){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 u=1,h=n.indexOf("+"),m="";if(h===-1&&(h=n.indexOf("-"),u=-1),h!==-1){if(m=n.substring(h+1),n=n.substring(0,h),m.length!==2&&m.length!==4)throw new Error("Wrong input string for conversion");let g=parseInt(m.substring(0,2),10);if(isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");if(a=u*g,m.length===4){if(g=parseInt(m.substring(2,4),10),isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");c=u*g}}}let l=n.indexOf(".");if(l===-1&&(l=n.indexOf(",")),l!==-1){let u=new Number(`0${n.substring(l)}`);if(isNaN(u.valueOf()))throw new Error("Wrong input string for conversion");o=u.valueOf(),s=n.substring(0,l)}else s=n;switch(!0){case s.length===8:if(i=/(\d{4})(\d{2})(\d{2})/ig,l!==-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,l!==-1){let u=60*o;this.minute=Math.floor(u),u=60*(u-this.minute),this.second=Math.floor(u),u=1e3*(u-this.second),this.millisecond=Math.floor(u)}break;case s.length===12:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let u=60*o;this.second=Math.floor(u),u=1e3*(u-this.second),this.millisecond=Math.floor(u)}break;case s.length===14:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let u=1e3*o;this.millisecond=Math.floor(u)}break;default:throw new Error("Wrong input string for conversion")}let f=i.exec(s);if(f===null)throw new Error("Wrong input string for conversion");for(let u=1;u<f.length;u++)switch(u){case 1:this.year=parseInt(f[u],10);break;case 2:this.month=parseInt(f[u],10);break;case 3:this.day=parseInt(f[u],10);break;case 4:this.hour=parseInt(f[u],10)+a;break;case 5:this.minute=parseInt(f[u],10)+c;break;case 6:this.second=parseInt(f[u],10);break;default:throw new Error("Wrong input string for conversion")}if(e===!1){let u=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=u.getUTCFullYear(),this.month=u.getUTCMonth(),this.day=u.getUTCDay(),this.hour=u.getUTCHours(),this.minute=u.getUTCMinutes(),this.second=u.getUTCSeconds(),this.millisecond=u.getUTCMilliseconds()}}toString(t="iso"){if(t==="iso"){let e=[];return e.push(kt(this.year,4)),e.push(kt(this.month,2)),e.push(kt(this.day,2)),e.push(kt(this.hour,2)),e.push(kt(this.minute,2)),e.push(kt(this.second,2)),this.millisecond!==0&&(e.push("."),e.push(kt(this.millisecond,3))),e.push("Z"),e.join("")}return super.toString(t)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};lc=ts;S.GeneralizedTime=lc;ts.NAME="GeneralizedTime";var uc,es=class extends le{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};uc=es;S.DATE=uc;es.NAME="DATE";var fc,rs=class extends le{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};fc=rs;S.TimeOfDay=fc;rs.NAME="TimeOfDay";var hc,ns=class extends le{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};hc=ns;S.DateTime=hc;ns.NAME="DateTime";var dc,ss=class extends le{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};dc=ss;S.Duration=dc;ss.NAME="Duration";var pc,os=class extends le{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};pc=os;S.TIME=pc;os.NAME="TIME";function Eh(r){let{result:t}=gr(r),e=t.valueBlock.value;return{n:z(qt(e[1].toBigInt()),"base64url"),e:z(qt(e[2].toBigInt()),"base64url"),d:z(qt(e[3].toBigInt()),"base64url"),p:z(qt(e[4].toBigInt()),"base64url"),q:z(qt(e[5].toBigInt()),"base64url"),dp:z(qt(e[6].toBigInt()),"base64url"),dq:z(qt(e[7].toBigInt()),"base64url"),qi:z(qt(e[8].toBigInt()),"base64url"),kty:"RSA",alg:"RS256"}}function Bh(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 U("JWK was missing components","ERR_INVALID_PARAMETERS");let e=new ft({value:[new ot({value:0}),ot.fromBigInt(Gt(Z(r.n,"base64url"))),ot.fromBigInt(Gt(Z(r.e,"base64url"))),ot.fromBigInt(Gt(Z(r.d,"base64url"))),ot.fromBigInt(Gt(Z(r.p,"base64url"))),ot.fromBigInt(Gt(Z(r.q,"base64url"))),ot.fromBigInt(Gt(Z(r.dp,"base64url"))),ot.fromBigInt(Gt(Z(r.dq,"base64url"))),ot.fromBigInt(Gt(Z(r.qi,"base64url")))]}).toBER();return new Uint8Array(e,0,e.byteLength)}function Ah(r){let{result:t}=gr(r),e=t.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:z(qt(e[0].toBigInt()),"base64url"),e:z(qt(e[1].toBigInt()),"base64url")}}function Sh(r){if(r.n==null||r.e==null)throw new U("JWK was missing components","ERR_INVALID_PARAMETERS");let e=new ft({value:[new ft({value:[new Vt({value:"1.2.840.113549.1.1.1"}),new Ne]}),new dr({valueHex:new ft({value:[ot.fromBigInt(Gt(Z(r.n,"base64url"))),ot.fromBigInt(Gt(Z(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(e,0,e.byteLength)}function qt(r){let t=r.toString(16);t.length%2>0&&(t=`0${t}`);let e=t.length/2,n=new Uint8Array(e),s=0,o=0;for(;s<e;)n[s]=parseInt(t.slice(o,o+2),16),s+=1,o+=2;return n}function Gt(r){let t=[];return r.forEach(function(e){let n=e.toString(16);n.length%2>0&&(n=`0${n}`),t.push(n)}),BigInt("0x"+t.join(""))}var kh=16,Vo=32,Fo=1e4;async function Ih(r,t){let e=At.get(),s=new ft({value:[new ot({value:0}),new ft({value:[new Vt({value:"1.2.840.113549.1.1.1"}),new Ne]}),new ce({valueHex:r.marshal()})]}).toBER(),o=new Uint8Array(s,0,s.byteLength),i=Ke(kh),a=await Uo(or,t,i,{c:Fo,dkLen:Vo}),c=Ke(16),l=await e.subtle.importKey("raw",a,"AES-CBC",!1,["encrypt"]),f=await e.subtle.encrypt({name:"AES-CBC",iv:c},l,o),u=new ft({value:[new ce({valueHex:i}),new ot({value:Fo}),new ot({value:Vo}),new ft({value:[new Vt({value:"1.2.840.113549.2.11"}),new Ne]})]}),h=new ft({value:[new Vt({value:"1.2.840.113549.1.5.13"}),new ft({value:[new ft({value:[new Vt({value:"1.2.840.113549.1.5.12"}),u]}),new ft({value:[new Vt({value:"2.16.840.1.101.3.4.1.42"}),new ce({valueHex:c})]})]})]}),g=new ft({value:[h,new ce({valueHex:f})]}).toBER(),d=new Uint8Array(g,0,g.byteLength);return["-----BEGIN ENCRYPTED PRIVATE KEY-----",...z(d,"base64pad").split(/(.{64})/).filter(Boolean),"-----END ENCRYPTED PRIVATE KEY-----"].join(`
7
+ `)}async function Rh(r,t){let e=At.get(),n;if(r.includes("-----BEGIN ENCRYPTED PRIVATE KEY-----")){let s=Z(r.replace("-----BEGIN ENCRYPTED PRIVATE KEY-----","").replace("-----END ENCRYPTED PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:o}=gr(s),{iv:i,salt:a,iterations:c,keySize:l,cipherText:f}=Nh(o),u=await Uo(or,t,a,{c,dkLen:l}),h=await e.subtle.importKey("raw",u,"AES-CBC",!1,["decrypt"]),m=$r(await e.subtle.decrypt({name:"AES-CBC",iv:i},h,f)),{result:g}=gr(m);n=gc(g)}else if(r.includes("-----BEGIN PRIVATE KEY-----")){let s=Z(r.replace("-----BEGIN PRIVATE KEY-----","").replace("-----END PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:o}=gr(s);n=gc(o)}else throw new U("Could not parse private key from PEM data","ERR_INVALID_PARAMETERS");return Ho(n)}function Nh(r){let t=r.valueBlock.value[0];if(t.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.13")throw new U("Only pkcs5PBES2 encrypted private keys are supported","ERR_INVALID_PARAMS");let n=t.valueBlock.value[1].valueBlock.value[0];if(n.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.12")throw new U("Only pkcs5PBKDF2 key derivation functions are supported","ERR_INVALID_PARAMS");let o=n.valueBlock.value[1],i=$r(o.valueBlock.value[0].getValue()),a=Fo,c=Vo;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 U("Could not derive key size and iterations from PEM file - please use @libp2p/rsa to re-import your key","ERR_INVALID_PARAMS");let l=t.valueBlock.value[1].valueBlock.value[1],f=l.valueBlock.value[0].toString();if(f!=="OBJECT IDENTIFIER : 1.2.840.113549.3.7"){if(f!=="OBJECT IDENTIFIER : 1.3.14.3.2.7"){if(f!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.2"){if(f!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.22"){if(f!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.42")throw new U("Only AES-CBC encryption schemes are supported","ERR_INVALID_PARAMS")}}}}let u=$r(l.valueBlock.value[1].getValue());return{cipherText:$r(r.valueBlock.value[1].getValue()),salt:i,iterations:a,keySize:c,iv:u}}function gc(r){return $r(r.valueBlock.value[2].getValue())}function $r(r){return new Uint8Array(r,0,r.byteLength)}async function mc(r){let t=await At.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),e=await wc(t);return{privateKey:e[0],publicKey:e[1]}}async function Mo(r){let e=[await At.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),await Th(r)],n=await wc({privateKey:e[0],publicKey:e[1]});return{privateKey:n[0],publicKey:n[1]}}async function yc(r,t){let e=await At.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await At.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function bc(r,t,e){let n=await At.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return At.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function wc(r){if(r.privateKey==null||r.publicKey==null)throw new U("Private and public key are required","ERR_INVALID_PARAMETERS");return Promise.all([At.get().subtle.exportKey("jwk",r.privateKey),At.get().subtle.exportKey("jwk",r.publicKey)])}async function Th(r){return At.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 as(r){if(r.kty!=="RSA")throw new U("invalid key type","ERR_INVALID_KEY_TYPE");if(r.n==null)throw new U("invalid key modulus","ERR_INVALID_KEY_MODULUS");return Z(r.n,"base64url").length*8}var Gr=8192,qr=class{_key;constructor(t){this._key=t}verify(t,e){return bc(this._key,e,t)}marshal(){return Te.jwkToPkix(this._key)}get bytes(){return Se.encode({Type:gt.RSA,Data:this.marshal()}).subarray()}equals(t){return bt(this.bytes,t.bytes)}hash(){let t=pt.digest(this.bytes);return Tt(t)?t.then(({bytes:e})=>e):t.bytes}},mr=class{_key;_publicKey;constructor(t,e){this._key=t,this._publicKey=e}genSecret(){return Ke(16)}sign(t){return yc(this._key,t)}get public(){if(this._publicKey==null)throw new U("public key not provided","ERR_PUBKEY_NOT_PROVIDED");return new qr(this._publicKey)}marshal(){return Te.jwkToPkcs1(this._key)}get bytes(){return ke.encode({Type:gt.RSA,Data:this.marshal()}).subarray()}equals(t){return bt(this.bytes,t.bytes)}hash(){let t=pt.digest(this.bytes);return Tt(t)?t.then(({bytes:e})=>e):t.bytes}async id(){let t=await this.public.hash();return z(t,"base58btc")}async export(t,e="pkcs-8"){if(e==="pkcs-8")return Te.exportToPem(this,t);if(e==="libp2p-key")return cr(this.bytes,t);throw new U(`export format '${e}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};async function Ho(r){let t=Te.pkcs1ToJwk(r);if(as(t)>Gr)throw new U("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await Mo(t);return new mr(e.privateKey,e.publicKey)}function _h(r){let t=Te.pkixToJwk(r);if(as(t)>Gr)throw new U("key size is too large","ERR_KEY_SIZE_TOO_LARGE");return new qr(t)}async function Uh(r){if(as(r)>Gr)throw new U("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await Mo(r);return new mr(t.privateKey,t.publicKey)}async function Ch(r){if(r>Gr)throw new U("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await mc(r);return new mr(t.privateKey,t.publicKey)}var jo={};lt(jo,{Secp256k1PrivateKey:()=>jr,Secp256k1PublicKey:()=>zr,generateKeyPair:()=>Yh,unmarshalSecp256k1PrivateKey:()=>jh,unmarshalSecp256k1PublicKey:()=>Wh});var Dh=(r,t,e)=>r&t^~r&e,Ph=(r,t,e)=>r&t^r&e^t&e,Oh=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]),Le=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),_e=new Uint32Array(64),$o=class extends sr{constructor(){super(64,32,8,!1),this.A=Le[0]|0,this.B=Le[1]|0,this.C=Le[2]|0,this.D=Le[3]|0,this.E=Le[4]|0,this.F=Le[5]|0,this.G=Le[6]|0,this.H=Le[7]|0}get(){let{A:t,B:e,C:n,D:s,E:o,F:i,G:a,H:c}=this;return[t,e,n,s,o,i,a,c]}set(t,e,n,s,o,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let u=0;u<16;u++,e+=4)_e[u]=t.getUint32(e,!1);for(let u=16;u<64;u++){let h=_e[u-15],m=_e[u-2],g=Ct(h,7)^Ct(h,18)^h>>>3,d=Ct(m,17)^Ct(m,19)^m>>>10;_e[u]=d+_e[u-7]+g+_e[u-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:l,H:f}=this;for(let u=0;u<64;u++){let h=Ct(a,6)^Ct(a,11)^Ct(a,25),m=f+h+Dh(a,c,l)+Oh[u]+_e[u]|0,d=(Ct(n,2)^Ct(n,13)^Ct(n,22))+Ph(n,s,o)|0;f=l,l=c,c=a,a=i+m|0,i=o,o=s,s=n,n=m+d|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,l=l+this.G|0,f=f+this.H|0,this.set(n,s,o,i,a,c,l,f)}roundClean(){_e.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var xc=nn(()=>new $o);function Vh(r){let t=Tr(r);Kt(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:s}=t;if(e){if(!n.eql(s,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:Fh,hexToBytes:Hh}=an,qe={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(r){let{Err:t}=qe;if(r.length<2||r[0]!==2)throw new t("Invalid signature integer tag");let e=r[1],n=r.subarray(2,e+2);if(!e||n.length!==e)throw new t("Invalid signature integer: wrong length");if(n[0]&128)throw new t("Invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new t("Invalid signature integer: unnecessary leading zero");return{d:Fh(n),l:r.subarray(e+2)}},toSig(r){let{Err:t}=qe,e=typeof r=="string"?Hh(r):r;if(!Dt(e))throw new Error("ui8a expected");let n=e.length;if(n<2||e[0]!=48)throw new t("Invalid signature tag");if(e[1]!==n-2)throw new t("Invalid signature: incorrect length");let{d:s,l:o}=qe._parseInt(e.subarray(2)),{d:i,l:a}=qe._parseInt(o);if(a.length)throw new t("Invalid signature: left bytes after parsing");return{r:s,s:i}},hexFromSig(r){let t=l=>Number.parseInt(l[0],16)&8?"00"+l:l,e=l=>{let f=l.toString(16);return f.length&1?`0${f}`:f},n=t(e(r.s)),s=t(e(r.r)),o=n.length/2,i=s.length/2,a=e(o),c=e(i);return`30${e(i+o+4)}02${c}${s}02${a}${n}`}},he=BigInt(0),_t=BigInt(1),wm=BigInt(2),vc=BigInt(3),xm=BigInt(4);function Mh(r){let t=Vh(r),{Fp:e}=t,n=t.toBytes||((g,d,p)=>{let y=d.toAffine();return Qt(Uint8Array.from([4]),e.toBytes(y.x),e.toBytes(y.y))}),s=t.fromBytes||(g=>{let d=g.subarray(1),p=e.fromBytes(d.subarray(0,e.BYTES)),y=e.fromBytes(d.subarray(e.BYTES,2*e.BYTES));return{x:p,y}});function o(g){let{a:d,b:p}=t,y=e.sqr(g),v=e.mul(y,g);return e.add(e.add(v,e.mul(g,d)),p)}if(!e.eql(e.sqr(t.Gy),o(t.Gx)))throw new Error("bad generator point: equation left != right");function i(g){return typeof g=="bigint"&&he<g&&g<t.n}function a(g){if(!i(g))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(g){let{allowedPrivateKeyLengths:d,nByteLength:p,wrapPrivateKey:y,n:v}=t;if(d&&typeof g!="bigint"){if(Dt(g)&&(g=Jt(g)),typeof g!="string"||!d.includes(g.length))throw new Error("Invalid key");g=g.padStart(p*2,"0")}let w;try{w=typeof g=="bigint"?g:Xt(et("private key",g,p))}catch{throw new Error(`private key must be ${p} bytes, hex or bigint, not ${typeof g}`)}return y&&(w=Y(w,v)),a(w),w}let l=new Map;function f(g){if(!(g instanceof u))throw new Error("ProjectivePoint expected")}class u{constructor(d,p,y){if(this.px=d,this.py=p,this.pz=y,d==null||!e.isValid(d))throw new Error("x required");if(p==null||!e.isValid(p))throw new Error("y required");if(y==null||!e.isValid(y))throw new Error("z required")}static fromAffine(d){let{x:p,y}=d||{};if(!d||!e.isValid(p)||!e.isValid(y))throw new Error("invalid affine point");if(d instanceof u)throw new Error("projective point not allowed");let v=w=>e.eql(w,e.ZERO);return v(p)&&v(y)?u.ZERO:new u(p,y,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){let p=e.invertBatch(d.map(y=>y.pz));return d.map((y,v)=>y.toAffine(p[v])).map(u.fromAffine)}static fromHex(d){let p=u.fromAffine(s(et("pointHex",d)));return p.assertValidity(),p}static fromPrivateKey(d){return u.BASE.multiply(c(d))}_setWindowSize(d){this._WINDOW_SIZE=d,l.delete(this)}assertValidity(){if(this.is0()){if(t.allowInfinityPoint&&!e.is0(this.py))return;throw new Error("bad point: ZERO")}let{x:d,y:p}=this.toAffine();if(!e.isValid(d)||!e.isValid(p))throw new Error("bad point: x or y not FE");let y=e.sqr(p),v=o(d);if(!e.eql(y,v))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:d}=this.toAffine();if(e.isOdd)return!e.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){f(d);let{px:p,py:y,pz:v}=this,{px:w,py:T,pz:x}=d,A=e.eql(e.mul(p,x),e.mul(w,v)),R=e.eql(e.mul(y,x),e.mul(T,v));return A&&R}negate(){return new u(this.px,e.neg(this.py),this.pz)}double(){let{a:d,b:p}=t,y=e.mul(p,vc),{px:v,py:w,pz:T}=this,x=e.ZERO,A=e.ZERO,R=e.ZERO,N=e.mul(v,v),q=e.mul(w,w),K=e.mul(T,T),P=e.mul(v,w);return P=e.add(P,P),R=e.mul(v,T),R=e.add(R,R),x=e.mul(d,R),A=e.mul(y,K),A=e.add(x,A),x=e.sub(q,A),A=e.add(q,A),A=e.mul(x,A),x=e.mul(P,x),R=e.mul(y,R),K=e.mul(d,K),P=e.sub(N,K),P=e.mul(d,P),P=e.add(P,R),R=e.add(N,N),N=e.add(R,N),N=e.add(N,K),N=e.mul(N,P),A=e.add(A,N),K=e.mul(w,T),K=e.add(K,K),N=e.mul(K,P),x=e.sub(x,N),R=e.mul(K,q),R=e.add(R,R),R=e.add(R,R),new u(x,A,R)}add(d){f(d);let{px:p,py:y,pz:v}=this,{px:w,py:T,pz:x}=d,A=e.ZERO,R=e.ZERO,N=e.ZERO,q=t.a,K=e.mul(t.b,vc),P=e.mul(p,w),nt=e.mul(y,T),rt=e.mul(v,x),Nt=e.add(p,y),E=e.add(w,T);Nt=e.mul(Nt,E),E=e.add(P,nt),Nt=e.sub(Nt,E),E=e.add(p,v);let I=e.add(w,x);return E=e.mul(E,I),I=e.add(P,rt),E=e.sub(E,I),I=e.add(y,v),A=e.add(T,x),I=e.mul(I,A),A=e.add(nt,rt),I=e.sub(I,A),N=e.mul(q,E),A=e.mul(K,rt),N=e.add(A,N),A=e.sub(nt,N),N=e.add(nt,N),R=e.mul(A,N),nt=e.add(P,P),nt=e.add(nt,P),rt=e.mul(q,rt),E=e.mul(K,E),nt=e.add(nt,rt),rt=e.sub(P,rt),rt=e.mul(q,rt),E=e.add(E,rt),P=e.mul(nt,E),R=e.add(R,P),P=e.mul(I,E),A=e.mul(Nt,A),A=e.sub(A,P),P=e.mul(Nt,nt),N=e.mul(I,N),N=e.add(N,P),new u(A,R,N)}subtract(d){return this.add(d.negate())}is0(){return this.equals(u.ZERO)}wNAF(d){return m.wNAFCached(this,l,d,p=>{let y=e.invertBatch(p.map(v=>v.pz));return p.map((v,w)=>v.toAffine(y[w])).map(u.fromAffine)})}multiplyUnsafe(d){let p=u.ZERO;if(d===he)return p;if(a(d),d===_t)return this;let{endo:y}=t;if(!y)return m.unsafeLadder(this,d);let{k1neg:v,k1:w,k2neg:T,k2:x}=y.splitScalar(d),A=p,R=p,N=this;for(;w>he||x>he;)w&_t&&(A=A.add(N)),x&_t&&(R=R.add(N)),N=N.double(),w>>=_t,x>>=_t;return v&&(A=A.negate()),T&&(R=R.negate()),R=new u(e.mul(R.px,y.beta),R.py,R.pz),A.add(R)}multiply(d){a(d);let p=d,y,v,{endo:w}=t;if(w){let{k1neg:T,k1:x,k2neg:A,k2:R}=w.splitScalar(p),{p:N,f:q}=this.wNAF(x),{p:K,f:P}=this.wNAF(R);N=m.constTimeNegate(T,N),K=m.constTimeNegate(A,K),K=new u(e.mul(K.px,w.beta),K.py,K.pz),y=N.add(K),v=q.add(P)}else{let{p:T,f:x}=this.wNAF(p);y=T,v=x}return u.normalizeZ([y,v])[0]}multiplyAndAddUnsafe(d,p,y){let v=u.BASE,w=(x,A)=>A===he||A===_t||!x.equals(v)?x.multiplyUnsafe(A):x.multiply(A),T=w(this,p).add(w(d,y));return T.is0()?void 0:T}toAffine(d){let{px:p,py:y,pz:v}=this,w=this.is0();d==null&&(d=w?e.ONE:e.inv(v));let T=e.mul(p,d),x=e.mul(y,d),A=e.mul(v,d);if(w)return{x:e.ZERO,y:e.ZERO};if(!e.eql(A,e.ONE))throw new Error("invZ was invalid");return{x:T,y:x}}isTorsionFree(){let{h:d,isTorsionFree:p}=t;if(d===_t)return!0;if(p)return p(u,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:d,clearCofactor:p}=t;return d===_t?this:p?p(u,this):this.multiplyUnsafe(t.h)}toRawBytes(d=!0){return this.assertValidity(),n(u,this,d)}toHex(d=!0){return Jt(this.toRawBytes(d))}}u.BASE=new u(t.Gx,t.Gy,e.ONE),u.ZERO=new u(e.ZERO,e.ONE,e.ZERO);let h=t.nBitLength,m=un(u,t.endo?Math.ceil(h/2):h);return{CURVE:t,ProjectivePoint:u,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:i}}function Kh(r){let t=Tr(r);return Kt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Ec(r){let t=Kh(r),{Fp:e,n}=t,s=e.BYTES+1,o=2*e.BYTES+1;function i(E){return he<E&&E<e.ORDER}function a(E){return Y(E,n)}function c(E){return cn(E,n)}let{ProjectivePoint:l,normPrivateKeyToScalar:f,weierstrassEquation:u,isWithinCurveOrder:h}=Mh({...t,toBytes(E,I,O){let B=I.toAffine(),b=e.toBytes(B.x),k=Qt;return O?k(Uint8Array.from([I.hasEvenY()?2:3]),b):k(Uint8Array.from([4]),b,e.toBytes(B.y))},fromBytes(E){let I=E.length,O=E[0],B=E.subarray(1);if(I===s&&(O===2||O===3)){let b=Xt(B);if(!i(b))throw new Error("Point is not on curve");let k=u(b),L=e.sqrt(k),_=(L&_t)===_t;return(O&1)===1!==_&&(L=e.neg(L)),{x:b,y:L}}else if(I===o&&O===4){let b=e.fromBytes(B.subarray(0,e.BYTES)),k=e.fromBytes(B.subarray(e.BYTES,2*e.BYTES));return{x:b,y:k}}else throw new Error(`Point of length ${I} was invalid. Expected ${s} compressed bytes or ${o} uncompressed bytes`)}}),m=E=>Jt(Ee(E,t.nByteLength));function g(E){let I=n>>_t;return E>I}function d(E){return g(E)?a(-E):E}let p=(E,I,O)=>Xt(E.slice(I,O));class y{constructor(I,O,B){this.r=I,this.s=O,this.recovery=B,this.assertValidity()}static fromCompact(I){let O=t.nByteLength;return I=et("compactSignature",I,O*2),new y(p(I,0,O),p(I,O,2*O))}static fromDER(I){let{r:O,s:B}=qe.toSig(et("DER",I));return new y(O,B)}assertValidity(){if(!h(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!h(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:O,s:B,recovery:b}=this,k=R(et("msgHash",I));if(b==null||![0,1,2,3].includes(b))throw new Error("recovery id invalid");let L=b===2||b===3?O+t.n:O;if(L>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let _=b&1?"03":"02",V=l.fromHex(_+m(L)),F=c(L),j=a(-k*F),M=a(B*F),$=l.BASE.multiplyAndAddUnsafe(V,j,M);if(!$)throw new Error("point at infinify");return $.assertValidity(),$}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new y(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return Pe(this.toDERHex())}toDERHex(){return qe.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Pe(this.toCompactHex())}toCompactHex(){return m(this.r)+m(this.s)}}let v={isValidPrivateKey(E){try{return f(E),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let E=io(t.n);return ca(t.randomBytes(E),t.n)},precompute(E=8,I=l.BASE){return I._setWindowSize(E),I.multiply(BigInt(3)),I}};function w(E,I=!0){return l.fromPrivateKey(E).toRawBytes(I)}function T(E){let I=Dt(E),O=typeof E=="string",B=(I||O)&&E.length;return I?B===s||B===o:O?B===2*s||B===2*o:E instanceof l}function x(E,I,O=!0){if(T(E))throw new Error("first arg must be private key");if(!T(I))throw new Error("second arg must be public key");return l.fromHex(I).multiply(f(E)).toRawBytes(O)}let A=t.bits2int||function(E){let I=Xt(E),O=E.length*8-t.nBitLength;return O>0?I>>BigInt(O):I},R=t.bits2int_modN||function(E){return a(A(E))},N=Nr(t.nBitLength);function q(E){if(typeof E!="bigint")throw new Error("bigint expected");if(!(he<=E&&E<N))throw new Error(`bigint expected < 2^${t.nBitLength}`);return Ee(E,t.nByteLength)}function K(E,I,O=P){if(["recovered","canonical"].some(Q=>Q in O))throw new Error("sign() legacy options not supported");let{hash:B,randomBytes:b}=t,{lowS:k,prehash:L,extraEntropy:_}=O;k==null&&(k=!0),E=et("msgHash",E),L&&(E=et("prehashed msgHash",B(E)));let V=R(E),F=f(I),j=[q(F),q(V)];if(_!=null){let Q=_===!0?b(e.BYTES):_;j.push(et("extraEntropy",Q))}let M=Qt(...j),$=V;function st(Q){let ht=A(Q);if(!h(ht))return;let dt=c(ht),it=l.BASE.multiply(ht).toAffine(),yt=a(it.x);if(yt===he)return;let zt=a(dt*a($+yt*F));if(zt===he)return;let Ue=(it.x===yt?0:2)|Number(it.y&_t),Ar=zt;return k&&g(zt)&&(Ar=d(zt),Ue^=1),new y(yt,Ar,Ue)}return{seed:M,k2sig:st}}let P={lowS:t.lowS,prehash:!1},nt={lowS:t.lowS,prehash:!1};function rt(E,I,O=P){let{seed:B,k2sig:b}=K(E,I,O),k=t;return ro(k.hash.outputLen,k.nByteLength,k.hmac)(B,b)}l.BASE._setWindowSize(8);function Nt(E,I,O,B=nt){let b=E;if(I=et("msgHash",I),O=et("publicKey",O),"strict"in B)throw new Error("options.strict was renamed to lowS");let{lowS:k,prehash:L}=B,_,V;try{if(typeof b=="string"||Dt(b))try{_=y.fromDER(b)}catch(it){if(!(it instanceof qe.Err))throw it;_=y.fromCompact(b)}else if(typeof b=="object"&&typeof b.r=="bigint"&&typeof b.s=="bigint"){let{r:it,s:yt}=b;_=new y(it,yt)}else throw new Error("PARSE");V=l.fromHex(O)}catch(it){if(it.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(k&&_.hasHighS())return!1;L&&(I=t.hash(I));let{r:F,s:j}=_,M=R(I),$=c(j),st=a(M*$),Q=a(F*$),ht=l.BASE.multiplyAndAddUnsafe(V,st,Q)?.toAffine();return ht?a(ht.x)===F:!1}return{CURVE:t,getPublicKey:w,getSharedSecret:x,sign:rt,verify:Nt,ProjectivePoint:l,Signature:y,utils:v}}function $h(r){return{hash:r,hmac:(t,...e)=>Cr(r,t,rn(...e)),randomBytes:nr}}function Bc(r,t){let e=n=>Ec({...r,...$h(n)});return Object.freeze({...e(t),create:e})}var kc=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Ac=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),qh=BigInt(1),qo=BigInt(2),Sc=(r,t)=>(r+t/qo)/t;function Gh(r){let t=kc,e=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),l=r*r*r%t,f=l*l*r%t,u=X(f,e,t)*f%t,h=X(u,e,t)*f%t,m=X(h,qo,t)*l%t,g=X(m,s,t)*m%t,d=X(g,o,t)*g%t,p=X(d,a,t)*d%t,y=X(p,c,t)*p%t,v=X(y,a,t)*d%t,w=X(v,e,t)*f%t,T=X(w,i,t)*g%t,x=X(T,n,t)*l%t,A=X(x,qo,t);if(!Go.eql(Go.sqr(A),r))throw new Error("Cannot find square root");return A}var Go=ln(kc,void 0,void 0,{sqrt:Gh}),Ht=Bc({a:BigInt(0),b:BigInt(7),Fp:Go,n:Ac,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Ac,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-qh*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=e,i=BigInt("0x100000000000000000000000000000000"),a=Sc(o*r,t),c=Sc(-n*r,t),l=Y(r-a*e-c*s,t),f=Y(-a*n-c*o,t),u=l>i,h=f>i;if(u&&(l=t-l),h&&(f=t-f),l>i||f>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:u,k1:l,k2neg:h,k2:f}}}},xc),Nm=BigInt(0);var Tm=Ht.ProjectivePoint;function Ic(){return Ht.utils.randomPrivateKey()}function Rc(r,t){let e=pt.digest(t instanceof Uint8Array?t:t.subarray());if(Tt(e))return e.then(({digest:n})=>Ht.sign(n,r).toDERRawBytes()).catch(n=>{throw new U(String(n),"ERR_INVALID_INPUT")});try{return Ht.sign(e.digest,r).toDERRawBytes()}catch(n){throw new U(String(n),"ERR_INVALID_INPUT")}}function Nc(r,t,e){let n=pt.digest(e instanceof Uint8Array?e:e.subarray());if(Tt(n))return n.then(({digest:s})=>Ht.verify(t,s,r)).catch(s=>{throw new U(String(s),"ERR_INVALID_INPUT")});try{return Ht.verify(t,n.digest,r)}catch(s){throw new U(String(s),"ERR_INVALID_INPUT")}}function Tc(r){return Ht.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Lc(r){try{Ht.getPublicKey(r,!0)}catch(t){throw new U(String(t),"ERR_INVALID_PRIVATE_KEY")}}function zo(r){try{Ht.ProjectivePoint.fromHex(r)}catch(t){throw new U(String(t),"ERR_INVALID_PUBLIC_KEY")}}function _c(r){try{return Ht.getPublicKey(r,!0)}catch(t){throw new U(String(t),"ERR_INVALID_PRIVATE_KEY")}}var zr=class{_key;constructor(t){zo(t),this._key=t}verify(t,e){return Nc(this._key,e,t)}marshal(){return Tc(this._key)}get bytes(){return Se.encode({Type:gt.Secp256k1,Data:this.marshal()}).subarray()}equals(t){return bt(this.bytes,t.bytes)}async hash(){let t=pt.digest(this.bytes),e;return Tt(t)?{bytes:e}=await t:e=t.bytes,e}},jr=class{_key;_publicKey;constructor(t,e){this._key=t,this._publicKey=e??_c(t),Lc(this._key),zo(this._publicKey)}sign(t){return Rc(this._key,t)}get public(){return new zr(this._publicKey)}marshal(){return this._key}get bytes(){return ke.encode({Type:gt.Secp256k1,Data:this.marshal()}).subarray()}equals(t){return bt(this.bytes,t.bytes)}hash(){let t=pt.digest(this.bytes);return Tt(t)?t.then(({bytes:e})=>e):t.bytes}async id(){let t=await this.public.hash();return z(t,"base58btc")}async export(t,e="libp2p-key"){if(e==="libp2p-key")return cr(this.bytes,t);throw new U(`export format '${e}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function jh(r){return new jr(r)}function Wh(r){return new zr(r)}async function Yh(){let r=Ic();return new jr(r)}var Uc={rsa:Ko,ed25519:_o,secp256k1:jo};function Zh(r){let t=Object.keys(Uc).join(" / ");return new U(`invalid or unsupported key type ${r}. Must be ${t}`,"ERR_UNSUPPORTED_KEY_TYPE")}function Wo(r){if(r=r.toLowerCase(),r==="rsa"||r==="ed25519"||r==="secp256k1")return Uc[r];throw Zh(r)}async function Cc(r,t){return Wo(r).generateKeyPair(t??2048)}function Dc(r,t){return t=(t??"rsa").toLowerCase(),Wo(t),r.bytes}function Pc(r,t){return t=(t??"rsa").toLowerCase(),Wo(t),r.bytes}var Oc=async()=>{let r=await Cc("Ed25519"),t=await Jh(r);if(t.type==="Ed25519")return t;throw new Error(`Generated unexpected PeerId type "${t.type}"`)};async function Jh(r){return Gi(Dc(r.public),Pc(r))}var cs=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}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(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,s){return this.readAtomically(()=>{let o=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",l=2**(8*s)-1;for(;;){let f=this.readAtomically(()=>{let u=this.readChar();if(u===void 0)return;let h=Number.parseInt(u,t);if(!Number.isNaN(h))return h});if(f===void 0)break;if(o*=t,o+=f,o>l||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&c&&i>1?void 0:o})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let s=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[s]=i[0],e[s+1]=i[1],e[s+2]=i[2],e[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];e[s]=o>>8,e[s+1]=o&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,s]=t(e);if(n===16)return e;if(s||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let o=new Uint8Array(14),i=16-(n+2),[a]=t(o.subarray(0,i));return e.set(o.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Vc=45,Xh=15,yr=new cs;function Yo(r){if(!(r.length>Xh))return yr.new(r).parseWith(()=>yr.readIPv4Addr())}function Zo(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Vc))return yr.new(r).parseWith(()=>yr.readIPv6Addr())}function ls(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Vc))return yr.new(r).parseWith(()=>yr.readIPAddr())}function us(r){return!!Yo(r)}function fs(r){return!!Zo(r)}function hs(r){return!!ls(r)}var Hc=Bs(Fc(),1),Qh=["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.0.0/29","192.0.0.8/32","192.0.0.9/32","192.0.0.10/32","192.0.0.170/32","192.0.0.171/32","192.0.2.0/24","192.31.196.0/24","192.52.193.0/24","192.88.99.0/24","192.168.0.0/16","192.175.48.0/24","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","240.0.0.0/4","255.255.255.255/32"],td=Qh.map(r=>new Hc.Netmask(r));function ed(r){for(let t of td)if(t.contains(r))return!0;return!1}function rd(r){return/^::$/.test(r)||/^::1$/.test(r)||/^::f{4}:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^::f{4}:0.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(r)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(r)||/^ff([0-9a-fA-F]{2,2}):/i.test(r)}function Jo(r){return us(r)?ed(r):fs(r)?rd(r):void 0}var uy=parseInt("0xFFFF",16),fy=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var $c=us,ad=fs,Xo=function(r){let t=0;if(r=r.toString().trim(),$c(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(ad(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let o=$c(e[n]),i;o&&(i=Xo(e[n]),e[n]=z(i.slice(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,z(i.slice(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let o=[n,1];for(n=9-e.length;n>0;n--)o.push("0");e.splice.apply(e,o)}let s=new Uint8Array(t+16);for(n=0;n<e.length;n++){let o=parseInt(e[n],16);s[t++]=o>>8&255,s[t++]=o&255}return s}throw new Error("invalid ip address")},qc=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let s=[];for(let o=0;o<e;o++)s.push(r[t+o]);return s.join(".")}if(e===16){let s=[];for(let o=0;o<e;o+=2)s.push(n.getUint16(t+o).toString(16));return s.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var br={},Qo={},ld=[[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"]];ld.forEach(r=>{let t=ud(...r);Qo[t.code]=t,br[t.name]=t});function ud(r,t,e,n,s){return{code:r,size:t,name:e,resolvable:!!n,path:!!s}}function W(r){if(typeof r=="number"){if(Qo[r]!=null)return Qo[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(br[r]!=null)return br[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var zy=W("ip4"),jy=W("ip6"),Wy=W("ipcidr");function ei(r,t){switch(W(r).code){case 4:case 41:return hd(t);case 42:return jc(t);case 6:case 273:case 33:case 132:return Yc(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return jc(t);case 421:return md(t);case 444:return Wc(t);case 445:return Wc(t);case 466:return gd(t);default:return z(t,"base16")}}function ri(r,t){switch(W(r).code){case 4:return Gc(t);case 41:return Gc(t);case 42:return zc(t);case 6:case 273:case 33:case 132:return ni(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return zc(t);case 421:return dd(t);case 444:return yd(t);case 445:return bd(t);case 466:return pd(t);default:return Z(t,"base16")}}var ti=Object.values(me).map(r=>r.decoder),fd=function(){let r=ti[0].or(ti[1]);return ti.slice(2).forEach(t=>r=r.or(t)),r}();function Gc(r){if(!hs(r))throw new Error("invalid ip address");return Xo(r)}function hd(r){let t=qc(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!hs(t))throw new Error("invalid ip address");return t}function ni(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Yc(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function zc(r){let t=Z(r),e=Uint8Array.from(Be(t.length));return Bt([e,t],e.length+t.length)}function jc(r){let t=re(r);if(r=r.slice(ut(t)),r.length!==t)throw new Error("inconsistent lengths");return z(r)}function dd(r){let t;r[0]==="Q"||r[0]==="1"?t=Ce(at.decode(`z${r}`)).bytes:t=Ut.parse(r).multihash.bytes;let e=Uint8Array.from(Be(t.length));return Bt([e,t],e.length+t.length)}function pd(r){let t=fd.decode(r),e=Uint8Array.from(Be(t.length));return Bt([e,t],e.length+t.length)}function gd(r){let t=re(r),e=r.slice(ut(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+z(e,"base64url")}function md(r){let t=re(r),e=r.slice(ut(t));if(e.length!==t)throw new Error("inconsistent lengths");return z(e,"base58btc")}function yd(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=Wt.decode("b"+t[0]),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let s=ni(n);return Bt([e,s],e.length+s.length)}function bd(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=Wt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let s=ni(n);return Bt([e,s],e.length+s.length)}function Wc(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=z(t,"base32"),s=Yc(e);return`${n}:${s}`}function Zc(r){r=si(r);let t=[],e=[],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=W(i);if(a.size===0){t.push([a.code]),e.push([a.code]);continue}if(o++,o>=s.length)throw Xc("invalid address: "+r);if(a.path===!0){n=si(s.slice(o).join("/")),t.push([a.code,ri(a.code,n)]),e.push([a.code,n]);break}let c=ri(a.code,s[o]);t.push([a.code,c]),e.push([a.code,ei(a.code,c)])}return{string:Jc(e),bytes:ii(t),tuples:t,stringTuples:e,path:n}}function oi(r){let t=[],e=[],n=null,s=0;for(;s<r.length;){let o=re(r,s),i=ut(o),a=W(o),c=wd(a,r.slice(s+i));if(c===0){t.push([o]),e.push([o]),s+=i;continue}let l=r.slice(s+i,s+i+c);if(s+=c+i,s>r.length)throw Xc("Invalid address Uint8Array: "+z(r,"base16"));t.push([o,l]);let f=ei(o,l);if(e.push([o,f]),a.path===!0){n=f;break}}return{bytes:Uint8Array.from(r),string:Jc(e),tuples:t,stringTuples:e,path:n}}function Jc(r){let t=[];return r.map(e=>{let n=W(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),si(t.join("/"))}function ii(r){return Bt(r.map(t=>{let e=W(t[0]),n=Uint8Array.from(Be(e.code));return t.length>1&&t[1]!=null&&(n=Bt([n,t[1]])),n}))}function wd(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=re(t instanceof Uint8Array?t:Uint8Array.from(t));return e+ut(e)}}function si(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}function Xc(r){return new Error("Error parsing address: "+r)}var xd=Symbol.for("nodejs.util.inspect.custom"),ai=Symbol.for("@multiformats/js-multiaddr/multiaddr"),vd=[W("dns").code,W("dns4").code,W("dns6").code,W("dnsaddr").code],ds=class r{bytes;#e;#t;#r;#n;[ai]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=oi(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Zc(t)}else if(tl(t))e=oi(t.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=e.bytes,this.#e=e.string,this.#t=e.tuples,this.#r=e.stringTuples,this.#n=e.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let t,e,n,s,o="",i=W("tcp"),a=W("udp"),c=W("ip4"),l=W("ip6"),f=W("dns6"),u=W("ip6zone");for(let[m,g]of this.stringTuples())m===u.code&&(o=`%${g??""}`),vd.includes(m)&&(e=i.name,s=443,n=`${g??""}${o}`,t=m===f.code?6:4),(m===i.code||m===a.code)&&(e=W(m).name,s=parseInt(g??"")),(m===c.code||m===l.code)&&(e=W(m).name,n=`${g??""}${o}`,t=m===l.code?6:4);if(t==null||e==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:t,host:n,transport:e,port:s}}protos(){return this.#t.map(([t])=>Object.assign({},W(t)))}protoCodes(){return this.#t.map(([t])=>t)}protoNames(){return this.#t.map(([t])=>W(t).name)}tuples(){return this.#t}stringTuples(){return this.#r}encapsulate(t){return t=new r(t),new r(this.toString()+t.toString())}decapsulate(t){let e=t.toString(),n=this.toString(),s=n.lastIndexOf(e);if(s<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,s))}decapsulateCode(t){let e=this.tuples();for(let n=e.length-1;n>=0;n--)if(e[n][0]===t)return new r(ii(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,s])=>{n===br.p2p.code&&t.push([n,s]),n===br["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?z(at.decode(`z${n}`),"base58btc"):z(Ut.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return bt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(o=>o.resolvable);if(e==null)return[this];let n=Qc.get(e.name);if(n==null)throw new U(`no available resolver for ${e.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,t)).map(o=>wr(o))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[xd](){return`Multiaddr(${this.#e})`}};var Qc=new Map;function tl(r){return!!r?.[ai]}function wr(r){return new ds(r)}function Ed(r){return r[Symbol.asyncIterator]!=null}function Bd(r){if(Ed(r))return(async()=>{for await(let t of r)return t})();for(let t of r)return t}var ci=Bd;var rl=Symbol.for("@achingbrain/uint8arraylist");function el(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let s=e+n.byteLength;if(t<s)return{buf:n,index:t-e};e=s}throw new RangeError("index is out of bounds")}function ps(r){return!!r?.[rl]}var xr=class r{bufs;length;[rl]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(ps(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(ps(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=el(this.bufs,t);return e.buf[e.index]}set(t,e){let n=el(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(ps(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:s}=this._subList(t,e);return Bt(n,s)}subarray(t,e){let{bufs:n,length:s}=this._subList(t,e);return n.length===1?n[0]:Bt(n,s)}sublist(t,e){let{bufs:n,length:s}=this._subList(t,e),o=new r;return o.length=s,o.bufs=[...n],o}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],s=0;for(let o=0;o<this.bufs.length;o++){let i=this.bufs[o],a=s,c=a+i.byteLength;if(s=c,t>=c)continue;let l=t>=a&&t<c,f=e>a&&e<=c;if(l&&f){if(t===a&&e===c){n.push(i);break}let u=t-a;n.push(i.subarray(u,u+(e-t)));break}if(l){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!ps(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let o=256,i=new Int32Array(o);for(let u=0;u<o;u++)i[u]=-1;for(let u=0;u<s;u++)i[n[u]]=u;let a=i,c=this.byteLength-n.byteLength,l=n.byteLength-1,f;for(let u=e;u<=c;u+=f){f=0;for(let h=l;h>=0;h--){let m=this.get(u+h);if(n[h]!==m){f=Math.max(1,h-a[m]);break}}if(f===0)return u}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=wt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let s=Yt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,e,n),this.write(s,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let s=Yt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,e,n),this.write(s,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let s=Yt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,e,n),this.write(s,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=wt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let s=Yt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,e,n),this.write(s,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let s=Yt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,e,n),this.write(s,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let s=Yt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,e,n),this.write(s,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let s=Yt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,e,n),this.write(s,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let s=Yt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,e,n),this.write(s,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!bt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((s,o)=>s+o.byteLength,0)),n.length=e,n}};function gs(r){return r[Symbol.asyncIterator]!=null}var ms=r=>{let t=ut(r),e=wt(t);return Be(r,e),ms.bytes=t,e};ms.bytes=0;function Yr(r,t){t=t??{};let e=t.lengthEncoder??ms;function*n(s){let o=e(s.byteLength);o instanceof Uint8Array?yield o:yield*o,s instanceof Uint8Array?yield s:yield*s}return gs(r)?async function*(){for await(let s of r)yield*n(s)}():function*(){for(let s of r)yield*n(s)}()}Yr.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??ms;return new xr(e(r.byteLength),r)};var vr=Bs(ol(),1);var Sd=8,kd=1024*1024*4,Ge;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(Ge||(Ge={}));var li=r=>{let t=re(r);return li.bytes=ut(t),t};li.bytes=0;function Er(r,t){let e=new xr,n=Ge.LENGTH,s=-1,o=t?.lengthDecoder??li,i=t?.maxLengthLength??Sd,a=t?.maxDataLength??kd;function*c(){for(;e.byteLength>0;){if(n===Ge.LENGTH)try{if(s=o(e),s<0)throw(0,vr.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(s>a)throw(0,vr.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let l=o.bytes;e.consume(l),t?.onLength!=null&&t.onLength(s),n=Ge.DATA}catch(l){if(l instanceof RangeError){if(e.byteLength>i)throw(0,vr.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw l}if(n===Ge.DATA){if(e.byteLength<s)break;let l=e.sublist(0,s);e.consume(s),t?.onData!=null&&t.onData(l),yield l,n=Ge.LENGTH}}}return gs(r)?async function*(){for await(let l of r)e.append(l),yield*c();if(e.byteLength>0)throw(0,vr.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(let l of r)e.append(l),yield*c();if(e.byteLength>0)throw(0,vr.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}Er.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:o,value:i}=await r.next(e);if(o===!0)return;i!=null&&(yield i)}catch(o){if(o.code==="ERR_UNDER_READ")return{done:!0,value:null};throw o}finally{e=1}}();return Er(n,{...t??{},onLength:o=>{e=o}})};function Rd(r){let[t,e]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>t.next(),push:s=>{n.push(s)},next:()=>n.length>0?{done:!1,value:n.shift()}:t.next(),[e](){return this}}}var il=Rd;function Nd(r){return r[Symbol.asyncIterator]!=null}function Td(r,t){if(Nd(r))return async function*(){for await(let a of r)yield t(a)}();let e=il(r),{value:n,done:s}=e.next();if(s===!0)return function*(){}();let o=t(n);if(typeof o.then=="function")return async function*(){yield await o;for await(let a of e)yield t(a)}();let i=t;return function*(){yield o;for(let a of e)yield i(a)}()}var al=Td;function de(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var ys=globalThis.CustomEvent??Event;async function*ui(r,t={}){let e=t.concurrency??1/0;e<1&&(e=1/0);let n=t.ordered==null?!1:t.ordered,s=new EventTarget,o=[],i=de(),a=de(),c=!1,l,f=!1;s.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let g of r){if(o.length===e&&(i=de(),await i.promise),f)break;let d={done:!1};o.push(d),g().then(p=>{d.done=!0,d.ok=!0,d.value=p,s.dispatchEvent(new ys("task-complete"))},p=>{d.done=!0,d.err=p,s.dispatchEvent(new ys("task-complete"))})}c=!0,s.dispatchEvent(new ys("task-complete"))}catch(g){l=g,s.dispatchEvent(new ys("task-complete"))}});function u(){return n?o[0]?.done:!!o.find(g=>g.done)}function*h(){for(;o.length>0&&o[0].done;){let g=o[0];if(o.shift(),g.ok)yield g.value;else throw f=!0,i.resolve(),g.err;i.resolve()}}function*m(){for(;u();)for(let g=0;g<o.length;g++)if(o[g].done){let d=o[g];if(o.splice(g,1),g--,d.ok)yield d.value;else throw f=!0,i.resolve(),d.err;i.resolve()}}for(;;){if(u()||(a=de(),await a.promise),l!=null)throw l;if(n?yield*h():yield*m(),c&&o.length===0)break}}var bs=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||t-1&t)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},Br=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new bs(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new bs(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var fi=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function ws(r={}){return Ld(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function Ld(r,t){t=t??{};let e=t.onEnd,n=new Br,s,o,i,a=de(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((p,y)=>{o=v=>{o=null,n.push(v);try{p(r(n))}catch(w){y(w)}return s}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=de()})}},l=p=>o!=null?o(p):(n.push(p),s),f=p=>(n=new Br,o!=null?o({error:p}):(n.push({error:p}),s)),u=p=>{if(i)return s;if(t?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:p})},h=p=>i?s:(i=!0,p!=null?f(p):l({done:!0})),m=()=>(n=new Br,h(),{done:!0}),g=p=>(h(p),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:m,throw:g,push:u,end:h,get readableLength(){return n.size},onEmpty:async p=>{let y=p?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let v,w;y!=null&&(v=new Promise((T,x)=>{w=()=>{x(new fi)},y.addEventListener("abort",w)}));try{await Promise.race([a.promise,v])}finally{w!=null&&y!=null&&y?.removeEventListener("abort",w)}}},e==null)return s;let d=s;return s={[Symbol.asyncIterator](){return this},next(){return d.next()},throw(p){return d.throw(p),e!=null&&(e(p),e=void 0),{done:!0}},return(){return d.return(),e!=null&&(e(),e=void 0),{done:!0}},push:u,end(p){return d.end(p),e!=null&&(e(p),e=void 0),s},get readableLength(){return d.readableLength},onEmpty:p=>d.onEmpty(p)},s}function _d(r){return r[Symbol.asyncIterator]!=null}function Ud(...r){let t=[];for(let e of r)_d(e)||t.push(e);return t.length===r.length?function*(){for(let e of t)yield*e}():async function*(){let e=ws({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let s of n)e.push(s)})),e.end()}catch(n){e.end(n)}}),yield*e}()}var cl=Ud;function di(r,...t){if(r==null)throw new Error("Empty pipeline");if(hi(r)){let n=r;r=()=>n.source}else if(ul(r)||ll(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&hi(e[e.length-1])&&(e[e.length-1]=e[e.length-1].sink),e.length>2)for(let n=1;n<e.length-1;n++)hi(e[n])&&(e[n]=Dd(e[n]));return Cd(...e)}var Cd=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},ll=r=>r?.[Symbol.asyncIterator]!=null,ul=r=>r?.[Symbol.iterator]!=null,hi=r=>r==null?!1:r.sink!=null&&r.source!=null,Dd=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=ws({objectMode:!0});e.then(()=>{n.end()},i=>{n.end(i)});let s,o=r.source;if(ll(o))s=async function*(){yield*o,n.end()};else if(ul(o))s=function*(){yield*o,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return cl(n,s())}return r.source};var fl="libp2p",hl="autonat",dl="1.0.0";var D;(function(r){let t;(function(l){l.DIAL="DIAL",l.DIAL_RESPONSE="DIAL_RESPONSE"})(t=r.MessageType||(r.MessageType={}));let e;(function(l){l[l.DIAL=0]="DIAL",l[l.DIAL_RESPONSE=1]="DIAL_RESPONSE"})(e||(e={})),function(l){l.codec=()=>ur(e)}(t=r.MessageType||(r.MessageType={}));let n;(function(l){l.OK="OK",l.E_DIAL_ERROR="E_DIAL_ERROR",l.E_DIAL_REFUSED="E_DIAL_REFUSED",l.E_BAD_REQUEST="E_BAD_REQUEST",l.E_INTERNAL_ERROR="E_INTERNAL_ERROR"})(n=r.ResponseStatus||(r.ResponseStatus={}));let s;(function(l){l[l.OK=0]="OK",l[l.E_DIAL_ERROR=100]="E_DIAL_ERROR",l[l.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",l[l.E_BAD_REQUEST=200]="E_BAD_REQUEST",l[l.E_INTERNAL_ERROR=300]="E_INTERNAL_ERROR"})(s||(s={})),function(l){l.codec=()=>ur(s)}(n=r.ResponseStatus||(r.ResponseStatus={}));let o;(function(l){let f;l.codec=()=>(f==null&&(f=oe((u,h,m={})=>{if(m.lengthDelimited!==!1&&h.fork(),u.id!=null&&(h.uint32(10),h.bytes(u.id)),u.addrs!=null)for(let g of u.addrs)h.uint32(18),h.bytes(g);m.lengthDelimited!==!1&&h.ldelim()},(u,h)=>{let m={addrs:[]},g=h==null?u.len:u.pos+h;for(;u.pos<g;){let d=u.uint32();switch(d>>>3){case 1:m.id=u.bytes();break;case 2:m.addrs.push(u.bytes());break;default:u.skipType(d&7);break}}return m})),f),l.encode=u=>se(u,l.codec()),l.decode=u=>ne(u,l.codec())})(o=r.PeerInfo||(r.PeerInfo={}));let i;(function(l){let f;l.codec=()=>(f==null&&(f=oe((u,h,m={})=>{m.lengthDelimited!==!1&&h.fork(),u.peer!=null&&(h.uint32(10),r.PeerInfo.codec().encode(u.peer,h)),m.lengthDelimited!==!1&&h.ldelim()},(u,h)=>{let m={},g=h==null?u.len:u.pos+h;for(;u.pos<g;){let d=u.uint32();switch(d>>>3){case 1:m.peer=r.PeerInfo.codec().decode(u,u.uint32());break;default:u.skipType(d&7);break}}return m})),f),l.encode=u=>se(u,l.codec()),l.decode=u=>ne(u,l.codec())})(i=r.Dial||(r.Dial={}));let a;(function(l){let f;l.codec=()=>(f==null&&(f=oe((u,h,m={})=>{m.lengthDelimited!==!1&&h.fork(),u.status!=null&&(h.uint32(8),r.ResponseStatus.codec().encode(u.status,h)),u.statusText!=null&&(h.uint32(18),h.string(u.statusText)),u.addr!=null&&(h.uint32(26),h.bytes(u.addr)),m.lengthDelimited!==!1&&h.ldelim()},(u,h)=>{let m={},g=h==null?u.len:u.pos+h;for(;u.pos<g;){let d=u.uint32();switch(d>>>3){case 1:m.status=r.ResponseStatus.codec().decode(u);break;case 2:m.statusText=u.string();break;case 3:m.addr=u.bytes();break;default:u.skipType(d&7);break}}return m})),f),l.encode=u=>se(u,l.codec()),l.decode=u=>ne(u,l.codec())})(a=r.DialResponse||(r.DialResponse={}));let c;r.codec=()=>(c==null&&(c=oe((l,f,u={})=>{u.lengthDelimited!==!1&&f.fork(),l.type!=null&&(f.uint32(8),r.MessageType.codec().encode(l.type,f)),l.dial!=null&&(f.uint32(18),r.Dial.codec().encode(l.dial,f)),l.dialResponse!=null&&(f.uint32(26),r.DialResponse.codec().encode(l.dialResponse,f)),u.lengthDelimited!==!1&&f.ldelim()},(l,f)=>{let u={},h=f==null?l.len:l.pos+f;for(;l.pos<h;){let m=l.uint32();switch(m>>>3){case 1:u.type=r.MessageType.codec().decode(l);break;case 2:u.dial=r.Dial.codec().decode(l,l.uint32());break;case 3:u.dialResponse=r.DialResponse.codec().decode(l,l.uint32());break;default:l.skipType(m&7);break}}return u})),c),r.encode=l=>se(l,r.codec()),r.decode=l=>ne(l,r.codec())})(D||(D={}));var pi=4,xs=class{components;startupDelay;refreshInterval;protocol;timeout;maxInboundStreams;maxOutboundStreams;verifyAddressTimeout;started;log;constructor(t,e){this.components=t,this.log=t.logger.forComponent("libp2p:autonat"),this.started=!1,this.protocol=`/${e.protocolPrefix??fl}/${hl}/${dl}`,this.timeout=e.timeout??3e4,this.maxInboundStreams=e.maxInboundStreams??1,this.maxOutboundStreams=e.maxOutboundStreams??1,this.startupDelay=e.startupDelay??5e3,this.refreshInterval=e.refreshInterval??6e4,this._verifyExternalAddresses=this._verifyExternalAddresses.bind(this)}isStarted(){return this.started}async start(){this.started||(await this.components.registrar.handle(this.protocol,t=>{this.handleIncomingAutonatStream(t).catch(e=>{this.log.error("error handling incoming autonat stream",e)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.verifyAddressTimeout=setTimeout(this._verifyExternalAddresses,this.startupDelay),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.protocol),clearTimeout(this.verifyAddressTimeout),this.started=!1}async handleIncomingAutonatStream(t){let e=AbortSignal.timeout(this.timeout),n=()=>{t.stream.abort(new U("handleIncomingAutonatStream timeout",As))};e.addEventListener("abort",n,{once:!0}),Ss(1/0,e);let s=this.components.addressManager.getAddresses().map(o=>o.toOptions().host);try{let o=this;await di(t.stream,i=>Er(i),async function*(i){let a=await ci(i);if(a==null){o.log("no message received"),yield D.encode({type:D.MessageType.DIAL_RESPONSE,dialResponse:{status:D.ResponseStatus.E_BAD_REQUEST,statusText:"No message was sent"}});return}let c;try{c=D.decode(a)}catch(d){o.log.error("could not decode message",d),yield D.encode({type:D.MessageType.DIAL_RESPONSE,dialResponse:{status:D.ResponseStatus.E_BAD_REQUEST,statusText:"Could not decode message"}});return}let l=c.dial;if(l==null){o.log.error("dial was missing from message"),yield D.encode({type:D.MessageType.DIAL_RESPONSE,dialResponse:{status:D.ResponseStatus.E_BAD_REQUEST,statusText:"No Dial message found in message"}});return}let f,u=l.peer;if(u==null||u.id==null){o.log.error("PeerId missing from message"),yield D.encode({type:D.MessageType.DIAL_RESPONSE,dialResponse:{status:D.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}});return}try{f=Xr(u.id)}catch(d){o.log.error("invalid PeerId",d),yield D.encode({type:D.MessageType.DIAL_RESPONSE,dialResponse:{status:D.ResponseStatus.E_BAD_REQUEST,statusText:"bad peer id"}});return}if(o.log("incoming request from %p",f),!t.connection.remotePeer.equals(f)){o.log("target peer %p did not equal sending peer %p",f,t.connection.remotePeer),yield D.encode({type:D.MessageType.DIAL_RESPONSE,dialResponse:{status:D.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}});return}let h=u.addrs.map(d=>wr(d)).filter(d=>{let p=d.toOptions().host===t.connection.remoteAddr.toOptions().host;return o.log.trace("request to dial %a was sent from %a is same host %s",d,t.connection.remoteAddr,p),p}).filter(d=>{let p=d.toOptions().host,y=!(Jo(p)??!1);return o.log.trace("host %s was public %s",p,y),y}).filter(d=>{let p=d.toOptions().host,y=!s.includes(p);return o.log.trace("host %s was not our host %s",p,y),y}).filter(d=>{let p=!!o.components.transportManager.transportForMultiaddr(d);return o.log.trace("transport for %a is supported %s",d,p),p}).map(d=>(d.getPeerId()==null&&(d=d.encapsulate(`/p2p/${f.toString()}`)),d));if(h.length===0){o.log("no valid multiaddrs for %p in message",f),yield D.encode({type:D.MessageType.DIAL_RESPONSE,dialResponse:{status:D.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}});return}o.log("dial multiaddrs %s for peer %p",h.map(d=>d.toString()).join(", "),f);let m="",g=h[0];for await(let d of h){let p;g=d;try{if(p=await o.components.connectionManager.openConnection(d,{signal:e}),!p.remoteAddr.equals(d))throw o.log.error("tried to dial %a but dialed %a",d,p.remoteAddr),new Error("Unexpected remote address");o.log("Success %p",f),yield D.encode({type:D.MessageType.DIAL_RESPONSE,dialResponse:{status:D.ResponseStatus.OK,addr:p.remoteAddr.decapsulateCode(W("p2p").code).bytes}});return}catch(y){o.log("could not dial %p",f,y),m=y.message}finally{p!=null&&await p.close()}}yield D.encode({type:D.MessageType.DIAL_RESPONSE,dialResponse:{status:D.ResponseStatus.E_DIAL_ERROR,statusText:m,addr:g.bytes}})},i=>Yr(i),t.stream)}catch(o){this.log.error("error handling incoming autonat stream",o)}finally{e.removeEventListener("abort",n)}}_verifyExternalAddresses(){this.verifyExternalAddresses().catch(t=>{this.log.error("error verifying external address",t)})}async verifyExternalAddresses(){if(clearTimeout(this.verifyAddressTimeout),!this.isStarted())return;let t=this.components.addressManager,e=t.getObservedAddrs().filter(o=>{let i=o.toOptions();return!(Jo(i.host)??!1)});if(e.length===0){this.log("no public addresses found, not requesting verification"),this.verifyAddressTimeout=setTimeout(this._verifyExternalAddresses,this.refreshInterval);return}let n=AbortSignal.timeout(this.timeout);Ss(1/0,n);let s=this;try{this.log("verify multiaddrs %s",e.map(u=>u.toString()).join(", "));let o=D.encode({type:D.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toBytes(),addrs:e.map(u=>u.bytes)}}}),a=(await Oc()).toBytes(),c={},l=[],f=async u=>{let h=()=>{};try{this.log("asking %p to verify multiaddr",u.id);let m=await s.components.connectionManager.openConnection(u.id,{signal:n}),g=await m.newStream(this.protocol,{signal:n});h=()=>{g.abort(new U("verifyAddress timeout",As))},n.addEventListener("abort",h,{once:!0});let d=await di([o],y=>Yr(y),g,y=>Er(y),async y=>ci(y));if(d==null){this.log("no response received from %p",m.remotePeer);return}let p=D.decode(d);if(p.type!==D.MessageType.DIAL_RESPONSE||p.dialResponse==null){this.log("invalid autonat response from %p",m.remotePeer);return}if(p.dialResponse.status===D.ResponseStatus.OK){let y=m.remoteAddr.toOptions(),v;if(y.family===4)v=y.host.split(".")[0];else if(y.family===6)v=y.host.split(":")[0];else{this.log('remote address "%s" was not IP4 or IP6?',y.host);return}if(l.includes(v)){this.log("already have response from network segment %d - %s",v,y.host);return}l.push(v)}return p.dialResponse}catch(m){this.log.error("error asking remote to verify multiaddr",m)}finally{n.removeEventListener("abort",h)}};for await(let u of ui(al(this.components.peerRouting.getClosestPeers(a,{signal:n}),h=>async()=>f(h)),{concurrency:pi}))try{if(u==null)continue;let h=u.addr==null?e[0]:wr(u.addr);if(this.log("autonat response for %a is %s",h,u.status),u.status===D.ResponseStatus.E_BAD_REQUEST||u.status===D.ResponseStatus.E_DIAL_REFUSED||u.addr==null&&e.length>1)continue;if(!e.some(g=>g.equals(h))){this.log("peer reported %a as %s but it was not in our observed address list",h,u.status);continue}let m=h.toString();if(c[m]==null&&(c[m]={success:0,failure:0}),u.status===D.ResponseStatus.OK?c[m].success++:u.status===D.ResponseStatus.E_DIAL_ERROR&&c[m].failure++,c[m].success===pi){this.log("%a is externally dialable",h),t.confirmObservedAddr(h);return}if(c[m].failure===pi){this.log("%a is not externally dialable",h),t.removeObservedAddr(h);return}}catch(h){this.log.error("could not verify external address",h)}}finally{this.verifyAddressTimeout=setTimeout(this._verifyExternalAddresses,this.refreshInterval)}}};function Md(r={}){return t=>new xs(t,r)}return Il(Kd);})();
8
8
  /*! Bundled license information:
9
9
 
10
10
  pvtsutils/build/index.js:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/autonat",
3
- "version": "1.0.13-ab466004b",
3
+ "version": "1.0.13-e1798aa26",
4
4
  "description": "Implementation of Autonat Protocol",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/protocol-autonat#readme",
@@ -52,11 +52,11 @@
52
52
  "doc-check": "aegir doc-check"
53
53
  },
54
54
  "dependencies": {
55
- "@libp2p/interface": "1.1.4-ab466004b",
56
- "@libp2p/interface-internal": "1.0.9-ab466004b",
57
- "@libp2p/peer-id": "4.0.7-ab466004b",
58
- "@libp2p/peer-id-factory": "4.0.7-ab466004b",
59
- "@libp2p/utils": "5.2.6-ab466004b",
55
+ "@libp2p/interface": "1.1.4-e1798aa26",
56
+ "@libp2p/interface-internal": "1.0.9-e1798aa26",
57
+ "@libp2p/peer-id": "4.0.7-e1798aa26",
58
+ "@libp2p/peer-id-factory": "4.0.7-e1798aa26",
59
+ "@libp2p/utils": "5.2.6-e1798aa26",
60
60
  "@multiformats/multiaddr": "^12.1.14",
61
61
  "it-first": "^3.0.4",
62
62
  "it-length-prefixed": "^9.0.4",
@@ -67,7 +67,7 @@
67
67
  "uint8arraylist": "^2.4.8"
68
68
  },
69
69
  "devDependencies": {
70
- "@libp2p/logger": "4.0.7-ab466004b",
70
+ "@libp2p/logger": "4.0.7-e1798aa26",
71
71
  "aegir": "^42.2.4",
72
72
  "it-all": "^3.0.4",
73
73
  "it-pushable": "^3.2.3",