@libp2p/peer-store 10.1.4 → 10.1.5
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 +3 -3
- package/package.json +7 -7
package/dist/index.min.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PPeerStore = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PPeerStore=(()=>{var Yl=Object.create;var fn=Object.defineProperty;var Zl=Object.getOwnPropertyDescriptor;var Jl=Object.getOwnPropertyNames;var Xl=Object.getPrototypeOf,Ql=Object.prototype.hasOwnProperty;var qo=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),ue=(r,e)=>{for(var t in e)fn(r,t,{get:e[t],enumerable:!0})},$o=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Jl(e))!Ql.call(r,s)&&s!==t&&fn(r,s,{get:()=>e[s],enumerable:!(n=Zl(e,s))||n.enumerable});return r};var zo=(r,e,t)=>(t=r!=null?Yl(Xl(r)):{},$o(e||!r||!r.__esModule?fn(t,"default",{value:r,enumerable:!0}):t,r)),eu=r=>$o(fn({},"__esModule",{value:!0}),r);var Wa=qo(yr=>{"use strict";var Ch="[object ArrayBuffer]",lt=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===Ch}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,t){let n=r.toUint8Array(e),s=r.toUint8Array(t);if(n.length!==s.byteLength)return!1;for(let i=0;i<n.length;i++)if(n[i]!==s[i])return!1;return!0}static concat(...e){let t;Array.isArray(e[0])&&!(e[1]instanceof Function)||Array.isArray(e[0])&&e[1]instanceof Function?t=e[0]:e[e.length-1]instanceof Function?t=e.slice(0,e.length-1):t=e;let n=0;for(let o of t)n+=o.byteLength;let s=new Uint8Array(n),i=0;for(let o of t){let a=this.toUint8Array(o);s.set(a,i),i+=a.length}return e[e.length-1]instanceof Function?this.toView(s,e[e.length-1]):s.buffer}},Hi="string",Lh=/^[0-9a-f]+$/i,Uh=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Ph=/^[a-zA-Z0-9-_]+$/,_n=class{static fromString(e){let t=unescape(encodeURIComponent(e)),n=new Uint8Array(t.length);for(let s=0;s<t.length;s++)n[s]=t.charCodeAt(s);return n.buffer}static toString(e){let t=lt.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return decodeURIComponent(escape(n))}},Ve=class{static toString(e,t=!1){let n=lt.toArrayBuffer(e),s=new DataView(n),i="";for(let o=0;o<n.byteLength;o+=2){let a=s.getUint16(o,t);i+=String.fromCharCode(a)}return i}static fromString(e,t=!1){let n=new ArrayBuffer(e.length*2),s=new DataView(n);for(let i=0;i<e.length;i++)s.setUint16(i*2,e.charCodeAt(i),t);return n}},Cn=class r{static isHex(e){return typeof e===Hi&&Lh.test(e)}static isBase64(e){return typeof e===Hi&&Uh.test(e)}static isBase64Url(e){return typeof e===Hi&&Ph.test(e)}static ToString(e,t="utf8"){let n=lt.toUint8Array(e);switch(t.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 Ve.toString(n,!0);case"utf16":case"utf16be":return Ve.toString(n);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromString(e,t="utf8"){if(!e)return new ArrayBuffer(0);switch(t.toLowerCase()){case"utf8":return this.FromUtf8String(e);case"binary":return this.FromBinary(e);case"hex":return this.FromHex(e);case"base64":return this.FromBase64(e);case"base64url":return this.FromBase64Url(e);case"utf16le":return Ve.fromString(e,!0);case"utf16":case"utf16be":return Ve.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=lt.toUint8Array(e);if(typeof btoa<"u"){let n=this.ToString(t,"binary");return btoa(n)}else return Buffer.from(t).toString("base64")}static FromBase64(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64(t))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(t)):new Uint8Array(Buffer.from(t,"base64")).buffer}static FromBase64Url(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64Url(t))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(t.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(e){return this.ToBase64(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.FromBinary(e);case"utf8":return _n.fromString(e);case"utf16":case"utf16be":return Ve.fromString(e);case"utf16le":case"usc2":return Ve.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return _n.toString(e);case"utf16":case"utf16be":return Ve.toString(e);case"utf16le":case"usc2":return Ve.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){let t=e.length,n=new Uint8Array(t);for(let s=0;s<t;s++)n[s]=e.charCodeAt(s);return n.buffer}static ToBinary(e){let t=lt.toUint8Array(e),n="";for(let s=0;s<t.length;s++)n+=String.fromCharCode(t[s]);return n}static ToHex(e){let t=lt.toUint8Array(e),n="",s=t.length;for(let i=0;i<s;i++){let o=t[i];o<16&&(n+="0"),n+=o.toString(16)}return n}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);let n=new Uint8Array(t.length/2);for(let s=0;s<t.length;s=s+2){let i=t.slice(s,s+2);n[s/2]=parseInt(i,16)}return n.buffer}static ToUtf16String(e,t=!1){return Ve.toString(e,t)}static FromUtf16String(e,t=!1){return Ve.fromString(e,t)}static Base64Padding(e){let t=4-e.length%4;if(t<4)for(let n=0;n<t;n++)e+="=";return e}static formatString(e){return e?.replace(/[\n\r\t ]/g,"")||""}};Cn.DEFAULT_UTF8_ENCODING="utf8";function Dh(r,...e){let t=arguments[0];for(let n=1;n<arguments.length;n++){let s=arguments[n];for(let i in s)t[i]=s[i]}return t}function Vh(...r){let e=r.map(s=>s.byteLength).reduce((s,i)=>s+i),t=new Uint8Array(e),n=0;return r.map(s=>new Uint8Array(s)).forEach(s=>{for(let i of s)t[n++]=i}),t.buffer}function Oh(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let s=0;s<r.byteLength;s++)if(t[s]!==n[s])return!1;return!0}yr.BufferSourceConverter=lt;yr.Convert=Cn;yr.assign=Dh;yr.combine=Vh;yr.isEqual=Oh});var Nl=qo((Wb,xo)=>{"use strict";var Hd=Object.prototype.hasOwnProperty,Re="~";function an(){}Object.create&&(an.prototype=Object.create(null),new an().__proto__||(Re=!1));function Kd(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function Rl(r,e,t,n,s){if(typeof t!="function")throw new TypeError("The listener must be a function");var i=new Kd(t,n||r,s),o=Re?Re+e:e;return r._events[o]?r._events[o].fn?r._events[o]=[r._events[o],i]:r._events[o].push(i):(r._events[o]=i,r._eventsCount++),r}function Is(r,e){--r._eventsCount===0?r._events=new an:delete r._events[e]}function ve(){this._events=new an,this._eventsCount=0}ve.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)Hd.call(t,n)&&e.push(Re?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};ve.prototype.listeners=function(e){var t=Re?Re+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var s=0,i=n.length,o=new Array(i);s<i;s++)o[s]=n[s].fn;return o};ve.prototype.listenerCount=function(e){var t=Re?Re+e:e,n=this._events[t];return n?n.fn?1:n.length:0};ve.prototype.emit=function(e,t,n,s,i,o){var a=Re?Re+e:e;if(!this._events[a])return!1;var c=this._events[a],f=arguments.length,u,l;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),f){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,s),!0;case 5:return c.fn.call(c.context,t,n,s,i),!0;case 6:return c.fn.call(c.context,t,n,s,i,o),!0}for(l=1,u=new Array(f-1);l<f;l++)u[l-1]=arguments[l];c.fn.apply(c.context,u)}else{var h=c.length,m;for(l=0;l<h;l++)switch(c[l].once&&this.removeListener(e,c[l].fn,void 0,!0),f){case 1:c[l].fn.call(c[l].context);break;case 2:c[l].fn.call(c[l].context,t);break;case 3:c[l].fn.call(c[l].context,t,n);break;case 4:c[l].fn.call(c[l].context,t,n,s);break;default:if(!u)for(m=1,u=new Array(f-1);m<f;m++)u[m-1]=arguments[m];c[l].fn.apply(c[l].context,u)}}return!0};ve.prototype.on=function(e,t,n){return Rl(this,e,t,n,!1)};ve.prototype.once=function(e,t,n){return Rl(this,e,t,n,!0)};ve.prototype.removeListener=function(e,t,n,s){var i=Re?Re+e:e;if(!this._events[i])return this;if(!t)return Is(this,i),this;var o=this._events[i];if(o.fn)o.fn===t&&(!s||o.once)&&(!n||o.context===n)&&Is(this,i);else{for(var a=0,c=[],f=o.length;a<f;a++)(o[a].fn!==t||s&&!o[a].once||n&&o[a].context!==n)&&c.push(o[a]);c.length?this._events[i]=c.length===1?c[0]:c:Is(this,i)}return this};ve.prototype.removeAllListeners=function(e){var t;return e?(t=Re?Re+e:e,this._events[t]&&Is(this,t)):(this._events=new an,this._eventsCount=0),this};ve.prototype.off=ve.prototype.removeListener;ve.prototype.addListener=ve.prototype.on;ve.prefixed=Re;ve.EventEmitter=ve;typeof xo<"u"&&(xo.exports=ve)});var Yd={};ue(Yd,{PersistentPeerStore:()=>Uo});var hn=Symbol.for("@libp2p/peer-id");function Go(r){return r!=null&&!!r[hn]}var R=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var Oi={};ue(Oi,{Ed25519PrivateKey:()=>$t,Ed25519PublicKey:()=>Mr,generateKeyPair:()=>Nh,generateKeyPairFromSeed:()=>Ga,unmarshalEd25519PrivateKey:()=>Ih,unmarshalEd25519PublicKey:()=>Rh});var Ks={};ue(Ks,{base58btc:()=>ce,base58flickr:()=>ou});var Qd=new Uint8Array(0);function Wo(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function tt(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 jo(r){return new TextEncoder().encode(r)}function Yo(r){return new TextDecoder().decode(r)}function tu(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var s=0;s<r.length;s++){var i=r.charAt(s),o=i.charCodeAt(0);if(t[o]!==255)throw new TypeError(i+" is ambiguous");t[o]=s}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function l(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var d=0,g=0,b=0,B=p.length;b!==B&&p[b]===0;)b++,d++;for(var w=(B-b)*u+1>>>0,_=new Uint8Array(w);b!==B;){for(var x=p[b],A=0,N=w-1;(x!==0||A<g)&&N!==-1;N--,A++)x+=256*_[N]>>>0,_[N]=x%a>>>0,x=x/a>>>0;if(x!==0)throw new Error("Non-zero carry");g=A,b++}for(var T=w-g;T!==w&&_[T]===0;)T++;for(var z=c.repeat(d);T<w;++T)z+=r.charAt(_[T]);return z}function h(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var d=0;if(p[d]!==" "){for(var g=0,b=0;p[d]===c;)g++,d++;for(var B=(p.length-d)*f+1>>>0,w=new Uint8Array(B);p[d];){var _=t[p.charCodeAt(d)];if(_===255)return;for(var x=0,A=B-1;(_!==0||x<b)&&A!==-1;A--,x++)_+=a*w[A]>>>0,w[A]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");b=x,d++}if(p[d]!==" "){for(var N=B-b;N!==B&&w[N]===0;)N++;for(var T=new Uint8Array(g+(B-N)),z=g;N!==B;)T[z++]=w[N++];return T}}}function m(p){var d=h(p);if(d)return d;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:h,decode:m}}var ru=tu,nu=ru,Jo=nu;var Vs=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Os=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Xo(this,e)}},Ms=class{decoders;constructor(e){this.decoders=e}or(e){return Xo(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Xo(r,e){return new Ms({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Hs=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,s){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=s,this.encoder=new Vs(e,t,n),this.decoder=new Os(e,t,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function er({name:r,prefix:e,encode:t,decode:n}){return new Hs(r,e,t,n)}function bt({name:r,prefix:e,alphabet:t}){let{encode:n,decode:s}=Jo(t,r);return er({prefix:e,name:r,encode:n,decode:i=>tt(s(i))})}function su(r,e,t,n){let s={};for(let u=0;u<e.length;++u)s[e[u]]=u;let i=r.length;for(;r[i-1]==="=";)--i;let o=new Uint8Array(i*t/8|0),a=0,c=0,f=0;for(let u=0;u<i;++u){let l=s[r[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|l,a+=t,a>=8&&(a-=8,o[f++]=255&c>>a)}if(a>=t||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o}function iu(r,e,t){let n=e[e.length-1]==="=",s=(1<<t)-1,i="",o=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],o+=8;o>t;)o-=t,i+=e[s&a>>o];if(o!==0&&(i+=e[s&a<<t-o]),n)for(;i.length*t&7;)i+="=";return i}function ee({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return er({prefix:e,name:r,encode(s){return iu(s,n,t)},decode(s){return su(s,n,t,r)}})}var ce=bt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ou=bt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var qs={};ue(qs,{identity:()=>rt});var au=ta,Qo=128,cu=127,lu=~cu,uu=Math.pow(2,31);function ta(r,e,t){e=e||[],t=t||0;for(var n=t;r>=uu;)e[t++]=r&255|Qo,r/=128;for(;r&lu;)e[t++]=r&255|Qo,r>>>=7;return e[t]=r|0,ta.bytes=t-n+1,e}var fu=Fs,hu=128,ea=127;function Fs(r,n){var t=0,n=n||0,s=0,i=n,o,a=r.length;do{if(i>=a)throw Fs.bytes=0,new RangeError("Could not decode varint");o=r[i++],t+=s<28?(o&ea)<<s:(o&ea)*Math.pow(2,s),s+=7}while(o>=hu);return Fs.bytes=i-n,t}var du=Math.pow(2,7),pu=Math.pow(2,14),gu=Math.pow(2,21),mu=Math.pow(2,28),yu=Math.pow(2,35),bu=Math.pow(2,42),wu=Math.pow(2,49),xu=Math.pow(2,56),vu=Math.pow(2,63),Eu=function(r){return r<du?1:r<pu?2:r<gu?3:r<mu?4:r<yu?5:r<bu?6:r<wu?7:r<xu?8:r<vu?9:10},Bu={encode:au,decode:fu,encodingLength:Eu},Au=Bu,_r=Au;function Cr(r,e=0){return[_r.decode(r,e),_r.decode.bytes]}function tr(r,e,t=0){return _r.encode(r,e,t),e}function rr(r){return _r.encodingLength(r)}function Ge(r,e){let t=e.byteLength,n=rr(r),s=n+rr(t),i=new Uint8Array(s+t);return tr(r,i,0),tr(t,i,n),i.set(e,s),new nr(r,t,e,i)}function Dt(r){let e=tt(r),[t,n]=Cr(e),[s,i]=Cr(e.subarray(n)),o=e.subarray(n+i);if(o.byteLength!==s)throw new Error("Incorrect length");return new nr(t,s,o,e)}function ra(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Wo(r.bytes,t.bytes)}}var nr=class{code;size;digest;bytes;constructor(e,t,n,s){this.code=e,this.size=t,this.digest=n,this.bytes=s}};var na=0,ku="identity",sa=tt;function Su(r){return Ge(na,sa(r))}var rt={code:na,name:ku,encode:sa,digest:Su};var Gs={};ue(Gs,{sha256:()=>pe,sha512:()=>Iu});function zs({name:r,code:e,encode:t}){return new $s(r,e,t)}var $s=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?Ge(this.code,t):t.then(n=>Ge(this.code,n))}else throw Error("Unknown type, must be binary type")}};function oa(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var pe=zs({name:"sha2-256",code:18,encode:oa("SHA-256")}),Iu=zs({name:"sha2-512",code:19,encode:oa("SHA-512")});function te(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function nt(r=0){return new Uint8Array(r)}function Ne(r=0){return new Uint8Array(r)}function Ee(r,e){e==null&&(e=r.reduce((s,i)=>s+i.length,0));let t=Ne(e),n=0;for(let s of r)t.set(s,n),n+=s.length;return t}var Ws={};ue(Ws,{base10:()=>Ru});var Ru=bt({prefix:"9",name:"base10",alphabet:"0123456789"});var js={};ue(js,{base16:()=>Nu,base16upper:()=>Tu});var Nu=ee({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Tu=ee({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Ys={};ue(Ys,{base2:()=>_u});var _u=ee({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Zs={};ue(Zs,{base256emoji:()=>Du});var aa=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}"),Cu=aa.reduce((r,e,t)=>(r[t]=e,r),[]),Lu=aa.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function Uu(r){return r.reduce((e,t)=>(e+=Cu[t],e),"")}function Pu(r){let e=[];for(let t of r){let n=Lu[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var Du=er({prefix:"\u{1F680}",name:"base256emoji",encode:Uu,decode:Pu});var Js={};ue(Js,{base32:()=>Me,base32hex:()=>Hu,base32hexpad:()=>Fu,base32hexpadupper:()=>qu,base32hexupper:()=>Ku,base32pad:()=>Ou,base32padupper:()=>Mu,base32upper:()=>Vu,base32z:()=>$u});var Me=ee({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Vu=ee({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ou=ee({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Mu=ee({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Hu=ee({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ku=ee({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Fu=ee({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),qu=ee({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),$u=ee({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Xs={};ue(Xs,{base36:()=>zu,base36upper:()=>Gu});var zu=bt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Gu=bt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ei={};ue(ei,{base64:()=>Qs,base64pad:()=>Wu,base64url:()=>ju,base64urlpad:()=>Yu});var Qs=ee({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Wu=ee({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ju=ee({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Yu=ee({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ti={};ue(ti,{base8:()=>Zu});var Zu=ee({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ri={};ue(ri,{identity:()=>Ju});var Ju=er({prefix:"\0",name:"identity",encode:r=>Yo(r),decode:r=>jo(r)});var I0=new TextEncoder,R0=new TextDecoder;function ca(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return tf(t,ni(r),e??ce.encoder);default:return rf(t,ni(r),e??Me.encoder)}}var la=new WeakMap;function ni(r){let e=la.get(r);if(e==null){let t=new Map;return la.set(r,t),t}return e}var Pe=class r{code;version;multihash;bytes;"/";constructor(e,t,n,s){this.code=t,this.version=e,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:e,multihash:t}=this;if(e!==Lr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==nf)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}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:e,digest:t}=this.multihash,n=Ge(e,t);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(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&ra(e.multihash,n.multihash)}toString(e){return ca(this,e)}toJSON(){return{"/":ca(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:s,multihash:i,bytes:o}=t;return new r(n,s,i,o??ua(n,s,i.bytes))}else if(t[sf]===!0){let{version:n,multihash:s,code:i}=t,o=Dt(s);return r.create(n,i,o)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==Lr)throw new Error(`Version 0 CID must use dag-pb (code: ${Lr}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let s=ua(e,t,n.bytes);return new r(e,t,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Lr,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,s=tt(e.subarray(n,n+t.multihashSize));if(s.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=s.subarray(t.multihashSize-t.digestSize),o=new nr(t.multihashCode,t.digestSize,i,s);return[t.version===0?r.createV0(o):r.createV1(t.codec,o),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[l,h]=Cr(e.subarray(t));return t+=h,l},s=n(),i=Lr;if(s===18?(s=0,t=0):i=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let o=t,a=n(),c=n(),f=t+c,u=f-o;return{version:s,codec:i,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(e,t){let[n,s]=ef(e,t),i=r.decode(s);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ni(i).set(n,e),i}};function ef(r,e){switch(r[0]){case"Q":{let t=e??ce;return[ce.prefix,t.decode(`${ce.prefix}${r}`)]}case ce.prefix:{let t=e??ce;return[ce.prefix,t.decode(r)]}case Me.prefix:{let t=e??Me;return[Me.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function tf(r,e,t){let{prefix:n}=t;if(n!==ce.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let s=e.get(n);if(s==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return s}function rf(r,e,t){let{prefix:n}=t,s=e.get(n);if(s==null){let i=t.encode(r);return e.set(n,i),i}else return s}var Lr=112,nf=18;function ua(r,e,t){let n=rr(r),s=n+rr(e),i=new Uint8Array(s+t.byteLength);return tr(r,i,0),tr(e,i,n),i.set(t,s),i}var sf=Symbol.for("@ipld/js-cid/CID");var wt={...ri,...Ys,...ti,...Ws,...js,...Js,...Xs,...Ks,...ei,...Zs},$0={...Gs,...qs};function ha(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var fa=ha("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),si=ha("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=Ne(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),of={utf8:fa,"utf-8":fa,hex:wt.base16,latin1:si,ascii:si,binary:si,...wt},pn=of;function G(r,e="utf8"){let t=pn[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function De(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function sr(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function af(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function ir(r,...e){if(!af(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${r.length}`)}function gn(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");sr(r.outputLen),sr(r.blockLen)}function or(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function da(r,e){ir(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var mn=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var cr=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),He=(r,e)=>r<<32-e|r>>>e;var sp=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var cf=async()=>{};async function pa(r,e,t){let n=Date.now();for(let s=0;s<r;s++){t(s);let i=Date.now()-n;i>=0&&i<e||(await cf(),n+=i)}}function ga(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function xt(r){return typeof r=="string"&&(r=ga(r)),ir(r),r}function ii(...r){let e=0;for(let n=0;n<r.length;n++){let s=r[n];ir(s),e+=s.length}let t=new Uint8Array(e);for(let n=0,s=0;n<r.length;n++){let i=r[n];t.set(i,s),s+=i.length}return t}var ar=class{clone(){return this._cloneInto()}},lf={}.toString;function ma(r,e){if(e!==void 0&&lf.call(e)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(r,e)}function yn(r){let e=n=>r().update(xt(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function lr(r=32){if(mn&&typeof mn.getRandomValues=="function")return mn.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function uf(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let s=BigInt(32),i=BigInt(4294967295),o=Number(t>>s&i),a=Number(t&i),c=n?4:0,f=n?0:4;r.setUint32(e+c,o,n),r.setUint32(e+f,a,n)}var ya=(r,e,t)=>r&e^~r&t,ba=(r,e,t)=>r&e^r&t^e&t,ur=class extends ar{constructor(e,t,n,s){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=cr(this.buffer)}update(e){or(this);let{view:t,buffer:n,blockLen:s}=this;e=xt(e);let i=e.length;for(let o=0;o<i;){let a=Math.min(s-this.pos,i-o);if(a===s){let c=cr(e);for(;s<=i-o;o+=s)this.process(c,o);continue}n.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===s&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){or(this),da(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:s,isLE:i}=this,{pos:o}=this;t[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>s-o&&(this.process(n,0),o=0);for(let l=o;l<s;l++)t[l]=0;uf(n,s-8,BigInt(this.length*8),i),this.process(n,0);let a=cr(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)a.setUint32(4*l,u[l],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:s,finished:i,destroyed:o,pos:a}=this;return e.length=s,e.pos=a,e.finished=i,e.destroyed=o,s%t&&e.buffer.set(n),e}};var bn=BigInt(4294967295),oi=BigInt(32);function wa(r,e=!1){return e?{h:Number(r&bn),l:Number(r>>oi&bn)}:{h:Number(r>>oi&bn)|0,l:Number(r&bn)|0}}function ff(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let s=0;s<r.length;s++){let{h:i,l:o}=wa(r[s],e);[t[s],n[s]]=[i,o]}return[t,n]}var hf=(r,e)=>BigInt(r>>>0)<<oi|BigInt(e>>>0),df=(r,e,t)=>r>>>t,pf=(r,e,t)=>r<<32-t|e>>>t,gf=(r,e,t)=>r>>>t|e<<32-t,mf=(r,e,t)=>r<<32-t|e>>>t,yf=(r,e,t)=>r<<64-t|e>>>t-32,bf=(r,e,t)=>r>>>t-32|e<<64-t,wf=(r,e)=>e,xf=(r,e)=>r,vf=(r,e,t)=>r<<t|e>>>32-t,Ef=(r,e,t)=>e<<t|r>>>32-t,Bf=(r,e,t)=>e<<t-32|r>>>64-t,Af=(r,e,t)=>r<<t-32|e>>>64-t;function kf(r,e,t,n){let s=(e>>>0)+(n>>>0);return{h:r+t+(s/2**32|0)|0,l:s|0}}var Sf=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),If=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,Rf=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),Nf=(r,e,t,n,s)=>e+t+n+s+(r/2**32|0)|0,Tf=(r,e,t,n,s)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(s>>>0),_f=(r,e,t,n,s,i)=>e+t+n+s+i+(r/2**32|0)|0;var Cf={fromBig:wa,split:ff,toBig:hf,shrSH:df,shrSL:pf,rotrSH:gf,rotrSL:mf,rotrBH:yf,rotrBL:bf,rotr32H:wf,rotr32L:xf,rotlSH:vf,rotlSL:Ef,rotlBH:Bf,rotlBL:Af,add:kf,add3L:Sf,add3H:If,add4L:Rf,add4H:Nf,add5H:_f,add5L:Tf},U=Cf;var[Lf,Uf]=U.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),vt=new Uint32Array(80),Et=new Uint32Array(80),ai=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:e,Al:t,Bh:n,Bl:s,Ch:i,Cl:o,Dh:a,Dl:c,Eh:f,El:u,Fh:l,Fl:h,Gh:m,Gl:p,Hh:d,Hl:g}=this;return[e,t,n,s,i,o,a,c,f,u,l,h,m,p,d,g]}set(e,t,n,s,i,o,a,c,f,u,l,h,m,p,d,g){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=s|0,this.Ch=i|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=l|0,this.Fl=h|0,this.Gh=m|0,this.Gl=p|0,this.Hh=d|0,this.Hl=g|0}process(e,t){for(let w=0;w<16;w++,t+=4)vt[w]=e.getUint32(t),Et[w]=e.getUint32(t+=4);for(let w=16;w<80;w++){let _=vt[w-15]|0,x=Et[w-15]|0,A=U.rotrSH(_,x,1)^U.rotrSH(_,x,8)^U.shrSH(_,x,7),N=U.rotrSL(_,x,1)^U.rotrSL(_,x,8)^U.shrSL(_,x,7),T=vt[w-2]|0,z=Et[w-2]|0,F=U.rotrSH(T,z,19)^U.rotrBH(T,z,61)^U.shrSH(T,z,6),P=U.rotrSL(T,z,19)^U.rotrBL(T,z,61)^U.shrSL(T,z,6),se=U.add4L(N,P,Et[w-7],Et[w-16]),ne=U.add4H(se,A,F,vt[w-7],vt[w-16]);vt[w]=ne|0,Et[w]=se|0}let{Ah:n,Al:s,Bh:i,Bl:o,Ch:a,Cl:c,Dh:f,Dl:u,Eh:l,El:h,Fh:m,Fl:p,Gh:d,Gl:g,Hh:b,Hl:B}=this;for(let w=0;w<80;w++){let _=U.rotrSH(l,h,14)^U.rotrSH(l,h,18)^U.rotrBH(l,h,41),x=U.rotrSL(l,h,14)^U.rotrSL(l,h,18)^U.rotrBL(l,h,41),A=l&m^~l&d,N=h&p^~h&g,T=U.add5L(B,x,N,Uf[w],Et[w]),z=U.add5H(T,b,_,A,Lf[w],vt[w]),F=T|0,P=U.rotrSH(n,s,28)^U.rotrBH(n,s,34)^U.rotrBH(n,s,39),se=U.rotrSL(n,s,28)^U.rotrBL(n,s,34)^U.rotrBL(n,s,39),ne=n&i^n&a^i&a,Ue=s&o^s&c^o&c;b=d|0,B=g|0,d=m|0,g=p|0,m=l|0,p=h|0,{h:l,l:h}=U.add(f|0,u|0,z|0,F|0),f=a|0,u=c|0,a=i|0,c=o|0,i=n|0,o=s|0;let v=U.add3L(F,se,Ue);n=U.add3H(v,z,P,ne),s=v|0}({h:n,l:s}=U.add(this.Ah|0,this.Al|0,n|0,s|0)),{h:i,l:o}=U.add(this.Bh|0,this.Bl|0,i|0,o|0),{h:a,l:c}=U.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=U.add(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:h}=U.add(this.Eh|0,this.El|0,l|0,h|0),{h:m,l:p}=U.add(this.Fh|0,this.Fl|0,m|0,p|0),{h:d,l:g}=U.add(this.Gh|0,this.Gl|0,d|0,g|0),{h:b,l:B}=U.add(this.Hh|0,this.Hl|0,b|0,B|0),this.set(n,s,i,o,a,c,f,u,l,h,m,p,d,g,b,B)}roundClean(){vt.fill(0),Et.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 Ur=yn(()=>new ai);var xn={};ue(xn,{abytes:()=>fr,bitGet:()=>Kf,bitLen:()=>Hf,bitMask:()=>Pr,bitSet:()=>Ff,bytesToHex:()=>it,bytesToNumberBE:()=>ot,bytesToNumberLE:()=>At,concatBytes:()=>at,createHmacDrbg:()=>ui,ensureBytes:()=>re,equalBytes:()=>Of,hexToBytes:()=>Ot,hexToNumber:()=>li,isBytes:()=>Bt,numberToBytesBE:()=>kt,numberToBytesLE:()=>Mt,numberToHexUnpadded:()=>Ba,numberToVarBytesBE:()=>Vf,utf8ToBytes:()=>Mf,validateObject:()=>We});var Ea=BigInt(0),wn=BigInt(1),Pf=BigInt(2);function Bt(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function fr(r){if(!Bt(r))throw new Error("Uint8Array expected")}var Df=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function it(r){fr(r);let e="";for(let t=0;t<r.length;t++)e+=Df[r[t]];return e}function Ba(r){let e=r.toString(16);return e.length&1?`0${e}`:e}function li(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var st={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function xa(r){if(r>=st._0&&r<=st._9)return r-st._0;if(r>=st._A&&r<=st._F)return r-(st._A-10);if(r>=st._a&&r<=st._f)return r-(st._a-10)}function Ot(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let e=r.length,t=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let s=0,i=0;s<t;s++,i+=2){let o=xa(r.charCodeAt(i)),a=xa(r.charCodeAt(i+1));if(o===void 0||a===void 0){let c=r[i]+r[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[s]=o*16+a}return n}function ot(r){return li(it(r))}function At(r){return fr(r),li(it(Uint8Array.from(r).reverse()))}function kt(r,e){return Ot(r.toString(16).padStart(e*2,"0"))}function Mt(r,e){return kt(r,e).reverse()}function Vf(r){return Ot(Ba(r))}function re(r,e,t){let n;if(typeof e=="string")try{n=Ot(e)}catch(i){throw new Error(`${r} must be valid hex string, got "${e}". Cause: ${i}`)}else if(Bt(e))n=Uint8Array.from(e);else throw new Error(`${r} must be hex string or Uint8Array`);let s=n.length;if(typeof t=="number"&&s!==t)throw new Error(`${r} expected ${t} bytes, got ${s}`);return n}function at(...r){let e=0;for(let n=0;n<r.length;n++){let s=r[n];fr(s),e+=s.length}let t=new Uint8Array(e);for(let n=0,s=0;n<r.length;n++){let i=r[n];t.set(i,s),s+=i.length}return t}function Of(r,e){if(r.length!==e.length)return!1;let t=0;for(let n=0;n<r.length;n++)t|=r[n]^e[n];return t===0}function Mf(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Hf(r){let e;for(e=0;r>Ea;r>>=wn,e+=1);return e}function Kf(r,e){return r>>BigInt(e)&wn}function Ff(r,e,t){return r|(t?wn:Ea)<<BigInt(e)}var Pr=r=>(Pf<<BigInt(r-1))-wn,ci=r=>new Uint8Array(r),va=r=>Uint8Array.from(r);function ui(r,e,t){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof t!="function")throw new Error("hmacFn must be a function");let n=ci(r),s=ci(r),i=0,o=()=>{n.fill(1),s.fill(0),i=0},a=(...l)=>t(s,n,...l),c=(l=ci())=>{s=a(va([0]),l),n=a(),l.length!==0&&(s=a(va([1]),l),n=a())},f=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,h=[];for(;l<e;){n=a();let m=n.slice();h.push(m),l+=n.length}return at(...h)};return(l,h)=>{o(),c(l);let m;for(;!(m=h(f()));)c();return o(),m}}var qf={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"||Bt(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,e)=>e.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function We(r,e,t={}){let n=(s,i,o)=>{let a=qf[i];if(typeof a!="function")throw new Error(`Invalid validator "${i}", expected function`);let c=r[s];if(!(o&&c===void 0)&&!a(c,r))throw new Error(`Invalid param ${String(s)}=${c} (${typeof c}), expected ${i}`)};for(let[s,i]of Object.entries(e))n(s,i,!1);for(let[s,i]of Object.entries(t))n(s,i,!0);return r}var le=BigInt(0),Z=BigInt(1),Ht=BigInt(2),$f=BigInt(3),fi=BigInt(4),Aa=BigInt(5),ka=BigInt(8),zf=BigInt(9),Gf=BigInt(16);function j(r,e){let t=r%e;return t>=le?t:e+t}function Wf(r,e,t){if(t<=le||e<le)throw new Error("Expected power/modulo > 0");if(t===Z)return le;let n=Z;for(;e>le;)e&Z&&(n=n*r%t),r=r*r%t,e>>=Z;return n}function J(r,e,t){let n=r;for(;e-- >le;)n*=n,n%=t;return n}function vn(r,e){if(r===le||e<=le)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=j(r,e),n=e,s=le,i=Z,o=Z,a=le;for(;t!==le;){let f=n/t,u=n%t,l=s-o*f,h=i-a*f;n=t,t=u,s=o,i=a,o=l,a=h}if(n!==Z)throw new Error("invert: does not exist");return j(s,e)}function jf(r){let e=(r-Z)/Ht,t,n,s;for(t=r-Z,n=0;t%Ht===le;t/=Ht,n++);for(s=Ht;s<r&&Wf(s,e,r)!==r-Z;s++);if(n===1){let o=(r+Z)/fi;return function(c,f){let u=c.pow(f,o);if(!c.eql(c.sqr(u),f))throw new Error("Cannot find square root");return u}}let i=(t+Z)/Ht;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let f=n,u=a.pow(a.mul(a.ONE,s),t),l=a.pow(c,i),h=a.pow(c,t);for(;!a.eql(h,a.ONE);){if(a.eql(h,a.ZERO))return a.ZERO;let m=1;for(let d=a.sqr(h);m<f&&!a.eql(d,a.ONE);m++)d=a.sqr(d);let p=a.pow(u,Z<<BigInt(f-m-1));u=a.sqr(p),l=a.mul(l,p),h=a.mul(h,u),f=m}return l}}function Yf(r){if(r%fi===$f){let e=(r+Z)/fi;return function(n,s){let i=n.pow(s,e);if(!n.eql(n.sqr(i),s))throw new Error("Cannot find square root");return i}}if(r%ka===Aa){let e=(r-Aa)/ka;return function(n,s){let i=n.mul(s,Ht),o=n.pow(i,e),a=n.mul(s,o),c=n.mul(n.mul(a,Ht),o),f=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(f),s))throw new Error("Cannot find square root");return f}}return r%Gf,jf(r)}var Sa=(r,e)=>(j(r,e)&Z)===Z,Zf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function hi(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=Zf.reduce((n,s)=>(n[s]="function",n),e);return We(r,t)}function Jf(r,e,t){if(t<le)throw new Error("Expected power > 0");if(t===le)return r.ONE;if(t===Z)return e;let n=r.ONE,s=e;for(;t>le;)t&Z&&(n=r.mul(n,s)),s=r.sqr(s),t>>=Z;return n}function Xf(r,e){let t=new Array(e.length),n=e.reduce((i,o,a)=>r.is0(o)?i:(t[a]=i,r.mul(i,o)),r.ONE),s=r.inv(n);return e.reduceRight((i,o,a)=>r.is0(o)?i:(t[a]=r.mul(i,t[a]),r.mul(i,o)),s),t}function di(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function En(r,e,t=!1,n={}){if(r<=le)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:s,nByteLength:i}=di(r,e);if(i>2048)throw new Error("Field lengths over 2048 bytes are not supported");let o=Yf(r),a=Object.freeze({ORDER:r,BITS:s,BYTES:i,MASK:Pr(s),ZERO:le,ONE:Z,create:c=>j(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return le<=c&&c<r},is0:c=>c===le,isOdd:c=>(c&Z)===Z,neg:c=>j(-c,r),eql:(c,f)=>c===f,sqr:c=>j(c*c,r),add:(c,f)=>j(c+f,r),sub:(c,f)=>j(c-f,r),mul:(c,f)=>j(c*f,r),pow:(c,f)=>Jf(a,c,f),div:(c,f)=>j(c*vn(f,r),r),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>vn(c,r),sqrt:n.sqrt||(c=>o(a,c)),invertBatch:c=>Xf(a,c),cmov:(c,f,u)=>u?f:c,toBytes:c=>t?Mt(c,i):kt(c,i),fromBytes:c=>{if(c.length!==i)throw new Error(`Fp.fromBytes: expected ${i}, got ${c.length}`);return t?At(c):ot(c)}});return Object.freeze(a)}function Ia(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let e=r.toString(2).length;return Math.ceil(e/8)}function pi(r){let e=Ia(r);return e+Math.ceil(e/2)}function Ra(r,e,t=!1){let n=r.length,s=Ia(e),i=pi(e);if(n<16||n<i||n>1024)throw new Error(`expected ${i}-1024 bytes of input, got ${n}`);let o=t?ot(r):At(r),a=j(o,e-Z)+Z;return t?Mt(a,s):kt(a,s)}var eh=BigInt(0),gi=BigInt(1);function Bn(r,e){let t=(s,i)=>{let o=i.negate();return s?o:i},n=s=>{let i=Math.ceil(e/s)+1,o=2**(s-1);return{windows:i,windowSize:o}};return{constTimeNegate:t,unsafeLadder(s,i){let o=r.ZERO,a=s;for(;i>eh;)i&gi&&(o=o.add(a)),a=a.double(),i>>=gi;return o},precomputeWindow(s,i){let{windows:o,windowSize:a}=n(i),c=[],f=s,u=f;for(let l=0;l<o;l++){u=f,c.push(u);for(let h=1;h<a;h++)u=u.add(f),c.push(u);f=u.double()}return c},wNAF(s,i,o){let{windows:a,windowSize:c}=n(s),f=r.ZERO,u=r.BASE,l=BigInt(2**s-1),h=2**s,m=BigInt(s);for(let p=0;p<a;p++){let d=p*c,g=Number(o&l);o>>=m,g>c&&(g-=h,o+=gi);let b=d,B=d+Math.abs(g)-1,w=p%2!==0,_=g<0;g===0?u=u.add(t(w,i[b])):f=f.add(t(_,i[B]))}return{p:f,f:u}},wNAFCached(s,i,o,a){let c=s._WINDOW_SIZE||1,f=i.get(s);return f||(f=this.precomputeWindow(s,c),c!==1&&i.set(s,a(f))),this.wNAF(c,f,o)}}}function Dr(r){return hi(r.Fp),We(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...di(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Ke=BigInt(0),Ce=BigInt(1),An=BigInt(2),th=BigInt(8),rh={zip215:!0};function nh(r){let e=Dr(r);return We(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function Na(r){let e=nh(r),{Fp:t,n,prehash:s,hash:i,randomBytes:o,nByteLength:a,h:c}=e,f=An<<BigInt(a*8)-Ce,u=t.create,l=e.uvRatio||((E,y)=>{try{return{isValid:!0,value:t.sqrt(E*t.inv(y))}}catch{return{isValid:!1,value:Ke}}}),h=e.adjustScalarBytes||(E=>E),m=e.domain||((E,y,S)=>{if(y.length||S)throw new Error("Contexts/pre-hash are not supported");return E}),p=E=>typeof E=="bigint"&&Ke<E,d=(E,y)=>p(E)&&p(y)&&E<y,g=E=>E===Ke||d(E,f);function b(E,y){if(d(E,y))return E;throw new Error(`Expected valid scalar < ${y}, got ${typeof E} ${E}`)}function B(E){return E===Ke?E:b(E,n)}let w=new Map;function _(E){if(!(E instanceof x))throw new Error("ExtendedPoint expected")}class x{constructor(y,S,C,L){if(this.ex=y,this.ey=S,this.ez=C,this.et=L,!g(y))throw new Error("x required");if(!g(S))throw new Error("y required");if(!g(C))throw new Error("z required");if(!g(L))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(y){if(y instanceof x)throw new Error("extended point not allowed");let{x:S,y:C}=y||{};if(!g(S)||!g(C))throw new Error("invalid affine point");return new x(S,C,Ce,u(S*C))}static normalizeZ(y){let S=t.invertBatch(y.map(C=>C.ez));return y.map((C,L)=>C.toAffine(S[L])).map(x.fromAffine)}_setWindowSize(y){this._WINDOW_SIZE=y,w.delete(this)}assertValidity(){let{a:y,d:S}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:C,ey:L,ez:V,et:O}=this,$=u(C*C),K=u(L*L),q=u(V*V),ie=u(q*q),Q=u($*y),he=u(q*u(Q+K)),de=u(ie+u(S*u($*K)));if(he!==de)throw new Error("bad point: equation left != right (1)");let ae=u(C*L),ye=u(V*O);if(ae!==ye)throw new Error("bad point: equation left != right (2)")}equals(y){_(y);let{ex:S,ey:C,ez:L}=this,{ex:V,ey:O,ez:$}=y,K=u(S*$),q=u(V*L),ie=u(C*$),Q=u(O*L);return K===q&&ie===Q}is0(){return this.equals(x.ZERO)}negate(){return new x(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:y}=e,{ex:S,ey:C,ez:L}=this,V=u(S*S),O=u(C*C),$=u(An*u(L*L)),K=u(y*V),q=S+C,ie=u(u(q*q)-V-O),Q=K+O,he=Q-$,de=K-O,ae=u(ie*he),ye=u(Q*de),et=u(ie*de),Pt=u(he*Q);return new x(ae,ye,Pt,et)}add(y){_(y);let{a:S,d:C}=e,{ex:L,ey:V,ez:O,et:$}=this,{ex:K,ey:q,ez:ie,et:Q}=y;if(S===BigInt(-1)){let Do=u((V-L)*(q+K)),Vo=u((V+L)*(q-K)),Ds=u(Vo-Do);if(Ds===Ke)return this.double();let Oo=u(O*An*Q),Mo=u($*An*ie),Ho=Mo+Oo,Ko=Vo+Do,Fo=Mo-Oo,zl=u(Ho*Ds),Gl=u(Ko*Fo),Wl=u(Ho*Fo),jl=u(Ds*Ko);return new x(zl,Gl,jl,Wl)}let he=u(L*K),de=u(V*q),ae=u($*C*Q),ye=u(O*ie),et=u((L+V)*(K+q)-he-de),Pt=ye-ae,Tr=ye+ae,Po=u(de-S*he),Kl=u(et*Pt),Fl=u(Tr*Po),ql=u(et*Po),$l=u(Pt*Tr);return new x(Kl,Fl,$l,ql)}subtract(y){return this.add(y.negate())}wNAF(y){return T.wNAFCached(this,w,y,x.normalizeZ)}multiply(y){let{p:S,f:C}=this.wNAF(b(y,n));return x.normalizeZ([S,C])[0]}multiplyUnsafe(y){let S=B(y);return S===Ke?N:this.equals(N)||S===Ce?this:this.equals(A)?this.wNAF(S).p:T.unsafeLadder(this,S)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return T.unsafeLadder(this,n).is0()}toAffine(y){let{ex:S,ey:C,ez:L}=this,V=this.is0();y==null&&(y=V?th:t.inv(L));let O=u(S*y),$=u(C*y),K=u(L*y);if(V)return{x:Ke,y:Ce};if(K!==Ce)throw new Error("invZ was invalid");return{x:O,y:$}}clearCofactor(){let{h:y}=e;return y===Ce?this:this.multiplyUnsafe(y)}static fromHex(y,S=!1){let{d:C,a:L}=e,V=t.BYTES;y=re("pointHex",y,V);let O=y.slice(),$=y[V-1];O[V-1]=$&-129;let K=At(O);K===Ke||(S?b(K,f):b(K,t.ORDER));let q=u(K*K),ie=u(q-Ce),Q=u(C*q-L),{isValid:he,value:de}=l(ie,Q);if(!he)throw new Error("Point.fromHex: invalid y coordinate");let ae=(de&Ce)===Ce,ye=($&128)!==0;if(!S&&de===Ke&&ye)throw new Error("Point.fromHex: x=0 and x_0=1");return ye!==ae&&(de=u(-de)),x.fromAffine({x:de,y:K})}static fromPrivateKey(y){return P(y).point}toRawBytes(){let{x:y,y:S}=this.toAffine(),C=Mt(S,t.BYTES);return C[C.length-1]|=y&Ce?128:0,C}toHex(){return it(this.toRawBytes())}}x.BASE=new x(e.Gx,e.Gy,Ce,u(e.Gx*e.Gy)),x.ZERO=new x(Ke,Ce,Ce,Ke);let{BASE:A,ZERO:N}=x,T=Bn(x,a*8);function z(E){return j(E,n)}function F(E){return z(At(E))}function P(E){let y=a;E=re("private key",E,y);let S=re("hashed private key",i(E),2*y),C=h(S.slice(0,y)),L=S.slice(y,2*y),V=F(C),O=A.multiply(V),$=O.toRawBytes();return{head:C,prefix:L,scalar:V,point:O,pointBytes:$}}function se(E){return P(E).pointBytes}function ne(E=new Uint8Array,...y){let S=at(...y);return F(i(m(S,re("context",E),!!s)))}function Ue(E,y,S={}){E=re("message",E),s&&(E=s(E));let{prefix:C,scalar:L,pointBytes:V}=P(y),O=ne(S.context,C,E),$=A.multiply(O).toRawBytes(),K=ne(S.context,$,V,E),q=z(O+K*L);B(q);let ie=at($,Mt(q,t.BYTES));return re("result",ie,a*2)}let v=rh;function I(E,y,S,C=v){let{context:L,zip215:V}=C,O=t.BYTES;E=re("signature",E,2*O),y=re("message",y),s&&(y=s(y));let $=At(E.slice(O,2*O)),K,q,ie;try{K=x.fromHex(S,V),q=x.fromHex(E.slice(0,O),V),ie=A.multiplyUnsafe($)}catch{return!1}if(!V&&K.isSmallOrder())return!1;let Q=ne(L,q.toRawBytes(),K.toRawBytes(),y);return q.add(K.multiplyUnsafe(Q)).subtract(ie).clearCofactor().equals(x.ZERO)}return A._setWindowSize(8),{CURVE:e,getPublicKey:se,sign:Ue,verify:I,ExtendedPoint:x,utils:{getExtendedPublicKey:P,randomPrivateKey:()=>o(t.BYTES),precompute(E=8,y=x.BASE){return y._setWindowSize(E),y.multiply(BigInt(3)),y}}}}var mi=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Ta=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Ip=BigInt(0),sh=BigInt(1),_a=BigInt(2),Rp=BigInt(3),ih=BigInt(5),oh=BigInt(8);function ah(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),s=BigInt(80),i=mi,a=r*r%i*r%i,c=J(a,_a,i)*a%i,f=J(c,sh,i)*r%i,u=J(f,ih,i)*f%i,l=J(u,e,i)*u%i,h=J(l,t,i)*l%i,m=J(h,n,i)*h%i,p=J(m,s,i)*m%i,d=J(p,s,i)*m%i,g=J(d,e,i)*u%i;return{pow_p_5_8:J(g,_a,i)*r%i,b2:a}}function ch(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function lh(r,e){let t=mi,n=j(e*e*e,t),s=j(n*n*e,t),i=ah(r*s).pow_p_5_8,o=j(r*n*i,t),a=j(e*o*o,t),c=o,f=j(o*Ta,t),u=a===r,l=a===j(-r,t),h=a===j(-r*Ta,t);return u&&(o=c),(l||h)&&(o=f),Sa(o,t)&&(o=j(-o,t)),{isValid:u||l,value:o}}var uh=En(mi,void 0,!0),fh={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:uh,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:oh,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Ur,randomBytes:lr,adjustScalarBytes:ch,uvRatio:lh},hr=Na(fh);var dr=32,ct=64,kn=32;function Ca(){let r=hr.utils.randomPrivateKey(),e=hr.getPublicKey(r);return{privateKey:Da(r,e),publicKey:e}}function La(r){if(r.length!==kn)throw new TypeError('"seed" must be 32 bytes in length.');if(!(r instanceof Uint8Array))throw new TypeError('"seed" must be a node.js Buffer, or Uint8Array.');let e=r,t=hr.getPublicKey(e);return{privateKey:Da(e,t),publicKey:t}}function Ua(r,e){let t=r.subarray(0,kn);return hr.sign(e instanceof Uint8Array?e:e.subarray(),t)}function Pa(r,e,t){return hr.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}function Da(r,e){let t=new Uint8Array(ct);for(let n=0;n<kn;n++)t[n]=r[n],t[kn+n]=e[n];return t}var Be={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw Object.assign(new Error("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api"),{code:"ERR_MISSING_WEB_CRYPTO"});return e}};var yi={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function Va(r){let e=r?.algorithm??"AES-GCM",t=r?.keyLength??16,n=r?.nonceLength??12,s=r?.digest??"SHA-256",i=r?.saltLength??16,o=r?.iterations??32767,a=Be.get();t*=8;async function c(l,h){let m=a.getRandomValues(new Uint8Array(i)),p=a.getRandomValues(new Uint8Array(n)),d={name:e,iv:p};typeof h=="string"&&(h=G(h));let g;if(h.length===0){g=await a.subtle.importKey("jwk",yi,{name:"AES-GCM"},!0,["encrypt"]);try{let B={name:"PBKDF2",salt:m,iterations:o,hash:{name:s}},w=await a.subtle.importKey("raw",h,{name:"PBKDF2"},!1,["deriveKey"]);g=await a.subtle.deriveKey(B,w,{name:e,length:t},!0,["encrypt"])}catch{g=await a.subtle.importKey("jwk",yi,{name:"AES-GCM"},!0,["encrypt"])}}else{let B={name:"PBKDF2",salt:m,iterations:o,hash:{name:s}},w=await a.subtle.importKey("raw",h,{name:"PBKDF2"},!1,["deriveKey"]);g=await a.subtle.deriveKey(B,w,{name:e,length:t},!0,["encrypt"])}let b=await a.subtle.encrypt(d,g,l);return Ee([m,d.iv,new Uint8Array(b)])}async function f(l,h){let m=l.subarray(0,i),p=l.subarray(i,i+n),d=l.subarray(i+n),g={name:e,iv:p};typeof h=="string"&&(h=G(h));let b;if(h.length===0)try{let w={name:"PBKDF2",salt:m,iterations:o,hash:{name:s}},_=await a.subtle.importKey("raw",h,{name:"PBKDF2"},!1,["deriveKey"]);b=await a.subtle.deriveKey(w,_,{name:e,length:t},!0,["decrypt"])}catch{b=await a.subtle.importKey("jwk",yi,{name:"AES-GCM"},!0,["decrypt"])}else{let w={name:"PBKDF2",salt:m,iterations:o,hash:{name:s}},_=await a.subtle.importKey("raw",h,{name:"PBKDF2"},!1,["deriveKey"]);b=await a.subtle.deriveKey(w,_,{name:e,length:t},!0,["decrypt"])}let B=await a.subtle.decrypt(g,b,d);return new Uint8Array(B)}return{encrypt:c,decrypt:f}}async function pr(r,e){let n=await Va().encrypt(r,e);return Qs.encode(n)}var ph=Math.pow(2,7),gh=Math.pow(2,14),mh=Math.pow(2,21),bi=Math.pow(2,28),wi=Math.pow(2,35),xi=Math.pow(2,42),vi=Math.pow(2,49),W=128,be=127;function Te(r){if(r<ph)return 1;if(r<gh)return 2;if(r<mh)return 3;if(r<bi)return 4;if(r<wi)return 5;if(r<xi)return 6;if(r<vi)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ei(r,e,t=0){switch(Te(r)){case 8:e[t++]=r&255|W,r/=128;case 7:e[t++]=r&255|W,r/=128;case 6:e[t++]=r&255|W,r/=128;case 5:e[t++]=r&255|W,r/=128;case 4:e[t++]=r&255|W,r>>>=7;case 3:e[t++]=r&255|W,r>>>=7;case 2:e[t++]=r&255|W,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function yh(r,e,t=0){switch(Te(r)){case 8:e.set(t++,r&255|W),r/=128;case 7:e.set(t++,r&255|W),r/=128;case 6:e.set(t++,r&255|W),r/=128;case 5:e.set(t++,r&255|W),r/=128;case 4:e.set(t++,r&255|W),r>>>=7;case 3:e.set(t++,r&255|W),r>>>=7;case 2:e.set(t++,r&255|W),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Bi(r,e){let t=r[e],n=0;if(n+=t&be,t<W||(t=r[e+1],n+=(t&be)<<7,t<W)||(t=r[e+2],n+=(t&be)<<14,t<W)||(t=r[e+3],n+=(t&be)<<21,t<W)||(t=r[e+4],n+=(t&be)*bi,t<W)||(t=r[e+5],n+=(t&be)*wi,t<W)||(t=r[e+6],n+=(t&be)*xi,t<W)||(t=r[e+7],n+=(t&be)*vi,t<W))return n;throw new RangeError("Could not decode varint")}function bh(r,e){let t=r.get(e),n=0;if(n+=t&be,t<W||(t=r.get(e+1),n+=(t&be)<<7,t<W)||(t=r.get(e+2),n+=(t&be)<<14,t<W)||(t=r.get(e+3),n+=(t&be)<<21,t<W)||(t=r.get(e+4),n+=(t&be)*bi,t<W)||(t=r.get(e+5),n+=(t&be)*wi,t<W)||(t=r.get(e+6),n+=(t&be)*xi,t<W)||(t=r.get(e+7),n+=(t&be)*vi,t<W))return n;throw new RangeError("Could not decode varint")}function je(r,e,t=0){return e==null&&(e=Ne(Te(r))),e instanceof Uint8Array?Ei(r,e,t):yh(r,e,t)}function Kt(r,e=0){return r instanceof Uint8Array?Bi(r,e):bh(r,e)}var ki=new Float32Array([-0]),St=new Uint8Array(ki.buffer);function Oa(r,e,t){ki[0]=r,e[t]=St[0],e[t+1]=St[1],e[t+2]=St[2],e[t+3]=St[3]}function Ma(r,e){return St[0]=r[e],St[1]=r[e+1],St[2]=r[e+2],St[3]=r[e+3],ki[0]}var Si=new Float64Array([-0]),we=new Uint8Array(Si.buffer);function Ha(r,e,t){Si[0]=r,e[t]=we[0],e[t+1]=we[1],e[t+2]=we[2],e[t+3]=we[3],e[t+4]=we[4],e[t+5]=we[5],e[t+6]=we[6],e[t+7]=we[7]}function Ka(r,e){return we[0]=r[e],we[1]=r[e+1],we[2]=r[e+2],we[3]=r[e+3],we[4]=r[e+4],we[5]=r[e+5],we[6]=r[e+6],we[7]=r[e+7],Si[0]}var wh=BigInt(Number.MAX_SAFE_INTEGER),xh=BigInt(Number.MIN_SAFE_INTEGER),Le=class r{lo;hi;constructor(e,t){this.lo=e|0,this.hi=t|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(t+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(BigInt(t)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Ft;if(e<wh&&e>xh)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,s=e-(n<<32n);return t&&(n=~n|0n,s=~s|0n,++s>Fa&&(s=0n,++n>Fa&&(n=0n))),new r(Number(s),Number(n))}static fromNumber(e){if(e===0)return Ft;let t=e<0;t&&(e=-e);let n=e>>>0,s=(e-n)/4294967296>>>0;return t&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new r(n,s)}static from(e){return typeof e=="number"?r.fromNumber(e):typeof e=="bigint"?r.fromBigInt(e):typeof e=="string"?r.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new r(e.low>>>0,e.high>>>0):Ft}},Ft=new Le(0,0);Ft.toBigInt=function(){return 0n};Ft.zzEncode=Ft.zzDecode=function(){return this};Ft.length=function(){return 1};var Fa=4294967296n;function qa(r){let e=0,t=0;for(let n=0;n<r.length;++n)t=r.charCodeAt(n),t<128?e+=1:t<2048?e+=2:(t&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function $a(r,e,t){if(t-e<1)return"";let s,i=[],o=0,a;for(;e<t;)a=r[e++],a<128?i[o++]=a:a>191&&a<224?i[o++]=(a&31)<<6|r[e++]&63:a>239&&a<365?(a=((a&7)<<18|(r[e++]&63)<<12|(r[e++]&63)<<6|r[e++]&63)-65536,i[o++]=55296+(a>>10),i[o++]=56320+(a&1023)):i[o++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,o>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,i)),o=0);return s!=null?(o>0&&s.push(String.fromCharCode.apply(String,i.slice(0,o))),s.join("")):String.fromCharCode.apply(String,i.slice(0,o))}function Ii(r,e,t){let n=t,s,i;for(let o=0;o<r.length;++o)s=r.charCodeAt(o),s<128?e[t++]=s:s<2048?(e[t++]=s>>6|192,e[t++]=s&63|128):(s&64512)===55296&&((i=r.charCodeAt(o+1))&64512)===56320?(s=65536+((s&1023)<<10)+(i&1023),++o,e[t++]=s>>18|240,e[t++]=s>>12&63|128,e[t++]=s>>6&63|128,e[t++]=s&63|128):(e[t++]=s>>12|224,e[t++]=s>>6&63|128,e[t++]=s&63|128);return t-n}function Fe(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function Sn(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Ri=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Fe(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Fe(this,4);return Sn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Fe(this,4);return Sn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Fe(this,4);let e=Ma(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Fe(this,4);let e=Ka(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),t=this.pos,n=this.pos+e;if(n>this.len)throw Fe(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return $a(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Fe(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Fe(this);while(this.buf[this.pos++]&128);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Le(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw Fe(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<t*7)>>>0,e}if(this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw Fe(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Fe(this,8);let e=Sn(this.buf,this.pos+=4),t=Sn(this.buf,this.pos+=4);return new Le(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Bi(this.buf,this.pos);return this.pos+=Te(e),e}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 Ni(r){return new Ri(r instanceof Uint8Array?r:r.subarray())}function Ae(r,e,t){let n=Ni(r);return e.decode(n,void 0,t)}function Ti(r){let e=r??8192,t=e>>>1,n,s=e;return function(o){if(o<1||o>t)return Ne(o);s+o>e&&(n=Ne(e),s=0);let a=n.subarray(s,s+=o);return s&7&&(s=(s|7)+1),a}}var qt=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function _i(){}var Li=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},vh=Ti();function Eh(r){return globalThis.Buffer!=null?Ne(r):vh(r)}var Or=class{len;head;tail;states;constructor(){this.len=0,this.head=new qt(_i,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new qt(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Ui((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(In,10,Le.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=Le.fromBigInt(e);return this._push(In,t.length(),t)}uint64Number(e){return this._push(Ei,Te(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=Le.fromBigInt(e).zzEncode();return this._push(In,t.length(),t)}sint64Number(e){let t=Le.fromNumber(e).zzEncode();return this._push(In,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Ci,1,e?1:0)}fixed32(e){return this._push(Vr,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=Le.fromBigInt(e);return this._push(Vr,4,t.lo)._push(Vr,4,t.hi)}fixed64Number(e){let t=Le.fromNumber(e);return this._push(Vr,4,t.lo)._push(Vr,4,t.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(Oa,4,e)}double(e){return this._push(Ha,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Ci,1,0):this.uint32(t)._push(Ah,t,e)}string(e){let t=qa(e);return t!==0?this.uint32(t)._push(Ii,t,e):this._push(Ci,1,0)}fork(){return this.states=new Li(this),this.head=this.tail=new qt(_i,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 qt(_i,0,0),this.len=0),this}ldelim(){let e=this.head,t=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=t,this.len+=n),this}finish(){let e=this.head.next,t=Eh(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function Ci(r,e,t){e[t]=r&255}function Bh(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var Ui=class extends qt{next;constructor(e,t){super(Bh,e,t),this.next=void 0}};function In(r,e,t){for(;r.hi!==0;)e[t++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)e[t++]=r.lo&127|128,r.lo=r.lo>>>7;e[t++]=r.lo}function Vr(r,e,t){e[t]=r&255,e[t+1]=r>>>8&255,e[t+2]=r>>>16&255,e[t+3]=r>>>24}function Ah(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(Or.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(kh,e,r),this},Or.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(Sh,e,r),this});function kh(r,e,t){e.set(r,t)}function Sh(r,e,t){r.length<40?Ii(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(G(r),t)}function Pi(){return new Or}function ke(r,e){let t=Pi();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var gr;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(gr||(gr={}));function Rn(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function Di(r){function e(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let t=function(i,o){let a=e(i);o.int32(a)},n=function(i){let o=i.int32();return e(o)};return Rn("enum",gr.VARINT,t,n)}function Se(r,e){return Rn("message",gr.LENGTH_DELIMITED,r,e)}var X;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1"})(X||(X={}));var Vi;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1"})(Vi||(Vi={}));(function(r){r.codec=()=>Di(Vi)})(X||(X={}));var Ye;(function(r){let e;r.codec=()=>(e==null&&(e=Se((t,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),X.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),s.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let s={},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let o=t.uint32();switch(o>>>3){case 1:s.Type=X.codec().decode(t);break;case 2:s.Data=t.bytes();break;default:t.skipType(o&7);break}}return s})),e),r.encode=t=>ke(t,r.codec()),r.decode=t=>Ae(t,r.codec())})(Ye||(Ye={}));var Ze;(function(r){let e;r.codec=()=>(e==null&&(e=Se((t,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),X.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),s.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let s={},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let o=t.uint32();switch(o>>>3){case 1:s.Type=X.codec().decode(t);break;case 2:s.Data=t.bytes();break;default:t.skipType(o&7);break}}return s})),e),r.encode=t=>ke(t,r.codec()),r.decode=t=>Ae(t,r.codec())})(Ze||(Ze={}));var Mr=class{_key;constructor(e){this._key=mr(e,dr)}verify(e,t){return Pa(this._key,t,e)}marshal(){return this._key}get bytes(){return Ye.encode({Type:X.Ed25519,Data:this.marshal()}).subarray()}equals(e){return te(this.bytes,e.bytes)}hash(){let e=pe.digest(this.bytes);return De(e)?e.then(({bytes:t})=>t):e.bytes}},$t=class{_key;_publicKey;constructor(e,t){this._key=mr(e,ct),this._publicKey=mr(t,dr)}sign(e){return Ua(this._key,e)}get public(){return new Mr(this._publicKey)}marshal(){return this._key}get bytes(){return Ze.encode({Type:X.Ed25519,Data:this.marshal()}).subarray()}equals(e){return te(this.bytes,e.bytes)}async hash(){let e=pe.digest(this.bytes),t;return De(e)?{bytes:t}=await e:t=e.bytes,t}async id(){let e=rt.digest(this.public.bytes);return ce.encode(e.bytes).substring(1)}async export(e,t="libp2p-key"){if(t==="libp2p-key")return pr(this.bytes,e);throw new R(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function Ih(r){if(r.length>ct){r=mr(r,ct+dr);let n=r.subarray(0,ct),s=r.subarray(ct,r.length);return new $t(n,s)}r=mr(r,ct);let e=r.subarray(0,ct),t=r.subarray(dr);return new $t(e,t)}function Rh(r){return r=mr(r,dr),new Mr(r)}async function Nh(){let{privateKey:r,publicKey:e}=Ca();return new $t(r,e)}async function Ga(r){let{privateKey:e,publicKey:t}=La(r);return new $t(e,t)}function mr(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new R(`Key must be a Uint8Array of length ${e}, got ${r.length}`,"ERR_INVALID_KEY_TYPE");return r}function M(r,e="utf8"){let t=pn[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var ji={};ue(ji,{MAX_RSA_KEY_SIZE:()=>Jr,RsaPrivateKey:()=>vr,RsaPublicKey:()=>Zr,fromJwk:()=>rd,generateKeyPair:()=>nd,unmarshalRsaPrivateKey:()=>Gi,unmarshalRsaPublicKey:()=>td});function zt(r){if(isNaN(r)||r<=0)throw new R("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return lr(r)}var Tt={};ue(Tt,{exportToPem:()=>Zh,importFromPem:()=>Jh,jwkToPkcs1:()=>Gh,jwkToPkix:()=>jh,pkcs1ToJwk:()=>zh,pkixToJwk:()=>Wh});var Tn=class extends ar{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,gn(e);let n=xt(t);if(this.iHash=e.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,i=new Uint8Array(s);i.set(n.length>s?e.create().update(n).digest():n);for(let o=0;o<i.length;o++)i[o]^=54;this.iHash.update(i),this.oHash=e.create();for(let o=0;o<i.length;o++)i[o]^=106;this.oHash.update(i),i.fill(0)}update(e){return or(this),this.iHash.update(e),this}digestInto(e){or(this),ir(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:t,iHash:n,finished:s,destroyed:i,blockLen:o,outputLen:a}=this;return e=e,e.finished=s,e.destroyed=i,e.blockLen=o,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Hr=(r,e,t)=>new Tn(r,e).update(t).digest();Hr.create=(r,e)=>new Tn(r,e);function Th(r,e,t,n){gn(r);let s=ma({dkLen:32,asyncTick:10},n),{c:i,dkLen:o,asyncTick:a}=s;if(sr(i),sr(o),sr(a),i<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=xt(e),f=xt(t),u=new Uint8Array(o),l=Hr.create(r,c),h=l._cloneInto().update(f);return{c:i,dkLen:o,asyncTick:a,DK:u,PRF:l,PRFSalt:h}}function _h(r,e,t,n,s){return r.destroy(),e.destroy(),n&&n.destroy(),s.fill(0),t}async function Mi(r,e,t,n){let{c:s,dkLen:i,asyncTick:o,DK:a,PRF:c,PRFSalt:f}=Th(r,e,t,n),u,l=new Uint8Array(4),h=cr(l),m=new Uint8Array(c.outputLen);for(let p=1,d=0;d<i;p++,d+=c.outputLen){let g=a.subarray(d,d+c.outputLen);h.setInt32(0,p,!1),(u=f._cloneInto(u)).update(l).digestInto(m),g.set(m.subarray(0,g.length)),await pa(s-1,o,()=>{c._cloneInto(u).update(m).digestInto(m);for(let b=0;b<g.length;b++)g[b]^=m[b]})}return _h(c,f,a,u,m)}var H=zo(Wa());function Gt(r,e){let t=0;if(r.length===1)return r[0];for(let n=r.length-1;n>=0;n--)t+=r[r.length-1-n]*Math.pow(2,e*n);return t}function It(r,e,t=-1){let n=t,s=r,i=0,o=Math.pow(2,e);for(let a=1;a<8;a++){if(r<o){let c;if(n<0)c=new ArrayBuffer(a),i=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),i=n}let f=new Uint8Array(c);for(let u=a-1;u>=0;u--){let l=Math.pow(2,u*e);f[i-u-1]=Math.floor(s/l),s-=f[i-u-1]*l}return c}o*=Math.pow(2,e)}return new ArrayBuffer(0)}function Ln(...r){let e=0,t=0;for(let i of r)e+=i.length;let n=new ArrayBuffer(e),s=new Uint8Array(n);for(let i of r)s.set(i,t),t+=i.length;return s}function Ki(){let r=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){let a=r[0]===255&&r[1]&128,c=r[0]===0&&(r[1]&128)===0;(a||c)&&this.warnings.push("Needlessly long format")}let e=new ArrayBuffer(this.valueHex.byteLength),t=new Uint8Array(e);for(let a=0;a<this.valueHex.byteLength;a++)t[a]=0;t[0]=r[0]&128;let n=Gt(t,8),s=new ArrayBuffer(this.valueHex.byteLength),i=new Uint8Array(s);for(let a=0;a<this.valueHex.byteLength;a++)i[a]=r[a];return i[0]&=127,Gt(i,8)-n}function ja(r){let e=r<0?r*-1:r,t=128;for(let n=1;n<8;n++){if(e<=t){if(r<0){let o=t-e,a=It(o,8,n),c=new Uint8Array(a);return c[0]|=128,a}let s=It(e,8,n),i=new Uint8Array(s);if(i[0]&128){let o=s.slice(0),a=new Uint8Array(o);s=new ArrayBuffer(s.byteLength+1),i=new Uint8Array(s);for(let c=0;c<o.byteLength;c++)i[c+1]=a[c];i[0]=0}return s}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function Ya(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let s=0;s<t.length;s++)if(t[s]!==n[s])return!1;return!0}function _e(r,e){let t=r.toString(10);if(e<t.length)return"";let n=e-t.length,s=new Array(n);for(let o=0;o<n;o++)s[o]="0";return s.join("").concat(t)}var Dg=Math.log(2);function Un(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Fi(r){let e=0,t=0;for(let s=0;s<r.length;s++){let i=r[s];e+=i.byteLength}let n=new Uint8Array(e);for(let s=0;s<r.length;s++){let i=r[s];n.set(new Uint8Array(i),t),t+=i.byteLength}return n.buffer}function dt(r,e,t,n){return e instanceof Uint8Array?e.byteLength?t<0?(r.error="Wrong parameter: inputOffset less than zero",!1):n<0?(r.error="Wrong parameter: inputLength less than zero",!1):e.byteLength-t-n<0?(r.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):!0:(r.error="Wrong parameter: inputBuffer has zero length",!1):(r.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}var Fr=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return Fi(this.items)}},Kr=[new Uint8Array([1])],Za="0123456789";var wr="",$e=new ArrayBuffer(0),qi=new Uint8Array(0),qr="EndOfContent",Xa="OCTET STRING",Qa="BIT STRING";function pt(r){var e;return e=class extends r{constructor(...n){var s;super(...n);let i=n[0]||{};this.isHexOnly=(s=i.isHexOnly)!==null&&s!==void 0?s:!1,this.valueHexView=i.valueHex?H.BufferSourceConverter.toUint8Array(i.valueHex):qi}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}fromBER(n,s,i){let o=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!dt(this,o,s,i))return-1;let a=s+i;return this.valueHexView=o.subarray(s,a),this.valueHexView.length?(this.blockLength=i,a):(this.warnings.push("Zero buffer length"),s)}toBER(n=!1){return this.isHexOnly?n?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",$e)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:H.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var ut=class{constructor({blockLength:e=0,error:t=wr,warnings:n=[],valueBeforeDecode:s=qi}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=H.BufferSourceConverter.toUint8Array(s)}static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:H.Convert.ToHex(this.valueBeforeDecodeView)}}};ut.NAME="baseBlock";var xe=class extends ut{fromBER(e,t,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(e,t){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}};xe.NAME="valueBlock";var Pn=class extends pt(ut){constructor({idBlock:e={}}={}){var t,n,s,i;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?H.BufferSourceConverter.toUint8Array(e.valueHex):qi,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(s=e.tagNumber)!==null&&s!==void 0?s:-1,this.isConstructed=(i=e.isConstructed)!==null&&i!==void 0?i:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",$e}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let s=new Uint8Array(1);if(!e){let i=this.tagNumber;i&=31,t|=i,s[0]=t}return s.buffer}if(!this.isHexOnly){let s=It(this.tagNumber,7),i=new Uint8Array(s),o=s.byteLength,a=new Uint8Array(o+1);if(a[0]=t|31,!e){for(let c=0;c<o-1;c++)a[c+1]=i[c]|128;a[o]=i[o-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let s=this.valueHexView;for(let i=0;i<s.length-1;i++)n[i+1]=s[i]|128;n[this.valueHexView.byteLength]=s[s.length-1]}return n.buffer}fromBER(e,t,n){let s=H.BufferSourceConverter.toUint8Array(e);if(!dt(this,s,t,n))return-1;let i=s.subarray(t,t+n);if(i.length===0)return this.error="Zero buffer length",-1;switch(i[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=(i[0]&32)===32,this.isHexOnly=!1;let a=i[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,f=this.valueHexView=new Uint8Array(255),u=255;for(;i[c]&128;){if(f[c-1]=i[c]&127,c++,c>=i.length)return this.error="End of input reached before message was fully decoded",-1;if(c===u){u+=255;let h=new Uint8Array(u);for(let m=0;m<f.length;m++)h[m]=f[m];f=this.valueHexView=new Uint8Array(u)}}this.blockLength=c+1,f[c-1]=i[c]&127;let l=new Uint8Array(c);for(let h=0;h<c;h++)l[h]=f[h];f=this.valueHexView=new Uint8Array(c),f.set(l),this.blockLength<=9?this.tagNumber=Gt(f,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 t+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}};Pn.NAME="identificationBlock";var Dn=class extends ut{constructor({lenBlock:e={}}={}){var t,n,s;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0?t:!1,this.longFormUsed=(n=e.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(s=e.length)!==null&&s!==void 0?s:0}fromBER(e,t,n){let s=H.BufferSourceConverter.toUint8Array(e);if(!dt(this,s,t,n))return-1;let i=s.subarray(t,t+n);if(i.length===0)return this.error="Zero buffer length",-1;if(i[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=i[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(i[0]&128),this.longFormUsed===!1)return this.length=i[0],this.blockLength=1,t+this.blockLength;let o=i[0]&127;if(o>8)return this.error="Too big integer",-1;if(o+1>i.length)return this.error="End of input reached before message was fully decoded",-1;let a=t+1,c=s.subarray(a,a+o);return c[o-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=Gt(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=o+1,t+this.blockLength}toBER(e=!1){let t,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=128),t;if(this.longFormUsed){let s=It(this.length,8);if(s.byteLength>127)return this.error="Too big length",$e;if(t=new ArrayBuffer(s.byteLength+1),e)return t;let i=new Uint8Array(s);n=new Uint8Array(t),n[0]=s.byteLength|128;for(let o=0;o<s.byteLength;o++)n[o+1]=i[o];return t}return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};Dn.NAME="lengthBlock";var k={},ge=class extends ut{constructor({name:e=wr,optional:t=!1,primitiveSchema:n,...s}={},i){super(s),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new Pn(s),this.lenBlock=new Dn(s),this.valueBlock=i?new i(s):new xe(s)}fromBER(e,t,n){let s=this.valueBlock.fromBER(e,t,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(e,t){let n=t||new Fr;t||ec(this);let s=this.idBlock.toBER(e);if(n.write(s),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,n),n.write(new ArrayBuffer(2));else{let i=this.valueBlock.toBER(e);this.lenBlock.length=i.byteLength;let o=this.lenBlock.toBER(e);n.write(o),n.write(i)}return t?$e:n.final()}toJSON(){let e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return e==="ascii"?this.onAsciiEncoding():H.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${H.Convert.ToHex(this.valueBlock.valueBeforeDecodeView)}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;let t=this.toBER(),n=e.toBER();return Ya(t,n)}};ge.NAME="BaseBlock";function ec(r){if(r instanceof k.Constructed)for(let e of r.valueBlock.value)ec(e)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var Vn=class extends ge{constructor({value:e=wr,...t}={},n){super(t,n),e&&this.fromString(e)}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}fromBER(e,t,n){let s=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),s)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};Vn.NAME="BaseStringBlock";var On=class extends pt(xe){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};On.NAME="PrimitiveValueBlock";var tc,Mn=class extends ge{constructor(e={}){super(e,On),this.idBlock.isConstructed=!1}};tc=Mn;k.Primitive=tc;Mn.NAME="PRIMITIVE";function Hh(r,e){if(r instanceof e)return r;let t=new e;return t.idBlock=r.idBlock,t.lenBlock=r.lenBlock,t.warnings=r.warnings,t.valueBeforeDecodeView=r.valueBeforeDecodeView,t}function bs(r,e=0,t=r.length){let n=e,s=new ge({},xe),i=new ut;if(!dt(i,r,e,t))return s.error=i.error,{offset:-1,result:s};if(!r.subarray(e,e+t).length)return s.error="Zero buffer length",{offset:-1,result:s};let a=s.idBlock.fromBER(r,e,t);if(s.idBlock.warnings.length&&s.warnings.concat(s.idBlock.warnings),a===-1)return s.error=s.idBlock.error,{offset:-1,result:s};if(e=a,t-=s.idBlock.blockLength,a=s.lenBlock.fromBER(r,e,t),s.lenBlock.warnings.length&&s.warnings.concat(s.lenBlock.warnings),a===-1)return s.error=s.lenBlock.error,{offset:-1,result:s};if(e=a,t-=s.lenBlock.blockLength,!s.idBlock.isConstructed&&s.lenBlock.isIndefiniteForm)return s.error="Indefinite length form used for primitive encoding form",{offset:-1,result:s};let c=ge;switch(s.idBlock.tagClass){case 1:if(s.idBlock.tagNumber>=37&&s.idBlock.isHexOnly===!1)return s.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:s};switch(s.idBlock.tagNumber){case 0:if(s.idBlock.isConstructed&&s.lenBlock.length>0)return s.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:s};c=k.EndOfContent;break;case 1:c=k.Boolean;break;case 2:c=k.Integer;break;case 3:c=k.BitString;break;case 4:c=k.OctetString;break;case 5:c=k.Null;break;case 6:c=k.ObjectIdentifier;break;case 10:c=k.Enumerated;break;case 12:c=k.Utf8String;break;case 13:c=k.RelativeObjectIdentifier;break;case 14:c=k.TIME;break;case 15:return s.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:s};case 16:c=k.Sequence;break;case 17:c=k.Set;break;case 18:c=k.NumericString;break;case 19:c=k.PrintableString;break;case 20:c=k.TeletexString;break;case 21:c=k.VideotexString;break;case 22:c=k.IA5String;break;case 23:c=k.UTCTime;break;case 24:c=k.GeneralizedTime;break;case 25:c=k.GraphicString;break;case 26:c=k.VisibleString;break;case 27:c=k.GeneralString;break;case 28:c=k.UniversalString;break;case 29:c=k.CharacterString;break;case 30:c=k.BmpString;break;case 31:c=k.DATE;break;case 32:c=k.TimeOfDay;break;case 33:c=k.DateTime;break;case 34:c=k.Duration;break;default:{let f=s.idBlock.isConstructed?new k.Constructed:new k.Primitive;f.idBlock=s.idBlock,f.lenBlock=s.lenBlock,f.warnings=s.warnings,s=f}}break;case 2:case 3:case 4:default:c=s.idBlock.isConstructed?k.Constructed:k.Primitive}return s=Hh(s,c),a=s.fromBER(r,e,s.lenBlock.isIndefiniteForm?t:s.lenBlock.length),s.valueBeforeDecodeView=r.subarray(n,n+s.blockLength),{offset:a,result:s}}function xr(r){if(!r.byteLength){let e=new ge({},xe);return e.error="Input buffer has zero length",{offset:-1,result:e}}return bs(H.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function Kh(r,e){return r?1:e}var Je=class extends xe{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let s=H.BufferSourceConverter.toUint8Array(e);if(!dt(this,s,t,n))return-1;if(this.valueBeforeDecodeView=s.subarray(t,t+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let i=t;for(;Kh(this.isIndefiniteForm,n)>0;){let o=bs(s,i,n);if(o.offset===-1)return this.error=o.result.error,this.warnings.concat(o.result.warnings),-1;if(i=o.offset,this.blockLength+=o.result.blockLength,n-=o.result.blockLength,this.value.push(o.result),this.isIndefiniteForm&&o.result.constructor.NAME===qr)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===qr?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(e,t){let n=t||new Fr;for(let s=0;s<this.value.length;s++)this.value[s].toBER(e,n);return t?$e:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};Je.NAME="ConstructedValueBlock";var rc,Rt=class extends ge{constructor(e={}){super(e,Je),this.idBlock.isConstructed=!0}fromBER(e,t,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let s=this.valueBlock.fromBER(e,t,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 e=[];for(let n of this.valueBlock.value)e.push(n.toString("ascii").split(`
|
|
2
|
+
"use strict";var Libp2PPeerStore=(()=>{var eu=Object.create;var pn=Object.defineProperty;var tu=Object.getOwnPropertyDescriptor;var ru=Object.getOwnPropertyNames;var nu=Object.getPrototypeOf,su=Object.prototype.hasOwnProperty;var Wo=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),ue=(r,e)=>{for(var t in e)pn(r,t,{get:e[t],enumerable:!0})},Yo=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of ru(e))!su.call(r,s)&&s!==t&&pn(r,s,{get:()=>e[s],enumerable:!(n=tu(e,s))||n.enumerable});return r};var Zo=(r,e,t)=>(t=r!=null?eu(nu(r)):{},Yo(e||!r||!r.__esModule?pn(t,"default",{value:r,enumerable:!0}):t,r)),iu=r=>Yo(pn({},"__esModule",{value:!0}),r);var Xa=Wo(br=>{"use strict";var Oh="[object ArrayBuffer]",lt=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===Oh}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,t){let n=r.toUint8Array(e),s=r.toUint8Array(t);if(n.length!==s.byteLength)return!1;for(let i=0;i<n.length;i++)if(n[i]!==s[i])return!1;return!0}static concat(...e){let t;Array.isArray(e[0])&&!(e[1]instanceof Function)||Array.isArray(e[0])&&e[1]instanceof Function?t=e[0]:e[e.length-1]instanceof Function?t=e.slice(0,e.length-1):t=e;let n=0;for(let o of t)n+=o.byteLength;let s=new Uint8Array(n),i=0;for(let o of t){let a=this.toUint8Array(o);s.set(a,i),i+=a.length}return e[e.length-1]instanceof Function?this.toView(s,e[e.length-1]):s.buffer}},Gi="string",Mh=/^[0-9a-f]+$/i,Hh=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Kh=/^[a-zA-Z0-9-_]+$/,Un=class{static fromString(e){let t=unescape(encodeURIComponent(e)),n=new Uint8Array(t.length);for(let s=0;s<t.length;s++)n[s]=t.charCodeAt(s);return n.buffer}static toString(e){let t=lt.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return decodeURIComponent(escape(n))}},De=class{static toString(e,t=!1){let n=lt.toArrayBuffer(e),s=new DataView(n),i="";for(let o=0;o<n.byteLength;o+=2){let a=s.getUint16(o,t);i+=String.fromCharCode(a)}return i}static fromString(e,t=!1){let n=new ArrayBuffer(e.length*2),s=new DataView(n);for(let i=0;i<e.length;i++)s.setUint16(i*2,e.charCodeAt(i),t);return n}},Pn=class r{static isHex(e){return typeof e===Gi&&Mh.test(e)}static isBase64(e){return typeof e===Gi&&Hh.test(e)}static isBase64Url(e){return typeof e===Gi&&Kh.test(e)}static ToString(e,t="utf8"){let n=lt.toUint8Array(e);switch(t.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 De.toString(n,!0);case"utf16":case"utf16be":return De.toString(n);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromString(e,t="utf8"){if(!e)return new ArrayBuffer(0);switch(t.toLowerCase()){case"utf8":return this.FromUtf8String(e);case"binary":return this.FromBinary(e);case"hex":return this.FromHex(e);case"base64":return this.FromBase64(e);case"base64url":return this.FromBase64Url(e);case"utf16le":return De.fromString(e,!0);case"utf16":case"utf16be":return De.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=lt.toUint8Array(e);if(typeof btoa<"u"){let n=this.ToString(t,"binary");return btoa(n)}else return Buffer.from(t).toString("base64")}static FromBase64(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64(t))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(t)):new Uint8Array(Buffer.from(t,"base64")).buffer}static FromBase64Url(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64Url(t))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(t.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(e){return this.ToBase64(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.FromBinary(e);case"utf8":return Un.fromString(e);case"utf16":case"utf16be":return De.fromString(e);case"utf16le":case"usc2":return De.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return Un.toString(e);case"utf16":case"utf16be":return De.toString(e);case"utf16le":case"usc2":return De.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){let t=e.length,n=new Uint8Array(t);for(let s=0;s<t;s++)n[s]=e.charCodeAt(s);return n.buffer}static ToBinary(e){let t=lt.toUint8Array(e),n="";for(let s=0;s<t.length;s++)n+=String.fromCharCode(t[s]);return n}static ToHex(e){let t=lt.toUint8Array(e),n="",s=t.length;for(let i=0;i<s;i++){let o=t[i];o<16&&(n+="0"),n+=o.toString(16)}return n}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);let n=new Uint8Array(t.length/2);for(let s=0;s<t.length;s=s+2){let i=t.slice(s,s+2);n[s/2]=parseInt(i,16)}return n.buffer}static ToUtf16String(e,t=!1){return De.toString(e,t)}static FromUtf16String(e,t=!1){return De.fromString(e,t)}static Base64Padding(e){let t=4-e.length%4;if(t<4)for(let n=0;n<t;n++)e+="=";return e}static formatString(e){return e?.replace(/[\n\r\t ]/g,"")||""}};Pn.DEFAULT_UTF8_ENCODING="utf8";function Fh(r,...e){let t=arguments[0];for(let n=1;n<arguments.length;n++){let s=arguments[n];for(let i in s)t[i]=s[i]}return t}function qh(...r){let e=r.map(s=>s.byteLength).reduce((s,i)=>s+i),t=new Uint8Array(e),n=0;return r.map(s=>new Uint8Array(s)).forEach(s=>{for(let i of s)t[n++]=i}),t.buffer}function $h(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let s=0;s<r.byteLength;s++)if(t[s]!==n[s])return!1;return!0}br.BufferSourceConverter=lt;br.Convert=Pn;br.assign=Fh;br.combine=qh;br.isEqual=$h});var Pl=Wo((Qb,So)=>{"use strict";var Gd=Object.prototype.hasOwnProperty,Se="~";function ln(){}Object.create&&(ln.prototype=Object.create(null),new ln().__proto__||(Se=!1));function jd(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function Ul(r,e,t,n,s){if(typeof t!="function")throw new TypeError("The listener must be a function");var i=new jd(t,n||r,s),o=Se?Se+e:e;return r._events[o]?r._events[o].fn?r._events[o]=[r._events[o],i]:r._events[o].push(i):(r._events[o]=i,r._eventsCount++),r}function Ts(r,e){--r._eventsCount===0?r._events=new ln:delete r._events[e]}function we(){this._events=new ln,this._eventsCount=0}we.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)Gd.call(t,n)&&e.push(Se?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};we.prototype.listeners=function(e){var t=Se?Se+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var s=0,i=n.length,o=new Array(i);s<i;s++)o[s]=n[s].fn;return o};we.prototype.listenerCount=function(e){var t=Se?Se+e:e,n=this._events[t];return n?n.fn?1:n.length:0};we.prototype.emit=function(e,t,n,s,i,o){var a=Se?Se+e:e;if(!this._events[a])return!1;var c=this._events[a],f=arguments.length,u,l;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),f){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,s),!0;case 5:return c.fn.call(c.context,t,n,s,i),!0;case 6:return c.fn.call(c.context,t,n,s,i,o),!0}for(l=1,u=new Array(f-1);l<f;l++)u[l-1]=arguments[l];c.fn.apply(c.context,u)}else{var d=c.length,y;for(l=0;l<d;l++)switch(c[l].once&&this.removeListener(e,c[l].fn,void 0,!0),f){case 1:c[l].fn.call(c[l].context);break;case 2:c[l].fn.call(c[l].context,t);break;case 3:c[l].fn.call(c[l].context,t,n);break;case 4:c[l].fn.call(c[l].context,t,n,s);break;default:if(!u)for(y=1,u=new Array(f-1);y<f;y++)u[y-1]=arguments[y];c[l].fn.apply(c[l].context,u)}}return!0};we.prototype.on=function(e,t,n){return Ul(this,e,t,n,!1)};we.prototype.once=function(e,t,n){return Ul(this,e,t,n,!0)};we.prototype.removeListener=function(e,t,n,s){var i=Se?Se+e:e;if(!this._events[i])return this;if(!t)return Ts(this,i),this;var o=this._events[i];if(o.fn)o.fn===t&&(!s||o.once)&&(!n||o.context===n)&&Ts(this,i);else{for(var a=0,c=[],f=o.length;a<f;a++)(o[a].fn!==t||s&&!o[a].once||n&&o[a].context!==n)&&c.push(o[a]);c.length?this._events[i]=c.length===1?c[0]:c:Ts(this,i)}return this};we.prototype.removeAllListeners=function(e){var t;return e?(t=Se?Se+e:e,this._events[t]&&Ts(this,t)):(this._events=new ln,this._eventsCount=0),this};we.prototype.off=we.prototype.removeListener;we.prototype.addListener=we.prototype.on;we.prefixed=Se;we.EventEmitter=we;typeof So<"u"&&(So.exports=we)});var t0={};ue(t0,{PersistentPeerStore:()=>Ho});var gn=Symbol.for("@libp2p/peer-id");function Jo(r){return r!=null&&!!r[gn]}var N=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var $i={};ue($i,{Ed25519PrivateKey:()=>zt,Ed25519PublicKey:()=>Kr,generateKeyPair:()=>Ph,generateKeyPairFromSeed:()=>Ja,unmarshalEd25519PrivateKey:()=>Lh,unmarshalEd25519PublicKey:()=>Uh});var $s={};ue($s,{base58btc:()=>oe,base58flickr:()=>fu});var i0=new Uint8Array(0);function Xo(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function tt(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 Qo(r){return new TextEncoder().encode(r)}function ea(r){return new TextDecoder().decode(r)}function ou(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var s=0;s<r.length;s++){var i=r.charAt(s),o=i.charCodeAt(0);if(t[o]!==255)throw new TypeError(i+" is ambiguous");t[o]=s}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function l(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var h=0,b=0,v=0,w=g.length;v!==w&&g[v]===0;)v++,h++;for(var x=(w-v)*u+1>>>0,_=new Uint8Array(x);v!==w;){for(var S=g[v],k=0,T=x-1;(S!==0||k<b)&&T!==-1;T--,k++)S+=256*_[T]>>>0,_[T]=S%a>>>0,S=S/a>>>0;if(S!==0)throw new Error("Non-zero carry");b=k,v++}for(var I=x-b;I!==x&&_[I]===0;)I++;for(var z=c.repeat(h);I<x;++I)z+=r.charAt(_[I]);return z}function d(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var h=0;if(g[h]!==" "){for(var b=0,v=0;g[h]===c;)b++,h++;for(var w=(g.length-h)*f+1>>>0,x=new Uint8Array(w);g[h];){var _=t[g.charCodeAt(h)];if(_===255)return;for(var S=0,k=w-1;(_!==0||S<v)&&k!==-1;k--,S++)_+=a*x[k]>>>0,x[k]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");v=S,h++}if(g[h]!==" "){for(var T=w-v;T!==w&&x[T]===0;)T++;for(var I=new Uint8Array(b+(w-T)),z=b;T!==w;)I[z++]=x[T++];return I}}}function y(g){var h=d(g);if(h)return h;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:d,decode:y}}var au=ou,cu=au,ra=cu;var Hs=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Ks=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return na(this,e)}},Fs=class{decoders;constructor(e){this.decoders=e}or(e){return na(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function na(r,e){return new Fs({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var qs=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,s){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=s,this.encoder=new Hs(e,t,n),this.decoder=new Ks(e,t,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function tr({name:r,prefix:e,encode:t,decode:n}){return new qs(r,e,t,n)}function yt({name:r,prefix:e,alphabet:t}){let{encode:n,decode:s}=ra(t,r);return tr({prefix:e,name:r,encode:n,decode:i=>tt(s(i))})}function lu(r,e,t,n){let s={};for(let u=0;u<e.length;++u)s[e[u]]=u;let i=r.length;for(;r[i-1]==="=";)--i;let o=new Uint8Array(i*t/8|0),a=0,c=0,f=0;for(let u=0;u<i;++u){let l=s[r[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|l,a+=t,a>=8&&(a-=8,o[f++]=255&c>>a)}if(a>=t||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o}function uu(r,e,t){let n=e[e.length-1]==="=",s=(1<<t)-1,i="",o=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],o+=8;o>t;)o-=t,i+=e[s&a>>o];if(o!==0&&(i+=e[s&a<<t-o]),n)for(;i.length*t&7;)i+="=";return i}function Q({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return tr({prefix:e,name:r,encode(s){return uu(s,n,t)},decode(s){return lu(s,n,t,r)}})}var oe=yt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),fu=yt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Gs={};ue(Gs,{identity:()=>rt});var hu=oa,sa=128,du=127,pu=~du,gu=Math.pow(2,31);function oa(r,e,t){e=e||[],t=t||0;for(var n=t;r>=gu;)e[t++]=r&255|sa,r/=128;for(;r&pu;)e[t++]=r&255|sa,r>>>=7;return e[t]=r|0,oa.bytes=t-n+1,e}var mu=zs,yu=128,ia=127;function zs(r,n){var t=0,n=n||0,s=0,i=n,o,a=r.length;do{if(i>=a)throw zs.bytes=0,new RangeError("Could not decode varint");o=r[i++],t+=s<28?(o&ia)<<s:(o&ia)*Math.pow(2,s),s+=7}while(o>=yu);return zs.bytes=i-n,t}var bu=Math.pow(2,7),wu=Math.pow(2,14),xu=Math.pow(2,21),vu=Math.pow(2,28),Eu=Math.pow(2,35),Bu=Math.pow(2,42),Au=Math.pow(2,49),ku=Math.pow(2,56),Su=Math.pow(2,63),Iu=function(r){return r<bu?1:r<wu?2:r<xu?3:r<vu?4:r<Eu?5:r<Bu?6:r<Au?7:r<ku?8:r<Su?9:10},Ru={encode:hu,decode:mu,encodingLength:Iu},Nu=Ru,Cr=Nu;function Lr(r,e=0){return[Cr.decode(r,e),Cr.decode.bytes]}function rr(r,e,t=0){return Cr.encode(r,e,t),e}function nr(r){return Cr.encodingLength(r)}function je(r,e){let t=e.byteLength,n=nr(r),s=n+nr(t),i=new Uint8Array(s+t);return rr(r,i,0),rr(t,i,n),i.set(e,s),new sr(r,t,e,i)}function Dt(r){let e=tt(r),[t,n]=Lr(e),[s,i]=Lr(e.subarray(n)),o=e.subarray(n+i);if(o.byteLength!==s)throw new Error("Incorrect length");return new sr(t,s,o,e)}function aa(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Xo(r.bytes,t.bytes)}}var sr=class{code;size;digest;bytes;constructor(e,t,n,s){this.code=e,this.size=t,this.digest=n,this.bytes=s}};var ca=0,Tu="identity",la=tt;function _u(r){return je(ca,la(r))}var rt={code:ca,name:Tu,encode:la,digest:_u};var Ys={};ue(Ys,{sha256:()=>de,sha512:()=>Cu});function Ws({name:r,code:e,encode:t}){return new js(r,e,t)}var js=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?je(this.code,t):t.then(n=>je(this.code,n))}else throw Error("Unknown type, must be binary type")}};function fa(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var de=Ws({name:"sha2-256",code:18,encode:fa("SHA-256")}),Cu=Ws({name:"sha2-512",code:19,encode:fa("SHA-512")});function ee(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function nt(r=0){return new Uint8Array(r)}function Re(r=0){return new Uint8Array(r)}function xe(r,e){e==null&&(e=r.reduce((s,i)=>s+i.length,0));let t=Re(e),n=0;for(let s of r)t.set(s,n),n+=s.length;return t}var Zs={};ue(Zs,{base10:()=>Lu});var Lu=yt({prefix:"9",name:"base10",alphabet:"0123456789"});var Js={};ue(Js,{base16:()=>Uu,base16upper:()=>Pu});var Uu=Q({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Pu=Q({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Xs={};ue(Xs,{base2:()=>Du});var Du=Q({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Qs={};ue(Qs,{base256emoji:()=>Ku});var ha=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}"),Vu=ha.reduce((r,e,t)=>(r[t]=e,r),[]),Ou=ha.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function Mu(r){return r.reduce((e,t)=>(e+=Vu[t],e),"")}function Hu(r){let e=[];for(let t of r){let n=Ou[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var Ku=tr({prefix:"\u{1F680}",name:"base256emoji",encode:Mu,decode:Hu});var ei={};ue(ei,{base32:()=>Me,base32hex:()=>zu,base32hexpad:()=>ju,base32hexpadupper:()=>Wu,base32hexupper:()=>Gu,base32pad:()=>qu,base32padupper:()=>$u,base32upper:()=>Fu,base32z:()=>Yu});var Me=Q({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Fu=Q({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),qu=Q({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),$u=Q({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),zu=Q({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Gu=Q({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ju=Q({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Wu=Q({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Yu=Q({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ti={};ue(ti,{base36:()=>Zu,base36upper:()=>Ju});var Zu=yt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ju=yt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ni={};ue(ni,{base64:()=>ri,base64pad:()=>Xu,base64url:()=>Qu,base64urlpad:()=>ef});var ri=Q({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Xu=Q({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Qu=Q({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ef=Q({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var si={};ue(si,{base8:()=>tf});var tf=Q({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ii={};ue(ii,{identity:()=>rf});var rf=tr({prefix:"\0",name:"identity",encode:r=>ea(r),decode:r=>Qo(r)});var L0=new TextEncoder,U0=new TextDecoder;function da(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return af(t,oi(r),e??oe.encoder);default:return cf(t,oi(r),e??Me.encoder)}}var pa=new WeakMap;function oi(r){let e=pa.get(r);if(e==null){let t=new Map;return pa.set(r,t),t}return e}var Ue=class r{code;version;multihash;bytes;"/";constructor(e,t,n,s){this.code=t,this.version=e,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:e,multihash:t}=this;if(e!==Ur)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==lf)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}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:e,digest:t}=this.multihash,n=je(e,t);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(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&aa(e.multihash,n.multihash)}toString(e){return da(this,e)}toJSON(){return{"/":da(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:s,multihash:i,bytes:o}=t;return new r(n,s,i,o??ga(n,s,i.bytes))}else if(t[uf]===!0){let{version:n,multihash:s,code:i}=t,o=Dt(s);return r.create(n,i,o)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==Ur)throw new Error(`Version 0 CID must use dag-pb (code: ${Ur}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let s=ga(e,t,n.bytes);return new r(e,t,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Ur,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,s=tt(e.subarray(n,n+t.multihashSize));if(s.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=s.subarray(t.multihashSize-t.digestSize),o=new sr(t.multihashCode,t.digestSize,i,s);return[t.version===0?r.createV0(o):r.createV1(t.codec,o),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[l,d]=Lr(e.subarray(t));return t+=d,l},s=n(),i=Ur;if(s===18?(s=0,t=0):i=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let o=t,a=n(),c=n(),f=t+c,u=f-o;return{version:s,codec:i,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(e,t){let[n,s]=of(e,t),i=r.decode(s);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return oi(i).set(n,e),i}};function of(r,e){switch(r[0]){case"Q":{let t=e??oe;return[oe.prefix,t.decode(`${oe.prefix}${r}`)]}case oe.prefix:{let t=e??oe;return[oe.prefix,t.decode(r)]}case Me.prefix:{let t=e??Me;return[Me.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function af(r,e,t){let{prefix:n}=t;if(n!==oe.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let s=e.get(n);if(s==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return s}function cf(r,e,t){let{prefix:n}=t,s=e.get(n);if(s==null){let i=t.encode(r);return e.set(n,i),i}else return s}var Ur=112,lf=18;function ga(r,e,t){let n=nr(r),s=n+nr(e),i=new Uint8Array(s+t.byteLength);return rr(r,i,0),rr(e,i,n),i.set(t,s),i}var uf=Symbol.for("@ipld/js-cid/CID");var bt={...ii,...Xs,...si,...Zs,...Js,...ei,...ti,...$s,...ni,...Qs},Z0={...Ys,...Gs};function ya(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var ma=ya("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ai=ya("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=Re(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),ff={utf8:ma,"utf-8":ma,hex:bt.base16,latin1:ai,ascii:ai,binary:ai,...bt},yn=ff;function q(r,e="utf8"){let t=yn[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function Pe(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function ir(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function hf(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function or(r,...e){if(!hf(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${r.length}`)}function bn(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");ir(r.outputLen),ir(r.blockLen)}function ar(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function ba(r,e){or(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var wn=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var lr=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),He=(r,e)=>r<<32-e|r>>>e;var up=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var df=async()=>{};async function wa(r,e,t){let n=Date.now();for(let s=0;s<r;s++){t(s);let i=Date.now()-n;i>=0&&i<e||(await df(),n+=i)}}function xa(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function wt(r){return typeof r=="string"&&(r=xa(r)),or(r),r}function ci(...r){let e=0;for(let n=0;n<r.length;n++){let s=r[n];or(s),e+=s.length}let t=new Uint8Array(e);for(let n=0,s=0;n<r.length;n++){let i=r[n];t.set(i,s),s+=i.length}return t}var cr=class{clone(){return this._cloneInto()}},pf={}.toString;function va(r,e){if(e!==void 0&&pf.call(e)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(r,e)}function xn(r){let e=n=>r().update(wt(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function ur(r=32){if(wn&&typeof wn.getRandomValues=="function")return wn.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function gf(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let s=BigInt(32),i=BigInt(4294967295),o=Number(t>>s&i),a=Number(t&i),c=n?4:0,f=n?0:4;r.setUint32(e+c,o,n),r.setUint32(e+f,a,n)}var Ea=(r,e,t)=>r&e^~r&t,Ba=(r,e,t)=>r&e^r&t^e&t,fr=class extends cr{constructor(e,t,n,s){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=lr(this.buffer)}update(e){ar(this);let{view:t,buffer:n,blockLen:s}=this;e=wt(e);let i=e.length;for(let o=0;o<i;){let a=Math.min(s-this.pos,i-o);if(a===s){let c=lr(e);for(;s<=i-o;o+=s)this.process(c,o);continue}n.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===s&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){ar(this),ba(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:s,isLE:i}=this,{pos:o}=this;t[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>s-o&&(this.process(n,0),o=0);for(let l=o;l<s;l++)t[l]=0;gf(n,s-8,BigInt(this.length*8),i),this.process(n,0);let a=lr(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)a.setUint32(4*l,u[l],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:s,finished:i,destroyed:o,pos:a}=this;return e.length=s,e.pos=a,e.finished=i,e.destroyed=o,s%t&&e.buffer.set(n),e}};var vn=BigInt(4294967295),li=BigInt(32);function Aa(r,e=!1){return e?{h:Number(r&vn),l:Number(r>>li&vn)}:{h:Number(r>>li&vn)|0,l:Number(r&vn)|0}}function mf(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let s=0;s<r.length;s++){let{h:i,l:o}=Aa(r[s],e);[t[s],n[s]]=[i,o]}return[t,n]}var yf=(r,e)=>BigInt(r>>>0)<<li|BigInt(e>>>0),bf=(r,e,t)=>r>>>t,wf=(r,e,t)=>r<<32-t|e>>>t,xf=(r,e,t)=>r>>>t|e<<32-t,vf=(r,e,t)=>r<<32-t|e>>>t,Ef=(r,e,t)=>r<<64-t|e>>>t-32,Bf=(r,e,t)=>r>>>t-32|e<<64-t,Af=(r,e)=>e,kf=(r,e)=>r,Sf=(r,e,t)=>r<<t|e>>>32-t,If=(r,e,t)=>e<<t|r>>>32-t,Rf=(r,e,t)=>e<<t-32|r>>>64-t,Nf=(r,e,t)=>r<<t-32|e>>>64-t;function Tf(r,e,t,n){let s=(e>>>0)+(n>>>0);return{h:r+t+(s/2**32|0)|0,l:s|0}}var _f=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),Cf=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,Lf=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),Uf=(r,e,t,n,s)=>e+t+n+s+(r/2**32|0)|0,Pf=(r,e,t,n,s)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(s>>>0),Df=(r,e,t,n,s,i)=>e+t+n+s+i+(r/2**32|0)|0;var Vf={fromBig:Aa,split:mf,toBig:yf,shrSH:bf,shrSL:wf,rotrSH:xf,rotrSL:vf,rotrBH:Ef,rotrBL:Bf,rotr32H:Af,rotr32L:kf,rotlSH:Sf,rotlSL:If,rotlBH:Rf,rotlBL:Nf,add:Tf,add3L:_f,add3H:Cf,add4L:Lf,add4H:Uf,add5H:Df,add5L:Pf},P=Vf;var[Of,Mf]=P.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),xt=new Uint32Array(80),vt=new Uint32Array(80),ui=class extends fr{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:e,Al:t,Bh:n,Bl:s,Ch:i,Cl:o,Dh:a,Dl:c,Eh:f,El:u,Fh:l,Fl:d,Gh:y,Gl:g,Hh:h,Hl:b}=this;return[e,t,n,s,i,o,a,c,f,u,l,d,y,g,h,b]}set(e,t,n,s,i,o,a,c,f,u,l,d,y,g,h,b){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=s|0,this.Ch=i|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=l|0,this.Fl=d|0,this.Gh=y|0,this.Gl=g|0,this.Hh=h|0,this.Hl=b|0}process(e,t){for(let x=0;x<16;x++,t+=4)xt[x]=e.getUint32(t),vt[x]=e.getUint32(t+=4);for(let x=16;x<80;x++){let _=xt[x-15]|0,S=vt[x-15]|0,k=P.rotrSH(_,S,1)^P.rotrSH(_,S,8)^P.shrSH(_,S,7),T=P.rotrSL(_,S,1)^P.rotrSL(_,S,8)^P.shrSL(_,S,7),I=xt[x-2]|0,z=vt[x-2]|0,M=P.rotrSH(I,z,19)^P.rotrBH(I,z,61)^P.shrSH(I,z,6),H=P.rotrSL(I,z,19)^P.rotrBL(I,z,61)^P.shrSL(I,z,6),re=P.add4L(T,H,vt[x-7],vt[x-16]),se=P.add4H(re,k,M,xt[x-7],xt[x-16]);xt[x]=se|0,vt[x]=re|0}let{Ah:n,Al:s,Bh:i,Bl:o,Ch:a,Cl:c,Dh:f,Dl:u,Eh:l,El:d,Fh:y,Fl:g,Gh:h,Gl:b,Hh:v,Hl:w}=this;for(let x=0;x<80;x++){let _=P.rotrSH(l,d,14)^P.rotrSH(l,d,18)^P.rotrBH(l,d,41),S=P.rotrSL(l,d,14)^P.rotrSL(l,d,18)^P.rotrBL(l,d,41),k=l&y^~l&h,T=d&g^~d&b,I=P.add5L(w,S,T,Mf[x],vt[x]),z=P.add5H(I,v,_,k,Of[x],xt[x]),M=I|0,H=P.rotrSH(n,s,28)^P.rotrBH(n,s,34)^P.rotrBH(n,s,39),re=P.rotrSL(n,s,28)^P.rotrBL(n,s,34)^P.rotrBL(n,s,39),se=n&i^n&a^i&a,R=s&o^s&c^o&c;v=h|0,w=b|0,h=y|0,b=g|0,y=l|0,g=d|0,{h:l,l:d}=P.add(f|0,u|0,z|0,M|0),f=a|0,u=c|0,a=i|0,c=o|0,i=n|0,o=s|0;let m=P.add3L(M,re,R);n=P.add3H(m,z,H,se),s=m|0}({h:n,l:s}=P.add(this.Ah|0,this.Al|0,n|0,s|0)),{h:i,l:o}=P.add(this.Bh|0,this.Bl|0,i|0,o|0),{h:a,l:c}=P.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=P.add(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:d}=P.add(this.Eh|0,this.El|0,l|0,d|0),{h:y,l:g}=P.add(this.Fh|0,this.Fl|0,y|0,g|0),{h,l:b}=P.add(this.Gh|0,this.Gl|0,h|0,b|0),{h:v,l:w}=P.add(this.Hh|0,this.Hl|0,v|0,w|0),this.set(n,s,i,o,a,c,f,u,l,d,y,g,h,b,v,w)}roundClean(){xt.fill(0),vt.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 Pr=xn(()=>new ui);var Bn={};ue(Bn,{aInRange:()=>Ne,abool:()=>Ke,abytes:()=>hr,bitGet:()=>Gf,bitLen:()=>zf,bitMask:()=>Vr,bitSet:()=>jf,bytesToHex:()=>it,bytesToNumberBE:()=>ot,bytesToNumberLE:()=>Bt,concatBytes:()=>at,createHmacDrbg:()=>gi,ensureBytes:()=>te,equalBytes:()=>qf,hexToBytes:()=>Ot,hexToNumber:()=>pi,inRange:()=>Dr,isBytes:()=>Et,memoized:()=>Ht,notImplemented:()=>Yf,numberToBytesBE:()=>At,numberToBytesLE:()=>Mt,numberToHexUnpadded:()=>Ia,numberToVarBytesBE:()=>Ff,utf8ToBytes:()=>$f,validateObject:()=>We});var di=BigInt(0),En=BigInt(1),Hf=BigInt(2);function Et(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function hr(r){if(!Et(r))throw new Error("Uint8Array expected")}function Ke(r,e){if(typeof e!="boolean")throw new Error(`${r} must be valid boolean, got "${e}".`)}var Kf=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function it(r){hr(r);let e="";for(let t=0;t<r.length;t++)e+=Kf[r[t]];return e}function Ia(r){let e=r.toString(16);return e.length&1?`0${e}`:e}function pi(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var st={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function ka(r){if(r>=st._0&&r<=st._9)return r-st._0;if(r>=st._A&&r<=st._F)return r-(st._A-10);if(r>=st._a&&r<=st._f)return r-(st._a-10)}function Ot(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let e=r.length,t=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let s=0,i=0;s<t;s++,i+=2){let o=ka(r.charCodeAt(i)),a=ka(r.charCodeAt(i+1));if(o===void 0||a===void 0){let c=r[i]+r[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[s]=o*16+a}return n}function ot(r){return pi(it(r))}function Bt(r){return hr(r),pi(it(Uint8Array.from(r).reverse()))}function At(r,e){return Ot(r.toString(16).padStart(e*2,"0"))}function Mt(r,e){return At(r,e).reverse()}function Ff(r){return Ot(Ia(r))}function te(r,e,t){let n;if(typeof e=="string")try{n=Ot(e)}catch(i){throw new Error(`${r} must be valid hex string, got "${e}". Cause: ${i}`)}else if(Et(e))n=Uint8Array.from(e);else throw new Error(`${r} must be hex string or Uint8Array`);let s=n.length;if(typeof t=="number"&&s!==t)throw new Error(`${r} expected ${t} bytes, got ${s}`);return n}function at(...r){let e=0;for(let n=0;n<r.length;n++){let s=r[n];hr(s),e+=s.length}let t=new Uint8Array(e);for(let n=0,s=0;n<r.length;n++){let i=r[n];t.set(i,s),s+=i.length}return t}function qf(r,e){if(r.length!==e.length)return!1;let t=0;for(let n=0;n<r.length;n++)t|=r[n]^e[n];return t===0}function $f(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}var fi=r=>typeof r=="bigint"&&di<=r;function Dr(r,e,t){return fi(r)&&fi(e)&&fi(t)&&e<=r&&r<t}function Ne(r,e,t,n){if(!Dr(e,t,n))throw new Error(`expected valid ${r}: ${t} <= n < ${n}, got ${typeof e} ${e}`)}function zf(r){let e;for(e=0;r>di;r>>=En,e+=1);return e}function Gf(r,e){return r>>BigInt(e)&En}function jf(r,e,t){return r|(t?En:di)<<BigInt(e)}var Vr=r=>(Hf<<BigInt(r-1))-En,hi=r=>new Uint8Array(r),Sa=r=>Uint8Array.from(r);function gi(r,e,t){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof t!="function")throw new Error("hmacFn must be a function");let n=hi(r),s=hi(r),i=0,o=()=>{n.fill(1),s.fill(0),i=0},a=(...l)=>t(s,n,...l),c=(l=hi())=>{s=a(Sa([0]),l),n=a(),l.length!==0&&(s=a(Sa([1]),l),n=a())},f=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,d=[];for(;l<e;){n=a();let y=n.slice();d.push(y),l+=n.length}return at(...d)};return(l,d)=>{o(),c(l);let y;for(;!(y=d(f()));)c();return o(),y}}var Wf={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"||Et(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,e)=>e.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function We(r,e,t={}){let n=(s,i,o)=>{let a=Wf[i];if(typeof a!="function")throw new Error(`Invalid validator "${i}", expected function`);let c=r[s];if(!(o&&c===void 0)&&!a(c,r))throw new Error(`Invalid param ${String(s)}=${c} (${typeof c}), expected ${i}`)};for(let[s,i]of Object.entries(e))n(s,i,!1);for(let[s,i]of Object.entries(t))n(s,i,!0);return r}var Yf=()=>{throw new Error("not implemented")};function Ht(r){let e=new WeakMap;return(t,...n)=>{let s=e.get(t);if(s!==void 0)return s;let i=r(t,...n);return e.set(t,i),i}}var ae=BigInt(0),W=BigInt(1),Kt=BigInt(2),Zf=BigInt(3),mi=BigInt(4),Ra=BigInt(5),Na=BigInt(8),Jf=BigInt(9),Xf=BigInt(16);function G(r,e){let t=r%e;return t>=ae?t:e+t}function Qf(r,e,t){if(t<=ae||e<ae)throw new Error("Expected power/modulo > 0");if(t===W)return ae;let n=W;for(;e>ae;)e&W&&(n=n*r%t),r=r*r%t,e>>=W;return n}function Y(r,e,t){let n=r;for(;e-- >ae;)n*=n,n%=t;return n}function An(r,e){if(r===ae||e<=ae)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=G(r,e),n=e,s=ae,i=W,o=W,a=ae;for(;t!==ae;){let f=n/t,u=n%t,l=s-o*f,d=i-a*f;n=t,t=u,s=o,i=a,o=l,a=d}if(n!==W)throw new Error("invert: does not exist");return G(s,e)}function eh(r){let e=(r-W)/Kt,t,n,s;for(t=r-W,n=0;t%Kt===ae;t/=Kt,n++);for(s=Kt;s<r&&Qf(s,e,r)!==r-W;s++);if(n===1){let o=(r+W)/mi;return function(c,f){let u=c.pow(f,o);if(!c.eql(c.sqr(u),f))throw new Error("Cannot find square root");return u}}let i=(t+W)/Kt;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let f=n,u=a.pow(a.mul(a.ONE,s),t),l=a.pow(c,i),d=a.pow(c,t);for(;!a.eql(d,a.ONE);){if(a.eql(d,a.ZERO))return a.ZERO;let y=1;for(let h=a.sqr(d);y<f&&!a.eql(h,a.ONE);y++)h=a.sqr(h);let g=a.pow(u,W<<BigInt(f-y-1));u=a.sqr(g),l=a.mul(l,g),d=a.mul(d,u),f=y}return l}}function th(r){if(r%mi===Zf){let e=(r+W)/mi;return function(n,s){let i=n.pow(s,e);if(!n.eql(n.sqr(i),s))throw new Error("Cannot find square root");return i}}if(r%Na===Ra){let e=(r-Ra)/Na;return function(n,s){let i=n.mul(s,Kt),o=n.pow(i,e),a=n.mul(s,o),c=n.mul(n.mul(a,Kt),o),f=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(f),s))throw new Error("Cannot find square root");return f}}return r%Xf,eh(r)}var Ta=(r,e)=>(G(r,e)&W)===W,rh=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function yi(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=rh.reduce((n,s)=>(n[s]="function",n),e);return We(r,t)}function nh(r,e,t){if(t<ae)throw new Error("Expected power > 0");if(t===ae)return r.ONE;if(t===W)return e;let n=r.ONE,s=e;for(;t>ae;)t&W&&(n=r.mul(n,s)),s=r.sqr(s),t>>=W;return n}function sh(r,e){let t=new Array(e.length),n=e.reduce((i,o,a)=>r.is0(o)?i:(t[a]=i,r.mul(i,o)),r.ONE),s=r.inv(n);return e.reduceRight((i,o,a)=>r.is0(o)?i:(t[a]=r.mul(i,t[a]),r.mul(i,o)),s),t}function bi(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function kn(r,e,t=!1,n={}){if(r<=ae)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:s,nByteLength:i}=bi(r,e);if(i>2048)throw new Error("Field lengths over 2048 bytes are not supported");let o=th(r),a=Object.freeze({ORDER:r,BITS:s,BYTES:i,MASK:Vr(s),ZERO:ae,ONE:W,create:c=>G(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return ae<=c&&c<r},is0:c=>c===ae,isOdd:c=>(c&W)===W,neg:c=>G(-c,r),eql:(c,f)=>c===f,sqr:c=>G(c*c,r),add:(c,f)=>G(c+f,r),sub:(c,f)=>G(c-f,r),mul:(c,f)=>G(c*f,r),pow:(c,f)=>nh(a,c,f),div:(c,f)=>G(c*An(f,r),r),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>An(c,r),sqrt:n.sqrt||(c=>o(a,c)),invertBatch:c=>sh(a,c),cmov:(c,f,u)=>u?f:c,toBytes:c=>t?Mt(c,i):At(c,i),fromBytes:c=>{if(c.length!==i)throw new Error(`Fp.fromBytes: expected ${i}, got ${c.length}`);return t?Bt(c):ot(c)}});return Object.freeze(a)}function _a(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let e=r.toString(2).length;return Math.ceil(e/8)}function wi(r){let e=_a(r);return e+Math.ceil(e/2)}function Ca(r,e,t=!1){let n=r.length,s=_a(e),i=wi(e);if(n<16||n<i||n>1024)throw new Error(`expected ${i}-1024 bytes of input, got ${n}`);let o=t?ot(r):Bt(r),a=G(o,e-W)+W;return t?Mt(a,s):At(a,s)}var oh=BigInt(0),xi=BigInt(1),vi=new WeakMap,La=new WeakMap;function Sn(r,e){let t=(i,o)=>{let a=o.negate();return i?a:o},n=i=>{if(!Number.isSafeInteger(i)||i<=0||i>e)throw new Error(`Wrong window size=${i}, should be [1..${e}]`)},s=i=>{n(i);let o=Math.ceil(e/i)+1,a=2**(i-1);return{windows:o,windowSize:a}};return{constTimeNegate:t,unsafeLadder(i,o){let a=r.ZERO,c=i;for(;o>oh;)o&xi&&(a=a.add(c)),c=c.double(),o>>=xi;return a},precomputeWindow(i,o){let{windows:a,windowSize:c}=s(o),f=[],u=i,l=u;for(let d=0;d<a;d++){l=u,f.push(l);for(let y=1;y<c;y++)l=l.add(u),f.push(l);u=l.double()}return f},wNAF(i,o,a){let{windows:c,windowSize:f}=s(i),u=r.ZERO,l=r.BASE,d=BigInt(2**i-1),y=2**i,g=BigInt(i);for(let h=0;h<c;h++){let b=h*f,v=Number(a&d);a>>=g,v>f&&(v-=y,a+=xi);let w=b,x=b+Math.abs(v)-1,_=h%2!==0,S=v<0;v===0?l=l.add(t(_,o[w])):u=u.add(t(S,o[x]))}return{p:u,f:l}},wNAFCached(i,o,a){let c=La.get(i)||1,f=vi.get(i);return f||(f=this.precomputeWindow(i,c),c!==1&&vi.set(i,a(f))),this.wNAF(c,f,o)},setWindowSize(i,o){n(o),La.set(i,o),vi.delete(i)}}}function Or(r){return yi(r.Fp),We(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...bi(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Fe=BigInt(0),Te=BigInt(1),In=BigInt(2),ah=BigInt(8),ch={zip215:!0};function lh(r){let e=Or(r);return We(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function Ua(r){let e=lh(r),{Fp:t,n,prehash:s,hash:i,randomBytes:o,nByteLength:a,h:c}=e,f=In<<BigInt(a*8)-Te,u=t.create,l=e.uvRatio||((m,p)=>{try{return{isValid:!0,value:t.sqrt(m*t.inv(p))}}catch{return{isValid:!1,value:Fe}}}),d=e.adjustScalarBytes||(m=>m),y=e.domain||((m,p,E)=>{if(Ke("phflag",E),p.length||E)throw new Error("Contexts/pre-hash are not supported");return m});function g(m,p){Ne("coordinate "+m,p,Fe,f)}function h(m){if(!(m instanceof w))throw new Error("ExtendedPoint expected")}let b=Ht((m,p)=>{let{ex:E,ey:B,ez:C}=m,L=m.is0();p==null&&(p=L?ah:t.inv(C));let U=u(E*p),K=u(B*p),D=u(C*p);if(L)return{x:Fe,y:Te};if(D!==Te)throw new Error("invZ was invalid");return{x:U,y:K}}),v=Ht(m=>{let{a:p,d:E}=e;if(m.is0())throw new Error("bad point: ZERO");let{ex:B,ey:C,ez:L,et:U}=m,K=u(B*B),D=u(C*C),F=u(L*L),J=u(F*F),X=u(K*p),Ie=u(F*u(X+D)),ce=u(J+u(E*u(K*D)));if(Ie!==ce)throw new Error("bad point: equation left != right (1)");let ie=u(B*C),Ve=u(L*U);if(ie!==Ve)throw new Error("bad point: equation left != right (2)");return!0});class w{constructor(p,E,B,C){this.ex=p,this.ey=E,this.ez=B,this.et=C,g("x",p),g("y",E),g("z",B),g("t",C),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(p){if(p instanceof w)throw new Error("extended point not allowed");let{x:E,y:B}=p||{};return g("x",E),g("y",B),new w(E,B,Te,u(E*B))}static normalizeZ(p){let E=t.invertBatch(p.map(B=>B.ez));return p.map((B,C)=>B.toAffine(E[C])).map(w.fromAffine)}_setWindowSize(p){S.setWindowSize(this,p)}assertValidity(){v(this)}equals(p){h(p);let{ex:E,ey:B,ez:C}=this,{ex:L,ey:U,ez:K}=p,D=u(E*K),F=u(L*C),J=u(B*K),X=u(U*C);return D===F&&J===X}is0(){return this.equals(w.ZERO)}negate(){return new w(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:p}=e,{ex:E,ey:B,ez:C}=this,L=u(E*E),U=u(B*B),K=u(In*u(C*C)),D=u(p*L),F=E+B,J=u(u(F*F)-L-U),X=D+U,Ie=X-K,ce=D-U,ie=u(J*Ie),Ve=u(X*ce),le=u(J*ce),Oe=u(Ie*X);return new w(ie,Ve,Oe,le)}add(p){h(p);let{a:E,d:B}=e,{ex:C,ey:L,ez:U,et:K}=this,{ex:D,ey:F,ez:J,et:X}=p;if(E===BigInt(-1)){let Ko=u((L-C)*(F+D)),Fo=u((L+C)*(F-D)),Ms=u(Fo-Ko);if(Ms===Fe)return this.double();let qo=u(U*In*X),$o=u(K*In*J),zo=$o+qo,Go=Fo+Ko,jo=$o-qo,Zl=u(zo*Ms),Jl=u(Go*jo),Xl=u(zo*jo),Ql=u(Ms*Go);return new w(Zl,Jl,Ql,Xl)}let Ie=u(C*D),ce=u(L*F),ie=u(K*B*X),Ve=u(U*J),le=u((C+L)*(D+F)-Ie-ce),Oe=Ve-ie,Pt=Ve+ie,_r=u(ce-E*Ie),dn=u(le*Oe),jl=u(Pt*_r),Wl=u(le*_r),Yl=u(Oe*Pt);return new w(dn,jl,Yl,Wl)}subtract(p){return this.add(p.negate())}wNAF(p){return S.wNAFCached(this,p,w.normalizeZ)}multiply(p){let E=p;Ne("scalar",E,Te,n);let{p:B,f:C}=this.wNAF(E);return w.normalizeZ([B,C])[0]}multiplyUnsafe(p){let E=p;return Ne("scalar",E,Fe,n),E===Fe?_:this.equals(_)||E===Te?this:this.equals(x)?this.wNAF(E).p:S.unsafeLadder(this,E)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return S.unsafeLadder(this,n).is0()}toAffine(p){return b(this,p)}clearCofactor(){let{h:p}=e;return p===Te?this:this.multiplyUnsafe(p)}static fromHex(p,E=!1){let{d:B,a:C}=e,L=t.BYTES;p=te("pointHex",p,L),Ke("zip215",E);let U=p.slice(),K=p[L-1];U[L-1]=K&-129;let D=Bt(U),F=E?f:t.ORDER;Ne("pointHex.y",D,Fe,F);let J=u(D*D),X=u(J-Te),Ie=u(B*J-C),{isValid:ce,value:ie}=l(X,Ie);if(!ce)throw new Error("Point.fromHex: invalid y coordinate");let Ve=(ie&Te)===Te,le=(K&128)!==0;if(!E&&ie===Fe&&le)throw new Error("Point.fromHex: x=0 and x_0=1");return le!==Ve&&(ie=u(-ie)),w.fromAffine({x:ie,y:D})}static fromPrivateKey(p){return I(p).point}toRawBytes(){let{x:p,y:E}=this.toAffine(),B=Mt(E,t.BYTES);return B[B.length-1]|=p&Te?128:0,B}toHex(){return it(this.toRawBytes())}}w.BASE=new w(e.Gx,e.Gy,Te,u(e.Gx*e.Gy)),w.ZERO=new w(Fe,Te,Te,Fe);let{BASE:x,ZERO:_}=w,S=Sn(w,a*8);function k(m){return G(m,n)}function T(m){return k(Bt(m))}function I(m){let p=a;m=te("private key",m,p);let E=te("hashed private key",i(m),2*p),B=d(E.slice(0,p)),C=E.slice(p,2*p),L=T(B),U=x.multiply(L),K=U.toRawBytes();return{head:B,prefix:C,scalar:L,point:U,pointBytes:K}}function z(m){return I(m).pointBytes}function M(m=new Uint8Array,...p){let E=at(...p);return T(i(y(E,te("context",m),!!s)))}function H(m,p,E={}){m=te("message",m),s&&(m=s(m));let{prefix:B,scalar:C,pointBytes:L}=I(p),U=M(E.context,B,m),K=x.multiply(U).toRawBytes(),D=M(E.context,K,L,m),F=k(U+D*C);Ne("signature.s",F,Fe,n);let J=at(K,Mt(F,t.BYTES));return te("result",J,a*2)}let re=ch;function se(m,p,E,B=re){let{context:C,zip215:L}=B,U=t.BYTES;m=te("signature",m,2*U),p=te("message",p),L!==void 0&&Ke("zip215",L),s&&(p=s(p));let K=Bt(m.slice(U,2*U)),D,F,J;try{D=w.fromHex(E,L),F=w.fromHex(m.slice(0,U),L),J=x.multiplyUnsafe(K)}catch{return!1}if(!L&&D.isSmallOrder())return!1;let X=M(C,F.toRawBytes(),D.toRawBytes(),p);return F.add(D.multiplyUnsafe(X)).subtract(J).clearCofactor().equals(w.ZERO)}return x._setWindowSize(8),{CURVE:e,getPublicKey:z,sign:H,verify:se,ExtendedPoint:w,utils:{getExtendedPublicKey:I,randomPrivateKey:()=>o(t.BYTES),precompute(m=8,p=w.BASE){return p._setWindowSize(m),p.multiply(BigInt(3)),p}}}}var Ei=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Pa=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Lp=BigInt(0),uh=BigInt(1),Da=BigInt(2),Up=BigInt(3),fh=BigInt(5),hh=BigInt(8);function dh(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),s=BigInt(80),i=Ei,a=r*r%i*r%i,c=Y(a,Da,i)*a%i,f=Y(c,uh,i)*r%i,u=Y(f,fh,i)*f%i,l=Y(u,e,i)*u%i,d=Y(l,t,i)*l%i,y=Y(d,n,i)*d%i,g=Y(y,s,i)*y%i,h=Y(g,s,i)*y%i,b=Y(h,e,i)*u%i;return{pow_p_5_8:Y(b,Da,i)*r%i,b2:a}}function ph(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function gh(r,e){let t=Ei,n=G(e*e*e,t),s=G(n*n*e,t),i=dh(r*s).pow_p_5_8,o=G(r*n*i,t),a=G(e*o*o,t),c=o,f=G(o*Pa,t),u=a===r,l=a===G(-r,t),d=a===G(-r*Pa,t);return u&&(o=c),(l||d)&&(o=f),Ta(o,t)&&(o=G(-o,t)),{isValid:u||l,value:o}}var mh=kn(Ei,void 0,!0),yh={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:mh,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:hh,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Pr,randomBytes:ur,adjustScalarBytes:ph,uvRatio:gh},dr=Ua(yh);var pr=32,ct=64,Rn=32;function Va(){let r=dr.utils.randomPrivateKey(),e=dr.getPublicKey(r);return{privateKey:Ka(r,e),publicKey:e}}function Oa(r){if(r.length!==Rn)throw new TypeError('"seed" must be 32 bytes in length.');if(!(r instanceof Uint8Array))throw new TypeError('"seed" must be a node.js Buffer, or Uint8Array.');let e=r,t=dr.getPublicKey(e);return{privateKey:Ka(e,t),publicKey:t}}function Ma(r,e){let t=r.subarray(0,Rn);return dr.sign(e instanceof Uint8Array?e:e.subarray(),t)}function Ha(r,e,t){return dr.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}function Ka(r,e){let t=new Uint8Array(ct);for(let n=0;n<Rn;n++)t[n]=r[n],t[Rn+n]=e[n];return t}var ve={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw Object.assign(new Error("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api"),{code:"ERR_MISSING_WEB_CRYPTO"});return e}};var Bi={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function Fa(r){let e=r?.algorithm??"AES-GCM",t=r?.keyLength??16,n=r?.nonceLength??12,s=r?.digest??"SHA-256",i=r?.saltLength??16,o=r?.iterations??32767,a=ve.get();t*=8;async function c(l,d){let y=a.getRandomValues(new Uint8Array(i)),g=a.getRandomValues(new Uint8Array(n)),h={name:e,iv:g};typeof d=="string"&&(d=q(d));let b;if(d.length===0){b=await a.subtle.importKey("jwk",Bi,{name:"AES-GCM"},!0,["encrypt"]);try{let w={name:"PBKDF2",salt:y,iterations:o,hash:{name:s}},x=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);b=await a.subtle.deriveKey(w,x,{name:e,length:t},!0,["encrypt"])}catch{b=await a.subtle.importKey("jwk",Bi,{name:"AES-GCM"},!0,["encrypt"])}}else{let w={name:"PBKDF2",salt:y,iterations:o,hash:{name:s}},x=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);b=await a.subtle.deriveKey(w,x,{name:e,length:t},!0,["encrypt"])}let v=await a.subtle.encrypt(h,b,l);return xe([y,h.iv,new Uint8Array(v)])}async function f(l,d){let y=l.subarray(0,i),g=l.subarray(i,i+n),h=l.subarray(i+n),b={name:e,iv:g};typeof d=="string"&&(d=q(d));let v;if(d.length===0)try{let x={name:"PBKDF2",salt:y,iterations:o,hash:{name:s}},_=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);v=await a.subtle.deriveKey(x,_,{name:e,length:t},!0,["decrypt"])}catch{v=await a.subtle.importKey("jwk",Bi,{name:"AES-GCM"},!0,["decrypt"])}else{let x={name:"PBKDF2",salt:y,iterations:o,hash:{name:s}},_=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);v=await a.subtle.deriveKey(x,_,{name:e,length:t},!0,["decrypt"])}let w=await a.subtle.decrypt(b,v,h);return new Uint8Array(w)}return{encrypt:c,decrypt:f}}async function gr(r,e){let n=await Fa().encrypt(r,e);return ri.encode(n)}var xh=Math.pow(2,7),vh=Math.pow(2,14),Eh=Math.pow(2,21),Ai=Math.pow(2,28),ki=Math.pow(2,35),Si=Math.pow(2,42),Ii=Math.pow(2,49),$=128,me=127;function _e(r){if(r<xh)return 1;if(r<vh)return 2;if(r<Eh)return 3;if(r<Ai)return 4;if(r<ki)return 5;if(r<Si)return 6;if(r<Ii)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ri(r,e,t=0){switch(_e(r)){case 8:e[t++]=r&255|$,r/=128;case 7:e[t++]=r&255|$,r/=128;case 6:e[t++]=r&255|$,r/=128;case 5:e[t++]=r&255|$,r/=128;case 4:e[t++]=r&255|$,r>>>=7;case 3:e[t++]=r&255|$,r>>>=7;case 2:e[t++]=r&255|$,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function Bh(r,e,t=0){switch(_e(r)){case 8:e.set(t++,r&255|$),r/=128;case 7:e.set(t++,r&255|$),r/=128;case 6:e.set(t++,r&255|$),r/=128;case 5:e.set(t++,r&255|$),r/=128;case 4:e.set(t++,r&255|$),r>>>=7;case 3:e.set(t++,r&255|$),r>>>=7;case 2:e.set(t++,r&255|$),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Ni(r,e){let t=r[e],n=0;if(n+=t&me,t<$||(t=r[e+1],n+=(t&me)<<7,t<$)||(t=r[e+2],n+=(t&me)<<14,t<$)||(t=r[e+3],n+=(t&me)<<21,t<$)||(t=r[e+4],n+=(t&me)*Ai,t<$)||(t=r[e+5],n+=(t&me)*ki,t<$)||(t=r[e+6],n+=(t&me)*Si,t<$)||(t=r[e+7],n+=(t&me)*Ii,t<$))return n;throw new RangeError("Could not decode varint")}function Ah(r,e){let t=r.get(e),n=0;if(n+=t&me,t<$||(t=r.get(e+1),n+=(t&me)<<7,t<$)||(t=r.get(e+2),n+=(t&me)<<14,t<$)||(t=r.get(e+3),n+=(t&me)<<21,t<$)||(t=r.get(e+4),n+=(t&me)*Ai,t<$)||(t=r.get(e+5),n+=(t&me)*ki,t<$)||(t=r.get(e+6),n+=(t&me)*Si,t<$)||(t=r.get(e+7),n+=(t&me)*Ii,t<$))return n;throw new RangeError("Could not decode varint")}function Ye(r,e,t=0){return e==null&&(e=Re(_e(r))),e instanceof Uint8Array?Ri(r,e,t):Bh(r,e,t)}function Ft(r,e=0){return r instanceof Uint8Array?Ni(r,e):Ah(r,e)}var _i=new Float32Array([-0]),kt=new Uint8Array(_i.buffer);function qa(r,e,t){_i[0]=r,e[t]=kt[0],e[t+1]=kt[1],e[t+2]=kt[2],e[t+3]=kt[3]}function $a(r,e){return kt[0]=r[e],kt[1]=r[e+1],kt[2]=r[e+2],kt[3]=r[e+3],_i[0]}var Ci=new Float64Array([-0]),ye=new Uint8Array(Ci.buffer);function za(r,e,t){Ci[0]=r,e[t]=ye[0],e[t+1]=ye[1],e[t+2]=ye[2],e[t+3]=ye[3],e[t+4]=ye[4],e[t+5]=ye[5],e[t+6]=ye[6],e[t+7]=ye[7]}function Ga(r,e){return ye[0]=r[e],ye[1]=r[e+1],ye[2]=r[e+2],ye[3]=r[e+3],ye[4]=r[e+4],ye[5]=r[e+5],ye[6]=r[e+6],ye[7]=r[e+7],Ci[0]}var kh=BigInt(Number.MAX_SAFE_INTEGER),Sh=BigInt(Number.MIN_SAFE_INTEGER),Le=class r{lo;hi;constructor(e,t){this.lo=e|0,this.hi=t|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(t+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(BigInt(t)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return qt;if(e<kh&&e>Sh)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,s=e-(n<<32n);return t&&(n=~n|0n,s=~s|0n,++s>ja&&(s=0n,++n>ja&&(n=0n))),new r(Number(s),Number(n))}static fromNumber(e){if(e===0)return qt;let t=e<0;t&&(e=-e);let n=e>>>0,s=(e-n)/4294967296>>>0;return t&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new r(n,s)}static from(e){return typeof e=="number"?r.fromNumber(e):typeof e=="bigint"?r.fromBigInt(e):typeof e=="string"?r.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new r(e.low>>>0,e.high>>>0):qt}},qt=new Le(0,0);qt.toBigInt=function(){return 0n};qt.zzEncode=qt.zzDecode=function(){return this};qt.length=function(){return 1};var ja=4294967296n;function Wa(r){let e=0,t=0;for(let n=0;n<r.length;++n)t=r.charCodeAt(n),t<128?e+=1:t<2048?e+=2:(t&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function Ya(r,e,t){if(t-e<1)return"";let s,i=[],o=0,a;for(;e<t;)a=r[e++],a<128?i[o++]=a:a>191&&a<224?i[o++]=(a&31)<<6|r[e++]&63:a>239&&a<365?(a=((a&7)<<18|(r[e++]&63)<<12|(r[e++]&63)<<6|r[e++]&63)-65536,i[o++]=55296+(a>>10),i[o++]=56320+(a&1023)):i[o++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,o>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,i)),o=0);return s!=null?(o>0&&s.push(String.fromCharCode.apply(String,i.slice(0,o))),s.join("")):String.fromCharCode.apply(String,i.slice(0,o))}function Li(r,e,t){let n=t,s,i;for(let o=0;o<r.length;++o)s=r.charCodeAt(o),s<128?e[t++]=s:s<2048?(e[t++]=s>>6|192,e[t++]=s&63|128):(s&64512)===55296&&((i=r.charCodeAt(o+1))&64512)===56320?(s=65536+((s&1023)<<10)+(i&1023),++o,e[t++]=s>>18|240,e[t++]=s>>12&63|128,e[t++]=s>>6&63|128,e[t++]=s&63|128):(e[t++]=s>>12|224,e[t++]=s>>6&63|128,e[t++]=s&63|128);return t-n}function qe(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function Nn(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Ui=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,qe(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw qe(this,4);return Nn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw qe(this,4);return Nn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw qe(this,4);let e=$a(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw qe(this,4);let e=Ga(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),t=this.pos,n=this.pos+e;if(n>this.len)throw qe(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return Ya(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw qe(this,e);this.pos+=e}else do if(this.pos>=this.len)throw qe(this);while(this.buf[this.pos++]&128);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Le(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw qe(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<t*7)>>>0,e}if(this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw qe(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw qe(this,8);let e=Nn(this.buf,this.pos+=4),t=Nn(this.buf,this.pos+=4);return new Le(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Ni(this.buf,this.pos);return this.pos+=_e(e),e}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 Pi(r){return new Ui(r instanceof Uint8Array?r:r.subarray())}function Ee(r,e,t){let n=Pi(r);return e.decode(n,void 0,t)}function Di(r){let e=r??8192,t=e>>>1,n,s=e;return function(o){if(o<1||o>t)return Re(o);s+o>e&&(n=Re(e),s=0);let a=n.subarray(s,s+=o);return s&7&&(s=(s|7)+1),a}}var $t=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function Vi(){}var Mi=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Ih=Di();function Rh(r){return globalThis.Buffer!=null?Re(r):Ih(r)}var Hr=class{len;head;tail;states;constructor(){this.len=0,this.head=new $t(Vi,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new $t(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Hi((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(Tn,10,Le.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=Le.fromBigInt(e);return this._push(Tn,t.length(),t)}uint64Number(e){return this._push(Ri,_e(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=Le.fromBigInt(e).zzEncode();return this._push(Tn,t.length(),t)}sint64Number(e){let t=Le.fromNumber(e).zzEncode();return this._push(Tn,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Oi,1,e?1:0)}fixed32(e){return this._push(Mr,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=Le.fromBigInt(e);return this._push(Mr,4,t.lo)._push(Mr,4,t.hi)}fixed64Number(e){let t=Le.fromNumber(e);return this._push(Mr,4,t.lo)._push(Mr,4,t.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(qa,4,e)}double(e){return this._push(za,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Oi,1,0):this.uint32(t)._push(Th,t,e)}string(e){let t=Wa(e);return t!==0?this.uint32(t)._push(Li,t,e):this._push(Oi,1,0)}fork(){return this.states=new Mi(this),this.head=this.tail=new $t(Vi,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 $t(Vi,0,0),this.len=0),this}ldelim(){let e=this.head,t=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=t,this.len+=n),this}finish(){let e=this.head.next,t=Rh(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function Oi(r,e,t){e[t]=r&255}function Nh(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var Hi=class extends $t{next;constructor(e,t){super(Nh,e,t),this.next=void 0}};function Tn(r,e,t){for(;r.hi!==0;)e[t++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)e[t++]=r.lo&127|128,r.lo=r.lo>>>7;e[t++]=r.lo}function Mr(r,e,t){e[t]=r&255,e[t+1]=r>>>8&255,e[t+2]=r>>>16&255,e[t+3]=r>>>24}function Th(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(Hr.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(_h,e,r),this},Hr.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(Ch,e,r),this});function _h(r,e,t){e.set(r,t)}function Ch(r,e,t){r.length<40?Li(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(q(r),t)}function Ki(){return new Hr}function Be(r,e){let t=Ki();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var mr;(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"})(mr||(mr={}));function _n(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function Fi(r){function e(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let t=function(i,o){let a=e(i);o.int32(a)},n=function(i){let o=i.int32();return e(o)};return _n("enum",mr.VARINT,t,n)}function Ae(r,e){return _n("message",mr.LENGTH_DELIMITED,r,e)}var Z;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1"})(Z||(Z={}));var qi;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1"})(qi||(qi={}));(function(r){r.codec=()=>Fi(qi)})(Z||(Z={}));var Ze;(function(r){let e;r.codec=()=>(e==null&&(e=Ae((t,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),Z.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),s.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let s={},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let o=t.uint32();switch(o>>>3){case 1:s.Type=Z.codec().decode(t);break;case 2:s.Data=t.bytes();break;default:t.skipType(o&7);break}}return s})),e),r.encode=t=>Be(t,r.codec()),r.decode=t=>Ee(t,r.codec())})(Ze||(Ze={}));var Je;(function(r){let e;r.codec=()=>(e==null&&(e=Ae((t,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),Z.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),s.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let s={},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let o=t.uint32();switch(o>>>3){case 1:s.Type=Z.codec().decode(t);break;case 2:s.Data=t.bytes();break;default:t.skipType(o&7);break}}return s})),e),r.encode=t=>Be(t,r.codec()),r.decode=t=>Ee(t,r.codec())})(Je||(Je={}));var Kr=class{_key;constructor(e){this._key=yr(e,pr)}verify(e,t){return Ha(this._key,t,e)}marshal(){return this._key}get bytes(){return Ze.encode({Type:Z.Ed25519,Data:this.marshal()}).subarray()}equals(e){return ee(this.bytes,e.bytes)}hash(){let e=de.digest(this.bytes);return Pe(e)?e.then(({bytes:t})=>t):e.bytes}},zt=class{_key;_publicKey;constructor(e,t){this._key=yr(e,ct),this._publicKey=yr(t,pr)}sign(e){return Ma(this._key,e)}get public(){return new Kr(this._publicKey)}marshal(){return this._key}get bytes(){return Je.encode({Type:Z.Ed25519,Data:this.marshal()}).subarray()}equals(e){return ee(this.bytes,e.bytes)}async hash(){let e=de.digest(this.bytes),t;return Pe(e)?{bytes:t}=await e:t=e.bytes,t}async id(){let e=rt.digest(this.public.bytes);return oe.encode(e.bytes).substring(1)}async export(e,t="libp2p-key"){if(t==="libp2p-key")return gr(this.bytes,e);throw new N(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function Lh(r){if(r.length>ct){r=yr(r,ct+pr);let n=r.subarray(0,ct),s=r.subarray(ct,r.length);return new zt(n,s)}r=yr(r,ct);let e=r.subarray(0,ct),t=r.subarray(pr);return new zt(e,t)}function Uh(r){return r=yr(r,pr),new Kr(r)}async function Ph(){let{privateKey:r,publicKey:e}=Va();return new zt(r,e)}async function Ja(r){let{privateKey:e,publicKey:t}=Oa(r);return new zt(e,t)}function yr(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new N(`Key must be a Uint8Array of length ${e}, got ${r.length}`,"ERR_INVALID_KEY_TYPE");return r}function V(r,e="utf8"){let t=yn[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var eo={};ue(eo,{MAX_RSA_KEY_SIZE:()=>Qr,RsaPrivateKey:()=>Er,RsaPublicKey:()=>Xr,fromJwk:()=>cd,generateKeyPair:()=>ld,unmarshalRsaPrivateKey:()=>Xi,unmarshalRsaPublicKey:()=>ad});function Gt(r){if(isNaN(r)||r<=0)throw new N("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return ur(r)}var Nt={};ue(Nt,{exportToPem:()=>rd,importFromPem:()=>nd,jwkToPkcs1:()=>Xh,jwkToPkix:()=>ed,pkcs1ToJwk:()=>Jh,pkixToJwk:()=>Qh});var Ln=class extends cr{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,bn(e);let n=wt(t);if(this.iHash=e.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,i=new Uint8Array(s);i.set(n.length>s?e.create().update(n).digest():n);for(let o=0;o<i.length;o++)i[o]^=54;this.iHash.update(i),this.oHash=e.create();for(let o=0;o<i.length;o++)i[o]^=106;this.oHash.update(i),i.fill(0)}update(e){return ar(this),this.iHash.update(e),this}digestInto(e){ar(this),or(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:t,iHash:n,finished:s,destroyed:i,blockLen:o,outputLen:a}=this;return e=e,e.finished=s,e.destroyed=i,e.blockLen=o,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Fr=(r,e,t)=>new Ln(r,e).update(t).digest();Fr.create=(r,e)=>new Ln(r,e);function Dh(r,e,t,n){bn(r);let s=va({dkLen:32,asyncTick:10},n),{c:i,dkLen:o,asyncTick:a}=s;if(ir(i),ir(o),ir(a),i<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=wt(e),f=wt(t),u=new Uint8Array(o),l=Fr.create(r,c),d=l._cloneInto().update(f);return{c:i,dkLen:o,asyncTick:a,DK:u,PRF:l,PRFSalt:d}}function Vh(r,e,t,n,s){return r.destroy(),e.destroy(),n&&n.destroy(),s.fill(0),t}async function zi(r,e,t,n){let{c:s,dkLen:i,asyncTick:o,DK:a,PRF:c,PRFSalt:f}=Dh(r,e,t,n),u,l=new Uint8Array(4),d=lr(l),y=new Uint8Array(c.outputLen);for(let g=1,h=0;h<i;g++,h+=c.outputLen){let b=a.subarray(h,h+c.outputLen);d.setInt32(0,g,!1),(u=f._cloneInto(u)).update(l).digestInto(y),b.set(y.subarray(0,b.length)),await wa(s-1,o,()=>{c._cloneInto(u).update(y).digestInto(y);for(let v=0;v<b.length;v++)b[v]^=y[v]})}return Vh(c,f,a,u,y)}var O=Zo(Xa());function jt(r,e){let t=0;if(r.length===1)return r[0];for(let n=r.length-1;n>=0;n--)t+=r[r.length-1-n]*Math.pow(2,e*n);return t}function St(r,e,t=-1){let n=t,s=r,i=0,o=Math.pow(2,e);for(let a=1;a<8;a++){if(r<o){let c;if(n<0)c=new ArrayBuffer(a),i=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),i=n}let f=new Uint8Array(c);for(let u=a-1;u>=0;u--){let l=Math.pow(2,u*e);f[i-u-1]=Math.floor(s/l),s-=f[i-u-1]*l}return c}o*=Math.pow(2,e)}return new ArrayBuffer(0)}function Dn(...r){let e=0,t=0;for(let i of r)e+=i.length;let n=new ArrayBuffer(e),s=new Uint8Array(n);for(let i of r)s.set(i,t),t+=i.length;return s}function ji(){let r=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){let a=r[0]===255&&r[1]&128,c=r[0]===0&&(r[1]&128)===0;(a||c)&&this.warnings.push("Needlessly long format")}let e=new ArrayBuffer(this.valueHex.byteLength),t=new Uint8Array(e);for(let a=0;a<this.valueHex.byteLength;a++)t[a]=0;t[0]=r[0]&128;let n=jt(t,8),s=new ArrayBuffer(this.valueHex.byteLength),i=new Uint8Array(s);for(let a=0;a<this.valueHex.byteLength;a++)i[a]=r[a];return i[0]&=127,jt(i,8)-n}function Qa(r){let e=r<0?r*-1:r,t=128;for(let n=1;n<8;n++){if(e<=t){if(r<0){let o=t-e,a=St(o,8,n),c=new Uint8Array(a);return c[0]|=128,a}let s=St(e,8,n),i=new Uint8Array(s);if(i[0]&128){let o=s.slice(0),a=new Uint8Array(o);s=new ArrayBuffer(s.byteLength+1),i=new Uint8Array(s);for(let c=0;c<o.byteLength;c++)i[c+1]=a[c];i[0]=0}return s}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function ec(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let s=0;s<t.length;s++)if(t[s]!==n[s])return!1;return!0}function Ce(r,e){let t=r.toString(10);if(e<t.length)return"";let n=e-t.length,s=new Array(n);for(let o=0;o<n;o++)s[o]="0";return s.join("").concat(t)}var Fg=Math.log(2);function Vn(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Wi(r){let e=0,t=0;for(let s=0;s<r.length;s++){let i=r[s];e+=i.byteLength}let n=new Uint8Array(e);for(let s=0;s<r.length;s++){let i=r[s];n.set(new Uint8Array(i),t),t+=i.byteLength}return n.buffer}function dt(r,e,t,n){return e instanceof Uint8Array?e.byteLength?t<0?(r.error="Wrong parameter: inputOffset less than zero",!1):n<0?(r.error="Wrong parameter: inputLength less than zero",!1):e.byteLength-t-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 $r=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return Wi(this.items)}},qr=[new Uint8Array([1])],tc="0123456789";var xr="",ze=new ArrayBuffer(0),Yi=new Uint8Array(0),zr="EndOfContent",nc="OCTET STRING",sc="BIT STRING";function pt(r){var e;return e=class extends r{constructor(...n){var s;super(...n);let i=n[0]||{};this.isHexOnly=(s=i.isHexOnly)!==null&&s!==void 0?s:!1,this.valueHexView=i.valueHex?O.BufferSourceConverter.toUint8Array(i.valueHex):Yi}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}fromBER(n,s,i){let o=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!dt(this,o,s,i))return-1;let a=s+i;return this.valueHexView=o.subarray(s,a),this.valueHexView.length?(this.blockLength=i,a):(this.warnings.push("Zero buffer length"),s)}toBER(n=!1){return this.isHexOnly?n?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",ze)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:O.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var ut=class{constructor({blockLength:e=0,error:t=xr,warnings:n=[],valueBeforeDecode:s=Yi}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=O.BufferSourceConverter.toUint8Array(s)}static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:O.Convert.ToHex(this.valueBeforeDecodeView)}}};ut.NAME="baseBlock";var be=class extends ut{fromBER(e,t,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(e,t){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}};be.NAME="valueBlock";var On=class extends pt(ut){constructor({idBlock:e={}}={}){var t,n,s,i;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?O.BufferSourceConverter.toUint8Array(e.valueHex):Yi,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(s=e.tagNumber)!==null&&s!==void 0?s:-1,this.isConstructed=(i=e.isConstructed)!==null&&i!==void 0?i:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",ze}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let s=new Uint8Array(1);if(!e){let i=this.tagNumber;i&=31,t|=i,s[0]=t}return s.buffer}if(!this.isHexOnly){let s=St(this.tagNumber,7),i=new Uint8Array(s),o=s.byteLength,a=new Uint8Array(o+1);if(a[0]=t|31,!e){for(let c=0;c<o-1;c++)a[c+1]=i[c]|128;a[o]=i[o-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let s=this.valueHexView;for(let i=0;i<s.length-1;i++)n[i+1]=s[i]|128;n[this.valueHexView.byteLength]=s[s.length-1]}return n.buffer}fromBER(e,t,n){let s=O.BufferSourceConverter.toUint8Array(e);if(!dt(this,s,t,n))return-1;let i=s.subarray(t,t+n);if(i.length===0)return this.error="Zero buffer length",-1;switch(i[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=(i[0]&32)===32,this.isHexOnly=!1;let a=i[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,f=this.valueHexView=new Uint8Array(255),u=255;for(;i[c]&128;){if(f[c-1]=i[c]&127,c++,c>=i.length)return this.error="End of input reached before message was fully decoded",-1;if(c===u){u+=255;let d=new Uint8Array(u);for(let y=0;y<f.length;y++)d[y]=f[y];f=this.valueHexView=new Uint8Array(u)}}this.blockLength=c+1,f[c-1]=i[c]&127;let l=new Uint8Array(c);for(let d=0;d<c;d++)l[d]=f[d];f=this.valueHexView=new Uint8Array(c),f.set(l),this.blockLength<=9?this.tagNumber=jt(f,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 t+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}};On.NAME="identificationBlock";var Mn=class extends ut{constructor({lenBlock:e={}}={}){var t,n,s;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0?t:!1,this.longFormUsed=(n=e.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(s=e.length)!==null&&s!==void 0?s:0}fromBER(e,t,n){let s=O.BufferSourceConverter.toUint8Array(e);if(!dt(this,s,t,n))return-1;let i=s.subarray(t,t+n);if(i.length===0)return this.error="Zero buffer length",-1;if(i[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=i[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(i[0]&128),this.longFormUsed===!1)return this.length=i[0],this.blockLength=1,t+this.blockLength;let o=i[0]&127;if(o>8)return this.error="Too big integer",-1;if(o+1>i.length)return this.error="End of input reached before message was fully decoded",-1;let a=t+1,c=s.subarray(a,a+o);return c[o-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=jt(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=o+1,t+this.blockLength}toBER(e=!1){let t,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=128),t;if(this.longFormUsed){let s=St(this.length,8);if(s.byteLength>127)return this.error="Too big length",ze;if(t=new ArrayBuffer(s.byteLength+1),e)return t;let i=new Uint8Array(s);n=new Uint8Array(t),n[0]=s.byteLength|128;for(let o=0;o<s.byteLength;o++)n[o+1]=i[o];return t}return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};Mn.NAME="lengthBlock";var A={},pe=class extends ut{constructor({name:e=xr,optional:t=!1,primitiveSchema:n,...s}={},i){super(s),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new On(s),this.lenBlock=new Mn(s),this.valueBlock=i?new i(s):new be(s)}fromBER(e,t,n){let s=this.valueBlock.fromBER(e,t,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(e,t){let n=t||new $r;t||ic(this);let s=this.idBlock.toBER(e);if(n.write(s),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,n),n.write(new ArrayBuffer(2));else{let i=this.valueBlock.toBER(e);this.lenBlock.length=i.byteLength;let o=this.lenBlock.toBER(e);n.write(o),n.write(i)}return t?ze:n.final()}toJSON(){let e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return e==="ascii"?this.onAsciiEncoding():O.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${O.Convert.ToHex(this.valueBlock.valueBeforeDecodeView)}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;let t=this.toBER(),n=e.toBER();return ec(t,n)}};pe.NAME="BaseBlock";function ic(r){if(r instanceof A.Constructed)for(let e of r.valueBlock.value)ic(e)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var Hn=class extends pe{constructor({value:e=xr,...t}={},n){super(t,n),e&&this.fromString(e)}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}fromBER(e,t,n){let s=this.valueBlock.fromBER(e,t,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}'`}};Hn.NAME="BaseStringBlock";var Kn=class extends pt(be){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};Kn.NAME="PrimitiveValueBlock";var oc,Fn=class extends pe{constructor(e={}){super(e,Kn),this.idBlock.isConstructed=!1}};oc=Fn;A.Primitive=oc;Fn.NAME="PRIMITIVE";function Gh(r,e){if(r instanceof e)return r;let t=new e;return t.idBlock=r.idBlock,t.lenBlock=r.lenBlock,t.warnings=r.warnings,t.valueBeforeDecodeView=r.valueBeforeDecodeView,t}function vs(r,e=0,t=r.length){let n=e,s=new pe({},be),i=new ut;if(!dt(i,r,e,t))return s.error=i.error,{offset:-1,result:s};if(!r.subarray(e,e+t).length)return s.error="Zero buffer length",{offset:-1,result:s};let a=s.idBlock.fromBER(r,e,t);if(s.idBlock.warnings.length&&s.warnings.concat(s.idBlock.warnings),a===-1)return s.error=s.idBlock.error,{offset:-1,result:s};if(e=a,t-=s.idBlock.blockLength,a=s.lenBlock.fromBER(r,e,t),s.lenBlock.warnings.length&&s.warnings.concat(s.lenBlock.warnings),a===-1)return s.error=s.lenBlock.error,{offset:-1,result:s};if(e=a,t-=s.lenBlock.blockLength,!s.idBlock.isConstructed&&s.lenBlock.isIndefiniteForm)return s.error="Indefinite length form used for primitive encoding form",{offset:-1,result:s};let c=pe;switch(s.idBlock.tagClass){case 1:if(s.idBlock.tagNumber>=37&&s.idBlock.isHexOnly===!1)return s.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:s};switch(s.idBlock.tagNumber){case 0:if(s.idBlock.isConstructed&&s.lenBlock.length>0)return s.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:s};c=A.EndOfContent;break;case 1:c=A.Boolean;break;case 2:c=A.Integer;break;case 3:c=A.BitString;break;case 4:c=A.OctetString;break;case 5:c=A.Null;break;case 6:c=A.ObjectIdentifier;break;case 10:c=A.Enumerated;break;case 12:c=A.Utf8String;break;case 13:c=A.RelativeObjectIdentifier;break;case 14:c=A.TIME;break;case 15:return s.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:s};case 16:c=A.Sequence;break;case 17:c=A.Set;break;case 18:c=A.NumericString;break;case 19:c=A.PrintableString;break;case 20:c=A.TeletexString;break;case 21:c=A.VideotexString;break;case 22:c=A.IA5String;break;case 23:c=A.UTCTime;break;case 24:c=A.GeneralizedTime;break;case 25:c=A.GraphicString;break;case 26:c=A.VisibleString;break;case 27:c=A.GeneralString;break;case 28:c=A.UniversalString;break;case 29:c=A.CharacterString;break;case 30:c=A.BmpString;break;case 31:c=A.DATE;break;case 32:c=A.TimeOfDay;break;case 33:c=A.DateTime;break;case 34:c=A.Duration;break;default:{let f=s.idBlock.isConstructed?new A.Constructed:new A.Primitive;f.idBlock=s.idBlock,f.lenBlock=s.lenBlock,f.warnings=s.warnings,s=f}}break;case 2:case 3:case 4:default:c=s.idBlock.isConstructed?A.Constructed:A.Primitive}return s=Gh(s,c),a=s.fromBER(r,e,s.lenBlock.isIndefiniteForm?t:s.lenBlock.length),s.valueBeforeDecodeView=r.subarray(n,n+s.blockLength),{offset:a,result:s}}function vr(r){if(!r.byteLength){let e=new pe({},be);return e.error="Input buffer has zero length",{offset:-1,result:e}}return vs(O.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function jh(r,e){return r?1:e}var Xe=class extends be{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let s=O.BufferSourceConverter.toUint8Array(e);if(!dt(this,s,t,n))return-1;if(this.valueBeforeDecodeView=s.subarray(t,t+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let i=t;for(;jh(this.isIndefiniteForm,n)>0;){let o=vs(s,i,n);if(o.offset===-1)return this.error=o.result.error,this.warnings.concat(o.result.warnings),-1;if(i=o.offset,this.blockLength+=o.result.blockLength,n-=o.result.blockLength,this.value.push(o.result),this.isIndefiniteForm&&o.result.constructor.NAME===zr)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===zr?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(e,t){let n=t||new $r;for(let s=0;s<this.value.length;s++)this.value[s].toBER(e,n);return t?ze:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};Xe.NAME="ConstructedValueBlock";var ac,It=class extends pe{constructor(e={}){super(e,Xe),this.idBlock.isConstructed=!0}fromBER(e,t,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let s=this.valueBlock.fromBER(e,t,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 e=[];for(let n of this.valueBlock.value)e.push(n.toString("ascii").split(`
|
|
3
3
|
`).map(s=>` ${s}`).join(`
|
|
4
4
|
`));let t=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return e.length?`${t} :
|
|
5
5
|
${e.join(`
|
|
6
|
-
`)}`:`${t} :`}};rc=Rt;k.Constructed=rc;Rt.NAME="CONSTRUCTED";var Hn=class extends xe{fromBER(e,t,n){return t}toBER(e){return $e}};Hn.override="EndOfContentValueBlock";var nc,Kn=class extends ge{constructor(e={}){super(e,Hn),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};nc=Kn;k.EndOfContent=nc;Kn.NAME=qr;var sc,Nt=class extends ge{constructor(e={}){super(e,xe),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,t,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,t+n>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+n}toBER(e,t){let n=new ArrayBuffer(2);if(!e){let s=new Uint8Array(n);s[0]=5,s[1]=0}return t&&t.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};sc=Nt;k.Null=sc;Nt.NAME="NULL";var Fn=class extends pt(xe){constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=H.BufferSourceConverter.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}get value(){for(let e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}fromBER(e,t,n){let s=H.BufferSourceConverter.toUint8Array(e);return dt(this,s,t,n)?(this.valueHexView=s.subarray(t,t+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,Ki.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};Fn.NAME="BooleanValueBlock";var ic,qn=class extends ge{constructor(e={}){super(e,Fn),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};ic=qn;k.Boolean=ic;qn.NAME="BOOLEAN";var $n=class extends pt(Je){constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,n){let s=0;if(this.isConstructed){if(this.isHexOnly=!1,s=Je.prototype.fromBER.call(this,e,t,n),s===-1)return s;for(let i=0;i<this.value.length;i++){let o=this.value[i].constructor.NAME;if(o===qr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(o!==Xa)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,s=super.fromBER(e,t,n),this.blockLength=n;return s}toBER(e,t){return this.isConstructed?Je.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};$n.NAME="OctetStringValueBlock";var oc,ft=class r extends ge{constructor({idBlock:e={},lenBlock:t={},...n}={}){var s,i;(s=n.isConstructed)!==null&&s!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},$n),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,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),t;if(!this.valueBlock.isConstructed){let i=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+n);try{if(i.byteLength){let o=bs(i,0,i.byteLength);o.offset!==-1&&o.offset===n&&(this.valueBlock.value=[o.result])}}catch{}}return super.fromBER(e,t,n)}onAsciiEncoding(){return this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length?Rt.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${H.Convert.ToHex(this.valueBlock.valueHexView)}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let e=[];for(let t of this.valueBlock.value)t instanceof r&&e.push(t.valueBlock.valueHexView);return H.BufferSourceConverter.concat(e)}};oc=ft;k.OctetString=oc;ft.NAME=Xa;var zn=class extends pt(Je){constructor({unusedBits:e=0,isConstructed:t=!1,...n}={}){super(n),this.unusedBits=e,this.isConstructed=t,this.blockLength=this.valueHexView.byteLength}fromBER(e,t,n){if(!n)return t;let s=-1;if(this.isConstructed){if(s=Je.prototype.fromBER.call(this,e,t,n),s===-1)return s;for(let a of this.value){let c=a.constructor.NAME;if(c===qr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==Qa)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let f=a.valueBlock;if(this.unusedBits>0&&f.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=f.unusedBits}return s}let i=H.BufferSourceConverter.toUint8Array(e);if(!dt(this,i,t,n))return-1;let o=i.subarray(t,t+n);if(this.unusedBits=o[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let a=o.subarray(1);try{if(a.byteLength){let c=bs(a,0,a.byteLength);c.offset!==-1&&c.offset===n-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=o.subarray(1),this.blockLength=o.length,t+n}toBER(e,t){if(this.isConstructed)return Je.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return $e;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}}};zn.NAME="BitStringValueBlock";var ac,br=class extends ge{constructor({idBlock:e={},lenBlock:t={},...n}={}){var s,i;(s=n.isConstructed)!==null&&s!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},zn),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,t,n){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,t,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return Rt.prototype.onAsciiEncoding.call(this);{let e=[],t=this.valueBlock.valueHexView;for(let s of t)e.push(s.toString(2).padStart(8,"0"));let n=e.join("");return`${this.constructor.NAME} : ${n.substring(0,n.length-this.valueBlock.unusedBits)}`}}};ac=br;k.BitString=ac;br.NAME=Qa;var cc;function Fh(r,e){let t=new Uint8Array([0]),n=new Uint8Array(r),s=new Uint8Array(e),i=n.slice(0),o=i.length-1,a=s.slice(0),c=a.length-1,f=0,u=c<o?o:c,l=0;for(let h=u;h>=0;h--,l++){switch(!0){case l<a.length:f=i[o-l]+a[c-l]+t[0];break;default:f=i[o-l]+t[0]}switch(t[0]=f/10,!0){case l>=i.length:i=Ln(new Uint8Array([f%10]),i);break;default:i[o-l]=f%10}}return t[0]>0&&(i=Ln(t,i)),i}function Ja(r){if(r>=Kr.length)for(let e=Kr.length;e<=r;e++){let t=new Uint8Array([0]),n=Kr[e-1].slice(0);for(let s=n.length-1;s>=0;s--){let i=new Uint8Array([(n[s]<<1)+t[0]]);t[0]=i[0]/10,n[s]=i[0]%10}t[0]>0&&(n=Ln(t,n)),Kr.push(n)}return Kr[r]}function qh(r,e){let t=0,n=new Uint8Array(r),s=new Uint8Array(e),i=n.slice(0),o=i.length-1,a=s.slice(0),c=a.length-1,f,u=0;for(let l=c;l>=0;l--,u++)switch(f=i[o-u]-a[c-u]-t,!0){case f<0:t=1,i[o-u]=f+10;break;default:t=0,i[o-u]=f}if(t>0)for(let l=o-c+1;l>=0;l--,u++)if(f=i[o-u]-t,f<0)t=1,i[o-u]=f+10;else{t=0,i[o-u]=f;break}return i.slice()}var $r=class extends pt(xe){constructor({value:e,...t}={}){super(t),this._valueDec=0,t.valueHex&&this.setValueHex(),e!==void 0&&(this.valueDec=e)}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=Ki.call(this)))}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(ja(e))}get valueDec(){return this._valueDec}fromDER(e,t,n,s=0){let i=this.fromBER(e,t,n);if(i===-1)return i;let o=this.valueHexView;return o[0]===0&&o[1]&128?this.valueHexView=o.subarray(1):s!==0&&o.length<s&&(s-o.length>1&&(s=o.length+1),this.valueHexView=o.subarray(s-o.length)),i}toDER(e=!1){let t=this.valueHexView;switch(!0){case(t[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(t,1),this.valueHexView=n}break;case(t[0]===0&&(t[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,t,n){let s=super.fromBER(e,t,n);return s===-1||this.setValueHex(),s}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let e=this.valueHexView.length*8-1,t=new Uint8Array(this.valueHexView.length*8/3),n=0,s,i=this.valueHexView,o="",a=!1;for(let c=i.byteLength-1;c>=0;c--){s=i[c];for(let f=0;f<8;f++){if((s&1)===1)switch(n){case e:t=qh(Ja(n),t),o="-";break;default:t=Fh(t,Ja(n))}n++,s>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(o+=Za.charAt(t[c]));return a===!1&&(o+=Za.charAt(0)),o}};cc=$r;$r.NAME="IntegerValueBlock";Object.defineProperty(cc.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var lc,oe=class r extends ge{constructor(e={}){super(e,$r),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Un(),BigInt(this.valueBlock.toString())}static fromBigInt(e){Un();let t=BigInt(e),n=new Fr,s=t.toString(16).replace(/^-/,""),i=new Uint8Array(H.Convert.FromHex(s));if(t<0){let a=new Uint8Array(i.length+(i[0]&128?1:0));a[0]|=128;let f=BigInt(`0x${H.Convert.ToHex(a)}`)+t,u=H.BufferSourceConverter.toUint8Array(H.Convert.FromHex(f.toString(16)));u[0]|=128,n.write(u)}else i[0]&128&&n.write(new Uint8Array([0])),n.write(i);return new r({valueHex:n.final()})}convertToDER(){let e=new r({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}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()}`}};lc=oe;k.Integer=lc;oe.NAME="INTEGER";var uc,Gn=class extends oe{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};uc=Gn;k.Enumerated=uc;Gn.NAME="ENUMERATED";var zr=class extends pt(xe){constructor({valueDec:e=-1,isFirstSid:t=!1,...n}={}){super(n),this.valueDec=e,this.isFirstSid=t}fromBER(e,t,n){if(!n)return t;let s=H.BufferSourceConverter.toUint8Array(e);if(!dt(this,s,t,n))return-1;let i=s.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=i[a]&127,this.blockLength++,!!(i[a]&128));a++);let o=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)o[a]=this.valueHexView[a];return this.valueHexView=o,i[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Gt(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){Un();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;let n=new Uint8Array(t.length/7);for(let s=0;s<n.length;s++)n[s]=parseInt(t.slice(s*7,s*7+7),2)+(s+1<n.length?128:0);this.fromBER(n.buffer,0,n.length)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let s=this.valueHexView,i=new Uint8Array(this.blockLength);for(let o=0;o<this.blockLength-1;o++)i[o]=s[o]|128;return i[this.blockLength-1]=s[this.blockLength-1],i.buffer}let t=It(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",$e;let n=new Uint8Array(t.byteLength);if(!e){let s=new Uint8Array(t),i=t.byteLength-1;for(let o=0;o<i;o++)n[o]=s[o]|128;n[i]=s[i]}return n}toString(){let e="";if(this.isHexOnly)e=H.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let t=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",t-=40):(e="2.",t-=80),e+=t.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};zr.NAME="sidBlock";var Wn=class extends xe{constructor({value:e=wr,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let s=t;for(;n>0;){let i=new zr;if(s=i.fromBER(e,s,n),s===-1)return this.blockLength=0,this.error=i.error,s;this.value.length===0&&(i.isFirstSid=!0),this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return s}toBER(e){let t=[];for(let n=0;n<this.value.length;n++){let s=this.value[n].toBER(e);if(s.byteLength===0)return this.error=this.value[n].error,$e;t.push(s)}return Fi(t)}fromString(e){this.value=[];let t=0,n=0,s="",i=!1;do if(n=e.indexOf(".",t),n===-1?s=e.substring(t):s=e.substring(t,n),t=n+1,i){let o=this.value[0],a=0;switch(o.valueDec){case 0:break;case 1:a=40;break;case 2:a=80;break;default:this.value=[];return}let c=parseInt(s,10);if(isNaN(c))return;o.valueDec=c+a,i=!1}else{let o=new zr;if(s>Number.MAX_SAFE_INTEGER){Un();let a=BigInt(s);o.valueBigInt=a}else if(o.valueDec=parseInt(s,10),isNaN(o.valueDec))return;this.value.length||(o.isFirstSid=!0,i=!0),this.value.push(o)}while(n!==-1)}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let s=this.value[n].toString();n!==0&&(e=`${e}.`),t?(s=`{${s}}`,this.value[n].isFirstSid?e=`2.{${s} - 80}`:e+=s):e+=s}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};Wn.NAME="ObjectIdentifierValueBlock";var fc,qe=class extends ge{constructor(e={}){super(e,Wn),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};fc=qe;k.ObjectIdentifier=fc;qe.NAME="OBJECT IDENTIFIER";var Gr=class extends pt(ut){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let s=H.BufferSourceConverter.toUint8Array(e);if(!dt(this,s,t,n))return-1;let i=s.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=i[a]&127,this.blockLength++,!!(i[a]&128));a++);let o=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)o[a]=this.valueHexView[a];return this.valueHexView=o,i[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Gt(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let s=this.valueHexView,i=new Uint8Array(this.blockLength);for(let o=0;o<this.blockLength-1;o++)i[o]=s[o]|128;return i[this.blockLength-1]=s[this.blockLength-1],i.buffer}let t=It(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",$e;let n=new Uint8Array(t.byteLength);if(!e){let s=new Uint8Array(t),i=t.byteLength-1;for(let o=0;o<i;o++)n[o]=s[o]|128;n[i]=s[i]}return n.buffer}toString(){let e="";return this.isHexOnly?e=H.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};Gr.NAME="relativeSidBlock";var jn=class extends xe{constructor({value:e=wr,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let s=t;for(;n>0;){let i=new Gr;if(s=i.fromBER(e,s,n),s===-1)return this.blockLength=0,this.error=i.error,s;this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return s}toBER(e,t){let n=[];for(let s=0;s<this.value.length;s++){let i=this.value[s].toBER(e);if(i.byteLength===0)return this.error=this.value[s].error,$e;n.push(i)}return Fi(n)}fromString(e){this.value=[];let t=0,n=0,s="";do{n=e.indexOf(".",t),n===-1?s=e.substring(t):s=e.substring(t,n),t=n+1;let i=new Gr;if(i.valueDec=parseInt(s,10),isNaN(i.valueDec))return!0;this.value.push(i)}while(n!==-1);return!0}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let s=this.value[n].toString();n!==0&&(e=`${e}.`),t&&(s=`{${s}}`),e+=s}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};jn.NAME="RelativeObjectIdentifierValueBlock";var hc,Yn=class extends ge{constructor(e={}){super(e,jn),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};hc=Yn;k.RelativeObjectIdentifier=hc;Yn.NAME="RelativeObjectIdentifier";var dc,fe=class extends Rt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};dc=fe;k.Sequence=dc;fe.NAME="SEQUENCE";var pc,Zn=class extends Rt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};pc=Zn;k.Set=pc;Zn.NAME="SET";var Jn=class extends pt(xe){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=wr}toJSON(){return{...super.toJSON(),value:this.value}}};Jn.NAME="StringValueBlock";var Xn=class extends Jn{};Xn.NAME="SimpleStringValueBlock";var Ie=class extends Vn{constructor({...e}={}){super(e,Xn)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,H.BufferSourceConverter.toUint8Array(e))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t);for(let s=0;s<t;s++)n[s]=e.charCodeAt(s);this.valueBlock.value=e}};Ie.NAME="SIMPLE STRING";var Qn=class extends Ie{fromBuffer(e){this.valueBlock.valueHexView=H.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=H.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=H.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(H.Convert.FromUtf8String(e)),this.valueBlock.value=e}};Qn.NAME="Utf8StringValueBlock";var gc,ht=class extends Qn{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};gc=ht;k.Utf8String=gc;ht.NAME="UTF8String";var es=class extends Ie{fromBuffer(e){this.valueBlock.value=H.Convert.ToUtf16String(e),this.valueBlock.valueHexView=H.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(H.Convert.FromUtf16String(e))}};es.NAME="BmpStringValueBlock";var mc,ts=class extends es{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};mc=ts;k.BmpString=mc;ts.NAME="BMPString";var rs=class extends Ie{fromBuffer(e){let t=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),n=new Uint8Array(t);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(t))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t*4);for(let s=0;s<t;s++){let i=It(e.charCodeAt(s),8),o=new Uint8Array(i);if(o.length>4)continue;let a=4-o.length;for(let c=o.length-1;c>=0;c--)n[s*4+c+a]=o[c]}this.valueBlock.value=e}};rs.NAME="UniversalStringValueBlock";var yc,ns=class extends rs{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};yc=ns;k.UniversalString=yc;ns.NAME="UniversalString";var bc,ss=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};bc=ss;k.NumericString=bc;ss.NAME="NumericString";var wc,is=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};wc=is;k.PrintableString=wc;is.NAME="PrintableString";var xc,os=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};xc=os;k.TeletexString=xc;os.NAME="TeletexString";var vc,as=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};vc=as;k.VideotexString=vc;as.NAME="VideotexString";var Ec,cs=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};Ec=cs;k.IA5String=Ec;cs.NAME="IA5String";var Bc,ls=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};Bc=ls;k.GraphicString=Bc;ls.NAME="GraphicString";var Ac,Wr=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};Ac=Wr;k.VisibleString=Ac;Wr.NAME="VisibleString";var kc,us=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};kc=us;k.GeneralString=kc;us.NAME="GeneralString";var Sc,fs=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};Sc=fs;k.CharacterString=Sc;fs.NAME="CharacterString";var Ic,jr=class extends Wr{constructor({value:e,valueDate:t,...n}={}){if(super(n),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let s=0;s<e.length;s++)this.valueBlock.valueHexView[s]=e.charCodeAt(s)}t&&(this.fromDate(t),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,H.BufferSourceConverter.toUint8Array(e)))}toBuffer(){let e=this.toString(),t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let s=0;s<e.length;s++)n[s]=e.charCodeAt(s);return t}fromDate(e){this.year=e.getUTCFullYear(),this.month=e.getUTCMonth()+1,this.day=e.getUTCDate(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(e){let n=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(e);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(e="iso"){if(e==="iso"){let t=new Array(7);return t[0]=_e(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=_e(this.month,2),t[2]=_e(this.day,2),t[3]=_e(this.hour,2),t[4]=_e(this.minute,2),t[5]=_e(this.second,2),t[6]="Z",t.join("")}return super.toString(e)}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}}};Ic=jr;k.UTCTime=Ic;jr.NAME="UTCTime";var Rc,hs=class extends jr{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond))}fromString(e){let t=!1,n="",s="",i=0,o,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),t=!0;else{let l=new Number(e[e.length-1]);if(isNaN(l.valueOf()))throw new Error("Wrong input string for conversion");n=e}if(t){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 l=1,h=n.indexOf("+"),m="";if(h===-1&&(h=n.indexOf("-"),l=-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(a=l*p,m.length===4){if(p=parseInt(m.substring(2,4),10),isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");c=l*p}}}let f=n.indexOf(".");if(f===-1&&(f=n.indexOf(",")),f!==-1){let l=new Number(`0${n.substring(f)}`);if(isNaN(l.valueOf()))throw new Error("Wrong input string for conversion");i=l.valueOf(),s=n.substring(0,f)}else s=n;switch(!0){case s.length===8:if(o=/(\d{4})(\d{2})(\d{2})/ig,f!==-1)throw new Error("Wrong input string for conversion");break;case s.length===10:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let l=60*i;this.minute=Math.floor(l),l=60*(l-this.minute),this.second=Math.floor(l),l=1e3*(l-this.second),this.millisecond=Math.floor(l)}break;case s.length===12:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let l=60*i;this.second=Math.floor(l),l=1e3*(l-this.second),this.millisecond=Math.floor(l)}break;case s.length===14:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let l=1e3*i;this.millisecond=Math.floor(l)}break;default:throw new Error("Wrong input string for conversion")}let u=o.exec(s);if(u===null)throw new Error("Wrong input string for conversion");for(let l=1;l<u.length;l++)switch(l){case 1:this.year=parseInt(u[l],10);break;case 2:this.month=parseInt(u[l],10);break;case 3:this.day=parseInt(u[l],10);break;case 4:this.hour=parseInt(u[l],10)+a;break;case 5:this.minute=parseInt(u[l],10)+c;break;case 6:this.second=parseInt(u[l],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){let l=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=l.getUTCFullYear(),this.month=l.getUTCMonth(),this.day=l.getUTCDay(),this.hour=l.getUTCHours(),this.minute=l.getUTCMinutes(),this.second=l.getUTCSeconds(),this.millisecond=l.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let t=[];return t.push(_e(this.year,4)),t.push(_e(this.month,2)),t.push(_e(this.day,2)),t.push(_e(this.hour,2)),t.push(_e(this.minute,2)),t.push(_e(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(_e(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};Rc=hs;k.GeneralizedTime=Rc;hs.NAME="GeneralizedTime";var Nc,ds=class extends ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};Nc=ds;k.DATE=Nc;ds.NAME="DATE";var Tc,ps=class extends ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};Tc=ps;k.TimeOfDay=Tc;ps.NAME="TimeOfDay";var _c,gs=class extends ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};_c=gs;k.DateTime=_c;gs.NAME="DateTime";var Cc,ms=class extends ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};Cc=ms;k.Duration=Cc;ms.NAME="Duration";var Lc,ys=class extends ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};Lc=ys;k.TIME=Lc;ys.NAME="TIME";function zh(r){let{result:e}=xr(r),t=e.valueBlock.value;return{n:M(Xe(t[1].toBigInt()),"base64url"),e:M(Xe(t[2].toBigInt()),"base64url"),d:M(Xe(t[3].toBigInt()),"base64url"),p:M(Xe(t[4].toBigInt()),"base64url"),q:M(Xe(t[5].toBigInt()),"base64url"),dp:M(Xe(t[6].toBigInt()),"base64url"),dq:M(Xe(t[7].toBigInt()),"base64url"),qi:M(Xe(t[8].toBigInt()),"base64url"),kty:"RSA",alg:"RS256"}}function Gh(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 R("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new fe({value:[new oe({value:0}),oe.fromBigInt(Qe(G(r.n,"base64url"))),oe.fromBigInt(Qe(G(r.e,"base64url"))),oe.fromBigInt(Qe(G(r.d,"base64url"))),oe.fromBigInt(Qe(G(r.p,"base64url"))),oe.fromBigInt(Qe(G(r.q,"base64url"))),oe.fromBigInt(Qe(G(r.dp,"base64url"))),oe.fromBigInt(Qe(G(r.dq,"base64url"))),oe.fromBigInt(Qe(G(r.qi,"base64url")))]}).toBER();return new Uint8Array(t,0,t.byteLength)}function Wh(r){let{result:e}=xr(r),t=e.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:M(Xe(t[0].toBigInt()),"base64url"),e:M(Xe(t[1].toBigInt()),"base64url")}}function jh(r){if(r.n==null||r.e==null)throw new R("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new fe({value:[new fe({value:[new qe({value:"1.2.840.113549.1.1.1"}),new Nt]}),new br({valueHex:new fe({value:[oe.fromBigInt(Qe(G(r.n,"base64url"))),oe.fromBigInt(Qe(G(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(t,0,t.byteLength)}function Xe(r){let e=r.toString(16);e.length%2>0&&(e=`0${e}`);let t=e.length/2,n=new Uint8Array(t),s=0,i=0;for(;s<t;)n[s]=parseInt(e.slice(i,i+2),16),s+=1,i+=2;return n}function Qe(r){let e=[];return r.forEach(function(t){let n=t.toString(16);n.length%2>0&&(n=`0${n}`),e.push(n)}),BigInt("0x"+e.join(""))}var Yh=16,$i=32,zi=1e4;async function Zh(r,e){let t=Be.get(),s=new fe({value:[new oe({value:0}),new fe({value:[new qe({value:"1.2.840.113549.1.1.1"}),new Nt]}),new ft({valueHex:r.marshal()})]}).toBER(),i=new Uint8Array(s,0,s.byteLength),o=zt(Yh),a=await Mi(Ur,e,o,{c:zi,dkLen:$i}),c=zt(16),f=await t.subtle.importKey("raw",a,"AES-CBC",!1,["encrypt"]),u=await t.subtle.encrypt({name:"AES-CBC",iv:c},f,i),l=new fe({value:[new ft({valueHex:o}),new oe({value:zi}),new oe({value:$i}),new fe({value:[new qe({value:"1.2.840.113549.2.11"}),new Nt]})]}),h=new fe({value:[new qe({value:"1.2.840.113549.1.5.13"}),new fe({value:[new fe({value:[new qe({value:"1.2.840.113549.1.5.12"}),l]}),new fe({value:[new qe({value:"2.16.840.1.101.3.4.1.42"}),new ft({valueHex:c})]})]})]}),p=new fe({value:[h,new ft({valueHex:u})]}).toBER(),d=new Uint8Array(p,0,p.byteLength);return["-----BEGIN ENCRYPTED PRIVATE KEY-----",...M(d,"base64pad").split(/(.{64})/).filter(Boolean),"-----END ENCRYPTED PRIVATE KEY-----"].join(`
|
|
7
|
-
`)}async function Jh(r,e){let t=Be.get(),n;if(r.includes("-----BEGIN ENCRYPTED PRIVATE KEY-----")){let s=G(r.replace("-----BEGIN ENCRYPTED PRIVATE KEY-----","").replace("-----END ENCRYPTED PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:i}=xr(s),{iv:o,salt:a,iterations:c,keySize:f,cipherText:u}=Xh(i),l=await Mi(Ur,e,a,{c,dkLen:f}),h=await t.subtle.importKey("raw",l,"AES-CBC",!1,["decrypt"]),m=Yr(await t.subtle.decrypt({name:"AES-CBC",iv:o},h,u)),{result:p}=xr(m);n=Uc(p)}else if(r.includes("-----BEGIN PRIVATE KEY-----")){let s=G(r.replace("-----BEGIN PRIVATE KEY-----","").replace("-----END PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:i}=xr(s);n=Uc(i)}else throw new R("Could not parse private key from PEM data","ERR_INVALID_PARAMETERS");return Gi(n)}function Xh(r){let e=r.valueBlock.value[0];if(e.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.13")throw new R("Only pkcs5PBES2 encrypted private keys are supported","ERR_INVALID_PARAMS");let n=e.valueBlock.value[1].valueBlock.value[0];if(n.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.12")throw new R("Only pkcs5PBKDF2 key derivation functions are supported","ERR_INVALID_PARAMS");let i=n.valueBlock.value[1],o=Yr(i.valueBlock.value[0].getValue()),a=zi,c=$i;if(i.valueBlock.value.length===3)a=Number(i.valueBlock.value[1].toBigInt()),c=Number(i.valueBlock.value[2].toBigInt());else if(i.valueBlock.value.length===2)throw new R("Could not derive key size and iterations from PEM file - please use @libp2p/rsa to re-import your key","ERR_INVALID_PARAMS");let f=e.valueBlock.value[1].valueBlock.value[1],u=f.valueBlock.value[0].toString();if(u!=="OBJECT IDENTIFIER : 1.2.840.113549.3.7"){if(u!=="OBJECT IDENTIFIER : 1.3.14.3.2.7"){if(u!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.2"){if(u!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.22"){if(u!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.42")throw new R("Only AES-CBC encryption schemes are supported","ERR_INVALID_PARAMS")}}}}let l=Yr(f.valueBlock.value[1].getValue());return{cipherText:Yr(r.valueBlock.value[1].getValue()),salt:o,iterations:a,keySize:c,iv:l}}function Uc(r){return Yr(r.valueBlock.value[2].getValue())}function Yr(r){return new Uint8Array(r,0,r.byteLength)}async function Pc(r){let e=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"]),t=await Oc(e);return{privateKey:t[0],publicKey:t[1]}}async function Wi(r){let t=[await Be.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),await Qh(r)],n=await Oc({privateKey:t[0],publicKey:t[1]});return{privateKey:n[0],publicKey:n[1]}}async function Dc(r,e){let t=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"},t,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(n,0,n.byteLength)}async function Vc(r,e,t){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,e,t instanceof Uint8Array?t:t.subarray())}async function Oc(r){if(r.privateKey==null||r.publicKey==null)throw new R("Private and public key are required","ERR_INVALID_PARAMETERS");return Promise.all([Be.get().subtle.exportKey("jwk",r.privateKey),Be.get().subtle.exportKey("jwk",r.publicKey)])}async function Qh(r){return Be.get().subtle.importKey("jwk",{kty:r.kty,n:r.n,e:r.e},{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])}function ws(r){if(r.kty!=="RSA")throw new R("invalid key type","ERR_INVALID_KEY_TYPE");if(r.n==null)throw new R("invalid key modulus","ERR_INVALID_KEY_MODULUS");return G(r.n,"base64url").length*8}var Jr=8192,Zr=class{_key;constructor(e){this._key=e}verify(e,t){return Vc(this._key,t,e)}marshal(){return Tt.jwkToPkix(this._key)}get bytes(){return Ye.encode({Type:X.RSA,Data:this.marshal()}).subarray()}equals(e){return te(this.bytes,e.bytes)}hash(){let e=pe.digest(this.bytes);return De(e)?e.then(({bytes:t})=>t):e.bytes}},vr=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t}genSecret(){return zt(16)}sign(e){return Dc(this._key,e)}get public(){if(this._publicKey==null)throw new R("public key not provided","ERR_PUBKEY_NOT_PROVIDED");return new Zr(this._publicKey)}marshal(){return Tt.jwkToPkcs1(this._key)}get bytes(){return Ze.encode({Type:X.RSA,Data:this.marshal()}).subarray()}equals(e){return te(this.bytes,e.bytes)}hash(){let e=pe.digest(this.bytes);return De(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return M(e,"base58btc")}async export(e,t="pkcs-8"){if(t==="pkcs-8")return Tt.exportToPem(this,e);if(t==="libp2p-key")return pr(this.bytes,e);throw new R(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};async function Gi(r){let e=Tt.pkcs1ToJwk(r);if(ws(e)>Jr)throw new R("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await Wi(e);return new vr(t.privateKey,t.publicKey)}function td(r){let e=Tt.pkixToJwk(r);if(ws(e)>Jr)throw new R("key size is too large","ERR_KEY_SIZE_TOO_LARGE");return new Zr(e)}async function rd(r){if(ws(r)>Jr)throw new R("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await Wi(r);return new vr(e.privateKey,e.publicKey)}async function nd(r){if(r>Jr)throw new R("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await Pc(r);return new vr(e.privateKey,e.publicKey)}var Qi={};ue(Qi,{Secp256k1PrivateKey:()=>Qr,Secp256k1PublicKey:()=>Xr,generateKeyPair:()=>md,unmarshalSecp256k1PrivateKey:()=>pd,unmarshalSecp256k1PublicKey:()=>gd});var sd=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]),_t=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Ct=new Uint32Array(64),Yi=class extends ur{constructor(){super(64,32,8,!1),this.A=_t[0]|0,this.B=_t[1]|0,this.C=_t[2]|0,this.D=_t[3]|0,this.E=_t[4]|0,this.F=_t[5]|0,this.G=_t[6]|0,this.H=_t[7]|0}get(){let{A:e,B:t,C:n,D:s,E:i,F:o,G:a,H:c}=this;return[e,t,n,s,i,o,a,c]}set(e,t,n,s,i,o,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=s|0,this.E=i|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,t){for(let l=0;l<16;l++,t+=4)Ct[l]=e.getUint32(t,!1);for(let l=16;l<64;l++){let h=Ct[l-15],m=Ct[l-2],p=He(h,7)^He(h,18)^h>>>3,d=He(m,17)^He(m,19)^m>>>10;Ct[l]=d+Ct[l-7]+p+Ct[l-16]|0}let{A:n,B:s,C:i,D:o,E:a,F:c,G:f,H:u}=this;for(let l=0;l<64;l++){let h=He(a,6)^He(a,11)^He(a,25),m=u+h+ya(a,c,f)+sd[l]+Ct[l]|0,d=(He(n,2)^He(n,13)^He(n,22))+ba(n,s,i)|0;u=f,f=c,c=a,a=o+m|0,o=i,i=s,s=n,n=m+d|0}n=n+this.A|0,s=s+this.B|0,i=i+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,s,i,o,a,c,f,u)}roundClean(){Ct.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Mc=yn(()=>new Yi);function id(r){let e=Dr(r);We(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:t,Fp:n,a:s}=e;if(t){if(!n.eql(s,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof t!="object"||typeof t.beta!="bigint"||typeof t.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}var{bytesToNumberBE:od,hexToBytes:ad}=xn,Wt={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(r){let{Err:e}=Wt;if(r.length<2||r[0]!==2)throw new e("Invalid signature integer tag");let t=r[1],n=r.subarray(2,t+2);if(!t||n.length!==t)throw new e("Invalid signature integer: wrong length");if(n[0]&128)throw new e("Invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new e("Invalid signature integer: unnecessary leading zero");return{d:od(n),l:r.subarray(t+2)}},toSig(r){let{Err:e}=Wt,t=typeof r=="string"?ad(r):r;fr(t);let n=t.length;if(n<2||t[0]!=48)throw new e("Invalid signature tag");if(t[1]!==n-2)throw new e("Invalid signature: incorrect length");let{d:s,l:i}=Wt._parseInt(t.subarray(2)),{d:o,l:a}=Wt._parseInt(i);if(a.length)throw new e("Invalid signature: left bytes after parsing");return{r:s,s:o}},hexFromSig(r){let e=f=>Number.parseInt(f[0],16)&8?"00"+f:f,t=f=>{let u=f.toString(16);return u.length&1?`0${u}`:u},n=e(t(r.s)),s=e(t(r.r)),i=n.length/2,o=s.length/2,a=t(i),c=t(o);return`30${t(o+i+4)}02${c}${s}02${a}${n}`}},gt=BigInt(0),Oe=BigInt(1),cm=BigInt(2),Hc=BigInt(3),lm=BigInt(4);function cd(r){let e=id(r),{Fp:t}=e,n=e.toBytes||((p,d,g)=>{let b=d.toAffine();return at(Uint8Array.from([4]),t.toBytes(b.x),t.toBytes(b.y))}),s=e.fromBytes||(p=>{let d=p.subarray(1),g=t.fromBytes(d.subarray(0,t.BYTES)),b=t.fromBytes(d.subarray(t.BYTES,2*t.BYTES));return{x:g,y:b}});function i(p){let{a:d,b:g}=e,b=t.sqr(p),B=t.mul(b,p);return t.add(t.add(B,t.mul(p,d)),g)}if(!t.eql(t.sqr(e.Gy),i(e.Gx)))throw new Error("bad generator point: equation left != right");function o(p){return typeof p=="bigint"&><p&&p<e.n}function a(p){if(!o(p))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(p){let{allowedPrivateKeyLengths:d,nByteLength:g,wrapPrivateKey:b,n:B}=e;if(d&&typeof p!="bigint"){if(Bt(p)&&(p=it(p)),typeof p!="string"||!d.includes(p.length))throw new Error("Invalid key");p=p.padStart(g*2,"0")}let w;try{w=typeof p=="bigint"?p:ot(re("private key",p,g))}catch{throw new Error(`private key must be ${g} bytes, hex or bigint, not ${typeof p}`)}return b&&(w=j(w,B)),a(w),w}let f=new Map;function u(p){if(!(p instanceof l))throw new Error("ProjectivePoint expected")}class l{constructor(d,g,b){if(this.px=d,this.py=g,this.pz=b,d==null||!t.isValid(d))throw new Error("x required");if(g==null||!t.isValid(g))throw new Error("y required");if(b==null||!t.isValid(b))throw new Error("z required")}static fromAffine(d){let{x:g,y:b}=d||{};if(!d||!t.isValid(g)||!t.isValid(b))throw new Error("invalid affine point");if(d instanceof l)throw new Error("projective point not allowed");let B=w=>t.eql(w,t.ZERO);return B(g)&&B(b)?l.ZERO:new l(g,b,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){let g=t.invertBatch(d.map(b=>b.pz));return d.map((b,B)=>b.toAffine(g[B])).map(l.fromAffine)}static fromHex(d){let g=l.fromAffine(s(re("pointHex",d)));return g.assertValidity(),g}static fromPrivateKey(d){return l.BASE.multiply(c(d))}_setWindowSize(d){this._WINDOW_SIZE=d,f.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!t.is0(this.py))return;throw new Error("bad point: ZERO")}let{x:d,y:g}=this.toAffine();if(!t.isValid(d)||!t.isValid(g))throw new Error("bad point: x or y not FE");let b=t.sqr(g),B=i(d);if(!t.eql(b,B))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:d}=this.toAffine();if(t.isOdd)return!t.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){u(d);let{px:g,py:b,pz:B}=this,{px:w,py:_,pz:x}=d,A=t.eql(t.mul(g,x),t.mul(w,B)),N=t.eql(t.mul(b,x),t.mul(_,B));return A&&N}negate(){return new l(this.px,t.neg(this.py),this.pz)}double(){let{a:d,b:g}=e,b=t.mul(g,Hc),{px:B,py:w,pz:_}=this,x=t.ZERO,A=t.ZERO,N=t.ZERO,T=t.mul(B,B),z=t.mul(w,w),F=t.mul(_,_),P=t.mul(B,w);return P=t.add(P,P),N=t.mul(B,_),N=t.add(N,N),x=t.mul(d,N),A=t.mul(b,F),A=t.add(x,A),x=t.sub(z,A),A=t.add(z,A),A=t.mul(x,A),x=t.mul(P,x),N=t.mul(b,N),F=t.mul(d,F),P=t.sub(T,F),P=t.mul(d,P),P=t.add(P,N),N=t.add(T,T),T=t.add(N,T),T=t.add(T,F),T=t.mul(T,P),A=t.add(A,T),F=t.mul(w,_),F=t.add(F,F),T=t.mul(F,P),x=t.sub(x,T),N=t.mul(F,z),N=t.add(N,N),N=t.add(N,N),new l(x,A,N)}add(d){u(d);let{px:g,py:b,pz:B}=this,{px:w,py:_,pz:x}=d,A=t.ZERO,N=t.ZERO,T=t.ZERO,z=e.a,F=t.mul(e.b,Hc),P=t.mul(g,w),se=t.mul(b,_),ne=t.mul(B,x),Ue=t.add(g,b),v=t.add(w,_);Ue=t.mul(Ue,v),v=t.add(P,se),Ue=t.sub(Ue,v),v=t.add(g,B);let I=t.add(w,x);return v=t.mul(v,I),I=t.add(P,ne),v=t.sub(v,I),I=t.add(b,B),A=t.add(_,x),I=t.mul(I,A),A=t.add(se,ne),I=t.sub(I,A),T=t.mul(z,v),A=t.mul(F,ne),T=t.add(A,T),A=t.sub(se,T),T=t.add(se,T),N=t.mul(A,T),se=t.add(P,P),se=t.add(se,P),ne=t.mul(z,ne),v=t.mul(F,v),se=t.add(se,ne),ne=t.sub(P,ne),ne=t.mul(z,ne),v=t.add(v,ne),P=t.mul(se,v),N=t.add(N,P),P=t.mul(I,v),A=t.mul(Ue,A),A=t.sub(A,P),P=t.mul(Ue,se),T=t.mul(I,T),T=t.add(T,P),new l(A,N,T)}subtract(d){return this.add(d.negate())}is0(){return this.equals(l.ZERO)}wNAF(d){return m.wNAFCached(this,f,d,g=>{let b=t.invertBatch(g.map(B=>B.pz));return g.map((B,w)=>B.toAffine(b[w])).map(l.fromAffine)})}multiplyUnsafe(d){let g=l.ZERO;if(d===gt)return g;if(a(d),d===Oe)return this;let{endo:b}=e;if(!b)return m.unsafeLadder(this,d);let{k1neg:B,k1:w,k2neg:_,k2:x}=b.splitScalar(d),A=g,N=g,T=this;for(;w>gt||x>gt;)w&Oe&&(A=A.add(T)),x&Oe&&(N=N.add(T)),T=T.double(),w>>=Oe,x>>=Oe;return B&&(A=A.negate()),_&&(N=N.negate()),N=new l(t.mul(N.px,b.beta),N.py,N.pz),A.add(N)}multiply(d){a(d);let g=d,b,B,{endo:w}=e;if(w){let{k1neg:_,k1:x,k2neg:A,k2:N}=w.splitScalar(g),{p:T,f:z}=this.wNAF(x),{p:F,f:P}=this.wNAF(N);T=m.constTimeNegate(_,T),F=m.constTimeNegate(A,F),F=new l(t.mul(F.px,w.beta),F.py,F.pz),b=T.add(F),B=z.add(P)}else{let{p:_,f:x}=this.wNAF(g);b=_,B=x}return l.normalizeZ([b,B])[0]}multiplyAndAddUnsafe(d,g,b){let B=l.BASE,w=(x,A)=>A===gt||A===Oe||!x.equals(B)?x.multiplyUnsafe(A):x.multiply(A),_=w(this,g).add(w(d,b));return _.is0()?void 0:_}toAffine(d){let{px:g,py:b,pz:B}=this,w=this.is0();d==null&&(d=w?t.ONE:t.inv(B));let _=t.mul(g,d),x=t.mul(b,d),A=t.mul(B,d);if(w)return{x:t.ZERO,y:t.ZERO};if(!t.eql(A,t.ONE))throw new Error("invZ was invalid");return{x:_,y:x}}isTorsionFree(){let{h:d,isTorsionFree:g}=e;if(d===Oe)return!0;if(g)return g(l,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:d,clearCofactor:g}=e;return d===Oe?this:g?g(l,this):this.multiplyUnsafe(e.h)}toRawBytes(d=!0){return this.assertValidity(),n(l,this,d)}toHex(d=!0){return it(this.toRawBytes(d))}}l.BASE=new l(e.Gx,e.Gy,t.ONE),l.ZERO=new l(t.ZERO,t.ONE,t.ZERO);let h=e.nBitLength,m=Bn(l,e.endo?Math.ceil(h/2):h);return{CURVE:e,ProjectivePoint:l,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:o}}function ld(r){let e=Dr(r);return We(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function Kc(r){let e=ld(r),{Fp:t,n}=e,s=t.BYTES+1,i=2*t.BYTES+1;function o(v){return gt<v&&v<t.ORDER}function a(v){return j(v,n)}function c(v){return vn(v,n)}let{ProjectivePoint:f,normPrivateKeyToScalar:u,weierstrassEquation:l,isWithinCurveOrder:h}=cd({...e,toBytes(v,I,D){let E=I.toAffine(),y=t.toBytes(E.x),S=at;return D?S(Uint8Array.from([I.hasEvenY()?2:3]),y):S(Uint8Array.from([4]),y,t.toBytes(E.y))},fromBytes(v){let I=v.length,D=v[0],E=v.subarray(1);if(I===s&&(D===2||D===3)){let y=ot(E);if(!o(y))throw new Error("Point is not on curve");let S=l(y),C;try{C=t.sqrt(S)}catch(O){let $=O instanceof Error?": "+O.message:"";throw new Error("Point is not on curve"+$)}let L=(C&Oe)===Oe;return(D&1)===1!==L&&(C=t.neg(C)),{x:y,y:C}}else if(I===i&&D===4){let y=t.fromBytes(E.subarray(0,t.BYTES)),S=t.fromBytes(E.subarray(t.BYTES,2*t.BYTES));return{x:y,y:S}}else throw new Error(`Point of length ${I} was invalid. Expected ${s} compressed bytes or ${i} uncompressed bytes`)}}),m=v=>it(kt(v,e.nByteLength));function p(v){let I=n>>Oe;return v>I}function d(v){return p(v)?a(-v):v}let g=(v,I,D)=>ot(v.slice(I,D));class b{constructor(I,D,E){this.r=I,this.s=D,this.recovery=E,this.assertValidity()}static fromCompact(I){let D=e.nByteLength;return I=re("compactSignature",I,D*2),new b(g(I,0,D),g(I,D,2*D))}static fromDER(I){let{r:D,s:E}=Wt.toSig(re("DER",I));return new b(D,E)}assertValidity(){if(!h(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!h(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(I){return new b(this.r,this.s,I)}recoverPublicKey(I){let{r:D,s:E,recovery:y}=this,S=N(re("msgHash",I));if(y==null||![0,1,2,3].includes(y))throw new Error("recovery id invalid");let C=y===2||y===3?D+e.n:D;if(C>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let L=y&1?"03":"02",V=f.fromHex(L+m(C)),O=c(C),$=a(-S*O),K=a(E*O),q=f.BASE.multiplyAndAddUnsafe(V,$,K);if(!q)throw new Error("point at infinify");return q.assertValidity(),q}hasHighS(){return p(this.s)}normalizeS(){return this.hasHighS()?new b(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return Ot(this.toDERHex())}toDERHex(){return Wt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Ot(this.toCompactHex())}toCompactHex(){return m(this.r)+m(this.s)}}let B={isValidPrivateKey(v){try{return u(v),!0}catch{return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{let v=pi(e.n);return Ra(e.randomBytes(v),e.n)},precompute(v=8,I=f.BASE){return I._setWindowSize(v),I.multiply(BigInt(3)),I}};function w(v,I=!0){return f.fromPrivateKey(v).toRawBytes(I)}function _(v){let I=Bt(v),D=typeof v=="string",E=(I||D)&&v.length;return I?E===s||E===i:D?E===2*s||E===2*i:v instanceof f}function x(v,I,D=!0){if(_(v))throw new Error("first arg must be private key");if(!_(I))throw new Error("second arg must be public key");return f.fromHex(I).multiply(u(v)).toRawBytes(D)}let A=e.bits2int||function(v){let I=ot(v),D=v.length*8-e.nBitLength;return D>0?I>>BigInt(D):I},N=e.bits2int_modN||function(v){return a(A(v))},T=Pr(e.nBitLength);function z(v){if(typeof v!="bigint")throw new Error("bigint expected");if(!(gt<=v&&v<T))throw new Error(`bigint expected < 2^${e.nBitLength}`);return kt(v,e.nByteLength)}function F(v,I,D=P){if(["recovered","canonical"].some(Q=>Q in D))throw new Error("sign() legacy options not supported");let{hash:E,randomBytes:y}=e,{lowS:S,prehash:C,extraEntropy:L}=D;S==null&&(S=!0),v=re("msgHash",v),C&&(v=re("prehashed msgHash",E(v)));let V=N(v),O=u(I),$=[z(O),z(V)];if(L!=null&&L!==!1){let Q=L===!0?y(t.BYTES):L;$.push(re("extraEntropy",Q))}let K=at(...$),q=V;function ie(Q){let he=A(Q);if(!h(he))return;let de=c(he),ae=f.BASE.multiply(he).toAffine(),ye=a(ae.x);if(ye===gt)return;let et=a(de*a(q+ye*O));if(et===gt)return;let Pt=(ae.x===ye?0:2)|Number(ae.y&Oe),Tr=et;return S&&p(et)&&(Tr=d(et),Pt^=1),new b(ye,Tr,Pt)}return{seed:K,k2sig:ie}}let P={lowS:e.lowS,prehash:!1},se={lowS:e.lowS,prehash:!1};function ne(v,I,D=P){let{seed:E,k2sig:y}=F(v,I,D),S=e;return ui(S.hash.outputLen,S.nByteLength,S.hmac)(E,y)}f.BASE._setWindowSize(8);function Ue(v,I,D,E=se){let y=v;if(I=re("msgHash",I),D=re("publicKey",D),"strict"in E)throw new Error("options.strict was renamed to lowS");let{lowS:S,prehash:C}=E,L,V;try{if(typeof y=="string"||Bt(y))try{L=b.fromDER(y)}catch(ae){if(!(ae instanceof Wt.Err))throw ae;L=b.fromCompact(y)}else if(typeof y=="object"&&typeof y.r=="bigint"&&typeof y.s=="bigint"){let{r:ae,s:ye}=y;L=new b(ae,ye)}else throw new Error("PARSE");V=f.fromHex(D)}catch(ae){if(ae.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(S&&L.hasHighS())return!1;C&&(I=e.hash(I));let{r:O,s:$}=L,K=N(I),q=c($),ie=a(K*q),Q=a(O*q),he=f.BASE.multiplyAndAddUnsafe(V,ie,Q)?.toAffine();return he?a(he.x)===O:!1}return{CURVE:e,getPublicKey:w,getSharedSecret:x,sign:ne,verify:Ue,ProjectivePoint:f,Signature:b,utils:B}}function ud(r){return{hash:r,hmac:(e,...t)=>Hr(r,e,ii(...t)),randomBytes:lr}}function Fc(r,e){let t=n=>Kc({...r,...ud(n)});return Object.freeze({...t(e),create:t})}var zc=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),qc=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),fd=BigInt(1),Zi=BigInt(2),$c=(r,e)=>(r+e/Zi)/e;function hd(r){let e=zc,t=BigInt(3),n=BigInt(6),s=BigInt(11),i=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%e,u=f*f*r%e,l=J(u,t,e)*u%e,h=J(l,t,e)*u%e,m=J(h,Zi,e)*f%e,p=J(m,s,e)*m%e,d=J(p,i,e)*p%e,g=J(d,a,e)*d%e,b=J(g,c,e)*g%e,B=J(b,a,e)*d%e,w=J(B,t,e)*u%e,_=J(w,o,e)*p%e,x=J(_,n,e)*f%e,A=J(x,Zi,e);if(!Ji.eql(Ji.sqr(A),r))throw new Error("Cannot find square root");return A}var Ji=En(zc,void 0,void 0,{sqrt:hd}),ze=Fc({a:BigInt(0),b:BigInt(7),Fp:Ji,n:qc,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=qc,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-fd*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=t,o=BigInt("0x100000000000000000000000000000000"),a=$c(i*r,e),c=$c(-n*r,e),f=j(r-a*t-c*s,e),u=j(-a*n-c*i,e),l=f>o,h=u>o;if(l&&(f=e-f),h&&(u=e-u),f>o||u>o)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:l,k1:f,k2neg:h,k2:u}}}},Mc),bm=BigInt(0);var wm=ze.ProjectivePoint;function Gc(){return ze.utils.randomPrivateKey()}function Wc(r,e){let t=pe.digest(e instanceof Uint8Array?e:e.subarray());if(De(t))return t.then(({digest:n})=>ze.sign(n,r).toDERRawBytes()).catch(n=>{throw new R(String(n),"ERR_INVALID_INPUT")});try{return ze.sign(t.digest,r).toDERRawBytes()}catch(n){throw new R(String(n),"ERR_INVALID_INPUT")}}function jc(r,e,t){let n=pe.digest(t instanceof Uint8Array?t:t.subarray());if(De(n))return n.then(({digest:s})=>ze.verify(e,s,r)).catch(s=>{throw new R(String(s),"ERR_INVALID_INPUT")});try{return ze.verify(e,n.digest,r)}catch(s){throw new R(String(s),"ERR_INVALID_INPUT")}}function Yc(r){return ze.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Zc(r){try{ze.getPublicKey(r,!0)}catch(e){throw new R(String(e),"ERR_INVALID_PRIVATE_KEY")}}function Xi(r){try{ze.ProjectivePoint.fromHex(r)}catch(e){throw new R(String(e),"ERR_INVALID_PUBLIC_KEY")}}function Jc(r){try{return ze.getPublicKey(r,!0)}catch(e){throw new R(String(e),"ERR_INVALID_PRIVATE_KEY")}}var Xr=class{_key;constructor(e){Xi(e),this._key=e}verify(e,t){return jc(this._key,t,e)}marshal(){return Yc(this._key)}get bytes(){return Ye.encode({Type:X.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return te(this.bytes,e.bytes)}async hash(){let e=pe.digest(this.bytes),t;return De(e)?{bytes:t}=await e:t=e.bytes,t}},Qr=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t??Jc(e),Zc(this._key),Xi(this._publicKey)}sign(e){return Wc(this._key,e)}get public(){return new Xr(this._publicKey)}marshal(){return this._key}get bytes(){return Ze.encode({Type:X.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return te(this.bytes,e.bytes)}hash(){let e=pe.digest(this.bytes);return De(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return M(e,"base58btc")}async export(e,t="libp2p-key"){if(t==="libp2p-key")return pr(this.bytes,e);throw new R(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function pd(r){return new Qr(r)}function gd(r){return new Xr(r)}async function md(){let r=Gc();return new Qr(r)}var jt={rsa:ji,ed25519:Oi,secp256k1:Qi};function Xc(r){let e=Object.keys(jt).join(" / ");return new R(`invalid or unsupported key type ${r}. Must be ${e}`,"ERR_UNSUPPORTED_KEY_TYPE")}function Qc(r){let e=Ye.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case X.RSA:return jt.rsa.unmarshalRsaPublicKey(t);case X.Ed25519:return jt.ed25519.unmarshalEd25519PublicKey(t);case X.Secp256k1:return jt.secp256k1.unmarshalSecp256k1PublicKey(t);default:throw Xc(e.Type??"unknown")}}async function el(r){let e=Ze.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case X.RSA:return jt.rsa.unmarshalRsaPrivateKey(t);case X.Ed25519:return jt.ed25519.unmarshalEd25519PrivateKey(t);case X.Secp256k1:return jt.secp256k1.unmarshalSecp256k1PrivateKey(t);default:throw Xc(e.Type??"RSA")}}var rl=Symbol.for("nodejs.util.inspect.custom"),tl=Object.values(wt).map(r=>r.decoder).reduce((r,e)=>r.or(e),wt.identity.decoder),nl=114,ro=36,no=37,en=class{type;multihash;privateKey;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,this.privateKey=e.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[hn]=!0;toString(){return this.string==null&&(this.string=ce.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return Pe.createV1(nl,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return te(this.multihash.bytes,e);if(typeof e=="string")return tn(e).equals(this);if(e?.multihash?.bytes!=null)return te(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[rl](){return`PeerId(${this.toString()})`}},Yt=class extends en{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Zt=class extends en{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}},Jt=class extends en{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}},eo=2336,to=class{type="url";multihash;privateKey;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=rt.digest(G(this.url))}[rl](){return`PeerId(${this.url})`}[hn]=!0;toString(){return this.toCID().toString()}toCID(){return Pe.createV1(eo,this.multihash)}toBytes(){return this.toCID().bytes}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=M(e)),e.toString()===this.toString())}};function sl(r){if(r.type==="RSA")return new Yt(r);if(r.type==="Ed25519")return new Zt(r);if(r.type==="secp256k1")return new Jt(r);throw new R("Not a PeerId","ERR_INVALID_PARAMETERS")}function tn(r,e){if(e=e??tl,r.charAt(0)==="1"||r.charAt(0)==="Q"){let t=Dt(ce.decode(`z${r}`));return r.startsWith("12D")?new Zt({multihash:t}):r.startsWith("16U")?new Jt({multihash:t}):new Yt({multihash:t})}return rn(tl.decode(r))}function rn(r){try{let e=Dt(r);if(e.code===rt.code){if(e.digest.length===ro)return new Zt({multihash:e});if(e.digest.length===no)return new Jt({multihash:e})}if(e.code===pe.code)return new Yt({multihash:e})}catch{return yd(Pe.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function yd(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==nl&&r.code!==eo)throw new Error("Supplied PeerID CID is invalid");if(r.code===eo){let t=M(r.multihash.digest);return new to(new URL(t))}let e=r.multihash;if(e.code===pe.code)return new Yt({multihash:r.multihash});if(e.code===rt.code){if(e.digest.length===ro)return new Zt({multihash:r.multihash});if(e.digest.length===no)return new Jt({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function il(r,e){return r.length===ro?new Zt({multihash:Ge(rt.code,r),privateKey:e}):r.length===no?new Jt({multihash:Ge(rt.code,r),privateKey:e}):new Yt({multihash:await pe.digest(r),publicKey:r,privateKey:e})}var al=Symbol.for("@achingbrain/uint8arraylist");function ol(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let s=t+n.byteLength;if(e<s)return{buf:n,index:e-t};t=s}throw new RangeError("index is out of bounds")}function xs(r){return!!r?.[al]}var vs=class r{bufs;length;[al]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if(xs(n))t+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if(xs(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=ol(this.bufs,e);return t.buf[t.index]}set(e,t){let n=ol(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if(xs(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:s}=this._subList(e,t);return Ee(n,s)}subarray(e,t){let{bufs:n,length:s}=this._subList(e,t);return n.length===1?n[0]:Ee(n,s)}sublist(e,t){let{bufs:n,length:s}=this._subList(e,t),i=new r;return i.length=s,i.bufs=[...n],i}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let n=[],s=0;for(let i=0;i<this.bufs.length;i++){let o=this.bufs[i],a=s,c=a+o.byteLength;if(s=c,e>=c)continue;let f=e>=a&&e<c,u=t>a&&t<=c;if(f&&u){if(e===a&&t===c){n.push(o);break}let l=e-a;n.push(o.subarray(l,l+(t-e)));break}if(f){if(e===0){n.push(o);continue}n.push(o.subarray(e-a));continue}if(u){if(t===c){n.push(o);break}n.push(o.subarray(0,t-a));break}n.push(o)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!xs(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let i=256,o=new Int32Array(i);for(let l=0;l<i;l++)o[l]=-1;for(let l=0;l<s;l++)o[n[l]]=l;let a=o,c=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let l=t;l<=c;l+=u){u=0;for(let h=f;h>=0;h--){let m=this.get(l+h);if(n[h]!==m){u=Math.max(1,h-a[m]);break}}if(u===0)return l}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=Ne(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let s=nt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,t,n),this.write(s,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let s=nt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,t,n),this.write(s,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let s=nt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,t,n),this.write(s,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=Ne(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let s=nt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,t,n),this.write(s,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let s=nt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,t,n),this.write(s,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let s=nt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,t,n),this.write(s,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let s=nt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,t,n),this.write(s,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let s=nt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,t,n),this.write(s,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!te(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((s,i)=>s+i.byteLength,0)),n.length=t,n}};var cl={ERR_SIGNATURE_NOT_VALID:"ERR_SIGNATURE_NOT_VALID"};var nn;(function(r){let e;r.codec=()=>(e==null&&(e=Se((t,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),t.publicKey!=null&&t.publicKey.byteLength>0&&(n.uint32(10),n.bytes(t.publicKey)),t.payloadType!=null&&t.payloadType.byteLength>0&&(n.uint32(18),n.bytes(t.payloadType)),t.payload!=null&&t.payload.byteLength>0&&(n.uint32(26),n.bytes(t.payload)),t.signature!=null&&t.signature.byteLength>0&&(n.uint32(42),n.bytes(t.signature)),s.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let s={publicKey:new Uint8Array(0),payloadType:new Uint8Array(0),payload:new Uint8Array(0),signature:new Uint8Array(0)},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let o=t.uint32();switch(o>>>3){case 1:s.publicKey=t.bytes();break;case 2:s.payloadType=t.bytes();break;case 3:s.payload=t.bytes();break;case 5:s.signature=t.bytes();break;default:t.skipType(o&7);break}}return s})),e),r.encode=t=>ke(t,r.codec()),r.decode=t=>Ae(t,r.codec())})(nn||(nn={}));var Er=class r{static createFromProtobuf=async e=>{let t=nn.decode(e),n=await il(t.publicKey);return new r({peerId:n,payloadType:t.payloadType,payload:t.payload,signature:t.signature})};static seal=async(e,t)=>{if(t.privateKey==null)throw new Error("Missing private key");let n=e.domain,s=e.codec,i=e.marshal(),o=ll(n,s,i),c=await(await el(t.privateKey)).sign(o.subarray());return new r({peerId:t,payloadType:s,payload:i,signature:c})};static openAndCertify=async(e,t)=>{let n=await r.createFromProtobuf(e);if(!await n.validate(t))throw new R("envelope signature is not valid for the given domain",cl.ERR_SIGNATURE_NOT_VALID);return n};peerId;payloadType;payload;signature;marshaled;constructor(e){let{peerId:t,payloadType:n,payload:s,signature:i}=e;this.peerId=t,this.payloadType=n,this.payload=s,this.signature=i}marshal(){if(this.peerId.publicKey==null)throw new Error("Missing public key");return this.marshaled==null&&(this.marshaled=nn.encode({publicKey:this.peerId.publicKey,payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(e){return te(this.marshal(),e.marshal())}async validate(e){let t=ll(e,this.payloadType,this.payload);if(this.peerId.publicKey==null)throw new Error("Missing public key");return Qc(this.peerId.publicKey).verify(t.subarray(),this.signature)}},ll=(r,e,t)=>{let n=G(r),s=je(n.byteLength),i=je(e.length),o=je(t.length);return new vs(s,n,i,e,o,t)};function ul(r,e){let t=(n,s)=>n.toString().localeCompare(s.toString());return r.length!==e.length?!1:(e.sort(t),r.sort(t).every((n,s)=>e[s].equals(n)))}var Es=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}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(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,s){return this.readAtomically(()=>{let i=0,o=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",f=2**(8*s)-1;for(;;){let u=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let h=Number.parseInt(l,e);if(!Number.isNaN(h))return h});if(u===void 0)break;if(i*=e,i+=u,i>f||(o+=1,t!==void 0&&o>t))return}if(o!==0)return!n&&c&&o>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let s=n*2;if(n<t.length-3){let o=this.readSeparator(":",n,()=>this.readIPv4Addr());if(o!==void 0)return t[s]=o[0],t[s+1]=o[1],t[s+2]=o[2],t[s+3]=o[3],[s+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[s,!1];t[s]=i>>8,t[s+1]=i&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,s]=e(t);if(n===16)return t;if(s||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),o=16-(n+2),[a]=e(i.subarray(0,o));return t.set(i.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var fl=45,bd=15,Br=new Es;function so(r){if(!(r.length>bd))return Br.new(r).parseWith(()=>Br.readIPv4Addr())}function io(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>fl))return Br.new(r).parseWith(()=>Br.readIPv6Addr())}function Bs(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>fl))return Br.new(r).parseWith(()=>Br.readIPAddr())}var my=parseInt("0xFFFF",16),yy=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function pl(r){return!!so(r)}function gl(r){return!!io(r)}function As(r){return!!Bs(r)}var ml=pl,Bd=gl,oo=function(r){let e=0;if(r=r.toString().trim(),ml(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(Bd(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=ml(t[n]),o;i&&(o=oo(t[n]),t[n]=M(o.slice(0,2),"base16")),o!=null&&++n<8&&t.splice(n,0,M(o.slice(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let i=[n,1];for(n=9-t.length;n>0;n--)i.push("0");t.splice.apply(t,i)}let s=new Uint8Array(e+16);for(n=0;n<t.length;n++){let i=parseInt(t[n],16);s[e++]=i>>8&255,s[e++]=i&255}return s}throw new Error("invalid ip address")},yl=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let s=[];for(let i=0;i<t;i++)s.push(r[e+i]);return s.join(".")}if(t===16){let s=[];for(let i=0;i<t;i+=2)s.push(n.getUint16(e+i).toString(16));return s.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var Ar={},ao={},kd=[[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"]];kd.forEach(r=>{let e=Sd(...r);ao[e.code]=e,Ar[e.name]=e});function Sd(r,e,t,n,s){return{code:r,size:e,name:t,resolvable:!!n,path:!!s}}function Y(r){if(typeof r=="number"){if(ao[r]!=null)return ao[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Ar[r]!=null)return Ar[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var eb=Y("ip4"),tb=Y("ip6"),rb=Y("ipcidr");function fo(r,e){switch(Y(r).code){case 4:case 41:return Rd(e);case 42:return uo(e);case 6:case 273:case 33:case 132:return xl(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return uo(e);case 421:return Cd(e);case 444:return wl(e);case 445:return wl(e);case 466:return _d(e);case 481:return globalThis.encodeURIComponent(uo(e));default:return M(e,"base16")}}function ho(r,e){switch(Y(r).code){case 4:return bl(e);case 41:return bl(e);case 42:return lo(e);case 6:case 273:case 33:case 132:return po(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return lo(e);case 421:return Nd(e);case 444:return Ld(e);case 445:return Ud(e);case 466:return Td(e);case 481:return lo(globalThis.decodeURIComponent(e));default:return G(e,"base16")}}var co=Object.values(wt).map(r=>r.decoder),Id=function(){let r=co[0].or(co[1]);return co.slice(2).forEach(e=>r=r.or(e)),r}();function bl(r){if(!As(r))throw new Error("invalid ip address");return oo(r)}function Rd(r){let e=yl(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!As(e))throw new Error("invalid ip address");return e}function po(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function xl(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function lo(r){let e=G(r),t=Uint8Array.from(je(e.length));return Ee([t,e],t.length+e.length)}function uo(r){let e=Kt(r);if(r=r.slice(Te(e)),r.length!==e)throw new Error("inconsistent lengths");return M(r)}function Nd(r){let e;r[0]==="Q"||r[0]==="1"?e=Dt(ce.decode(`z${r}`)).bytes:e=Pe.parse(r).multihash.bytes;let t=Uint8Array.from(je(e.length));return Ee([t,e],t.length+e.length)}function Td(r){let e=Id.decode(r),t=Uint8Array.from(je(e.length));return Ee([t,e],t.length+e.length)}function _d(r){let e=Kt(r),t=r.slice(Te(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+M(t,"base64url")}function Cd(r){let e=Kt(r),t=r.slice(Te(e));if(t.length!==e)throw new Error("inconsistent lengths");return M(t,"base58btc")}function Ld(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=Me.decode("b"+e[0]),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let s=po(n);return Ee([t,s],t.length+s.length)}function Ud(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let t=Me.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let s=po(n);return Ee([t,s],t.length+s.length)}function wl(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=M(e,"base32"),s=xl(t);return`${n}:${s}`}function vl(r){r=go(r);let e=[],t=[],n=null,s=r.split("/").slice(1);if(s.length===1&&s[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let i=0;i<s.length;i++){let o=s[i],a=Y(o);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(i++,i>=s.length)throw Bl("invalid address: "+r);if(a.path===!0){n=go(s.slice(i).join("/")),e.push([a.code,ho(a.code,n)]),t.push([a.code,n]);break}let c=ho(a.code,s[i]);e.push([a.code,c]),t.push([a.code,fo(a.code,c)])}return{string:El(t),bytes:yo(e),tuples:e,stringTuples:t,path:n}}function mo(r){let e=[],t=[],n=null,s=0;for(;s<r.length;){let i=Kt(r,s),o=Te(i),a=Y(i),c=Pd(a,r.slice(s+o));if(c===0){e.push([i]),t.push([i]),s+=o;continue}let f=r.slice(s+o,s+o+c);if(s+=c+o,s>r.length)throw Bl("Invalid address Uint8Array: "+M(r,"base16"));e.push([i,f]);let u=fo(i,f);if(t.push([i,u]),a.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:El(t),tuples:e,stringTuples:t,path:n}}function El(r){let e=[];return r.map(t=>{let n=Y(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),go(e.join("/"))}function yo(r){return Ee(r.map(e=>{let t=Y(e[0]),n=Uint8Array.from(je(t.code));return e.length>1&&e[1]!=null&&(n=Ee([n,e[1]])),n}))}function Pd(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=Kt(e instanceof Uint8Array?e:Uint8Array.from(e));return t+Te(t)}}function go(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function Bl(r){return new Error("Error parsing address: "+r)}var Dd=Symbol.for("nodejs.util.inspect.custom"),bo=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Vd=[Y("dns").code,Y("dns4").code,Y("dns6").code,Y("dnsaddr").code],ks=class r{bytes;#e;#t;#i;#a;[bo]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=mo(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=vl(e)}else if(Ss(e))t=mo(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#i=t.stringTuples,this.#a=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,s,i="",o=Y("tcp"),a=Y("udp"),c=Y("ip4"),f=Y("ip6"),u=Y("dns6"),l=Y("ip6zone");for(let[m,p]of this.stringTuples())m===l.code&&(i=`%${p??""}`),Vd.includes(m)&&(t=o.name,s=443,n=`${p??""}${i}`,e=m===u.code?6:4),(m===o.code||m===a.code)&&(t=Y(m).name,s=parseInt(p??"")),(m===c.code||m===f.code)&&(t=Y(m).name,n=`${p??""}${i}`,e=m===f.code?6:4);if(e==null||t==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:e,host:n,transport:t,port:s}}protos(){return this.#t.map(([e])=>Object.assign({},Y(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>Y(e).name)}tuples(){return this.#t}stringTuples(){return this.#i}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),s=n.lastIndexOf(t);if(s<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,s))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(yo(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,s])=>{n===Ar.p2p.code&&e.push([n,s]),n===Ar["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?M(ce.decode(`z${n}`),"base58btc"):M(Pe.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#a}equals(e){return te(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(i=>i.resolvable);if(t==null)return[this];let n=Al.get(t.name);if(n==null)throw new R(`no available resolver for ${t.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,e)).map(i=>mt(i))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[Dd](){return`Multiaddr(${this.#e})`}};var Al=new Map;function Ss(r){return!!r?.[bo]}function mt(r){return new ks(r)}var kl="libp2p-peer-record",Sl=Uint8Array.from([3,1]);var sn;(function(r){let e;(function(n){let s;n.codec=()=>(s==null&&(s=Se((i,o,a={})=>{a.lengthDelimited!==!1&&o.fork(),i.multiaddr!=null&&i.multiaddr.byteLength>0&&(o.uint32(10),o.bytes(i.multiaddr)),a.lengthDelimited!==!1&&o.ldelim()},(i,o)=>{let a={multiaddr:new Uint8Array(0)},c=o==null?i.len:i.pos+o;for(;i.pos<c;){let f=i.uint32();switch(f>>>3){case 1:a.multiaddr=i.bytes();break;default:i.skipType(f&7);break}}return a})),s),n.encode=i=>ke(i,n.codec()),n.decode=i=>Ae(i,n.codec())})(e=r.AddressInfo||(r.AddressInfo={}));let t;r.codec=()=>(t==null&&(t=Se((n,s,i={})=>{if(i.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 o of n.addresses)s.uint32(26),r.AddressInfo.codec().encode(o,s);i.lengthDelimited!==!1&&s.ldelim()},(n,s)=>{let i={peerId:new Uint8Array(0),seq:0n,addresses:[]},o=s==null?n.len:n.pos+s;for(;n.pos<o;){let a=n.uint32();switch(a>>>3){case 1:i.peerId=n.bytes();break;case 2:i.seq=n.uint64();break;case 3:i.addresses.push(r.AddressInfo.codec().decode(n,n.uint32()));break;default:n.skipType(a&7);break}}return i})),t),r.encode=n=>ke(n,r.codec()),r.decode=n=>Ae(n,r.codec())})(sn||(sn={}));var Xt=class r{static createFromProtobuf=e=>{let t=sn.decode(e),n=rn(t.peerId),s=(t.addresses??[]).map(o=>mt(o.multiaddr)),i=t.seq;return new r({peerId:n,multiaddrs:s,seqNumber:i})};static DOMAIN=kl;static CODEC=Sl;peerId;multiaddrs;seqNumber;domain=r.DOMAIN;codec=r.CODEC;marshaled;constructor(e){let{peerId:t,multiaddrs:n,seqNumber:s}=e;this.peerId=t,this.multiaddrs=n??[],this.seqNumber=s??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=sn.encode({peerId:this.peerId.toBytes(),seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(e=>({multiaddr:e.bytes}))})),this.marshaled}equals(e){return!(!(e instanceof r)||!this.peerId.equals(e.peerId)||this.seqNumber!==e.seqNumber||!ul(this.multiaddrs,e.multiaddrs))}};function Od(r){return r[Symbol.asyncIterator]!=null}function Md(r){if(Od(r))return(async()=>{let t=[];for await(let n of r)t.push(n);return t})();let e=[];for(let t of r)e.push(t);return e}var Il=Md;function wo(r,e){let t={[Symbol.iterator]:()=>t,next:()=>{let n=r.next(),s=n.value;return n.done===!0||s==null?{done:!0,value:void 0}:{done:!1,value:e(s)}}};return t}var on=class{map;constructor(e){if(this.map=new Map,e!=null)for(let[t,n]of e.entries())this.map.set(t.toString(),n)}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(e){return this.map.delete(e.toString())}entries(){return wo(this.map.entries(),e=>[tn(e[0]),e[1]])}forEach(e){this.map.forEach((t,n)=>{e(t,tn(n),this)})}get(e){return this.map.get(e.toString())}has(e){return this.map.has(e.toString())}set(e,t){this.map.set(e.toString(),t)}keys(){return wo(this.map.keys(),e=>tn(e))}values(){return this.map.values()}get size(){return this.map.size}};var vo=zo(Nl(),1);var cn=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Eo=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Tl=r=>globalThis.DOMException===void 0?new Eo(r):new DOMException(r),_l=r=>{let e=r.reason===void 0?Tl("This operation was aborted."):r.reason;return e instanceof Error?e:Tl(e)};function ln(r,e){let{milliseconds:t,fallback:n,message:s,customTimers:i={setTimeout,clearTimeout}}=e,o,c=new Promise((f,u)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:h}=e;h.aborted&&u(_l(h)),h.addEventListener("abort",()=>{u(_l(h))})}if(t===Number.POSITIVE_INFINITY){r.then(f,u);return}let l=new cn;o=i.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(h){u(h)}return}typeof r.cancel=="function"&&r.cancel(),s===!1?f():s instanceof Error?u(s):(l.message=s??`Promise timed out after ${t} milliseconds`,u(l))},t),(async()=>{try{f(await r)}catch(h){u(h)}})()}).finally(()=>{c.clear()});return c.clear=()=>{i.clearTimeout.call(void 0,o),o=void 0},c}function Bo(r,e,t){let n=0,s=r.length;for(;s>0;){let i=Math.trunc(s/2),o=n+i;t(r[o],e)<=0?(n=++o,s-=i+1):s=i}return n}var un=class{#e=[];enqueue(e,t){t={priority:0,...t};let n={priority:t.priority,run:e};if(this.size&&this.#e[this.size-1].priority>=t.priority){this.#e.push(n);return}let s=Bo(this.#e,n,(i,o)=>o.priority-i.priority);this.#e.splice(s,0,n)}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(t=>t.priority===e.priority).map(t=>t.run)}get size(){return this.#e.length}};var kr=class extends vo.default{#e;#t;#i=0;#a;#c;#p=0;#n;#l;#r;#g;#s=0;#u;#o;#m;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:un,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);this.#e=e.carryoverConcurrencyCount,this.#t=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#a=e.intervalCap,this.#c=e.interval,this.#r=new e.queueClass,this.#g=e.queueClass,this.concurrency=e.concurrency,this.timeout=e.timeout,this.#m=e.throwOnTimeout===!0,this.#o=e.autoStart===!1}get#w(){return this.#t||this.#i<this.#a}get#x(){return this.#s<this.#u}#v(){this.#s--,this.#f(),this.emit("next")}#E(){this.#b(),this.#y(),this.#l=void 0}get#B(){let e=Date.now();if(this.#n===void 0){let t=this.#p-e;if(t<0)this.#i=this.#e?this.#s:0;else return this.#l===void 0&&(this.#l=setTimeout(()=>{this.#E()},t)),!0}return!1}#f(){if(this.#r.size===0)return this.#n&&clearInterval(this.#n),this.#n=void 0,this.emit("empty"),this.#s===0&&this.emit("idle"),!1;if(!this.#o){let e=!this.#B;if(this.#w&&this.#x){let t=this.#r.dequeue();return t?(this.emit("active"),t(),e&&this.#y(),!0):!1}}return!1}#y(){this.#t||this.#n!==void 0||(this.#n=setInterval(()=>{this.#b()},this.#c),this.#p=Date.now()+this.#c)}#b(){this.#i===0&&this.#s===0&&this.#n&&(clearInterval(this.#n),this.#n=void 0),this.#i=this.#e?this.#s:0,this.#h()}#h(){for(;this.#f(););}get concurrency(){return this.#u}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#u=e,this.#h()}async#A(e){return new Promise((t,n)=>{e.addEventListener("abort",()=>{n(e.reason)},{once:!0})})}async add(e,t={}){return t={timeout:this.timeout,throwOnTimeout:this.#m,...t},new Promise((n,s)=>{this.#r.enqueue(async()=>{this.#s++,this.#i++;try{t.signal?.throwIfAborted();let i=e({signal:t.signal});t.timeout&&(i=ln(Promise.resolve(i),{milliseconds:t.timeout})),t.signal&&(i=Promise.race([i,this.#A(t.signal)]));let o=await i;n(o),this.emit("completed",o)}catch(i){if(i instanceof cn&&!t.throwOnTimeout){n();return}s(i),this.emit("error",i)}finally{this.#v()}},t),this.emit("add"),this.#f()})}async addAll(e,t){return Promise.all(e.map(async n=>this.add(n,t)))}start(){return this.#o?(this.#o=!1,this.#h(),this):this}pause(){this.#o=!0}clear(){this.#r=new this.#g}async onEmpty(){this.#r.size!==0&&await this.#d("empty")}async onSizeLessThan(e){this.#r.size<e||await this.#d("next",()=>this.#r.size<e)}async onIdle(){this.#s===0&&this.#r.size===0||await this.#d("idle")}async#d(e,t){return new Promise(n=>{let s=()=>{t&&!t()||(this.off(e,s),n())};this.on(e,s)})}get size(){return this.#r.size}sizeBy(e){return this.#r.filter(e).length}get pending(){return this.#s}get isPaused(){return this.#o}};var Lt={},Sr=r=>{r.addEventListener("message",e=>{Sr.dispatchEvent("message",r,e)}),r.port!=null&&r.port.addEventListener("message",e=>{Sr.dispatchEvent("message",r,e)})};Sr.addEventListener=(r,e)=>{Lt[r]==null&&(Lt[r]=[]),Lt[r].push(e)};Sr.removeEventListener=(r,e)=>{Lt[r]!=null&&(Lt[r]=Lt[r].filter(t=>t===e))};Sr.dispatchEvent=function(r,e,t){Lt[r]!=null&&Lt[r].forEach(n=>n(e,t))};var Ao=Sr;var ko="lock:worker:request-read",So="lock:worker:release-read",Io="lock:master:grant-read",Ro="lock:worker:request-write",No="lock:worker:release-write",To="lock:master:grant-write";var Cl=(r=21)=>Math.random().toString().substring(2);var Ll=(r,e,t,n,s)=>(i,o)=>{if(o.data.type!==t)return;let a={type:o.data.type,name:o.data.name,identifier:o.data.identifier};r.dispatchEvent(new MessageEvent(e,{data:{name:a.name,handler:async()=>{i.postMessage({type:s,name:a.name,identifier:a.identifier}),await new Promise(c=>{let f=u=>{if(u==null||u.data==null)return;let l={type:u.data.type,name:u.data.name,identifier:u.data.identifier};l.type===n&&l.identifier===a.identifier&&(i.removeEventListener("message",f),c())};i.addEventListener("message",f)})}}}))},Ul=(r,e,t,n)=>async()=>{let s=Cl();return globalThis.postMessage({type:e,identifier:s,name:r}),new Promise(i=>{let o=a=>{if(a==null||a.data==null)return;let c={type:a.data.type,identifier:a.data.identifier};c.type===t&&c.identifier===s&&(globalThis.removeEventListener("message",o),i(()=>{globalThis.postMessage({type:n,identifier:s,name:r})}))};globalThis.addEventListener("message",o)})},Fd={singleProcess:!1},Pl=r=>{if(r=Object.assign({},Fd,r),!!globalThis.document||r.singleProcess){let t=new EventTarget;return Ao.addEventListener("message",Ll(t,"requestReadLock",ko,So,Io)),Ao.addEventListener("message",Ll(t,"requestWriteLock",Ro,No,To)),t}return{isWorker:!0,readLock:t=>Ul(t,ko,Io,So),writeLock:t=>Ul(t,Ro,To,No)}};var Qt={},Ut;async function _o(r,e){let t,n=new Promise(s=>{t=s});return r.add(async()=>ln((async()=>{await new Promise(s=>{t(()=>{s()})})})(),{milliseconds:e.timeout})),n}var qd=(r,e)=>{if(Ut.isWorker===!0)return{readLock:Ut.readLock(r,e),writeLock:Ut.writeLock(r,e)};let t=new kr({concurrency:1}),n;return{async readLock(){if(n!=null)return _o(n,e);n=new kr({concurrency:e.concurrency,autoStart:!1});let s=n,i=_o(n,e);return t.add(async()=>{s.start(),await s.onIdle().then(()=>{n===s&&(n=null)})}),i},async writeLock(){return n=null,_o(t,e)}}},$d={name:"lock",concurrency:1/0,timeout:846e5,singleProcess:!1};function Co(r){let e=Object.assign({},$d,r);return Ut==null&&(Ut=Pl(e),Ut.isWorker!==!0&&(Ut.addEventListener("requestReadLock",t=>{Qt[t.data.name]!=null&&Qt[t.data.name].readLock().then(async n=>t.data.handler().finally(()=>{n()}))}),Ut.addEventListener("requestWriteLock",async t=>{Qt[t.data.name]!=null&&Qt[t.data.name].writeLock().then(async n=>t.data.handler().finally(()=>{n()}))}))),Qt[e.name]==null&&(Qt[e.name]=qd(e.name,e)),Qt[e.name]}var me={ERR_INVALID_PARAMETERS:"ERR_INVALID_PARAMETERS"};var Ir;(function(r){let e;(function(s){let i;s.codec=()=>(i==null&&(i=Se((o,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),o.key!=null&&o.key!==""&&(a.uint32(10),a.string(o.key)),o.value!=null&&o.value.byteLength>0&&(a.uint32(18),a.bytes(o.value)),c.lengthDelimited!==!1&&a.ldelim()},(o,a)=>{let c={key:"",value:new Uint8Array(0)},f=a==null?o.len:o.pos+a;for(;o.pos<f;){let u=o.uint32();switch(u>>>3){case 1:c.key=o.string();break;case 2:c.value=o.bytes();break;default:o.skipType(u&7);break}}return c})),i),s.encode=o=>ke(o,s.codec()),s.decode=o=>Ae(o,s.codec())})(e=r.Peer$metadataEntry||(r.Peer$metadataEntry={}));let t;(function(s){let i;s.codec=()=>(i==null&&(i=Se((o,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),o.key!=null&&o.key!==""&&(a.uint32(10),a.string(o.key)),o.value!=null&&(a.uint32(18),Ns.codec().encode(o.value,a)),c.lengthDelimited!==!1&&a.ldelim()},(o,a)=>{let c={key:""},f=a==null?o.len:o.pos+a;for(;o.pos<f;){let u=o.uint32();switch(u>>>3){case 1:c.key=o.string();break;case 2:c.value=Ns.codec().decode(o,o.uint32());break;default:o.skipType(u&7);break}}return c})),i),s.encode=o=>ke(o,s.codec()),s.decode=o=>Ae(o,s.codec())})(t=r.Peer$tagsEntry||(r.Peer$tagsEntry={}));let n;r.codec=()=>(n==null&&(n=Se((s,i,o={})=>{if(o.lengthDelimited!==!1&&i.fork(),s.addresses!=null)for(let a of s.addresses)i.uint32(10),Rs.codec().encode(a,i);if(s.protocols!=null)for(let a of s.protocols)i.uint32(18),i.string(a);if(s.publicKey!=null&&(i.uint32(34),i.bytes(s.publicKey)),s.peerRecordEnvelope!=null&&(i.uint32(42),i.bytes(s.peerRecordEnvelope)),s.metadata!=null&&s.metadata.size!==0)for(let[a,c]of s.metadata.entries())i.uint32(50),r.Peer$metadataEntry.codec().encode({key:a,value:c},i);if(s.tags!=null&&s.tags.size!==0)for(let[a,c]of s.tags.entries())i.uint32(58),r.Peer$tagsEntry.codec().encode({key:a,value:c},i);o.lengthDelimited!==!1&&i.ldelim()},(s,i)=>{let o={addresses:[],protocols:[],metadata:new Map,tags:new Map},a=i==null?s.len:s.pos+i;for(;s.pos<a;){let c=s.uint32();switch(c>>>3){case 1:o.addresses.push(Rs.codec().decode(s,s.uint32()));break;case 2:o.protocols.push(s.string());break;case 4:o.publicKey=s.bytes();break;case 5:o.peerRecordEnvelope=s.bytes();break;case 6:{let f=r.Peer$metadataEntry.codec().decode(s,s.uint32());o.metadata.set(f.key,f.value);break}case 7:{let f=r.Peer$tagsEntry.codec().decode(s,s.uint32());o.tags.set(f.key,f.value);break}default:s.skipType(c&7);break}}return o})),n),r.encode=s=>ke(s,r.codec()),r.decode=s=>Ae(s,r.codec())})(Ir||(Ir={}));var Rs;(function(r){let e;r.codec=()=>(e==null&&(e=Se((t,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),t.multiaddr!=null&&t.multiaddr.byteLength>0&&(n.uint32(10),n.bytes(t.multiaddr)),t.isCertified!=null&&(n.uint32(16),n.bool(t.isCertified)),s.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let s={multiaddr:new Uint8Array(0)},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let o=t.uint32();switch(o>>>3){case 1:s.multiaddr=t.bytes();break;case 2:s.isCertified=t.bool();break;default:t.skipType(o&7);break}}return s})),e),r.encode=t=>ke(t,r.codec()),r.decode=t=>Ae(t,r.codec())})(Rs||(Rs={}));var Ns;(function(r){let e;r.codec=()=>(e==null&&(e=Se((t,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),t.value!=null&&t.value!==0&&(n.uint32(8),n.uint32(t.value)),t.expiry!=null&&(n.uint32(16),n.uint64(t.expiry)),s.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let s={value:0},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let o=t.uint32();switch(o>>>3){case 1:s.value=t.uint32();break;case 2:s.expiry=t.uint64();break;default:t.skipType(o&7);break}}return s})),e),r.encode=t=>ke(t,r.codec()),r.decode=t=>Ae(t,r.codec())})(Ns||(Ns={}));function Rr(r,e){let t=Ir.decode(e);t.publicKey!=null&&r.publicKey==null&&(r=sl({...r,publicKey:r.publicKey}));let n=new Map,s=BigInt(Date.now());for(let[i,o]of t.tags.entries())o.expiry!=null&&o.expiry<s||n.set(i,o);return{...t,id:r,addresses:t.addresses.map(({multiaddr:i,isCertified:o})=>({multiaddr:mt(i),isCertified:o??!1})),metadata:t.metadata,peerRecordEnvelope:t.peerRecordEnvelope??void 0,tags:n}}var yt="/",Dl=new TextEncoder().encode(yt),Ts=Dl[0],_s=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=G(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(t==null&&(t=!0),t&&this.clean(),this._buf.byteLength===0||this._buf[0]!==Ts)throw new Error("Invalid key")}toString(e="utf8"){return M(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new r(e.join(yt))}static random(){return new r(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new r(e):typeof e.uint8Array=="function"?new r(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=Dl),this._buf[0]!==Ts){let e=new Uint8Array(this._buf.byteLength+1);e.fill(Ts,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Ts;)this._buf=this._buf.subarray(0,-1)}less(e){let t=this.list(),n=e.list();for(let s=0;s<t.length;s++){if(n.length<s+1)return!1;let i=t[s],o=n[s];if(i<o)return!0;if(i>o)return!1}return t.length<n.length}reverse(){return r.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(yt).slice(1)}type(){return zd(this.baseNamespace())}name(){return Gd(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(yt)||(e+=yt),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(yt):new r(e.slice(0,-1).join(yt))}child(e){return this.toString()===yt?e:e.toString()===yt?this:new r(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()===this.toString()?!1:e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()===this.toString()?!1:this.toString().startsWith(e.toString())}isTopLevel(){return this.list().length===1}concat(...e){return r.withNamespaces([...this.namespaces(),...Wd(e.map(t=>t.namespaces()))])}};function zd(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function Gd(r){let e=r.split(":");return e[e.length-1]}function Wd(r){return[].concat(...r)}var Lo="/peers/";function Nr(r){if(!Go(r)||r.type==null)throw new R("Invalid PeerId",me.ERR_INVALID_PARAMETERS);let e=r.toCID().toString();return new _s(`${Lo}${e}`)}async function Vl(r,e,t){let n=new Map;for(let s of t){if(s==null)continue;if(s.multiaddr instanceof Uint8Array&&(s.multiaddr=mt(s.multiaddr)),!Ss(s.multiaddr))throw new R("Multiaddr was invalid",me.ERR_INVALID_PARAMETERS);if(!await e(r,s.multiaddr))continue;let i=s.isCertified??!1,o=s.multiaddr.toString(),a=n.get(o);a!=null?s.isCertified=a.isCertified||i:n.set(o,{multiaddr:s.multiaddr,isCertified:i})}return[...n.values()].sort((s,i)=>s.multiaddr.toString().localeCompare(i.multiaddr.toString())).map(({isCertified:s,multiaddr:i})=>({isCertified:s,multiaddr:i.bytes}))}async function Ls(r,e,t,n){if(e==null)throw new R("Invalid PeerData",me.ERR_INVALID_PARAMETERS);if(e.publicKey!=null&&r.publicKey!=null&&!te(e.publicKey,r.publicKey))throw new R("publicKey bytes do not match peer id publicKey bytes",me.ERR_INVALID_PARAMETERS);let s=n.existingPeer;if(s!=null&&!r.equals(s.id))throw new R("peer id did not match existing peer id",me.ERR_INVALID_PARAMETERS);let i=s?.addresses??[],o=new Set(s?.protocols??[]),a=s?.metadata??new Map,c=s?.tags??new Map,f=s?.peerRecordEnvelope;if(t==="patch"){if((e.multiaddrs!=null||e.addresses!=null)&&(i=[],e.multiaddrs!=null&&i.push(...e.multiaddrs.map(l=>({isCertified:!1,multiaddr:l}))),e.addresses!=null&&i.push(...e.addresses)),e.protocols!=null&&(o=new Set(e.protocols)),e.metadata!=null){let l=e.metadata instanceof Map?[...e.metadata.entries()]:Object.entries(e.metadata);a=Cs(l,{validate:Ol})}if(e.tags!=null){let l=e.tags instanceof Map?[...e.tags.entries()]:Object.entries(e.tags);c=Cs(l,{validate:Ml,map:Hl})}e.peerRecordEnvelope!=null&&(f=e.peerRecordEnvelope)}if(t==="merge"){if(e.multiaddrs!=null&&i.push(...e.multiaddrs.map(l=>({isCertified:!1,multiaddr:l}))),e.addresses!=null&&i.push(...e.addresses),e.protocols!=null&&(o=new Set([...o,...e.protocols])),e.metadata!=null){let l=e.metadata instanceof Map?[...e.metadata.entries()]:Object.entries(e.metadata);for(let[h,m]of l)m==null?a.delete(h):a.set(h,m);a=Cs([...a.entries()],{validate:Ol})}if(e.tags!=null){let l=e.tags instanceof Map?[...e.tags.entries()]:Object.entries(e.tags),h=new Map(c);for(let[m,p]of l)p==null?h.delete(m):h.set(m,p);c=Cs([...h.entries()],{validate:Ml,map:Hl})}e.peerRecordEnvelope!=null&&(f=e.peerRecordEnvelope)}let u={addresses:await Vl(r,n.addressFilter??(async()=>!0),i),protocols:[...o.values()].sort((l,h)=>l.localeCompare(h)),metadata:a,tags:c,publicKey:s?.id.publicKey??e.publicKey??r.publicKey,peerRecordEnvelope:f};return r.type!=="RSA"&&delete u.publicKey,u}function Cs(r,e){let t=new Map;for(let[n,s]of r)s!=null&&e.validate(n,s);for(let[n,s]of r.sort(([i],[o])=>i.localeCompare(o)))s!=null&&t.set(n,e.map?.(n,s)??s);return t}function Ol(r,e){if(typeof r!="string")throw new R("Metadata key must be a string",me.ERR_INVALID_PARAMETERS);if(!(e instanceof Uint8Array))throw new R("Metadata value must be a Uint8Array",me.ERR_INVALID_PARAMETERS)}function Ml(r,e){if(typeof r!="string")throw new R("Tag name must be a string",me.ERR_INVALID_PARAMETERS);if(e.value!=null){if(parseInt(`${e.value}`,10)!==e.value)throw new R("Tag value must be an integer",me.ERR_INVALID_PARAMETERS);if(e.value<0||e.value>100)throw new R("Tag value must be between 0-100",me.ERR_INVALID_PARAMETERS)}if(e.ttl!=null){if(parseInt(`${e.ttl}`,10)!==e.ttl)throw new R("Tag ttl must be an integer",me.ERR_INVALID_PARAMETERS);if(e.ttl<0)throw new R("Tag ttl must be between greater than 0",me.ERR_INVALID_PARAMETERS)}}function Hl(r,e){let t;return e.expiry!=null&&(t=e.expiry),e.ttl!=null&&(t=BigInt(Date.now()+Number(e.ttl))),{value:e.value??0,expiry:t}}function Us(r,e,t){let n=r.toString().split("/")[2],s=Me.decode(n),i=rn(s),o=t.get(i);if(o!=null)return o;let a=Rr(i,e);return t.set(i,a),a}function jd(r,e){return r==null?{}:{prefix:Lo,filters:(r.filters??[]).map(t=>({key:n,value:s})=>t(Us(n,s,e))),orders:(r.orders??[]).map(t=>(n,s)=>t(Us(n.key,n.value,e),Us(s.key,s.value,e)))}}var Ps=class{peerId;datastore;lock;addressFilter;constructor(e,t={}){this.peerId=e.peerId,this.datastore=e.datastore,this.addressFilter=t.addressFilter,this.lock=Co({name:"peer-store",singleProcess:!0})}async has(e){return this.datastore.has(Nr(e))}async delete(e){if(this.peerId.equals(e))throw new R("Cannot delete self peer",me.ERR_INVALID_PARAMETERS);await this.datastore.delete(Nr(e))}async load(e){let t=await this.datastore.get(Nr(e));return Rr(e,t)}async save(e,t){let{existingBuf:n,existingPeer:s}=await this.#e(e),i=await Ls(e,t,"patch",{addressFilter:this.addressFilter});return this.#t(e,i,n,s)}async patch(e,t){let{existingBuf:n,existingPeer:s}=await this.#e(e),i=await Ls(e,t,"patch",{addressFilter:this.addressFilter,existingPeer:s});return this.#t(e,i,n,s)}async merge(e,t){let{existingBuf:n,existingPeer:s}=await this.#e(e),i=await Ls(e,t,"merge",{addressFilter:this.addressFilter,existingPeer:s});return this.#t(e,i,n,s)}async*all(e){let t=new on;for await(let{key:n,value:s}of this.datastore.query(jd(e??{},t))){let i=Us(n,s,t);i.id.equals(this.peerId)||(yield i)}}async#e(e){try{let t=await this.datastore.get(Nr(e)),n=Rr(e,t);return{existingBuf:t,existingPeer:n}}catch(t){if(t.code!=="ERR_NOT_FOUND")throw t}return{}}async#t(e,t,n,s){let i=Ir.encode(t);return n!=null&&te(i,n)?{peer:Rr(e,i),previous:s,updated:!1}:(await this.datastore.put(Nr(e),i),{peer:Rr(e,i),previous:s,updated:!0})}};var Uo=class{store;events;peerId;log;constructor(e,t={}){this.log=e.logger.forComponent("libp2p:peer-store"),this.events=e.events,this.peerId=e.peerId,this.store=new Ps(e,t)}[Symbol.toStringTag]="@libp2p/peer-store";async forEach(e,t){this.log.trace("forEach await read lock");let n=await this.store.lock.readLock();this.log.trace("forEach got read lock");try{for await(let s of this.store.all(t))e(s)}finally{this.log.trace("forEach release read lock"),n()}}async all(e){this.log.trace("all await read lock");let t=await this.store.lock.readLock();this.log.trace("all got read lock");try{return await Il(this.store.all(e))}finally{this.log.trace("all release read lock"),t()}}async delete(e){this.log.trace("delete await write lock");let t=await this.store.lock.writeLock();this.log.trace("delete got write lock");try{await this.store.delete(e)}finally{this.log.trace("delete release write lock"),t()}}async has(e){this.log.trace("has await read lock");let t=await this.store.lock.readLock();this.log.trace("has got read lock");try{return await this.store.has(e)}finally{this.log.trace("has release read lock"),t()}}async get(e){this.log.trace("get await read lock");let t=await this.store.lock.readLock();this.log.trace("get got read lock");try{return await this.store.load(e)}finally{this.log.trace("get release read lock"),t()}}async save(e,t){this.log.trace("save await write lock");let n=await this.store.lock.writeLock();this.log.trace("save got write lock");try{let s=await this.store.save(e,t);return this.#e(e,s),s.peer}finally{this.log.trace("save release write lock"),n()}}async patch(e,t){this.log.trace("patch await write lock");let n=await this.store.lock.writeLock();this.log.trace("patch got write lock");try{let s=await this.store.patch(e,t);return this.#e(e,s),s.peer}finally{this.log.trace("patch release write lock"),n()}}async merge(e,t){this.log.trace("merge await write lock");let n=await this.store.lock.writeLock();this.log.trace("merge got write lock");try{let s=await this.store.merge(e,t);return this.#e(e,s),s.peer}finally{this.log.trace("merge release write lock"),n()}}async consumePeerRecord(e,t){let n=await Er.openAndCertify(e,Xt.DOMAIN);if(t?.equals(n.peerId)===!1)return this.log("envelope peer id was not the expected peer id - expected: %p received: %p",t,n.peerId),!1;let s=Xt.createFromProtobuf(n.payload),i;try{i=await this.get(n.peerId)}catch(o){if(o.code!=="ERR_NOT_FOUND")throw o}if(i?.peerRecordEnvelope!=null){let o=await Er.createFromProtobuf(i.peerRecordEnvelope),a=Xt.createFromProtobuf(o.payload);if(a.seqNumber>=s.seqNumber)return this.log("sequence number was lower or equal to existing sequence number - stored: %d received: %d",a.seqNumber,s.seqNumber),!1}return await this.patch(s.peerId,{peerRecordEnvelope:e,addresses:s.multiaddrs.map(o=>({isCertified:!0,multiaddr:o}))}),!0}#e(e,t){t.updated&&(this.peerId.equals(e)?this.events.safeDispatchEvent("self:peer:update",{detail:t}):this.events.safeDispatchEvent("peer:update",{detail:t}))}};return eu(Yd);})();
|
|
6
|
+
`)}`:`${t} :`}};ac=It;A.Constructed=ac;It.NAME="CONSTRUCTED";var qn=class extends be{fromBER(e,t,n){return t}toBER(e){return ze}};qn.override="EndOfContentValueBlock";var cc,$n=class extends pe{constructor(e={}){super(e,qn),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};cc=$n;A.EndOfContent=cc;$n.NAME=zr;var lc,Rt=class extends pe{constructor(e={}){super(e,be),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,t,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,t+n>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+n}toBER(e,t){let n=new ArrayBuffer(2);if(!e){let s=new Uint8Array(n);s[0]=5,s[1]=0}return t&&t.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};lc=Rt;A.Null=lc;Rt.NAME="NULL";var zn=class extends pt(be){constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=O.BufferSourceConverter.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}get value(){for(let e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}fromBER(e,t,n){let s=O.BufferSourceConverter.toUint8Array(e);return dt(this,s,t,n)?(this.valueHexView=s.subarray(t,t+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,ji.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};zn.NAME="BooleanValueBlock";var uc,Gn=class extends pe{constructor(e={}){super(e,zn),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};uc=Gn;A.Boolean=uc;Gn.NAME="BOOLEAN";var jn=class extends pt(Xe){constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,n){let s=0;if(this.isConstructed){if(this.isHexOnly=!1,s=Xe.prototype.fromBER.call(this,e,t,n),s===-1)return s;for(let i=0;i<this.value.length;i++){let o=this.value[i].constructor.NAME;if(o===zr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(o!==nc)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,s=super.fromBER(e,t,n),this.blockLength=n;return s}toBER(e,t){return this.isConstructed?Xe.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};jn.NAME="OctetStringValueBlock";var fc,ft=class r extends pe{constructor({idBlock:e={},lenBlock:t={},...n}={}){var s,i;(s=n.isConstructed)!==null&&s!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},jn),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,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),t;if(!this.valueBlock.isConstructed){let i=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+n);try{if(i.byteLength){let o=vs(i,0,i.byteLength);o.offset!==-1&&o.offset===n&&(this.valueBlock.value=[o.result])}}catch{}}return super.fromBER(e,t,n)}onAsciiEncoding(){return this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length?It.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${O.Convert.ToHex(this.valueBlock.valueHexView)}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let e=[];for(let t of this.valueBlock.value)t instanceof r&&e.push(t.valueBlock.valueHexView);return O.BufferSourceConverter.concat(e)}};fc=ft;A.OctetString=fc;ft.NAME=nc;var Wn=class extends pt(Xe){constructor({unusedBits:e=0,isConstructed:t=!1,...n}={}){super(n),this.unusedBits=e,this.isConstructed=t,this.blockLength=this.valueHexView.byteLength}fromBER(e,t,n){if(!n)return t;let s=-1;if(this.isConstructed){if(s=Xe.prototype.fromBER.call(this,e,t,n),s===-1)return s;for(let a of this.value){let c=a.constructor.NAME;if(c===zr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==sc)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let f=a.valueBlock;if(this.unusedBits>0&&f.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=f.unusedBits}return s}let i=O.BufferSourceConverter.toUint8Array(e);if(!dt(this,i,t,n))return-1;let o=i.subarray(t,t+n);if(this.unusedBits=o[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let a=o.subarray(1);try{if(a.byteLength){let c=vs(a,0,a.byteLength);c.offset!==-1&&c.offset===n-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=o.subarray(1),this.blockLength=o.length,t+n}toBER(e,t){if(this.isConstructed)return Xe.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return ze;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}}};Wn.NAME="BitStringValueBlock";var hc,wr=class extends pe{constructor({idBlock:e={},lenBlock:t={},...n}={}){var s,i;(s=n.isConstructed)!==null&&s!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},Wn),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,t,n){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,t,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return It.prototype.onAsciiEncoding.call(this);{let e=[],t=this.valueBlock.valueHexView;for(let s of t)e.push(s.toString(2).padStart(8,"0"));let n=e.join("");return`${this.constructor.NAME} : ${n.substring(0,n.length-this.valueBlock.unusedBits)}`}}};hc=wr;A.BitString=hc;wr.NAME=sc;var dc;function Wh(r,e){let t=new Uint8Array([0]),n=new Uint8Array(r),s=new Uint8Array(e),i=n.slice(0),o=i.length-1,a=s.slice(0),c=a.length-1,f=0,u=c<o?o:c,l=0;for(let d=u;d>=0;d--,l++){switch(!0){case l<a.length:f=i[o-l]+a[c-l]+t[0];break;default:f=i[o-l]+t[0]}switch(t[0]=f/10,!0){case l>=i.length:i=Dn(new Uint8Array([f%10]),i);break;default:i[o-l]=f%10}}return t[0]>0&&(i=Dn(t,i)),i}function rc(r){if(r>=qr.length)for(let e=qr.length;e<=r;e++){let t=new Uint8Array([0]),n=qr[e-1].slice(0);for(let s=n.length-1;s>=0;s--){let i=new Uint8Array([(n[s]<<1)+t[0]]);t[0]=i[0]/10,n[s]=i[0]%10}t[0]>0&&(n=Dn(t,n)),qr.push(n)}return qr[r]}function Yh(r,e){let t=0,n=new Uint8Array(r),s=new Uint8Array(e),i=n.slice(0),o=i.length-1,a=s.slice(0),c=a.length-1,f,u=0;for(let l=c;l>=0;l--,u++)switch(f=i[o-u]-a[c-u]-t,!0){case f<0:t=1,i[o-u]=f+10;break;default:t=0,i[o-u]=f}if(t>0)for(let l=o-c+1;l>=0;l--,u++)if(f=i[o-u]-t,f<0)t=1,i[o-u]=f+10;else{t=0,i[o-u]=f;break}return i.slice()}var Gr=class extends pt(be){constructor({value:e,...t}={}){super(t),this._valueDec=0,t.valueHex&&this.setValueHex(),e!==void 0&&(this.valueDec=e)}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=ji.call(this)))}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(Qa(e))}get valueDec(){return this._valueDec}fromDER(e,t,n,s=0){let i=this.fromBER(e,t,n);if(i===-1)return i;let o=this.valueHexView;return o[0]===0&&o[1]&128?this.valueHexView=o.subarray(1):s!==0&&o.length<s&&(s-o.length>1&&(s=o.length+1),this.valueHexView=o.subarray(s-o.length)),i}toDER(e=!1){let t=this.valueHexView;switch(!0){case(t[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(t,1),this.valueHexView=n}break;case(t[0]===0&&(t[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,t,n){let s=super.fromBER(e,t,n);return s===-1||this.setValueHex(),s}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let e=this.valueHexView.length*8-1,t=new Uint8Array(this.valueHexView.length*8/3),n=0,s,i=this.valueHexView,o="",a=!1;for(let c=i.byteLength-1;c>=0;c--){s=i[c];for(let f=0;f<8;f++){if((s&1)===1)switch(n){case e:t=Yh(rc(n),t),o="-";break;default:t=Wh(t,rc(n))}n++,s>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(o+=tc.charAt(t[c]));return a===!1&&(o+=tc.charAt(0)),o}};dc=Gr;Gr.NAME="IntegerValueBlock";Object.defineProperty(dc.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var pc,ne=class r extends pe{constructor(e={}){super(e,Gr),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Vn(),BigInt(this.valueBlock.toString())}static fromBigInt(e){Vn();let t=BigInt(e),n=new $r,s=t.toString(16).replace(/^-/,""),i=new Uint8Array(O.Convert.FromHex(s));if(t<0){let a=new Uint8Array(i.length+(i[0]&128?1:0));a[0]|=128;let f=BigInt(`0x${O.Convert.ToHex(a)}`)+t,u=O.BufferSourceConverter.toUint8Array(O.Convert.FromHex(f.toString(16)));u[0]|=128,n.write(u)}else i[0]&128&&n.write(new Uint8Array([0])),n.write(i);return new r({valueHex:n.final()})}convertToDER(){let e=new r({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}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()}`}};pc=ne;A.Integer=pc;ne.NAME="INTEGER";var gc,Yn=class extends ne{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};gc=Yn;A.Enumerated=gc;Yn.NAME="ENUMERATED";var jr=class extends pt(be){constructor({valueDec:e=-1,isFirstSid:t=!1,...n}={}){super(n),this.valueDec=e,this.isFirstSid=t}fromBER(e,t,n){if(!n)return t;let s=O.BufferSourceConverter.toUint8Array(e);if(!dt(this,s,t,n))return-1;let i=s.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=i[a]&127,this.blockLength++,!!(i[a]&128));a++);let o=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)o[a]=this.valueHexView[a];return this.valueHexView=o,i[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=jt(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){Vn();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;let n=new Uint8Array(t.length/7);for(let s=0;s<n.length;s++)n[s]=parseInt(t.slice(s*7,s*7+7),2)+(s+1<n.length?128:0);this.fromBER(n.buffer,0,n.length)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let s=this.valueHexView,i=new Uint8Array(this.blockLength);for(let o=0;o<this.blockLength-1;o++)i[o]=s[o]|128;return i[this.blockLength-1]=s[this.blockLength-1],i.buffer}let t=St(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",ze;let n=new Uint8Array(t.byteLength);if(!e){let s=new Uint8Array(t),i=t.byteLength-1;for(let o=0;o<i;o++)n[o]=s[o]|128;n[i]=s[i]}return n}toString(){let e="";if(this.isHexOnly)e=O.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let t=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",t-=40):(e="2.",t-=80),e+=t.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};jr.NAME="sidBlock";var Zn=class extends be{constructor({value:e=xr,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let s=t;for(;n>0;){let i=new jr;if(s=i.fromBER(e,s,n),s===-1)return this.blockLength=0,this.error=i.error,s;this.value.length===0&&(i.isFirstSid=!0),this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return s}toBER(e){let t=[];for(let n=0;n<this.value.length;n++){let s=this.value[n].toBER(e);if(s.byteLength===0)return this.error=this.value[n].error,ze;t.push(s)}return Wi(t)}fromString(e){this.value=[];let t=0,n=0,s="",i=!1;do if(n=e.indexOf(".",t),n===-1?s=e.substring(t):s=e.substring(t,n),t=n+1,i){let o=this.value[0],a=0;switch(o.valueDec){case 0:break;case 1:a=40;break;case 2:a=80;break;default:this.value=[];return}let c=parseInt(s,10);if(isNaN(c))return;o.valueDec=c+a,i=!1}else{let o=new jr;if(s>Number.MAX_SAFE_INTEGER){Vn();let a=BigInt(s);o.valueBigInt=a}else if(o.valueDec=parseInt(s,10),isNaN(o.valueDec))return;this.value.length||(o.isFirstSid=!0,i=!0),this.value.push(o)}while(n!==-1)}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let s=this.value[n].toString();n!==0&&(e=`${e}.`),t?(s=`{${s}}`,this.value[n].isFirstSid?e=`2.{${s} - 80}`:e+=s):e+=s}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};Zn.NAME="ObjectIdentifierValueBlock";var mc,$e=class extends pe{constructor(e={}){super(e,Zn),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};mc=$e;A.ObjectIdentifier=mc;$e.NAME="OBJECT IDENTIFIER";var Wr=class extends pt(ut){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let s=O.BufferSourceConverter.toUint8Array(e);if(!dt(this,s,t,n))return-1;let i=s.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=i[a]&127,this.blockLength++,!!(i[a]&128));a++);let o=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)o[a]=this.valueHexView[a];return this.valueHexView=o,i[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=jt(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let s=this.valueHexView,i=new Uint8Array(this.blockLength);for(let o=0;o<this.blockLength-1;o++)i[o]=s[o]|128;return i[this.blockLength-1]=s[this.blockLength-1],i.buffer}let t=St(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",ze;let n=new Uint8Array(t.byteLength);if(!e){let s=new Uint8Array(t),i=t.byteLength-1;for(let o=0;o<i;o++)n[o]=s[o]|128;n[i]=s[i]}return n.buffer}toString(){let e="";return this.isHexOnly?e=O.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};Wr.NAME="relativeSidBlock";var Jn=class extends be{constructor({value:e=xr,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let s=t;for(;n>0;){let i=new Wr;if(s=i.fromBER(e,s,n),s===-1)return this.blockLength=0,this.error=i.error,s;this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return s}toBER(e,t){let n=[];for(let s=0;s<this.value.length;s++){let i=this.value[s].toBER(e);if(i.byteLength===0)return this.error=this.value[s].error,ze;n.push(i)}return Wi(n)}fromString(e){this.value=[];let t=0,n=0,s="";do{n=e.indexOf(".",t),n===-1?s=e.substring(t):s=e.substring(t,n),t=n+1;let i=new Wr;if(i.valueDec=parseInt(s,10),isNaN(i.valueDec))return!0;this.value.push(i)}while(n!==-1);return!0}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let s=this.value[n].toString();n!==0&&(e=`${e}.`),t&&(s=`{${s}}`),e+=s}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};Jn.NAME="RelativeObjectIdentifierValueBlock";var yc,Xn=class extends pe{constructor(e={}){super(e,Jn),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};yc=Xn;A.RelativeObjectIdentifier=yc;Xn.NAME="RelativeObjectIdentifier";var bc,fe=class extends It{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};bc=fe;A.Sequence=bc;fe.NAME="SEQUENCE";var wc,Qn=class extends It{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};wc=Qn;A.Set=wc;Qn.NAME="SET";var es=class extends pt(be){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=xr}toJSON(){return{...super.toJSON(),value:this.value}}};es.NAME="StringValueBlock";var ts=class extends es{};ts.NAME="SimpleStringValueBlock";var ke=class extends Hn{constructor({...e}={}){super(e,ts)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,O.BufferSourceConverter.toUint8Array(e))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t);for(let s=0;s<t;s++)n[s]=e.charCodeAt(s);this.valueBlock.value=e}};ke.NAME="SIMPLE STRING";var rs=class extends ke{fromBuffer(e){this.valueBlock.valueHexView=O.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=O.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=O.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(O.Convert.FromUtf8String(e)),this.valueBlock.value=e}};rs.NAME="Utf8StringValueBlock";var xc,ht=class extends rs{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};xc=ht;A.Utf8String=xc;ht.NAME="UTF8String";var ns=class extends ke{fromBuffer(e){this.valueBlock.value=O.Convert.ToUtf16String(e),this.valueBlock.valueHexView=O.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(O.Convert.FromUtf16String(e))}};ns.NAME="BmpStringValueBlock";var vc,ss=class extends ns{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};vc=ss;A.BmpString=vc;ss.NAME="BMPString";var is=class extends ke{fromBuffer(e){let t=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),n=new Uint8Array(t);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(t))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t*4);for(let s=0;s<t;s++){let i=St(e.charCodeAt(s),8),o=new Uint8Array(i);if(o.length>4)continue;let a=4-o.length;for(let c=o.length-1;c>=0;c--)n[s*4+c+a]=o[c]}this.valueBlock.value=e}};is.NAME="UniversalStringValueBlock";var Ec,os=class extends is{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};Ec=os;A.UniversalString=Ec;os.NAME="UniversalString";var Bc,as=class extends ke{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};Bc=as;A.NumericString=Bc;as.NAME="NumericString";var Ac,cs=class extends ke{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};Ac=cs;A.PrintableString=Ac;cs.NAME="PrintableString";var kc,ls=class extends ke{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};kc=ls;A.TeletexString=kc;ls.NAME="TeletexString";var Sc,us=class extends ke{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};Sc=us;A.VideotexString=Sc;us.NAME="VideotexString";var Ic,fs=class extends ke{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};Ic=fs;A.IA5String=Ic;fs.NAME="IA5String";var Rc,hs=class extends ke{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};Rc=hs;A.GraphicString=Rc;hs.NAME="GraphicString";var Nc,Yr=class extends ke{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};Nc=Yr;A.VisibleString=Nc;Yr.NAME="VisibleString";var Tc,ds=class extends ke{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};Tc=ds;A.GeneralString=Tc;ds.NAME="GeneralString";var _c,ps=class extends ke{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};_c=ps;A.CharacterString=_c;ps.NAME="CharacterString";var Cc,Zr=class extends Yr{constructor({value:e,valueDate:t,...n}={}){if(super(n),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let s=0;s<e.length;s++)this.valueBlock.valueHexView[s]=e.charCodeAt(s)}t&&(this.fromDate(t),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,O.BufferSourceConverter.toUint8Array(e)))}toBuffer(){let e=this.toString(),t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let s=0;s<e.length;s++)n[s]=e.charCodeAt(s);return t}fromDate(e){this.year=e.getUTCFullYear(),this.month=e.getUTCMonth()+1,this.day=e.getUTCDate(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(e){let n=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(e);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(e="iso"){if(e==="iso"){let t=new Array(7);return t[0]=Ce(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=Ce(this.month,2),t[2]=Ce(this.day,2),t[3]=Ce(this.hour,2),t[4]=Ce(this.minute,2),t[5]=Ce(this.second,2),t[6]="Z",t.join("")}return super.toString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}};Cc=Zr;A.UTCTime=Cc;Zr.NAME="UTCTime";var Lc,gs=class extends Zr{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond))}fromString(e){let t=!1,n="",s="",i=0,o,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),t=!0;else{let l=new Number(e[e.length-1]);if(isNaN(l.valueOf()))throw new Error("Wrong input string for conversion");n=e}if(t){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 l=1,d=n.indexOf("+"),y="";if(d===-1&&(d=n.indexOf("-"),l=-1),d!==-1){if(y=n.substring(d+1),n=n.substring(0,d),y.length!==2&&y.length!==4)throw new Error("Wrong input string for conversion");let g=parseInt(y.substring(0,2),10);if(isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");if(a=l*g,y.length===4){if(g=parseInt(y.substring(2,4),10),isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");c=l*g}}}let f=n.indexOf(".");if(f===-1&&(f=n.indexOf(",")),f!==-1){let l=new Number(`0${n.substring(f)}`);if(isNaN(l.valueOf()))throw new Error("Wrong input string for conversion");i=l.valueOf(),s=n.substring(0,f)}else s=n;switch(!0){case s.length===8:if(o=/(\d{4})(\d{2})(\d{2})/ig,f!==-1)throw new Error("Wrong input string for conversion");break;case s.length===10:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let l=60*i;this.minute=Math.floor(l),l=60*(l-this.minute),this.second=Math.floor(l),l=1e3*(l-this.second),this.millisecond=Math.floor(l)}break;case s.length===12:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let l=60*i;this.second=Math.floor(l),l=1e3*(l-this.second),this.millisecond=Math.floor(l)}break;case s.length===14:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let l=1e3*i;this.millisecond=Math.floor(l)}break;default:throw new Error("Wrong input string for conversion")}let u=o.exec(s);if(u===null)throw new Error("Wrong input string for conversion");for(let l=1;l<u.length;l++)switch(l){case 1:this.year=parseInt(u[l],10);break;case 2:this.month=parseInt(u[l],10);break;case 3:this.day=parseInt(u[l],10);break;case 4:this.hour=parseInt(u[l],10)+a;break;case 5:this.minute=parseInt(u[l],10)+c;break;case 6:this.second=parseInt(u[l],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){let l=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=l.getUTCFullYear(),this.month=l.getUTCMonth(),this.day=l.getUTCDay(),this.hour=l.getUTCHours(),this.minute=l.getUTCMinutes(),this.second=l.getUTCSeconds(),this.millisecond=l.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let t=[];return t.push(Ce(this.year,4)),t.push(Ce(this.month,2)),t.push(Ce(this.day,2)),t.push(Ce(this.hour,2)),t.push(Ce(this.minute,2)),t.push(Ce(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(Ce(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};Lc=gs;A.GeneralizedTime=Lc;gs.NAME="GeneralizedTime";var Uc,ms=class extends ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};Uc=ms;A.DATE=Uc;ms.NAME="DATE";var Pc,ys=class extends ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};Pc=ys;A.TimeOfDay=Pc;ys.NAME="TimeOfDay";var Dc,bs=class extends ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};Dc=bs;A.DateTime=Dc;bs.NAME="DateTime";var Vc,ws=class extends ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};Vc=ws;A.Duration=Vc;ws.NAME="Duration";var Oc,xs=class extends ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};Oc=xs;A.TIME=Oc;xs.NAME="TIME";function Jh(r){let{result:e}=vr(r),t=e.valueBlock.value;return{n:V(Qe(t[1].toBigInt()),"base64url"),e:V(Qe(t[2].toBigInt()),"base64url"),d:V(Qe(t[3].toBigInt()),"base64url"),p:V(Qe(t[4].toBigInt()),"base64url"),q:V(Qe(t[5].toBigInt()),"base64url"),dp:V(Qe(t[6].toBigInt()),"base64url"),dq:V(Qe(t[7].toBigInt()),"base64url"),qi:V(Qe(t[8].toBigInt()),"base64url"),kty:"RSA",alg:"RS256"}}function Xh(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 N("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new fe({value:[new ne({value:0}),ne.fromBigInt(et(q(r.n,"base64url"))),ne.fromBigInt(et(q(r.e,"base64url"))),ne.fromBigInt(et(q(r.d,"base64url"))),ne.fromBigInt(et(q(r.p,"base64url"))),ne.fromBigInt(et(q(r.q,"base64url"))),ne.fromBigInt(et(q(r.dp,"base64url"))),ne.fromBigInt(et(q(r.dq,"base64url"))),ne.fromBigInt(et(q(r.qi,"base64url")))]}).toBER();return new Uint8Array(t,0,t.byteLength)}function Qh(r){let{result:e}=vr(r),t=e.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:V(Qe(t[0].toBigInt()),"base64url"),e:V(Qe(t[1].toBigInt()),"base64url")}}function ed(r){if(r.n==null||r.e==null)throw new N("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new fe({value:[new fe({value:[new $e({value:"1.2.840.113549.1.1.1"}),new Rt]}),new wr({valueHex:new fe({value:[ne.fromBigInt(et(q(r.n,"base64url"))),ne.fromBigInt(et(q(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(t,0,t.byteLength)}function Qe(r){let e=r.toString(16);e.length%2>0&&(e=`0${e}`);let t=e.length/2,n=new Uint8Array(t),s=0,i=0;for(;s<t;)n[s]=parseInt(e.slice(i,i+2),16),s+=1,i+=2;return n}function et(r){let e=[];return r.forEach(function(t){let n=t.toString(16);n.length%2>0&&(n=`0${n}`),e.push(n)}),BigInt("0x"+e.join(""))}var td=16,Zi=32,Ji=1e4;async function rd(r,e){let t=ve.get(),s=new fe({value:[new ne({value:0}),new fe({value:[new $e({value:"1.2.840.113549.1.1.1"}),new Rt]}),new ft({valueHex:r.marshal()})]}).toBER(),i=new Uint8Array(s,0,s.byteLength),o=Gt(td),a=await zi(Pr,e,o,{c:Ji,dkLen:Zi}),c=Gt(16),f=await t.subtle.importKey("raw",a,"AES-CBC",!1,["encrypt"]),u=await t.subtle.encrypt({name:"AES-CBC",iv:c},f,i),l=new fe({value:[new ft({valueHex:o}),new ne({value:Ji}),new ne({value:Zi}),new fe({value:[new $e({value:"1.2.840.113549.2.11"}),new Rt]})]}),d=new fe({value:[new $e({value:"1.2.840.113549.1.5.13"}),new fe({value:[new fe({value:[new $e({value:"1.2.840.113549.1.5.12"}),l]}),new fe({value:[new $e({value:"2.16.840.1.101.3.4.1.42"}),new ft({valueHex:c})]})]})]}),g=new fe({value:[d,new ft({valueHex:u})]}).toBER(),h=new Uint8Array(g,0,g.byteLength);return["-----BEGIN ENCRYPTED PRIVATE KEY-----",...V(h,"base64pad").split(/(.{64})/).filter(Boolean),"-----END ENCRYPTED PRIVATE KEY-----"].join(`
|
|
7
|
+
`)}async function nd(r,e){let t=ve.get(),n;if(r.includes("-----BEGIN ENCRYPTED PRIVATE KEY-----")){let s=q(r.replace("-----BEGIN ENCRYPTED PRIVATE KEY-----","").replace("-----END ENCRYPTED PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:i}=vr(s),{iv:o,salt:a,iterations:c,keySize:f,cipherText:u}=sd(i),l=await zi(Pr,e,a,{c,dkLen:f}),d=await t.subtle.importKey("raw",l,"AES-CBC",!1,["decrypt"]),y=Jr(await t.subtle.decrypt({name:"AES-CBC",iv:o},d,u)),{result:g}=vr(y);n=Mc(g)}else if(r.includes("-----BEGIN PRIVATE KEY-----")){let s=q(r.replace("-----BEGIN PRIVATE KEY-----","").replace("-----END PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:i}=vr(s);n=Mc(i)}else throw new N("Could not parse private key from PEM data","ERR_INVALID_PARAMETERS");return Xi(n)}function sd(r){let e=r.valueBlock.value[0];if(e.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.13")throw new N("Only pkcs5PBES2 encrypted private keys are supported","ERR_INVALID_PARAMS");let n=e.valueBlock.value[1].valueBlock.value[0];if(n.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.12")throw new N("Only pkcs5PBKDF2 key derivation functions are supported","ERR_INVALID_PARAMS");let i=n.valueBlock.value[1],o=Jr(i.valueBlock.value[0].getValue()),a=Ji,c=Zi;if(i.valueBlock.value.length===3)a=Number(i.valueBlock.value[1].toBigInt()),c=Number(i.valueBlock.value[2].toBigInt());else if(i.valueBlock.value.length===2)throw new N("Could not derive key size and iterations from PEM file - please use @libp2p/rsa to re-import your key","ERR_INVALID_PARAMS");let f=e.valueBlock.value[1].valueBlock.value[1],u=f.valueBlock.value[0].toString();if(u!=="OBJECT IDENTIFIER : 1.2.840.113549.3.7"){if(u!=="OBJECT IDENTIFIER : 1.3.14.3.2.7"){if(u!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.2"){if(u!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.22"){if(u!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.42")throw new N("Only AES-CBC encryption schemes are supported","ERR_INVALID_PARAMS")}}}}let l=Jr(f.valueBlock.value[1].getValue());return{cipherText:Jr(r.valueBlock.value[1].getValue()),salt:o,iterations:a,keySize:c,iv:l}}function Mc(r){return Jr(r.valueBlock.value[2].getValue())}function Jr(r){return new Uint8Array(r,0,r.byteLength)}async function Hc(r){let e=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"]),t=await qc(e);return{privateKey:t[0],publicKey:t[1]}}async function Qi(r){let t=[await ve.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),await id(r)],n=await qc({privateKey:t[0],publicKey:t[1]});return{privateKey:n[0],publicKey:n[1]}}async function Kc(r,e){let t=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"},t,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(n,0,n.byteLength)}async function Fc(r,e,t){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,e,t instanceof Uint8Array?t:t.subarray())}async function qc(r){if(r.privateKey==null||r.publicKey==null)throw new N("Private and public key are required","ERR_INVALID_PARAMETERS");return Promise.all([ve.get().subtle.exportKey("jwk",r.privateKey),ve.get().subtle.exportKey("jwk",r.publicKey)])}async function id(r){return ve.get().subtle.importKey("jwk",{kty:r.kty,n:r.n,e:r.e},{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])}function Es(r){if(r.kty!=="RSA")throw new N("invalid key type","ERR_INVALID_KEY_TYPE");if(r.n==null)throw new N("invalid key modulus","ERR_INVALID_KEY_MODULUS");return q(r.n,"base64url").length*8}var Qr=8192,Xr=class{_key;constructor(e){this._key=e}verify(e,t){return Fc(this._key,t,e)}marshal(){return Nt.jwkToPkix(this._key)}get bytes(){return Ze.encode({Type:Z.RSA,Data:this.marshal()}).subarray()}equals(e){return ee(this.bytes,e.bytes)}hash(){let e=de.digest(this.bytes);return Pe(e)?e.then(({bytes:t})=>t):e.bytes}},Er=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t}genSecret(){return Gt(16)}sign(e){return Kc(this._key,e)}get public(){if(this._publicKey==null)throw new N("public key not provided","ERR_PUBKEY_NOT_PROVIDED");return new Xr(this._publicKey)}marshal(){return Nt.jwkToPkcs1(this._key)}get bytes(){return Je.encode({Type:Z.RSA,Data:this.marshal()}).subarray()}equals(e){return ee(this.bytes,e.bytes)}hash(){let e=de.digest(this.bytes);return Pe(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return V(e,"base58btc")}async export(e,t="pkcs-8"){if(t==="pkcs-8")return Nt.exportToPem(this,e);if(t==="libp2p-key")return gr(this.bytes,e);throw new N(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};async function Xi(r){let e=Nt.pkcs1ToJwk(r);if(Es(e)>Qr)throw new N("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await Qi(e);return new Er(t.privateKey,t.publicKey)}function ad(r){let e=Nt.pkixToJwk(r);if(Es(e)>Qr)throw new N("key size is too large","ERR_KEY_SIZE_TOO_LARGE");return new Xr(e)}async function cd(r){if(Es(r)>Qr)throw new N("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await Qi(r);return new Er(e.privateKey,e.publicKey)}async function ld(r){if(r>Qr)throw new N("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await Hc(r);return new Er(e.privateKey,e.publicKey)}var io={};ue(io,{Secp256k1PrivateKey:()=>tn,Secp256k1PublicKey:()=>en,generateKeyPair:()=>Ed,unmarshalSecp256k1PrivateKey:()=>xd,unmarshalSecp256k1PublicKey:()=>vd});var ud=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]),Tt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),_t=new Uint32Array(64),to=class extends fr{constructor(){super(64,32,8,!1),this.A=Tt[0]|0,this.B=Tt[1]|0,this.C=Tt[2]|0,this.D=Tt[3]|0,this.E=Tt[4]|0,this.F=Tt[5]|0,this.G=Tt[6]|0,this.H=Tt[7]|0}get(){let{A:e,B:t,C:n,D:s,E:i,F:o,G:a,H:c}=this;return[e,t,n,s,i,o,a,c]}set(e,t,n,s,i,o,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=s|0,this.E=i|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,t){for(let l=0;l<16;l++,t+=4)_t[l]=e.getUint32(t,!1);for(let l=16;l<64;l++){let d=_t[l-15],y=_t[l-2],g=He(d,7)^He(d,18)^d>>>3,h=He(y,17)^He(y,19)^y>>>10;_t[l]=h+_t[l-7]+g+_t[l-16]|0}let{A:n,B:s,C:i,D:o,E:a,F:c,G:f,H:u}=this;for(let l=0;l<64;l++){let d=He(a,6)^He(a,11)^He(a,25),y=u+d+Ea(a,c,f)+ud[l]+_t[l]|0,h=(He(n,2)^He(n,13)^He(n,22))+Ba(n,s,i)|0;u=f,f=c,c=a,a=o+y|0,o=i,i=s,s=n,n=y+h|0}n=n+this.A|0,s=s+this.B|0,i=i+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,s,i,o,a,c,f,u)}roundClean(){_t.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var $c=xn(()=>new to);function zc(r){r.lowS!==void 0&&Ke("lowS",r.lowS),r.prehash!==void 0&&Ke("prehash",r.prehash)}function fd(r){let e=Or(r);We(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:t,Fp:n,a:s}=e;if(t){if(!n.eql(s,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof t!="object"||typeof t.beta!="bigint"||typeof t.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}var{bytesToNumberBE:hd,hexToBytes:dd}=Bn,Wt={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(r){let{Err:e}=Wt;if(r.length<2||r[0]!==2)throw new e("Invalid signature integer tag");let t=r[1],n=r.subarray(2,t+2);if(!t||n.length!==t)throw new e("Invalid signature integer: wrong length");if(n[0]&128)throw new e("Invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new e("Invalid signature integer: unnecessary leading zero");return{d:hd(n),l:r.subarray(t+2)}},toSig(r){let{Err:e}=Wt,t=typeof r=="string"?dd(r):r;hr(t);let n=t.length;if(n<2||t[0]!=48)throw new e("Invalid signature tag");if(t[1]!==n-2)throw new e("Invalid signature: incorrect length");let{d:s,l:i}=Wt._parseInt(t.subarray(2)),{d:o,l:a}=Wt._parseInt(i);if(a.length)throw new e("Invalid signature: left bytes after parsing");return{r:s,s:o}},hexFromSig(r){let e=f=>Number.parseInt(f[0],16)&8?"00"+f:f,t=f=>{let u=f.toString(16);return u.length&1?`0${u}`:u},n=e(t(r.s)),s=e(t(r.r)),i=n.length/2,o=s.length/2,a=t(i),c=t(o);return`30${t(o+i+4)}02${c}${s}02${a}${n}`}},Ct=BigInt(0),he=BigInt(1),pm=BigInt(2),Gc=BigInt(3),gm=BigInt(4);function pd(r){let e=fd(r),{Fp:t}=e,n=e.toBytes||((g,h,b)=>{let v=h.toAffine();return at(Uint8Array.from([4]),t.toBytes(v.x),t.toBytes(v.y))}),s=e.fromBytes||(g=>{let h=g.subarray(1),b=t.fromBytes(h.subarray(0,t.BYTES)),v=t.fromBytes(h.subarray(t.BYTES,2*t.BYTES));return{x:b,y:v}});function i(g){let{a:h,b}=e,v=t.sqr(g),w=t.mul(v,g);return t.add(t.add(w,t.mul(g,h)),b)}if(!t.eql(t.sqr(e.Gy),i(e.Gx)))throw new Error("bad generator point: equation left != right");function o(g){return Dr(g,he,e.n)}function a(g){let{allowedPrivateKeyLengths:h,nByteLength:b,wrapPrivateKey:v,n:w}=e;if(h&&typeof g!="bigint"){if(Et(g)&&(g=it(g)),typeof g!="string"||!h.includes(g.length))throw new Error("Invalid key");g=g.padStart(b*2,"0")}let x;try{x=typeof g=="bigint"?g:ot(te("private key",g,b))}catch{throw new Error(`private key must be ${b} bytes, hex or bigint, not ${typeof g}`)}return v&&(x=G(x,w)),Ne("private key",x,he,w),x}function c(g){if(!(g instanceof l))throw new Error("ProjectivePoint expected")}let f=Ht((g,h)=>{let{px:b,py:v,pz:w}=g;if(t.eql(w,t.ONE))return{x:b,y:v};let x=g.is0();h==null&&(h=x?t.ONE:t.inv(w));let _=t.mul(b,h),S=t.mul(v,h),k=t.mul(w,h);if(x)return{x:t.ZERO,y:t.ZERO};if(!t.eql(k,t.ONE))throw new Error("invZ was invalid");return{x:_,y:S}}),u=Ht(g=>{if(g.is0()){if(e.allowInfinityPoint&&!t.is0(g.py))return;throw new Error("bad point: ZERO")}let{x:h,y:b}=g.toAffine();if(!t.isValid(h)||!t.isValid(b))throw new Error("bad point: x or y not FE");let v=t.sqr(b),w=i(h);if(!t.eql(v,w))throw new Error("bad point: equation left != right");if(!g.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class l{constructor(h,b,v){if(this.px=h,this.py=b,this.pz=v,h==null||!t.isValid(h))throw new Error("x required");if(b==null||!t.isValid(b))throw new Error("y required");if(v==null||!t.isValid(v))throw new Error("z required");Object.freeze(this)}static fromAffine(h){let{x:b,y:v}=h||{};if(!h||!t.isValid(b)||!t.isValid(v))throw new Error("invalid affine point");if(h instanceof l)throw new Error("projective point not allowed");let w=x=>t.eql(x,t.ZERO);return w(b)&&w(v)?l.ZERO:new l(b,v,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let b=t.invertBatch(h.map(v=>v.pz));return h.map((v,w)=>v.toAffine(b[w])).map(l.fromAffine)}static fromHex(h){let b=l.fromAffine(s(te("pointHex",h)));return b.assertValidity(),b}static fromPrivateKey(h){return l.BASE.multiply(a(h))}_setWindowSize(h){y.setWindowSize(this,h)}assertValidity(){u(this)}hasEvenY(){let{y:h}=this.toAffine();if(t.isOdd)return!t.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){c(h);let{px:b,py:v,pz:w}=this,{px:x,py:_,pz:S}=h,k=t.eql(t.mul(b,S),t.mul(x,w)),T=t.eql(t.mul(v,S),t.mul(_,w));return k&&T}negate(){return new l(this.px,t.neg(this.py),this.pz)}double(){let{a:h,b}=e,v=t.mul(b,Gc),{px:w,py:x,pz:_}=this,S=t.ZERO,k=t.ZERO,T=t.ZERO,I=t.mul(w,w),z=t.mul(x,x),M=t.mul(_,_),H=t.mul(w,x);return H=t.add(H,H),T=t.mul(w,_),T=t.add(T,T),S=t.mul(h,T),k=t.mul(v,M),k=t.add(S,k),S=t.sub(z,k),k=t.add(z,k),k=t.mul(S,k),S=t.mul(H,S),T=t.mul(v,T),M=t.mul(h,M),H=t.sub(I,M),H=t.mul(h,H),H=t.add(H,T),T=t.add(I,I),I=t.add(T,I),I=t.add(I,M),I=t.mul(I,H),k=t.add(k,I),M=t.mul(x,_),M=t.add(M,M),I=t.mul(M,H),S=t.sub(S,I),T=t.mul(M,z),T=t.add(T,T),T=t.add(T,T),new l(S,k,T)}add(h){c(h);let{px:b,py:v,pz:w}=this,{px:x,py:_,pz:S}=h,k=t.ZERO,T=t.ZERO,I=t.ZERO,z=e.a,M=t.mul(e.b,Gc),H=t.mul(b,x),re=t.mul(v,_),se=t.mul(w,S),R=t.add(b,v),m=t.add(x,_);R=t.mul(R,m),m=t.add(H,re),R=t.sub(R,m),m=t.add(b,w);let p=t.add(x,S);return m=t.mul(m,p),p=t.add(H,se),m=t.sub(m,p),p=t.add(v,w),k=t.add(_,S),p=t.mul(p,k),k=t.add(re,se),p=t.sub(p,k),I=t.mul(z,m),k=t.mul(M,se),I=t.add(k,I),k=t.sub(re,I),I=t.add(re,I),T=t.mul(k,I),re=t.add(H,H),re=t.add(re,H),se=t.mul(z,se),m=t.mul(M,m),re=t.add(re,se),se=t.sub(H,se),se=t.mul(z,se),m=t.add(m,se),H=t.mul(re,m),T=t.add(T,H),H=t.mul(p,m),k=t.mul(R,k),k=t.sub(k,H),H=t.mul(R,re),I=t.mul(p,I),I=t.add(I,H),new l(k,T,I)}subtract(h){return this.add(h.negate())}is0(){return this.equals(l.ZERO)}wNAF(h){return y.wNAFCached(this,h,l.normalizeZ)}multiplyUnsafe(h){Ne("scalar",h,Ct,e.n);let b=l.ZERO;if(h===Ct)return b;if(h===he)return this;let{endo:v}=e;if(!v)return y.unsafeLadder(this,h);let{k1neg:w,k1:x,k2neg:_,k2:S}=v.splitScalar(h),k=b,T=b,I=this;for(;x>Ct||S>Ct;)x&he&&(k=k.add(I)),S&he&&(T=T.add(I)),I=I.double(),x>>=he,S>>=he;return w&&(k=k.negate()),_&&(T=T.negate()),T=new l(t.mul(T.px,v.beta),T.py,T.pz),k.add(T)}multiply(h){let{endo:b,n:v}=e;Ne("scalar",h,he,v);let w,x;if(b){let{k1neg:_,k1:S,k2neg:k,k2:T}=b.splitScalar(h),{p:I,f:z}=this.wNAF(S),{p:M,f:H}=this.wNAF(T);I=y.constTimeNegate(_,I),M=y.constTimeNegate(k,M),M=new l(t.mul(M.px,b.beta),M.py,M.pz),w=I.add(M),x=z.add(H)}else{let{p:_,f:S}=this.wNAF(h);w=_,x=S}return l.normalizeZ([w,x])[0]}multiplyAndAddUnsafe(h,b,v){let w=l.BASE,x=(S,k)=>k===Ct||k===he||!S.equals(w)?S.multiplyUnsafe(k):S.multiply(k),_=x(this,b).add(x(h,v));return _.is0()?void 0:_}toAffine(h){return f(this,h)}isTorsionFree(){let{h,isTorsionFree:b}=e;if(h===he)return!0;if(b)return b(l,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:b}=e;return h===he?this:b?b(l,this):this.multiplyUnsafe(e.h)}toRawBytes(h=!0){return Ke("isCompressed",h),this.assertValidity(),n(l,this,h)}toHex(h=!0){return Ke("isCompressed",h),it(this.toRawBytes(h))}}l.BASE=new l(e.Gx,e.Gy,t.ONE),l.ZERO=new l(t.ZERO,t.ONE,t.ZERO);let d=e.nBitLength,y=Sn(l,e.endo?Math.ceil(d/2):d);return{CURVE:e,ProjectivePoint:l,normPrivateKeyToScalar:a,weierstrassEquation:i,isWithinCurveOrder:o}}function gd(r){let e=Or(r);return We(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function jc(r){let e=gd(r),{Fp:t,n}=e,s=t.BYTES+1,i=2*t.BYTES+1;function o(R){return G(R,n)}function a(R){return An(R,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:f,weierstrassEquation:u,isWithinCurveOrder:l}=pd({...e,toBytes(R,m,p){let E=m.toAffine(),B=t.toBytes(E.x),C=at;return Ke("isCompressed",p),p?C(Uint8Array.from([m.hasEvenY()?2:3]),B):C(Uint8Array.from([4]),B,t.toBytes(E.y))},fromBytes(R){let m=R.length,p=R[0],E=R.subarray(1);if(m===s&&(p===2||p===3)){let B=ot(E);if(!Dr(B,he,t.ORDER))throw new Error("Point is not on curve");let C=u(B),L;try{L=t.sqrt(C)}catch(D){let F=D instanceof Error?": "+D.message:"";throw new Error("Point is not on curve"+F)}let U=(L&he)===he;return(p&1)===1!==U&&(L=t.neg(L)),{x:B,y:L}}else if(m===i&&p===4){let B=t.fromBytes(E.subarray(0,t.BYTES)),C=t.fromBytes(E.subarray(t.BYTES,2*t.BYTES));return{x:B,y:C}}else throw new Error(`Point of length ${m} was invalid. Expected ${s} compressed bytes or ${i} uncompressed bytes`)}}),d=R=>it(At(R,e.nByteLength));function y(R){let m=n>>he;return R>m}function g(R){return y(R)?o(-R):R}let h=(R,m,p)=>ot(R.slice(m,p));class b{constructor(m,p,E){this.r=m,this.s=p,this.recovery=E,this.assertValidity()}static fromCompact(m){let p=e.nByteLength;return m=te("compactSignature",m,p*2),new b(h(m,0,p),h(m,p,2*p))}static fromDER(m){let{r:p,s:E}=Wt.toSig(te("DER",m));return new b(p,E)}assertValidity(){Ne("r",this.r,he,n),Ne("s",this.s,he,n)}addRecoveryBit(m){return new b(this.r,this.s,m)}recoverPublicKey(m){let{r:p,s:E,recovery:B}=this,C=k(te("msgHash",m));if(B==null||![0,1,2,3].includes(B))throw new Error("recovery id invalid");let L=B===2||B===3?p+e.n:p;if(L>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let U=B&1?"03":"02",K=c.fromHex(U+d(L)),D=a(L),F=o(-C*D),J=o(E*D),X=c.BASE.multiplyAndAddUnsafe(K,F,J);if(!X)throw new Error("point at infinify");return X.assertValidity(),X}hasHighS(){return y(this.s)}normalizeS(){return this.hasHighS()?new b(this.r,o(-this.s),this.recovery):this}toDERRawBytes(){return Ot(this.toDERHex())}toDERHex(){return Wt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Ot(this.toCompactHex())}toCompactHex(){return d(this.r)+d(this.s)}}let v={isValidPrivateKey(R){try{return f(R),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let R=wi(e.n);return Ca(e.randomBytes(R),e.n)},precompute(R=8,m=c.BASE){return m._setWindowSize(R),m.multiply(BigInt(3)),m}};function w(R,m=!0){return c.fromPrivateKey(R).toRawBytes(m)}function x(R){let m=Et(R),p=typeof R=="string",E=(m||p)&&R.length;return m?E===s||E===i:p?E===2*s||E===2*i:R instanceof c}function _(R,m,p=!0){if(x(R))throw new Error("first arg must be private key");if(!x(m))throw new Error("second arg must be public key");return c.fromHex(m).multiply(f(R)).toRawBytes(p)}let S=e.bits2int||function(R){let m=ot(R),p=R.length*8-e.nBitLength;return p>0?m>>BigInt(p):m},k=e.bits2int_modN||function(R){return o(S(R))},T=Vr(e.nBitLength);function I(R){return Ne(`num < 2^${e.nBitLength}`,R,Ct,T),At(R,e.nByteLength)}function z(R,m,p=M){if(["recovered","canonical"].some(ce=>ce in p))throw new Error("sign() legacy options not supported");let{hash:E,randomBytes:B}=e,{lowS:C,prehash:L,extraEntropy:U}=p;C==null&&(C=!0),R=te("msgHash",R),zc(p),L&&(R=te("prehashed msgHash",E(R)));let K=k(R),D=f(m),F=[I(D),I(K)];if(U!=null&&U!==!1){let ce=U===!0?B(t.BYTES):U;F.push(te("extraEntropy",ce))}let J=at(...F),X=K;function Ie(ce){let ie=S(ce);if(!l(ie))return;let Ve=a(ie),le=c.BASE.multiply(ie).toAffine(),Oe=o(le.x);if(Oe===Ct)return;let Pt=o(Ve*o(X+Oe*D));if(Pt===Ct)return;let _r=(le.x===Oe?0:2)|Number(le.y&he),dn=Pt;return C&&y(Pt)&&(dn=g(Pt),_r^=1),new b(Oe,dn,_r)}return{seed:J,k2sig:Ie}}let M={lowS:e.lowS,prehash:!1},H={lowS:e.lowS,prehash:!1};function re(R,m,p=M){let{seed:E,k2sig:B}=z(R,m,p),C=e;return gi(C.hash.outputLen,C.nByteLength,C.hmac)(E,B)}c.BASE._setWindowSize(8);function se(R,m,p,E=H){let B=R;if(m=te("msgHash",m),p=te("publicKey",p),"strict"in E)throw new Error("options.strict was renamed to lowS");zc(E);let{lowS:C,prehash:L}=E,U,K;try{if(typeof B=="string"||Et(B))try{U=b.fromDER(B)}catch(le){if(!(le instanceof Wt.Err))throw le;U=b.fromCompact(B)}else if(typeof B=="object"&&typeof B.r=="bigint"&&typeof B.s=="bigint"){let{r:le,s:Oe}=B;U=new b(le,Oe)}else throw new Error("PARSE");K=c.fromHex(p)}catch(le){if(le.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(C&&U.hasHighS())return!1;L&&(m=e.hash(m));let{r:D,s:F}=U,J=k(m),X=a(F),Ie=o(J*X),ce=o(D*X),ie=c.BASE.multiplyAndAddUnsafe(K,Ie,ce)?.toAffine();return ie?o(ie.x)===D:!1}return{CURVE:e,getPublicKey:w,getSharedSecret:_,sign:re,verify:se,ProjectivePoint:c,Signature:b,utils:v}}function md(r){return{hash:r,hmac:(e,...t)=>Fr(r,e,ci(...t)),randomBytes:ur}}function Wc(r,e){let t=n=>jc({...r,...md(n)});return Object.freeze({...t(e),create:t})}var Jc=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Yc=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),yd=BigInt(1),ro=BigInt(2),Zc=(r,e)=>(r+e/ro)/e;function bd(r){let e=Jc,t=BigInt(3),n=BigInt(6),s=BigInt(11),i=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%e,u=f*f*r%e,l=Y(u,t,e)*u%e,d=Y(l,t,e)*u%e,y=Y(d,ro,e)*f%e,g=Y(y,s,e)*y%e,h=Y(g,i,e)*g%e,b=Y(h,a,e)*h%e,v=Y(b,c,e)*b%e,w=Y(v,a,e)*h%e,x=Y(w,t,e)*u%e,_=Y(x,o,e)*g%e,S=Y(_,n,e)*f%e,k=Y(S,ro,e);if(!no.eql(no.sqr(k),r))throw new Error("Cannot find square root");return k}var no=kn(Jc,void 0,void 0,{sqrt:bd}),Ge=Wc({a:BigInt(0),b:BigInt(7),Fp:no,n:Yc,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=Yc,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-yd*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=t,o=BigInt("0x100000000000000000000000000000000"),a=Zc(i*r,e),c=Zc(-n*r,e),f=G(r-a*t-c*s,e),u=G(-a*n-c*i,e),l=f>o,d=u>o;if(l&&(f=e-f),d&&(u=e-u),f>o||u>o)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:l,k1:f,k2neg:d,k2:u}}}},$c),Am=BigInt(0);var km=Ge.ProjectivePoint;function Xc(){return Ge.utils.randomPrivateKey()}function Qc(r,e){let t=de.digest(e instanceof Uint8Array?e:e.subarray());if(Pe(t))return t.then(({digest:n})=>Ge.sign(n,r).toDERRawBytes()).catch(n=>{throw new N(String(n),"ERR_INVALID_INPUT")});try{return Ge.sign(t.digest,r).toDERRawBytes()}catch(n){throw new N(String(n),"ERR_INVALID_INPUT")}}function el(r,e,t){let n=de.digest(t instanceof Uint8Array?t:t.subarray());if(Pe(n))return n.then(({digest:s})=>Ge.verify(e,s,r)).catch(s=>{throw new N(String(s),"ERR_INVALID_INPUT")});try{return Ge.verify(e,n.digest,r)}catch(s){throw new N(String(s),"ERR_INVALID_INPUT")}}function tl(r){return Ge.ProjectivePoint.fromHex(r).toRawBytes(!0)}function rl(r){try{Ge.getPublicKey(r,!0)}catch(e){throw new N(String(e),"ERR_INVALID_PRIVATE_KEY")}}function so(r){try{Ge.ProjectivePoint.fromHex(r)}catch(e){throw new N(String(e),"ERR_INVALID_PUBLIC_KEY")}}function nl(r){try{return Ge.getPublicKey(r,!0)}catch(e){throw new N(String(e),"ERR_INVALID_PRIVATE_KEY")}}var en=class{_key;constructor(e){so(e),this._key=e}verify(e,t){return el(this._key,t,e)}marshal(){return tl(this._key)}get bytes(){return Ze.encode({Type:Z.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return ee(this.bytes,e.bytes)}async hash(){let e=de.digest(this.bytes),t;return Pe(e)?{bytes:t}=await e:t=e.bytes,t}},tn=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t??nl(e),rl(this._key),so(this._publicKey)}sign(e){return Qc(this._key,e)}get public(){return new en(this._publicKey)}marshal(){return this._key}get bytes(){return Je.encode({Type:Z.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return ee(this.bytes,e.bytes)}hash(){let e=de.digest(this.bytes);return Pe(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return V(e,"base58btc")}async export(e,t="libp2p-key"){if(t==="libp2p-key")return gr(this.bytes,e);throw new N(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function xd(r){return new tn(r)}function vd(r){return new en(r)}async function Ed(){let r=Xc();return new tn(r)}var Yt={rsa:eo,ed25519:$i,secp256k1:io};function sl(r){let e=Object.keys(Yt).join(" / ");return new N(`invalid or unsupported key type ${r}. Must be ${e}`,"ERR_UNSUPPORTED_KEY_TYPE")}function il(r){let e=Ze.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case Z.RSA:return Yt.rsa.unmarshalRsaPublicKey(t);case Z.Ed25519:return Yt.ed25519.unmarshalEd25519PublicKey(t);case Z.Secp256k1:return Yt.secp256k1.unmarshalSecp256k1PublicKey(t);default:throw sl(e.Type??"unknown")}}async function ol(r){let e=Je.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case Z.RSA:return Yt.rsa.unmarshalRsaPrivateKey(t);case Z.Ed25519:return Yt.ed25519.unmarshalEd25519PrivateKey(t);case Z.Secp256k1:return Yt.secp256k1.unmarshalSecp256k1PrivateKey(t);default:throw sl(e.Type??"RSA")}}var cl=Symbol.for("nodejs.util.inspect.custom"),al=Object.values(bt).map(r=>r.decoder).reduce((r,e)=>r.or(e),bt.identity.decoder),ll=114,co=36,lo=37,rn=class{type;multihash;privateKey;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,this.privateKey=e.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[gn]=!0;toString(){return this.string==null&&(this.string=oe.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return Ue.createV1(ll,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return ee(this.multihash.bytes,e);if(typeof e=="string")return nn(e).equals(this);if(e?.multihash?.bytes!=null)return ee(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[cl](){return`PeerId(${this.toString()})`}},Zt=class extends rn{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Jt=class extends rn{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}},Xt=class extends rn{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}},oo=2336,ao=class{type="url";multihash;privateKey;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=rt.digest(q(this.url))}[cl](){return`PeerId(${this.url})`}[gn]=!0;toString(){return this.toCID().toString()}toCID(){return Ue.createV1(oo,this.multihash)}toBytes(){return this.toCID().bytes}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=V(e)),e.toString()===this.toString())}};function ul(r){if(r.type==="RSA")return new Zt(r);if(r.type==="Ed25519")return new Jt(r);if(r.type==="secp256k1")return new Xt(r);throw new N("Not a PeerId","ERR_INVALID_PARAMETERS")}function nn(r,e){if(e=e??al,r.charAt(0)==="1"||r.charAt(0)==="Q"){let t=Dt(oe.decode(`z${r}`));return r.startsWith("12D")?new Jt({multihash:t}):r.startsWith("16U")?new Xt({multihash:t}):new Zt({multihash:t})}return sn(al.decode(r))}function sn(r){try{let e=Dt(r);if(e.code===rt.code){if(e.digest.length===co)return new Jt({multihash:e});if(e.digest.length===lo)return new Xt({multihash:e})}if(e.code===de.code)return new Zt({multihash:e})}catch{return Bd(Ue.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function Bd(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==ll&&r.code!==oo)throw new Error("Supplied PeerID CID is invalid");if(r.code===oo){let t=V(r.multihash.digest);return new ao(new URL(t))}let e=r.multihash;if(e.code===de.code)return new Zt({multihash:r.multihash});if(e.code===rt.code){if(e.digest.length===co)return new Jt({multihash:r.multihash});if(e.digest.length===lo)return new Xt({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function fl(r,e){return r.length===co?new Jt({multihash:je(rt.code,r),privateKey:e}):r.length===lo?new Xt({multihash:je(rt.code,r),privateKey:e}):new Zt({multihash:await de.digest(r),publicKey:r,privateKey:e})}var dl=Symbol.for("@achingbrain/uint8arraylist");function hl(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let s=t+n.byteLength;if(e<s)return{buf:n,index:e-t};t=s}throw new RangeError("index is out of bounds")}function Bs(r){return!!r?.[dl]}var As=class r{bufs;length;[dl]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if(Bs(n))t+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if(Bs(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=hl(this.bufs,e);return t.buf[t.index]}set(e,t){let n=hl(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if(Bs(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:s}=this._subList(e,t);return xe(n,s)}subarray(e,t){let{bufs:n,length:s}=this._subList(e,t);return n.length===1?n[0]:xe(n,s)}sublist(e,t){let{bufs:n,length:s}=this._subList(e,t),i=new r;return i.length=s,i.bufs=[...n],i}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let n=[],s=0;for(let i=0;i<this.bufs.length;i++){let o=this.bufs[i],a=s,c=a+o.byteLength;if(s=c,e>=c)continue;let f=e>=a&&e<c,u=t>a&&t<=c;if(f&&u){if(e===a&&t===c){n.push(o);break}let l=e-a;n.push(o.subarray(l,l+(t-e)));break}if(f){if(e===0){n.push(o);continue}n.push(o.subarray(e-a));continue}if(u){if(t===c){n.push(o);break}n.push(o.subarray(0,t-a));break}n.push(o)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!Bs(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let i=256,o=new Int32Array(i);for(let l=0;l<i;l++)o[l]=-1;for(let l=0;l<s;l++)o[n[l]]=l;let a=o,c=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let l=t;l<=c;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-a[y]);break}}if(u===0)return l}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=Re(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let s=nt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,t,n),this.write(s,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let s=nt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,t,n),this.write(s,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let s=nt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,t,n),this.write(s,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=Re(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let s=nt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,t,n),this.write(s,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let s=nt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,t,n),this.write(s,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let s=nt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,t,n),this.write(s,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let s=nt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,t,n),this.write(s,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let s=nt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,t,n),this.write(s,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!ee(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((s,i)=>s+i.byteLength,0)),n.length=t,n}};var pl={ERR_SIGNATURE_NOT_VALID:"ERR_SIGNATURE_NOT_VALID"};var on;(function(r){let e;r.codec=()=>(e==null&&(e=Ae((t,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),t.publicKey!=null&&t.publicKey.byteLength>0&&(n.uint32(10),n.bytes(t.publicKey)),t.payloadType!=null&&t.payloadType.byteLength>0&&(n.uint32(18),n.bytes(t.payloadType)),t.payload!=null&&t.payload.byteLength>0&&(n.uint32(26),n.bytes(t.payload)),t.signature!=null&&t.signature.byteLength>0&&(n.uint32(42),n.bytes(t.signature)),s.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let s={publicKey:new Uint8Array(0),payloadType:new Uint8Array(0),payload:new Uint8Array(0),signature:new Uint8Array(0)},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let o=t.uint32();switch(o>>>3){case 1:s.publicKey=t.bytes();break;case 2:s.payloadType=t.bytes();break;case 3:s.payload=t.bytes();break;case 5:s.signature=t.bytes();break;default:t.skipType(o&7);break}}return s})),e),r.encode=t=>Be(t,r.codec()),r.decode=t=>Ee(t,r.codec())})(on||(on={}));var Br=class r{static createFromProtobuf=async e=>{let t=on.decode(e),n=await fl(t.publicKey);return new r({peerId:n,payloadType:t.payloadType,payload:t.payload,signature:t.signature})};static seal=async(e,t)=>{if(t.privateKey==null)throw new Error("Missing private key");let n=e.domain,s=e.codec,i=e.marshal(),o=gl(n,s,i),c=await(await ol(t.privateKey)).sign(o.subarray());return new r({peerId:t,payloadType:s,payload:i,signature:c})};static openAndCertify=async(e,t)=>{let n=await r.createFromProtobuf(e);if(!await n.validate(t))throw new N("envelope signature is not valid for the given domain",pl.ERR_SIGNATURE_NOT_VALID);return n};peerId;payloadType;payload;signature;marshaled;constructor(e){let{peerId:t,payloadType:n,payload:s,signature:i}=e;this.peerId=t,this.payloadType=n,this.payload=s,this.signature=i}marshal(){if(this.peerId.publicKey==null)throw new Error("Missing public key");return this.marshaled==null&&(this.marshaled=on.encode({publicKey:this.peerId.publicKey,payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(e){return ee(this.marshal(),e.marshal())}async validate(e){let t=gl(e,this.payloadType,this.payload);if(this.peerId.publicKey==null)throw new Error("Missing public key");return il(this.peerId.publicKey).verify(t.subarray(),this.signature)}},gl=(r,e,t)=>{let n=q(r),s=Ye(n.byteLength),i=Ye(e.length),o=Ye(t.length);return new As(s,n,i,e,o,t)};function ml(r,e){let t=(n,s)=>n.toString().localeCompare(s.toString());return r.length!==e.length?!1:(e.sort(t),r.sort(t).every((n,s)=>e[s].equals(n)))}var ks=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}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(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,s){return this.readAtomically(()=>{let i=0,o=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",f=2**(8*s)-1;for(;;){let u=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let d=Number.parseInt(l,e);if(!Number.isNaN(d))return d});if(u===void 0)break;if(i*=e,i+=u,i>f||(o+=1,t!==void 0&&o>t))return}if(o!==0)return!n&&c&&o>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let s=n*2;if(n<t.length-3){let o=this.readSeparator(":",n,()=>this.readIPv4Addr());if(o!==void 0)return t[s]=o[0],t[s+1]=o[1],t[s+2]=o[2],t[s+3]=o[3],[s+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[s,!1];t[s]=i>>8,t[s+1]=i&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,s]=e(t);if(n===16)return t;if(s||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),o=16-(n+2),[a]=e(i.subarray(0,o));return t.set(i.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var yl=45,Ad=15,Ar=new ks;function uo(r){if(!(r.length>Ad))return Ar.new(r).parseWith(()=>Ar.readIPv4Addr())}function fo(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>yl))return Ar.new(r).parseWith(()=>Ar.readIPv6Addr())}function Ss(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>yl))return Ar.new(r).parseWith(()=>Ar.readIPAddr())}var Ey=parseInt("0xFFFF",16),By=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function xl(r){return!!uo(r)}function vl(r){return!!fo(r)}function Is(r){return!!Ss(r)}var El=xl,Nd=vl,ho=function(r){let e=0;if(r=r.toString().trim(),El(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(Nd(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=El(t[n]),o;i&&(o=ho(t[n]),t[n]=V(o.slice(0,2),"base16")),o!=null&&++n<8&&t.splice(n,0,V(o.slice(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let i=[n,1];for(n=9-t.length;n>0;n--)i.push("0");t.splice.apply(t,i)}let s=new Uint8Array(e+16);for(n=0;n<t.length;n++){let i=parseInt(t[n],16);s[e++]=i>>8&255,s[e++]=i&255}return s}throw new Error("invalid ip address")},Bl=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let s=[];for(let i=0;i<t;i++)s.push(r[e+i]);return s.join(".")}if(t===16){let s=[];for(let i=0;i<t;i+=2)s.push(n.getUint16(e+i).toString(16));return s.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var kr={},po={},_d=[[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"]];_d.forEach(r=>{let e=Cd(...r);po[e.code]=e,kr[e.name]=e});function Cd(r,e,t,n,s){return{code:r,size:e,name:t,resolvable:!!n,path:!!s}}function j(r){if(typeof r=="number"){if(po[r]!=null)return po[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(kr[r]!=null)return kr[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var ob=j("ip4"),ab=j("ip6"),cb=j("ipcidr");function bo(r,e){switch(j(r).code){case 4:case 41:return Ud(e);case 42:return yo(e);case 6:case 273:case 33:case 132:return Sl(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return yo(e);case 421:return Od(e);case 444:return kl(e);case 445:return kl(e);case 466:return Vd(e);case 481:return globalThis.encodeURIComponent(yo(e));default:return V(e,"base16")}}function wo(r,e){switch(j(r).code){case 4:return Al(e);case 41:return Al(e);case 42:return mo(e);case 6:case 273:case 33:case 132:return xo(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return mo(e);case 421:return Pd(e);case 444:return Md(e);case 445:return Hd(e);case 466:return Dd(e);case 481:return mo(globalThis.decodeURIComponent(e));default:return q(e,"base16")}}var go=Object.values(bt).map(r=>r.decoder),Ld=function(){let r=go[0].or(go[1]);return go.slice(2).forEach(e=>r=r.or(e)),r}();function Al(r){if(!Is(r))throw new Error("invalid ip address");return ho(r)}function Ud(r){let e=Bl(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!Is(e))throw new Error("invalid ip address");return e}function xo(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function Sl(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function mo(r){let e=q(r),t=Uint8Array.from(Ye(e.length));return xe([t,e],t.length+e.length)}function yo(r){let e=Ft(r);if(r=r.slice(_e(e)),r.length!==e)throw new Error("inconsistent lengths");return V(r)}function Pd(r){let e;r[0]==="Q"||r[0]==="1"?e=Dt(oe.decode(`z${r}`)).bytes:e=Ue.parse(r).multihash.bytes;let t=Uint8Array.from(Ye(e.length));return xe([t,e],t.length+e.length)}function Dd(r){let e=Ld.decode(r),t=Uint8Array.from(Ye(e.length));return xe([t,e],t.length+e.length)}function Vd(r){let e=Ft(r),t=r.slice(_e(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+V(t,"base64url")}function Od(r){let e=Ft(r),t=r.slice(_e(e));if(t.length!==e)throw new Error("inconsistent lengths");return V(t,"base58btc")}function Md(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=Me.decode("b"+e[0]),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let s=xo(n);return xe([t,s],t.length+s.length)}function Hd(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let t=Me.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let s=xo(n);return xe([t,s],t.length+s.length)}function kl(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=V(e,"base32"),s=Sl(t);return`${n}:${s}`}function Il(r){r=vo(r);let e=[],t=[],n=null,s=r.split("/").slice(1);if(s.length===1&&s[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let i=0;i<s.length;i++){let o=s[i],a=j(o);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(i++,i>=s.length)throw Nl("invalid address: "+r);if(a.path===!0){n=vo(s.slice(i).join("/")),e.push([a.code,wo(a.code,n)]),t.push([a.code,n]);break}let c=wo(a.code,s[i]);e.push([a.code,c]),t.push([a.code,bo(a.code,c)])}return{string:Rl(t),bytes:Bo(e),tuples:e,stringTuples:t,path:n}}function Eo(r){let e=[],t=[],n=null,s=0;for(;s<r.length;){let i=Ft(r,s),o=_e(i),a=j(i),c=Kd(a,r.slice(s+o));if(c===0){e.push([i]),t.push([i]),s+=o;continue}let f=r.slice(s+o,s+o+c);if(s+=c+o,s>r.length)throw Nl("Invalid address Uint8Array: "+V(r,"base16"));e.push([i,f]);let u=bo(i,f);if(t.push([i,u]),a.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:Rl(t),tuples:e,stringTuples:t,path:n}}function Rl(r){let e=[];return r.map(t=>{let n=j(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),vo(e.join("/"))}function Bo(r){return xe(r.map(e=>{let t=j(e[0]),n=Uint8Array.from(Ye(t.code));return e.length>1&&e[1]!=null&&(n=xe([n,e[1]])),n}))}function Kd(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=Ft(e instanceof Uint8Array?e:Uint8Array.from(e));return t+_e(t)}}function vo(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function Nl(r){return new Error("Error parsing address: "+r)}var Fd=Symbol.for("nodejs.util.inspect.custom"),Ao=Symbol.for("@multiformats/js-multiaddr/multiaddr"),qd=[j("dns").code,j("dns4").code,j("dns6").code,j("dnsaddr").code],Rs=class r{bytes;#e;#t;#i;#a;[Ao]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=Eo(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=Il(e)}else if(Ns(e))t=Eo(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#i=t.stringTuples,this.#a=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,s,i="",o=j("tcp"),a=j("udp"),c=j("ip4"),f=j("ip6"),u=j("dns6"),l=j("ip6zone");for(let[y,g]of this.stringTuples())y===l.code&&(i=`%${g??""}`),qd.includes(y)&&(t=o.name,s=443,n=`${g??""}${i}`,e=y===u.code?6:4),(y===o.code||y===a.code)&&(t=j(y).name,s=parseInt(g??"")),(y===c.code||y===f.code)&&(t=j(y).name,n=`${g??""}${i}`,e=y===f.code?6:4);if(e==null||t==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:e,host:n,transport:t,port:s}}protos(){return this.#t.map(([e])=>Object.assign({},j(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>j(e).name)}tuples(){return this.#t}stringTuples(){return this.#i}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),s=n.lastIndexOf(t);if(s<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,s))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(Bo(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,s])=>{n===kr.p2p.code&&e.push([n,s]),n===kr["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?V(oe.decode(`z${n}`),"base58btc"):V(Ue.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#a}equals(e){return ee(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(i=>i.resolvable);if(t==null)return[this];let n=Tl.get(t.name);if(n==null)throw new N(`no available resolver for ${t.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,e)).map(i=>gt(i))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[Fd](){return`Multiaddr(${this.#e})`}};var Tl=new Map;function Ns(r){return!!r?.[Ao]}function gt(r){return new Rs(r)}var _l="libp2p-peer-record",Cl=Uint8Array.from([3,1]);var an;(function(r){let e;(function(n){let s;n.codec=()=>(s==null&&(s=Ae((i,o,a={})=>{a.lengthDelimited!==!1&&o.fork(),i.multiaddr!=null&&i.multiaddr.byteLength>0&&(o.uint32(10),o.bytes(i.multiaddr)),a.lengthDelimited!==!1&&o.ldelim()},(i,o)=>{let a={multiaddr:new Uint8Array(0)},c=o==null?i.len:i.pos+o;for(;i.pos<c;){let f=i.uint32();switch(f>>>3){case 1:a.multiaddr=i.bytes();break;default:i.skipType(f&7);break}}return a})),s),n.encode=i=>Be(i,n.codec()),n.decode=i=>Ee(i,n.codec())})(e=r.AddressInfo||(r.AddressInfo={}));let t;r.codec=()=>(t==null&&(t=Ae((n,s,i={})=>{if(i.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 o of n.addresses)s.uint32(26),r.AddressInfo.codec().encode(o,s);i.lengthDelimited!==!1&&s.ldelim()},(n,s)=>{let i={peerId:new Uint8Array(0),seq:0n,addresses:[]},o=s==null?n.len:n.pos+s;for(;n.pos<o;){let a=n.uint32();switch(a>>>3){case 1:i.peerId=n.bytes();break;case 2:i.seq=n.uint64();break;case 3:i.addresses.push(r.AddressInfo.codec().decode(n,n.uint32()));break;default:n.skipType(a&7);break}}return i})),t),r.encode=n=>Be(n,r.codec()),r.decode=n=>Ee(n,r.codec())})(an||(an={}));var Qt=class r{static createFromProtobuf=e=>{let t=an.decode(e),n=sn(t.peerId),s=(t.addresses??[]).map(o=>gt(o.multiaddr)),i=t.seq;return new r({peerId:n,multiaddrs:s,seqNumber:i})};static DOMAIN=_l;static CODEC=Cl;peerId;multiaddrs;seqNumber;domain=r.DOMAIN;codec=r.CODEC;marshaled;constructor(e){let{peerId:t,multiaddrs:n,seqNumber:s}=e;this.peerId=t,this.multiaddrs=n??[],this.seqNumber=s??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=an.encode({peerId:this.peerId.toBytes(),seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(e=>({multiaddr:e.bytes}))})),this.marshaled}equals(e){return!(!(e instanceof r)||!this.peerId.equals(e.peerId)||this.seqNumber!==e.seqNumber||!ml(this.multiaddrs,e.multiaddrs))}};function $d(r){return r[Symbol.asyncIterator]!=null}function zd(r){if($d(r))return(async()=>{let t=[];for await(let n of r)t.push(n);return t})();let e=[];for(let t of r)e.push(t);return e}var Ll=zd;function ko(r,e){let t={[Symbol.iterator]:()=>t,next:()=>{let n=r.next(),s=n.value;return n.done===!0||s==null?{done:!0,value:void 0}:{done:!1,value:e(s)}}};return t}var cn=class{map;constructor(e){if(this.map=new Map,e!=null)for(let[t,n]of e.entries())this.map.set(t.toString(),n)}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(e){return this.map.delete(e.toString())}entries(){return ko(this.map.entries(),e=>[nn(e[0]),e[1]])}forEach(e){this.map.forEach((t,n)=>{e(t,nn(n),this)})}get(e){return this.map.get(e.toString())}has(e){return this.map.has(e.toString())}set(e,t){this.map.set(e.toString(),t)}keys(){return ko(this.map.keys(),e=>nn(e))}values(){return this.map.values()}get size(){return this.map.size}};var Io=Zo(Pl(),1);var un=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Ro=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Dl=r=>globalThis.DOMException===void 0?new Ro(r):new DOMException(r),Vl=r=>{let e=r.reason===void 0?Dl("This operation was aborted."):r.reason;return e instanceof Error?e:Dl(e)};function fn(r,e){let{milliseconds:t,fallback:n,message:s,customTimers:i={setTimeout,clearTimeout}}=e,o,c=new Promise((f,u)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:d}=e;d.aborted&&u(Vl(d)),d.addEventListener("abort",()=>{u(Vl(d))})}if(t===Number.POSITIVE_INFINITY){r.then(f,u);return}let l=new un;o=i.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(d){u(d)}return}typeof r.cancel=="function"&&r.cancel(),s===!1?f():s instanceof Error?u(s):(l.message=s??`Promise timed out after ${t} milliseconds`,u(l))},t),(async()=>{try{f(await r)}catch(d){u(d)}})()}).finally(()=>{c.clear()});return c.clear=()=>{i.clearTimeout.call(void 0,o),o=void 0},c}function No(r,e,t){let n=0,s=r.length;for(;s>0;){let i=Math.trunc(s/2),o=n+i;t(r[o],e)<=0?(n=++o,s-=i+1):s=i}return n}var hn=class{#e=[];enqueue(e,t){t={priority:0,...t};let n={priority:t.priority,run:e};if(this.size&&this.#e[this.size-1].priority>=t.priority){this.#e.push(n);return}let s=No(this.#e,n,(i,o)=>o.priority-i.priority);this.#e.splice(s,0,n)}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(t=>t.priority===e.priority).map(t=>t.run)}get size(){return this.#e.length}};var Sr=class extends Io.default{#e;#t;#i=0;#a;#c;#p=0;#n;#l;#r;#g;#s=0;#u;#o;#m;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:hn,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);this.#e=e.carryoverConcurrencyCount,this.#t=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#a=e.intervalCap,this.#c=e.interval,this.#r=new e.queueClass,this.#g=e.queueClass,this.concurrency=e.concurrency,this.timeout=e.timeout,this.#m=e.throwOnTimeout===!0,this.#o=e.autoStart===!1}get#w(){return this.#t||this.#i<this.#a}get#x(){return this.#s<this.#u}#v(){this.#s--,this.#f(),this.emit("next")}#E(){this.#b(),this.#y(),this.#l=void 0}get#B(){let e=Date.now();if(this.#n===void 0){let t=this.#p-e;if(t<0)this.#i=this.#e?this.#s:0;else return this.#l===void 0&&(this.#l=setTimeout(()=>{this.#E()},t)),!0}return!1}#f(){if(this.#r.size===0)return this.#n&&clearInterval(this.#n),this.#n=void 0,this.emit("empty"),this.#s===0&&this.emit("idle"),!1;if(!this.#o){let e=!this.#B;if(this.#w&&this.#x){let t=this.#r.dequeue();return t?(this.emit("active"),t(),e&&this.#y(),!0):!1}}return!1}#y(){this.#t||this.#n!==void 0||(this.#n=setInterval(()=>{this.#b()},this.#c),this.#p=Date.now()+this.#c)}#b(){this.#i===0&&this.#s===0&&this.#n&&(clearInterval(this.#n),this.#n=void 0),this.#i=this.#e?this.#s:0,this.#h()}#h(){for(;this.#f(););}get concurrency(){return this.#u}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#u=e,this.#h()}async#A(e){return new Promise((t,n)=>{e.addEventListener("abort",()=>{n(e.reason)},{once:!0})})}async add(e,t={}){return t={timeout:this.timeout,throwOnTimeout:this.#m,...t},new Promise((n,s)=>{this.#r.enqueue(async()=>{this.#s++,this.#i++;try{t.signal?.throwIfAborted();let i=e({signal:t.signal});t.timeout&&(i=fn(Promise.resolve(i),{milliseconds:t.timeout})),t.signal&&(i=Promise.race([i,this.#A(t.signal)]));let o=await i;n(o),this.emit("completed",o)}catch(i){if(i instanceof un&&!t.throwOnTimeout){n();return}s(i),this.emit("error",i)}finally{this.#v()}},t),this.emit("add"),this.#f()})}async addAll(e,t){return Promise.all(e.map(async n=>this.add(n,t)))}start(){return this.#o?(this.#o=!1,this.#h(),this):this}pause(){this.#o=!0}clear(){this.#r=new this.#g}async onEmpty(){this.#r.size!==0&&await this.#d("empty")}async onSizeLessThan(e){this.#r.size<e||await this.#d("next",()=>this.#r.size<e)}async onIdle(){this.#s===0&&this.#r.size===0||await this.#d("idle")}async#d(e,t){return new Promise(n=>{let s=()=>{t&&!t()||(this.off(e,s),n())};this.on(e,s)})}get size(){return this.#r.size}sizeBy(e){return this.#r.filter(e).length}get pending(){return this.#s}get isPaused(){return this.#o}};var Lt={},Ir=r=>{r.addEventListener("message",e=>{Ir.dispatchEvent("message",r,e)}),r.port!=null&&r.port.addEventListener("message",e=>{Ir.dispatchEvent("message",r,e)})};Ir.addEventListener=(r,e)=>{Lt[r]==null&&(Lt[r]=[]),Lt[r].push(e)};Ir.removeEventListener=(r,e)=>{Lt[r]!=null&&(Lt[r]=Lt[r].filter(t=>t===e))};Ir.dispatchEvent=function(r,e,t){Lt[r]!=null&&Lt[r].forEach(n=>n(e,t))};var To=Ir;var _o="lock:worker:request-read",Co="lock:worker:release-read",Lo="lock:master:grant-read",Uo="lock:worker:request-write",Po="lock:worker:release-write",Do="lock:master:grant-write";var Ol=(r=21)=>Math.random().toString().substring(2);var Ml=(r,e,t,n,s)=>(i,o)=>{if(o.data.type!==t)return;let a={type:o.data.type,name:o.data.name,identifier:o.data.identifier};r.dispatchEvent(new MessageEvent(e,{data:{name:a.name,handler:async()=>{i.postMessage({type:s,name:a.name,identifier:a.identifier}),await new Promise(c=>{let f=u=>{if(u==null||u.data==null)return;let l={type:u.data.type,name:u.data.name,identifier:u.data.identifier};l.type===n&&l.identifier===a.identifier&&(i.removeEventListener("message",f),c())};i.addEventListener("message",f)})}}}))},Hl=(r,e,t,n)=>async()=>{let s=Ol();return globalThis.postMessage({type:e,identifier:s,name:r}),new Promise(i=>{let o=a=>{if(a==null||a.data==null)return;let c={type:a.data.type,identifier:a.data.identifier};c.type===t&&c.identifier===s&&(globalThis.removeEventListener("message",o),i(()=>{globalThis.postMessage({type:n,identifier:s,name:r})}))};globalThis.addEventListener("message",o)})},Wd={singleProcess:!1},Kl=r=>{if(r=Object.assign({},Wd,r),!!globalThis.document||r.singleProcess){let t=new EventTarget;return To.addEventListener("message",Ml(t,"requestReadLock",_o,Co,Lo)),To.addEventListener("message",Ml(t,"requestWriteLock",Uo,Po,Do)),t}return{isWorker:!0,readLock:t=>Hl(t,_o,Lo,Co),writeLock:t=>Hl(t,Uo,Do,Po)}};var er={},Ut;async function Vo(r,e){let t,n=new Promise(s=>{t=s});return r.add(async()=>fn((async()=>{await new Promise(s=>{t(()=>{s()})})})(),{milliseconds:e.timeout})),n}var Yd=(r,e)=>{if(Ut.isWorker===!0)return{readLock:Ut.readLock(r,e),writeLock:Ut.writeLock(r,e)};let t=new Sr({concurrency:1}),n;return{async readLock(){if(n!=null)return Vo(n,e);n=new Sr({concurrency:e.concurrency,autoStart:!1});let s=n,i=Vo(n,e);return t.add(async()=>{s.start(),await s.onIdle().then(()=>{n===s&&(n=null)})}),i},async writeLock(){return n=null,Vo(t,e)}}},Zd={name:"lock",concurrency:1/0,timeout:846e5,singleProcess:!1};function Oo(r){let e=Object.assign({},Zd,r);return Ut==null&&(Ut=Kl(e),Ut.isWorker!==!0&&(Ut.addEventListener("requestReadLock",t=>{er[t.data.name]!=null&&er[t.data.name].readLock().then(async n=>t.data.handler().finally(()=>{n()}))}),Ut.addEventListener("requestWriteLock",async t=>{er[t.data.name]!=null&&er[t.data.name].writeLock().then(async n=>t.data.handler().finally(()=>{n()}))}))),er[e.name]==null&&(er[e.name]=Yd(e.name,e)),er[e.name]}var ge={ERR_INVALID_PARAMETERS:"ERR_INVALID_PARAMETERS"};var Rr;(function(r){let e;(function(s){let i;s.codec=()=>(i==null&&(i=Ae((o,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),o.key!=null&&o.key!==""&&(a.uint32(10),a.string(o.key)),o.value!=null&&o.value.byteLength>0&&(a.uint32(18),a.bytes(o.value)),c.lengthDelimited!==!1&&a.ldelim()},(o,a)=>{let c={key:"",value:new Uint8Array(0)},f=a==null?o.len:o.pos+a;for(;o.pos<f;){let u=o.uint32();switch(u>>>3){case 1:c.key=o.string();break;case 2:c.value=o.bytes();break;default:o.skipType(u&7);break}}return c})),i),s.encode=o=>Be(o,s.codec()),s.decode=o=>Ee(o,s.codec())})(e=r.Peer$metadataEntry||(r.Peer$metadataEntry={}));let t;(function(s){let i;s.codec=()=>(i==null&&(i=Ae((o,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),o.key!=null&&o.key!==""&&(a.uint32(10),a.string(o.key)),o.value!=null&&(a.uint32(18),Cs.codec().encode(o.value,a)),c.lengthDelimited!==!1&&a.ldelim()},(o,a)=>{let c={key:""},f=a==null?o.len:o.pos+a;for(;o.pos<f;){let u=o.uint32();switch(u>>>3){case 1:c.key=o.string();break;case 2:c.value=Cs.codec().decode(o,o.uint32());break;default:o.skipType(u&7);break}}return c})),i),s.encode=o=>Be(o,s.codec()),s.decode=o=>Ee(o,s.codec())})(t=r.Peer$tagsEntry||(r.Peer$tagsEntry={}));let n;r.codec=()=>(n==null&&(n=Ae((s,i,o={})=>{if(o.lengthDelimited!==!1&&i.fork(),s.addresses!=null)for(let a of s.addresses)i.uint32(10),_s.codec().encode(a,i);if(s.protocols!=null)for(let a of s.protocols)i.uint32(18),i.string(a);if(s.publicKey!=null&&(i.uint32(34),i.bytes(s.publicKey)),s.peerRecordEnvelope!=null&&(i.uint32(42),i.bytes(s.peerRecordEnvelope)),s.metadata!=null&&s.metadata.size!==0)for(let[a,c]of s.metadata.entries())i.uint32(50),r.Peer$metadataEntry.codec().encode({key:a,value:c},i);if(s.tags!=null&&s.tags.size!==0)for(let[a,c]of s.tags.entries())i.uint32(58),r.Peer$tagsEntry.codec().encode({key:a,value:c},i);o.lengthDelimited!==!1&&i.ldelim()},(s,i)=>{let o={addresses:[],protocols:[],metadata:new Map,tags:new Map},a=i==null?s.len:s.pos+i;for(;s.pos<a;){let c=s.uint32();switch(c>>>3){case 1:o.addresses.push(_s.codec().decode(s,s.uint32()));break;case 2:o.protocols.push(s.string());break;case 4:o.publicKey=s.bytes();break;case 5:o.peerRecordEnvelope=s.bytes();break;case 6:{let f=r.Peer$metadataEntry.codec().decode(s,s.uint32());o.metadata.set(f.key,f.value);break}case 7:{let f=r.Peer$tagsEntry.codec().decode(s,s.uint32());o.tags.set(f.key,f.value);break}default:s.skipType(c&7);break}}return o})),n),r.encode=s=>Be(s,r.codec()),r.decode=s=>Ee(s,r.codec())})(Rr||(Rr={}));var _s;(function(r){let e;r.codec=()=>(e==null&&(e=Ae((t,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),t.multiaddr!=null&&t.multiaddr.byteLength>0&&(n.uint32(10),n.bytes(t.multiaddr)),t.isCertified!=null&&(n.uint32(16),n.bool(t.isCertified)),s.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let s={multiaddr:new Uint8Array(0)},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let o=t.uint32();switch(o>>>3){case 1:s.multiaddr=t.bytes();break;case 2:s.isCertified=t.bool();break;default:t.skipType(o&7);break}}return s})),e),r.encode=t=>Be(t,r.codec()),r.decode=t=>Ee(t,r.codec())})(_s||(_s={}));var Cs;(function(r){let e;r.codec=()=>(e==null&&(e=Ae((t,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),t.value!=null&&t.value!==0&&(n.uint32(8),n.uint32(t.value)),t.expiry!=null&&(n.uint32(16),n.uint64(t.expiry)),s.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let s={value:0},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let o=t.uint32();switch(o>>>3){case 1:s.value=t.uint32();break;case 2:s.expiry=t.uint64();break;default:t.skipType(o&7);break}}return s})),e),r.encode=t=>Be(t,r.codec()),r.decode=t=>Ee(t,r.codec())})(Cs||(Cs={}));function Nr(r,e){let t=Rr.decode(e);t.publicKey!=null&&r.publicKey==null&&(r=ul({...r,publicKey:r.publicKey}));let n=new Map,s=BigInt(Date.now());for(let[i,o]of t.tags.entries())o.expiry!=null&&o.expiry<s||n.set(i,o);return{...t,id:r,addresses:t.addresses.map(({multiaddr:i,isCertified:o})=>({multiaddr:gt(i),isCertified:o??!1})),metadata:t.metadata,peerRecordEnvelope:t.peerRecordEnvelope??void 0,tags:n}}var mt="/",Fl=new TextEncoder().encode(mt),Ls=Fl[0],Us=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=q(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(t==null&&(t=!0),t&&this.clean(),this._buf.byteLength===0||this._buf[0]!==Ls)throw new Error("Invalid key")}toString(e="utf8"){return V(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new r(e.join(mt))}static random(){return new r(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new r(e):typeof e.uint8Array=="function"?new r(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=Fl),this._buf[0]!==Ls){let e=new Uint8Array(this._buf.byteLength+1);e.fill(Ls,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Ls;)this._buf=this._buf.subarray(0,-1)}less(e){let t=this.list(),n=e.list();for(let s=0;s<t.length;s++){if(n.length<s+1)return!1;let i=t[s],o=n[s];if(i<o)return!0;if(i>o)return!1}return t.length<n.length}reverse(){return r.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(mt).slice(1)}type(){return Jd(this.baseNamespace())}name(){return Xd(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(mt)||(e+=mt),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(mt):new r(e.slice(0,-1).join(mt))}child(e){return this.toString()===mt?e:e.toString()===mt?this:new r(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()===this.toString()?!1:e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()===this.toString()?!1:this.toString().startsWith(e.toString())}isTopLevel(){return this.list().length===1}concat(...e){return r.withNamespaces([...this.namespaces(),...Qd(e.map(t=>t.namespaces()))])}};function Jd(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function Xd(r){let e=r.split(":");return e[e.length-1]}function Qd(r){return[].concat(...r)}var Mo="/peers/";function Tr(r){if(!Jo(r)||r.type==null)throw new N("Invalid PeerId",ge.ERR_INVALID_PARAMETERS);let e=r.toCID().toString();return new Us(`${Mo}${e}`)}async function ql(r,e,t){let n=new Map;for(let s of t){if(s==null)continue;if(s.multiaddr instanceof Uint8Array&&(s.multiaddr=gt(s.multiaddr)),!Ns(s.multiaddr))throw new N("Multiaddr was invalid",ge.ERR_INVALID_PARAMETERS);if(!await e(r,s.multiaddr))continue;let i=s.isCertified??!1,o=s.multiaddr.toString(),a=n.get(o);a!=null?s.isCertified=a.isCertified||i:n.set(o,{multiaddr:s.multiaddr,isCertified:i})}return[...n.values()].sort((s,i)=>s.multiaddr.toString().localeCompare(i.multiaddr.toString())).map(({isCertified:s,multiaddr:i})=>({isCertified:s,multiaddr:i.bytes}))}async function Ds(r,e,t,n){if(e==null)throw new N("Invalid PeerData",ge.ERR_INVALID_PARAMETERS);if(e.publicKey!=null&&r.publicKey!=null&&!ee(e.publicKey,r.publicKey))throw new N("publicKey bytes do not match peer id publicKey bytes",ge.ERR_INVALID_PARAMETERS);let s=n.existingPeer;if(s!=null&&!r.equals(s.id))throw new N("peer id did not match existing peer id",ge.ERR_INVALID_PARAMETERS);let i=s?.addresses??[],o=new Set(s?.protocols??[]),a=s?.metadata??new Map,c=s?.tags??new Map,f=s?.peerRecordEnvelope;if(t==="patch"){if((e.multiaddrs!=null||e.addresses!=null)&&(i=[],e.multiaddrs!=null&&i.push(...e.multiaddrs.map(l=>({isCertified:!1,multiaddr:l}))),e.addresses!=null&&i.push(...e.addresses)),e.protocols!=null&&(o=new Set(e.protocols)),e.metadata!=null){let l=e.metadata instanceof Map?[...e.metadata.entries()]:Object.entries(e.metadata);a=Ps(l,{validate:$l})}if(e.tags!=null){let l=e.tags instanceof Map?[...e.tags.entries()]:Object.entries(e.tags);c=Ps(l,{validate:zl,map:Gl})}e.peerRecordEnvelope!=null&&(f=e.peerRecordEnvelope)}if(t==="merge"){if(e.multiaddrs!=null&&i.push(...e.multiaddrs.map(l=>({isCertified:!1,multiaddr:l}))),e.addresses!=null&&i.push(...e.addresses),e.protocols!=null&&(o=new Set([...o,...e.protocols])),e.metadata!=null){let l=e.metadata instanceof Map?[...e.metadata.entries()]:Object.entries(e.metadata);for(let[d,y]of l)y==null?a.delete(d):a.set(d,y);a=Ps([...a.entries()],{validate:$l})}if(e.tags!=null){let l=e.tags instanceof Map?[...e.tags.entries()]:Object.entries(e.tags),d=new Map(c);for(let[y,g]of l)g==null?d.delete(y):d.set(y,g);c=Ps([...d.entries()],{validate:zl,map:Gl})}e.peerRecordEnvelope!=null&&(f=e.peerRecordEnvelope)}let u={addresses:await ql(r,n.addressFilter??(async()=>!0),i),protocols:[...o.values()].sort((l,d)=>l.localeCompare(d)),metadata:a,tags:c,publicKey:s?.id.publicKey??e.publicKey??r.publicKey,peerRecordEnvelope:f};return r.type!=="RSA"&&delete u.publicKey,u}function Ps(r,e){let t=new Map;for(let[n,s]of r)s!=null&&e.validate(n,s);for(let[n,s]of r.sort(([i],[o])=>i.localeCompare(o)))s!=null&&t.set(n,e.map?.(n,s)??s);return t}function $l(r,e){if(typeof r!="string")throw new N("Metadata key must be a string",ge.ERR_INVALID_PARAMETERS);if(!(e instanceof Uint8Array))throw new N("Metadata value must be a Uint8Array",ge.ERR_INVALID_PARAMETERS)}function zl(r,e){if(typeof r!="string")throw new N("Tag name must be a string",ge.ERR_INVALID_PARAMETERS);if(e.value!=null){if(parseInt(`${e.value}`,10)!==e.value)throw new N("Tag value must be an integer",ge.ERR_INVALID_PARAMETERS);if(e.value<0||e.value>100)throw new N("Tag value must be between 0-100",ge.ERR_INVALID_PARAMETERS)}if(e.ttl!=null){if(parseInt(`${e.ttl}`,10)!==e.ttl)throw new N("Tag ttl must be an integer",ge.ERR_INVALID_PARAMETERS);if(e.ttl<0)throw new N("Tag ttl must be between greater than 0",ge.ERR_INVALID_PARAMETERS)}}function Gl(r,e){let t;return e.expiry!=null&&(t=e.expiry),e.ttl!=null&&(t=BigInt(Date.now()+Number(e.ttl))),{value:e.value??0,expiry:t}}function Vs(r,e,t){let n=r.toString().split("/")[2],s=Me.decode(n),i=sn(s),o=t.get(i);if(o!=null)return o;let a=Nr(i,e);return t.set(i,a),a}function e0(r,e){return r==null?{}:{prefix:Mo,filters:(r.filters??[]).map(t=>({key:n,value:s})=>t(Vs(n,s,e))),orders:(r.orders??[]).map(t=>(n,s)=>t(Vs(n.key,n.value,e),Vs(s.key,s.value,e)))}}var Os=class{peerId;datastore;lock;addressFilter;constructor(e,t={}){this.peerId=e.peerId,this.datastore=e.datastore,this.addressFilter=t.addressFilter,this.lock=Oo({name:"peer-store",singleProcess:!0})}async has(e){return this.datastore.has(Tr(e))}async delete(e){if(this.peerId.equals(e))throw new N("Cannot delete self peer",ge.ERR_INVALID_PARAMETERS);await this.datastore.delete(Tr(e))}async load(e){let t=await this.datastore.get(Tr(e));return Nr(e,t)}async save(e,t){let{existingBuf:n,existingPeer:s}=await this.#e(e),i=await Ds(e,t,"patch",{addressFilter:this.addressFilter});return this.#t(e,i,n,s)}async patch(e,t){let{existingBuf:n,existingPeer:s}=await this.#e(e),i=await Ds(e,t,"patch",{addressFilter:this.addressFilter,existingPeer:s});return this.#t(e,i,n,s)}async merge(e,t){let{existingBuf:n,existingPeer:s}=await this.#e(e),i=await Ds(e,t,"merge",{addressFilter:this.addressFilter,existingPeer:s});return this.#t(e,i,n,s)}async*all(e){let t=new cn;for await(let{key:n,value:s}of this.datastore.query(e0(e??{},t))){let i=Vs(n,s,t);i.id.equals(this.peerId)||(yield i)}}async#e(e){try{let t=await this.datastore.get(Tr(e)),n=Nr(e,t);return{existingBuf:t,existingPeer:n}}catch(t){if(t.code!=="ERR_NOT_FOUND")throw t}return{}}async#t(e,t,n,s){let i=Rr.encode(t);return n!=null&&ee(i,n)?{peer:Nr(e,i),previous:s,updated:!1}:(await this.datastore.put(Tr(e),i),{peer:Nr(e,i),previous:s,updated:!0})}};var Ho=class{store;events;peerId;log;constructor(e,t={}){this.log=e.logger.forComponent("libp2p:peer-store"),this.events=e.events,this.peerId=e.peerId,this.store=new Os(e,t)}[Symbol.toStringTag]="@libp2p/peer-store";async forEach(e,t){this.log.trace("forEach await read lock");let n=await this.store.lock.readLock();this.log.trace("forEach got read lock");try{for await(let s of this.store.all(t))e(s)}finally{this.log.trace("forEach release read lock"),n()}}async all(e){this.log.trace("all await read lock");let t=await this.store.lock.readLock();this.log.trace("all got read lock");try{return await Ll(this.store.all(e))}finally{this.log.trace("all release read lock"),t()}}async delete(e){this.log.trace("delete await write lock");let t=await this.store.lock.writeLock();this.log.trace("delete got write lock");try{await this.store.delete(e)}finally{this.log.trace("delete release write lock"),t()}}async has(e){this.log.trace("has await read lock");let t=await this.store.lock.readLock();this.log.trace("has got read lock");try{return await this.store.has(e)}finally{this.log.trace("has release read lock"),t()}}async get(e){this.log.trace("get await read lock");let t=await this.store.lock.readLock();this.log.trace("get got read lock");try{return await this.store.load(e)}finally{this.log.trace("get release read lock"),t()}}async save(e,t){this.log.trace("save await write lock");let n=await this.store.lock.writeLock();this.log.trace("save got write lock");try{let s=await this.store.save(e,t);return this.#e(e,s),s.peer}finally{this.log.trace("save release write lock"),n()}}async patch(e,t){this.log.trace("patch await write lock");let n=await this.store.lock.writeLock();this.log.trace("patch got write lock");try{let s=await this.store.patch(e,t);return this.#e(e,s),s.peer}finally{this.log.trace("patch release write lock"),n()}}async merge(e,t){this.log.trace("merge await write lock");let n=await this.store.lock.writeLock();this.log.trace("merge got write lock");try{let s=await this.store.merge(e,t);return this.#e(e,s),s.peer}finally{this.log.trace("merge release write lock"),n()}}async consumePeerRecord(e,t){let n=await Br.openAndCertify(e,Qt.DOMAIN);if(t?.equals(n.peerId)===!1)return this.log("envelope peer id was not the expected peer id - expected: %p received: %p",t,n.peerId),!1;let s=Qt.createFromProtobuf(n.payload),i;try{i=await this.get(n.peerId)}catch(o){if(o.code!=="ERR_NOT_FOUND")throw o}if(i?.peerRecordEnvelope!=null){let o=await Br.createFromProtobuf(i.peerRecordEnvelope),a=Qt.createFromProtobuf(o.payload);if(a.seqNumber>=s.seqNumber)return this.log("sequence number was lower or equal to existing sequence number - stored: %d received: %d",a.seqNumber,s.seqNumber),!1}return await this.patch(s.peerId,{peerRecordEnvelope:e,addresses:s.multiaddrs.map(o=>({isCertified:!0,multiaddr:o}))}),!0}#e(e,t){t.updated&&(this.peerId.equals(e)?this.events.safeDispatchEvent("self:peer:update",{detail:t}):this.events.safeDispatchEvent("peer:update",{detail:t}))}};return iu(t0);})();
|
|
8
8
|
/*! Bundled license information:
|
|
9
9
|
|
|
10
10
|
pvtsutils/build/index.js:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/peer-store",
|
|
3
|
-
"version": "10.1.
|
|
3
|
+
"version": "10.1.5",
|
|
4
4
|
"description": "Stores information about peers libp2p knows on the network",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/peer-store#readme",
|
|
@@ -59,10 +59,10 @@
|
|
|
59
59
|
"test:electron-main": "aegir test -t electron-main"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@libp2p/interface": "^1.
|
|
63
|
-
"@libp2p/peer-collections": "^5.2.
|
|
64
|
-
"@libp2p/peer-id": "^4.2.
|
|
65
|
-
"@libp2p/peer-record": "^7.0.
|
|
62
|
+
"@libp2p/interface": "^1.7.0",
|
|
63
|
+
"@libp2p/peer-collections": "^5.2.9",
|
|
64
|
+
"@libp2p/peer-id": "^4.2.4",
|
|
65
|
+
"@libp2p/peer-record": "^7.0.25",
|
|
66
66
|
"@multiformats/multiaddr": "^12.2.3",
|
|
67
67
|
"interface-datastore": "^8.2.11",
|
|
68
68
|
"it-all": "^3.0.6",
|
|
@@ -73,8 +73,8 @@
|
|
|
73
73
|
"uint8arrays": "^5.1.0"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
|
-
"@libp2p/logger": "^4.0.
|
|
77
|
-
"@libp2p/peer-id-factory": "^4.2.
|
|
76
|
+
"@libp2p/logger": "^4.0.20",
|
|
77
|
+
"@libp2p/peer-id-factory": "^4.2.4",
|
|
78
78
|
"@types/sinon": "^17.0.3",
|
|
79
79
|
"aegir": "^44.0.1",
|
|
80
80
|
"datastore-core": "^9.2.9",
|