@libp2p/autonat 1.0.8-8bbd43628 → 1.0.9

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,21 +1,21 @@
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 Fl=Object.create;var tn=Object.defineProperty;var Hl=Object.getOwnPropertyDescriptor;var Ml=Object.getOwnPropertyNames;var $l=Object.getPrototypeOf,Kl=Object.prototype.hasOwnProperty;var en=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),ut=(r,t)=>{for(var e in t)tn(r,e,{get:t[e],enumerable:!0})},Ri=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Ml(t))!Kl.call(r,s)&&s!==e&&tn(r,s,{get:()=>t[s],enumerable:!(n=Hl(t,s))||n.enumerable});return r};var rn=(r,t,e)=>(e=r!=null?Fl($l(r)):{},Ri(t||!r||!r.__esModule?tn(e,"default",{value:r,enumerable:!0}):e,r)),ql=r=>Ri(tn({},"__esModule",{value:!0}),r);var Pa=en(yr=>{"use strict";var Ah="[object ArrayBuffer]",le=class r{static isArrayBuffer(t){return Object.prototype.toString.call(t)===Ah}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",Bh=/^[0-9a-f]+$/i,Ih=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Sh=/^[a-zA-Z0-9-_]+$/,In=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=le.toUint8Array(t),n="";for(let o=0;o<e.length;o++)n+=String.fromCharCode(e[o]);return decodeURIComponent(escape(n))}},_t=class{static toString(t,e=!1){let n=le.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}},Sn=class r{static isHex(t){return typeof t===Co&&Bh.test(t)}static isBase64(t){return typeof t===Co&&Ih.test(t)}static isBase64Url(t){return typeof t===Co&&Sh.test(t)}static ToString(t,e="utf8"){let n=le.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 _t.toString(n,!0);case"utf16":case"utf16be":return _t.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 _t.fromString(t,!0);case"utf16":case"utf16be":return _t.fromString(t);default:throw new Error(`Unknown type of encoding '${e}'`)}}static ToBase64(t){let e=le.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 In.fromString(t);case"utf16":case"utf16be":return _t.fromString(t);case"utf16le":case"usc2":return _t.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 In.toString(t);case"utf16":case"utf16be":return _t.toString(t);case"utf16le":case"usc2":return _t.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=le.toUint8Array(t),n="";for(let s=0;s<e.length;s++)n+=String.fromCharCode(e[s]);return n}static ToHex(t){let e=le.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 _t.toString(t,e)}static FromUtf16String(t,e=!1){return _t.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,"")||""}};Sn.DEFAULT_UTF8_ENCODING="utf8";function kh(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 Rh(...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 Nh(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}yr.BufferSourceConverter=le;yr.Convert=Sn;yr.assign=kh;yr.combine=Rh;yr.isEqual=Nh});var dl=en((w1,hl)=>{"use strict";function fl(r,t){for(let e in t)Object.defineProperty(r,e,{value:t[e],enumerable:!0,configurable:!0});return r}function Hd(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 fl(r,e)}catch{e.message=r.message,e.stack=r.stack;let s=function(){};return s.prototype=Object.create(Object.getPrototypeOf(r)),fl(new s,e)}}hl.exports=Hd});var wl=en(Qr=>{(function(){var r,t,e,n,s,o,i,a;a=function(c){var l,h,u,m;return l=(c&255<<24)>>>24,h=(c&255<<16)>>>16,u=(c&65280)>>>8,m=c&255,[l,h,u,m].join(".")},i=function(c){var l,h,u,m,f,p;for(l=[],u=m=0;m<=3&&c.length!==0;u=++m){if(u>0){if(c[0]!==".")throw new Error("Invalid IP");c=c.substring(1)}p=t(c),f=p[0],h=p[1],c=c.substring(h),l.push(f)}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,h,u,m,f;for(m=0,l=10,h="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,h="7")),f=u;u<c.length;){if("0"<=c[u]&&c[u]<=h)m=m*l+(e(c[u])-n)>>>0;else if(l===16)if("a"<=c[u]&&c[u]<="f")m=m*l+(10+e(c[u])-o)>>>0;else if("A"<=c[u]&&c[u]<="F")m=m*l+(10+e(c[u])-s)>>>0;else break;else break;if(m>4294967295)throw new Error("too large");u++}if(u===f)throw new Error("empty octet");return[m,u]},r=function(){function c(l,h){var u,m,f,p;if(typeof l!="string")throw new Error("Missing `net' parameter");if(h||(p=l.split("/",2),l=p[0],h=p[1]),h||(h=32),typeof h=="string"&&h.indexOf(".")>-1){try{this.maskLong=i(h)}catch(d){throw u=d,new Error("Invalid mask: "+h)}for(m=f=32;f>=0;m=--f)if(this.maskLong===4294967295<<32-m>>>0){this.bitmask=m;break}}else if(h||h===0)this.bitmask=parseInt(h,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: "+h);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 h,u,m;for(m=i(this.first),u=i(this.last),h=0;m<=u;)l(a(m),m,h),h++,m++},c.prototype.toString=function(){return this.base+"/"+this.bitmask},c}(),Qr.ip2long=i,Qr.long2ip=a,Qr.Netmask=r}).call(Qr)});var Al=en((El,Ss)=>{(function(r){"use strict";let t="(0?\\d+|0x[a-f0-9]+)",e={fourOctet:new RegExp(`^${t}\\.${t}\\.${t}\\.${t}$`,"i"),threeOctet:new RegExp(`^${t}\\.${t}\\.${t}$`,"i"),twoOctet:new RegExp(`^${t}\\.${t}$`,"i"),longValue:new RegExp(`^${t}$`,"i")},n=new RegExp("^0[0-7]+$","i"),s=new RegExp("^0x[a-f0-9]+$","i"),o="%[0-9a-z]{1,}",i="(?:[0-9a-f]+::?)+",a={zoneIndex:new RegExp(o,"i"),native:new RegExp(`^(::)?(${i})?([0-9a-f]+)?(::)?(${o})?$`,"i"),deprecatedTransitional:new RegExp(`^(?:::)(${t}\\.${t}\\.${t}\\.${t}(${o})?)$`,"i"),transitional:new RegExp(`^((?:${i})|(?:::)(?:${i})?)${t}\\.${t}\\.${t}\\.${t}(${o})?$`,"i")};function c(f,p){if(f.indexOf("::")!==f.lastIndexOf("::"))return null;let d=0,g=-1,y=(f.match(a.zoneIndex)||[])[0],b,w;for(y&&(y=y.substring(1),f=f.replace(/%.+$/,""));(g=f.indexOf(":",g+1))>=0;)d++;if(f.substr(0,2)==="::"&&d--,f.substr(-2,2)==="::"&&d--,d>p)return null;for(w=p-d,b=":";w--;)b+="0:";return f=f.replace("::",b),f[0]===":"&&(f=f.slice(1)),f[f.length-1]===":"&&(f=f.slice(0,-1)),p=function(){let k=f.split(":"),v=[];for(let B=0;B<k.length;B++)v.push(parseInt(k[B],16));return v}(),{parts:p,zoneId:y}}function l(f,p,d,g){if(f.length!==p.length)throw new Error("ipaddr: cannot match CIDR for objects with different lengths");let y=0,b;for(;g>0;){if(b=d-g,b<0&&(b=0),f[y]>>b!==p[y]>>b)return!1;g-=d,y+=1}return!0}function h(f){if(s.test(f))return parseInt(f,16);if(f[0]==="0"&&!isNaN(parseInt(f[1],10))){if(n.test(f))return parseInt(f,8);throw new Error(`ipaddr: cannot parse ${f} as octal`)}return parseInt(f,10)}function u(f,p){for(;f.length<p;)f=`0${f}`;return f}let m={};m.IPv4=function(){function f(p){if(p.length!==4)throw new Error("ipaddr: ipv4 octet count should be 4");let d,g;for(d=0;d<p.length;d++)if(g=p[d],!(0<=g&&g<=255))throw new Error("ipaddr: ipv4 octet should fit in 8 bits");this.octets=p}return f.prototype.SpecialRanges={unspecified:[[new f([0,0,0,0]),8]],broadcast:[[new f([255,255,255,255]),32]],multicast:[[new f([224,0,0,0]),4]],linkLocal:[[new f([169,254,0,0]),16]],loopback:[[new f([127,0,0,0]),8]],carrierGradeNat:[[new f([100,64,0,0]),10]],private:[[new f([10,0,0,0]),8],[new f([172,16,0,0]),12],[new f([192,168,0,0]),16]],reserved:[[new f([192,0,0,0]),24],[new f([192,0,2,0]),24],[new f([192,88,99,0]),24],[new f([198,18,0,0]),15],[new f([198,51,100,0]),24],[new f([203,0,113,0]),24],[new f([240,0,0,0]),4]]},f.prototype.kind=function(){return"ipv4"},f.prototype.match=function(p,d){let g;if(d===void 0&&(g=p,p=g[0],d=g[1]),p.kind()!=="ipv4")throw new Error("ipaddr: cannot match ipv4 address with non-ipv4 one");return l(this.octets,p.octets,8,d)},f.prototype.prefixLengthFromSubnetMask=function(){let p=0,d=!1,g={0:8,128:7,192:6,224:5,240:4,248:3,252:2,254:1,255:0},y,b,w;for(y=3;y>=0;y-=1)if(b=this.octets[y],b in g){if(w=g[b],d&&w!==0)return null;w!==8&&(d=!0),p+=w}else return null;return 32-p},f.prototype.range=function(){return m.subnetMatch(this,this.SpecialRanges)},f.prototype.toByteArray=function(){return this.octets.slice(0)},f.prototype.toIPv4MappedAddress=function(){return m.IPv6.parse(`::ffff:${this.toString()}`)},f.prototype.toNormalizedString=function(){return this.toString()},f.prototype.toString=function(){return this.octets.join(".")},f}(),m.IPv4.broadcastAddressFromCIDR=function(f){try{let p=this.parseCIDR(f),d=p[0].toByteArray(),g=this.subnetMaskFromPrefixLength(p[1]).toByteArray(),y=[],b=0;for(;b<4;)y.push(parseInt(d[b],10)|parseInt(g[b],10)^255),b++;return new this(y)}catch{throw new Error("ipaddr: the address does not have IPv4 CIDR format")}},m.IPv4.isIPv4=function(f){return this.parser(f)!==null},m.IPv4.isValid=function(f){try{return new this(this.parser(f)),!0}catch{return!1}},m.IPv4.isValidFourPartDecimal=function(f){return!!(m.IPv4.isValid(f)&&f.match(/^(0|[1-9]\d*)(\.(0|[1-9]\d*)){3}$/))},m.IPv4.networkAddressFromCIDR=function(f){let p,d,g,y,b;try{for(p=this.parseCIDR(f),g=p[0].toByteArray(),b=this.subnetMaskFromPrefixLength(p[1]).toByteArray(),y=[],d=0;d<4;)y.push(parseInt(g[d],10)&parseInt(b[d],10)),d++;return new this(y)}catch{throw new Error("ipaddr: the address does not have IPv4 CIDR format")}},m.IPv4.parse=function(f){let p=this.parser(f);if(p===null)throw new Error("ipaddr: string is not formatted like an IPv4 Address");return new this(p)},m.IPv4.parseCIDR=function(f){let p;if(p=f.match(/^(.+)\/(\d+)$/)){let d=parseInt(p[2]);if(d>=0&&d<=32){let g=[this.parse(p[1]),d];return Object.defineProperty(g,"toString",{value:function(){return this.join("/")}}),g}}throw new Error("ipaddr: string is not formatted like an IPv4 CIDR range")},m.IPv4.parser=function(f){let p,d,g;if(p=f.match(e.fourOctet))return function(){let y=p.slice(1,6),b=[];for(let w=0;w<y.length;w++)d=y[w],b.push(h(d));return b}();if(p=f.match(e.longValue)){if(g=h(p[1]),g>4294967295||g<0)throw new Error("ipaddr: address outside defined range");return function(){let y=[],b;for(b=0;b<=24;b+=8)y.push(g>>b&255);return y}().reverse()}else return(p=f.match(e.twoOctet))?function(){let y=p.slice(1,4),b=[];if(g=h(y[1]),g>16777215||g<0)throw new Error("ipaddr: address outside defined range");return b.push(h(y[0])),b.push(g>>16&255),b.push(g>>8&255),b.push(g&255),b}():(p=f.match(e.threeOctet))?function(){let y=p.slice(1,5),b=[];if(g=h(y[2]),g>65535||g<0)throw new Error("ipaddr: address outside defined range");return b.push(h(y[0])),b.push(h(y[1])),b.push(g>>8&255),b.push(g&255),b}():null},m.IPv4.subnetMaskFromPrefixLength=function(f){if(f=parseInt(f),f<0||f>32)throw new Error("ipaddr: invalid IPv4 prefix length");let p=[0,0,0,0],d=0,g=Math.floor(f/8);for(;d<g;)p[d]=255,d++;return g<4&&(p[g]=Math.pow(2,f%8)-1<<8-f%8),new this(p)},m.IPv6=function(){function f(p,d){let g,y;if(p.length===16)for(this.parts=[],g=0;g<=14;g+=2)this.parts.push(p[g]<<8|p[g+1]);else if(p.length===8)this.parts=p;else throw new Error("ipaddr: ipv6 part count should be 8 or 16");for(g=0;g<this.parts.length;g++)if(y=this.parts[g],!(0<=y&&y<=65535))throw new Error("ipaddr: ipv6 part should fit in 16 bits");d&&(this.zoneId=d)}return f.prototype.SpecialRanges={unspecified:[new f([0,0,0,0,0,0,0,0]),128],linkLocal:[new f([65152,0,0,0,0,0,0,0]),10],multicast:[new f([65280,0,0,0,0,0,0,0]),8],loopback:[new f([0,0,0,0,0,0,0,1]),128],uniqueLocal:[new f([64512,0,0,0,0,0,0,0]),7],ipv4Mapped:[new f([0,0,0,0,0,65535,0,0]),96],rfc6145:[new f([0,0,0,0,65535,0,0,0]),96],rfc6052:[new f([100,65435,0,0,0,0,0,0]),96],"6to4":[new f([8194,0,0,0,0,0,0,0]),16],teredo:[new f([8193,0,0,0,0,0,0,0]),32],reserved:[[new f([8193,3512,0,0,0,0,0,0]),32]],benchmarking:[new f([8193,2,0,0,0,0,0,0]),48],amt:[new f([8193,3,0,0,0,0,0,0]),32],as112v6:[new f([8193,4,274,0,0,0,0,0]),48],deprecated:[new f([8193,16,0,0,0,0,0,0]),28],orchid2:[new f([8193,32,0,0,0,0,0,0]),28]},f.prototype.isIPv4MappedAddress=function(){return this.range()==="ipv4Mapped"},f.prototype.kind=function(){return"ipv6"},f.prototype.match=function(p,d){let g;if(d===void 0&&(g=p,p=g[0],d=g[1]),p.kind()!=="ipv6")throw new Error("ipaddr: cannot match ipv6 address with non-ipv6 one");return l(this.parts,p.parts,16,d)},f.prototype.prefixLengthFromSubnetMask=function(){let p=0,d=!1,g={0:16,32768:15,49152:14,57344:13,61440:12,63488:11,64512:10,65024:9,65280:8,65408:7,65472:6,65504:5,65520:4,65528:3,65532:2,65534:1,65535:0},y,b;for(let w=7;w>=0;w-=1)if(y=this.parts[w],y in g){if(b=g[y],d&&b!==0)return null;b!==16&&(d=!0),p+=b}else return null;return 128-p},f.prototype.range=function(){return m.subnetMatch(this,this.SpecialRanges)},f.prototype.toByteArray=function(){let p,d=[],g=this.parts;for(let y=0;y<g.length;y++)p=g[y],d.push(p>>8),d.push(p&255);return d},f.prototype.toFixedLengthString=function(){let p=function(){let g=[];for(let y=0;y<this.parts.length;y++)g.push(u(this.parts[y].toString(16),4));return g}.call(this).join(":"),d="";return this.zoneId&&(d=`%${this.zoneId}`),p+d},f.prototype.toIPv4Address=function(){if(!this.isIPv4MappedAddress())throw new Error("ipaddr: trying to convert a generic ipv6 address to ipv4");let p=this.parts.slice(-2),d=p[0],g=p[1];return new m.IPv4([d>>8,d&255,g>>8,g&255])},f.prototype.toNormalizedString=function(){let p=function(){let g=[];for(let y=0;y<this.parts.length;y++)g.push(this.parts[y].toString(16));return g}.call(this).join(":"),d="";return this.zoneId&&(d=`%${this.zoneId}`),p+d},f.prototype.toRFC5952String=function(){let p=/((^|:)(0(:|$)){2,})/g,d=this.toNormalizedString(),g=0,y=-1,b;for(;b=p.exec(d);)b[0].length>y&&(g=b.index,y=b[0].length);return y<0?d:`${d.substring(0,g)}::${d.substring(g+y)}`},f.prototype.toString=function(){return this.toRFC5952String()},f}(),m.IPv6.broadcastAddressFromCIDR=function(f){try{let p=this.parseCIDR(f),d=p[0].toByteArray(),g=this.subnetMaskFromPrefixLength(p[1]).toByteArray(),y=[],b=0;for(;b<16;)y.push(parseInt(d[b],10)|parseInt(g[b],10)^255),b++;return new this(y)}catch(p){throw new Error(`ipaddr: the address does not have IPv6 CIDR format (${p})`)}},m.IPv6.isIPv6=function(f){return this.parser(f)!==null},m.IPv6.isValid=function(f){if(typeof f=="string"&&f.indexOf(":")===-1)return!1;try{let p=this.parser(f);return new this(p.parts,p.zoneId),!0}catch{return!1}},m.IPv6.networkAddressFromCIDR=function(f){let p,d,g,y,b;try{for(p=this.parseCIDR(f),g=p[0].toByteArray(),b=this.subnetMaskFromPrefixLength(p[1]).toByteArray(),y=[],d=0;d<16;)y.push(parseInt(g[d],10)&parseInt(b[d],10)),d++;return new this(y)}catch(w){throw new Error(`ipaddr: the address does not have IPv6 CIDR format (${w})`)}},m.IPv6.parse=function(f){let p=this.parser(f);if(p.parts===null)throw new Error("ipaddr: string is not formatted like an IPv6 Address");return new this(p.parts,p.zoneId)},m.IPv6.parseCIDR=function(f){let p,d,g;if((d=f.match(/^(.+)\/(\d+)$/))&&(p=parseInt(d[2]),p>=0&&p<=128))return g=[this.parse(d[1]),p],Object.defineProperty(g,"toString",{value:function(){return this.join("/")}}),g;throw new Error("ipaddr: string is not formatted like an IPv6 CIDR range")},m.IPv6.parser=function(f){let p,d,g,y,b,w;if(g=f.match(a.deprecatedTransitional))return this.parser(`::ffff:${g[1]}`);if(a.native.test(f))return c(f,8);if((g=f.match(a.transitional))&&(w=g[6]||"",p=c(g[1].slice(0,-1)+w,6),p.parts)){for(b=[parseInt(g[2]),parseInt(g[3]),parseInt(g[4]),parseInt(g[5])],d=0;d<b.length;d++)if(y=b[d],!(0<=y&&y<=255))return null;return p.parts.push(b[0]<<8|b[1]),p.parts.push(b[2]<<8|b[3]),{parts:p.parts,zoneId:p.zoneId}}return null},m.IPv6.subnetMaskFromPrefixLength=function(f){if(f=parseInt(f),f<0||f>128)throw new Error("ipaddr: invalid IPv6 prefix length");let p=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],d=0,g=Math.floor(f/8);for(;d<g;)p[d]=255,d++;return g<16&&(p[g]=Math.pow(2,f%8)-1<<8-f%8),new this(p)},m.fromByteArray=function(f){let p=f.length;if(p===4)return new m.IPv4(f);if(p===16)return new m.IPv6(f);throw new Error("ipaddr: the binary input is neither an IPv6 nor IPv4 address")},m.isValid=function(f){return m.IPv6.isValid(f)||m.IPv4.isValid(f)},m.parse=function(f){if(m.IPv6.isValid(f))return m.IPv6.parse(f);if(m.IPv4.isValid(f))return m.IPv4.parse(f);throw new Error("ipaddr: the address has neither IPv6 nor IPv4 format")},m.parseCIDR=function(f){try{return m.IPv6.parseCIDR(f)}catch{try{return m.IPv4.parseCIDR(f)}catch{throw new Error("ipaddr: the address has neither IPv6 nor IPv4 CIDR format")}}},m.process=function(f){let p=this.parse(f);return p.kind()==="ipv6"&&p.isIPv4MappedAddress()?p.toIPv4Address():p},m.subnetMatch=function(f,p,d){let g,y,b,w;d==null&&(d="unicast");for(y in p)if(Object.prototype.hasOwnProperty.call(p,y)){for(b=p[y],b[0]&&!(b[0]instanceof Array)&&(b=[b]),g=0;g<b.length;g++)if(w=b[g],f.kind()===w[0].kind()&&f.match.apply(f,w))return y}return d},typeof Ss<"u"&&Ss.exports?Ss.exports=m:r.ipaddr=m})(El)});var h0={};ut(h0,{autoNAT:()=>f0});var p0=Symbol.for("@libp2p/connection");var m0=Symbol.for("@libp2p/content-routing");var w0=Symbol.for("@libp2p/peer-discovery");var Ni=Symbol.for("@libp2p/peer-id");var E0=Symbol.for("@libp2p/peer-routing");var Ti;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(Ti||(Ti={}));var S0=Symbol.for("@libp2p/transport");var Li;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Li||(Li={}));var _=class extends Error{code;props;constructor(t,e,n){super(t),this.code=e,this.name=n?.name??"CodeError",this.props=n??{}}};var Ns="ERR_TIMEOUT";var Ts=class extends Event{detail;constructor(t,e){super(t,e),this.detail=e?.detail}},N0=globalThis.CustomEvent??Ts;var Ls=(r,...t)=>{try{[...t]}catch{}};var Ds={};ut(Ds,{base58btc:()=>ct,base58flickr:()=>Zl});var op=new Uint8Array(0);function _i(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 Xt(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 Ci(r){return new TextEncoder().encode(r)}function Ui(r){return new TextDecoder().decode(r)}function zl(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),h=Math.log(256)/Math.log(a);function u(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var d=0,g=0,y=0,b=p.length;y!==b&&p[y]===0;)y++,d++;for(var w=(b-y)*h+1>>>0,k=new Uint8Array(w);y!==b;){for(var v=p[y],B=0,N=w-1;(v!==0||B<g)&&N!==-1;N--,B++)v+=256*k[N]>>>0,k[N]=v%a>>>0,v=v/a>>>0;if(v!==0)throw new Error("Non-zero carry");g=B,y++}for(var T=w-g;T!==w&&k[T]===0;)T++;for(var z=c.repeat(d);T<w;++T)z+=r.charAt(k[T]);return z}function m(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var d=0;if(p[d]!==" "){for(var g=0,y=0;p[d]===c;)g++,d++;for(var b=(p.length-d)*l+1>>>0,w=new Uint8Array(b);p[d];){var k=e[p.charCodeAt(d)];if(k===255)return;for(var v=0,B=b-1;(k!==0||v<y)&&B!==-1;B--,v++)k+=a*w[B]>>>0,w[B]=k%256>>>0,k=k/256>>>0;if(k!==0)throw new Error("Non-zero carry");y=v,d++}if(p[d]!==" "){for(var N=b-y;N!==b&&w[N]===0;)N++;for(var T=new Uint8Array(g+(b-N)),z=g;N!==b;)T[z++]=w[N++];return T}}}function f(p){var d=m(p);if(d)return d;throw new Error(`Non-${t} character`)}return{encode:u,decodeUnsafe:m,decode:f}}var jl=zl,Gl=jl,Di=Gl;var _s=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")}},Cs=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 Oi(this,t)}},Us=class{decoders;constructor(t){this.decoders=t}or(t){return Oi(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 Oi(r,t){return new Us({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Ps=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 _s(t,e,n),this.decoder=new Cs(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 Ps(r,t,e,n)}function be({name:r,prefix:t,alphabet:e}){let{encode:n,decode:s}=Di(e,r);return Ze({prefix:t,name:r,encode:n,decode:o=>Xt(s(o))})}function Wl(r,t,e,n){let s={};for(let h=0;h<t.length;++h)s[t[h]]=h;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 h=0;h<o;++h){let u=s[r[h]];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 Yl(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 Yl(s,n,e)},decode(s){return Wl(s,n,e,r)}})}var ct=be({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Zl=be({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Os={};ut(Os,{base10:()=>Jl});var Jl=be({prefix:"9",name:"base10",alphabet:"0123456789"});var Vs={};ut(Vs,{base16:()=>Xl,base16upper:()=>Ql});var Xl=tt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ql=tt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Fs={};ut(Fs,{base2:()=>tu});var tu=tt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Hs={};ut(Hs,{base256emoji:()=>ou});var Vi=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}"),eu=Vi.reduce((r,t,e)=>(r[e]=t,r),[]),ru=Vi.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function nu(r){return r.reduce((t,e)=>(t+=eu[e],t),"")}function su(r){let t=[];for(let e of r){let n=ru[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var ou=Ze({prefix:"\u{1F680}",name:"base256emoji",encode:nu,decode:su});var Ms={};ut(Ms,{base32:()=>Qt,base32hex:()=>lu,base32hexpad:()=>fu,base32hexpadupper:()=>hu,base32hexupper:()=>uu,base32pad:()=>au,base32padupper:()=>cu,base32upper:()=>iu,base32z:()=>du});var Qt=tt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),iu=tt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),au=tt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),cu=tt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),lu=tt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),uu=tt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),fu=tt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),hu=tt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),du=tt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var $s={};ut($s,{base36:()=>pu,base36upper:()=>gu});var pu=be({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),gu=be({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ks={};ut(Ks,{base64:()=>nn,base64pad:()=>mu,base64url:()=>yu,base64urlpad:()=>bu});var nn=tt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),mu=tt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),yu=tt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),bu=tt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var qs={};ut(qs,{base8:()=>wu});var wu=tt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var zs={};ut(zs,{identity:()=>xu});var xu=Ze({prefix:"\0",name:"identity",encode:r=>Ui(r),decode:r=>Ci(r)});var vp=new TextEncoder,Ep=new TextDecoder;var Gs={};ut(Gs,{identity:()=>we});var Au=Mi,Fi=128,Bu=127,Iu=~Bu,Su=Math.pow(2,31);function Mi(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Su;)t[e++]=r&255|Fi,r/=128;for(;r&Iu;)t[e++]=r&255|Fi,r>>>=7;return t[e]=r|0,Mi.bytes=e-n+1,t}var ku=js,Ru=128,Hi=127;function js(r,n){var e=0,n=n||0,s=0,o=n,i,a=r.length;do{if(o>=a)throw js.bytes=0,new RangeError("Could not decode varint");i=r[o++],e+=s<28?(i&Hi)<<s:(i&Hi)*Math.pow(2,s),s+=7}while(i>=Ru);return js.bytes=o-n,e}var Nu=Math.pow(2,7),Tu=Math.pow(2,14),Lu=Math.pow(2,21),_u=Math.pow(2,28),Cu=Math.pow(2,35),Uu=Math.pow(2,42),Pu=Math.pow(2,49),Du=Math.pow(2,56),Ou=Math.pow(2,63),Vu=function(r){return r<Nu?1:r<Tu?2:r<Lu?3:r<_u?4:r<Cu?5:r<Uu?6:r<Pu?7:r<Du?8:r<Ou?9:10},Fu={encode:Au,decode:ku,encodingLength:Vu},Hu=Fu,Cr=Hu;function Ur(r,t=0){return[Cr.decode(r,t),Cr.decode.bytes]}function Je(r,t,e=0){return Cr.encode(r,t,e),t}function Xe(r){return Cr.encodingLength(r)}function jt(r,t){let e=t.byteLength,n=Xe(r),s=n+Xe(e),o=new Uint8Array(s+e);return Je(r,o,0),Je(e,o,n),o.set(t,s),new Qe(r,e,t,o)}function Ve(r){let t=Xt(r),[e,n]=Ur(t),[s,o]=Ur(t.subarray(n)),i=t.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new Qe(e,s,i,t)}function $i(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&_i(r.bytes,e.bytes)}}var Qe=class{code;size;digest;bytes;constructor(t,e,n,s){this.code=t,this.size=e,this.digest=n,this.bytes=s}};var Ki=0,Mu="identity",qi=Xt;function $u(r){return jt(Ki,qi(r))}var we={code:Ki,name:Mu,encode:qi,digest:$u};var Zs={};ut(Zs,{sha256:()=>gt,sha512:()=>Ku});function Ys({name:r,code:t,encode:e}){return new Ws(r,t,e)}var Ws=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?jt(this.code,e):e.then(n=>jt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function ji(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var gt=Ys({name:"sha2-256",code:18,encode:ji("SHA-256")}),Ku=Ys({name:"sha2-512",code:19,encode:ji("SHA-512")});function Gi(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return zu(e,Js(r),t??ct.encoder);default:return ju(e,Js(r),t??Qt.encoder)}}var Wi=new WeakMap;function Js(r){let t=Wi.get(r);if(t==null){let e=new Map;return Wi.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!==Pr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Gu)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=jt(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&&$i(t.multihash,n.multihash)}toString(t){return Gi(this,t)}toJSON(){return{"/":Gi(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??Yi(n,s,o.bytes))}else if(e[Wu]===!0){let{version:n,multihash:s,code:o}=e,i=Ve(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!==Pr)throw new Error(`Version 0 CID must use dag-pb (code: ${Pr}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let s=Yi(t,e,n.bytes);return new r(t,e,n,s)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Pr,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=Xt(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 Qe(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,m]=Ur(t.subarray(e));return e+=m,u},s=n(),o=Pr;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,h=l-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:h,size:l}}static parse(t,e){let[n,s]=qu(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 qu(r,t){switch(r[0]){case"Q":{let e=t??ct;return[ct.prefix,e.decode(`${ct.prefix}${r}`)]}case ct.prefix:{let e=t??ct;return[ct.prefix,e.decode(r)]}case Qt.prefix:{let e=t??Qt;return[Qt.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 zu(r,t,e){let{prefix:n}=e;if(n!==ct.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 ju(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 Pr=112,Gu=18;function Yi(r,t,e){let n=Xe(r),s=n+Xe(t),o=new Uint8Array(s+e.byteLength);return Je(r,o,0),Je(t,o,n),o.set(e,s),o}var Wu=Symbol.for("@ipld/js-cid/CID");var xe={...zs,...Fs,...qs,...Os,...Vs,...Ms,...$s,...Ds,...Ks,...Hs},Kp={...Zs,...Gs};function mt(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 Yu=Symbol.for("nodejs.util.inspect.custom"),Zi=Object.values(xe).map(r=>r.decoder).reduce((r,t)=>r.or(t),xe.identity.decoder),Ji=114,Xs=36,Qs=37,Dr=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()})`}[Ni]=!0;toString(){return this.string==null&&(this.string=ct.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return Ut.createV1(Ji,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return mt(this.multihash.bytes,t);if(typeof t=="string")return Zu(t).equals(this);if(t?.multihash?.bytes!=null)return mt(this.multihash.bytes,t.multihash.bytes);throw new Error("not valid Id")}[Yu](){return`PeerId(${this.toString()})`}},tr=class extends Dr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},er=class extends Dr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.multihash.digest}},rr=class extends Dr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.multihash.digest}};function Zu(r,t){if(t=t??Zi,r.charAt(0)==="1"||r.charAt(0)==="Q"){let e=Ve(ct.decode(`z${r}`));return r.startsWith("12D")?new er({multihash:e}):r.startsWith("16U")?new rr({multihash:e}):new tr({multihash:e})}return on(Zi.decode(r))}function on(r){try{let t=Ve(r);if(t.code===we.code){if(t.digest.length===Xs)return new er({multihash:t});if(t.digest.length===Qs)return new rr({multihash:t})}if(t.code===gt.code)return new tr({multihash:t})}catch{return Ju(Ut.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function Ju(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==Ji)throw new Error("Supplied PeerID CID is invalid");let t=r.multihash;if(t.code===gt.code)return new tr({multihash:r.multihash});if(t.code===we.code){if(t.digest.length===Xs)return new er({multihash:r.multihash});if(t.digest.length===Qs)return new rr({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function Xi(r,t){return r.length===Xs?new er({multihash:jt(we.code,r),privateKey:t}):r.length===Qs?new rr({multihash:jt(we.code,r),privateKey:t}):new tr({multihash:await gt.digest(r),publicKey:r,privateKey:t})}var Lo={};ut(Lo,{Ed25519PrivateKey:()=>Re,Ed25519PublicKey:()=>gr,generateKeyPair:()=>yh,generateKeyPairFromSeed:()=>Ua,unmarshalEd25519PrivateKey:()=>gh,unmarshalEd25519PublicKey:()=>mh});function ve(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function te(r=0){return globalThis.Buffer?.alloc!=null?ve(globalThis.Buffer.alloc(r)):new Uint8Array(r)}function vt(r=0){return globalThis.Buffer?.allocUnsafe!=null?ve(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function yt(r,t){if(globalThis.Buffer!=null)return ve(globalThis.Buffer.concat(r,t));t==null&&(t=r.reduce((s,o)=>s+o.length,0));let e=vt(t),n=0;for(let s of r)e.set(s,n),n+=s.length;return ve(e)}function ta(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Qi=ta("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),to=ta("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=vt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Xu={utf8:Qi,"utf-8":Qi,hex:xe.base16,latin1:to,ascii:to,binary:to,...xe},an=Xu;function Z(r,t="utf8"){let e=an[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?ve(globalThis.Buffer.from(r,"utf-8")):e.decoder.decode(`${e.prefix}${r}`)}function Lt(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function nr(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`Wrong positive integer: ${r}`)}function Qu(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function eo(r,...t){if(!Qu(r))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(r.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${r.length}`)}function cn(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");nr(r.outputLen),nr(r.blockLen)}function sr(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 ea(r,t){eo(r);let e=t.outputLen;if(r.length<e)throw new Error(`digestInto() expects output buffer of length at least ${e}`)}var ln=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function ra(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var ir=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Pt=(r,t)=>r<<32-t|r>>>t,tf=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!tf)throw new Error("Non little-endian hardware is not supported");var ef=async()=>{};async function na(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 ef(),n+=o)}}function ro(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Ee(r){if(typeof r=="string"&&(r=ro(r)),!ra(r))throw new Error(`expected Uint8Array, got ${typeof r}`);return r}function un(...r){let t=0;for(let n=0;n<r.length;n++){let s=r[n];if(!ra(s))throw new Error("Uint8Array expected");t+=s.length}let e=new Uint8Array(t);for(let n=0,s=0;n<r.length;n++){let o=r[n];e.set(o,s),s+=o.length}return e}var or=class{clone(){return this._cloneInto()}},rf={}.toString;function sa(r,t){if(t!==void 0&&rf.call(t)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(r,t)}function fn(r){let t=n=>r().update(Ee(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function ar(r=32){if(ln&&typeof ln.getRandomValues=="function")return ln.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function nf(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 cr=class extends or{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=ir(this.buffer)}update(t){sr(this);let{view:e,buffer:n,blockLen:s}=this;t=Ee(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=ir(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){sr(this),ea(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;nf(n,s-8,BigInt(this.length*8),o),this.process(n,0);let a=ir(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=c/4,h=this.get();if(l>h.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<l;u++)a.setUint32(4*u,h[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 hn=BigInt(4294967295),no=BigInt(32);function oa(r,t=!1){return t?{h:Number(r&hn),l:Number(r>>no&hn)}:{h:Number(r>>no&hn)|0,l:Number(r&hn)|0}}function sf(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}=oa(r[s],t);[e[s],n[s]]=[o,i]}return[e,n]}var of=(r,t)=>BigInt(r>>>0)<<no|BigInt(t>>>0),af=(r,t,e)=>r>>>e,cf=(r,t,e)=>r<<32-e|t>>>e,lf=(r,t,e)=>r>>>e|t<<32-e,uf=(r,t,e)=>r<<32-e|t>>>e,ff=(r,t,e)=>r<<64-e|t>>>e-32,hf=(r,t,e)=>r>>>e-32|t<<64-e,df=(r,t)=>t,pf=(r,t)=>r,gf=(r,t,e)=>r<<e|t>>>32-e,mf=(r,t,e)=>t<<e|r>>>32-e,yf=(r,t,e)=>t<<e-32|r>>>64-e,bf=(r,t,e)=>r<<e-32|t>>>64-e;function wf(r,t,e,n){let s=(t>>>0)+(n>>>0);return{h:r+e+(s/2**32|0)|0,l:s|0}}var xf=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),vf=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Ef=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Af=(r,t,e,n,s)=>t+e+n+s+(r/2**32|0)|0,Bf=(r,t,e,n,s)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(s>>>0),If=(r,t,e,n,s,o)=>t+e+n+s+o+(r/2**32|0)|0;var Sf={fromBig:oa,split:sf,toBig:of,shrSH:af,shrSL:cf,rotrSH:lf,rotrSL:uf,rotrBH:ff,rotrBL:hf,rotr32H:df,rotr32L:pf,rotlSH:gf,rotlSL:mf,rotlBH:yf,rotlBL:bf,add:wf,add3L:xf,add3H:vf,add4L:Ef,add4H:Af,add5H:If,add5L:Bf},U=Sf;var[kf,Rf]=U.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))),Ae=new Uint32Array(80),Be=new Uint32Array(80),so=class extends cr{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:h,Fh:u,Fl:m,Gh:f,Gl:p,Hh:d,Hl:g}=this;return[t,e,n,s,o,i,a,c,l,h,u,m,f,p,d,g]}set(t,e,n,s,o,i,a,c,l,h,u,m,f,p,d,g){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=h|0,this.Fh=u|0,this.Fl=m|0,this.Gh=f|0,this.Gl=p|0,this.Hh=d|0,this.Hl=g|0}process(t,e){for(let w=0;w<16;w++,e+=4)Ae[w]=t.getUint32(e),Be[w]=t.getUint32(e+=4);for(let w=16;w<80;w++){let k=Ae[w-15]|0,v=Be[w-15]|0,B=U.rotrSH(k,v,1)^U.rotrSH(k,v,8)^U.shrSH(k,v,7),N=U.rotrSL(k,v,1)^U.rotrSL(k,v,8)^U.shrSL(k,v,7),T=Ae[w-2]|0,z=Be[w-2]|0,$=U.rotrSH(T,z,19)^U.rotrBH(T,z,61)^U.shrSH(T,z,6),D=U.rotrSL(T,z,19)^U.rotrBL(T,z,61)^U.shrSL(T,z,6),nt=U.add4L(N,D,Be[w-7],Be[w-16]),rt=U.add4H(nt,B,$,Ae[w-7],Ae[w-16]);Ae[w]=rt|0,Be[w]=nt|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:l,Dl:h,Eh:u,El:m,Fh:f,Fl:p,Gh:d,Gl:g,Hh:y,Hl:b}=this;for(let w=0;w<80;w++){let k=U.rotrSH(u,m,14)^U.rotrSH(u,m,18)^U.rotrBH(u,m,41),v=U.rotrSL(u,m,14)^U.rotrSL(u,m,18)^U.rotrBL(u,m,41),B=u&f^~u&d,N=m&p^~m&g,T=U.add5L(b,v,N,Rf[w],Be[w]),z=U.add5H(T,y,k,B,kf[w],Ae[w]),$=T|0,D=U.rotrSH(n,s,28)^U.rotrBH(n,s,34)^U.rotrBH(n,s,39),nt=U.rotrSL(n,s,28)^U.rotrBL(n,s,34)^U.rotrBL(n,s,39),rt=n&o^n&a^o&a,Tt=s&i^s&c^i&c;y=d|0,b=g|0,d=f|0,g=p|0,f=u|0,p=m|0,{h:u,l:m}=U.add(l|0,h|0,z|0,$|0),l=a|0,h=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let E=U.add3L($,nt,Tt);n=U.add3H(E,z,D,rt),s=E|0}({h:n,l:s}=U.add(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=U.add(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=U.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:h}=U.add(this.Dh|0,this.Dl|0,l|0,h|0),{h:u,l:m}=U.add(this.Eh|0,this.El|0,u|0,m|0),{h:f,l:p}=U.add(this.Fh|0,this.Fl|0,f|0,p|0),{h:d,l:g}=U.add(this.Gh|0,this.Gl|0,d|0,g|0),{h:y,l:b}=U.add(this.Hh|0,this.Hl|0,y|0,b|0),this.set(n,s,o,i,a,c,l,h,u,m,f,p,d,g,y,b)}roundClean(){Ae.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 lr=fn(()=>new so);var pn={};ut(pn,{bitGet:()=>Pf,bitLen:()=>Uf,bitMask:()=>Or,bitSet:()=>Df,bytesToHex:()=>re,bytesToNumberBE:()=>ne,bytesToNumberLE:()=>Ie,concatBytes:()=>se,createHmacDrbg:()=>ao,ensureBytes:()=>et,equalBytes:()=>_f,hexToBytes:()=>He,hexToNumber:()=>io,isBytes:()=>Dt,numberToBytesBE:()=>Se,numberToBytesLE:()=>Me,numberToHexUnpadded:()=>la,numberToVarBytesBE:()=>Lf,utf8ToBytes:()=>Cf,validateObject:()=>Gt});var ca=BigInt(0),dn=BigInt(1),Nf=BigInt(2);function Dt(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var Tf=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function re(r){if(!Dt(r))throw new Error("Uint8Array expected");let t="";for(let e=0;e<r.length;e++)t+=Tf[r[e]];return t}function la(r){let t=r.toString(16);return t.length&1?`0${t}`:t}function io(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var ee={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function ia(r){if(r>=ee._0&&r<=ee._9)return r-ee._0;if(r>=ee._A&&r<=ee._F)return r-(ee._A-10);if(r>=ee._a&&r<=ee._f)return r-(ee._a-10)}function He(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=ia(r.charCodeAt(o)),a=ia(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 ne(r){return io(re(r))}function Ie(r){if(!Dt(r))throw new Error("Uint8Array expected");return io(re(Uint8Array.from(r).reverse()))}function Se(r,t){return He(r.toString(16).padStart(t*2,"0"))}function Me(r,t){return Se(r,t).reverse()}function Lf(r){return He(la(r))}function et(r,t,e){let n;if(typeof t=="string")try{n=He(t)}catch(o){throw new Error(`${r} must be valid hex string, got "${t}". Cause: ${o}`)}else if(Dt(t))n=Uint8Array.from(t);else throw new Error(`${r} must be hex string or Uint8Array`);let s=n.length;if(typeof e=="number"&&s!==e)throw new Error(`${r} expected ${e} bytes, got ${s}`);return n}function se(...r){let t=0;for(let s=0;s<r.length;s++){let o=r[s];if(!Dt(o))throw new Error("Uint8Array expected");t+=o.length}let e=new Uint8Array(t),n=0;for(let s=0;s<r.length;s++){let o=r[s];e.set(o,n),n+=o.length}return e}function _f(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 Cf(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Uf(r){let t;for(t=0;r>ca;r>>=dn,t+=1);return t}function Pf(r,t){return r>>BigInt(t)&dn}var Df=(r,t,e)=>r|(e?dn:ca)<<BigInt(t),Or=r=>(Nf<<BigInt(r-1))-dn,oo=r=>new Uint8Array(r),aa=r=>Uint8Array.from(r);function ao(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=oo(r),s=oo(r),o=0,i=()=>{n.fill(1),s.fill(0),o=0},a=(...u)=>e(s,n,...u),c=(u=oo())=>{s=a(aa([0]),u),n=a(),u.length!==0&&(s=a(aa([1]),u),n=a())},l=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let u=0,m=[];for(;u<t;){n=a();let f=n.slice();m.push(f),u+=n.length}return se(...m)};return(u,m)=>{i(),c(u);let f;for(;!(f=m(l()));)c();return i(),f}}var Of={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||Dt(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function Gt(r,t,e={}){let n=(s,o,i)=>{let a=Of[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 lt=BigInt(0),J=BigInt(1),$e=BigInt(2),Vf=BigInt(3),co=BigInt(4),ua=BigInt(5),fa=BigInt(8),Ff=BigInt(9),Hf=BigInt(16);function Y(r,t){let e=r%t;return e>=lt?e:t+e}function Mf(r,t,e){if(e<=lt||t<lt)throw new Error("Expected power/modulo > 0");if(e===J)return lt;let n=J;for(;t>lt;)t&J&&(n=n*r%e),r=r*r%e,t>>=J;return n}function X(r,t,e){let n=r;for(;t-- >lt;)n*=n,n%=e;return n}function gn(r,t){if(r===lt||t<=lt)throw new Error(`invert: expected positive integers, got n=${r} mod=${t}`);let e=Y(r,t),n=t,s=lt,o=J,i=J,a=lt;for(;e!==lt;){let l=n/e,h=n%e,u=s-i*l,m=o-a*l;n=e,e=h,s=i,o=a,i=u,a=m}if(n!==J)throw new Error("invert: does not exist");return Y(s,t)}function $f(r){let t=(r-J)/$e,e,n,s;for(e=r-J,n=0;e%$e===lt;e/=$e,n++);for(s=$e;s<r&&Mf(s,t,r)!==r-J;s++);if(n===1){let i=(r+J)/co;return function(c,l){let h=c.pow(l,i);if(!c.eql(c.sqr(h),l))throw new Error("Cannot find square root");return h}}let o=(e+J)/$e;return function(a,c){if(a.pow(c,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let l=n,h=a.pow(a.mul(a.ONE,s),e),u=a.pow(c,o),m=a.pow(c,e);for(;!a.eql(m,a.ONE);){if(a.eql(m,a.ZERO))return a.ZERO;let f=1;for(let d=a.sqr(m);f<l&&!a.eql(d,a.ONE);f++)d=a.sqr(d);let p=a.pow(h,J<<BigInt(l-f-1));h=a.sqr(p),u=a.mul(u,p),m=a.mul(m,h),l=f}return u}}function Kf(r){if(r%co===Vf){let t=(r+J)/co;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%fa===ua){let t=(r-ua)/fa;return function(n,s){let o=n.mul(s,$e),i=n.pow(o,t),a=n.mul(s,i),c=n.mul(n.mul(a,$e),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%Hf,$f(r)}var ha=(r,t)=>(Y(r,t)&J)===J,qf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function lo(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=qf.reduce((n,s)=>(n[s]="function",n),t);return Gt(r,e)}function zf(r,t,e){if(e<lt)throw new Error("Expected power > 0");if(e===lt)return r.ONE;if(e===J)return t;let n=r.ONE,s=t;for(;e>lt;)e&J&&(n=r.mul(n,s)),s=r.sqr(s),e>>=J;return n}function jf(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 uo(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function mn(r,t,e=!1,n={}){if(r<=lt)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:s,nByteLength:o}=uo(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:Or(s),ZERO:lt,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 lt<=c&&c<r},is0:c=>c===lt,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)=>zf(a,c,l),div:(c,l)=>Y(c*gn(l,r),r),sqrN:c=>c*c,addN:(c,l)=>c+l,subN:(c,l)=>c-l,mulN:(c,l)=>c*l,inv:c=>gn(c,r),sqrt:n.sqrt||(c=>i(a,c)),invertBatch:c=>jf(a,c),cmov:(c,l,h)=>h?l:c,toBytes:c=>e?Me(c,o):Se(c,o),fromBytes:c=>{if(c.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);return e?Ie(c):ne(c)}});return Object.freeze(a)}function da(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 pa(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 fo(r){let t=pa(r);return t+Math.ceil(t/2)}function ga(r,t,e=!1){let n=r.length,s=pa(t),o=fo(t);if(n<16||n<o||n>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${n}`);let i=e?ne(r):Ie(r),a=Y(i,t-J)+J;return e?Me(a,s):Se(a,s)}var Wf=BigInt(0),ho=BigInt(1);function yn(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>Wf;)o&ho&&(i=i.add(a)),a=a.double(),o>>=ho;return i},precomputeWindow(s,o){let{windows:i,windowSize:a}=n(o),c=[],l=s,h=l;for(let u=0;u<i;u++){h=l,c.push(h);for(let m=1;m<a;m++)h=h.add(l),c.push(h);l=h.double()}return c},wNAF(s,o,i){let{windows:a,windowSize:c}=n(s),l=r.ZERO,h=r.BASE,u=BigInt(2**s-1),m=2**s,f=BigInt(s);for(let p=0;p<a;p++){let d=p*c,g=Number(i&u);i>>=f,g>c&&(g-=m,i+=ho);let y=d,b=d+Math.abs(g)-1,w=p%2!==0,k=g<0;g===0?h=h.add(e(w,o[y])):l=l.add(e(k,o[b]))}return{p:l,f:h}},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 Vr(r){return lo(r.Fp),Gt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...uo(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Ot=BigInt(0),Nt=BigInt(1),bn=BigInt(2),Yf=BigInt(8),Zf={zip215:!0};function Jf(r){let t=Vr(r);return Gt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function wn(r){let t=Jf(r),{Fp:e,n,prehash:s,hash:o,randomBytes:i,nByteLength:a,h:c}=t,l=bn<<BigInt(a*8)-Nt,h=e.create,u=t.uvRatio||((A,x)=>{try{return{isValid:!0,value:e.sqrt(A*e.inv(x))}}catch{return{isValid:!1,value:Ot}}}),m=t.adjustScalarBytes||(A=>A),f=t.domain||((A,x,S)=>{if(x.length||S)throw new Error("Contexts/pre-hash are not supported");return A}),p=A=>typeof A=="bigint"&&Ot<A,d=(A,x)=>p(A)&&p(x)&&A<x,g=A=>A===Ot||d(A,l);function y(A,x){if(d(A,x))return A;throw new Error(`Expected valid scalar < ${x}, got ${typeof A} ${A}`)}function b(A){return A===Ot?A:y(A,n)}let w=new Map;function k(A){if(!(A instanceof v))throw new Error("ExtendedPoint expected")}class v{constructor(x,S,L,C){if(this.ex=x,this.ey=S,this.ez=L,this.et=C,!g(x))throw new Error("x required");if(!g(S))throw new Error("y required");if(!g(L))throw new Error("z required");if(!g(C))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(x){if(x instanceof v)throw new Error("extended point not allowed");let{x:S,y:L}=x||{};if(!g(S)||!g(L))throw new Error("invalid affine point");return new v(S,L,Nt,h(S*L))}static normalizeZ(x){let S=e.invertBatch(x.map(L=>L.ez));return x.map((L,C)=>L.toAffine(S[C])).map(v.fromAffine)}_setWindowSize(x){this._WINDOW_SIZE=x,w.delete(this)}assertValidity(){let{a:x,d:S}=t;if(this.is0())throw new Error("bad point: ZERO");let{ex:L,ey:C,ez:V,et:F}=this,G=h(L*L),M=h(C*C),K=h(V*V),st=h(K*K),Q=h(G*x),dt=h(K*h(Q+M)),pt=h(st+h(S*h(G*M)));if(dt!==pt)throw new Error("bad point: equation left != right (1)");let at=h(L*C),xt=h(V*F);if(at!==xt)throw new Error("bad point: equation left != right (2)")}equals(x){k(x);let{ex:S,ey:L,ez:C}=this,{ex:V,ey:F,ez:G}=x,M=h(S*G),K=h(V*C),st=h(L*G),Q=h(F*C);return M===K&&st===Q}is0(){return this.equals(v.ZERO)}negate(){return new v(h(-this.ex),this.ey,this.ez,h(-this.et))}double(){let{a:x}=t,{ex:S,ey:L,ez:C}=this,V=h(S*S),F=h(L*L),G=h(bn*h(C*C)),M=h(x*V),K=S+L,st=h(h(K*K)-V-F),Q=M+F,dt=Q-G,pt=M-F,at=h(st*dt),xt=h(Q*pt),Jt=h(st*pt),Oe=h(dt*Q);return new v(at,xt,Oe,Jt)}add(x){k(x);let{a:S,d:L}=t,{ex:C,ey:V,ez:F,et:G}=this,{ex:M,ey:K,ez:st,et:Q}=x;if(S===BigInt(-1)){let vi=h((V-C)*(K+M)),Ei=h((V+C)*(K-M)),Rs=h(Ei-vi);if(Rs===Ot)return this.double();let Ai=h(F*bn*Q),Bi=h(G*bn*st),Ii=Bi+Ai,Si=Ei+vi,ki=Bi-Ai,Pl=h(Ii*Rs),Dl=h(Si*ki),Ol=h(Ii*ki),Vl=h(Rs*Si);return new v(Pl,Dl,Vl,Ol)}let dt=h(C*M),pt=h(V*K),at=h(G*L*Q),xt=h(F*st),Jt=h((C+V)*(M+K)-dt-pt),Oe=xt-at,_r=xt+at,xi=h(pt-S*dt),Ll=h(Jt*Oe),_l=h(_r*xi),Cl=h(Jt*xi),Ul=h(Oe*_r);return new v(Ll,_l,Ul,Cl)}subtract(x){return this.add(x.negate())}wNAF(x){return T.wNAFCached(this,w,x,v.normalizeZ)}multiply(x){let{p:S,f:L}=this.wNAF(y(x,n));return v.normalizeZ([S,L])[0]}multiplyUnsafe(x){let S=b(x);return S===Ot?N:this.equals(N)||S===Nt?this:this.equals(B)?this.wNAF(S).p:T.unsafeLadder(this,S)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return T.unsafeLadder(this,n).is0()}toAffine(x){let{ex:S,ey:L,ez:C}=this,V=this.is0();x==null&&(x=V?Yf:e.inv(C));let F=h(S*x),G=h(L*x),M=h(C*x);if(V)return{x:Ot,y:Nt};if(M!==Nt)throw new Error("invZ was invalid");return{x:F,y:G}}clearCofactor(){let{h:x}=t;return x===Nt?this:this.multiplyUnsafe(x)}static fromHex(x,S=!1){let{d:L,a:C}=t,V=e.BYTES;x=et("pointHex",x,V);let F=x.slice(),G=x[V-1];F[V-1]=G&-129;let M=Ie(F);M===Ot||(S?y(M,l):y(M,e.ORDER));let K=h(M*M),st=h(K-Nt),Q=h(L*K-C),{isValid:dt,value:pt}=u(st,Q);if(!dt)throw new Error("Point.fromHex: invalid y coordinate");let at=(pt&Nt)===Nt,xt=(G&128)!==0;if(!S&&pt===Ot&&xt)throw new Error("Point.fromHex: x=0 and x_0=1");return xt!==at&&(pt=h(-pt)),v.fromAffine({x:pt,y:M})}static fromPrivateKey(x){return D(x).point}toRawBytes(){let{x,y:S}=this.toAffine(),L=Me(S,e.BYTES);return L[L.length-1]|=x&Nt?128:0,L}toHex(){return re(this.toRawBytes())}}v.BASE=new v(t.Gx,t.Gy,Nt,h(t.Gx*t.Gy)),v.ZERO=new v(Ot,Nt,Nt,Ot);let{BASE:B,ZERO:N}=v,T=yn(v,a*8);function z(A){return Y(A,n)}function $(A){return z(Ie(A))}function D(A){let x=a;A=et("private key",A,x);let S=et("hashed private key",o(A),2*x),L=m(S.slice(0,x)),C=S.slice(x,2*x),V=$(L),F=B.multiply(V),G=F.toRawBytes();return{head:L,prefix:C,scalar:V,point:F,pointBytes:G}}function nt(A){return D(A).pointBytes}function rt(A=new Uint8Array,...x){let S=se(...x);return $(o(f(S,et("context",A),!!s)))}function Tt(A,x,S={}){A=et("message",A),s&&(A=s(A));let{prefix:L,scalar:C,pointBytes:V}=D(x),F=rt(S.context,L,A),G=B.multiply(F).toRawBytes(),M=rt(S.context,G,V,A),K=z(F+M*C);b(K);let st=se(G,Me(K,e.BYTES));return et("result",st,a*2)}let E=Zf;function R(A,x,S,L=E){let{context:C,zip215:V}=L,F=e.BYTES;A=et("signature",A,2*F),x=et("message",x),s&&(x=s(x));let G=Ie(A.slice(F,2*F)),M,K,st;try{M=v.fromHex(S,V),K=v.fromHex(A.slice(0,F),V),st=B.multiplyUnsafe(G)}catch{return!1}if(!V&&M.isSmallOrder())return!1;let Q=rt(C,K.toRawBytes(),M.toRawBytes(),x);return K.add(M.multiplyUnsafe(Q)).subtract(st).clearCofactor().equals(v.ZERO)}return B._setWindowSize(8),{CURVE:t,getPublicKey:nt,sign:Tt,verify:R,ExtendedPoint:v,utils:{getExtendedPublicKey:D,randomPrivateKey:()=>i(e.BYTES),precompute(A=8,x=v.BASE){return x._setWindowSize(A),x.multiply(BigInt(3)),x}}}}var go=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),ma=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Hg=BigInt(0),Xf=BigInt(1),po=BigInt(2),Qf=BigInt(5),ya=BigInt(10),th=BigInt(20),eh=BigInt(40),ba=BigInt(80);function rh(r){let t=go,n=r*r%t*r%t,s=X(n,po,t)*n%t,o=X(s,Xf,t)*r%t,i=X(o,Qf,t)*o%t,a=X(i,ya,t)*i%t,c=X(a,th,t)*a%t,l=X(c,eh,t)*c%t,h=X(l,ba,t)*l%t,u=X(h,ba,t)*l%t,m=X(u,ya,t)*i%t;return{pow_p_5_8:X(m,po,t)*r%t,b2:n}}function nh(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function sh(r,t){let e=go,n=Y(t*t*t,e),s=Y(n*n*t,e),o=rh(r*s).pow_p_5_8,i=Y(r*n*o,e),a=Y(t*i*i,e),c=i,l=Y(i*ma,e),h=a===r,u=a===Y(-r,e),m=a===Y(-r*ma,e);return h&&(i=c),(u||m)&&(i=l),ha(i,e)&&(i=Y(-i,e)),{isValid:h||u,value:i}}var oe=mn(go,void 0,!0),mo={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:oe,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:lr,randomBytes:ar,adjustScalarBytes:nh,uvRatio:sh},ur=wn(mo);function wa(r,t,e){if(t.length>255)throw new Error("Context is too big");return un(ro("SigEd25519 no Ed25519 collisions"),new Uint8Array([e?1:0,t.length]),t,r)}var Mg=wn({...mo,domain:wa}),$g=wn({...mo,domain:wa,prehash:lr});var oh=(oe.ORDER+BigInt(3))/BigInt(8),Kg=oe.pow(po,oh),qg=oe.sqrt(oe.neg(oe.ONE)),zg=(oe.ORDER-BigInt(5))/BigInt(8),jg=BigInt(486662);var Gg=da(oe,oe.neg(BigInt(486664)));var Wg=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Yg=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Zg=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Jg=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var Xg=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var fr=32,ie=64,xn=32;function xa(){let r=ur.utils.randomPrivateKey(),t=ur.getPublicKey(r);return{privateKey:Ba(r,t),publicKey:t}}function va(r){if(r.length!==xn)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=ur.getPublicKey(t);return{privateKey:Ba(t,e),publicKey:e}}function Ea(r,t){let e=r.subarray(0,xn);return ur.sign(t instanceof Uint8Array?t:t.subarray(),e)}function Aa(r,t,e){return ur.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}function Ba(r,t){let e=new Uint8Array(ie);for(let n=0;n<xn;n++)e[n]=r[n],e[xn+n]=t[n];return e}var bt={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 yo={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function bo(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=bt.get();e*=8;async function c(u,m){let f=a.getRandomValues(new Uint8Array(o)),p=a.getRandomValues(new Uint8Array(n)),d={name:t,iv:p};typeof m=="string"&&(m=Z(m));let g;if(m.length===0){g=await a.subtle.importKey("jwk",yo,{name:"AES-GCM"},!0,["encrypt"]);try{let b={name:"PBKDF2",salt:f,iterations:i,hash:{name:s}},w=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);g=await a.subtle.deriveKey(b,w,{name:t,length:e},!0,["encrypt"])}catch{g=await a.subtle.importKey("jwk",yo,{name:"AES-GCM"},!0,["encrypt"])}}else{let b={name:"PBKDF2",salt:f,iterations:i,hash:{name:s}},w=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);g=await a.subtle.deriveKey(b,w,{name:t,length:e},!0,["encrypt"])}let y=await a.subtle.encrypt(d,g,u);return yt([f,d.iv,new Uint8Array(y)])}async function l(u,m){let f=u.subarray(0,o),p=u.subarray(o,o+n),d=u.subarray(o+n),g={name:t,iv:p};typeof m=="string"&&(m=Z(m));let y;if(m.length===0)try{let w={name:"PBKDF2",salt:f,iterations:i,hash:{name:s}},k=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(w,k,{name:t,length:e},!0,["decrypt"])}catch{y=await a.subtle.importKey("jwk",yo,{name:"AES-GCM"},!0,["decrypt"])}else{let w={name:"PBKDF2",salt:f,iterations:i,hash:{name:s}},k=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(w,k,{name:t,length:e},!0,["decrypt"])}let b=await a.subtle.decrypt(g,y,d);return new Uint8Array(b)}return{encrypt:c,decrypt:l}}async function hr(r,t){let n=await bo().encrypt(r,t);return nn.encode(n)}var wo=new Float32Array([-0]),ke=new Uint8Array(wo.buffer);function Sa(r,t,e){wo[0]=r,t[e]=ke[0],t[e+1]=ke[1],t[e+2]=ke[2],t[e+3]=ke[3]}function ka(r,t){return ke[0]=r[t],ke[1]=r[t+1],ke[2]=r[t+2],ke[3]=r[t+3],wo[0]}var xo=new Float64Array([-0]),Et=new Uint8Array(xo.buffer);function Ra(r,t,e){xo[0]=r,t[e]=Et[0],t[e+1]=Et[1],t[e+2]=Et[2],t[e+3]=Et[3],t[e+4]=Et[4],t[e+5]=Et[5],t[e+6]=Et[6],t[e+7]=Et[7]}function Na(r,t){return Et[0]=r[t],Et[1]=r[t+1],Et[2]=r[t+2],Et[3]=r[t+3],Et[4]=r[t+4],Et[5]=r[t+5],Et[6]=r[t+6],Et[7]=r[t+7],xo[0]}var ah=BigInt(Number.MAX_SAFE_INTEGER),ch=BigInt(Number.MIN_SAFE_INTEGER),St=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 Ke;if(t<ah&&t>ch)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>Ta&&(s=0n,++n>Ta&&(n=0n))),new r(Number(s),Number(n))}static fromNumber(t){if(t===0)return Ke;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):Ke}},Ke=new St(0,0);Ke.toBigInt=function(){return 0n};Ke.zzEncode=Ke.zzDecode=function(){return this};Ke.length=function(){return 1};var Ta=4294967296n;function La(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 _a(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 Vt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function vn(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,Vt(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 Vt(this,4);return vn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Vt(this,4);return vn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Vt(this,4);let t=ka(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Vt(this,4);let t=Na(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 Vt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return _a(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Vt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Vt(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 St(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 Vt(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 Vt(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 Vt(this,8);let t=vn(this.buf,this.pos+=4),e=vn(this.buf,this.pos+=4);return new St(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){return this.readLongVarint().toNumber(!0)}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 Ao(r){return new Eo(r instanceof Uint8Array?r:r.subarray())}function Ft(r,t){let e=Ao(r);return t.decode(e)}function Bo(r){let t=r??8192,e=t>>>1,n,s=t;return function(i){if(i<1||i>e)return vt(i);s+i>t&&(n=vt(t),s=0);let a=n.subarray(s,s+=i);return s&7&&(s=(s|7)+1),a}}var qe=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Io(){}var ko=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},lh=Bo();function uh(r){return globalThis.Buffer!=null?vt(r):lh(r)}var Mr=class{len;head;tail;states;constructor(){this.len=0,this.head=new qe(Io,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new qe(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(Fr,10,St.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=St.fromBigInt(t);return this._push(Fr,e.length(),e)}uint64Number(t){let e=St.fromNumber(t);return this._push(Fr,e.length(),e)}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=St.fromBigInt(t).zzEncode();return this._push(Fr,e.length(),e)}sint64Number(t){let e=St.fromNumber(t).zzEncode();return this._push(Fr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(So,1,t?1:0)}fixed32(t){return this._push(Hr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=St.fromBigInt(t);return this._push(Hr,4,e.lo)._push(Hr,4,e.hi)}fixed64Number(t){let e=St.fromNumber(t);return this._push(Hr,4,e.lo)._push(Hr,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(Sa,4,t)}double(t){return this._push(Ra,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(So,1,0):this.uint32(e)._push(hh,e,t)}string(t){let e=La(t);return e!==0?this.uint32(e)._push(vo,e,t):this._push(So,1,0)}fork(){return this.states=new ko(this),this.head=this.tail=new qe(Io,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 qe(Io,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=uh(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function So(r,t,e){t[e]=r&255}function fh(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Ro=class extends qe{next;constructor(t,e){super(fh,t,e),this.next=void 0}};function Fr(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 Hr(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 hh(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Mr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(dh,t,r),this},Mr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(ph,t,r),this});function dh(r,t,e){t.set(r,e)}function ph(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 Mr}function Ht(r,t){let e=No();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var dr;(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"})(dr||(dr={}));function En(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function pr(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 En("enum",dr.VARINT,e,n)}function Mt(r,t){return En("message",dr.LENGTH_DELIMITED,r,t)}var ft;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1"})(ft||(ft={}));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=()=>pr(To)})(ft||(ft={}));var ae;(function(r){let t;r.codec=()=>(t==null&&(t=Mt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),ft.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=ft.codec().decode(e);break;case 2:s.Data=e.bytes();break;default:e.skipType(i&7);break}}return s})),t),r.encode=e=>Ht(e,r.codec()),r.decode=e=>Ft(e,r.codec())})(ae||(ae={}));var ce;(function(r){let t;r.codec=()=>(t==null&&(t=Mt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),ft.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=ft.codec().decode(e);break;case 2:s.Data=e.bytes();break;default:e.skipType(i&7);break}}return s})),t),r.encode=e=>Ht(e,r.codec()),r.decode=e=>Ft(e,r.codec())})(ce||(ce={}));var gr=class{_key;constructor(t){this._key=mr(t,fr)}verify(t,e){return Aa(this._key,e,t)}marshal(){return this._key}get bytes(){return ae.encode({Type:ft.Ed25519,Data:this.marshal()}).subarray()}equals(t){return mt(this.bytes,t.bytes)}hash(){let t=gt.digest(this.bytes);return Lt(t)?t.then(({bytes:e})=>e):t.bytes}},Re=class{_key;_publicKey;constructor(t,e){this._key=mr(t,ie),this._publicKey=mr(e,fr)}sign(t){return Ea(this._key,t)}get public(){return new gr(this._publicKey)}marshal(){return this._key}get bytes(){return ce.encode({Type:ft.Ed25519,Data:this.marshal()}).subarray()}equals(t){return mt(this.bytes,t.bytes)}async hash(){let t=gt.digest(this.bytes),e;return Lt(t)?{bytes:e}=await t:e=t.bytes,e}async id(){let t=we.digest(this.public.bytes);return ct.encode(t.bytes).substring(1)}async export(t,e="libp2p-key"){if(e==="libp2p-key")return hr(this.bytes,t);throw new _(`export format '${e}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function gh(r){if(r.length>ie){r=mr(r,ie+fr);let n=r.subarray(0,ie),s=r.subarray(ie,r.length);return new Re(n,s)}r=mr(r,ie);let t=r.subarray(0,ie),e=r.subarray(fr);return new Re(t,e)}function mh(r){return r=mr(r,fr),new gr(r)}async function yh(){let{privateKey:r,publicKey:t}=xa();return new Re(r,t)}async function Ua(r){let{privateKey:t,publicKey:e}=va(r);return new Re(t,e)}function mr(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new _(`Key must be a Uint8Array of length ${t}, got ${r.length}`,"ERR_INVALID_KEY_TYPE");return r}function q(r,t="utf8"){let e=an[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):e.encoder.encode(r).substring(1)}var bh={"P-256":256,"P-384":384,"P-521":521},wh=Object.keys(bh),Qm=wh.join(" / ");var Mo={};ut(Mo,{MAX_RSA_KEY_SIZE:()=>Er,RsaPrivateKey:()=>Ge,RsaPublicKey:()=>vr,fromJwk:()=>jh,generateKeyPair:()=>Gh,unmarshalRsaPrivateKey:()=>Fo,unmarshalRsaPublicKey:()=>zh});function ze(r){if(isNaN(r)||r<=0)throw new _("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return ar(r)}var _e={};ut(_e,{exportToPem:()=>Mh,importFromPem:()=>Ac,jwkToPkcs1:()=>Oh,jwkToPkix:()=>Fh,pkcs1ToJwk:()=>Dh,pkixToJwk:()=>Vh});var Bn=class extends or{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,cn(t);let n=Ee(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 sr(this),this.iHash.update(t),this}digestInto(t){sr(this),eo(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()}},$r=(r,t,e)=>new Bn(r,t).update(e).digest();$r.create=(r,t)=>new Bn(r,t);function vh(r,t,e,n){cn(r);let s=sa({dkLen:32,asyncTick:10},n),{c:o,dkLen:i,asyncTick:a}=s;if(nr(o),nr(i),nr(a),o<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=Ee(t),l=Ee(e),h=new Uint8Array(i),u=$r.create(r,c),m=u._cloneInto().update(l);return{c:o,dkLen:i,asyncTick:a,DK:h,PRF:u,PRFSalt:m}}function Eh(r,t,e,n,s){return r.destroy(),t.destroy(),n&&n.destroy(),s.fill(0),e}async function _o(r,t,e,n){let{c:s,dkLen:o,asyncTick:i,DK:a,PRF:c,PRFSalt:l}=vh(r,t,e,n),h,u=new Uint8Array(4),m=ir(u),f=new Uint8Array(c.outputLen);for(let p=1,d=0;d<o;p++,d+=c.outputLen){let g=a.subarray(d,d+c.outputLen);m.setInt32(0,p,!1),(h=l._cloneInto(h)).update(u).digestInto(f),g.set(f.subarray(0,g.length)),await na(s-1,i,()=>{c._cloneInto(h).update(f).digestInto(f);for(let y=0;y<g.length;y++)g[y]^=f[y]})}return Eh(c,l,a,h,f)}var H=rn(Pa());function je(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 Ne(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 h=a-1;h>=0;h--){let u=Math.pow(2,h*t);l[o-h-1]=Math.floor(s/u),s-=l[o-h-1]*u}return c}i*=Math.pow(2,t)}return new ArrayBuffer(0)}function kn(...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 Uo(){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=je(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,je(o,8)-n}function Da(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=Ne(i,8,n),c=new Uint8Array(a);return c[0]|=128,a}let s=Ne(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 Oa(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 Sy=Math.log(2);function Rn(){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 de(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 qr=class{constructor(){this.items=[]}write(t){this.items.push(t)}final(){return Po(this.items)}},Kr=[new Uint8Array([1])],Va="0123456789";var wr="",Kt=new ArrayBuffer(0),Do=new Uint8Array(0),zr="EndOfContent",Ha="OCTET STRING",Ma="BIT STRING";function pe(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):Do}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(!de(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",Kt)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:H.Convert.ToHex(this.valueHexView)}}},t.NAME="hexBlock",t}var ue=class{constructor({blockLength:t=0,error:e=wr,warnings:n=[],valueBeforeDecode:s=Do}={}){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)}}};ue.NAME="baseBlock";var At=class extends ue{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'")}};At.NAME="valueBlock";var Nn=class extends pe(ue){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):Do,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",Kt}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=Ne(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(!de(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),h=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===h){h+=255;let m=new Uint8Array(h);for(let f=0;f<l.length;f++)m[f]=l[f];l=this.valueHexView=new Uint8Array(h)}}this.blockLength=c+1,l[c-1]=o[c]&127;let u=new Uint8Array(c);for(let m=0;m<c;m++)u[m]=l[m];l=this.valueHexView=new Uint8Array(c),l.set(u),this.blockLength<=9?this.tagNumber=je(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}}};Nn.NAME="identificationBlock";var Tn=class extends ue{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(!de(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=je(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=Ne(this.length,8);if(s.byteLength>127)return this.error="Too big length",Kt;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}}};Tn.NAME="lengthBlock";var I={},wt=class extends ue{constructor({name:t=wr,optional:e=!1,primitiveSchema:n,...s}={},o){super(s),this.name=t,this.optional=e,n&&(this.primitiveSchema=n),this.idBlock=new Nn(s),this.lenBlock=new Tn(s),this.valueBlock=o?new o(s):new At(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 qr;e||$a(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?Kt: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 Oa(e,n)}};wt.NAME="BaseBlock";function $a(r){if(r instanceof I.Constructed)for(let t of r.valueBlock.value)$a(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var Ln=class extends wt{constructor({value:t=wr,...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}'`}};Ln.NAME="BaseStringBlock";var _n=class extends pe(At){constructor({isHexOnly:t=!0,...e}={}){super(e),this.isHexOnly=t}};_n.NAME="PrimitiveValueBlock";var Ka,Cn=class extends wt{constructor(t={}){super(t,_n),this.idBlock.isConstructed=!1}};Ka=Cn;I.Primitive=Ka;Cn.NAME="PRIMITIVE";function Lh(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 hs(r,t=0,e=r.length){let n=t,s=new wt({},At),o=new ue;if(!de(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=wt;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=I.EndOfContent;break;case 1:c=I.Boolean;break;case 2:c=I.Integer;break;case 3:c=I.BitString;break;case 4:c=I.OctetString;break;case 5:c=I.Null;break;case 6:c=I.ObjectIdentifier;break;case 10:c=I.Enumerated;break;case 12:c=I.Utf8String;break;case 13:c=I.RelativeObjectIdentifier;break;case 14:c=I.TIME;break;case 15:return s.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:s};case 16:c=I.Sequence;break;case 17:c=I.Set;break;case 18:c=I.NumericString;break;case 19:c=I.PrintableString;break;case 20:c=I.TeletexString;break;case 21:c=I.VideotexString;break;case 22:c=I.IA5String;break;case 23:c=I.UTCTime;break;case 24:c=I.GeneralizedTime;break;case 25:c=I.GraphicString;break;case 26:c=I.VisibleString;break;case 27:c=I.GeneralString;break;case 28:c=I.UniversalString;break;case 29:c=I.CharacterString;break;case 30:c=I.BmpString;break;case 31:c=I.DATE;break;case 32:c=I.TimeOfDay;break;case 33:c=I.DateTime;break;case 34:c=I.Duration;break;default:{let l=s.idBlock.isConstructed?new I.Constructed:new I.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?I.Constructed:I.Primitive}return s=Lh(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 xr(r){if(!r.byteLength){let t=new wt({},At);return t.error="Input buffer has zero length",{offset:-1,result:t}}return hs(H.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function _h(r,t){return r?1:t}var Wt=class extends At{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(!de(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(;_h(this.isIndefiniteForm,n)>0;){let i=hs(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===zr)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===zr?this.value.pop():this.warnings.push("No EndOfContent block encoded")),o}toBER(t,e){let n=e||new qr;for(let s=0;s<this.value.length;s++)this.value[s].toBER(t,n);return e?Kt:n.final()}toJSON(){let t={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let e of this.value)t.value.push(e.toJSON());return t}};Wt.NAME="ConstructedValueBlock";var qa,Te=class extends wt{constructor(t={}){super(t,Wt),this.idBlock.isConstructed=!0}fromBER(t,e,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let s=this.valueBlock.fromBER(t,e,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),s)}onAsciiEncoding(){let t=[];for(let n of this.valueBlock.value)t.push(n.toString("ascii").split(`
2
+ "use strict";var Libp2PAutonat=(()=>{var Cl=Object.create;var tn=Object.defineProperty;var Ul=Object.getOwnPropertyDescriptor;var Pl=Object.getOwnPropertyNames;var Dl=Object.getPrototypeOf,Ol=Object.prototype.hasOwnProperty;var en=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),ut=(r,t)=>{for(var e in t)tn(r,e,{get:t[e],enumerable:!0})},Ii=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Pl(t))!Ol.call(r,s)&&s!==e&&tn(r,s,{get:()=>t[s],enumerable:!(n=Ul(t,s))||n.enumerable});return r};var rn=(r,t,e)=>(e=r!=null?Cl(Dl(r)):{},Ii(t||!r||!r.__esModule?tn(e,"default",{value:r,enumerable:!0}):e,r)),Vl=r=>Ii(tn({},"__esModule",{value:!0}),r);var Ta=en(gr=>{"use strict";var gh="[object ArrayBuffer]",ae=class r{static isArrayBuffer(t){return Object.prototype.toString.call(t)===gh}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}},Lo="string",mh=/^[0-9a-f]+$/i,yh=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,bh=/^[a-zA-Z0-9-_]+$/,Bn=class{static fromString(t){let e=unescape(encodeURIComponent(t)),n=new Uint8Array(e.length);for(let s=0;s<e.length;s++)n[s]=e.charCodeAt(s);return n.buffer}static toString(t){let e=ae.toUint8Array(t),n="";for(let o=0;o<e.length;o++)n+=String.fromCharCode(e[o]);return decodeURIComponent(escape(n))}},_t=class{static toString(t,e=!1){let n=ae.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}},An=class r{static isHex(t){return typeof t===Lo&&mh.test(t)}static isBase64(t){return typeof t===Lo&&yh.test(t)}static isBase64Url(t){return typeof t===Lo&&bh.test(t)}static ToString(t,e="utf8"){let n=ae.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 _t.toString(n,!0);case"utf16":case"utf16be":return _t.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 _t.fromString(t,!0);case"utf16":case"utf16be":return _t.fromString(t);default:throw new Error(`Unknown type of encoding '${e}'`)}}static ToBase64(t){let e=ae.toUint8Array(t);if(typeof btoa<"u"){let n=this.ToString(e,"binary");return btoa(n)}else return Buffer.from(e).toString("base64")}static FromBase64(t){let e=this.formatString(t);if(!e)return new ArrayBuffer(0);if(!r.isBase64(e))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(e)):new Uint8Array(Buffer.from(e,"base64")).buffer}static FromBase64Url(t){let e=this.formatString(t);if(!e)return new ArrayBuffer(0);if(!r.isBase64Url(e))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(e.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(t){return this.ToBase64(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(t,e=r.DEFAULT_UTF8_ENCODING){switch(e){case"ascii":return this.FromBinary(t);case"utf8":return Bn.fromString(t);case"utf16":case"utf16be":return _t.fromString(t);case"utf16le":case"usc2":return _t.fromString(t,!0);default:throw new Error(`Unknown type of encoding '${e}'`)}}static ToUtf8String(t,e=r.DEFAULT_UTF8_ENCODING){switch(e){case"ascii":return this.ToBinary(t);case"utf8":return Bn.toString(t);case"utf16":case"utf16be":return _t.toString(t);case"utf16le":case"usc2":return _t.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=ae.toUint8Array(t),n="";for(let s=0;s<e.length;s++)n+=String.fromCharCode(e[s]);return n}static ToHex(t){let e=ae.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 _t.toString(t,e)}static FromUtf16String(t,e=!1){return _t.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,"")||""}};An.DEFAULT_UTF8_ENCODING="utf8";function wh(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 xh(...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 vh(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}gr.BufferSourceConverter=ae;gr.Convert=An;gr.assign=wh;gr.combine=xh;gr.isEqual=vh});var al=en((Mb,il)=>{"use strict";function ol(r,t){for(let e in t)Object.defineProperty(r,e,{value:t[e],enumerable:!0,configurable:!0});return r}function Cd(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 ol(r,e)}catch{e.message=r.message,e.stack=r.stack;let s=function(){};return s.prototype=Object.create(Object.getPrototypeOf(r)),ol(new s,e)}}il.exports=Cd});var dl=en(Qr=>{(function(){var r,t,e,n,s,o,i,a;a=function(c){var l,h,u,m;return l=(c&255<<24)>>>24,h=(c&255<<16)>>>16,u=(c&65280)>>>8,m=c&255,[l,h,u,m].join(".")},i=function(c){var l,h,u,m,f,p;for(l=[],u=m=0;m<=3&&c.length!==0;u=++m){if(u>0){if(c[0]!==".")throw new Error("Invalid IP");c=c.substring(1)}p=t(c),f=p[0],h=p[1],c=c.substring(h),l.push(f)}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,h,u,m,f;for(m=0,l=10,h="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,h="7")),f=u;u<c.length;){if("0"<=c[u]&&c[u]<=h)m=m*l+(e(c[u])-n)>>>0;else if(l===16)if("a"<=c[u]&&c[u]<="f")m=m*l+(10+e(c[u])-o)>>>0;else if("A"<=c[u]&&c[u]<="F")m=m*l+(10+e(c[u])-s)>>>0;else break;else break;if(m>4294967295)throw new Error("too large");u++}if(u===f)throw new Error("empty octet");return[m,u]},r=function(){function c(l,h){var u,m,f,p;if(typeof l!="string")throw new Error("Missing `net' parameter");if(h||(p=l.split("/",2),l=p[0],h=p[1]),h||(h=32),typeof h=="string"&&h.indexOf(".")>-1){try{this.maskLong=i(h)}catch(d){throw u=d,new Error("Invalid mask: "+h)}for(m=f=32;f>=0;m=--f)if(this.maskLong===4294967295<<32-m>>>0){this.bitmask=m;break}}else if(h||h===0)this.bitmask=parseInt(h,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: "+h);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 h,u,m;for(m=i(this.first),u=i(this.last),h=0;m<=u;)l(a(m),m,h),h++,m++},c.prototype.toString=function(){return this.base+"/"+this.bitmask},c}(),Qr.ip2long=i,Qr.long2ip=a,Qr.Netmask=r}).call(Qr)});var yl=en((ml,As)=>{(function(r){"use strict";let t="(0?\\d+|0x[a-f0-9]+)",e={fourOctet:new RegExp(`^${t}\\.${t}\\.${t}\\.${t}$`,"i"),threeOctet:new RegExp(`^${t}\\.${t}\\.${t}$`,"i"),twoOctet:new RegExp(`^${t}\\.${t}$`,"i"),longValue:new RegExp(`^${t}$`,"i")},n=new RegExp("^0[0-7]+$","i"),s=new RegExp("^0x[a-f0-9]+$","i"),o="%[0-9a-z]{1,}",i="(?:[0-9a-f]+::?)+",a={zoneIndex:new RegExp(o,"i"),native:new RegExp(`^(::)?(${i})?([0-9a-f]+)?(::)?(${o})?$`,"i"),deprecatedTransitional:new RegExp(`^(?:::)(${t}\\.${t}\\.${t}\\.${t}(${o})?)$`,"i"),transitional:new RegExp(`^((?:${i})|(?:::)(?:${i})?)${t}\\.${t}\\.${t}\\.${t}(${o})?$`,"i")};function c(f,p){if(f.indexOf("::")!==f.lastIndexOf("::"))return null;let d=0,g=-1,y=(f.match(a.zoneIndex)||[])[0],b,w;for(y&&(y=y.substring(1),f=f.replace(/%.+$/,""));(g=f.indexOf(":",g+1))>=0;)d++;if(f.substr(0,2)==="::"&&d--,f.substr(-2,2)==="::"&&d--,d>p)return null;for(w=p-d,b=":";w--;)b+="0:";return f=f.replace("::",b),f[0]===":"&&(f=f.slice(1)),f[f.length-1]===":"&&(f=f.slice(0,-1)),p=function(){let k=f.split(":"),v=[];for(let A=0;A<k.length;A++)v.push(parseInt(k[A],16));return v}(),{parts:p,zoneId:y}}function l(f,p,d,g){if(f.length!==p.length)throw new Error("ipaddr: cannot match CIDR for objects with different lengths");let y=0,b;for(;g>0;){if(b=d-g,b<0&&(b=0),f[y]>>b!==p[y]>>b)return!1;g-=d,y+=1}return!0}function h(f){if(s.test(f))return parseInt(f,16);if(f[0]==="0"&&!isNaN(parseInt(f[1],10))){if(n.test(f))return parseInt(f,8);throw new Error(`ipaddr: cannot parse ${f} as octal`)}return parseInt(f,10)}function u(f,p){for(;f.length<p;)f=`0${f}`;return f}let m={};m.IPv4=function(){function f(p){if(p.length!==4)throw new Error("ipaddr: ipv4 octet count should be 4");let d,g;for(d=0;d<p.length;d++)if(g=p[d],!(0<=g&&g<=255))throw new Error("ipaddr: ipv4 octet should fit in 8 bits");this.octets=p}return f.prototype.SpecialRanges={unspecified:[[new f([0,0,0,0]),8]],broadcast:[[new f([255,255,255,255]),32]],multicast:[[new f([224,0,0,0]),4]],linkLocal:[[new f([169,254,0,0]),16]],loopback:[[new f([127,0,0,0]),8]],carrierGradeNat:[[new f([100,64,0,0]),10]],private:[[new f([10,0,0,0]),8],[new f([172,16,0,0]),12],[new f([192,168,0,0]),16]],reserved:[[new f([192,0,0,0]),24],[new f([192,0,2,0]),24],[new f([192,88,99,0]),24],[new f([198,18,0,0]),15],[new f([198,51,100,0]),24],[new f([203,0,113,0]),24],[new f([240,0,0,0]),4]]},f.prototype.kind=function(){return"ipv4"},f.prototype.match=function(p,d){let g;if(d===void 0&&(g=p,p=g[0],d=g[1]),p.kind()!=="ipv4")throw new Error("ipaddr: cannot match ipv4 address with non-ipv4 one");return l(this.octets,p.octets,8,d)},f.prototype.prefixLengthFromSubnetMask=function(){let p=0,d=!1,g={0:8,128:7,192:6,224:5,240:4,248:3,252:2,254:1,255:0},y,b,w;for(y=3;y>=0;y-=1)if(b=this.octets[y],b in g){if(w=g[b],d&&w!==0)return null;w!==8&&(d=!0),p+=w}else return null;return 32-p},f.prototype.range=function(){return m.subnetMatch(this,this.SpecialRanges)},f.prototype.toByteArray=function(){return this.octets.slice(0)},f.prototype.toIPv4MappedAddress=function(){return m.IPv6.parse(`::ffff:${this.toString()}`)},f.prototype.toNormalizedString=function(){return this.toString()},f.prototype.toString=function(){return this.octets.join(".")},f}(),m.IPv4.broadcastAddressFromCIDR=function(f){try{let p=this.parseCIDR(f),d=p[0].toByteArray(),g=this.subnetMaskFromPrefixLength(p[1]).toByteArray(),y=[],b=0;for(;b<4;)y.push(parseInt(d[b],10)|parseInt(g[b],10)^255),b++;return new this(y)}catch{throw new Error("ipaddr: the address does not have IPv4 CIDR format")}},m.IPv4.isIPv4=function(f){return this.parser(f)!==null},m.IPv4.isValid=function(f){try{return new this(this.parser(f)),!0}catch{return!1}},m.IPv4.isValidFourPartDecimal=function(f){return!!(m.IPv4.isValid(f)&&f.match(/^(0|[1-9]\d*)(\.(0|[1-9]\d*)){3}$/))},m.IPv4.networkAddressFromCIDR=function(f){let p,d,g,y,b;try{for(p=this.parseCIDR(f),g=p[0].toByteArray(),b=this.subnetMaskFromPrefixLength(p[1]).toByteArray(),y=[],d=0;d<4;)y.push(parseInt(g[d],10)&parseInt(b[d],10)),d++;return new this(y)}catch{throw new Error("ipaddr: the address does not have IPv4 CIDR format")}},m.IPv4.parse=function(f){let p=this.parser(f);if(p===null)throw new Error("ipaddr: string is not formatted like an IPv4 Address");return new this(p)},m.IPv4.parseCIDR=function(f){let p;if(p=f.match(/^(.+)\/(\d+)$/)){let d=parseInt(p[2]);if(d>=0&&d<=32){let g=[this.parse(p[1]),d];return Object.defineProperty(g,"toString",{value:function(){return this.join("/")}}),g}}throw new Error("ipaddr: string is not formatted like an IPv4 CIDR range")},m.IPv4.parser=function(f){let p,d,g;if(p=f.match(e.fourOctet))return function(){let y=p.slice(1,6),b=[];for(let w=0;w<y.length;w++)d=y[w],b.push(h(d));return b}();if(p=f.match(e.longValue)){if(g=h(p[1]),g>4294967295||g<0)throw new Error("ipaddr: address outside defined range");return function(){let y=[],b;for(b=0;b<=24;b+=8)y.push(g>>b&255);return y}().reverse()}else return(p=f.match(e.twoOctet))?function(){let y=p.slice(1,4),b=[];if(g=h(y[1]),g>16777215||g<0)throw new Error("ipaddr: address outside defined range");return b.push(h(y[0])),b.push(g>>16&255),b.push(g>>8&255),b.push(g&255),b}():(p=f.match(e.threeOctet))?function(){let y=p.slice(1,5),b=[];if(g=h(y[2]),g>65535||g<0)throw new Error("ipaddr: address outside defined range");return b.push(h(y[0])),b.push(h(y[1])),b.push(g>>8&255),b.push(g&255),b}():null},m.IPv4.subnetMaskFromPrefixLength=function(f){if(f=parseInt(f),f<0||f>32)throw new Error("ipaddr: invalid IPv4 prefix length");let p=[0,0,0,0],d=0,g=Math.floor(f/8);for(;d<g;)p[d]=255,d++;return g<4&&(p[g]=Math.pow(2,f%8)-1<<8-f%8),new this(p)},m.IPv6=function(){function f(p,d){let g,y;if(p.length===16)for(this.parts=[],g=0;g<=14;g+=2)this.parts.push(p[g]<<8|p[g+1]);else if(p.length===8)this.parts=p;else throw new Error("ipaddr: ipv6 part count should be 8 or 16");for(g=0;g<this.parts.length;g++)if(y=this.parts[g],!(0<=y&&y<=65535))throw new Error("ipaddr: ipv6 part should fit in 16 bits");d&&(this.zoneId=d)}return f.prototype.SpecialRanges={unspecified:[new f([0,0,0,0,0,0,0,0]),128],linkLocal:[new f([65152,0,0,0,0,0,0,0]),10],multicast:[new f([65280,0,0,0,0,0,0,0]),8],loopback:[new f([0,0,0,0,0,0,0,1]),128],uniqueLocal:[new f([64512,0,0,0,0,0,0,0]),7],ipv4Mapped:[new f([0,0,0,0,0,65535,0,0]),96],rfc6145:[new f([0,0,0,0,65535,0,0,0]),96],rfc6052:[new f([100,65435,0,0,0,0,0,0]),96],"6to4":[new f([8194,0,0,0,0,0,0,0]),16],teredo:[new f([8193,0,0,0,0,0,0,0]),32],reserved:[[new f([8193,3512,0,0,0,0,0,0]),32]],benchmarking:[new f([8193,2,0,0,0,0,0,0]),48],amt:[new f([8193,3,0,0,0,0,0,0]),32],as112v6:[new f([8193,4,274,0,0,0,0,0]),48],deprecated:[new f([8193,16,0,0,0,0,0,0]),28],orchid2:[new f([8193,32,0,0,0,0,0,0]),28]},f.prototype.isIPv4MappedAddress=function(){return this.range()==="ipv4Mapped"},f.prototype.kind=function(){return"ipv6"},f.prototype.match=function(p,d){let g;if(d===void 0&&(g=p,p=g[0],d=g[1]),p.kind()!=="ipv6")throw new Error("ipaddr: cannot match ipv6 address with non-ipv6 one");return l(this.parts,p.parts,16,d)},f.prototype.prefixLengthFromSubnetMask=function(){let p=0,d=!1,g={0:16,32768:15,49152:14,57344:13,61440:12,63488:11,64512:10,65024:9,65280:8,65408:7,65472:6,65504:5,65520:4,65528:3,65532:2,65534:1,65535:0},y,b;for(let w=7;w>=0;w-=1)if(y=this.parts[w],y in g){if(b=g[y],d&&b!==0)return null;b!==16&&(d=!0),p+=b}else return null;return 128-p},f.prototype.range=function(){return m.subnetMatch(this,this.SpecialRanges)},f.prototype.toByteArray=function(){let p,d=[],g=this.parts;for(let y=0;y<g.length;y++)p=g[y],d.push(p>>8),d.push(p&255);return d},f.prototype.toFixedLengthString=function(){let p=function(){let g=[];for(let y=0;y<this.parts.length;y++)g.push(u(this.parts[y].toString(16),4));return g}.call(this).join(":"),d="";return this.zoneId&&(d=`%${this.zoneId}`),p+d},f.prototype.toIPv4Address=function(){if(!this.isIPv4MappedAddress())throw new Error("ipaddr: trying to convert a generic ipv6 address to ipv4");let p=this.parts.slice(-2),d=p[0],g=p[1];return new m.IPv4([d>>8,d&255,g>>8,g&255])},f.prototype.toNormalizedString=function(){let p=function(){let g=[];for(let y=0;y<this.parts.length;y++)g.push(this.parts[y].toString(16));return g}.call(this).join(":"),d="";return this.zoneId&&(d=`%${this.zoneId}`),p+d},f.prototype.toRFC5952String=function(){let p=/((^|:)(0(:|$)){2,})/g,d=this.toNormalizedString(),g=0,y=-1,b;for(;b=p.exec(d);)b[0].length>y&&(g=b.index,y=b[0].length);return y<0?d:`${d.substring(0,g)}::${d.substring(g+y)}`},f.prototype.toString=function(){return this.toRFC5952String()},f}(),m.IPv6.broadcastAddressFromCIDR=function(f){try{let p=this.parseCIDR(f),d=p[0].toByteArray(),g=this.subnetMaskFromPrefixLength(p[1]).toByteArray(),y=[],b=0;for(;b<16;)y.push(parseInt(d[b],10)|parseInt(g[b],10)^255),b++;return new this(y)}catch(p){throw new Error(`ipaddr: the address does not have IPv6 CIDR format (${p})`)}},m.IPv6.isIPv6=function(f){return this.parser(f)!==null},m.IPv6.isValid=function(f){if(typeof f=="string"&&f.indexOf(":")===-1)return!1;try{let p=this.parser(f);return new this(p.parts,p.zoneId),!0}catch{return!1}},m.IPv6.networkAddressFromCIDR=function(f){let p,d,g,y,b;try{for(p=this.parseCIDR(f),g=p[0].toByteArray(),b=this.subnetMaskFromPrefixLength(p[1]).toByteArray(),y=[],d=0;d<16;)y.push(parseInt(g[d],10)&parseInt(b[d],10)),d++;return new this(y)}catch(w){throw new Error(`ipaddr: the address does not have IPv6 CIDR format (${w})`)}},m.IPv6.parse=function(f){let p=this.parser(f);if(p.parts===null)throw new Error("ipaddr: string is not formatted like an IPv6 Address");return new this(p.parts,p.zoneId)},m.IPv6.parseCIDR=function(f){let p,d,g;if((d=f.match(/^(.+)\/(\d+)$/))&&(p=parseInt(d[2]),p>=0&&p<=128))return g=[this.parse(d[1]),p],Object.defineProperty(g,"toString",{value:function(){return this.join("/")}}),g;throw new Error("ipaddr: string is not formatted like an IPv6 CIDR range")},m.IPv6.parser=function(f){let p,d,g,y,b,w;if(g=f.match(a.deprecatedTransitional))return this.parser(`::ffff:${g[1]}`);if(a.native.test(f))return c(f,8);if((g=f.match(a.transitional))&&(w=g[6]||"",p=c(g[1].slice(0,-1)+w,6),p.parts)){for(b=[parseInt(g[2]),parseInt(g[3]),parseInt(g[4]),parseInt(g[5])],d=0;d<b.length;d++)if(y=b[d],!(0<=y&&y<=255))return null;return p.parts.push(b[0]<<8|b[1]),p.parts.push(b[2]<<8|b[3]),{parts:p.parts,zoneId:p.zoneId}}return null},m.IPv6.subnetMaskFromPrefixLength=function(f){if(f=parseInt(f),f<0||f>128)throw new Error("ipaddr: invalid IPv6 prefix length");let p=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],d=0,g=Math.floor(f/8);for(;d<g;)p[d]=255,d++;return g<16&&(p[g]=Math.pow(2,f%8)-1<<8-f%8),new this(p)},m.fromByteArray=function(f){let p=f.length;if(p===4)return new m.IPv4(f);if(p===16)return new m.IPv6(f);throw new Error("ipaddr: the binary input is neither an IPv6 nor IPv4 address")},m.isValid=function(f){return m.IPv6.isValid(f)||m.IPv4.isValid(f)},m.parse=function(f){if(m.IPv6.isValid(f))return m.IPv6.parse(f);if(m.IPv4.isValid(f))return m.IPv4.parse(f);throw new Error("ipaddr: the address has neither IPv6 nor IPv4 format")},m.parseCIDR=function(f){try{return m.IPv6.parseCIDR(f)}catch{try{return m.IPv4.parseCIDR(f)}catch{throw new Error("ipaddr: the address has neither IPv6 nor IPv4 CIDR format")}}},m.process=function(f){let p=this.parse(f);return p.kind()==="ipv6"&&p.isIPv4MappedAddress()?p.toIPv4Address():p},m.subnetMatch=function(f,p,d){let g,y,b,w;d==null&&(d="unicast");for(y in p)if(Object.prototype.hasOwnProperty.call(p,y)){for(b=p[y],b[0]&&!(b[0]instanceof Array)&&(b=[b]),g=0;g<b.length;g++)if(w=b[g],f.kind()===w[0].kind()&&f.match.apply(f,w))return y}return d},typeof As<"u"&&As.exports?As.exports=m:r.ipaddr=m})(ml)});var o0={};ut(o0,{autoNAT:()=>s0});var Si=Symbol.for("@libp2p/peer-id");var C=class extends Error{code;props;constructor(t,e,n){super(t),this.code=e,this.name=n?.name??"CodeError",this.props=n??{}}};var ks="ERR_TIMEOUT";var Rs=(r,...t)=>{try{[...t]}catch{}};var Cs={};ut(Cs,{base58btc:()=>ct,base58flickr:()=>ql});var u0=new Uint8Array(0);function ki(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 Zt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function Ri(r){return new TextEncoder().encode(r)}function Ni(r){return new TextDecoder().decode(r)}function Fl(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),h=Math.log(256)/Math.log(a);function u(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var d=0,g=0,y=0,b=p.length;y!==b&&p[y]===0;)y++,d++;for(var w=(b-y)*h+1>>>0,k=new Uint8Array(w);y!==b;){for(var v=p[y],A=0,N=w-1;(v!==0||A<g)&&N!==-1;N--,A++)v+=256*k[N]>>>0,k[N]=v%a>>>0,v=v/a>>>0;if(v!==0)throw new Error("Non-zero carry");g=A,y++}for(var T=w-g;T!==w&&k[T]===0;)T++;for(var q=c.repeat(d);T<w;++T)q+=r.charAt(k[T]);return q}function m(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var d=0;if(p[d]!==" "){for(var g=0,y=0;p[d]===c;)g++,d++;for(var b=(p.length-d)*l+1>>>0,w=new Uint8Array(b);p[d];){var k=e[p.charCodeAt(d)];if(k===255)return;for(var v=0,A=b-1;(k!==0||v<y)&&A!==-1;A--,v++)k+=a*w[A]>>>0,w[A]=k%256>>>0,k=k/256>>>0;if(k!==0)throw new Error("Non-zero carry");y=v,d++}if(p[d]!==" "){for(var N=b-y;N!==b&&w[N]===0;)N++;for(var T=new Uint8Array(g+(b-N)),q=g;N!==b;)T[q++]=w[N++];return T}}}function f(p){var d=m(p);if(d)return d;throw new Error(`Non-${t} character`)}return{encode:u,decodeUnsafe:m,decode:f}}var Hl=Fl,Ml=Hl,Li=Ml;var Ns=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")}},Ts=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 _i(this,t)}},Ls=class{decoders;constructor(t){this.decoders=t}or(t){return _i(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 _i(r,t){return new Ls({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var _s=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 Ns(t,e,n),this.decoder=new Ts(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 _s(r,t,e,n)}function me({name:r,prefix:t,alphabet:e}){let{encode:n,decode:s}=Li(e,r);return Ze({prefix:t,name:r,encode:n,decode:o=>Zt(s(o))})}function $l(r,t,e,n){let s={};for(let h=0;h<t.length;++h)s[t[h]]=h;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 h=0;h<o;++h){let u=s[r[h]];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 Kl(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 Kl(s,n,e)},decode(s){return $l(s,n,e,r)}})}var ct=me({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ql=me({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Us={};ut(Us,{base10:()=>zl});var zl=me({prefix:"9",name:"base10",alphabet:"0123456789"});var Ps={};ut(Ps,{base16:()=>jl,base16upper:()=>Gl});var jl=tt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Gl=tt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Ds={};ut(Ds,{base2:()=>Wl});var Wl=tt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Os={};ut(Os,{base256emoji:()=>Ql});var Ci=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}"),Zl=Ci.reduce((r,t,e)=>(r[e]=t,r),[]),Yl=Ci.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function Jl(r){return r.reduce((t,e)=>(t+=Zl[e],t),"")}function Xl(r){let t=[];for(let e of r){let n=Yl[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var Ql=Ze({prefix:"\u{1F680}",name:"base256emoji",encode:Jl,decode:Xl});var Vs={};ut(Vs,{base32:()=>Yt,base32hex:()=>nu,base32hexpad:()=>ou,base32hexpadupper:()=>iu,base32hexupper:()=>su,base32pad:()=>eu,base32padupper:()=>ru,base32upper:()=>tu,base32z:()=>au});var Yt=tt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),tu=tt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),eu=tt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ru=tt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),nu=tt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),su=tt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ou=tt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),iu=tt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),au=tt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Fs={};ut(Fs,{base36:()=>cu,base36upper:()=>lu});var cu=me({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),lu=me({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ms={};ut(Ms,{base64:()=>Hs,base64pad:()=>uu,base64url:()=>fu,base64urlpad:()=>hu});var Hs=tt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),uu=tt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),fu=tt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),hu=tt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var $s={};ut($s,{base8:()=>du});var du=tt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ks={};ut(Ks,{identity:()=>pu});var pu=Ze({prefix:"\0",name:"identity",encode:r=>Ni(r),decode:r=>Ri(r)});var S0=new TextEncoder,k0=new TextDecoder;var zs={};ut(zs,{identity:()=>ye});var yu=Di,Ui=128,bu=127,wu=~bu,xu=Math.pow(2,31);function Di(r,t,e){t=t||[],e=e||0;for(var n=e;r>=xu;)t[e++]=r&255|Ui,r/=128;for(;r&wu;)t[e++]=r&255|Ui,r>>>=7;return t[e]=r|0,Di.bytes=e-n+1,t}var vu=qs,Eu=128,Pi=127;function qs(r,n){var e=0,n=n||0,s=0,o=n,i,a=r.length;do{if(o>=a)throw qs.bytes=0,new RangeError("Could not decode varint");i=r[o++],e+=s<28?(i&Pi)<<s:(i&Pi)*Math.pow(2,s),s+=7}while(i>=Eu);return qs.bytes=o-n,e}var Bu=Math.pow(2,7),Au=Math.pow(2,14),Iu=Math.pow(2,21),Su=Math.pow(2,28),ku=Math.pow(2,35),Ru=Math.pow(2,42),Nu=Math.pow(2,49),Tu=Math.pow(2,56),Lu=Math.pow(2,63),_u=function(r){return r<Bu?1:r<Au?2:r<Iu?3:r<Su?4:r<ku?5:r<Ru?6:r<Nu?7:r<Tu?8:r<Lu?9:10},Cu={encode:yu,decode:vu,encodingLength:_u},Uu=Cu,Rr=Uu;function Nr(r,t=0){return[Rr.decode(r,t),Rr.decode.bytes]}function Ye(r,t,e=0){return Rr.encode(r,t,e),t}function Je(r){return Rr.encodingLength(r)}function Kt(r,t){let e=t.byteLength,n=Je(r),s=n+Je(e),o=new Uint8Array(s+e);return Ye(r,o,0),Ye(e,o,n),o.set(t,s),new Xe(r,e,t,o)}function Oe(r){let t=Zt(r),[e,n]=Nr(t),[s,o]=Nr(t.subarray(n)),i=t.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new Xe(e,s,i,t)}function Oi(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&ki(r.bytes,e.bytes)}}var Xe=class{code;size;digest;bytes;constructor(t,e,n,s){this.code=t,this.size=e,this.digest=n,this.bytes=s}};var Vi=0,Pu="identity",Fi=Zt;function Du(r){return Kt(Vi,Fi(r))}var ye={code:Vi,name:Pu,encode:Fi,digest:Du};var Ws={};ut(Ws,{sha256:()=>pt,sha512:()=>Ou});function Gs({name:r,code:t,encode:e}){return new js(r,t,e)}var js=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?Kt(this.code,e):e.then(n=>Kt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Mi(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var pt=Gs({name:"sha2-256",code:18,encode:Mi("SHA-256")}),Ou=Gs({name:"sha2-512",code:19,encode:Mi("SHA-512")});function $i(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Fu(e,Zs(r),t??ct.encoder);default:return Hu(e,Zs(r),t??Yt.encoder)}}var Ki=new WeakMap;function Zs(r){let t=Ki.get(r);if(t==null){let e=new Map;return Ki.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!==Tr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Mu)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=Kt(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&&Oi(t.multihash,n.multihash)}toString(t){return $i(this,t)}toJSON(){return{"/":$i(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??qi(n,s,o.bytes))}else if(e[$u]===!0){let{version:n,multihash:s,code:o}=e,i=Oe(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!==Tr)throw new Error(`Version 0 CID must use dag-pb (code: ${Tr}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let s=qi(t,e,n.bytes);return new r(t,e,n,s)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Tr,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=Zt(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 Xe(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,m]=Nr(t.subarray(e));return e+=m,u},s=n(),o=Tr;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,h=l-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:h,size:l}}static parse(t,e){let[n,s]=Vu(t,e),o=r.decode(s);if(o.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Zs(o).set(n,t),o}};function Vu(r,t){switch(r[0]){case"Q":{let e=t??ct;return[ct.prefix,e.decode(`${ct.prefix}${r}`)]}case ct.prefix:{let e=t??ct;return[ct.prefix,e.decode(r)]}case Yt.prefix:{let e=t??Yt;return[Yt.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 Fu(r,t,e){let{prefix:n}=e;if(n!==ct.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 Hu(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 Tr=112,Mu=18;function qi(r,t,e){let n=Je(r),s=n+Je(t),o=new Uint8Array(s+e.byteLength);return Ye(r,o,0),Ye(t,o,n),o.set(e,s),o}var $u=Symbol.for("@ipld/js-cid/CID");var be={...Ks,...Ds,...$s,...Us,...Ps,...Vs,...Fs,...Cs,...Ms,...Os},W0={...Ws,...zs};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 Ku=Symbol.for("nodejs.util.inspect.custom"),zi=Object.values(be).map(r=>r.decoder).reduce((r,t)=>r.or(t),be.identity.decoder),ji=114,Ys=36,Js=37,Lr=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()})`}[Si]=!0;toString(){return this.string==null&&(this.string=ct.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return Ut.createV1(ji,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 qu(t).equals(this);if(t?.multihash?.bytes!=null)return bt(this.multihash.bytes,t.multihash.bytes);throw new Error("not valid Id")}[Ku](){return`PeerId(${this.toString()})`}},Qe=class extends Lr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},tr=class extends Lr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.multihash.digest}},er=class extends Lr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.multihash.digest}};function qu(r,t){if(t=t??zi,r.charAt(0)==="1"||r.charAt(0)==="Q"){let e=Oe(ct.decode(`z${r}`));return r.startsWith("12D")?new tr({multihash:e}):r.startsWith("16U")?new er({multihash:e}):new Qe({multihash:e})}return sn(zi.decode(r))}function sn(r){try{let t=Oe(r);if(t.code===ye.code){if(t.digest.length===Ys)return new tr({multihash:t});if(t.digest.length===Js)return new er({multihash:t})}if(t.code===pt.code)return new Qe({multihash:t})}catch{return zu(Ut.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function zu(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==ji)throw new Error("Supplied PeerID CID is invalid");let t=r.multihash;if(t.code===pt.code)return new Qe({multihash:r.multihash});if(t.code===ye.code){if(t.digest.length===Ys)return new tr({multihash:r.multihash});if(t.digest.length===Js)return new er({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function Gi(r,t){return r.length===Ys?new tr({multihash:Kt(ye.code,r),privateKey:t}):r.length===Js?new er({multihash:Kt(ye.code,r),privateKey:t}):new Qe({multihash:await pt.digest(r),publicKey:r,privateKey:t})}var No={};ut(No,{Ed25519PrivateKey:()=>qe,Ed25519PublicKey:()=>Or,generateKeyPair:()=>hh,generateKeyPairFromSeed:()=>Na,unmarshalEd25519PrivateKey:()=>uh,unmarshalEd25519PublicKey:()=>fh});function we(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function Jt(r=0){return globalThis.Buffer?.alloc!=null?we(globalThis.Buffer.alloc(r)):new Uint8Array(r)}function wt(r=0){return globalThis.Buffer?.allocUnsafe!=null?we(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function Bt(r,t){if(globalThis.Buffer!=null)return we(globalThis.Buffer.concat(r,t));t==null&&(t=r.reduce((s,o)=>s+o.length,0));let e=wt(t),n=0;for(let s of r)e.set(s,n),n+=s.length;return we(e)}function Zi(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Wi=Zi("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Xs=Zi("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}),ju={utf8:Wi,"utf-8":Wi,hex:be.base16,latin1:Xs,ascii:Xs,binary:Xs,...be},on=ju;function Y(r,t="utf8"){let e=on[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?we(globalThis.Buffer.from(r,"utf-8")):e.decoder.decode(`${e.prefix}${r}`)}function Lt(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function rr(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`Wrong positive integer: ${r}`)}function Gu(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Qs(r,...t){if(!Gu(r))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(r.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${r.length}`)}function an(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");rr(r.outputLen),rr(r.blockLen)}function nr(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 Yi(r,t){Qs(r);let e=t.outputLen;if(r.length<e)throw new Error(`digestInto() expects output buffer of length at least ${e}`)}var cn=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Ji(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var or=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Pt=(r,t)=>r<<32-t|r>>>t,Wu=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Wu)throw new Error("Non little-endian hardware is not supported");var Zu=async()=>{};async function Xi(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 Zu(),n+=o)}}function to(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function xe(r){if(typeof r=="string"&&(r=to(r)),!Ji(r))throw new Error(`expected Uint8Array, got ${typeof r}`);return r}function ln(...r){let t=0;for(let n=0;n<r.length;n++){let s=r[n];if(!Ji(s))throw new Error("Uint8Array expected");t+=s.length}let e=new Uint8Array(t);for(let n=0,s=0;n<r.length;n++){let o=r[n];e.set(o,s),s+=o.length}return e}var sr=class{clone(){return this._cloneInto()}},Yu={}.toString;function Qi(r,t){if(t!==void 0&&Yu.call(t)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(r,t)}function un(r){let t=n=>r().update(xe(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function ir(r=32){if(cn&&typeof cn.getRandomValues=="function")return cn.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function Ju(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 ar=class extends sr{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=or(this.buffer)}update(t){nr(this);let{view:e,buffer:n,blockLen:s}=this;t=xe(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=or(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){nr(this),Yi(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;Ju(n,s-8,BigInt(this.length*8),o),this.process(n,0);let a=or(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=c/4,h=this.get();if(l>h.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<l;u++)a.setUint32(4*u,h[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 fn=BigInt(4294967295),eo=BigInt(32);function ta(r,t=!1){return t?{h:Number(r&fn),l:Number(r>>eo&fn)}:{h:Number(r>>eo&fn)|0,l:Number(r&fn)|0}}function Xu(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}=ta(r[s],t);[e[s],n[s]]=[o,i]}return[e,n]}var Qu=(r,t)=>BigInt(r>>>0)<<eo|BigInt(t>>>0),tf=(r,t,e)=>r>>>e,ef=(r,t,e)=>r<<32-e|t>>>e,rf=(r,t,e)=>r>>>e|t<<32-e,nf=(r,t,e)=>r<<32-e|t>>>e,sf=(r,t,e)=>r<<64-e|t>>>e-32,of=(r,t,e)=>r>>>e-32|t<<64-e,af=(r,t)=>t,cf=(r,t)=>r,lf=(r,t,e)=>r<<e|t>>>32-e,uf=(r,t,e)=>t<<e|r>>>32-e,ff=(r,t,e)=>t<<e-32|r>>>64-e,hf=(r,t,e)=>r<<e-32|t>>>64-e;function df(r,t,e,n){let s=(t>>>0)+(n>>>0);return{h:r+e+(s/2**32|0)|0,l:s|0}}var pf=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),gf=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,mf=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),yf=(r,t,e,n,s)=>t+e+n+s+(r/2**32|0)|0,bf=(r,t,e,n,s)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(s>>>0),wf=(r,t,e,n,s,o)=>t+e+n+s+o+(r/2**32|0)|0;var xf={fromBig:ta,split:Xu,toBig:Qu,shrSH:tf,shrSL:ef,rotrSH:rf,rotrSL:nf,rotrBH:sf,rotrBL:of,rotr32H:af,rotr32L:cf,rotlSH:lf,rotlSL:uf,rotlBH:ff,rotlBL:hf,add:df,add3L:pf,add3H:gf,add4L:mf,add4H:yf,add5H:wf,add5L:bf},U=xf;var[vf,Ef]=U.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))),ve=new Uint32Array(80),Ee=new Uint32Array(80),ro=class extends ar{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:h,Fh:u,Fl:m,Gh:f,Gl:p,Hh:d,Hl:g}=this;return[t,e,n,s,o,i,a,c,l,h,u,m,f,p,d,g]}set(t,e,n,s,o,i,a,c,l,h,u,m,f,p,d,g){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=h|0,this.Fh=u|0,this.Fl=m|0,this.Gh=f|0,this.Gl=p|0,this.Hh=d|0,this.Hl=g|0}process(t,e){for(let w=0;w<16;w++,e+=4)ve[w]=t.getUint32(e),Ee[w]=t.getUint32(e+=4);for(let w=16;w<80;w++){let k=ve[w-15]|0,v=Ee[w-15]|0,A=U.rotrSH(k,v,1)^U.rotrSH(k,v,8)^U.shrSH(k,v,7),N=U.rotrSL(k,v,1)^U.rotrSL(k,v,8)^U.shrSL(k,v,7),T=ve[w-2]|0,q=Ee[w-2]|0,$=U.rotrSH(T,q,19)^U.rotrBH(T,q,61)^U.shrSH(T,q,6),D=U.rotrSL(T,q,19)^U.rotrBL(T,q,61)^U.shrSL(T,q,6),nt=U.add4L(N,D,Ee[w-7],Ee[w-16]),rt=U.add4H(nt,A,$,ve[w-7],ve[w-16]);ve[w]=rt|0,Ee[w]=nt|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:l,Dl:h,Eh:u,El:m,Fh:f,Fl:p,Gh:d,Gl:g,Hh:y,Hl:b}=this;for(let w=0;w<80;w++){let k=U.rotrSH(u,m,14)^U.rotrSH(u,m,18)^U.rotrBH(u,m,41),v=U.rotrSL(u,m,14)^U.rotrSL(u,m,18)^U.rotrBL(u,m,41),A=u&f^~u&d,N=m&p^~m&g,T=U.add5L(b,v,N,Ef[w],Ee[w]),q=U.add5H(T,y,k,A,vf[w],ve[w]),$=T|0,D=U.rotrSH(n,s,28)^U.rotrBH(n,s,34)^U.rotrBH(n,s,39),nt=U.rotrSL(n,s,28)^U.rotrBL(n,s,34)^U.rotrBL(n,s,39),rt=n&o^n&a^o&a,Tt=s&i^s&c^i&c;y=d|0,b=g|0,d=f|0,g=p|0,f=u|0,p=m|0,{h:u,l:m}=U.add(l|0,h|0,q|0,$|0),l=a|0,h=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let E=U.add3L($,nt,Tt);n=U.add3H(E,q,D,rt),s=E|0}({h:n,l:s}=U.add(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=U.add(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=U.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:h}=U.add(this.Dh|0,this.Dl|0,l|0,h|0),{h:u,l:m}=U.add(this.Eh|0,this.El|0,u|0,m|0),{h:f,l:p}=U.add(this.Fh|0,this.Fl|0,f|0,p|0),{h:d,l:g}=U.add(this.Gh|0,this.Gl|0,d|0,g|0),{h:y,l:b}=U.add(this.Hh|0,this.Hl|0,y|0,b|0),this.set(n,s,o,i,a,c,l,h,u,m,f,p,d,g,y,b)}roundClean(){ve.fill(0),Ee.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 cr=un(()=>new ro);var dn={};ut(dn,{bitGet:()=>Nf,bitLen:()=>Rf,bitMask:()=>_r,bitSet:()=>Tf,bytesToHex:()=>Qt,bytesToNumberBE:()=>te,bytesToNumberLE:()=>Be,concatBytes:()=>ee,createHmacDrbg:()=>oo,ensureBytes:()=>et,equalBytes:()=>Sf,hexToBytes:()=>Fe,hexToNumber:()=>so,isBytes:()=>Dt,numberToBytesBE:()=>Ae,numberToBytesLE:()=>He,numberToHexUnpadded:()=>sa,numberToVarBytesBE:()=>If,utf8ToBytes:()=>kf,validateObject:()=>qt});var na=BigInt(0),hn=BigInt(1),Bf=BigInt(2);function Dt(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var Af=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Qt(r){if(!Dt(r))throw new Error("Uint8Array expected");let t="";for(let e=0;e<r.length;e++)t+=Af[r[e]];return t}function sa(r){let t=r.toString(16);return t.length&1?`0${t}`:t}function so(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var Xt={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function ea(r){if(r>=Xt._0&&r<=Xt._9)return r-Xt._0;if(r>=Xt._A&&r<=Xt._F)return r-(Xt._A-10);if(r>=Xt._a&&r<=Xt._f)return r-(Xt._a-10)}function Fe(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=ea(r.charCodeAt(o)),a=ea(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 te(r){return so(Qt(r))}function Be(r){if(!Dt(r))throw new Error("Uint8Array expected");return so(Qt(Uint8Array.from(r).reverse()))}function Ae(r,t){return Fe(r.toString(16).padStart(t*2,"0"))}function He(r,t){return Ae(r,t).reverse()}function If(r){return Fe(sa(r))}function et(r,t,e){let n;if(typeof t=="string")try{n=Fe(t)}catch(o){throw new Error(`${r} must be valid hex string, got "${t}". Cause: ${o}`)}else if(Dt(t))n=Uint8Array.from(t);else throw new Error(`${r} must be hex string or Uint8Array`);let s=n.length;if(typeof e=="number"&&s!==e)throw new Error(`${r} expected ${e} bytes, got ${s}`);return n}function ee(...r){let t=0;for(let s=0;s<r.length;s++){let o=r[s];if(!Dt(o))throw new Error("Uint8Array expected");t+=o.length}let e=new Uint8Array(t),n=0;for(let s=0;s<r.length;s++){let o=r[s];e.set(o,n),n+=o.length}return e}function Sf(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 kf(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Rf(r){let t;for(t=0;r>na;r>>=hn,t+=1);return t}function Nf(r,t){return r>>BigInt(t)&hn}var Tf=(r,t,e)=>r|(e?hn:na)<<BigInt(t),_r=r=>(Bf<<BigInt(r-1))-hn,no=r=>new Uint8Array(r),ra=r=>Uint8Array.from(r);function oo(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=no(r),s=no(r),o=0,i=()=>{n.fill(1),s.fill(0),o=0},a=(...u)=>e(s,n,...u),c=(u=no())=>{s=a(ra([0]),u),n=a(),u.length!==0&&(s=a(ra([1]),u),n=a())},l=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let u=0,m=[];for(;u<t;){n=a();let f=n.slice();m.push(f),u+=n.length}return ee(...m)};return(u,m)=>{i(),c(u);let f;for(;!(f=m(l()));)c();return i(),f}}var Lf={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||Dt(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function qt(r,t,e={}){let n=(s,o,i)=>{let a=Lf[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 lt=BigInt(0),J=BigInt(1),Me=BigInt(2),_f=BigInt(3),io=BigInt(4),oa=BigInt(5),ia=BigInt(8),Cf=BigInt(9),Uf=BigInt(16);function Z(r,t){let e=r%t;return e>=lt?e:t+e}function Pf(r,t,e){if(e<=lt||t<lt)throw new Error("Expected power/modulo > 0");if(e===J)return lt;let n=J;for(;t>lt;)t&J&&(n=n*r%e),r=r*r%e,t>>=J;return n}function X(r,t,e){let n=r;for(;t-- >lt;)n*=n,n%=e;return n}function pn(r,t){if(r===lt||t<=lt)throw new Error(`invert: expected positive integers, got n=${r} mod=${t}`);let e=Z(r,t),n=t,s=lt,o=J,i=J,a=lt;for(;e!==lt;){let l=n/e,h=n%e,u=s-i*l,m=o-a*l;n=e,e=h,s=i,o=a,i=u,a=m}if(n!==J)throw new Error("invert: does not exist");return Z(s,t)}function Df(r){let t=(r-J)/Me,e,n,s;for(e=r-J,n=0;e%Me===lt;e/=Me,n++);for(s=Me;s<r&&Pf(s,t,r)!==r-J;s++);if(n===1){let i=(r+J)/io;return function(c,l){let h=c.pow(l,i);if(!c.eql(c.sqr(h),l))throw new Error("Cannot find square root");return h}}let o=(e+J)/Me;return function(a,c){if(a.pow(c,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let l=n,h=a.pow(a.mul(a.ONE,s),e),u=a.pow(c,o),m=a.pow(c,e);for(;!a.eql(m,a.ONE);){if(a.eql(m,a.ZERO))return a.ZERO;let f=1;for(let d=a.sqr(m);f<l&&!a.eql(d,a.ONE);f++)d=a.sqr(d);let p=a.pow(h,J<<BigInt(l-f-1));h=a.sqr(p),u=a.mul(u,p),m=a.mul(m,h),l=f}return u}}function Of(r){if(r%io===_f){let t=(r+J)/io;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%ia===oa){let t=(r-oa)/ia;return function(n,s){let o=n.mul(s,Me),i=n.pow(o,t),a=n.mul(s,i),c=n.mul(n.mul(a,Me),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%Uf,Df(r)}var aa=(r,t)=>(Z(r,t)&J)===J,Vf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ao(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=Vf.reduce((n,s)=>(n[s]="function",n),t);return qt(r,e)}function Ff(r,t,e){if(e<lt)throw new Error("Expected power > 0");if(e===lt)return r.ONE;if(e===J)return t;let n=r.ONE,s=t;for(;e>lt;)e&J&&(n=r.mul(n,s)),s=r.sqr(s),e>>=J;return n}function Hf(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 co(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function gn(r,t,e=!1,n={}){if(r<=lt)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:s,nByteLength:o}=co(r,t);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let i=Of(r),a=Object.freeze({ORDER:r,BITS:s,BYTES:o,MASK:_r(s),ZERO:lt,ONE:J,create:c=>Z(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return lt<=c&&c<r},is0:c=>c===lt,isOdd:c=>(c&J)===J,neg:c=>Z(-c,r),eql:(c,l)=>c===l,sqr:c=>Z(c*c,r),add:(c,l)=>Z(c+l,r),sub:(c,l)=>Z(c-l,r),mul:(c,l)=>Z(c*l,r),pow:(c,l)=>Ff(a,c,l),div:(c,l)=>Z(c*pn(l,r),r),sqrN:c=>c*c,addN:(c,l)=>c+l,subN:(c,l)=>c-l,mulN:(c,l)=>c*l,inv:c=>pn(c,r),sqrt:n.sqrt||(c=>i(a,c)),invertBatch:c=>Hf(a,c),cmov:(c,l,h)=>h?l:c,toBytes:c=>e?He(c,o):Ae(c,o),fromBytes:c=>{if(c.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);return e?Be(c):te(c)}});return Object.freeze(a)}function ca(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 la(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 lo(r){let t=la(r);return t+Math.ceil(t/2)}function ua(r,t,e=!1){let n=r.length,s=la(t),o=lo(t);if(n<16||n<o||n>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${n}`);let i=e?te(r):Be(r),a=Z(i,t-J)+J;return e?He(a,s):Ae(a,s)}var $f=BigInt(0),uo=BigInt(1);function mn(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>$f;)o&uo&&(i=i.add(a)),a=a.double(),o>>=uo;return i},precomputeWindow(s,o){let{windows:i,windowSize:a}=n(o),c=[],l=s,h=l;for(let u=0;u<i;u++){h=l,c.push(h);for(let m=1;m<a;m++)h=h.add(l),c.push(h);l=h.double()}return c},wNAF(s,o,i){let{windows:a,windowSize:c}=n(s),l=r.ZERO,h=r.BASE,u=BigInt(2**s-1),m=2**s,f=BigInt(s);for(let p=0;p<a;p++){let d=p*c,g=Number(i&u);i>>=f,g>c&&(g-=m,i+=uo);let y=d,b=d+Math.abs(g)-1,w=p%2!==0,k=g<0;g===0?h=h.add(e(w,o[y])):l=l.add(e(k,o[b]))}return{p:l,f:h}},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 Cr(r){return ao(r.Fp),qt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...co(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Ot=BigInt(0),Nt=BigInt(1),yn=BigInt(2),Kf=BigInt(8),qf={zip215:!0};function zf(r){let t=Cr(r);return qt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function bn(r){let t=zf(r),{Fp:e,n,prehash:s,hash:o,randomBytes:i,nByteLength:a,h:c}=t,l=yn<<BigInt(a*8)-Nt,h=e.create,u=t.uvRatio||((B,x)=>{try{return{isValid:!0,value:e.sqrt(B*e.inv(x))}}catch{return{isValid:!1,value:Ot}}}),m=t.adjustScalarBytes||(B=>B),f=t.domain||((B,x,S)=>{if(x.length||S)throw new Error("Contexts/pre-hash are not supported");return B}),p=B=>typeof B=="bigint"&&Ot<B,d=(B,x)=>p(B)&&p(x)&&B<x,g=B=>B===Ot||d(B,l);function y(B,x){if(d(B,x))return B;throw new Error(`Expected valid scalar < ${x}, got ${typeof B} ${B}`)}function b(B){return B===Ot?B:y(B,n)}let w=new Map;function k(B){if(!(B instanceof v))throw new Error("ExtendedPoint expected")}class v{constructor(x,S,L,_){if(this.ex=x,this.ey=S,this.ez=L,this.et=_,!g(x))throw new Error("x required");if(!g(S))throw new Error("y required");if(!g(L))throw new Error("z required");if(!g(_))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(x){if(x instanceof v)throw new Error("extended point not allowed");let{x:S,y:L}=x||{};if(!g(S)||!g(L))throw new Error("invalid affine point");return new v(S,L,Nt,h(S*L))}static normalizeZ(x){let S=e.invertBatch(x.map(L=>L.ez));return x.map((L,_)=>L.toAffine(S[_])).map(v.fromAffine)}_setWindowSize(x){this._WINDOW_SIZE=x,w.delete(this)}assertValidity(){let{a:x,d:S}=t;if(this.is0())throw new Error("bad point: ZERO");let{ex:L,ey:_,ez:V,et:F}=this,G=h(L*L),M=h(_*_),K=h(V*V),st=h(K*K),Q=h(G*x),ht=h(K*h(Q+M)),dt=h(st+h(S*h(G*M)));if(ht!==dt)throw new Error("bad point: equation left != right (1)");let at=h(L*_),yt=h(V*F);if(at!==yt)throw new Error("bad point: equation left != right (2)")}equals(x){k(x);let{ex:S,ey:L,ez:_}=this,{ex:V,ey:F,ez:G}=x,M=h(S*G),K=h(V*_),st=h(L*G),Q=h(F*_);return M===K&&st===Q}is0(){return this.equals(v.ZERO)}negate(){return new v(h(-this.ex),this.ey,this.ez,h(-this.et))}double(){let{a:x}=t,{ex:S,ey:L,ez:_}=this,V=h(S*S),F=h(L*L),G=h(yn*h(_*_)),M=h(x*V),K=S+L,st=h(h(K*K)-V-F),Q=M+F,ht=Q-G,dt=M-F,at=h(st*ht),yt=h(Q*dt),Wt=h(st*dt),De=h(ht*Q);return new v(at,yt,De,Wt)}add(x){k(x);let{a:S,d:L}=t,{ex:_,ey:V,ez:F,et:G}=this,{ex:M,ey:K,ez:st,et:Q}=x;if(S===BigInt(-1)){let bi=h((V-_)*(K+M)),wi=h((V+_)*(K-M)),Ss=h(wi-bi);if(Ss===Ot)return this.double();let xi=h(F*yn*Q),vi=h(G*yn*st),Ei=vi+xi,Bi=wi+bi,Ai=vi-xi,Nl=h(Ei*Ss),Tl=h(Bi*Ai),Ll=h(Ei*Ai),_l=h(Ss*Bi);return new v(Nl,Tl,_l,Ll)}let ht=h(_*M),dt=h(V*K),at=h(G*L*Q),yt=h(F*st),Wt=h((_+V)*(M+K)-ht-dt),De=yt-at,kr=yt+at,yi=h(dt-S*ht),Il=h(Wt*De),Sl=h(kr*yi),kl=h(Wt*yi),Rl=h(De*kr);return new v(Il,Sl,Rl,kl)}subtract(x){return this.add(x.negate())}wNAF(x){return T.wNAFCached(this,w,x,v.normalizeZ)}multiply(x){let{p:S,f:L}=this.wNAF(y(x,n));return v.normalizeZ([S,L])[0]}multiplyUnsafe(x){let S=b(x);return S===Ot?N:this.equals(N)||S===Nt?this:this.equals(A)?this.wNAF(S).p:T.unsafeLadder(this,S)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return T.unsafeLadder(this,n).is0()}toAffine(x){let{ex:S,ey:L,ez:_}=this,V=this.is0();x==null&&(x=V?Kf:e.inv(_));let F=h(S*x),G=h(L*x),M=h(_*x);if(V)return{x:Ot,y:Nt};if(M!==Nt)throw new Error("invZ was invalid");return{x:F,y:G}}clearCofactor(){let{h:x}=t;return x===Nt?this:this.multiplyUnsafe(x)}static fromHex(x,S=!1){let{d:L,a:_}=t,V=e.BYTES;x=et("pointHex",x,V);let F=x.slice(),G=x[V-1];F[V-1]=G&-129;let M=Be(F);M===Ot||(S?y(M,l):y(M,e.ORDER));let K=h(M*M),st=h(K-Nt),Q=h(L*K-_),{isValid:ht,value:dt}=u(st,Q);if(!ht)throw new Error("Point.fromHex: invalid y coordinate");let at=(dt&Nt)===Nt,yt=(G&128)!==0;if(!S&&dt===Ot&&yt)throw new Error("Point.fromHex: x=0 and x_0=1");return yt!==at&&(dt=h(-dt)),v.fromAffine({x:dt,y:M})}static fromPrivateKey(x){return D(x).point}toRawBytes(){let{x,y:S}=this.toAffine(),L=He(S,e.BYTES);return L[L.length-1]|=x&Nt?128:0,L}toHex(){return Qt(this.toRawBytes())}}v.BASE=new v(t.Gx,t.Gy,Nt,h(t.Gx*t.Gy)),v.ZERO=new v(Ot,Nt,Nt,Ot);let{BASE:A,ZERO:N}=v,T=mn(v,a*8);function q(B){return Z(B,n)}function $(B){return q(Be(B))}function D(B){let x=a;B=et("private key",B,x);let S=et("hashed private key",o(B),2*x),L=m(S.slice(0,x)),_=S.slice(x,2*x),V=$(L),F=A.multiply(V),G=F.toRawBytes();return{head:L,prefix:_,scalar:V,point:F,pointBytes:G}}function nt(B){return D(B).pointBytes}function rt(B=new Uint8Array,...x){let S=ee(...x);return $(o(f(S,et("context",B),!!s)))}function Tt(B,x,S={}){B=et("message",B),s&&(B=s(B));let{prefix:L,scalar:_,pointBytes:V}=D(x),F=rt(S.context,L,B),G=A.multiply(F).toRawBytes(),M=rt(S.context,G,V,B),K=q(F+M*_);b(K);let st=ee(G,He(K,e.BYTES));return et("result",st,a*2)}let E=qf;function R(B,x,S,L=E){let{context:_,zip215:V}=L,F=e.BYTES;B=et("signature",B,2*F),x=et("message",x),s&&(x=s(x));let G=Be(B.slice(F,2*F)),M,K,st;try{M=v.fromHex(S,V),K=v.fromHex(B.slice(0,F),V),st=A.multiplyUnsafe(G)}catch{return!1}if(!V&&M.isSmallOrder())return!1;let Q=rt(_,K.toRawBytes(),M.toRawBytes(),x);return K.add(M.multiplyUnsafe(Q)).subtract(st).clearCofactor().equals(v.ZERO)}return A._setWindowSize(8),{CURVE:t,getPublicKey:nt,sign:Tt,verify:R,ExtendedPoint:v,utils:{getExtendedPublicKey:D,randomPrivateKey:()=>i(e.BYTES),precompute(B=8,x=v.BASE){return x._setWindowSize(B),x.multiply(BigInt(3)),x}}}}var ho=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),fa=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),qp=BigInt(0),jf=BigInt(1),fo=BigInt(2),Gf=BigInt(5),ha=BigInt(10),Wf=BigInt(20),Zf=BigInt(40),da=BigInt(80);function Yf(r){let t=ho,n=r*r%t*r%t,s=X(n,fo,t)*n%t,o=X(s,jf,t)*r%t,i=X(o,Gf,t)*o%t,a=X(i,ha,t)*i%t,c=X(a,Wf,t)*a%t,l=X(c,Zf,t)*c%t,h=X(l,da,t)*l%t,u=X(h,da,t)*l%t,m=X(u,ha,t)*i%t;return{pow_p_5_8:X(m,fo,t)*r%t,b2:n}}function Jf(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Xf(r,t){let e=ho,n=Z(t*t*t,e),s=Z(n*n*t,e),o=Yf(r*s).pow_p_5_8,i=Z(r*n*o,e),a=Z(t*i*i,e),c=i,l=Z(i*fa,e),h=a===r,u=a===Z(-r,e),m=a===Z(-r*fa,e);return h&&(i=c),(u||m)&&(i=l),aa(i,e)&&(i=Z(-i,e)),{isValid:h||u,value:i}}var re=gn(ho,void 0,!0),po={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:re,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:cr,randomBytes:ir,adjustScalarBytes:Jf,uvRatio:Xf},lr=bn(po);function pa(r,t,e){if(t.length>255)throw new Error("Context is too big");return ln(to("SigEd25519 no Ed25519 collisions"),new Uint8Array([e?1:0,t.length]),t,r)}var zp=bn({...po,domain:pa}),jp=bn({...po,domain:pa,prehash:cr});var Qf=(re.ORDER+BigInt(3))/BigInt(8),Gp=re.pow(fo,Qf),Wp=re.sqrt(re.neg(re.ONE)),Zp=(re.ORDER-BigInt(5))/BigInt(8),Yp=BigInt(486662);var Jp=ca(re,re.neg(BigInt(486664)));var Xp=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Qp=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),tg=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),eg=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var rg=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var ur=32,ne=64,wn=32;function ga(){let r=lr.utils.randomPrivateKey(),t=lr.getPublicKey(r);return{privateKey:wa(r,t),publicKey:t}}function ma(r){if(r.length!==wn)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=lr.getPublicKey(t);return{privateKey:wa(t,e),publicKey:e}}function ya(r,t){let e=r.subarray(0,wn);return lr.sign(t instanceof Uint8Array?t:t.subarray(),e)}function ba(r,t,e){return lr.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}function wa(r,t){let e=new Uint8Array(ne);for(let n=0;n<wn;n++)e[n]=r[n],e[wn+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 go={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function xa(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,m){let f=a.getRandomValues(new Uint8Array(o)),p=a.getRandomValues(new Uint8Array(n)),d={name:t,iv:p};typeof m=="string"&&(m=Y(m));let g;if(m.length===0){g=await a.subtle.importKey("jwk",go,{name:"AES-GCM"},!0,["encrypt"]);try{let b={name:"PBKDF2",salt:f,iterations:i,hash:{name:s}},w=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);g=await a.subtle.deriveKey(b,w,{name:t,length:e},!0,["encrypt"])}catch{g=await a.subtle.importKey("jwk",go,{name:"AES-GCM"},!0,["encrypt"])}}else{let b={name:"PBKDF2",salt:f,iterations:i,hash:{name:s}},w=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);g=await a.subtle.deriveKey(b,w,{name:t,length:e},!0,["encrypt"])}let y=await a.subtle.encrypt(d,g,u);return Bt([f,d.iv,new Uint8Array(y)])}async function l(u,m){let f=u.subarray(0,o),p=u.subarray(o,o+n),d=u.subarray(o+n),g={name:t,iv:p};typeof m=="string"&&(m=Y(m));let y;if(m.length===0)try{let w={name:"PBKDF2",salt:f,iterations:i,hash:{name:s}},k=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(w,k,{name:t,length:e},!0,["decrypt"])}catch{y=await a.subtle.importKey("jwk",go,{name:"AES-GCM"},!0,["decrypt"])}else{let w={name:"PBKDF2",salt:f,iterations:i,hash:{name:s}},k=await a.subtle.importKey("raw",m,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(w,k,{name:t,length:e},!0,["decrypt"])}let b=await a.subtle.decrypt(g,y,d);return new Uint8Array(b)}return{encrypt:c,decrypt:l}}async function fr(r,t){let n=await xa().encrypt(r,t);return Hs.encode(n)}var mo=new Float32Array([-0]),Ie=new Uint8Array(mo.buffer);function va(r,t,e){mo[0]=r,t[e]=Ie[0],t[e+1]=Ie[1],t[e+2]=Ie[2],t[e+3]=Ie[3]}function Ea(r,t){return Ie[0]=r[t],Ie[1]=r[t+1],Ie[2]=r[t+2],Ie[3]=r[t+3],mo[0]}var yo=new Float64Array([-0]),xt=new Uint8Array(yo.buffer);function Ba(r,t,e){yo[0]=r,t[e]=xt[0],t[e+1]=xt[1],t[e+2]=xt[2],t[e+3]=xt[3],t[e+4]=xt[4],t[e+5]=xt[5],t[e+6]=xt[6],t[e+7]=xt[7]}function Aa(r,t){return xt[0]=r[t],xt[1]=r[t+1],xt[2]=r[t+2],xt[3]=r[t+3],xt[4]=r[t+4],xt[5]=r[t+5],xt[6]=r[t+6],xt[7]=r[t+7],yo[0]}var rh=BigInt(Number.MAX_SAFE_INTEGER),nh=BigInt(Number.MIN_SAFE_INTEGER),St=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 $e;if(t<rh&&t>nh)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>Ia&&(s=0n,++n>Ia&&(n=0n))),new r(Number(s),Number(n))}static fromNumber(t){if(t===0)return $e;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):$e}},$e=new St(0,0);$e.toBigInt=function(){return 0n};$e.zzEncode=$e.zzDecode=function(){return this};$e.length=function(){return 1};var Ia=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 bo(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 Vt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function xn(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var wo=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,Vt(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 Vt(this,4);return xn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Vt(this,4);return xn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Vt(this,4);let t=Ea(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Vt(this,4);let t=Aa(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 Vt(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 Vt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Vt(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 St(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 Vt(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 Vt(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 Vt(this,8);let t=xn(this.buf,this.pos+=4),e=xn(this.buf,this.pos+=4);return new St(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){return this.readLongVarint().toNumber(!0)}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 xo(r){return new wo(r instanceof Uint8Array?r:r.subarray())}function se(r,t){let e=xo(r);return t.decode(e)}function vo(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 Ke=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Eo(){}var Ao=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},sh=vo();function oh(r){return globalThis.Buffer!=null?wt(r):sh(r)}var Dr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ke(Eo,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Ke(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Io((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(Ur,10,St.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=St.fromBigInt(t);return this._push(Ur,e.length(),e)}uint64Number(t){let e=St.fromNumber(t);return this._push(Ur,e.length(),e)}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=St.fromBigInt(t).zzEncode();return this._push(Ur,e.length(),e)}sint64Number(t){let e=St.fromNumber(t).zzEncode();return this._push(Ur,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Bo,1,t?1:0)}fixed32(t){return this._push(Pr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=St.fromBigInt(t);return this._push(Pr,4,e.lo)._push(Pr,4,e.hi)}fixed64Number(t){let e=St.fromNumber(t);return this._push(Pr,4,e.lo)._push(Pr,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(va,4,t)}double(t){return this._push(Ba,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Bo,1,0):this.uint32(e)._push(ah,e,t)}string(t){let e=Sa(t);return e!==0?this.uint32(e)._push(bo,e,t):this._push(Bo,1,0)}fork(){return this.states=new Ao(this),this.head=this.tail=new Ke(Eo,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 Ke(Eo,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=oh(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Bo(r,t,e){t[e]=r&255}function ih(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Io=class extends Ke{next;constructor(t,e){super(ih,t,e),this.next=void 0}};function Ur(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 Pr(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 ah(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Dr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(ch,t,r),this},Dr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(lh,t,r),this});function ch(r,t,e){t.set(r,e)}function lh(r,t,e){r.length<40?bo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(Y(r),e)}function So(){return new Dr}function oe(r,t){let e=So();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var hr;(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"})(hr||(hr={}));function vn(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function dr(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 vn("enum",hr.VARINT,e,n)}function ie(r,t){return vn("message",hr.LENGTH_DELIMITED,r,t)}var gt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1"})(gt||(gt={}));var ko;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1"})(ko||(ko={}));(function(r){r.codec=()=>dr(ko)})(gt||(gt={}));var Se;(function(r){let t;r.codec=()=>(t==null&&(t=ie((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=>oe(e,r.codec()),r.decode=e=>se(e,r.codec())})(Se||(Se={}));var ke;(function(r){let t;r.codec=()=>(t==null&&(t=ie((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=>oe(e,r.codec()),r.decode=e=>se(e,r.codec())})(ke||(ke={}));var Or=class{_key;constructor(t){this._key=pr(t,ur)}verify(t,e){return ba(this._key,e,t)}marshal(){return this._key}get bytes(){return Se.encode({Type:gt.Ed25519,Data:this.marshal()}).subarray()}equals(t){return bt(this.bytes,t.bytes)}hash(){let t=pt.digest(this.bytes);return Lt(t)?t.then(({bytes:e})=>e):t.bytes}},qe=class{_key;_publicKey;constructor(t,e){this._key=pr(t,ne),this._publicKey=pr(e,ur)}sign(t){return ya(this._key,t)}get public(){return new Or(this._publicKey)}marshal(){return this._key}get bytes(){return ke.encode({Type:gt.Ed25519,Data:this.marshal()}).subarray()}equals(t){return bt(this.bytes,t.bytes)}async hash(){let t=pt.digest(this.bytes),e;return Lt(t)?{bytes:e}=await t:e=t.bytes,e}async id(){let t=ye.digest(this.public.bytes);return ct.encode(t.bytes).substring(1)}async export(t,e="libp2p-key"){if(e==="libp2p-key")return fr(this.bytes,t);throw new C(`export format '${e}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function uh(r){if(r.length>ne){r=pr(r,ne+ur);let n=r.subarray(0,ne),s=r.subarray(ne,r.length);return new qe(n,s)}r=pr(r,ne);let t=r.subarray(0,ne),e=r.subarray(ur);return new qe(t,e)}function fh(r){return r=pr(r,ur),new Or(r)}async function hh(){let{privateKey:r,publicKey:t}=ga();return new qe(r,t)}async function Na(r){let{privateKey:t,publicKey:e}=ma(r);return new qe(t,e)}function pr(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new C(`Key must be a Uint8Array of length ${t}, got ${r.length}`,"ERR_INVALID_KEY_TYPE");return r}function z(r,t="utf8"){let e=on[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):e.encoder.encode(r).substring(1)}var Fo={};ut(Fo,{MAX_RSA_KEY_SIZE:()=>Zr,RsaPrivateKey:()=>wr,RsaPublicKey:()=>Wr,fromJwk:()=>Fh,generateKeyPair:()=>Hh,unmarshalRsaPrivateKey:()=>Oo,unmarshalRsaPublicKey:()=>Vh});function ze(r){if(isNaN(r)||r<=0)throw new C("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return ir(r)}var Le={};ut(Le,{exportToPem:()=>Ch,importFromPem:()=>Uh,jwkToPkcs1:()=>Nh,jwkToPkix:()=>Lh,pkcs1ToJwk:()=>Rh,pkixToJwk:()=>Th});var En=class extends sr{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,an(t);let n=xe(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 nr(this),this.iHash.update(t),this}digestInto(t){nr(this),Qs(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()}},Vr=(r,t,e)=>new En(r,t).update(e).digest();Vr.create=(r,t)=>new En(r,t);function dh(r,t,e,n){an(r);let s=Qi({dkLen:32,asyncTick:10},n),{c:o,dkLen:i,asyncTick:a}=s;if(rr(o),rr(i),rr(a),o<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=xe(t),l=xe(e),h=new Uint8Array(i),u=Vr.create(r,c),m=u._cloneInto().update(l);return{c:o,dkLen:i,asyncTick:a,DK:h,PRF:u,PRFSalt:m}}function ph(r,t,e,n,s){return r.destroy(),t.destroy(),n&&n.destroy(),s.fill(0),e}async function To(r,t,e,n){let{c:s,dkLen:o,asyncTick:i,DK:a,PRF:c,PRFSalt:l}=dh(r,t,e,n),h,u=new Uint8Array(4),m=or(u),f=new Uint8Array(c.outputLen);for(let p=1,d=0;d<o;p++,d+=c.outputLen){let g=a.subarray(d,d+c.outputLen);m.setInt32(0,p,!1),(h=l._cloneInto(h)).update(u).digestInto(f),g.set(f.subarray(0,g.length)),await Xi(s-1,i,()=>{c._cloneInto(h).update(f).digestInto(f);for(let y=0;y<g.length;y++)g[y]^=f[y]})}return ph(c,l,a,h,f)}var H=rn(Ta());function je(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 Re(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 h=a-1;h>=0;h--){let u=Math.pow(2,h*t);l[o-h-1]=Math.floor(s/u),s-=l[o-h-1]*u}return c}i*=Math.pow(2,t)}return new ArrayBuffer(0)}function In(...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 _o(){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=je(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,je(o,8)-n}function La(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=Re(i,8,n),c=new Uint8Array(a);return c[0]|=128,a}let s=Re(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 _a(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 am=Math.log(2);function Sn(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Co(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 fe(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 Hr=class{constructor(){this.items=[]}write(t){this.items.push(t)}final(){return Co(this.items)}},Fr=[new Uint8Array([1])],Ca="0123456789";var yr="",Ht=new ArrayBuffer(0),Uo=new Uint8Array(0),Mr="EndOfContent",Pa="OCTET STRING",Da="BIT STRING";function he(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):Uo}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(!fe(this,i,s,o))return-1;let a=s+o;return this.valueHexView=i.subarray(s,a),this.valueHexView.length?(this.blockLength=o,a):(this.warnings.push("Zero buffer length"),s)}toBER(n=!1){return this.isHexOnly?n?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",Ht)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:H.Convert.ToHex(this.valueHexView)}}},t.NAME="hexBlock",t}var ce=class{constructor({blockLength:t=0,error:e=yr,warnings:n=[],valueBeforeDecode:s=Uo}={}){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)}}};ce.NAME="baseBlock";var vt=class extends ce{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'")}};vt.NAME="valueBlock";var kn=class extends he(ce){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):Uo,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",Ht}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=Re(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(!fe(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),h=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===h){h+=255;let m=new Uint8Array(h);for(let f=0;f<l.length;f++)m[f]=l[f];l=this.valueHexView=new Uint8Array(h)}}this.blockLength=c+1,l[c-1]=o[c]&127;let u=new Uint8Array(c);for(let m=0;m<c;m++)u[m]=l[m];l=this.valueHexView=new Uint8Array(c),l.set(u),this.blockLength<=9?this.tagNumber=je(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}}};kn.NAME="identificationBlock";var Rn=class extends ce{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(!fe(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=je(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=Re(this.length,8);if(s.byteLength>127)return this.error="Too big length",Ht;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}}};Rn.NAME="lengthBlock";var I={},mt=class extends ce{constructor({name:t=yr,optional:e=!1,primitiveSchema:n,...s}={},o){super(s),this.name=t,this.optional=e,n&&(this.primitiveSchema=n),this.idBlock=new kn(s),this.lenBlock=new Rn(s),this.valueBlock=o?new o(s):new vt(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 Hr;e||Oa(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?Ht: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 _a(e,n)}};mt.NAME="BaseBlock";function Oa(r){if(r instanceof I.Constructed)for(let t of r.valueBlock.value)Oa(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var Nn=class extends mt{constructor({value:t=yr,...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}'`}};Nn.NAME="BaseStringBlock";var Tn=class extends he(vt){constructor({isHexOnly:t=!0,...e}={}){super(e),this.isHexOnly=t}};Tn.NAME="PrimitiveValueBlock";var Va,Ln=class extends mt{constructor(t={}){super(t,Tn),this.idBlock.isConstructed=!1}};Va=Ln;I.Primitive=Va;Ln.NAME="PRIMITIVE";function Bh(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 us(r,t=0,e=r.length){let n=t,s=new mt({},vt),o=new ce;if(!fe(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=I.EndOfContent;break;case 1:c=I.Boolean;break;case 2:c=I.Integer;break;case 3:c=I.BitString;break;case 4:c=I.OctetString;break;case 5:c=I.Null;break;case 6:c=I.ObjectIdentifier;break;case 10:c=I.Enumerated;break;case 12:c=I.Utf8String;break;case 13:c=I.RelativeObjectIdentifier;break;case 14:c=I.TIME;break;case 15:return s.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:s};case 16:c=I.Sequence;break;case 17:c=I.Set;break;case 18:c=I.NumericString;break;case 19:c=I.PrintableString;break;case 20:c=I.TeletexString;break;case 21:c=I.VideotexString;break;case 22:c=I.IA5String;break;case 23:c=I.UTCTime;break;case 24:c=I.GeneralizedTime;break;case 25:c=I.GraphicString;break;case 26:c=I.VisibleString;break;case 27:c=I.GeneralString;break;case 28:c=I.UniversalString;break;case 29:c=I.CharacterString;break;case 30:c=I.BmpString;break;case 31:c=I.DATE;break;case 32:c=I.TimeOfDay;break;case 33:c=I.DateTime;break;case 34:c=I.Duration;break;default:{let l=s.idBlock.isConstructed?new I.Constructed:new I.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?I.Constructed:I.Primitive}return s=Bh(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 br(r){if(!r.byteLength){let t=new mt({},vt);return t.error="Input buffer has zero length",{offset:-1,result:t}}return us(H.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function Ah(r,t){return r?1:t}var zt=class extends vt{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(!fe(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(;Ah(this.isIndefiniteForm,n)>0;){let i=us(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===Mr)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===Mr?this.value.pop():this.warnings.push("No EndOfContent block encoded")),o}toBER(t,e){let n=e||new Hr;for(let s=0;s<this.value.length;s++)this.value[s].toBER(t,n);return e?Ht:n.final()}toJSON(){let t={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let e of this.value)t.value.push(e.toJSON());return t}};zt.NAME="ConstructedValueBlock";var Fa,Ne=class extends mt{constructor(t={}){super(t,zt),this.idBlock.isConstructed=!0}fromBER(t,e,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let s=this.valueBlock.fromBER(t,e,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),s)}onAsciiEncoding(){let t=[];for(let n of this.valueBlock.value)t.push(n.toString("ascii").split(`
3
3
  `).map(s=>` ${s}`).join(`
4
4
  `));let e=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return t.length?`${e} :
5
5
  ${t.join(`
6
- `)}`:`${e} :`}};qa=Te;I.Constructed=qa;Te.NAME="CONSTRUCTED";var Un=class extends At{fromBER(t,e,n){return e}toBER(t){return Kt}};Un.override="EndOfContentValueBlock";var za,Pn=class extends wt{constructor(t={}){super(t,Un),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};za=Pn;I.EndOfContent=za;Pn.NAME=zr;var ja,Le=class extends wt{constructor(t={}){super(t,At),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}`}};ja=Le;I.Null=ja;Le.NAME="NULL";var Dn=class extends pe(At){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 de(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,Uo.call(this),this.blockLength=n,e+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};Dn.NAME="BooleanValueBlock";var Ga,On=class extends wt{constructor(t={}){super(t,Dn),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}`}};Ga=On;I.Boolean=Ga;On.NAME="BOOLEAN";var Vn=class extends pe(Wt){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=Wt.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===zr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(i!==Ha)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?Wt.prototype.toBER.call(this,t,e):t?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};Vn.NAME="OctetStringValueBlock";var Wa,fe=class r extends wt{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},Vn),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=hs(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?Te.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)}};Wa=fe;I.OctetString=Wa;fe.NAME=Ha;var Fn=class extends pe(Wt){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=Wt.prototype.fromBER.call(this,t,e,n),s===-1)return s;for(let a of this.value){let c=a.constructor.NAME;if(c===zr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==Ma)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(!de(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=hs(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 Wt.prototype.toBER.call(this,t,e);if(t)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return Kt;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}}};Fn.NAME="BitStringValueBlock";var Ya,br=class extends wt{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},Fn),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 Te.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)}`}}};Ya=br;I.BitString=Ya;br.NAME=Ma;var Za;function Ch(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,h=c<i?i:c,u=0;for(let m=h;m>=0;m--,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=kn(new Uint8Array([l%10]),o);break;default:o[i-u]=l%10}}return e[0]>0&&(o=kn(e,o)),o}function Fa(r){if(r>=Kr.length)for(let t=Kr.length;t<=r;t++){let e=new Uint8Array([0]),n=Kr[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=kn(e,n)),Kr.push(n)}return Kr[r]}function Uh(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,h=0;for(let u=c;u>=0;u--,h++)switch(l=o[i-h]-a[c-h]-e,!0){case l<0:e=1,o[i-h]=l+10;break;default:e=0,o[i-h]=l}if(e>0)for(let u=i-c+1;u>=0;u--,h++)if(l=o[i-h]-e,l<0)e=1,o[i-h]=l+10;else{e=0,o[i-h]=l;break}return o.slice()}var jr=class extends pe(At){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=Uo.call(this)))}set valueDec(t){this._valueDec=t,this.isHexOnly=!1,this.valueHexView=new Uint8Array(Da(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=Uh(Fa(n),e),i="-";break;default:e=Ch(e,Fa(n))}n++,s>>=1}}for(let c=0;c<e.length;c++)e[c]&&(a=!0),a&&(i+=Va.charAt(e[c]));return a===!1&&(i+=Va.charAt(0)),i}};Za=jr;jr.NAME="IntegerValueBlock";Object.defineProperty(Za.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var Ja,ot=class r extends wt{constructor(t={}){super(t,jr),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Rn(),BigInt(this.valueBlock.toString())}static fromBigInt(t){Rn();let e=BigInt(t),n=new qr,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,h=H.BufferSourceConverter.toUint8Array(H.Convert.FromHex(l.toString(16)));h[0]|=128,n.write(h)}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()}`}};Ja=ot;I.Integer=Ja;ot.NAME="INTEGER";var Xa,Hn=class extends ot{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};Xa=Hn;I.Enumerated=Xa;Hn.NAME="ENUMERATED";var Gr=class extends pe(At){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(!de(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=je(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),e+this.blockLength)}set valueBigInt(t){Rn();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=Ne(this.valueDec,7);if(e.byteLength===0)return this.error="Error during encoding SID value",Kt;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}}};Gr.NAME="sidBlock";var Mn=class extends At{constructor({value:t=wr,...e}={}){super(e),this.value=[],t&&this.fromString(t)}fromBER(t,e,n){let s=e;for(;n>0;){let o=new Gr;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,Kt;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 Gr;if(s>Number.MAX_SAFE_INTEGER){Rn();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}};Mn.NAME="ObjectIdentifierValueBlock";var Qa,$t=class extends wt{constructor(t={}){super(t,Mn),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()}}};Qa=$t;I.ObjectIdentifier=Qa;$t.NAME="OBJECT IDENTIFIER";var Wr=class extends pe(ue){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(!de(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=je(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=Ne(this.valueDec,7);if(e.byteLength===0)return this.error="Error during encoding SID value",Kt;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}}};Wr.NAME="relativeSidBlock";var $n=class extends At{constructor({value:t=wr,...e}={}){super(e),this.value=[],t&&this.fromString(t)}fromBER(t,e,n){let s=e;for(;n>0;){let o=new Wr;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,Kt;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 Wr;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}};$n.NAME="RelativeObjectIdentifierValueBlock";var tc,Kn=class extends wt{constructor(t={}){super(t,$n),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()}}};tc=Kn;I.RelativeObjectIdentifier=tc;Kn.NAME="RelativeObjectIdentifier";var ec,ht=class extends Te{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};ec=ht;I.Sequence=ec;ht.NAME="SEQUENCE";var rc,qn=class extends Te{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};rc=qn;I.Set=rc;qn.NAME="SET";var zn=class extends pe(At){constructor({...t}={}){super(t),this.isHexOnly=!0,this.value=wr}toJSON(){return{...super.toJSON(),value:this.value}}};zn.NAME="StringValueBlock";var jn=class extends zn{};jn.NAME="SimpleStringValueBlock";var It=class extends Ln{constructor({...t}={}){super(t,jn)}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}};It.NAME="SIMPLE STRING";var Gn=class extends It{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}};Gn.NAME="Utf8StringValueBlock";var nc,he=class extends Gn{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};nc=he;I.Utf8String=nc;he.NAME="UTF8String";var Wn=class extends It{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))}};Wn.NAME="BmpStringValueBlock";var sc,Yn=class extends Wn{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};sc=Yn;I.BmpString=sc;Yn.NAME="BMPString";var Zn=class extends It{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=Ne(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 oc,Jn=class extends Zn{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};oc=Jn;I.UniversalString=oc;Jn.NAME="UniversalString";var ic,Xn=class extends It{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};ic=Xn;I.NumericString=ic;Xn.NAME="NumericString";var ac,Qn=class extends It{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};ac=Qn;I.PrintableString=ac;Qn.NAME="PrintableString";var cc,ts=class extends It{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};cc=ts;I.TeletexString=cc;ts.NAME="TeletexString";var lc,es=class extends It{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};lc=es;I.VideotexString=lc;es.NAME="VideotexString";var uc,rs=class extends It{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};uc=rs;I.IA5String=uc;rs.NAME="IA5String";var fc,ns=class extends It{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};fc=ns;I.GraphicString=fc;ns.NAME="GraphicString";var hc,Yr=class extends It{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};hc=Yr;I.VisibleString=hc;Yr.NAME="VisibleString";var dc,ss=class extends It{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};dc=ss;I.GeneralString=dc;ss.NAME="GeneralString";var pc,os=class extends It{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};pc=os;I.CharacterString=pc;os.NAME="CharacterString";var gc,Zr=class extends Yr{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}}};gc=Zr;I.UTCTime=gc;Zr.NAME="UTCTime";var mc,is=class extends Zr{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,m=n.indexOf("+"),f="";if(m===-1&&(m=n.indexOf("-"),u=-1),m!==-1){if(f=n.substring(m+1),n=n.substring(0,m),f.length!==2&&f.length!==4)throw new Error("Wrong input string for conversion");let p=parseInt(f.substring(0,2),10);if(isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");if(a=u*p,f.length===4){if(p=parseInt(f.substring(2,4),10),isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");c=u*p}}}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 h=i.exec(s);if(h===null)throw new Error("Wrong input string for conversion");for(let u=1;u<h.length;u++)switch(u){case 1:this.year=parseInt(h[u],10);break;case 2:this.month=parseInt(h[u],10);break;case 3:this.day=parseInt(h[u],10);break;case 4:this.hour=parseInt(h[u],10)+a;break;case 5:this.minute=parseInt(h[u],10)+c;break;case 6:this.second=parseInt(h[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}}};mc=is;I.GeneralizedTime=mc;is.NAME="GeneralizedTime";var yc,as=class extends he{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};yc=as;I.DATE=yc;as.NAME="DATE";var bc,cs=class extends he{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};bc=cs;I.TimeOfDay=bc;cs.NAME="TimeOfDay";var wc,ls=class extends he{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};wc=ls;I.DateTime=wc;ls.NAME="DateTime";var xc,us=class extends he{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};xc=us;I.Duration=xc;us.NAME="Duration";var vc,fs=class extends he{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};vc=fs;I.TIME=vc;fs.NAME="TIME";function Dh(r){let{result:t}=xr(r),e=t.valueBlock.value;return{n:q(Yt(e[1].toBigInt()),"base64url"),e:q(Yt(e[2].toBigInt()),"base64url"),d:q(Yt(e[3].toBigInt()),"base64url"),p:q(Yt(e[4].toBigInt()),"base64url"),q:q(Yt(e[5].toBigInt()),"base64url"),dp:q(Yt(e[6].toBigInt()),"base64url"),dq:q(Yt(e[7].toBigInt()),"base64url"),qi:q(Yt(e[8].toBigInt()),"base64url"),kty:"RSA",alg:"RS256"}}function Oh(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 _("JWK was missing components","ERR_INVALID_PARAMETERS");let e=new ht({value:[new ot({value:0}),ot.fromBigInt(Zt(Z(r.n,"base64url"))),ot.fromBigInt(Zt(Z(r.e,"base64url"))),ot.fromBigInt(Zt(Z(r.d,"base64url"))),ot.fromBigInt(Zt(Z(r.p,"base64url"))),ot.fromBigInt(Zt(Z(r.q,"base64url"))),ot.fromBigInt(Zt(Z(r.dp,"base64url"))),ot.fromBigInt(Zt(Z(r.dq,"base64url"))),ot.fromBigInt(Zt(Z(r.qi,"base64url")))]}).toBER();return new Uint8Array(e,0,e.byteLength)}function Vh(r){let{result:t}=xr(r),e=t.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:q(Yt(e[0].toBigInt()),"base64url"),e:q(Yt(e[1].toBigInt()),"base64url")}}function Fh(r){if(r.n==null||r.e==null)throw new _("JWK was missing components","ERR_INVALID_PARAMETERS");let e=new ht({value:[new ht({value:[new $t({value:"1.2.840.113549.1.1.1"}),new Le]}),new br({valueHex:new ht({value:[ot.fromBigInt(Zt(Z(r.n,"base64url"))),ot.fromBigInt(Zt(Z(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(e,0,e.byteLength)}function Yt(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 Zt(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 Hh=16,Oo=32,Vo=1e4;async function Mh(r,t){let e=bt.get(),s=new ht({value:[new ot({value:0}),new ht({value:[new $t({value:"1.2.840.113549.1.1.1"}),new Le]}),new fe({valueHex:r.marshal()})]}).toBER(),o=new Uint8Array(s,0,s.byteLength),i=ze(Hh),a=await _o(lr,t,i,{c:Vo,dkLen:Oo}),c=ze(16),l=await e.subtle.importKey("raw",a,"AES-CBC",!1,["encrypt"]),h=await e.subtle.encrypt({name:"AES-CBC",iv:c},l,o),u=new ht({value:[new fe({valueHex:i}),new ot({value:Vo}),new ot({value:Oo}),new ht({value:[new $t({value:"1.2.840.113549.2.11"}),new Le]})]}),m=new ht({value:[new $t({value:"1.2.840.113549.1.5.13"}),new ht({value:[new ht({value:[new $t({value:"1.2.840.113549.1.5.12"}),u]}),new ht({value:[new $t({value:"2.16.840.1.101.3.4.1.42"}),new fe({valueHex:c})]})]})]}),p=new ht({value:[m,new fe({valueHex:h})]}).toBER(),d=new Uint8Array(p,0,p.byteLength);return["-----BEGIN ENCRYPTED PRIVATE KEY-----",...q(d,"base64pad").split(/(.{64})/).filter(Boolean),"-----END ENCRYPTED PRIVATE KEY-----"].join(`
7
- `)}async function Ac(r,t){let e=bt.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}=xr(s),{iv:i,salt:a,iterations:c,keySize:l,cipherText:h}=$h(o),u=await _o(lr,t,a,{c,dkLen:l}),m=await e.subtle.importKey("raw",u,"AES-CBC",!1,["decrypt"]),f=Jr(await e.subtle.decrypt({name:"AES-CBC",iv:i},m,h)),{result:p}=xr(f);n=Ec(p)}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}=xr(s);n=Ec(o)}else throw new _("Could not parse private key from PEM data","ERR_INVALID_PARAMETERS");return Fo(n)}function $h(r){let t=r.valueBlock.value[0];if(t.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.13")throw new _("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 _("Only pkcs5PBKDF2 key derivation functions are supported","ERR_INVALID_PARAMS");let o=n.valueBlock.value[1],i=Jr(o.valueBlock.value[0].getValue()),a=Vo,c=Oo;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 _("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],h=l.valueBlock.value[0].toString();if(h!=="OBJECT IDENTIFIER : 1.2.840.113549.3.7"){if(h!=="OBJECT IDENTIFIER : 1.3.14.3.2.7"){if(h!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.2"){if(h!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.22"){if(h!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.42")throw new _("Only AES-CBC encryption schemes are supported","ERR_INVALID_PARAMS")}}}}let u=Jr(l.valueBlock.value[1].getValue());return{cipherText:Jr(r.valueBlock.value[1].getValue()),salt:i,iterations:a,keySize:c,iv:u}}function Ec(r){return Jr(r.valueBlock.value[2].getValue())}function Jr(r){return new Uint8Array(r,0,r.byteLength)}async function Bc(r){let t=await bt.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 kc(t);return{privateKey:e[0],publicKey:e[1]}}async function Ho(r){let e=[await bt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),await Kh(r)],n=await kc({privateKey:e[0],publicKey:e[1]});return{privateKey:n[0],publicKey:n[1]}}async function Ic(r,t){let e=await bt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await bt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function Sc(r,t,e){let n=await bt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return bt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function kc(r){if(r.privateKey==null||r.publicKey==null)throw new _("Private and public key are required","ERR_INVALID_PARAMETERS");return Promise.all([bt.get().subtle.exportKey("jwk",r.privateKey),bt.get().subtle.exportKey("jwk",r.publicKey)])}async function Kh(r){return bt.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 ds(r){if(r.kty!=="RSA")throw new _("invalid key type","ERR_INVALID_KEY_TYPE");if(r.n==null)throw new _("invalid key modulus","ERR_INVALID_KEY_MODULUS");return Z(r.n,"base64url").length*8}var Er=8192,vr=class{_key;constructor(t){this._key=t}verify(t,e){return Sc(this._key,e,t)}marshal(){return _e.jwkToPkix(this._key)}get bytes(){return ae.encode({Type:ft.RSA,Data:this.marshal()}).subarray()}equals(t){return mt(this.bytes,t.bytes)}hash(){let t=gt.digest(this.bytes);return Lt(t)?t.then(({bytes:e})=>e):t.bytes}},Ge=class{_key;_publicKey;constructor(t,e){this._key=t,this._publicKey=e}genSecret(){return ze(16)}sign(t){return Ic(this._key,t)}get public(){if(this._publicKey==null)throw new _("public key not provided","ERR_PUBKEY_NOT_PROVIDED");return new vr(this._publicKey)}marshal(){return _e.jwkToPkcs1(this._key)}get bytes(){return ce.encode({Type:ft.RSA,Data:this.marshal()}).subarray()}equals(t){return mt(this.bytes,t.bytes)}hash(){let t=gt.digest(this.bytes);return Lt(t)?t.then(({bytes:e})=>e):t.bytes}async id(){let t=await this.public.hash();return q(t,"base58btc")}async export(t,e="pkcs-8"){if(e==="pkcs-8")return _e.exportToPem(this,t);if(e==="libp2p-key")return hr(this.bytes,t);throw new _(`export format '${e}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};async function Fo(r){let t=_e.pkcs1ToJwk(r);if(ds(t)>Er)throw new _("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await Ho(t);return new Ge(e.privateKey,e.publicKey)}function zh(r){let t=_e.pkixToJwk(r);if(ds(t)>Er)throw new _("key size is too large","ERR_KEY_SIZE_TOO_LARGE");return new vr(t)}async function jh(r){if(ds(r)>Er)throw new _("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await Ho(r);return new Ge(t.privateKey,t.publicKey)}async function Gh(r){if(r>Er)throw new _("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await Bc(r);return new Ge(t.privateKey,t.publicKey)}var jo={};ut(jo,{Secp256k1PrivateKey:()=>Br,Secp256k1PublicKey:()=>Ar,generateKeyPair:()=>cd,unmarshalSecp256k1PrivateKey:()=>id,unmarshalSecp256k1PublicKey:()=>ad});var Wh=(r,t,e)=>r&t^~r&e,Yh=(r,t,e)=>r&t^r&e^t&e,Zh=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]),Ce=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Ue=new Uint32Array(64),$o=class extends cr{constructor(){super(64,32,8,!1),this.A=Ce[0]|0,this.B=Ce[1]|0,this.C=Ce[2]|0,this.D=Ce[3]|0,this.E=Ce[4]|0,this.F=Ce[5]|0,this.G=Ce[6]|0,this.H=Ce[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)Ue[u]=t.getUint32(e,!1);for(let u=16;u<64;u++){let m=Ue[u-15],f=Ue[u-2],p=Pt(m,7)^Pt(m,18)^m>>>3,d=Pt(f,17)^Pt(f,19)^f>>>10;Ue[u]=d+Ue[u-7]+p+Ue[u-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:l,H:h}=this;for(let u=0;u<64;u++){let m=Pt(a,6)^Pt(a,11)^Pt(a,25),f=h+m+Wh(a,c,l)+Zh[u]+Ue[u]|0,d=(Pt(n,2)^Pt(n,13)^Pt(n,22))+Yh(n,s,o)|0;h=l,l=c,c=a,a=i+f|0,i=o,o=s,s=n,n=f+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,h=h+this.H|0,this.set(n,s,o,i,a,c,l,h)}roundClean(){Ue.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Rc=fn(()=>new $o);function Jh(r){let t=Vr(r);Gt(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:Xh,hexToBytes:Qh}=pn,We={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(r){let{Err:t}=We;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:Xh(n),l:r.subarray(e+2)}},toSig(r){let{Err:t}=We,e=typeof r=="string"?Qh(r):r;if(!Dt(e))throw new Error("ui8a expected");let n=e.length;if(n<2||e[0]!=48)throw new t("Invalid signature tag");if(e[1]!==n-2)throw new t("Invalid signature: incorrect length");let{d:s,l:o}=We._parseInt(e.subarray(2)),{d:i,l:a}=We._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 h=l.toString(16);return h.length&1?`0${h}`:h},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}`}},ge=BigInt(0),Ct=BigInt(1),Xy=BigInt(2),Nc=BigInt(3),Qy=BigInt(4);function td(r){let t=Jh(r),{Fp:e}=t,n=t.toBytes||((p,d,g)=>{let y=d.toAffine();return se(Uint8Array.from([4]),e.toBytes(y.x),e.toBytes(y.y))}),s=t.fromBytes||(p=>{let d=p.subarray(1),g=e.fromBytes(d.subarray(0,e.BYTES)),y=e.fromBytes(d.subarray(e.BYTES,2*e.BYTES));return{x:g,y}});function o(p){let{a:d,b:g}=t,y=e.sqr(p),b=e.mul(y,p);return e.add(e.add(b,e.mul(p,d)),g)}if(!e.eql(e.sqr(t.Gy),o(t.Gx)))throw new Error("bad generator point: equation left != right");function i(p){return typeof p=="bigint"&&ge<p&&p<t.n}function a(p){if(!i(p))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(p){let{allowedPrivateKeyLengths:d,nByteLength:g,wrapPrivateKey:y,n:b}=t;if(d&&typeof p!="bigint"){if(Dt(p)&&(p=re(p)),typeof p!="string"||!d.includes(p.length))throw new Error("Invalid key");p=p.padStart(g*2,"0")}let w;try{w=typeof p=="bigint"?p:ne(et("private key",p,g))}catch{throw new Error(`private key must be ${g} bytes, hex or bigint, not ${typeof p}`)}return y&&(w=Y(w,b)),a(w),w}let l=new Map;function h(p){if(!(p instanceof u))throw new Error("ProjectivePoint expected")}class u{constructor(d,g,y){if(this.px=d,this.py=g,this.pz=y,d==null||!e.isValid(d))throw new Error("x required");if(g==null||!e.isValid(g))throw new Error("y required");if(y==null||!e.isValid(y))throw new Error("z required")}static fromAffine(d){let{x:g,y}=d||{};if(!d||!e.isValid(g)||!e.isValid(y))throw new Error("invalid affine point");if(d instanceof u)throw new Error("projective point not allowed");let b=w=>e.eql(w,e.ZERO);return b(g)&&b(y)?u.ZERO:new u(g,y,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){let g=e.invertBatch(d.map(y=>y.pz));return d.map((y,b)=>y.toAffine(g[b])).map(u.fromAffine)}static fromHex(d){let g=u.fromAffine(s(et("pointHex",d)));return g.assertValidity(),g}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:g}=this.toAffine();if(!e.isValid(d)||!e.isValid(g))throw new Error("bad point: x or y not FE");let y=e.sqr(g),b=o(d);if(!e.eql(y,b))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){h(d);let{px:g,py:y,pz:b}=this,{px:w,py:k,pz:v}=d,B=e.eql(e.mul(g,v),e.mul(w,b)),N=e.eql(e.mul(y,v),e.mul(k,b));return B&&N}negate(){return new u(this.px,e.neg(this.py),this.pz)}double(){let{a:d,b:g}=t,y=e.mul(g,Nc),{px:b,py:w,pz:k}=this,v=e.ZERO,B=e.ZERO,N=e.ZERO,T=e.mul(b,b),z=e.mul(w,w),$=e.mul(k,k),D=e.mul(b,w);return D=e.add(D,D),N=e.mul(b,k),N=e.add(N,N),v=e.mul(d,N),B=e.mul(y,$),B=e.add(v,B),v=e.sub(z,B),B=e.add(z,B),B=e.mul(v,B),v=e.mul(D,v),N=e.mul(y,N),$=e.mul(d,$),D=e.sub(T,$),D=e.mul(d,D),D=e.add(D,N),N=e.add(T,T),T=e.add(N,T),T=e.add(T,$),T=e.mul(T,D),B=e.add(B,T),$=e.mul(w,k),$=e.add($,$),T=e.mul($,D),v=e.sub(v,T),N=e.mul($,z),N=e.add(N,N),N=e.add(N,N),new u(v,B,N)}add(d){h(d);let{px:g,py:y,pz:b}=this,{px:w,py:k,pz:v}=d,B=e.ZERO,N=e.ZERO,T=e.ZERO,z=t.a,$=e.mul(t.b,Nc),D=e.mul(g,w),nt=e.mul(y,k),rt=e.mul(b,v),Tt=e.add(g,y),E=e.add(w,k);Tt=e.mul(Tt,E),E=e.add(D,nt),Tt=e.sub(Tt,E),E=e.add(g,b);let R=e.add(w,v);return E=e.mul(E,R),R=e.add(D,rt),E=e.sub(E,R),R=e.add(y,b),B=e.add(k,v),R=e.mul(R,B),B=e.add(nt,rt),R=e.sub(R,B),T=e.mul(z,E),B=e.mul($,rt),T=e.add(B,T),B=e.sub(nt,T),T=e.add(nt,T),N=e.mul(B,T),nt=e.add(D,D),nt=e.add(nt,D),rt=e.mul(z,rt),E=e.mul($,E),nt=e.add(nt,rt),rt=e.sub(D,rt),rt=e.mul(z,rt),E=e.add(E,rt),D=e.mul(nt,E),N=e.add(N,D),D=e.mul(R,E),B=e.mul(Tt,B),B=e.sub(B,D),D=e.mul(Tt,nt),T=e.mul(R,T),T=e.add(T,D),new u(B,N,T)}subtract(d){return this.add(d.negate())}is0(){return this.equals(u.ZERO)}wNAF(d){return f.wNAFCached(this,l,d,g=>{let y=e.invertBatch(g.map(b=>b.pz));return g.map((b,w)=>b.toAffine(y[w])).map(u.fromAffine)})}multiplyUnsafe(d){let g=u.ZERO;if(d===ge)return g;if(a(d),d===Ct)return this;let{endo:y}=t;if(!y)return f.unsafeLadder(this,d);let{k1neg:b,k1:w,k2neg:k,k2:v}=y.splitScalar(d),B=g,N=g,T=this;for(;w>ge||v>ge;)w&Ct&&(B=B.add(T)),v&Ct&&(N=N.add(T)),T=T.double(),w>>=Ct,v>>=Ct;return b&&(B=B.negate()),k&&(N=N.negate()),N=new u(e.mul(N.px,y.beta),N.py,N.pz),B.add(N)}multiply(d){a(d);let g=d,y,b,{endo:w}=t;if(w){let{k1neg:k,k1:v,k2neg:B,k2:N}=w.splitScalar(g),{p:T,f:z}=this.wNAF(v),{p:$,f:D}=this.wNAF(N);T=f.constTimeNegate(k,T),$=f.constTimeNegate(B,$),$=new u(e.mul($.px,w.beta),$.py,$.pz),y=T.add($),b=z.add(D)}else{let{p:k,f:v}=this.wNAF(g);y=k,b=v}return u.normalizeZ([y,b])[0]}multiplyAndAddUnsafe(d,g,y){let b=u.BASE,w=(v,B)=>B===ge||B===Ct||!v.equals(b)?v.multiplyUnsafe(B):v.multiply(B),k=w(this,g).add(w(d,y));return k.is0()?void 0:k}toAffine(d){let{px:g,py:y,pz:b}=this,w=this.is0();d==null&&(d=w?e.ONE:e.inv(b));let k=e.mul(g,d),v=e.mul(y,d),B=e.mul(b,d);if(w)return{x:e.ZERO,y:e.ZERO};if(!e.eql(B,e.ONE))throw new Error("invZ was invalid");return{x:k,y:v}}isTorsionFree(){let{h:d,isTorsionFree:g}=t;if(d===Ct)return!0;if(g)return g(u,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:d,clearCofactor:g}=t;return d===Ct?this:g?g(u,this):this.multiplyUnsafe(t.h)}toRawBytes(d=!0){return this.assertValidity(),n(u,this,d)}toHex(d=!0){return re(this.toRawBytes(d))}}u.BASE=new u(t.Gx,t.Gy,e.ONE),u.ZERO=new u(e.ZERO,e.ONE,e.ZERO);let m=t.nBitLength,f=yn(u,t.endo?Math.ceil(m/2):m);return{CURVE:t,ProjectivePoint:u,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:i}}function ed(r){let t=Vr(r);return Gt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Tc(r){let t=ed(r),{Fp:e,n}=t,s=e.BYTES+1,o=2*e.BYTES+1;function i(E){return ge<E&&E<e.ORDER}function a(E){return Y(E,n)}function c(E){return gn(E,n)}let{ProjectivePoint:l,normPrivateKeyToScalar:h,weierstrassEquation:u,isWithinCurveOrder:m}=td({...t,toBytes(E,R,O){let A=R.toAffine(),x=e.toBytes(A.x),S=se;return O?S(Uint8Array.from([R.hasEvenY()?2:3]),x):S(Uint8Array.from([4]),x,e.toBytes(A.y))},fromBytes(E){let R=E.length,O=E[0],A=E.subarray(1);if(R===s&&(O===2||O===3)){let x=ne(A);if(!i(x))throw new Error("Point is not on curve");let S=u(x),L=e.sqrt(S),C=(L&Ct)===Ct;return(O&1)===1!==C&&(L=e.neg(L)),{x,y:L}}else if(R===o&&O===4){let x=e.fromBytes(A.subarray(0,e.BYTES)),S=e.fromBytes(A.subarray(e.BYTES,2*e.BYTES));return{x,y:S}}else throw new Error(`Point of length ${R} was invalid. Expected ${s} compressed bytes or ${o} uncompressed bytes`)}}),f=E=>re(Se(E,t.nByteLength));function p(E){let R=n>>Ct;return E>R}function d(E){return p(E)?a(-E):E}let g=(E,R,O)=>ne(E.slice(R,O));class y{constructor(R,O,A){this.r=R,this.s=O,this.recovery=A,this.assertValidity()}static fromCompact(R){let O=t.nByteLength;return R=et("compactSignature",R,O*2),new y(g(R,0,O),g(R,O,2*O))}static fromDER(R){let{r:O,s:A}=We.toSig(et("DER",R));return new y(O,A)}assertValidity(){if(!m(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!m(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(R){return new y(this.r,this.s,R)}recoverPublicKey(R){let{r:O,s:A,recovery:x}=this,S=N(et("msgHash",R));if(x==null||![0,1,2,3].includes(x))throw new Error("recovery id invalid");let L=x===2||x===3?O+t.n:O;if(L>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let C=x&1?"03":"02",V=l.fromHex(C+f(L)),F=c(L),G=a(-S*F),M=a(A*F),K=l.BASE.multiplyAndAddUnsafe(V,G,M);if(!K)throw new Error("point at infinify");return K.assertValidity(),K}hasHighS(){return p(this.s)}normalizeS(){return this.hasHighS()?new y(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return He(this.toDERHex())}toDERHex(){return We.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return He(this.toCompactHex())}toCompactHex(){return f(this.r)+f(this.s)}}let b={isValidPrivateKey(E){try{return h(E),!0}catch{return!1}},normPrivateKeyToScalar:h,randomPrivateKey:()=>{let E=fo(t.n);return ga(t.randomBytes(E),t.n)},precompute(E=8,R=l.BASE){return R._setWindowSize(E),R.multiply(BigInt(3)),R}};function w(E,R=!0){return l.fromPrivateKey(E).toRawBytes(R)}function k(E){let R=Dt(E),O=typeof E=="string",A=(R||O)&&E.length;return R?A===s||A===o:O?A===2*s||A===2*o:E instanceof l}function v(E,R,O=!0){if(k(E))throw new Error("first arg must be private key");if(!k(R))throw new Error("second arg must be public key");return l.fromHex(R).multiply(h(E)).toRawBytes(O)}let B=t.bits2int||function(E){let R=ne(E),O=E.length*8-t.nBitLength;return O>0?R>>BigInt(O):R},N=t.bits2int_modN||function(E){return a(B(E))},T=Or(t.nBitLength);function z(E){if(typeof E!="bigint")throw new Error("bigint expected");if(!(ge<=E&&E<T))throw new Error(`bigint expected < 2^${t.nBitLength}`);return Se(E,t.nByteLength)}function $(E,R,O=D){if(["recovered","canonical"].some(Q=>Q in O))throw new Error("sign() legacy options not supported");let{hash:A,randomBytes:x}=t,{lowS:S,prehash:L,extraEntropy:C}=O;S==null&&(S=!0),E=et("msgHash",E),L&&(E=et("prehashed msgHash",A(E)));let V=N(E),F=h(R),G=[z(F),z(V)];if(C!=null){let Q=C===!0?x(e.BYTES):C;G.push(et("extraEntropy",Q))}let M=se(...G),K=V;function st(Q){let dt=B(Q);if(!m(dt))return;let pt=c(dt),at=l.BASE.multiply(dt).toAffine(),xt=a(at.x);if(xt===ge)return;let Jt=a(pt*a(K+xt*F));if(Jt===ge)return;let Oe=(at.x===xt?0:2)|Number(at.y&Ct),_r=Jt;return S&&p(Jt)&&(_r=d(Jt),Oe^=1),new y(xt,_r,Oe)}return{seed:M,k2sig:st}}let D={lowS:t.lowS,prehash:!1},nt={lowS:t.lowS,prehash:!1};function rt(E,R,O=D){let{seed:A,k2sig:x}=$(E,R,O),S=t;return ao(S.hash.outputLen,S.nByteLength,S.hmac)(A,x)}l.BASE._setWindowSize(8);function Tt(E,R,O,A=nt){let x=E;if(R=et("msgHash",R),O=et("publicKey",O),"strict"in A)throw new Error("options.strict was renamed to lowS");let{lowS:S,prehash:L}=A,C,V;try{if(typeof x=="string"||Dt(x))try{C=y.fromDER(x)}catch(at){if(!(at instanceof We.Err))throw at;C=y.fromCompact(x)}else if(typeof x=="object"&&typeof x.r=="bigint"&&typeof x.s=="bigint"){let{r:at,s:xt}=x;C=new y(at,xt)}else throw new Error("PARSE");V=l.fromHex(O)}catch(at){if(at.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(S&&C.hasHighS())return!1;L&&(R=t.hash(R));let{r:F,s:G}=C,M=N(R),K=c(G),st=a(M*K),Q=a(F*K),dt=l.BASE.multiplyAndAddUnsafe(V,st,Q)?.toAffine();return dt?a(dt.x)===F:!1}return{CURVE:t,getPublicKey:w,getSharedSecret:v,sign:rt,verify:Tt,ProjectivePoint:l,Signature:y,utils:b}}function rd(r){return{hash:r,hmac:(t,...e)=>$r(r,t,un(...e)),randomBytes:ar}}function Lc(r,t){let e=n=>Tc({...r,...rd(n)});return Object.freeze({...e(t),create:e})}var Uc=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),_c=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),nd=BigInt(1),Ko=BigInt(2),Cc=(r,t)=>(r+t/Ko)/t;function sd(r){let t=Uc,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,h=l*l*r%t,u=X(h,e,t)*h%t,m=X(u,e,t)*h%t,f=X(m,Ko,t)*l%t,p=X(f,s,t)*f%t,d=X(p,o,t)*p%t,g=X(d,a,t)*d%t,y=X(g,c,t)*g%t,b=X(y,a,t)*d%t,w=X(b,e,t)*h%t,k=X(w,i,t)*p%t,v=X(k,n,t)*l%t,B=X(v,Ko,t);if(!qo.eql(qo.sqr(B),r))throw new Error("Cannot find square root");return B}var qo=mn(Uc,void 0,void 0,{sqrt:sd}),qt=Lc({a:BigInt(0),b:BigInt(7),Fp:qo,n:_c,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=_c,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-nd*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=e,i=BigInt("0x100000000000000000000000000000000"),a=Cc(o*r,t),c=Cc(-n*r,t),l=Y(r-a*e-c*s,t),h=Y(-a*n-c*o,t),u=l>i,m=h>i;if(u&&(l=t-l),m&&(h=t-h),l>i||h>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:u,k1:l,k2neg:m,k2:h}}}},Rc),cb=BigInt(0);var lb=qt.ProjectivePoint;function Pc(){return qt.utils.randomPrivateKey()}function Dc(r,t){let e=gt.digest(t instanceof Uint8Array?t:t.subarray());if(Lt(e))return e.then(({digest:n})=>qt.sign(n,r).toDERRawBytes()).catch(n=>{throw new _(String(n),"ERR_INVALID_INPUT")});try{return qt.sign(e.digest,r).toDERRawBytes()}catch(n){throw new _(String(n),"ERR_INVALID_INPUT")}}function Oc(r,t,e){let n=gt.digest(e instanceof Uint8Array?e:e.subarray());if(Lt(n))return n.then(({digest:s})=>qt.verify(t,s,r)).catch(s=>{throw new _(String(s),"ERR_INVALID_INPUT")});try{return qt.verify(t,n.digest,r)}catch(s){throw new _(String(s),"ERR_INVALID_INPUT")}}function Vc(r){return qt.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Fc(r){try{qt.getPublicKey(r,!0)}catch(t){throw new _(String(t),"ERR_INVALID_PRIVATE_KEY")}}function zo(r){try{qt.ProjectivePoint.fromHex(r)}catch(t){throw new _(String(t),"ERR_INVALID_PUBLIC_KEY")}}function Hc(r){try{return qt.getPublicKey(r,!0)}catch(t){throw new _(String(t),"ERR_INVALID_PRIVATE_KEY")}}var Ar=class{_key;constructor(t){zo(t),this._key=t}verify(t,e){return Oc(this._key,e,t)}marshal(){return Vc(this._key)}get bytes(){return ae.encode({Type:ft.Secp256k1,Data:this.marshal()}).subarray()}equals(t){return mt(this.bytes,t.bytes)}async hash(){let t=gt.digest(this.bytes),e;return Lt(t)?{bytes:e}=await t:e=t.bytes,e}},Br=class{_key;_publicKey;constructor(t,e){this._key=t,this._publicKey=e??Hc(t),Fc(this._key),zo(this._publicKey)}sign(t){return Dc(this._key,t)}get public(){return new Ar(this._publicKey)}marshal(){return this._key}get bytes(){return ce.encode({Type:ft.Secp256k1,Data:this.marshal()}).subarray()}equals(t){return mt(this.bytes,t.bytes)}hash(){let t=gt.digest(this.bytes);return Lt(t)?t.then(({bytes:e})=>e):t.bytes}async id(){let t=await this.public.hash();return q(t,"base58btc")}async export(t,e="libp2p-key"){if(e==="libp2p-key")return hr(this.bytes,t);throw new _(`export format '${e}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function id(r){return new Br(r)}function ad(r){return new Ar(r)}async function cd(){let r=Pc();return new Br(r)}var Mc={rsa:Mo,ed25519:Lo,secp256k1:jo};function ld(r){let t=Object.keys(Mc).join(" / ");return new _(`invalid or unsupported key type ${r}. Must be ${t}`,"ERR_UNSUPPORTED_KEY_TYPE")}function Go(r){if(r=r.toLowerCase(),r==="rsa"||r==="ed25519"||r==="secp256k1")return Mc[r];throw ld(r)}async function $c(r,t){return Go(r).generateKeyPair(t??2048)}function Kc(r,t){return t=(t??"rsa").toLowerCase(),Go(t),r.bytes}function qc(r,t){return t=(t??"rsa").toLowerCase(),Go(t),r.bytes}var Wo;(function(r){let t;r.codec=()=>(t==null&&(t=Mt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.id!=null&&(n.uint32(10),n.bytes(e.id)),e.pubKey!=null&&(n.uint32(18),n.bytes(e.pubKey)),e.privKey!=null&&(n.uint32(26),n.bytes(e.privKey)),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.id=e.bytes();break;case 2:s.pubKey=e.bytes();break;case 3:s.privKey=e.bytes();break;default:e.skipType(i&7);break}}return s})),t),r.encode=e=>Ht(e,r.codec()),r.decode=e=>Ft(e,r.codec())})(Wo||(Wo={}));var zc=async()=>{let r=await $c("Ed25519"),t=await ud(r);if(t.type==="Ed25519")return t;throw new Error(`Generated unexpected PeerId type "${t.type}"`)};async function ud(r){return Xi(Kc(r.public),qc(r))}var fd=Math.pow(2,7),hd=Math.pow(2,14),dd=Math.pow(2,21),Yo=Math.pow(2,28),Zo=Math.pow(2,35),Jo=Math.pow(2,42),Xo=Math.pow(2,49),j=128,Bt=127;function Rt(r){if(r<fd)return 1;if(r<hd)return 2;if(r<dd)return 3;if(r<Yo)return 4;if(r<Zo)return 5;if(r<Jo)return 6;if(r<Xo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function pd(r,t,e=0){switch(Rt(r)){case 8:t[e++]=r&255|j,r/=128;case 7:t[e++]=r&255|j,r/=128;case 6:t[e++]=r&255|j,r/=128;case 5:t[e++]=r&255|j,r/=128;case 4:t[e++]=r&255|j,r>>>=7;case 3:t[e++]=r&255|j,r>>>=7;case 2:t[e++]=r&255|j,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function gd(r,t,e=0){switch(Rt(r)){case 8:t.set(e++,r&255|j),r/=128;case 7:t.set(e++,r&255|j),r/=128;case 6:t.set(e++,r&255|j),r/=128;case 5:t.set(e++,r&255|j),r/=128;case 4:t.set(e++,r&255|j),r>>>=7;case 3:t.set(e++,r&255|j),r>>>=7;case 2:t.set(e++,r&255|j),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function md(r,t){let e=r[t],n=0;if(n+=e&Bt,e<j||(e=r[t+1],n+=(e&Bt)<<7,e<j)||(e=r[t+2],n+=(e&Bt)<<14,e<j)||(e=r[t+3],n+=(e&Bt)<<21,e<j)||(e=r[t+4],n+=(e&Bt)*Yo,e<j)||(e=r[t+5],n+=(e&Bt)*Zo,e<j)||(e=r[t+6],n+=(e&Bt)*Jo,e<j)||(e=r[t+7],n+=(e&Bt)*Xo,e<j))return n;throw new RangeError("Could not decode varint")}function yd(r,t){let e=r.get(t),n=0;if(n+=e&Bt,e<j||(e=r.get(t+1),n+=(e&Bt)<<7,e<j)||(e=r.get(t+2),n+=(e&Bt)<<14,e<j)||(e=r.get(t+3),n+=(e&Bt)<<21,e<j)||(e=r.get(t+4),n+=(e&Bt)*Yo,e<j)||(e=r.get(t+5),n+=(e&Bt)*Zo,e<j)||(e=r.get(t+6),n+=(e&Bt)*Jo,e<j)||(e=r.get(t+7),n+=(e&Bt)*Xo,e<j))return n;throw new RangeError("Could not decode varint")}function Pe(r,t,e=0){return t==null&&(t=vt(Rt(r))),t instanceof Uint8Array?pd(r,t,e):gd(r,t,e)}function me(r,t=0){return r instanceof Uint8Array?md(r,t):yd(r,t)}var gs=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 h=this.readAtomically(()=>{let u=this.readChar();if(u===void 0)return;let m=Number.parseInt(u,t);if(!Number.isNaN(m))return m});if(h===void 0)break;if(o*=t,o+=h,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 jc=45,bd=15,Ir=new gs;function Qo(r){if(!(r.length>bd))return Ir.new(r).parseWith(()=>Ir.readIPv4Addr())}function ti(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>jc))return Ir.new(r).parseWith(()=>Ir.readIPv6Addr())}function ms(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>jc))return Ir.new(r).parseWith(()=>Ir.readIPAddr())}var Xb=parseInt("0xFFFF",16),Qb=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Yc(r){return!!Qo(r)}function Zc(r){return!!ti(r)}function Sr(r){return!!ms(r)}var Jc=Yc,Ad=Zc,ei=function(r){let t=0;if(r=r.toString().trim(),Jc(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(Ad(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let o=Jc(e[n]),i;o&&(i=ei(e[n]),e[n]=q(i.slice(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,q(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")},Xc=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 kr={},ri={},Id=[[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"]];Id.forEach(r=>{let t=Sd(...r);ri[t.code]=t,kr[t.name]=t});function Sd(r,t,e,n,s){return{code:r,size:t,name:e,resolvable:!!n,path:!!s}}function W(r){if(typeof r=="number"){if(ri[r]!=null)return ri[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(kr[r]!=null)return kr[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Dw=W("ip4"),Ow=W("ip6"),Vw=W("ipcidr");function si(r,t){switch(W(r).code){case 4:case 41:return Rd(t);case 42:return el(t);case 6:case 273:case 33:case 132:return nl(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return el(t);case 421:return _d(t);case 444:return rl(t);case 445:return rl(t);case 466:return Ld(t);default:return q(t,"base16")}}function oi(r,t){switch(W(r).code){case 4:return Qc(t);case 41:return Qc(t);case 42:return tl(t);case 6:case 273:case 33:case 132:return ii(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return tl(t);case 421:return Nd(t);case 444:return Cd(t);case 445:return Ud(t);case 466:return Td(t);default:return Z(t,"base16")}}var ni=Object.values(xe).map(r=>r.decoder),kd=function(){let r=ni[0].or(ni[1]);return ni.slice(2).forEach(t=>r=r.or(t)),r}();function Qc(r){if(!Sr(r))throw new Error("invalid ip address");return ei(r)}function Rd(r){let t=Xc(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!Sr(t))throw new Error("invalid ip address");return t}function ii(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function nl(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function tl(r){let t=Z(r),e=Uint8Array.from(Pe(t.length));return yt([e,t],e.length+t.length)}function el(r){let t=me(r);if(r=r.slice(Rt(t)),r.length!==t)throw new Error("inconsistent lengths");return q(r)}function Nd(r){let t;r[0]==="Q"||r[0]==="1"?t=Ve(ct.decode(`z${r}`)).bytes:t=Ut.parse(r).multihash.bytes;let e=Uint8Array.from(Pe(t.length));return yt([e,t],e.length+t.length)}function Td(r){let t=kd.decode(r),e=Uint8Array.from(Pe(t.length));return yt([e,t],e.length+t.length)}function Ld(r){let t=me(r),e=r.slice(Rt(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+q(e,"base64url")}function _d(r){let t=me(r),e=r.slice(Rt(t));if(e.length!==t)throw new Error("inconsistent lengths");return q(e,"base58btc")}function Cd(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=Qt.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=ii(n);return yt([e,s],e.length+s.length)}function Ud(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=Qt.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=ii(n);return yt([e,s],e.length+s.length)}function rl(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=q(t,"base32"),s=nl(e);return`${n}:${s}`}function sl(r){r=ai(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 il("invalid address: "+r);if(a.path===!0){n=ai(s.slice(o).join("/")),t.push([a.code,oi(a.code,n)]),e.push([a.code,n]);break}let c=oi(a.code,s[o]);t.push([a.code,c]),e.push([a.code,si(a.code,c)])}return{string:ol(e),bytes:li(t),tuples:t,stringTuples:e,path:n}}function ci(r){let t=[],e=[],n=null,s=0;for(;s<r.length;){let o=me(r,s),i=Rt(o),a=W(o),c=Pd(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 il("Invalid address Uint8Array: "+q(r,"base16"));t.push([o,l]);let h=si(o,l);if(e.push([o,h]),a.path===!0){n=h;break}}return{bytes:Uint8Array.from(r),string:ol(e),tuples:t,stringTuples:e,path:n}}function ol(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}),ai(t.join("/"))}function li(r){return yt(r.map(t=>{let e=W(t[0]),n=Uint8Array.from(Pe(e.code));return t.length>1&&t[1]!=null&&(n=yt([n,t[1]])),n}))}function Pd(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=me(t instanceof Uint8Array?t:Uint8Array.from(t));return e+Rt(e)}}function ai(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}function il(r){return new Error("Error parsing address: "+r)}var Dd=Symbol.for("nodejs.util.inspect.custom"),ui=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Od=[W("dns").code,W("dns4").code,W("dns6").code,W("dnsaddr").code],ys=class r{bytes;#e;#t;#r;#n;[ui]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=ci(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=sl(t)}else if(cl(t))e=ci(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"),h=W("dns6"),u=W("ip6zone");for(let[f,p]of this.stringTuples())f===u.code&&(o=`%${p??""}`),Od.includes(f)&&(e=i.name,s=443,n=`${p??""}${o}`,t=f===h.code?6:4),(f===i.code||f===a.code)&&(e=W(f).name,s=parseInt(p??"")),(f===c.code||f===l.code)&&(e=W(f).name,n=`${p??""}${o}`,t=f===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(li(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,s])=>{n===kr.p2p.code&&t.push([n,s]),n===kr["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?q(ct.decode(`z${n}`),"base58btc"):q(Ut.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return mt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(o=>o.resolvable);if(e==null)return[this];let n=al.get(e.name);if(n==null)throw new _(`no available resolver for ${e.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,t)).map(o=>new r(o))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[Dd](){return`Multiaddr(${this.#e})`}};var al=new Map;function cl(r){return!!r?.[ui]}function bs(r){return new ys(r)}function Vd(r){return r[Symbol.asyncIterator]!=null}function Fd(r){if(Vd(r))return(async()=>{for await(let t of r)return t})();for(let t of r)return t}var fi=Fd;var ul=Symbol.for("@achingbrain/uint8arraylist");function ll(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 ws(r){return!!r?.[ul]}var Rr=class r{bufs;length;[ul]=!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(ws(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(ws(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=ll(this.bufs,t);return e.buf[e.index]}set(t,e){let n=ll(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(ws(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 yt(n,s)}subarray(t,e){let{bufs:n,length:s}=this._subList(t,e);return n.length===1?n[0]:yt(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,h=e>a&&e<=c;if(l&&h){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(h){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(!ws(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,h;for(let u=e;u<=c;u+=h){h=0;for(let m=l;m>=0;m--){let f=this.get(u+m);if(n[m]!==f){h=Math.max(1,m-a[f]);break}}if(h===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=vt(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=te(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=te(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=te(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=vt(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=te(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=te(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=te(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=te(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=te(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(!mt(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 xs(r){return r[Symbol.asyncIterator]!=null}var vs=r=>{let t=Rt(r),e=vt(t);return Pe(r,e),vs.bytes=t,e};vs.bytes=0;function Xr(r,t){t=t??{};let e=t.lengthEncoder??vs;function*n(s){let o=e(s.byteLength);o instanceof Uint8Array?yield o:yield*o,s instanceof Uint8Array?yield s:yield*s}return xs(r)?async function*(){for await(let s of r)yield*n(s)}():function*(){for(let s of r)yield*n(s)}()}Xr.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??vs;return new Rr(e(r.byteLength),r)};var Nr=rn(dl(),1);var Md=8,$d=1024*1024*4,Ye;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(Ye||(Ye={}));var hi=r=>{let t=me(r);return hi.bytes=Rt(t),t};hi.bytes=0;function Tr(r,t){let e=new Rr,n=Ye.LENGTH,s=-1,o=t?.lengthDecoder??hi,i=t?.maxLengthLength??Md,a=t?.maxDataLength??$d;function*c(){for(;e.byteLength>0;){if(n===Ye.LENGTH)try{if(s=o(e),s<0)throw(0,Nr.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(s>a)throw(0,Nr.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=Ye.DATA}catch(l){if(l instanceof RangeError){if(e.byteLength>i)throw(0,Nr.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw l}if(n===Ye.DATA){if(e.byteLength<s)break;let l=e.sublist(0,s);e.consume(s),t?.onData!=null&&t.onData(l),yield l,n=Ye.LENGTH}}}return xs(r)?async function*(){for await(let l of r)e.append(l),yield*c();if(e.byteLength>0)throw(0,Nr.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,Nr.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}Tr.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 Tr(n,{...t??{},onLength:o=>{e=o}})};function qd(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 pl=qd;function zd(r){return r[Symbol.asyncIterator]!=null}function jd(r,t){if(zd(r))return async function*(){for await(let a of r)yield t(a)}();let e=pl(r),{value:n,done:s}=e.next();if(s===!0)return function*(){}();let o=t(n);if(typeof o.then=="function")return async function*(){yield await o;for await(let a of e)yield t(a)}();let i=t;return function*(){yield o;for(let a of e)yield i(a)}()}var gl=jd;function ye(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Es=globalThis.CustomEvent??Event;async function*di(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=ye(),a=ye(),c=!1,l,h=!1;s.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let p of r){if(o.length===e&&(i=ye(),await i.promise),h)break;let d={done:!1};o.push(d),p().then(g=>{d.done=!0,d.ok=!0,d.value=g,s.dispatchEvent(new Es("task-complete"))},g=>{d.done=!0,d.err=g,s.dispatchEvent(new Es("task-complete"))})}c=!0,s.dispatchEvent(new Es("task-complete"))}catch(p){l=p,s.dispatchEvent(new Es("task-complete"))}});function u(){return n?o[0]?.done:!!o.find(p=>p.done)}function*m(){for(;o.length>0&&o[0].done;){let p=o[0];if(o.shift(),p.ok)yield p.value;else throw h=!0,i.resolve(),p.err;i.resolve()}}function*f(){for(;u();)for(let p=0;p<o.length;p++)if(o[p].done){let d=o[p];if(o.splice(p,1),p--,d.ok)yield d.value;else throw h=!0,i.resolve(),d.err;i.resolve()}}for(;;){if(u()||(a=ye(),await a.promise),l!=null)throw l;if(n?yield*m():yield*f(),c&&o.length===0)break}}var As=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}},Lr=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new As(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 As(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 pi=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function Bs(r={}){return Gd(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 Gd(r,t){t=t??{};let e=t.onEnd,n=new Lr,s,o,i,a=ye(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((g,y)=>{o=b=>{o=null,n.push(b);try{g(r(n))}catch(w){y(w)}return s}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=ye()})}},l=g=>o!=null?o(g):(n.push(g),s),h=g=>(n=new Lr,o!=null?o({error:g}):(n.push({error:g}),s)),u=g=>{if(i)return s;if(t?.objectMode!==!0&&g?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:g})},m=g=>i?s:(i=!0,g!=null?h(g):l({done:!0})),f=()=>(n=new Lr,m(),{done:!0}),p=g=>(m(g),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:f,throw:p,push:u,end:m,get readableLength(){return n.size},onEmpty:async g=>{let y=g?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let b,w;y!=null&&(b=new Promise((k,v)=>{w=()=>{v(new pi)},y.addEventListener("abort",w)}));try{await Promise.race([a.promise,b])}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(g){return d.throw(g),e!=null&&(e(g),e=void 0),{done:!0}},return(){return d.return(),e!=null&&(e(),e=void 0),{done:!0}},push:u,end(g){return d.end(g),e!=null&&(e(g),e=void 0),s},get readableLength(){return d.readableLength},onEmpty:g=>d.onEmpty(g)},s}function Wd(r){return r[Symbol.asyncIterator]!=null}function Yd(...r){let t=[];for(let e of r)Wd(e)||t.push(e);return t.length===r.length?function*(){for(let e of t)yield*e}():async function*(){let e=Bs({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 ml=Yd;function mi(r,...t){if(r==null)throw new Error("Empty pipeline");if(gi(r)){let n=r;r=()=>n.source}else if(bl(r)||yl(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&gi(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++)gi(e[n])&&(e[n]=Jd(e[n]));return Zd(...e)}var Zd=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},yl=r=>r?.[Symbol.asyncIterator]!=null,bl=r=>r?.[Symbol.iterator]!=null,gi=r=>r==null?!1:r.sink!=null&&r.source!=null,Jd=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=Bs({objectMode:!0});e.then(()=>{n.end()},i=>{n.end(i)});let s,o=r.source;if(yl(o))s=async function*(){yield*o,n.end()};else if(bl(o))s=function*(){yield*o,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return ml(n,s())}return r.source};var Il=rn(wl(),1);var xl="[a-fA-F\\d:]",De=r=>r&&r.includeBoundaries?`(?:(?<=\\s|^)(?=${xl})|(?<=${xl})(?=\\s|$))`:"",zt="(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}",it="[a-fA-F\\d]{1,4}",Is=`
6
+ `)}`:`${e} :`}};Fa=Ne;I.Constructed=Fa;Ne.NAME="CONSTRUCTED";var _n=class extends vt{fromBER(t,e,n){return e}toBER(t){return Ht}};_n.override="EndOfContentValueBlock";var Ha,Cn=class extends mt{constructor(t={}){super(t,_n),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};Ha=Cn;I.EndOfContent=Ha;Cn.NAME=Mr;var Ma,Te=class extends mt{constructor(t={}){super(t,vt),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}`}};Ma=Te;I.Null=Ma;Te.NAME="NULL";var Un=class extends he(vt){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 fe(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,_o.call(this),this.blockLength=n,e+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};Un.NAME="BooleanValueBlock";var $a,Pn=class extends mt{constructor(t={}){super(t,Un),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}`}};$a=Pn;I.Boolean=$a;Pn.NAME="BOOLEAN";var Dn=class extends he(zt){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=zt.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===Mr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(i!==Pa)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?zt.prototype.toBER.call(this,t,e):t?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};Dn.NAME="OctetStringValueBlock";var Ka,le=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},Dn),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=us(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?Ne.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=le;I.OctetString=Ka;le.NAME=Pa;var On=class extends he(zt){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=zt.prototype.fromBER.call(this,t,e,n),s===-1)return s;for(let a of this.value){let c=a.constructor.NAME;if(c===Mr){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(!fe(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=us(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 zt.prototype.toBER.call(this,t,e);if(t)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return Ht;let n=new Uint8Array(this.valueHexView.length+1);return n[0]=this.unusedBits,n.set(this.valueHexView,1),n.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}};On.NAME="BitStringValueBlock";var qa,mr=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},On),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 Ne.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)}`}}};qa=mr;I.BitString=qa;mr.NAME=Da;var za;function Ih(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,h=c<i?i:c,u=0;for(let m=h;m>=0;m--,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=In(new Uint8Array([l%10]),o);break;default:o[i-u]=l%10}}return e[0]>0&&(o=In(e,o)),o}function Ua(r){if(r>=Fr.length)for(let t=Fr.length;t<=r;t++){let e=new Uint8Array([0]),n=Fr[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=In(e,n)),Fr.push(n)}return Fr[r]}function Sh(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,h=0;for(let u=c;u>=0;u--,h++)switch(l=o[i-h]-a[c-h]-e,!0){case l<0:e=1,o[i-h]=l+10;break;default:e=0,o[i-h]=l}if(e>0)for(let u=i-c+1;u>=0;u--,h++)if(l=o[i-h]-e,l<0)e=1,o[i-h]=l+10;else{e=0,o[i-h]=l;break}return o.slice()}var $r=class extends he(vt){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=_o.call(this)))}set valueDec(t){this._valueDec=t,this.isHexOnly=!1,this.valueHexView=new Uint8Array(La(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=Sh(Ua(n),e),i="-";break;default:e=Ih(e,Ua(n))}n++,s>>=1}}for(let c=0;c<e.length;c++)e[c]&&(a=!0),a&&(i+=Ca.charAt(e[c]));return a===!1&&(i+=Ca.charAt(0)),i}};za=$r;$r.NAME="IntegerValueBlock";Object.defineProperty(za.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var ja,ot=class r extends mt{constructor(t={}){super(t,$r),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Sn(),BigInt(this.valueBlock.toString())}static fromBigInt(t){Sn();let e=BigInt(t),n=new Hr,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,h=H.BufferSourceConverter.toUint8Array(H.Convert.FromHex(l.toString(16)));h[0]|=128,n.write(h)}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()}`}};ja=ot;I.Integer=ja;ot.NAME="INTEGER";var Ga,Vn=class extends ot{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};Ga=Vn;I.Enumerated=Ga;Vn.NAME="ENUMERATED";var Kr=class extends he(vt){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(!fe(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=je(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),e+this.blockLength)}set valueBigInt(t){Sn();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=Re(this.valueDec,7);if(e.byteLength===0)return this.error="Error during encoding SID value",Ht;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}}};Kr.NAME="sidBlock";var Fn=class extends vt{constructor({value:t=yr,...e}={}){super(e),this.value=[],t&&this.fromString(t)}fromBER(t,e,n){let s=e;for(;n>0;){let o=new Kr;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,Ht;e.push(s)}return Co(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 Kr;if(s>Number.MAX_SAFE_INTEGER){Sn();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}};Fn.NAME="ObjectIdentifierValueBlock";var Wa,Ft=class extends mt{constructor(t={}){super(t,Fn),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()}}};Wa=Ft;I.ObjectIdentifier=Wa;Ft.NAME="OBJECT IDENTIFIER";var qr=class extends he(ce){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(!fe(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=je(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=Re(this.valueDec,7);if(e.byteLength===0)return this.error="Error during encoding SID value",Ht;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}}};qr.NAME="relativeSidBlock";var Hn=class extends vt{constructor({value:t=yr,...e}={}){super(e),this.value=[],t&&this.fromString(t)}fromBER(t,e,n){let s=e;for(;n>0;){let o=new qr;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,Ht;n.push(o)}return Co(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 qr;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}};Hn.NAME="RelativeObjectIdentifierValueBlock";var Za,Mn=class extends mt{constructor(t={}){super(t,Hn),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()}}};Za=Mn;I.RelativeObjectIdentifier=Za;Mn.NAME="RelativeObjectIdentifier";var Ya,ft=class extends Ne{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};Ya=ft;I.Sequence=Ya;ft.NAME="SEQUENCE";var Ja,$n=class extends Ne{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};Ja=$n;I.Set=Ja;$n.NAME="SET";var Kn=class extends he(vt){constructor({...t}={}){super(t),this.isHexOnly=!0,this.value=yr}toJSON(){return{...super.toJSON(),value:this.value}}};Kn.NAME="StringValueBlock";var qn=class extends Kn{};qn.NAME="SimpleStringValueBlock";var It=class extends Nn{constructor({...t}={}){super(t,qn)}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}};It.NAME="SIMPLE STRING";var zn=class extends It{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}};zn.NAME="Utf8StringValueBlock";var Xa,ue=class extends zn{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};Xa=ue;I.Utf8String=Xa;ue.NAME="UTF8String";var jn=class extends It{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))}};jn.NAME="BmpStringValueBlock";var Qa,Gn=class extends jn{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};Qa=Gn;I.BmpString=Qa;Gn.NAME="BMPString";var Wn=class extends It{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=Re(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}};Wn.NAME="UniversalStringValueBlock";var tc,Zn=class extends Wn{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};tc=Zn;I.UniversalString=tc;Zn.NAME="UniversalString";var ec,Yn=class extends It{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};ec=Yn;I.NumericString=ec;Yn.NAME="NumericString";var rc,Jn=class extends It{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};rc=Jn;I.PrintableString=rc;Jn.NAME="PrintableString";var nc,Xn=class extends It{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};nc=Xn;I.TeletexString=nc;Xn.NAME="TeletexString";var sc,Qn=class extends It{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};sc=Qn;I.VideotexString=sc;Qn.NAME="VideotexString";var oc,ts=class extends It{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};oc=ts;I.IA5String=oc;ts.NAME="IA5String";var ic,es=class extends It{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};ic=es;I.GraphicString=ic;es.NAME="GraphicString";var ac,zr=class extends It{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};ac=zr;I.VisibleString=ac;zr.NAME="VisibleString";var cc,rs=class extends It{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};cc=rs;I.GeneralString=cc;rs.NAME="GeneralString";var lc,ns=class extends It{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};lc=ns;I.CharacterString=lc;ns.NAME="CharacterString";var uc,jr=class extends zr{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}}};uc=jr;I.UTCTime=uc;jr.NAME="UTCTime";var fc,ss=class extends jr{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,m=n.indexOf("+"),f="";if(m===-1&&(m=n.indexOf("-"),u=-1),m!==-1){if(f=n.substring(m+1),n=n.substring(0,m),f.length!==2&&f.length!==4)throw new Error("Wrong input string for conversion");let p=parseInt(f.substring(0,2),10);if(isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");if(a=u*p,f.length===4){if(p=parseInt(f.substring(2,4),10),isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");c=u*p}}}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 h=i.exec(s);if(h===null)throw new Error("Wrong input string for conversion");for(let u=1;u<h.length;u++)switch(u){case 1:this.year=parseInt(h[u],10);break;case 2:this.month=parseInt(h[u],10);break;case 3:this.day=parseInt(h[u],10);break;case 4:this.hour=parseInt(h[u],10)+a;break;case 5:this.minute=parseInt(h[u],10)+c;break;case 6:this.second=parseInt(h[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}}};fc=ss;I.GeneralizedTime=fc;ss.NAME="GeneralizedTime";var hc,os=class extends ue{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};hc=os;I.DATE=hc;os.NAME="DATE";var dc,is=class extends ue{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};dc=is;I.TimeOfDay=dc;is.NAME="TimeOfDay";var pc,as=class extends ue{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};pc=as;I.DateTime=pc;as.NAME="DateTime";var gc,cs=class extends ue{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};gc=cs;I.Duration=gc;cs.NAME="Duration";var mc,ls=class extends ue{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};mc=ls;I.TIME=mc;ls.NAME="TIME";function Rh(r){let{result:t}=br(r),e=t.valueBlock.value;return{n:z(jt(e[1].toBigInt()),"base64url"),e:z(jt(e[2].toBigInt()),"base64url"),d:z(jt(e[3].toBigInt()),"base64url"),p:z(jt(e[4].toBigInt()),"base64url"),q:z(jt(e[5].toBigInt()),"base64url"),dp:z(jt(e[6].toBigInt()),"base64url"),dq:z(jt(e[7].toBigInt()),"base64url"),qi:z(jt(e[8].toBigInt()),"base64url"),kty:"RSA",alg:"RS256"}}function Nh(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 C("JWK was missing components","ERR_INVALID_PARAMETERS");let e=new ft({value:[new ot({value:0}),ot.fromBigInt(Gt(Y(r.n,"base64url"))),ot.fromBigInt(Gt(Y(r.e,"base64url"))),ot.fromBigInt(Gt(Y(r.d,"base64url"))),ot.fromBigInt(Gt(Y(r.p,"base64url"))),ot.fromBigInt(Gt(Y(r.q,"base64url"))),ot.fromBigInt(Gt(Y(r.dp,"base64url"))),ot.fromBigInt(Gt(Y(r.dq,"base64url"))),ot.fromBigInt(Gt(Y(r.qi,"base64url")))]}).toBER();return new Uint8Array(e,0,e.byteLength)}function Th(r){let{result:t}=br(r),e=t.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:z(jt(e[0].toBigInt()),"base64url"),e:z(jt(e[1].toBigInt()),"base64url")}}function Lh(r){if(r.n==null||r.e==null)throw new C("JWK was missing components","ERR_INVALID_PARAMETERS");let e=new ft({value:[new ft({value:[new Ft({value:"1.2.840.113549.1.1.1"}),new Te]}),new mr({valueHex:new ft({value:[ot.fromBigInt(Gt(Y(r.n,"base64url"))),ot.fromBigInt(Gt(Y(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(e,0,e.byteLength)}function jt(r){let t=r.toString(16);t.length%2>0&&(t=`0${t}`);let e=t.length/2,n=new Uint8Array(e),s=0,o=0;for(;s<e;)n[s]=parseInt(t.slice(o,o+2),16),s+=1,o+=2;return n}function Gt(r){let t=[];return r.forEach(function(e){let n=e.toString(16);n.length%2>0&&(n=`0${n}`),t.push(n)}),BigInt("0x"+t.join(""))}var _h=16,Po=32,Do=1e4;async function Ch(r,t){let e=At.get(),s=new ft({value:[new ot({value:0}),new ft({value:[new Ft({value:"1.2.840.113549.1.1.1"}),new Te]}),new le({valueHex:r.marshal()})]}).toBER(),o=new Uint8Array(s,0,s.byteLength),i=ze(_h),a=await To(cr,t,i,{c:Do,dkLen:Po}),c=ze(16),l=await e.subtle.importKey("raw",a,"AES-CBC",!1,["encrypt"]),h=await e.subtle.encrypt({name:"AES-CBC",iv:c},l,o),u=new ft({value:[new le({valueHex:i}),new ot({value:Do}),new ot({value:Po}),new ft({value:[new Ft({value:"1.2.840.113549.2.11"}),new Te]})]}),m=new ft({value:[new Ft({value:"1.2.840.113549.1.5.13"}),new ft({value:[new ft({value:[new Ft({value:"1.2.840.113549.1.5.12"}),u]}),new ft({value:[new Ft({value:"2.16.840.1.101.3.4.1.42"}),new le({valueHex:c})]})]})]}),p=new ft({value:[m,new le({valueHex:h})]}).toBER(),d=new Uint8Array(p,0,p.byteLength);return["-----BEGIN ENCRYPTED PRIVATE KEY-----",...z(d,"base64pad").split(/(.{64})/).filter(Boolean),"-----END ENCRYPTED PRIVATE KEY-----"].join(`
7
+ `)}async function Uh(r,t){let e=At.get(),n;if(r.includes("-----BEGIN ENCRYPTED PRIVATE KEY-----")){let s=Y(r.replace("-----BEGIN ENCRYPTED PRIVATE KEY-----","").replace("-----END ENCRYPTED PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:o}=br(s),{iv:i,salt:a,iterations:c,keySize:l,cipherText:h}=Ph(o),u=await To(cr,t,a,{c,dkLen:l}),m=await e.subtle.importKey("raw",u,"AES-CBC",!1,["decrypt"]),f=Gr(await e.subtle.decrypt({name:"AES-CBC",iv:i},m,h)),{result:p}=br(f);n=yc(p)}else if(r.includes("-----BEGIN PRIVATE KEY-----")){let s=Y(r.replace("-----BEGIN PRIVATE KEY-----","").replace("-----END PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:o}=br(s);n=yc(o)}else throw new C("Could not parse private key from PEM data","ERR_INVALID_PARAMETERS");return Oo(n)}function Ph(r){let t=r.valueBlock.value[0];if(t.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.13")throw new C("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 C("Only pkcs5PBKDF2 key derivation functions are supported","ERR_INVALID_PARAMS");let o=n.valueBlock.value[1],i=Gr(o.valueBlock.value[0].getValue()),a=Do,c=Po;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 C("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],h=l.valueBlock.value[0].toString();if(h!=="OBJECT IDENTIFIER : 1.2.840.113549.3.7"){if(h!=="OBJECT IDENTIFIER : 1.3.14.3.2.7"){if(h!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.2"){if(h!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.22"){if(h!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.42")throw new C("Only AES-CBC encryption schemes are supported","ERR_INVALID_PARAMS")}}}}let u=Gr(l.valueBlock.value[1].getValue());return{cipherText:Gr(r.valueBlock.value[1].getValue()),salt:i,iterations:a,keySize:c,iv:u}}function yc(r){return Gr(r.valueBlock.value[2].getValue())}function Gr(r){return new Uint8Array(r,0,r.byteLength)}async function bc(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 vc(t);return{privateKey:e[0],publicKey:e[1]}}async function Vo(r){let e=[await At.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),await Dh(r)],n=await vc({privateKey:e[0],publicKey:e[1]});return{privateKey:n[0],publicKey:n[1]}}async function wc(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 xc(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 vc(r){if(r.privateKey==null||r.publicKey==null)throw new C("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 Dh(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 fs(r){if(r.kty!=="RSA")throw new C("invalid key type","ERR_INVALID_KEY_TYPE");if(r.n==null)throw new C("invalid key modulus","ERR_INVALID_KEY_MODULUS");return Y(r.n,"base64url").length*8}var Zr=8192,Wr=class{_key;constructor(t){this._key=t}verify(t,e){return xc(this._key,e,t)}marshal(){return Le.jwkToPkix(this._key)}get bytes(){return Se.encode({Type:gt.RSA,Data:this.marshal()}).subarray()}equals(t){return bt(this.bytes,t.bytes)}hash(){let t=pt.digest(this.bytes);return Lt(t)?t.then(({bytes:e})=>e):t.bytes}},wr=class{_key;_publicKey;constructor(t,e){this._key=t,this._publicKey=e}genSecret(){return ze(16)}sign(t){return wc(this._key,t)}get public(){if(this._publicKey==null)throw new C("public key not provided","ERR_PUBKEY_NOT_PROVIDED");return new Wr(this._publicKey)}marshal(){return Le.jwkToPkcs1(this._key)}get bytes(){return ke.encode({Type:gt.RSA,Data:this.marshal()}).subarray()}equals(t){return bt(this.bytes,t.bytes)}hash(){let t=pt.digest(this.bytes);return Lt(t)?t.then(({bytes:e})=>e):t.bytes}async id(){let t=await this.public.hash();return z(t,"base58btc")}async export(t,e="pkcs-8"){if(e==="pkcs-8")return Le.exportToPem(this,t);if(e==="libp2p-key")return fr(this.bytes,t);throw new C(`export format '${e}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};async function Oo(r){let t=Le.pkcs1ToJwk(r);if(fs(t)>Zr)throw new C("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await Vo(t);return new wr(e.privateKey,e.publicKey)}function Vh(r){let t=Le.pkixToJwk(r);if(fs(t)>Zr)throw new C("key size is too large","ERR_KEY_SIZE_TOO_LARGE");return new Wr(t)}async function Fh(r){if(fs(r)>Zr)throw new C("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await Vo(r);return new wr(t.privateKey,t.publicKey)}async function Hh(r){if(r>Zr)throw new C("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await bc(r);return new wr(t.privateKey,t.publicKey)}var qo={};ut(qo,{Secp256k1PrivateKey:()=>Jr,Secp256k1PublicKey:()=>Yr,generateKeyPair:()=>ed,unmarshalSecp256k1PrivateKey:()=>Qh,unmarshalSecp256k1PublicKey:()=>td});var Mh=(r,t,e)=>r&t^~r&e,$h=(r,t,e)=>r&t^r&e^t&e,Kh=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]),_e=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Ce=new Uint32Array(64),Ho=class extends ar{constructor(){super(64,32,8,!1),this.A=_e[0]|0,this.B=_e[1]|0,this.C=_e[2]|0,this.D=_e[3]|0,this.E=_e[4]|0,this.F=_e[5]|0,this.G=_e[6]|0,this.H=_e[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)Ce[u]=t.getUint32(e,!1);for(let u=16;u<64;u++){let m=Ce[u-15],f=Ce[u-2],p=Pt(m,7)^Pt(m,18)^m>>>3,d=Pt(f,17)^Pt(f,19)^f>>>10;Ce[u]=d+Ce[u-7]+p+Ce[u-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:l,H:h}=this;for(let u=0;u<64;u++){let m=Pt(a,6)^Pt(a,11)^Pt(a,25),f=h+m+Mh(a,c,l)+Kh[u]+Ce[u]|0,d=(Pt(n,2)^Pt(n,13)^Pt(n,22))+$h(n,s,o)|0;h=l,l=c,c=a,a=i+f|0,i=o,o=s,s=n,n=f+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,h=h+this.H|0,this.set(n,s,o,i,a,c,l,h)}roundClean(){Ce.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Ec=un(()=>new Ho);function qh(r){let t=Cr(r);qt(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:zh,hexToBytes:jh}=dn,Ge={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(r){let{Err:t}=Ge;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:zh(n),l:r.subarray(e+2)}},toSig(r){let{Err:t}=Ge,e=typeof r=="string"?jh(r):r;if(!Dt(e))throw new Error("ui8a expected");let n=e.length;if(n<2||e[0]!=48)throw new t("Invalid signature tag");if(e[1]!==n-2)throw new t("Invalid signature: incorrect length");let{d:s,l:o}=Ge._parseInt(e.subarray(2)),{d:i,l:a}=Ge._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 h=l.toString(16);return h.length&1?`0${h}`:h},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}`}},de=BigInt(0),Ct=BigInt(1),Cm=BigInt(2),Bc=BigInt(3),Um=BigInt(4);function Gh(r){let t=qh(r),{Fp:e}=t,n=t.toBytes||((p,d,g)=>{let y=d.toAffine();return ee(Uint8Array.from([4]),e.toBytes(y.x),e.toBytes(y.y))}),s=t.fromBytes||(p=>{let d=p.subarray(1),g=e.fromBytes(d.subarray(0,e.BYTES)),y=e.fromBytes(d.subarray(e.BYTES,2*e.BYTES));return{x:g,y}});function o(p){let{a:d,b:g}=t,y=e.sqr(p),b=e.mul(y,p);return e.add(e.add(b,e.mul(p,d)),g)}if(!e.eql(e.sqr(t.Gy),o(t.Gx)))throw new Error("bad generator point: equation left != right");function i(p){return typeof p=="bigint"&&de<p&&p<t.n}function a(p){if(!i(p))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(p){let{allowedPrivateKeyLengths:d,nByteLength:g,wrapPrivateKey:y,n:b}=t;if(d&&typeof p!="bigint"){if(Dt(p)&&(p=Qt(p)),typeof p!="string"||!d.includes(p.length))throw new Error("Invalid key");p=p.padStart(g*2,"0")}let w;try{w=typeof p=="bigint"?p:te(et("private key",p,g))}catch{throw new Error(`private key must be ${g} bytes, hex or bigint, not ${typeof p}`)}return y&&(w=Z(w,b)),a(w),w}let l=new Map;function h(p){if(!(p instanceof u))throw new Error("ProjectivePoint expected")}class u{constructor(d,g,y){if(this.px=d,this.py=g,this.pz=y,d==null||!e.isValid(d))throw new Error("x required");if(g==null||!e.isValid(g))throw new Error("y required");if(y==null||!e.isValid(y))throw new Error("z required")}static fromAffine(d){let{x:g,y}=d||{};if(!d||!e.isValid(g)||!e.isValid(y))throw new Error("invalid affine point");if(d instanceof u)throw new Error("projective point not allowed");let b=w=>e.eql(w,e.ZERO);return b(g)&&b(y)?u.ZERO:new u(g,y,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){let g=e.invertBatch(d.map(y=>y.pz));return d.map((y,b)=>y.toAffine(g[b])).map(u.fromAffine)}static fromHex(d){let g=u.fromAffine(s(et("pointHex",d)));return g.assertValidity(),g}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:g}=this.toAffine();if(!e.isValid(d)||!e.isValid(g))throw new Error("bad point: x or y not FE");let y=e.sqr(g),b=o(d);if(!e.eql(y,b))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){h(d);let{px:g,py:y,pz:b}=this,{px:w,py:k,pz:v}=d,A=e.eql(e.mul(g,v),e.mul(w,b)),N=e.eql(e.mul(y,v),e.mul(k,b));return A&&N}negate(){return new u(this.px,e.neg(this.py),this.pz)}double(){let{a:d,b:g}=t,y=e.mul(g,Bc),{px:b,py:w,pz:k}=this,v=e.ZERO,A=e.ZERO,N=e.ZERO,T=e.mul(b,b),q=e.mul(w,w),$=e.mul(k,k),D=e.mul(b,w);return D=e.add(D,D),N=e.mul(b,k),N=e.add(N,N),v=e.mul(d,N),A=e.mul(y,$),A=e.add(v,A),v=e.sub(q,A),A=e.add(q,A),A=e.mul(v,A),v=e.mul(D,v),N=e.mul(y,N),$=e.mul(d,$),D=e.sub(T,$),D=e.mul(d,D),D=e.add(D,N),N=e.add(T,T),T=e.add(N,T),T=e.add(T,$),T=e.mul(T,D),A=e.add(A,T),$=e.mul(w,k),$=e.add($,$),T=e.mul($,D),v=e.sub(v,T),N=e.mul($,q),N=e.add(N,N),N=e.add(N,N),new u(v,A,N)}add(d){h(d);let{px:g,py:y,pz:b}=this,{px:w,py:k,pz:v}=d,A=e.ZERO,N=e.ZERO,T=e.ZERO,q=t.a,$=e.mul(t.b,Bc),D=e.mul(g,w),nt=e.mul(y,k),rt=e.mul(b,v),Tt=e.add(g,y),E=e.add(w,k);Tt=e.mul(Tt,E),E=e.add(D,nt),Tt=e.sub(Tt,E),E=e.add(g,b);let R=e.add(w,v);return E=e.mul(E,R),R=e.add(D,rt),E=e.sub(E,R),R=e.add(y,b),A=e.add(k,v),R=e.mul(R,A),A=e.add(nt,rt),R=e.sub(R,A),T=e.mul(q,E),A=e.mul($,rt),T=e.add(A,T),A=e.sub(nt,T),T=e.add(nt,T),N=e.mul(A,T),nt=e.add(D,D),nt=e.add(nt,D),rt=e.mul(q,rt),E=e.mul($,E),nt=e.add(nt,rt),rt=e.sub(D,rt),rt=e.mul(q,rt),E=e.add(E,rt),D=e.mul(nt,E),N=e.add(N,D),D=e.mul(R,E),A=e.mul(Tt,A),A=e.sub(A,D),D=e.mul(Tt,nt),T=e.mul(R,T),T=e.add(T,D),new u(A,N,T)}subtract(d){return this.add(d.negate())}is0(){return this.equals(u.ZERO)}wNAF(d){return f.wNAFCached(this,l,d,g=>{let y=e.invertBatch(g.map(b=>b.pz));return g.map((b,w)=>b.toAffine(y[w])).map(u.fromAffine)})}multiplyUnsafe(d){let g=u.ZERO;if(d===de)return g;if(a(d),d===Ct)return this;let{endo:y}=t;if(!y)return f.unsafeLadder(this,d);let{k1neg:b,k1:w,k2neg:k,k2:v}=y.splitScalar(d),A=g,N=g,T=this;for(;w>de||v>de;)w&Ct&&(A=A.add(T)),v&Ct&&(N=N.add(T)),T=T.double(),w>>=Ct,v>>=Ct;return b&&(A=A.negate()),k&&(N=N.negate()),N=new u(e.mul(N.px,y.beta),N.py,N.pz),A.add(N)}multiply(d){a(d);let g=d,y,b,{endo:w}=t;if(w){let{k1neg:k,k1:v,k2neg:A,k2:N}=w.splitScalar(g),{p:T,f:q}=this.wNAF(v),{p:$,f:D}=this.wNAF(N);T=f.constTimeNegate(k,T),$=f.constTimeNegate(A,$),$=new u(e.mul($.px,w.beta),$.py,$.pz),y=T.add($),b=q.add(D)}else{let{p:k,f:v}=this.wNAF(g);y=k,b=v}return u.normalizeZ([y,b])[0]}multiplyAndAddUnsafe(d,g,y){let b=u.BASE,w=(v,A)=>A===de||A===Ct||!v.equals(b)?v.multiplyUnsafe(A):v.multiply(A),k=w(this,g).add(w(d,y));return k.is0()?void 0:k}toAffine(d){let{px:g,py:y,pz:b}=this,w=this.is0();d==null&&(d=w?e.ONE:e.inv(b));let k=e.mul(g,d),v=e.mul(y,d),A=e.mul(b,d);if(w)return{x:e.ZERO,y:e.ZERO};if(!e.eql(A,e.ONE))throw new Error("invZ was invalid");return{x:k,y:v}}isTorsionFree(){let{h:d,isTorsionFree:g}=t;if(d===Ct)return!0;if(g)return g(u,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:d,clearCofactor:g}=t;return d===Ct?this:g?g(u,this):this.multiplyUnsafe(t.h)}toRawBytes(d=!0){return this.assertValidity(),n(u,this,d)}toHex(d=!0){return Qt(this.toRawBytes(d))}}u.BASE=new u(t.Gx,t.Gy,e.ONE),u.ZERO=new u(e.ZERO,e.ONE,e.ZERO);let m=t.nBitLength,f=mn(u,t.endo?Math.ceil(m/2):m);return{CURVE:t,ProjectivePoint:u,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:i}}function Wh(r){let t=Cr(r);return qt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Ac(r){let t=Wh(r),{Fp:e,n}=t,s=e.BYTES+1,o=2*e.BYTES+1;function i(E){return de<E&&E<e.ORDER}function a(E){return Z(E,n)}function c(E){return pn(E,n)}let{ProjectivePoint:l,normPrivateKeyToScalar:h,weierstrassEquation:u,isWithinCurveOrder:m}=Gh({...t,toBytes(E,R,O){let B=R.toAffine(),x=e.toBytes(B.x),S=ee;return O?S(Uint8Array.from([R.hasEvenY()?2:3]),x):S(Uint8Array.from([4]),x,e.toBytes(B.y))},fromBytes(E){let R=E.length,O=E[0],B=E.subarray(1);if(R===s&&(O===2||O===3)){let x=te(B);if(!i(x))throw new Error("Point is not on curve");let S=u(x),L=e.sqrt(S),_=(L&Ct)===Ct;return(O&1)===1!==_&&(L=e.neg(L)),{x,y:L}}else if(R===o&&O===4){let x=e.fromBytes(B.subarray(0,e.BYTES)),S=e.fromBytes(B.subarray(e.BYTES,2*e.BYTES));return{x,y:S}}else throw new Error(`Point of length ${R} was invalid. Expected ${s} compressed bytes or ${o} uncompressed bytes`)}}),f=E=>Qt(Ae(E,t.nByteLength));function p(E){let R=n>>Ct;return E>R}function d(E){return p(E)?a(-E):E}let g=(E,R,O)=>te(E.slice(R,O));class y{constructor(R,O,B){this.r=R,this.s=O,this.recovery=B,this.assertValidity()}static fromCompact(R){let O=t.nByteLength;return R=et("compactSignature",R,O*2),new y(g(R,0,O),g(R,O,2*O))}static fromDER(R){let{r:O,s:B}=Ge.toSig(et("DER",R));return new y(O,B)}assertValidity(){if(!m(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!m(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(R){return new y(this.r,this.s,R)}recoverPublicKey(R){let{r:O,s:B,recovery:x}=this,S=N(et("msgHash",R));if(x==null||![0,1,2,3].includes(x))throw new Error("recovery id invalid");let L=x===2||x===3?O+t.n:O;if(L>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let _=x&1?"03":"02",V=l.fromHex(_+f(L)),F=c(L),G=a(-S*F),M=a(B*F),K=l.BASE.multiplyAndAddUnsafe(V,G,M);if(!K)throw new Error("point at infinify");return K.assertValidity(),K}hasHighS(){return p(this.s)}normalizeS(){return this.hasHighS()?new y(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return Fe(this.toDERHex())}toDERHex(){return Ge.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Fe(this.toCompactHex())}toCompactHex(){return f(this.r)+f(this.s)}}let b={isValidPrivateKey(E){try{return h(E),!0}catch{return!1}},normPrivateKeyToScalar:h,randomPrivateKey:()=>{let E=lo(t.n);return ua(t.randomBytes(E),t.n)},precompute(E=8,R=l.BASE){return R._setWindowSize(E),R.multiply(BigInt(3)),R}};function w(E,R=!0){return l.fromPrivateKey(E).toRawBytes(R)}function k(E){let R=Dt(E),O=typeof E=="string",B=(R||O)&&E.length;return R?B===s||B===o:O?B===2*s||B===2*o:E instanceof l}function v(E,R,O=!0){if(k(E))throw new Error("first arg must be private key");if(!k(R))throw new Error("second arg must be public key");return l.fromHex(R).multiply(h(E)).toRawBytes(O)}let A=t.bits2int||function(E){let R=te(E),O=E.length*8-t.nBitLength;return O>0?R>>BigInt(O):R},N=t.bits2int_modN||function(E){return a(A(E))},T=_r(t.nBitLength);function q(E){if(typeof E!="bigint")throw new Error("bigint expected");if(!(de<=E&&E<T))throw new Error(`bigint expected < 2^${t.nBitLength}`);return Ae(E,t.nByteLength)}function $(E,R,O=D){if(["recovered","canonical"].some(Q=>Q in O))throw new Error("sign() legacy options not supported");let{hash:B,randomBytes:x}=t,{lowS:S,prehash:L,extraEntropy:_}=O;S==null&&(S=!0),E=et("msgHash",E),L&&(E=et("prehashed msgHash",B(E)));let V=N(E),F=h(R),G=[q(F),q(V)];if(_!=null){let Q=_===!0?x(e.BYTES):_;G.push(et("extraEntropy",Q))}let M=ee(...G),K=V;function st(Q){let ht=A(Q);if(!m(ht))return;let dt=c(ht),at=l.BASE.multiply(ht).toAffine(),yt=a(at.x);if(yt===de)return;let Wt=a(dt*a(K+yt*F));if(Wt===de)return;let De=(at.x===yt?0:2)|Number(at.y&Ct),kr=Wt;return S&&p(Wt)&&(kr=d(Wt),De^=1),new y(yt,kr,De)}return{seed:M,k2sig:st}}let D={lowS:t.lowS,prehash:!1},nt={lowS:t.lowS,prehash:!1};function rt(E,R,O=D){let{seed:B,k2sig:x}=$(E,R,O),S=t;return oo(S.hash.outputLen,S.nByteLength,S.hmac)(B,x)}l.BASE._setWindowSize(8);function Tt(E,R,O,B=nt){let x=E;if(R=et("msgHash",R),O=et("publicKey",O),"strict"in B)throw new Error("options.strict was renamed to lowS");let{lowS:S,prehash:L}=B,_,V;try{if(typeof x=="string"||Dt(x))try{_=y.fromDER(x)}catch(at){if(!(at instanceof Ge.Err))throw at;_=y.fromCompact(x)}else if(typeof x=="object"&&typeof x.r=="bigint"&&typeof x.s=="bigint"){let{r:at,s:yt}=x;_=new y(at,yt)}else throw new Error("PARSE");V=l.fromHex(O)}catch(at){if(at.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(S&&_.hasHighS())return!1;L&&(R=t.hash(R));let{r:F,s:G}=_,M=N(R),K=c(G),st=a(M*K),Q=a(F*K),ht=l.BASE.multiplyAndAddUnsafe(V,st,Q)?.toAffine();return ht?a(ht.x)===F:!1}return{CURVE:t,getPublicKey:w,getSharedSecret:v,sign:rt,verify:Tt,ProjectivePoint:l,Signature:y,utils:b}}function Zh(r){return{hash:r,hmac:(t,...e)=>Vr(r,t,ln(...e)),randomBytes:ir}}function Ic(r,t){let e=n=>Ac({...r,...Zh(n)});return Object.freeze({...e(t),create:e})}var Rc=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Sc=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Yh=BigInt(1),Mo=BigInt(2),kc=(r,t)=>(r+t/Mo)/t;function Jh(r){let t=Rc,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,h=l*l*r%t,u=X(h,e,t)*h%t,m=X(u,e,t)*h%t,f=X(m,Mo,t)*l%t,p=X(f,s,t)*f%t,d=X(p,o,t)*p%t,g=X(d,a,t)*d%t,y=X(g,c,t)*g%t,b=X(y,a,t)*d%t,w=X(b,e,t)*h%t,k=X(w,i,t)*p%t,v=X(k,n,t)*l%t,A=X(v,Mo,t);if(!$o.eql($o.sqr(A),r))throw new Error("Cannot find square root");return A}var $o=gn(Rc,void 0,void 0,{sqrt:Jh}),Mt=Ic({a:BigInt(0),b:BigInt(7),Fp:$o,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=-Yh*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=e,i=BigInt("0x100000000000000000000000000000000"),a=kc(o*r,t),c=kc(-n*r,t),l=Z(r-a*e-c*s,t),h=Z(-a*n-c*o,t),u=l>i,m=h>i;if(u&&(l=t-l),m&&(h=t-h),l>i||h>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:u,k1:l,k2neg:m,k2:h}}}},Ec),Km=BigInt(0);var qm=Mt.ProjectivePoint;function Nc(){return Mt.utils.randomPrivateKey()}function Tc(r,t){let e=pt.digest(t instanceof Uint8Array?t:t.subarray());if(Lt(e))return e.then(({digest:n})=>Mt.sign(n,r).toDERRawBytes()).catch(n=>{throw new C(String(n),"ERR_INVALID_INPUT")});try{return Mt.sign(e.digest,r).toDERRawBytes()}catch(n){throw new C(String(n),"ERR_INVALID_INPUT")}}function Lc(r,t,e){let n=pt.digest(e instanceof Uint8Array?e:e.subarray());if(Lt(n))return n.then(({digest:s})=>Mt.verify(t,s,r)).catch(s=>{throw new C(String(s),"ERR_INVALID_INPUT")});try{return Mt.verify(t,n.digest,r)}catch(s){throw new C(String(s),"ERR_INVALID_INPUT")}}function _c(r){return Mt.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Cc(r){try{Mt.getPublicKey(r,!0)}catch(t){throw new C(String(t),"ERR_INVALID_PRIVATE_KEY")}}function Ko(r){try{Mt.ProjectivePoint.fromHex(r)}catch(t){throw new C(String(t),"ERR_INVALID_PUBLIC_KEY")}}function Uc(r){try{return Mt.getPublicKey(r,!0)}catch(t){throw new C(String(t),"ERR_INVALID_PRIVATE_KEY")}}var Yr=class{_key;constructor(t){Ko(t),this._key=t}verify(t,e){return Lc(this._key,e,t)}marshal(){return _c(this._key)}get bytes(){return Se.encode({Type:gt.Secp256k1,Data:this.marshal()}).subarray()}equals(t){return bt(this.bytes,t.bytes)}async hash(){let t=pt.digest(this.bytes),e;return Lt(t)?{bytes:e}=await t:e=t.bytes,e}},Jr=class{_key;_publicKey;constructor(t,e){this._key=t,this._publicKey=e??Uc(t),Cc(this._key),Ko(this._publicKey)}sign(t){return Tc(this._key,t)}get public(){return new Yr(this._publicKey)}marshal(){return this._key}get bytes(){return ke.encode({Type:gt.Secp256k1,Data:this.marshal()}).subarray()}equals(t){return bt(this.bytes,t.bytes)}hash(){let t=pt.digest(this.bytes);return Lt(t)?t.then(({bytes:e})=>e):t.bytes}async id(){let t=await this.public.hash();return z(t,"base58btc")}async export(t,e="libp2p-key"){if(e==="libp2p-key")return fr(this.bytes,t);throw new C(`export format '${e}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function Qh(r){return new Jr(r)}function td(r){return new Yr(r)}async function ed(){let r=Nc();return new Jr(r)}var Pc={rsa:Fo,ed25519:No,secp256k1:qo};function rd(r){let t=Object.keys(Pc).join(" / ");return new C(`invalid or unsupported key type ${r}. Must be ${t}`,"ERR_UNSUPPORTED_KEY_TYPE")}function zo(r){if(r=r.toLowerCase(),r==="rsa"||r==="ed25519"||r==="secp256k1")return Pc[r];throw rd(r)}async function Dc(r,t){return zo(r).generateKeyPair(t??2048)}function Oc(r,t){return t=(t??"rsa").toLowerCase(),zo(t),r.bytes}function Vc(r,t){return t=(t??"rsa").toLowerCase(),zo(t),r.bytes}var Fc=async()=>{let r=await Dc("Ed25519"),t=await nd(r);if(t.type==="Ed25519")return t;throw new Error(`Generated unexpected PeerId type "${t.type}"`)};async function nd(r){return Gi(Oc(r.public),Vc(r))}var sd=Math.pow(2,7),od=Math.pow(2,14),id=Math.pow(2,21),jo=Math.pow(2,28),Go=Math.pow(2,35),Wo=Math.pow(2,42),Zo=Math.pow(2,49),j=128,Et=127;function Rt(r){if(r<sd)return 1;if(r<od)return 2;if(r<id)return 3;if(r<jo)return 4;if(r<Go)return 5;if(r<Wo)return 6;if(r<Zo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ad(r,t,e=0){switch(Rt(r)){case 8:t[e++]=r&255|j,r/=128;case 7:t[e++]=r&255|j,r/=128;case 6:t[e++]=r&255|j,r/=128;case 5:t[e++]=r&255|j,r/=128;case 4:t[e++]=r&255|j,r>>>=7;case 3:t[e++]=r&255|j,r>>>=7;case 2:t[e++]=r&255|j,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function cd(r,t,e=0){switch(Rt(r)){case 8:t.set(e++,r&255|j),r/=128;case 7:t.set(e++,r&255|j),r/=128;case 6:t.set(e++,r&255|j),r/=128;case 5:t.set(e++,r&255|j),r/=128;case 4:t.set(e++,r&255|j),r>>>=7;case 3:t.set(e++,r&255|j),r>>>=7;case 2:t.set(e++,r&255|j),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function ld(r,t){let e=r[t],n=0;if(n+=e&Et,e<j||(e=r[t+1],n+=(e&Et)<<7,e<j)||(e=r[t+2],n+=(e&Et)<<14,e<j)||(e=r[t+3],n+=(e&Et)<<21,e<j)||(e=r[t+4],n+=(e&Et)*jo,e<j)||(e=r[t+5],n+=(e&Et)*Go,e<j)||(e=r[t+6],n+=(e&Et)*Wo,e<j)||(e=r[t+7],n+=(e&Et)*Zo,e<j))return n;throw new RangeError("Could not decode varint")}function ud(r,t){let e=r.get(t),n=0;if(n+=e&Et,e<j||(e=r.get(t+1),n+=(e&Et)<<7,e<j)||(e=r.get(t+2),n+=(e&Et)<<14,e<j)||(e=r.get(t+3),n+=(e&Et)<<21,e<j)||(e=r.get(t+4),n+=(e&Et)*jo,e<j)||(e=r.get(t+5),n+=(e&Et)*Go,e<j)||(e=r.get(t+6),n+=(e&Et)*Wo,e<j)||(e=r.get(t+7),n+=(e&Et)*Zo,e<j))return n;throw new RangeError("Could not decode varint")}function Ue(r,t,e=0){return t==null&&(t=wt(Rt(r))),t instanceof Uint8Array?ad(r,t,e):cd(r,t,e)}function pe(r,t=0){return r instanceof Uint8Array?ld(r,t):ud(r,t)}var ds=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 h=this.readAtomically(()=>{let u=this.readChar();if(u===void 0)return;let m=Number.parseInt(u,t);if(!Number.isNaN(m))return m});if(h===void 0)break;if(o*=t,o+=h,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 Hc=45,fd=15,xr=new ds;function Yo(r){if(!(r.length>fd))return xr.new(r).parseWith(()=>xr.readIPv4Addr())}function Jo(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Hc))return xr.new(r).parseWith(()=>xr.readIPv6Addr())}function ps(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Hc))return xr.new(r).parseWith(()=>xr.readIPAddr())}var xy=parseInt("0xFFFF",16),vy=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Kc(r){return!!Yo(r)}function qc(r){return!!Jo(r)}function vr(r){return!!ps(r)}var zc=Kc,md=qc,Xo=function(r){let t=0;if(r=r.toString().trim(),zc(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(md(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let o=zc(e[n]),i;o&&(i=Xo(e[n]),e[n]=z(i.slice(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,z(i.slice(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let o=[n,1];for(n=9-e.length;n>0;n--)o.push("0");e.splice.apply(e,o)}let s=new Uint8Array(t+16);for(n=0;n<e.length;n++){let o=parseInt(e[n],16);s[t++]=o>>8&255,s[t++]=o&255}return s}throw new Error("invalid ip address")},jc=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 Er={},Qo={},bd=[[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"]];bd.forEach(r=>{let t=wd(...r);Qo[t.code]=t,Er[t.name]=t});function wd(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(Er[r]!=null)return Er[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var sb=W("ip4"),ob=W("ip6"),ib=W("ipcidr");function ei(r,t){switch(W(r).code){case 4:case 41:return vd(t);case 42:return Zc(t);case 6:case 273:case 33:case 132:return Jc(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Zc(t);case 421:return Id(t);case 444:return Yc(t);case 445:return Yc(t);case 466:return Ad(t);default:return z(t,"base16")}}function ri(r,t){switch(W(r).code){case 4:return Gc(t);case 41:return Gc(t);case 42:return Wc(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 Wc(t);case 421:return Ed(t);case 444:return Sd(t);case 445:return kd(t);case 466:return Bd(t);default:return Y(t,"base16")}}var ti=Object.values(be).map(r=>r.decoder),xd=function(){let r=ti[0].or(ti[1]);return ti.slice(2).forEach(t=>r=r.or(t)),r}();function Gc(r){if(!vr(r))throw new Error("invalid ip address");return Xo(r)}function vd(r){let t=jc(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!vr(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 Jc(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Wc(r){let t=Y(r),e=Uint8Array.from(Ue(t.length));return Bt([e,t],e.length+t.length)}function Zc(r){let t=pe(r);if(r=r.slice(Rt(t)),r.length!==t)throw new Error("inconsistent lengths");return z(r)}function Ed(r){let t;r[0]==="Q"||r[0]==="1"?t=Oe(ct.decode(`z${r}`)).bytes:t=Ut.parse(r).multihash.bytes;let e=Uint8Array.from(Ue(t.length));return Bt([e,t],e.length+t.length)}function Bd(r){let t=xd.decode(r),e=Uint8Array.from(Ue(t.length));return Bt([e,t],e.length+t.length)}function Ad(r){let t=pe(r),e=r.slice(Rt(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+z(e,"base64url")}function Id(r){let t=pe(r),e=r.slice(Rt(t));if(e.length!==t)throw new Error("inconsistent lengths");return z(e,"base58btc")}function Sd(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=Yt.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 kd(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=Yt.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=z(t,"base32"),s=Jc(e);return`${n}:${s}`}function Xc(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 tl("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:Qc(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=pe(r,s),i=Rt(o),a=W(o),c=Rd(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 tl("Invalid address Uint8Array: "+z(r,"base16"));t.push([o,l]);let h=ei(o,l);if(e.push([o,h]),a.path===!0){n=h;break}}return{bytes:Uint8Array.from(r),string:Qc(e),tuples:t,stringTuples:e,path:n}}function Qc(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(Ue(e.code));return t.length>1&&t[1]!=null&&(n=Bt([n,t[1]])),n}))}function Rd(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=pe(t instanceof Uint8Array?t:Uint8Array.from(t));return e+Rt(e)}}function si(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}function tl(r){return new Error("Error parsing address: "+r)}var Nd=Symbol.for("nodejs.util.inspect.custom"),ai=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Td=[W("dns").code,W("dns4").code,W("dns6").code,W("dnsaddr").code],gs=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=Xc(t)}else if(rl(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"),h=W("dns6"),u=W("ip6zone");for(let[f,p]of this.stringTuples())f===u.code&&(o=`%${p??""}`),Td.includes(f)&&(e=i.name,s=443,n=`${p??""}${o}`,t=f===h.code?6:4),(f===i.code||f===a.code)&&(e=W(f).name,s=parseInt(p??"")),(f===c.code||f===l.code)&&(e=W(f).name,n=`${p??""}${o}`,t=f===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===Er.p2p.code&&t.push([n,s]),n===Er["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?z(ct.decode(`z${n}`),"base58btc"):z(Ut.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return bt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(o=>o.resolvable);if(e==null)return[this];let n=el.get(e.name);if(n==null)throw new C(`no available resolver for ${e.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,t)).map(o=>new r(o))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[Nd](){return`Multiaddr(${this.#e})`}};var el=new Map;function rl(r){return!!r?.[ai]}function ms(r){return new gs(r)}function Ld(r){return r[Symbol.asyncIterator]!=null}function _d(r){if(Ld(r))return(async()=>{for await(let t of r)return t})();for(let t of r)return t}var ci=_d;var sl=Symbol.for("@achingbrain/uint8arraylist");function nl(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 ys(r){return!!r?.[sl]}var Br=class r{bufs;length;[sl]=!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(ys(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(ys(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=nl(this.bufs,t);return e.buf[e.index]}set(t,e){let n=nl(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(ys(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,h=e>a&&e<=c;if(l&&h){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(h){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(!ys(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,h;for(let u=e;u<=c;u+=h){h=0;for(let m=l;m>=0;m--){let f=this.get(u+m);if(n[m]!==f){h=Math.max(1,m-a[f]);break}}if(h===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=Jt(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=Jt(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=Jt(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=Jt(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=Jt(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=Jt(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=Jt(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=Jt(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 bs(r){return r[Symbol.asyncIterator]!=null}var ws=r=>{let t=Rt(r),e=wt(t);return Ue(r,e),ws.bytes=t,e};ws.bytes=0;function Xr(r,t){t=t??{};let e=t.lengthEncoder??ws;function*n(s){let o=e(s.byteLength);o instanceof Uint8Array?yield o:yield*o,s instanceof Uint8Array?yield s:yield*s}return bs(r)?async function*(){for await(let s of r)yield*n(s)}():function*(){for(let s of r)yield*n(s)}()}Xr.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??ws;return new Br(e(r.byteLength),r)};var Ar=rn(al(),1);var Ud=8,Pd=1024*1024*4,We;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(We||(We={}));var li=r=>{let t=pe(r);return li.bytes=Rt(t),t};li.bytes=0;function Ir(r,t){let e=new Br,n=We.LENGTH,s=-1,o=t?.lengthDecoder??li,i=t?.maxLengthLength??Ud,a=t?.maxDataLength??Pd;function*c(){for(;e.byteLength>0;){if(n===We.LENGTH)try{if(s=o(e),s<0)throw(0,Ar.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(s>a)throw(0,Ar.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=We.DATA}catch(l){if(l instanceof RangeError){if(e.byteLength>i)throw(0,Ar.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw l}if(n===We.DATA){if(e.byteLength<s)break;let l=e.sublist(0,s);e.consume(s),t?.onData!=null&&t.onData(l),yield l,n=We.LENGTH}}}return bs(r)?async function*(){for await(let l of r)e.append(l),yield*c();if(e.byteLength>0)throw(0,Ar.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,Ar.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}Ir.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 Ir(n,{...t??{},onLength:o=>{e=o}})};function Od(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 cl=Od;function Vd(r){return r[Symbol.asyncIterator]!=null}function Fd(r,t){if(Vd(r))return async function*(){for await(let a of r)yield t(a)}();let e=cl(r),{value:n,done:s}=e.next();if(s===!0)return function*(){}();let o=t(n);if(typeof o.then=="function")return async function*(){yield await o;for await(let a of e)yield t(a)}();let i=t;return function*(){yield o;for(let a of e)yield i(a)}()}var ll=Fd;function ge(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var xs=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=ge(),a=ge(),c=!1,l,h=!1;s.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let p of r){if(o.length===e&&(i=ge(),await i.promise),h)break;let d={done:!1};o.push(d),p().then(g=>{d.done=!0,d.ok=!0,d.value=g,s.dispatchEvent(new xs("task-complete"))},g=>{d.done=!0,d.err=g,s.dispatchEvent(new xs("task-complete"))})}c=!0,s.dispatchEvent(new xs("task-complete"))}catch(p){l=p,s.dispatchEvent(new xs("task-complete"))}});function u(){return n?o[0]?.done:!!o.find(p=>p.done)}function*m(){for(;o.length>0&&o[0].done;){let p=o[0];if(o.shift(),p.ok)yield p.value;else throw h=!0,i.resolve(),p.err;i.resolve()}}function*f(){for(;u();)for(let p=0;p<o.length;p++)if(o[p].done){let d=o[p];if(o.splice(p,1),p--,d.ok)yield d.value;else throw h=!0,i.resolve(),d.err;i.resolve()}}for(;;){if(u()||(a=ge(),await a.promise),l!=null)throw l;if(n?yield*m():yield*f(),c&&o.length===0)break}}var vs=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}},Sr=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new vs(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 vs(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 Es(r={}){return Hd(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 Hd(r,t){t=t??{};let e=t.onEnd,n=new Sr,s,o,i,a=ge(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((g,y)=>{o=b=>{o=null,n.push(b);try{g(r(n))}catch(w){y(w)}return s}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=ge()})}},l=g=>o!=null?o(g):(n.push(g),s),h=g=>(n=new Sr,o!=null?o({error:g}):(n.push({error:g}),s)),u=g=>{if(i)return s;if(t?.objectMode!==!0&&g?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:g})},m=g=>i?s:(i=!0,g!=null?h(g):l({done:!0})),f=()=>(n=new Sr,m(),{done:!0}),p=g=>(m(g),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:f,throw:p,push:u,end:m,get readableLength(){return n.size},onEmpty:async g=>{let y=g?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let b,w;y!=null&&(b=new Promise((k,v)=>{w=()=>{v(new fi)},y.addEventListener("abort",w)}));try{await Promise.race([a.promise,b])}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(g){return d.throw(g),e!=null&&(e(g),e=void 0),{done:!0}},return(){return d.return(),e!=null&&(e(),e=void 0),{done:!0}},push:u,end(g){return d.end(g),e!=null&&(e(g),e=void 0),s},get readableLength(){return d.readableLength},onEmpty:g=>d.onEmpty(g)},s}function Md(r){return r[Symbol.asyncIterator]!=null}function $d(...r){let t=[];for(let e of r)Md(e)||t.push(e);return t.length===r.length?function*(){for(let e of t)yield*e}():async function*(){let e=Es({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 ul=$d;function di(r,...t){if(r==null)throw new Error("Empty pipeline");if(hi(r)){let n=r;r=()=>n.source}else if(hl(r)||fl(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]=qd(e[n]));return Kd(...e)}var Kd=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},fl=r=>r?.[Symbol.asyncIterator]!=null,hl=r=>r?.[Symbol.iterator]!=null,hi=r=>r==null?!1:r.sink!=null&&r.source!=null,qd=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=Es({objectMode:!0});e.then(()=>{n.end()},i=>{n.end(i)});let s,o=r.source;if(fl(o))s=async function*(){yield*o,n.end()};else if(hl(o))s=function*(){yield*o,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return ul(n,s())}return r.source};var wl=rn(dl(),1);var pl="[a-fA-F\\d:]",Pe=r=>r&&r.includeBoundaries?`(?:(?<=\\s|^)(?=${pl})|(?<=${pl})(?=\\s|$))`:"",$t="(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}",it="[a-fA-F\\d]{1,4}",Bs=`
8
8
  (?:
9
9
  (?:${it}:){7}(?:${it}|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8
10
- (?:${it}:){6}(?:${zt}|:${it}|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4
11
- (?:${it}:){5}(?::${zt}|(?::${it}){1,2}|:)| // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::7:1.2.3.4
12
- (?:${it}:){4}(?:(?::${it}){0,1}:${zt}|(?::${it}){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4
13
- (?:${it}:){3}(?:(?::${it}){0,2}:${zt}|(?::${it}){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4
14
- (?:${it}:){2}(?:(?::${it}){0,3}:${zt}|(?::${it}){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4
15
- (?:${it}:){1}(?:(?::${it}){0,4}:${zt}|(?::${it}){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4
16
- (?::(?:(?::${it}){0,5}:${zt}|(?::${it}){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4
10
+ (?:${it}:){6}(?:${$t}|:${it}|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4
11
+ (?:${it}:){5}(?::${$t}|(?::${it}){1,2}|:)| // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::7:1.2.3.4
12
+ (?:${it}:){4}(?:(?::${it}){0,1}:${$t}|(?::${it}){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4
13
+ (?:${it}:){3}(?:(?::${it}){0,2}:${$t}|(?::${it}){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4
14
+ (?:${it}:){2}(?:(?::${it}){0,3}:${$t}|(?::${it}){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4
15
+ (?:${it}:){1}(?:(?::${it}){0,4}:${$t}|(?::${it}){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4
16
+ (?::(?:(?::${it}){0,5}:${$t}|(?::${it}){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4
17
17
  )(?:%[0-9a-zA-Z]{1,})? // %eth0 %1
18
- `.replace(/\s*\/\/.*$/gm,"").replace(/\n/g,"").trim(),Xd=new RegExp(`(?:^${zt}$)|(?:^${Is}$)`),Qd=new RegExp(`^${zt}$`),t0=new RegExp(`^${Is}$`),yi=r=>r&&r.exact?Xd:new RegExp(`(?:${De(r)}${zt}${De(r)})|(?:${De(r)}${Is}${De(r)})`,"g");yi.v4=r=>r&&r.exact?Qd:new RegExp(`${De(r)}${zt}${De(r)}`,"g");yi.v6=r=>r&&r.exact?t0:new RegExp(`${De(r)}${Is}${De(r)}`,"g");var vl=yi;var Sl=rn(Al(),1),{isValid:e0,parse:r0}=Sl.default,n0=["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"],s0=n0.map(r=>new Il.Netmask(r));function o0(r){for(let t of s0)if(t.contains(r))return!0;return!1}function Bl(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)}var kl=r=>{if(e0(r)){let t=r0(r);if(t.kind()==="ipv4")return o0(t.toNormalizedString());if(t.kind()==="ipv6")return Bl(r)}else if(Sr(r)&&vl.v6().test(r))return Bl(r)};var bi=kl;var Rl="libp2p",Nl="autonat",Tl="1.0.0";var P;(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=()=>pr(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=()=>pr(s)}(n=r.ResponseStatus||(r.ResponseStatus={}));let o;(function(l){let h;l.codec=()=>(h==null&&(h=Mt((u,m,f={})=>{if(f.lengthDelimited!==!1&&m.fork(),u.id!=null&&(m.uint32(10),m.bytes(u.id)),u.addrs!=null)for(let p of u.addrs)m.uint32(18),m.bytes(p);f.lengthDelimited!==!1&&m.ldelim()},(u,m)=>{let f={addrs:[]},p=m==null?u.len:u.pos+m;for(;u.pos<p;){let d=u.uint32();switch(d>>>3){case 1:f.id=u.bytes();break;case 2:f.addrs.push(u.bytes());break;default:u.skipType(d&7);break}}return f})),h),l.encode=u=>Ht(u,l.codec()),l.decode=u=>Ft(u,l.codec())})(o=r.PeerInfo||(r.PeerInfo={}));let i;(function(l){let h;l.codec=()=>(h==null&&(h=Mt((u,m,f={})=>{f.lengthDelimited!==!1&&m.fork(),u.peer!=null&&(m.uint32(10),r.PeerInfo.codec().encode(u.peer,m)),f.lengthDelimited!==!1&&m.ldelim()},(u,m)=>{let f={},p=m==null?u.len:u.pos+m;for(;u.pos<p;){let d=u.uint32();switch(d>>>3){case 1:f.peer=r.PeerInfo.codec().decode(u,u.uint32());break;default:u.skipType(d&7);break}}return f})),h),l.encode=u=>Ht(u,l.codec()),l.decode=u=>Ft(u,l.codec())})(i=r.Dial||(r.Dial={}));let a;(function(l){let h;l.codec=()=>(h==null&&(h=Mt((u,m,f={})=>{f.lengthDelimited!==!1&&m.fork(),u.status!=null&&(m.uint32(8),r.ResponseStatus.codec().encode(u.status,m)),u.statusText!=null&&(m.uint32(18),m.string(u.statusText)),u.addr!=null&&(m.uint32(26),m.bytes(u.addr)),f.lengthDelimited!==!1&&m.ldelim()},(u,m)=>{let f={},p=m==null?u.len:u.pos+m;for(;u.pos<p;){let d=u.uint32();switch(d>>>3){case 1:f.status=r.ResponseStatus.codec().decode(u);break;case 2:f.statusText=u.string();break;case 3:f.addr=u.bytes();break;default:u.skipType(d&7);break}}return f})),h),l.encode=u=>Ht(u,l.codec()),l.decode=u=>Ft(u,l.codec())})(a=r.DialResponse||(r.DialResponse={}));let c;r.codec=()=>(c==null&&(c=Mt((l,h,u={})=>{u.lengthDelimited!==!1&&h.fork(),l.type!=null&&(h.uint32(8),r.MessageType.codec().encode(l.type,h)),l.dial!=null&&(h.uint32(18),r.Dial.codec().encode(l.dial,h)),l.dialResponse!=null&&(h.uint32(26),r.DialResponse.codec().encode(l.dialResponse,h)),u.lengthDelimited!==!1&&h.ldelim()},(l,h)=>{let u={},m=h==null?l.len:l.pos+h;for(;l.pos<m;){let f=l.uint32();switch(f>>>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(f&7);break}}return u})),c),r.encode=l=>Ht(l,r.codec()),r.decode=l=>Ft(l,r.codec())})(P||(P={}));var wi=4,ks=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??Rl}/${Nl}/${Tl}`,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 _("handleIncomingAutonatStream timeout",Ns))};e.addEventListener("abort",n,{once:!0}),Ls(1/0,e);let s=this.components.addressManager.getAddresses().map(o=>o.toOptions().host);try{let o=this;await mi(t.stream,i=>Tr(i),async function*(i){let a=await fi(i);if(a==null){o.log("no message received"),yield P.encode({type:P.MessageType.DIAL_RESPONSE,dialResponse:{status:P.ResponseStatus.E_BAD_REQUEST,statusText:"No message was sent"}});return}let c;try{c=P.decode(a)}catch(d){o.log.error("could not decode message",d),yield P.encode({type:P.MessageType.DIAL_RESPONSE,dialResponse:{status:P.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 P.encode({type:P.MessageType.DIAL_RESPONSE,dialResponse:{status:P.ResponseStatus.E_BAD_REQUEST,statusText:"No Dial message found in message"}});return}let h,u=l.peer;if(u==null||u.id==null){o.log.error("PeerId missing from message"),yield P.encode({type:P.MessageType.DIAL_RESPONSE,dialResponse:{status:P.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}});return}try{h=on(u.id)}catch(d){o.log.error("invalid PeerId",d),yield P.encode({type:P.MessageType.DIAL_RESPONSE,dialResponse:{status:P.ResponseStatus.E_BAD_REQUEST,statusText:"bad peer id"}});return}if(o.log("incoming request from %p",h),!t.connection.remotePeer.equals(h)){o.log("target peer %p did not equal sending peer %p",h,t.connection.remotePeer),yield P.encode({type:P.MessageType.DIAL_RESPONSE,dialResponse:{status:P.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}});return}let m=u.addrs.map(d=>bs(d)).filter(d=>{let g=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,g),g}).filter(d=>{let g=d.toOptions().host,y=!(bi(g)??!1);return o.log.trace("host %s was public %s",g,y),y}).filter(d=>{let g=d.toOptions().host,y=!s.includes(g);return o.log.trace("host %s was not our host %s",g,y),y}).filter(d=>{let g=!!o.components.transportManager.transportForMultiaddr(d);return o.log.trace("transport for %a is supported %s",d,g),g}).map(d=>(d.getPeerId()==null&&(d=d.encapsulate(`/p2p/${h.toString()}`)),d));if(m.length===0){o.log("no valid multiaddrs for %p in message",h),yield P.encode({type:P.MessageType.DIAL_RESPONSE,dialResponse:{status:P.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}});return}o.log("dial multiaddrs %s for peer %p",m.map(d=>d.toString()).join(", "),h);let f="",p=m[0];for await(let d of m){let g;p=d;try{if(g=await o.components.connectionManager.openConnection(d,{signal:e}),!g.remoteAddr.equals(d))throw o.log.error("tried to dial %a but dialed %a",d,g.remoteAddr),new Error("Unexpected remote address");o.log("Success %p",h),yield P.encode({type:P.MessageType.DIAL_RESPONSE,dialResponse:{status:P.ResponseStatus.OK,addr:g.remoteAddr.decapsulateCode(W("p2p").code).bytes}});return}catch(y){o.log("could not dial %p",h,y),f=y.message}finally{g!=null&&await g.close()}}yield P.encode({type:P.MessageType.DIAL_RESPONSE,dialResponse:{status:P.ResponseStatus.E_DIAL_ERROR,statusText:f,addr:p.bytes}})},i=>Xr(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!(bi(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);Ls(1/0,n);let s=this;try{this.log("verify multiaddrs %s",e.map(u=>u.toString()).join(", "));let o=P.encode({type:P.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toBytes(),addrs:e.map(u=>u.bytes)}}}),a=(await zc()).toBytes(),c={},l=[],h=async u=>{let m=()=>{};try{this.log("asking %p to verify multiaddr",u.id);let f=await s.components.connectionManager.openConnection(u.id,{signal:n}),p=await f.newStream(this.protocol,{signal:n});m=()=>{p.abort(new _("verifyAddress timeout",Ns))},n.addEventListener("abort",m,{once:!0});let d=await mi([o],y=>Xr(y),p,y=>Tr(y),async y=>fi(y));if(d==null){this.log("no response received from %p",f.remotePeer);return}let g=P.decode(d);if(g.type!==P.MessageType.DIAL_RESPONSE||g.dialResponse==null){this.log("invalid autonat response from %p",f.remotePeer);return}if(g.dialResponse.status===P.ResponseStatus.OK){let y=f.remoteAddr.toOptions(),b;if(y.family===4)b=y.host.split(".")[0];else if(y.family===6)b=y.host.split(":")[0];else{this.log('remote address "%s" was not IP4 or IP6?',y.host);return}if(l.includes(b)){this.log("already have response from network segment %d - %s",b,y.host);return}l.push(b)}return g.dialResponse}catch(f){this.log.error("error asking remote to verify multiaddr",f)}finally{n.removeEventListener("abort",m)}};for await(let u of di(gl(this.components.peerRouting.getClosestPeers(a,{signal:n}),m=>async()=>h(m)),{concurrency:wi}))try{if(u==null)continue;let m=u.addr==null?e[0]:bs(u.addr);if(this.log("autonat response for %a is %s",m,u.status),u.status===P.ResponseStatus.E_BAD_REQUEST||u.status===P.ResponseStatus.E_DIAL_REFUSED||u.addr==null&&e.length>1)continue;if(!e.some(p=>p.equals(m))){this.log("peer reported %a as %s but it was not in our observed address list",m,u.status);continue}let f=m.toString();if(c[f]==null&&(c[f]={success:0,failure:0}),u.status===P.ResponseStatus.OK?c[f].success++:u.status===P.ResponseStatus.E_DIAL_ERROR&&c[f].failure++,c[f].success===wi){this.log("%a is externally dialable",m),t.confirmObservedAddr(m);return}if(c[f].failure===wi){this.log("%a is not externally dialable",m),t.removeObservedAddr(m);return}}catch(m){this.log.error("could not verify external address",m)}}finally{this.verifyAddressTimeout=setTimeout(this._verifyExternalAddresses,this.refreshInterval)}}};function f0(r={}){return t=>new ks(t,r)}return ql(h0);})();
18
+ `.replace(/\s*\/\/.*$/gm,"").replace(/\n/g,"").trim(),zd=new RegExp(`(?:^${$t}$)|(?:^${Bs}$)`),jd=new RegExp(`^${$t}$`),Gd=new RegExp(`^${Bs}$`),pi=r=>r&&r.exact?zd:new RegExp(`(?:${Pe(r)}${$t}${Pe(r)})|(?:${Pe(r)}${Bs}${Pe(r)})`,"g");pi.v4=r=>r&&r.exact?jd:new RegExp(`${Pe(r)}${$t}${Pe(r)}`,"g");pi.v6=r=>r&&r.exact?Gd:new RegExp(`${Pe(r)}${Bs}${Pe(r)}`,"g");var gl=pi;var xl=rn(yl(),1),{isValid:Wd,parse:Zd}=xl.default,Yd=["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"],Jd=Yd.map(r=>new wl.Netmask(r));function Xd(r){for(let t of Jd)if(t.contains(r))return!0;return!1}function bl(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)}var vl=r=>{if(Wd(r)){let t=Zd(r);if(t.kind()==="ipv4")return Xd(t.toNormalizedString());if(t.kind()==="ipv6")return bl(r)}else if(vr(r)&&gl.v6().test(r))return bl(r)};var gi=vl;var El="libp2p",Bl="autonat",Al="1.0.0";var P;(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=()=>dr(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=()=>dr(s)}(n=r.ResponseStatus||(r.ResponseStatus={}));let o;(function(l){let h;l.codec=()=>(h==null&&(h=ie((u,m,f={})=>{if(f.lengthDelimited!==!1&&m.fork(),u.id!=null&&(m.uint32(10),m.bytes(u.id)),u.addrs!=null)for(let p of u.addrs)m.uint32(18),m.bytes(p);f.lengthDelimited!==!1&&m.ldelim()},(u,m)=>{let f={addrs:[]},p=m==null?u.len:u.pos+m;for(;u.pos<p;){let d=u.uint32();switch(d>>>3){case 1:f.id=u.bytes();break;case 2:f.addrs.push(u.bytes());break;default:u.skipType(d&7);break}}return f})),h),l.encode=u=>oe(u,l.codec()),l.decode=u=>se(u,l.codec())})(o=r.PeerInfo||(r.PeerInfo={}));let i;(function(l){let h;l.codec=()=>(h==null&&(h=ie((u,m,f={})=>{f.lengthDelimited!==!1&&m.fork(),u.peer!=null&&(m.uint32(10),r.PeerInfo.codec().encode(u.peer,m)),f.lengthDelimited!==!1&&m.ldelim()},(u,m)=>{let f={},p=m==null?u.len:u.pos+m;for(;u.pos<p;){let d=u.uint32();switch(d>>>3){case 1:f.peer=r.PeerInfo.codec().decode(u,u.uint32());break;default:u.skipType(d&7);break}}return f})),h),l.encode=u=>oe(u,l.codec()),l.decode=u=>se(u,l.codec())})(i=r.Dial||(r.Dial={}));let a;(function(l){let h;l.codec=()=>(h==null&&(h=ie((u,m,f={})=>{f.lengthDelimited!==!1&&m.fork(),u.status!=null&&(m.uint32(8),r.ResponseStatus.codec().encode(u.status,m)),u.statusText!=null&&(m.uint32(18),m.string(u.statusText)),u.addr!=null&&(m.uint32(26),m.bytes(u.addr)),f.lengthDelimited!==!1&&m.ldelim()},(u,m)=>{let f={},p=m==null?u.len:u.pos+m;for(;u.pos<p;){let d=u.uint32();switch(d>>>3){case 1:f.status=r.ResponseStatus.codec().decode(u);break;case 2:f.statusText=u.string();break;case 3:f.addr=u.bytes();break;default:u.skipType(d&7);break}}return f})),h),l.encode=u=>oe(u,l.codec()),l.decode=u=>se(u,l.codec())})(a=r.DialResponse||(r.DialResponse={}));let c;r.codec=()=>(c==null&&(c=ie((l,h,u={})=>{u.lengthDelimited!==!1&&h.fork(),l.type!=null&&(h.uint32(8),r.MessageType.codec().encode(l.type,h)),l.dial!=null&&(h.uint32(18),r.Dial.codec().encode(l.dial,h)),l.dialResponse!=null&&(h.uint32(26),r.DialResponse.codec().encode(l.dialResponse,h)),u.lengthDelimited!==!1&&h.ldelim()},(l,h)=>{let u={},m=h==null?l.len:l.pos+h;for(;l.pos<m;){let f=l.uint32();switch(f>>>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(f&7);break}}return u})),c),r.encode=l=>oe(l,r.codec()),r.decode=l=>se(l,r.codec())})(P||(P={}));var mi=4,Is=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??El}/${Bl}/${Al}`,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 C("handleIncomingAutonatStream timeout",ks))};e.addEventListener("abort",n,{once:!0}),Rs(1/0,e);let s=this.components.addressManager.getAddresses().map(o=>o.toOptions().host);try{let o=this;await di(t.stream,i=>Ir(i),async function*(i){let a=await ci(i);if(a==null){o.log("no message received"),yield P.encode({type:P.MessageType.DIAL_RESPONSE,dialResponse:{status:P.ResponseStatus.E_BAD_REQUEST,statusText:"No message was sent"}});return}let c;try{c=P.decode(a)}catch(d){o.log.error("could not decode message",d),yield P.encode({type:P.MessageType.DIAL_RESPONSE,dialResponse:{status:P.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 P.encode({type:P.MessageType.DIAL_RESPONSE,dialResponse:{status:P.ResponseStatus.E_BAD_REQUEST,statusText:"No Dial message found in message"}});return}let h,u=l.peer;if(u==null||u.id==null){o.log.error("PeerId missing from message"),yield P.encode({type:P.MessageType.DIAL_RESPONSE,dialResponse:{status:P.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}});return}try{h=sn(u.id)}catch(d){o.log.error("invalid PeerId",d),yield P.encode({type:P.MessageType.DIAL_RESPONSE,dialResponse:{status:P.ResponseStatus.E_BAD_REQUEST,statusText:"bad peer id"}});return}if(o.log("incoming request from %p",h),!t.connection.remotePeer.equals(h)){o.log("target peer %p did not equal sending peer %p",h,t.connection.remotePeer),yield P.encode({type:P.MessageType.DIAL_RESPONSE,dialResponse:{status:P.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}});return}let m=u.addrs.map(d=>ms(d)).filter(d=>{let g=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,g),g}).filter(d=>{let g=d.toOptions().host,y=!(gi(g)??!1);return o.log.trace("host %s was public %s",g,y),y}).filter(d=>{let g=d.toOptions().host,y=!s.includes(g);return o.log.trace("host %s was not our host %s",g,y),y}).filter(d=>{let g=!!o.components.transportManager.transportForMultiaddr(d);return o.log.trace("transport for %a is supported %s",d,g),g}).map(d=>(d.getPeerId()==null&&(d=d.encapsulate(`/p2p/${h.toString()}`)),d));if(m.length===0){o.log("no valid multiaddrs for %p in message",h),yield P.encode({type:P.MessageType.DIAL_RESPONSE,dialResponse:{status:P.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}});return}o.log("dial multiaddrs %s for peer %p",m.map(d=>d.toString()).join(", "),h);let f="",p=m[0];for await(let d of m){let g;p=d;try{if(g=await o.components.connectionManager.openConnection(d,{signal:e}),!g.remoteAddr.equals(d))throw o.log.error("tried to dial %a but dialed %a",d,g.remoteAddr),new Error("Unexpected remote address");o.log("Success %p",h),yield P.encode({type:P.MessageType.DIAL_RESPONSE,dialResponse:{status:P.ResponseStatus.OK,addr:g.remoteAddr.decapsulateCode(W("p2p").code).bytes}});return}catch(y){o.log("could not dial %p",h,y),f=y.message}finally{g!=null&&await g.close()}}yield P.encode({type:P.MessageType.DIAL_RESPONSE,dialResponse:{status:P.ResponseStatus.E_DIAL_ERROR,statusText:f,addr:p.bytes}})},i=>Xr(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!(gi(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);Rs(1/0,n);let s=this;try{this.log("verify multiaddrs %s",e.map(u=>u.toString()).join(", "));let o=P.encode({type:P.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toBytes(),addrs:e.map(u=>u.bytes)}}}),a=(await Fc()).toBytes(),c={},l=[],h=async u=>{let m=()=>{};try{this.log("asking %p to verify multiaddr",u.id);let f=await s.components.connectionManager.openConnection(u.id,{signal:n}),p=await f.newStream(this.protocol,{signal:n});m=()=>{p.abort(new C("verifyAddress timeout",ks))},n.addEventListener("abort",m,{once:!0});let d=await di([o],y=>Xr(y),p,y=>Ir(y),async y=>ci(y));if(d==null){this.log("no response received from %p",f.remotePeer);return}let g=P.decode(d);if(g.type!==P.MessageType.DIAL_RESPONSE||g.dialResponse==null){this.log("invalid autonat response from %p",f.remotePeer);return}if(g.dialResponse.status===P.ResponseStatus.OK){let y=f.remoteAddr.toOptions(),b;if(y.family===4)b=y.host.split(".")[0];else if(y.family===6)b=y.host.split(":")[0];else{this.log('remote address "%s" was not IP4 or IP6?',y.host);return}if(l.includes(b)){this.log("already have response from network segment %d - %s",b,y.host);return}l.push(b)}return g.dialResponse}catch(f){this.log.error("error asking remote to verify multiaddr",f)}finally{n.removeEventListener("abort",m)}};for await(let u of ui(ll(this.components.peerRouting.getClosestPeers(a,{signal:n}),m=>async()=>h(m)),{concurrency:mi}))try{if(u==null)continue;let m=u.addr==null?e[0]:ms(u.addr);if(this.log("autonat response for %a is %s",m,u.status),u.status===P.ResponseStatus.E_BAD_REQUEST||u.status===P.ResponseStatus.E_DIAL_REFUSED||u.addr==null&&e.length>1)continue;if(!e.some(p=>p.equals(m))){this.log("peer reported %a as %s but it was not in our observed address list",m,u.status);continue}let f=m.toString();if(c[f]==null&&(c[f]={success:0,failure:0}),u.status===P.ResponseStatus.OK?c[f].success++:u.status===P.ResponseStatus.E_DIAL_ERROR&&c[f].failure++,c[f].success===mi){this.log("%a is externally dialable",m),t.confirmObservedAddr(m);return}if(c[f].failure===mi){this.log("%a is not externally dialable",m),t.removeObservedAddr(m);return}}catch(m){this.log.error("could not verify external address",m)}}finally{this.verifyAddressTimeout=setTimeout(this._verifyExternalAddresses,this.refreshInterval)}}};function s0(r={}){return t=>new Is(t,r)}return Vl(o0);})();
19
19
  /*! Bundled license information:
20
20
 
21
21
  pvtsutils/build/index.js:
@@ -0,0 +1,8 @@
1
+ {
2
+ "AutoNATComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_autonat.AutoNATComponents.html",
3
+ ".:AutoNATComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_autonat.AutoNATComponents.html",
4
+ "AutoNATServiceInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_autonat.AutoNATServiceInit.html",
5
+ ".:AutoNATServiceInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_autonat.AutoNATServiceInit.html",
6
+ "autoNAT": "https://libp2p.github.io/js-libp2p/functions/_libp2p_autonat.autoNAT.html",
7
+ ".:autoNAT": "https://libp2p.github.io/js-libp2p/functions/_libp2p_autonat.autoNAT.html"
8
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/autonat",
3
- "version": "1.0.8-8bbd43628",
3
+ "version": "1.0.9",
4
4
  "description": "Implementation of Autonat Protocol",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/protocol-autonat#readme",
@@ -51,10 +51,10 @@
51
51
  "dep-check": "aegir dep-check"
52
52
  },
53
53
  "dependencies": {
54
- "@libp2p/interface": "1.1.1-8bbd43628",
55
- "@libp2p/interface-internal": "1.0.6-8bbd43628",
56
- "@libp2p/peer-id": "4.0.4-8bbd43628",
57
- "@libp2p/peer-id-factory": "4.0.4-8bbd43628",
54
+ "@libp2p/interface": "^1.1.2",
55
+ "@libp2p/interface-internal": "^1.0.7",
56
+ "@libp2p/peer-id": "^4.0.5",
57
+ "@libp2p/peer-id-factory": "^4.0.5",
58
58
  "@multiformats/multiaddr": "^12.1.10",
59
59
  "it-first": "^3.0.3",
60
60
  "it-length-prefixed": "^9.0.3",
@@ -66,12 +66,13 @@
66
66
  "uint8arraylist": "^2.4.7"
67
67
  },
68
68
  "devDependencies": {
69
- "@libp2p/logger": "4.0.4-8bbd43628",
69
+ "@libp2p/logger": "^4.0.5",
70
70
  "aegir": "^42.0.0",
71
71
  "it-all": "^3.0.3",
72
72
  "it-pushable": "^3.2.1",
73
73
  "protons": "^7.3.0",
74
74
  "sinon": "^17.0.1",
75
75
  "sinon-ts": "^2.0.0"
76
- }
76
+ },
77
+ "sideEffects": false
77
78
  }