@libp2p/identify 3.0.23-e2f49432b → 3.0.24-3f127b610
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 +1 -71
- package/package.json +8 -8
package/dist/index.min.js
CHANGED
|
@@ -1,37 +1,7 @@
|
|
|
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 wu=Object.create;var hn=Object.defineProperty;var xu=Object.getOwnPropertyDescriptor;var vu=Object.getOwnPropertyNames;var Eu=Object.getPrototypeOf,Bu=Object.prototype.hasOwnProperty;var sa=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),St=(r,t)=>{for(var e in t)hn(r,e,{get:t[e],enumerable:!0})},oa=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of vu(t))!Bu.call(r,s)&&s!==e&&hn(r,s,{get:()=>t[s],enumerable:!(n=xu(t,s))||n.enumerable});return r};var ia=(r,t,e)=>(e=r!=null?wu(Eu(r)):{},oa(t||!r||!r.__esModule?hn(e,"default",{value:r,enumerable:!0}):e,r)),Au=r=>oa(hn({},"__esModule",{value:!0}),r);var ic=sa(pr=>{"use strict";var jh="[object ArrayBuffer]",pe=class r{static isArrayBuffer(t){return Object.prototype.toString.call(t)===jh}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 c=this.toUint8Array(i);s.set(c,o),o+=c.length}return t[t.length-1]instanceof Function?this.toView(s,t[t.length-1]):s.buffer}},fi="string",Zh=/^[0-9a-f\s]+$/i,Yh=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Jh=/^[a-zA-Z0-9-_]+$/,Vn=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=pe.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=pe.toArrayBuffer(t),s=new DataView(n),o="";for(let i=0;i<n.byteLength;i+=2){let c=s.getUint16(i,e);o+=String.fromCharCode(c)}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}},Dn=class r{static isHex(t){return typeof t===fi&&Zh.test(t)}static isBase64(t){return typeof t===fi&&Yh.test(t)}static isBase64Url(t){return typeof t===fi&&Jh.test(t)}static ToString(t,e="utf8"){let n=pe.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=pe.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 Vn.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 Vn.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=pe.toUint8Array(t),n="";for(let s=0;s<e.length;s++)n+=String.fromCharCode(e[s]);return n}static ToHex(t){let e=pe.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,"")||""}};Dn.DEFAULT_UTF8_ENCODING="utf8";function Xh(r,...t){let e=arguments[0];for(let n=1;n<arguments.length;n++){let s=arguments[n];for(let o in s)e[o]=s[o]}return e}function Qh(...r){let t=r.map(s=>s.byteLength).reduce((s,o)=>s+o),e=new Uint8Array(t),n=0;return r.map(s=>new Uint8Array(s)).forEach(s=>{for(let o of s)e[n++]=o}),e.buffer}function td(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}pr.BufferSourceConverter=pe;pr.Convert=Dn;pr.assign=Xh;pr.combine=Qh;pr.isEqual=td});var Xl=sa(cn=>{(function(){var r,t,e,n,s,o,i,c;c=function(a){var l,u,f,h;return l=(a&255<<24)>>>24,u=(a&255<<16)>>>16,f=(a&65280)>>>8,h=a&255,[l,u,f,h].join(".")},i=function(a){var l,u,f,h,m,p;for(l=[],f=h=0;h<=3&&a.length!==0;f=++h){if(f>0){if(a[0]!==".")throw new Error("Invalid IP");a=a.substring(1)}p=t(a),m=p[0],u=p[1],a=a.substring(u),l.push(m)}if(a.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(a){return a.charCodeAt(0)},n=e("0"),o=e("a"),s=e("A"),t=function(a){var l,u,f,h,m;for(h=0,l=10,u="9",f=0,a.length>1&&a[f]==="0"&&(a[f+1]==="x"||a[f+1]==="X"?(f+=2,l=16):"0"<=a[f+1]&&a[f+1]<="9"&&(f++,l=8,u="7")),m=f;f<a.length;){if("0"<=a[f]&&a[f]<=u)h=h*l+(e(a[f])-n)>>>0;else if(l===16)if("a"<=a[f]&&a[f]<="f")h=h*l+(10+e(a[f])-o)>>>0;else if("A"<=a[f]&&a[f]<="F")h=h*l+(10+e(a[f])-s)>>>0;else break;else break;if(h>4294967295)throw new Error("too large");f++}if(f===m)throw new Error("empty octet");return[h,f]},r=function(){function a(l,u){var f,h,m,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=m=32;m>=0;h=--m)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=c(this.netLong),this.mask=c(this.maskLong),this.hostmask=c(~this.maskLong),this.first=this.bitmask<=30?c(this.netLong+1):this.base,this.last=this.bitmask<=30?c(this.netLong+this.size-2):c(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?c(this.netLong+this.size-1):void 0}return a.prototype.contains=function(l){return typeof l=="string"&&(l.indexOf("/")>0||l.split(".").length!==4)&&(l=new a(l)),l instanceof a?this.contains(l.base)&&this.contains(l.broadcast||l.last):(i(l)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},a.prototype.next=function(l){return l==null&&(l=1),new a(c(this.netLong+this.size*l),this.mask)},a.prototype.forEach=function(l){var u,f,h;for(h=i(this.first),f=i(this.last),u=0;h<=f;)l(c(h),h,u),u++,h++},a.prototype.toString=function(){return this.base+"/"+this.bitmask},a}(),cn.ip2long=i,cn.long2ip=c,cn.Netmask=r}).call(cn)});var l0={};St(l0,{identify:()=>a0,identifyPush:()=>c0});var eo=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 dn=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},pn=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}},mn=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 Me=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var gn=Symbol.for("@libp2p/service-capabilities"),d0=Symbol.for("@libp2p/service-dependencies");var io={};St(io,{base58btc:()=>X,base58flickr:()=>Tu});var O0=new Uint8Array(0);function aa(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 ie(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 ca(r){return new TextEncoder().encode(r)}function la(r){return new TextDecoder().decode(r)}function Su(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 c=r.length,a=r.charAt(0),l=Math.log(c)/Math.log(256),u=Math.log(256)/Math.log(c);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,d=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 L=p[v],U=0,k=y-1;(L!==0||U<d)&&k!==-1;k--,U++)L+=256*I[k]>>>0,I[k]=L%c>>>0,L=L/c>>>0;if(L!==0)throw new Error("Non-zero carry");d=U,v++}for(var T=y-d;T!==y&&I[T]===0;)T++;for(var C=a.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 d=0,v=0;p[b]===a;)d++,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 L=0,U=A-1;(I!==0||L<v)&&U!==-1;U--,L++)I+=c*y[U]>>>0,y[U]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");v=L,b++}if(p[b]!==" "){for(var k=A-v;k!==A&&y[k]===0;)k++;for(var T=new Uint8Array(d+(A-k)),C=d;k!==A;)T[C++]=y[k++];return T}}}function m(p){var b=h(p);if(b)return b;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:h,decode:m}}var Iu=Su,ku=Iu,fa=ku;var ro=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")}},no=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 ha(this,t)}},so=class{decoders;constructor(t){this.decoders=t}or(t){return ha(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 ha(r,t){return new so({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var oo=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 ro(t,e,n),this.decoder=new no(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 oo(r,t,e,n)}function Be({name:r,prefix:t,alphabet:e}){let{encode:n,decode:s}=fa(e,r);return nr({prefix:t,name:r,encode:n,decode:o=>ie(s(o))})}function Cu(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),c=0,a=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`);a=a<<e|f,c+=e,c>=8&&(c-=8,i[l++]=255&a>>c)}if(c>=e||(255&a<<8-c)!==0)throw new SyntaxError("Unexpected end of data");return i}function Nu(r,t,e){let n=t[t.length-1]==="=",s=(1<<e)-1,o="",i=0,c=0;for(let a=0;a<r.length;++a)for(c=c<<8|r[a],i+=8;i>e;)i-=e,o+=t[s&c>>i];if(i!==0&&(o+=t[s&c<<e-i]),n)for(;(o.length*e&7)!==0;)o+="=";return o}function ot({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return nr({prefix:t,name:r,encode(s){return Nu(s,n,e)},decode(s){return Cu(s,n,e,r)}})}var X=Be({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Tu=Be({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ao={};St(ao,{base32:()=>ae,base32hex:()=>Pu,base32hexpad:()=>Ou,base32hexpadupper:()=>Vu,base32hexupper:()=>_u,base32pad:()=>Lu,base32padupper:()=>Ru,base32upper:()=>Uu,base32z:()=>Du});var ae=ot({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Uu=ot({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Lu=ot({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ru=ot({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Pu=ot({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),_u=ot({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ou=ot({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Vu=ot({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Du=ot({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var co={};St(co,{base36:()=>Tr,base36upper:()=>Mu});var Tr=Be({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Mu=Be({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Fu=ma,da=128,Hu=127,Ku=~Hu,qu=Math.pow(2,31);function ma(r,t,e){t=t||[],e=e||0;for(var n=e;r>=qu;)t[e++]=r&255|da,r/=128;for(;r&Ku;)t[e++]=r&255|da,r>>>=7;return t[e]=r|0,ma.bytes=e-n+1,t}var $u=lo,zu=128,pa=127;function lo(r,n){var e=0,n=n||0,s=0,o=n,i,c=r.length;do{if(o>=c)throw lo.bytes=0,new RangeError("Could not decode varint");i=r[o++],e+=s<28?(i&pa)<<s:(i&pa)*Math.pow(2,s),s+=7}while(i>=zu);return lo.bytes=o-n,e}var Gu=Math.pow(2,7),Wu=Math.pow(2,14),ju=Math.pow(2,21),Zu=Math.pow(2,28),Yu=Math.pow(2,35),Ju=Math.pow(2,42),Xu=Math.pow(2,49),Qu=Math.pow(2,56),tf=Math.pow(2,63),ef=function(r){return r<Gu?1:r<Wu?2:r<ju?3:r<Zu?4:r<Yu?5:r<Ju?6:r<Xu?7:r<Qu?8:r<tf?9:10},rf={encode:Fu,decode:$u,encodingLength:ef},nf=rf,Ur=nf;function Lr(r,t=0){return[Ur.decode(r,t),Ur.decode.bytes]}function sr(r,t,e=0){return Ur.encode(r,t,e),t}function or(r){return Ur.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 Fe(r){let t=ie(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 ga(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&aa(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 ya(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return of(e,uo(r),t??X.encoder);default:return af(e,uo(r),t??ae.encoder)}}var ba=new WeakMap;function uo(r){let t=ba.get(r);if(t==null){let e=new Map;return ba.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!==Rr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==cf)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&&ga(t.multihash,n.multihash)}toString(t){return ya(this,t)}toJSON(){return{"/":ya(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??wa(n,s,o.bytes))}else if(e[lf]===!0){let{version:n,multihash:s,code:o}=e,i=Fe(s);return r.create(n,o,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==Rr)throw new Error(`Version 0 CID must use dag-pb (code: ${Rr}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let s=wa(t,e,n.bytes);return new r(t,e,n,s)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Rr,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,s=ie(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=Rr;if(s===18?(s=0,e=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=e,c=n(),a=n(),l=e+a,u=l-i;return{version:s,codec:o,multihashCode:c,digestSize:a,multihashSize:u,size:l}}static parse(t,e){let[n,s]=sf(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 uo(o).set(n,t),o}};function sf(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 ae.prefix:{let e=t??ae;return[ae.prefix,e.decode(r)]}case Tr.prefix:{let e=t??Tr;return[Tr.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 of(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 af(r,t,e){let{prefix:n}=e,s=t.get(n);if(s==null){let o=e.encode(r);return t.set(n,o),o}else return s}var Rr=112,cf=18;function wa(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 lf=Symbol.for("@ipld/js-cid/CID");var fo={};St(fo,{identity:()=>ce});var xa=0,uf="identity",va=ie;function ff(r){return Mt(xa,va(r))}var ce={code:xa,name:uf,encode:va,digest:ff};function bt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Ea(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function hf(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function ar(r,...t){if(!hf(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 Ba(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Ea(r.outputLen),Ea(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 Aa(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 He=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function bn(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Ft(r,t){return r<<32-t|r>>>t}function Sa(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function Pr(r){return typeof r=="string"&&(r=Sa(r)),ar(r),r}function ho(...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 wn(r){let t=n=>r().update(Pr(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function xn(r=32){if(He&&typeof He.getRandomValues=="function")return He.getRandomValues(new Uint8Array(r));if(He&&typeof He.randomBytes=="function")return He.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),c=Number(e&o),a=n?4:0,l=n?0:4;r.setUint32(t+a,i,n),r.setUint32(t+l,c,n)}function Ia(r,t,e){return r&t^~r&e}function ka(r,t,e){return r&t^r&e^t&e}var 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=bn(this.buffer)}update(t){cr(this);let{view:e,buffer:n,blockLen:s}=this;t=Pr(t);let o=t.length;for(let i=0;i<o;){let c=Math.min(s-this.pos,o-i);if(c===s){let a=bn(t);for(;s<=o-i;i+=s)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===s&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){cr(this),Aa(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 c=bn(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=a/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<l;f++)c.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:c}=this;return t.length=s,t.pos=c,t.finished=o,t.destroyed=i,s%e&&t.buffer.set(n),t}};var vn=BigInt(4294967295),po=BigInt(32);function Ca(r,t=!1){return t?{h:Number(r&vn),l:Number(r>>po&vn)}:{h:Number(r>>po&vn)|0,l:Number(r&vn)|0}}function pf(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}=Ca(r[s],t);[e[s],n[s]]=[o,i]}return[e,n]}var mf=(r,t)=>BigInt(r>>>0)<<po|BigInt(t>>>0),gf=(r,t,e)=>r>>>e,yf=(r,t,e)=>r<<32-e|t>>>e,bf=(r,t,e)=>r>>>e|t<<32-e,wf=(r,t,e)=>r<<32-e|t>>>e,xf=(r,t,e)=>r<<64-e|t>>>e-32,vf=(r,t,e)=>r>>>e-32|t<<64-e,Ef=(r,t)=>t,Bf=(r,t)=>r,Af=(r,t,e)=>r<<e|t>>>32-e,Sf=(r,t,e)=>t<<e|r>>>32-e,If=(r,t,e)=>t<<e-32|r>>>64-e,kf=(r,t,e)=>r<<e-32|t>>>64-e;function Cf(r,t,e,n){let s=(t>>>0)+(n>>>0);return{h:r+e+(s/2**32|0)|0,l:s|0}}var Nf=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Tf=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Uf=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Lf=(r,t,e,n,s)=>t+e+n+s+(r/2**32|0)|0,Rf=(r,t,e,n,s)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(s>>>0),Pf=(r,t,e,n,s,o)=>t+e+n+s+o+(r/2**32|0)|0;var _f={fromBig:Ca,split:pf,toBig:mf,shrSH:gf,shrSL:yf,rotrSH:bf,rotrSL:wf,rotrBH:xf,rotrBL:vf,rotr32H:Ef,rotr32L:Bf,rotlSH:Af,rotlSL:Sf,rotlBH:If,rotlBL:kf,add:Cf,add3L:Nf,add3H:Tf,add4L:Uf,add4H:Lf,add5H:Pf,add5L:Rf},O=_f;var[Of,Vf]=O.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))),Se=new Uint32Array(80),Ie=new Uint32Array(80),mo=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:c,Dl:a,Eh:l,El:u,Fh:f,Fl:h,Gh:m,Gl:p,Hh:b,Hl:d}=this;return[t,e,n,s,o,i,c,a,l,u,f,h,m,p,b,d]}set(t,e,n,s,o,i,c,a,l,u,f,h,m,p,b,d){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=s|0,this.Ch=o|0,this.Cl=i|0,this.Dh=c|0,this.Dl=a|0,this.Eh=l|0,this.El=u|0,this.Fh=f|0,this.Fl=h|0,this.Gh=m|0,this.Gl=p|0,this.Hh=b|0,this.Hl=d|0}process(t,e){for(let y=0;y<16;y++,e+=4)Se[y]=t.getUint32(e),Ie[y]=t.getUint32(e+=4);for(let y=16;y<80;y++){let I=Se[y-15]|0,L=Ie[y-15]|0,U=O.rotrSH(I,L,1)^O.rotrSH(I,L,8)^O.shrSH(I,L,7),k=O.rotrSL(I,L,1)^O.rotrSL(I,L,8)^O.shrSL(I,L,7),T=Se[y-2]|0,C=Ie[y-2]|0,tt=O.rotrSH(T,C,19)^O.rotrBH(T,C,61)^O.shrSH(T,C,6),q=O.rotrSL(T,C,19)^O.rotrBL(T,C,61)^O.shrSL(T,C,6),D=O.add4L(k,q,Ie[y-7],Ie[y-16]),it=O.add4H(D,U,tt,Se[y-7],Se[y-16]);Se[y]=it|0,Ie[y]=D|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:c,Cl:a,Dh:l,Dl:u,Eh:f,El:h,Fh:m,Fl:p,Gh:b,Gl:d,Hh:v,Hl:A}=this;for(let y=0;y<80;y++){let I=O.rotrSH(f,h,14)^O.rotrSH(f,h,18)^O.rotrBH(f,h,41),L=O.rotrSL(f,h,14)^O.rotrSL(f,h,18)^O.rotrBL(f,h,41),U=f&m^~f&b,k=h&p^~h&d,T=O.add5L(A,L,k,Vf[y],Ie[y]),C=O.add5H(T,v,I,U,Of[y],Se[y]),tt=T|0,q=O.rotrSH(n,s,28)^O.rotrBH(n,s,34)^O.rotrBH(n,s,39),D=O.rotrSL(n,s,28)^O.rotrBL(n,s,34)^O.rotrBL(n,s,39),it=n&o^n&c^o&c,E=s&i^s&a^i&a;v=b|0,A=d|0,b=m|0,d=p|0,m=f|0,p=h|0,{h:f,l:h}=O.add(l|0,u|0,C|0,tt|0),l=c|0,u=a|0,c=o|0,a=i|0,o=n|0,i=s|0;let N=O.add3L(tt,D,E);n=O.add3H(N,C,q,it),s=N|0}({h:n,l:s}=O.add(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=O.add(this.Bh|0,this.Bl|0,o|0,i|0),{h:c,l:a}=O.add(this.Ch|0,this.Cl|0,c|0,a|0),{h:l,l:u}=O.add(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:h}=O.add(this.Eh|0,this.El|0,f|0,h|0),{h:m,l:p}=O.add(this.Fh|0,this.Fl|0,m|0,p|0),{h:b,l:d}=O.add(this.Gh|0,this.Gl|0,b|0,d|0),{h:v,l:A}=O.add(this.Hh|0,this.Hl|0,v|0,A|0),this.set(n,s,o,i,c,a,l,u,f,h,m,p,b,d,v,A)}roundClean(){Se.fill(0),Ie.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 Na=wn(()=>new mo);var An={};St(An,{aInRange:()=>Nt,abool:()=>Ht,abytes:()=>fr,bitGet:()=>qf,bitLen:()=>wo,bitMask:()=>Or,bitSet:()=>$f,bytesToHex:()=>ue,bytesToNumberBE:()=>fe,bytesToNumberLE:()=>Ce,concatBytes:()=>he,createHmacDrbg:()=>xo,ensureBytes:()=>nt,equalBytes:()=>Hf,hexToBytes:()=>qe,hexToNumber:()=>bo,inRange:()=>_r,isBytes:()=>ke,memoized:()=>ze,notImplemented:()=>Gf,numberToBytesBE:()=>Ne,numberToBytesLE:()=>$e,numberToHexUnpadded:()=>Ke,numberToVarBytesBE:()=>Ff,utf8ToBytes:()=>Kf,validateObject:()=>Xt});var En=BigInt(0),Bn=BigInt(1),Df=BigInt(2);function ke(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function fr(r){if(!ke(r))throw new Error("Uint8Array expected")}function Ht(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}var Mf=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function ue(r){fr(r);let t="";for(let e=0;e<r.length;e++)t+=Mf[r[e]];return t}function Ke(r){let t=r.toString(16);return t.length&1?"0"+t:t}function bo(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?En:BigInt("0x"+r)}var le={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ta(r){if(r>=le._0&&r<=le._9)return r-le._0;if(r>=le.A&&r<=le.F)return r-(le.A-10);if(r>=le.a&&r<=le.f)return r-(le.a-10)}function qe(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=Ta(r.charCodeAt(o)),c=Ta(r.charCodeAt(o+1));if(i===void 0||c===void 0){let a=r[o]+r[o+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+o)}n[s]=i*16+c}return n}function fe(r){return bo(ue(r))}function Ce(r){return fr(r),bo(ue(Uint8Array.from(r).reverse()))}function Ne(r,t){return qe(r.toString(16).padStart(t*2,"0"))}function $e(r,t){return Ne(r,t).reverse()}function Ff(r){return qe(Ke(r))}function nt(r,t,e){let n;if(typeof t=="string")try{n=qe(t)}catch(o){throw new Error(r+" must be hex string or Uint8Array, cause: "+o)}else if(ke(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 he(...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 Hf(r,t){if(r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}function Kf(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}var go=r=>typeof r=="bigint"&&En<=r;function _r(r,t,e){return go(r)&&go(t)&&go(e)&&t<=r&&r<e}function Nt(r,t,e,n){if(!_r(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function wo(r){let t;for(t=0;r>En;r>>=Bn,t+=1);return t}function qf(r,t){return r>>BigInt(t)&Bn}function $f(r,t,e){return r|(e?Bn:En)<<BigInt(t)}var Or=r=>(Df<<BigInt(r-1))-Bn,yo=r=>new Uint8Array(r),Ua=r=>Uint8Array.from(r);function xo(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=yo(r),s=yo(r),o=0,i=()=>{n.fill(1),s.fill(0),o=0},c=(...f)=>e(s,n,...f),a=(f=yo())=>{s=c(Ua([0]),f),n=c(),f.length!==0&&(s=c(Ua([1]),f),n=c())},l=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,h=[];for(;f<t;){n=c();let m=n.slice();h.push(m),f+=n.length}return he(...h)};return(f,h)=>{i(),a(f);let m;for(;!(m=h(l()));)a();return i(),m}}var zf={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"||ke(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 Xt(r,t,e={}){let n=(s,o,i)=>{let c=zf[o];if(typeof c!="function")throw new Error("invalid validator function");let a=r[s];if(!(i&&a===void 0)&&!c(a,r))throw new Error("param "+String(s)+" is invalid. Expected "+o+", got "+a)};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 Gf=()=>{throw new Error("not implemented")};function ze(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),Ge=BigInt(2),Wf=BigInt(3),vo=BigInt(4),La=BigInt(5),Ra=BigInt(8),jf=BigInt(9),Zf=BigInt(16);function Z(r,t){let e=r%t;return e>=at?e:t+e}function Yf(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 Sn(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,c=at;for(;e!==at;){let l=n/e,u=n%e,f=s-i*l,h=o-c*l;n=e,e=u,s=i,o=c,i=f,c=h}if(n!==et)throw new Error("invert: does not exist");return Z(s,t)}function Jf(r){let t=(r-et)/Ge,e,n,s;for(e=r-et,n=0;e%Ge===at;e/=Ge,n++);for(s=Ge;s<r&&Yf(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)/vo;return function(a,l){let u=a.pow(l,i);if(!a.eql(a.sqr(u),l))throw new Error("Cannot find square root");return u}}let o=(e+et)/Ge;return function(c,a){if(c.pow(a,t)===c.neg(c.ONE))throw new Error("Cannot find square root");let l=n,u=c.pow(c.mul(c.ONE,s),e),f=c.pow(a,o),h=c.pow(a,e);for(;!c.eql(h,c.ONE);){if(c.eql(h,c.ZERO))return c.ZERO;let m=1;for(let b=c.sqr(h);m<l&&!c.eql(b,c.ONE);m++)b=c.sqr(b);let p=c.pow(u,et<<BigInt(l-m-1));u=c.sqr(p),f=c.mul(f,p),h=c.mul(h,u),l=m}return f}}function Xf(r){if(r%vo===Wf){let t=(r+et)/vo;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%Ra===La){let t=(r-La)/Ra;return function(n,s){let o=n.mul(s,Ge),i=n.pow(o,t),c=n.mul(s,i),a=n.mul(n.mul(c,Ge),i),l=n.mul(c,n.sub(a,n.ONE));if(!n.eql(n.sqr(l),s))throw new Error("Cannot find square root");return l}}return r%Zf,Jf(r)}var Pa=(r,t)=>(Z(r,t)&et)===et,Qf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Eo(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=Qf.reduce((n,s)=>(n[s]="function",n),t);return Xt(r,e)}function th(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 eh(r,t){let e=new Array(t.length),n=t.reduce((o,i,c)=>r.is0(i)?o:(e[c]=o,r.mul(o,i)),r.ONE),s=r.inv(n);return t.reduceRight((o,i,c)=>r.is0(i)?o:(e[c]=r.mul(o,e[c]),r.mul(o,i)),s),e}function Bo(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Te(r,t,e=!1,n={}){if(r<=at)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:s,nByteLength:o}=Bo(r,t);if(o>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let i,c=Object.freeze({ORDER:r,isLE:e,BITS:s,BYTES:o,MASK:Or(s),ZERO:at,ONE:et,create:a=>Z(a,r),isValid:a=>{if(typeof a!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof a);return at<=a&&a<r},is0:a=>a===at,isOdd:a=>(a&et)===et,neg:a=>Z(-a,r),eql:(a,l)=>a===l,sqr:a=>Z(a*a,r),add:(a,l)=>Z(a+l,r),sub:(a,l)=>Z(a-l,r),mul:(a,l)=>Z(a*l,r),pow:(a,l)=>th(c,a,l),div:(a,l)=>Z(a*Sn(l,r),r),sqrN:a=>a*a,addN:(a,l)=>a+l,subN:(a,l)=>a-l,mulN:(a,l)=>a*l,inv:a=>Sn(a,r),sqrt:n.sqrt||(a=>(i||(i=Xf(r)),i(c,a))),invertBatch:a=>eh(c,a),cmov:(a,l,u)=>u?l:a,toBytes:a=>e?$e(a,o):Ne(a,o),fromBytes:a=>{if(a.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+a.length);return e?Ce(a):fe(a)}});return Object.freeze(c)}function _a(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 Ao(r){let t=_a(r);return t+Math.ceil(t/2)}function Oa(r,t,e=!1){let n=r.length,s=_a(t),o=Ao(t);if(n<16||n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);let i=e?Ce(r):fe(r),c=Z(i,t-et)+et;return e?$e(c,s):Ne(c,s)}var Va=BigInt(0),In=BigInt(1);function So(r,t){let e=t.negate();return r?e:t}function Da(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function Io(r,t){Da(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1);return{windows:e,windowSize:n}}function rh(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 ko=new WeakMap,Ma=new WeakMap;function Co(r){return Ma.get(r)||1}function kn(r,t){return{constTimeNegate:So,hasPrecomputes(e){return Co(e)!==1},unsafeLadder(e,n,s=r.ZERO){let o=e;for(;n>Va;)n&In&&(s=s.add(o)),o=o.double(),n>>=In;return s},precomputeWindow(e,n){let{windows:s,windowSize:o}=Io(n,t),i=[],c=e,a=c;for(let l=0;l<s;l++){a=c,i.push(a);for(let u=1;u<o;u++)a=a.add(c),i.push(a);c=a.double()}return i},wNAF(e,n,s){let{windows:o,windowSize:i}=Io(e,t),c=r.ZERO,a=r.BASE,l=BigInt(2**e-1),u=2**e,f=BigInt(e);for(let h=0;h<o;h++){let m=h*i,p=Number(s&l);s>>=f,p>i&&(p-=u,s+=In);let b=m,d=m+Math.abs(p)-1,v=h%2!==0,A=p<0;p===0?a=a.add(So(v,n[b])):c=c.add(So(A,n[d]))}return{p:c,f:a}},wNAFUnsafe(e,n,s,o=r.ZERO){let{windows:i,windowSize:c}=Io(e,t),a=BigInt(2**e-1),l=2**e,u=BigInt(e);for(let f=0;f<i;f++){let h=f*c;if(s===Va)break;let m=Number(s&a);if(s>>=u,m>c&&(m-=l,s+=In),m===0)continue;let p=n[h+Math.abs(m)-1];m<0&&(p=p.negate()),o=o.add(p)}return o},getPrecomputes(e,n,s){let o=ko.get(n);return o||(o=this.precomputeWindow(n,e),e!==1&&ko.set(n,s(o))),o},wNAFCached(e,n,s){let o=Co(e);return this.wNAF(o,this.getPrecomputes(o,e,s),n)},wNAFCachedUnsafe(e,n,s,o){let i=Co(e);return i===1?this.unsafeLadder(e,n,o):this.wNAFUnsafe(i,this.getPrecomputes(i,e,s),n,o)},setWindowSize(e,n){Da(n,t),Ma.set(e,n),ko.delete(e)}}}function Cn(r,t,e,n){if(rh(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=wo(BigInt(e.length)),i=o>12?o-3:o>4?o-2:o?2:1,c=(1<<i)-1,a=new Array(c+1).fill(s),l=Math.floor((t.BITS-1)/i)*i,u=s;for(let f=l;f>=0;f-=i){a.fill(s);for(let m=0;m<n.length;m++){let p=n[m],b=Number(p>>BigInt(f)&BigInt(c));a[b]=a[b].add(e[m])}let h=s;for(let m=a.length-1,p=s;m>0;m--)p=p.add(a[m]),h=h.add(p);if(u=u.add(h),f!==0)for(let m=0;m<i;m++)u=u.double()}return u}function Vr(r){return Eo(r.Fp),Xt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Bo(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Kt=BigInt(0),Tt=BigInt(1),Nn=BigInt(2),sh=BigInt(8),oh={zip215:!0};function ih(r){let t=Vr(r);return Xt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Fa(r){let t=ih(r),{Fp:e,n,prehash:s,hash:o,randomBytes:i,nByteLength:c,h:a}=t,l=Nn<<BigInt(c*8)-Tt,u=e.create,f=Te(t.n,t.nBitLength),h=t.uvRatio||((w,g)=>{try{return{isValid:!0,value:e.sqrt(w*e.inv(g))}}catch{return{isValid:!1,value:Kt}}}),m=t.adjustScalarBytes||(w=>w),p=t.domain||((w,g,x)=>{if(Ht("phflag",x),g.length||x)throw new Error("Contexts/pre-hash are not supported");return w});function b(w,g){Nt("coordinate "+w,g,Kt,l)}function d(w){if(!(w instanceof y))throw new Error("ExtendedPoint expected")}let v=ze((w,g)=>{let{ex:x,ey:S,ez:R}=w,P=w.is0();g==null&&(g=P?sh:e.inv(R));let V=u(x*g),F=u(S*g),_=u(R*g);if(P)return{x:Kt,y:Tt};if(_!==Tt)throw new Error("invZ was invalid");return{x:V,y:F}}),A=ze(w=>{let{a:g,d:x}=t;if(w.is0())throw new Error("bad point: ZERO");let{ex:S,ey:R,ez:P,et:V}=w,F=u(S*S),_=u(R*R),j=u(P*P),J=u(j*j),lt=u(F*g),ut=u(j*u(lt+_)),ht=u(J+u(x*u(F*_)));if(ut!==ht)throw new Error("bad point: equation left != right (1)");let yt=u(S*R),Ct=u(P*V);if(yt!==Ct)throw new Error("bad point: equation left != right (2)");return!0});class y{constructor(g,x,S,R){this.ex=g,this.ey=x,this.ez=S,this.et=R,b("x",g),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(g){if(g instanceof y)throw new Error("extended point not allowed");let{x,y:S}=g||{};return b("x",x),b("y",S),new y(x,S,Tt,u(x*S))}static normalizeZ(g){let x=e.invertBatch(g.map(S=>S.ez));return g.map((S,R)=>S.toAffine(x[R])).map(y.fromAffine)}static msm(g,x){return Cn(y,f,g,x)}_setWindowSize(g){U.setWindowSize(this,g)}assertValidity(){A(this)}equals(g){d(g);let{ex:x,ey:S,ez:R}=this,{ex:P,ey:V,ez:F}=g,_=u(x*F),j=u(P*R),J=u(S*F),lt=u(V*R);return _===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:g}=t,{ex:x,ey:S,ez:R}=this,P=u(x*x),V=u(S*S),F=u(Nn*u(R*R)),_=u(g*P),j=x+S,J=u(u(j*j)-P-V),lt=_+V,ut=lt-F,ht=_-V,yt=u(J*ut),Ct=u(lt*ht),At=u(J*ht),Jt=u(ut*lt);return new y(yt,Ct,Jt,At)}add(g){d(g);let{a:x,d:S}=t,{ex:R,ey:P,ez:V,et:F}=this,{ex:_,ey:j,ez:J,et:lt}=g;if(x===BigInt(-1)){let Ji=u((P-R)*(j+_)),Xi=u((P+R)*(j-_)),to=u(Xi-Ji);if(to===Kt)return this.double();let Qi=u(V*Nn*lt),ta=u(F*Nn*J),ea=ta+Qi,ra=Xi+Ji,na=ta-Qi,mu=u(ea*to),gu=u(ra*na),yu=u(ea*na),bu=u(to*ra);return new y(mu,gu,bu,yu)}let ut=u(R*_),ht=u(P*j),yt=u(F*S*lt),Ct=u(V*J),At=u((R+P)*(_+j)-ut-ht),Jt=Ct-yt,oe=Ct+yt,Nr=u(ht-x*ut),fu=u(At*Jt),hu=u(oe*Nr),du=u(At*Nr),pu=u(Jt*oe);return new y(fu,hu,pu,du)}subtract(g){return this.add(g.negate())}wNAF(g){return U.wNAFCached(this,g,y.normalizeZ)}multiply(g){let x=g;Nt("scalar",x,Tt,n);let{p:S,f:R}=this.wNAF(x);return y.normalizeZ([S,R])[0]}multiplyUnsafe(g,x=y.ZERO){let S=g;return Nt("scalar",S,Kt,n),S===Kt?L:this.is0()||S===Tt?this:U.wNAFCachedUnsafe(this,S,y.normalizeZ,x)}isSmallOrder(){return this.multiplyUnsafe(a).is0()}isTorsionFree(){return U.unsafeLadder(this,n).is0()}toAffine(g){return v(this,g)}clearCofactor(){let{h:g}=t;return g===Tt?this:this.multiplyUnsafe(g)}static fromHex(g,x=!1){let{d:S,a:R}=t,P=e.BYTES;g=nt("pointHex",g,P),Ht("zip215",x);let V=g.slice(),F=g[P-1];V[P-1]=F&-129;let _=Ce(V),j=x?l:e.ORDER;Nt("pointHex.y",_,Kt,j);let J=u(_*_),lt=u(J-Tt),ut=u(S*J-R),{isValid:ht,value:yt}=h(lt,ut);if(!ht)throw new Error("Point.fromHex: invalid y coordinate");let Ct=(yt&Tt)===Tt,At=(F&128)!==0;if(!x&&yt===Kt&&At)throw new Error("Point.fromHex: x=0 and x_0=1");return At!==Ct&&(yt=u(-yt)),y.fromAffine({x:yt,y:_})}static fromPrivateKey(g){return C(g).point}toRawBytes(){let{x:g,y:x}=this.toAffine(),S=$e(x,e.BYTES);return S[S.length-1]|=g&Tt?128:0,S}toHex(){return ue(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:L}=y,U=kn(y,c*8);function k(w){return Z(w,n)}function T(w){return k(Ce(w))}function C(w){let g=e.BYTES;w=nt("private key",w,g);let x=nt("hashed private key",o(w),2*g),S=m(x.slice(0,g)),R=x.slice(g,2*g),P=T(S),V=I.multiply(P),F=V.toRawBytes();return{head:S,prefix:R,scalar:P,point:V,pointBytes:F}}function tt(w){return C(w).pointBytes}function q(w=new Uint8Array,...g){let x=he(...g);return T(o(p(x,nt("context",w),!!s)))}function D(w,g,x={}){w=nt("message",w),s&&(w=s(w));let{prefix:S,scalar:R,pointBytes:P}=C(g),V=q(x.context,S,w),F=I.multiply(V).toRawBytes(),_=q(x.context,F,P,w),j=k(V+_*R);Nt("signature.s",j,Kt,n);let J=he(F,$e(j,e.BYTES));return nt("result",J,e.BYTES*2)}let it=oh;function E(w,g,x,S=it){let{context:R,zip215:P}=S,V=e.BYTES;w=nt("signature",w,2*V),g=nt("message",g),x=nt("publicKey",x,V),P!==void 0&&Ht("zip215",P),s&&(g=s(g));let F=Ce(w.slice(V,2*V)),_,j,J;try{_=y.fromHex(x,P),j=y.fromHex(w.slice(0,V),P),J=I.multiplyUnsafe(F)}catch{return!1}if(!P&&_.isSmallOrder())return!1;let lt=q(R,j.toRawBytes(),_.toRawBytes(),g);return j.add(_.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,g=y.BASE){return g._setWindowSize(w),g.multiply(BigInt(3)),g}}}}var No=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Ha=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Cp=BigInt(0),ah=BigInt(1),Ka=BigInt(2),Np=BigInt(3),ch=BigInt(5),lh=BigInt(8);function uh(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),s=BigInt(80),o=No,c=r*r%o*r%o,a=rt(c,Ka,o)*c%o,l=rt(a,ah,o)*r%o,u=rt(l,ch,o)*l%o,f=rt(u,t,o)*u%o,h=rt(f,e,o)*f%o,m=rt(h,n,o)*h%o,p=rt(m,s,o)*m%o,b=rt(p,s,o)*m%o,d=rt(b,t,o)*u%o;return{pow_p_5_8:rt(d,Ka,o)*r%o,b2:c}}function fh(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function hh(r,t){let e=No,n=Z(t*t*t,e),s=Z(n*n*t,e),o=uh(r*s).pow_p_5_8,i=Z(r*n*o,e),c=Z(t*i*i,e),a=i,l=Z(i*Ha,e),u=c===r,f=c===Z(-r,e),h=c===Z(-r*Ha,e);return u&&(i=a),(f||h)&&(i=l),Pa(i,e)&&(i=Z(-i,e)),{isValid:u||f,value:i}}var dh=Te(No,void 0,!0),ph={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:dh,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:lh,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Na,randomBytes:xn,adjustScalarBytes:fh,uvRatio:hh},qa=Fa(ph);var Tn=32;function $a(r,t,e){return qa.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var Un=class{type="Ed25519";raw;constructor(t){this.raw=To(t,Tn)}toMultihash(){return ce.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:bt(this.raw,t.raw)}verify(t,e){return $a(this.raw,e,t)}};function Uo(r){return r=To(r,Tn),new Un(r)}function To(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 Ut(r=0){return new Uint8Array(r)}var gh=Math.pow(2,7),yh=Math.pow(2,14),bh=Math.pow(2,21),Lo=Math.pow(2,28),Ro=Math.pow(2,35),Po=Math.pow(2,42),_o=Math.pow(2,49),W=128,wt=127;function xt(r){if(r<gh)return 1;if(r<yh)return 2;if(r<bh)return 3;if(r<Lo)return 4;if(r<Ro)return 5;if(r<Po)return 6;if(r<_o)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Oo(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 wh(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 Vo(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)*Lo,e<W)||(e=r[t+5],n+=(e&wt)*Ro,e<W)||(e=r[t+6],n+=(e&wt)*Po,e<W)||(e=r[t+7],n+=(e&wt)*_o,e<W))return n;throw new RangeError("Could not decode varint")}function xh(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)*Lo,e<W)||(e=r.get(t+5),n+=(e&wt)*Ro,e<W)||(e=r.get(t+6),n+=(e&wt)*Po,e<W)||(e=r.get(t+7),n+=(e&wt)*_o,e<W))return n;throw new RangeError("Could not decode varint")}function Ot(r,t,e=0){return t==null&&(t=Ut(xt(r))),t instanceof Uint8Array?Oo(r,t,e):wh(r,t,e)}function de(r,t=0){return r instanceof Uint8Array?Vo(r,t):xh(r,t)}var Do=new Float32Array([-0]),Le=new Uint8Array(Do.buffer);function Ga(r,t,e){Do[0]=r,t[e]=Le[0],t[e+1]=Le[1],t[e+2]=Le[2],t[e+3]=Le[3]}function Wa(r,t){return Le[0]=r[t],Le[1]=r[t+1],Le[2]=r[t+2],Le[3]=r[t+3],Do[0]}var Mo=new Float64Array([-0]),vt=new Uint8Array(Mo.buffer);function ja(r,t,e){Mo[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 Za(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],Mo[0]}var vh=BigInt(Number.MAX_SAFE_INTEGER),Eh=BigInt(Number.MIN_SAFE_INTEGER),Pt=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 We;if(t<vh&&t>Eh)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>Ya&&(s=0n,++n>Ya&&(n=0n))),new r(Number(s),Number(n))}static fromNumber(t){if(t===0)return We;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):We}},We=new Pt(0,0);We.toBigInt=function(){return 0n};We.zzEncode=We.zzDecode=function(){return this};We.length=function(){return 1};var Ya=4294967296n;function Ja(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 Xa(r,t,e){if(e-t<1)return"";let s,o=[],i=0,c;for(;t<e;)c=r[t++],c<128?o[i++]=c:c>191&&c<224?o[i++]=(c&31)<<6|r[t++]&63:c>239&&c<365?(c=((c&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,o[i++]=55296+(c>>10),o[i++]=56320+(c&1023)):o[i++]=(c&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 Fo(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 Rn(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Ho=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 Rn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw qt(this,4);return Rn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw qt(this,4);let t=Wa(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw qt(this,4);let t=Za(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 Xa(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)!==0);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 Pt(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=Rn(this.buf,this.pos+=4),e=Rn(this.buf,this.pos+=4);return new Pt(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=Vo(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 Ko(r){return new Ho(r instanceof Uint8Array?r:r.subarray())}function $t(r,t,e){let n=Ko(r);return t.decode(n,void 0,e)}var qo={};St(qo,{base10:()=>Bh});var Bh=Be({prefix:"9",name:"base10",alphabet:"0123456789"});var $o={};St($o,{base16:()=>Ah,base16upper:()=>Sh});var Ah=ot({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Sh=ot({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var zo={};St(zo,{base2:()=>Ih});var Ih=ot({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Go={};St(Go,{base256emoji:()=>Uh});var tc=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}"),kh=tc.reduce((r,t,e)=>(r[e]=t,r),[]),Ch=tc.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Nh(r){return r.reduce((t,e)=>(t+=kh[e],t),"")}function Th(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let s=Ch[n];if(s==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(s)}return new Uint8Array(t)}var Uh=nr({prefix:"\u{1F680}",name:"base256emoji",encode:Nh,decode:Th});var jo={};St(jo,{base64:()=>Lh,base64pad:()=>Rh,base64url:()=>Wo,base64urlpad:()=>Ph});var Lh=ot({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Rh=ot({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Wo=ot({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ph=ot({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Zo={};St(Zo,{base8:()=>_h});var _h=ot({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Yo={};St(Yo,{identity:()=>Oh});var Oh=nr({prefix:"\0",name:"identity",encode:r=>la(r),decode:r=>ca(r)});var fm=new TextEncoder,hm=new TextDecoder;var Qo={};St(Qo,{sha256:()=>Dr,sha512:()=>Mh});function Xo({name:r,code:t,encode:e}){return new Jo(r,t,e)}var Jo=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 rc(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Dr=Xo({name:"sha2-256",code:18,encode:rc("SHA-256")}),Mh=Xo({name:"sha2-512",code:19,encode:rc("SHA-512")});var Mr={...Yo,...zo,...Zo,...qo,...$o,...ao,...co,...io,...jo,...Go},Am={...Qo,...fo};function sc(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var nc=sc("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ti=sc("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=Ut(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Fh={utf8:nc,"utf-8":nc,hex:Mr.base16,latin1:ti,ascii:ti,binary:ti,...Mr},Pn=Fh;function $(r,t="utf8"){let e=Pn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function ei(r){let t=r??8192,e=t>>>1,n,s=t;return function(i){if(i<1||i>e)return Ut(i);s+i>t&&(n=Ut(t),s=0);let c=n.subarray(s,s+=i);return(s&7)!==0&&(s=(s|7)+1),c}}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 ri(){}var si=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Hh=ei();function Kh(r){return globalThis.Buffer!=null?Ut(r):Hh(r)}var Hr=class{len;head;tail;states;constructor(){this.len=0,this.head=new je(ri,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 oi((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(_n,10,Pt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Pt.fromBigInt(t);return this._push(_n,e.length(),e)}uint64Number(t){return this._push(Oo,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=Pt.fromBigInt(t).zzEncode();return this._push(_n,e.length(),e)}sint64Number(t){let e=Pt.fromNumber(t).zzEncode();return this._push(_n,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ni,1,t?1:0)}fixed32(t){return this._push(Fr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Pt.fromBigInt(t);return this._push(Fr,4,e.lo)._push(Fr,4,e.hi)}fixed64Number(t){let e=Pt.fromNumber(t);return this._push(Fr,4,e.lo)._push(Fr,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(Ga,4,t)}double(t){return this._push(ja,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(ni,1,0):this.uint32(e)._push($h,e,t)}string(t){let e=Ja(t);return e!==0?this.uint32(e)._push(Fo,e,t):this._push(ni,1,0)}fork(){return this.states=new si(this),this.head=this.tail=new je(ri,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(ri,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=Kh(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function ni(r,t,e){t[e]=r&255}function qh(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var oi=class extends je{next;constructor(t,e){super(qh,t,e),this.next=void 0}};function _n(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 Fr(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 $h(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Hr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(zh,t,r),this},Hr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Gh,t,r),this});function zh(r,t,e){t.set(r,e)}function Gh(r,t,e){r.length<40?Fo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set($(r),e)}function ii(){return new Hr}function zt(r,t){let e=ii();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 On(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function ai(r){function t(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let e=function(o,i){let c=t(o);i.int32(c)},n=function(o){let i=o.int32();return t(i)};return On("enum",hr.VARINT,e,n)}function Gt(r,t){return On("message",hr.LENGTH_DELIMITED,r,t)}var Ze=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 ci;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1"})(ci||(ci={}));(function(r){r.codec=()=>ai(ci)})(ct||(ct={}));var Qt;(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 c=e.uint32();switch(c>>>3){case 1:{o.Type=ct.codec().decode(e);break}case 2:{o.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return o})),t),r.encode=e=>zt(e,r.codec()),r.decode=(e,n)=>$t(e,r.codec(),n)})(Qt||(Qt={}));var li;(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 c=e.uint32();switch(c>>>3){case 1:{o.Type=ct.codec().decode(e);break}case 2:{o.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return o})),t),r.encode=e=>zt(e,r.codec()),r.decode=(e,n)=>$t(e,r.codec(),n)})(li||(li={}));var Jr={};St(Jr,{MAX_RSA_KEY_SIZE:()=>ks,generateRSAKeyPair:()=>el,jwkToJWKKeyPair:()=>rl,jwkToPkcs1:()=>cd,jwkToPkix:()=>bi,jwkToRSAPrivateKey:()=>tl,pkcs1ToJwk:()=>Jc,pkcs1ToRSAPrivateKey:()=>Qc,pkixToJwk:()=>Xc,pkixToRSAPublicKey:()=>wi});var Wh=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]),Re=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Pe=new Uint32Array(64),ui=class extends ur{constructor(){super(64,32,8,!1),this.A=Re[0]|0,this.B=Re[1]|0,this.C=Re[2]|0,this.D=Re[3]|0,this.E=Re[4]|0,this.F=Re[5]|0,this.G=Re[6]|0,this.H=Re[7]|0}get(){let{A:t,B:e,C:n,D:s,E:o,F:i,G:c,H:a}=this;return[t,e,n,s,o,i,c,a]}set(t,e,n,s,o,i,c,a){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=c|0,this.H=a|0}process(t,e){for(let f=0;f<16;f++,e+=4)Pe[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let h=Pe[f-15],m=Pe[f-2],p=Ft(h,7)^Ft(h,18)^h>>>3,b=Ft(m,17)^Ft(m,19)^m>>>10;Pe[f]=b+Pe[f-7]+p+Pe[f-16]|0}let{A:n,B:s,C:o,D:i,E:c,F:a,G:l,H:u}=this;for(let f=0;f<64;f++){let h=Ft(c,6)^Ft(c,11)^Ft(c,25),m=u+h+Ia(c,a,l)+Wh[f]+Pe[f]|0,b=(Ft(n,2)^Ft(n,13)^Ft(n,22))+ka(n,s,o)|0;u=l,l=a,a=c,c=i+m|0,i=o,o=s,s=n,n=m+b|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,l=l+this.G|0,u=u+this.H|0,this.set(n,s,o,i,c,a,l,u)}roundClean(){Pe.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var dr=wn(()=>new ui);var M=ia(ic());function Ye(r,t){let e=0;if(r.length===1)return r[0];for(let n=r.length-1;n>=0;n--)e+=r[r.length-1-n]*Math.pow(2,t*n);return e}function _e(r,t,e=-1){let n=e,s=r,o=0,i=Math.pow(2,t);for(let c=1;c<8;c++){if(r<i){let a;if(n<0)a=new ArrayBuffer(c),o=c;else{if(n<c)return new ArrayBuffer(0);a=new ArrayBuffer(n),o=n}let l=new Uint8Array(a);for(let u=c-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 a}i*=Math.pow(2,t)}return new ArrayBuffer(0)}function Mn(...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 hi(){let r=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){let c=r[0]===255&&r[1]&128,a=r[0]===0&&(r[1]&128)===0;(c||a)&&this.warnings.push("Needlessly long format")}let t=new ArrayBuffer(this.valueHex.byteLength),e=new Uint8Array(t);for(let c=0;c<this.valueHex.byteLength;c++)e[c]=0;e[0]=r[0]&128;let n=Ye(e,8),s=new ArrayBuffer(this.valueHex.byteLength),o=new Uint8Array(s);for(let c=0;c<this.valueHex.byteLength;c++)o[c]=r[c];return o[0]&=127,Ye(o,8)-n}function ac(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,c=_e(i,8,n),a=new Uint8Array(c);return a[0]|=128,c}let s=_e(t,8,n),o=new Uint8Array(s);if(o[0]&128){let i=s.slice(0),c=new Uint8Array(i);s=new ArrayBuffer(s.byteLength+1),o=new Uint8Array(s);for(let a=0;a<i.byteLength;a++)o[a+1]=c[a];o[0]=0}return s}e*=Math.pow(2,8)}return new ArrayBuffer(0)}function cc(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 Lt(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 og=Math.log(2);function Fn(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function di(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 be(r,t,e,n){return t instanceof Uint8Array?t.byteLength?e<0?(r.error="Wrong parameter: inputOffset less than zero",!1):n<0?(r.error="Wrong parameter: inputLength less than zero",!1):t.byteLength-e-n<0?(r.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):!0:(r.error="Wrong parameter: inputBuffer has zero length",!1):(r.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}var qr=class{constructor(){this.items=[]}write(t){this.items.push(t)}final(){return di(this.items)}},Kr=[new Uint8Array([1])],lc="0123456789";var br="",Wt=new ArrayBuffer(0),pi=new Uint8Array(0),$r="EndOfContent",fc="OCTET STRING",hc="BIT STRING";function we(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):pi}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(!be(this,i,s,o))return-1;let c=s+o;return this.valueHexView=i.subarray(s,c),this.valueHexView.length?(this.blockLength=o,c):(this.warnings.push("Zero buffer length"),s)}toBER(n=!1){return this.isHexOnly?n?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",Wt)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:M.Convert.ToHex(this.valueHexView)}}},t.NAME="hexBlock",t}var me=class{constructor({blockLength:t=0,error:e=br,warnings:n=[],valueBeforeDecode:s=pi}={}){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 Hn=class extends we(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):pi,this.tagClass=(n=t.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(s=t.tagNumber)!==null&&s!==void 0?s:-1,this.isConstructed=(o=t.isConstructed)!==null&&o!==void 0?o:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(t=!1){let e=0;switch(this.tagClass){case 1:e|=0;break;case 2:e|=64;break;case 3:e|=128;break;case 4:e|=192;break;default:return this.error="Unknown tag class",Wt}if(this.isConstructed&&(e|=32),this.tagNumber<31&&!this.isHexOnly){let s=new Uint8Array(1);if(!t){let o=this.tagNumber;o&=31,e|=o,s[0]=e}return s.buffer}if(!this.isHexOnly){let s=_e(this.tagNumber,7),o=new Uint8Array(s),i=s.byteLength,c=new Uint8Array(i+1);if(c[0]=e|31,!t){for(let a=0;a<i-1;a++)c[a+1]=o[a]|128;c[i]=o[i-1]}return c.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(!be(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 c=o[0]&31;if(c!==31)this.tagNumber=c,this.blockLength=1;else{let a=1,l=this.valueHexView=new Uint8Array(255),u=255;for(;o[a]&128;){if(l[a-1]=o[a]&127,a++,a>=o.length)return this.error="End of input reached before message was fully decoded",-1;if(a===u){u+=255;let h=new Uint8Array(u);for(let m=0;m<l.length;m++)h[m]=l[m];l=this.valueHexView=new Uint8Array(u)}}this.blockLength=a+1,l[a-1]=o[a]&127;let f=new Uint8Array(a);for(let h=0;h<a;h++)f[h]=l[h];l=this.valueHexView=new Uint8Array(a),l.set(f),this.blockLength<=9?this.tagNumber=Ye(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}}};Hn.NAME="identificationBlock";var Kn=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(!be(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 c=e+1,a=s.subarray(c,c+i);return a[i-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=Ye(a,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=i+1,e+this.blockLength}toBER(t=!1){let e,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return e=new ArrayBuffer(1),t===!1&&(n=new Uint8Array(e),n[0]=128),e;if(this.longFormUsed){let s=_e(this.length,8);if(s.byteLength>127)return this.error="Too big length",Wt;if(e=new ArrayBuffer(s.byteLength+1),t)return e;let o=new Uint8Array(s);n=new Uint8Array(e),n[0]=s.byteLength|128;for(let i=0;i<s.byteLength;i++)n[i+1]=o[i];return e}return e=new ArrayBuffer(1),t===!1&&(n=new Uint8Array(e),n[0]=this.length),e}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};Kn.NAME="lengthBlock";var B={},mt=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 Hn(s),this.lenBlock=new Kn(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 qr;e||dc(this);let s=this.idBlock.toBER(t);if(n.write(s),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(t,n),n.write(new ArrayBuffer(2));else{let o=this.valueBlock.toBER(t);this.lenBlock.length=o.byteLength;let i=this.lenBlock.toBER(t);n.write(i),n.write(o)}return e?Wt:n.final()}toJSON(){let t={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(t.primitiveSchema=this.primitiveSchema.toJSON()),t}toString(t="ascii"){return t==="ascii"?this.onAsciiEncoding():M.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${M.Convert.ToHex(this.valueBlock.valueBeforeDecodeView)}`}isEqual(t){if(this===t)return!0;if(!(t instanceof this.constructor))return!1;let e=this.toBER(),n=t.toBER();return cc(e,n)}};mt.NAME="BaseBlock";function dc(r){if(r instanceof B.Constructed)for(let t of r.valueBlock.value)dc(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var qn=class extends mt{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}'`}};qn.NAME="BaseStringBlock";var $n=class extends we(Et){constructor({isHexOnly:t=!0,...e}={}){super(e),this.isHexOnly=t}};$n.NAME="PrimitiveValueBlock";var pc,zn=class extends mt{constructor(t={}){super(t,$n),this.idBlock.isConstructed=!1}};pc=zn;B.Primitive=pc;zn.NAME="PRIMITIVE";function rd(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 Ss(r,t=0,e=r.length){let n=t,s=new mt({},Et),o=new me;if(!be(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 c=s.idBlock.fromBER(r,t,e);if(s.idBlock.warnings.length&&s.warnings.concat(s.idBlock.warnings),c===-1)return s.error=s.idBlock.error,{offset:-1,result:s};if(t=c,e-=s.idBlock.blockLength,c=s.lenBlock.fromBER(r,t,e),s.lenBlock.warnings.length&&s.warnings.concat(s.lenBlock.warnings),c===-1)return s.error=s.lenBlock.error,{offset:-1,result:s};if(t=c,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 a=mt;switch(s.idBlock.tagClass){case 1:if(s.idBlock.tagNumber>=37&&s.idBlock.isHexOnly===!1)return s.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:s};switch(s.idBlock.tagNumber){case 0:if(s.idBlock.isConstructed&&s.lenBlock.length>0)return s.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:s};a=B.EndOfContent;break;case 1:a=B.Boolean;break;case 2:a=B.Integer;break;case 3:a=B.BitString;break;case 4:a=B.OctetString;break;case 5:a=B.Null;break;case 6:a=B.ObjectIdentifier;break;case 10:a=B.Enumerated;break;case 12:a=B.Utf8String;break;case 13:a=B.RelativeObjectIdentifier;break;case 14:a=B.TIME;break;case 15:return s.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:s};case 16:a=B.Sequence;break;case 17:a=B.Set;break;case 18:a=B.NumericString;break;case 19:a=B.PrintableString;break;case 20:a=B.TeletexString;break;case 21:a=B.VideotexString;break;case 22:a=B.IA5String;break;case 23:a=B.UTCTime;break;case 24:a=B.GeneralizedTime;break;case 25:a=B.GraphicString;break;case 26:a=B.VisibleString;break;case 27:a=B.GeneralString;break;case 28:a=B.UniversalString;break;case 29:a=B.CharacterString;break;case 30:a=B.BmpString;break;case 31:a=B.DATE;break;case 32:a=B.TimeOfDay;break;case 33:a=B.DateTime;break;case 34:a=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:a=s.idBlock.isConstructed?B.Constructed:B.Primitive}return s=rd(s,a),c=s.fromBER(r,t,s.lenBlock.isIndefiniteForm?e:s.lenBlock.length),s.valueBeforeDecodeView=r.subarray(n,n+s.blockLength),{offset:c,result:s}}function mi(r){if(!r.byteLength){let t=new mt({},Et);return t.error="Input buffer has zero length",{offset:-1,result:t}}return Ss(M.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function nd(r,t){return r?1:t}var te=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(!be(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(;nd(this.isIndefiniteForm,n)>0;){let i=Ss(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===$r)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===$r?this.value.pop():this.warnings.push("No EndOfContent block encoded")),o}toBER(t,e){let n=e||new qr;for(let s=0;s<this.value.length;s++)this.value[s].toBER(t,n);return e?Wt:n.final()}toJSON(){let t={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let e of this.value)t.value.push(e.toJSON());return t}};te.NAME="ConstructedValueBlock";var mc,Oe=class extends mt{constructor(t={}){super(t,te),this.idBlock.isConstructed=!0}fromBER(t,e,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let s=this.valueBlock.fromBER(t,e,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),s)}onAsciiEncoding(){let t=[];for(let n of this.valueBlock.value)t.push(n.toString("ascii").split(`
|
|
3
|
-
`).map(s=>` ${s}`).join(`
|
|
4
|
-
`));let e=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return t.length?`${e} :
|
|
5
|
-
${t.join(`
|
|
6
|
-
`)}`:`${e} :`}};mc=Oe;B.Constructed=mc;Oe.NAME="CONSTRUCTED";var Gn=class extends Et{fromBER(t,e,n){return e}toBER(t){return Wt}};Gn.override="EndOfContentValueBlock";var gc,Wn=class extends mt{constructor(t={}){super(t,Gn),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};gc=Wn;B.EndOfContent=gc;Wn.NAME=$r;var yc,mr=class extends mt{constructor(t={}){super(t,Et),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(t,e,n){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=n,e+n>t.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):e+n}toBER(t,e){let n=new ArrayBuffer(2);if(!t){let s=new Uint8Array(n);s[0]=5,s[1]=0}return e&&e.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};yc=mr;B.Null=yc;mr.NAME="NULL";var jn=class extends we(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 be(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,hi.call(this),this.blockLength=n,e+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};jn.NAME="BooleanValueBlock";var bc,Zn=class extends mt{constructor(t={}){super(t,jn),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}`}};bc=Zn;B.Boolean=bc;Zn.NAME="BOOLEAN";var Yn=class extends we(te){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=te.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===$r){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(i!==fc)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?te.prototype.toBER.call(this,t,e):t?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};Yn.NAME="OctetStringValueBlock";var wc,Jn=class r extends mt{constructor({idBlock:t={},lenBlock:e={},...n}={}){var s,o;(s=n.isConstructed)!==null&&s!==void 0||(n.isConstructed=!!(!((o=n.value)===null||o===void 0)&&o.length)),super({idBlock:{isConstructed:n.isConstructed,...t},lenBlock:{...e,isIndefiniteForm:!!n.isIndefiniteForm},...n},Yn),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=Ss(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?Oe.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)}};wc=Jn;B.OctetString=wc;Jn.NAME=fc;var Xn=class extends we(te){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=te.prototype.fromBER.call(this,t,e,n),s===-1)return s;for(let c of this.value){let a=c.constructor.NAME;if(a===$r){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(a!==hc)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let l=c.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(!be(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 c=i.subarray(1);try{if(c.byteLength){let a=Ss(c,0,c.byteLength);a.offset!==-1&&a.offset===n-1&&(this.value=[a.result])}}catch{}}return this.valueHexView=i.subarray(1),this.blockLength=i.length,e+n}toBER(t,e){if(this.isConstructed)return te.prototype.toBER.call(this,t,e);if(t)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return Wt;let n=new Uint8Array(this.valueHexView.length+1);return n[0]=this.unusedBits,n.set(this.valueHexView,1),n.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}};Xn.NAME="BitStringValueBlock";var xc,gr=class extends mt{constructor({idBlock:t={},lenBlock:e={},...n}={}){var s,o;(s=n.isConstructed)!==null&&s!==void 0||(n.isConstructed=!!(!((o=n.value)===null||o===void 0)&&o.length)),super({idBlock:{isConstructed:n.isConstructed,...t},lenBlock:{...e,isIndefiniteForm:!!n.isIndefiniteForm},...n},Xn),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 Oe.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)}`}}};xc=gr;B.BitString=xc;gr.NAME=hc;var vc;function sd(r,t){let e=new Uint8Array([0]),n=new Uint8Array(r),s=new Uint8Array(t),o=n.slice(0),i=o.length-1,c=s.slice(0),a=c.length-1,l=0,u=a<i?i:a,f=0;for(let h=u;h>=0;h--,f++){switch(!0){case f<c.length:l=o[i-f]+c[a-f]+e[0];break;default:l=o[i-f]+e[0]}switch(e[0]=l/10,!0){case f>=o.length:o=Mn(new Uint8Array([l%10]),o);break;default:o[i-f]=l%10}}return e[0]>0&&(o=Mn(e,o)),o}function uc(r){if(r>=Kr.length)for(let t=Kr.length;t<=r;t++){let e=new Uint8Array([0]),n=Kr[t-1].slice(0);for(let s=n.length-1;s>=0;s--){let o=new Uint8Array([(n[s]<<1)+e[0]]);e[0]=o[0]/10,n[s]=o[0]%10}e[0]>0&&(n=Mn(e,n)),Kr.push(n)}return Kr[r]}function od(r,t){let e=0,n=new Uint8Array(r),s=new Uint8Array(t),o=n.slice(0),i=o.length-1,c=s.slice(0),a=c.length-1,l,u=0;for(let f=a;f>=0;f--,u++)switch(l=o[i-u]-c[a-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-a+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 zr=class extends we(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=hi.call(this)))}set valueDec(t){this._valueDec=t,this.isHexOnly=!1,this.valueHexView=new Uint8Array(ac(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)!==0?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="",c=!1;for(let a=o.byteLength-1;a>=0;a--){s=o[a];for(let l=0;l<8;l++){if((s&1)===1)switch(n){case t:e=od(uc(n),e),i="-";break;default:e=sd(e,uc(n))}n++,s>>=1}}for(let a=0;a<e.length;a++)e[a]&&(c=!0),c&&(i+=lc.charAt(e[a]));return c===!1&&(i+=lc.charAt(0)),i}};vc=zr;zr.NAME="IntegerValueBlock";Object.defineProperty(vc.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var Ec,gt=class r extends mt{constructor(t={}){super(t,zr),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Fn(),BigInt(this.valueBlock.toString())}static fromBigInt(t){Fn();let e=BigInt(t),n=new qr,s=e.toString(16).replace(/^-/,""),o=new Uint8Array(M.Convert.FromHex(s));if(e<0){let c=new Uint8Array(o.length+(o[0]&128?1:0));c[0]|=128;let l=BigInt(`0x${M.Convert.ToHex(c)}`)+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()}`}};Ec=gt;B.Integer=Ec;gt.NAME="INTEGER";var Bc,Qn=class extends gt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};Bc=Qn;B.Enumerated=Bc;Qn.NAME="ENUMERATED";var Gr=class extends we(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(!be(this,s,e,n))return-1;let o=s.subarray(e,e+n);this.valueHexView=new Uint8Array(n);for(let c=0;c<n&&(this.valueHexView[c]=o[c]&127,this.blockLength++,(o[c]&128)!==0);c++);let i=new Uint8Array(this.blockLength);for(let c=0;c<this.blockLength;c++)i[c]=this.valueHexView[c];return this.valueHexView=i,(o[this.blockLength-1]&128)!==0?(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=Ye(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),e+this.blockLength)}set valueBigInt(t){Fn();let e=BigInt(t).toString(2);for(;e.length%7;)e="0"+e;let n=new Uint8Array(e.length/7);for(let s=0;s<n.length;s++)n[s]=parseInt(e.slice(s*7,s*7+7),2)+(s+1<n.length?128:0);this.fromBER(n.buffer,0,n.length)}toBER(t){if(this.isHexOnly){if(t)return new ArrayBuffer(this.valueHexView.byteLength);let s=this.valueHexView,o=new Uint8Array(this.blockLength);for(let i=0;i<this.blockLength-1;i++)o[i]=s[i]|128;return o[this.blockLength-1]=s[this.blockLength-1],o.buffer}let e=_e(this.valueDec,7);if(e.byteLength===0)return this.error="Error during encoding SID value",Wt;let n=new Uint8Array(e.byteLength);if(!t){let s=new Uint8Array(e),o=e.byteLength-1;for(let i=0;i<o;i++)n[i]=s[i]|128;n[o]=s[o]}return n}toString(){let t="";if(this.isHexOnly)t=M.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let e=this.valueDec;this.valueDec<=39?t="0.":this.valueDec<=79?(t="1.",e-=40):(t="2.",e-=80),t+=e.toString()}else t=this.valueDec.toString();return t}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};Gr.NAME="sidBlock";var ts=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.value.length===0&&(o.isFirstSid=!0),this.blockLength+=o.blockLength,n-=o.blockLength,this.value.push(o)}return s}toBER(t){let e=[];for(let n=0;n<this.value.length;n++){let s=this.value[n].toBER(t);if(s.byteLength===0)return this.error=this.value[n].error,Wt;e.push(s)}return di(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],c=0;switch(i.valueDec){case 0:break;case 1:c=40;break;case 2:c=80;break;default:this.value=[];return}let a=parseInt(s,10);if(isNaN(a))return;i.valueDec=a+c,o=!1}else{let i=new Gr;if(s>Number.MAX_SAFE_INTEGER){Fn();let c=BigInt(s);i.valueBigInt=c}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}};ts.NAME="ObjectIdentifierValueBlock";var Ac,yr=class extends mt{constructor(t={}){super(t,ts),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()}}};Ac=yr;B.ObjectIdentifier=Ac;yr.NAME="OBJECT IDENTIFIER";var Wr=class extends we(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(!be(this,s,e,n))return-1;let o=s.subarray(e,e+n);this.valueHexView=new Uint8Array(n);for(let c=0;c<n&&(this.valueHexView[c]=o[c]&127,this.blockLength++,(o[c]&128)!==0);c++);let i=new Uint8Array(this.blockLength);for(let c=0;c<this.blockLength;c++)i[c]=this.valueHexView[c];return this.valueHexView=i,(o[this.blockLength-1]&128)!==0?(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=Ye(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),e+this.blockLength)}toBER(t){if(this.isHexOnly){if(t)return new ArrayBuffer(this.valueHexView.byteLength);let s=this.valueHexView,o=new Uint8Array(this.blockLength);for(let i=0;i<this.blockLength-1;i++)o[i]=s[i]|128;return o[this.blockLength-1]=s[this.blockLength-1],o.buffer}let e=_e(this.valueDec,7);if(e.byteLength===0)return this.error="Error during encoding SID value",Wt;let n=new Uint8Array(e.byteLength);if(!t){let s=new Uint8Array(e),o=e.byteLength-1;for(let i=0;i<o;i++)n[i]=s[i]|128;n[o]=s[o]}return n.buffer}toString(){let t="";return this.isHexOnly?t=M.Convert.ToHex(this.valueHexView):t=this.valueDec.toString(),t}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};Wr.NAME="relativeSidBlock";var es=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 Wr;if(s=o.fromBER(t,s,n),s===-1)return this.blockLength=0,this.error=o.error,s;this.blockLength+=o.blockLength,n-=o.blockLength,this.value.push(o)}return s}toBER(t,e){let n=[];for(let s=0;s<this.value.length;s++){let o=this.value[s].toBER(t);if(o.byteLength===0)return this.error=this.value[s].error,Wt;n.push(o)}return di(n)}fromString(t){this.value=[];let e=0,n=0,s="";do{n=t.indexOf(".",e),n===-1?s=t.substring(e):s=t.substring(e,n),e=n+1;let o=new Wr;if(o.valueDec=parseInt(s,10),isNaN(o.valueDec))return!0;this.value.push(o)}while(n!==-1);return!0}toString(){let t="",e=!1;for(let n=0;n<this.value.length;n++){e=this.value[n].isHexOnly;let s=this.value[n].toString();n!==0&&(t=`${t}.`),e&&(s=`{${s}}`),t+=s}return t}toJSON(){let t={...super.toJSON(),value:this.toString(),sidArray:[]};for(let e=0;e<this.value.length;e++)t.sidArray.push(this.value[e].toJSON());return t}};es.NAME="RelativeObjectIdentifierValueBlock";var Sc,rs=class extends mt{constructor(t={}){super(t,es),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()}}};Sc=rs;B.RelativeObjectIdentifier=Sc;rs.NAME="RelativeObjectIdentifier";var Ic,ge=class extends Oe{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};Ic=ge;B.Sequence=Ic;ge.NAME="SEQUENCE";var kc,ns=class extends Oe{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};kc=ns;B.Set=kc;ns.NAME="SET";var ss=class extends we(Et){constructor({...t}={}){super(t),this.isHexOnly=!0,this.value=br}toJSON(){return{...super.toJSON(),value:this.value}}};ss.NAME="StringValueBlock";var os=class extends ss{};os.NAME="SimpleStringValueBlock";var kt=class extends qn{constructor({...t}={}){super(t,os)}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 is=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}};is.NAME="Utf8StringValueBlock";var Cc,ye=class extends is{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};Cc=ye;B.Utf8String=Cc;ye.NAME="UTF8String";var as=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))}};as.NAME="BmpStringValueBlock";var Nc,cs=class extends as{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};Nc=cs;B.BmpString=Nc;cs.NAME="BMPString";var ls=class extends kt{fromBuffer(t){let e=ArrayBuffer.isView(t)?t.slice().buffer:t.slice(0),n=new Uint8Array(e);for(let s=0;s<n.length;s+=4)n[s]=n[s+3],n[s+1]=n[s+2],n[s+2]=0,n[s+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(e))}fromString(t){let e=t.length,n=this.valueBlock.valueHexView=new Uint8Array(e*4);for(let s=0;s<e;s++){let o=_e(t.charCodeAt(s),8),i=new Uint8Array(o);if(i.length>4)continue;let c=4-i.length;for(let a=i.length-1;a>=0;a--)n[s*4+a+c]=i[a]}this.valueBlock.value=t}};ls.NAME="UniversalStringValueBlock";var Tc,us=class extends ls{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};Tc=us;B.UniversalString=Tc;us.NAME="UniversalString";var Uc,fs=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};Uc=fs;B.NumericString=Uc;fs.NAME="NumericString";var Lc,hs=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};Lc=hs;B.PrintableString=Lc;hs.NAME="PrintableString";var Rc,ds=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};Rc=ds;B.TeletexString=Rc;ds.NAME="TeletexString";var Pc,ps=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};Pc=ps;B.VideotexString=Pc;ps.NAME="VideotexString";var _c,ms=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};_c=ms;B.IA5String=_c;ms.NAME="IA5String";var Oc,gs=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};Oc=gs;B.GraphicString=Oc;gs.NAME="GraphicString";var Vc,jr=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};Vc=jr;B.VisibleString=Vc;jr.NAME="VisibleString";var Dc,ys=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};Dc=ys;B.GeneralString=Dc;ys.NAME="GeneralString";var Mc,bs=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};Mc=bs;B.CharacterString=Mc;bs.NAME="CharacterString";var Fc,Zr=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]=Lt(this.year<2e3?this.year-1900:this.year-2e3,2),e[1]=Lt(this.month,2),e[2]=Lt(this.day,2),e[3]=Lt(this.hour,2),e[4]=Lt(this.minute,2),e[5]=Lt(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}}};Fc=Zr;B.UTCTime=Fc;Zr.NAME="UTCTime";var Hc,ws=class extends Zr{constructor(t={}){var e;super(t),(e=this.millisecond)!==null&&e!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(t){super.fromDate(t),this.millisecond=t.getUTCMilliseconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond))}fromString(t){let e=!1,n="",s="",o=0,i,c=0,a=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("+"),m="";if(h===-1&&(h=n.indexOf("-"),f=-1),h!==-1){if(m=n.substring(h+1),n=n.substring(0,h),m.length!==2&&m.length!==4)throw new Error("Wrong input string for conversion");let p=parseInt(m.substring(0,2),10);if(isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");if(c=f*p,m.length===4){if(p=parseInt(m.substring(2,4),10),isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");a=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)+c;break;case 5:this.minute=parseInt(u[f],10)+a;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(Lt(this.year,4)),e.push(Lt(this.month,2)),e.push(Lt(this.day,2)),e.push(Lt(this.hour,2)),e.push(Lt(this.minute,2)),e.push(Lt(this.second,2)),this.millisecond!==0&&(e.push("."),e.push(Lt(this.millisecond,3))),e.push("Z"),e.join("")}return super.toString(t)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};Hc=ws;B.GeneralizedTime=Hc;ws.NAME="GeneralizedTime";var Kc,xs=class extends ye{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};Kc=xs;B.DATE=Kc;xs.NAME="DATE";var qc,vs=class extends ye{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};qc=vs;B.TimeOfDay=qc;vs.NAME="TimeOfDay";var $c,Es=class extends ye{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};$c=Es;B.DateTime=$c;Es.NAME="DateTime";var zc,Bs=class extends ye{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};zc=Bs;B.Duration=zc;Bs.NAME="Duration";var Gc,As=class extends ye{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};Gc=As;B.TIME=Gc;As.NAME="TIME";function Q(r,t="utf8"){let e=Pn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Yr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Is=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Wc={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Is("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 Ve=Wc;async function jc(r){let t=await Ve.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 ad(t);return{privateKey:e[0],publicKey:e[1]}}async function Zc(r,t){let e=await Ve.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await Ve.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function Yc(r,t,e){let n=await Ve.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return Ve.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function ad(r){if(r.privateKey==null||r.publicKey==null)throw new It("Private and public key are required");return Promise.all([Ve.get().subtle.exportKey("jwk",r.privateKey),Ve.get().subtle.exportKey("jwk",r.publicKey)])}function gi(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 wr=class{type="RSA";_key;_raw;_multihash;constructor(t,e){this._key=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=Jr.jwkToPkix(this._key)),this._raw}toMultihash(){return this._multihash}toCID(){return dt.createV1(114,this._multihash)}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,e){return Yc(this._key,e,t)}},Xr=class{type="RSA";_key;_raw;publicKey;constructor(t,e){this._key=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=Jr.jwkToPkcs1(this._key)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}sign(t){return Zc(this._key,t)}};var ks=8192,yi=18;function Jc(r){let{result:t}=mi(r),e=t.valueBlock.value;return{n:ee(e[1]),e:ee(e[2]),d:ee(e[3]),p:ee(e[4]),q:ee(e[5]),dp:ee(e[6]),dq:ee(e[7]),qi:ee(e[8]),kty:"RSA",alg:"RS256"}}function cd(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 ge({value:[new gt({value:0}),gt.fromBigInt(re($(r.n,"base64url"))),gt.fromBigInt(re($(r.e,"base64url"))),gt.fromBigInt(re($(r.d,"base64url"))),gt.fromBigInt(re($(r.p,"base64url"))),gt.fromBigInt(re($(r.q,"base64url"))),gt.fromBigInt(re($(r.dp,"base64url"))),gt.fromBigInt(re($(r.dq,"base64url"))),gt.fromBigInt(re($(r.qi,"base64url")))]}).toBER();return new Uint8Array(e,0,e.byteLength)}function Xc(r){let{result:t}=mi(r),e=t.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:ee(e[0]),e:ee(e[1])}}function bi(r){if(r.n==null||r.e==null)throw new It("JWK was missing components");let e=new ge({value:[new ge({value:[new yr({value:"1.2.840.113549.1.1.1"}),new mr]}),new gr({valueHex:new ge({value:[gt.fromBigInt(re($(r.n,"base64url"))),gt.fromBigInt(re($(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(e,0,e.byteLength)}function ee(r){let t=r.valueBlock.valueHexView;for(;t[0]===0;)t=t.subarray(1);return Q(t,"base64url")}function re(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 Qc(r){let t=Jc(r);return tl(t)}function wi(r){let t=Xc(r);if(gi(t)>ks)throw new rr("Key size is too large");let e=dr(Qt.encode({Type:ct.RSA,Data:r})),n=Mt(yi,e);return new wr(t,n)}function tl(r){if(gi(r)>ks)throw new It("Key size is too large");let t=rl(r),e=dr(Qt.encode({Type:ct.RSA,Data:bi(t.publicKey)})),n=Mt(yi,e);return new Xr(t.privateKey,new wr(t.publicKey,n))}async function el(r){if(r>ks)throw new It("Key size is too large");let t=await jc(r),e=dr(Qt.encode({Type:ct.RSA,Data:bi(t.publicKey)})),n=Mt(yi,e);return new Xr(t.privateKey,new wr(t.publicKey,n))}function rl(r){if(r==null)throw new It("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}var Cs=class extends lr{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Ba(t);let n=Pr(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:c}=this;return t=t,t.finished=s,t.destroyed=o,t.blockLen=i,t.outputLen=c,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},xi=(r,t,e)=>new Cs(r,t).update(e).digest();xi.create=(r,t)=>new Cs(r,t);function nl(r){r.lowS!==void 0&&Ht("lowS",r.lowS),r.prehash!==void 0&&Ht("prehash",r.prehash)}function ld(r){let t=Vr(r);Xt(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:ud,hexToBytes:fd}=An,vi=class extends Error{constructor(t=""){super(t)}},xe={Err:vi,_tlv:{encode:(r,t)=>{let{Err:e}=xe;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=Ke(n);if(s.length/2&128)throw new e("tlv.encode: long form length too big");let o=n>127?Ke(s.length/2|128):"";return Ke(r)+o+s+t},decode(r,t){let{Err:e}=xe,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 a=s&127;if(!a)throw new e("tlv.decode(long): indefinite length not supported");if(a>4)throw new e("tlv.decode(long): byte length is too big");let l=t.subarray(n,n+a);if(l.length!==a)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+=a,i<128)throw new e("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new e("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=xe;if(r<ve)throw new t("integer: negative integers are not allowed");let e=Ke(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}=xe;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 ud(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=xe,s=typeof r=="string"?fd(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:c,l:a}=n.decode(2,o),{v:l,l:u}=n.decode(2,a);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(c),s:e.decode(l)}},hexFromSig(r){let{_tlv:t,_int:e}=xe,n=t.encode(2,e.encode(r.r)),s=t.encode(2,e.encode(r.s)),o=n+s;return t.encode(48,o)}},ve=BigInt(0),ft=BigInt(1),Vg=BigInt(2),sl=BigInt(3),Dg=BigInt(4);function hd(r){let t=ld(r),{Fp:e}=t,n=Te(t.n,t.nBitLength),s=t.toBytes||((b,d,v)=>{let A=d.toAffine();return he(Uint8Array.from([4]),e.toBytes(A.x),e.toBytes(A.y))}),o=t.fromBytes||(b=>{let d=b.subarray(1),v=e.fromBytes(d.subarray(0,e.BYTES)),A=e.fromBytes(d.subarray(e.BYTES,2*e.BYTES));return{x:v,y:A}});function i(b){let{a:d,b:v}=t,A=e.sqr(b),y=e.mul(A,b);return e.add(e.add(y,e.mul(b,d)),v)}if(!e.eql(e.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function c(b){return _r(b,ft,t.n)}function a(b){let{allowedPrivateKeyLengths:d,nByteLength:v,wrapPrivateKey:A,n:y}=t;if(d&&typeof b!="bigint"){if(ke(b)&&(b=ue(b)),typeof b!="string"||!d.includes(b.length))throw new Error("invalid private key");b=b.padStart(v*2,"0")}let I;try{I=typeof b=="bigint"?b:fe(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=ze((b,d)=>{let{px:v,py:A,pz:y}=b;if(e.eql(y,e.ONE))return{x:v,y:A};let I=b.is0();d==null&&(d=I?e.ONE:e.inv(y));let L=e.mul(v,d),U=e.mul(A,d),k=e.mul(y,d);if(I)return{x:e.ZERO,y:e.ZERO};if(!e.eql(k,e.ONE))throw new Error("invZ was invalid");return{x:L,y:U}}),f=ze(b=>{if(b.is0()){if(t.allowInfinityPoint&&!e.is0(b.py))return;throw new Error("bad point: ZERO")}let{x:d,y:v}=b.toAffine();if(!e.isValid(d)||!e.isValid(v))throw new Error("bad point: x or y not FE");let A=e.sqr(v),y=i(d);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(d,v,A){if(this.px=d,this.py=v,this.pz=A,d==null||!e.isValid(d))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(d){let{x:v,y:A}=d||{};if(!d||!e.isValid(v)||!e.isValid(A))throw new Error("invalid affine point");if(d 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(d){let v=e.invertBatch(d.map(A=>A.pz));return d.map((A,y)=>A.toAffine(v[y])).map(h.fromAffine)}static fromHex(d){let v=h.fromAffine(o(nt("pointHex",d)));return v.assertValidity(),v}static fromPrivateKey(d){return h.BASE.multiply(a(d))}static msm(d,v){return Cn(h,n,d,v)}_setWindowSize(d){p.setWindowSize(this,d)}assertValidity(){f(this)}hasEvenY(){let{y:d}=this.toAffine();if(e.isOdd)return!e.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){l(d);let{px:v,py:A,pz:y}=this,{px:I,py:L,pz:U}=d,k=e.eql(e.mul(v,U),e.mul(I,y)),T=e.eql(e.mul(A,U),e.mul(L,y));return k&&T}negate(){return new h(this.px,e.neg(this.py),this.pz)}double(){let{a:d,b:v}=t,A=e.mul(v,sl),{px:y,py:I,pz:L}=this,U=e.ZERO,k=e.ZERO,T=e.ZERO,C=e.mul(y,y),tt=e.mul(I,I),q=e.mul(L,L),D=e.mul(y,I);return D=e.add(D,D),T=e.mul(y,L),T=e.add(T,T),U=e.mul(d,T),k=e.mul(A,q),k=e.add(U,k),U=e.sub(tt,k),k=e.add(tt,k),k=e.mul(U,k),U=e.mul(D,U),T=e.mul(A,T),q=e.mul(d,q),D=e.sub(C,q),D=e.mul(d,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,L),q=e.add(q,q),C=e.mul(q,D),U=e.sub(U,C),T=e.mul(q,tt),T=e.add(T,T),T=e.add(T,T),new h(U,k,T)}add(d){l(d);let{px:v,py:A,pz:y}=this,{px:I,py:L,pz:U}=d,k=e.ZERO,T=e.ZERO,C=e.ZERO,tt=t.a,q=e.mul(t.b,sl),D=e.mul(v,I),it=e.mul(A,L),E=e.mul(y,U),N=e.add(v,A),w=e.add(I,L);N=e.mul(N,w),w=e.add(D,it),N=e.sub(N,w),w=e.add(v,y);let g=e.add(I,U);return w=e.mul(w,g),g=e.add(D,E),w=e.sub(w,g),g=e.add(A,y),k=e.add(L,U),g=e.mul(g,k),k=e.add(it,E),g=e.sub(g,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(g,w),k=e.mul(N,k),k=e.sub(k,D),D=e.mul(N,it),C=e.mul(g,C),C=e.add(C,D),new h(k,T,C)}subtract(d){return this.add(d.negate())}is0(){return this.equals(h.ZERO)}wNAF(d){return p.wNAFCached(this,d,h.normalizeZ)}multiplyUnsafe(d){let{endo:v,n:A}=t;Nt("scalar",d,ve,A);let y=h.ZERO;if(d===ve)return y;if(this.is0()||d===ft)return this;if(!v||p.hasPrecomputes(this))return p.wNAFCachedUnsafe(this,d,h.normalizeZ);let{k1neg:I,k1:L,k2neg:U,k2:k}=v.splitScalar(d),T=y,C=y,tt=this;for(;L>ve||k>ve;)L&ft&&(T=T.add(tt)),k&ft&&(C=C.add(tt)),tt=tt.double(),L>>=ft,k>>=ft;return I&&(T=T.negate()),U&&(C=C.negate()),C=new h(e.mul(C.px,v.beta),C.py,C.pz),T.add(C)}multiply(d){let{endo:v,n:A}=t;Nt("scalar",d,ft,A);let y,I;if(v){let{k1neg:L,k1:U,k2neg:k,k2:T}=v.splitScalar(d),{p:C,f:tt}=this.wNAF(U),{p:q,f:D}=this.wNAF(T);C=p.constTimeNegate(L,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:L,f:U}=this.wNAF(d);y=L,I=U}return h.normalizeZ([y,I])[0]}multiplyAndAddUnsafe(d,v,A){let y=h.BASE,I=(U,k)=>k===ve||k===ft||!U.equals(y)?U.multiplyUnsafe(k):U.multiply(k),L=I(this,v).add(I(d,A));return L.is0()?void 0:L}toAffine(d){return u(this,d)}isTorsionFree(){let{h:d,isTorsionFree:v}=t;if(d===ft)return!0;if(v)return v(h,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:d,clearCofactor:v}=t;return d===ft?this:v?v(h,this):this.multiplyUnsafe(t.h)}toRawBytes(d=!0){return Ht("isCompressed",d),this.assertValidity(),s(h,this,d)}toHex(d=!0){return Ht("isCompressed",d),ue(this.toRawBytes(d))}}h.BASE=new h(t.Gx,t.Gy,e.ONE),h.ZERO=new h(e.ZERO,e.ONE,e.ZERO);let m=t.nBitLength,p=kn(h,t.endo?Math.ceil(m/2):m);return{CURVE:t,ProjectivePoint:h,normPrivateKeyToScalar:a,weierstrassEquation:i,isWithinCurveOrder:c}}function dd(r){let t=Vr(r);return Xt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function ol(r){let t=dd(r),{Fp:e,n}=t,s=e.BYTES+1,o=2*e.BYTES+1;function i(E){return Z(E,n)}function c(E){return Sn(E,n)}let{ProjectivePoint:a,normPrivateKeyToScalar:l,weierstrassEquation:u,isWithinCurveOrder:f}=hd({...t,toBytes(E,N,w){let g=N.toAffine(),x=e.toBytes(g.x),S=he;return Ht("isCompressed",w),w?S(Uint8Array.from([N.hasEvenY()?2:3]),x):S(Uint8Array.from([4]),x,e.toBytes(g.y))},fromBytes(E){let N=E.length,w=E[0],g=E.subarray(1);if(N===s&&(w===2||w===3)){let x=fe(g);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 _=F instanceof Error?": "+F.message:"";throw new Error("Point is not on curve"+_)}let P=(R&ft)===ft;return(w&1)===1!==P&&(R=e.neg(R)),{x,y:R}}else if(N===o&&w===4){let x=e.fromBytes(g.subarray(0,e.BYTES)),S=e.fromBytes(g.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=>ue(Ne(E,t.nByteLength));function m(E){let N=n>>ft;return E>N}function p(E){return m(E)?i(-E):E}let b=(E,N,w)=>fe(E.slice(N,w));class d{constructor(N,w,g){this.r=N,this.s=w,this.recovery=g,this.assertValidity()}static fromCompact(N){let w=t.nByteLength;return N=nt("compactSignature",N,w*2),new d(b(N,0,w),b(N,w,2*w))}static fromDER(N){let{r:w,s:g}=xe.toSig(nt("DER",N));return new d(w,g)}assertValidity(){Nt("r",this.r,ft,n),Nt("s",this.s,ft,n)}addRecoveryBit(N){return new d(this.r,this.s,N)}recoverPublicKey(N){let{r:w,s:g,recovery:x}=this,S=U(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 P=(x&1)===0?"02":"03",V=a.fromHex(P+h(R)),F=c(R),_=i(-S*F),j=i(g*F),J=a.BASE.multiplyAndAddUnsafe(V,_,j);if(!J)throw new Error("point at infinify");return J.assertValidity(),J}hasHighS(){return m(this.s)}normalizeS(){return this.hasHighS()?new d(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return qe(this.toDERHex())}toDERHex(){return xe.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return qe(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=Ao(t.n);return Oa(t.randomBytes(E),t.n)},precompute(E=8,N=a.BASE){return N._setWindowSize(E),N.multiply(BigInt(3)),N}};function A(E,N=!0){return a.fromPrivateKey(E).toRawBytes(N)}function y(E){let N=ke(E),w=typeof E=="string",g=(N||w)&&E.length;return N?g===s||g===o:w?g===2*s||g===2*o:E instanceof a}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 a.fromHex(N).multiply(l(E)).toRawBytes(w)}let L=t.bits2int||function(E){if(E.length>8192)throw new Error("input is too large");let N=fe(E),w=E.length*8-t.nBitLength;return w>0?N>>BigInt(w):N},U=t.bits2int_modN||function(E){return i(L(E))},k=Or(t.nBitLength);function T(E){return Nt("num < 2^"+t.nBitLength,E,ve,k),Ne(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:g,randomBytes:x}=t,{lowS:S,prehash:R,extraEntropy:P}=w;S==null&&(S=!0),E=nt("msgHash",E),nl(w),R&&(E=nt("prehashed msgHash",g(E)));let V=U(E),F=l(N),_=[T(F),T(V)];if(P!=null&&P!==!1){let ut=P===!0?x(e.BYTES):P;_.push(nt("extraEntropy",ut))}let j=he(..._),J=V;function lt(ut){let ht=L(ut);if(!f(ht))return;let yt=c(ht),Ct=a.BASE.multiply(ht).toAffine(),At=i(Ct.x);if(At===ve)return;let Jt=i(yt*i(J+At*F));if(Jt===ve)return;let oe=(Ct.x===At?0:2)|Number(Ct.y&ft),Nr=Jt;return S&&m(Jt)&&(Nr=p(Jt),oe^=1),new d(At,Nr,oe)}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:g,k2sig:x}=C(E,N,w),S=t;return xo(S.hash.outputLen,S.nByteLength,S.hmac)(g,x)}a.BASE._setWindowSize(8);function it(E,N,w,g=q){let x=E;N=nt("msgHash",N),w=nt("publicKey",w);let{lowS:S,prehash:R,format:P}=g;if(nl(g),"strict"in g)throw new Error("options.strict was renamed to lowS");if(P!==void 0&&P!=="compact"&&P!=="der")throw new Error("format must be compact or der");let V=typeof x=="string"||ke(x),F=!V&&!P&&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 _,j;try{if(F&&(_=new d(x.r,x.s)),V){try{P!=="compact"&&(_=d.fromDER(x))}catch(oe){if(!(oe instanceof xe.Err))throw oe}!_&&P!=="der"&&(_=d.fromCompact(x))}j=a.fromHex(w)}catch{return!1}if(!_||S&&_.hasHighS())return!1;R&&(N=t.hash(N));let{r:J,s:lt}=_,ut=U(N),ht=c(lt),yt=i(ut*ht),Ct=i(J*ht),At=a.BASE.multiplyAndAddUnsafe(j,yt,Ct)?.toAffine();return At?i(At.x)===J:!1}return{CURVE:t,getPublicKey:A,getSharedSecret:I,sign:D,verify:it,ProjectivePoint:a,Signature:d,utils:v}}function pd(r){return{hash:r,hmac:(t,...e)=>xi(r,t,ho(...e)),randomBytes:xn}}function il(r,t){let e=n=>ol({...r,...pd(n)});return{...e(t),create:e}}var ll=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),al=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),md=BigInt(1),Ei=BigInt(2),cl=(r,t)=>(r+t/Ei)/t;function gd(r){let t=ll,e=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),c=BigInt(44),a=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,m=rt(h,Ei,t)*l%t,p=rt(m,s,t)*m%t,b=rt(p,o,t)*p%t,d=rt(b,c,t)*b%t,v=rt(d,a,t)*d%t,A=rt(v,c,t)*b%t,y=rt(A,e,t)*u%t,I=rt(y,i,t)*p%t,L=rt(I,n,t)*l%t,U=rt(L,Ei,t);if(!Bi.eql(Bi.sqr(U),r))throw new Error("Cannot find square root");return U}var Bi=Te(ll,void 0,void 0,{sqrt:gd}),Je=il({a:BigInt(0),b:BigInt(7),Fp:Bi,n:al,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=al,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-md*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=e,i=BigInt("0x100000000000000000000000000000000"),c=cl(o*r,t),a=cl(-n*r,t),l=Z(r-c*e-a*s,t),u=Z(-c*n-a*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}}}},dr),Wg=BigInt(0);var jg=Je.ProjectivePoint;function _t(r,t){t==null&&(t=r.reduce((s,o)=>s+o.length,0));let e=Ut(t),n=0;for(let s of r)e.set(s,n),n+=s.length;return e}function ul(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function fl(r,t,e){let n=Dr.digest(e instanceof Uint8Array?e:e.subarray());if(ul(n))return n.then(({digest:s})=>Je.verify(t,s,r)).catch(s=>{throw new Yr(String(s))});try{return Je.verify(t,n.digest,r)}catch(s){throw new Yr(String(s))}}var Ns=class{type="secp256k1";raw;_key;constructor(t){this._key=dl(t),this.raw=hl(this._key)}toMultihash(){return ce.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:bt(this.raw,t.raw)}verify(t,e){return fl(this._key,e,t)}};function Ai(r){return new Ns(r)}function hl(r){return Je.ProjectivePoint.fromHex(r).toRawBytes(!0)}function dl(r){try{return Je.ProjectivePoint.fromHex(r),r}catch(t){throw new rr(String(t))}}function xr(r){let{Type:t,Data:e}=Qt.decode(r),n=e??new Uint8Array;switch(t){case ct.RSA:return wi(n);case ct.Ed25519:return Uo(n);case ct.secp256k1:return Ai(n);default:throw new Me}}function pl(r){let{Type:t,Data:e}=Qt.decode(r.digest),n=e??new Uint8Array;switch(t){case ct.Ed25519:return Uo(n);case ct.secp256k1:return Ai(n);default:throw new Me}}function Ue(r){return Qt.encode({Type:ct[r.type],Data:r.raw})}var gl=Symbol.for("@achingbrain/uint8arraylist");function ml(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 Ts(r){return!!r?.[gl]}var jt=class r{bufs;length;[gl]=!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(Ts(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(Ts(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=ml(this.bufs,t);return e.buf[e.index]}set(t,e){let n=ml(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(Ts(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 _t(n,s)}subarray(t,e){let{bufs:n,length:s}=this._subList(t,e);return n.length===1?n[0]:_t(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],c=s,a=c+i.byteLength;if(s=a,t>=a)continue;let l=t>=c&&t<a,u=e>c&&e<=a;if(l&&u){if(t===c&&e===a){n.push(i);break}let f=t-c;n.push(i.subarray(f,f+(e-t)));break}if(l){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(u){if(e===a){n.push(i);break}n.push(i.subarray(0,e-c));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Ts(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 c=i,a=this.byteLength-n.byteLength,l=n.byteLength-1,u;for(let f=e;f<=a;f+=u){u=0;for(let h=l;h>=0;h--){let m=this.get(f+h);if(n[h]!==m){u=Math.max(1,h-c[m]);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=Ut(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=Ut(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(!bt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((s,o)=>s+o.byteLength,0)),n.length=e,n}};var Qr;(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 c=e.uint32();switch(c>>>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(c&7);break}}}return o})),t),r.encode=e=>zt(e,r.codec()),r.decode=(e,n)=>$t(e,r.codec(),n)})(Qr||(Qr={}));var Us=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var ne=class r{static createFromProtobuf=async t=>{let e=Qr.decode(t),n=xr(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=yl(n,s,o),c=await e.sign(i.subarray());return new r({publicKey:e.publicKey,payloadType:s,payload:o,signature:c})};static openAndCertify=async(t,e)=>{let n=await r.createFromProtobuf(t);if(!await n.validate(e))throw new Us("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=Qr.encode({publicKey:Ue(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return bt(this.marshal(),t.marshal())}async validate(t){let e=yl(t,this.payloadType,this.payload);return this.publicKey.verify(e.subarray(),this.signature)}},yl=(r,t,e)=>{let n=$(r),s=Ot(n.byteLength),o=Ot(t.length),i=Ot(e.length);return new jt(s,n,o,t,i,e)};var bl=Symbol.for("nodejs.util.inspect.custom"),yd=114,tn=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()})`}[eo]=!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(yd,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return bt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return bt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[bl](){return`PeerId(${this.toString()})`}},en=class extends tn{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},rn=class extends tn{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},nn=class extends tn{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},bd=2336,sn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=ce.digest($(this.url))}[bl](){return`PeerId(${this.url})`}[eo]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return dt.createV1(bd,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=Q(t)),t.toString()===this.toString())}};var wd=114,wl=2336;function xl(r){if(r.type==="Ed25519")return new rn({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new nn({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new en({multihash:r.toCID().multihash,publicKey:r});throw new Me}function Si(r){if(vd(r))return new en({multihash:r});if(xd(r))try{let t=pl(r);if(t.type==="Ed25519")return new rn({multihash:r,publicKey:t});if(t.type==="secp256k1")return new nn({multihash:r,publicKey:t})}catch{let e=Q(r.digest);return new sn(new URL(e))}throw new pn("Supplied PeerID Multihash is invalid")}function Ls(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==wd&&r.code!==wl)throw new dn("Supplied PeerID CID is invalid");if(r.code===wl){let t=Q(r.multihash.digest);return new sn(new URL(t))}return Si(r.multihash)}function xd(r){return r.code===ce.code}function vd(r){return r.code===Dr.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 Rs=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,c=this.peekChar();if(c===void 0)return;let a=c==="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&&a&&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),[c]=t(o.subarray(0,i));return e.set(o.subarray(0,c),16-c),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var El=45,Ed=15,vr=new Rs;function Ps(r){if(!(r.length>Ed))return vr.new(r).parseWith(()=>vr.readIPv4Addr())}function _s(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>El))return vr.new(r).parseWith(()=>vr.readIPv6Addr())}function Xe(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>El)return;let e=vr.new(r).parseWith(()=>vr.readIPAddr());if(e)return t&&e.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,e[0],e[1],e[2],e[3]]):e}function Bl(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 Al(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 Ii(r){switch(r.length){case Qe:return r.join(".");case tr:{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 Sl(r){let t=0;for(let[e,n]of r.entries()){if(n===255){t+=8;continue}for(;(n&128)!=0;)t++,n=n<<1;if((n&128)!=0)return-1;for(let s=e+1;s<r.length;s++)if(r[s]!=0)return-1;break}return t}function Il(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var Qe=4,tr=16,Bb=parseInt("0xFFFF",16),Bd=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function on(r,t){t.length===tr&&r.length===Qe&&Bl(t,0,11)&&(t=t.slice(12)),t.length===Qe&&r.length===tr&&Al(r,Bd,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 kl(r,t){if(typeof t=="string"&&(t=Xe(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 ki(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=Qe,s=Ps(t);if(s==null&&(n=tr,s=_s(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=Ci(o,8*n);return{network:on(s,i),mask:i}}function Ci(r,t){if(t!==8*Qe&&t!==8*tr)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 Er=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=ki(t));else{let n=Xe(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=Xe(e);if(o==null)throw new Error("Failed to parse mask");this.mask=o}else this.mask=Ci(s,8*n.length);this.network=on(n,this.mask)}}contains(t){return kl({network:this.network,mask:this.mask},t)}toString(){let t=Sl(this.mask),e=t!==-1?String(t):Il(this.mask);return Ii(this.network)+"/"+e}};function Cl(r,t){return new Er(r).contains(t)}function Br(r){return!!Ps(r)}function Ar(r){return!!_s(r)}function Os(r){return!!Xe(r)}var Nl=Br,Ad=Ar,Ni=function(r){let t=0;if(r=r.toString().trim(),Nl(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(Ad(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let o=Nl(e[n]),i;o&&(i=Ni(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")},Tl=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 Sr={},Ti={},Id=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];Id.forEach(r=>{let t=kd(...r);Ti[t.code]=t,Sr[t.name]=t});function kd(r,t,e,n,s){return{code:r,size:t,name:e,resolvable:!!n,path:!!s}}function z(r){if(typeof r=="number"){if(Ti[r]!=null)return Ti[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Sr[r]!=null)return Sr[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var rw=z("ip4"),nw=z("ip6"),sw=z("ipcidr");function Pi(r,t){switch(z(r).code){case 4:case 41:return Nd(t);case 42:return Ri(t);case 43:return Q(t,"base10");case 6:case 273:case 33:case 132:return Rl(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Ri(t);case 421:return Rd(t);case 444:return Ll(t);case 445:return Ll(t);case 466:return Ld(t);case 481:return globalThis.encodeURIComponent(Ri(t));default:return Q(t,"base16")}}function _i(r,t){switch(z(r).code){case 4:return Ul(t);case 41:return Ul(t);case 42:return Li(t);case 43:return $(t,"base10");case 6:case 273:case 33:case 132:return Oi(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Li(t);case 421:return Td(t);case 444:return Pd(t);case 445:return _d(t);case 466:return Ud(t);case 481:return Li(globalThis.decodeURIComponent(t));default:return $(t,"base16")}}var Ui=Object.values(Mr).map(r=>r.decoder),Cd=function(){let r=Ui[0].or(Ui[1]);return Ui.slice(2).forEach(t=>r=r.or(t)),r}();function Ul(r){if(!Os(r))throw new Error("invalid ip address");return Ni(r)}function Nd(r){let t=Tl(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!Os(t))throw new Error("invalid ip address");return t}function Oi(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Rl(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Li(r){let t=$(r),e=Uint8Array.from(Ot(t.length));return _t([e,t],e.length+t.length)}function Ri(r){let t=de(r);if(r=r.slice(xt(t)),r.length!==t)throw new Error("inconsistent lengths");return Q(r)}function Td(r){let t;r[0]==="Q"||r[0]==="1"?t=Fe(X.decode(`z${r}`)).bytes:t=dt.parse(r).multihash.bytes;let e=Uint8Array.from(Ot(t.length));return _t([e,t],e.length+t.length)}function Ud(r){let t=Cd.decode(r),e=Uint8Array.from(Ot(t.length));return _t([e,t],e.length+t.length)}function Ld(r){let t=de(r),e=r.slice(xt(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+Q(e,"base64url")}function Rd(r){let t=de(r),e=r.slice(xt(t));if(e.length!==t)throw new Error("inconsistent lengths");return Q(e,"base58btc")}function Pd(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=ae.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=Oi(n);return _t([e,s],e.length+s.length)}function _d(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=ae.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=Oi(n);return _t([e,s],e.length+s.length)}function Ll(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=Q(t,"base32"),s=Rl(e);return`${n}:${s}`}function Pl(r){r=Vi(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],c=z(i);if(c.size===0){t.push([c.code]),e.push([c.code]);continue}if(o++,o>=s.length)throw new Vs("invalid address: "+r);if(c.path===!0){n=Vi(s.slice(o).join("/")),t.push([c.code,_i(c.code,n)]),e.push([c.code,n]);break}let a=_i(c.code,s[o]);t.push([c.code,a]),e.push([c.code,Pi(c.code,a)])}return{string:_l(e),bytes:Ds(t),tuples:t,stringTuples:e,path:n}}function Di(r){let t=[],e=[],n=null,s=0;for(;s<r.length;){let o=de(r,s),i=xt(o),c=z(o),a=Od(c,r.slice(s+i));if(a===0){t.push([o]),e.push([o]),s+=i;continue}let l=r.slice(s+i,s+i+a);if(s+=a+i,s>r.length)throw new Vs("Invalid address Uint8Array: "+Q(r,"base16"));t.push([o,l]);let u=Pi(o,l);if(e.push([o,u]),c.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:_l(e),tuples:t,stringTuples:e,path:n}}function _l(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}),Vi(t.join("/"))}function Ds(r){return _t(r.map(t=>{let e=z(t[0]),n=Uint8Array.from(Ot(e.code));return t.length>1&&t[1]!=null&&(n=_t([n,t[1]])),n}))}function Od(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=de(t instanceof Uint8Array?t:Uint8Array.from(t));return e+xt(e)}}function Vi(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}var Vs=class extends Error{static name="ParseError";name="ParseError";constructor(t){super(`Error parsing address: ${t}`)}};var Vd=Symbol.for("nodejs.util.inspect.custom"),Fi=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Dd=[z("dns").code,z("dns4").code,z("dns6").code,z("dnsaddr").code],Mi=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},Ms=class r{bytes;#e;#t;#r;#n;[Fi]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=Di(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Pl(t)}else if(Vl(t))e=Di(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"),c=z("udp"),a=z("ip4"),l=z("ip6"),u=z("dns6"),f=z("ip6zone");for(let[m,p]of this.stringTuples())m===f.code&&(o=`%${p??""}`),Dd.includes(m)&&(e=i.name==="tcp"?"tcp":"udp",s=443,n=`${p??""}${o}`,t=m===u.code?6:4),(m===i.code||m===c.code)&&(e=z(m).name==="tcp"?"tcp":"udp",s=parseInt(p??"")),(m===a.code||m===l.code)&&(e=z(m).name==="tcp"?"tcp":"udp",n=`${p??""}${o}`,t=m===l.code?6:4);if(t==null||e==null||n==null||s==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:t,host:n,transport:e,port:s}}protos(){return this.#t.map(([t])=>Object.assign({},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(Ds(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,s])=>{n===Sr.p2p.code&&t.push([n,s]),n===Sr["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 bt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(o=>o.resolvable);if(e==null)return[this];let n=Ol.get(e.name);if(n==null)throw new Mi(`no available resolver for ${e.name}`);return(await n(this,t)).map(o=>se(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)}[Vd](){return`Multiaddr(${this.#e})`}};var Ol=new Map;function Vl(r){return!!r?.[Fi]}function se(r){return new Ms(r)}var Dl="libp2p-peer-record",Ml=Uint8Array.from([3,1]);var an;(function(r){let t;(function(n){let s;n.codec=()=>(s==null&&(s=Gt((o,i,c={})=>{c.lengthDelimited!==!1&&i.fork(),o.multiaddr!=null&&o.multiaddr.byteLength>0&&(i.uint32(10),i.bytes(o.multiaddr)),c.lengthDelimited!==!1&&i.ldelim()},(o,i,c={})=>{let a={multiaddr:pt(0)},l=i==null?o.len:o.pos+i;for(;o.pos<l;){let u=o.uint32();switch(u>>>3){case 1:{a.multiaddr=o.bytes();break}default:{o.skipType(u&7);break}}}return a})),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:[]},c=s==null?n.len:n.pos+s;for(;n.pos<c;){let a=n.uint32();switch(a>>>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 Ze('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(a&7);break}}}return i})),e),r.encode=n=>zt(n,r.codec()),r.decode=(n,s)=>$t(n,r.codec(),s)})(an||(an={}));var Zt=class r{static createFromProtobuf=t=>{let e=an.decode(t),n=Si(Fe(e.peerId)),s=(e.addresses??[]).map(i=>se(i.multiaddr)),o=e.seq;return new r({peerId:n,multiaddrs:s,seqNumber:o})};static DOMAIN=Dl;static CODEC=Ml;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=an.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 Md(r){return r[Symbol.asyncIterator]!=null}function Fd(r){if(Md(r))return(async()=>{for await(let t of r);})();for(let t of r);}var Fl=Fd;function Yt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Fs=globalThis.CustomEvent??Event;async function*Hi(r,t={}){let e=t.concurrency??1/0;e<1&&(e=1/0);let n=t.ordered==null?!1:t.ordered,s=new EventTarget,o=[],i=Yt(),c=Yt(),a=!1,l,u=!1;s.addEventListener("task-complete",()=>{c.resolve()}),Promise.resolve().then(async()=>{try{for await(let p of r){if(o.length===e&&(i=Yt(),await i.promise),u)break;let b={done:!1};o.push(b),p().then(d=>{b.done=!0,b.ok=!0,b.value=d,s.dispatchEvent(new Fs("task-complete"))},d=>{b.done=!0,b.err=d,s.dispatchEvent(new Fs("task-complete"))})}a=!0,s.dispatchEvent(new Fs("task-complete"))}catch(p){l=p,s.dispatchEvent(new Fs("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*m(){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()||(c=Yt(),await c.promise),l!=null)throw l;if(n?yield*h():yield*m(),a&&o.length===0)break}}var Hs=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 Hl(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new Hs(e?.errorMessage,e?.errorCode,e?.errorName));let n,s=new Hs(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 Ki=class{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=Yt(),this.haveNext=Yt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Yt(),t}async throw(t){return this.ended=!0,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return await this._push(void 0),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Yt(),await Hl(this.readNext.promise,e?.signal,e)}};function Kl(){return new Ki}var Ks=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};var qi=class extends Error{code;constructor(t,e){super(t),this.code=e}},$i=class extends qi{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted",this.name="AbortError"}};function ql(r,t){let e=Kl();r.sink(e).catch(async i=>{await e.end(i)}),r.sink=async i=>{for await(let c of i)await e.push(c);await e.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let s=new jt;return{read:async(i,c)=>{c?.signal?.throwIfAborted();let a,l=new Promise((u,f)=>{a=()=>{f(new $i("Read aborted"))},c?.signal?.addEventListener("abort",a)});try{if(i==null){let{done:f,value:h}=await Promise.race([n.next(),l]);return f===!0?new jt:h}for(;s.byteLength<i;){let{value:f,done:h}=await Promise.race([n.next(),l]);if(h===!0)throw new Ks("unexpected end of input");s.append(f)}let u=s.sublist(0,i);return s.consume(i),u}finally{a!=null&&c?.signal?.removeEventListener("abort",a)}},write:async(i,c)=>{c?.signal?.throwIfAborted(),i instanceof Uint8Array?await e.push(i,c):await e.push(i.subarray(),c)},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 qs=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},$s=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},zs=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function $l(r,t={}){let e=ql(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=xt(t.maxDataLength));let n=t?.lengthDecoder??de,s=t?.lengthEncoder??Ot;return{read:async i=>{let c=-1,a=new jt;for(;;){a.append(await e.read(1,i));try{c=n(a)}catch(l){if(l instanceof RangeError)continue;throw l}if(c<0)throw new qs("Invalid message length");if(t?.maxLengthLength!=null&&a.byteLength>t.maxLengthLength)throw new zs("message length length too long");if(c>-1)break}if(t?.maxDataLength!=null&&c>t.maxDataLength)throw new $s("message length too long");return e.read(c,i)},write:async(i,c)=>{await e.write(new jt(s(i.byteLength),i),c)},writeV:async(i,c)=>{let a=new jt(...i.flatMap(l=>[s(l.byteLength),l]));await e.write(a,c)},unwrap:()=>e.unwrap()}}function Ir(r,t){let e=$l(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(c=>o.encode(c)),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 zl="0.1.0",Gl="id",Wl="id/push",jl="1.0.0",Zl="1.0.0";var De;(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 c=e.uint32();switch(c>>>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 Ze('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 Ze('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(c&7);break}}}return o})),t),r.encode=e=>zt(e,r.codec()),r.decode=(e,n)=>$t(e,r.codec(),n)})(De||(De={}));var Rt={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function Yl(r){if(r!=null&&r.length>0)try{return se(r)}catch{}}function qd(r,t){return t??r.userAgent}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(a=>({isCertified:!1,multiaddr:se(a)}))),s.protocols.length>0&&(o.protocols=s.protocols),s.publicKey!=null){let a=xr(s.publicKey);if(!xl(a).equals(n.remotePeer))throw new Dt("public key did not match remote PeerId");o.publicKey=a}let i;if(s.signedPeerRecord!=null){e.trace("received signedPeerRecord from %p",n.remotePeer);let a=s.signedPeerRecord,l=await ne.openAndCertify(a,Zt.DOMAIN),u=Zt.createFromProtobuf(l.payload),f=Ls(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(m){if(m.name!=="NotFoundError")throw m}if(h!=null&&(o.metadata=h.metadata,h.peerRecordEnvelope!=null)){let m=await ne.createFromProtobuf(h.peerRecordEnvelope),p=Zt.createFromProtobuf(m.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,a=h.peerRecordEnvelope)}o.peerRecordEnvelope=a,o.addresses=u.multiaddrs.map(m=>({isCertified:!0,multiaddr:m})),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 a={};s.agentVersion!=null&&(a.AgentVersion=$(s.agentVersion)),s.protocolVersion!=null&&(a.ProtocolVersion=$(s.protocolVersion)),e.trace("merging %p metadata",n.remotePeer,a),await r.merge(n.remotePeer,{metadata:a})}let c={peerId:n.remotePeer,protocolVersion:s.protocolVersion,agentVersion:s.agentVersion,publicKey:s.publicKey,listenAddrs:s.listenAddrs.map(a=>se(a)),observedAddr:s.observedAddr==null?void 0:se(s.observedAddr),protocols:s.protocols,signedPeerRecord:i,connection:n};return t.safeDispatchEvent("peer:identify",{detail:c}),c}var kr=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}/${zl}`,agentVersion:qd(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 kr{connectionManager;concurrency;constructor(t,e={}){super(t,{...e,protocol:`/${e.protocolPrefix??Rt.protocolPrefix}/${Wl}/${Zl}`,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)})})}[gn]=["@libp2p/identify-push"];async push(){if(!this.isStarted())return;let t=this.addressManager.getAddresses().map(u=>u.decapsulateCode(z("p2p").code)),e=new Zt({peerId:this.peerId,multiaddrs:t}),n=await ne.seal(e,this.privateKey),s=this.registrar.getProtocols(),o=await this.peerStore.get(this.peerId),i=Q(o.metadata.get("AgentVersion")??$(this.host.agentVersion)),c=Q(o.metadata.get("ProtocolVersion")??$(this.host.protocolVersion)),a=this;async function*l(){for(let u of a.connectionManager.getConnections())(await a.peerStore.get(u.remotePeer)).protocols.includes(a.protocol)&&(yield async()=>{let h,m=AbortSignal.timeout(a.timeout);try{h=await u.newStream(a.protocol,{signal:m,runOnLimitedConnection:a.runOnLimitedConnection}),await Ir(h,{maxDataLength:a.maxMessageSize}).pb(De).write({listenAddrs:t.map(b=>b.bytes),signedPeerRecord:n.marshal(),protocols:s,agentVersion:i,protocolVersion:c},{signal:m}),await h.close({signal:m})}catch(p){a.log.error("could not push identify update to peer",p),h?.abort(p)}})}await Fl(Hi(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 Ir(n,{maxDataLength:this.maxMessageSize}).pb(De).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 zd=41;function Jl(r){try{let[[t,e]]=r.stringTuples();if(e==null)return!1;if(t===zd)return Cl("2000::/3",e)}catch{}return!1}var Ql=ia(Xl(),1),Gd=["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"],Wd=Gd.map(r=>new Ql.Netmask(r));function zi(r){for(let t of Wd)if(t.contains(r))return!0;return!1}function jd(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function Zd(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 zi(s)}function Yd(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function Jd(r){let t=r.split(":"),e=t[t.length-1];return zi(e)}function Xd(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 tu(r){return Br(r)?zi(r):jd(r)?Zd(r):Yd(r)?Jd(r):Ar(r)?Xd(r):void 0}function eu(r){try{let[[t]]=r.stringTuples();return t===4||t===41}catch{}return!1}function ru(r){try{if(!eu(r))return!1;let[[,t]]=r.stringTuples();return t==null?!1:tu(t)??!1}catch{}return!0}var Qd=r=>r.toString().split("/").slice(1),Cr=r=>({match:t=>t.length<1?!1:r(t[0])?t.slice(1):!1,pattern:"fn"}),H=r=>({match:t=>Cr(e=>e===r).match(t),pattern:r}),er=()=>({match:r=>Cr(t=>typeof t=="string").match(r),pattern:"{string}"}),ln=()=>({match:r=>Cr(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}"}),un=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{Wo.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=Qd(s);for(let i of r){let c=i.match(o);if(c===!1)return!1;o=c}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()),Wi=K(H("dns"),er()),Gx=st(Zs,G(Y())),Wx=st(Ys,G(Y())),jx=st(Js,G(Y())),Zx=st(Bt(Wi,Js,Zs,Ys),G(Y())),nu=K(H("ip4"),Cr(Br)),su=K(H("ip6"),Cr(Ar)),ji=Bt(nu,su),Ee=Bt(ji,Wi,Zs,Ys,Js),ou=st(Bt(ji,K(Bt(Wi,Js,Zs,Ys),G(Y())))),Yx=st(nu),Jx=st(su),Xx=st(ji),Zi=K(Ee,H("tcp"),ln()),fn=K(Ee,H("udp"),ln()),iu=st(K(Zi,G(Y()))),Qx=st(fn),Yi=K(fn,H("quic"),G(Y())),Xs=K(fn,H("quic-v1"),G(Y())),t0=Bt(Yi,Xs),t1=st(Yi),e1=st(Xs),Gi=Bt(Ee,Zi,fn,Yi,Xs),au=Bt(K(Gi,H("ws"),G(Y()))),r1=st(au),cu=Bt(K(Gi,H("wss"),G(Y())),K(Gi,H("tls"),G(K(H("sni"),er())),H("ws"),G(Y()))),n1=st(cu),lu=K(fn,H("webrtc-direct"),G(un()),G(un()),G(Y())),s1=st(lu),uu=K(Xs,H("webtransport"),G(un()),G(un()),G(Y())),o1=st(uu),js=Bt(au,cu,K(Zi,G(Y())),K(t0,G(Y())),K(Ee,G(Y())),lu,uu,Y()),i1=st(js),e0=K(js,H("p2p-circuit"),Y()),a1=st(e0),r0=Bt(K(js,H("p2p-circuit"),H("webrtc"),G(Y())),K(js,H("webrtc"),G(Y())),K(H("webrtc"),G(Y()))),c1=st(r0),n0=Bt(K(Ee,H("tcp"),ln(),H("http"),G(Y())),K(Ee,H("http"),G(Y()))),l1=st(n0),s0=Bt(K(Ee,H("tcp"),Bt(K(H("443"),H("http")),K(ln(),H("https"))),G(Y())),K(Ee,H("tls"),H("http"),G(Y())),K(Ee,H("https"),G(Y()))),u1=st(s0),o0=Bt(K(H("memory"),er(),G(Y()))),f1=st(o0);var i0=41,Qs=class extends kr{constructor(t,e={}){super(t,{...e,protocol:`/${e.protocolPrefix??Rt.protocolPrefix}/${Gl}/${jl}`,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!==mn.name&&this.log.error("error during identify trigged by connection:open",o)})})}[gn]=["@libp2p/identify"];async _identify(t,e={}){let n;if(e.signal==null){let s=AbortSignal.timeout(this.timeout);e={...e,signal:s}}try{n=await t.newStream(this.protocol,{...e,runOnLimitedConnection:this.runOnLimitedConnection});let o=await Ir(n,{maxDataLength:this.maxMessageSize}).pb(De).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 c=xr(s),a=Ls(c.toCID());if(!t.remotePeer.equals(a))throw new Dt("identified peer does not match the expected peer");if(this.peerId.equals(a))throw new Dt("identified peer is our own peer id?");return this.maybeAddObservedAddress(i),this.log("identify completed for peer %p and protocols %o",a,o),Gs(this.peerStore,this.events,this.log,t,n)}maybeAddObservedAddress(t){let e=Yl(t);if(e==null)return;if(this.log.trace("our observed address was %a",e),ru(e)){this.log.trace("our observed address was private");return}if(e.stringTuples()[0][0]===i0&&!Jl(e)){this.log.trace("our observed address was IPv6 but not a global unicast address");return}iu.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);try{let o=await this.peerStore.get(this.peerId),i=this.addressManager.getAddresses().map(u=>u.decapsulateCode(z("p2p").code)),c=o.peerRecordEnvelope;if(i.length>0&&c==null){let u=new Zt({peerId:this.peerId,multiaddrs:i});c=(await ne.seal(u,this.privateKey)).marshal().subarray()}let a=e.remoteAddr.bytes;ou.matches(e.remoteAddr)||(a=void 0),await Ir(n).pb(De).write({protocolVersion:this.host.protocolVersion,agentVersion:this.host.agentVersion,publicKey:Ue(this.privateKey.publicKey),listenAddrs:i.map(u=>u.bytes),signedPeerRecord:c,observedAddr:a,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 c0(r={}){return t=>new Ws(t,r)}return Au(l0);})();
|
|
2
|
+
"use strict";var Libp2PIdentify=(()=>{var lc=Object.create;var Nr=Object.defineProperty;var dc=Object.getOwnPropertyDescriptor;var hc=Object.getOwnPropertyNames;var pc=Object.getPrototypeOf,mc=Object.prototype.hasOwnProperty;var gc=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),Et=(r,t)=>{for(var e in t)Nr(r,e,{get:t[e],enumerable:!0})},Os=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of hc(t))!mc.call(r,o)&&o!==e&&Nr(r,o,{get:()=>t[o],enumerable:!(n=dc(t,o))||n.enumerable});return r};var yc=(r,t,e)=>(e=r!=null?lc(pc(r)):{},Os(t||!r||!r.__esModule?Nr(e,"default",{value:r,enumerable:!0}):e,r)),bc=r=>Os(Nr({},"__esModule",{value:!0}),r);var za=gc(Pr=>{(function(){var r,t,e,n,o,s,i,c;c=function(a){var f,u,l,d;return f=(a&255<<24)>>>24,u=(a&255<<16)>>>16,l=(a&65280)>>>8,d=a&255,[f,u,l,d].join(".")},i=function(a){var f,u,l,d,y,m;for(f=[],l=d=0;d<=3&&a.length!==0;l=++d){if(l>0){if(a[0]!==".")throw new Error("Invalid IP");a=a.substring(1)}m=t(a),y=m[0],u=m[1],a=a.substring(u),f.push(y)}if(a.length!==0)throw new Error("Invalid IP");switch(f.length){case 1:if(f[0]>4294967295)throw new Error("Invalid IP");return f[0]>>>0;case 2:if(f[0]>255||f[1]>16777215)throw new Error("Invalid IP");return(f[0]<<24|f[1])>>>0;case 3:if(f[0]>255||f[1]>255||f[2]>65535)throw new Error("Invalid IP");return(f[0]<<24|f[1]<<16|f[2])>>>0;case 4:if(f[0]>255||f[1]>255||f[2]>255||f[3]>255)throw new Error("Invalid IP");return(f[0]<<24|f[1]<<16|f[2]<<8|f[3])>>>0;default:throw new Error("Invalid IP")}},e=function(a){return a.charCodeAt(0)},n=e("0"),s=e("a"),o=e("A"),t=function(a){var f,u,l,d,y;for(d=0,f=10,u="9",l=0,a.length>1&&a[l]==="0"&&(a[l+1]==="x"||a[l+1]==="X"?(l+=2,f=16):"0"<=a[l+1]&&a[l+1]<="9"&&(l++,f=8,u="7")),y=l;l<a.length;){if("0"<=a[l]&&a[l]<=u)d=d*f+(e(a[l])-n)>>>0;else if(f===16)if("a"<=a[l]&&a[l]<="f")d=d*f+(10+e(a[l])-s)>>>0;else if("A"<=a[l]&&a[l]<="F")d=d*f+(10+e(a[l])-o)>>>0;else break;else break;if(d>4294967295)throw new Error("too large");l++}if(l===y)throw new Error("empty octet");return[d,l]},r=function(){function a(f,u){var l,d,y,m;if(typeof f!="string")throw new Error("Missing `net' parameter");if(u||(m=f.split("/",2),f=m[0],u=m[1]),u||(u=32),typeof u=="string"&&u.indexOf(".")>-1){try{this.maskLong=i(u)}catch(b){throw l=b,new Error("Invalid mask: "+u)}for(d=y=32;y>=0;d=--y)if(this.maskLong===4294967295<<32-d>>>0){this.bitmask=d;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(f)&this.maskLong)>>>0}catch(b){throw l=b,new Error("Invalid net address: "+f)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+u);this.size=Math.pow(2,32-this.bitmask),this.base=c(this.netLong),this.mask=c(this.maskLong),this.hostmask=c(~this.maskLong),this.first=this.bitmask<=30?c(this.netLong+1):this.base,this.last=this.bitmask<=30?c(this.netLong+this.size-2):c(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?c(this.netLong+this.size-1):void 0}return a.prototype.contains=function(f){return typeof f=="string"&&(f.indexOf("/")>0||f.split(".").length!==4)&&(f=new a(f)),f instanceof a?this.contains(f.base)&&this.contains(f.broadcast||f.last):(i(f)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},a.prototype.next=function(f){return f==null&&(f=1),new a(c(this.netLong+this.size*f),this.mask)},a.prototype.forEach=function(f){var u,l,d;for(d=i(this.first),l=i(this.last),u=0;d<=l;)f(c(d),d,u),u++,d++},a.prototype.toString=function(){return this.base+"/"+this.bitmask},a}(),Pr.ip2long=i,Pr.long2ip=c,Pr.Netmask=r}).call(Pr)});var Jl={};Et(Jl,{identify:()=>jl,identifyPush:()=>Ql});var Dn=Symbol.for("@libp2p/peer-id");var vt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Oe=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Ur=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},Dr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}},Or=class extends Error{static name="UnsupportedProtocolError";constructor(t="Unsupported protocol error"){super(t),this.name="UnsupportedProtocolError"}},_t=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var we=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var kr=Symbol.for("@libp2p/service-capabilities"),nd=Symbol.for("@libp2p/service-dependencies");var Fn={};Et(Fn,{base58btc:()=>j,base58flickr:()=>Ic});var Bd=new Uint8Array(0);function ks(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 Yt(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 Ms(r){return new TextEncoder().encode(r)}function Ks(r){return new TextDecoder().decode(r)}function xc(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var c=r.length,a=r.charAt(0),f=Math.log(c)/Math.log(256),u=Math.log(256)/Math.log(c);function l(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var b=0,h=0,E=0,S=m.length;E!==S&&m[E]===0;)E++,b++;for(var g=(S-E)*u+1>>>0,A=new Uint8Array(g);E!==S;){for(var R=m[E],C=0,B=g-1;(R!==0||C<h)&&B!==-1;B--,C++)R+=256*A[B]>>>0,A[B]=R%c>>>0,R=R/c>>>0;if(R!==0)throw new Error("Non-zero carry");h=C,E++}for(var P=g-h;P!==g&&A[P]===0;)P++;for(var T=a.repeat(b);P<g;++P)T+=r.charAt(A[P]);return T}function d(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var b=0;if(m[b]!==" "){for(var h=0,E=0;m[b]===a;)h++,b++;for(var S=(m.length-b)*f+1>>>0,g=new Uint8Array(S);m[b];){var A=e[m.charCodeAt(b)];if(A===255)return;for(var R=0,C=S-1;(A!==0||R<E)&&C!==-1;C--,R++)A+=c*g[C]>>>0,g[C]=A%256>>>0,A=A/256>>>0;if(A!==0)throw new Error("Non-zero carry");E=R,b++}if(m[b]!==" "){for(var B=S-E;B!==S&&g[B]===0;)B++;for(var P=new Uint8Array(h+(S-B)),T=h;B!==S;)P[T++]=g[B++];return P}}}function y(m){var b=d(m);if(b)return b;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:d,decode:y}}var wc=xc,Ec=wc,Vs=Ec;var On=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")}},kn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,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 qs(this,t)}},Mn=class{decoders;constructor(t){this.decoders=t}or(t){return qs(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 qs(r,t){return new Mn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Kn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new On(t,e,n),this.decoder=new kn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ke({name:r,prefix:t,encode:e,decode:n}){return new Kn(r,t,e,n)}function ie({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Vs(e,r);return ke({prefix:t,name:r,encode:n,decode:s=>Yt(o(s))})}function vc(r,t,e,n){let o={};for(let u=0;u<t.length;++u)o[t[u]]=u;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*e/8|0),c=0,a=0,f=0;for(let u=0;u<s;++u){let l=o[r[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|l,c+=e,c>=8&&(c-=8,i[f++]=255&a>>c)}if(c>=e||(255&a<<8-c)!==0)throw new SyntaxError("Unexpected end of data");return i}function Sc(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,c=0;for(let a=0;a<r.length;++a)for(c=c<<8|r[a],i+=8;i>e;)i-=e,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function nt({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return ke({prefix:t,name:r,encode(o){return Sc(o,n,e)},decode(o){return vc(o,n,e,r)}})}var j=ie({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ic=ie({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Vn={};Et(Vn,{base32:()=>Xt,base32hex:()=>Lc,base32hexpad:()=>Cc,base32hexpadupper:()=>Rc,base32hexupper:()=>Pc,base32pad:()=>Bc,base32padupper:()=>Tc,base32upper:()=>Ac,base32z:()=>_c});var Xt=nt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ac=nt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Bc=nt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Tc=nt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Lc=nt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Pc=nt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Cc=nt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Rc=nt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),_c=nt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var qn={};Et(qn,{base36:()=>sr,base36upper:()=>Nc});var sr=ie({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Nc=ie({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Uc=Gs,Hs=128,Dc=127,Oc=~Dc,kc=Math.pow(2,31);function Gs(r,t,e){t=t||[],e=e||0;for(var n=e;r>=kc;)t[e++]=r&255|Hs,r/=128;for(;r&Oc;)t[e++]=r&255|Hs,r>>>=7;return t[e]=r|0,Gs.bytes=e-n+1,t}var Mc=Hn,Kc=128,zs=127;function Hn(r,n){var e=0,n=n||0,o=0,s=n,i,c=r.length;do{if(s>=c)throw Hn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&zs)<<o:(i&zs)*Math.pow(2,o),o+=7}while(i>=Kc);return Hn.bytes=s-n,e}var Fc=Math.pow(2,7),Vc=Math.pow(2,14),qc=Math.pow(2,21),Hc=Math.pow(2,28),zc=Math.pow(2,35),Gc=Math.pow(2,42),$c=Math.pow(2,49),Zc=Math.pow(2,56),Wc=Math.pow(2,63),Yc=function(r){return r<Fc?1:r<Vc?2:r<qc?3:r<Hc?4:r<zc?5:r<Gc?6:r<$c?7:r<Zc?8:r<Wc?9:10},Xc={encode:Uc,decode:Mc,encodingLength:Yc},jc=Xc,ir=jc;function ar(r,t=0){return[ir.decode(r,t),ir.decode.bytes]}function Me(r,t,e=0){return ir.encode(r,t,e),t}function Ke(r){return ir.encodingLength(r)}function Nt(r,t){let e=t.byteLength,n=Ke(r),o=n+Ke(e),s=new Uint8Array(o+e);return Me(r,s,0),Me(e,s,n),s.set(t,o),new Fe(r,e,t,s)}function Ee(r){let t=Yt(r),[e,n]=ar(t),[o,s]=ar(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Fe(e,o,i,t)}function $s(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&ks(r.bytes,e.bytes)}}var Fe=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function Zs(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Jc(e,zn(r),t??j.encoder);default:return tu(e,zn(r),t??Xt.encoder)}}var Ws=new WeakMap;function zn(r){let t=Ws.get(r);if(t==null){let e=new Map;return Ws.set(r,e),e}return t}var dt=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==cr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==eu)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=Nt(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&&$s(t.multihash,n.multihash)}toString(t){return Zs(this,t)}toJSON(){return{"/":Zs(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??Ys(n,o,s.bytes))}else if(e[ru]===!0){let{version:n,multihash:o,code:s}=e,i=Ee(o);return r.create(n,s,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!==cr)throw new Error(`Version 0 CID must use dag-pb (code: ${cr}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Ys(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,cr,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Yt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new Fe(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[l,d]=ar(t.subarray(e));return e+=d,l},o=n(),s=cr;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,c=n(),a=n(),f=e+a,u=f-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:u,size:f}}static parse(t,e){let[n,o]=Qc(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return zn(s).set(n,t),s}};function Qc(r,t){switch(r[0]){case"Q":{let e=t??j;return[j.prefix,e.decode(`${j.prefix}${r}`)]}case j.prefix:{let e=t??j;return[j.prefix,e.decode(r)]}case Xt.prefix:{let e=t??Xt;return[Xt.prefix,e.decode(r)]}case sr.prefix:{let e=t??sr;return[sr.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 Jc(r,t,e){let{prefix:n}=e;if(n!==j.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function tu(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var cr=112,eu=18;function Ys(r,t,e){let n=Ke(r),o=n+Ke(t),s=new Uint8Array(o+e.byteLength);return Me(r,s,0),Me(t,s,n),s.set(e,o),s}var ru=Symbol.for("@ipld/js-cid/CID");var Gn={};Et(Gn,{identity:()=>jt});var Xs=0,nu="identity",js=Yt;function ou(r){return Nt(Xs,js(r))}var jt={code:Xs,name:nu,encode:js,digest:ou};function mt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Qs(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function su(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Ve(r,...t){if(!su(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 Js(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Qs(r.outputLen),Qs(r.blockLen)}function qe(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 ti(r,t){Ve(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}var ve=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Kr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Ut(r,t){return r<<32-t|r>>>t}function ei(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function ur(r){return typeof r=="string"&&(r=ei(r)),Ve(r),r}function $n(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Ve(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}var He=class{clone(){return this._cloneInto()}};function Fr(r){let t=n=>r().update(ur(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function Vr(r=32){if(ve&&typeof ve.getRandomValues=="function")return ve.getRandomValues(new Uint8Array(r));if(ve&&typeof ve.randomBytes=="function")return ve.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function iu(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(e>>o&s),c=Number(e&s),a=n?4:0,f=n?0:4;r.setUint32(t+a,i,n),r.setUint32(t+f,c,n)}function ri(r,t,e){return r&t^~r&e}function ni(r,t,e){return r&t^r&e^t&e}var ze=class extends He{constructor(t,e,n,o){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=Kr(this.buffer)}update(t){qe(this);let{view:e,buffer:n,blockLen:o}=this;t=ur(t);let s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=Kr(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){qe(this),ti(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)e[l]=0;iu(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=Kr(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=a/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)c.setUint32(4*l,u[l],s)}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:o,finished:s,destroyed:i,pos:c}=this;return t.length=o,t.pos=c,t.finished=s,t.destroyed=i,o%e&&t.buffer.set(n),t}};var qr=BigInt(4294967295),Zn=BigInt(32);function oi(r,t=!1){return t?{h:Number(r&qr),l:Number(r>>Zn&qr)}:{h:Number(r>>Zn&qr)|0,l:Number(r&qr)|0}}function au(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:s,l:i}=oi(r[o],t);[e[o],n[o]]=[s,i]}return[e,n]}var cu=(r,t)=>BigInt(r>>>0)<<Zn|BigInt(t>>>0),uu=(r,t,e)=>r>>>e,fu=(r,t,e)=>r<<32-e|t>>>e,lu=(r,t,e)=>r>>>e|t<<32-e,du=(r,t,e)=>r<<32-e|t>>>e,hu=(r,t,e)=>r<<64-e|t>>>e-32,pu=(r,t,e)=>r>>>e-32|t<<64-e,mu=(r,t)=>t,gu=(r,t)=>r,yu=(r,t,e)=>r<<e|t>>>32-e,bu=(r,t,e)=>t<<e|r>>>32-e,xu=(r,t,e)=>t<<e-32|r>>>64-e,wu=(r,t,e)=>r<<e-32|t>>>64-e;function Eu(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var vu=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Su=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Iu=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Au=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Bu=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Tu=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Lu={fromBig:oi,split:au,toBig:cu,shrSH:uu,shrSL:fu,rotrSH:lu,rotrSL:du,rotrBH:hu,rotrBL:pu,rotr32H:mu,rotr32L:gu,rotlSH:yu,rotlSL:bu,rotlBH:xu,rotlBL:wu,add:Eu,add3L:vu,add3H:Su,add4L:Iu,add4H:Au,add5H:Tu,add5L:Bu},D=Lu;var[Pu,Cu]=D.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))),ce=new Uint32Array(80),ue=new Uint32Array(80),Wn=class extends ze{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:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:f,El:u,Fh:l,Fl:d,Gh:y,Gl:m,Hh:b,Hl:h}=this;return[t,e,n,o,s,i,c,a,f,u,l,d,y,m,b,h]}set(t,e,n,o,s,i,c,a,f,u,l,d,y,m,b,h){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=c|0,this.Dl=a|0,this.Eh=f|0,this.El=u|0,this.Fh=l|0,this.Fl=d|0,this.Gh=y|0,this.Gl=m|0,this.Hh=b|0,this.Hl=h|0}process(t,e){for(let g=0;g<16;g++,e+=4)ce[g]=t.getUint32(e),ue[g]=t.getUint32(e+=4);for(let g=16;g<80;g++){let A=ce[g-15]|0,R=ue[g-15]|0,C=D.rotrSH(A,R,1)^D.rotrSH(A,R,8)^D.shrSH(A,R,7),B=D.rotrSL(A,R,1)^D.rotrSL(A,R,8)^D.shrSL(A,R,7),P=ce[g-2]|0,T=ue[g-2]|0,Q=D.rotrSH(P,T,19)^D.rotrBH(P,T,61)^D.shrSH(P,T,6),q=D.rotrSL(P,T,19)^D.rotrBL(P,T,61)^D.shrSL(P,T,6),k=D.add4L(B,q,ue[g-7],ue[g-16]),st=D.add4H(k,C,Q,ce[g-7],ce[g-16]);ce[g]=st|0,ue[g]=k|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:f,Dl:u,Eh:l,El:d,Fh:y,Fl:m,Gh:b,Gl:h,Hh:E,Hl:S}=this;for(let g=0;g<80;g++){let A=D.rotrSH(l,d,14)^D.rotrSH(l,d,18)^D.rotrBH(l,d,41),R=D.rotrSL(l,d,14)^D.rotrSL(l,d,18)^D.rotrBL(l,d,41),C=l&y^~l&b,B=d&m^~d&h,P=D.add5L(S,R,B,Cu[g],ue[g]),T=D.add5H(P,E,A,C,Pu[g],ce[g]),Q=P|0,q=D.rotrSH(n,o,28)^D.rotrBH(n,o,34)^D.rotrBH(n,o,39),k=D.rotrSL(n,o,28)^D.rotrBL(n,o,34)^D.rotrBL(n,o,39),st=n&s^n&c^s&c,v=o&i^o&a^i&a;E=b|0,S=h|0,b=y|0,h=m|0,y=l|0,m=d|0,{h:l,l:d}=D.add(f|0,u|0,T|0,Q|0),f=c|0,u=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let L=D.add3L(Q,k,v);n=D.add3H(L,T,q,st),o=L|0}({h:n,l:o}=D.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=D.add(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=D.add(this.Ch|0,this.Cl|0,c|0,a|0),{h:f,l:u}=D.add(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:d}=D.add(this.Eh|0,this.El|0,l|0,d|0),{h:y,l:m}=D.add(this.Fh|0,this.Fl|0,y|0,m|0),{h:b,l:h}=D.add(this.Gh|0,this.Gl|0,b|0,h|0),{h:E,l:S}=D.add(this.Hh|0,this.Hl|0,E|0,S|0),this.set(n,o,s,i,c,a,f,u,l,d,y,m,b,h,E,S)}roundClean(){ce.fill(0),ue.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 si=Fr(()=>new Wn);var Gr={};Et(Gr,{aInRange:()=>It,abool:()=>Dt,abytes:()=>Ge,bitGet:()=>Ou,bitLen:()=>Qn,bitMask:()=>lr,bitSet:()=>ku,bytesToHex:()=>Jt,bytesToNumberBE:()=>te,bytesToNumberLE:()=>le,concatBytes:()=>ee,createHmacDrbg:()=>Jn,ensureBytes:()=>et,equalBytes:()=>Uu,hexToBytes:()=>Ie,hexToNumber:()=>jn,inRange:()=>fr,isBytes:()=>fe,memoized:()=>Be,notImplemented:()=>Ku,numberToBytesBE:()=>de,numberToBytesLE:()=>Ae,numberToHexUnpadded:()=>Se,numberToVarBytesBE:()=>Nu,utf8ToBytes:()=>Du,validateObject:()=>zt});var Hr=BigInt(0),zr=BigInt(1),Ru=BigInt(2);function fe(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Ge(r){if(!fe(r))throw new Error("Uint8Array expected")}function Dt(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}var _u=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Jt(r){Ge(r);let t="";for(let e=0;e<r.length;e++)t+=_u[r[e]];return t}function Se(r){let t=r.toString(16);return t.length&1?"0"+t:t}function jn(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Hr:BigInt("0x"+r)}var Qt={_0:48,_9:57,A:65,F:70,a:97,f:102};function ii(r){if(r>=Qt._0&&r<=Qt._9)return r-Qt._0;if(r>=Qt.A&&r<=Qt.F)return r-(Qt.A-10);if(r>=Qt.a&&r<=Qt.f)return r-(Qt.a-10)}function Ie(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 o=0,s=0;o<e;o++,s+=2){let i=ii(r.charCodeAt(s)),c=ii(r.charCodeAt(s+1));if(i===void 0||c===void 0){let a=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function te(r){return jn(Jt(r))}function le(r){return Ge(r),jn(Jt(Uint8Array.from(r).reverse()))}function de(r,t){return Ie(r.toString(16).padStart(t*2,"0"))}function Ae(r,t){return de(r,t).reverse()}function Nu(r){return Ie(Se(r))}function et(r,t,e){let n;if(typeof t=="string")try{n=Ie(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(fe(t))n=Uint8Array.from(t);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof e=="number"&&o!==e)throw new Error(r+" of length "+e+" expected, got "+o);return n}function ee(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Ge(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}function Uu(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 Du(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}var Yn=r=>typeof r=="bigint"&&Hr<=r;function fr(r,t,e){return Yn(r)&&Yn(t)&&Yn(e)&&t<=r&&r<e}function It(r,t,e,n){if(!fr(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Qn(r){let t;for(t=0;r>Hr;r>>=zr,t+=1);return t}function Ou(r,t){return r>>BigInt(t)&zr}function ku(r,t,e){return r|(e?zr:Hr)<<BigInt(t)}var lr=r=>(Ru<<BigInt(r-1))-zr,Xn=r=>new Uint8Array(r),ai=r=>Uint8Array.from(r);function Jn(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=Xn(r),o=Xn(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},c=(...l)=>e(o,n,...l),a=(l=Xn())=>{o=c(ai([0]),l),n=c(),l.length!==0&&(o=c(ai([1]),l),n=c())},f=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,d=[];for(;l<t;){n=c();let y=n.slice();d.push(y),l+=n.length}return ee(...d)};return(l,d)=>{i(),a(l);let y;for(;!(y=d(f()));)a();return i(),y}}var Mu={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"||fe(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 zt(r,t,e={}){let n=(o,s,i)=>{let c=Mu[s];if(typeof c!="function")throw new Error("invalid validator function");let a=r[o];if(!(i&&a===void 0)&&!c(a,r))throw new Error("param "+String(o)+" is invalid. Expected "+s+", got "+a)};for(let[o,s]of Object.entries(t))n(o,s,!1);for(let[o,s]of Object.entries(e))n(o,s,!0);return r}var Ku=()=>{throw new Error("not implemented")};function Be(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var it=BigInt(0),J=BigInt(1),Te=BigInt(2),Fu=BigInt(3),to=BigInt(4),ci=BigInt(5),ui=BigInt(8),Vu=BigInt(9),qu=BigInt(16);function W(r,t){let e=r%t;return e>=it?e:t+e}function Hu(r,t,e){if(t<it)throw new Error("invalid exponent, negatives unsupported");if(e<=it)throw new Error("invalid modulus");if(e===J)return it;let n=J;for(;t>it;)t&J&&(n=n*r%e),r=r*r%e,t>>=J;return n}function tt(r,t,e){let n=r;for(;t-- >it;)n*=n,n%=e;return n}function $r(r,t){if(r===it)throw new Error("invert: expected non-zero number");if(t<=it)throw new Error("invert: expected positive modulus, got "+t);let e=W(r,t),n=t,o=it,s=J,i=J,c=it;for(;e!==it;){let f=n/e,u=n%e,l=o-i*f,d=s-c*f;n=e,e=u,o=i,s=c,i=l,c=d}if(n!==J)throw new Error("invert: does not exist");return W(o,t)}function zu(r){let t=(r-J)/Te,e,n,o;for(e=r-J,n=0;e%Te===it;e/=Te,n++);for(o=Te;o<r&&Hu(o,t,r)!==r-J;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let i=(r+J)/to;return function(a,f){let u=a.pow(f,i);if(!a.eql(a.sqr(u),f))throw new Error("Cannot find square root");return u}}let s=(e+J)/Te;return function(c,a){if(c.pow(a,t)===c.neg(c.ONE))throw new Error("Cannot find square root");let f=n,u=c.pow(c.mul(c.ONE,o),e),l=c.pow(a,s),d=c.pow(a,e);for(;!c.eql(d,c.ONE);){if(c.eql(d,c.ZERO))return c.ZERO;let y=1;for(let b=c.sqr(d);y<f&&!c.eql(b,c.ONE);y++)b=c.sqr(b);let m=c.pow(u,J<<BigInt(f-y-1));u=c.sqr(m),l=c.mul(l,m),d=c.mul(d,u),f=y}return l}}function Gu(r){if(r%to===Fu){let t=(r+J)/to;return function(n,o){let s=n.pow(o,t);if(!n.eql(n.sqr(s),o))throw new Error("Cannot find square root");return s}}if(r%ui===ci){let t=(r-ci)/ui;return function(n,o){let s=n.mul(o,Te),i=n.pow(s,t),c=n.mul(o,i),a=n.mul(n.mul(c,Te),i),f=n.mul(c,n.sub(a,n.ONE));if(!n.eql(n.sqr(f),o))throw new Error("Cannot find square root");return f}}return r%qu,zu(r)}var fi=(r,t)=>(W(r,t)&J)===J,$u=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function eo(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=$u.reduce((n,o)=>(n[o]="function",n),t);return zt(r,e)}function Zu(r,t,e){if(e<it)throw new Error("invalid exponent, negatives unsupported");if(e===it)return r.ONE;if(e===J)return t;let n=r.ONE,o=t;for(;e>it;)e&J&&(n=r.mul(n,o)),o=r.sqr(o),e>>=J;return n}function Wu(r,t){let e=new Array(t.length),n=t.reduce((s,i,c)=>r.is0(i)?s:(e[c]=s,r.mul(s,i)),r.ONE),o=r.inv(n);return t.reduceRight((s,i,c)=>r.is0(i)?s:(e[c]=r.mul(s,e[c]),r.mul(s,i)),o),e}function ro(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function he(r,t,e=!1,n={}){if(r<=it)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:s}=ro(r,t);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let i,c=Object.freeze({ORDER:r,isLE:e,BITS:o,BYTES:s,MASK:lr(o),ZERO:it,ONE:J,create:a=>W(a,r),isValid:a=>{if(typeof a!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof a);return it<=a&&a<r},is0:a=>a===it,isOdd:a=>(a&J)===J,neg:a=>W(-a,r),eql:(a,f)=>a===f,sqr:a=>W(a*a,r),add:(a,f)=>W(a+f,r),sub:(a,f)=>W(a-f,r),mul:(a,f)=>W(a*f,r),pow:(a,f)=>Zu(c,a,f),div:(a,f)=>W(a*$r(f,r),r),sqrN:a=>a*a,addN:(a,f)=>a+f,subN:(a,f)=>a-f,mulN:(a,f)=>a*f,inv:a=>$r(a,r),sqrt:n.sqrt||(a=>(i||(i=Gu(r)),i(c,a))),invertBatch:a=>Wu(c,a),cmov:(a,f,u)=>u?f:a,toBytes:a=>e?Ae(a,s):de(a,s),fromBytes:a=>{if(a.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+a.length);return e?le(a):te(a)}});return Object.freeze(c)}function li(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 no(r){let t=li(r);return t+Math.ceil(t/2)}function di(r,t,e=!1){let n=r.length,o=li(t),s=no(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?le(r):te(r),c=W(i,t-J)+J;return e?Ae(c,o):de(c,o)}var hi=BigInt(0),Zr=BigInt(1);function oo(r,t){let e=t.negate();return r?e:t}function pi(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function so(r,t){pi(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1);return{windows:e,windowSize:n}}function Yu(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 Xu(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 io=new WeakMap,mi=new WeakMap;function ao(r){return mi.get(r)||1}function Wr(r,t){return{constTimeNegate:oo,hasPrecomputes(e){return ao(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>hi;)n&Zr&&(o=o.add(s)),s=s.double(),n>>=Zr;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=so(n,t),i=[],c=e,a=c;for(let f=0;f<o;f++){a=c,i.push(a);for(let u=1;u<s;u++)a=a.add(c),i.push(a);c=a.double()}return i},wNAF(e,n,o){let{windows:s,windowSize:i}=so(e,t),c=r.ZERO,a=r.BASE,f=BigInt(2**e-1),u=2**e,l=BigInt(e);for(let d=0;d<s;d++){let y=d*i,m=Number(o&f);o>>=l,m>i&&(m-=u,o+=Zr);let b=y,h=y+Math.abs(m)-1,E=d%2!==0,S=m<0;m===0?a=a.add(oo(E,n[b])):c=c.add(oo(S,n[h]))}return{p:c,f:a}},wNAFUnsafe(e,n,o,s=r.ZERO){let{windows:i,windowSize:c}=so(e,t),a=BigInt(2**e-1),f=2**e,u=BigInt(e);for(let l=0;l<i;l++){let d=l*c;if(o===hi)break;let y=Number(o&a);if(o>>=u,y>c&&(y-=f,o+=Zr),y===0)continue;let m=n[d+Math.abs(y)-1];y<0&&(m=m.negate()),s=s.add(m)}return s},getPrecomputes(e,n,o){let s=io.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&io.set(n,o(s))),s},wNAFCached(e,n,o){let s=ao(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=ao(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){pi(n,t),mi.set(e,n),io.delete(e)}}}function Yr(r,t,e,n){if(Yu(e,r),Xu(n,t),e.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=r.ZERO,s=Qn(BigInt(e.length)),i=s>12?s-3:s>4?s-2:s?2:1,c=(1<<i)-1,a=new Array(c+1).fill(o),f=Math.floor((t.BITS-1)/i)*i,u=o;for(let l=f;l>=0;l-=i){a.fill(o);for(let y=0;y<n.length;y++){let m=n[y],b=Number(m>>BigInt(l)&BigInt(c));a[b]=a[b].add(e[y])}let d=o;for(let y=a.length-1,m=o;y>0;y--)m=m.add(a[y]),d=d.add(m);if(u=u.add(d),l!==0)for(let y=0;y<i;y++)u=u.double()}return u}function dr(r){return eo(r.Fp),zt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...ro(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Ot=BigInt(0),At=BigInt(1),Xr=BigInt(2),ju=BigInt(8),Qu={zip215:!0};function Ju(r){let t=dr(r);return zt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function gi(r){let t=Ju(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:c,h:a}=t,f=Xr<<BigInt(c*8)-At,u=e.create,l=he(t.n,t.nBitLength),d=t.uvRatio||((x,p)=>{try{return{isValid:!0,value:e.sqrt(x*e.inv(p))}}catch{return{isValid:!1,value:Ot}}}),y=t.adjustScalarBytes||(x=>x),m=t.domain||((x,p,w)=>{if(Dt("phflag",w),p.length||w)throw new Error("Contexts/pre-hash are not supported");return x});function b(x,p){It("coordinate "+x,p,Ot,f)}function h(x){if(!(x instanceof g))throw new Error("ExtendedPoint expected")}let E=Be((x,p)=>{let{ex:w,ey:I,ez:_}=x,N=x.is0();p==null&&(p=N?ju:e.inv(_));let O=u(w*p),M=u(I*p),U=u(_*p);if(N)return{x:Ot,y:At};if(U!==At)throw new Error("invZ was invalid");return{x:O,y:M}}),S=Be(x=>{let{a:p,d:w}=t;if(x.is0())throw new Error("bad point: ZERO");let{ex:I,ey:_,ez:N,et:O}=x,M=u(I*I),U=u(_*_),Z=u(N*N),X=u(Z*Z),ct=u(M*p),ut=u(Z*u(ct+U)),lt=u(X+u(w*u(M*U)));if(ut!==lt)throw new Error("bad point: equation left != right (1)");let pt=u(I*_),St=u(N*O);if(pt!==St)throw new Error("bad point: equation left != right (2)");return!0});class g{constructor(p,w,I,_){this.ex=p,this.ey=w,this.ez=I,this.et=_,b("x",p),b("y",w),b("z",I),b("t",_),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(p){if(p instanceof g)throw new Error("extended point not allowed");let{x:w,y:I}=p||{};return b("x",w),b("y",I),new g(w,I,At,u(w*I))}static normalizeZ(p){let w=e.invertBatch(p.map(I=>I.ez));return p.map((I,_)=>I.toAffine(w[_])).map(g.fromAffine)}static msm(p,w){return Yr(g,l,p,w)}_setWindowSize(p){C.setWindowSize(this,p)}assertValidity(){S(this)}equals(p){h(p);let{ex:w,ey:I,ez:_}=this,{ex:N,ey:O,ez:M}=p,U=u(w*M),Z=u(N*_),X=u(I*M),ct=u(O*_);return U===Z&&X===ct}is0(){return this.equals(g.ZERO)}negate(){return new g(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:p}=t,{ex:w,ey:I,ez:_}=this,N=u(w*w),O=u(I*I),M=u(Xr*u(_*_)),U=u(p*N),Z=w+I,X=u(u(Z*Z)-N-O),ct=U+O,ut=ct-M,lt=U-O,pt=u(X*ut),St=u(ct*lt),wt=u(X*lt),Ht=u(ut*ct);return new g(pt,St,Ht,wt)}add(p){h(p);let{a:w,d:I}=t,{ex:_,ey:N,ez:O,et:M}=this,{ex:U,ey:Z,ez:X,et:ct}=p;if(w===BigInt(-1)){let Ps=u((N-_)*(Z+U)),Cs=u((N+_)*(Z-U)),Un=u(Cs-Ps);if(Un===Ot)return this.double();let Rs=u(O*Xr*ct),_s=u(M*Xr*X),Ns=_s+Rs,Us=Cs+Ps,Ds=_s-Rs,ac=u(Ns*Un),cc=u(Us*Ds),uc=u(Ns*Ds),fc=u(Un*Us);return new g(ac,cc,fc,uc)}let ut=u(_*U),lt=u(N*Z),pt=u(M*I*ct),St=u(O*X),wt=u((_+N)*(U+Z)-ut-lt),Ht=St-pt,Wt=St+pt,or=u(lt-w*ut),nc=u(wt*Ht),oc=u(Wt*or),sc=u(wt*or),ic=u(Ht*Wt);return new g(nc,oc,ic,sc)}subtract(p){return this.add(p.negate())}wNAF(p){return C.wNAFCached(this,p,g.normalizeZ)}multiply(p){let w=p;It("scalar",w,At,n);let{p:I,f:_}=this.wNAF(w);return g.normalizeZ([I,_])[0]}multiplyUnsafe(p,w=g.ZERO){let I=p;return It("scalar",I,Ot,n),I===Ot?R:this.is0()||I===At?this:C.wNAFCachedUnsafe(this,I,g.normalizeZ,w)}isSmallOrder(){return this.multiplyUnsafe(a).is0()}isTorsionFree(){return C.unsafeLadder(this,n).is0()}toAffine(p){return E(this,p)}clearCofactor(){let{h:p}=t;return p===At?this:this.multiplyUnsafe(p)}static fromHex(p,w=!1){let{d:I,a:_}=t,N=e.BYTES;p=et("pointHex",p,N),Dt("zip215",w);let O=p.slice(),M=p[N-1];O[N-1]=M&-129;let U=le(O),Z=w?f:e.ORDER;It("pointHex.y",U,Ot,Z);let X=u(U*U),ct=u(X-At),ut=u(I*X-_),{isValid:lt,value:pt}=d(ct,ut);if(!lt)throw new Error("Point.fromHex: invalid y coordinate");let St=(pt&At)===At,wt=(M&128)!==0;if(!w&&pt===Ot&&wt)throw new Error("Point.fromHex: x=0 and x_0=1");return wt!==St&&(pt=u(-pt)),g.fromAffine({x:pt,y:U})}static fromPrivateKey(p){return T(p).point}toRawBytes(){let{x:p,y:w}=this.toAffine(),I=Ae(w,e.BYTES);return I[I.length-1]|=p&At?128:0,I}toHex(){return Jt(this.toRawBytes())}}g.BASE=new g(t.Gx,t.Gy,At,u(t.Gx*t.Gy)),g.ZERO=new g(Ot,At,At,Ot);let{BASE:A,ZERO:R}=g,C=Wr(g,c*8);function B(x){return W(x,n)}function P(x){return B(le(x))}function T(x){let p=e.BYTES;x=et("private key",x,p);let w=et("hashed private key",s(x),2*p),I=y(w.slice(0,p)),_=w.slice(p,2*p),N=P(I),O=A.multiply(N),M=O.toRawBytes();return{head:I,prefix:_,scalar:N,point:O,pointBytes:M}}function Q(x){return T(x).pointBytes}function q(x=new Uint8Array,...p){let w=ee(...p);return P(s(m(w,et("context",x),!!o)))}function k(x,p,w={}){x=et("message",x),o&&(x=o(x));let{prefix:I,scalar:_,pointBytes:N}=T(p),O=q(w.context,I,x),M=A.multiply(O).toRawBytes(),U=q(w.context,M,N,x),Z=B(O+U*_);It("signature.s",Z,Ot,n);let X=ee(M,Ae(Z,e.BYTES));return et("result",X,e.BYTES*2)}let st=Qu;function v(x,p,w,I=st){let{context:_,zip215:N}=I,O=e.BYTES;x=et("signature",x,2*O),p=et("message",p),w=et("publicKey",w,O),N!==void 0&&Dt("zip215",N),o&&(p=o(p));let M=le(x.slice(O,2*O)),U,Z,X;try{U=g.fromHex(w,N),Z=g.fromHex(x.slice(0,O),N),X=A.multiplyUnsafe(M)}catch{return!1}if(!N&&U.isSmallOrder())return!1;let ct=q(_,Z.toRawBytes(),U.toRawBytes(),p);return Z.add(U.multiplyUnsafe(ct)).subtract(X).clearCofactor().equals(g.ZERO)}return A._setWindowSize(8),{CURVE:t,getPublicKey:Q,sign:k,verify:v,ExtendedPoint:g,utils:{getExtendedPublicKey:T,randomPrivateKey:()=>i(e.BYTES),precompute(x=8,p=g.BASE){return p._setWindowSize(x),p.multiply(BigInt(3)),p}}}}var co=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),yi=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),bh=BigInt(0),tf=BigInt(1),bi=BigInt(2),xh=BigInt(3),ef=BigInt(5),rf=BigInt(8);function nf(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=co,c=r*r%s*r%s,a=tt(c,bi,s)*c%s,f=tt(a,tf,s)*r%s,u=tt(f,ef,s)*f%s,l=tt(u,t,s)*u%s,d=tt(l,e,s)*l%s,y=tt(d,n,s)*d%s,m=tt(y,o,s)*y%s,b=tt(m,o,s)*y%s,h=tt(b,t,s)*u%s;return{pow_p_5_8:tt(h,bi,s)*r%s,b2:c}}function of(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function sf(r,t){let e=co,n=W(t*t*t,e),o=W(n*n*t,e),s=nf(r*o).pow_p_5_8,i=W(r*n*s,e),c=W(t*i*i,e),a=i,f=W(i*yi,e),u=c===r,l=c===W(-r,e),d=c===W(-r*yi,e);return u&&(i=a),(l||d)&&(i=f),fi(i,e)&&(i=W(-i,e)),{isValid:u||l,value:i}}var af=he(co,void 0,!0),cf={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:af,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:rf,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:si,randomBytes:Vr,adjustScalarBytes:of,uvRatio:sf},xi=gi(cf);var jr=32;function wi(r,t,e){return xi.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var Qr=class{type="Ed25519";raw;constructor(t){this.raw=uo(t,jr)}toMultihash(){return jt.digest(pe(this))}toCID(){return dt.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:mt(this.raw,t.raw)}verify(t,e){return wi(this.raw,e,t)}};function fo(r){return r=uo(r,jr),new Qr(r)}function uo(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new vt(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}function ht(r=0){return new Uint8Array(r)}function Bt(r=0){return new Uint8Array(r)}var ff=Math.pow(2,7),lf=Math.pow(2,14),df=Math.pow(2,21),lo=Math.pow(2,28),ho=Math.pow(2,35),po=Math.pow(2,42),mo=Math.pow(2,49),$=128,gt=127;function yt(r){if(r<ff)return 1;if(r<lf)return 2;if(r<df)return 3;if(r<lo)return 4;if(r<ho)return 5;if(r<po)return 6;if(r<mo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function go(r,t,e=0){switch(yt(r)){case 8:t[e++]=r&255|$,r/=128;case 7:t[e++]=r&255|$,r/=128;case 6:t[e++]=r&255|$,r/=128;case 5:t[e++]=r&255|$,r/=128;case 4:t[e++]=r&255|$,r>>>=7;case 3:t[e++]=r&255|$,r>>>=7;case 2:t[e++]=r&255|$,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function hf(r,t,e=0){switch(yt(r)){case 8:t.set(e++,r&255|$),r/=128;case 7:t.set(e++,r&255|$),r/=128;case 6:t.set(e++,r&255|$),r/=128;case 5:t.set(e++,r&255|$),r/=128;case 4:t.set(e++,r&255|$),r>>>=7;case 3:t.set(e++,r&255|$),r>>>=7;case 2:t.set(e++,r&255|$),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function yo(r,t){let e=r[t],n=0;if(n+=e>,e<$||(e=r[t+1],n+=(e>)<<7,e<$)||(e=r[t+2],n+=(e>)<<14,e<$)||(e=r[t+3],n+=(e>)<<21,e<$)||(e=r[t+4],n+=(e>)*lo,e<$)||(e=r[t+5],n+=(e>)*ho,e<$)||(e=r[t+6],n+=(e>)*po,e<$)||(e=r[t+7],n+=(e>)*mo,e<$))return n;throw new RangeError("Could not decode varint")}function pf(r,t){let e=r.get(t),n=0;if(n+=e>,e<$||(e=r.get(t+1),n+=(e>)<<7,e<$)||(e=r.get(t+2),n+=(e>)<<14,e<$)||(e=r.get(t+3),n+=(e>)<<21,e<$)||(e=r.get(t+4),n+=(e>)*lo,e<$)||(e=r.get(t+5),n+=(e>)*ho,e<$)||(e=r.get(t+6),n+=(e>)*po,e<$)||(e=r.get(t+7),n+=(e>)*mo,e<$))return n;throw new RangeError("Could not decode varint")}function Ct(r,t,e=0){return t==null&&(t=Bt(yt(r))),t instanceof Uint8Array?go(r,t,e):hf(r,t,e)}function re(r,t=0){return r instanceof Uint8Array?yo(r,t):pf(r,t)}var bo=new Float32Array([-0]),me=new Uint8Array(bo.buffer);function vi(r,t,e){bo[0]=r,t[e]=me[0],t[e+1]=me[1],t[e+2]=me[2],t[e+3]=me[3]}function Si(r,t){return me[0]=r[t],me[1]=r[t+1],me[2]=r[t+2],me[3]=r[t+3],bo[0]}var xo=new Float64Array([-0]),bt=new Uint8Array(xo.buffer);function Ii(r,t,e){xo[0]=r,t[e]=bt[0],t[e+1]=bt[1],t[e+2]=bt[2],t[e+3]=bt[3],t[e+4]=bt[4],t[e+5]=bt[5],t[e+6]=bt[6],t[e+7]=bt[7]}function Ai(r,t){return bt[0]=r[t],bt[1]=r[t+1],bt[2]=r[t+2],bt[3]=r[t+3],bt[4]=r[t+4],bt[5]=r[t+5],bt[6]=r[t+6],bt[7]=r[t+7],xo[0]}var mf=BigInt(Number.MAX_SAFE_INTEGER),gf=BigInt(Number.MIN_SAFE_INTEGER),Lt=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 Le;if(t<mf&&t>gf)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>Bi&&(o=0n,++n>Bi&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return Le;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):Le}},Le=new Lt(0,0);Le.toBigInt=function(){return 0n};Le.zzEncode=Le.zzDecode=function(){return this};Le.length=function(){return 1};var Bi=4294967296n;function Ti(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 Li(r,t,e){if(e-t<1)return"";let o,s=[],i=0,c;for(;t<e;)c=r[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|r[t++]&63:c>239&&c<365?(c=((c&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function wo(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function kt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function tn(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Eo=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,kt(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 kt(this,4);return tn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw kt(this,4);return tn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw kt(this,4);let t=Si(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw kt(this,4);let t=Ai(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 kt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Li(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw kt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw kt(this);while((this.buf[this.pos++]&128)!==0);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 Lt(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 kt(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 kt(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 kt(this,8);let t=tn(this.buf,this.pos+=4),e=tn(this.buf,this.pos+=4);return new Lt(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=yo(this.buf,this.pos);return this.pos+=yt(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 vo(r){return new Eo(r instanceof Uint8Array?r:r.subarray())}function Mt(r,t,e){let n=vo(r);return t.decode(n,void 0,e)}var So={};Et(So,{base10:()=>yf});var yf=ie({prefix:"9",name:"base10",alphabet:"0123456789"});var Io={};Et(Io,{base16:()=>bf,base16upper:()=>xf});var bf=nt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),xf=nt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Ao={};Et(Ao,{base2:()=>wf});var wf=nt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Bo={};Et(Bo,{base256emoji:()=>Af});var Ci=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Ef=Ci.reduce((r,t,e)=>(r[e]=t,r),[]),vf=Ci.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Sf(r){return r.reduce((t,e)=>(t+=Ef[e],t),"")}function If(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=vf[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Af=ke({prefix:"\u{1F680}",name:"base256emoji",encode:Sf,decode:If});var Lo={};Et(Lo,{base64:()=>Bf,base64pad:()=>Tf,base64url:()=>To,base64urlpad:()=>Lf});var Bf=nt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Tf=nt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),To=nt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Lf=nt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Po={};Et(Po,{base8:()=>Pf});var Pf=nt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Co={};Et(Co,{identity:()=>Cf});var Cf=ke({prefix:"\0",name:"identity",encode:r=>Ks(r),decode:r=>Ms(r)});var ep=new TextEncoder,rp=new TextDecoder;var No={};Et(No,{sha256:()=>hr,sha512:()=>Nf});function _o({name:r,code:t,encode:e}){return new Ro(r,t,e)}var Ro=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?Nt(this.code,e):e.then(n=>Nt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function _i(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var hr=_o({name:"sha2-256",code:18,encode:_i("SHA-256")}),Nf=_o({name:"sha2-512",code:19,encode:_i("SHA-512")});var pr={...Co,...Ao,...Po,...So,...Io,...Vn,...qn,...Fn,...Lo,...Bo},pp={...No,...Gn};function Ui(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Ni=Ui("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Uo=Ui("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=Bt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Uf={utf8:Ni,"utf-8":Ni,hex:pr.base16,latin1:Uo,ascii:Uo,binary:Uo,...pr},en=Uf;function H(r,t="utf8"){let e=en[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function Do(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return Bt(i);o+i>t&&(n=Bt(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var Pe=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Oo(){}var Mo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Df=Do();function Of(r){return globalThis.Buffer!=null?Bt(r):Df(r)}var gr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Pe(Oo,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Pe(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Ko((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,Lt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Lt.fromBigInt(t);return this._push(rn,e.length(),e)}uint64Number(t){return this._push(go,yt(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=Lt.fromBigInt(t).zzEncode();return this._push(rn,e.length(),e)}sint64Number(t){let e=Lt.fromNumber(t).zzEncode();return this._push(rn,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ko,1,t?1:0)}fixed32(t){return this._push(mr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Lt.fromBigInt(t);return this._push(mr,4,e.lo)._push(mr,4,e.hi)}fixed64Number(t){let e=Lt.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(vi,4,t)}double(t){return this._push(Ii,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(ko,1,0):this.uint32(e)._push(Mf,e,t)}string(t){let e=Ti(t);return e!==0?this.uint32(e)._push(wo,e,t):this._push(ko,1,0)}fork(){return this.states=new Mo(this),this.head=this.tail=new Pe(Oo,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 Pe(Oo,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=Of(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function ko(r,t,e){t[e]=r&255}function kf(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Ko=class extends Pe{next;constructor(t,e){super(kf,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 Mf(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(gr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Kf,t,r),this},gr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Ff,t,r),this});function Kf(r,t,e){t.set(r,e)}function Ff(r,t,e){r.length<40?wo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(H(r),e)}function Fo(){return new gr}function Kt(r,t){let e=Fo();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var $e;(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"})($e||($e={}));function nn(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Vo(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let c=t(s);i.int32(c)},n=function(s){let i=s.int32();return t(i)};return nn("enum",$e.VARINT,e,n)}function Ft(r,t){return nn("message",$e.LENGTH_DELIMITED,r,t)}var Ce=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var at;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1"})(at||(at={}));var qo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1"})(qo||(qo={}));(function(r){r.codec=()=>Vo(qo)})(at||(at={}));var Gt;(function(r){let t;r.codec=()=>(t==null&&(t=Ft((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),at.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let c=e.uint32();switch(c>>>3){case 1:{s.Type=at.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Kt(e,r.codec()),r.decode=(e,n)=>Mt(e,r.codec(),n)})(Gt||(Gt={}));var Ho;(function(r){let t;r.codec=()=>(t==null&&(t=Ft((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),at.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let c=e.uint32();switch(c>>>3){case 1:{s.Type=at.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Kt(e,r.codec()),r.decode=(e,n)=>Mt(e,r.codec(),n)})(Ho||(Ho={}));var xr={};Et(xr,{MAX_RSA_KEY_SIZE:()=>Wo,generateRSAKeyPair:()=>Yi,jwkToJWKKeyPair:()=>Xi,jwkToPkcs1:()=>Qf,jwkToPkix:()=>Xo,jwkToRSAPrivateKey:()=>Wi,pkcs1ToJwk:()=>Gi,pkcs1ToRSAPrivateKey:()=>Zi,pkixToJwk:()=>$i,pkixToRSAPublicKey:()=>jo});var Vf=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]),ge=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ye=new Uint32Array(64),zo=class extends ze{constructor(){super(64,32,8,!1),this.A=ge[0]|0,this.B=ge[1]|0,this.C=ge[2]|0,this.D=ge[3]|0,this.E=ge[4]|0,this.F=ge[5]|0,this.G=ge[6]|0,this.H=ge[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,e,n,o,s,i,c,a]}set(t,e,n,o,s,i,c,a){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=a|0}process(t,e){for(let l=0;l<16;l++,e+=4)ye[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let d=ye[l-15],y=ye[l-2],m=Ut(d,7)^Ut(d,18)^d>>>3,b=Ut(y,17)^Ut(y,19)^y>>>10;ye[l]=b+ye[l-7]+m+ye[l-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:f,H:u}=this;for(let l=0;l<64;l++){let d=Ut(c,6)^Ut(c,11)^Ut(c,25),y=u+d+ri(c,a,f)+Vf[l]+ye[l]|0,b=(Ut(n,2)^Ut(n,13)^Ut(n,22))+ni(n,o,s)|0;u=f,f=a,a=c,c=i+y|0,i=s,s=o,o=n,n=y+b|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,o,s,i,c,a,f,u)}roundClean(){ye.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Ze=Fr(()=>new zo);function K(r,t="utf8"){let e=en[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}function Pt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=Bt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var ki=Symbol.for("@achingbrain/uint8arraylist");function Oi(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function on(r){return!!r?.[ki]}var ot=class r{bufs;length;[ki]=!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(on(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(on(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=Oi(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Oi(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(on(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return Pt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Pt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],c=o,a=c+i.byteLength;if(o=a,t>=a)continue;let f=t>=c&&t<a,u=e>c&&e<=a;if(f&&u){if(t===c&&e===a){n.push(i);break}let l=t-c;n.push(i.subarray(l,l+(e-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(u){if(e===a){n.push(i);break}n.push(i.subarray(0,e-c));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!on(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let c=i,a=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let l=e;l<=a;l+=u){u=0;for(let d=f;d>=0;d--){let y=this.get(l+d);if(n[d]!==y){u=Math.max(1,d-c[y]);break}}if(u===0)return l}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=Bt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=ht(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=ht(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=ht(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=Bt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=ht(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=ht(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=ht(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=ht(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=ht(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!mt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var qf=parseInt("11111",2),$o=parseInt("10000000",2),Hf=parseInt("01111111",2),Mi={2:zf,3:Zf,5:$f,6:Gf,16:Go,22:Go,48:Go};function yr(r,t={offset:0}){let e=r[t.offset]&qf;if(t.offset++,Mi[e]!=null)return Mi[e](r,t);throw new Error("No decoder for tag "+e)}function sn(r,t){let e=0;if((r[t.offset]&$o)===$o){let n=r[t.offset]&Hf,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function Go(r,t){sn(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=yr(r,t);if(n===null)break;e.push(n)}return e}function zf(r,t){let e=sn(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function Gf(r,t){let e=sn(r,t);return t.offset+=e,["oid-unimplemented"]}function $f(r,t){return t.offset++,null}function Zf(r,t){let e=sn(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return yr(o,{offset:0})}function Wf(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new ot;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Zo(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Wf(r.byteLength);return new ot(Uint8Array.from([t.byteLength|$o]),t)}function Rt(r){let t=new ot,e=parseInt("10000000",2);return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new ot(Uint8Array.from([2]),Zo(t),t)}function Ki(r){let t=Uint8Array.from([0]),e=new ot(t,r);return new ot(Uint8Array.from([3]),Zo(e),e)}function an(r){let t=new ot;for(let e of r)t.append(e);return new ot(Uint8Array.from([48]),Zo(t),t)}var br=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},cn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Fi={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new cn("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 be=Fi;async function Vi(r){let t=await be.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 Yf(t);return{privateKey:e[0],publicKey:e[1]}}async function qi(r,t){let e=await be.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await be.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function Hi(r,t,e){let n=await be.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return be.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function Yf(r){if(r.privateKey==null||r.publicKey==null)throw new vt("Private and public key are required");return Promise.all([be.get().subtle.exportKey("jwk",r.privateKey),be.get().subtle.exportKey("jwk",r.publicKey)])}function zi(r){if(r.kty!=="RSA")throw new vt("invalid key type");if(r.n==null)throw new vt("invalid key modulus");return H(r.n,"base64url").length*8}var We=class{type="RSA";_key;_raw;_multihash;constructor(t,e){this._key=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=xr.jwkToPkix(this._key)),this._raw}toMultihash(){return this._multihash}toCID(){return dt.createV1(114,this._multihash)}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:mt(this.raw,t.raw)}verify(t,e){return Hi(this._key,e,t)}},wr=class{type="RSA";_key;_raw;publicKey;constructor(t,e){this._key=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=xr.jwkToPkcs1(this._key)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:mt(this.raw,t.raw)}sign(t){return qi(this._key,t)}};var Wo=8192,Yo=18,Xf=1062,jf=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Gi(r){let t=yr(r);return{n:K(t[1],"base64url"),e:K(t[2],"base64url"),d:K(t[3],"base64url"),p:K(t[4],"base64url"),q:K(t[5],"base64url"),dp:K(t[6],"base64url"),dq:K(t[7],"base64url"),qi:K(t[8],"base64url"),kty:"RSA"}}function Qf(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 vt("JWK was missing components");return an([Rt(Uint8Array.from([0])),Rt(H(r.n,"base64url")),Rt(H(r.e,"base64url")),Rt(H(r.d,"base64url")),Rt(H(r.p,"base64url")),Rt(H(r.q,"base64url")),Rt(H(r.dp,"base64url")),Rt(H(r.dq,"base64url")),Rt(H(r.qi,"base64url"))]).subarray()}function $i(r){let t=yr(r,{offset:0});return{kty:"RSA",n:K(t[1][0],"base64url"),e:K(t[1][1],"base64url")}}function Xo(r){if(r.n==null||r.e==null)throw new vt("JWK was missing components");return an([jf,Ki(an([Rt(H(r.n,"base64url")),Rt(H(r.e,"base64url"))]))]).subarray()}function Zi(r){let t=Gi(r);return Wi(t)}function jo(r,t){if(r.byteLength>=Xf)throw new Oe("Key size is too large");let e=$i(r);if(t==null){let n=Ze(Gt.encode({Type:at.RSA,Data:r}));t=Nt(Yo,n)}return new We(e,t)}function Wi(r){if(zi(r)>Wo)throw new vt("Key size is too large");let t=Xi(r),e=Ze(Gt.encode({Type:at.RSA,Data:Xo(t.publicKey)})),n=Nt(Yo,e);return new wr(t.privateKey,new We(t.publicKey,n))}async function Yi(r){if(r>Wo)throw new vt("Key size is too large");let t=await Vi(r),e=Ze(Gt.encode({Type:at.RSA,Data:Xo(t.publicKey)})),n=Nt(Yo,e);return new wr(t.privateKey,new We(t.publicKey,n))}function Xi(r){if(r==null)throw new vt("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}var un=class extends He{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Js(t);let n=ur(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 o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),s.fill(0)}update(t){return qe(this),this.iHash.update(t),this}digestInto(t){qe(this),Ve(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:o,destroyed:s,blockLen:i,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Qo=(r,t,e)=>new un(r,t).update(e).digest();Qo.create=(r,t)=>new un(r,t);function ji(r){r.lowS!==void 0&&Dt("lowS",r.lowS),r.prehash!==void 0&&Dt("prehash",r.prehash)}function Jf(r){let t=dr(r);zt(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:o}=t;if(e){if(!n.eql(o,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:tl,hexToBytes:el}=Gr,Jo=class extends Error{constructor(t=""){super(t)}},ne={Err:Jo,_tlv:{encode:(r,t)=>{let{Err:e}=ne;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,o=Se(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?Se(o.length/2|128):"";return Se(r)+s+o+t},decode(r,t){let{Err:e}=ne,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 o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let a=o&127;if(!a)throw new e("tlv.decode(long): indefinite length not supported");if(a>4)throw new e("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+a);if(f.length!==a)throw new e("tlv.decode: length bytes not complete");if(f[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let u of f)i=i<<8|u;if(n+=a,i<128)throw new e("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new e("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=ne;if(r<oe)throw new t("integer: negative integers are not allowed");let e=Se(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}=ne;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 tl(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=ne,o=typeof r=="string"?el(r):r;Ge(o);let{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,s),{v:f,l:u}=n.decode(2,a);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(c),s:e.decode(f)}},hexFromSig(r){let{_tlv:t,_int:e}=ne,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},oe=BigInt(0),ft=BigInt(1),O0=BigInt(2),Qi=BigInt(3),k0=BigInt(4);function rl(r){let t=Jf(r),{Fp:e}=t,n=he(t.n,t.nBitLength),o=t.toBytes||((b,h,E)=>{let S=h.toAffine();return ee(Uint8Array.from([4]),e.toBytes(S.x),e.toBytes(S.y))}),s=t.fromBytes||(b=>{let h=b.subarray(1),E=e.fromBytes(h.subarray(0,e.BYTES)),S=e.fromBytes(h.subarray(e.BYTES,2*e.BYTES));return{x:E,y:S}});function i(b){let{a:h,b:E}=t,S=e.sqr(b),g=e.mul(S,b);return e.add(e.add(g,e.mul(b,h)),E)}if(!e.eql(e.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function c(b){return fr(b,ft,t.n)}function a(b){let{allowedPrivateKeyLengths:h,nByteLength:E,wrapPrivateKey:S,n:g}=t;if(h&&typeof b!="bigint"){if(fe(b)&&(b=Jt(b)),typeof b!="string"||!h.includes(b.length))throw new Error("invalid private key");b=b.padStart(E*2,"0")}let A;try{A=typeof b=="bigint"?b:te(et("private key",b,E))}catch{throw new Error("invalid private key, expected hex or "+E+" bytes, got "+typeof b)}return S&&(A=W(A,g)),It("private key",A,ft,g),A}function f(b){if(!(b instanceof d))throw new Error("ProjectivePoint expected")}let u=Be((b,h)=>{let{px:E,py:S,pz:g}=b;if(e.eql(g,e.ONE))return{x:E,y:S};let A=b.is0();h==null&&(h=A?e.ONE:e.inv(g));let R=e.mul(E,h),C=e.mul(S,h),B=e.mul(g,h);if(A)return{x:e.ZERO,y:e.ZERO};if(!e.eql(B,e.ONE))throw new Error("invZ was invalid");return{x:R,y:C}}),l=Be(b=>{if(b.is0()){if(t.allowInfinityPoint&&!e.is0(b.py))return;throw new Error("bad point: ZERO")}let{x:h,y:E}=b.toAffine();if(!e.isValid(h)||!e.isValid(E))throw new Error("bad point: x or y not FE");let S=e.sqr(E),g=i(h);if(!e.eql(S,g))throw new Error("bad point: equation left != right");if(!b.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class d{constructor(h,E,S){if(this.px=h,this.py=E,this.pz=S,h==null||!e.isValid(h))throw new Error("x required");if(E==null||!e.isValid(E))throw new Error("y required");if(S==null||!e.isValid(S))throw new Error("z required");Object.freeze(this)}static fromAffine(h){let{x:E,y:S}=h||{};if(!h||!e.isValid(E)||!e.isValid(S))throw new Error("invalid affine point");if(h instanceof d)throw new Error("projective point not allowed");let g=A=>e.eql(A,e.ZERO);return g(E)&&g(S)?d.ZERO:new d(E,S,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let E=e.invertBatch(h.map(S=>S.pz));return h.map((S,g)=>S.toAffine(E[g])).map(d.fromAffine)}static fromHex(h){let E=d.fromAffine(s(et("pointHex",h)));return E.assertValidity(),E}static fromPrivateKey(h){return d.BASE.multiply(a(h))}static msm(h,E){return Yr(d,n,h,E)}_setWindowSize(h){m.setWindowSize(this,h)}assertValidity(){l(this)}hasEvenY(){let{y:h}=this.toAffine();if(e.isOdd)return!e.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){f(h);let{px:E,py:S,pz:g}=this,{px:A,py:R,pz:C}=h,B=e.eql(e.mul(E,C),e.mul(A,g)),P=e.eql(e.mul(S,C),e.mul(R,g));return B&&P}negate(){return new d(this.px,e.neg(this.py),this.pz)}double(){let{a:h,b:E}=t,S=e.mul(E,Qi),{px:g,py:A,pz:R}=this,C=e.ZERO,B=e.ZERO,P=e.ZERO,T=e.mul(g,g),Q=e.mul(A,A),q=e.mul(R,R),k=e.mul(g,A);return k=e.add(k,k),P=e.mul(g,R),P=e.add(P,P),C=e.mul(h,P),B=e.mul(S,q),B=e.add(C,B),C=e.sub(Q,B),B=e.add(Q,B),B=e.mul(C,B),C=e.mul(k,C),P=e.mul(S,P),q=e.mul(h,q),k=e.sub(T,q),k=e.mul(h,k),k=e.add(k,P),P=e.add(T,T),T=e.add(P,T),T=e.add(T,q),T=e.mul(T,k),B=e.add(B,T),q=e.mul(A,R),q=e.add(q,q),T=e.mul(q,k),C=e.sub(C,T),P=e.mul(q,Q),P=e.add(P,P),P=e.add(P,P),new d(C,B,P)}add(h){f(h);let{px:E,py:S,pz:g}=this,{px:A,py:R,pz:C}=h,B=e.ZERO,P=e.ZERO,T=e.ZERO,Q=t.a,q=e.mul(t.b,Qi),k=e.mul(E,A),st=e.mul(S,R),v=e.mul(g,C),L=e.add(E,S),x=e.add(A,R);L=e.mul(L,x),x=e.add(k,st),L=e.sub(L,x),x=e.add(E,g);let p=e.add(A,C);return x=e.mul(x,p),p=e.add(k,v),x=e.sub(x,p),p=e.add(S,g),B=e.add(R,C),p=e.mul(p,B),B=e.add(st,v),p=e.sub(p,B),T=e.mul(Q,x),B=e.mul(q,v),T=e.add(B,T),B=e.sub(st,T),T=e.add(st,T),P=e.mul(B,T),st=e.add(k,k),st=e.add(st,k),v=e.mul(Q,v),x=e.mul(q,x),st=e.add(st,v),v=e.sub(k,v),v=e.mul(Q,v),x=e.add(x,v),k=e.mul(st,x),P=e.add(P,k),k=e.mul(p,x),B=e.mul(L,B),B=e.sub(B,k),k=e.mul(L,st),T=e.mul(p,T),T=e.add(T,k),new d(B,P,T)}subtract(h){return this.add(h.negate())}is0(){return this.equals(d.ZERO)}wNAF(h){return m.wNAFCached(this,h,d.normalizeZ)}multiplyUnsafe(h){let{endo:E,n:S}=t;It("scalar",h,oe,S);let g=d.ZERO;if(h===oe)return g;if(this.is0()||h===ft)return this;if(!E||m.hasPrecomputes(this))return m.wNAFCachedUnsafe(this,h,d.normalizeZ);let{k1neg:A,k1:R,k2neg:C,k2:B}=E.splitScalar(h),P=g,T=g,Q=this;for(;R>oe||B>oe;)R&ft&&(P=P.add(Q)),B&ft&&(T=T.add(Q)),Q=Q.double(),R>>=ft,B>>=ft;return A&&(P=P.negate()),C&&(T=T.negate()),T=new d(e.mul(T.px,E.beta),T.py,T.pz),P.add(T)}multiply(h){let{endo:E,n:S}=t;It("scalar",h,ft,S);let g,A;if(E){let{k1neg:R,k1:C,k2neg:B,k2:P}=E.splitScalar(h),{p:T,f:Q}=this.wNAF(C),{p:q,f:k}=this.wNAF(P);T=m.constTimeNegate(R,T),q=m.constTimeNegate(B,q),q=new d(e.mul(q.px,E.beta),q.py,q.pz),g=T.add(q),A=Q.add(k)}else{let{p:R,f:C}=this.wNAF(h);g=R,A=C}return d.normalizeZ([g,A])[0]}multiplyAndAddUnsafe(h,E,S){let g=d.BASE,A=(C,B)=>B===oe||B===ft||!C.equals(g)?C.multiplyUnsafe(B):C.multiply(B),R=A(this,E).add(A(h,S));return R.is0()?void 0:R}toAffine(h){return u(this,h)}isTorsionFree(){let{h,isTorsionFree:E}=t;if(h===ft)return!0;if(E)return E(d,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:E}=t;return h===ft?this:E?E(d,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return Dt("isCompressed",h),this.assertValidity(),o(d,this,h)}toHex(h=!0){return Dt("isCompressed",h),Jt(this.toRawBytes(h))}}d.BASE=new d(t.Gx,t.Gy,e.ONE),d.ZERO=new d(e.ZERO,e.ONE,e.ZERO);let y=t.nBitLength,m=Wr(d,t.endo?Math.ceil(y/2):y);return{CURVE:t,ProjectivePoint:d,normPrivateKeyToScalar:a,weierstrassEquation:i,isWithinCurveOrder:c}}function nl(r){let t=dr(r);return zt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Ji(r){let t=nl(r),{Fp:e,n}=t,o=e.BYTES+1,s=2*e.BYTES+1;function i(v){return W(v,n)}function c(v){return $r(v,n)}let{ProjectivePoint:a,normPrivateKeyToScalar:f,weierstrassEquation:u,isWithinCurveOrder:l}=rl({...t,toBytes(v,L,x){let p=L.toAffine(),w=e.toBytes(p.x),I=ee;return Dt("isCompressed",x),x?I(Uint8Array.from([L.hasEvenY()?2:3]),w):I(Uint8Array.from([4]),w,e.toBytes(p.y))},fromBytes(v){let L=v.length,x=v[0],p=v.subarray(1);if(L===o&&(x===2||x===3)){let w=te(p);if(!fr(w,ft,e.ORDER))throw new Error("Point is not on curve");let I=u(w),_;try{_=e.sqrt(I)}catch(M){let U=M instanceof Error?": "+M.message:"";throw new Error("Point is not on curve"+U)}let N=(_&ft)===ft;return(x&1)===1!==N&&(_=e.neg(_)),{x:w,y:_}}else if(L===s&&x===4){let w=e.fromBytes(p.subarray(0,e.BYTES)),I=e.fromBytes(p.subarray(e.BYTES,2*e.BYTES));return{x:w,y:I}}else{let w=o,I=s;throw new Error("invalid Point, expected length of "+w+", or uncompressed "+I+", got "+L)}}}),d=v=>Jt(de(v,t.nByteLength));function y(v){let L=n>>ft;return v>L}function m(v){return y(v)?i(-v):v}let b=(v,L,x)=>te(v.slice(L,x));class h{constructor(L,x,p){this.r=L,this.s=x,this.recovery=p,this.assertValidity()}static fromCompact(L){let x=t.nByteLength;return L=et("compactSignature",L,x*2),new h(b(L,0,x),b(L,x,2*x))}static fromDER(L){let{r:x,s:p}=ne.toSig(et("DER",L));return new h(x,p)}assertValidity(){It("r",this.r,ft,n),It("s",this.s,ft,n)}addRecoveryBit(L){return new h(this.r,this.s,L)}recoverPublicKey(L){let{r:x,s:p,recovery:w}=this,I=C(et("msgHash",L));if(w==null||![0,1,2,3].includes(w))throw new Error("recovery id invalid");let _=w===2||w===3?x+t.n:x;if(_>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let N=(w&1)===0?"02":"03",O=a.fromHex(N+d(_)),M=c(_),U=i(-I*M),Z=i(p*M),X=a.BASE.multiplyAndAddUnsafe(O,U,Z);if(!X)throw new Error("point at infinify");return X.assertValidity(),X}hasHighS(){return y(this.s)}normalizeS(){return this.hasHighS()?new h(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return Ie(this.toDERHex())}toDERHex(){return ne.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Ie(this.toCompactHex())}toCompactHex(){return d(this.r)+d(this.s)}}let E={isValidPrivateKey(v){try{return f(v),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let v=no(t.n);return di(t.randomBytes(v),t.n)},precompute(v=8,L=a.BASE){return L._setWindowSize(v),L.multiply(BigInt(3)),L}};function S(v,L=!0){return a.fromPrivateKey(v).toRawBytes(L)}function g(v){let L=fe(v),x=typeof v=="string",p=(L||x)&&v.length;return L?p===o||p===s:x?p===2*o||p===2*s:v instanceof a}function A(v,L,x=!0){if(g(v))throw new Error("first arg must be private key");if(!g(L))throw new Error("second arg must be public key");return a.fromHex(L).multiply(f(v)).toRawBytes(x)}let R=t.bits2int||function(v){if(v.length>8192)throw new Error("input is too large");let L=te(v),x=v.length*8-t.nBitLength;return x>0?L>>BigInt(x):L},C=t.bits2int_modN||function(v){return i(R(v))},B=lr(t.nBitLength);function P(v){return It("num < 2^"+t.nBitLength,v,oe,B),de(v,t.nByteLength)}function T(v,L,x=Q){if(["recovered","canonical"].some(ut=>ut in x))throw new Error("sign() legacy options not supported");let{hash:p,randomBytes:w}=t,{lowS:I,prehash:_,extraEntropy:N}=x;I==null&&(I=!0),v=et("msgHash",v),ji(x),_&&(v=et("prehashed msgHash",p(v)));let O=C(v),M=f(L),U=[P(M),P(O)];if(N!=null&&N!==!1){let ut=N===!0?w(e.BYTES):N;U.push(et("extraEntropy",ut))}let Z=ee(...U),X=O;function ct(ut){let lt=R(ut);if(!l(lt))return;let pt=c(lt),St=a.BASE.multiply(lt).toAffine(),wt=i(St.x);if(wt===oe)return;let Ht=i(pt*i(X+wt*M));if(Ht===oe)return;let Wt=(St.x===wt?0:2)|Number(St.y&ft),or=Ht;return I&&y(Ht)&&(or=m(Ht),Wt^=1),new h(wt,or,Wt)}return{seed:Z,k2sig:ct}}let Q={lowS:t.lowS,prehash:!1},q={lowS:t.lowS,prehash:!1};function k(v,L,x=Q){let{seed:p,k2sig:w}=T(v,L,x),I=t;return Jn(I.hash.outputLen,I.nByteLength,I.hmac)(p,w)}a.BASE._setWindowSize(8);function st(v,L,x,p=q){let w=v;L=et("msgHash",L),x=et("publicKey",x);let{lowS:I,prehash:_,format:N}=p;if(ji(p),"strict"in p)throw new Error("options.strict was renamed to lowS");if(N!==void 0&&N!=="compact"&&N!=="der")throw new Error("format must be compact or der");let O=typeof w=="string"||fe(w),M=!O&&!N&&typeof w=="object"&&w!==null&&typeof w.r=="bigint"&&typeof w.s=="bigint";if(!O&&!M)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let U,Z;try{if(M&&(U=new h(w.r,w.s)),O){try{N!=="compact"&&(U=h.fromDER(w))}catch(Wt){if(!(Wt instanceof ne.Err))throw Wt}!U&&N!=="der"&&(U=h.fromCompact(w))}Z=a.fromHex(x)}catch{return!1}if(!U||I&&U.hasHighS())return!1;_&&(L=t.hash(L));let{r:X,s:ct}=U,ut=C(L),lt=c(ct),pt=i(ut*lt),St=i(X*lt),wt=a.BASE.multiplyAndAddUnsafe(Z,pt,St)?.toAffine();return wt?i(wt.x)===X:!1}return{CURVE:t,getPublicKey:S,getSharedSecret:A,sign:k,verify:st,ProjectivePoint:a,Signature:h,utils:E}}function ol(r){return{hash:r,hmac:(t,...e)=>Qo(r,t,$n(...e)),randomBytes:Vr}}function ta(r,t){let e=n=>Ji({...r,...ol(n)});return{...e(t),create:e}}var na=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),ea=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),sl=BigInt(1),ts=BigInt(2),ra=(r,t)=>(r+t/ts)/t;function il(r){let t=na,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),f=r*r*r%t,u=f*f*r%t,l=tt(u,e,t)*u%t,d=tt(l,e,t)*u%t,y=tt(d,ts,t)*f%t,m=tt(y,o,t)*y%t,b=tt(m,s,t)*m%t,h=tt(b,c,t)*b%t,E=tt(h,a,t)*h%t,S=tt(E,c,t)*b%t,g=tt(S,e,t)*u%t,A=tt(g,i,t)*m%t,R=tt(A,n,t)*f%t,C=tt(R,ts,t);if(!es.eql(es.sqr(C),r))throw new Error("Cannot find square root");return C}var es=he(na,void 0,void 0,{sqrt:il}),Re=ta({a:BigInt(0),b:BigInt(7),Fp:es,n:ea,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=ea,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-sl*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),c=ra(s*r,t),a=ra(-n*r,t),f=W(r-c*e-a*o,t),u=W(-c*n-a*s,t),l=f>i,d=u>i;if(l&&(f=t-f),d&&(u=t-u),f>i||u>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:l,k1:f,k2neg:d,k2:u}}}},Ze),$0=BigInt(0);var Z0=Re.ProjectivePoint;function oa(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function sa(r,t,e){let n=hr.digest(e instanceof Uint8Array?e:e.subarray());if(oa(n))return n.then(({digest:o})=>Re.verify(t,o,r)).catch(o=>{throw new br(String(o))});try{return Re.verify(t,n.digest,r)}catch(o){throw new br(String(o))}}var fn=class{type="secp256k1";raw;_key;constructor(t){this._key=aa(t),this.raw=ia(this._key)}toMultihash(){return jt.digest(pe(this))}toCID(){return dt.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:mt(this.raw,t.raw)}verify(t,e){return sa(this._key,e,t)}};function rs(r){return new fn(r)}function ia(r){return Re.ProjectivePoint.fromHex(r).toRawBytes(!0)}function aa(r){try{return Re.ProjectivePoint.fromHex(r),r}catch(t){throw new Oe(String(t))}}function Ye(r,t){let{Type:e,Data:n}=Gt.decode(r),o=n??new Uint8Array;switch(e){case at.RSA:return jo(o,t);case at.Ed25519:return fo(o);case at.secp256k1:return rs(o);default:throw new we}}function ca(r){let{Type:t,Data:e}=Gt.decode(r.digest),n=e??new Uint8Array;switch(t){case at.Ed25519:return fo(n);case at.secp256k1:return rs(n);default:throw new we}}function pe(r){return Gt.encode({Type:at[r.type],Data:r.raw})}var Er;(function(r){let t;r.codec=()=>(t==null&&(t=Ft((e,n,o={})=>{o.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)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={publicKey:ht(0),payloadType:ht(0),payload:ht(0),signature:ht(0)},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let c=e.uint32();switch(c>>>3){case 1:{s.publicKey=e.bytes();break}case 2:{s.payloadType=e.bytes();break}case 3:{s.payload=e.bytes();break}case 5:{s.signature=e.bytes();break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Kt(e,r.codec()),r.decode=(e,n)=>Mt(e,r.codec(),n)})(Er||(Er={}));var ln=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var $t=class r{static createFromProtobuf=async t=>{let e=Er.decode(t),n=Ye(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,o=t.codec,s=t.marshal(),i=ua(n,o,s),c=await e.sign(i.subarray());return new r({publicKey:e.publicKey,payloadType:o,payload:s,signature:c})};static openAndCertify=async(t,e)=>{let n=await r.createFromProtobuf(t);if(!await n.validate(e))throw new ln("Envelope signature is not valid for the given domain");return n};publicKey;payloadType;payload;signature;marshaled;constructor(t){let{publicKey:e,payloadType:n,payload:o,signature:s}=t;this.publicKey=e,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=Er.encode({publicKey:pe(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return mt(this.marshal(),t.marshal())}async validate(t){let e=ua(t,this.payloadType,this.payload);return this.publicKey.verify(e.subarray(),this.signature)}},ua=(r,t,e)=>{let n=H(r),o=Ct(n.byteLength),s=Ct(t.length),i=Ct(e.length);return new ot(o,n,s,t,i,e)};var fa=Symbol.for("nodejs.util.inspect.custom"),al=114,vr=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()})`}[Dn]=!0;toString(){return this.string==null&&(this.string=j.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return dt.createV1(al,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return mt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return mt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[fa](){return`PeerId(${this.toString()})`}},Sr=class extends vr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Ir=class extends vr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Ar=class extends vr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},cl=2336,Br=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=jt.digest(H(this.url))}[fa](){return`PeerId(${this.url})`}[Dn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return dt.createV1(cl,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=K(t)),t.toString()===this.toString())}};var ul=114,la=2336;function da(r){if(r.type==="Ed25519")return new Ir({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new Ar({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new Sr({multihash:r.toCID().multihash,publicKey:r});throw new we}function ns(r){if(ll(r))return new Sr({multihash:r});if(fl(r))try{let t=ca(r);if(t.type==="Ed25519")return new Ir({multihash:r,publicKey:t});if(t.type==="secp256k1")return new Ar({multihash:r,publicKey:t})}catch{let e=K(r.digest);return new Br(new URL(e))}throw new Dr("Supplied PeerID Multihash is invalid")}function dn(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==ul&&r.code!==la)throw new Ur("Supplied PeerID CID is invalid");if(r.code===la){let t=K(r.multihash.digest);return new Br(new URL(t))}return ns(r.multihash)}function fl(r){return r.code===jt.code}function ll(r){return r.code===hr.code}function ha(r,t){let e=(n,o)=>n.toString().localeCompare(o.toString());return r.length!==t.length?!1:(t.sort(e),r.sort(e).every((n,o)=>t[o].equals(n)))}var hn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,c=this.peekChar();if(c===void 0)return;let a=c==="0",f=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let d=Number.parseInt(l,t);if(!Number.isNaN(d))return d});if(u===void 0)break;if(s*=t,s+=u,s>f||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&a&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];e[o]=s>>8,e[o+1]=s&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[c]=t(s.subarray(0,i));return e.set(s.subarray(0,c),16-c),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var pa=45,dl=15,Xe=new hn;function pn(r){if(!(r.length>dl))return Xe.new(r).parseWith(()=>Xe.readIPv4Addr())}function mn(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>pa))return Xe.new(r).parseWith(()=>Xe.readIPv6Addr())}function _e(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>pa)return;let e=Xe.new(r).parseWith(()=>Xe.readIPAddr());if(e)return t&&e.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,e[0],e[1],e[2],e[3]]):e}function ma(r,t,e){let n=0;for(let o of r)if(!(n<t)){if(n>e)break;if(o!==255)return!1;n++}return!0}function ga(r,t,e,n){let o=0;for(let s of r)if(!(o<e)){if(o>n)break;if(s!==t[o])return!1;o++}return!0}function os(r){switch(r.length){case Ne:return r.join(".");case Ue:{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 ya(r){let t=0;for(let[e,n]of r.entries()){if(n===255){t+=8;continue}for(;(n&128)!=0;)t++,n=n<<1;if((n&128)!=0)return-1;for(let o=e+1;o<r.length;o++)if(r[o]!=0)return-1;break}return t}function ba(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var Ne=4,Ue=16,hg=parseInt("0xFFFF",16),hl=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Tr(r,t){t.length===Ue&&r.length===Ne&&ma(t,0,11)&&(t=t.slice(12)),t.length===Ne&&r.length===Ue&&ga(r,hl,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 o=0;o<e;o++)n[o]=r[o]&t[o];return n}function xa(r,t){if(typeof t=="string"&&(t=_e(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 ss(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=Ne,o=pn(t);if(o==null&&(n=Ue,o=mn(t),o==null))throw new Error("Failed to parse given CIDR: "+r);let s=parseInt(e,10);if(Number.isNaN(s)||String(s).length!==e.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+r);let i=is(s,8*n);return{network:Tr(o,i),mask:i}}function is(r,t){if(t!==8*Ne&&t!==8*Ue)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 o=0;o<e;o++){if(r>=8){n[o]=255,r-=8;continue}n[o]=255-(255>>r),r=0}return n}var je=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=ss(t));else{let n=_e(t);if(n==null)throw new Error("Failed to parse network");e=String(e);let o=parseInt(e,10);if(Number.isNaN(o)||String(o).length!==e.length||o<0||o>n.length*8){let s=_e(e);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=is(o,8*n.length);this.network=Tr(n,this.mask)}}contains(t){return xa({network:this.network,mask:this.mask},t)}toString(){let t=ya(this.mask),e=t!==-1?String(t):ba(this.mask);return os(this.network)+"/"+e}};function wa(r,t){return new je(r).contains(t)}function Qe(r){return!!pn(r)}function Je(r){return!!mn(r)}function gn(r){return!!_e(r)}var Ea=Qe,pl=Je,as=function(r){let t=0;if(r=r.toString().trim(),Ea(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(pl(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=Ea(e[n]),i;s&&(i=as(e[n]),e[n]=K(i.slice(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,K(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 s=[n,1];for(n=9-e.length;n>0;n--)s.push("0");e.splice.apply(e,s)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){let s=parseInt(e[n],16);o[t++]=s>>8&255,o[t++]=s&255}return o}throw new Error("invalid ip address")},va=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let o=[];for(let s=0;s<e;s++)o.push(r[t+s]);return o.join(".")}if(e===16){let o=[];for(let s=0;s<e;s+=2)o.push(n.getUint16(t+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var tr={},cs={},gl=[[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"]];gl.forEach(r=>{let t=yl(...r);cs[t.code]=t,tr[t.name]=t});function yl(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function z(r){if(typeof r=="number"){if(cs[r]!=null)return cs[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(tr[r]!=null)return tr[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var $g=z("ip4"),Zg=z("ip6"),Wg=z("ipcidr");function ds(r,t){switch(z(r).code){case 4:case 41:return xl(t);case 42:return ls(t);case 43:return K(t,"base10");case 6:case 273:case 33:case 132:return Aa(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return ls(t);case 421:return Sl(t);case 444:return Ia(t);case 445:return Ia(t);case 466:return vl(t);case 481:return globalThis.encodeURIComponent(ls(t));default:return K(t,"base16")}}function hs(r,t){switch(z(r).code){case 4:return Sa(t);case 41:return Sa(t);case 42:return fs(t);case 43:return H(t,"base10");case 6:case 273:case 33:case 132:return ps(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return fs(t);case 421:return wl(t);case 444:return Il(t);case 445:return Al(t);case 466:return El(t);case 481:return fs(globalThis.decodeURIComponent(t));default:return H(t,"base16")}}var us=Object.values(pr).map(r=>r.decoder),bl=function(){let r=us[0].or(us[1]);return us.slice(2).forEach(t=>r=r.or(t)),r}();function Sa(r){if(!gn(r))throw new Error("invalid ip address");return as(r)}function xl(r){let t=va(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!gn(t))throw new Error("invalid ip address");return t}function ps(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Aa(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function fs(r){let t=H(r),e=Uint8Array.from(Ct(t.length));return Pt([e,t],e.length+t.length)}function ls(r){let t=re(r);if(r=r.slice(yt(t)),r.length!==t)throw new Error("inconsistent lengths");return K(r)}function wl(r){let t;r[0]==="Q"||r[0]==="1"?t=Ee(j.decode(`z${r}`)).bytes:t=dt.parse(r).multihash.bytes;let e=Uint8Array.from(Ct(t.length));return Pt([e,t],e.length+t.length)}function El(r){let t=bl.decode(r),e=Uint8Array.from(Ct(t.length));return Pt([e,t],e.length+t.length)}function vl(r){let t=re(r),e=r.slice(yt(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+K(e,"base64url")}function Sl(r){let t=re(r),e=r.slice(yt(t));if(e.length!==t)throw new Error("inconsistent lengths");return K(e,"base58btc")}function Il(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=Xt.decode("b"+t[0]),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ps(n);return Pt([e,o],e.length+o.length)}function Al(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=Xt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ps(n);return Pt([e,o],e.length+o.length)}function Ia(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=K(t,"base32"),o=Aa(e);return`${n}:${o}`}function Ba(r){r=ms(r);let t=[],e=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let s=0;s<o.length;s++){let i=o[s],c=z(i);if(c.size===0){t.push([c.code]),e.push([c.code]);continue}if(s++,s>=o.length)throw new yn("invalid address: "+r);if(c.path===!0){n=ms(o.slice(s).join("/")),t.push([c.code,hs(c.code,n)]),e.push([c.code,n]);break}let a=hs(c.code,o[s]);t.push([c.code,a]),e.push([c.code,ds(c.code,a)])}return{string:Ta(e),bytes:bn(t),tuples:t,stringTuples:e,path:n}}function gs(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let s=re(r,o),i=yt(s),c=z(s),a=Bl(c,r.slice(o+i));if(a===0){t.push([s]),e.push([s]),o+=i;continue}let f=r.slice(o+i,o+i+a);if(o+=a+i,o>r.length)throw new yn("Invalid address Uint8Array: "+K(r,"base16"));t.push([s,f]);let u=ds(s,f);if(e.push([s,u]),c.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:Ta(e),tuples:t,stringTuples:e,path:n}}function Ta(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}),ms(t.join("/"))}function bn(r){return Pt(r.map(t=>{let e=z(t[0]),n=Uint8Array.from(Ct(e.code));return t.length>1&&t[1]!=null&&(n=Pt([n,t[1]])),n}))}function Bl(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=re(t instanceof Uint8Array?t:Uint8Array.from(t));return e+yt(e)}}function ms(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}var yn=class extends Error{static name="ParseError";name="ParseError";constructor(t){super(`Error parsing address: ${t}`)}};var Tl=Symbol.for("nodejs.util.inspect.custom"),bs=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Ll=[z("dns").code,z("dns4").code,z("dns6").code,z("dnsaddr").code],ys=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},xn=class r{bytes;#e;#t;#r;#n;[bs]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=gs(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Ba(t)}else if(Pa(t))e=gs(t.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=e.bytes,this.#e=e.string,this.#t=e.tuples,this.#r=e.stringTuples,this.#n=e.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let t,e,n,o,s="",i=z("tcp"),c=z("udp"),a=z("ip4"),f=z("ip6"),u=z("dns6"),l=z("ip6zone");for(let[y,m]of this.stringTuples())y===l.code&&(s=`%${m??""}`),Ll.includes(y)&&(e=i.name==="tcp"?"tcp":"udp",o=443,n=`${m??""}${s}`,t=y===u.code?6:4),(y===i.code||y===c.code)&&(e=z(y).name==="tcp"?"tcp":"udp",o=parseInt(m??"")),(y===a.code||y===f.code)&&(e=z(y).name==="tcp"?"tcp":"udp",n=`${m??""}${s}`,t=y===f.code?6:4);if(t==null||e==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:t,host:n,transport:e,port:o}}protos(){return this.#t.map(([t])=>Object.assign({},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(),o=n.lastIndexOf(e);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o))}decapsulateCode(t){let e=this.tuples();for(let n=e.length-1;n>=0;n--)if(e[n][0]===t)return new r(bn(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===tr.p2p.code&&t.push([n,o]),n===tr["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?K(j.decode(`z${n}`),"base58btc"):K(dt.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return mt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(s=>s.resolvable);if(e==null)return[this];let n=La.get(e.name);if(n==null)throw new ys(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>Zt(s))}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)}[Tl](){return`Multiaddr(${this.#e})`}};var La=new Map;function Pa(r){return!!r?.[bs]}function Zt(r){return new xn(r)}var Ca="libp2p-peer-record",Ra=Uint8Array.from([3,1]);var Lr;(function(r){let t;(function(n){let o;n.codec=()=>(o==null&&(o=Ft((s,i,c={})=>{c.lengthDelimited!==!1&&i.fork(),s.multiaddr!=null&&s.multiaddr.byteLength>0&&(i.uint32(10),i.bytes(s.multiaddr)),c.lengthDelimited!==!1&&i.ldelim()},(s,i,c={})=>{let a={multiaddr:ht(0)},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{a.multiaddr=s.bytes();break}default:{s.skipType(u&7);break}}}return a})),o),n.encode=s=>Kt(s,n.codec()),n.decode=(s,i)=>Mt(s,n.codec(),i)})(t=r.AddressInfo||(r.AddressInfo={}));let e;r.codec=()=>(e==null&&(e=Ft((n,o,s={})=>{if(s.lengthDelimited!==!1&&o.fork(),n.peerId!=null&&n.peerId.byteLength>0&&(o.uint32(10),o.bytes(n.peerId)),n.seq!=null&&n.seq!==0n&&(o.uint32(16),o.uint64(n.seq)),n.addresses!=null)for(let i of n.addresses)o.uint32(26),r.AddressInfo.codec().encode(i,o);s.lengthDelimited!==!1&&o.ldelim()},(n,o,s={})=>{let i={peerId:ht(0),seq:0n,addresses:[]},c=o==null?n.len:n.pos+o;for(;n.pos<c;){let a=n.uint32();switch(a>>>3){case 1:{i.peerId=n.bytes();break}case 2:{i.seq=n.uint64();break}case 3:{if(s.limits?.addresses!=null&&i.addresses.length===s.limits.addresses)throw new Ce('Decode error - map field "addresses" had too many elements');i.addresses.push(r.AddressInfo.codec().decode(n,n.uint32(),{limits:s.limits?.addresses$}));break}default:{n.skipType(a&7);break}}}return i})),e),r.encode=n=>Kt(n,r.codec()),r.decode=(n,o)=>Mt(n,r.codec(),o)})(Lr||(Lr={}));var Vt=class r{static createFromProtobuf=t=>{let e=Lr.decode(t),n=ns(Ee(e.peerId)),o=(e.addresses??[]).map(i=>Zt(i.multiaddr)),s=e.seq;return new r({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Ca;static CODEC=Ra;peerId;multiaddrs;seqNumber;domain=r.DOMAIN;codec=r.CODEC;marshaled;constructor(t){let{peerId:e,multiaddrs:n,seqNumber:o}=t;this.peerId=e,this.multiaddrs=n??[],this.seqNumber=o??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=Lr.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||!ha(this.multiaddrs,t.multiaddrs))}};function Pl(r){return r[Symbol.asyncIterator]!=null}function Cl(r){if(Pl(r))return(async()=>{for await(let t of r);})();for(let t of r);}var _a=Cl;function qt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var wn=globalThis.CustomEvent??Event;async function*xs(r,t={}){let e=t.concurrency??1/0;e<1&&(e=1/0);let n=t.ordered==null?!1:t.ordered,o=new EventTarget,s=[],i=qt(),c=qt(),a=!1,f,u=!1;o.addEventListener("task-complete",()=>{c.resolve()}),Promise.resolve().then(async()=>{try{for await(let m of r){if(s.length===e&&(i=qt(),await i.promise),u)break;let b={done:!1};s.push(b),m().then(h=>{b.done=!0,b.ok=!0,b.value=h,o.dispatchEvent(new wn("task-complete"))},h=>{b.done=!0,b.err=h,o.dispatchEvent(new wn("task-complete"))})}a=!0,o.dispatchEvent(new wn("task-complete"))}catch(m){f=m,o.dispatchEvent(new wn("task-complete"))}});function l(){return n?s[0]?.done:!!s.find(m=>m.done)}function*d(){for(;s.length>0&&s[0].done;){let m=s[0];if(s.shift(),m.ok)yield m.value;else throw u=!0,i.resolve(),m.err;i.resolve()}}function*y(){for(;l();)for(let m=0;m<s.length;m++)if(s[m].done){let b=s[m];if(s.splice(m,1),m--,b.ok)yield b.value;else throw u=!0,i.resolve(),b.err;i.resolve()}}for(;;){if(l()||(c=qt(),await c.promise),f!=null)throw f;if(n?yield*d():yield*y(),a&&s.length===0)break}}var En=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 Na(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new En(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new En(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((s,i)=>{n=()=>{i(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var ws=class{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=qt(),this.haveNext=qt()}[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=qt(),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=qt(),await Na(this.readNext.promise,e?.signal,e)}};function Ua(){return new ws}var vn=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};var Es=class extends Error{code;constructor(t,e){super(t),this.code=e}},vs=class extends Es{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted",this.name="AbortError"}};function Da(r,t){let e=Ua();r.sink(e).catch(async i=>{await e.end(i)}),r.sink=async i=>{for await(let c of i)await e.push(c);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 o=new ot;return{read:async(i,c)=>{c?.signal?.throwIfAborted();let a,f=new Promise((u,l)=>{a=()=>{l(new vs("Read aborted"))},c?.signal?.addEventListener("abort",a)});try{if(i==null){let{done:l,value:d}=await Promise.race([n.next(),f]);return l===!0?new ot:d}for(;o.byteLength<i;){let{value:l,done:d}=await Promise.race([n.next(),f]);if(d===!0)throw new vn("unexpected end of input");o.append(l)}let u=o.sublist(0,i);return o.consume(i),u}finally{a!=null&&c?.signal?.removeEventListener("abort",a)}},write:async(i,c)=>{c?.signal?.throwIfAborted(),i instanceof Uint8Array?await e.push(i,c):await e.push(i.subarray(),c)},unwrap:()=>{if(o.byteLength>0){let i=r.source;r.source=async function*(){t?.yieldBytes===!1?yield o:yield*o,yield*i}()}return r}}}var Sn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},In=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},An=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Oa(r,t={}){let e=Da(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=yt(t.maxDataLength));let n=t?.lengthDecoder??re,o=t?.lengthEncoder??Ct;return{read:async i=>{let c=-1,a=new ot;for(;;){a.append(await e.read(1,i));try{c=n(a)}catch(f){if(f instanceof RangeError)continue;throw f}if(c<0)throw new Sn("Invalid message length");if(t?.maxLengthLength!=null&&a.byteLength>t.maxLengthLength)throw new An("message length length too long");if(c>-1)break}if(t?.maxDataLength!=null&&c>t.maxDataLength)throw new In("message length too long");return e.read(c,i)},write:async(i,c)=>{await e.write(new ot(o(i.byteLength),i),c)},writeV:async(i,c)=>{let a=new ot(...i.flatMap(f=>[o(f.byteLength),f]));await e.write(a,c)},unwrap:()=>e.unwrap()}}function er(r,t){let e=Oa(r,t),n={read:async(o,s)=>{let i=await e.read(s);return o.decode(i)},write:async(o,s,i)=>{await e.write(s.encode(o),i)},writeV:async(o,s,i)=>{await e.writeV(o.map(c=>s.encode(c)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var ka="0.1.0",Ma="id",Ka="id/push",Fa="1.0.0",Va="1.0.0";var xe;(function(r){let t;r.codec=()=>(t==null&&(t=Ft((e,n,o={})=>{if(o.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 s of e.listenAddrs)n.uint32(18),n.bytes(s);if(e.observedAddr!=null&&(n.uint32(34),n.bytes(e.observedAddr)),e.protocols!=null)for(let s of e.protocols)n.uint32(26),n.string(s);e.signedPeerRecord!=null&&(n.uint32(66),n.bytes(e.signedPeerRecord)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={listenAddrs:[],protocols:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let c=e.uint32();switch(c>>>3){case 5:{s.protocolVersion=e.string();break}case 6:{s.agentVersion=e.string();break}case 1:{s.publicKey=e.bytes();break}case 2:{if(o.limits?.listenAddrs!=null&&s.listenAddrs.length===o.limits.listenAddrs)throw new Ce('Decode error - map field "listenAddrs" had too many elements');s.listenAddrs.push(e.bytes());break}case 4:{s.observedAddr=e.bytes();break}case 3:{if(o.limits?.protocols!=null&&s.protocols.length===o.limits.protocols)throw new Ce('Decode error - map field "protocols" had too many elements');s.protocols.push(e.string());break}case 8:{s.signedPeerRecord=e.bytes();break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Kt(e,r.codec()),r.decode=(e,n)=>Mt(e,r.codec(),n)})(xe||(xe={}));var Tt={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function qa(r){if(r!=null&&r.length>0)try{return Zt(r)}catch{}}function Nl(r,t){return t??r.userAgent}async function Bn(r,t,e,n,o){if(e("received identify from %p",n.remotePeer),o==null)throw new _t("message was null or undefined");let s={};if(o.listenAddrs.length>0&&(s.addresses=o.listenAddrs.map(a=>({isCertified:!1,multiaddr:Zt(a)}))),o.protocols.length>0&&(s.protocols=o.protocols),o.publicKey!=null){let a=Ye(o.publicKey);if(!da(a).equals(n.remotePeer))throw new _t("public key did not match remote PeerId");s.publicKey=a}let i;if(o.signedPeerRecord!=null){e.trace("received signedPeerRecord from %p",n.remotePeer);let a=o.signedPeerRecord,f=await $t.openAndCertify(a,Vt.DOMAIN),u=Vt.createFromProtobuf(f.payload),l=dn(f.publicKey.toCID());if(!u.peerId.equals(l))throw new _t("signing key does not match PeerId in the PeerRecord");if(!n.remotePeer.equals(u.peerId))throw new _t("signing key does not match remote PeerId");let d;try{d=await r.get(u.peerId)}catch(y){if(y.name!=="NotFoundError")throw y}if(d!=null&&(s.metadata=d.metadata,d.peerRecordEnvelope!=null)){let y=await $t.createFromProtobuf(d.peerRecordEnvelope),m=Vt.createFromProtobuf(y.payload);m.seqNumber>=u.seqNumber&&(e("sequence number was lower or equal to existing sequence number - stored: %d received: %d",m.seqNumber,u.seqNumber),u=m,a=d.peerRecordEnvelope)}s.peerRecordEnvelope=a,s.addresses=u.multiaddrs.map(y=>({isCertified:!0,multiaddr:y})),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,s),await r.patch(n.remotePeer,s),o.agentVersion!=null||o.protocolVersion!=null){let a={};o.agentVersion!=null&&(a.AgentVersion=H(o.agentVersion)),o.protocolVersion!=null&&(a.ProtocolVersion=H(o.protocolVersion)),e.trace("merging %p metadata",n.remotePeer,a),await r.merge(n.remotePeer,{metadata:a})}let c={peerId:n.remotePeer,protocolVersion:o.protocolVersion,agentVersion:o.agentVersion,publicKey:o.publicKey,listenAddrs:o.listenAddrs.map(a=>Zt(a)),observedAddr:o.observedAddr==null?void 0:Zt(o.observedAddr),protocols:o.protocols,signedPeerRecord:i,connection:n};return t.safeDispatchEvent("peer:identify",{detail:c}),c}var rr=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??Tt.timeout,this.maxInboundStreams=e.maxInboundStreams??Tt.maxInboundStreams,this.maxOutboundStreams=e.maxOutboundStreams??Tt.maxOutboundStreams,this.maxMessageSize=e.maxMessageSize??Tt.maxMessageSize,this.maxObservedAddresses=e.maxObservedAddresses??Tt.maxObservedAddresses,this.runOnLimitedConnection=e.runOnLimitedConnection??Tt.runOnLimitedConnection,this.host={protocolVersion:`${e.protocolPrefix??Tt.protocolPrefix}/${ka}`,agentVersion:Nl(t.nodeInfo,e.agentVersion)}}isStarted(){return this.started}async start(){this.started||(await this.peerStore.merge(this.peerId,{metadata:{AgentVersion:H(this.host.agentVersion),ProtocolVersion:H(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 Tn=class extends rr{connectionManager;concurrency;constructor(t,e={}){super(t,{...e,protocol:`/${e.protocolPrefix??Tt.protocolPrefix}/${Ka}/${Va}`,log:t.logger.forComponent("libp2p:identify-push")}),this.connectionManager=t.connectionManager,this.concurrency=e.concurrency??Tt.concurrency,(e.runOnSelfUpdate??Tt.runOnSelfUpdate)&&t.events.addEventListener("self:peer:update",n=>{this.push().catch(o=>{this.log.error(o)})})}[kr]=["@libp2p/identify-push"];async push(){if(!this.isStarted())return;let t=this.addressManager.getAddresses().map(u=>u.decapsulateCode(z("p2p").code)),e=new Vt({peerId:this.peerId,multiaddrs:t}),n=await $t.seal(e,this.privateKey),o=this.registrar.getProtocols(),s=await this.peerStore.get(this.peerId),i=K(s.metadata.get("AgentVersion")??H(this.host.agentVersion)),c=K(s.metadata.get("ProtocolVersion")??H(this.host.protocolVersion)),a=this;async function*f(){for(let u of a.connectionManager.getConnections())(await a.peerStore.get(u.remotePeer)).protocols.includes(a.protocol)&&(yield async()=>{let d,y=AbortSignal.timeout(a.timeout);try{d=await u.newStream(a.protocol,{signal:y,runOnLimitedConnection:a.runOnLimitedConnection}),await er(d,{maxDataLength:a.maxMessageSize}).pb(xe).write({listenAddrs:t.map(b=>b.bytes),signedPeerRecord:n.marshal(),protocols:o,agentVersion:i,protocolVersion:c},{signal:y}),await d.close({signal:y})}catch(m){a.log.error("could not push identify update to peer",m),d?.abort(m)}})}await _a(xs(f(),{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 o={signal:AbortSignal.timeout(this.timeout)},i=await er(n,{maxDataLength:this.maxMessageSize}).pb(xe).read(o);await n.close(o),await Bn(this.peerStore,this.events,this.log,e,i)}catch(o){this.log.error("received invalid message",o),n.abort(o);return}this.log.trace("handled push from %p",e.remotePeer)}};var Dl=41;function Ha(r){try{let[[t,e]]=r.stringTuples();if(e==null)return!1;if(t===Dl)return wa("2000::/3",e)}catch{}return!1}var Ga=yc(za(),1),Ol=["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"],kl=Ol.map(r=>new Ga.Netmask(r));function Ss(r){for(let t of kl)if(t.contains(r))return!0;return!1}function Ml(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function Kl(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"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(e.substring(0,2),16)}.${parseInt(e.substring(2),16)}`;return Ss(o)}function Fl(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function Vl(r){let t=r.split(":"),e=t[t.length-1];return Ss(e)}function ql(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 $a(r){return Qe(r)?Ss(r):Ml(r)?Kl(r):Fl(r)?Vl(r):Je(r)?ql(r):void 0}function Za(r){try{let[[t]]=r.stringTuples();return t===4||t===41}catch{}return!1}function Wa(r){try{if(!Za(r))return!1;let[[,t]]=r.stringTuples();return t==null?!1:$a(t)??!1}catch{}return!0}var Hl=r=>r.toString().split("/").slice(1),nr=r=>({match:t=>t.length<1?!1:r(t[0])?t.slice(1):!1,pattern:"fn"}),F=r=>({match:t=>nr(e=>e===r).match(t),pattern:r}),De=()=>({match:r=>nr(t=>typeof t=="string").match(r),pattern:"{string}"}),Cr=()=>({match:r=>nr(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{j.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),Rr=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{To.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})`}),xt=(...r)=>({match:t=>{let e;for(let n of r){let o=n.match(t);o!==!1&&(e==null||o.length<e.length)&&(e=o)}return e??!1},pattern:`or(${r.map(t=>t.pattern).join(", ")})`}),V=(...r)=>({match:t=>{for(let e of r){let n=e.match(t);if(n===!1)return!1;t=n}return t},pattern:`and(${r.map(t=>t.pattern).join(", ")})`});function rt(...r){function t(o){let s=Hl(o);for(let i of r){let c=i.match(s);if(c===!1)return!1;s=c}return s}function e(o){return t(o)!==!1}function n(o){let s=t(o);return s===!1?!1:s.length===0}return{matchers:r,matches:e,exactMatch:n}}var Pn=V(F("dns4"),De()),Cn=V(F("dns6"),De()),Rn=V(F("dnsaddr"),De()),As=V(F("dns"),De()),Ob=rt(Pn,G(Y())),kb=rt(Cn,G(Y())),Mb=rt(Rn,G(Y())),Kb=rt(xt(As,Rn,Pn,Cn),G(Y())),Ya=V(F("ip4"),nr(Qe)),Xa=V(F("ip6"),nr(Je)),Bs=xt(Ya,Xa),se=xt(Bs,As,Pn,Cn,Rn),ja=rt(xt(Bs,V(xt(As,Rn,Pn,Cn),G(Y())))),Fb=rt(Ya),Vb=rt(Xa),qb=rt(Bs),Ts=V(se,F("tcp"),Cr()),_r=V(se,F("udp"),Cr()),Qa=rt(V(Ts,G(Y()))),Hb=rt(_r),Ls=V(_r,F("quic"),G(Y())),_n=V(_r,F("quic-v1"),G(Y())),zl=xt(Ls,_n),zb=rt(Ls),Gb=rt(_n),Is=xt(se,Ts,_r,Ls,_n),Ja=xt(V(Is,F("ws"),G(Y()))),$b=rt(Ja),tc=xt(V(Is,F("wss"),G(Y())),V(Is,F("tls"),G(V(F("sni"),De())),F("ws"),G(Y()))),Zb=rt(tc),ec=V(_r,F("webrtc-direct"),G(Rr()),G(Rr()),G(Y())),Wb=rt(ec),rc=V(_n,F("webtransport"),G(Rr()),G(Rr()),G(Y())),Yb=rt(rc),Ln=xt(Ja,tc,V(Ts,G(Y())),V(zl,G(Y())),V(se,G(Y())),ec,rc,Y()),Xb=rt(Ln),Gl=V(Ln,F("p2p-circuit"),Y()),jb=rt(Gl),$l=xt(V(Ln,F("p2p-circuit"),F("webrtc"),G(Y())),V(Ln,F("webrtc"),G(Y())),V(F("webrtc"),G(Y()))),Qb=rt($l),Zl=xt(V(se,F("tcp"),Cr(),F("http"),G(Y())),V(se,F("http"),G(Y()))),Jb=rt(Zl),Wl=xt(V(se,F("tcp"),xt(V(F("443"),F("http")),V(Cr(),F("https"))),G(Y())),V(se,F("tls"),F("http"),G(Y())),V(se,F("https"),G(Y()))),tx=rt(Wl),Yl=xt(V(F("memory"),De(),G(Y()))),ex=rt(Yl);var Xl=41,Nn=class extends rr{constructor(t,e={}){super(t,{...e,protocol:`/${e.protocolPrefix??Tt.protocolPrefix}/${Ma}/${Fa}`,log:t.logger.forComponent("libp2p:identify")}),(e.runOnConnectionOpen??Tt.runOnConnectionOpen)&&t.events.addEventListener("connection:open",n=>{let o=n.detail;this.identify(o).catch(s=>{s.name!==Or.name&&this.log.error("error during identify trigged by connection:open",s)})})}[kr]=["@libp2p/identify"];async _identify(t,e={}){let n;if(e.signal==null){let o=AbortSignal.timeout(this.timeout);e={...e,signal:o}}try{n=await t.newStream(this.protocol,{...e,runOnLimitedConnection:this.runOnLimitedConnection});let s=await er(n,{maxDataLength:this.maxMessageSize}).pb(xe).read(e);return await n.close(e),s}catch(o){throw n?.abort(o),o}}async identify(t,e={}){let n=await this._identify(t,e),{publicKey:o,protocols:s,observedAddr:i}=n;if(o==null)throw new _t("public key was missing from identify message");let c=Ye(o),a=dn(c.toCID());if(!t.remotePeer.equals(a))throw new _t("identified peer does not match the expected peer");if(this.peerId.equals(a))throw new _t("identified peer is our own peer id?");return this.maybeAddObservedAddress(i),this.log("identify completed for peer %p and protocols %o",a,s),Bn(this.peerStore,this.events,this.log,t,n)}maybeAddObservedAddress(t){let e=qa(t);if(e==null)return;if(this.log.trace("our observed address was %a",e),Wa(e)){this.log.trace("our observed address was private");return}if(e.stringTuples()[0][0]===Xl&&!Ha(e)){this.log.trace("our observed address was IPv6 but not a global unicast address");return}Qa.exactMatch(e)||(this.log.trace("storing the observed address"),this.addressManager.addObservedAddr(e))}async handleProtocol(t){let{connection:e,stream:n}=t,o=AbortSignal.timeout(this.timeout);try{let s=await this.peerStore.get(this.peerId),i=this.addressManager.getAddresses().map(u=>u.decapsulateCode(z("p2p").code)),c=s.peerRecordEnvelope;if(i.length>0&&c==null){let u=new Vt({peerId:this.peerId,multiaddrs:i});c=(await $t.seal(u,this.privateKey)).marshal().subarray()}let a=e.remoteAddr.bytes;ja.matches(e.remoteAddr)||(a=void 0),await er(n).pb(xe).write({protocolVersion:this.host.protocolVersion,agentVersion:this.host.agentVersion,publicKey:pe(this.privateKey.publicKey),listenAddrs:i.map(u=>u.bytes),signedPeerRecord:c,observedAddr:a,protocols:s.protocols},{signal:o}),await n.close({signal:o})}catch(s){this.log.error("could not respond to identify request",s),n.abort(s)}}};function jl(r={}){return t=>new Nn(t,r)}function Ql(r={}){return t=>new Tn(t,r)}return bc(Jl);})();
|
|
7
3
|
/*! Bundled license information:
|
|
8
4
|
|
|
9
|
-
pvtsutils/build/index.js:
|
|
10
|
-
(*!
|
|
11
|
-
* MIT License
|
|
12
|
-
*
|
|
13
|
-
* Copyright (c) 2017-2024 Peculiar Ventures, LLC
|
|
14
|
-
*
|
|
15
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
16
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
17
|
-
* in the Software without restriction, including without limitation the rights
|
|
18
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
19
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
20
|
-
* furnished to do so, subject to the following conditions:
|
|
21
|
-
*
|
|
22
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
23
|
-
* copies or substantial portions of the Software.
|
|
24
|
-
*
|
|
25
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
26
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
27
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
28
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
29
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
30
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
31
|
-
* SOFTWARE.
|
|
32
|
-
*
|
|
33
|
-
*)
|
|
34
|
-
|
|
35
5
|
@noble/hashes/esm/utils.js:
|
|
36
6
|
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
37
7
|
|
|
@@ -50,46 +20,6 @@ pvtsutils/build/index.js:
|
|
|
50
20
|
@noble/curves/esm/ed25519.js:
|
|
51
21
|
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
52
22
|
|
|
53
|
-
pvutils/build/utils.es.js:
|
|
54
|
-
(*!
|
|
55
|
-
Copyright (c) Peculiar Ventures, LLC
|
|
56
|
-
*)
|
|
57
|
-
|
|
58
|
-
asn1js/build/index.es.js:
|
|
59
|
-
(*!
|
|
60
|
-
* Copyright (c) 2014, GMO GlobalSign
|
|
61
|
-
* Copyright (c) 2015-2022, Peculiar Ventures
|
|
62
|
-
* All rights reserved.
|
|
63
|
-
*
|
|
64
|
-
* Author 2014-2019, Yury Strozhevsky
|
|
65
|
-
*
|
|
66
|
-
* Redistribution and use in source and binary forms, with or without modification,
|
|
67
|
-
* are permitted provided that the following conditions are met:
|
|
68
|
-
*
|
|
69
|
-
* * Redistributions of source code must retain the above copyright notice, this
|
|
70
|
-
* list of conditions and the following disclaimer.
|
|
71
|
-
*
|
|
72
|
-
* * Redistributions in binary form must reproduce the above copyright notice, this
|
|
73
|
-
* list of conditions and the following disclaimer in the documentation and/or
|
|
74
|
-
* other materials provided with the distribution.
|
|
75
|
-
*
|
|
76
|
-
* * Neither the name of the copyright holder nor the names of its
|
|
77
|
-
* contributors may be used to endorse or promote products derived from
|
|
78
|
-
* this software without specific prior written permission.
|
|
79
|
-
*
|
|
80
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
81
|
-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
82
|
-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
83
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
84
|
-
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
85
|
-
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
86
|
-
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
87
|
-
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
88
|
-
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
89
|
-
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
90
|
-
*
|
|
91
|
-
*)
|
|
92
|
-
|
|
93
23
|
@noble/curves/esm/abstract/weierstrass.js:
|
|
94
24
|
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
95
25
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/identify",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.24-3f127b610",
|
|
4
4
|
"description": "Implementation of the Identify Protocol",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/protocol-identify#readme",
|
|
@@ -52,12 +52,12 @@
|
|
|
52
52
|
"doc-check": "aegir doc-check"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@libp2p/crypto": "5.0.
|
|
56
|
-
"@libp2p/interface": "2.6.1-
|
|
57
|
-
"@libp2p/interface-internal": "2.3.
|
|
58
|
-
"@libp2p/peer-id": "5.0.
|
|
59
|
-
"@libp2p/peer-record": "8.0.
|
|
60
|
-
"@libp2p/utils": "6.5.
|
|
55
|
+
"@libp2p/crypto": "5.0.14-3f127b610",
|
|
56
|
+
"@libp2p/interface": "2.6.1-3f127b610",
|
|
57
|
+
"@libp2p/interface-internal": "2.3.6-3f127b610",
|
|
58
|
+
"@libp2p/peer-id": "5.0.15-3f127b610",
|
|
59
|
+
"@libp2p/peer-record": "8.0.22-3f127b610",
|
|
60
|
+
"@libp2p/utils": "6.5.6-3f127b610",
|
|
61
61
|
"@multiformats/multiaddr": "^12.3.3",
|
|
62
62
|
"@multiformats/multiaddr-matcher": "^1.6.0",
|
|
63
63
|
"it-drain": "^3.0.7",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"uint8arrays": "^5.1.0"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
|
-
"@libp2p/logger": "5.1.
|
|
71
|
+
"@libp2p/logger": "5.1.11-3f127b610",
|
|
72
72
|
"aegir": "^45.1.1",
|
|
73
73
|
"delay": "^6.0.0",
|
|
74
74
|
"it-length-prefixed": "^10.0.1",
|