@libp2p/identify 3.0.12-f8da60e73 → 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/dist/index.min.js +2 -2
- 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/dist/typedoc-urls.json +18 -0
- package/package.json +8 -8
- package/src/identify.ts +39 -13
package/dist/index.min.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
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 Tu=Object.create;var un=Object.defineProperty;var Lu=Object.getOwnPropertyDescriptor;var Uu=Object.getOwnPropertyNames;var Ru=Object.getPrototypeOf,_u=Object.prototype.hasOwnProperty;var eo=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),St=(r,t)=>{for(var e in t)un(r,e,{get:t[e],enumerable:!0})},ua=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Uu(t))!_u.call(r,s)&&s!==e&&un(r,s,{get:()=>t[s],enumerable:!(n=Lu(t,s))||n.enumerable});return r};var ro=(r,t,e)=>(e=r!=null?Tu(Ru(r)):{},ua(t||!r||!r.__esModule?un(e,"default",{value:r,enumerable:!0}):e,r)),Ou=r=>ua(un({},"__esModule",{value:!0}),r);var pc=eo(dr=>{"use strict";var ld="[object ArrayBuffer]",ge=class r{static isArrayBuffer(t){return Object.prototype.toString.call(t)===ld}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}},mi="string",ud=/^[0-9a-f\s]+$/i,fd=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,hd=/^[a-zA-Z0-9-_]+$/,Mn=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))}},Pt=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}},Fn=class r{static isHex(t){return typeof t===mi&&ud.test(t)}static isBase64(t){return typeof t===mi&&fd.test(t)}static isBase64Url(t){return typeof t===mi&&hd.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 Pt.toString(n,!0);case"utf16":case"utf16be":return Pt.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 Pt.fromString(t,!0);case"utf16":case"utf16be":return Pt.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 Mn.fromString(t);case"utf16":case"utf16be":return Pt.fromString(t);case"utf16le":case"usc2":return Pt.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 Mn.toString(t);case"utf16":case"utf16be":return Pt.toString(t);case"utf16le":case"usc2":return Pt.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 Pt.toString(t,e)}static FromUtf16String(t,e=!1){return Pt.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,"")||""}};Fn.DEFAULT_UTF8_ENCODING="utf8";function dd(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 pd(...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 gd(r,t){if(!(r&&t)||r.byteLength!==t.byteLength)return!1;let e=new Uint8Array(r),n=new Uint8Array(t);for(let s=0;s<r.byteLength;s++)if(e[s]!==n[s])return!1;return!0}dr.BufferSourceConverter=ge;dr.Convert=Fn;dr.assign=dd;dr.combine=pd;dr.isEqual=gd});var nu=eo(($x,ru)=>{function i0(){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)}ru.exports=i0});var hu=eo(on=>{(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}(),on.ip2long=i,on.long2ip=a,on.Netmask=r}).call(on)});var I0={};St(I0,{identify:()=>A0,identifyPush:()=>S0});var no=Symbol.for("@libp2p/peer-id");var It=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},rr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var fn=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},hn=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}},dn=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 Nr=(r,...t)=>{try{[...t]}catch{}};var pn=Symbol.for("@libp2p/service-capabilities"),L0=Symbol.for("@libp2p/service-dependencies");var co={};St(co,{base58btc:()=>X,base58flickr:()=>Hu});var ep=new Uint8Array(0);function fa(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 ha(r){return new TextEncoder().encode(r)}function da(r){return new TextDecoder().decode(r)}function Vu(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 N=c.repeat(b);T<y;++T)N+=r.charAt(I[T]);return N}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)),N=g;k!==A;)T[N++]=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 Pu=Vu,Du=Pu,ga=Du;var so=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")}},oo=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 ma(this,t)}},io=class{decoders;constructor(t){this.decoders=t}or(t){return ma(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 ma(r,t){return new io({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var ao=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 so(t,e,n),this.decoder=new oo(t,e,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function nr({name:r,prefix:t,encode:e,decode:n}){return new ao(r,t,e,n)}function Ae({name:r,prefix:t,alphabet:e}){let{encode:n,decode:s}=ga(e,r);return nr({prefix:t,name:r,encode:n,decode:o=>ae(s(o))})}function Mu(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 Fu(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 nr({prefix:t,name:r,encode(s){return Fu(s,n,e)},decode(s){return Mu(s,n,e,r)}})}var X=Ae({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Hu=Ae({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var lo={};St(lo,{base32:()=>ce,base32hex:()=>zu,base32hexpad:()=>Wu,base32hexpadupper:()=>ju,base32hexupper:()=>Gu,base32pad:()=>qu,base32padupper:()=>$u,base32upper:()=>Ku,base32z:()=>Zu});var ce=ot({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ku=ot({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),qu=ot({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),$u=ot({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),zu=ot({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Gu=ot({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Wu=ot({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ju=ot({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Zu=ot({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var uo={};St(uo,{base36:()=>Cr,base36upper:()=>Yu});var Cr=Ae({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Yu=Ae({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ju=wa,ba=128,Xu=127,Qu=~Xu,tf=Math.pow(2,31);function wa(r,t,e){t=t||[],e=e||0;for(var n=e;r>=tf;)t[e++]=r&255|ba,r/=128;for(;r&Qu;)t[e++]=r&255|ba,r>>>=7;return t[e]=r|0,wa.bytes=e-n+1,t}var ef=fo,rf=128,ya=127;function fo(r,n){var e=0,n=n||0,s=0,o=n,i,a=r.length;do{if(o>=a)throw fo.bytes=0,new RangeError("Could not decode varint");i=r[o++],e+=s<28?(i&ya)<<s:(i&ya)*Math.pow(2,s),s+=7}while(i>=rf);return fo.bytes=o-n,e}var nf=Math.pow(2,7),sf=Math.pow(2,14),of=Math.pow(2,21),af=Math.pow(2,28),cf=Math.pow(2,35),lf=Math.pow(2,42),uf=Math.pow(2,49),ff=Math.pow(2,56),hf=Math.pow(2,63),df=function(r){return r<nf?1:r<sf?2:r<of?3:r<af?4:r<cf?5:r<lf?6:r<uf?7:r<ff?8:r<hf?9:10},pf={encode:Ju,decode:ef,encodingLength:df},gf=pf,Tr=gf;function Lr(r,t=0){return[Tr.decode(r,t),Tr.decode.bytes]}function sr(r,t,e=0){return Tr.encode(r,t,e),t}function or(r){return Tr.encodingLength(r)}function Mt(r,t){let e=t.byteLength,n=or(r),s=n+or(e),o=new Uint8Array(s+e);return sr(r,o,0),sr(e,o,n),o.set(t,s),new ir(r,e,t,o)}function qe(r){let t=ae(r),[e,n]=Lr(t),[s,o]=Lr(t.subarray(n)),i=t.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new ir(e,s,i,t)}function xa(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&fa(r.bytes,e.bytes)}}var ir=class{code;size;digest;bytes;constructor(t,e,n,s){this.code=t,this.size=e,this.digest=n,this.bytes=s}};function va(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return bf(e,ho(r),t??X.encoder);default:return yf(e,ho(r),t??ce.encoder)}}var Ea=new WeakMap;function ho(r){let t=Ea.get(r);if(t==null){let e=new Map;return Ea.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!==Ur)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==wf)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&&xa(t.multihash,n.multihash)}toString(t){return va(this,t)}toJSON(){return{"/":va(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??Ba(n,s,o.bytes))}else if(e[xf]===!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!==Ur)throw new Error(`Version 0 CID must use dag-pb (code: ${Ur}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let s=Ba(t,e,n.bytes);return new r(t,e,n,s)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Ur,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 ir(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]=Lr(t.subarray(e));return e+=h,f},s=n(),o=Ur;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]=mf(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 ho(o).set(n,t),o}};function mf(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 Cr.prefix:{let e=t??Cr;return[Cr.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 bf(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 yf(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 Ur=112,wf=18;function Ba(r,t,e){let n=or(r),s=n+or(t),o=new Uint8Array(s+e.byteLength);return sr(r,o,0),sr(t,o,n),o.set(e,s),o}var xf=Symbol.for("@ipld/js-cid/CID");var po={};St(po,{identity:()=>le});var Aa=0,vf="identity",Sa=ae;function Ef(r){return Mt(Aa,Sa(r))}var le={code:Aa,name:vf,encode:Sa,digest:Ef};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 Ia(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function Bf(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function ar(r,...t){if(!Bf(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 ka(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Ia(r.outputLen),Ia(r.blockLen)}function cr(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 Na(r,t){ar(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 mn=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Ft=(r,t)=>r<<32-t|r>>>t;function Ca(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function Rr(r){return typeof r=="string"&&(r=Ca(r)),ar(r),r}function go(...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}var lr=class{clone(){return this._cloneInto()}};function bn(r){let t=n=>r().update(Rr(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function yn(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 Af(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 Ta=(r,t,e)=>r&t^~r&e,La=(r,t,e)=>r&t^r&e^t&e,ur=class extends lr{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=mn(this.buffer)}update(t){cr(this);let{view:e,buffer:n,blockLen:s}=this;t=Rr(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=mn(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){cr(this),Na(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;Af(n,s-8,BigInt(this.length*8),o),this.process(n,0);let a=mn(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 wn=BigInt(4294967295),mo=BigInt(32);function Ua(r,t=!1){return t?{h:Number(r&wn),l:Number(r>>mo&wn)}:{h:Number(r>>mo&wn)|0,l:Number(r&wn)|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}=Ua(r[s],t);[e[s],n[s]]=[o,i]}return[e,n]}var If=(r,t)=>BigInt(r>>>0)<<mo|BigInt(t>>>0),kf=(r,t,e)=>r>>>e,Nf=(r,t,e)=>r<<32-e|t>>>e,Cf=(r,t,e)=>r>>>e|t<<32-e,Tf=(r,t,e)=>r<<32-e|t>>>e,Lf=(r,t,e)=>r<<64-e|t>>>e-32,Uf=(r,t,e)=>r>>>e-32|t<<64-e,Rf=(r,t)=>t,_f=(r,t)=>r,Of=(r,t,e)=>r<<e|t>>>32-e,Vf=(r,t,e)=>t<<e|r>>>32-e,Pf=(r,t,e)=>t<<e-32|r>>>64-e,Df=(r,t,e)=>r<<e-32|t>>>64-e;function Mf(r,t,e,n){let s=(t>>>0)+(n>>>0);return{h:r+e+(s/2**32|0)|0,l:s|0}}var Ff=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Hf=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Kf=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),qf=(r,t,e,n,s)=>t+e+n+s+(r/2**32|0)|0,$f=(r,t,e,n,s)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(s>>>0),zf=(r,t,e,n,s,o)=>t+e+n+s+o+(r/2**32|0)|0;var Gf={fromBig:Ua,split:Sf,toBig:If,shrSH:kf,shrSL:Nf,rotrSH:Cf,rotrSL:Tf,rotrBH:Lf,rotrBL:Uf,rotr32H:Rf,rotr32L:_f,rotlSH:Of,rotlSL:Vf,rotlBH:Pf,rotlBL:Df,add:Mf,add3L:Ff,add3H:Hf,add4L:Kf,add4H:qf,add5H:zf,add5L:$f},V=Gf;var[Wf,jf]=V.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 ur{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=V.rotrSH(I,U,1)^V.rotrSH(I,U,8)^V.shrSH(I,U,7),k=V.rotrSL(I,U,1)^V.rotrSL(I,U,8)^V.shrSL(I,U,7),T=Ie[y-2]|0,N=ke[y-2]|0,Q=V.rotrSH(T,N,19)^V.rotrBH(T,N,61)^V.shrSH(T,N,6),q=V.rotrSL(T,N,19)^V.rotrBL(T,N,61)^V.shrSL(T,N,6),D=V.add4L(k,q,ke[y-7],ke[y-16]),it=V.add4H(D,L,Q,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=V.rotrSH(f,h,14)^V.rotrSH(f,h,18)^V.rotrBH(f,h,41),U=V.rotrSL(f,h,14)^V.rotrSL(f,h,18)^V.rotrBL(f,h,41),L=f&d^~f&b,k=h&p^~h&g,T=V.add5L(A,U,k,jf[y],ke[y]),N=V.add5H(T,v,I,L,Wf[y],Ie[y]),Q=T|0,q=V.rotrSH(n,s,28)^V.rotrBH(n,s,34)^V.rotrBH(n,s,39),D=V.rotrSL(n,s,28)^V.rotrBL(n,s,34)^V.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}=V.add(l|0,u|0,N|0,Q|0),l=a|0,u=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let C=V.add3L(Q,D,E);n=V.add3H(C,N,q,it),s=C|0}({h:n,l:s}=V.add(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=V.add(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=V.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:u}=V.add(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:h}=V.add(this.Eh|0,this.El|0,f|0,h|0),{h:d,l:p}=V.add(this.Fh|0,this.Fl|0,d|0,p|0),{h:b,l:g}=V.add(this.Gh|0,this.Gl|0,b|0,g|0),{h:v,l:A}=V.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 Ra=bn(()=>new bo);var En={};St(En,{aInRange:()=>Ct,abool:()=>Ht,abytes:()=>fr,bitGet:()=>th,bitLen:()=>vo,bitMask:()=>Or,bitSet:()=>eh,bytesToHex:()=>fe,bytesToNumberBE:()=>he,bytesToNumberLE:()=>Ce,concatBytes:()=>de,createHmacDrbg:()=>Eo,ensureBytes:()=>nt,equalBytes:()=>Xf,hexToBytes:()=>Ge,hexToNumber:()=>xo,inRange:()=>_r,isBytes:()=>Ne,memoized:()=>je,notImplemented:()=>nh,numberToBytesBE:()=>Te,numberToBytesLE:()=>We,numberToHexUnpadded:()=>ze,numberToVarBytesBE:()=>Jf,utf8ToBytes:()=>Qf,validateObject:()=>Qt});var xn=BigInt(0),vn=BigInt(1),Zf=BigInt(2);function Ne(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function fr(r){if(!Ne(r))throw new Error("Uint8Array expected")}function Ht(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}var Yf=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function fe(r){fr(r);let t="";for(let e=0;e<r.length;e++)t+=Yf[r[e]];return t}function ze(r){let t=r.toString(16);return t.length&1?"0"+t:t}function xo(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?xn:BigInt("0x"+r)}var ue={_0:48,_9:57,A:65,F:70,a:97,f:102};function _a(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=_a(r.charCodeAt(o)),a=_a(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 xo(fe(r))}function Ce(r){return fr(r),xo(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 Jf(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(Ne(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];fr(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 Xf(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 Qf(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}var yo=r=>typeof r=="bigint"&&xn<=r;function _r(r,t,e){return yo(r)&&yo(t)&&yo(e)&&t<=r&&r<e}function Ct(r,t,e,n){if(!_r(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function vo(r){let t;for(t=0;r>xn;r>>=vn,t+=1);return t}function th(r,t){return r>>BigInt(t)&vn}function eh(r,t,e){return r|(e?vn:xn)<<BigInt(t)}var Or=r=>(Zf<<BigInt(r-1))-vn,wo=r=>new Uint8Array(r),Oa=r=>Uint8Array.from(r);function Eo(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=wo(r),s=wo(r),o=0,i=()=>{n.fill(1),s.fill(0),o=0},a=(...f)=>e(s,n,...f),c=(f=wo())=>{s=a(Oa([0]),f),n=a(),f.length!==0&&(s=a(Oa([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 rh={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"||Ne(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=rh[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 nh=()=>{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),tt=BigInt(1),Ze=BigInt(2),sh=BigInt(3),Bo=BigInt(4),Va=BigInt(5),Pa=BigInt(8),oh=BigInt(9),ih=BigInt(16);function Z(r,t){let e=r%t;return e>=at?e:t+e}function ah(r,t,e){if(t<at)throw new Error("invalid exponent, negatives unsupported");if(e<=at)throw new Error("invalid modulus");if(e===tt)return at;let n=tt;for(;t>at;)t&tt&&(n=n*r%e),r=r*r%e,t>>=tt;return n}function et(r,t,e){let n=r;for(;t-- >at;)n*=n,n%=e;return n}function Bn(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=tt,i=tt,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!==tt)throw new Error("invert: does not exist");return Z(s,t)}function ch(r){let t=(r-tt)/Ze,e,n,s;for(e=r-tt,n=0;e%Ze===at;e/=Ze,n++);for(s=Ze;s<r&&ah(s,t,r)!==r-tt;s++)if(s>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let i=(r+tt)/Bo;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+tt)/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,tt<<BigInt(l-d-1));u=a.sqr(p),f=a.mul(f,p),h=a.mul(h,u),l=d}return f}}function lh(r){if(r%Bo===sh){let t=(r+tt)/Bo;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%Pa===Va){let t=(r-Va)/Pa;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%ih,ch(r)}var Da=(r,t)=>(Z(r,t)&tt)===tt,uh=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ao(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=uh.reduce((n,s)=>(n[s]="function",n),t);return Qt(r,e)}function fh(r,t,e){if(e<at)throw new Error("invalid exponent, negatives unsupported");if(e===at)return r.ONE;if(e===tt)return t;let n=r.ONE,s=t;for(;e>at;)e&tt&&(n=r.mul(n,s)),s=r.sqr(s),e>>=tt;return n}function hh(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 So(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}=So(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:Or(s),ZERO:at,ONE:tt,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&tt)===tt,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)=>fh(a,c,l),div:(c,l)=>Z(c*Bn(l,r),r),sqrN:c=>c*c,addN:(c,l)=>c+l,subN:(c,l)=>c-l,mulN:(c,l)=>c*l,inv:c=>Bn(c,r),sqrt:n.sqrt||(c=>(i||(i=lh(r)),i(a,c))),invertBatch:c=>hh(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?Ce(c):he(c)}});return Object.freeze(a)}function Ma(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function Io(r){let t=Ma(r);return t+Math.ceil(t/2)}function Fa(r,t,e=!1){let n=r.length,s=Ma(t),o=Io(t);if(n<16||n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);let i=e?he(r):Ce(r),a=Z(i,t-tt)+tt;return e?We(a,s):Te(a,s)}var Ha=BigInt(0),An=BigInt(1);function ko(r,t){let e=t.negate();return r?e:t}function Ka(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function No(r,t){Ka(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1);return{windows:e,windowSize:n}}function ph(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 gh(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 Co=new WeakMap,qa=new WeakMap;function To(r){return qa.get(r)||1}function Sn(r,t){return{constTimeNegate:ko,hasPrecomputes(e){return To(e)!==1},unsafeLadder(e,n,s=r.ZERO){let o=e;for(;n>Ha;)n&An&&(s=s.add(o)),o=o.double(),n>>=An;return s},precomputeWindow(e,n){let{windows:s,windowSize:o}=No(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}=No(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+=An);let b=d,g=d+Math.abs(p)-1,v=h%2!==0,A=p<0;p===0?c=c.add(ko(v,n[b])):a=a.add(ko(A,n[g]))}return{p:a,f:c}},wNAFUnsafe(e,n,s,o=r.ZERO){let{windows:i,windowSize:a}=No(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===Ha)break;let d=Number(s&c);if(s>>=u,d>a&&(d-=l,s+=An),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=Co.get(n);return o||(o=this.precomputeWindow(n,e),e!==1&&Co.set(n,s(o))),o},wNAFCached(e,n,s){let o=To(e);return this.wNAF(o,this.getPrecomputes(o,e,s),n)},wNAFCachedUnsafe(e,n,s,o){let i=To(e);return i===1?this.unsafeLadder(e,n,o):this.wNAFUnsafe(i,this.getPrecomputes(i,e,s),n,o)},setWindowSize(e,n){Ka(n,t),qa.set(e,n),Co.delete(e)}}}function In(r,t,e,n){if(ph(e,r),gh(n,t),e.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let s=r.ZERO,o=vo(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 Vr(r){return Ao(r.Fp),Qt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...So(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Kt=BigInt(0),Tt=BigInt(1),kn=BigInt(2),mh=BigInt(8),bh={zip215:!0};function yh(r){let t=Vr(r);return Qt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function $a(r){let t=yh(r),{Fp:e,n,prehash:s,hash:o,randomBytes:i,nByteLength:a,h:c}=t,l=kn<<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){Ct("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=_?mh:e.inv(R));let P=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:P,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:P}=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),Nt=u(_*P);if(bt!==Nt)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 In(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:P,ez:F}=m,O=u(x*F),j=u(_*R),J=u(S*F),lt=u(P*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),P=u(S*S),F=u(kn*u(R*R)),O=u(m*_),j=x+S,J=u(u(j*j)-_-P),lt=O+P,ut=lt-F,ht=O-P,bt=u(J*ut),Nt=u(lt*ht),At=u(J*ht),Xt=u(ut*lt);return new y(bt,Nt,Xt,At)}add(m){g(m);let{a:x,d:S}=t,{ex:R,ey:_,ez:P,et:F}=this,{ex:O,ey:j,ez:J,et:lt}=m;if(x===BigInt(-1)){let na=u((_-R)*(j+O)),sa=u((_+R)*(j-O)),to=u(sa-na);if(to===Kt)return this.double();let oa=u(P*kn*lt),ia=u(F*kn*J),aa=ia+oa,ca=sa+na,la=ia-oa,Iu=u(aa*to),ku=u(ca*la),Nu=u(aa*la),Cu=u(to*ca);return new y(Iu,ku,Cu,Nu)}let ut=u(R*O),ht=u(_*j),bt=u(F*S*lt),Nt=u(P*J),At=u((R+_)*(O+j)-ut-ht),Xt=Nt-bt,ie=Nt+bt,kr=u(ht-x*ut),Eu=u(At*Xt),Bu=u(ie*kr),Au=u(At*kr),Su=u(Xt*ie);return new y(Eu,Bu,Su,Au)}subtract(m){return this.add(m.negate())}wNAF(m){return L.wNAFCached(this,m,y.normalizeZ)}multiply(m){let x=m;Ct("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 Ct("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 P=m.slice(),F=m[_-1];P[_-1]=F&-129;let O=Ce(P),j=x?l:e.ORDER;Ct("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 Nt=(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!==Nt&&(bt=u(-bt)),y.fromAffine({x:bt,y:O})}static fromPrivateKey(m){return N(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=Sn(y,a*8);function k(w){return Z(w,n)}function T(w){return k(Ce(w))}function N(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),P=I.multiply(_),F=P.toRawBytes();return{head:S,prefix:R,scalar:_,point:P,pointBytes:F}}function Q(w){return N(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:_}=N(m),P=q(x.context,S,w),F=I.multiply(P).toRawBytes(),O=q(x.context,F,_,w),j=k(P+O*R);Ct("signature.s",j,Kt,n);let J=de(F,We(j,e.BYTES));return nt("result",J,e.BYTES*2)}let it=bh;function E(w,m,x,S=it){let{context:R,zip215:_}=S,P=e.BYTES;w=nt("signature",w,2*P),m=nt("message",m),x=nt("publicKey",x,P),_!==void 0&&Ht("zip215",_),s&&(m=s(m));let F=Ce(w.slice(P,2*P)),O,j,J;try{O=y.fromHex(x,_),j=y.fromHex(w.slice(0,P),_),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:Q,sign:D,verify:E,ExtendedPoint:y,utils:{getExtendedPublicKey:N,randomPrivateKey:()=>i(e.BYTES),precompute(w=8,m=y.BASE){return m._setWindowSize(w),m.multiply(BigInt(3)),m}}}}var Lo=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),za=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Gp=BigInt(0),wh=BigInt(1),Ga=BigInt(2),Wp=BigInt(3),xh=BigInt(5),vh=BigInt(8);function Eh(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),s=BigInt(80),o=Lo,a=r*r%o*r%o,c=et(a,Ga,o)*a%o,l=et(c,wh,o)*r%o,u=et(l,xh,o)*l%o,f=et(u,t,o)*u%o,h=et(f,e,o)*f%o,d=et(h,n,o)*h%o,p=et(d,s,o)*d%o,b=et(p,s,o)*d%o,g=et(b,t,o)*u%o;return{pow_p_5_8:et(g,Ga,o)*r%o,b2:a}}function Bh(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Ah(r,t){let e=Lo,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*za,e),u=a===r,f=a===Z(-r,e),h=a===Z(-r*za,e);return u&&(i=c),(f||h)&&(i=l),Da(i,e)&&(i=Z(-i,e)),{isValid:u||f,value:i}}var Sh=Le(Lo,void 0,!0),Ih={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Sh,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:vh,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Ra,randomBytes:yn,adjustScalarBytes:Bh,uvRatio:Ah},Wa=$a(Ih);var Nn=32;function ja(r,t,e){return Wa.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var Cn=class{type="Ed25519";raw;constructor(t){this.raw=Uo(t,Nn)}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 ja(this.raw,e,t)}};function Ro(r){return r=Uo(r,Nn),new Cn(r)}function Uo(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 Nh=Math.pow(2,7),Ch=Math.pow(2,14),Th=Math.pow(2,21),_o=Math.pow(2,28),Oo=Math.pow(2,35),Vo=Math.pow(2,42),Po=Math.pow(2,49),W=128,wt=127;function xt(r){if(r<Nh)return 1;if(r<Ch)return 2;if(r<Th)return 3;if(r<_o)return 4;if(r<Oo)return 5;if(r<Vo)return 6;if(r<Po)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Do(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 Lh(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 Mo(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)*_o,e<W)||(e=r[t+5],n+=(e&wt)*Oo,e<W)||(e=r[t+6],n+=(e&wt)*Vo,e<W)||(e=r[t+7],n+=(e&wt)*Po,e<W))return n;throw new RangeError("Could not decode varint")}function Uh(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)*_o,e<W)||(e=r.get(t+5),n+=(e&wt)*Oo,e<W)||(e=r.get(t+6),n+=(e&wt)*Vo,e<W)||(e=r.get(t+7),n+=(e&wt)*Po,e<W))return n;throw new RangeError("Could not decode varint")}function Vt(r,t,e=0){return t==null&&(t=Lt(xt(r))),t instanceof Uint8Array?Do(r,t,e):Lh(r,t,e)}function pe(r,t=0){return r instanceof Uint8Array?Mo(r,t):Uh(r,t)}var Fo=new Float32Array([-0]),Re=new Uint8Array(Fo.buffer);function Ya(r,t,e){Fo[0]=r,t[e]=Re[0],t[e+1]=Re[1],t[e+2]=Re[2],t[e+3]=Re[3]}function Ja(r,t){return Re[0]=r[t],Re[1]=r[t+1],Re[2]=r[t+2],Re[3]=r[t+3],Fo[0]}var Ho=new Float64Array([-0]),vt=new Uint8Array(Ho.buffer);function Xa(r,t,e){Ho[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 Qa(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],Ho[0]}var Rh=BigInt(Number.MAX_SAFE_INTEGER),_h=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<Rh&&t>_h)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>tc&&(s=0n,++n>tc&&(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 tc=4294967296n;function ec(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 rc(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 Ko(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 Ln(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var qo=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 Ln(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw qt(this,4);return Ln(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw qt(this,4);let t=Ja(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw qt(this,4);let t=Qa(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 rc(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=Ln(this.buf,this.pos+=4),e=Ln(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=Mo(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 $o(r){return new qo(r instanceof Uint8Array?r:r.subarray())}function $t(r,t,e){let n=$o(r);return t.decode(n,void 0,e)}var zo={};St(zo,{base10:()=>Oh});var Oh=Ae({prefix:"9",name:"base10",alphabet:"0123456789"});var Go={};St(Go,{base16:()=>Vh,base16upper:()=>Ph});var Vh=ot({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ph=ot({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Wo={};St(Wo,{base2:()=>Dh});var Dh=ot({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var jo={};St(jo,{base256emoji:()=>qh});var sc=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}"),Mh=sc.reduce((r,t,e)=>(r[e]=t,r),[]),Fh=sc.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Hh(r){return r.reduce((t,e)=>(t+=Mh[e],t),"")}function Kh(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let s=Fh[n];if(s==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(s)}return new Uint8Array(t)}var qh=nr({prefix:"\u{1F680}",name:"base256emoji",encode:Hh,decode:Kh});var Yo={};St(Yo,{base64:()=>$h,base64pad:()=>zh,base64url:()=>Zo,base64urlpad:()=>Gh});var $h=ot({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),zh=ot({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Zo=ot({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Gh=ot({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Jo={};St(Jo,{base8:()=>Wh});var Wh=ot({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Xo={};St(Xo,{identity:()=>jh});var jh=nr({prefix:"\0",name:"identity",encode:r=>da(r),decode:r=>ha(r)});var Cg=new TextEncoder,Tg=new TextDecoder;var ei={};St(ei,{sha256:()=>Pr,sha512:()=>Jh});function ti({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 ic(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Pr=ti({name:"sha2-256",code:18,encode:ic("SHA-256")}),Jh=ti({name:"sha2-512",code:19,encode:ic("SHA-512")});var Dr={...Xo,...Wo,...Jo,...zo,...Go,...lo,...uo,...co,...Yo,...jo},Kg={...ei,...po};function cc(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var ac=cc("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ri=cc("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}),Xh={utf8:ac,"utf-8":ac,hex:Dr.base16,latin1:ri,ascii:ri,binary:ri,...Dr},Un=Xh;function $(r,t="utf8"){let e=Un[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function ni(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 si(){}var ii=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Qh=ni();function td(r){return globalThis.Buffer!=null?Lt(r):Qh(r)}var Fr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Je(si,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 ai((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(Rn,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(Rn,e.length(),e)}uint64Number(t){return this._push(Do,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(Rn,e.length(),e)}sint64Number(t){let e=_t.fromNumber(t).zzEncode();return this._push(Rn,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(oi,1,t?1:0)}fixed32(t){return this._push(Mr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=_t.fromBigInt(t);return this._push(Mr,4,e.lo)._push(Mr,4,e.hi)}fixed64Number(t){let e=_t.fromNumber(t);return this._push(Mr,4,e.lo)._push(Mr,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(Ya,4,t)}double(t){return this._push(Xa,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(oi,1,0):this.uint32(e)._push(rd,e,t)}string(t){let e=ec(t);return e!==0?this.uint32(e)._push(Ko,e,t):this._push(oi,1,0)}fork(){return this.states=new ii(this),this.head=this.tail=new Je(si,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(si,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=td(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function oi(r,t,e){t[e]=r&255}function ed(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var ai=class extends Je{next;constructor(t,e){super(ed,t,e),this.next=void 0}};function Rn(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 Mr(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 rd(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Fr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(nd,t,r),this},Fr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(sd,t,r),this});function nd(r,t,e){t.set(r,e)}function sd(r,t,e){r.length<40?Ko(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set($(r),e)}function ci(){return new Fr}function zt(r,t){let e=ci();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var hr;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(hr||(hr={}));function _n(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function li(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 _n("enum",hr.VARINT,e,n)}function Gt(r,t){return _n("message",hr.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 ui;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1"})(ui||(ui={}));(function(r){r.codec=()=>li(ui)})(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 fi;(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)})(fi||(fi={}));var Yr={};St(Yr,{MAX_RSA_KEY_SIZE:()=>Cs,generateRSAKeyPair:()=>ll,jwkToJWKKeyPair:()=>ul,jwkToPkcs1:()=>Bd,jwkToPkix:()=>Bi,jwkToRSAPrivateKey:()=>cl,pkcs1ToJwk:()=>ol,pkcs1ToRSAPrivateKey:()=>al,pkixToJwk:()=>il,pkixToRSAPublicKey:()=>Ai});function od(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function hi(r,...t){if(!od(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 di(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 uc(r,t){hi(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}var Vn=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Wt=(r,t)=>r<<32-t|r>>>t;function id(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function pi(r){return typeof r=="string"&&(r=id(r)),hi(r),r}var On=class{clone(){return this._cloneInto()}};function fc(r){let t=n=>r().update(pi(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function ad(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 hc=(r,t,e)=>r&t^~r&e,dc=(r,t,e)=>r&t^r&e^t&e,Pn=class extends On{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){di(this);let{view:e,buffer:n,blockLen:s}=this;t=pi(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){di(this),uc(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;ad(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 cd=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),gi=class extends Pn{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+hc(a,c,l)+cd[f]+Oe[f]|0,b=(Wt(n,2)^Wt(n,13)^Wt(n,22))+dc(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 Dn=fc(()=>new gi);var M=ro(pc());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 Ve(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 Hn(...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 gc(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=Ve(i,8,n),c=new Uint8Array(a);return c[0]|=128,a}let s=Ve(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 mc(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 Cm=Math.log(2);function Kn(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function yi(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 Kr=class{constructor(){this.items=[]}write(t){this.items.push(t)}final(){return yi(this.items)}},Hr=[new Uint8Array([1])],bc="0123456789";var br="",jt=new ArrayBuffer(0),wi=new Uint8Array(0),qr="EndOfContent",wc="OCTET STRING",xc="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):wi}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=br,warnings:n=[],valueBeforeDecode:s=wi}={}){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 qn=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):wi,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=Ve(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}}};qn.NAME="identificationBlock";var $n=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=Ve(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}}};$n.NAME="lengthBlock";var B={},gt=class extends me{constructor({name:t=br,optional:e=!1,primitiveSchema:n,...s}={},o){super(s),this.name=t,this.optional=e,n&&(this.primitiveSchema=n),this.idBlock=new qn(s),this.lenBlock=new $n(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 Kr;e||vc(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 mc(e,n)}};gt.NAME="BaseBlock";function vc(r){if(r instanceof B.Constructed)for(let t of r.valueBlock.value)vc(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var zn=class extends gt{constructor({value:t=br,...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}'`}};zn.NAME="BaseStringBlock";var Gn=class extends xe(Et){constructor({isHexOnly:t=!0,...e}={}){super(e),this.isHexOnly=t}};Gn.NAME="PrimitiveValueBlock";var Ec,Wn=class extends gt{constructor(t={}){super(t,Gn),this.idBlock.isConstructed=!1}};Ec=Wn;B.Primitive=Ec;Wn.NAME="PRIMITIVE";function bd(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 ks(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=bd(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 xi(r){if(!r.byteLength){let t=new gt({},Et);return t.error="Input buffer has zero length",{offset:-1,result:t}}return ks(M.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function yd(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(;yd(this.isIndefiniteForm,n)>0;){let i=ks(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===qr)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===qr?this.value.pop():this.warnings.push("No EndOfContent block encoded")),o}toBER(t,e){let n=e||new Kr;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 Bc,Pe=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(`
|
|
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} :`}};Bc=Pe;B.Constructed=Bc;Pe.NAME="CONSTRUCTED";var jn=class extends Et{fromBER(t,e,n){return e}toBER(t){return jt}};jn.override="EndOfContentValueBlock";var Ac,Zn=class extends gt{constructor(t={}){super(t,jn),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};Ac=Zn;B.EndOfContent=Ac;Zn.NAME=qr;var Sc,pr=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}`}};Sc=pr;B.Null=Sc;pr.NAME="NULL";var Yn=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}}};Yn.NAME="BooleanValueBlock";var Ic,Jn=class extends gt{constructor(t={}){super(t,Yn),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}`}};Ic=Jn;B.Boolean=Ic;Jn.NAME="BOOLEAN";var Xn=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===qr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(i!==wc)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}}};Xn.NAME="OctetStringValueBlock";var kc,Qn=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},Xn),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=ks(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)}};kc=Qn;B.OctetString=kc;Qn.NAME=wc;var ts=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===qr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==xc)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=ks(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}}};ts.NAME="BitStringValueBlock";var Nc,gr=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},ts),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)}`}}};Nc=gr;B.BitString=Nc;gr.NAME=xc;var Cc;function wd(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=Hn(new Uint8Array([l%10]),o);break;default:o[i-f]=l%10}}return e[0]>0&&(o=Hn(e,o)),o}function yc(r){if(r>=Hr.length)for(let t=Hr.length;t<=r;t++){let e=new Uint8Array([0]),n=Hr[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=Hn(e,n)),Hr.push(n)}return Hr[r]}function xd(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 $r=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(gc(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=xd(yc(n),e),i="-";break;default:e=wd(e,yc(n))}n++,s>>=1}}for(let c=0;c<e.length;c++)e[c]&&(a=!0),a&&(i+=bc.charAt(e[c]));return a===!1&&(i+=bc.charAt(0)),i}};Cc=$r;$r.NAME="IntegerValueBlock";Object.defineProperty(Cc.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var Tc,mt=class r extends gt{constructor(t={}){super(t,$r),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Kn(),BigInt(this.valueBlock.toString())}static fromBigInt(t){Kn();let e=BigInt(t),n=new Kr,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()}`}};Tc=mt;B.Integer=Tc;mt.NAME="INTEGER";var Lc,es=class extends mt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};Lc=es;B.Enumerated=Lc;es.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){Kn();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=Ve(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 rs=class extends Et{constructor({value:t=br,...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 yi(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){Kn();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}};rs.NAME="ObjectIdentifierValueBlock";var Uc,mr=class extends gt{constructor(t={}){super(t,rs),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()}}};Uc=mr;B.ObjectIdentifier=Uc;mr.NAME="OBJECT IDENTIFIER";var Gr=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=Ve(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}}};Gr.NAME="relativeSidBlock";var ns=class extends Et{constructor({value:t=br,...e}={}){super(e),this.value=[],t&&this.fromString(t)}fromBER(t,e,n){let s=e;for(;n>0;){let o=new Gr;if(s=o.fromBER(t,s,n),s===-1)return this.blockLength=0,this.error=o.error,s;this.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 yi(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 Gr;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}};ns.NAME="RelativeObjectIdentifierValueBlock";var Rc,ss=class extends gt{constructor(t={}){super(t,ns),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()}}};Rc=ss;B.RelativeObjectIdentifier=Rc;ss.NAME="RelativeObjectIdentifier";var _c,be=class extends Pe{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};_c=be;B.Sequence=_c;be.NAME="SEQUENCE";var Oc,os=class extends Pe{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};Oc=os;B.Set=Oc;os.NAME="SET";var is=class extends xe(Et){constructor({...t}={}){super(t),this.isHexOnly=!0,this.value=br}toJSON(){return{...super.toJSON(),value:this.value}}};is.NAME="StringValueBlock";var as=class extends is{};as.NAME="SimpleStringValueBlock";var kt=class extends zn{constructor({...t}={}){super(t,as)}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 cs=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}};cs.NAME="Utf8StringValueBlock";var Vc,ye=class extends cs{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};Vc=ye;B.Utf8String=Vc;ye.NAME="UTF8String";var ls=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))}};ls.NAME="BmpStringValueBlock";var Pc,us=class extends ls{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};Pc=us;B.BmpString=Pc;us.NAME="BMPString";var fs=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=Ve(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}};fs.NAME="UniversalStringValueBlock";var Dc,hs=class extends fs{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};Dc=hs;B.UniversalString=Dc;hs.NAME="UniversalString";var Mc,ds=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};Mc=ds;B.NumericString=Mc;ds.NAME="NumericString";var Fc,ps=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};Fc=ps;B.PrintableString=Fc;ps.NAME="PrintableString";var Hc,gs=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};Hc=gs;B.TeletexString=Hc;gs.NAME="TeletexString";var Kc,ms=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};Kc=ms;B.VideotexString=Kc;ms.NAME="VideotexString";var qc,bs=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};qc=bs;B.IA5String=qc;bs.NAME="IA5String";var $c,ys=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};$c=ys;B.GraphicString=$c;ys.NAME="GraphicString";var zc,Wr=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};zc=Wr;B.VisibleString=zc;Wr.NAME="VisibleString";var Gc,ws=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};Gc=ws;B.GeneralString=Gc;ws.NAME="GeneralString";var Wc,xs=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};Wc=xs;B.CharacterString=Wc;xs.NAME="CharacterString";var jc,jr=class extends Wr{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}}};jc=jr;B.UTCTime=jc;jr.NAME="UTCTime";var Zc,vs=class extends jr{constructor(t={}){var e;super(t),(e=this.millisecond)!==null&&e!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(t){super.fromDate(t),this.millisecond=t.getUTCMilliseconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond))}fromString(t){let e=!1,n="",s="",o=0,i,a=0,c=0;if(t[t.length-1]==="Z")n=t.substring(0,t.length-1),e=!0;else{let 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}}};Zc=vs;B.GeneralizedTime=Zc;vs.NAME="GeneralizedTime";var Yc,Es=class extends ye{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};Yc=Es;B.DATE=Yc;Es.NAME="DATE";var Jc,Bs=class extends ye{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};Jc=Bs;B.TimeOfDay=Jc;Bs.NAME="TimeOfDay";var Xc,As=class extends ye{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};Xc=As;B.DateTime=Xc;As.NAME="DateTime";var Qc,Ss=class extends ye{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};Qc=Ss;B.Duration=Qc;Ss.NAME="Duration";var tl,Is=class extends ye{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};tl=Is;B.TIME=tl;Is.NAME="TIME";function rt(r,t="utf8"){let e=Un[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Zr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Ns=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var el={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Ns("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=el;async function rl(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 Ed(t);return{privateKey:e[0],publicKey:e[1]}}async function nl(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 sl(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 Ed(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 vi(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 yr=class{type="RSA";_key;_raw;_multihash;constructor(t,e){this._key=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=Yr.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 sl(this._key,e,t)}},Jr=class{type="RSA";_key;_raw;publicKey;constructor(t,e){this._key=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=Yr.jwkToPkcs1(this._key)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:yt(this.raw,t.raw)}sign(t){return nl(this._key,t)}};var Cs=8192,Ei=18;function ol(r){let{result:t}=xi(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 Bd(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 il(r){let{result:t}=xi(r),e=t.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:re(e[0]),e:re(e[1])}}function Bi(r){if(r.n==null||r.e==null)throw new It("JWK was missing components");let e=new be({value:[new be({value:[new mr({value:"1.2.840.113549.1.1.1"}),new pr]}),new gr({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 rt(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 al(r){let t=ol(r);return cl(t)}function Ai(r){let t=il(r);if(vi(t)>Cs)throw new rr("Key size is too large");let e=Dn(te.encode({Type:ct.RSA,Data:r})),n=Mt(Ei,e);return new yr(t,n)}function cl(r){if(vi(r)>Cs)throw new It("Key size is too large");let t=ul(r),e=Dn(te.encode({Type:ct.RSA,Data:Bi(t.publicKey)})),n=Mt(Ei,e);return new Jr(t.privateKey,new yr(t.publicKey,n))}async function ll(r){if(r>Cs)throw new It("Key size is too large");let t=await rl(r),e=Dn(te.encode({Type:ct.RSA,Data:Bi(t.publicKey)})),n=Mt(Ei,e);return new Jr(t.privateKey,new yr(t.publicKey,n))}function ul(r){if(r==null)throw new It("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}var Ad=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),Si=class extends ur{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+Ta(a,c,l)+Ad[f]+Fe[f]|0,b=(Ft(n,2)^Ft(n,13)^Ft(n,22))+La(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 fl=bn(()=>new Si);var Ts=class extends lr{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,ka(t);let n=Rr(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 cr(this),this.iHash.update(t),this}digestInto(t){cr(this),ar(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()}},Ii=(r,t,e)=>new Ts(r,t).update(e).digest();Ii.create=(r,t)=>new Ts(r,t);function hl(r){r.lowS!==void 0&&Ht("lowS",r.lowS),r.prehash!==void 0&&Ht("prehash",r.prehash)}function Sd(r){let t=Vr(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:Id,hexToBytes:kd}=En,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 Id(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=ve,s=typeof r=="string"?kd(r):r;fr(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),ub=BigInt(2),dl=BigInt(3),fb=BigInt(4);function Nd(r){let t=Sd(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 _r(b,ft,t.n)}function c(b){let{allowedPrivateKeyLengths:g,nByteLength:v,wrapPrivateKey:A,n:y}=t;if(g&&typeof b!="bigint"){if(Ne(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)),Ct("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 In(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,dl),{px:y,py:I,pz:U}=this,L=e.ZERO,k=e.ZERO,T=e.ZERO,N=e.mul(y,y),Q=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(Q,k),k=e.add(Q,k),k=e.mul(L,k),L=e.mul(D,L),T=e.mul(A,T),q=e.mul(g,q),D=e.sub(N,q),D=e.mul(g,D),D=e.add(D,T),T=e.add(N,N),N=e.add(T,N),N=e.add(N,q),N=e.mul(N,D),k=e.add(k,N),q=e.mul(I,U),q=e.add(q,q),N=e.mul(q,D),L=e.sub(L,N),T=e.mul(q,Q),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,N=e.ZERO,Q=t.a,q=e.mul(t.b,dl),D=e.mul(v,I),it=e.mul(A,U),E=e.mul(y,L),C=e.add(v,A),w=e.add(I,U);C=e.mul(C,w),w=e.add(D,it),C=e.sub(C,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),N=e.mul(Q,w),k=e.mul(q,E),N=e.add(k,N),k=e.sub(it,N),N=e.add(it,N),T=e.mul(k,N),it=e.add(D,D),it=e.add(it,D),E=e.mul(Q,E),w=e.mul(q,w),it=e.add(it,E),E=e.sub(D,E),E=e.mul(Q,E),w=e.add(w,E),D=e.mul(it,w),T=e.add(T,D),D=e.mul(m,w),k=e.mul(C,k),k=e.sub(k,D),D=e.mul(C,it),N=e.mul(m,N),N=e.add(N,D),new h(k,T,N)}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;Ct("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,N=y,Q=this;for(;U>Ee||k>Ee;)U&ft&&(T=T.add(Q)),k&ft&&(N=N.add(Q)),Q=Q.double(),U>>=ft,k>>=ft;return I&&(T=T.negate()),L&&(N=N.negate()),N=new h(e.mul(N.px,v.beta),N.py,N.pz),T.add(N)}multiply(g){let{endo:v,n:A}=t;Ct("scalar",g,ft,A);let y,I;if(v){let{k1neg:U,k1:L,k2neg:k,k2:T}=v.splitScalar(g),{p:N,f:Q}=this.wNAF(L),{p:q,f:D}=this.wNAF(T);N=p.constTimeNegate(U,N),q=p.constTimeNegate(k,q),q=new h(e.mul(q.px,v.beta),q.py,q.pz),y=N.add(q),I=Q.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=Sn(h,t.endo?Math.ceil(d/2):d);return{CURVE:t,ProjectivePoint:h,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:a}}function Cd(r){let t=Vr(r);return Qt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function pl(r){let t=Cd(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 Bn(E,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:l,weierstrassEquation:u,isWithinCurveOrder:f}=Nd({...t,toBytes(E,C,w){let m=C.toAffine(),x=e.toBytes(m.x),S=de;return Ht("isCompressed",w),w?S(Uint8Array.from([C.hasEvenY()?2:3]),x):S(Uint8Array.from([4]),x,e.toBytes(m.y))},fromBytes(E){let C=E.length,w=E[0],m=E.subarray(1);if(C===s&&(w===2||w===3)){let x=he(m);if(!_r(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(C===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 "+C)}}}),h=E=>fe(Te(E,t.nByteLength));function d(E){let C=n>>ft;return E>C}function p(E){return d(E)?i(-E):E}let b=(E,C,w)=>he(E.slice(C,w));class g{constructor(C,w,m){this.r=C,this.s=w,this.recovery=m,this.assertValidity()}static fromCompact(C){let w=t.nByteLength;return C=nt("compactSignature",C,w*2),new g(b(C,0,w),b(C,w,2*w))}static fromDER(C){let{r:w,s:m}=ve.toSig(nt("DER",C));return new g(w,m)}assertValidity(){Ct("r",this.r,ft,n),Ct("s",this.s,ft,n)}addRecoveryBit(C){return new g(this.r,this.s,C)}recoverPublicKey(C){let{r:w,s:m,recovery:x}=this,S=L(nt("msgHash",C));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",P=c.fromHex(_+h(R)),F=a(R),O=i(-S*F),j=i(m*F),J=c.BASE.multiplyAndAddUnsafe(P,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=Io(t.n);return Fa(t.randomBytes(E),t.n)},precompute(E=8,C=c.BASE){return C._setWindowSize(E),C.multiply(BigInt(3)),C}};function A(E,C=!0){return c.fromPrivateKey(E).toRawBytes(C)}function y(E){let C=Ne(E),w=typeof E=="string",m=(C||w)&&E.length;return C?m===s||m===o:w?m===2*s||m===2*o:E instanceof c}function I(E,C,w=!0){if(y(E))throw new Error("first arg must be private key");if(!y(C))throw new Error("second arg must be public key");return c.fromHex(C).multiply(l(E)).toRawBytes(w)}let U=t.bits2int||function(E){if(E.length>8192)throw new Error("input is too large");let C=he(E),w=E.length*8-t.nBitLength;return w>0?C>>BigInt(w):C},L=t.bits2int_modN||function(E){return i(U(E))},k=Or(t.nBitLength);function T(E){return Ct("num < 2^"+t.nBitLength,E,Ee,k),Te(E,t.nByteLength)}function N(E,C,w=Q){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),hl(w),R&&(E=nt("prehashed msgHash",m(E)));let P=L(E),F=l(C),O=[T(F),T(P)];if(_!=null&&_!==!1){let ut=_===!0?x(e.BYTES):_;O.push(nt("extraEntropy",ut))}let j=de(...O),J=P;function lt(ut){let ht=U(ut);if(!f(ht))return;let bt=a(ht),Nt=c.BASE.multiply(ht).toAffine(),At=i(Nt.x);if(At===Ee)return;let Xt=i(bt*i(J+At*F));if(Xt===Ee)return;let ie=(Nt.x===At?0:2)|Number(Nt.y&ft),kr=Xt;return S&&d(Xt)&&(kr=p(Xt),ie^=1),new g(At,kr,ie)}return{seed:j,k2sig:lt}}let Q={lowS:t.lowS,prehash:!1},q={lowS:t.lowS,prehash:!1};function D(E,C,w=Q){let{seed:m,k2sig:x}=N(E,C,w),S=t;return Eo(S.hash.outputLen,S.nByteLength,S.hmac)(m,x)}c.BASE._setWindowSize(8);function it(E,C,w,m=q){let x=E;C=nt("msgHash",C),w=nt("publicKey",w);let{lowS:S,prehash:R,format:_}=m;if(hl(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 P=typeof x=="string"||Ne(x),F=!P&&!_&&typeof x=="object"&&x!==null&&typeof x.r=="bigint"&&typeof x.s=="bigint";if(!P&&!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)),P){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&&(C=t.hash(C));let{r:J,s:lt}=O,ut=L(C),ht=a(lt),bt=i(ut*ht),Nt=i(J*ht),At=c.BASE.multiplyAndAddUnsafe(j,bt,Nt)?.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 Td(r){return{hash:r,hmac:(t,...e)=>Ii(r,t,go(...e)),randomBytes:yn}}function gl(r,t){let e=n=>pl({...r,...Td(n)});return Object.freeze({...e(t),create:e})}var yl=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),ml=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Ld=BigInt(1),ki=BigInt(2),bl=(r,t)=>(r+t/ki)/t;function Ud(r){let t=yl,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=et(u,e,t)*u%t,h=et(f,e,t)*u%t,d=et(h,ki,t)*l%t,p=et(d,s,t)*d%t,b=et(p,o,t)*p%t,g=et(b,a,t)*b%t,v=et(g,c,t)*g%t,A=et(v,a,t)*b%t,y=et(A,e,t)*u%t,I=et(y,i,t)*p%t,U=et(I,n,t)*l%t,L=et(U,ki,t);if(!Ni.eql(Ni.sqr(L),r))throw new Error("Cannot find square root");return L}var Ni=Le(yl,void 0,void 0,{sqrt:Ud}),tr=gl({a:BigInt(0),b:BigInt(7),Fp:Ni,n:ml,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=ml,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Ld*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=e,i=BigInt("0x100000000000000000000000000000000"),a=bl(o*r,t),c=bl(-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}}}},fl),xb=BigInt(0);var vb=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 wl(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function xl(r,t,e){let n=Pr.digest(e instanceof Uint8Array?e:e.subarray());if(wl(n))return n.then(({digest:s})=>tr.verify(t,s,r)).catch(s=>{throw new Zr(String(s))});try{return tr.verify(t,n.digest,r)}catch(s){throw new Zr(String(s))}}var Ls=class{type="secp256k1";raw;_key;constructor(t){this._key=El(t),this.raw=vl(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 xl(this._key,e,t)}};function Ci(r){return new Ls(r)}function vl(r){return tr.ProjectivePoint.fromHex(r).toRawBytes(!0)}function El(r){try{return tr.ProjectivePoint.fromHex(r),r}catch(t){throw new rr(String(t))}}function wr(r){let{Type:t,Data:e}=te.decode(r),n=e??new Uint8Array;switch(t){case ct.RSA:return Ai(n);case ct.Ed25519:return Ro(n);case ct.secp256k1:return Ci(n);default:throw new Ke}}function Bl(r){let{Type:t,Data:e}=te.decode(r.digest),n=e??new Uint8Array;switch(t){case ct.Ed25519:return Ro(n);case ct.secp256k1:return Ci(n);default:throw new Ke}}function Ue(r){return te.encode({Type:ct[r.type],Data:r.raw})}var Sl=Symbol.for("@achingbrain/uint8arraylist");function Al(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 Us(r){return!!r?.[Sl]}var Zt=class r{bufs;length;[Sl]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Us(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(Us(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=Al(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Al(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(Us(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(!Us(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 Xr;(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)})(Xr||(Xr={}));var Rs=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var se=class r{static createFromProtobuf=async t=>{let e=Xr.decode(t),n=wr(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 Rs("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=Xr.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=Il(t,this.payloadType,this.payload);return this.publicKey.verify(e.subarray(),this.signature)}},Il=(r,t,e)=>{let n=$(r),s=Vt(n.byteLength),o=Vt(t.length),i=Vt(e.length);return new Zt(s,n,o,t,i,e)};var kl=Symbol.for("nodejs.util.inspect.custom"),Rd=114,Qr=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()})`}[no]=!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(Rd,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")}[kl](){return`PeerId(${this.toString()})`}},tn=class extends Qr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},en=class extends Qr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},rn=class extends Qr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},_d=2336,nn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=le.digest($(this.url))}[kl](){return`PeerId(${this.url})`}[no]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return dt.createV1(_d,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=rt(t)),t.toString()===this.toString())}};var Od=114,Nl=2336;function Cl(r){if(r.type==="Ed25519")return new en({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new rn({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new tn({multihash:r.toCID().multihash,publicKey:r});throw new Ke}function Ti(r){if(Pd(r))return new tn({multihash:r});if(Vd(r))try{let t=Bl(r);if(t.type==="Ed25519")return new en({multihash:r,publicKey:t});if(t.type==="secp256k1")return new rn({multihash:r,publicKey:t})}catch{let e=rt(r.digest);return new nn(new URL(e))}throw new hn("Supplied PeerID Multihash is invalid")}function _s(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==Od&&r.code!==Nl)throw new fn("Supplied PeerID CID is invalid");if(r.code===Nl){let t=rt(r.multihash.digest);return new nn(new URL(t))}return Ti(r.multihash)}function Vd(r){return r.code===le.code}function Pd(r){return r.code===Pr.code}function Tl(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 Os=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 Ll=45,Dd=15,xr=new Os;function Li(r){if(!(r.length>Dd))return xr.new(r).parseWith(()=>xr.readIPv4Addr())}function Ui(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Ll))return xr.new(r).parseWith(()=>xr.readIPv6Addr())}function Vs(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Ll))return xr.new(r).parseWith(()=>xr.readIPAddr())}var Xy=parseInt("0xFFFF",16),Qy=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function vr(r){return!!Li(r)}function Er(r){return!!Ui(r)}function Ps(r){return!!Vs(r)}var _l=vr,qd=Er,Ri=function(r){let t=0;if(r=r.toString().trim(),_l(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(qd(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let o=_l(e[n]),i;o&&(i=Ri(e[n]),e[n]=rt(i.slice(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,rt(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")},Ol=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let s=[];for(let o=0;o<e;o++)s.push(r[t+o]);return s.join(".")}if(e===16){let s=[];for(let o=0;o<e;o+=2)s.push(n.getUint16(t+o).toString(16));return s.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var Br={},_i={},zd=[[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"]];zd.forEach(r=>{let t=Gd(...r);_i[t.code]=t,Br[t.name]=t});function Gd(r,t,e,n,s){return{code:r,size:t,name:e,resolvable:!!n,path:!!s}}function z(r){if(typeof r=="number"){if(_i[r]!=null)return _i[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Br[r]!=null)return Br[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Vw=z("ip4"),Pw=z("ip6"),Dw=z("ipcidr");function Di(r,t){switch(z(r).code){case 4:case 41:return jd(t);case 42:return Pi(t);case 6:case 273:case 33:case 132:return Dl(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Pi(t);case 421:return Xd(t);case 444:return Pl(t);case 445:return Pl(t);case 466:return Jd(t);case 481:return globalThis.encodeURIComponent(Pi(t));default:return rt(t,"base16")}}function Mi(r,t){switch(z(r).code){case 4:return Vl(t);case 41:return Vl(t);case 42:return Vi(t);case 6:case 273:case 33:case 132:return Fi(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Vi(t);case 421:return Zd(t);case 444:return Qd(t);case 445:return t0(t);case 466:return Yd(t);case 481:return Vi(globalThis.decodeURIComponent(t));default:return $(t,"base16")}}var Oi=Object.values(Dr).map(r=>r.decoder),Wd=function(){let r=Oi[0].or(Oi[1]);return Oi.slice(2).forEach(t=>r=r.or(t)),r}();function Vl(r){if(!Ps(r))throw new Error("invalid ip address");return Ri(r)}function jd(r){let t=Ol(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!Ps(t))throw new Error("invalid ip address");return t}function Fi(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Dl(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Vi(r){let t=$(r),e=Uint8Array.from(Vt(t.length));return Ot([e,t],e.length+t.length)}function Pi(r){let t=pe(r);if(r=r.slice(xt(t)),r.length!==t)throw new Error("inconsistent lengths");return rt(r)}function Zd(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(Vt(t.length));return Ot([e,t],e.length+t.length)}function Yd(r){let t=Wd.decode(r),e=Uint8Array.from(Vt(t.length));return Ot([e,t],e.length+t.length)}function Jd(r){let t=pe(r),e=r.slice(xt(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+rt(e,"base64url")}function Xd(r){let t=pe(r),e=r.slice(xt(t));if(e.length!==t)throw new Error("inconsistent lengths");return rt(e,"base58btc")}function Qd(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=Fi(n);return Ot([e,s],e.length+s.length)}function t0(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=Fi(n);return Ot([e,s],e.length+s.length)}function Pl(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=rt(t,"base32"),s=Dl(e);return`${n}:${s}`}function Ml(r){r=Hi(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 Hl("invalid address: "+r);if(a.path===!0){n=Hi(s.slice(o).join("/")),t.push([a.code,Mi(a.code,n)]),e.push([a.code,n]);break}let c=Mi(a.code,s[o]);t.push([a.code,c]),e.push([a.code,Di(a.code,c)])}return{string:Fl(e),bytes:qi(t),tuples:t,stringTuples:e,path:n}}function Ki(r){let t=[],e=[],n=null,s=0;for(;s<r.length;){let o=pe(r,s),i=xt(o),a=z(o),c=e0(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 Hl("Invalid address Uint8Array: "+rt(r,"base16"));t.push([o,l]);let u=Di(o,l);if(e.push([o,u]),a.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:Fl(e),tuples:t,stringTuples:e,path:n}}function Fl(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}),Hi(t.join("/"))}function qi(r){return Ot(r.map(t=>{let e=z(t[0]),n=Uint8Array.from(Vt(e.code));return t.length>1&&t[1]!=null&&(n=Ot([n,t[1]])),n}))}function e0(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 Hi(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}function Hl(r){return new Error("Error parsing address: "+r)}var r0=Symbol.for("nodejs.util.inspect.custom"),zi=Symbol.for("@multiformats/js-multiaddr/multiaddr"),n0=[z("dns").code,z("dns4").code,z("dns6").code,z("dnsaddr").code],$i=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},Ds=class r{bytes;#e;#t;#r;#n;[zi]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=Ki(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Ml(t)}else if(ql(t))e=Ki(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??""}`),n0.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(qi(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,s])=>{n===Br.p2p.code&&t.push([n,s]),n===Br["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?rt(X.decode(`z${n}`),"base58btc"):rt(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=Kl.get(e.name);if(n==null)throw new $i(`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)}[r0](){return`Multiaddr(${this.#e})`}};var Kl=new Map;function ql(r){return!!r?.[zi]}function oe(r){return new Ds(r)}var $l="libp2p-peer-record",zl=Uint8Array.from([3,1]);var sn;(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)})(sn||(sn={}));var Yt=class r{static createFromProtobuf=t=>{let e=sn.decode(t),n=Ti(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=$l;static CODEC=zl;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=sn.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||!Tl(this.multiaddrs,t.multiaddrs))}};function s0(r){return r[Symbol.asyncIterator]!=null}function o0(r){if(s0(r))return(async()=>{for await(let t of r);})();for(let t of r);}var Gl=o0;function Jt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Ms=globalThis.CustomEvent??Event;async function*Gi(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 Ms("task-complete"))},g=>{b.done=!0,b.err=g,s.dispatchEvent(new Ms("task-complete"))})}c=!0,s.dispatchEvent(new Ms("task-complete"))}catch(p){l=p,s.dispatchEvent(new Ms("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 Fs=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 Wl(r,t,e){if(t==null)return r;if(t.aborted)return Promise.reject(new Fs(e?.errorMessage,e?.errorCode,e?.errorName));let n,s=new Fs(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 Wi=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 Wl(this.readNext.promise,e?.signal,e)}};function jl(){return new Wi}var Hs=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};var ji=class extends Error{code;constructor(t,e){super(t),this.code=e}},Zi=class extends ji{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted",this.name="AbortError"}};function Zl(r,t){let e=jl();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 Zi("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 Hs("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 Ks=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},qs=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},$s=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Yl(r,t={}){let e=Zl(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=xt(t.maxDataLength));let n=t?.lengthDecoder??pe,s=t?.lengthEncoder??Vt;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 Ks("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new $s("message length length too long");if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new qs("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 Ar(r,t){let e=Yl(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 Jl="0.1.0",Xl="id",Ql="id/push",tu="1.0.0",eu="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 su=ro(nu(),1),Yi=typeof window=="object"&&typeof document=="object"&&document.nodeType===9,zs=(0,su.default)(),ou=Yi&&!zs,iu=zs&&!Yi,au=zs&&Yi,cu=typeof globalThis.process<"u"&&typeof globalThis.process.release<"u"&&globalThis.process.release.name==="node"&&!zs,lu=typeof importScripts=="function"&&typeof self<"u"&&typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope,zx=typeof globalThis.process<"u"&&typeof globalThis.process.env<"u"&&globalThis.process.env["NODE"+"_"+"ENV"]==="test",uu=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 fu(r){if(r!=null&&r.length>0)try{return oe(r)}catch{}}function l0(r,t){return t!=null||(t=`${r.name}/${r.version}`,cu||iu?t+=` UserAgent=${globalThis.process.version}`:(ou||lu||au||uu)&&(t+=` UserAgent=${globalThis.navigator.userAgent}`)),t}async function Gs(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=wr(s.publicKey);if(!Cl(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=_s(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 Sr=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}/${Jl}`,agentVersion:l0(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 Ws=class extends Sr{connectionManager;concurrency;constructor(t,e={}){super(t,{...e,protocol:`/${e.protocolPrefix??Rt.protocolPrefix}/${Ql}/${eu}`,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)})})}[pn]=["@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=rt(o.metadata.get("AgentVersion")??$(this.host.agentVersion)),a=rt(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);Nr(1/0,d);try{h=await u.newStream(c.protocol,{signal:d,runOnLimitedConnection:c.runOnLimitedConnection}),await Ar(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 Gl(Gi(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 Ar(n,{maxDataLength:this.maxMessageSize}).pb(He).read(s);await n.close(s),await Gs(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 du=ro(hu(),1),u0=["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"],f0=u0.map(r=>new du.Netmask(r));function Ji(r){for(let t of f0)if(t.contains(r))return!0;return!1}function h0(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function d0(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 Ji(s)}function p0(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function g0(r){let t=r.split(":"),e=t[t.length-1];return Ji(e)}function m0(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 pu(r){return vr(r)?Ji(r):h0(r)?d0(r):p0(r)?g0(r):Er(r)?m0(r):void 0}var b0=r=>r.toString().split("/").slice(1),Ir=r=>({match:t=>t.length<1?!1:r(t[0])?t.slice(1):!1,pattern:"fn"}),H=r=>({match:t=>Ir(e=>e===r).match(t),pattern:r}),er=()=>({match:r=>Ir(t=>typeof t=="string").match(r),pattern:"{string}"}),an=()=>({match:r=>Ir(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}"}),cn=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{Zo.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=b0(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 Zs=K(H("dns4"),er()),Ys=K(H("dns6"),er()),Js=K(H("dnsaddr"),er()),Qi=K(H("dns"),er()),E1=st(Zs,G(Y())),B1=st(Ys,G(Y())),A1=st(Js,G(Y())),S1=st(Bt(Qi,Js,Zs,Ys),G(Y())),gu=K(H("ip4"),Ir(vr)),mu=K(H("ip6"),Ir(Er)),ta=Bt(gu,mu),Be=Bt(ta,Qi,Zs,Ys,Js),bu=st(Bt(ta,K(Bt(Qi,Js,Zs,Ys),G(Y())))),I1=st(gu),k1=st(mu),N1=st(ta),ea=K(Be,H("tcp"),an()),ln=K(Be,H("udp"),an()),C1=st(K(ea,G(Y()))),T1=st(ln),ra=K(ln,H("quic"),G(Y())),Xs=K(ln,H("quic-v1"),G(Y())),y0=Bt(ra,Xs),L1=st(ra),U1=st(Xs),Xi=Bt(Be,ea,ln,ra,Xs),yu=Bt(K(Xi,H("ws"),G(Y()))),R1=st(yu),wu=Bt(K(Xi,H("wss"),G(Y())),K(Xi,H("tls"),G(K(H("sni"),er())),H("ws"),G(Y()))),_1=st(wu),xu=K(ln,H("webrtc-direct"),G(cn()),G(cn()),G(Y())),O1=st(xu),vu=K(Xs,H("webtransport"),G(cn()),G(cn()),G(Y())),V1=st(vu),js=Bt(yu,wu,K(ea,G(Y())),K(y0,G(Y())),K(Be,G(Y())),xu,vu,Y()),P1=st(js),w0=K(js,H("p2p-circuit"),Y()),D1=st(w0),x0=Bt(K(js,H("p2p-circuit"),H("webrtc"),G(Y())),K(js,H("webrtc"),G(Y())),K(H("webrtc"),G(Y()))),M1=st(x0),v0=Bt(K(Be,H("tcp"),an(),H("http"),G(Y())),K(Be,H("http"),G(Y()))),F1=st(v0),E0=Bt(K(Be,H("tcp"),Bt(K(H("443"),H("http")),K(an(),H("https"))),G(Y())),K(Be,H("tls"),H("http"),G(Y())),K(Be,H("https"),G(Y()))),H1=st(E0),B0=Bt(K(H("memory"),er(),G(Y()))),K1=st(B0);var Qs=class extends Sr{constructor(t,e={}){super(t,{...e,protocol:`/${e.protocolPrefix??Rt.protocolPrefix}/${Xl}/${tu}`,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!==dn.name&&this.log.error("error during identify trigged by connection:open",o)})})}[pn]=["@libp2p/identify"];async _identify(t,e={}){let n;if(e.signal==null){let s=AbortSignal.timeout(this.timeout);Nr(1/0,s),e={...e,signal:s}}try{n=await t.newStream(this.protocol,{...e,runOnLimitedConnection:this.runOnLimitedConnection});let o=await Ar(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=wr(s),c=_s(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=fu(i);return this.log("identify completed for peer %p and protocols %o",c,o),l!=null&&(this.log("our observed address was %a",l),pu(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))),Gs(this.peerStore,this.events,this.log,t,n)}async handleProtocol(t){let{connection:e,stream:n}=t,s=AbortSignal.timeout(this.timeout);Nr(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;bu.matches(e.remoteAddr)||(c=void 0),await Ar(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 A0(r={}){return t=>new Qs(t,r)}function S0(r={}){return t=>new Ws(t,r)}return Ou(I0);})();
|
|
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:
|