@libp2p/autonat 1.0.21 → 1.0.22-44791342

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,103 +1,3 @@
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 Bl=Object.create;var Jr=Object.defineProperty;var Al=Object.getOwnPropertyDescriptor;var Sl=Object.getOwnPropertyNames;var kl=Object.getPrototypeOf,Il=Object.prototype.hasOwnProperty;var Bs=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),lt=(r,t)=>{for(var e in t)Jr(r,e,{get:t[e],enumerable:!0})},Bi=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Sl(t))!Il.call(r,s)&&s!==e&&Jr(r,s,{get:()=>t[s],enumerable:!(n=Al(t,s))||n.enumerable});return r};var As=(r,t,e)=>(e=r!=null?Bl(kl(r)):{},Bi(t||!r||!r.__esModule?Jr(e,"default",{value:r,enumerable:!0}):e,r)),Rl=r=>Bi(Jr({},"__esModule",{value:!0}),r);var Na=Bs(dr=>{"use strict";var lh="[object ArrayBuffer]",oe=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-_]+$/,xn=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=oe.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=oe.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}},vn=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=oe.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=oe.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 xn.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 xn.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=oe.toUint8Array(t),n="";for(let s=0;s<e.length;s++)n+=String.fromCharCode(e[s]);return n}static ToHex(t){let e=oe.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,"")||""}};vn.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}dr.BufferSourceConverter=oe;dr.Convert=vn;dr.assign=dh;dr.combine=ph;dr.isEqual=gh});var Hc=Bs(Yr=>{(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}(),Yr.ip2long=i,Yr.long2ip=a,Yr.Netmask=r}).call(Yr)});var il=Bs((Rb,ol)=>{"use strict";function sl(r,t){for(let e in t)Object.defineProperty(r,e,{value:t[e],enumerable:!0,configurable:!0});return r}function Ed(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 sl(r,e)}catch{e.message=r.message,e.stack=r.stack;let s=function(){};return s.prototype=Object.create(Object.getPrototypeOf(r)),sl(new s,e)}}ol.exports=Ed});var Hd={};lt(Hd,{autoNAT:()=>Fd});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 Ss="ERR_TIMEOUT";var ks=(r,...t)=>{try{[...t]}catch{}};var Ls={};lt(Ls,{base58btc:()=>at,base58flickr:()=>Cl});var zd=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 Gt(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 Nl(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 z=c.repeat(d);N<w;++N)z+=r.charAt(T[N]);return z}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)),z=p;R!==v;)N[z++]=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 Tl=Nl,Ll=Tl,Ni=Ll;var Is=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")}},Rs=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)}},Ns=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 Ns({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Ts=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 Is(t,e,n),this.decoder=new Rs(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 Ts(r,t,e,n)}function de({name:r,prefix:t,alphabet:e}){let{encode:n,decode:s}=Ni(e,r);return ze({prefix:t,name:r,encode:n,decode:o=>Gt(s(o))})}function _l(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 Ul(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 Ul(s,n,e)},decode(s){return _l(s,n,e,r)}})}var at=de({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Cl=de({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var _s={};lt(_s,{base10:()=>Dl});var Dl=de({prefix:"9",name:"base10",alphabet:"0123456789"});var Us={};lt(Us,{base16:()=>Pl,base16upper:()=>Ol});var Pl=tt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ol=tt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Cs={};lt(Cs,{base2:()=>Vl});var Vl=tt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ds={};lt(Ds,{base256emoji:()=>$l});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}"),Fl=Li.reduce((r,t,e)=>(r[e]=t,r),[]),Hl=Li.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function Ml(r){return r.reduce((t,e)=>(t+=Fl[e],t),"")}function Kl(r){let t=[];for(let e of r){let n=Hl[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var $l=ze({prefix:"\u{1F680}",name:"base256emoji",encode:Ml,decode:Kl});var Ps={};lt(Ps,{base32:()=>jt,base32hex:()=>jl,base32hexpad:()=>Yl,base32hexpadupper:()=>Zl,base32hexupper:()=>Wl,base32pad:()=>zl,base32padupper:()=>Gl,base32upper:()=>ql,base32z:()=>Jl});var jt=tt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ql=tt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),zl=tt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Gl=tt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),jl=tt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Wl=tt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Yl=tt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Zl=tt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Jl=tt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Os={};lt(Os,{base36:()=>Xl,base36upper:()=>Ql});var Xl=de({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ql=de({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Fs={};lt(Fs,{base64:()=>Vs,base64pad:()=>tu,base64url:()=>eu,base64urlpad:()=>ru});var Vs=tt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),tu=tt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),eu=tt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ru=tt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Hs={};lt(Hs,{base8:()=>nu});var nu=tt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ms={};lt(Ms,{identity:()=>su});var su=ze({prefix:"\0",name:"identity",encode:r=>Ii(r),decode:r=>ki(r)});var a0=new TextEncoder,c0=new TextDecoder;var $s={};lt($s,{identity:()=>pe});var au=Ci,_i=128,cu=127,lu=~cu,uu=Math.pow(2,31);function Ci(r,t,e){t=t||[],e=e||0;for(var n=e;r>=uu;)t[e++]=r&255|_i,r/=128;for(;r&lu;)t[e++]=r&255|_i,r>>>=7;return t[e]=r|0,Ci.bytes=e-n+1,t}var fu=Ks,hu=128,Ui=127;function Ks(r,n){var e=0,n=n||0,s=0,o=n,i,a=r.length;do{if(o>=a)throw Ks.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>=hu);return Ks.bytes=o-n,e}var du=Math.pow(2,7),pu=Math.pow(2,14),gu=Math.pow(2,21),mu=Math.pow(2,28),yu=Math.pow(2,35),bu=Math.pow(2,42),wu=Math.pow(2,49),xu=Math.pow(2,56),vu=Math.pow(2,63),Eu=function(r){return r<du?1:r<pu?2:r<gu?3:r<mu?4:r<yu?5:r<bu?6:r<wu?7:r<xu?8:r<vu?9:10},Bu={encode:au,decode:fu,encodingLength:Eu},Au=Bu,kr=Au;function Ir(r,t=0){return[kr.decode(r,t),kr.decode.bytes]}function Ge(r,t,e=0){return kr.encode(r,t,e),t}function je(r){return kr.encodingLength(r)}function Ht(r,t){let e=t.byteLength,n=je(r),s=n+je(e),o=new Uint8Array(s+e);return Ge(r,o,0),Ge(e,o,n),o.set(t,s),new We(r,e,t,o)}function Ue(r){let t=Gt(r),[e,n]=Ir(t),[s,o]=Ir(t.subarray(n)),i=t.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new We(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 We=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,Su="identity",Oi=Gt;function ku(r){return Ht(Pi,Oi(r))}var pe={code:Pi,name:Su,encode:Oi,digest:ku};var Gs={};lt(Gs,{sha256:()=>pt,sha512:()=>Iu});function zs({name:r,code:t,encode:e}){return new qs(r,t,e)}var qs=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?Ht(this.code,e):e.then(n=>Ht(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=zs({name:"sha2-256",code:18,encode:Fi("SHA-256")}),Iu=zs({name:"sha2-512",code:19,encode:Fi("SHA-512")});function Hi(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Nu(e,js(r),t??at.encoder);default:return Tu(e,js(r),t??jt.encoder)}}var Mi=new WeakMap;function js(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!==Rr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Lu)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=Ht(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[_u]===!0){let{version:n,multihash:s,code:o}=e,i=Ue(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!==Rr)throw new Error(`Version 0 CID must use dag-pb (code: ${Rr}) 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,Rr,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=Gt(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 We(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]=Ir(t.subarray(e));return e+=h,u},s=n(),o=Rr;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]=Ru(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 js(o).set(n,t),o}};function Ru(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 jt.prefix:{let e=t??jt;return[jt.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 Nu(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 Tu(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 Rr=112,Lu=18;function Ki(r,t,e){let n=je(r),s=n+je(t),o=new Uint8Array(s+e.byteLength);return Ge(r,o,0),Ge(t,o,n),o.set(e,s),o}var _u=Symbol.for("@ipld/js-cid/CID");var ge={...Ms,...Cs,...Hs,..._s,...Us,...Ps,...Os,...Ls,...Fs,...Ds},N0={...Gs,...$s};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 Uu=Symbol.for("nodejs.util.inspect.custom"),$i=Object.values(ge).map(r=>r.decoder).reduce((r,t)=>r.or(t),ge.identity.decoder),qi=114,Ws=36,Ys=37,Nr=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 Cu(t).equals(this);if(t?.multihash?.bytes!=null)return bt(this.multihash.bytes,t.multihash.bytes);throw new Error("not valid Id")}[Uu](){return`PeerId(${this.toString()})`}},Ye=class extends Nr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Ze=class extends Nr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.multihash.digest}},Je=class extends Nr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.multihash.digest}};function Cu(r,t){if(t=t??$i,r.charAt(0)==="1"||r.charAt(0)==="Q"){let e=Ue(at.decode(`z${r}`));return r.startsWith("12D")?new Ze({multihash:e}):r.startsWith("16U")?new Je({multihash:e}):new Ye({multihash:e})}return Qr($i.decode(r))}function Qr(r){try{let t=Ue(r);if(t.code===pe.code){if(t.digest.length===Ws)return new Ze({multihash:t});if(t.digest.length===Ys)return new Je({multihash:t})}if(t.code===pt.code)return new Ye({multihash:t})}catch{return Du(Ut.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function Du(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 Ye({multihash:r.multihash});if(t.code===pe.code){if(t.digest.length===Ws)return new Ze({multihash:r.multihash});if(t.digest.length===Ys)return new Je({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function zi(r,t){return r.length===Ws?new Ze({multihash:Ht(pe.code,r),privateKey:t}):r.length===Ys?new Je({multihash:Ht(pe.code,r),privateKey:t}):new Ye({multihash:await pt.digest(r),publicKey:r,privateKey:t})}var _o={};lt(_o,{Ed25519PrivateKey:()=>He,Ed25519PublicKey:()=>Cr,generateKeyPair:()=>ih,generateKeyPairFromSeed:()=>Ra,unmarshalEd25519PrivateKey:()=>sh,unmarshalEd25519PublicKey:()=>oh});function Wt(r=0){return new Uint8Array(r)}function wt(r=0){return new Uint8Array(r)}function Bt(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 e}function ji(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Gi=ji("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Zs=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}),Pu={utf8:Gi,"utf-8":Gi,hex:ge.base16,latin1:Zs,ascii:Zs,binary:Zs,...ge},tn=Pu;function Z(r,t="utf8"){let e=tn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return 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 Xe(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function Ou(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Qe(r,...t){if(!Ou(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${r.length}`)}function en(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Xe(r.outputLen),Xe(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){Qe(r);let e=t.outputLen;if(r.length<e)throw new Error(`digestInto() expects output buffer of length at least ${e}`)}var rn=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var rr=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Ct=(r,t)=>r<<32-t|r>>>t;var sp=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var Vu=async()=>{};async function Yi(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 me(r){return typeof r=="string"&&(r=Js(r)),Qe(r),r}function nn(...r){let t=0;for(let n=0;n<r.length;n++){let s=r[n];Qe(s),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 Zi(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 sn(r){let t=n=>r().update(me(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function nr(r=32){if(rn&&typeof rn.getRandomValues=="function")return rn.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 Ji=(r,t,e)=>r&t^~r&e,Xi=(r,t,e)=>r&t^r&e^t&e,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=me(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 on=BigInt(4294967295),Xs=BigInt(32);function Qi(r,t=!1){return t?{h:Number(r&on),l:Number(r>>Xs&on)}:{h:Number(r>>Xs&on)|0,l:Number(r&on)|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}=Qi(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,zu=(r,t,e)=>r>>>e|t<<32-e,Gu=(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:Qi,split:Mu,toBig:Ku,shrSH:$u,shrSL:qu,rotrSH:zu,rotrSL:Gu,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))),ye=new Uint32Array(80),be=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)ye[w]=t.getUint32(e),be[w]=t.getUint32(e+=4);for(let w=16;w<80;w++){let T=ye[w-15]|0,x=be[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=ye[w-2]|0,z=be[w-2]|0,K=C.rotrSH(N,z,19)^C.rotrBH(N,z,61)^C.shrSH(N,z,6),P=C.rotrSL(N,z,19)^C.rotrBL(N,z,61)^C.shrSL(N,z,6),nt=C.add4L(R,P,be[w-7],be[w-16]),rt=C.add4H(nt,A,K,ye[w-7],ye[w-16]);ye[w]=rt|0,be[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],be[w]),z=C.add5H(N,y,T,A,uf[w],ye[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,z|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,z,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(){ye.fill(0),be.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=sn(()=>new Qs);var cn={};lt(cn,{abytes:()=>ir,bitGet:()=>bf,bitLen:()=>yf,bitMask:()=>Tr,bitSet:()=>wf,bytesToHex:()=>Zt,bytesToNumberBE:()=>Jt,bytesToNumberLE:()=>xe,concatBytes:()=>Xt,createHmacDrbg:()=>ro,ensureBytes:()=>et,equalBytes:()=>gf,hexToBytes:()=>De,hexToNumber:()=>eo,isBytes:()=>we,numberToBytesBE:()=>ve,numberToBytesLE:()=>Pe,numberToHexUnpadded:()=>na,numberToVarBytesBE:()=>pf,utf8ToBytes:()=>mf,validateObject:()=>Mt});var ra=BigInt(0),an=BigInt(1),hf=BigInt(2);function we(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function ir(r){if(!we(r))throw new Error("Uint8Array expected")}var df=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Zt(r){ir(r);let t="";for(let e=0;e<r.length;e++)t+=df[r[e]];return t}function na(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 Yt={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function ta(r){if(r>=Yt._0&&r<=Yt._9)return r-Yt._0;if(r>=Yt._A&&r<=Yt._F)return r-(Yt._A-10);if(r>=Yt._a&&r<=Yt._f)return r-(Yt._a-10)}function De(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=ta(r.charCodeAt(o)),a=ta(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 Jt(r){return eo(Zt(r))}function xe(r){return ir(r),eo(Zt(Uint8Array.from(r).reverse()))}function ve(r,t){return De(r.toString(16).padStart(t*2,"0"))}function Pe(r,t){return ve(r,t).reverse()}function pf(r){return De(na(r))}function et(r,t,e){let n;if(typeof t=="string")try{n=De(t)}catch(o){throw new Error(`${r} must be valid hex string, got "${t}". Cause: ${o}`)}else if(we(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 Xt(...r){let t=0;for(let n=0;n<r.length;n++){let s=r[n];ir(s),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}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>ra;r>>=an,t+=1);return t}function bf(r,t){return r>>BigInt(t)&an}function wf(r,t,e){return r|(e?an:ra)<<BigInt(t)}var Tr=r=>(hf<<BigInt(r-1))-an,to=r=>new Uint8Array(r),ea=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(ea([0]),u),n=a(),u.length!==0&&(s=a(ea([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 Xt(...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"||we(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 Mt(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),Oe=BigInt(2),vf=BigInt(3),no=BigInt(4),sa=BigInt(5),oa=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 ln(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)/Oe,e,n,s;for(e=r-J,n=0;e%Oe===ct;e/=Oe,n++);for(s=Oe;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)/Oe;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%oa===sa){let t=(r-sa)/oa;return function(n,s){let o=n.mul(s,Oe),i=n.pow(o,t),a=n.mul(s,i),c=n.mul(n.mul(a,Oe),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 ia=(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 Mt(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 un(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:Tr(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*ln(l,r),r),sqrN:c=>c*c,addN:(c,l)=>c+l,subN:(c,l)=>c-l,mulN:(c,l)=>c*l,inv:c=>ln(c,r),sqrt:n.sqrt||(c=>i(a,c)),invertBatch:c=>Nf(a,c),cmov:(c,l,f)=>f?l:c,toBytes:c=>e?Pe(c,o):ve(c,o),fromBytes:c=>{if(c.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);return e?xe(c):Jt(c)}});return Object.freeze(a)}function aa(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 ca(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=ca(r);return t+Math.ceil(t/2)}function la(r,t,e=!1){let n=r.length,s=ca(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?Jt(r):xe(r),a=Y(i,t-J)+J;return e?Pe(a,s):ve(a,s)}var Lf=BigInt(0),ao=BigInt(1);function fn(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 Lr(r){return so(r.Fp),Mt(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 Dt=BigInt(0),It=BigInt(1),hn=BigInt(2),_f=BigInt(8),Uf={zip215:!0};function Cf(r){let t=Lr(r);return Mt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function dn(r){let t=Cf(r),{Fp:e,n,prehash:s,hash:o,randomBytes:i,nByteLength:a,h:c}=t,l=hn<<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:Dt}}}),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"&&Dt<B,d=(B,b)=>g(B)&&g(b)&&B<b,p=B=>B===Dt||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===Dt?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,q=f(L*L),M=f(_*_),$=f(V*V),st=f($*$),Q=f(q*b),ht=f($*f(Q+M)),dt=f(st+f(k*f(q*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:q}=b,M=f(k*q),$=f(V*_),st=f(L*q),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),q=f(hn*f(_*_)),M=f(b*V),$=k+L,st=f(f($*$)-V-F),Q=M+F,ht=Q-q,dt=M-F,it=f(st*ht),yt=f(Q*dt),zt=f(st*dt),_e=f(ht*Q);return new x(it,yt,_e,zt)}add(b){T(b);let{a:k,d:L}=t,{ex:_,ey:V,ez:F,et:q}=this,{ex:M,ey:$,ez:st,et:Q}=b;if(k===BigInt(-1)){let mi=f((V-_)*($+M)),yi=f((V+_)*($-M)),Es=f(yi-mi);if(Es===Dt)return this.double();let bi=f(F*hn*Q),wi=f(q*hn*st),xi=wi+bi,vi=yi+mi,Ei=wi-bi,wl=f(xi*Es),xl=f(vi*Ei),vl=f(xi*Ei),El=f(Es*vi);return new x(wl,xl,El,vl)}let ht=f(_*M),dt=f(V*$),it=f(q*L*Q),yt=f(F*st),zt=f((_+V)*(M+$)-ht-dt),_e=yt-it,Sr=yt+it,gi=f(dt-k*ht),gl=f(zt*_e),ml=f(Sr*gi),yl=f(zt*gi),bl=f(_e*Sr);return new x(gl,ml,bl,yl)}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===Dt?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),q=f(L*b),M=f(_*b);if(V)return{x:Dt,y:It};if(M!==It)throw new Error("invZ was invalid");return{x:F,y:q}}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(),q=b[V-1];F[V-1]=q&-129;let M=xe(F);M===Dt||(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=(q&128)!==0;if(!k&&dt===Dt&&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=Pe(k,e.BYTES);return L[L.length-1]|=b&It?128:0,L}toHex(){return Zt(this.toRawBytes())}}x.BASE=new x(t.Gx,t.Gy,It,f(t.Gx*t.Gy)),x.ZERO=new x(Dt,It,It,Dt);let{BASE:A,ZERO:R}=x,N=fn(x,a*8);function z(B){return Y(B,n)}function K(B){return z(xe(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),q=F.toRawBytes();return{head:L,prefix:_,scalar:V,point:F,pointBytes:q}}function nt(B){return P(B).pointBytes}function rt(B=new Uint8Array,...b){let k=Xt(...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),q=A.multiply(F).toRawBytes(),M=rt(k.context,q,V,B),$=z(F+M*_);v($);let st=Xt(q,Pe($,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 q=xe(B.slice(F,2*F)),M,$,st;try{M=x.fromHex(k,V),$=x.fromHex(B.slice(0,F),V),st=A.multiplyUnsafe(q)}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"),ua=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),kp=BigInt(0),Df=BigInt(1),co=BigInt(2),Pf=BigInt(5),fa=BigInt(10),Of=BigInt(20),Vf=BigInt(40),ha=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,fa,t)*i%t,c=X(a,Of,t)*a%t,l=X(c,Vf,t)*c%t,f=X(l,ha,t)*l%t,u=X(f,ha,t)*l%t,h=X(u,fa,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*ua,e),f=a===r,u=a===Y(-r,e),h=a===Y(-r*ua,e);return f&&(i=c),(u||h)&&(i=l),ia(i,e)&&(i=Y(-i,e)),{isValid:f||u,value:i}}var Qt=un(lo,void 0,!0),uo={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Qt,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:or,randomBytes:nr,adjustScalarBytes:Hf,uvRatio:Mf},ar=dn(uo);function da(r,t,e){if(t.length>255)throw new Error("Context is too big");return nn(Js("SigEd25519 no Ed25519 collisions"),new Uint8Array([e?1:0,t.length]),t,r)}var Ip=dn({...uo,domain:da}),Rp=dn({...uo,domain:da,prehash:or});var Kf=(Qt.ORDER+BigInt(3))/BigInt(8),Np=Qt.pow(co,Kf),Tp=Qt.sqrt(Qt.neg(Qt.ONE)),Lp=(Qt.ORDER-BigInt(5))/BigInt(8),_p=BigInt(486662);var Up=aa(Qt,Qt.neg(BigInt(486664)));var Cp=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Dp=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Pp=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Op=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var Vp=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var cr=32,te=64,pn=32;function pa(){let r=ar.utils.randomPrivateKey(),t=ar.getPublicKey(r);return{privateKey:ba(r,t),publicKey:t}}function ga(r){if(r.length!==pn)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=ar.getPublicKey(t);return{privateKey:ba(t,e),publicKey:e}}function ma(r,t){let e=r.subarray(0,pn);return ar.sign(t instanceof Uint8Array?t:t.subarray(),e)}function ya(r,t,e){return ar.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}function ba(r,t){let e=new Uint8Array(te);for(let n=0;n<pn;n++)e[n]=r[n],e[pn+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 wa(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 lr(r,t){let n=await wa().encrypt(r,t);return Vs.encode(n)}var zf=Math.pow(2,7),Gf=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<zf)return 1;if(r<Gf)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 Ee(r,t,e=0){return t==null&&(t=wt(ut(r))),t instanceof Uint8Array?yo(r,t,e):Wf(r,t,e)}function ee(r,t=0){return r instanceof Uint8Array?bo(r,t):Yf(r,t)}var wo=new Float32Array([-0]),Be=new Uint8Array(wo.buffer);function xa(r,t,e){wo[0]=r,t[e]=Be[0],t[e+1]=Be[1],t[e+2]=Be[2],t[e+3]=Be[3]}function va(r,t){return Be[0]=r[t],Be[1]=r[t+1],Be[2]=r[t+2],Be[3]=r[t+3],wo[0]}var xo=new Float64Array([-0]),vt=new Uint8Array(xo.buffer);function Ea(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 Ba(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 Ve;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>Aa&&(s=0n,++n>Aa&&(n=0n))),new r(Number(s),Number(n))}static fromNumber(t){if(t===0)return Ve;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):Ve}},Ve=new Rt(0,0);Ve.toBigInt=function(){return 0n};Ve.zzEncode=Ve.zzDecode=function(){return this};Ve.length=function(){return 1};var Aa=4294967296n;function Sa(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 ka(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 Pt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function mn(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,Pt(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 Pt(this,4);return mn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Pt(this,4);return mn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Pt(this,4);let t=va(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Pt(this,4);let t=Ba(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 Pt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return ka(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Pt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Pt(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 Pt(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 Pt(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 Pt(this,8);let t=mn(this.buf,this.pos+=4),e=mn(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 re(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 Fe=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 Ur=class{len;head;tail;states;constructor(){this.len=0,this.head=new Fe(So,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Fe(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(yn,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(yn,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(yn,e.length(),e)}sint64Number(t){let e=Rt.fromNumber(t).zzEncode();return this._push(yn,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(_r,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Rt.fromBigInt(t);return this._push(_r,4,e.lo)._push(_r,4,e.hi)}fixed64Number(t){let e=Rt.fromNumber(t);return this._push(_r,4,e.lo)._push(_r,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(xa,4,t)}double(t){return this._push(Ea,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=Sa(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 Fe(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 Fe(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 Fe{next;constructor(t,e){super(th,t,e),this.next=void 0}};function yn(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 _r(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&&(Ur.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(rh,t,r),this},Ur.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 Ur}function ne(r,t){let e=No();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var ur;(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"})(ur||(ur={}));function bn(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function fr(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 bn("enum",ur.VARINT,e,n)}function se(r,t){return bn("message",ur.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=()=>fr(To)})(gt||(gt={}));var Ae;(function(r){let t;r.codec=()=>(t==null&&(t=se((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=>ne(e,r.codec()),r.decode=e=>re(e,r.codec())})(Ae||(Ae={}));var Se;(function(r){let t;r.codec=()=>(t==null&&(t=se((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=>ne(e,r.codec()),r.decode=e=>re(e,r.codec())})(Se||(Se={}));var Cr=class{_key;constructor(t){this._key=hr(t,cr)}verify(t,e){return ya(this._key,e,t)}marshal(){return this._key}get bytes(){return Ae.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}},He=class{_key;_publicKey;constructor(t,e){this._key=hr(t,te),this._publicKey=hr(e,cr)}sign(t){return ma(this._key,t)}get public(){return new Cr(this._publicKey)}marshal(){return this._key}get bytes(){return Se.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=pe.digest(this.public.bytes);return at.encode(t.bytes).substring(1)}async export(t,e="libp2p-key"){if(e==="libp2p-key")return lr(this.bytes,t);throw new U(`export format '${e}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function sh(r){if(r.length>te){r=hr(r,te+cr);let n=r.subarray(0,te),s=r.subarray(te,r.length);return new He(n,s)}r=hr(r,te);let t=r.subarray(0,te),e=r.subarray(cr);return new He(t,e)}function oh(r){return r=hr(r,cr),new Cr(r)}async function ih(){let{privateKey:r,publicKey:t}=pa();return new He(r,t)}async function Ra(r){let{privateKey:t,publicKey:e}=ga(r);return new He(t,e)}function hr(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 j(r,t="utf8"){let e=tn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Ko={};lt(Ko,{MAX_RSA_KEY_SIZE:()=>Gr,RsaPrivateKey:()=>yr,RsaPublicKey:()=>zr,fromJwk:()=>Uh,generateKeyPair:()=>Ch,unmarshalRsaPrivateKey:()=>Ho,unmarshalRsaPublicKey:()=>_h});function Me(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 Ne={};lt(Ne,{exportToPem:()=>Ih,importFromPem:()=>Rh,jwkToPkcs1:()=>Bh,jwkToPkix:()=>Sh,pkcs1ToJwk:()=>Eh,pkixToJwk:()=>Ah});var wn=class extends er{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,en(t);let n=me(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),Qe(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()}},Dr=(r,t,e)=>new wn(r,t).update(e).digest();Dr.create=(r,t)=>new wn(r,t);function ah(r,t,e,n){en(r);let s=Zi({dkLen:32,asyncTick:10},n),{c:o,dkLen:i,asyncTick:a}=s;if(Xe(o),Xe(i),Xe(a),o<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=me(t),l=me(e),f=new Uint8Array(i),u=Dr.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 Yi(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=As(Na());function Ke(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 ke(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 En(...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=Ke(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,Ke(o,8)-n}function Ta(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=ke(i,8,n),c=new Uint8Array(a);return c[0]|=128,a}let s=ke(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 La(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 Gg=Math.log(2);function Bn(){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 le(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 Or=class{constructor(){this.items=[]}write(t){this.items.push(t)}final(){return Po(this.items)}},Pr=[new Uint8Array([1])],_a="0123456789";var gr="",Vt=new ArrayBuffer(0),Oo=new Uint8Array(0),Vr="EndOfContent",Ca="OCTET STRING",Da="BIT STRING";function ue(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(!le(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",Vt)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:H.Convert.ToHex(this.valueHexView)}}},t.NAME="hexBlock",t}var ie=class{constructor({blockLength:t=0,error:e=gr,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)}}};ie.NAME="baseBlock";var Et=class extends ie{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 An=class extends ue(ie){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",Vt}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=ke(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(!le(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=Ke(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}}};An.NAME="identificationBlock";var Sn=class extends ie{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(!le(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=Ke(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=ke(this.length,8);if(s.byteLength>127)return this.error="Too big length",Vt;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}}};Sn.NAME="lengthBlock";var S={},mt=class extends ie{constructor({name:t=gr,optional:e=!1,primitiveSchema:n,...s}={},o){super(s),this.name=t,this.optional=e,n&&(this.primitiveSchema=n),this.idBlock=new An(s),this.lenBlock=new Sn(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 Or;e||Pa(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?Vt: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 La(e,n)}};mt.NAME="BaseBlock";function Pa(r){if(r instanceof S.Constructed)for(let t of r.valueBlock.value)Pa(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var kn=class extends mt{constructor({value:t=gr,...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}'`}};kn.NAME="BaseStringBlock";var In=class extends ue(Et){constructor({isHexOnly:t=!0,...e}={}){super(e),this.isHexOnly=t}};In.NAME="PrimitiveValueBlock";var Oa,Rn=class extends mt{constructor(t={}){super(t,In),this.idBlock.isConstructed=!1}};Oa=Rn;S.Primitive=Oa;Rn.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 as(r,t=0,e=r.length){let n=t,s=new mt({},Et),o=new ie;if(!le(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 mr(r){if(!r.byteLength){let t=new mt({},Et);return t.error="Input buffer has zero length",{offset:-1,result:t}}return as(H.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function bh(r,t){return r?1:t}var Kt=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(!le(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=as(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===Vr)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===Vr?this.value.pop():this.warnings.push("No EndOfContent block encoded")),o}toBER(t,e){let n=e||new Or;for(let s=0;s<this.value.length;s++)this.value[s].toBER(t,n);return e?Vt:n.final()}toJSON(){let t={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let e of this.value)t.value.push(e.toJSON());return t}};Kt.NAME="ConstructedValueBlock";var Va,Ie=class extends mt{constructor(t={}){super(t,Kt),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
- `).map(s=>` ${s}`).join(`
4
- `));let e=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return t.length?`${e} :
5
- ${t.join(`
6
- `)}`:`${e} :`}};Va=Ie;S.Constructed=Va;Ie.NAME="CONSTRUCTED";var Nn=class extends Et{fromBER(t,e,n){return e}toBER(t){return Vt}};Nn.override="EndOfContentValueBlock";var Fa,Tn=class extends mt{constructor(t={}){super(t,Nn),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};Fa=Tn;S.EndOfContent=Fa;Tn.NAME=Vr;var Ha,Re=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}`}};Ha=Re;S.Null=Ha;Re.NAME="NULL";var Ln=class extends ue(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 le(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}}};Ln.NAME="BooleanValueBlock";var Ma,_n=class extends mt{constructor(t={}){super(t,Ln),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}`}};Ma=_n;S.Boolean=Ma;_n.NAME="BOOLEAN";var Un=class extends ue(Kt){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=Kt.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===Vr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(i!==Ca)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?Kt.prototype.toBER.call(this,t,e):t?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};Un.NAME="OctetStringValueBlock";var Ka,ae=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},Un),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=as(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?Ie.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)}};Ka=ae;S.OctetString=Ka;ae.NAME=Ca;var Cn=class extends ue(Kt){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=Kt.prototype.fromBER.call(this,t,e,n),s===-1)return s;for(let a of this.value){let c=a.constructor.NAME;if(c===Vr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==Da)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(!le(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=as(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 Kt.prototype.toBER.call(this,t,e);if(t)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return Vt;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}}};Cn.NAME="BitStringValueBlock";var $a,pr=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},Cn),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 Ie.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)}`}}};$a=pr;S.BitString=$a;pr.NAME=Da;var qa;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=En(new Uint8Array([l%10]),o);break;default:o[i-u]=l%10}}return e[0]>0&&(o=En(e,o)),o}function Ua(r){if(r>=Pr.length)for(let t=Pr.length;t<=r;t++){let e=new Uint8Array([0]),n=Pr[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=En(e,n)),Pr.push(n)}return Pr[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 Fr=class extends ue(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(Ta(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(Ua(n),e),i="-";break;default:e=wh(e,Ua(n))}n++,s>>=1}}for(let c=0;c<e.length;c++)e[c]&&(a=!0),a&&(i+=_a.charAt(e[c]));return a===!1&&(i+=_a.charAt(0)),i}};qa=Fr;Fr.NAME="IntegerValueBlock";Object.defineProperty(qa.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var za,ot=class r extends mt{constructor(t={}){super(t,Fr),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Bn(),BigInt(this.valueBlock.toString())}static fromBigInt(t){Bn();let e=BigInt(t),n=new Or,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()}`}};za=ot;S.Integer=za;ot.NAME="INTEGER";var Ga,Dn=class extends ot{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};Ga=Dn;S.Enumerated=Ga;Dn.NAME="ENUMERATED";var Hr=class extends ue(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(!le(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=Ke(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),e+this.blockLength)}set valueBigInt(t){Bn();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=ke(this.valueDec,7);if(e.byteLength===0)return this.error="Error during encoding SID value",Vt;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}}};Hr.NAME="sidBlock";var Pn=class extends Et{constructor({value:t=gr,...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.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,Vt;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 Hr;if(s>Number.MAX_SAFE_INTEGER){Bn();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}};Pn.NAME="ObjectIdentifierValueBlock";var ja,Ot=class extends mt{constructor(t={}){super(t,Pn),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()}}};ja=Ot;S.ObjectIdentifier=ja;Ot.NAME="OBJECT IDENTIFIER";var Mr=class extends ue(ie){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(!le(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=Ke(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=ke(this.valueDec,7);if(e.byteLength===0)return this.error="Error during encoding SID value",Vt;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}}};Mr.NAME="relativeSidBlock";var On=class extends Et{constructor({value:t=gr,...e}={}){super(e),this.value=[],t&&this.fromString(t)}fromBER(t,e,n){let s=e;for(;n>0;){let o=new Mr;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,Vt;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 Mr;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}};On.NAME="RelativeObjectIdentifierValueBlock";var Wa,Vn=class extends mt{constructor(t={}){super(t,On),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()}}};Wa=Vn;S.RelativeObjectIdentifier=Wa;Vn.NAME="RelativeObjectIdentifier";var Ya,ft=class extends Ie{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};Ya=ft;S.Sequence=Ya;ft.NAME="SEQUENCE";var Za,Fn=class extends Ie{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};Za=Fn;S.Set=Za;Fn.NAME="SET";var Hn=class extends ue(Et){constructor({...t}={}){super(t),this.isHexOnly=!0,this.value=gr}toJSON(){return{...super.toJSON(),value:this.value}}};Hn.NAME="StringValueBlock";var Mn=class extends Hn{};Mn.NAME="SimpleStringValueBlock";var St=class extends kn{constructor({...t}={}){super(t,Mn)}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 Kn=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}};Kn.NAME="Utf8StringValueBlock";var Ja,ce=class extends Kn{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};Ja=ce;S.Utf8String=Ja;ce.NAME="UTF8String";var $n=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))}};$n.NAME="BmpStringValueBlock";var Xa,qn=class extends $n{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};Xa=qn;S.BmpString=Xa;qn.NAME="BMPString";var zn=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=ke(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}};zn.NAME="UniversalStringValueBlock";var Qa,Gn=class extends zn{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};Qa=Gn;S.UniversalString=Qa;Gn.NAME="UniversalString";var tc,jn=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};tc=jn;S.NumericString=tc;jn.NAME="NumericString";var ec,Wn=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};ec=Wn;S.PrintableString=ec;Wn.NAME="PrintableString";var rc,Yn=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};rc=Yn;S.TeletexString=rc;Yn.NAME="TeletexString";var nc,Zn=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};nc=Zn;S.VideotexString=nc;Zn.NAME="VideotexString";var sc,Jn=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};sc=Jn;S.IA5String=sc;Jn.NAME="IA5String";var oc,Xn=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};oc=Xn;S.GraphicString=oc;Xn.NAME="GraphicString";var ic,Kr=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};ic=Kr;S.VisibleString=ic;Kr.NAME="VisibleString";var ac,Qn=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};ac=Qn;S.GeneralString=ac;Qn.NAME="GeneralString";var cc,ts=class extends St{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};cc=ts;S.CharacterString=cc;ts.NAME="CharacterString";var lc,$r=class extends Kr{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}}};lc=$r;S.UTCTime=lc;$r.NAME="UTCTime";var uc,es=class extends $r{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}}};uc=es;S.GeneralizedTime=uc;es.NAME="GeneralizedTime";var fc,rs=class extends ce{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};fc=rs;S.DATE=fc;rs.NAME="DATE";var hc,ns=class extends ce{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};hc=ns;S.TimeOfDay=hc;ns.NAME="TimeOfDay";var dc,ss=class extends ce{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};dc=ss;S.DateTime=dc;ss.NAME="DateTime";var pc,os=class extends ce{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};pc=os;S.Duration=pc;os.NAME="Duration";var gc,is=class extends ce{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};gc=is;S.TIME=gc;is.NAME="TIME";function Eh(r){let{result:t}=mr(r),e=t.valueBlock.value;return{n:j($t(e[1].toBigInt()),"base64url"),e:j($t(e[2].toBigInt()),"base64url"),d:j($t(e[3].toBigInt()),"base64url"),p:j($t(e[4].toBigInt()),"base64url"),q:j($t(e[5].toBigInt()),"base64url"),dp:j($t(e[6].toBigInt()),"base64url"),dq:j($t(e[7].toBigInt()),"base64url"),qi:j($t(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(qt(Z(r.n,"base64url"))),ot.fromBigInt(qt(Z(r.e,"base64url"))),ot.fromBigInt(qt(Z(r.d,"base64url"))),ot.fromBigInt(qt(Z(r.p,"base64url"))),ot.fromBigInt(qt(Z(r.q,"base64url"))),ot.fromBigInt(qt(Z(r.dp,"base64url"))),ot.fromBigInt(qt(Z(r.dq,"base64url"))),ot.fromBigInt(qt(Z(r.qi,"base64url")))]}).toBER();return new Uint8Array(e,0,e.byteLength)}function Ah(r){let{result:t}=mr(r),e=t.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:j($t(e[0].toBigInt()),"base64url"),e:j($t(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 Ot({value:"1.2.840.113549.1.1.1"}),new Re]}),new pr({valueHex:new ft({value:[ot.fromBigInt(qt(Z(r.n,"base64url"))),ot.fromBigInt(qt(Z(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(e,0,e.byteLength)}function $t(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 qt(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 Ot({value:"1.2.840.113549.1.1.1"}),new Re]}),new ae({valueHex:r.marshal()})]}).toBER(),o=new Uint8Array(s,0,s.byteLength),i=Me(kh),a=await Uo(or,t,i,{c:Fo,dkLen:Vo}),c=Me(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 ae({valueHex:i}),new ot({value:Fo}),new ot({value:Vo}),new ft({value:[new Ot({value:"1.2.840.113549.2.11"}),new Re]})]}),h=new ft({value:[new Ot({value:"1.2.840.113549.1.5.13"}),new ft({value:[new ft({value:[new Ot({value:"1.2.840.113549.1.5.12"}),u]}),new ft({value:[new Ot({value:"2.16.840.1.101.3.4.1.42"}),new ae({valueHex:c})]})]})]}),g=new ft({value:[h,new ae({valueHex:f})]}).toBER(),d=new Uint8Array(g,0,g.byteLength);return["-----BEGIN ENCRYPTED PRIVATE KEY-----",...j(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}=mr(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=qr(await e.subtle.decrypt({name:"AES-CBC",iv:i},h,f)),{result:g}=mr(m);n=mc(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}=mr(s);n=mc(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=qr(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=qr(l.valueBlock.value[1].getValue());return{cipherText:qr(r.valueBlock.value[1].getValue()),salt:i,iterations:a,keySize:c,iv:u}}function mc(r){return qr(r.valueBlock.value[2].getValue())}function qr(r){return new Uint8Array(r,0,r.byteLength)}async function yc(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 xc(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 xc({privateKey:e[0],publicKey:e[1]});return{privateKey:n[0],publicKey:n[1]}}async function bc(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 wc(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 xc(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 cs(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,zr=class{_key;constructor(t){this._key=t}verify(t,e){return wc(this._key,e,t)}marshal(){return Ne.jwkToPkix(this._key)}get bytes(){return Ae.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}},yr=class{_key;_publicKey;constructor(t,e){this._key=t,this._publicKey=e}genSecret(){return Me(16)}sign(t){return bc(this._key,t)}get public(){if(this._publicKey==null)throw new U("public key not provided","ERR_PUBKEY_NOT_PROVIDED");return new zr(this._publicKey)}marshal(){return Ne.jwkToPkcs1(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}async id(){let t=await this.public.hash();return j(t,"base58btc")}async export(t,e="pkcs-8"){if(e==="pkcs-8")return Ne.exportToPem(this,t);if(e==="libp2p-key")return lr(this.bytes,t);throw new U(`export format '${e}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};async function Ho(r){let t=Ne.pkcs1ToJwk(r);if(cs(t)>Gr)throw new U("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await Mo(t);return new yr(e.privateKey,e.publicKey)}function _h(r){let t=Ne.pkixToJwk(r);if(cs(t)>Gr)throw new U("key size is too large","ERR_KEY_SIZE_TOO_LARGE");return new zr(t)}async function Uh(r){if(cs(r)>Gr)throw new U("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await Mo(r);return new yr(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 yc(r);return new yr(t.privateKey,t.publicKey)}var jo={};lt(jo,{Secp256k1PrivateKey:()=>Wr,Secp256k1PublicKey:()=>jr,generateKeyPair:()=>jh,unmarshalSecp256k1PrivateKey:()=>zh,unmarshalSecp256k1PublicKey:()=>Gh});var Dh=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]),Te=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Le=new Uint32Array(64),$o=class extends sr{constructor(){super(64,32,8,!1),this.A=Te[0]|0,this.B=Te[1]|0,this.C=Te[2]|0,this.D=Te[3]|0,this.E=Te[4]|0,this.F=Te[5]|0,this.G=Te[6]|0,this.H=Te[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)Le[u]=t.getUint32(e,!1);for(let u=16;u<64;u++){let h=Le[u-15],m=Le[u-2],g=Ct(h,7)^Ct(h,18)^h>>>3,d=Ct(m,17)^Ct(m,19)^m>>>10;Le[u]=d+Le[u-7]+g+Le[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+Ji(a,c,l)+Dh[u]+Le[u]|0,d=(Ct(n,2)^Ct(n,13)^Ct(n,22))+Xi(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(){Le.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var vc=sn(()=>new $o);function Ph(r){let t=Lr(r);Mt(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:Oh,hexToBytes:Vh}=cn,$e={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(r){let{Err:t}=$e;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:Oh(n),l:r.subarray(e+2)}},toSig(r){let{Err:t}=$e,e=typeof r=="string"?Vh(r):r;ir(e);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}=$e._parseInt(e.subarray(2)),{d:i,l:a}=$e._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}`}},fe=BigInt(0),_t=BigInt(1),bm=BigInt(2),Ec=BigInt(3),wm=BigInt(4);function Fh(r){let t=Ph(r),{Fp:e}=t,n=t.toBytes||((g,d,p)=>{let y=d.toAffine();return Xt(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"&&fe<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(we(g)&&(g=Zt(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:Jt(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,Ec),{px:v,py:w,pz:T}=this,x=e.ZERO,A=e.ZERO,R=e.ZERO,N=e.mul(v,v),z=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(z,A),A=e.add(z,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,z),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,z=t.a,K=e.mul(t.b,Ec),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(z,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(z,rt),E=e.mul(K,E),nt=e.add(nt,rt),rt=e.sub(P,rt),rt=e.mul(z,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===fe)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>fe||x>fe;)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:z}=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=z.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===fe||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 Zt(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=fn(u,t.endo?Math.ceil(h/2):h);return{CURVE:t,ProjectivePoint:u,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:i}}function Hh(r){let t=Lr(r);return Mt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Bc(r){let t=Hh(r),{Fp:e,n}=t,s=e.BYTES+1,o=2*e.BYTES+1;function i(E){return fe<E&&E<e.ORDER}function a(E){return Y(E,n)}function c(E){return ln(E,n)}let{ProjectivePoint:l,normPrivateKeyToScalar:f,weierstrassEquation:u,isWithinCurveOrder:h}=Fh({...t,toBytes(E,I,O){let B=I.toAffine(),b=e.toBytes(B.x),k=Xt;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=Jt(B);if(!i(b))throw new Error("Point is not on curve");let k=u(b),L;try{L=e.sqrt(k)}catch(F){let q=F instanceof Error?": "+F.message:"";throw new Error("Point is not on curve"+q)}let _=(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=>Zt(ve(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)=>Jt(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}=$e.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),q=a(-k*F),M=a(B*F),$=l.BASE.multiplyAndAddUnsafe(V,q,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 De(this.toDERHex())}toDERHex(){return $e.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return De(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 la(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=we(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=Jt(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=Tr(t.nBitLength);function z(E){if(typeof E!="bigint")throw new Error("bigint expected");if(!(fe<=E&&E<N))throw new Error(`bigint expected < 2^${t.nBitLength}`);return ve(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),q=[z(F),z(V)];if(_!=null&&_!==!1){let Q=_===!0?b(e.BYTES):_;q.push(et("extraEntropy",Q))}let M=Xt(...q),$=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===fe)return;let zt=a(dt*a($+yt*F));if(zt===fe)return;let _e=(it.x===yt?0:2)|Number(it.y&_t),Sr=zt;return k&&g(zt)&&(Sr=d(zt),_e^=1),new y(yt,Sr,_e)}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"||we(b))try{_=y.fromDER(b)}catch(it){if(!(it instanceof $e.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:q}=_,M=R(I),$=c(q),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 Mh(r){return{hash:r,hmac:(t,...e)=>Dr(r,t,nn(...e)),randomBytes:nr}}function Ac(r,t){let e=n=>Bc({...r,...Mh(n)});return Object.freeze({...e(t),create:e})}var Ic=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Sc=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Kh=BigInt(1),qo=BigInt(2),kc=(r,t)=>(r+t/qo)/t;function $h(r){let t=Ic,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(!zo.eql(zo.sqr(A),r))throw new Error("Cannot find square root");return A}var zo=un(Ic,void 0,void 0,{sqrt:$h}),Ft=Ac({a:BigInt(0),b:BigInt(7),Fp:zo,n:Sc,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Sc,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Kh*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=e,i=BigInt("0x100000000000000000000000000000000"),a=kc(o*r,t),c=kc(-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}}}},vc),Rm=BigInt(0);var Nm=Ft.ProjectivePoint;function Rc(){return Ft.utils.randomPrivateKey()}function Nc(r,t){let e=pt.digest(t instanceof Uint8Array?t:t.subarray());if(Tt(e))return e.then(({digest:n})=>Ft.sign(n,r).toDERRawBytes()).catch(n=>{throw new U(String(n),"ERR_INVALID_INPUT")});try{return Ft.sign(e.digest,r).toDERRawBytes()}catch(n){throw new U(String(n),"ERR_INVALID_INPUT")}}function Tc(r,t,e){let n=pt.digest(e instanceof Uint8Array?e:e.subarray());if(Tt(n))return n.then(({digest:s})=>Ft.verify(t,s,r)).catch(s=>{throw new U(String(s),"ERR_INVALID_INPUT")});try{return Ft.verify(t,n.digest,r)}catch(s){throw new U(String(s),"ERR_INVALID_INPUT")}}function Lc(r){return Ft.ProjectivePoint.fromHex(r).toRawBytes(!0)}function _c(r){try{Ft.getPublicKey(r,!0)}catch(t){throw new U(String(t),"ERR_INVALID_PRIVATE_KEY")}}function Go(r){try{Ft.ProjectivePoint.fromHex(r)}catch(t){throw new U(String(t),"ERR_INVALID_PUBLIC_KEY")}}function Uc(r){try{return Ft.getPublicKey(r,!0)}catch(t){throw new U(String(t),"ERR_INVALID_PRIVATE_KEY")}}var jr=class{_key;constructor(t){Go(t),this._key=t}verify(t,e){return Tc(this._key,e,t)}marshal(){return Lc(this._key)}get bytes(){return Ae.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}},Wr=class{_key;_publicKey;constructor(t,e){this._key=t,this._publicKey=e??Uc(t),_c(this._key),Go(this._publicKey)}sign(t){return Nc(this._key,t)}get public(){return new jr(this._publicKey)}marshal(){return this._key}get bytes(){return Se.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 j(t,"base58btc")}async export(t,e="libp2p-key"){if(e==="libp2p-key")return lr(this.bytes,t);throw new U(`export format '${e}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function zh(r){return new Wr(r)}function Gh(r){return new jr(r)}async function jh(){let r=Rc();return new Wr(r)}var Cc={rsa:Ko,ed25519:_o,secp256k1:jo};function Wh(r){let t=Object.keys(Cc).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 Cc[r];throw Wh(r)}async function Dc(r,t){return Wo(r).generateKeyPair(t??2048)}function Pc(r,t){return t=(t??"rsa").toLowerCase(),Wo(t),r.bytes}function Oc(r,t){return t=(t??"rsa").toLowerCase(),Wo(t),r.bytes}var Vc=async()=>{let r=await Dc("Ed25519"),t=await Yh(r);if(t.type==="Ed25519")return t;throw new Error(`Generated unexpected PeerId type "${t.type}"`)};async function Yh(r){return zi(Pc(r.public),Oc(r))}var ls=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 Fc=45,Zh=15,br=new ls;function Yo(r){if(!(r.length>Zh))return br.new(r).parseWith(()=>br.readIPv4Addr())}function Zo(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Fc))return br.new(r).parseWith(()=>br.readIPv6Addr())}function us(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Fc))return br.new(r).parseWith(()=>br.readIPAddr())}function fs(r){return!!Yo(r)}function hs(r){return!!Zo(r)}function ds(r){return!!us(r)}var Mc=As(Hc(),1),Jh=["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"],Xh=Jh.map(r=>new Mc.Netmask(r));function Qh(r){for(let t of Xh)if(t.contains(r))return!0;return!1}function td(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 fs(r)?Qh(r):hs(r)?td(r):void 0}var ly=parseInt("0xFFFF",16),uy=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var qc=fs,od=hs,Xo=function(r){let t=0;if(r=r.toString().trim(),qc(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(od(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let o=qc(e[n]),i;o&&(i=Xo(e[n]),e[n]=j(i.slice(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,j(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")},zc=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 wr={},Qo={},ad=[[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"]];ad.forEach(r=>{let t=cd(...r);Qo[t.code]=t,wr[t.name]=t});function cd(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(wr[r]!=null)return wr[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var zy=W("ip4"),Gy=W("ip6"),jy=W("ipcidr");function ei(r,t){switch(W(r).code){case 4:case 41:return ud(t);case 42:return Wc(t);case 6:case 273:case 33:case 132:return Zc(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Wc(t);case 421:return pd(t);case 444:return Yc(t);case 445:return Yc(t);case 466:return dd(t);default:return j(t,"base16")}}function ri(r,t){switch(W(r).code){case 4:return Gc(t);case 41:return Gc(t);case 42:return jc(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 jc(t);case 421:return fd(t);case 444:return gd(t);case 445:return md(t);case 466:return hd(t);default:return Z(t,"base16")}}var ti=Object.values(ge).map(r=>r.decoder),ld=function(){let r=ti[0].or(ti[1]);return ti.slice(2).forEach(t=>r=r.or(t)),r}();function Gc(r){if(!ds(r))throw new Error("invalid ip address");return Xo(r)}function ud(r){let t=zc(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!ds(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 Zc(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function jc(r){let t=Z(r),e=Uint8Array.from(Ee(t.length));return Bt([e,t],e.length+t.length)}function Wc(r){let t=ee(r);if(r=r.slice(ut(t)),r.length!==t)throw new Error("inconsistent lengths");return j(r)}function fd(r){let t;r[0]==="Q"||r[0]==="1"?t=Ue(at.decode(`z${r}`)).bytes:t=Ut.parse(r).multihash.bytes;let e=Uint8Array.from(Ee(t.length));return Bt([e,t],e.length+t.length)}function hd(r){let t=ld.decode(r),e=Uint8Array.from(Ee(t.length));return Bt([e,t],e.length+t.length)}function dd(r){let t=ee(r),e=r.slice(ut(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+j(e,"base64url")}function pd(r){let t=ee(r),e=r.slice(ut(t));if(e.length!==t)throw new Error("inconsistent lengths");return j(e,"base58btc")}function gd(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=jt.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 md(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=jt.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 Yc(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=j(t,"base32"),s=Zc(e);return`${n}:${s}`}function Jc(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 Qc("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:Xc(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=ee(r,s),i=ut(o),a=W(o),c=yd(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 Qc("Invalid address Uint8Array: "+j(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:Xc(e),tuples:t,stringTuples:e,path:n}}function Xc(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(Ee(e.code));return t.length>1&&t[1]!=null&&(n=Bt([n,t[1]])),n}))}function yd(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=ee(t instanceof Uint8Array?t:Uint8Array.from(t));return e+ut(e)}}function si(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}function Qc(r){return new Error("Error parsing address: "+r)}var bd=Symbol.for("nodejs.util.inspect.custom"),ai=Symbol.for("@multiformats/js-multiaddr/multiaddr"),wd=[W("dns").code,W("dns4").code,W("dns6").code,W("dnsaddr").code],ps=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=Jc(t)}else if(el(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??""}`),wd.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===wr.p2p.code&&t.push([n,s]),n===wr["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?j(at.decode(`z${n}`),"base58btc"):j(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=tl.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=>xr(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)}[bd](){return`Multiaddr(${this.#e})`}};var tl=new Map;function el(r){return!!r?.[ai]}function xr(r){return new ps(r)}function xd(r){return r[Symbol.asyncIterator]!=null}function vd(r){if(xd(r))return(async()=>{for await(let t of r)return t})();for(let t of r)return t}var ci=vd;var nl=Symbol.for("@achingbrain/uint8arraylist");function rl(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 gs(r){return!!r?.[nl]}var vr=class r{bufs;length;[nl]=!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(gs(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(gs(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=rl(this.bufs,t);return e.buf[e.index]}set(t,e){let n=rl(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(gs(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(!gs(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=Wt(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=Wt(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=Wt(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=Wt(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=Wt(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=Wt(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=Wt(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=Wt(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 ms(r){return r[Symbol.asyncIterator]!=null}var ys=r=>{let t=ut(r),e=wt(t);return Ee(r,e),ys.bytes=t,e};ys.bytes=0;function Zr(r,t){t=t??{};let e=t.lengthEncoder??ys;function*n(s){let o=e(s.byteLength);o instanceof Uint8Array?yield o:yield*o,s instanceof Uint8Array?yield s:yield*s}return ms(r)?async function*(){for await(let s of r)yield*n(s)}():function*(){for(let s of r)yield*n(s)}()}Zr.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??ys;return new vr(e(r.byteLength),r)};var Er=As(il(),1);var Bd=8,Ad=1024*1024*4,qe;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(qe||(qe={}));var li=r=>{let t=ee(r);return li.bytes=ut(t),t};li.bytes=0;function Br(r,t){let e=new vr,n=qe.LENGTH,s=-1,o=t?.lengthDecoder??li,i=t?.maxLengthLength??Bd,a=t?.maxDataLength??Ad;function*c(){for(;e.byteLength>0;){if(n===qe.LENGTH)try{if(s=o(e),s<0)throw(0,Er.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(s>a)throw(0,Er.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=qe.DATA}catch(l){if(l instanceof RangeError){if(e.byteLength>i)throw(0,Er.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw l}if(n===qe.DATA){if(e.byteLength<s)break;let l=e.sublist(0,s);e.consume(s),t?.onData!=null&&t.onData(l),yield l,n=qe.LENGTH}}}return ms(r)?async function*(){for await(let l of r)e.append(l),yield*c();if(e.byteLength>0)throw(0,Er.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,Er.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}Br.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 Br(n,{...t??{},onLength:o=>{e=o}})};function kd(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 al=kd;function Id(r){return r[Symbol.asyncIterator]!=null}function Rd(r,t){let e=0;if(Id(r))return async function*(){for await(let c of r)yield t(c,e++)}();let n=al(r),{value:s,done:o}=n.next();if(o===!0)return function*(){}();let i=t(s,e++);if(typeof i.then=="function")return async function*(){yield await i;for await(let c of n)yield t(c,e++)}();let a=t;return function*(){yield i;for(let c of n)yield a(c,e++)}()}var cl=Rd;function he(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var bs=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=he(),a=he(),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=he(),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 bs("task-complete"))},p=>{d.done=!0,d.err=p,s.dispatchEvent(new bs("task-complete"))})}c=!0,s.dispatchEvent(new bs("task-complete"))}catch(g){l=g,s.dispatchEvent(new bs("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=he(),await a.promise),l!=null)throw l;if(n?yield*h():yield*m(),c&&o.length===0)break}}var ws=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}},Ar=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new ws(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 ws(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 xs(r={}){return Nd(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 Nd(r,t){t=t??{};let e=t.onEnd,n=new Ar,s,o,i,a=he(),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=he()})}},l=p=>o!=null?o(p):(n.push(p),s),f=p=>(n=new Ar,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 Ar,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 Td(r){return r[Symbol.asyncIterator]!=null}function Ld(...r){let t=[];for(let e of r)Td(e)||t.push(e);return t.length===r.length?function*(){for(let e of t)yield*e}():async function*(){let e=xs({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 ll=Ld;function di(r,...t){if(r==null)throw new Error("Empty pipeline");if(hi(r)){let n=r;r=()=>n.source}else if(fl(r)||ul(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]=Ud(e[n]));return _d(...e)}var _d=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},ul=r=>r?.[Symbol.asyncIterator]!=null,fl=r=>r?.[Symbol.iterator]!=null,hi=r=>r==null?!1:r.sink!=null&&r.source!=null,Ud=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=xs({objectMode:!0});e.then(()=>{n.end()},i=>{n.end(i)});let s,o=r.source;if(ul(o))s=async function*(){yield*o,n.end()};else if(fl(o))s=function*(){yield*o,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return ll(n,s())}return r.source};var hl="libp2p",dl="autonat",pl="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=()=>fr(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=()=>fr(s)}(n=r.ResponseStatus||(r.ResponseStatus={}));let o;(function(l){let f;l.codec=()=>(f==null&&(f=se((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=>ne(u,l.codec()),l.decode=u=>re(u,l.codec())})(o=r.PeerInfo||(r.PeerInfo={}));let i;(function(l){let f;l.codec=()=>(f==null&&(f=se((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=>ne(u,l.codec()),l.decode=u=>re(u,l.codec())})(i=r.Dial||(r.Dial={}));let a;(function(l){let f;l.codec=()=>(f==null&&(f=se((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=>ne(u,l.codec()),l.decode=u=>re(u,l.codec())})(a=r.DialResponse||(r.DialResponse={}));let c;r.codec=()=>(c==null&&(c=se((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=>ne(l,r.codec()),r.decode=l=>re(l,r.codec())})(D||(D={}));var pi=4,vs=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??hl}/${dl}/${pl}`,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",Ss))};e.addEventListener("abort",n,{once:!0}),ks(1/0,e);let s=this.components.addressManager.getAddresses().map(o=>o.toOptions().host);try{let o=this;await di(t.stream,i=>Br(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=Qr(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=>xr(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.dialTransportForMultiaddr(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=>Zr(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);ks(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 Vc()).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",Ss))},n.addEventListener("abort",h,{once:!0});let d=await di([o],y=>Zr(y),g,y=>Br(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(cl(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]:xr(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 Fd(r={}){return t=>new vs(t,r)}return Rl(Hd);})();
8
- /*! Bundled license information:
9
-
10
- pvtsutils/build/index.js:
11
- (*!
12
- * MIT License
13
- *
14
- * Copyright (c) 2017-2022 Peculiar Ventures, LLC
15
- *
16
- * Permission is hereby granted, free of charge, to any person obtaining a copy
17
- * of this software and associated documentation files (the "Software"), to deal
18
- * in the Software without restriction, including without limitation the rights
19
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20
- * copies of the Software, and to permit persons to whom the Software is
21
- * furnished to do so, subject to the following conditions:
22
- *
23
- * The above copyright notice and this permission notice shall be included in all
24
- * copies or substantial portions of the Software.
25
- *
26
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32
- * SOFTWARE.
33
- *
34
- *)
35
-
36
- @noble/hashes/esm/utils.js:
37
- (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
38
-
39
- @noble/curves/esm/abstract/utils.js:
40
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
41
-
42
- @noble/curves/esm/abstract/modular.js:
43
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
44
-
45
- @noble/curves/esm/abstract/curve.js:
46
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
47
-
48
- @noble/curves/esm/abstract/edwards.js:
49
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
50
-
51
- @noble/curves/esm/ed25519.js:
52
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
53
-
54
- pvutils/build/utils.es.js:
55
- (*!
56
- Copyright (c) Peculiar Ventures, LLC
57
- *)
58
-
59
- asn1js/build/index.es.js:
60
- (*!
61
- * Copyright (c) 2014, GMO GlobalSign
62
- * Copyright (c) 2015-2022, Peculiar Ventures
63
- * All rights reserved.
64
- *
65
- * Author 2014-2019, Yury Strozhevsky
66
- *
67
- * Redistribution and use in source and binary forms, with or without modification,
68
- * are permitted provided that the following conditions are met:
69
- *
70
- * * Redistributions of source code must retain the above copyright notice, this
71
- * list of conditions and the following disclaimer.
72
- *
73
- * * Redistributions in binary form must reproduce the above copyright notice, this
74
- * list of conditions and the following disclaimer in the documentation and/or
75
- * other materials provided with the distribution.
76
- *
77
- * * Neither the name of the copyright holder nor the names of its
78
- * contributors may be used to endorse or promote products derived from
79
- * this software without specific prior written permission.
80
- *
81
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
82
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
83
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
84
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
85
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
86
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
87
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
88
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
89
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
90
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
91
- *
92
- *)
93
-
94
- @noble/curves/esm/abstract/weierstrass.js:
95
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
96
-
97
- @noble/curves/esm/_shortw_utils.js:
98
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
99
-
100
- @noble/curves/esm/secp256k1.js:
101
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
102
- */
2
+ "use strict";var Libp2PAutonat=(()=>{var xn=Object.create;var Nt=Object.defineProperty;var En=Object.getOwnPropertyDescriptor;var An=Object.getOwnPropertyNames;var In=Object.getPrototypeOf,Sn=Object.prototype.hasOwnProperty;var ur=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),N=(r,t)=>{for(var e in t)Nt(r,e,{get:t[e],enumerable:!0})},lr=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of An(t))!Sn.call(r,o)&&o!==e&&Nt(r,o,{get:()=>t[o],enumerable:!(n=En(t,o))||n.enumerable});return r};var hr=(r,t,e)=>(e=r!=null?xn(In(r)):{},lr(t||!r||!r.__esModule?Nt(e,"default",{value:r,enumerable:!0}):e,r)),vn=r=>lr(Nt({},"__esModule",{value:!0}),r);var Or=ur(vt=>{(function(){var r,t,e,n,o,i,c,u;u=function(f){var s,l,a,h;return s=(f&255<<24)>>>24,l=(f&255<<16)>>>16,a=(f&65280)>>>8,h=f&255,[s,l,a,h].join(".")},c=function(f){var s,l,a,h,p,d;for(s=[],a=h=0;h<=3&&f.length!==0;a=++h){if(a>0){if(f[0]!==".")throw new Error("Invalid IP");f=f.substring(1)}d=t(f),p=d[0],l=d[1],f=f.substring(l),s.push(p)}if(f.length!==0)throw new Error("Invalid IP");switch(s.length){case 1:if(s[0]>4294967295)throw new Error("Invalid IP");return s[0]>>>0;case 2:if(s[0]>255||s[1]>16777215)throw new Error("Invalid IP");return(s[0]<<24|s[1])>>>0;case 3:if(s[0]>255||s[1]>255||s[2]>65535)throw new Error("Invalid IP");return(s[0]<<24|s[1]<<16|s[2])>>>0;case 4:if(s[0]>255||s[1]>255||s[2]>255||s[3]>255)throw new Error("Invalid IP");return(s[0]<<24|s[1]<<16|s[2]<<8|s[3])>>>0;default:throw new Error("Invalid IP")}},e=function(f){return f.charCodeAt(0)},n=e("0"),i=e("a"),o=e("A"),t=function(f){var s,l,a,h,p;for(h=0,s=10,l="9",a=0,f.length>1&&f[a]==="0"&&(f[a+1]==="x"||f[a+1]==="X"?(a+=2,s=16):"0"<=f[a+1]&&f[a+1]<="9"&&(a++,s=8,l="7")),p=a;a<f.length;){if("0"<=f[a]&&f[a]<=l)h=h*s+(e(f[a])-n)>>>0;else if(s===16)if("a"<=f[a]&&f[a]<="f")h=h*s+(10+e(f[a])-i)>>>0;else if("A"<=f[a]&&f[a]<="F")h=h*s+(10+e(f[a])-o)>>>0;else break;else break;if(h>4294967295)throw new Error("too large");a++}if(a===p)throw new Error("empty octet");return[h,a]},r=function(){function f(s,l){var a,h,p,d;if(typeof s!="string")throw new Error("Missing `net' parameter");if(l||(d=s.split("/",2),s=d[0],l=d[1]),l||(l=32),typeof l=="string"&&l.indexOf(".")>-1){try{this.maskLong=c(l)}catch(m){throw a=m,new Error("Invalid mask: "+l)}for(h=p=32;p>=0;h=--p)if(this.maskLong===4294967295<<32-h>>>0){this.bitmask=h;break}}else if(l||l===0)this.bitmask=parseInt(l,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(c(s)&this.maskLong)>>>0}catch(m){throw a=m,new Error("Invalid net address: "+s)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+l);this.size=Math.pow(2,32-this.bitmask),this.base=u(this.netLong),this.mask=u(this.maskLong),this.hostmask=u(~this.maskLong),this.first=this.bitmask<=30?u(this.netLong+1):this.base,this.last=this.bitmask<=30?u(this.netLong+this.size-2):u(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?u(this.netLong+this.size-1):void 0}return f.prototype.contains=function(s){return typeof s=="string"&&(s.indexOf("/")>0||s.split(".").length!==4)&&(s=new f(s)),s instanceof f?this.contains(s.base)&&this.contains(s.broadcast||s.last):(c(s)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},f.prototype.next=function(s){return s==null&&(s=1),new f(u(this.netLong+this.size*s),this.mask)},f.prototype.forEach=function(s){var l,a,h;for(h=c(this.first),a=c(this.last),l=0;h<=a;)s(u(h),h,l),l++,h++},f.prototype.toString=function(){return this.base+"/"+this.bitmask},f}(),vt.ip2long=c,vt.long2ip=u,vt.Netmask=r}).call(vt)});var rn=ur((Uc,en)=>{"use strict";function tn(r,t){for(let e in t)Object.defineProperty(r,e,{value:t[e],enumerable:!0,configurable:!0});return r}function di(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 tn(r,e)}catch{e.message=r.message,e.stack=r.stack;let o=function(){};return o.prototype=Object.create(Object.getPrototypeOf(r)),tn(new o,e)}}en.exports=di});var Mi={};N(Mi,{autoNAT:()=>Bi});var fr=Symbol.for("@libp2p/peer-id");var W=class extends Error{code;props;constructor(t,e,n){super(t),this.code=e,this.name=n?.name??"CodeError",this.props=n??{}}};var te="ERR_TIMEOUT";var ee=(r,...t)=>{try{[...t]}catch{}};var se={};N(se,{base58btc:()=>S,base58flickr:()=>Nn});var qi=new Uint8Array(0);function dr(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 M(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 pr(r){return new TextEncoder().encode(r)}function mr(r){return new TextDecoder().decode(r)}function Ln(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 o=0;o<r.length;o++){var i=r.charAt(o),c=i.charCodeAt(0);if(e[c]!==255)throw new TypeError(i+" is ambiguous");e[c]=o}var u=r.length,f=r.charAt(0),s=Math.log(u)/Math.log(256),l=Math.log(256)/Math.log(u);function a(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var m=0,g=0,E=0,T=d.length;E!==T&&d[E]===0;)E++,m++;for(var I=(T-E)*l+1>>>0,F=new Uint8Array(I);E!==T;){for(var _=d[E],q=0,P=I-1;(_!==0||q<g)&&P!==-1;P--,q++)_+=256*F[P]>>>0,F[P]=_%u>>>0,_=_/u>>>0;if(_!==0)throw new Error("Non-zero carry");g=q,E++}for(var B=I-g;B!==I&&F[B]===0;)B++;for(var Ft=f.repeat(m);B<I;++B)Ft+=r.charAt(F[B]);return Ft}function h(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var m=0;if(d[m]!==" "){for(var g=0,E=0;d[m]===f;)g++,m++;for(var T=(d.length-m)*s+1>>>0,I=new Uint8Array(T);d[m];){var F=e[d.charCodeAt(m)];if(F===255)return;for(var _=0,q=T-1;(F!==0||_<E)&&q!==-1;q--,_++)F+=u*I[q]>>>0,I[q]=F%256>>>0,F=F/256>>>0;if(F!==0)throw new Error("Non-zero carry");E=_,m++}if(d[m]!==" "){for(var P=T-E;P!==T&&I[P]===0;)P++;for(var B=new Uint8Array(g+(T-P)),Ft=g;P!==T;)B[Ft++]=I[P++];return B}}}function p(d){var m=h(d);if(m)return m;throw new Error(`Non-${t} character`)}return{encode:a,decodeUnsafe:h,decode:p}}var Rn=Ln,Tn=Rn,wr=Tn;var re=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")}},ne=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 yr(this,t)}},oe=class{decoders;constructor(t){this.decoders=t}or(t){return yr(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 yr(r,t){return new oe({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var ie=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new re(t,e,n),this.decoder=new ne(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function nt({name:r,prefix:t,encode:e,decode:n}){return new ie(r,t,e,n)}function j({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=wr(e,r);return nt({prefix:t,name:r,encode:n,decode:i=>M(o(i))})}function Dn(r,t,e,n){let o={};for(let l=0;l<t.length;++l)o[t[l]]=l;let i=r.length;for(;r[i-1]==="=";)--i;let c=new Uint8Array(i*e/8|0),u=0,f=0,s=0;for(let l=0;l<i;++l){let a=o[r[l]];if(a===void 0)throw new SyntaxError(`Non-${n} character`);f=f<<e|a,u+=e,u>=8&&(u-=8,c[s++]=255&f>>u)}if(u>=e||255&f<<8-u)throw new SyntaxError("Unexpected end of data");return c}function Fn(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,i="",c=0,u=0;for(let f=0;f<r.length;++f)for(u=u<<8|r[f],c+=8;c>e;)c-=e,i+=t[o&u>>c];if(c!==0&&(i+=t[o&u<<e-c]),n)for(;i.length*e&7;)i+="=";return i}function x({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return nt({prefix:t,name:r,encode(o){return Fn(o,n,e)},decode(o){return Dn(o,n,e,r)}})}var S=j({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Nn=j({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ae={};N(ae,{base10:()=>Un});var Un=j({prefix:"9",name:"base10",alphabet:"0123456789"});var ce={};N(ce,{base16:()=>_n,base16upper:()=>kn});var _n=x({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),kn=x({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ue={};N(ue,{base2:()=>Pn});var Pn=x({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var le={};N(le,{base256emoji:()=>zn});var br=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}"),On=br.reduce((r,t,e)=>(r[e]=t,r),[]),Cn=br.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function Bn(r){return r.reduce((t,e)=>(t+=On[e],t),"")}function Mn(r){let t=[];for(let e of r){let n=Cn[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var zn=nt({prefix:"\u{1F680}",name:"base256emoji",encode:Bn,decode:Mn});var he={};N(he,{base32:()=>z,base32hex:()=>qn,base32hexpad:()=>Hn,base32hexpadupper:()=>Xn,base32hexupper:()=>jn,base32pad:()=>$n,base32padupper:()=>Gn,base32upper:()=>Vn,base32z:()=>Kn});var z=x({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Vn=x({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),$n=x({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Gn=x({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),qn=x({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),jn=x({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Hn=x({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Xn=x({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Kn=x({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var fe={};N(fe,{base36:()=>Qn,base36upper:()=>Wn});var Qn=j({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Wn=j({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var de={};N(de,{base64:()=>Jn,base64pad:()=>Zn,base64url:()=>Yn,base64urlpad:()=>to});var Jn=x({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Zn=x({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Yn=x({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),to=x({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var pe={};N(pe,{base8:()=>eo});var eo=x({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var me={};N(me,{identity:()=>ro});var ro=nt({prefix:"\0",name:"identity",encode:r=>mr(r),decode:r=>pr(r)});var ss=new TextEncoder,as=new TextDecoder;var we={};N(we,{identity:()=>_t});var io=Ar,xr=128,so=127,ao=~so,co=Math.pow(2,31);function Ar(r,t,e){t=t||[],e=e||0;for(var n=e;r>=co;)t[e++]=r&255|xr,r/=128;for(;r&ao;)t[e++]=r&255|xr,r>>>=7;return t[e]=r|0,Ar.bytes=e-n+1,t}var uo=ge,lo=128,Er=127;function ge(r,n){var e=0,n=n||0,o=0,i=n,c,u=r.length;do{if(i>=u)throw ge.bytes=0,new RangeError("Could not decode varint");c=r[i++],e+=o<28?(c&Er)<<o:(c&Er)*Math.pow(2,o),o+=7}while(c>=lo);return ge.bytes=i-n,e}var ho=Math.pow(2,7),fo=Math.pow(2,14),po=Math.pow(2,21),mo=Math.pow(2,28),go=Math.pow(2,35),wo=Math.pow(2,42),yo=Math.pow(2,49),bo=Math.pow(2,56),xo=Math.pow(2,63),Eo=function(r){return r<ho?1:r<fo?2:r<po?3:r<mo?4:r<go?5:r<wo?6:r<yo?7:r<bo?8:r<xo?9:10},Ao={encode:io,decode:uo,encodingLength:Eo},Io=Ao,yt=Io;function bt(r,t=0){return[yt.decode(r,t),yt.decode.bytes]}function ot(r,t,e=0){return yt.encode(r,t,e),t}function it(r){return yt.encodingLength(r)}function H(r,t){let e=t.byteLength,n=it(r),o=n+it(e),i=new Uint8Array(o+e);return ot(r,i,0),ot(e,i,n),i.set(t,o),new st(r,e,t,i)}function J(r){let t=M(r),[e,n]=bt(t),[o,i]=bt(t.subarray(n)),c=t.subarray(n+i);if(c.byteLength!==o)throw new Error("Incorrect length");return new st(e,o,c,t)}function Ir(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&dr(r.bytes,e.bytes)}}var st=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};var Sr=0,So="identity",vr=M;function vo(r){return H(Sr,vr(r))}var _t={code:Sr,name:So,encode:vr,digest:vo};var xe={};N(xe,{sha256:()=>kt,sha512:()=>Lo});function be({name:r,code:t,encode:e}){return new ye(r,t,e)}var ye=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?H(this.code,e):e.then(n=>H(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Rr(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var kt=be({name:"sha2-256",code:18,encode:Rr("SHA-256")}),Lo=be({name:"sha2-512",code:19,encode:Rr("SHA-512")});function Tr(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return To(e,Ee(r),t??S.encoder);default:return Do(e,Ee(r),t??z.encoder)}}var Dr=new WeakMap;function Ee(r){let t=Dr.get(r);if(t==null){let e=new Map;return Dr.set(r,e),e}return t}var O=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}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!==xt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Fo)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=H(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&&Ir(t.multihash,n.multihash)}toString(t){return Tr(this,t)}toJSON(){return{"/":Tr(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:o,multihash:i,bytes:c}=e;return new r(n,o,i,c??Fr(n,o,i.bytes))}else if(e[No]===!0){let{version:n,multihash:o,code:i}=e,c=J(o);return r.create(n,i,c)}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!==xt)throw new Error(`Version 0 CID must use dag-pb (code: ${xt}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Fr(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,xt,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,o=M(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let i=o.subarray(e.multihashSize-e.digestSize),c=new st(e.multihashCode,e.digestSize,i,o);return[e.version===0?r.createV0(c):r.createV1(e.codec,c),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[a,h]=bt(t.subarray(e));return e+=h,a},o=n(),i=xt;if(o===18?(o=0,e=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let c=e,u=n(),f=n(),s=e+f,l=s-c;return{version:o,codec:i,multihashCode:u,digestSize:f,multihashSize:l,size:s}}static parse(t,e){let[n,o]=Ro(t,e),i=r.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ee(i).set(n,t),i}};function Ro(r,t){switch(r[0]){case"Q":{let e=t??S;return[S.prefix,e.decode(`${S.prefix}${r}`)]}case S.prefix:{let e=t??S;return[S.prefix,e.decode(r)]}case z.prefix:{let e=t??z;return[z.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 To(r,t,e){let{prefix:n}=e;if(n!==S.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let i=e.encode(r).slice(1);return t.set(n,i),i}else return o}function Do(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let i=e.encode(r);return t.set(n,i),i}else return o}var xt=112,Fo=18;function Fr(r,t,e){let n=it(r),o=n+it(t),i=new Uint8Array(o+e.byteLength);return ot(r,i,0),ot(t,i,n),i.set(e,o),i}var No=Symbol.for("@ipld/js-cid/CID");var X={...me,...ue,...pe,...ae,...ce,...he,...fe,...se,...de,...le},Ts={...xe,...we};function Y(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 Uo=Symbol.for("nodejs.util.inspect.custom"),Nr=Object.values(X).map(r=>r.decoder).reduce((r,t)=>r.or(t),X.identity.decoder),Ur=114,_r=36,kr=37,Et=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()})`}[fr]=!0;toString(){return this.string==null&&(this.string=S.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return O.createV1(Ur,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return Y(this.multihash.bytes,t);if(typeof t=="string")return _o(t).equals(this);if(t?.multihash?.bytes!=null)return Y(this.multihash.bytes,t.multihash.bytes);throw new Error("not valid Id")}[Uo](){return`PeerId(${this.toString()})`}},At=class extends Et{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},It=class extends Et{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.multihash.digest}},St=class extends Et{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.multihash.digest}};function _o(r,t){if(t=t??Nr,r.charAt(0)==="1"||r.charAt(0)==="Q"){let e=J(S.decode(`z${r}`));return r.startsWith("12D")?new It({multihash:e}):r.startsWith("16U")?new St({multihash:e}):new At({multihash:e})}return Ae(Nr.decode(r))}function Ae(r){try{let t=J(r);if(t.code===_t.code){if(t.digest.length===_r)return new It({multihash:t});if(t.digest.length===kr)return new St({multihash:t})}if(t.code===kt.code)return new At({multihash:t})}catch{return ko(O.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function ko(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==Ur)throw new Error("Supplied PeerID CID is invalid");let t=r.multihash;if(t.code===kt.code)return new At({multihash:r.multihash});if(t.code===_t.code){if(t.digest.length===_r)return new It({multihash:r.multihash});if(t.digest.length===kr)return new St({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}var Pt=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,o){return this.readAtomically(()=>{let i=0,c=0,u=this.peekChar();if(u===void 0)return;let f=u==="0",s=2**(8*o)-1;for(;;){let l=this.readAtomically(()=>{let a=this.readChar();if(a===void 0)return;let h=Number.parseInt(a,t);if(!Number.isNaN(h))return h});if(l===void 0)break;if(i*=t,i+=l,i>s||(c+=1,e!==void 0&&c>e))return}if(c!==0)return!n&&f&&c>1?void 0:i})}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 o=n*2;if(n<e.length-3){let c=this.readSeparator(":",n,()=>this.readIPv4Addr());if(c!==void 0)return e[o]=c[0],e[o+1]=c[1],e[o+2]=c[2],e[o+3]=c[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];e[o]=i>>8,e[o+1]=i&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),c=16-(n+2),[u]=t(i.subarray(0,c));return e.set(i.subarray(0,u),16-u),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Pr=45,Po=15,at=new Pt;function Ie(r){if(!(r.length>Po))return at.new(r).parseWith(()=>at.readIPv4Addr())}function Se(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Pr))return at.new(r).parseWith(()=>at.readIPv6Addr())}function Ot(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Pr))return at.new(r).parseWith(()=>at.readIPAddr())}function Ct(r){return!!Ie(r)}function Bt(r){return!!Se(r)}function Mt(r){return!!Ot(r)}var Cr=hr(Or(),1),Oo=["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"],Co=Oo.map(r=>new Cr.Netmask(r));function Bo(r){for(let t of Co)if(t.contains(r))return!0;return!1}function Mo(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 ve(r){return Ct(r)?Bo(r):Bt(r)?Mo(r):void 0}function V(r=0){return new Uint8Array(r)}function v(r=0){return new Uint8Array(r)}function Mr(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Br=Mr("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Le=Mr("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=v(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),zo={utf8:Br,"utf-8":Br,hex:X.base16,latin1:Le,ascii:Le,binary:Le,...X},zt=zo;function D(r,t="utf8"){let e=zt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Vo=Math.pow(2,7),$o=Math.pow(2,14),Go=Math.pow(2,21),Re=Math.pow(2,28),Te=Math.pow(2,35),De=Math.pow(2,42),Fe=Math.pow(2,49),y=128,L=127;function A(r){if(r<Vo)return 1;if(r<$o)return 2;if(r<Go)return 3;if(r<Re)return 4;if(r<Te)return 5;if(r<De)return 6;if(r<Fe)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ne(r,t,e=0){switch(A(r)){case 8:t[e++]=r&255|y,r/=128;case 7:t[e++]=r&255|y,r/=128;case 6:t[e++]=r&255|y,r/=128;case 5:t[e++]=r&255|y,r/=128;case 4:t[e++]=r&255|y,r>>>=7;case 3:t[e++]=r&255|y,r>>>=7;case 2:t[e++]=r&255|y,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function qo(r,t,e=0){switch(A(r)){case 8:t.set(e++,r&255|y),r/=128;case 7:t.set(e++,r&255|y),r/=128;case 6:t.set(e++,r&255|y),r/=128;case 5:t.set(e++,r&255|y),r/=128;case 4:t.set(e++,r&255|y),r>>>=7;case 3:t.set(e++,r&255|y),r>>>=7;case 2:t.set(e++,r&255|y),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Ue(r,t){let e=r[t],n=0;if(n+=e&L,e<y||(e=r[t+1],n+=(e&L)<<7,e<y)||(e=r[t+2],n+=(e&L)<<14,e<y)||(e=r[t+3],n+=(e&L)<<21,e<y)||(e=r[t+4],n+=(e&L)*Re,e<y)||(e=r[t+5],n+=(e&L)*Te,e<y)||(e=r[t+6],n+=(e&L)*De,e<y)||(e=r[t+7],n+=(e&L)*Fe,e<y))return n;throw new RangeError("Could not decode varint")}function jo(r,t){let e=r.get(t),n=0;if(n+=e&L,e<y||(e=r.get(t+1),n+=(e&L)<<7,e<y)||(e=r.get(t+2),n+=(e&L)<<14,e<y)||(e=r.get(t+3),n+=(e&L)<<21,e<y)||(e=r.get(t+4),n+=(e&L)*Re,e<y)||(e=r.get(t+5),n+=(e&L)*Te,e<y)||(e=r.get(t+6),n+=(e&L)*De,e<y)||(e=r.get(t+7),n+=(e&L)*Fe,e<y))return n;throw new RangeError("Could not decode varint")}function K(r,t,e=0){return t==null&&(t=v(A(r))),t instanceof Uint8Array?Ne(r,t,e):qo(r,t,e)}function $(r,t=0){return r instanceof Uint8Array?Ue(r,t):jo(r,t)}function k(r,t){t==null&&(t=r.reduce((o,i)=>o+i.length,0));let e=v(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var ha=parseInt("0xFFFF",16),fa=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Lt(r,t="utf8"){let e=zt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}var $r=Ct,Wo=Bt,_e=function(r){let t=0;if(r=r.toString().trim(),$r(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(Wo(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let i=$r(e[n]),c;i&&(c=_e(e[n]),e[n]=D(c.slice(0,2),"base16")),c!=null&&++n<8&&e.splice(n,0,D(c.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 i=[n,1];for(n=9-e.length;n>0;n--)i.push("0");e.splice.apply(e,i)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){let i=parseInt(e[n],16);o[t++]=i>>8&255,o[t++]=i&255}return o}throw new Error("invalid ip address")},Gr=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let o=[];for(let i=0;i<e;i++)o.push(r[t+i]);return o.join(".")}if(e===16){let o=[];for(let i=0;i<e;i+=2)o.push(n.getUint16(t+i).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var ct={},ke={},Zo=[[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"],[481,-1,"http-path"],[777,-1,"memory"]];Zo.forEach(r=>{let t=Yo(...r);ke[t.code]=t,ct[t.name]=t});function Yo(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function b(r){if(typeof r=="number"){if(ke[r]!=null)return ke[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(ct[r]!=null)return ct[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Qa=b("ip4"),Wa=b("ip6"),Ja=b("ipcidr");function Be(r,t){switch(b(r).code){case 4:case 41:return ei(t);case 42:return Ce(t);case 6:case 273:case 33:case 132:return Hr(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Ce(t);case 421:return ii(t);case 444:return jr(t);case 445:return jr(t);case 466:return oi(t);case 481:return globalThis.encodeURIComponent(Ce(t));default:return D(t,"base16")}}function Me(r,t){switch(b(r).code){case 4:return qr(t);case 41:return qr(t);case 42:return Oe(t);case 6:case 273:case 33:case 132:return ze(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Oe(t);case 421:return ri(t);case 444:return si(t);case 445:return ai(t);case 466:return ni(t);case 481:return Oe(globalThis.decodeURIComponent(t));default:return Lt(t,"base16")}}var Pe=Object.values(X).map(r=>r.decoder),ti=function(){let r=Pe[0].or(Pe[1]);return Pe.slice(2).forEach(t=>r=r.or(t)),r}();function qr(r){if(!Mt(r))throw new Error("invalid ip address");return _e(r)}function ei(r){let t=Gr(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!Mt(t))throw new Error("invalid ip address");return t}function ze(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Hr(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Oe(r){let t=Lt(r),e=Uint8Array.from(K(t.length));return k([e,t],e.length+t.length)}function Ce(r){let t=$(r);if(r=r.slice(A(t)),r.length!==t)throw new Error("inconsistent lengths");return D(r)}function ri(r){let t;r[0]==="Q"||r[0]==="1"?t=J(S.decode(`z${r}`)).bytes:t=O.parse(r).multihash.bytes;let e=Uint8Array.from(K(t.length));return k([e,t],e.length+t.length)}function ni(r){let t=ti.decode(r),e=Uint8Array.from(K(t.length));return k([e,t],e.length+t.length)}function oi(r){let t=$(r),e=r.slice(A(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+D(e,"base64url")}function ii(r){let t=$(r),e=r.slice(A(t));if(e.length!==t)throw new Error("inconsistent lengths");return D(e,"base58btc")}function si(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=z.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 o=ze(n);return k([e,o],e.length+o.length)}function ai(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=z.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 o=ze(n);return k([e,o],e.length+o.length)}function jr(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=D(t,"base32"),o=Hr(e);return`${n}:${o}`}function Xr(r){r=Ve(r);let t=[],e=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let i=0;i<o.length;i++){let c=o[i],u=b(c);if(u.size===0){t.push([u.code]),e.push([u.code]);continue}if(i++,i>=o.length)throw Qr("invalid address: "+r);if(u.path===!0){n=Ve(o.slice(i).join("/")),t.push([u.code,Me(u.code,n)]),e.push([u.code,n]);break}let f=Me(u.code,o[i]);t.push([u.code,f]),e.push([u.code,Be(u.code,f)])}return{string:Kr(e),bytes:Ge(t),tuples:t,stringTuples:e,path:n}}function $e(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let i=$(r,o),c=A(i),u=b(i),f=ci(u,r.slice(o+c));if(f===0){t.push([i]),e.push([i]),o+=c;continue}let s=r.slice(o+c,o+c+f);if(o+=f+c,o>r.length)throw Qr("Invalid address Uint8Array: "+D(r,"base16"));t.push([i,s]);let l=Be(i,s);if(e.push([i,l]),u.path===!0){n=l;break}}return{bytes:Uint8Array.from(r),string:Kr(e),tuples:t,stringTuples:e,path:n}}function Kr(r){let t=[];return r.map(e=>{let n=b(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),Ve(t.join("/"))}function Ge(r){return k(r.map(t=>{let e=b(t[0]),n=Uint8Array.from(K(e.code));return t.length>1&&t[1]!=null&&(n=k([n,t[1]])),n}))}function ci(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=$(t instanceof Uint8Array?t:Uint8Array.from(t));return e+A(e)}}function Ve(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}function Qr(r){return new Error("Error parsing address: "+r)}var ui=Symbol.for("nodejs.util.inspect.custom"),qe=Symbol.for("@multiformats/js-multiaddr/multiaddr"),li=[b("dns").code,b("dns4").code,b("dns6").code,b("dnsaddr").code],$t=class r{bytes;#e;#t;#r;#n;[qe]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=$e(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Xr(t)}else if(Jr(t))e=$e(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,o,i="",c=b("tcp"),u=b("udp"),f=b("ip4"),s=b("ip6"),l=b("dns6"),a=b("ip6zone");for(let[p,d]of this.stringTuples())p===a.code&&(i=`%${d??""}`),li.includes(p)&&(e=c.name,o=443,n=`${d??""}${i}`,t=p===l.code?6:4),(p===c.code||p===u.code)&&(e=b(p).name,o=parseInt(d??"")),(p===f.code||p===s.code)&&(e=b(p).name,n=`${d??""}${i}`,t=p===s.code?6:4);if(t==null||e==null||n==null||o==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:o}}protos(){return this.#t.map(([t])=>Object.assign({},b(t)))}protoCodes(){return this.#t.map(([t])=>t)}protoNames(){return this.#t.map(([t])=>b(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(),o=n.lastIndexOf(e);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o))}decapsulateCode(t){let e=this.tuples();for(let n=e.length-1;n>=0;n--)if(e[n][0]===t)return new r(Ge(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===ct.p2p.code&&t.push([n,o]),n===ct["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?D(S.decode(`z${n}`),"base58btc"):D(O.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return Y(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(i=>i.resolvable);if(e==null)return[this];let n=Wr.get(e.name);if(n==null)throw new W(`no available resolver for ${e.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,t)).map(i=>ut(i))}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)}[ui](){return`Multiaddr(${this.#e})`}};var Wr=new Map;function Jr(r){return!!r?.[qe]}function ut(r){return new $t(r)}function hi(r){return r[Symbol.asyncIterator]!=null}function fi(r){if(hi(r))return(async()=>{for await(let t of r)return t})();for(let t of r)return t}var je=fi;var Yr=Symbol.for("@achingbrain/uint8arraylist");function Zr(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function Gt(r){return!!r?.[Yr]}var lt=class r{bufs;length;[Yr]=!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(Gt(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(Gt(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=Zr(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Zr(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(Gt(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:o}=this._subList(t,e);return k(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:k(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),i=new r;return i.length=o,i.bufs=[...n],i}_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=[],o=0;for(let i=0;i<this.bufs.length;i++){let c=this.bufs[i],u=o,f=u+c.byteLength;if(o=f,t>=f)continue;let s=t>=u&&t<f,l=e>u&&e<=f;if(s&&l){if(t===u&&e===f){n.push(c);break}let a=t-u;n.push(c.subarray(a,a+(e-t)));break}if(s){if(t===0){n.push(c);continue}n.push(c.subarray(t-u));continue}if(l){if(e===f){n.push(c);break}n.push(c.subarray(0,e-u));break}n.push(c)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Gt(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 o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,c=new Int32Array(i);for(let a=0;a<i;a++)c[a]=-1;for(let a=0;a<o;a++)c[n[a]]=a;let u=c,f=this.byteLength-n.byteLength,s=n.byteLength-1,l;for(let a=e;a<=f;a+=l){l=0;for(let h=s;h>=0;h--){let p=this.get(a+h);if(n[h]!==p){l=Math.max(1,h-u[p]);break}}if(l===0)return a}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=v(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 o=V(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,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 o=V(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,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 o=V(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,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=v(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 o=V(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,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 o=V(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,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 o=V(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,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 o=V(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,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 o=V(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,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(!Y(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((o,i)=>o+i.byteLength,0)),n.length=e,n}};function qt(r){return r[Symbol.asyncIterator]!=null}var jt=r=>{let t=A(r),e=v(t);return K(r,e),jt.bytes=t,e};jt.bytes=0;function Rt(r,t){t=t??{};let e=t.lengthEncoder??jt;function*n(o){let i=e(o.byteLength);i instanceof Uint8Array?yield i:yield*i,o instanceof Uint8Array?yield o:yield*o}return qt(r)?async function*(){for await(let o of r)yield*n(o)}():function*(){for(let o of r)yield*n(o)}()}Rt.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??jt;return new lt(e(r.byteLength),r)};var ht=hr(rn(),1);var pi=8,mi=1024*1024*4,tt;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(tt||(tt={}));var He=r=>{let t=$(r);return He.bytes=A(t),t};He.bytes=0;function ft(r,t){let e=new lt,n=tt.LENGTH,o=-1,i=t?.lengthDecoder??He,c=t?.maxLengthLength??pi,u=t?.maxDataLength??mi;function*f(){for(;e.byteLength>0;){if(n===tt.LENGTH)try{if(o=i(e),o<0)throw(0,ht.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(o>u)throw(0,ht.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let s=i.bytes;e.consume(s),t?.onLength!=null&&t.onLength(o),n=tt.DATA}catch(s){if(s instanceof RangeError){if(e.byteLength>c)throw(0,ht.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw s}if(n===tt.DATA){if(e.byteLength<o)break;let s=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(s),yield s,n=tt.LENGTH}}}return qt(r)?async function*(){for await(let s of r)e.append(s),yield*f();if(e.byteLength>0)throw(0,ht.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(let s of r)e.append(s),yield*f();if(e.byteLength>0)throw(0,ht.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}ft.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:i,value:c}=await r.next(e);if(i===!0)return;c!=null&&(yield c)}catch(i){if(i.code==="ERR_UNDER_READ")return{done:!0,value:null};throw i}finally{e=1}}();return ft(n,{...t??{},onLength:i=>{e=i}})};function wi(r){let[t,e]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>t.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:t.next(),[e](){return this}}}var nn=wi;function yi(r){return r[Symbol.asyncIterator]!=null}function bi(r,t){let e=0;if(yi(r))return async function*(){for await(let f of r)yield t(f,e++)}();let n=nn(r),{value:o,done:i}=n.next();if(i===!0)return function*(){}();let c=t(o,e++);if(typeof c.then=="function")return async function*(){yield await c;for await(let f of n)yield t(f,e++)}();let u=t;return function*(){yield c;for(let f of n)yield u(f,e++)}()}var on=bi;function G(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Ht=globalThis.CustomEvent??Event;async function*Xe(r,t={}){let e=t.concurrency??1/0;e<1&&(e=1/0);let n=t.ordered==null?!1:t.ordered,o=new EventTarget,i=[],c=G(),u=G(),f=!1,s,l=!1;o.addEventListener("task-complete",()=>{u.resolve()}),Promise.resolve().then(async()=>{try{for await(let d of r){if(i.length===e&&(c=G(),await c.promise),l)break;let m={done:!1};i.push(m),d().then(g=>{m.done=!0,m.ok=!0,m.value=g,o.dispatchEvent(new Ht("task-complete"))},g=>{m.done=!0,m.err=g,o.dispatchEvent(new Ht("task-complete"))})}f=!0,o.dispatchEvent(new Ht("task-complete"))}catch(d){s=d,o.dispatchEvent(new Ht("task-complete"))}});function a(){return n?i[0]?.done:!!i.find(d=>d.done)}function*h(){for(;i.length>0&&i[0].done;){let d=i[0];if(i.shift(),d.ok)yield d.value;else throw l=!0,c.resolve(),d.err;c.resolve()}}function*p(){for(;a();)for(let d=0;d<i.length;d++)if(i[d].done){let m=i[d];if(i.splice(d,1),d--,m.ok)yield m.value;else throw l=!0,c.resolve(),m.err;c.resolve()}}for(;;){if(a()||(u=G(),await u.promise),s!=null)throw s;if(n?yield*h():yield*p(),f&&i.length===0)break}}var Xt=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}},dt=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Xt(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 Xt(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 Ke=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function Kt(r={}){return xi(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 xi(r,t){t=t??{};let e=t.onEnd,n=new dt,o,i,c,u=G(),f=async()=>{try{return n.isEmpty()?c?{done:!0}:await new Promise((g,E)=>{i=T=>{i=null,n.push(T);try{g(r(n))}catch(I){E(I)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{u.resolve(),u=G()})}},s=g=>i!=null?i(g):(n.push(g),o),l=g=>(n=new dt,i!=null?i({error:g}):(n.push({error:g}),o)),a=g=>{if(c)return o;if(t?.objectMode!==!0&&g?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return s({done:!1,value:g})},h=g=>c?o:(c=!0,g!=null?l(g):s({done:!0})),p=()=>(n=new dt,h(),{done:!0}),d=g=>(h(g),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:f,return:p,throw:d,push:a,end:h,get readableLength(){return n.size},onEmpty:async g=>{let E=g?.signal;if(E?.throwIfAborted(),n.isEmpty())return;let T,I;E!=null&&(T=new Promise((F,_)=>{I=()=>{_(new Ke)},E.addEventListener("abort",I)}));try{await Promise.race([u.promise,T])}finally{I!=null&&E!=null&&E?.removeEventListener("abort",I)}}},e==null)return o;let m=o;return o={[Symbol.asyncIterator](){return this},next(){return m.next()},throw(g){return m.throw(g),e!=null&&(e(g),e=void 0),{done:!0}},return(){return m.return(),e!=null&&(e(),e=void 0),{done:!0}},push:a,end(g){return m.end(g),e!=null&&(e(g),e=void 0),o},get readableLength(){return m.readableLength},onEmpty:g=>m.onEmpty(g)},o}function Ei(r){return r[Symbol.asyncIterator]!=null}function Ai(...r){let t=[];for(let e of r)Ei(e)||t.push(e);return t.length===r.length?function*(){for(let e of t)yield*e}():async function*(){let e=Kt({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let o of n)e.push(o)})),e.end()}catch(n){e.end(n)}}),yield*e}()}var sn=Ai;function We(r,...t){if(r==null)throw new Error("Empty pipeline");if(Qe(r)){let n=r;r=()=>n.source}else if(cn(r)||an(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&Qe(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++)Qe(e[n])&&(e[n]=Si(e[n]));return Ii(...e)}var Ii=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},an=r=>r?.[Symbol.asyncIterator]!=null,cn=r=>r?.[Symbol.iterator]!=null,Qe=r=>r==null?!1:r.sink!=null&&r.source!=null,Si=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=Kt({objectMode:!0});e.then(()=>{n.end()},c=>{n.end(c)});let o,i=r.source;if(an(i))o=async function*(){yield*i,n.end()};else if(cn(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return sn(n,o())}return r.source};var un="libp2p",ln="autonat",hn="1.0.0";var Je=new Float32Array([-0]),Q=new Uint8Array(Je.buffer);function fn(r,t,e){Je[0]=r,t[e]=Q[0],t[e+1]=Q[1],t[e+2]=Q[2],t[e+3]=Q[3]}function dn(r,t){return Q[0]=r[t],Q[1]=r[t+1],Q[2]=r[t+2],Q[3]=r[t+3],Je[0]}var Ze=new Float64Array([-0]),R=new Uint8Array(Ze.buffer);function pn(r,t,e){Ze[0]=r,t[e]=R[0],t[e+1]=R[1],t[e+2]=R[2],t[e+3]=R[3],t[e+4]=R[4],t[e+5]=R[5],t[e+6]=R[6],t[e+7]=R[7]}function mn(r,t){return R[0]=r[t],R[1]=r[t+1],R[2]=r[t+2],R[3]=r[t+3],R[4]=r[t+4],R[5]=r[t+5],R[6]=r[t+6],R[7]=r[t+7],Ze[0]}var vi=BigInt(Number.MAX_SAFE_INTEGER),Li=BigInt(Number.MIN_SAFE_INTEGER),U=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 et;if(t<vi&&t>Li)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>gn&&(o=0n,++n>gn&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return et;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}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):et}},et=new U(0,0);et.toBigInt=function(){return 0n};et.zzEncode=et.zzDecode=function(){return this};et.length=function(){return 1};var gn=4294967296n;function wn(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 yn(r,t,e){if(e-t<1)return"";let o,i=[],c=0,u;for(;t<e;)u=r[t++],u<128?i[c++]=u:u>191&&u<224?i[c++]=(u&31)<<6|r[t++]&63:u>239&&u<365?(u=((u&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,i[c++]=55296+(u>>10),i[c++]=56320+(u&1023)):i[c++]=(u&15)<<12|(r[t++]&63)<<6|r[t++]&63,c>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),c=0);return o!=null?(c>0&&o.push(String.fromCharCode.apply(String,i.slice(0,c))),o.join("")):String.fromCharCode.apply(String,i.slice(0,c))}function Ye(r,t,e){let n=e,o,i;for(let c=0;c<r.length;++c)o=r.charCodeAt(c),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((i=r.charCodeAt(c+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++c,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function C(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Qt(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var tr=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,C(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 C(this,4);return Qt(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw C(this,4);return Qt(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw C(this,4);let t=dn(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw C(this,4);let t=mn(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 C(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return yn(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw C(this,t);this.pos+=t}else do if(this.pos>=this.len)throw C(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 U(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 C(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 C(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 C(this,8);let t=Qt(this.buf,this.pos+=4),e=Qt(this.buf,this.pos+=4);return new U(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=Ue(this.buf,this.pos);return this.pos+=A(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 er(r){return new tr(r instanceof Uint8Array?r:r.subarray())}function pt(r,t,e){let n=er(r);return t.decode(n,void 0,e)}function rr(r){let t=r??8192,e=t>>>1,n,o=t;return function(c){if(c<1||c>e)return v(c);o+c>t&&(n=v(t),o=0);let u=n.subarray(o,o+=c);return o&7&&(o=(o|7)+1),u}}var rt=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function nr(){}var ir=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Ri=rr();function Ti(r){return globalThis.Buffer!=null?v(r):Ri(r)}var Dt=class{len;head;tail;states;constructor(){this.len=0,this.head=new rt(nr,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new rt(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new sr((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(Wt,10,U.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=U.fromBigInt(t);return this._push(Wt,e.length(),e)}uint64Number(t){return this._push(Ne,A(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=U.fromBigInt(t).zzEncode();return this._push(Wt,e.length(),e)}sint64Number(t){let e=U.fromNumber(t).zzEncode();return this._push(Wt,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(or,1,t?1:0)}fixed32(t){return this._push(Tt,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=U.fromBigInt(t);return this._push(Tt,4,e.lo)._push(Tt,4,e.hi)}fixed64Number(t){let e=U.fromNumber(t);return this._push(Tt,4,e.lo)._push(Tt,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(fn,4,t)}double(t){return this._push(pn,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(or,1,0):this.uint32(e)._push(Fi,e,t)}string(t){let e=wn(t);return e!==0?this.uint32(e)._push(Ye,e,t):this._push(or,1,0)}fork(){return this.states=new ir(this),this.head=this.tail=new rt(nr,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 rt(nr,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=Ti(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function or(r,t,e){t[e]=r&255}function Di(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var sr=class extends rt{next;constructor(t,e){super(Di,t,e),this.next=void 0}};function Wt(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 Tt(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 Fi(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Dt.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Ni,t,r),this},Dt.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Ui,t,r),this});function Ni(r,t,e){t.set(r,e)}function Ui(r,t,e){r.length<40?Ye(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(Lt(r),e)}function ar(){return new Dt}function mt(r,t){let e=ar();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var gt;(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"})(gt||(gt={}));function Jt(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Zt(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(i,c){let u=t(i);c.int32(u)},n=function(i){let c=i.int32();return t(c)};return Jt("enum",gt.VARINT,e,n)}function wt(r,t){return Jt("message",gt.LENGTH_DELIMITED,r,t)}var w;(function(r){let t;(function(s){s.DIAL="DIAL",s.DIAL_RESPONSE="DIAL_RESPONSE"})(t=r.MessageType||(r.MessageType={}));let e;(function(s){s[s.DIAL=0]="DIAL",s[s.DIAL_RESPONSE=1]="DIAL_RESPONSE"})(e||(e={})),function(s){s.codec=()=>Zt(e)}(t=r.MessageType||(r.MessageType={}));let n;(function(s){s.OK="OK",s.E_DIAL_ERROR="E_DIAL_ERROR",s.E_DIAL_REFUSED="E_DIAL_REFUSED",s.E_BAD_REQUEST="E_BAD_REQUEST",s.E_INTERNAL_ERROR="E_INTERNAL_ERROR"})(n=r.ResponseStatus||(r.ResponseStatus={}));let o;(function(s){s[s.OK=0]="OK",s[s.E_DIAL_ERROR=100]="E_DIAL_ERROR",s[s.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",s[s.E_BAD_REQUEST=200]="E_BAD_REQUEST",s[s.E_INTERNAL_ERROR=300]="E_INTERNAL_ERROR"})(o||(o={})),function(s){s.codec=()=>Zt(o)}(n=r.ResponseStatus||(r.ResponseStatus={}));let i;(function(s){let l;s.codec=()=>(l==null&&(l=wt((a,h,p={})=>{if(p.lengthDelimited!==!1&&h.fork(),a.id!=null&&(h.uint32(10),h.bytes(a.id)),a.addrs!=null)for(let d of a.addrs)h.uint32(18),h.bytes(d);p.lengthDelimited!==!1&&h.ldelim()},(a,h)=>{let p={addrs:[]},d=h==null?a.len:a.pos+h;for(;a.pos<d;){let m=a.uint32();switch(m>>>3){case 1:p.id=a.bytes();break;case 2:p.addrs.push(a.bytes());break;default:a.skipType(m&7);break}}return p})),l),s.encode=a=>mt(a,s.codec()),s.decode=a=>pt(a,s.codec())})(i=r.PeerInfo||(r.PeerInfo={}));let c;(function(s){let l;s.codec=()=>(l==null&&(l=wt((a,h,p={})=>{p.lengthDelimited!==!1&&h.fork(),a.peer!=null&&(h.uint32(10),r.PeerInfo.codec().encode(a.peer,h)),p.lengthDelimited!==!1&&h.ldelim()},(a,h)=>{let p={},d=h==null?a.len:a.pos+h;for(;a.pos<d;){let m=a.uint32();switch(m>>>3){case 1:p.peer=r.PeerInfo.codec().decode(a,a.uint32());break;default:a.skipType(m&7);break}}return p})),l),s.encode=a=>mt(a,s.codec()),s.decode=a=>pt(a,s.codec())})(c=r.Dial||(r.Dial={}));let u;(function(s){let l;s.codec=()=>(l==null&&(l=wt((a,h,p={})=>{p.lengthDelimited!==!1&&h.fork(),a.status!=null&&(h.uint32(8),r.ResponseStatus.codec().encode(a.status,h)),a.statusText!=null&&(h.uint32(18),h.string(a.statusText)),a.addr!=null&&(h.uint32(26),h.bytes(a.addr)),p.lengthDelimited!==!1&&h.ldelim()},(a,h)=>{let p={},d=h==null?a.len:a.pos+h;for(;a.pos<d;){let m=a.uint32();switch(m>>>3){case 1:p.status=r.ResponseStatus.codec().decode(a);break;case 2:p.statusText=a.string();break;case 3:p.addr=a.bytes();break;default:a.skipType(m&7);break}}return p})),l),s.encode=a=>mt(a,s.codec()),s.decode=a=>pt(a,s.codec())})(u=r.DialResponse||(r.DialResponse={}));let f;r.codec=()=>(f==null&&(f=wt((s,l,a={})=>{a.lengthDelimited!==!1&&l.fork(),s.type!=null&&(l.uint32(8),r.MessageType.codec().encode(s.type,l)),s.dial!=null&&(l.uint32(18),r.Dial.codec().encode(s.dial,l)),s.dialResponse!=null&&(l.uint32(26),r.DialResponse.codec().encode(s.dialResponse,l)),a.lengthDelimited!==!1&&l.ldelim()},(s,l)=>{let a={},h=l==null?s.len:s.pos+l;for(;s.pos<h;){let p=s.uint32();switch(p>>>3){case 1:a.type=r.MessageType.codec().decode(s);break;case 2:a.dial=r.Dial.codec().decode(s,s.uint32());break;case 3:a.dialResponse=r.DialResponse.codec().decode(s,s.uint32());break;default:s.skipType(p&7);break}}return a})),f),r.encode=s=>mt(s,r.codec()),r.decode=s=>pt(s,r.codec())})(w||(w={}));var cr=4,Yt=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??un}/${ln}/${hn}`,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 W("handleIncomingAutonatStream timeout",te))};e.addEventListener("abort",n,{once:!0}),ee(1/0,e);try{let o=this;await We(t.stream,i=>ft(i),async function*(i){let c=await je(i);if(c==null){o.log("no message received"),yield w.encode({type:w.MessageType.DIAL_RESPONSE,dialResponse:{status:w.ResponseStatus.E_BAD_REQUEST,statusText:"No message was sent"}});return}let u;try{u=w.decode(c)}catch(f){o.log.error("could not decode message",f),yield w.encode({type:w.MessageType.DIAL_RESPONSE,dialResponse:{status:w.ResponseStatus.E_BAD_REQUEST,statusText:"Could not decode message"}});return}yield w.encode(await o.handleAutonatMessage(u,t.connection,{signal:e}))},i=>Rt(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 handleAutonatMessage(t,e,n){let o=this.components.addressManager.getAddresses().map(a=>a.toOptions().host),i=t.dial;if(i==null)return this.log.error("dial was missing from message"),{type:w.MessageType.DIAL_RESPONSE,dialResponse:{status:w.ResponseStatus.E_BAD_REQUEST,statusText:"No Dial message found in message"}};let c,u=i.peer;if(u==null||u.id==null)return this.log.error("PeerId missing from message"),{type:w.MessageType.DIAL_RESPONSE,dialResponse:{status:w.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{c=Ae(u.id)}catch(a){return this.log.error("invalid PeerId",a),{type:w.MessageType.DIAL_RESPONSE,dialResponse:{status:w.ResponseStatus.E_BAD_REQUEST,statusText:"bad peer id"}}}if(this.log("incoming request from %p",c),!e.remotePeer.equals(c))return this.log("target peer %p did not equal sending peer %p",c,e.remotePeer),{type:w.MessageType.DIAL_RESPONSE,dialResponse:{status:w.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}};let f=u.addrs.map(a=>ut(a)).filter(a=>{let h=a.toOptions().host===e.remoteAddr.toOptions().host;return this.log.trace("request to dial %a was sent from %a is same host %s",a,e.remoteAddr,h),h}).filter(a=>{let h=a.toOptions().host,p=!(ve(h)??!1);return this.log.trace("host %s was public %s",h,p),p}).filter(a=>{let h=a.toOptions().host,p=!o.includes(h);return this.log.trace("host %s was not our host %s",h,p),p}).filter(a=>{let h=!!this.components.transportManager.dialTransportForMultiaddr(a);return this.log.trace("transport for %a is supported %s",a,h),h}).map(a=>(a.getPeerId()==null&&(a=a.encapsulate(`/p2p/${c.toString()}`)),a));if(f.length===0)return this.log("no valid multiaddrs for %p in message",c),{type:w.MessageType.DIAL_RESPONSE,dialResponse:{status:w.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}};this.log("dial multiaddrs %s for peer %p",f.map(a=>a.toString()).join(", "),c);let s="",l=f[0];for await(let a of f){let h;l=a;try{if(h=await this.components.connectionManager.openConnection(a,n),!h.remoteAddr.equals(a))throw this.log.error("tried to dial %a but dialed %a",a,h.remoteAddr),new Error("Unexpected remote address");return this.log("Success %p",c),{type:w.MessageType.DIAL_RESPONSE,dialResponse:{status:w.ResponseStatus.OK,addr:h.remoteAddr.decapsulateCode(b("p2p").code).bytes}}}catch(p){this.log("could not dial %p",c,p),s=p.message}finally{h!=null&&await h.close()}}return{type:w.MessageType.DIAL_RESPONSE,dialResponse:{status:w.ResponseStatus.E_DIAL_ERROR,statusText:s,addr:l.bytes}}}async verifyExternalAddresses(){if(clearTimeout(this.verifyAddressTimeout),!this.isStarted())return;let t=this.components.addressManager,e=t.getObservedAddrs().filter(i=>{let c=i.toOptions();return!(ve(c.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);ee(1/0,n);let o=this;try{this.log("verify multiaddrs %s",e.map(s=>s.toString()).join(", "));let i=w.encode({type:w.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toBytes(),addrs:e.map(s=>s.bytes)}}}),c={},u=[],f=async s=>{let l=()=>{};try{this.log("asking %p to verify multiaddr",s.id);let a=await o.components.connectionManager.openConnection(s.id,{signal:n}),h=await a.newStream(this.protocol,{signal:n});l=()=>{h.abort(new W("verifyAddress timeout",te))},n.addEventListener("abort",l,{once:!0});let p=await We([i],m=>Rt(m),h,m=>ft(m),async m=>je(m));if(p==null){this.log("no response received from %p",a.remotePeer);return}let d=w.decode(p);if(d.type!==w.MessageType.DIAL_RESPONSE||d.dialResponse==null){this.log("invalid autonat response from %p",a.remotePeer);return}if(d.dialResponse.status===w.ResponseStatus.OK){let m=a.remoteAddr.toOptions(),g;if(m.family===4)g=m.host.split(".")[0];else if(m.family===6)g=m.host.split(":")[0];else{this.log('remote address "%s" was not IP4 or IP6?',m.host);return}if(u.includes(g)){this.log("already have response from network segment %d - %s",g,m.host);return}u.push(g)}return d.dialResponse}catch(a){this.log.error("error asking remote to verify multiaddr",a)}finally{n.removeEventListener("abort",l)}};for await(let s of Xe(on(this.components.randomWalk.walk({signal:n}),l=>async()=>f(l)),{concurrency:cr}))try{if(s==null)continue;let l=s.addr==null?e[0]:ut(s.addr);if(this.log("autonat response for %a is %s",l,s.status),s.status===w.ResponseStatus.E_BAD_REQUEST||s.status===w.ResponseStatus.E_DIAL_REFUSED||s.addr==null&&e.length>1)continue;if(!e.some(h=>h.equals(l))){this.log("peer reported %a as %s but it was not in our observed address list",l,s.status);continue}let a=l.toString();if(c[a]==null&&(c[a]={success:0,failure:0}),s.status===w.ResponseStatus.OK?c[a].success++:s.status===w.ResponseStatus.E_DIAL_ERROR&&c[a].failure++,c[a].success===cr){this.log("%a is externally dialable",l),t.confirmObservedAddr(l);return}if(c[a].failure===cr){this.log("%a is not externally dialable",l),t.removeObservedAddr(l);return}}catch(l){this.log.error("could not verify external address",l)}}finally{this.verifyAddressTimeout=setTimeout(this._verifyExternalAddresses,this.refreshInterval)}}};function Bi(r={}){return t=>new Yt(t,r)}return vn(Mi);})();
103
3
  return Libp2PAutonat}));