@libp2p/identify 3.0.12 → 3.0.13
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/README.md +1 -1
- package/dist/index.min.js +6 -3
- package/dist/src/identify.d.ts +1 -0
- package/dist/src/identify.d.ts.map +1 -1
- package/dist/src/identify.js +32 -14
- package/dist/src/identify.js.map +1 -1
- package/package.json +16 -16
- package/src/identify.ts +39 -13
- package/LICENSE +0 -4
package/dist/index.min.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PIdentify = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PIdentify=(()=>{var uu=Object.create;var cn=Object.defineProperty;var fu=Object.getOwnPropertyDescriptor;var hu=Object.getOwnPropertyNames;var du=Object.getPrototypeOf,pu=Object.prototype.hasOwnProperty;var Ws=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),St=(r,t)=>{for(var e in t)cn(r,e,{get:t[e],enumerable:!0})},Ji=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of hu(t))!pu.call(r,s)&&s!==e&&cn(r,s,{get:()=>t[s],enumerable:!(n=fu(t,s))||n.enumerable});return r};var js=(r,t,e)=>(e=r!=null?uu(du(r)):{},Ji(t||!r||!r.__esModule?cn(e,"default",{value:r,enumerable:!0}):e,r)),mu=r=>Ji(cn({},"__esModule",{value:!0}),r);var Za=Ws(ur=>{"use strict";var Mh="[object ArrayBuffer]",de=class r{static isArrayBuffer(t){return Object.prototype.toString.call(t)===Mh}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}},si="string",Fh=/^[0-9a-f]+$/i,Hh=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Kh=/^[a-zA-Z0-9-_]+$/,Ln=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=de.toUint8Array(t),n="";for(let o=0;o<e.length;o++)n+=String.fromCharCode(e[o]);return decodeURIComponent(escape(n))}},Vt=class{static toString(t,e=!1){let n=de.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}},Un=class r{static isHex(t){return typeof t===si&&Fh.test(t)}static isBase64(t){return typeof t===si&&Hh.test(t)}static isBase64Url(t){return typeof t===si&&Kh.test(t)}static ToString(t,e="utf8"){let n=de.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 Vt.toString(n,!0);case"utf16":case"utf16be":return Vt.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 Vt.fromString(t,!0);case"utf16":case"utf16be":return Vt.fromString(t);default:throw new Error(`Unknown type of encoding '${e}'`)}}static ToBase64(t){let e=de.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 Ln.fromString(t);case"utf16":case"utf16be":return Vt.fromString(t);case"utf16le":case"usc2":return Vt.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 Ln.toString(t);case"utf16":case"utf16be":return Vt.toString(t);case"utf16le":case"usc2":return Vt.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=de.toUint8Array(t),n="";for(let s=0;s<e.length;s++)n+=String.fromCharCode(e[s]);return n}static ToHex(t){let e=de.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 Vt.toString(t,e)}static FromUtf16String(t,e=!1){return Vt.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,"")||""}};Un.DEFAULT_UTF8_ENCODING="utf8";function $h(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 qh(...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 zh(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}ur.BufferSourceConverter=de;ur.Convert=Un;ur.assign=$h;ur.combine=qh;ur.isEqual=zh});var Vl=Ws((hx,Ol)=>{function Pd(){return!!(typeof window<"u"&&typeof window.process=="object"&&window.process.type==="renderer"||typeof process<"u"&&typeof process.versions=="object"&&process.versions.electron||typeof navigator=="object"&&typeof navigator.userAgent=="string"&&navigator.userAgent.indexOf("Electron")>=0)}Ol.exports=Pd});var Gl=Ws(nn=>{(function(){var r,t,e,n,s,o,i,a;a=function(c){var l,u,f,h;return l=(c&255<<24)>>>24,u=(c&255<<16)>>>16,f=(c&65280)>>>8,h=c&255,[l,u,f,h].join(".")},i=function(c){var l,u,f,h,g,m;for(l=[],f=h=0;h<=3&&c.length!==0;f=++h){if(f>0){if(c[0]!==".")throw new Error("Invalid IP");c=c.substring(1)}m=t(c),g=m[0],u=m[1],c=c.substring(u),l.push(g)}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,u,f,h,g;for(h=0,l=10,u="9",f=0,c.length>1&&c[f]==="0"&&(c[f+1]==="x"||c[f+1]==="X"?(f+=2,l=16):"0"<=c[f+1]&&c[f+1]<="9"&&(f++,l=8,u="7")),g=f;f<c.length;){if("0"<=c[f]&&c[f]<=u)h=h*l+(e(c[f])-n)>>>0;else if(l===16)if("a"<=c[f]&&c[f]<="f")h=h*l+(10+e(c[f])-o)>>>0;else if("A"<=c[f]&&c[f]<="F")h=h*l+(10+e(c[f])-s)>>>0;else break;else break;if(h>4294967295)throw new Error("too large");f++}if(f===g)throw new Error("empty octet");return[h,f]},r=function(){function c(l,u){var f,h,g,m;if(typeof l!="string")throw new Error("Missing `net' parameter");if(u||(m=l.split("/",2),l=m[0],u=m[1]),u||(u=32),typeof u=="string"&&u.indexOf(".")>-1){try{this.maskLong=i(u)}catch(b){throw f=b,new Error("Invalid mask: "+u)}for(h=g=32;g>=0;h=--g)if(this.maskLong===4294967295<<32-h>>>0){this.bitmask=h;break}}else if(u||u===0)this.bitmask=parseInt(u,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(b){throw f=b,new Error("Invalid net address: "+l)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+u);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 u,f,h;for(h=i(this.first),f=i(this.last),u=0;h<=f;)l(a(h),h,u),u++,h++},c.prototype.toString=function(){return this.base+"/"+this.bitmask},c}(),nn.ip2long=i,nn.long2ip=a,nn.Netmask=r}).call(nn)});var e0={};St(e0,{identify:()=>Qd,identifyPush:()=>t0});var Zs=Symbol.for("@libp2p/peer-id");var It=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Xe=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var ln=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},un=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}},fn=class extends Error{static name="UnsupportedProtocolError";constructor(t="Unsupported protocol error"){super(t),this.name="UnsupportedProtocolError"}},Dt=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var De=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Ir=(r,...t)=>{try{[...t]}catch{}};var hn=Symbol.for("@libp2p/service-capabilities"),i0=Symbol.for("@libp2p/service-dependencies");var to={};St(to,{base58btc:()=>X,base58flickr:()=>vu});var T0=new Uint8Array(0);function Xi(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 oe(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 Qi(r){return new TextEncoder().encode(r)}function ta(r){return new TextDecoder().decode(r)}function gu(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),u=Math.log(256)/Math.log(a);function f(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var b=0,d=0,x=0,B=m.length;x!==B&&m[x]===0;)x++,b++;for(var y=(B-x)*u+1>>>0,S=new Uint8Array(y);x!==B;){for(var U=m[x],L=0,I=y-1;(U!==0||L<d)&&I!==-1;I--,L++)U+=256*S[I]>>>0,S[I]=U%a>>>0,U=U/a>>>0;if(U!==0)throw new Error("Non-zero carry");d=L,x++}for(var k=y-d;k!==y&&S[k]===0;)k++;for(var T=c.repeat(b);k<y;++k)T+=r.charAt(S[k]);return T}function h(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var b=0;if(m[b]!==" "){for(var d=0,x=0;m[b]===c;)d++,b++;for(var B=(m.length-b)*l+1>>>0,y=new Uint8Array(B);m[b];){var S=e[m.charCodeAt(b)];if(S===255)return;for(var U=0,L=B-1;(S!==0||U<x)&&L!==-1;L--,U++)S+=a*y[L]>>>0,y[L]=S%256>>>0,S=S/256>>>0;if(S!==0)throw new Error("Non-zero carry");x=U,b++}if(m[b]!==" "){for(var I=B-x;I!==B&&y[I]===0;)I++;for(var k=new Uint8Array(d+(B-I)),T=d;I!==B;)k[T++]=y[I++];return k}}}function g(m){var b=h(m);if(b)return b;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:h,decode:g}}var yu=gu,bu=yu,ra=bu;var Ys=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")}},Js=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let s=e.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return na(this,t)}},Xs=class{decoders;constructor(t){this.decoders=t}or(t){return na(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 na(r,t){return new Xs({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Qs=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 Ys(t,e,n),this.decoder=new Js(t,e,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Qe({name:r,prefix:t,encode:e,decode:n}){return new Qs(r,t,e,n)}function Ee({name:r,prefix:t,alphabet:e}){let{encode:n,decode:s}=ra(e,r);return Qe({prefix:t,name:r,encode:n,decode:o=>oe(s(o))})}function wu(r,t,e,n){let s={};for(let u=0;u<t.length;++u)s[t[u]]=u;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 u=0;u<o;++u){let f=s[r[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|f,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 xu(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 nt({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return Qe({prefix:t,name:r,encode(s){return xu(s,n,e)},decode(s){return wu(s,n,e,r)}})}var X=Ee({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),vu=Ee({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var eo={};St(eo,{base32:()=>ie,base32hex:()=>Su,base32hexpad:()=>ku,base32hexpadupper:()=>Nu,base32hexupper:()=>Iu,base32pad:()=>Bu,base32padupper:()=>Au,base32upper:()=>Eu,base32z:()=>Cu});var ie=nt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Eu=nt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Bu=nt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Au=nt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Su=nt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Iu=nt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ku=nt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Nu=nt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Cu=nt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ro={};St(ro,{base36:()=>kr,base36upper:()=>Tu});var kr=Ee({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Tu=Ee({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Lu=ia,sa=128,Uu=127,Ru=~Uu,_u=Math.pow(2,31);function ia(r,t,e){t=t||[],e=e||0;for(var n=e;r>=_u;)t[e++]=r&255|sa,r/=128;for(;r&Ru;)t[e++]=r&255|sa,r>>>=7;return t[e]=r|0,ia.bytes=e-n+1,t}var Pu=no,Ou=128,oa=127;function no(r,n){var e=0,n=n||0,s=0,o=n,i,a=r.length;do{if(o>=a)throw no.bytes=0,new RangeError("Could not decode varint");i=r[o++],e+=s<28?(i&oa)<<s:(i&oa)*Math.pow(2,s),s+=7}while(i>=Ou);return no.bytes=o-n,e}var Vu=Math.pow(2,7),Du=Math.pow(2,14),Mu=Math.pow(2,21),Fu=Math.pow(2,28),Hu=Math.pow(2,35),Ku=Math.pow(2,42),$u=Math.pow(2,49),qu=Math.pow(2,56),zu=Math.pow(2,63),Gu=function(r){return r<Vu?1:r<Du?2:r<Mu?3:r<Fu?4:r<Hu?5:r<Ku?6:r<$u?7:r<qu?8:r<zu?9:10},Wu={encode:Lu,decode:Pu,encodingLength:Gu},ju=Wu,Nr=ju;function Cr(r,t=0){return[Nr.decode(r,t),Nr.decode.bytes]}function tr(r,t,e=0){return Nr.encode(r,t,e),t}function er(r){return Nr.encodingLength(r)}function Mt(r,t){let e=t.byteLength,n=er(r),s=n+er(e),o=new Uint8Array(s+e);return tr(r,o,0),tr(e,o,n),o.set(t,s),new rr(r,e,t,o)}function Me(r){let t=oe(r),[e,n]=Cr(t),[s,o]=Cr(t.subarray(n)),i=t.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new rr(e,s,i,t)}function aa(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Xi(r.bytes,e.bytes)}}var rr=class{code;size;digest;bytes;constructor(t,e,n,s){this.code=t,this.size=e,this.digest=n,this.bytes=s}};function ca(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Yu(e,so(r),t??X.encoder);default:return Ju(e,so(r),t??ie.encoder)}}var la=new WeakMap;function so(r){let t=la.get(r);if(t==null){let e=new Map;return la.set(r,e),e}return t}var pt=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!==Xu)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=Mt(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&aa(t.multihash,n.multihash)}toString(t){return ca(this,t)}toJSON(){return{"/":ca(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??ua(n,s,o.bytes))}else if(e[Qu]===!0){let{version:n,multihash:s,code:o}=e,i=Me(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=ua(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=oe(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 rr(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[f,h]=Cr(t.subarray(e));return e+=h,f},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,u=l-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:u,size:l}}static parse(t,e){let[n,s]=Zu(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 so(o).set(n,t),o}};function Zu(r,t){switch(r[0]){case"Q":{let e=t??X;return[X.prefix,e.decode(`${X.prefix}${r}`)]}case X.prefix:{let e=t??X;return[X.prefix,e.decode(r)]}case ie.prefix:{let e=t??ie;return[ie.prefix,e.decode(r)]}case kr.prefix:{let e=t??kr;return[kr.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Yu(r,t,e){let{prefix:n}=e;if(n!==X.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 Tr=112,Xu=18;function ua(r,t,e){let n=er(r),s=n+er(t),o=new Uint8Array(s+e.byteLength);return tr(r,o,0),tr(t,o,n),o.set(e,s),o}var Qu=Symbol.for("@ipld/js-cid/CID");var oo={};St(oo,{identity:()=>ae});var fa=0,tf="identity",ha=oe;function ef(r){return Mt(fa,ha(r))}var ae={code:fa,name:tf,encode:ha,digest:ef};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}function da(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function rf(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function nr(r,...t){if(!rf(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${r.length}`)}function pa(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");da(r.outputLen),da(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 ma(r,t){nr(r);let e=t.outputLen;if(r.length<e)throw new Error(`digestInto() expects output buffer of length at least ${e}`)}var Fe=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var pn=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Ft=(r,t)=>r<<32-t|r>>>t;var Q0=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function ga(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Lr(r){return typeof r=="string"&&(r=ga(r)),nr(r),r}function io(...r){let t=0;for(let n=0;n<r.length;n++){let s=r[n];nr(s),t+=s.length}let e=new Uint8Array(t);for(let n=0,s=0;n<r.length;n++){let o=r[n];e.set(o,s),s+=o.length}return e}var or=class{clone(){return this._cloneInto()}},tp={}.toString;function mn(r){let t=n=>r().update(Lr(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function gn(r=32){if(Fe&&typeof Fe.getRandomValues=="function")return Fe.getRandomValues(new Uint8Array(r));if(Fe&&typeof Fe.randomBytes=="function")return Fe.randomBytes(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 ya=(r,t,e)=>r&t^~r&e,ba=(r,t,e)=>r&t^r&e^t&e,ir=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=pn(this.buffer)}update(t){sr(this);let{view:e,buffer:n,blockLen:s}=this;t=Lr(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=pn(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),ma(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 f=i;f<s;f++)e[f]=0;nf(n,s-8,BigInt(this.length*8),o),this.process(n,0);let a=pn(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=c/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<l;f++)a.setUint32(4*f,u[f],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 yn=BigInt(4294967295),ao=BigInt(32);function wa(r,t=!1){return t?{h:Number(r&yn),l:Number(r>>ao&yn)}:{h:Number(r>>ao&yn)|0,l:Number(r&yn)|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}=wa(r[s],t);[e[s],n[s]]=[o,i]}return[e,n]}var of=(r,t)=>BigInt(r>>>0)<<ao|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,mf=(r,t,e)=>r<<e|t>>>32-e,gf=(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),Bf=(r,t,e,n,s)=>t+e+n+s+(r/2**32|0)|0,Af=(r,t,e,n,s)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(s>>>0),Sf=(r,t,e,n,s,o)=>t+e+n+s+o+(r/2**32|0)|0;var If={fromBig:wa,split:sf,toBig:of,shrSH:af,shrSL:cf,rotrSH:lf,rotrSL:uf,rotrBH:ff,rotrBL:hf,rotr32H:df,rotr32L:pf,rotlSH:mf,rotlSL:gf,rotlBH:yf,rotlBL:bf,add:wf,add3L:xf,add3H:vf,add4L:Ef,add4H:Bf,add5H:Sf,add5L:Af},P=If;var[kf,Nf]=P.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),Se=new Uint32Array(80),co=class extends ir{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:u,Fh:f,Fl:h,Gh:g,Gl:m,Hh:b,Hl:d}=this;return[t,e,n,s,o,i,a,c,l,u,f,h,g,m,b,d]}set(t,e,n,s,o,i,a,c,l,u,f,h,g,m,b,d){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=u|0,this.Fh=f|0,this.Fl=h|0,this.Gh=g|0,this.Gl=m|0,this.Hh=b|0,this.Hl=d|0}process(t,e){for(let y=0;y<16;y++,e+=4)Ae[y]=t.getUint32(e),Se[y]=t.getUint32(e+=4);for(let y=16;y<80;y++){let S=Ae[y-15]|0,U=Se[y-15]|0,L=P.rotrSH(S,U,1)^P.rotrSH(S,U,8)^P.shrSH(S,U,7),I=P.rotrSL(S,U,1)^P.rotrSL(S,U,8)^P.shrSL(S,U,7),k=Ae[y-2]|0,T=Se[y-2]|0,ot=P.rotrSH(k,T,19)^P.rotrBH(k,T,61)^P.shrSH(k,T,6),$=P.rotrSL(k,T,19)^P.rotrBL(k,T,61)^P.shrSL(k,T,6),O=P.add4L(I,$,Se[y-7],Se[y-16]),it=P.add4H(O,L,ot,Ae[y-7],Ae[y-16]);Ae[y]=it|0,Se[y]=O|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:l,Dl:u,Eh:f,El:h,Fh:g,Fl:m,Gh:b,Gl:d,Hh:x,Hl:B}=this;for(let y=0;y<80;y++){let S=P.rotrSH(f,h,14)^P.rotrSH(f,h,18)^P.rotrBH(f,h,41),U=P.rotrSL(f,h,14)^P.rotrSL(f,h,18)^P.rotrBL(f,h,41),L=f&g^~f&b,I=h&m^~h&d,k=P.add5L(B,U,I,Nf[y],Se[y]),T=P.add5H(k,x,S,L,kf[y],Ae[y]),ot=k|0,$=P.rotrSH(n,s,28)^P.rotrBH(n,s,34)^P.rotrBH(n,s,39),O=P.rotrSL(n,s,28)^P.rotrBL(n,s,34)^P.rotrBL(n,s,39),it=n&o^n&a^o&a,E=s&i^s&c^i&c;x=b|0,B=d|0,b=g|0,d=m|0,g=f|0,m=h|0,{h:f,l:h}=P.add(l|0,u|0,T|0,ot|0),l=a|0,u=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let N=P.add3L(ot,O,E);n=P.add3H(N,T,$,it),s=N|0}({h:n,l:s}=P.add(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=P.add(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=P.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:u}=P.add(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:h}=P.add(this.Eh|0,this.El|0,f|0,h|0),{h:g,l:m}=P.add(this.Fh|0,this.Fl|0,g|0,m|0),{h:b,l:d}=P.add(this.Gh|0,this.Gl|0,b|0,d|0),{h:x,l:B}=P.add(this.Hh|0,this.Hl|0,x|0,B|0),this.set(n,s,o,i,a,c,l,u,f,h,g,m,b,d,x,B)}roundClean(){Ae.fill(0),Se.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 xa=mn(()=>new co);var wn={};St(wn,{aInRange:()=>Ct,abool:()=>Ht,abytes:()=>ar,bitGet:()=>_f,bitLen:()=>po,bitMask:()=>Rr,bitSet:()=>Pf,bytesToHex:()=>le,bytesToNumberBE:()=>ue,bytesToNumberLE:()=>ke,concatBytes:()=>fe,createHmacDrbg:()=>mo,ensureBytes:()=>st,equalBytes:()=>Uf,hexToBytes:()=>Ke,hexToNumber:()=>ho,inRange:()=>Ur,isBytes:()=>Ie,memoized:()=>qe,notImplemented:()=>Vf,numberToBytesBE:()=>Ne,numberToBytesLE:()=>$e,numberToHexUnpadded:()=>He,numberToVarBytesBE:()=>Lf,utf8ToBytes:()=>Rf,validateObject:()=>Jt});var fo=BigInt(0),bn=BigInt(1),Cf=BigInt(2);function Ie(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function ar(r){if(!Ie(r))throw new Error("Uint8Array expected")}function Ht(r,t){if(typeof t!="boolean")throw new Error(`${r} must be valid boolean, got "${t}".`)}var Tf=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function le(r){ar(r);let t="";for(let e=0;e<r.length;e++)t+=Tf[r[e]];return t}function He(r){let t=r.toString(16);return t.length&1?`0${t}`:t}function ho(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var ce={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function va(r){if(r>=ce._0&&r<=ce._9)return r-ce._0;if(r>=ce._A&&r<=ce._F)return r-(ce._A-10);if(r>=ce._a&&r<=ce._f)return r-(ce._a-10)}function Ke(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=va(r.charCodeAt(o)),a=va(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 ue(r){return ho(le(r))}function ke(r){return ar(r),ho(le(Uint8Array.from(r).reverse()))}function Ne(r,t){return Ke(r.toString(16).padStart(t*2,"0"))}function $e(r,t){return Ne(r,t).reverse()}function Lf(r){return Ke(He(r))}function st(r,t,e){let n;if(typeof t=="string")try{n=Ke(t)}catch(o){throw new Error(`${r} must be valid hex string, got "${t}". Cause: ${o}`)}else if(Ie(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 fe(...r){let t=0;for(let n=0;n<r.length;n++){let s=r[n];ar(s),t+=s.length}let e=new Uint8Array(t);for(let n=0,s=0;n<r.length;n++){let o=r[n];e.set(o,s),s+=o.length}return e}function Uf(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 Rf(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}var lo=r=>typeof r=="bigint"&&fo<=r;function Ur(r,t,e){return lo(r)&&lo(t)&&lo(e)&&t<=r&&r<e}function Ct(r,t,e,n){if(!Ur(t,e,n))throw new Error(`expected valid ${r}: ${e} <= n < ${n}, got ${typeof t} ${t}`)}function po(r){let t;for(t=0;r>fo;r>>=bn,t+=1);return t}function _f(r,t){return r>>BigInt(t)&bn}function Pf(r,t,e){return r|(e?bn:fo)<<BigInt(t)}var Rr=r=>(Cf<<BigInt(r-1))-bn,uo=r=>new Uint8Array(r),Ea=r=>Uint8Array.from(r);function mo(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=uo(r),s=uo(r),o=0,i=()=>{n.fill(1),s.fill(0),o=0},a=(...f)=>e(s,n,...f),c=(f=uo())=>{s=a(Ea([0]),f),n=a(),f.length!==0&&(s=a(Ea([1]),f),n=a())},l=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,h=[];for(;f<t;){n=a();let g=n.slice();h.push(g),f+=n.length}return fe(...h)};return(f,h)=>{i(),c(f);let g;for(;!(g=h(l()));)c();return i(),g}}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"||Ie(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 Jt(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 Vf=()=>{throw new Error("not implemented")};function qe(r){let t=new WeakMap;return(e,...n)=>{let s=t.get(e);if(s!==void 0)return s;let o=r(e,...n);return t.set(e,o),o}}var ct=BigInt(0),Q=BigInt(1),ze=BigInt(2),Df=BigInt(3),go=BigInt(4),Ba=BigInt(5),Aa=BigInt(8),Mf=BigInt(9),Ff=BigInt(16);function Z(r,t){let e=r%t;return e>=ct?e:t+e}function Hf(r,t,e){if(e<=ct||t<ct)throw new Error("Expected power/modulo > 0");if(e===Q)return ct;let n=Q;for(;t>ct;)t&Q&&(n=n*r%e),r=r*r%e,t>>=Q;return n}function tt(r,t,e){let n=r;for(;t-- >ct;)n*=n,n%=e;return n}function xn(r,t){if(r===ct||t<=ct)throw new Error(`invert: expected positive integers, got n=${r} mod=${t}`);let e=Z(r,t),n=t,s=ct,o=Q,i=Q,a=ct;for(;e!==ct;){let l=n/e,u=n%e,f=s-i*l,h=o-a*l;n=e,e=u,s=i,o=a,i=f,a=h}if(n!==Q)throw new Error("invert: does not exist");return Z(s,t)}function Kf(r){let t=(r-Q)/ze,e,n,s;for(e=r-Q,n=0;e%ze===ct;e/=ze,n++);for(s=ze;s<r&&Hf(s,t,r)!==r-Q;s++);if(n===1){let i=(r+Q)/go;return function(c,l){let u=c.pow(l,i);if(!c.eql(c.sqr(u),l))throw new Error("Cannot find square root");return u}}let o=(e+Q)/ze;return function(a,c){if(a.pow(c,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let l=n,u=a.pow(a.mul(a.ONE,s),e),f=a.pow(c,o),h=a.pow(c,e);for(;!a.eql(h,a.ONE);){if(a.eql(h,a.ZERO))return a.ZERO;let g=1;for(let b=a.sqr(h);g<l&&!a.eql(b,a.ONE);g++)b=a.sqr(b);let m=a.pow(u,Q<<BigInt(l-g-1));u=a.sqr(m),f=a.mul(f,m),h=a.mul(h,u),l=g}return f}}function $f(r){if(r%go===Df){let t=(r+Q)/go;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%Aa===Ba){let t=(r-Ba)/Aa;return function(n,s){let o=n.mul(s,ze),i=n.pow(o,t),a=n.mul(s,i),c=n.mul(n.mul(a,ze),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%Ff,Kf(r)}var Sa=(r,t)=>(Z(r,t)&Q)===Q,qf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function yo(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=qf.reduce((n,s)=>(n[s]="function",n),t);return Jt(r,e)}function zf(r,t,e){if(e<ct)throw new Error("Expected power > 0");if(e===ct)return r.ONE;if(e===Q)return t;let n=r.ONE,s=t;for(;e>ct;)e&Q&&(n=r.mul(n,s)),s=r.sqr(s),e>>=Q;return n}function Gf(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 bo(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Ce(r,t,e=!1,n={}){if(r<=ct)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:s,nByteLength:o}=bo(r,t);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let i=$f(r),a=Object.freeze({ORDER:r,BITS:s,BYTES:o,MASK:Rr(s),ZERO:ct,ONE:Q,create:c=>Z(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return ct<=c&&c<r},is0:c=>c===ct,isOdd:c=>(c&Q)===Q,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)=>zf(a,c,l),div:(c,l)=>Z(c*xn(l,r),r),sqrN:c=>c*c,addN:(c,l)=>c+l,subN:(c,l)=>c-l,mulN:(c,l)=>c*l,inv:c=>xn(c,r),sqrt:n.sqrt||(c=>i(a,c)),invertBatch:c=>Gf(a,c),cmov:(c,l,u)=>u?l:c,toBytes:c=>e?$e(c,o):Ne(c,o),fromBytes:c=>{if(c.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);return e?ke(c):ue(c)}});return Object.freeze(a)}function Ia(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 wo(r){let t=Ia(r);return t+Math.ceil(t/2)}function ka(r,t,e=!1){let n=r.length,s=Ia(t),o=wo(t);if(n<16||n<o||n>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${n}`);let i=e?ue(r):ke(r),a=Z(i,t-Q)+Q;return e?$e(a,s):Ne(a,s)}var jf=BigInt(0),xo=BigInt(1),vo=new WeakMap,Na=new WeakMap;function vn(r,t){let e=(o,i)=>{let a=i.negate();return o?a:i},n=o=>{if(!Number.isSafeInteger(o)||o<=0||o>t)throw new Error(`Wrong window size=${o}, should be [1..${t}]`)},s=o=>{n(o);let i=Math.ceil(t/o)+1,a=2**(o-1);return{windows:i,windowSize:a}};return{constTimeNegate:e,unsafeLadder(o,i){let a=r.ZERO,c=o;for(;i>jf;)i&xo&&(a=a.add(c)),c=c.double(),i>>=xo;return a},precomputeWindow(o,i){let{windows:a,windowSize:c}=s(i),l=[],u=o,f=u;for(let h=0;h<a;h++){f=u,l.push(f);for(let g=1;g<c;g++)f=f.add(u),l.push(f);u=f.double()}return l},wNAF(o,i,a){let{windows:c,windowSize:l}=s(o),u=r.ZERO,f=r.BASE,h=BigInt(2**o-1),g=2**o,m=BigInt(o);for(let b=0;b<c;b++){let d=b*l,x=Number(a&h);a>>=m,x>l&&(x-=g,a+=xo);let B=d,y=d+Math.abs(x)-1,S=b%2!==0,U=x<0;x===0?f=f.add(e(S,i[B])):u=u.add(e(U,i[y]))}return{p:u,f}},wNAFCached(o,i,a){let c=Na.get(o)||1,l=vo.get(o);return l||(l=this.precomputeWindow(o,c),c!==1&&vo.set(o,a(l))),this.wNAF(c,l,i)},setWindowSize(o,i){n(i),Na.set(o,i),vo.delete(o)}}}function En(r,t,e,n){if(!Array.isArray(e)||!Array.isArray(n)||n.length!==e.length)throw new Error("arrays of points and scalars must have equal length");n.forEach((u,f)=>{if(!t.isValid(u))throw new Error(`wrong scalar at index ${f}`)}),e.forEach((u,f)=>{if(!(u instanceof r))throw new Error(`wrong point at index ${f}`)});let s=po(BigInt(e.length)),o=s>12?s-3:s>4?s-2:s?2:1,i=(1<<o)-1,a=new Array(i+1).fill(r.ZERO),c=Math.floor((t.BITS-1)/o)*o,l=r.ZERO;for(let u=c;u>=0;u-=o){a.fill(r.ZERO);for(let h=0;h<n.length;h++){let g=n[h],m=Number(g>>BigInt(u)&BigInt(i));a[m]=a[m].add(e[h])}let f=r.ZERO;for(let h=a.length-1,g=r.ZERO;h>0;h--)g=g.add(a[h]),f=f.add(g);if(l=l.add(f),u!==0)for(let h=0;h<o;h++)l=l.double()}return l}function _r(r){return yo(r.Fp),Jt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...bo(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Kt=BigInt(0),Tt=BigInt(1),Bn=BigInt(2),Zf=BigInt(8),Yf={zip215:!0};function Jf(r){let t=_r(r);return Jt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Ca(r){let t=Jf(r),{Fp:e,n,prehash:s,hash:o,randomBytes:i,nByteLength:a,h:c}=t,l=Bn<<BigInt(a*8)-Tt,u=e.create,f=Ce(t.n,t.nBitLength),h=t.uvRatio||((w,p)=>{try{return{isValid:!0,value:e.sqrt(w*e.inv(p))}}catch{return{isValid:!1,value:Kt}}}),g=t.adjustScalarBytes||(w=>w),m=t.domain||((w,p,v)=>{if(Ht("phflag",v),p.length||v)throw new Error("Contexts/pre-hash are not supported");return w});function b(w,p){Ct("coordinate "+w,p,Kt,l)}function d(w){if(!(w instanceof y))throw new Error("ExtendedPoint expected")}let x=qe((w,p)=>{let{ex:v,ey:C,ez:R}=w,_=w.is0();p==null&&(p=_?Zf:e.inv(R));let V=u(v*p),F=u(C*p),D=u(R*p);if(_)return{x:Kt,y:Tt};if(D!==Tt)throw new Error("invZ was invalid");return{x:V,y:F}}),B=qe(w=>{let{a:p,d:v}=t;if(w.is0())throw new Error("bad point: ZERO");let{ex:C,ey:R,ez:_,et:V}=w,F=u(C*C),D=u(R*R),j=u(_*_),J=u(j*j),ut=u(F*p),ft=u(j*u(ut+D)),dt=u(J+u(v*u(F*D)));if(ft!==dt)throw new Error("bad point: equation left != right (1)");let At=u(C*R),at=u(_*V);if(At!==at)throw new Error("bad point: equation left != right (2)");return!0});class y{constructor(p,v,C,R){this.ex=p,this.ey=v,this.ez=C,this.et=R,b("x",p),b("y",v),b("z",C),b("t",R),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(p){if(p instanceof y)throw new Error("extended point not allowed");let{x:v,y:C}=p||{};return b("x",v),b("y",C),new y(v,C,Tt,u(v*C))}static normalizeZ(p){let v=e.invertBatch(p.map(C=>C.ez));return p.map((C,R)=>C.toAffine(v[R])).map(y.fromAffine)}static msm(p,v){return En(y,f,p,v)}_setWindowSize(p){L.setWindowSize(this,p)}assertValidity(){B(this)}equals(p){d(p);let{ex:v,ey:C,ez:R}=this,{ex:_,ey:V,ez:F}=p,D=u(v*F),j=u(_*R),J=u(C*F),ut=u(V*R);return D===j&&J===ut}is0(){return this.equals(y.ZERO)}negate(){return new y(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:p}=t,{ex:v,ey:C,ez:R}=this,_=u(v*v),V=u(C*C),F=u(Bn*u(R*R)),D=u(p*_),j=v+C,J=u(u(j*j)-_-V),ut=D+V,ft=ut-F,dt=D-V,At=u(J*ft),at=u(ut*dt),Nt=u(J*dt),se=u(ft*ut);return new y(At,at,se,Nt)}add(p){d(p);let{a:v,d:C}=t,{ex:R,ey:_,ez:V,et:F}=this,{ex:D,ey:j,ez:J,et:ut}=p;if(v===BigInt(-1)){let qi=u((_-R)*(j+D)),zi=u((_+R)*(j-D)),Gs=u(zi-qi);if(Gs===Kt)return this.double();let Gi=u(V*Bn*ut),Wi=u(F*Bn*J),ji=Wi+Gi,Zi=zi+qi,Yi=Wi-Gi,iu=u(ji*Gs),au=u(Zi*Yi),cu=u(ji*Yi),lu=u(Gs*Zi);return new y(iu,au,lu,cu)}let ft=u(R*D),dt=u(_*j),At=u(F*C*ut),at=u(V*J),Nt=u((R+_)*(D+j)-ft-dt),se=at-At,Ar=at+At,Sr=u(dt-v*ft),ru=u(Nt*se),nu=u(Ar*Sr),su=u(Nt*Sr),ou=u(se*Ar);return new y(ru,nu,ou,su)}subtract(p){return this.add(p.negate())}wNAF(p){return L.wNAFCached(this,p,y.normalizeZ)}multiply(p){let v=p;Ct("scalar",v,Tt,n);let{p:C,f:R}=this.wNAF(v);return y.normalizeZ([C,R])[0]}multiplyUnsafe(p){let v=p;return Ct("scalar",v,Kt,n),v===Kt?U:this.equals(U)||v===Tt?this:this.equals(S)?this.wNAF(v).p:L.unsafeLadder(this,v)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return L.unsafeLadder(this,n).is0()}toAffine(p){return x(this,p)}clearCofactor(){let{h:p}=t;return p===Tt?this:this.multiplyUnsafe(p)}static fromHex(p,v=!1){let{d:C,a:R}=t,_=e.BYTES;p=st("pointHex",p,_),Ht("zip215",v);let V=p.slice(),F=p[_-1];V[_-1]=F&-129;let D=ke(V),j=v?l:e.ORDER;Ct("pointHex.y",D,Kt,j);let J=u(D*D),ut=u(J-Tt),ft=u(C*J-R),{isValid:dt,value:At}=h(ut,ft);if(!dt)throw new Error("Point.fromHex: invalid y coordinate");let at=(At&Tt)===Tt,Nt=(F&128)!==0;if(!v&&At===Kt&&Nt)throw new Error("Point.fromHex: x=0 and x_0=1");return Nt!==at&&(At=u(-At)),y.fromAffine({x:At,y:D})}static fromPrivateKey(p){return T(p).point}toRawBytes(){let{x:p,y:v}=this.toAffine(),C=$e(v,e.BYTES);return C[C.length-1]|=p&Tt?128:0,C}toHex(){return le(this.toRawBytes())}}y.BASE=new y(t.Gx,t.Gy,Tt,u(t.Gx*t.Gy)),y.ZERO=new y(Kt,Tt,Tt,Kt);let{BASE:S,ZERO:U}=y,L=vn(y,a*8);function I(w){return Z(w,n)}function k(w){return I(ke(w))}function T(w){let p=a;w=st("private key",w,p);let v=st("hashed private key",o(w),2*p),C=g(v.slice(0,p)),R=v.slice(p,2*p),_=k(C),V=S.multiply(_),F=V.toRawBytes();return{head:C,prefix:R,scalar:_,point:V,pointBytes:F}}function ot(w){return T(w).pointBytes}function $(w=new Uint8Array,...p){let v=fe(...p);return k(o(m(v,st("context",w),!!s)))}function O(w,p,v={}){w=st("message",w),s&&(w=s(w));let{prefix:C,scalar:R,pointBytes:_}=T(p),V=$(v.context,C,w),F=S.multiply(V).toRawBytes(),D=$(v.context,F,_,w),j=I(V+D*R);Ct("signature.s",j,Kt,n);let J=fe(F,$e(j,e.BYTES));return st("result",J,a*2)}let it=Yf;function E(w,p,v,C=it){let{context:R,zip215:_}=C,V=e.BYTES;w=st("signature",w,2*V),p=st("message",p),_!==void 0&&Ht("zip215",_),s&&(p=s(p));let F=ke(w.slice(V,2*V)),D,j,J;try{D=y.fromHex(v,_),j=y.fromHex(w.slice(0,V),_),J=S.multiplyUnsafe(F)}catch{return!1}if(!_&&D.isSmallOrder())return!1;let ut=$(R,j.toRawBytes(),D.toRawBytes(),p);return j.add(D.multiplyUnsafe(ut)).subtract(J).clearCofactor().equals(y.ZERO)}return S._setWindowSize(8),{CURVE:t,getPublicKey:ot,sign:O,verify:E,ExtendedPoint:y,utils:{getExtendedPublicKey:T,randomPrivateKey:()=>i(e.BYTES),precompute(w=8,p=y.BASE){return p._setWindowSize(w),p.multiply(BigInt(3)),p}}}}var Eo=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Ta=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Bp=BigInt(0),Xf=BigInt(1),La=BigInt(2),Ap=BigInt(3),Qf=BigInt(5),th=BigInt(8);function eh(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),s=BigInt(80),o=Eo,a=r*r%o*r%o,c=tt(a,La,o)*a%o,l=tt(c,Xf,o)*r%o,u=tt(l,Qf,o)*l%o,f=tt(u,t,o)*u%o,h=tt(f,e,o)*f%o,g=tt(h,n,o)*h%o,m=tt(g,s,o)*g%o,b=tt(m,s,o)*g%o,d=tt(b,t,o)*u%o;return{pow_p_5_8:tt(d,La,o)*r%o,b2:a}}function rh(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function nh(r,t){let e=Eo,n=Z(t*t*t,e),s=Z(n*n*t,e),o=eh(r*s).pow_p_5_8,i=Z(r*n*o,e),a=Z(t*i*i,e),c=i,l=Z(i*Ta,e),u=a===r,f=a===Z(-r,e),h=a===Z(-r*Ta,e);return u&&(i=c),(f||h)&&(i=l),Sa(i,e)&&(i=Z(-i,e)),{isValid:u||f,value:i}}var sh=Ce(Eo,void 0,!0),oh={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:sh,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:th,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:xa,randomBytes:gn,adjustScalarBytes:rh,uvRatio:nh},Ua=Ca(oh);var An=32;function Ra(r,t,e){return Ua.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var Sn=class{type="Ed25519";raw;constructor(t){this.raw=Bo(t,An)}toMultihash(){return ae.digest(Te(this))}toCID(){return pt.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,e){return Ra(this.raw,e,t)}};function Ao(r){return r=Bo(r,An),new Sn(r)}function Bo(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new It(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}function mt(r=0){return new Uint8Array(r)}function Lt(r=0){return new Uint8Array(r)}var ah=Math.pow(2,7),ch=Math.pow(2,14),lh=Math.pow(2,21),So=Math.pow(2,28),Io=Math.pow(2,35),ko=Math.pow(2,42),No=Math.pow(2,49),W=128,wt=127;function xt(r){if(r<ah)return 1;if(r<ch)return 2;if(r<lh)return 3;if(r<So)return 4;if(r<Io)return 5;if(r<ko)return 6;if(r<No)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Co(r,t,e=0){switch(xt(r)){case 8:t[e++]=r&255|W,r/=128;case 7:t[e++]=r&255|W,r/=128;case 6:t[e++]=r&255|W,r/=128;case 5:t[e++]=r&255|W,r/=128;case 4:t[e++]=r&255|W,r>>>=7;case 3:t[e++]=r&255|W,r>>>=7;case 2:t[e++]=r&255|W,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function uh(r,t,e=0){switch(xt(r)){case 8:t.set(e++,r&255|W),r/=128;case 7:t.set(e++,r&255|W),r/=128;case 6:t.set(e++,r&255|W),r/=128;case 5:t.set(e++,r&255|W),r/=128;case 4:t.set(e++,r&255|W),r>>>=7;case 3:t.set(e++,r&255|W),r>>>=7;case 2:t.set(e++,r&255|W),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function To(r,t){let e=r[t],n=0;if(n+=e&wt,e<W||(e=r[t+1],n+=(e&wt)<<7,e<W)||(e=r[t+2],n+=(e&wt)<<14,e<W)||(e=r[t+3],n+=(e&wt)<<21,e<W)||(e=r[t+4],n+=(e&wt)*So,e<W)||(e=r[t+5],n+=(e&wt)*Io,e<W)||(e=r[t+6],n+=(e&wt)*ko,e<W)||(e=r[t+7],n+=(e&wt)*No,e<W))return n;throw new RangeError("Could not decode varint")}function fh(r,t){let e=r.get(t),n=0;if(n+=e&wt,e<W||(e=r.get(t+1),n+=(e&wt)<<7,e<W)||(e=r.get(t+2),n+=(e&wt)<<14,e<W)||(e=r.get(t+3),n+=(e&wt)<<21,e<W)||(e=r.get(t+4),n+=(e&wt)*So,e<W)||(e=r.get(t+5),n+=(e&wt)*Io,e<W)||(e=r.get(t+6),n+=(e&wt)*ko,e<W)||(e=r.get(t+7),n+=(e&wt)*No,e<W))return n;throw new RangeError("Could not decode varint")}function Ot(r,t,e=0){return t==null&&(t=Lt(xt(r))),t instanceof Uint8Array?Co(r,t,e):uh(r,t,e)}function he(r,t=0){return r instanceof Uint8Array?To(r,t):fh(r,t)}var Lo=new Float32Array([-0]),Le=new Uint8Array(Lo.buffer);function Pa(r,t,e){Lo[0]=r,t[e]=Le[0],t[e+1]=Le[1],t[e+2]=Le[2],t[e+3]=Le[3]}function Oa(r,t){return Le[0]=r[t],Le[1]=r[t+1],Le[2]=r[t+2],Le[3]=r[t+3],Lo[0]}var Uo=new Float64Array([-0]),vt=new Uint8Array(Uo.buffer);function Va(r,t,e){Uo[0]=r,t[e]=vt[0],t[e+1]=vt[1],t[e+2]=vt[2],t[e+3]=vt[3],t[e+4]=vt[4],t[e+5]=vt[5],t[e+6]=vt[6],t[e+7]=vt[7]}function Da(r,t){return vt[0]=r[t],vt[1]=r[t+1],vt[2]=r[t+2],vt[3]=r[t+3],vt[4]=r[t+4],vt[5]=r[t+5],vt[6]=r[t+6],vt[7]=r[t+7],Uo[0]}var hh=BigInt(Number.MAX_SAFE_INTEGER),dh=BigInt(Number.MIN_SAFE_INTEGER),_t=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 Ge;if(t<hh&&t>dh)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>Ma&&(s=0n,++n>Ma&&(n=0n))),new r(Number(s),Number(n))}static fromNumber(t){if(t===0)return Ge;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):Ge}},Ge=new _t(0,0);Ge.toBigInt=function(){return 0n};Ge.zzEncode=Ge.zzDecode=function(){return this};Ge.length=function(){return 1};var Ma=4294967296n;function Fa(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 Ha(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 Ro(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 $t(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function kn(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var _o=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,$t(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 $t(this,4);return kn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw $t(this,4);return kn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw $t(this,4);let t=Oa(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw $t(this,4);let t=Da(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 $t(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Ha(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw $t(this,t);this.pos+=t}else do if(this.pos>=this.len)throw $t(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 _t(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 $t(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 $t(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 $t(this,8);let t=kn(this.buf,this.pos+=4),e=kn(this.buf,this.pos+=4);return new _t(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=To(this.buf,this.pos);return this.pos+=xt(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Po(r){return new _o(r instanceof Uint8Array?r:r.subarray())}function qt(r,t,e){let n=Po(r);return t.decode(n,void 0,e)}var Oo={};St(Oo,{base10:()=>ph});var ph=Ee({prefix:"9",name:"base10",alphabet:"0123456789"});var Vo={};St(Vo,{base16:()=>mh,base16upper:()=>gh});var mh=nt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),gh=nt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Do={};St(Do,{base2:()=>yh});var yh=nt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Mo={};St(Mo,{base256emoji:()=>Eh});var $a=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}"),bh=$a.reduce((r,t,e)=>(r[e]=t,r),[]),wh=$a.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function xh(r){return r.reduce((t,e)=>(t+=bh[e],t),"")}function vh(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let s=wh[n];if(s==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(s)}return new Uint8Array(t)}var Eh=Qe({prefix:"\u{1F680}",name:"base256emoji",encode:xh,decode:vh});var Ho={};St(Ho,{base64:()=>Bh,base64pad:()=>Ah,base64url:()=>Fo,base64urlpad:()=>Sh});var Bh=nt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ah=nt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Fo=nt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Sh=nt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ko={};St(Ko,{base8:()=>Ih});var Ih=nt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var $o={};St($o,{identity:()=>kh});var kh=Qe({prefix:"\0",name:"identity",encode:r=>ta(r),decode:r=>Qi(r)});var im=new TextEncoder,am=new TextDecoder;var Go={};St(Go,{sha256:()=>Pr,sha512:()=>Th});function zo({name:r,code:t,encode:e}){return new qo(r,t,e)}var qo=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?Mt(this.code,e):e.then(n=>Mt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function za(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Pr=zo({name:"sha2-256",code:18,encode:za("SHA-256")}),Th=zo({name:"sha2-512",code:19,encode:za("SHA-512")});var Or={...$o,...Do,...Ko,...Oo,...Vo,...eo,...ro,...to,...Ho,...Mo},wm={...Go,...oo};function Wa(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Ga=Wa("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Wo=Wa("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=Lt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Lh={utf8:Ga,"utf-8":Ga,hex:Or.base16,latin1:Wo,ascii:Wo,binary:Wo,...Or},Nn=Lh;function q(r,t="utf8"){let e=Nn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function jo(r){let t=r??8192,e=t>>>1,n,s=t;return function(i){if(i<1||i>e)return Lt(i);s+i>t&&(n=Lt(t),s=0);let a=n.subarray(s,s+=i);return s&7&&(s=(s|7)+1),a}}var We=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Zo(){}var Jo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Uh=jo();function Rh(r){return globalThis.Buffer!=null?Lt(r):Uh(r)}var Dr=class{len;head;tail;states;constructor(){this.len=0,this.head=new We(Zo,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new We(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Xo((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(Cn,10,_t.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=_t.fromBigInt(t);return this._push(Cn,e.length(),e)}uint64Number(t){return this._push(Co,xt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=_t.fromBigInt(t).zzEncode();return this._push(Cn,e.length(),e)}sint64Number(t){let e=_t.fromNumber(t).zzEncode();return this._push(Cn,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Yo,1,t?1:0)}fixed32(t){return this._push(Vr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=_t.fromBigInt(t);return this._push(Vr,4,e.lo)._push(Vr,4,e.hi)}fixed64Number(t){let e=_t.fromNumber(t);return this._push(Vr,4,e.lo)._push(Vr,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(Pa,4,t)}double(t){return this._push(Va,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Yo,1,0):this.uint32(e)._push(Ph,e,t)}string(t){let e=Fa(t);return e!==0?this.uint32(e)._push(Ro,e,t):this._push(Yo,1,0)}fork(){return this.states=new Jo(this),this.head=this.tail=new We(Zo,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 We(Zo,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=Rh(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Yo(r,t,e){t[e]=r&255}function _h(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Xo=class extends We{next;constructor(t,e){super(_h,t,e),this.next=void 0}};function Cn(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 Vr(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 Ph(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(Oh,t,r),this},Dr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Vh,t,r),this});function Oh(r,t,e){t.set(r,e)}function Vh(r,t,e){r.length<40?Ro(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(q(r),e)}function Qo(){return new Dr}function zt(r,t){let e=Qo();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var cr;(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"})(cr||(cr={}));function Tn(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function ti(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 Tn("enum",cr.VARINT,e,n)}function Gt(r,t){return Tn("message",cr.LENGTH_DELIMITED,r,t)}var je=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var lt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1"})(lt||(lt={}));var ei;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1"})(ei||(ei={}));(function(r){r.codec=()=>ti(ei)})(lt||(lt={}));var Xt;(function(r){let t;r.codec=()=>(t==null&&(t=Gt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),lt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let o={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{o.Type=lt.codec().decode(e);break}case 2:{o.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return o})),t),r.encode=e=>zt(e,r.codec()),r.decode=(e,n)=>qt(e,r.codec(),n)})(Xt||(Xt={}));var ri;(function(r){let t;r.codec=()=>(t==null&&(t=Gt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),lt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let o={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{o.Type=lt.codec().decode(e);break}case 2:{o.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return o})),t),r.encode=e=>zt(e,r.codec()),r.decode=(e,n)=>qt(e,r.codec(),n)})(ri||(ri={}));var jr={};St(jr,{MAX_RSA_KEY_SIZE:()=>vs,generateRSAKeyPair:()=>qc,jwkToJWKKeyPair:()=>zc,jwkToPkcs1:()=>Qh,jwkToPkix:()=>fi,jwkToRSAPrivateKey:()=>$c,pkcs1ToJwk:()=>Fc,pkcs1ToRSAPrivateKey:()=>Kc,pkixToJwk:()=>Hc,pkixToRSAPublicKey:()=>hi});var Dh=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Ue=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Re=new Uint32Array(64),ni=class extends ir{constructor(){super(64,32,8,!1),this.A=Ue[0]|0,this.B=Ue[1]|0,this.C=Ue[2]|0,this.D=Ue[3]|0,this.E=Ue[4]|0,this.F=Ue[5]|0,this.G=Ue[6]|0,this.H=Ue[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 f=0;f<16;f++,e+=4)Re[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let h=Re[f-15],g=Re[f-2],m=Ft(h,7)^Ft(h,18)^h>>>3,b=Ft(g,17)^Ft(g,19)^g>>>10;Re[f]=b+Re[f-7]+m+Re[f-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:l,H:u}=this;for(let f=0;f<64;f++){let h=Ft(a,6)^Ft(a,11)^Ft(a,25),g=u+h+ya(a,c,l)+Dh[f]+Re[f]|0,b=(Ft(n,2)^Ft(n,13)^Ft(n,22))+ba(n,s,o)|0;u=l,l=c,c=a,a=i+g|0,i=o,o=s,s=n,n=g+b|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,u=u+this.H|0,this.set(n,s,o,i,a,c,l,u)}roundClean(){Re.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var lr=mn(()=>new ni);var M=js(Za());function Ze(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 _e(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 u=a-1;u>=0;u--){let f=Math.pow(2,u*t);l[o-u-1]=Math.floor(s/f),s-=l[o-u-1]*f}return c}i*=Math.pow(2,t)}return new ArrayBuffer(0)}function Rn(...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 oi(){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=Ze(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,Ze(o,8)-n}function Ya(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=_e(i,8,n),c=new Uint8Array(a);return c[0]|=128,a}let s=_e(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 Ja(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 Ut(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 tg=Math.log(2);function _n(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function ii(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 ye(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 Fr=class{constructor(){this.items=[]}write(t){this.items.push(t)}final(){return ii(this.items)}},Mr=[new Uint8Array([1])],Xa="0123456789";var pr="",Wt=new ArrayBuffer(0),ai=new Uint8Array(0),Hr="EndOfContent",tc="OCTET STRING",ec="BIT STRING";function be(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?M.BufferSourceConverter.toUint8Array(o.valueHex):ai}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(!ye(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",Wt)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:M.Convert.ToHex(this.valueHexView)}}},t.NAME="hexBlock",t}var pe=class{constructor({blockLength:t=0,error:e=pr,warnings:n=[],valueBeforeDecode:s=ai}={}){this.blockLength=t,this.error=e,this.warnings=n,this.valueBeforeDecodeView=M.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:M.Convert.ToHex(this.valueBeforeDecodeView)}}};pe.NAME="baseBlock";var Et=class extends pe{fromBER(t,e,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(t,e){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}};Et.NAME="valueBlock";var Pn=class extends be(pe){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?M.BufferSourceConverter.toUint8Array(t.valueHex):ai,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",Wt}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=_e(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=M.BufferSourceConverter.toUint8Array(t);if(!ye(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),u=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===u){u+=255;let h=new Uint8Array(u);for(let g=0;g<l.length;g++)h[g]=l[g];l=this.valueHexView=new Uint8Array(u)}}this.blockLength=c+1,l[c-1]=o[c]&127;let f=new Uint8Array(c);for(let h=0;h<c;h++)f[h]=l[h];l=this.valueHexView=new Uint8Array(c),l.set(f),this.blockLength<=9?this.tagNumber=Ze(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}}};Pn.NAME="identificationBlock";var On=class extends pe{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=M.BufferSourceConverter.toUint8Array(t);if(!ye(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=Ze(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=_e(this.length,8);if(s.byteLength>127)return this.error="Too big length",Wt;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}}};On.NAME="lengthBlock";var A={},gt=class extends pe{constructor({name:t=pr,optional:e=!1,primitiveSchema:n,...s}={},o){super(s),this.name=t,this.optional=e,n&&(this.primitiveSchema=n),this.idBlock=new Pn(s),this.lenBlock=new On(s),this.valueBlock=o?new o(s):new Et(s)}fromBER(t,e,n){let s=this.valueBlock.fromBER(t,e,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),s)}toBER(t,e){let n=e||new Fr;e||rc(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?Wt: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():M.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${M.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 Ja(e,n)}};gt.NAME="BaseBlock";function rc(r){if(r instanceof A.Constructed)for(let t of r.valueBlock.value)rc(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var Vn=class extends gt{constructor({value:t=pr,...e}={},n){super(e,n),t&&this.fromString(t)}getValue(){return this.valueBlock.value}setValue(t){this.valueBlock.value=t}fromBER(t,e,n){let s=this.valueBlock.fromBER(t,e,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),s)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};Vn.NAME="BaseStringBlock";var Dn=class extends be(Et){constructor({isHexOnly:t=!0,...e}={}){super(e),this.isHexOnly=t}};Dn.NAME="PrimitiveValueBlock";var nc,Mn=class extends gt{constructor(t={}){super(t,Dn),this.idBlock.isConstructed=!1}};nc=Mn;A.Primitive=nc;Mn.NAME="PRIMITIVE";function Wh(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 ws(r,t=0,e=r.length){let n=t,s=new gt({},Et),o=new pe;if(!ye(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=gt;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=A.EndOfContent;break;case 1:c=A.Boolean;break;case 2:c=A.Integer;break;case 3:c=A.BitString;break;case 4:c=A.OctetString;break;case 5:c=A.Null;break;case 6:c=A.ObjectIdentifier;break;case 10:c=A.Enumerated;break;case 12:c=A.Utf8String;break;case 13:c=A.RelativeObjectIdentifier;break;case 14:c=A.TIME;break;case 15:return s.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:s};case 16:c=A.Sequence;break;case 17:c=A.Set;break;case 18:c=A.NumericString;break;case 19:c=A.PrintableString;break;case 20:c=A.TeletexString;break;case 21:c=A.VideotexString;break;case 22:c=A.IA5String;break;case 23:c=A.UTCTime;break;case 24:c=A.GeneralizedTime;break;case 25:c=A.GraphicString;break;case 26:c=A.VisibleString;break;case 27:c=A.GeneralString;break;case 28:c=A.UniversalString;break;case 29:c=A.CharacterString;break;case 30:c=A.BmpString;break;case 31:c=A.DATE;break;case 32:c=A.TimeOfDay;break;case 33:c=A.DateTime;break;case 34:c=A.Duration;break;default:{let l=s.idBlock.isConstructed?new A.Constructed:new A.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?A.Constructed:A.Primitive}return s=Wh(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 ci(r){if(!r.byteLength){let t=new gt({},Et);return t.error="Input buffer has zero length",{offset:-1,result:t}}return ws(M.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function jh(r,t){return r?1:t}var Qt=class extends Et{constructor({value:t=[],isIndefiniteForm:e=!1,...n}={}){super(n),this.value=t,this.isIndefiniteForm=e}fromBER(t,e,n){let s=M.BufferSourceConverter.toUint8Array(t);if(!ye(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(;jh(this.isIndefiniteForm,n)>0;){let i=ws(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===Hr)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===Hr?this.value.pop():this.warnings.push("No EndOfContent block encoded")),o}toBER(t,e){let n=e||new Fr;for(let s=0;s<this.value.length;s++)this.value[s].toBER(t,n);return e?Wt:n.final()}toJSON(){let t={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let e of this.value)t.value.push(e.toJSON());return t}};Qt.NAME="ConstructedValueBlock";var sc,Pe=class extends gt{constructor(t={}){super(t,Qt),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 Libp2PIdentify=(()=>{var $u=Object.create;var gn=Object.defineProperty;var zu=Object.getOwnPropertyDescriptor;var Gu=Object.getOwnPropertyNames;var Wu=Object.getPrototypeOf,ju=Object.prototype.hasOwnProperty;var ao=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),St=(r,t)=>{for(var e in t)gn(r,e,{get:t[e],enumerable:!0})},ba=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Gu(t))!ju.call(r,s)&&s!==e&&gn(r,s,{get:()=>t[s],enumerable:!(n=zu(t,s))||n.enumerable});return r};var co=(r,t,e)=>(e=r!=null?$u(Wu(r)):{},ba(t||!r||!r.__esModule?gn(e,"default",{value:r,enumerable:!0}):e,r)),Zu=r=>ba(gn({},"__esModule",{value:!0}),r);var vc=ao(mr=>{"use strict";var Bd="[object ArrayBuffer]",ge=class r{static isArrayBuffer(t){return Object.prototype.toString.call(t)===Bd}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}},Ei="string",Ad=/^[0-9a-f\s]+$/i,Sd=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Id=/^[a-zA-Z0-9-_]+$/,$n=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=ge.toUint8Array(t),n="";for(let o=0;o<e.length;o++)n+=String.fromCharCode(e[o]);return decodeURIComponent(escape(n))}},Vt=class{static toString(t,e=!1){let n=ge.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}},zn=class r{static isHex(t){return typeof t===Ei&&Ad.test(t)}static isBase64(t){return typeof t===Ei&&Sd.test(t)}static isBase64Url(t){return typeof t===Ei&&Id.test(t)}static ToString(t,e="utf8"){let n=ge.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 Vt.toString(n,!0);case"utf16":case"utf16be":return Vt.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 Vt.fromString(t,!0);case"utf16":case"utf16be":return Vt.fromString(t);default:throw new Error(`Unknown type of encoding '${e}'`)}}static ToBase64(t){let e=ge.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 $n.fromString(t);case"utf16":case"utf16be":return Vt.fromString(t);case"utf16le":case"usc2":return Vt.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 $n.toString(t);case"utf16":case"utf16be":return Vt.toString(t);case"utf16le":case"usc2":return Vt.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=ge.toUint8Array(t),n="";for(let s=0;s<e.length;s++)n+=String.fromCharCode(e[s]);return n}static ToHex(t){let e=ge.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 Vt.toString(t,e)}static FromUtf16String(t,e=!1){return Vt.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,"")||""}};zn.DEFAULT_UTF8_ENCODING="utf8";function kd(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 Cd(...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 Nd(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}mr.BufferSourceConverter=ge;mr.Convert=zn;mr.assign=kd;mr.combine=Cd;mr.isEqual=Nd});var pu=ao((r1,du)=>{function b0(){return!!(typeof window<"u"&&typeof window.process=="object"&&window.process.type==="renderer"||typeof process<"u"&&typeof process.versions=="object"&&process.versions.electron||typeof navigator=="object"&&typeof navigator.userAgent=="string"&&navigator.userAgent.indexOf("Electron")>=0)}du.exports=b0});var Au=ao(fn=>{(function(){var r,t,e,n,s,o,i,a;a=function(c){var l,u,f,h;return l=(c&255<<24)>>>24,u=(c&255<<16)>>>16,f=(c&65280)>>>8,h=c&255,[l,u,f,h].join(".")},i=function(c){var l,u,f,h,d,p;for(l=[],f=h=0;h<=3&&c.length!==0;f=++h){if(f>0){if(c[0]!==".")throw new Error("Invalid IP");c=c.substring(1)}p=t(c),d=p[0],u=p[1],c=c.substring(u),l.push(d)}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,u,f,h,d;for(h=0,l=10,u="9",f=0,c.length>1&&c[f]==="0"&&(c[f+1]==="x"||c[f+1]==="X"?(f+=2,l=16):"0"<=c[f+1]&&c[f+1]<="9"&&(f++,l=8,u="7")),d=f;f<c.length;){if("0"<=c[f]&&c[f]<=u)h=h*l+(e(c[f])-n)>>>0;else if(l===16)if("a"<=c[f]&&c[f]<="f")h=h*l+(10+e(c[f])-o)>>>0;else if("A"<=c[f]&&c[f]<="F")h=h*l+(10+e(c[f])-s)>>>0;else break;else break;if(h>4294967295)throw new Error("too large");f++}if(f===d)throw new Error("empty octet");return[h,f]},r=function(){function c(l,u){var f,h,d,p;if(typeof l!="string")throw new Error("Missing `net' parameter");if(u||(p=l.split("/",2),l=p[0],u=p[1]),u||(u=32),typeof u=="string"&&u.indexOf(".")>-1){try{this.maskLong=i(u)}catch(b){throw f=b,new Error("Invalid mask: "+u)}for(h=d=32;d>=0;h=--d)if(this.maskLong===4294967295<<32-h>>>0){this.bitmask=h;break}}else if(u||u===0)this.bitmask=parseInt(u,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(b){throw f=b,new Error("Invalid net address: "+l)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+u);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 u,f,h;for(h=i(this.first),f=i(this.last),u=0;h<=f;)l(a(h),h,u),u++,h++},c.prototype.toString=function(){return this.base+"/"+this.bitmask},c}(),fn.ip2long=i,fn.long2ip=a,fn.Netmask=r}).call(fn)});var z0={};St(z0,{identify:()=>q0,identifyPush:()=>$0});var lo=Symbol.for("@libp2p/peer-id");var It=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},or=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var mn=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},bn=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}},yn=class extends Error{static name="UnsupportedProtocolError";constructor(t="Unsupported protocol error"){super(t),this.name="UnsupportedProtocolError"}},Dt=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var Ke=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Ur=(r,...t)=>{try{[...t]}catch{}};var wn=Symbol.for("@libp2p/service-capabilities"),Y0=Symbol.for("@libp2p/service-dependencies");var go={};St(go,{base58btc:()=>X,base58flickr:()=>ef});var xp=new Uint8Array(0);function ya(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 ae(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 wa(r){return new TextEncoder().encode(r)}function xa(r){return new TextDecoder().decode(r)}function Yu(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),u=Math.log(256)/Math.log(a);function f(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 b=0,g=0,v=0,A=p.length;v!==A&&p[v]===0;)v++,b++;for(var y=(A-v)*u+1>>>0,I=new Uint8Array(y);v!==A;){for(var U=p[v],L=0,k=y-1;(U!==0||L<g)&&k!==-1;k--,L++)U+=256*I[k]>>>0,I[k]=U%a>>>0,U=U/a>>>0;if(U!==0)throw new Error("Non-zero carry");g=L,v++}for(var T=y-g;T!==y&&I[T]===0;)T++;for(var C=c.repeat(b);T<y;++T)C+=r.charAt(I[T]);return C}function h(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var b=0;if(p[b]!==" "){for(var g=0,v=0;p[b]===c;)g++,b++;for(var A=(p.length-b)*l+1>>>0,y=new Uint8Array(A);p[b];){var I=e[p.charCodeAt(b)];if(I===255)return;for(var U=0,L=A-1;(I!==0||U<v)&&L!==-1;L--,U++)I+=a*y[L]>>>0,y[L]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");v=U,b++}if(p[b]!==" "){for(var k=A-v;k!==A&&y[k]===0;)k++;for(var T=new Uint8Array(g+(A-k)),C=g;k!==A;)T[C++]=y[k++];return T}}}function d(p){var b=h(p);if(b)return b;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:h,decode:d}}var Ju=Yu,Xu=Ju,Ea=Xu;var uo=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")}},fo=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let s=e.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Ba(this,t)}},ho=class{decoders;constructor(t){this.decoders=t}or(t){return Ba(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 Ba(r,t){return new ho({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var po=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 uo(t,e,n),this.decoder=new fo(t,e,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ir({name:r,prefix:t,encode:e,decode:n}){return new po(r,t,e,n)}function Ae({name:r,prefix:t,alphabet:e}){let{encode:n,decode:s}=Ea(e,r);return ir({prefix:t,name:r,encode:n,decode:o=>ae(s(o))})}function Qu(r,t,e,n){let s={};for(let u=0;u<t.length;++u)s[t[u]]=u;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 u=0;u<o;++u){let f=s[r[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|f,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 tf(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 ot({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return ir({prefix:t,name:r,encode(s){return tf(s,n,e)},decode(s){return Qu(s,n,e,r)}})}var X=Ae({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ef=Ae({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var mo={};St(mo,{base32:()=>ce,base32hex:()=>of,base32hexpad:()=>cf,base32hexpadupper:()=>lf,base32hexupper:()=>af,base32pad:()=>nf,base32padupper:()=>sf,base32upper:()=>rf,base32z:()=>uf});var ce=ot({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),rf=ot({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),nf=ot({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),sf=ot({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),of=ot({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),af=ot({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),cf=ot({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),lf=ot({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),uf=ot({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var bo={};St(bo,{base36:()=>Rr,base36upper:()=>ff});var Rr=Ae({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ff=Ae({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var hf=Ia,Aa=128,df=127,pf=~df,gf=Math.pow(2,31);function Ia(r,t,e){t=t||[],e=e||0;for(var n=e;r>=gf;)t[e++]=r&255|Aa,r/=128;for(;r&pf;)t[e++]=r&255|Aa,r>>>=7;return t[e]=r|0,Ia.bytes=e-n+1,t}var mf=yo,bf=128,Sa=127;function yo(r,n){var e=0,n=n||0,s=0,o=n,i,a=r.length;do{if(o>=a)throw yo.bytes=0,new RangeError("Could not decode varint");i=r[o++],e+=s<28?(i&Sa)<<s:(i&Sa)*Math.pow(2,s),s+=7}while(i>=bf);return yo.bytes=o-n,e}var yf=Math.pow(2,7),wf=Math.pow(2,14),xf=Math.pow(2,21),vf=Math.pow(2,28),Ef=Math.pow(2,35),Bf=Math.pow(2,42),Af=Math.pow(2,49),Sf=Math.pow(2,56),If=Math.pow(2,63),kf=function(r){return r<yf?1:r<wf?2:r<xf?3:r<vf?4:r<Ef?5:r<Bf?6:r<Af?7:r<Sf?8:r<If?9:10},Cf={encode:hf,decode:mf,encodingLength:kf},Nf=Cf,_r=Nf;function Or(r,t=0){return[_r.decode(r,t),_r.decode.bytes]}function ar(r,t,e=0){return _r.encode(r,t,e),t}function cr(r){return _r.encodingLength(r)}function Mt(r,t){let e=t.byteLength,n=cr(r),s=n+cr(e),o=new Uint8Array(s+e);return ar(r,o,0),ar(e,o,n),o.set(t,s),new lr(r,e,t,o)}function qe(r){let t=ae(r),[e,n]=Or(t),[s,o]=Or(t.subarray(n)),i=t.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new lr(e,s,i,t)}function ka(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&ya(r.bytes,e.bytes)}}var lr=class{code;size;digest;bytes;constructor(t,e,n,s){this.code=t,this.size=e,this.digest=n,this.bytes=s}};function Ca(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Lf(e,wo(r),t??X.encoder);default:return Uf(e,wo(r),t??ce.encoder)}}var Na=new WeakMap;function wo(r){let t=Na.get(r);if(t==null){let e=new Map;return Na.set(r,e),e}return t}var dt=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!==Rf)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=Mt(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&ka(t.multihash,n.multihash)}toString(t){return Ca(this,t)}toJSON(){return{"/":Ca(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??Ta(n,s,o.bytes))}else if(e[_f]===!0){let{version:n,multihash:s,code:o}=e,i=qe(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=Ta(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=ae(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 lr(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[f,h]=Or(t.subarray(e));return e+=h,f},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,u=l-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:u,size:l}}static parse(t,e){let[n,s]=Tf(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 wo(o).set(n,t),o}};function Tf(r,t){switch(r[0]){case"Q":{let e=t??X;return[X.prefix,e.decode(`${X.prefix}${r}`)]}case X.prefix:{let e=t??X;return[X.prefix,e.decode(r)]}case ce.prefix:{let e=t??ce;return[ce.prefix,e.decode(r)]}case Rr.prefix:{let e=t??Rr;return[Rr.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Lf(r,t,e){let{prefix:n}=e;if(n!==X.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 Uf(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,Rf=18;function Ta(r,t,e){let n=cr(r),s=n+cr(t),o=new Uint8Array(s+e.byteLength);return ar(r,o,0),ar(t,o,n),o.set(e,s),o}var _f=Symbol.for("@ipld/js-cid/CID");var xo={};St(xo,{identity:()=>le});var La=0,Of="identity",Ua=ae;function Pf(r){return Mt(La,Ua(r))}var le={code:La,name:Of,encode:Ua,digest:Pf};function yt(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 Ra(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function Vf(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function ur(r,...t){if(!Vf(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error("Uint8Array expected of length "+t+", got length="+r.length)}function _a(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Ra(r.outputLen),Ra(r.blockLen)}function fr(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 Oa(r,t){ur(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}var $e=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var vn=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Ft=(r,t)=>r<<32-t|r>>>t;function Pa(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function Vr(r){return typeof r=="string"&&(r=Pa(r)),ur(r),r}function vo(...r){let t=0;for(let n=0;n<r.length;n++){let s=r[n];ur(s),t+=s.length}let e=new Uint8Array(t);for(let n=0,s=0;n<r.length;n++){let o=r[n];e.set(o,s),s+=o.length}return e}var hr=class{clone(){return this._cloneInto()}};function En(r){let t=n=>r().update(Vr(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function Bn(r=32){if($e&&typeof $e.getRandomValues=="function")return $e.getRandomValues(new Uint8Array(r));if($e&&typeof $e.randomBytes=="function")return $e.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function Df(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 Va=(r,t,e)=>r&t^~r&e,Da=(r,t,e)=>r&t^r&e^t&e,dr=class extends hr{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=vn(this.buffer)}update(t){fr(this);let{view:e,buffer:n,blockLen:s}=this;t=Vr(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=vn(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){fr(this),Oa(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 f=i;f<s;f++)e[f]=0;Df(n,s-8,BigInt(this.length*8),o),this.process(n,0);let a=vn(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=c/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<l;f++)a.setUint32(4*f,u[f],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 An=BigInt(4294967295),Eo=BigInt(32);function Ma(r,t=!1){return t?{h:Number(r&An),l:Number(r>>Eo&An)}:{h:Number(r>>Eo&An)|0,l:Number(r&An)|0}}function Mf(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}=Ma(r[s],t);[e[s],n[s]]=[o,i]}return[e,n]}var Ff=(r,t)=>BigInt(r>>>0)<<Eo|BigInt(t>>>0),Hf=(r,t,e)=>r>>>e,Kf=(r,t,e)=>r<<32-e|t>>>e,qf=(r,t,e)=>r>>>e|t<<32-e,$f=(r,t,e)=>r<<32-e|t>>>e,zf=(r,t,e)=>r<<64-e|t>>>e-32,Gf=(r,t,e)=>r>>>e-32|t<<64-e,Wf=(r,t)=>t,jf=(r,t)=>r,Zf=(r,t,e)=>r<<e|t>>>32-e,Yf=(r,t,e)=>t<<e|r>>>32-e,Jf=(r,t,e)=>t<<e-32|r>>>64-e,Xf=(r,t,e)=>r<<e-32|t>>>64-e;function Qf(r,t,e,n){let s=(t>>>0)+(n>>>0);return{h:r+e+(s/2**32|0)|0,l:s|0}}var th=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),eh=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,rh=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),nh=(r,t,e,n,s)=>t+e+n+s+(r/2**32|0)|0,sh=(r,t,e,n,s)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(s>>>0),oh=(r,t,e,n,s,o)=>t+e+n+s+o+(r/2**32|0)|0;var ih={fromBig:Ma,split:Mf,toBig:Ff,shrSH:Hf,shrSL:Kf,rotrSH:qf,rotrSL:$f,rotrBH:zf,rotrBL:Gf,rotr32H:Wf,rotr32L:jf,rotlSH:Zf,rotlSL:Yf,rotlBH:Jf,rotlBL:Xf,add:Qf,add3L:th,add3H:eh,add4L:rh,add4H:nh,add5H:oh,add5L:sh},P=ih;var[ah,ch]=P.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))),Ie=new Uint32Array(80),ke=new Uint32Array(80),Bo=class extends dr{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:u,Fh:f,Fl:h,Gh:d,Gl:p,Hh:b,Hl:g}=this;return[t,e,n,s,o,i,a,c,l,u,f,h,d,p,b,g]}set(t,e,n,s,o,i,a,c,l,u,f,h,d,p,b,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=u|0,this.Fh=f|0,this.Fl=h|0,this.Gh=d|0,this.Gl=p|0,this.Hh=b|0,this.Hl=g|0}process(t,e){for(let y=0;y<16;y++,e+=4)Ie[y]=t.getUint32(e),ke[y]=t.getUint32(e+=4);for(let y=16;y<80;y++){let I=Ie[y-15]|0,U=ke[y-15]|0,L=P.rotrSH(I,U,1)^P.rotrSH(I,U,8)^P.shrSH(I,U,7),k=P.rotrSL(I,U,1)^P.rotrSL(I,U,8)^P.shrSL(I,U,7),T=Ie[y-2]|0,C=ke[y-2]|0,tt=P.rotrSH(T,C,19)^P.rotrBH(T,C,61)^P.shrSH(T,C,6),q=P.rotrSL(T,C,19)^P.rotrBL(T,C,61)^P.shrSL(T,C,6),D=P.add4L(k,q,ke[y-7],ke[y-16]),it=P.add4H(D,L,tt,Ie[y-7],Ie[y-16]);Ie[y]=it|0,ke[y]=D|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:l,Dl:u,Eh:f,El:h,Fh:d,Fl:p,Gh:b,Gl:g,Hh:v,Hl:A}=this;for(let y=0;y<80;y++){let I=P.rotrSH(f,h,14)^P.rotrSH(f,h,18)^P.rotrBH(f,h,41),U=P.rotrSL(f,h,14)^P.rotrSL(f,h,18)^P.rotrBL(f,h,41),L=f&d^~f&b,k=h&p^~h&g,T=P.add5L(A,U,k,ch[y],ke[y]),C=P.add5H(T,v,I,L,ah[y],Ie[y]),tt=T|0,q=P.rotrSH(n,s,28)^P.rotrBH(n,s,34)^P.rotrBH(n,s,39),D=P.rotrSL(n,s,28)^P.rotrBL(n,s,34)^P.rotrBL(n,s,39),it=n&o^n&a^o&a,E=s&i^s&c^i&c;v=b|0,A=g|0,b=d|0,g=p|0,d=f|0,p=h|0,{h:f,l:h}=P.add(l|0,u|0,C|0,tt|0),l=a|0,u=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let N=P.add3L(tt,D,E);n=P.add3H(N,C,q,it),s=N|0}({h:n,l:s}=P.add(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=P.add(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=P.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:u}=P.add(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:h}=P.add(this.Eh|0,this.El|0,f|0,h|0),{h:d,l:p}=P.add(this.Fh|0,this.Fl|0,d|0,p|0),{h:b,l:g}=P.add(this.Gh|0,this.Gl|0,b|0,g|0),{h:v,l:A}=P.add(this.Hh|0,this.Hl|0,v|0,A|0),this.set(n,s,o,i,a,c,l,u,f,h,d,p,b,g,v,A)}roundClean(){Ie.fill(0),ke.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 Fa=En(()=>new Bo);var kn={};St(kn,{aInRange:()=>Nt,abool:()=>Ht,abytes:()=>pr,bitGet:()=>ph,bitLen:()=>ko,bitMask:()=>Mr,bitSet:()=>gh,bytesToHex:()=>fe,bytesToNumberBE:()=>he,bytesToNumberLE:()=>Ne,concatBytes:()=>de,createHmacDrbg:()=>Co,ensureBytes:()=>nt,equalBytes:()=>hh,hexToBytes:()=>Ge,hexToNumber:()=>Io,inRange:()=>Dr,isBytes:()=>Ce,memoized:()=>je,notImplemented:()=>bh,numberToBytesBE:()=>Te,numberToBytesLE:()=>We,numberToHexUnpadded:()=>ze,numberToVarBytesBE:()=>fh,utf8ToBytes:()=>dh,validateObject:()=>Qt});var Sn=BigInt(0),In=BigInt(1),lh=BigInt(2);function Ce(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function pr(r){if(!Ce(r))throw new Error("Uint8Array expected")}function Ht(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}var uh=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function fe(r){pr(r);let t="";for(let e=0;e<r.length;e++)t+=uh[r[e]];return t}function ze(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 r===""?Sn:BigInt("0x"+r)}var ue={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ha(r){if(r>=ue._0&&r<=ue._9)return r-ue._0;if(r>=ue.A&&r<=ue.F)return r-(ue.A-10);if(r>=ue.a&&r<=ue.f)return r-(ue.a-10)}function Ge(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("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=Ha(r.charCodeAt(o)),a=Ha(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 he(r){return Io(fe(r))}function Ne(r){return pr(r),Io(fe(Uint8Array.from(r).reverse()))}function Te(r,t){return Ge(r.toString(16).padStart(t*2,"0"))}function We(r,t){return Te(r,t).reverse()}function fh(r){return Ge(ze(r))}function nt(r,t,e){let n;if(typeof t=="string")try{n=Ge(t)}catch(o){throw new Error(r+" must be hex string or Uint8Array, cause: "+o)}else if(Ce(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+" of length "+e+" expected, got "+s);return n}function de(...r){let t=0;for(let n=0;n<r.length;n++){let s=r[n];pr(s),t+=s.length}let e=new Uint8Array(t);for(let n=0,s=0;n<r.length;n++){let o=r[n];e.set(o,s),s+=o.length}return e}function hh(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 dh(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}var Ao=r=>typeof r=="bigint"&&Sn<=r;function Dr(r,t,e){return Ao(r)&&Ao(t)&&Ao(e)&&t<=r&&r<e}function Nt(r,t,e,n){if(!Dr(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function ko(r){let t;for(t=0;r>Sn;r>>=In,t+=1);return t}function ph(r,t){return r>>BigInt(t)&In}function gh(r,t,e){return r|(e?In:Sn)<<BigInt(t)}var Mr=r=>(lh<<BigInt(r-1))-In,So=r=>new Uint8Array(r),Ka=r=>Uint8Array.from(r);function Co(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=So(r),s=So(r),o=0,i=()=>{n.fill(1),s.fill(0),o=0},a=(...f)=>e(s,n,...f),c=(f=So())=>{s=a(Ka([0]),f),n=a(),f.length!==0&&(s=a(Ka([1]),f),n=a())},l=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,h=[];for(;f<t;){n=a();let d=n.slice();h.push(d),f+=n.length}return de(...h)};return(f,h)=>{i(),c(f);let d;for(;!(d=h(l()));)c();return i(),d}}var mh={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"||Ce(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=mh[o];if(typeof a!="function")throw new Error("invalid validator function");let c=r[s];if(!(i&&c===void 0)&&!a(c,r))throw new Error("param "+String(s)+" is invalid. Expected "+o+", got "+c)};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 bh=()=>{throw new Error("not implemented")};function je(r){let t=new WeakMap;return(e,...n)=>{let s=t.get(e);if(s!==void 0)return s;let o=r(e,...n);return t.set(e,o),o}}var at=BigInt(0),et=BigInt(1),Ze=BigInt(2),yh=BigInt(3),No=BigInt(4),qa=BigInt(5),$a=BigInt(8),wh=BigInt(9),xh=BigInt(16);function Z(r,t){let e=r%t;return e>=at?e:t+e}function vh(r,t,e){if(t<at)throw new Error("invalid exponent, negatives unsupported");if(e<=at)throw new Error("invalid modulus");if(e===et)return at;let n=et;for(;t>at;)t&et&&(n=n*r%e),r=r*r%e,t>>=et;return n}function rt(r,t,e){let n=r;for(;t-- >at;)n*=n,n%=e;return n}function Cn(r,t){if(r===at)throw new Error("invert: expected non-zero number");if(t<=at)throw new Error("invert: expected positive modulus, got "+t);let e=Z(r,t),n=t,s=at,o=et,i=et,a=at;for(;e!==at;){let l=n/e,u=n%e,f=s-i*l,h=o-a*l;n=e,e=u,s=i,o=a,i=f,a=h}if(n!==et)throw new Error("invert: does not exist");return Z(s,t)}function Eh(r){let t=(r-et)/Ze,e,n,s;for(e=r-et,n=0;e%Ze===at;e/=Ze,n++);for(s=Ze;s<r&&vh(s,t,r)!==r-et;s++)if(s>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let i=(r+et)/No;return function(c,l){let u=c.pow(l,i);if(!c.eql(c.sqr(u),l))throw new Error("Cannot find square root");return u}}let o=(e+et)/Ze;return function(a,c){if(a.pow(c,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let l=n,u=a.pow(a.mul(a.ONE,s),e),f=a.pow(c,o),h=a.pow(c,e);for(;!a.eql(h,a.ONE);){if(a.eql(h,a.ZERO))return a.ZERO;let d=1;for(let b=a.sqr(h);d<l&&!a.eql(b,a.ONE);d++)b=a.sqr(b);let p=a.pow(u,et<<BigInt(l-d-1));u=a.sqr(p),f=a.mul(f,p),h=a.mul(h,u),l=d}return f}}function Bh(r){if(r%No===yh){let t=(r+et)/No;return function(n,s){let o=n.pow(s,t);if(!n.eql(n.sqr(o),s))throw new Error("Cannot find square root");return o}}if(r%$a===qa){let t=(r-qa)/$a;return function(n,s){let o=n.mul(s,Ze),i=n.pow(o,t),a=n.mul(s,i),c=n.mul(n.mul(a,Ze),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%xh,Eh(r)}var za=(r,t)=>(Z(r,t)&et)===et,Ah=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function To(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=Ah.reduce((n,s)=>(n[s]="function",n),t);return Qt(r,e)}function Sh(r,t,e){if(e<at)throw new Error("invalid exponent, negatives unsupported");if(e===at)return r.ONE;if(e===et)return t;let n=r.ONE,s=t;for(;e>at;)e&et&&(n=r.mul(n,s)),s=r.sqr(s),e>>=et;return n}function Ih(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 Lo(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Le(r,t,e=!1,n={}){if(r<=at)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:s,nByteLength:o}=Lo(r,t);if(o>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let i,a=Object.freeze({ORDER:r,BITS:s,BYTES:o,MASK:Mr(s),ZERO:at,ONE:et,create:c=>Z(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return at<=c&&c<r},is0:c=>c===at,isOdd:c=>(c&et)===et,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)=>Sh(a,c,l),div:(c,l)=>Z(c*Cn(l,r),r),sqrN:c=>c*c,addN:(c,l)=>c+l,subN:(c,l)=>c-l,mulN:(c,l)=>c*l,inv:c=>Cn(c,r),sqrt:n.sqrt||(c=>(i||(i=Bh(r)),i(a,c))),invertBatch:c=>Ih(a,c),cmov:(c,l,u)=>u?l:c,toBytes:c=>e?We(c,o):Te(c,o),fromBytes:c=>{if(c.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+c.length);return e?Ne(c):he(c)}});return Object.freeze(a)}function Ga(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 Uo(r){let t=Ga(r);return t+Math.ceil(t/2)}function Wa(r,t,e=!1){let n=r.length,s=Ga(t),o=Uo(t);if(n<16||n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);let i=e?he(r):Ne(r),a=Z(i,t-et)+et;return e?We(a,s):Te(a,s)}var ja=BigInt(0),Nn=BigInt(1);function Ro(r,t){let e=t.negate();return r?e:t}function Za(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function _o(r,t){Za(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1);return{windows:e,windowSize:n}}function Ch(r,t){if(!Array.isArray(r))throw new Error("array expected");r.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})}function Nh(r,t){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}var Oo=new WeakMap,Ya=new WeakMap;function Po(r){return Ya.get(r)||1}function Tn(r,t){return{constTimeNegate:Ro,hasPrecomputes(e){return Po(e)!==1},unsafeLadder(e,n,s=r.ZERO){let o=e;for(;n>ja;)n&Nn&&(s=s.add(o)),o=o.double(),n>>=Nn;return s},precomputeWindow(e,n){let{windows:s,windowSize:o}=_o(n,t),i=[],a=e,c=a;for(let l=0;l<s;l++){c=a,i.push(c);for(let u=1;u<o;u++)c=c.add(a),i.push(c);a=c.double()}return i},wNAF(e,n,s){let{windows:o,windowSize:i}=_o(e,t),a=r.ZERO,c=r.BASE,l=BigInt(2**e-1),u=2**e,f=BigInt(e);for(let h=0;h<o;h++){let d=h*i,p=Number(s&l);s>>=f,p>i&&(p-=u,s+=Nn);let b=d,g=d+Math.abs(p)-1,v=h%2!==0,A=p<0;p===0?c=c.add(Ro(v,n[b])):a=a.add(Ro(A,n[g]))}return{p:a,f:c}},wNAFUnsafe(e,n,s,o=r.ZERO){let{windows:i,windowSize:a}=_o(e,t),c=BigInt(2**e-1),l=2**e,u=BigInt(e);for(let f=0;f<i;f++){let h=f*a;if(s===ja)break;let d=Number(s&c);if(s>>=u,d>a&&(d-=l,s+=Nn),d===0)continue;let p=n[h+Math.abs(d)-1];d<0&&(p=p.negate()),o=o.add(p)}return o},getPrecomputes(e,n,s){let o=Oo.get(n);return o||(o=this.precomputeWindow(n,e),e!==1&&Oo.set(n,s(o))),o},wNAFCached(e,n,s){let o=Po(e);return this.wNAF(o,this.getPrecomputes(o,e,s),n)},wNAFCachedUnsafe(e,n,s,o){let i=Po(e);return i===1?this.unsafeLadder(e,n,o):this.wNAFUnsafe(i,this.getPrecomputes(i,e,s),n,o)},setWindowSize(e,n){Za(n,t),Ya.set(e,n),Oo.delete(e)}}}function Ln(r,t,e,n){if(Ch(e,r),Nh(n,t),e.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let s=r.ZERO,o=ko(BigInt(e.length)),i=o>12?o-3:o>4?o-2:o?2:1,a=(1<<i)-1,c=new Array(a+1).fill(s),l=Math.floor((t.BITS-1)/i)*i,u=s;for(let f=l;f>=0;f-=i){c.fill(s);for(let d=0;d<n.length;d++){let p=n[d],b=Number(p>>BigInt(f)&BigInt(a));c[b]=c[b].add(e[d])}let h=s;for(let d=c.length-1,p=s;d>0;d--)p=p.add(c[d]),h=h.add(p);if(u=u.add(h),f!==0)for(let d=0;d<i;d++)u=u.double()}return u}function Fr(r){return To(r.Fp),Qt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Lo(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Kt=BigInt(0),Tt=BigInt(1),Un=BigInt(2),Th=BigInt(8),Lh={zip215:!0};function Uh(r){let t=Fr(r);return Qt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Ja(r){let t=Uh(r),{Fp:e,n,prehash:s,hash:o,randomBytes:i,nByteLength:a,h:c}=t,l=Un<<BigInt(a*8)-Tt,u=e.create,f=Le(t.n,t.nBitLength),h=t.uvRatio||((w,m)=>{try{return{isValid:!0,value:e.sqrt(w*e.inv(m))}}catch{return{isValid:!1,value:Kt}}}),d=t.adjustScalarBytes||(w=>w),p=t.domain||((w,m,x)=>{if(Ht("phflag",x),m.length||x)throw new Error("Contexts/pre-hash are not supported");return w});function b(w,m){Nt("coordinate "+w,m,Kt,l)}function g(w){if(!(w instanceof y))throw new Error("ExtendedPoint expected")}let v=je((w,m)=>{let{ex:x,ey:S,ez:R}=w,_=w.is0();m==null&&(m=_?Th:e.inv(R));let V=u(x*m),F=u(S*m),O=u(R*m);if(_)return{x:Kt,y:Tt};if(O!==Tt)throw new Error("invZ was invalid");return{x:V,y:F}}),A=je(w=>{let{a:m,d:x}=t;if(w.is0())throw new Error("bad point: ZERO");let{ex:S,ey:R,ez:_,et:V}=w,F=u(S*S),O=u(R*R),j=u(_*_),J=u(j*j),lt=u(F*m),ut=u(j*u(lt+O)),ht=u(J+u(x*u(F*O)));if(ut!==ht)throw new Error("bad point: equation left != right (1)");let bt=u(S*R),Ct=u(_*V);if(bt!==Ct)throw new Error("bad point: equation left != right (2)");return!0});class y{constructor(m,x,S,R){this.ex=m,this.ey=x,this.ez=S,this.et=R,b("x",m),b("y",x),b("z",S),b("t",R),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(m){if(m instanceof y)throw new Error("extended point not allowed");let{x,y:S}=m||{};return b("x",x),b("y",S),new y(x,S,Tt,u(x*S))}static normalizeZ(m){let x=e.invertBatch(m.map(S=>S.ez));return m.map((S,R)=>S.toAffine(x[R])).map(y.fromAffine)}static msm(m,x){return Ln(y,f,m,x)}_setWindowSize(m){L.setWindowSize(this,m)}assertValidity(){A(this)}equals(m){g(m);let{ex:x,ey:S,ez:R}=this,{ex:_,ey:V,ez:F}=m,O=u(x*F),j=u(_*R),J=u(S*F),lt=u(V*R);return O===j&&J===lt}is0(){return this.equals(y.ZERO)}negate(){return new y(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:m}=t,{ex:x,ey:S,ez:R}=this,_=u(x*x),V=u(S*S),F=u(Un*u(R*R)),O=u(m*_),j=x+S,J=u(u(j*j)-_-V),lt=O+V,ut=lt-F,ht=O-V,bt=u(J*ut),Ct=u(lt*ht),At=u(J*ht),Xt=u(ut*lt);return new y(bt,Ct,Xt,At)}add(m){g(m);let{a:x,d:S}=t,{ex:R,ey:_,ez:V,et:F}=this,{ex:O,ey:j,ez:J,et:lt}=m;if(x===BigInt(-1)){let ua=u((_-R)*(j+O)),fa=u((_+R)*(j-O)),io=u(fa-ua);if(io===Kt)return this.double();let ha=u(V*Un*lt),da=u(F*Un*J),pa=da+ha,ga=fa+ua,ma=da-ha,Fu=u(pa*io),Hu=u(ga*ma),Ku=u(pa*ma),qu=u(io*ga);return new y(Fu,Hu,qu,Ku)}let ut=u(R*O),ht=u(_*j),bt=u(F*S*lt),Ct=u(V*J),At=u((R+_)*(O+j)-ut-ht),Xt=Ct-bt,ie=Ct+bt,Lr=u(ht-x*ut),Pu=u(At*Xt),Vu=u(ie*Lr),Du=u(At*Lr),Mu=u(Xt*ie);return new y(Pu,Vu,Mu,Du)}subtract(m){return this.add(m.negate())}wNAF(m){return L.wNAFCached(this,m,y.normalizeZ)}multiply(m){let x=m;Nt("scalar",x,Tt,n);let{p:S,f:R}=this.wNAF(x);return y.normalizeZ([S,R])[0]}multiplyUnsafe(m,x=y.ZERO){let S=m;return Nt("scalar",S,Kt,n),S===Kt?U:this.is0()||S===Tt?this:L.wNAFCachedUnsafe(this,S,y.normalizeZ,x)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return L.unsafeLadder(this,n).is0()}toAffine(m){return v(this,m)}clearCofactor(){let{h:m}=t;return m===Tt?this:this.multiplyUnsafe(m)}static fromHex(m,x=!1){let{d:S,a:R}=t,_=e.BYTES;m=nt("pointHex",m,_),Ht("zip215",x);let V=m.slice(),F=m[_-1];V[_-1]=F&-129;let O=Ne(V),j=x?l:e.ORDER;Nt("pointHex.y",O,Kt,j);let J=u(O*O),lt=u(J-Tt),ut=u(S*J-R),{isValid:ht,value:bt}=h(lt,ut);if(!ht)throw new Error("Point.fromHex: invalid y coordinate");let Ct=(bt&Tt)===Tt,At=(F&128)!==0;if(!x&&bt===Kt&&At)throw new Error("Point.fromHex: x=0 and x_0=1");return At!==Ct&&(bt=u(-bt)),y.fromAffine({x:bt,y:O})}static fromPrivateKey(m){return C(m).point}toRawBytes(){let{x:m,y:x}=this.toAffine(),S=We(x,e.BYTES);return S[S.length-1]|=m&Tt?128:0,S}toHex(){return fe(this.toRawBytes())}}y.BASE=new y(t.Gx,t.Gy,Tt,u(t.Gx*t.Gy)),y.ZERO=new y(Kt,Tt,Tt,Kt);let{BASE:I,ZERO:U}=y,L=Tn(y,a*8);function k(w){return Z(w,n)}function T(w){return k(Ne(w))}function C(w){let m=e.BYTES;w=nt("private key",w,m);let x=nt("hashed private key",o(w),2*m),S=d(x.slice(0,m)),R=x.slice(m,2*m),_=T(S),V=I.multiply(_),F=V.toRawBytes();return{head:S,prefix:R,scalar:_,point:V,pointBytes:F}}function tt(w){return C(w).pointBytes}function q(w=new Uint8Array,...m){let x=de(...m);return T(o(p(x,nt("context",w),!!s)))}function D(w,m,x={}){w=nt("message",w),s&&(w=s(w));let{prefix:S,scalar:R,pointBytes:_}=C(m),V=q(x.context,S,w),F=I.multiply(V).toRawBytes(),O=q(x.context,F,_,w),j=k(V+O*R);Nt("signature.s",j,Kt,n);let J=de(F,We(j,e.BYTES));return nt("result",J,e.BYTES*2)}let it=Lh;function E(w,m,x,S=it){let{context:R,zip215:_}=S,V=e.BYTES;w=nt("signature",w,2*V),m=nt("message",m),x=nt("publicKey",x,V),_!==void 0&&Ht("zip215",_),s&&(m=s(m));let F=Ne(w.slice(V,2*V)),O,j,J;try{O=y.fromHex(x,_),j=y.fromHex(w.slice(0,V),_),J=I.multiplyUnsafe(F)}catch{return!1}if(!_&&O.isSmallOrder())return!1;let lt=q(R,j.toRawBytes(),O.toRawBytes(),m);return j.add(O.multiplyUnsafe(lt)).subtract(J).clearCofactor().equals(y.ZERO)}return I._setWindowSize(8),{CURVE:t,getPublicKey:tt,sign:D,verify:E,ExtendedPoint:y,utils:{getExtendedPublicKey:C,randomPrivateKey:()=>i(e.BYTES),precompute(w=8,m=y.BASE){return m._setWindowSize(w),m.multiply(BigInt(3)),m}}}}var Vo=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Xa=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),fg=BigInt(0),Rh=BigInt(1),Qa=BigInt(2),hg=BigInt(3),_h=BigInt(5),Oh=BigInt(8);function Ph(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),s=BigInt(80),o=Vo,a=r*r%o*r%o,c=rt(a,Qa,o)*a%o,l=rt(c,Rh,o)*r%o,u=rt(l,_h,o)*l%o,f=rt(u,t,o)*u%o,h=rt(f,e,o)*f%o,d=rt(h,n,o)*h%o,p=rt(d,s,o)*d%o,b=rt(p,s,o)*d%o,g=rt(b,t,o)*u%o;return{pow_p_5_8:rt(g,Qa,o)*r%o,b2:a}}function Vh(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Dh(r,t){let e=Vo,n=Z(t*t*t,e),s=Z(n*n*t,e),o=Ph(r*s).pow_p_5_8,i=Z(r*n*o,e),a=Z(t*i*i,e),c=i,l=Z(i*Xa,e),u=a===r,f=a===Z(-r,e),h=a===Z(-r*Xa,e);return u&&(i=c),(f||h)&&(i=l),za(i,e)&&(i=Z(-i,e)),{isValid:u||f,value:i}}var Mh=Le(Vo,void 0,!0),Fh={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Mh,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:Oh,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Fa,randomBytes:Bn,adjustScalarBytes:Vh,uvRatio:Dh},tc=Ja(Fh);var Rn=32;function ec(r,t,e){return tc.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var _n=class{type="Ed25519";raw;constructor(t){this.raw=Do(t,Rn)}toMultihash(){return le.digest(Ue(this))}toCID(){return dt.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:yt(this.raw,t.raw)}verify(t,e){return ec(this.raw,e,t)}};function Mo(r){return r=Do(r,Rn),new _n(r)}function Do(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new It(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}function pt(r=0){return new Uint8Array(r)}function Lt(r=0){return new Uint8Array(r)}var Kh=Math.pow(2,7),qh=Math.pow(2,14),$h=Math.pow(2,21),Fo=Math.pow(2,28),Ho=Math.pow(2,35),Ko=Math.pow(2,42),qo=Math.pow(2,49),W=128,wt=127;function xt(r){if(r<Kh)return 1;if(r<qh)return 2;if(r<$h)return 3;if(r<Fo)return 4;if(r<Ho)return 5;if(r<Ko)return 6;if(r<qo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function $o(r,t,e=0){switch(xt(r)){case 8:t[e++]=r&255|W,r/=128;case 7:t[e++]=r&255|W,r/=128;case 6:t[e++]=r&255|W,r/=128;case 5:t[e++]=r&255|W,r/=128;case 4:t[e++]=r&255|W,r>>>=7;case 3:t[e++]=r&255|W,r>>>=7;case 2:t[e++]=r&255|W,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function zh(r,t,e=0){switch(xt(r)){case 8:t.set(e++,r&255|W),r/=128;case 7:t.set(e++,r&255|W),r/=128;case 6:t.set(e++,r&255|W),r/=128;case 5:t.set(e++,r&255|W),r/=128;case 4:t.set(e++,r&255|W),r>>>=7;case 3:t.set(e++,r&255|W),r>>>=7;case 2:t.set(e++,r&255|W),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function zo(r,t){let e=r[t],n=0;if(n+=e&wt,e<W||(e=r[t+1],n+=(e&wt)<<7,e<W)||(e=r[t+2],n+=(e&wt)<<14,e<W)||(e=r[t+3],n+=(e&wt)<<21,e<W)||(e=r[t+4],n+=(e&wt)*Fo,e<W)||(e=r[t+5],n+=(e&wt)*Ho,e<W)||(e=r[t+6],n+=(e&wt)*Ko,e<W)||(e=r[t+7],n+=(e&wt)*qo,e<W))return n;throw new RangeError("Could not decode varint")}function Gh(r,t){let e=r.get(t),n=0;if(n+=e&wt,e<W||(e=r.get(t+1),n+=(e&wt)<<7,e<W)||(e=r.get(t+2),n+=(e&wt)<<14,e<W)||(e=r.get(t+3),n+=(e&wt)<<21,e<W)||(e=r.get(t+4),n+=(e&wt)*Fo,e<W)||(e=r.get(t+5),n+=(e&wt)*Ho,e<W)||(e=r.get(t+6),n+=(e&wt)*Ko,e<W)||(e=r.get(t+7),n+=(e&wt)*qo,e<W))return n;throw new RangeError("Could not decode varint")}function Pt(r,t,e=0){return t==null&&(t=Lt(xt(r))),t instanceof Uint8Array?$o(r,t,e):zh(r,t,e)}function pe(r,t=0){return r instanceof Uint8Array?zo(r,t):Gh(r,t)}var Go=new Float32Array([-0]),Re=new Uint8Array(Go.buffer);function nc(r,t,e){Go[0]=r,t[e]=Re[0],t[e+1]=Re[1],t[e+2]=Re[2],t[e+3]=Re[3]}function sc(r,t){return Re[0]=r[t],Re[1]=r[t+1],Re[2]=r[t+2],Re[3]=r[t+3],Go[0]}var Wo=new Float64Array([-0]),vt=new Uint8Array(Wo.buffer);function oc(r,t,e){Wo[0]=r,t[e]=vt[0],t[e+1]=vt[1],t[e+2]=vt[2],t[e+3]=vt[3],t[e+4]=vt[4],t[e+5]=vt[5],t[e+6]=vt[6],t[e+7]=vt[7]}function ic(r,t){return vt[0]=r[t],vt[1]=r[t+1],vt[2]=r[t+2],vt[3]=r[t+3],vt[4]=r[t+4],vt[5]=r[t+5],vt[6]=r[t+6],vt[7]=r[t+7],Wo[0]}var Wh=BigInt(Number.MAX_SAFE_INTEGER),jh=BigInt(Number.MIN_SAFE_INTEGER),_t=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 Ye;if(t<Wh&&t>jh)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>ac&&(s=0n,++n>ac&&(n=0n))),new r(Number(s),Number(n))}static fromNumber(t){if(t===0)return Ye;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):Ye}},Ye=new _t(0,0);Ye.toBigInt=function(){return 0n};Ye.zzEncode=Ye.zzDecode=function(){return this};Ye.length=function(){return 1};var ac=4294967296n;function cc(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 lc(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 jo(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 qt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Pn(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Zo=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,qt(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 qt(this,4);return Pn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw qt(this,4);return Pn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw qt(this,4);let t=sc(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw qt(this,4);let t=ic(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 qt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return lc(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw qt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw qt(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 _t(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 qt(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 qt(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 qt(this,8);let t=Pn(this.buf,this.pos+=4),e=Pn(this.buf,this.pos+=4);return new _t(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=zo(this.buf,this.pos);return this.pos+=xt(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Yo(r){return new Zo(r instanceof Uint8Array?r:r.subarray())}function $t(r,t,e){let n=Yo(r);return t.decode(n,void 0,e)}var Jo={};St(Jo,{base10:()=>Zh});var Zh=Ae({prefix:"9",name:"base10",alphabet:"0123456789"});var Xo={};St(Xo,{base16:()=>Yh,base16upper:()=>Jh});var Yh=ot({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Jh=ot({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Qo={};St(Qo,{base2:()=>Xh});var Xh=ot({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ti={};St(ti,{base256emoji:()=>nd});var fc=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}"),Qh=fc.reduce((r,t,e)=>(r[e]=t,r),[]),td=fc.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function ed(r){return r.reduce((t,e)=>(t+=Qh[e],t),"")}function rd(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let s=td[n];if(s==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(s)}return new Uint8Array(t)}var nd=ir({prefix:"\u{1F680}",name:"base256emoji",encode:ed,decode:rd});var ri={};St(ri,{base64:()=>sd,base64pad:()=>od,base64url:()=>ei,base64urlpad:()=>id});var sd=ot({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),od=ot({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ei=ot({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),id=ot({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ni={};St(ni,{base8:()=>ad});var ad=ot({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var si={};St(si,{identity:()=>cd});var cd=ir({prefix:"\0",name:"identity",encode:r=>xa(r),decode:r=>wa(r)});var jg=new TextEncoder,Zg=new TextDecoder;var ai={};St(ai,{sha256:()=>Hr,sha512:()=>fd});function ii({name:r,code:t,encode:e}){return new oi(r,t,e)}var oi=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?Mt(this.code,e):e.then(n=>Mt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function dc(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Hr=ii({name:"sha2-256",code:18,encode:dc("SHA-256")}),fd=ii({name:"sha2-512",code:19,encode:dc("SHA-512")});var Kr={...si,...Qo,...ni,...Jo,...Xo,...mo,...bo,...go,...ri,...ti},am={...ai,...xo};function gc(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var pc=gc("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ci=gc("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=Lt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),hd={utf8:pc,"utf-8":pc,hex:Kr.base16,latin1:ci,ascii:ci,binary:ci,...Kr},Vn=hd;function $(r,t="utf8"){let e=Vn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function li(r){let t=r??8192,e=t>>>1,n,s=t;return function(i){if(i<1||i>e)return Lt(i);s+i>t&&(n=Lt(t),s=0);let a=n.subarray(s,s+=i);return s&7&&(s=(s|7)+1),a}}var Je=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function ui(){}var hi=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},dd=li();function pd(r){return globalThis.Buffer!=null?Lt(r):dd(r)}var $r=class{len;head;tail;states;constructor(){this.len=0,this.head=new Je(ui,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Je(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new di((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(Dn,10,_t.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=_t.fromBigInt(t);return this._push(Dn,e.length(),e)}uint64Number(t){return this._push($o,xt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=_t.fromBigInt(t).zzEncode();return this._push(Dn,e.length(),e)}sint64Number(t){let e=_t.fromNumber(t).zzEncode();return this._push(Dn,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(fi,1,t?1:0)}fixed32(t){return this._push(qr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=_t.fromBigInt(t);return this._push(qr,4,e.lo)._push(qr,4,e.hi)}fixed64Number(t){let e=_t.fromNumber(t);return this._push(qr,4,e.lo)._push(qr,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(nc,4,t)}double(t){return this._push(oc,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(fi,1,0):this.uint32(e)._push(md,e,t)}string(t){let e=cc(t);return e!==0?this.uint32(e)._push(jo,e,t):this._push(fi,1,0)}fork(){return this.states=new hi(this),this.head=this.tail=new Je(ui,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 Je(ui,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=pd(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function fi(r,t,e){t[e]=r&255}function gd(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var di=class extends Je{next;constructor(t,e){super(gd,t,e),this.next=void 0}};function Dn(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 qr(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 md(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&($r.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(bd,t,r),this},$r.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(yd,t,r),this});function bd(r,t,e){t.set(r,e)}function yd(r,t,e){r.length<40?jo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set($(r),e)}function pi(){return new $r}function zt(r,t){let e=pi();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var gr;(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"})(gr||(gr={}));function Mn(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function gi(r){function t(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let e=function(o,i){let a=t(o);i.int32(a)},n=function(o){let i=o.int32();return t(i)};return Mn("enum",gr.VARINT,e,n)}function Gt(r,t){return Mn("message",gr.LENGTH_DELIMITED,r,t)}var Xe=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var ct;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1"})(ct||(ct={}));var mi;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1"})(mi||(mi={}));(function(r){r.codec=()=>gi(mi)})(ct||(ct={}));var te;(function(r){let t;r.codec=()=>(t==null&&(t=Gt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),ct.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let o={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{o.Type=ct.codec().decode(e);break}case 2:{o.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return o})),t),r.encode=e=>zt(e,r.codec()),r.decode=(e,n)=>$t(e,r.codec(),n)})(te||(te={}));var bi;(function(r){let t;r.codec=()=>(t==null&&(t=Gt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),ct.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let o={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{o.Type=ct.codec().decode(e);break}case 2:{o.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return o})),t),r.encode=e=>zt(e,r.codec()),r.decode=(e,n)=>$t(e,r.codec(),n)})(bi||(bi={}));var tn={};St(tn,{MAX_RSA_KEY_SIZE:()=>_s,generateRSAKeyPair:()=>ml,jwkToJWKKeyPair:()=>bl,jwkToPkcs1:()=>Vd,jwkToPkix:()=>Ni,jwkToRSAPrivateKey:()=>gl,pkcs1ToJwk:()=>hl,pkcs1ToRSAPrivateKey:()=>pl,pkixToJwk:()=>dl,pkixToRSAPublicKey:()=>Ti});function wd(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function yi(r,...t){if(!wd(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error("Uint8Array expected of length "+t+", got length="+r.length)}function wi(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 bc(r,t){yi(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}var Hn=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Wt=(r,t)=>r<<32-t|r>>>t;function xd(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function xi(r){return typeof r=="string"&&(r=xd(r)),yi(r),r}var Fn=class{clone(){return this._cloneInto()}};function yc(r){let t=n=>r().update(xi(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function vd(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 wc=(r,t,e)=>r&t^~r&e,xc=(r,t,e)=>r&t^r&e^t&e,Kn=class extends Fn{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=Hn(this.buffer)}update(t){wi(this);let{view:e,buffer:n,blockLen:s}=this;t=xi(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=Hn(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){wi(this),bc(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 f=i;f<s;f++)e[f]=0;vd(n,s-8,BigInt(this.length*8),o),this.process(n,0);let a=Hn(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=c/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<l;f++)a.setUint32(4*f,u[f],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 Ed=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]),Oe=new Uint32Array(64),vi=class extends Kn{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 f=0;f<16;f++,e+=4)Oe[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let h=Oe[f-15],d=Oe[f-2],p=Wt(h,7)^Wt(h,18)^h>>>3,b=Wt(d,17)^Wt(d,19)^d>>>10;Oe[f]=b+Oe[f-7]+p+Oe[f-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:l,H:u}=this;for(let f=0;f<64;f++){let h=Wt(a,6)^Wt(a,11)^Wt(a,25),d=u+h+wc(a,c,l)+Ed[f]+Oe[f]|0,b=(Wt(n,2)^Wt(n,13)^Wt(n,22))+xc(n,s,o)|0;u=l,l=c,c=a,a=i+d|0,i=o,o=s,s=n,n=d+b|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,u=u+this.H|0,this.set(n,s,o,i,a,c,l,u)}roundClean(){Oe.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var qn=yc(()=>new vi);var M=co(vc());function Qe(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 Pe(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 u=a-1;u>=0;u--){let f=Math.pow(2,u*t);l[o-u-1]=Math.floor(s/f),s-=l[o-u-1]*f}return c}i*=Math.pow(2,t)}return new ArrayBuffer(0)}function Gn(...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 Bi(){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=Qe(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,Qe(o,8)-n}function Ec(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=Pe(i,8,n),c=new Uint8Array(a);return c[0]|=128,a}let s=Pe(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 Bc(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 Ut(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 jm=Math.log(2);function Wn(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Ai(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 we(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 Gr=class{constructor(){this.items=[]}write(t){this.items.push(t)}final(){return Ai(this.items)}},zr=[new Uint8Array([1])],Ac="0123456789";var xr="",jt=new ArrayBuffer(0),Si=new Uint8Array(0),Wr="EndOfContent",Ic="OCTET STRING",kc="BIT STRING";function xe(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?M.BufferSourceConverter.toUint8Array(o.valueHex):Si}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(!we(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",jt)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:M.Convert.ToHex(this.valueHexView)}}},t.NAME="hexBlock",t}var me=class{constructor({blockLength:t=0,error:e=xr,warnings:n=[],valueBeforeDecode:s=Si}={}){this.blockLength=t,this.error=e,this.warnings=n,this.valueBeforeDecodeView=M.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:M.Convert.ToHex(this.valueBeforeDecodeView)}}};me.NAME="baseBlock";var Et=class extends me{fromBER(t,e,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(t,e){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}};Et.NAME="valueBlock";var jn=class extends xe(me){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?M.BufferSourceConverter.toUint8Array(t.valueHex):Si,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",jt}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=Pe(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=M.BufferSourceConverter.toUint8Array(t);if(!we(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),u=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===u){u+=255;let h=new Uint8Array(u);for(let d=0;d<l.length;d++)h[d]=l[d];l=this.valueHexView=new Uint8Array(u)}}this.blockLength=c+1,l[c-1]=o[c]&127;let f=new Uint8Array(c);for(let h=0;h<c;h++)f[h]=l[h];l=this.valueHexView=new Uint8Array(c),l.set(f),this.blockLength<=9?this.tagNumber=Qe(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}}};jn.NAME="identificationBlock";var Zn=class extends me{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=M.BufferSourceConverter.toUint8Array(t);if(!we(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=Qe(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=Pe(this.length,8);if(s.byteLength>127)return this.error="Too big length",jt;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}}};Zn.NAME="lengthBlock";var B={},gt=class extends me{constructor({name:t=xr,optional:e=!1,primitiveSchema:n,...s}={},o){super(s),this.name=t,this.optional=e,n&&(this.primitiveSchema=n),this.idBlock=new jn(s),this.lenBlock=new Zn(s),this.valueBlock=o?new o(s):new Et(s)}fromBER(t,e,n){let s=this.valueBlock.fromBER(t,e,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),s)}toBER(t,e){let n=e||new Gr;e||Cc(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?jt: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():M.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${M.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 Bc(e,n)}};gt.NAME="BaseBlock";function Cc(r){if(r instanceof B.Constructed)for(let t of r.valueBlock.value)Cc(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var Yn=class extends gt{constructor({value:t=xr,...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}'`}};Yn.NAME="BaseStringBlock";var Jn=class extends xe(Et){constructor({isHexOnly:t=!0,...e}={}){super(e),this.isHexOnly=t}};Jn.NAME="PrimitiveValueBlock";var Nc,Xn=class extends gt{constructor(t={}){super(t,Jn),this.idBlock.isConstructed=!1}};Nc=Xn;B.Primitive=Nc;Xn.NAME="PRIMITIVE";function Ld(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 gt({},Et),o=new me;if(!we(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=gt;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=B.EndOfContent;break;case 1:c=B.Boolean;break;case 2:c=B.Integer;break;case 3:c=B.BitString;break;case 4:c=B.OctetString;break;case 5:c=B.Null;break;case 6:c=B.ObjectIdentifier;break;case 10:c=B.Enumerated;break;case 12:c=B.Utf8String;break;case 13:c=B.RelativeObjectIdentifier;break;case 14:c=B.TIME;break;case 15:return s.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:s};case 16:c=B.Sequence;break;case 17:c=B.Set;break;case 18:c=B.NumericString;break;case 19:c=B.PrintableString;break;case 20:c=B.TeletexString;break;case 21:c=B.VideotexString;break;case 22:c=B.IA5String;break;case 23:c=B.UTCTime;break;case 24:c=B.GeneralizedTime;break;case 25:c=B.GraphicString;break;case 26:c=B.VisibleString;break;case 27:c=B.GeneralString;break;case 28:c=B.UniversalString;break;case 29:c=B.CharacterString;break;case 30:c=B.BmpString;break;case 31:c=B.DATE;break;case 32:c=B.TimeOfDay;break;case 33:c=B.DateTime;break;case 34:c=B.Duration;break;default:{let l=s.idBlock.isConstructed?new B.Constructed:new B.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?B.Constructed:B.Primitive}return s=Ld(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 Ii(r){if(!r.byteLength){let t=new gt({},Et);return t.error="Input buffer has zero length",{offset:-1,result:t}}return Us(M.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function Ud(r,t){return r?1:t}var ee=class extends Et{constructor({value:t=[],isIndefiniteForm:e=!1,...n}={}){super(n),this.value=t,this.isIndefiniteForm=e}fromBER(t,e,n){let s=M.BufferSourceConverter.toUint8Array(t);if(!we(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(;Ud(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===Wr)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===Wr?this.value.pop():this.warnings.push("No EndOfContent block encoded")),o}toBER(t,e){let n=e||new Gr;for(let s=0;s<this.value.length;s++)this.value[s].toBER(t,n);return e?jt:n.final()}toJSON(){let t={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let e of this.value)t.value.push(e.toJSON());return t}};ee.NAME="ConstructedValueBlock";var Tc,Ve=class extends gt{constructor(t={}){super(t,ee),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} :`}};sc=Pe;A.Constructed=sc;Pe.NAME="CONSTRUCTED";var Fn=class extends Et{fromBER(t,e,n){return e}toBER(t){return Wt}};Fn.override="EndOfContentValueBlock";var oc,Hn=class extends gt{constructor(t={}){super(t,Fn),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};oc=Hn;A.EndOfContent=oc;Hn.NAME=Hr;var ic,fr=class extends gt{constructor(t={}){super(t,Et),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(t,e,n){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=n,e+n>t.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):e+n}toBER(t,e){let n=new ArrayBuffer(2);if(!t){let s=new Uint8Array(n);s[0]=5,s[1]=0}return e&&e.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};ic=fr;A.Null=ic;fr.NAME="NULL";var Kn=class extends be(Et){constructor({value:t,...e}={}){super(e),e.valueHex?this.valueHexView=M.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=M.BufferSourceConverter.toUint8Array(t);return ye(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,oi.call(this),this.blockLength=n,e+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};Kn.NAME="BooleanValueBlock";var ac,$n=class extends gt{constructor(t={}){super(t,Kn),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}`}};ac=$n;A.Boolean=ac;$n.NAME="BOOLEAN";var qn=class extends be(Qt){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=Qt.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===Hr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(i!==tc)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?Qt.prototype.toBER.call(this,t,e):t?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};qn.NAME="OctetStringValueBlock";var cc,zn=class r extends gt{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},qn),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=ws(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?Pe.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${M.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 M.BufferSourceConverter.concat(t)}};cc=zn;A.OctetString=cc;zn.NAME=tc;var Gn=class extends be(Qt){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=Qt.prototype.fromBER.call(this,t,e,n),s===-1)return s;for(let a of this.value){let c=a.constructor.NAME;if(c===Hr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==ec)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=M.BufferSourceConverter.toUint8Array(t);if(!ye(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=ws(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 Qt.prototype.toBER.call(this,t,e);if(t)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return Wt;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}}};Gn.NAME="BitStringValueBlock";var lc,hr=class extends gt{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},Gn),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 Pe.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)}`}}};lc=hr;A.BitString=lc;hr.NAME=ec;var uc;function Zh(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,u=c<i?i:c,f=0;for(let h=u;h>=0;h--,f++){switch(!0){case f<a.length:l=o[i-f]+a[c-f]+e[0];break;default:l=o[i-f]+e[0]}switch(e[0]=l/10,!0){case f>=o.length:o=Rn(new Uint8Array([l%10]),o);break;default:o[i-f]=l%10}}return e[0]>0&&(o=Rn(e,o)),o}function Qa(r){if(r>=Mr.length)for(let t=Mr.length;t<=r;t++){let e=new Uint8Array([0]),n=Mr[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=Rn(e,n)),Mr.push(n)}return Mr[r]}function Yh(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,u=0;for(let f=c;f>=0;f--,u++)switch(l=o[i-u]-a[c-u]-e,!0){case l<0:e=1,o[i-u]=l+10;break;default:e=0,o[i-u]=l}if(e>0)for(let f=i-c+1;f>=0;f--,u++)if(l=o[i-u]-e,l<0)e=1,o[i-u]=l+10;else{e=0,o[i-u]=l;break}return o.slice()}var Kr=class extends be(Et){constructor({value:t,...e}={}){super(e),this._valueDec=0,e.valueHex&&this.setValueHex(),t!==void 0&&(this.valueDec=t)}setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=oi.call(this)))}set valueDec(t){this._valueDec=t,this.isHexOnly=!1,this.valueHexView=new Uint8Array(Ya(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=Yh(Qa(n),e),i="-";break;default:e=Zh(e,Qa(n))}n++,s>>=1}}for(let c=0;c<e.length;c++)e[c]&&(a=!0),a&&(i+=Xa.charAt(e[c]));return a===!1&&(i+=Xa.charAt(0)),i}};uc=Kr;Kr.NAME="IntegerValueBlock";Object.defineProperty(uc.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var fc,yt=class r extends gt{constructor(t={}){super(t,Kr),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return _n(),BigInt(this.valueBlock.toString())}static fromBigInt(t){_n();let e=BigInt(t),n=new Fr,s=e.toString(16).replace(/^-/,""),o=new Uint8Array(M.Convert.FromHex(s));if(e<0){let a=new Uint8Array(o.length+(o[0]&128?1:0));a[0]|=128;let l=BigInt(`0x${M.Convert.ToHex(a)}`)+e,u=M.BufferSourceConverter.toUint8Array(M.Convert.FromHex(l.toString(16)));u[0]|=128,n.write(u)}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()}`}};fc=yt;A.Integer=fc;yt.NAME="INTEGER";var hc,Wn=class extends yt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};hc=Wn;A.Enumerated=hc;Wn.NAME="ENUMERATED";var $r=class extends be(Et){constructor({valueDec:t=-1,isFirstSid:e=!1,...n}={}){super(n),this.valueDec=t,this.isFirstSid=e}fromBER(t,e,n){if(!n)return e;let s=M.BufferSourceConverter.toUint8Array(t);if(!ye(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=Ze(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),e+this.blockLength)}set valueBigInt(t){_n();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=_e(this.valueDec,7);if(e.byteLength===0)return this.error="Error during encoding SID value",Wt;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=M.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}}};$r.NAME="sidBlock";var jn=class extends Et{constructor({value:t=pr,...e}={}){super(e),this.value=[],t&&this.fromString(t)}fromBER(t,e,n){let s=e;for(;n>0;){let o=new $r;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,Wt;e.push(s)}return ii(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 $r;if(s>Number.MAX_SAFE_INTEGER){_n();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}};jn.NAME="ObjectIdentifierValueBlock";var dc,dr=class extends gt{constructor(t={}){super(t,jn),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()}}};dc=dr;A.ObjectIdentifier=dc;dr.NAME="OBJECT IDENTIFIER";var qr=class extends be(pe){constructor({valueDec:t=0,...e}={}){super(e),this.valueDec=t}fromBER(t,e,n){if(n===0)return e;let s=M.BufferSourceConverter.toUint8Array(t);if(!ye(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=Ze(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=_e(this.valueDec,7);if(e.byteLength===0)return this.error="Error during encoding SID value",Wt;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=M.Convert.ToHex(this.valueHexView):t=this.valueDec.toString(),t}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};qr.NAME="relativeSidBlock";var Zn=class extends Et{constructor({value:t=pr,...e}={}){super(e),this.value=[],t&&this.fromString(t)}fromBER(t,e,n){let s=e;for(;n>0;){let o=new 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,Wt;n.push(o)}return ii(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}};Zn.NAME="RelativeObjectIdentifierValueBlock";var pc,Yn=class extends gt{constructor(t={}){super(t,Zn),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()}}};pc=Yn;A.RelativeObjectIdentifier=pc;Yn.NAME="RelativeObjectIdentifier";var mc,me=class extends Pe{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};mc=me;A.Sequence=mc;me.NAME="SEQUENCE";var gc,Jn=class extends Pe{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};gc=Jn;A.Set=gc;Jn.NAME="SET";var Xn=class extends be(Et){constructor({...t}={}){super(t),this.isHexOnly=!0,this.value=pr}toJSON(){return{...super.toJSON(),value:this.value}}};Xn.NAME="StringValueBlock";var Qn=class extends Xn{};Qn.NAME="SimpleStringValueBlock";var kt=class extends Vn{constructor({...t}={}){super(t,Qn)}fromBuffer(t){this.valueBlock.value=String.fromCharCode.apply(null,M.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}};kt.NAME="SIMPLE STRING";var ts=class extends kt{fromBuffer(t){this.valueBlock.valueHexView=M.BufferSourceConverter.toUint8Array(t);try{this.valueBlock.value=M.Convert.ToUtf8String(t)}catch(e){this.warnings.push(`Error during "decodeURIComponent": ${e}, using raw string`),this.valueBlock.value=M.Convert.ToBinary(t)}}fromString(t){this.valueBlock.valueHexView=new Uint8Array(M.Convert.FromUtf8String(t)),this.valueBlock.value=t}};ts.NAME="Utf8StringValueBlock";var yc,ge=class extends ts{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};yc=ge;A.Utf8String=yc;ge.NAME="UTF8String";var es=class extends kt{fromBuffer(t){this.valueBlock.value=M.Convert.ToUtf16String(t),this.valueBlock.valueHexView=M.BufferSourceConverter.toUint8Array(t)}fromString(t){this.valueBlock.value=t,this.valueBlock.valueHexView=new Uint8Array(M.Convert.FromUtf16String(t))}};es.NAME="BmpStringValueBlock";var bc,rs=class extends es{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};bc=rs;A.BmpString=bc;rs.NAME="BMPString";var ns=class extends kt{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=_e(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}};ns.NAME="UniversalStringValueBlock";var wc,ss=class extends ns{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};wc=ss;A.UniversalString=wc;ss.NAME="UniversalString";var xc,os=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};xc=os;A.NumericString=xc;os.NAME="NumericString";var vc,is=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};vc=is;A.PrintableString=vc;is.NAME="PrintableString";var Ec,as=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};Ec=as;A.TeletexString=Ec;as.NAME="TeletexString";var Bc,cs=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};Bc=cs;A.VideotexString=Bc;cs.NAME="VideotexString";var Ac,ls=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};Ac=ls;A.IA5String=Ac;ls.NAME="IA5String";var Sc,us=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};Sc=us;A.GraphicString=Sc;us.NAME="GraphicString";var Ic,zr=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};Ic=zr;A.VisibleString=Ic;zr.NAME="VisibleString";var kc,fs=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};kc=fs;A.GeneralString=kc;fs.NAME="GeneralString";var Nc,hs=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};Nc=hs;A.CharacterString=Nc;hs.NAME="CharacterString";var Cc,Gr=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,M.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]=Ut(this.year<2e3?this.year-1900:this.year-2e3,2),e[1]=Ut(this.month,2),e[2]=Ut(this.day,2),e[3]=Ut(this.hour,2),e[4]=Ut(this.minute,2),e[5]=Ut(this.second,2),e[6]="Z",e.join("")}return super.toString(t)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}};Cc=Gr;A.UTCTime=Cc;Gr.NAME="UTCTime";var Tc,ds=class extends Gr{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 f=new Number(t[t.length-1]);if(isNaN(f.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 f=1,h=n.indexOf("+"),g="";if(h===-1&&(h=n.indexOf("-"),f=-1),h!==-1){if(g=n.substring(h+1),n=n.substring(0,h),g.length!==2&&g.length!==4)throw new Error("Wrong input string for conversion");let m=parseInt(g.substring(0,2),10);if(isNaN(m.valueOf()))throw new Error("Wrong input string for conversion");if(a=f*m,g.length===4){if(m=parseInt(g.substring(2,4),10),isNaN(m.valueOf()))throw new Error("Wrong input string for conversion");c=f*m}}}let l=n.indexOf(".");if(l===-1&&(l=n.indexOf(",")),l!==-1){let f=new Number(`0${n.substring(l)}`);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");o=f.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 f=60*o;this.minute=Math.floor(f),f=60*(f-this.minute),this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case s.length===12:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let f=60*o;this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case s.length===14:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let f=1e3*o;this.millisecond=Math.floor(f)}break;default:throw new Error("Wrong input string for conversion")}let u=i.exec(s);if(u===null)throw new Error("Wrong input string for conversion");for(let f=1;f<u.length;f++)switch(f){case 1:this.year=parseInt(u[f],10);break;case 2:this.month=parseInt(u[f],10);break;case 3:this.day=parseInt(u[f],10);break;case 4:this.hour=parseInt(u[f],10)+a;break;case 5:this.minute=parseInt(u[f],10)+c;break;case 6:this.second=parseInt(u[f],10);break;default:throw new Error("Wrong input string for conversion")}if(e===!1){let f=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=f.getUTCFullYear(),this.month=f.getUTCMonth(),this.day=f.getUTCDay(),this.hour=f.getUTCHours(),this.minute=f.getUTCMinutes(),this.second=f.getUTCSeconds(),this.millisecond=f.getUTCMilliseconds()}}toString(t="iso"){if(t==="iso"){let e=[];return e.push(Ut(this.year,4)),e.push(Ut(this.month,2)),e.push(Ut(this.day,2)),e.push(Ut(this.hour,2)),e.push(Ut(this.minute,2)),e.push(Ut(this.second,2)),this.millisecond!==0&&(e.push("."),e.push(Ut(this.millisecond,3))),e.push("Z"),e.join("")}return super.toString(t)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};Tc=ds;A.GeneralizedTime=Tc;ds.NAME="GeneralizedTime";var Lc,ps=class extends ge{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};Lc=ps;A.DATE=Lc;ps.NAME="DATE";var Uc,ms=class extends ge{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};Uc=ms;A.TimeOfDay=Uc;ms.NAME="TimeOfDay";var Rc,gs=class extends ge{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};Rc=gs;A.DateTime=Rc;gs.NAME="DateTime";var _c,ys=class extends ge{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};_c=ys;A.Duration=_c;ys.NAME="Duration";var Pc,bs=class extends ge{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};Pc=bs;A.TIME=Pc;bs.NAME="TIME";function et(r,t="utf8"){let e=Nn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Wr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},xs=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Oc={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new xs("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var Oe=Oc;async function Vc(r){let t=await Oe.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 Xh(t);return{privateKey:e[0],publicKey:e[1]}}async function Dc(r,t){let e=await Oe.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await Oe.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function Mc(r,t,e){let n=await Oe.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return Oe.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function Xh(r){if(r.privateKey==null||r.publicKey==null)throw new It("Private and public key are required");return Promise.all([Oe.get().subtle.exportKey("jwk",r.privateKey),Oe.get().subtle.exportKey("jwk",r.publicKey)])}function li(r){if(r.kty!=="RSA")throw new It("invalid key type");if(r.n==null)throw new It("invalid key modulus");return q(r.n,"base64url").length*8}var mr=class{type="RSA";_key;_raw;_multihash;constructor(t,e){this._key=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=jr.jwkToPkix(this._key)),this._raw}toMultihash(){return this._multihash}toCID(){return pt.createV1(114,this._multihash)}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,e){return Mc(this._key,e,t)}},Zr=class{type="RSA";_key;_raw;publicKey;constructor(t,e){this._key=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=jr.jwkToPkcs1(this._key)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}sign(t){return Dc(this._key,t)}};var vs=8192,ui=18;function Fc(r){let{result:t}=ci(r),e=t.valueBlock.value;return{n:te(e[1]),e:te(e[2]),d:te(e[3]),p:te(e[4]),q:te(e[5]),dp:te(e[6]),dq:te(e[7]),qi:te(e[8]),kty:"RSA",alg:"RS256"}}function Qh(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 It("JWK was missing components");let e=new me({value:[new yt({value:0}),yt.fromBigInt(ee(q(r.n,"base64url"))),yt.fromBigInt(ee(q(r.e,"base64url"))),yt.fromBigInt(ee(q(r.d,"base64url"))),yt.fromBigInt(ee(q(r.p,"base64url"))),yt.fromBigInt(ee(q(r.q,"base64url"))),yt.fromBigInt(ee(q(r.dp,"base64url"))),yt.fromBigInt(ee(q(r.dq,"base64url"))),yt.fromBigInt(ee(q(r.qi,"base64url")))]}).toBER();return new Uint8Array(e,0,e.byteLength)}function Hc(r){let{result:t}=ci(r),e=t.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:te(e[0]),e:te(e[1])}}function fi(r){if(r.n==null||r.e==null)throw new It("JWK was missing components");let e=new me({value:[new me({value:[new dr({value:"1.2.840.113549.1.1.1"}),new fr]}),new hr({valueHex:new me({value:[yt.fromBigInt(ee(q(r.n,"base64url"))),yt.fromBigInt(ee(q(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(e,0,e.byteLength)}function te(r){let t=r.valueBlock.valueHexView;for(;t[0]===0;)t=t.subarray(1);return et(t,"base64url")}function ee(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(""))}function Kc(r){let t=Fc(r);return $c(t)}function hi(r){let t=Hc(r);if(li(t)>vs)throw new Xe("Key size is too large");let e=lr(Xt.encode({Type:lt.RSA,Data:r})),n=Mt(ui,e);return new mr(t,n)}function $c(r){if(li(r)>vs)throw new It("Key size is too large");let t=zc(r),e=lr(Xt.encode({Type:lt.RSA,Data:fi(t.publicKey)})),n=Mt(ui,e);return new Zr(t.privateKey,new mr(t.publicKey,n))}async function qc(r){if(r>vs)throw new It("Key size is too large");let t=await Vc(r),e=lr(Xt.encode({Type:lt.RSA,Data:fi(t.publicKey)})),n=Mt(ui,e);return new Zr(t.privateKey,new mr(t.publicKey,n))}function zc(r){if(r==null)throw new It("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}var Es=class extends or{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,pa(t);let n=Lr(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),nr(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()}},di=(r,t,e)=>new Es(r,t).update(e).digest();di.create=(r,t)=>new Es(r,t);function Gc(r){r.lowS!==void 0&&Ht("lowS",r.lowS),r.prehash!==void 0&&Ht("prehash",r.prehash)}function td(r){let t=_r(r);Jt(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:ed,hexToBytes:rd}=wn,we={Err:class extends Error{constructor(t=""){super(t)}},_tlv:{encode:(r,t)=>{let{Err:e}=we;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,s=He(n);if(s.length/2&128)throw new e("tlv.encode: long form length too big");let o=n>127?He(s.length/2|128):"";return`${He(r)}${o}${s}${t}`},decode(r,t){let{Err:e}=we,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let s=t[n++],o=!!(s&128),i=0;if(!o)i=s;else{let c=s&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let l=t.subarray(n,n+c);if(l.length!==c)throw new e("tlv.decode: length bytes not complete");if(l[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let u of l)i=i<<8|u;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=we;if(r<xe)throw new t("integer: negative integers are not allowed");let e=He(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected assertion");return e},decode(r){let{Err:t}=we;if(r[0]&128)throw new t("Invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("Invalid signature integer: unnecessary leading zero");return ed(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=we,s=typeof r=="string"?rd(r):r;ar(s);let{v:o,l:i}=n.decode(48,s);if(i.length)throw new t("Invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,o),{v:l,l:u}=n.decode(2,c);if(u.length)throw new t("Invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(l)}},hexFromSig(r){let{_tlv:t,_int:e}=we,n=`${t.encode(2,e.encode(r.r))}${t.encode(2,e.encode(r.s))}`;return t.encode(48,n)}},xe=BigInt(0),ht=BigInt(1),Ug=BigInt(2),Wc=BigInt(3),Rg=BigInt(4);function nd(r){let t=td(r),{Fp:e}=t,n=Ce(t.n,t.nBitLength),s=t.toBytes||((b,d,x)=>{let B=d.toAffine();return fe(Uint8Array.from([4]),e.toBytes(B.x),e.toBytes(B.y))}),o=t.fromBytes||(b=>{let d=b.subarray(1),x=e.fromBytes(d.subarray(0,e.BYTES)),B=e.fromBytes(d.subarray(e.BYTES,2*e.BYTES));return{x,y:B}});function i(b){let{a:d,b:x}=t,B=e.sqr(b),y=e.mul(B,b);return e.add(e.add(y,e.mul(b,d)),x)}if(!e.eql(e.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function a(b){return Ur(b,ht,t.n)}function c(b){let{allowedPrivateKeyLengths:d,nByteLength:x,wrapPrivateKey:B,n:y}=t;if(d&&typeof b!="bigint"){if(Ie(b)&&(b=le(b)),typeof b!="string"||!d.includes(b.length))throw new Error("Invalid key");b=b.padStart(x*2,"0")}let S;try{S=typeof b=="bigint"?b:ue(st("private key",b,x))}catch{throw new Error(`private key must be ${x} bytes, hex or bigint, not ${typeof b}`)}return B&&(S=Z(S,y)),Ct("private key",S,ht,y),S}function l(b){if(!(b instanceof h))throw new Error("ProjectivePoint expected")}let u=qe((b,d)=>{let{px:x,py:B,pz:y}=b;if(e.eql(y,e.ONE))return{x,y:B};let S=b.is0();d==null&&(d=S?e.ONE:e.inv(y));let U=e.mul(x,d),L=e.mul(B,d),I=e.mul(y,d);if(S)return{x:e.ZERO,y:e.ZERO};if(!e.eql(I,e.ONE))throw new Error("invZ was invalid");return{x:U,y:L}}),f=qe(b=>{if(b.is0()){if(t.allowInfinityPoint&&!e.is0(b.py))return;throw new Error("bad point: ZERO")}let{x:d,y:x}=b.toAffine();if(!e.isValid(d)||!e.isValid(x))throw new Error("bad point: x or y not FE");let B=e.sqr(x),y=i(d);if(!e.eql(B,y))throw new Error("bad point: equation left != right");if(!b.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class h{constructor(d,x,B){if(this.px=d,this.py=x,this.pz=B,d==null||!e.isValid(d))throw new Error("x required");if(x==null||!e.isValid(x))throw new Error("y required");if(B==null||!e.isValid(B))throw new Error("z required");Object.freeze(this)}static fromAffine(d){let{x,y:B}=d||{};if(!d||!e.isValid(x)||!e.isValid(B))throw new Error("invalid affine point");if(d instanceof h)throw new Error("projective point not allowed");let y=S=>e.eql(S,e.ZERO);return y(x)&&y(B)?h.ZERO:new h(x,B,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){let x=e.invertBatch(d.map(B=>B.pz));return d.map((B,y)=>B.toAffine(x[y])).map(h.fromAffine)}static fromHex(d){let x=h.fromAffine(o(st("pointHex",d)));return x.assertValidity(),x}static fromPrivateKey(d){return h.BASE.multiply(c(d))}static msm(d,x){return En(h,n,d,x)}_setWindowSize(d){m.setWindowSize(this,d)}assertValidity(){f(this)}hasEvenY(){let{y:d}=this.toAffine();if(e.isOdd)return!e.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){l(d);let{px:x,py:B,pz:y}=this,{px:S,py:U,pz:L}=d,I=e.eql(e.mul(x,L),e.mul(S,y)),k=e.eql(e.mul(B,L),e.mul(U,y));return I&&k}negate(){return new h(this.px,e.neg(this.py),this.pz)}double(){let{a:d,b:x}=t,B=e.mul(x,Wc),{px:y,py:S,pz:U}=this,L=e.ZERO,I=e.ZERO,k=e.ZERO,T=e.mul(y,y),ot=e.mul(S,S),$=e.mul(U,U),O=e.mul(y,S);return O=e.add(O,O),k=e.mul(y,U),k=e.add(k,k),L=e.mul(d,k),I=e.mul(B,$),I=e.add(L,I),L=e.sub(ot,I),I=e.add(ot,I),I=e.mul(L,I),L=e.mul(O,L),k=e.mul(B,k),$=e.mul(d,$),O=e.sub(T,$),O=e.mul(d,O),O=e.add(O,k),k=e.add(T,T),T=e.add(k,T),T=e.add(T,$),T=e.mul(T,O),I=e.add(I,T),$=e.mul(S,U),$=e.add($,$),T=e.mul($,O),L=e.sub(L,T),k=e.mul($,ot),k=e.add(k,k),k=e.add(k,k),new h(L,I,k)}add(d){l(d);let{px:x,py:B,pz:y}=this,{px:S,py:U,pz:L}=d,I=e.ZERO,k=e.ZERO,T=e.ZERO,ot=t.a,$=e.mul(t.b,Wc),O=e.mul(x,S),it=e.mul(B,U),E=e.mul(y,L),N=e.add(x,B),w=e.add(S,U);N=e.mul(N,w),w=e.add(O,it),N=e.sub(N,w),w=e.add(x,y);let p=e.add(S,L);return w=e.mul(w,p),p=e.add(O,E),w=e.sub(w,p),p=e.add(B,y),I=e.add(U,L),p=e.mul(p,I),I=e.add(it,E),p=e.sub(p,I),T=e.mul(ot,w),I=e.mul($,E),T=e.add(I,T),I=e.sub(it,T),T=e.add(it,T),k=e.mul(I,T),it=e.add(O,O),it=e.add(it,O),E=e.mul(ot,E),w=e.mul($,w),it=e.add(it,E),E=e.sub(O,E),E=e.mul(ot,E),w=e.add(w,E),O=e.mul(it,w),k=e.add(k,O),O=e.mul(p,w),I=e.mul(N,I),I=e.sub(I,O),O=e.mul(N,it),T=e.mul(p,T),T=e.add(T,O),new h(I,k,T)}subtract(d){return this.add(d.negate())}is0(){return this.equals(h.ZERO)}wNAF(d){return m.wNAFCached(this,d,h.normalizeZ)}multiplyUnsafe(d){Ct("scalar",d,xe,t.n);let x=h.ZERO;if(d===xe)return x;if(d===ht)return this;let{endo:B}=t;if(!B)return m.unsafeLadder(this,d);let{k1neg:y,k1:S,k2neg:U,k2:L}=B.splitScalar(d),I=x,k=x,T=this;for(;S>xe||L>xe;)S&ht&&(I=I.add(T)),L&ht&&(k=k.add(T)),T=T.double(),S>>=ht,L>>=ht;return y&&(I=I.negate()),U&&(k=k.negate()),k=new h(e.mul(k.px,B.beta),k.py,k.pz),I.add(k)}multiply(d){let{endo:x,n:B}=t;Ct("scalar",d,ht,B);let y,S;if(x){let{k1neg:U,k1:L,k2neg:I,k2:k}=x.splitScalar(d),{p:T,f:ot}=this.wNAF(L),{p:$,f:O}=this.wNAF(k);T=m.constTimeNegate(U,T),$=m.constTimeNegate(I,$),$=new h(e.mul($.px,x.beta),$.py,$.pz),y=T.add($),S=ot.add(O)}else{let{p:U,f:L}=this.wNAF(d);y=U,S=L}return h.normalizeZ([y,S])[0]}multiplyAndAddUnsafe(d,x,B){let y=h.BASE,S=(L,I)=>I===xe||I===ht||!L.equals(y)?L.multiplyUnsafe(I):L.multiply(I),U=S(this,x).add(S(d,B));return U.is0()?void 0:U}toAffine(d){return u(this,d)}isTorsionFree(){let{h:d,isTorsionFree:x}=t;if(d===ht)return!0;if(x)return x(h,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:d,clearCofactor:x}=t;return d===ht?this:x?x(h,this):this.multiplyUnsafe(t.h)}toRawBytes(d=!0){return Ht("isCompressed",d),this.assertValidity(),s(h,this,d)}toHex(d=!0){return Ht("isCompressed",d),le(this.toRawBytes(d))}}h.BASE=new h(t.Gx,t.Gy,e.ONE),h.ZERO=new h(e.ZERO,e.ONE,e.ZERO);let g=t.nBitLength,m=vn(h,t.endo?Math.ceil(g/2):g);return{CURVE:t,ProjectivePoint:h,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:a}}function sd(r){let t=_r(r);return Jt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function jc(r){let t=sd(r),{Fp:e,n}=t,s=e.BYTES+1,o=2*e.BYTES+1;function i(E){return Z(E,n)}function a(E){return xn(E,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:l,weierstrassEquation:u,isWithinCurveOrder:f}=nd({...t,toBytes(E,N,w){let p=N.toAffine(),v=e.toBytes(p.x),C=fe;return Ht("isCompressed",w),w?C(Uint8Array.from([N.hasEvenY()?2:3]),v):C(Uint8Array.from([4]),v,e.toBytes(p.y))},fromBytes(E){let N=E.length,w=E[0],p=E.subarray(1);if(N===s&&(w===2||w===3)){let v=ue(p);if(!Ur(v,ht,e.ORDER))throw new Error("Point is not on curve");let C=u(v),R;try{R=e.sqrt(C)}catch(F){let D=F instanceof Error?": "+F.message:"";throw new Error("Point is not on curve"+D)}let _=(R&ht)===ht;return(w&1)===1!==_&&(R=e.neg(R)),{x:v,y:R}}else if(N===o&&w===4){let v=e.fromBytes(p.subarray(0,e.BYTES)),C=e.fromBytes(p.subarray(e.BYTES,2*e.BYTES));return{x:v,y:C}}else throw new Error(`Point of length ${N} was invalid. Expected ${s} compressed bytes or ${o} uncompressed bytes`)}}),h=E=>le(Ne(E,t.nByteLength));function g(E){let N=n>>ht;return E>N}function m(E){return g(E)?i(-E):E}let b=(E,N,w)=>ue(E.slice(N,w));class d{constructor(N,w,p){this.r=N,this.s=w,this.recovery=p,this.assertValidity()}static fromCompact(N){let w=t.nByteLength;return N=st("compactSignature",N,w*2),new d(b(N,0,w),b(N,w,2*w))}static fromDER(N){let{r:w,s:p}=we.toSig(st("DER",N));return new d(w,p)}assertValidity(){Ct("r",this.r,ht,n),Ct("s",this.s,ht,n)}addRecoveryBit(N){return new d(this.r,this.s,N)}recoverPublicKey(N){let{r:w,s:p,recovery:v}=this,C=L(st("msgHash",N));if(v==null||![0,1,2,3].includes(v))throw new Error("recovery id invalid");let R=v===2||v===3?w+t.n:w;if(R>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let _=v&1?"03":"02",V=c.fromHex(_+h(R)),F=a(R),D=i(-C*F),j=i(p*F),J=c.BASE.multiplyAndAddUnsafe(V,D,j);if(!J)throw new Error("point at infinify");return J.assertValidity(),J}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new d(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return Ke(this.toDERHex())}toDERHex(){return we.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Ke(this.toCompactHex())}toCompactHex(){return h(this.r)+h(this.s)}}let x={isValidPrivateKey(E){try{return l(E),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let E=wo(t.n);return ka(t.randomBytes(E),t.n)},precompute(E=8,N=c.BASE){return N._setWindowSize(E),N.multiply(BigInt(3)),N}};function B(E,N=!0){return c.fromPrivateKey(E).toRawBytes(N)}function y(E){let N=Ie(E),w=typeof E=="string",p=(N||w)&&E.length;return N?p===s||p===o:w?p===2*s||p===2*o:E instanceof c}function S(E,N,w=!0){if(y(E))throw new Error("first arg must be private key");if(!y(N))throw new Error("second arg must be public key");return c.fromHex(N).multiply(l(E)).toRawBytes(w)}let U=t.bits2int||function(E){let N=ue(E),w=E.length*8-t.nBitLength;return w>0?N>>BigInt(w):N},L=t.bits2int_modN||function(E){return i(U(E))},I=Rr(t.nBitLength);function k(E){return Ct(`num < 2^${t.nBitLength}`,E,xe,I),Ne(E,t.nByteLength)}function T(E,N,w=ot){if(["recovered","canonical"].some(ft=>ft in w))throw new Error("sign() legacy options not supported");let{hash:p,randomBytes:v}=t,{lowS:C,prehash:R,extraEntropy:_}=w;C==null&&(C=!0),E=st("msgHash",E),Gc(w),R&&(E=st("prehashed msgHash",p(E)));let V=L(E),F=l(N),D=[k(F),k(V)];if(_!=null&&_!==!1){let ft=_===!0?v(e.BYTES):_;D.push(st("extraEntropy",ft))}let j=fe(...D),J=V;function ut(ft){let dt=U(ft);if(!f(dt))return;let At=a(dt),at=c.BASE.multiply(dt).toAffine(),Nt=i(at.x);if(Nt===xe)return;let se=i(At*i(J+Nt*F));if(se===xe)return;let Ar=(at.x===Nt?0:2)|Number(at.y&ht),Sr=se;return C&&g(se)&&(Sr=m(se),Ar^=1),new d(Nt,Sr,Ar)}return{seed:j,k2sig:ut}}let ot={lowS:t.lowS,prehash:!1},$={lowS:t.lowS,prehash:!1};function O(E,N,w=ot){let{seed:p,k2sig:v}=T(E,N,w),C=t;return mo(C.hash.outputLen,C.nByteLength,C.hmac)(p,v)}c.BASE._setWindowSize(8);function it(E,N,w,p=$){let v=E;if(N=st("msgHash",N),w=st("publicKey",w),"strict"in p)throw new Error("options.strict was renamed to lowS");Gc(p);let{lowS:C,prehash:R}=p,_,V;try{if(typeof v=="string"||Ie(v))try{_=d.fromDER(v)}catch(at){if(!(at instanceof we.Err))throw at;_=d.fromCompact(v)}else if(typeof v=="object"&&typeof v.r=="bigint"&&typeof v.s=="bigint"){let{r:at,s:Nt}=v;_=new d(at,Nt)}else throw new Error("PARSE");V=c.fromHex(w)}catch(at){if(at.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(C&&_.hasHighS())return!1;R&&(N=t.hash(N));let{r:F,s:D}=_,j=L(N),J=a(D),ut=i(j*J),ft=i(F*J),dt=c.BASE.multiplyAndAddUnsafe(V,ut,ft)?.toAffine();return dt?i(dt.x)===F:!1}return{CURVE:t,getPublicKey:B,getSharedSecret:S,sign:O,verify:it,ProjectivePoint:c,Signature:d,utils:x}}function od(r){return{hash:r,hmac:(t,...e)=>di(r,t,io(...e)),randomBytes:gn}}function Zc(r,t){let e=n=>jc({...r,...od(n)});return Object.freeze({...e(t),create:e})}var Xc=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Yc=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),id=BigInt(1),pi=BigInt(2),Jc=(r,t)=>(r+t/pi)/t;function ad(r){let t=Xc,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,u=l*l*r%t,f=tt(u,e,t)*u%t,h=tt(f,e,t)*u%t,g=tt(h,pi,t)*l%t,m=tt(g,s,t)*g%t,b=tt(m,o,t)*m%t,d=tt(b,a,t)*b%t,x=tt(d,c,t)*d%t,B=tt(x,a,t)*b%t,y=tt(B,e,t)*u%t,S=tt(y,i,t)*m%t,U=tt(S,n,t)*l%t,L=tt(U,pi,t);if(!mi.eql(mi.sqr(L),r))throw new Error("Cannot find square root");return L}var mi=Ce(Xc,void 0,void 0,{sqrt:ad}),Ye=Zc({a:BigInt(0),b:BigInt(7),Fp:mi,n:Yc,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Yc,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-id*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=e,i=BigInt("0x100000000000000000000000000000000"),a=Jc(o*r,t),c=Jc(-n*r,t),l=Z(r-a*e-c*s,t),u=Z(-a*n-c*o,t),f=l>i,h=u>i;if(f&&(l=t-l),h&&(u=t-u),l>i||u>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:l,k2neg:h,k2:u}}}},lr),Kg=BigInt(0);var $g=Ye.ProjectivePoint;function Pt(r,t){t==null&&(t=r.reduce((s,o)=>s+o.length,0));let e=Lt(t),n=0;for(let s of r)e.set(s,n),n+=s.length;return e}function Qc(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function tl(r,t,e){let n=Pr.digest(e instanceof Uint8Array?e:e.subarray());if(Qc(n))return n.then(({digest:s})=>Ye.verify(t,s,r)).catch(s=>{throw new Wr(String(s))});try{return Ye.verify(t,n.digest,r)}catch(s){throw new Wr(String(s))}}var Bs=class{type="secp256k1";raw;_key;constructor(t){this._key=rl(t),this.raw=el(this._key)}toMultihash(){return ae.digest(Te(this))}toCID(){return pt.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,e){return tl(this._key,e,t)}};function gi(r){return new Bs(r)}function el(r){return Ye.ProjectivePoint.fromHex(r).toRawBytes(!0)}function rl(r){try{return Ye.ProjectivePoint.fromHex(r),r}catch(t){throw new Xe(String(t))}}function gr(r){let{Type:t,Data:e}=Xt.decode(r),n=e??new Uint8Array;switch(t){case lt.RSA:return hi(n);case lt.Ed25519:return Ao(n);case lt.secp256k1:return gi(n);default:throw new De}}function nl(r){let{Type:t,Data:e}=Xt.decode(r.digest),n=e??new Uint8Array;switch(t){case lt.Ed25519:return Ao(n);case lt.secp256k1:return gi(n);default:throw new De}}function Te(r){return Xt.encode({Type:lt[r.type],Data:r.raw})}var ol=Symbol.for("@achingbrain/uint8arraylist");function sl(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 As(r){return!!r?.[ol]}var jt=class r{bufs;length;[ol]=!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(As(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(As(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=sl(this.bufs,t);return e.buf[e.index]}set(t,e){let n=sl(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(As(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 Pt(n,s)}subarray(t,e){let{bufs:n,length:s}=this._subList(t,e);return n.length===1?n[0]:Pt(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,u=e>a&&e<=c;if(l&&u){if(t===a&&e===c){n.push(i);break}let f=t-a;n.push(i.subarray(f,f+(e-t)));break}if(l){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(u){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(!As(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 f=0;f<o;f++)i[f]=-1;for(let f=0;f<s;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,l=n.byteLength-1,u;for(let f=e;f<=c;f+=u){u=0;for(let h=l;h>=0;h--){let g=this.get(f+h);if(n[h]!==g){u=Math.max(1,h-a[g]);break}}if(u===0)return f}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=Lt(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=mt(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=mt(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=mt(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=Lt(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=mt(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=mt(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=mt(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=mt(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=mt(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}};var Yr;(function(r){let t;r.codec=()=>(t==null&&(t=Gt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.publicKey!=null&&e.publicKey.byteLength>0&&(n.uint32(10),n.bytes(e.publicKey)),e.payloadType!=null&&e.payloadType.byteLength>0&&(n.uint32(18),n.bytes(e.payloadType)),e.payload!=null&&e.payload.byteLength>0&&(n.uint32(26),n.bytes(e.payload)),e.signature!=null&&e.signature.byteLength>0&&(n.uint32(42),n.bytes(e.signature)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let o={publicKey:mt(0),payloadType:mt(0),payload:mt(0),signature:mt(0)},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{o.publicKey=e.bytes();break}case 2:{o.payloadType=e.bytes();break}case 3:{o.payload=e.bytes();break}case 5:{o.signature=e.bytes();break}default:{e.skipType(a&7);break}}}return o})),t),r.encode=e=>zt(e,r.codec()),r.decode=(e,n)=>qt(e,r.codec(),n)})(Yr||(Yr={}));var Ss=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var re=class r{static createFromProtobuf=async t=>{let e=Yr.decode(t),n=gr(e.publicKey);return new r({publicKey:n,payloadType:e.payloadType,payload:e.payload,signature:e.signature})};static seal=async(t,e)=>{if(e==null)throw new Error("Missing private key");let n=t.domain,s=t.codec,o=t.marshal(),i=il(n,s,o),a=await e.sign(i.subarray());return new r({publicKey:e.publicKey,payloadType:s,payload:o,signature:a})};static openAndCertify=async(t,e)=>{let n=await r.createFromProtobuf(t);if(!await n.validate(e))throw new Ss("Envelope signature is not valid for the given domain");return n};publicKey;payloadType;payload;signature;marshaled;constructor(t){let{publicKey:e,payloadType:n,payload:s,signature:o}=t;this.publicKey=e,this.payloadType=n,this.payload=s,this.signature=o}marshal(){return this.marshaled==null&&(this.marshaled=Yr.encode({publicKey:Te(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return bt(this.marshal(),t.marshal())}async validate(t){let e=il(t,this.payloadType,this.payload);return this.publicKey.verify(e.subarray(),this.signature)}},il=(r,t,e)=>{let n=q(r),s=Ot(n.byteLength),o=Ot(t.length),i=Ot(e.length);return new jt(s,n,o,t,i,e)};var al=Symbol.for("nodejs.util.inspect.custom"),cd=114,Jr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Zs]=!0;toString(){return this.string==null&&(this.string=X.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return pt.createV1(cd,this.multihash)}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 this.toString()===t;if(t?.toMultihash()?.bytes!=null)return bt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[al](){return`PeerId(${this.toString()})`}},Xr=class extends Jr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Qr=class extends Jr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},tn=class extends Jr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},ld=2336,en=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=ae.digest(q(this.url))}[al](){return`PeerId(${this.url})`}[Zs]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return pt.createV1(ld,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=et(t)),t.toString()===this.toString())}};var ud=114,cl=2336;function ll(r){if(r.type==="Ed25519")return new Qr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new tn({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new Xr({multihash:r.toCID().multihash,publicKey:r});throw new De}function yi(r){if(hd(r))return new Xr({multihash:r});if(fd(r))try{let t=nl(r);if(t.type==="Ed25519")return new Qr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new tn({multihash:r,publicKey:t})}catch{let e=et(r.digest);return new en(new URL(e))}throw new un("Supplied PeerID Multihash is invalid")}function Is(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==ud&&r.code!==cl)throw new ln("Supplied PeerID CID is invalid");if(r.code===cl){let t=et(r.multihash.digest);return new en(new URL(t))}return yi(r.multihash)}function fd(r){return r.code===ae.code}function hd(r){return r.code===Pr.code}function ul(r,t){let e=(n,s)=>n.toString().localeCompare(s.toString());return r.length!==t.length?!1:(t.sort(e),r.sort(e).every((n,s)=>t[s].equals(n)))}var ks=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 u=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let h=Number.parseInt(f,t);if(!Number.isNaN(h))return h});if(u===void 0)break;if(o*=t,o+=u,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 fl=45,dd=15,yr=new ks;function bi(r){if(!(r.length>dd))return yr.new(r).parseWith(()=>yr.readIPv4Addr())}function wi(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>fl))return yr.new(r).parseWith(()=>yr.readIPv6Addr())}function Ns(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>fl))return yr.new(r).parseWith(()=>yr.readIPAddr())}var xb=parseInt("0xFFFF",16),vb=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function br(r){return!!bi(r)}function wr(r){return!!wi(r)}function Cs(r){return!!Ns(r)}var pl=br,bd=wr,xi=function(r){let t=0;if(r=r.toString().trim(),pl(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(bd(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let o=pl(e[n]),i;o&&(i=xi(e[n]),e[n]=et(i.slice(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,et(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")},ml=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 xr={},vi={},xd=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];xd.forEach(r=>{let t=vd(...r);vi[t.code]=t,xr[t.name]=t});function vd(r,t,e,n,s){return{code:r,size:t,name:e,resolvable:!!n,path:!!s}}function z(r){if(typeof r=="number"){if(vi[r]!=null)return vi[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(xr[r]!=null)return xr[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var sw=z("ip4"),ow=z("ip6"),iw=z("ipcidr");function Si(r,t){switch(z(r).code){case 4:case 41:return Bd(t);case 42:return Ai(t);case 6:case 273:case 33:case 132:return bl(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Ai(t);case 421:return kd(t);case 444:return yl(t);case 445:return yl(t);case 466:return Id(t);case 481:return globalThis.encodeURIComponent(Ai(t));default:return et(t,"base16")}}function Ii(r,t){switch(z(r).code){case 4:return gl(t);case 41:return gl(t);case 42:return Bi(t);case 6:case 273:case 33:case 132:return ki(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Bi(t);case 421:return Ad(t);case 444:return Nd(t);case 445:return Cd(t);case 466:return Sd(t);case 481:return Bi(globalThis.decodeURIComponent(t));default:return q(t,"base16")}}var Ei=Object.values(Or).map(r=>r.decoder),Ed=function(){let r=Ei[0].or(Ei[1]);return Ei.slice(2).forEach(t=>r=r.or(t)),r}();function gl(r){if(!Cs(r))throw new Error("invalid ip address");return xi(r)}function Bd(r){let t=ml(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!Cs(t))throw new Error("invalid ip address");return t}function ki(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function bl(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Bi(r){let t=q(r),e=Uint8Array.from(Ot(t.length));return Pt([e,t],e.length+t.length)}function Ai(r){let t=he(r);if(r=r.slice(xt(t)),r.length!==t)throw new Error("inconsistent lengths");return et(r)}function Ad(r){let t;r[0]==="Q"||r[0]==="1"?t=Me(X.decode(`z${r}`)).bytes:t=pt.parse(r).multihash.bytes;let e=Uint8Array.from(Ot(t.length));return Pt([e,t],e.length+t.length)}function Sd(r){let t=Ed.decode(r),e=Uint8Array.from(Ot(t.length));return Pt([e,t],e.length+t.length)}function Id(r){let t=he(r),e=r.slice(xt(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+et(e,"base64url")}function kd(r){let t=he(r),e=r.slice(xt(t));if(e.length!==t)throw new Error("inconsistent lengths");return et(e,"base58btc")}function Nd(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=ie.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=ki(n);return Pt([e,s],e.length+s.length)}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!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=ie.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=ki(n);return Pt([e,s],e.length+s.length)}function yl(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=et(t,"base32"),s=bl(e);return`${n}:${s}`}function wl(r){r=Ni(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=z(i);if(a.size===0){t.push([a.code]),e.push([a.code]);continue}if(o++,o>=s.length)throw vl("invalid address: "+r);if(a.path===!0){n=Ni(s.slice(o).join("/")),t.push([a.code,Ii(a.code,n)]),e.push([a.code,n]);break}let c=Ii(a.code,s[o]);t.push([a.code,c]),e.push([a.code,Si(a.code,c)])}return{string:xl(e),bytes:Ti(t),tuples:t,stringTuples:e,path:n}}function Ci(r){let t=[],e=[],n=null,s=0;for(;s<r.length;){let o=he(r,s),i=xt(o),a=z(o),c=Td(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 vl("Invalid address Uint8Array: "+et(r,"base16"));t.push([o,l]);let u=Si(o,l);if(e.push([o,u]),a.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:xl(e),tuples:t,stringTuples:e,path:n}}function xl(r){let t=[];return r.map(e=>{let n=z(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),Ni(t.join("/"))}function Ti(r){return Pt(r.map(t=>{let e=z(t[0]),n=Uint8Array.from(Ot(e.code));return t.length>1&&t[1]!=null&&(n=Pt([n,t[1]])),n}))}function Td(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=he(t instanceof Uint8Array?t:Uint8Array.from(t));return e+xt(e)}}function Ni(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}function vl(r){return new Error("Error parsing address: "+r)}var Ld=Symbol.for("nodejs.util.inspect.custom"),Ui=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Ud=[z("dns").code,z("dns4").code,z("dns6").code,z("dnsaddr").code],Li=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},Ts=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=wl(t)}else if(Bl(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=z("tcp"),a=z("udp"),c=z("ip4"),l=z("ip6"),u=z("dns6"),f=z("ip6zone");for(let[g,m]of this.stringTuples())g===f.code&&(o=`%${m??""}`),Ud.includes(g)&&(e=i.name,s=443,n=`${m??""}${o}`,t=g===u.code?6:4),(g===i.code||g===a.code)&&(e=z(g).name,s=parseInt(m??"")),(g===c.code||g===l.code)&&(e=z(g).name,n=`${m??""}${o}`,t=g===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({},z(t)))}protoCodes(){return this.#t.map(([t])=>t)}protoNames(){return this.#t.map(([t])=>z(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(Ti(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,s])=>{n===xr.p2p.code&&t.push([n,s]),n===xr["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?et(X.decode(`z${n}`),"base58btc"):et(pt.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 Li(`no available resolver for ${e.name}`);return(await n(this,t)).map(o=>ne(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)}[Ld](){return`Multiaddr(${this.#e})`}};var El=new Map;function Bl(r){return!!r?.[Ui]}function ne(r){return new Ts(r)}var Al="libp2p-peer-record",Sl=Uint8Array.from([3,1]);var rn;(function(r){let t;(function(n){let s;n.codec=()=>(s==null&&(s=Gt((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.multiaddr!=null&&o.multiaddr.byteLength>0&&(i.uint32(10),i.bytes(o.multiaddr)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={multiaddr:mt(0)},l=i==null?o.len:o.pos+i;for(;o.pos<l;){let u=o.uint32();switch(u>>>3){case 1:{c.multiaddr=o.bytes();break}default:{o.skipType(u&7);break}}}return c})),s),n.encode=o=>zt(o,n.codec()),n.decode=(o,i)=>qt(o,n.codec(),i)})(t=r.AddressInfo||(r.AddressInfo={}));let e;r.codec=()=>(e==null&&(e=Gt((n,s,o={})=>{if(o.lengthDelimited!==!1&&s.fork(),n.peerId!=null&&n.peerId.byteLength>0&&(s.uint32(10),s.bytes(n.peerId)),n.seq!=null&&n.seq!==0n&&(s.uint32(16),s.uint64(n.seq)),n.addresses!=null)for(let i of n.addresses)s.uint32(26),r.AddressInfo.codec().encode(i,s);o.lengthDelimited!==!1&&s.ldelim()},(n,s,o={})=>{let i={peerId:mt(0),seq:0n,addresses:[]},a=s==null?n.len:n.pos+s;for(;n.pos<a;){let c=n.uint32();switch(c>>>3){case 1:{i.peerId=n.bytes();break}case 2:{i.seq=n.uint64();break}case 3:{if(o.limits?.addresses!=null&&i.addresses.length===o.limits.addresses)throw new je('Decode error - map field "addresses" had too many elements');i.addresses.push(r.AddressInfo.codec().decode(n,n.uint32(),{limits:o.limits?.addresses$}));break}default:{n.skipType(c&7);break}}}return i})),e),r.encode=n=>zt(n,r.codec()),r.decode=(n,s)=>qt(n,r.codec(),s)})(rn||(rn={}));var Zt=class r{static createFromProtobuf=t=>{let e=rn.decode(t),n=yi(Me(e.peerId)),s=(e.addresses??[]).map(i=>ne(i.multiaddr)),o=e.seq;return new r({peerId:n,multiaddrs:s,seqNumber:o})};static DOMAIN=Al;static CODEC=Sl;peerId;multiaddrs;seqNumber;domain=r.DOMAIN;codec=r.CODEC;marshaled;constructor(t){let{peerId:e,multiaddrs:n,seqNumber:s}=t;this.peerId=e,this.multiaddrs=n??[],this.seqNumber=s??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=rn.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(t=>({multiaddr:t.bytes}))})),this.marshaled}equals(t){return!(!(t instanceof r)||!this.peerId.equals(t.peerId)||this.seqNumber!==t.seqNumber||!ul(this.multiaddrs,t.multiaddrs))}};function Rd(r){return r[Symbol.asyncIterator]!=null}function _d(r){if(Rd(r))return(async()=>{for await(let t of r);})();for(let t of r);}var Il=_d;function Yt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Ls=globalThis.CustomEvent??Event;async function*Ri(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=Yt(),a=Yt(),c=!1,l,u=!1;s.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let m of r){if(o.length===e&&(i=Yt(),await i.promise),u)break;let b={done:!1};o.push(b),m().then(d=>{b.done=!0,b.ok=!0,b.value=d,s.dispatchEvent(new Ls("task-complete"))},d=>{b.done=!0,b.err=d,s.dispatchEvent(new Ls("task-complete"))})}c=!0,s.dispatchEvent(new Ls("task-complete"))}catch(m){l=m,s.dispatchEvent(new Ls("task-complete"))}});function f(){return n?o[0]?.done:!!o.find(m=>m.done)}function*h(){for(;o.length>0&&o[0].done;){let m=o[0];if(o.shift(),m.ok)yield m.value;else throw u=!0,i.resolve(),m.err;i.resolve()}}function*g(){for(;f();)for(let m=0;m<o.length;m++)if(o[m].done){let b=o[m];if(o.splice(m,1),m--,b.ok)yield b.value;else throw u=!0,i.resolve(),b.err;i.resolve()}}for(;;){if(f()||(a=Yt(),await a.promise),l!=null)throw l;if(n?yield*h():yield*g(),c&&o.length===0)break}}var Us=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function kl(r,t,e){if(t==null)return r;if(t.aborted)return Promise.reject(new Us(e?.errorMessage,e?.errorCode,e?.errorName));let n,s=new Us(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((o,i)=>{n=()=>{i(s)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var _i=class{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=Yt(),this.haveNext=Yt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Yt(),t}async throw(t){return this.ended=!0,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return await this._push(void 0),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Yt(),await kl(this.readNext.promise,e?.signal,e)}};function Nl(){return new _i}var Rs=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};var Pi=class extends Error{code;constructor(t,e){super(t),this.code=e}},Oi=class extends Pi{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted",this.name="AbortError"}};function Cl(r,t){let e=Nl();r.sink(e).catch(async i=>{await e.end(i)}),r.sink=async i=>{for await(let a of i)await e.push(a);await e.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let s=new jt;return{read:async(i,a)=>{a?.signal?.throwIfAborted();let c,l=new Promise((u,f)=>{c=()=>{f(new Oi("Read aborted"))},a?.signal?.addEventListener("abort",c)});try{if(i==null){let{done:f,value:h}=await Promise.race([n.next(),l]);return f===!0?new jt:h}for(;s.byteLength<i;){let{value:f,done:h}=await Promise.race([n.next(),l]);if(h===!0)throw new Rs("unexpected end of input");s.append(f)}let u=s.sublist(0,i);return s.consume(i),u}finally{c!=null&&a?.signal?.removeEventListener("abort",c)}},write:async(i,a)=>{a?.signal?.throwIfAborted(),i instanceof Uint8Array?await e.push(i,a):await e.push(i.subarray(),a)},unwrap:()=>{if(s.byteLength>0){let i=r.source;r.source=async function*(){t?.yieldBytes===!1?yield s:yield*s,yield*i}()}return r}}}var _s=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Ps=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Os=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Tl(r,t={}){let e=Cl(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=xt(t.maxDataLength));let n=t?.lengthDecoder??he,s=t?.lengthEncoder??Ot;return{read:async i=>{let a=-1,c=new jt;for(;;){c.append(await e.read(1,i));try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new _s("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new Os("message length length too long");if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new Ps("message length too long");return e.read(a,i)},write:async(i,a)=>{await e.write(new jt(s(i.byteLength),i),a)},writeV:async(i,a)=>{let c=new jt(...i.flatMap(l=>[s(l.byteLength),l]));await e.write(c,a)},unwrap:()=>e.unwrap()}}function vr(r,t){let e=Tl(r,t),n={read:async(s,o)=>{let i=await e.read(o);return s.decode(i)},write:async(s,o,i)=>{await e.write(o.encode(s),i)},writeV:async(s,o,i)=>{await e.writeV(s.map(a=>o.encode(a)),i)},pb:s=>({read:async o=>n.read(s,o),write:async(o,i)=>n.write(o,s,i),writeV:async(o,i)=>n.writeV(o,s,i),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var Ll="0.1.0",Ul="id",Rl="id/push",_l="1.0.0",Pl="1.0.0";var Ve;(function(r){let t;r.codec=()=>(t==null&&(t=Gt((e,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),e.protocolVersion!=null&&(n.uint32(42),n.string(e.protocolVersion)),e.agentVersion!=null&&(n.uint32(50),n.string(e.agentVersion)),e.publicKey!=null&&(n.uint32(10),n.bytes(e.publicKey)),e.listenAddrs!=null)for(let o of e.listenAddrs)n.uint32(18),n.bytes(o);if(e.observedAddr!=null&&(n.uint32(34),n.bytes(e.observedAddr)),e.protocols!=null)for(let o of e.protocols)n.uint32(26),n.string(o);e.signedPeerRecord!=null&&(n.uint32(66),n.bytes(e.signedPeerRecord)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let o={listenAddrs:[],protocols:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 5:{o.protocolVersion=e.string();break}case 6:{o.agentVersion=e.string();break}case 1:{o.publicKey=e.bytes();break}case 2:{if(s.limits?.listenAddrs!=null&&o.listenAddrs.length===s.limits.listenAddrs)throw new je('Decode error - map field "listenAddrs" had too many elements');o.listenAddrs.push(e.bytes());break}case 4:{o.observedAddr=e.bytes();break}case 3:{if(s.limits?.protocols!=null&&o.protocols.length===s.limits.protocols)throw new je('Decode error - map field "protocols" had too many elements');o.protocols.push(e.string());break}case 8:{o.signedPeerRecord=e.bytes();break}default:{e.skipType(a&7);break}}}return o})),t),r.encode=e=>zt(e,r.codec()),r.decode=(e,n)=>qt(e,r.codec(),n)})(Ve||(Ve={}));var Dl=js(Vl(),1),Vi=typeof window=="object"&&typeof document=="object"&&document.nodeType===9,Vs=(0,Dl.default)(),Ml=Vi&&!Vs,Fl=Vs&&!Vi,Hl=Vs&&Vi,Kl=typeof globalThis.process<"u"&&typeof globalThis.process.release<"u"&&globalThis.process.release.name==="node"&&!Vs,$l=typeof importScripts=="function"&&typeof self<"u"&&typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope,dx=typeof globalThis.process<"u"&&typeof globalThis.process.env<"u"&&globalThis.process.env["NODE"+"_"+"ENV"]==="test",ql=typeof navigator<"u"&&navigator.product==="ReactNative";var Rt={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function zl(r){if(r!=null&&r.length>0)try{return ne(r)}catch{}}function Dd(r,t){return t!=null||(t=`${r.name}/${r.version}`,Kl||Fl?t+=` UserAgent=${globalThis.process.version}`:(Ml||$l||Hl||ql)&&(t+=` UserAgent=${globalThis.navigator.userAgent}`)),t}async function Ds(r,t,e,n,s){if(e("received identify from %p",n.remotePeer),s==null)throw new Dt("message was null or undefined");let o={};if(s.listenAddrs.length>0&&(o.addresses=s.listenAddrs.map(c=>({isCertified:!1,multiaddr:ne(c)}))),s.protocols.length>0&&(o.protocols=s.protocols),s.publicKey!=null){let c=gr(s.publicKey);if(!ll(c).equals(n.remotePeer))throw new Dt("public key did not match remote PeerId");o.publicKey=c}let i;if(s.signedPeerRecord!=null){e.trace("received signedPeerRecord from %p",n.remotePeer);let c=s.signedPeerRecord,l=await re.openAndCertify(c,Zt.DOMAIN),u=Zt.createFromProtobuf(l.payload),f=Is(l.publicKey.toCID());if(!u.peerId.equals(f))throw new Dt("signing key does not match PeerId in the PeerRecord");if(!n.remotePeer.equals(u.peerId))throw new Dt("signing key does not match remote PeerId");let h;try{h=await r.get(u.peerId)}catch(g){if(g.name!=="NotFoundError")throw g}if(h!=null&&(o.metadata=h.metadata,h.peerRecordEnvelope!=null)){let g=await re.createFromProtobuf(h.peerRecordEnvelope),m=Zt.createFromProtobuf(g.payload);m.seqNumber>=u.seqNumber&&(e("sequence number was lower or equal to existing sequence number - stored: %d received: %d",m.seqNumber,u.seqNumber),u=m,c=h.peerRecordEnvelope)}o.peerRecordEnvelope=c,o.addresses=u.multiaddrs.map(g=>({isCertified:!0,multiaddr:g})),i={seq:u.seqNumber,addresses:u.multiaddrs}}else e("%p did not send a signed peer record",n.remotePeer);if(e.trace("patching %p with",n.remotePeer,o),await r.patch(n.remotePeer,o),s.agentVersion!=null||s.protocolVersion!=null){let c={};s.agentVersion!=null&&(c.AgentVersion=q(s.agentVersion)),s.protocolVersion!=null&&(c.ProtocolVersion=q(s.protocolVersion)),e.trace("merging %p metadata",n.remotePeer,c),await r.merge(n.remotePeer,{metadata:c})}let a={peerId:n.remotePeer,protocolVersion:s.protocolVersion,agentVersion:s.agentVersion,publicKey:s.publicKey,listenAddrs:s.listenAddrs.map(c=>ne(c)),observedAddr:s.observedAddr==null?void 0:ne(s.observedAddr),protocols:s.protocols,signedPeerRecord:i,connection:n};return t.safeDispatchEvent("peer:identify",{detail:a}),a}var Er=class{host;protocol;started;timeout;peerId;privateKey;peerStore;registrar;addressManager;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxObservedAddresses;events;runOnLimitedConnection;log;constructor(t,e){this.protocol=e.protocol,this.started=!1,this.peerId=t.peerId,this.privateKey=t.privateKey,this.peerStore=t.peerStore,this.registrar=t.registrar,this.addressManager=t.addressManager,this.events=t.events,this.log=e.log,this.timeout=e.timeout??Rt.timeout,this.maxInboundStreams=e.maxInboundStreams??Rt.maxInboundStreams,this.maxOutboundStreams=e.maxOutboundStreams??Rt.maxOutboundStreams,this.maxMessageSize=e.maxMessageSize??Rt.maxMessageSize,this.maxObservedAddresses=e.maxObservedAddresses??Rt.maxObservedAddresses,this.runOnLimitedConnection=e.runOnLimitedConnection??Rt.runOnLimitedConnection,this.host={protocolVersion:`${e.protocolPrefix??Rt.protocolPrefix}/${Ll}`,agentVersion:Dd(t.nodeInfo,e.agentVersion)}}isStarted(){return this.started}async start(){this.started||(await this.peerStore.merge(this.peerId,{metadata:{AgentVersion:q(this.host.agentVersion),ProtocolVersion:q(this.host.protocolVersion)}}),await this.registrar.handle(this.protocol,t=>{this.handleProtocol(t).catch(e=>{this.log.error(e)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnLimitedConnection:this.runOnLimitedConnection}),this.started=!0)}async stop(){await this.registrar.unhandle(this.protocol),this.started=!1}};var Ms=class extends Er{connectionManager;concurrency;constructor(t,e={}){super(t,{...e,protocol:`/${e.protocolPrefix??Rt.protocolPrefix}/${Rl}/${Pl}`,log:t.logger.forComponent("libp2p:identify-push")}),this.connectionManager=t.connectionManager,this.concurrency=e.concurrency??Rt.concurrency,(e.runOnSelfUpdate??Rt.runOnSelfUpdate)&&t.events.addEventListener("self:peer:update",n=>{this.push().catch(s=>{this.log.error(s)})})}[hn]=["@libp2p/identify-push"];async push(){if(!this.isStarted())return;let t=this.addressManager.getAddresses().map(u=>u.decapsulateCode(z("p2p").code)),e=new Zt({peerId:this.peerId,multiaddrs:t}),n=await re.seal(e,this.privateKey),s=this.registrar.getProtocols(),o=await this.peerStore.get(this.peerId),i=et(o.metadata.get("AgentVersion")??q(this.host.agentVersion)),a=et(o.metadata.get("ProtocolVersion")??q(this.host.protocolVersion)),c=this;async function*l(){for(let u of c.connectionManager.getConnections())(await c.peerStore.get(u.remotePeer)).protocols.includes(c.protocol)&&(yield async()=>{let h,g=AbortSignal.timeout(c.timeout);Ir(1/0,g);try{h=await u.newStream(c.protocol,{signal:g,runOnLimitedConnection:c.runOnLimitedConnection}),await vr(h,{maxDataLength:c.maxMessageSize}).pb(Ve).write({listenAddrs:t.map(b=>b.bytes),signedPeerRecord:n.marshal(),protocols:s,agentVersion:i,protocolVersion:a},{signal:g}),await h.close({signal:g})}catch(m){c.log.error("could not push identify update to peer",m),h?.abort(m)}})}await Il(Ri(l(),{concurrency:this.concurrency}))}async handleProtocol(t){let{connection:e,stream:n}=t;try{if(this.peerId.equals(e.remotePeer))throw new Error("received push from ourselves?");let s={signal:AbortSignal.timeout(this.timeout)},i=await vr(n,{maxDataLength:this.maxMessageSize}).pb(Ve).read(s);await n.close(s),await Ds(this.peerStore,this.events,this.log,e,i)}catch(s){this.log.error("received invalid message",s),n.abort(s);return}this.log.trace("handled push from %p",e.remotePeer)}};var Wl=js(Gl(),1),Md=["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"],Fd=Md.map(r=>new Wl.Netmask(r));function Di(r){for(let t of Fd)if(t.contains(r))return!0;return!1}function Hd(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function Kd(r){let t=r.split(":");if(t.length<2)return!1;let e=t[t.length-1].padStart(4,"0"),n=t[t.length-2].padStart(4,"0"),s=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(e.substring(0,2),16)}.${parseInt(e.substring(2),16)}`;return Di(s)}function $d(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function qd(r){let t=r.split(":"),e=t[t.length-1];return Di(e)}function zd(r){return/^::$/.test(r)||/^::1$/.test(r)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(r)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(r)||/^ff([0-9a-fA-F]{2,2}):/i.test(r)}function jl(r){return br(r)?Di(r):Hd(r)?Kd(r):$d(r)?qd(r):wr(r)?zd(r):void 0}var Gd=r=>r.toString().split("/").slice(1),Br=r=>({match:t=>t.length<1?!1:r(t[0])?t.slice(1):!1,pattern:"fn"}),H=r=>({match:t=>Br(e=>e===r).match(t),pattern:r}),Je=()=>({match:r=>Br(t=>typeof t=="string").match(r),pattern:"{string}"}),sn=()=>({match:r=>Br(t=>!isNaN(parseInt(t))).match(r),pattern:"{number}"}),Y=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{X.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),on=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{Fo.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),G=r=>({match:t=>{let e=r.match(t);return e===!1?t:e},pattern:`optional(${r.pattern})`}),Bt=(...r)=>({match:t=>{let e;for(let n of r){let s=n.match(t);s!==!1&&(e==null||s.length<e.length)&&(e=s)}return e??!1},pattern:`or(${r.map(t=>t.pattern).join(", ")})`}),K=(...r)=>({match:t=>{for(let e of r){let n=e.match(t);if(n===!1)return!1;t=n}return t},pattern:`and(${r.map(t=>t.pattern).join(", ")})`});function rt(...r){function t(s){let o=Gd(s);for(let i of r){let a=i.match(o);if(a===!1)return!1;o=a}return o}function e(s){return t(s)!==!1}function n(s){let o=t(s);return o===!1?!1:o.length===0}return{matchers:r,matches:e,exactMatch:n}}var Hs=K(H("dns4"),Je()),Ks=K(H("dns6"),Je()),$s=K(H("dnsaddr"),Je()),Fi=K(H("dns"),Je()),qx=rt(Hs,G(Y())),zx=rt(Ks,G(Y())),Gx=rt($s,G(Y())),Wx=rt(Bt(Fi,$s,Hs,Ks),G(Y())),Zl=K(H("ip4"),Br(br)),Yl=K(H("ip6"),Br(wr)),Hi=Bt(Zl,Yl),ve=Bt(Hi,Fi,Hs,Ks,$s),Jl=rt(Bt(Hi,K(Bt(Fi,$s,Hs,Ks),G(Y())))),jx=rt(Zl),Zx=rt(Yl),Yx=rt(Hi),Ki=K(ve,H("tcp"),sn()),an=K(ve,H("udp"),sn()),Jx=rt(K(Ki,G(Y()))),Xx=rt(an),$i=K(an,H("quic"),G(Y())),qs=K(an,H("quic-v1"),G(Y())),Wd=Bt($i,qs),Qx=rt($i),t1=rt(qs),Mi=Bt(ve,Ki,an,$i,qs),Xl=Bt(K(Mi,H("ws"),G(Y()))),e1=rt(Xl),Ql=Bt(K(Mi,H("wss"),G(Y())),K(Mi,H("tls"),G(K(H("sni"),Je())),H("ws"),G(Y()))),r1=rt(Ql),tu=K(an,H("webrtc-direct"),G(on()),G(on()),G(Y())),n1=rt(tu),eu=K(qs,H("webtransport"),G(on()),G(on()),G(Y())),s1=rt(eu),Fs=Bt(Xl,Ql,K(Ki,G(Y())),K(Wd,G(Y())),K(ve,G(Y())),tu,eu,Y()),o1=rt(Fs),jd=K(Fs,H("p2p-circuit"),Y()),i1=rt(jd),Zd=Bt(K(Fs,H("p2p-circuit"),H("webrtc"),G(Y())),K(Fs,H("webrtc"),G(Y())),K(H("webrtc"),G(Y()))),a1=rt(Zd),Yd=Bt(K(ve,H("tcp"),sn(),H("http"),G(Y())),K(ve,H("http"),G(Y()))),c1=rt(Yd),Jd=Bt(K(ve,H("tcp"),Bt(K(H("443"),H("http")),K(sn(),H("https"))),G(Y())),K(ve,H("tls"),H("http"),G(Y())),K(ve,H("https"),G(Y()))),l1=rt(Jd),Xd=Bt(K(H("memory"),Je(),G(Y()))),u1=rt(Xd);var zs=class extends Er{constructor(t,e={}){super(t,{...e,protocol:`/${e.protocolPrefix??Rt.protocolPrefix}/${Ul}/${_l}`,log:t.logger.forComponent("libp2p:identify")}),(e.runOnConnectionOpen??Rt.runOnConnectionOpen)&&t.events.addEventListener("connection:open",n=>{let s=n.detail;this.identify(s).catch(o=>{o.name!==fn.name&&this.log.error("error during identify trigged by connection:open",o)})})}[hn]=["@libp2p/identify"];async _identify(t,e={}){let n;if(e.signal==null){let s=AbortSignal.timeout(this.timeout);Ir(1/0,s),e={...e,signal:s}}try{n=await t.newStream(this.protocol,{...e,runOnLimitedConnection:this.runOnLimitedConnection});let o=await vr(n,{maxDataLength:this.maxMessageSize}).pb(Ve).read(e);return await n.close(e),o}catch(s){throw n?.abort(s),s}}async identify(t,e={}){let n=await this._identify(t,e),{publicKey:s,protocols:o,observedAddr:i}=n;if(s==null)throw new Dt("public key was missing from identify message");let a=gr(s),c=Is(a.toCID());if(!t.remotePeer.equals(c))throw new Dt("identified peer does not match the expected peer");if(this.peerId.equals(c))throw new Dt("identified peer is our own peer id?");let l=zl(i);return this.log("identify completed for peer %p and protocols %o",c,o),l!=null&&(this.log("our observed address was %a",l),jl(l?.nodeAddress().address)===!0?this.log("our observed address was private"):this.addressManager.getObservedAddrs().length<(this.maxObservedAddresses??1/0)&&(this.log("storing our observed address"),this.addressManager.addObservedAddr(l))),Ds(this.peerStore,this.events,this.log,t,n)}async handleProtocol(t){let{connection:e,stream:n}=t,s=AbortSignal.timeout(this.timeout);Ir(1/0,s);try{let o=await this.peerStore.get(this.peerId),i=this.addressManager.getAddresses().map(u=>u.decapsulateCode(z("p2p").code)),a=o.peerRecordEnvelope;if(i.length>0&&a==null){let u=new Zt({peerId:this.peerId,multiaddrs:i});a=(await re.seal(u,this.privateKey)).marshal().subarray()}let c=e.remoteAddr.bytes;Jl.matches(e.remoteAddr)||(c=void 0),await vr(n).pb(Ve).write({protocolVersion:this.host.protocolVersion,agentVersion:this.host.agentVersion,publicKey:Te(this.privateKey.publicKey),listenAddrs:i.map(u=>u.bytes),signedPeerRecord:a,observedAddr:c,protocols:o.protocols},{signal:s}),await n.close({signal:s})}catch(o){this.log.error("could not respond to identify request",o),n.abort(o)}}};function Qd(r={}){return t=>new zs(t,r)}function t0(r={}){return t=>new Ms(t,r)}return mu(e0);})();
|
|
6
|
+
`)}`:`${e} :`}};Tc=Ve;B.Constructed=Tc;Ve.NAME="CONSTRUCTED";var Qn=class extends Et{fromBER(t,e,n){return e}toBER(t){return jt}};Qn.override="EndOfContentValueBlock";var Lc,ts=class extends gt{constructor(t={}){super(t,Qn),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};Lc=ts;B.EndOfContent=Lc;ts.NAME=Wr;var Uc,br=class extends gt{constructor(t={}){super(t,Et),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(t,e,n){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=n,e+n>t.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):e+n}toBER(t,e){let n=new ArrayBuffer(2);if(!t){let s=new Uint8Array(n);s[0]=5,s[1]=0}return e&&e.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};Uc=br;B.Null=Uc;br.NAME="NULL";var es=class extends xe(Et){constructor({value:t,...e}={}){super(e),e.valueHex?this.valueHexView=M.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=M.BufferSourceConverter.toUint8Array(t);return we(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,Bi.call(this),this.blockLength=n,e+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};es.NAME="BooleanValueBlock";var Rc,rs=class extends gt{constructor(t={}){super(t,es),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}`}};Rc=rs;B.Boolean=Rc;rs.NAME="BOOLEAN";var ns=class extends xe(ee){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=ee.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===Wr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(i!==Ic)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?ee.prototype.toBER.call(this,t,e):t?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};ns.NAME="OctetStringValueBlock";var _c,ss=class r extends gt{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},ns),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?Ve.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${M.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 M.BufferSourceConverter.concat(t)}};_c=ss;B.OctetString=_c;ss.NAME=Ic;var os=class extends xe(ee){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=ee.prototype.fromBER.call(this,t,e,n),s===-1)return s;for(let a of this.value){let c=a.constructor.NAME;if(c===Wr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==kc)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=M.BufferSourceConverter.toUint8Array(t);if(!we(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 ee.prototype.toBER.call(this,t,e);if(t)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return jt;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}}};os.NAME="BitStringValueBlock";var Oc,yr=class extends gt{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},os),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 Ve.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)}`}}};Oc=yr;B.BitString=Oc;yr.NAME=kc;var Pc;function Rd(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,u=c<i?i:c,f=0;for(let h=u;h>=0;h--,f++){switch(!0){case f<a.length:l=o[i-f]+a[c-f]+e[0];break;default:l=o[i-f]+e[0]}switch(e[0]=l/10,!0){case f>=o.length:o=Gn(new Uint8Array([l%10]),o);break;default:o[i-f]=l%10}}return e[0]>0&&(o=Gn(e,o)),o}function Sc(r){if(r>=zr.length)for(let t=zr.length;t<=r;t++){let e=new Uint8Array([0]),n=zr[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=Gn(e,n)),zr.push(n)}return zr[r]}function _d(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,u=0;for(let f=c;f>=0;f--,u++)switch(l=o[i-u]-a[c-u]-e,!0){case l<0:e=1,o[i-u]=l+10;break;default:e=0,o[i-u]=l}if(e>0)for(let f=i-c+1;f>=0;f--,u++)if(l=o[i-u]-e,l<0)e=1,o[i-u]=l+10;else{e=0,o[i-u]=l;break}return o.slice()}var jr=class extends xe(Et){constructor({value:t,...e}={}){super(e),this._valueDec=0,e.valueHex&&this.setValueHex(),t!==void 0&&(this.valueDec=t)}setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=Bi.call(this)))}set valueDec(t){this._valueDec=t,this.isHexOnly=!1,this.valueHexView=new Uint8Array(Ec(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=_d(Sc(n),e),i="-";break;default:e=Rd(e,Sc(n))}n++,s>>=1}}for(let c=0;c<e.length;c++)e[c]&&(a=!0),a&&(i+=Ac.charAt(e[c]));return a===!1&&(i+=Ac.charAt(0)),i}};Pc=jr;jr.NAME="IntegerValueBlock";Object.defineProperty(Pc.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var Vc,mt=class r extends gt{constructor(t={}){super(t,jr),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Wn(),BigInt(this.valueBlock.toString())}static fromBigInt(t){Wn();let e=BigInt(t),n=new Gr,s=e.toString(16).replace(/^-/,""),o=new Uint8Array(M.Convert.FromHex(s));if(e<0){let a=new Uint8Array(o.length+(o[0]&128?1:0));a[0]|=128;let l=BigInt(`0x${M.Convert.ToHex(a)}`)+e,u=M.BufferSourceConverter.toUint8Array(M.Convert.FromHex(l.toString(16)));u[0]|=128,n.write(u)}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()}`}};Vc=mt;B.Integer=Vc;mt.NAME="INTEGER";var Dc,is=class extends mt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};Dc=is;B.Enumerated=Dc;is.NAME="ENUMERATED";var Zr=class extends xe(Et){constructor({valueDec:t=-1,isFirstSid:e=!1,...n}={}){super(n),this.valueDec=t,this.isFirstSid=e}fromBER(t,e,n){if(!n)return e;let s=M.BufferSourceConverter.toUint8Array(t);if(!we(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=Qe(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),e+this.blockLength)}set valueBigInt(t){Wn();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=Pe(this.valueDec,7);if(e.byteLength===0)return this.error="Error during encoding SID value",jt;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=M.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}}};Zr.NAME="sidBlock";var as=class extends Et{constructor({value:t=xr,...e}={}){super(e),this.value=[],t&&this.fromString(t)}fromBER(t,e,n){let s=e;for(;n>0;){let o=new Zr;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,jt;e.push(s)}return Ai(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 Zr;if(s>Number.MAX_SAFE_INTEGER){Wn();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}};as.NAME="ObjectIdentifierValueBlock";var Mc,wr=class extends gt{constructor(t={}){super(t,as),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()}}};Mc=wr;B.ObjectIdentifier=Mc;wr.NAME="OBJECT IDENTIFIER";var Yr=class extends xe(me){constructor({valueDec:t=0,...e}={}){super(e),this.valueDec=t}fromBER(t,e,n){if(n===0)return e;let s=M.BufferSourceConverter.toUint8Array(t);if(!we(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=Qe(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=Pe(this.valueDec,7);if(e.byteLength===0)return this.error="Error during encoding SID value",jt;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=M.Convert.ToHex(this.valueHexView):t=this.valueDec.toString(),t}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};Yr.NAME="relativeSidBlock";var cs=class extends Et{constructor({value:t=xr,...e}={}){super(e),this.value=[],t&&this.fromString(t)}fromBER(t,e,n){let s=e;for(;n>0;){let o=new Yr;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,jt;n.push(o)}return Ai(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 Yr;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}};cs.NAME="RelativeObjectIdentifierValueBlock";var Fc,ls=class extends gt{constructor(t={}){super(t,cs),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()}}};Fc=ls;B.RelativeObjectIdentifier=Fc;ls.NAME="RelativeObjectIdentifier";var Hc,be=class extends Ve{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};Hc=be;B.Sequence=Hc;be.NAME="SEQUENCE";var Kc,us=class extends Ve{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};Kc=us;B.Set=Kc;us.NAME="SET";var fs=class extends xe(Et){constructor({...t}={}){super(t),this.isHexOnly=!0,this.value=xr}toJSON(){return{...super.toJSON(),value:this.value}}};fs.NAME="StringValueBlock";var hs=class extends fs{};hs.NAME="SimpleStringValueBlock";var kt=class extends Yn{constructor({...t}={}){super(t,hs)}fromBuffer(t){this.valueBlock.value=String.fromCharCode.apply(null,M.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}};kt.NAME="SIMPLE STRING";var ds=class extends kt{fromBuffer(t){this.valueBlock.valueHexView=M.BufferSourceConverter.toUint8Array(t);try{this.valueBlock.value=M.Convert.ToUtf8String(t)}catch(e){this.warnings.push(`Error during "decodeURIComponent": ${e}, using raw string`),this.valueBlock.value=M.Convert.ToBinary(t)}}fromString(t){this.valueBlock.valueHexView=new Uint8Array(M.Convert.FromUtf8String(t)),this.valueBlock.value=t}};ds.NAME="Utf8StringValueBlock";var qc,ye=class extends ds{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};qc=ye;B.Utf8String=qc;ye.NAME="UTF8String";var ps=class extends kt{fromBuffer(t){this.valueBlock.value=M.Convert.ToUtf16String(t),this.valueBlock.valueHexView=M.BufferSourceConverter.toUint8Array(t)}fromString(t){this.valueBlock.value=t,this.valueBlock.valueHexView=new Uint8Array(M.Convert.FromUtf16String(t))}};ps.NAME="BmpStringValueBlock";var $c,gs=class extends ps{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};$c=gs;B.BmpString=$c;gs.NAME="BMPString";var ms=class extends kt{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=Pe(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}};ms.NAME="UniversalStringValueBlock";var zc,bs=class extends ms{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};zc=bs;B.UniversalString=zc;bs.NAME="UniversalString";var Gc,ys=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};Gc=ys;B.NumericString=Gc;ys.NAME="NumericString";var Wc,ws=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};Wc=ws;B.PrintableString=Wc;ws.NAME="PrintableString";var jc,xs=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};jc=xs;B.TeletexString=jc;xs.NAME="TeletexString";var Zc,vs=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};Zc=vs;B.VideotexString=Zc;vs.NAME="VideotexString";var Yc,Es=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};Yc=Es;B.IA5String=Yc;Es.NAME="IA5String";var Jc,Bs=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};Jc=Bs;B.GraphicString=Jc;Bs.NAME="GraphicString";var Xc,Jr=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};Xc=Jr;B.VisibleString=Xc;Jr.NAME="VisibleString";var Qc,As=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};Qc=As;B.GeneralString=Qc;As.NAME="GeneralString";var tl,Ss=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};tl=Ss;B.CharacterString=tl;Ss.NAME="CharacterString";var el,Xr=class extends Jr{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,M.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]=Ut(this.year<2e3?this.year-1900:this.year-2e3,2),e[1]=Ut(this.month,2),e[2]=Ut(this.day,2),e[3]=Ut(this.hour,2),e[4]=Ut(this.minute,2),e[5]=Ut(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}}};el=Xr;B.UTCTime=el;Xr.NAME="UTCTime";var rl,Is=class extends Xr{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 f=new Number(t[t.length-1]);if(isNaN(f.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 f=1,h=n.indexOf("+"),d="";if(h===-1&&(h=n.indexOf("-"),f=-1),h!==-1){if(d=n.substring(h+1),n=n.substring(0,h),d.length!==2&&d.length!==4)throw new Error("Wrong input string for conversion");let p=parseInt(d.substring(0,2),10);if(isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");if(a=f*p,d.length===4){if(p=parseInt(d.substring(2,4),10),isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");c=f*p}}}let l=n.indexOf(".");if(l===-1&&(l=n.indexOf(",")),l!==-1){let f=new Number(`0${n.substring(l)}`);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");o=f.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 f=60*o;this.minute=Math.floor(f),f=60*(f-this.minute),this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case s.length===12:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let f=60*o;this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case s.length===14:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let f=1e3*o;this.millisecond=Math.floor(f)}break;default:throw new Error("Wrong input string for conversion")}let u=i.exec(s);if(u===null)throw new Error("Wrong input string for conversion");for(let f=1;f<u.length;f++)switch(f){case 1:this.year=parseInt(u[f],10);break;case 2:this.month=parseInt(u[f],10);break;case 3:this.day=parseInt(u[f],10);break;case 4:this.hour=parseInt(u[f],10)+a;break;case 5:this.minute=parseInt(u[f],10)+c;break;case 6:this.second=parseInt(u[f],10);break;default:throw new Error("Wrong input string for conversion")}if(e===!1){let f=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=f.getUTCFullYear(),this.month=f.getUTCMonth(),this.day=f.getUTCDay(),this.hour=f.getUTCHours(),this.minute=f.getUTCMinutes(),this.second=f.getUTCSeconds(),this.millisecond=f.getUTCMilliseconds()}}toString(t="iso"){if(t==="iso"){let e=[];return e.push(Ut(this.year,4)),e.push(Ut(this.month,2)),e.push(Ut(this.day,2)),e.push(Ut(this.hour,2)),e.push(Ut(this.minute,2)),e.push(Ut(this.second,2)),this.millisecond!==0&&(e.push("."),e.push(Ut(this.millisecond,3))),e.push("Z"),e.join("")}return super.toString(t)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};rl=Is;B.GeneralizedTime=rl;Is.NAME="GeneralizedTime";var nl,ks=class extends ye{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};nl=ks;B.DATE=nl;ks.NAME="DATE";var sl,Cs=class extends ye{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};sl=Cs;B.TimeOfDay=sl;Cs.NAME="TimeOfDay";var ol,Ns=class extends ye{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};ol=Ns;B.DateTime=ol;Ns.NAME="DateTime";var il,Ts=class extends ye{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};il=Ts;B.Duration=il;Ts.NAME="Duration";var al,Ls=class extends ye{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};al=Ls;B.TIME=al;Ls.NAME="TIME";function Q(r,t="utf8"){let e=Vn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Qr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Rs=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var cl={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Rs("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var De=cl;async function ll(r){let t=await De.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 Pd(t);return{privateKey:e[0],publicKey:e[1]}}async function ul(r,t){let e=await De.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await De.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function fl(r,t,e){let n=await De.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return De.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function Pd(r){if(r.privateKey==null||r.publicKey==null)throw new It("Private and public key are required");return Promise.all([De.get().subtle.exportKey("jwk",r.privateKey),De.get().subtle.exportKey("jwk",r.publicKey)])}function ki(r){if(r.kty!=="RSA")throw new It("invalid key type");if(r.n==null)throw new It("invalid key modulus");return $(r.n,"base64url").length*8}var vr=class{type="RSA";_key;_raw;_multihash;constructor(t,e){this._key=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=tn.jwkToPkix(this._key)),this._raw}toMultihash(){return this._multihash}toCID(){return dt.createV1(114,this._multihash)}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:yt(this.raw,t.raw)}verify(t,e){return fl(this._key,e,t)}},en=class{type="RSA";_key;_raw;publicKey;constructor(t,e){this._key=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=tn.jwkToPkcs1(this._key)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:yt(this.raw,t.raw)}sign(t){return ul(this._key,t)}};var _s=8192,Ci=18;function hl(r){let{result:t}=Ii(r),e=t.valueBlock.value;return{n:re(e[1]),e:re(e[2]),d:re(e[3]),p:re(e[4]),q:re(e[5]),dp:re(e[6]),dq:re(e[7]),qi:re(e[8]),kty:"RSA",alg:"RS256"}}function Vd(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 It("JWK was missing components");let e=new be({value:[new mt({value:0}),mt.fromBigInt(ne($(r.n,"base64url"))),mt.fromBigInt(ne($(r.e,"base64url"))),mt.fromBigInt(ne($(r.d,"base64url"))),mt.fromBigInt(ne($(r.p,"base64url"))),mt.fromBigInt(ne($(r.q,"base64url"))),mt.fromBigInt(ne($(r.dp,"base64url"))),mt.fromBigInt(ne($(r.dq,"base64url"))),mt.fromBigInt(ne($(r.qi,"base64url")))]}).toBER();return new Uint8Array(e,0,e.byteLength)}function dl(r){let{result:t}=Ii(r),e=t.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:re(e[0]),e:re(e[1])}}function Ni(r){if(r.n==null||r.e==null)throw new It("JWK was missing components");let e=new be({value:[new be({value:[new wr({value:"1.2.840.113549.1.1.1"}),new br]}),new yr({valueHex:new be({value:[mt.fromBigInt(ne($(r.n,"base64url"))),mt.fromBigInt(ne($(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(e,0,e.byteLength)}function re(r){let t=r.valueBlock.valueHexView;for(;t[0]===0;)t=t.subarray(1);return Q(t,"base64url")}function ne(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(""))}function pl(r){let t=hl(r);return gl(t)}function Ti(r){let t=dl(r);if(ki(t)>_s)throw new or("Key size is too large");let e=qn(te.encode({Type:ct.RSA,Data:r})),n=Mt(Ci,e);return new vr(t,n)}function gl(r){if(ki(r)>_s)throw new It("Key size is too large");let t=bl(r),e=qn(te.encode({Type:ct.RSA,Data:Ni(t.publicKey)})),n=Mt(Ci,e);return new en(t.privateKey,new vr(t.publicKey,n))}async function ml(r){if(r>_s)throw new It("Key size is too large");let t=await ll(r),e=qn(te.encode({Type:ct.RSA,Data:Ni(t.publicKey)})),n=Mt(Ci,e);return new en(t.privateKey,new vr(t.publicKey,n))}function bl(r){if(r==null)throw new It("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}var Dd=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]),Me=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Fe=new Uint32Array(64),Li=class extends dr{constructor(){super(64,32,8,!1),this.A=Me[0]|0,this.B=Me[1]|0,this.C=Me[2]|0,this.D=Me[3]|0,this.E=Me[4]|0,this.F=Me[5]|0,this.G=Me[6]|0,this.H=Me[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 f=0;f<16;f++,e+=4)Fe[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let h=Fe[f-15],d=Fe[f-2],p=Ft(h,7)^Ft(h,18)^h>>>3,b=Ft(d,17)^Ft(d,19)^d>>>10;Fe[f]=b+Fe[f-7]+p+Fe[f-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:l,H:u}=this;for(let f=0;f<64;f++){let h=Ft(a,6)^Ft(a,11)^Ft(a,25),d=u+h+Va(a,c,l)+Dd[f]+Fe[f]|0,b=(Ft(n,2)^Ft(n,13)^Ft(n,22))+Da(n,s,o)|0;u=l,l=c,c=a,a=i+d|0,i=o,o=s,s=n,n=d+b|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,u=u+this.H|0,this.set(n,s,o,i,a,c,l,u)}roundClean(){Fe.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var yl=En(()=>new Li);var Os=class extends hr{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,_a(t);let n=Vr(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 fr(this),this.iHash.update(t),this}digestInto(t){fr(this),ur(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()}},Ui=(r,t,e)=>new Os(r,t).update(e).digest();Ui.create=(r,t)=>new Os(r,t);function wl(r){r.lowS!==void 0&&Ht("lowS",r.lowS),r.prehash!==void 0&&Ht("prehash",r.prehash)}function Md(r){let t=Fr(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("invalid 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("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:Fd,hexToBytes:Hd}=kn,ve={Err:class extends Error{constructor(t=""){super(t)}},_tlv:{encode:(r,t)=>{let{Err:e}=ve;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,s=ze(n);if(s.length/2&128)throw new e("tlv.encode: long form length too big");let o=n>127?ze(s.length/2|128):"";return ze(r)+o+s+t},decode(r,t){let{Err:e}=ve,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let s=t[n++],o=!!(s&128),i=0;if(!o)i=s;else{let c=s&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let l=t.subarray(n,n+c);if(l.length!==c)throw new e("tlv.decode: length bytes not complete");if(l[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let u of l)i=i<<8|u;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=ve;if(r<Ee)throw new t("integer: negative integers are not allowed");let e=ze(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=ve;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Fd(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=ve,s=typeof r=="string"?Hd(r):r;pr(s);let{v:o,l:i}=n.decode(48,s);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,o),{v:l,l:u}=n.decode(2,c);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(l)}},hexFromSig(r){let{_tlv:t,_int:e}=ve,n=t.encode(2,e.encode(r.r)),s=t.encode(2,e.encode(r.s)),o=n+s;return t.encode(48,o)}},Ee=BigInt(0),ft=BigInt(1),Nb=BigInt(2),xl=BigInt(3),Tb=BigInt(4);function Kd(r){let t=Md(r),{Fp:e}=t,n=Le(t.n,t.nBitLength),s=t.toBytes||((b,g,v)=>{let A=g.toAffine();return de(Uint8Array.from([4]),e.toBytes(A.x),e.toBytes(A.y))}),o=t.fromBytes||(b=>{let g=b.subarray(1),v=e.fromBytes(g.subarray(0,e.BYTES)),A=e.fromBytes(g.subarray(e.BYTES,2*e.BYTES));return{x:v,y:A}});function i(b){let{a:g,b:v}=t,A=e.sqr(b),y=e.mul(A,b);return e.add(e.add(y,e.mul(b,g)),v)}if(!e.eql(e.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function a(b){return Dr(b,ft,t.n)}function c(b){let{allowedPrivateKeyLengths:g,nByteLength:v,wrapPrivateKey:A,n:y}=t;if(g&&typeof b!="bigint"){if(Ce(b)&&(b=fe(b)),typeof b!="string"||!g.includes(b.length))throw new Error("invalid private key");b=b.padStart(v*2,"0")}let I;try{I=typeof b=="bigint"?b:he(nt("private key",b,v))}catch{throw new Error("invalid private key, expected hex or "+v+" bytes, got "+typeof b)}return A&&(I=Z(I,y)),Nt("private key",I,ft,y),I}function l(b){if(!(b instanceof h))throw new Error("ProjectivePoint expected")}let u=je((b,g)=>{let{px:v,py:A,pz:y}=b;if(e.eql(y,e.ONE))return{x:v,y:A};let I=b.is0();g==null&&(g=I?e.ONE:e.inv(y));let U=e.mul(v,g),L=e.mul(A,g),k=e.mul(y,g);if(I)return{x:e.ZERO,y:e.ZERO};if(!e.eql(k,e.ONE))throw new Error("invZ was invalid");return{x:U,y:L}}),f=je(b=>{if(b.is0()){if(t.allowInfinityPoint&&!e.is0(b.py))return;throw new Error("bad point: ZERO")}let{x:g,y:v}=b.toAffine();if(!e.isValid(g)||!e.isValid(v))throw new Error("bad point: x or y not FE");let A=e.sqr(v),y=i(g);if(!e.eql(A,y))throw new Error("bad point: equation left != right");if(!b.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class h{constructor(g,v,A){if(this.px=g,this.py=v,this.pz=A,g==null||!e.isValid(g))throw new Error("x required");if(v==null||!e.isValid(v))throw new Error("y required");if(A==null||!e.isValid(A))throw new Error("z required");Object.freeze(this)}static fromAffine(g){let{x:v,y:A}=g||{};if(!g||!e.isValid(v)||!e.isValid(A))throw new Error("invalid affine point");if(g instanceof h)throw new Error("projective point not allowed");let y=I=>e.eql(I,e.ZERO);return y(v)&&y(A)?h.ZERO:new h(v,A,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(g){let v=e.invertBatch(g.map(A=>A.pz));return g.map((A,y)=>A.toAffine(v[y])).map(h.fromAffine)}static fromHex(g){let v=h.fromAffine(o(nt("pointHex",g)));return v.assertValidity(),v}static fromPrivateKey(g){return h.BASE.multiply(c(g))}static msm(g,v){return Ln(h,n,g,v)}_setWindowSize(g){p.setWindowSize(this,g)}assertValidity(){f(this)}hasEvenY(){let{y:g}=this.toAffine();if(e.isOdd)return!e.isOdd(g);throw new Error("Field doesn't support isOdd")}equals(g){l(g);let{px:v,py:A,pz:y}=this,{px:I,py:U,pz:L}=g,k=e.eql(e.mul(v,L),e.mul(I,y)),T=e.eql(e.mul(A,L),e.mul(U,y));return k&&T}negate(){return new h(this.px,e.neg(this.py),this.pz)}double(){let{a:g,b:v}=t,A=e.mul(v,xl),{px:y,py:I,pz:U}=this,L=e.ZERO,k=e.ZERO,T=e.ZERO,C=e.mul(y,y),tt=e.mul(I,I),q=e.mul(U,U),D=e.mul(y,I);return D=e.add(D,D),T=e.mul(y,U),T=e.add(T,T),L=e.mul(g,T),k=e.mul(A,q),k=e.add(L,k),L=e.sub(tt,k),k=e.add(tt,k),k=e.mul(L,k),L=e.mul(D,L),T=e.mul(A,T),q=e.mul(g,q),D=e.sub(C,q),D=e.mul(g,D),D=e.add(D,T),T=e.add(C,C),C=e.add(T,C),C=e.add(C,q),C=e.mul(C,D),k=e.add(k,C),q=e.mul(I,U),q=e.add(q,q),C=e.mul(q,D),L=e.sub(L,C),T=e.mul(q,tt),T=e.add(T,T),T=e.add(T,T),new h(L,k,T)}add(g){l(g);let{px:v,py:A,pz:y}=this,{px:I,py:U,pz:L}=g,k=e.ZERO,T=e.ZERO,C=e.ZERO,tt=t.a,q=e.mul(t.b,xl),D=e.mul(v,I),it=e.mul(A,U),E=e.mul(y,L),N=e.add(v,A),w=e.add(I,U);N=e.mul(N,w),w=e.add(D,it),N=e.sub(N,w),w=e.add(v,y);let m=e.add(I,L);return w=e.mul(w,m),m=e.add(D,E),w=e.sub(w,m),m=e.add(A,y),k=e.add(U,L),m=e.mul(m,k),k=e.add(it,E),m=e.sub(m,k),C=e.mul(tt,w),k=e.mul(q,E),C=e.add(k,C),k=e.sub(it,C),C=e.add(it,C),T=e.mul(k,C),it=e.add(D,D),it=e.add(it,D),E=e.mul(tt,E),w=e.mul(q,w),it=e.add(it,E),E=e.sub(D,E),E=e.mul(tt,E),w=e.add(w,E),D=e.mul(it,w),T=e.add(T,D),D=e.mul(m,w),k=e.mul(N,k),k=e.sub(k,D),D=e.mul(N,it),C=e.mul(m,C),C=e.add(C,D),new h(k,T,C)}subtract(g){return this.add(g.negate())}is0(){return this.equals(h.ZERO)}wNAF(g){return p.wNAFCached(this,g,h.normalizeZ)}multiplyUnsafe(g){let{endo:v,n:A}=t;Nt("scalar",g,Ee,A);let y=h.ZERO;if(g===Ee)return y;if(this.is0()||g===ft)return this;if(!v||p.hasPrecomputes(this))return p.wNAFCachedUnsafe(this,g,h.normalizeZ);let{k1neg:I,k1:U,k2neg:L,k2:k}=v.splitScalar(g),T=y,C=y,tt=this;for(;U>Ee||k>Ee;)U&ft&&(T=T.add(tt)),k&ft&&(C=C.add(tt)),tt=tt.double(),U>>=ft,k>>=ft;return I&&(T=T.negate()),L&&(C=C.negate()),C=new h(e.mul(C.px,v.beta),C.py,C.pz),T.add(C)}multiply(g){let{endo:v,n:A}=t;Nt("scalar",g,ft,A);let y,I;if(v){let{k1neg:U,k1:L,k2neg:k,k2:T}=v.splitScalar(g),{p:C,f:tt}=this.wNAF(L),{p:q,f:D}=this.wNAF(T);C=p.constTimeNegate(U,C),q=p.constTimeNegate(k,q),q=new h(e.mul(q.px,v.beta),q.py,q.pz),y=C.add(q),I=tt.add(D)}else{let{p:U,f:L}=this.wNAF(g);y=U,I=L}return h.normalizeZ([y,I])[0]}multiplyAndAddUnsafe(g,v,A){let y=h.BASE,I=(L,k)=>k===Ee||k===ft||!L.equals(y)?L.multiplyUnsafe(k):L.multiply(k),U=I(this,v).add(I(g,A));return U.is0()?void 0:U}toAffine(g){return u(this,g)}isTorsionFree(){let{h:g,isTorsionFree:v}=t;if(g===ft)return!0;if(v)return v(h,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:g,clearCofactor:v}=t;return g===ft?this:v?v(h,this):this.multiplyUnsafe(t.h)}toRawBytes(g=!0){return Ht("isCompressed",g),this.assertValidity(),s(h,this,g)}toHex(g=!0){return Ht("isCompressed",g),fe(this.toRawBytes(g))}}h.BASE=new h(t.Gx,t.Gy,e.ONE),h.ZERO=new h(e.ZERO,e.ONE,e.ZERO);let d=t.nBitLength,p=Tn(h,t.endo?Math.ceil(d/2):d);return{CURVE:t,ProjectivePoint:h,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:a}}function qd(r){let t=Fr(r);return Qt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function vl(r){let t=qd(r),{Fp:e,n}=t,s=e.BYTES+1,o=2*e.BYTES+1;function i(E){return Z(E,n)}function a(E){return Cn(E,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:l,weierstrassEquation:u,isWithinCurveOrder:f}=Kd({...t,toBytes(E,N,w){let m=N.toAffine(),x=e.toBytes(m.x),S=de;return Ht("isCompressed",w),w?S(Uint8Array.from([N.hasEvenY()?2:3]),x):S(Uint8Array.from([4]),x,e.toBytes(m.y))},fromBytes(E){let N=E.length,w=E[0],m=E.subarray(1);if(N===s&&(w===2||w===3)){let x=he(m);if(!Dr(x,ft,e.ORDER))throw new Error("Point is not on curve");let S=u(x),R;try{R=e.sqrt(S)}catch(F){let O=F instanceof Error?": "+F.message:"";throw new Error("Point is not on curve"+O)}let _=(R&ft)===ft;return(w&1)===1!==_&&(R=e.neg(R)),{x,y:R}}else if(N===o&&w===4){let x=e.fromBytes(m.subarray(0,e.BYTES)),S=e.fromBytes(m.subarray(e.BYTES,2*e.BYTES));return{x,y:S}}else{let x=s,S=o;throw new Error("invalid Point, expected length of "+x+", or uncompressed "+S+", got "+N)}}}),h=E=>fe(Te(E,t.nByteLength));function d(E){let N=n>>ft;return E>N}function p(E){return d(E)?i(-E):E}let b=(E,N,w)=>he(E.slice(N,w));class g{constructor(N,w,m){this.r=N,this.s=w,this.recovery=m,this.assertValidity()}static fromCompact(N){let w=t.nByteLength;return N=nt("compactSignature",N,w*2),new g(b(N,0,w),b(N,w,2*w))}static fromDER(N){let{r:w,s:m}=ve.toSig(nt("DER",N));return new g(w,m)}assertValidity(){Nt("r",this.r,ft,n),Nt("s",this.s,ft,n)}addRecoveryBit(N){return new g(this.r,this.s,N)}recoverPublicKey(N){let{r:w,s:m,recovery:x}=this,S=L(nt("msgHash",N));if(x==null||![0,1,2,3].includes(x))throw new Error("recovery id invalid");let R=x===2||x===3?w+t.n:w;if(R>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let _=x&1?"03":"02",V=c.fromHex(_+h(R)),F=a(R),O=i(-S*F),j=i(m*F),J=c.BASE.multiplyAndAddUnsafe(V,O,j);if(!J)throw new Error("point at infinify");return J.assertValidity(),J}hasHighS(){return d(this.s)}normalizeS(){return this.hasHighS()?new g(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return Ge(this.toDERHex())}toDERHex(){return ve.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Ge(this.toCompactHex())}toCompactHex(){return h(this.r)+h(this.s)}}let v={isValidPrivateKey(E){try{return l(E),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let E=Uo(t.n);return Wa(t.randomBytes(E),t.n)},precompute(E=8,N=c.BASE){return N._setWindowSize(E),N.multiply(BigInt(3)),N}};function A(E,N=!0){return c.fromPrivateKey(E).toRawBytes(N)}function y(E){let N=Ce(E),w=typeof E=="string",m=(N||w)&&E.length;return N?m===s||m===o:w?m===2*s||m===2*o:E instanceof c}function I(E,N,w=!0){if(y(E))throw new Error("first arg must be private key");if(!y(N))throw new Error("second arg must be public key");return c.fromHex(N).multiply(l(E)).toRawBytes(w)}let U=t.bits2int||function(E){if(E.length>8192)throw new Error("input is too large");let N=he(E),w=E.length*8-t.nBitLength;return w>0?N>>BigInt(w):N},L=t.bits2int_modN||function(E){return i(U(E))},k=Mr(t.nBitLength);function T(E){return Nt("num < 2^"+t.nBitLength,E,Ee,k),Te(E,t.nByteLength)}function C(E,N,w=tt){if(["recovered","canonical"].some(ut=>ut in w))throw new Error("sign() legacy options not supported");let{hash:m,randomBytes:x}=t,{lowS:S,prehash:R,extraEntropy:_}=w;S==null&&(S=!0),E=nt("msgHash",E),wl(w),R&&(E=nt("prehashed msgHash",m(E)));let V=L(E),F=l(N),O=[T(F),T(V)];if(_!=null&&_!==!1){let ut=_===!0?x(e.BYTES):_;O.push(nt("extraEntropy",ut))}let j=de(...O),J=V;function lt(ut){let ht=U(ut);if(!f(ht))return;let bt=a(ht),Ct=c.BASE.multiply(ht).toAffine(),At=i(Ct.x);if(At===Ee)return;let Xt=i(bt*i(J+At*F));if(Xt===Ee)return;let ie=(Ct.x===At?0:2)|Number(Ct.y&ft),Lr=Xt;return S&&d(Xt)&&(Lr=p(Xt),ie^=1),new g(At,Lr,ie)}return{seed:j,k2sig:lt}}let tt={lowS:t.lowS,prehash:!1},q={lowS:t.lowS,prehash:!1};function D(E,N,w=tt){let{seed:m,k2sig:x}=C(E,N,w),S=t;return Co(S.hash.outputLen,S.nByteLength,S.hmac)(m,x)}c.BASE._setWindowSize(8);function it(E,N,w,m=q){let x=E;N=nt("msgHash",N),w=nt("publicKey",w);let{lowS:S,prehash:R,format:_}=m;if(wl(m),"strict"in m)throw new Error("options.strict was renamed to lowS");if(_!==void 0&&_!=="compact"&&_!=="der")throw new Error("format must be compact or der");let V=typeof x=="string"||Ce(x),F=!V&&!_&&typeof x=="object"&&x!==null&&typeof x.r=="bigint"&&typeof x.s=="bigint";if(!V&&!F)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let O,j;try{if(F&&(O=new g(x.r,x.s)),V){try{_!=="compact"&&(O=g.fromDER(x))}catch(ie){if(!(ie instanceof ve.Err))throw ie}!O&&_!=="der"&&(O=g.fromCompact(x))}j=c.fromHex(w)}catch{return!1}if(!O||S&&O.hasHighS())return!1;R&&(N=t.hash(N));let{r:J,s:lt}=O,ut=L(N),ht=a(lt),bt=i(ut*ht),Ct=i(J*ht),At=c.BASE.multiplyAndAddUnsafe(j,bt,Ct)?.toAffine();return At?i(At.x)===J:!1}return{CURVE:t,getPublicKey:A,getSharedSecret:I,sign:D,verify:it,ProjectivePoint:c,Signature:g,utils:v}}function $d(r){return{hash:r,hmac:(t,...e)=>Ui(r,t,vo(...e)),randomBytes:Bn}}function El(r,t){let e=n=>vl({...r,...$d(n)});return Object.freeze({...e(t),create:e})}var Sl=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Bl=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),zd=BigInt(1),Ri=BigInt(2),Al=(r,t)=>(r+t/Ri)/t;function Gd(r){let t=Sl,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,u=l*l*r%t,f=rt(u,e,t)*u%t,h=rt(f,e,t)*u%t,d=rt(h,Ri,t)*l%t,p=rt(d,s,t)*d%t,b=rt(p,o,t)*p%t,g=rt(b,a,t)*b%t,v=rt(g,c,t)*g%t,A=rt(v,a,t)*b%t,y=rt(A,e,t)*u%t,I=rt(y,i,t)*p%t,U=rt(I,n,t)*l%t,L=rt(U,Ri,t);if(!_i.eql(_i.sqr(L),r))throw new Error("Cannot find square root");return L}var _i=Le(Sl,void 0,void 0,{sqrt:Gd}),tr=El({a:BigInt(0),b:BigInt(7),Fp:_i,n:Bl,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Bl,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-zd*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=e,i=BigInt("0x100000000000000000000000000000000"),a=Al(o*r,t),c=Al(-n*r,t),l=Z(r-a*e-c*s,t),u=Z(-a*n-c*o,t),f=l>i,h=u>i;if(f&&(l=t-l),h&&(u=t-u),l>i||u>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:l,k2neg:h,k2:u}}}},yl),Mb=BigInt(0);var Fb=tr.ProjectivePoint;function Ot(r,t){t==null&&(t=r.reduce((s,o)=>s+o.length,0));let e=Lt(t),n=0;for(let s of r)e.set(s,n),n+=s.length;return e}function Il(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function kl(r,t,e){let n=Hr.digest(e instanceof Uint8Array?e:e.subarray());if(Il(n))return n.then(({digest:s})=>tr.verify(t,s,r)).catch(s=>{throw new Qr(String(s))});try{return tr.verify(t,n.digest,r)}catch(s){throw new Qr(String(s))}}var Ps=class{type="secp256k1";raw;_key;constructor(t){this._key=Nl(t),this.raw=Cl(this._key)}toMultihash(){return le.digest(Ue(this))}toCID(){return dt.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:yt(this.raw,t.raw)}verify(t,e){return kl(this._key,e,t)}};function Oi(r){return new Ps(r)}function Cl(r){return tr.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Nl(r){try{return tr.ProjectivePoint.fromHex(r),r}catch(t){throw new or(String(t))}}function Er(r){let{Type:t,Data:e}=te.decode(r),n=e??new Uint8Array;switch(t){case ct.RSA:return Ti(n);case ct.Ed25519:return Mo(n);case ct.secp256k1:return Oi(n);default:throw new Ke}}function Tl(r){let{Type:t,Data:e}=te.decode(r.digest),n=e??new Uint8Array;switch(t){case ct.Ed25519:return Mo(n);case ct.secp256k1:return Oi(n);default:throw new Ke}}function Ue(r){return te.encode({Type:ct[r.type],Data:r.raw})}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 Vs(r){return!!r?.[Ul]}var Zt=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(Vs(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(Vs(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(Vs(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 Ot(n,s)}subarray(t,e){let{bufs:n,length:s}=this._subList(t,e);return n.length===1?n[0]:Ot(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,u=e>a&&e<=c;if(l&&u){if(t===a&&e===c){n.push(i);break}let f=t-a;n.push(i.subarray(f,f+(e-t)));break}if(l){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(u){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(!Vs(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 f=0;f<o;f++)i[f]=-1;for(let f=0;f<s;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,l=n.byteLength-1,u;for(let f=e;f<=c;f+=u){u=0;for(let h=l;h>=0;h--){let d=this.get(f+h);if(n[h]!==d){u=Math.max(1,h-a[d]);break}}if(u===0)return f}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=Lt(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=pt(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=pt(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=pt(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=Lt(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=pt(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=pt(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=pt(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=pt(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=pt(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(!yt(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}};var rn;(function(r){let t;r.codec=()=>(t==null&&(t=Gt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.publicKey!=null&&e.publicKey.byteLength>0&&(n.uint32(10),n.bytes(e.publicKey)),e.payloadType!=null&&e.payloadType.byteLength>0&&(n.uint32(18),n.bytes(e.payloadType)),e.payload!=null&&e.payload.byteLength>0&&(n.uint32(26),n.bytes(e.payload)),e.signature!=null&&e.signature.byteLength>0&&(n.uint32(42),n.bytes(e.signature)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let o={publicKey:pt(0),payloadType:pt(0),payload:pt(0),signature:pt(0)},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{o.publicKey=e.bytes();break}case 2:{o.payloadType=e.bytes();break}case 3:{o.payload=e.bytes();break}case 5:{o.signature=e.bytes();break}default:{e.skipType(a&7);break}}}return o})),t),r.encode=e=>zt(e,r.codec()),r.decode=(e,n)=>$t(e,r.codec(),n)})(rn||(rn={}));var Ds=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var se=class r{static createFromProtobuf=async t=>{let e=rn.decode(t),n=Er(e.publicKey);return new r({publicKey:n,payloadType:e.payloadType,payload:e.payload,signature:e.signature})};static seal=async(t,e)=>{if(e==null)throw new Error("Missing private key");let n=t.domain,s=t.codec,o=t.marshal(),i=Rl(n,s,o),a=await e.sign(i.subarray());return new r({publicKey:e.publicKey,payloadType:s,payload:o,signature:a})};static openAndCertify=async(t,e)=>{let n=await r.createFromProtobuf(t);if(!await n.validate(e))throw new Ds("Envelope signature is not valid for the given domain");return n};publicKey;payloadType;payload;signature;marshaled;constructor(t){let{publicKey:e,payloadType:n,payload:s,signature:o}=t;this.publicKey=e,this.payloadType=n,this.payload=s,this.signature=o}marshal(){return this.marshaled==null&&(this.marshaled=rn.encode({publicKey:Ue(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return yt(this.marshal(),t.marshal())}async validate(t){let e=Rl(t,this.payloadType,this.payload);return this.publicKey.verify(e.subarray(),this.signature)}},Rl=(r,t,e)=>{let n=$(r),s=Pt(n.byteLength),o=Pt(t.length),i=Pt(e.length);return new Zt(s,n,o,t,i,e)};var _l=Symbol.for("nodejs.util.inspect.custom"),Wd=114,nn=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[lo]=!0;toString(){return this.string==null&&(this.string=X.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return dt.createV1(Wd,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return yt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return yt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[_l](){return`PeerId(${this.toString()})`}},sn=class extends nn{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},on=class extends nn{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},an=class extends nn{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},jd=2336,cn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=le.digest($(this.url))}[_l](){return`PeerId(${this.url})`}[lo]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return dt.createV1(jd,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=Q(t)),t.toString()===this.toString())}};var Zd=114,Ol=2336;function Pl(r){if(r.type==="Ed25519")return new on({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new an({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new sn({multihash:r.toCID().multihash,publicKey:r});throw new Ke}function Pi(r){if(Jd(r))return new sn({multihash:r});if(Yd(r))try{let t=Tl(r);if(t.type==="Ed25519")return new on({multihash:r,publicKey:t});if(t.type==="secp256k1")return new an({multihash:r,publicKey:t})}catch{let e=Q(r.digest);return new cn(new URL(e))}throw new bn("Supplied PeerID Multihash is invalid")}function Ms(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==Zd&&r.code!==Ol)throw new mn("Supplied PeerID CID is invalid");if(r.code===Ol){let t=Q(r.multihash.digest);return new cn(new URL(t))}return Pi(r.multihash)}function Yd(r){return r.code===le.code}function Jd(r){return r.code===Hr.code}function Vl(r,t){let e=(n,s)=>n.toString().localeCompare(s.toString());return r.length!==t.length?!1:(t.sort(e),r.sort(e).every((n,s)=>t[s].equals(n)))}var Fs=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 u=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let h=Number.parseInt(f,t);if(!Number.isNaN(h))return h});if(u===void 0)break;if(o*=t,o+=u,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 Dl=45,Xd=15,Br=new Fs;function Hs(r){if(!(r.length>Xd))return Br.new(r).parseWith(()=>Br.readIPv4Addr())}function Ks(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Dl))return Br.new(r).parseWith(()=>Br.readIPv6Addr())}function er(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Dl))return Br.new(r).parseWith(()=>Br.readIPAddr())}function Ml(r,t,e){let n=0;for(let s of r)if(!(n<t)){if(n>e)break;if(s!==255)return!1;n++}return!0}function Fl(r,t,e,n){let s=0;for(let o of r)if(!(s<e)){if(s>n)break;if(o!==t[s])return!1;s++}return!0}function Vi(r){switch(r.length){case rr:return r.join(".");case nr:{let t=[];for(let e=0;e<r.length;e++)e%2===0&&t.push(r[e].toString(16).padStart(2,"0")+r[e+1].toString(16).padStart(2,"0"));return t.join(":")}default:throw new Error("Invalid ip length")}}function Hl(r){let t=0;for(let[e,n]of r.entries()){if(n===255){t+=8;continue}for(;n&128;)t++,n=n<<1;if(n&128)return-1;for(let s=e+1;s<r.length;s++)if(r[s]!=0)return-1;break}return t}function Kl(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var rr=4,nr=16,gw=parseInt("0xFFFF",16),Qd=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function ln(r,t){t.length===nr&&r.length===rr&&Ml(t,0,11)&&(t=t.slice(12)),t.length===rr&&r.length===nr&&Fl(r,Qd,0,11)&&(r=r.slice(12));let e=r.length;if(e!=t.length)throw new Error("Failed to mask ip");let n=new Uint8Array(e);for(let s=0;s<e;s++)n[s]=r[s]&t[s];return n}function ql(r,t){if(typeof t=="string"&&(t=er(t)),t==null)throw new Error("Invalid ip");if(t.length!==r.network.length)return!1;for(let e=0;e<t.length;e++)if((r.network[e]&r.mask[e])!==(t[e]&r.mask[e]))return!1;return!0}function Di(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=rr,s=Hs(t);if(s==null&&(n=nr,s=Ks(t),s==null))throw new Error("Failed to parse given CIDR: "+r);let o=parseInt(e,10);if(Number.isNaN(o)||String(o).length!==e.length||o<0||o>n*8)throw new Error("Failed to parse given CIDR: "+r);let i=Mi(o,8*n);return{network:ln(s,i),mask:i}}function Mi(r,t){if(t!==8*rr&&t!==8*nr)throw new Error("Invalid CIDR mask");if(r<0||r>t)throw new Error("Invalid CIDR mask");let e=t/8,n=new Uint8Array(e);for(let s=0;s<e;s++){if(r>=8){n[s]=255,r-=8;continue}n[s]=255-(255>>r),r=0}return n}var Ar=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=Di(t));else{let n=er(t);if(n==null)throw new Error("Failed to parse network");e=String(e);let s=parseInt(e,10);if(Number.isNaN(s)||String(s).length!==e.length||s<0||s>n.length*8){let o=er(e);if(o==null)throw new Error("Failed to parse mask");this.mask=o}else this.mask=Mi(s,8*n.length);this.network=ln(n,this.mask)}}contains(t){return ql({network:this.network,mask:this.mask},t)}toString(){let t=Hl(this.mask),e=t!==-1?String(t):Kl(this.mask);return Vi(this.network)+"/"+e}};function $l(r,t){return new Ar(r).contains(t)}function Sr(r){return!!Hs(r)}function Ir(r){return!!Ks(r)}function qs(r){return!!er(r)}var zl=Sr,t0=Ir,Fi=function(r){let t=0;if(r=r.toString().trim(),zl(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(t0(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let o=zl(e[n]),i;o&&(i=Fi(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")},Gl=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={},Hi={},r0=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];r0.forEach(r=>{let t=n0(...r);Hi[t.code]=t,kr[t.name]=t});function n0(r,t,e,n,s){return{code:r,size:t,name:e,resolvable:!!n,path:!!s}}function z(r){if(typeof r=="number"){if(Hi[r]!=null)return Hi[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 jw=z("ip4"),Zw=z("ip6"),Yw=z("ipcidr");function zi(r,t){switch(z(r).code){case 4:case 41:return o0(t);case 42:return $i(t);case 43:return Q(t,"base10");case 6:case 273:case 33:case 132:return Zl(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return $i(t);case 421:return l0(t);case 444:return jl(t);case 445:return jl(t);case 466:return c0(t);case 481:return globalThis.encodeURIComponent($i(t));default:return Q(t,"base16")}}function Gi(r,t){switch(z(r).code){case 4:return Wl(t);case 41:return Wl(t);case 42:return qi(t);case 43:return $(t,"base10");case 6:case 273:case 33:case 132:return Wi(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return qi(t);case 421:return i0(t);case 444:return u0(t);case 445:return f0(t);case 466:return a0(t);case 481:return qi(globalThis.decodeURIComponent(t));default:return $(t,"base16")}}var Ki=Object.values(Kr).map(r=>r.decoder),s0=function(){let r=Ki[0].or(Ki[1]);return Ki.slice(2).forEach(t=>r=r.or(t)),r}();function Wl(r){if(!qs(r))throw new Error("invalid ip address");return Fi(r)}function o0(r){let t=Gl(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!qs(t))throw new Error("invalid ip address");return t}function Wi(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Zl(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function qi(r){let t=$(r),e=Uint8Array.from(Pt(t.length));return Ot([e,t],e.length+t.length)}function $i(r){let t=pe(r);if(r=r.slice(xt(t)),r.length!==t)throw new Error("inconsistent lengths");return Q(r)}function i0(r){let t;r[0]==="Q"||r[0]==="1"?t=qe(X.decode(`z${r}`)).bytes:t=dt.parse(r).multihash.bytes;let e=Uint8Array.from(Pt(t.length));return Ot([e,t],e.length+t.length)}function a0(r){let t=s0.decode(r),e=Uint8Array.from(Pt(t.length));return Ot([e,t],e.length+t.length)}function c0(r){let t=pe(r),e=r.slice(xt(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+Q(e,"base64url")}function l0(r){let t=pe(r),e=r.slice(xt(t));if(e.length!==t)throw new Error("inconsistent lengths");return Q(e,"base58btc")}function u0(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=ce.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=Wi(n);return Ot([e,s],e.length+s.length)}function f0(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=ce.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=Wi(n);return Ot([e,s],e.length+s.length)}function jl(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=Q(t,"base32"),s=Zl(e);return`${n}:${s}`}function Yl(r){r=ji(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=z(i);if(a.size===0){t.push([a.code]),e.push([a.code]);continue}if(o++,o>=s.length)throw Xl("invalid address: "+r);if(a.path===!0){n=ji(s.slice(o).join("/")),t.push([a.code,Gi(a.code,n)]),e.push([a.code,n]);break}let c=Gi(a.code,s[o]);t.push([a.code,c]),e.push([a.code,zi(a.code,c)])}return{string:Jl(e),bytes:Yi(t),tuples:t,stringTuples:e,path:n}}function Zi(r){let t=[],e=[],n=null,s=0;for(;s<r.length;){let o=pe(r,s),i=xt(o),a=z(o),c=h0(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 Xl("Invalid address Uint8Array: "+Q(r,"base16"));t.push([o,l]);let u=zi(o,l);if(e.push([o,u]),a.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:Jl(e),tuples:t,stringTuples:e,path:n}}function Jl(r){let t=[];return r.map(e=>{let n=z(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),ji(t.join("/"))}function Yi(r){return Ot(r.map(t=>{let e=z(t[0]),n=Uint8Array.from(Pt(e.code));return t.length>1&&t[1]!=null&&(n=Ot([n,t[1]])),n}))}function h0(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+xt(e)}}function ji(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}function Xl(r){return new Error("Error parsing address: "+r)}var d0=Symbol.for("nodejs.util.inspect.custom"),Xi=Symbol.for("@multiformats/js-multiaddr/multiaddr"),p0=[z("dns").code,z("dns4").code,z("dns6").code,z("dnsaddr").code],Ji=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},$s=class r{bytes;#e;#t;#r;#n;[Xi]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=Zi(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Yl(t)}else if(tu(t))e=Zi(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=z("tcp"),a=z("udp"),c=z("ip4"),l=z("ip6"),u=z("dns6"),f=z("ip6zone");for(let[d,p]of this.stringTuples())d===f.code&&(o=`%${p??""}`),p0.includes(d)&&(e=i.name,s=443,n=`${p??""}${o}`,t=d===u.code?6:4),(d===i.code||d===a.code)&&(e=z(d).name,s=parseInt(p??"")),(d===c.code||d===l.code)&&(e=z(d).name,n=`${p??""}${o}`,t=d===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({},z(t)))}protoCodes(){return this.#t.map(([t])=>t)}protoNames(){return this.#t.map(([t])=>z(t).name)}tuples(){return this.#t.map(([t,e])=>e==null?[t]:[t,e])}stringTuples(){return this.#r.map(([t,e])=>e==null?[t]:[t,e])}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(Yi(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(X.decode(`z${n}`),"base58btc"):Q(dt.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return yt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(o=>o.resolvable);if(e==null)return[this];let n=Ql.get(e.name);if(n==null)throw new Ji(`no available resolver for ${e.name}`);return(await n(this,t)).map(o=>oe(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)}[d0](){return`Multiaddr(${this.#e})`}};var Ql=new Map;function tu(r){return!!r?.[Xi]}function oe(r){return new $s(r)}var eu="libp2p-peer-record",ru=Uint8Array.from([3,1]);var un;(function(r){let t;(function(n){let s;n.codec=()=>(s==null&&(s=Gt((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.multiaddr!=null&&o.multiaddr.byteLength>0&&(i.uint32(10),i.bytes(o.multiaddr)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={multiaddr:pt(0)},l=i==null?o.len:o.pos+i;for(;o.pos<l;){let u=o.uint32();switch(u>>>3){case 1:{c.multiaddr=o.bytes();break}default:{o.skipType(u&7);break}}}return c})),s),n.encode=o=>zt(o,n.codec()),n.decode=(o,i)=>$t(o,n.codec(),i)})(t=r.AddressInfo||(r.AddressInfo={}));let e;r.codec=()=>(e==null&&(e=Gt((n,s,o={})=>{if(o.lengthDelimited!==!1&&s.fork(),n.peerId!=null&&n.peerId.byteLength>0&&(s.uint32(10),s.bytes(n.peerId)),n.seq!=null&&n.seq!==0n&&(s.uint32(16),s.uint64(n.seq)),n.addresses!=null)for(let i of n.addresses)s.uint32(26),r.AddressInfo.codec().encode(i,s);o.lengthDelimited!==!1&&s.ldelim()},(n,s,o={})=>{let i={peerId:pt(0),seq:0n,addresses:[]},a=s==null?n.len:n.pos+s;for(;n.pos<a;){let c=n.uint32();switch(c>>>3){case 1:{i.peerId=n.bytes();break}case 2:{i.seq=n.uint64();break}case 3:{if(o.limits?.addresses!=null&&i.addresses.length===o.limits.addresses)throw new Xe('Decode error - map field "addresses" had too many elements');i.addresses.push(r.AddressInfo.codec().decode(n,n.uint32(),{limits:o.limits?.addresses$}));break}default:{n.skipType(c&7);break}}}return i})),e),r.encode=n=>zt(n,r.codec()),r.decode=(n,s)=>$t(n,r.codec(),s)})(un||(un={}));var Yt=class r{static createFromProtobuf=t=>{let e=un.decode(t),n=Pi(qe(e.peerId)),s=(e.addresses??[]).map(i=>oe(i.multiaddr)),o=e.seq;return new r({peerId:n,multiaddrs:s,seqNumber:o})};static DOMAIN=eu;static CODEC=ru;peerId;multiaddrs;seqNumber;domain=r.DOMAIN;codec=r.CODEC;marshaled;constructor(t){let{peerId:e,multiaddrs:n,seqNumber:s}=t;this.peerId=e,this.multiaddrs=n??[],this.seqNumber=s??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=un.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(t=>({multiaddr:t.bytes}))})),this.marshaled}equals(t){return!(!(t instanceof r)||!this.peerId.equals(t.peerId)||this.seqNumber!==t.seqNumber||!Vl(this.multiaddrs,t.multiaddrs))}};function g0(r){return r[Symbol.asyncIterator]!=null}function m0(r){if(g0(r))return(async()=>{for await(let t of r);})();for(let t of r);}var nu=m0;function Jt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var zs=globalThis.CustomEvent??Event;async function*Qi(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=Jt(),a=Jt(),c=!1,l,u=!1;s.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let p of r){if(o.length===e&&(i=Jt(),await i.promise),u)break;let b={done:!1};o.push(b),p().then(g=>{b.done=!0,b.ok=!0,b.value=g,s.dispatchEvent(new zs("task-complete"))},g=>{b.done=!0,b.err=g,s.dispatchEvent(new zs("task-complete"))})}c=!0,s.dispatchEvent(new zs("task-complete"))}catch(p){l=p,s.dispatchEvent(new zs("task-complete"))}});function f(){return n?o[0]?.done:!!o.find(p=>p.done)}function*h(){for(;o.length>0&&o[0].done;){let p=o[0];if(o.shift(),p.ok)yield p.value;else throw u=!0,i.resolve(),p.err;i.resolve()}}function*d(){for(;f();)for(let p=0;p<o.length;p++)if(o[p].done){let b=o[p];if(o.splice(p,1),p--,b.ok)yield b.value;else throw u=!0,i.resolve(),b.err;i.resolve()}}for(;;){if(f()||(a=Jt(),await a.promise),l!=null)throw l;if(n?yield*h():yield*d(),c&&o.length===0)break}}var Gs=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function su(r,t,e){if(t==null)return r;if(t.aborted)return Promise.reject(new Gs(e?.errorMessage,e?.errorCode,e?.errorName));let n,s=new Gs(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((o,i)=>{n=()=>{i(s)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var ta=class{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=Jt(),this.haveNext=Jt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Jt(),t}async throw(t){return this.ended=!0,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return await this._push(void 0),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Jt(),await su(this.readNext.promise,e?.signal,e)}};function ou(){return new ta}var Ws=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};var ea=class extends Error{code;constructor(t,e){super(t),this.code=e}},ra=class extends ea{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted",this.name="AbortError"}};function iu(r,t){let e=ou();r.sink(e).catch(async i=>{await e.end(i)}),r.sink=async i=>{for await(let a of i)await e.push(a);await e.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let s=new Zt;return{read:async(i,a)=>{a?.signal?.throwIfAborted();let c,l=new Promise((u,f)=>{c=()=>{f(new ra("Read aborted"))},a?.signal?.addEventListener("abort",c)});try{if(i==null){let{done:f,value:h}=await Promise.race([n.next(),l]);return f===!0?new Zt:h}for(;s.byteLength<i;){let{value:f,done:h}=await Promise.race([n.next(),l]);if(h===!0)throw new Ws("unexpected end of input");s.append(f)}let u=s.sublist(0,i);return s.consume(i),u}finally{c!=null&&a?.signal?.removeEventListener("abort",c)}},write:async(i,a)=>{a?.signal?.throwIfAborted(),i instanceof Uint8Array?await e.push(i,a):await e.push(i.subarray(),a)},unwrap:()=>{if(s.byteLength>0){let i=r.source;r.source=async function*(){t?.yieldBytes===!1?yield s:yield*s,yield*i}()}return r}}}var js=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Zs=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Ys=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function au(r,t={}){let e=iu(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=xt(t.maxDataLength));let n=t?.lengthDecoder??pe,s=t?.lengthEncoder??Pt;return{read:async i=>{let a=-1,c=new Zt;for(;;){c.append(await e.read(1,i));try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new js("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new Ys("message length length too long");if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new Zs("message length too long");return e.read(a,i)},write:async(i,a)=>{await e.write(new Zt(s(i.byteLength),i),a)},writeV:async(i,a)=>{let c=new Zt(...i.flatMap(l=>[s(l.byteLength),l]));await e.write(c,a)},unwrap:()=>e.unwrap()}}function Cr(r,t){let e=au(r,t),n={read:async(s,o)=>{let i=await e.read(o);return s.decode(i)},write:async(s,o,i)=>{await e.write(o.encode(s),i)},writeV:async(s,o,i)=>{await e.writeV(s.map(a=>o.encode(a)),i)},pb:s=>({read:async o=>n.read(s,o),write:async(o,i)=>n.write(o,s,i),writeV:async(o,i)=>n.writeV(o,s,i),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var cu="0.1.0",lu="id",uu="id/push",fu="1.0.0",hu="1.0.0";var He;(function(r){let t;r.codec=()=>(t==null&&(t=Gt((e,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),e.protocolVersion!=null&&(n.uint32(42),n.string(e.protocolVersion)),e.agentVersion!=null&&(n.uint32(50),n.string(e.agentVersion)),e.publicKey!=null&&(n.uint32(10),n.bytes(e.publicKey)),e.listenAddrs!=null)for(let o of e.listenAddrs)n.uint32(18),n.bytes(o);if(e.observedAddr!=null&&(n.uint32(34),n.bytes(e.observedAddr)),e.protocols!=null)for(let o of e.protocols)n.uint32(26),n.string(o);e.signedPeerRecord!=null&&(n.uint32(66),n.bytes(e.signedPeerRecord)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let o={listenAddrs:[],protocols:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 5:{o.protocolVersion=e.string();break}case 6:{o.agentVersion=e.string();break}case 1:{o.publicKey=e.bytes();break}case 2:{if(s.limits?.listenAddrs!=null&&o.listenAddrs.length===s.limits.listenAddrs)throw new Xe('Decode error - map field "listenAddrs" had too many elements');o.listenAddrs.push(e.bytes());break}case 4:{o.observedAddr=e.bytes();break}case 3:{if(s.limits?.protocols!=null&&o.protocols.length===s.limits.protocols)throw new Xe('Decode error - map field "protocols" had too many elements');o.protocols.push(e.string());break}case 8:{o.signedPeerRecord=e.bytes();break}default:{e.skipType(a&7);break}}}return o})),t),r.encode=e=>zt(e,r.codec()),r.decode=(e,n)=>$t(e,r.codec(),n)})(He||(He={}));var gu=co(pu(),1),na=typeof window=="object"&&typeof document=="object"&&document.nodeType===9,Js=(0,gu.default)(),mu=na&&!Js,bu=Js&&!na,yu=Js&&na,wu=typeof globalThis.process<"u"&&typeof globalThis.process.release<"u"&&globalThis.process.release.name==="node"&&!Js,xu=typeof importScripts=="function"&&typeof self<"u"&&typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope,n1=typeof globalThis.process<"u"&&typeof globalThis.process.env<"u"&&globalThis.process.env["NODE"+"_"+"ENV"]==="test",vu=typeof navigator<"u"&&navigator.product==="ReactNative";var Rt={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function Eu(r){if(r!=null&&r.length>0)try{return oe(r)}catch{}}function x0(r,t){return t!=null||(t=`${r.name}/${r.version}`,wu||bu?t+=` UserAgent=${globalThis.process.version}`:(mu||xu||yu||vu)&&(t+=` UserAgent=${globalThis.navigator.userAgent}`)),t}async function Xs(r,t,e,n,s){if(e("received identify from %p",n.remotePeer),s==null)throw new Dt("message was null or undefined");let o={};if(s.listenAddrs.length>0&&(o.addresses=s.listenAddrs.map(c=>({isCertified:!1,multiaddr:oe(c)}))),s.protocols.length>0&&(o.protocols=s.protocols),s.publicKey!=null){let c=Er(s.publicKey);if(!Pl(c).equals(n.remotePeer))throw new Dt("public key did not match remote PeerId");o.publicKey=c}let i;if(s.signedPeerRecord!=null){e.trace("received signedPeerRecord from %p",n.remotePeer);let c=s.signedPeerRecord,l=await se.openAndCertify(c,Yt.DOMAIN),u=Yt.createFromProtobuf(l.payload),f=Ms(l.publicKey.toCID());if(!u.peerId.equals(f))throw new Dt("signing key does not match PeerId in the PeerRecord");if(!n.remotePeer.equals(u.peerId))throw new Dt("signing key does not match remote PeerId");let h;try{h=await r.get(u.peerId)}catch(d){if(d.name!=="NotFoundError")throw d}if(h!=null&&(o.metadata=h.metadata,h.peerRecordEnvelope!=null)){let d=await se.createFromProtobuf(h.peerRecordEnvelope),p=Yt.createFromProtobuf(d.payload);p.seqNumber>=u.seqNumber&&(e("sequence number was lower or equal to existing sequence number - stored: %d received: %d",p.seqNumber,u.seqNumber),u=p,c=h.peerRecordEnvelope)}o.peerRecordEnvelope=c,o.addresses=u.multiaddrs.map(d=>({isCertified:!0,multiaddr:d})),i={seq:u.seqNumber,addresses:u.multiaddrs}}else e("%p did not send a signed peer record",n.remotePeer);if(e.trace("patching %p with",n.remotePeer,o),await r.patch(n.remotePeer,o),s.agentVersion!=null||s.protocolVersion!=null){let c={};s.agentVersion!=null&&(c.AgentVersion=$(s.agentVersion)),s.protocolVersion!=null&&(c.ProtocolVersion=$(s.protocolVersion)),e.trace("merging %p metadata",n.remotePeer,c),await r.merge(n.remotePeer,{metadata:c})}let a={peerId:n.remotePeer,protocolVersion:s.protocolVersion,agentVersion:s.agentVersion,publicKey:s.publicKey,listenAddrs:s.listenAddrs.map(c=>oe(c)),observedAddr:s.observedAddr==null?void 0:oe(s.observedAddr),protocols:s.protocols,signedPeerRecord:i,connection:n};return t.safeDispatchEvent("peer:identify",{detail:a}),a}var Nr=class{host;protocol;started;timeout;peerId;privateKey;peerStore;registrar;addressManager;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxObservedAddresses;events;runOnLimitedConnection;log;constructor(t,e){this.protocol=e.protocol,this.started=!1,this.peerId=t.peerId,this.privateKey=t.privateKey,this.peerStore=t.peerStore,this.registrar=t.registrar,this.addressManager=t.addressManager,this.events=t.events,this.log=e.log,this.timeout=e.timeout??Rt.timeout,this.maxInboundStreams=e.maxInboundStreams??Rt.maxInboundStreams,this.maxOutboundStreams=e.maxOutboundStreams??Rt.maxOutboundStreams,this.maxMessageSize=e.maxMessageSize??Rt.maxMessageSize,this.maxObservedAddresses=e.maxObservedAddresses??Rt.maxObservedAddresses,this.runOnLimitedConnection=e.runOnLimitedConnection??Rt.runOnLimitedConnection,this.host={protocolVersion:`${e.protocolPrefix??Rt.protocolPrefix}/${cu}`,agentVersion:x0(t.nodeInfo,e.agentVersion)}}isStarted(){return this.started}async start(){this.started||(await this.peerStore.merge(this.peerId,{metadata:{AgentVersion:$(this.host.agentVersion),ProtocolVersion:$(this.host.protocolVersion)}}),await this.registrar.handle(this.protocol,t=>{this.handleProtocol(t).catch(e=>{this.log.error(e)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnLimitedConnection:this.runOnLimitedConnection}),this.started=!0)}async stop(){await this.registrar.unhandle(this.protocol),this.started=!1}};var Qs=class extends Nr{connectionManager;concurrency;constructor(t,e={}){super(t,{...e,protocol:`/${e.protocolPrefix??Rt.protocolPrefix}/${uu}/${hu}`,log:t.logger.forComponent("libp2p:identify-push")}),this.connectionManager=t.connectionManager,this.concurrency=e.concurrency??Rt.concurrency,(e.runOnSelfUpdate??Rt.runOnSelfUpdate)&&t.events.addEventListener("self:peer:update",n=>{this.push().catch(s=>{this.log.error(s)})})}[wn]=["@libp2p/identify-push"];async push(){if(!this.isStarted())return;let t=this.addressManager.getAddresses().map(u=>u.decapsulateCode(z("p2p").code)),e=new Yt({peerId:this.peerId,multiaddrs:t}),n=await se.seal(e,this.privateKey),s=this.registrar.getProtocols(),o=await this.peerStore.get(this.peerId),i=Q(o.metadata.get("AgentVersion")??$(this.host.agentVersion)),a=Q(o.metadata.get("ProtocolVersion")??$(this.host.protocolVersion)),c=this;async function*l(){for(let u of c.connectionManager.getConnections())(await c.peerStore.get(u.remotePeer)).protocols.includes(c.protocol)&&(yield async()=>{let h,d=AbortSignal.timeout(c.timeout);Ur(1/0,d);try{h=await u.newStream(c.protocol,{signal:d,runOnLimitedConnection:c.runOnLimitedConnection}),await Cr(h,{maxDataLength:c.maxMessageSize}).pb(He).write({listenAddrs:t.map(b=>b.bytes),signedPeerRecord:n.marshal(),protocols:s,agentVersion:i,protocolVersion:a},{signal:d}),await h.close({signal:d})}catch(p){c.log.error("could not push identify update to peer",p),h?.abort(p)}})}await nu(Qi(l(),{concurrency:this.concurrency}))}async handleProtocol(t){let{connection:e,stream:n}=t;try{if(this.peerId.equals(e.remotePeer))throw new Error("received push from ourselves?");let s={signal:AbortSignal.timeout(this.timeout)},i=await Cr(n,{maxDataLength:this.maxMessageSize}).pb(He).read(s);await n.close(s),await Xs(this.peerStore,this.events,this.log,e,i)}catch(s){this.log.error("received invalid message",s),n.abort(s);return}this.log.trace("handled push from %p",e.remotePeer)}};var v0=41;function Bu(r){try{let[[t,e]]=r.stringTuples();if(e==null)return!1;if(t===v0)return $l("2000::/3",e)}catch{}return!1}var Su=co(Au(),1),E0=["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"],B0=E0.map(r=>new Su.Netmask(r));function sa(r){for(let t of B0)if(t.contains(r))return!0;return!1}function A0(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function S0(r){let t=r.split(":");if(t.length<2)return!1;let e=t[t.length-1].padStart(4,"0"),n=t[t.length-2].padStart(4,"0"),s=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(e.substring(0,2),16)}.${parseInt(e.substring(2),16)}`;return sa(s)}function I0(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function k0(r){let t=r.split(":"),e=t[t.length-1];return sa(e)}function C0(r){return/^::$/.test(r)||/^::1$/.test(r)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(r)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(r)||/^ff([0-9a-fA-F]{2,2}):/i.test(r)}function Iu(r){return Sr(r)?sa(r):A0(r)?S0(r):I0(r)?k0(r):Ir(r)?C0(r):void 0}var N0=4,T0=41,L0=53,U0=54,R0=55,_0=56;function ku(r){try{let[[t,e]]=r.stringTuples();if(e==null)return!0;if(t===L0||t===U0||t===R0||t===_0)return!1;if(t===N0||t===T0)return Iu(e)??!1}catch{}return!0}var O0=r=>r.toString().split("/").slice(1),Tr=r=>({match:t=>t.length<1?!1:r(t[0])?t.slice(1):!1,pattern:"fn"}),H=r=>({match:t=>Tr(e=>e===r).match(t),pattern:r}),sr=()=>({match:r=>Tr(t=>typeof t=="string").match(r),pattern:"{string}"}),hn=()=>({match:r=>Tr(t=>!isNaN(parseInt(t))).match(r),pattern:"{number}"}),Y=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{X.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),dn=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{ei.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),G=r=>({match:t=>{let e=r.match(t);return e===!1?t:e},pattern:`optional(${r.pattern})`}),Bt=(...r)=>({match:t=>{let e;for(let n of r){let s=n.match(t);s!==!1&&(e==null||s.length<e.length)&&(e=s)}return e??!1},pattern:`or(${r.map(t=>t.pattern).join(", ")})`}),K=(...r)=>({match:t=>{for(let e of r){let n=e.match(t);if(n===!1)return!1;t=n}return t},pattern:`and(${r.map(t=>t.pattern).join(", ")})`});function st(...r){function t(s){let o=O0(s);for(let i of r){let a=i.match(o);if(a===!1)return!1;o=a}return o}function e(s){return t(s)!==!1}function n(s){let o=t(s);return o===!1?!1:o.length===0}return{matchers:r,matches:e,exactMatch:n}}var eo=K(H("dns4"),sr()),ro=K(H("dns6"),sr()),no=K(H("dnsaddr"),sr()),ia=K(H("dns"),sr()),D1=st(eo,G(Y())),M1=st(ro,G(Y())),F1=st(no,G(Y())),H1=st(Bt(ia,no,eo,ro),G(Y())),Cu=K(H("ip4"),Tr(Sr)),Nu=K(H("ip6"),Tr(Ir)),aa=Bt(Cu,Nu),Be=Bt(aa,ia,eo,ro,no),Tu=st(Bt(aa,K(Bt(ia,no,eo,ro),G(Y())))),K1=st(Cu),q1=st(Nu),$1=st(aa),ca=K(Be,H("tcp"),hn()),pn=K(Be,H("udp"),hn()),Lu=st(K(ca,G(Y()))),z1=st(pn),la=K(pn,H("quic"),G(Y())),so=K(pn,H("quic-v1"),G(Y())),P0=Bt(la,so),G1=st(la),W1=st(so),oa=Bt(Be,ca,pn,la,so),Uu=Bt(K(oa,H("ws"),G(Y()))),j1=st(Uu),Ru=Bt(K(oa,H("wss"),G(Y())),K(oa,H("tls"),G(K(H("sni"),sr())),H("ws"),G(Y()))),Z1=st(Ru),_u=K(pn,H("webrtc-direct"),G(dn()),G(dn()),G(Y())),Y1=st(_u),Ou=K(so,H("webtransport"),G(dn()),G(dn()),G(Y())),J1=st(Ou),to=Bt(Uu,Ru,K(ca,G(Y())),K(P0,G(Y())),K(Be,G(Y())),_u,Ou,Y()),X1=st(to),V0=K(to,H("p2p-circuit"),Y()),Q1=st(V0),D0=Bt(K(to,H("p2p-circuit"),H("webrtc"),G(Y())),K(to,H("webrtc"),G(Y())),K(H("webrtc"),G(Y()))),t2=st(D0),M0=Bt(K(Be,H("tcp"),hn(),H("http"),G(Y())),K(Be,H("http"),G(Y()))),e2=st(M0),F0=Bt(K(Be,H("tcp"),Bt(K(H("443"),H("http")),K(hn(),H("https"))),G(Y())),K(Be,H("tls"),H("http"),G(Y())),K(Be,H("https"),G(Y()))),r2=st(F0),H0=Bt(K(H("memory"),sr(),G(Y()))),n2=st(H0);var K0=41,oo=class extends Nr{constructor(t,e={}){super(t,{...e,protocol:`/${e.protocolPrefix??Rt.protocolPrefix}/${lu}/${fu}`,log:t.logger.forComponent("libp2p:identify")}),(e.runOnConnectionOpen??Rt.runOnConnectionOpen)&&t.events.addEventListener("connection:open",n=>{let s=n.detail;this.identify(s).catch(o=>{o.name!==yn.name&&this.log.error("error during identify trigged by connection:open",o)})})}[wn]=["@libp2p/identify"];async _identify(t,e={}){let n;if(e.signal==null){let s=AbortSignal.timeout(this.timeout);Ur(1/0,s),e={...e,signal:s}}try{n=await t.newStream(this.protocol,{...e,runOnLimitedConnection:this.runOnLimitedConnection});let o=await Cr(n,{maxDataLength:this.maxMessageSize}).pb(He).read(e);return await n.close(e),o}catch(s){throw n?.abort(s),s}}async identify(t,e={}){let n=await this._identify(t,e),{publicKey:s,protocols:o,observedAddr:i}=n;if(s==null)throw new Dt("public key was missing from identify message");let a=Er(s),c=Ms(a.toCID());if(!t.remotePeer.equals(c))throw new Dt("identified peer does not match the expected peer");if(this.peerId.equals(c))throw new Dt("identified peer is our own peer id?");return this.maybeAddObservedAddress(i),this.log("identify completed for peer %p and protocols %o",c,o),Xs(this.peerStore,this.events,this.log,t,n)}maybeAddObservedAddress(t){let e=Eu(t);if(e==null)return;if(this.log.trace("our observed address was %a",e),ku(e)){this.log.trace("our observed address was private");return}if(e.stringTuples()[0][0]===K0&&!Bu(e)){this.log.trace("our observed address was IPv6 but not a global unicast address");return}Lu.exactMatch(e)||(this.log.trace("storing the observed address"),this.addressManager.addObservedAddr(e))}async handleProtocol(t){let{connection:e,stream:n}=t,s=AbortSignal.timeout(this.timeout);Ur(1/0,s);try{let o=await this.peerStore.get(this.peerId),i=this.addressManager.getAddresses().map(u=>u.decapsulateCode(z("p2p").code)),a=o.peerRecordEnvelope;if(i.length>0&&a==null){let u=new Yt({peerId:this.peerId,multiaddrs:i});a=(await se.seal(u,this.privateKey)).marshal().subarray()}let c=e.remoteAddr.bytes;Tu.matches(e.remoteAddr)||(c=void 0),await Cr(n).pb(He).write({protocolVersion:this.host.protocolVersion,agentVersion:this.host.agentVersion,publicKey:Ue(this.privateKey.publicKey),listenAddrs:i.map(u=>u.bytes),signedPeerRecord:a,observedAddr:c,protocols:o.protocols},{signal:s}),await n.close({signal:s})}catch(o){this.log.error("could not respond to identify request",o),n.abort(o)}}};function q0(r={}){return t=>new oo(t,r)}function $0(r={}){return t=>new Qs(t,r)}return Zu(z0);})();
|
|
7
7
|
/*! Bundled license information:
|
|
8
8
|
|
|
9
9
|
pvtsutils/build/index.js:
|
|
10
10
|
(*!
|
|
11
11
|
* MIT License
|
|
12
12
|
*
|
|
13
|
-
* Copyright (c) 2017-
|
|
13
|
+
* Copyright (c) 2017-2024 Peculiar Ventures, LLC
|
|
14
14
|
*
|
|
15
15
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
16
16
|
* of this software and associated documentation files (the "Software"), to deal
|
|
@@ -50,6 +50,9 @@ pvtsutils/build/index.js:
|
|
|
50
50
|
@noble/curves/esm/ed25519.js:
|
|
51
51
|
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
52
52
|
|
|
53
|
+
@noble/hashes/esm/utils.js:
|
|
54
|
+
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
55
|
+
|
|
53
56
|
pvutils/build/utils.es.js:
|
|
54
57
|
(*!
|
|
55
58
|
Copyright (c) Peculiar Ventures, LLC
|