@libp2p/peer-store 10.1.5-1675adee2 → 10.1.5-2265e59ba
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 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(`
|
|
2
|
+
"use strict";var Libp2PPeerStore=(()=>{var nu=Object.create;var yn=Object.defineProperty;var su=Object.getOwnPropertyDescriptor;var iu=Object.getOwnPropertyNames;var ou=Object.getPrototypeOf,au=Object.prototype.hasOwnProperty;var Jo=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),ue=(r,e)=>{for(var t in e)yn(r,t,{get:e[t],enumerable:!0})},Xo=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of iu(e))!au.call(r,s)&&s!==t&&yn(r,s,{get:()=>e[s],enumerable:!(n=su(e,s))||n.enumerable});return r};var Qo=(r,e,t)=>(t=r!=null?nu(ou(r)):{},Xo(e||!r||!r.__esModule?yn(t,"default",{value:r,enumerable:!0}):t,r)),cu=r=>Xo(yn({},"__esModule",{value:!0}),r);var ec=Jo(vr=>{"use strict";var Hh="[object ArrayBuffer]",ut=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===Hh}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}},Yi="string",Kh=/^[0-9a-f]+$/i,Fh=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,qh=/^[a-zA-Z0-9-_]+$/,Dn=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=ut.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return decodeURIComponent(escape(n))}},Oe=class{static toString(e,t=!1){let n=ut.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}},Vn=class r{static isHex(e){return typeof e===Yi&&Kh.test(e)}static isBase64(e){return typeof e===Yi&&Fh.test(e)}static isBase64Url(e){return typeof e===Yi&&qh.test(e)}static ToString(e,t="utf8"){let n=ut.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 Oe.toString(n,!0);case"utf16":case"utf16be":return Oe.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 Oe.fromString(e,!0);case"utf16":case"utf16be":return Oe.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=ut.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 Dn.fromString(e);case"utf16":case"utf16be":return Oe.fromString(e);case"utf16le":case"usc2":return Oe.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 Dn.toString(e);case"utf16":case"utf16be":return Oe.toString(e);case"utf16le":case"usc2":return Oe.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=ut.toUint8Array(e),n="";for(let s=0;s<t.length;s++)n+=String.fromCharCode(t[s]);return n}static ToHex(e){let t=ut.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 Oe.toString(e,t)}static FromUtf16String(e,t=!1){return Oe.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,"")||""}};Vn.DEFAULT_UTF8_ENCODING="utf8";function $h(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 zh(...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 Gh(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}vr.BufferSourceConverter=ut;vr.Convert=Vn;vr.assign=$h;vr.combine=zh;vr.isEqual=Gh});var Vl=Jo((tw,No)=>{"use strict";var Wd=Object.prototype.hasOwnProperty,Re="~";function dn(){}Object.create&&(dn.prototype=Object.create(null),new dn().__proto__||(Re=!1));function Yd(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function Dl(r,e,t,n,s){if(typeof t!="function")throw new TypeError("The listener must be a function");var i=new Yd(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 Ls(r,e){--r._eventsCount===0?r._events=new dn:delete r._events[e]}function xe(){this._events=new dn,this._eventsCount=0}xe.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)Wd.call(t,n)&&e.push(Re?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};xe.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};xe.prototype.listenerCount=function(e){var t=Re?Re+e:e,n=this._events[t];return n?n.fn?1:n.length:0};xe.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};xe.prototype.on=function(e,t,n){return Dl(this,e,t,n,!1)};xe.prototype.once=function(e,t,n){return Dl(this,e,t,n,!0)};xe.prototype.removeListener=function(e,t,n,s){var i=Re?Re+e:e;if(!this._events[i])return this;if(!t)return Ls(this,i),this;var o=this._events[i];if(o.fn)o.fn===t&&(!s||o.once)&&(!n||o.context===n)&&Ls(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:Ls(this,i)}return this};xe.prototype.removeAllListeners=function(e){var t;return e?(t=Re?Re+e:e,this._events[t]&&Ls(this,t)):(this._events=new dn,this._eventsCount=0),this};xe.prototype.off=xe.prototype.removeListener;xe.prototype.addListener=xe.prototype.on;xe.prefixed=Re;xe.EventEmitter=xe;typeof No<"u"&&(No.exports=xe)});var np={};ue(np,{PersistentPeerStore:()=>qo});var bn=Symbol.for("@libp2p/peer-id");function ea(r){return r!=null&&!!r[bn]}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 ji={};ue(ji,{Ed25519PrivateKey:()=>Yt,Ed25519PublicKey:()=>zr,generateKeyPair:()=>Vh,generateKeyPairFromSeed:()=>Qa,unmarshalEd25519PrivateKey:()=>Ph,unmarshalEd25519PublicKey:()=>Dh});var Gs={};ue(Gs,{base58btc:()=>oe,base58flickr:()=>pu});var ap=new Uint8Array(0);function ta(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 rt(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 ra(r){return new TextEncoder().encode(r)}function na(r){return new TextDecoder().decode(r)}function lu(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(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var y=0,d=0,w=0,E=x.length;w!==E&&x[w]===0;)w++,y++;for(var g=(E-w)*u+1>>>0,B=new Uint8Array(g);w!==E;){for(var C=x[w],L=0,S=g-1;(C!==0||L<d)&&S!==-1;S--,L++)C+=256*B[S]>>>0,B[S]=C%a>>>0,C=C/a>>>0;if(C!==0)throw new Error("Non-zero carry");d=L,w++}for(var I=g-d;I!==g&&B[I]===0;)I++;for(var _=c.repeat(y);I<g;++I)_+=r.charAt(B[I]);return _}function h(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var y=0;if(x[y]!==" "){for(var d=0,w=0;x[y]===c;)d++,y++;for(var E=(x.length-y)*f+1>>>0,g=new Uint8Array(E);x[y];){var B=t[x.charCodeAt(y)];if(B===255)return;for(var C=0,L=E-1;(B!==0||C<w)&&L!==-1;L--,C++)B+=a*g[L]>>>0,g[L]=B%256>>>0,B=B/256>>>0;if(B!==0)throw new Error("Non-zero carry");w=C,y++}if(x[y]!==" "){for(var S=E-w;S!==E&&g[S]===0;)S++;for(var I=new Uint8Array(d+(E-S)),_=d;S!==E;)I[_++]=g[S++];return I}}}function m(x){var y=h(x);if(y)return y;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:h,decode:m}}var uu=lu,fu=uu,ia=fu;var Fs=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")}},qs=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 oa(this,e)}},$s=class{decoders;constructor(e){this.decoders=e}or(e){return oa(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 oa(r,e){return new $s({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var zs=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 Fs(e,t,n),this.decoder=new qs(e,t,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function sr({name:r,prefix:e,encode:t,decode:n}){return new zs(r,e,t,n)}function xt({name:r,prefix:e,alphabet:t}){let{encode:n,decode:s}=ia(t,r);return sr({prefix:e,name:r,encode:n,decode:i=>rt(s(i))})}function hu(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 du(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 sr({prefix:e,name:r,encode(s){return du(s,n,t)},decode(s){return hu(s,n,t,r)}})}var oe=xt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),pu=xt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ws={};ue(Ws,{identity:()=>nt});var gu=la,aa=128,mu=127,yu=~mu,bu=Math.pow(2,31);function la(r,e,t){e=e||[],t=t||0;for(var n=t;r>=bu;)e[t++]=r&255|aa,r/=128;for(;r&yu;)e[t++]=r&255|aa,r>>>=7;return e[t]=r|0,la.bytes=t-n+1,e}var wu=js,xu=128,ca=127;function js(r,n){var t=0,n=n||0,s=0,i=n,o,a=r.length;do{if(i>=a)throw js.bytes=0,new RangeError("Could not decode varint");o=r[i++],t+=s<28?(o&ca)<<s:(o&ca)*Math.pow(2,s),s+=7}while(o>=xu);return js.bytes=i-n,t}var vu=Math.pow(2,7),Eu=Math.pow(2,14),Bu=Math.pow(2,21),Au=Math.pow(2,28),ku=Math.pow(2,35),Su=Math.pow(2,42),Iu=Math.pow(2,49),Ru=Math.pow(2,56),Nu=Math.pow(2,63),Tu=function(r){return r<vu?1:r<Eu?2:r<Bu?3:r<Au?4:r<ku?5:r<Su?6:r<Iu?7:r<Ru?8:r<Nu?9:10},_u={encode:gu,decode:wu,encodingLength:Tu},Lu=_u,Dr=Lu;function Vr(r,e=0){return[Dr.decode(r,e),Dr.decode.bytes]}function ir(r,e,t=0){return Dr.encode(r,e,t),e}function or(r){return Dr.encodingLength(r)}function je(r,e){let t=e.byteLength,n=or(r),s=n+or(t),i=new Uint8Array(s+t);return ir(r,i,0),ir(t,i,n),i.set(e,s),new ar(r,t,e,i)}function Ot(r){let e=rt(r),[t,n]=Vr(e),[s,i]=Vr(e.subarray(n)),o=e.subarray(n+i);if(o.byteLength!==s)throw new Error("Incorrect length");return new ar(t,s,o,e)}function ua(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&ta(r.bytes,t.bytes)}}var ar=class{code;size;digest;bytes;constructor(e,t,n,s){this.code=e,this.size=t,this.digest=n,this.bytes=s}};var fa=0,Cu="identity",ha=rt;function Uu(r){return je(fa,ha(r))}var nt={code:fa,name:Cu,encode:ha,digest:Uu};var Js={};ue(Js,{sha256:()=>pe,sha512:()=>Pu});function Zs({name:r,code:e,encode:t}){return new Ys(r,e,t)}var Ys=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 pa(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var pe=Zs({name:"sha2-256",code:18,encode:pa("SHA-256")}),Pu=Zs({name:"sha2-512",code:19,encode:pa("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 st(r=0){return new Uint8Array(r)}function Te(r=0){return new Uint8Array(r)}function Ee(r,e){e==null&&(e=r.reduce((s,i)=>s+i.length,0));let t=Te(e),n=0;for(let s of r)t.set(s,n),n+=s.length;return t}var Xs={};ue(Xs,{base10:()=>Du});var Du=xt({prefix:"9",name:"base10",alphabet:"0123456789"});var Qs={};ue(Qs,{base16:()=>Vu,base16upper:()=>Ou});var Vu=Q({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ou=Q({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ei={};ue(ei,{base2:()=>Mu});var Mu=Q({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ti={};ue(ti,{base256emoji:()=>$u});var ga=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}"),Hu=ga.reduce((r,e,t)=>(r[t]=e,r),[]),Ku=ga.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function Fu(r){return r.reduce((e,t)=>(e+=Hu[t],e),"")}function qu(r){let e=[];for(let t of r){let n=Ku[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var $u=sr({prefix:"\u{1F680}",name:"base256emoji",encode:Fu,decode:qu});var ri={};ue(ri,{base32:()=>Me,base32hex:()=>Wu,base32hexpad:()=>Zu,base32hexpadupper:()=>Ju,base32hexupper:()=>Yu,base32pad:()=>Gu,base32padupper:()=>ju,base32upper:()=>zu,base32z:()=>Xu});var Me=Q({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),zu=Q({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Gu=Q({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ju=Q({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Wu=Q({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Yu=Q({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Zu=Q({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ju=Q({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Xu=Q({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ni={};ue(ni,{base36:()=>Qu,base36upper:()=>ef});var Qu=xt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ef=xt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ii={};ue(ii,{base64:()=>si,base64pad:()=>tf,base64url:()=>rf,base64urlpad:()=>nf});var si=Q({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),tf=Q({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),rf=Q({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),nf=Q({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var oi={};ue(oi,{base8:()=>sf});var sf=Q({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ai={};ue(ai,{identity:()=>of});var of=sr({prefix:"\0",name:"identity",encode:r=>na(r),decode:r=>ra(r)});var Pp=new TextEncoder,Dp=new TextDecoder;function ma(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return uf(t,ci(r),e??oe.encoder);default:return ff(t,ci(r),e??Me.encoder)}}var ya=new WeakMap;function ci(r){let e=ya.get(r);if(e==null){let t=new Map;return ya.set(r,t),t}return e}var De=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!==Or)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==hf)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&&ua(e.multihash,n.multihash)}toString(e){return ma(this,e)}toJSON(){return{"/":ma(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??ba(n,s,i.bytes))}else if(t[df]===!0){let{version:n,multihash:s,code:i}=t,o=Ot(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!==Or)throw new Error(`Version 0 CID must use dag-pb (code: ${Or}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let s=ba(e,t,n.bytes);return new r(e,t,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Or,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=rt(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 ar(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]=Vr(e.subarray(t));return t+=h,l},s=n(),i=Or;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]=lf(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 ci(i).set(n,e),i}};function lf(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 uf(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 ff(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 Or=112,hf=18;function ba(r,e,t){let n=or(r),s=n+or(e),i=new Uint8Array(s+t.byteLength);return ir(r,i,0),ir(e,i,n),i.set(t,s),i}var df=Symbol.for("@ipld/js-cid/CID");var vt={...ai,...ei,...oi,...Xs,...Qs,...ri,...ni,...Gs,...ii,...ti},Xp={...Js,...Ws};function xa(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var wa=xa("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),li=xa("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=Te(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),pf={utf8:wa,"utf-8":wa,hex:vt.base16,latin1:li,ascii:li,binary:li,...vt},xn=pf;function $(r,e="utf8"){let t=xn[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function Ve(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function cr(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function gf(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function lr(r,...e){if(!gf(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 vn(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");cr(r.outputLen),cr(r.blockLen)}function ur(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 va(r,e){lr(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var Ht=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var hr=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),He=(r,e)=>r<<32-e|r>>>e;var h0=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var mf=async()=>{};async function Ea(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 mf(),n+=i)}}function Ba(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Et(r){return typeof r=="string"&&(r=Ba(r)),lr(r),r}function ui(...r){let e=0;for(let n=0;n<r.length;n++){let s=r[n];lr(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 fr=class{clone(){return this._cloneInto()}},yf={}.toString;function Aa(r,e){if(e!==void 0&&yf.call(e)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(r,e)}function En(r){let e=n=>r().update(Et(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function dr(r=32){if(Ht&&typeof Ht.getRandomValues=="function")return Ht.getRandomValues(new Uint8Array(r));if(Ht&&typeof Ht.randomBytes=="function")return Ht.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function bf(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 ka=(r,e,t)=>r&e^~r&t,Sa=(r,e,t)=>r&e^r&t^e&t,pr=class extends fr{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=hr(this.buffer)}update(e){ur(this);let{view:t,buffer:n,blockLen:s}=this;e=Et(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=hr(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){ur(this),va(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;bf(n,s-8,BigInt(this.length*8),i),this.process(n,0);let a=hr(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),fi=BigInt(32);function Ia(r,e=!1){return e?{h:Number(r&Bn),l:Number(r>>fi&Bn)}:{h:Number(r>>fi&Bn)|0,l:Number(r&Bn)|0}}function wf(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}=Ia(r[s],e);[t[s],n[s]]=[i,o]}return[t,n]}var xf=(r,e)=>BigInt(r>>>0)<<fi|BigInt(e>>>0),vf=(r,e,t)=>r>>>t,Ef=(r,e,t)=>r<<32-t|e>>>t,Bf=(r,e,t)=>r>>>t|e<<32-t,Af=(r,e,t)=>r<<32-t|e>>>t,kf=(r,e,t)=>r<<64-t|e>>>t-32,Sf=(r,e,t)=>r>>>t-32|e<<64-t,If=(r,e)=>e,Rf=(r,e)=>r,Nf=(r,e,t)=>r<<t|e>>>32-t,Tf=(r,e,t)=>e<<t|r>>>32-t,_f=(r,e,t)=>e<<t-32|r>>>64-t,Lf=(r,e,t)=>r<<t-32|e>>>64-t;function Cf(r,e,t,n){let s=(e>>>0)+(n>>>0);return{h:r+t+(s/2**32|0)|0,l:s|0}}var Uf=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),Pf=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,Df=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),Vf=(r,e,t,n,s)=>e+t+n+s+(r/2**32|0)|0,Of=(r,e,t,n,s)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(s>>>0),Mf=(r,e,t,n,s,i)=>e+t+n+s+i+(r/2**32|0)|0;var Hf={fromBig:Ia,split:wf,toBig:xf,shrSH:vf,shrSL:Ef,rotrSH:Bf,rotrSL:Af,rotrBH:kf,rotrBL:Sf,rotr32H:If,rotr32L:Rf,rotlSH:Nf,rotlSL:Tf,rotlBH:_f,rotlBL:Lf,add:Cf,add3L:Uf,add3H:Pf,add4L:Df,add4H:Vf,add5H:Mf,add5L:Of},D=Hf;var[Kf,Ff]=D.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),Bt=new Uint32Array(80),At=new Uint32Array(80),hi=class extends pr{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:x,Hh:y,Hl:d}=this;return[e,t,n,s,i,o,a,c,f,u,l,h,m,x,y,d]}set(e,t,n,s,i,o,a,c,f,u,l,h,m,x,y,d){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=x|0,this.Hh=y|0,this.Hl=d|0}process(e,t){for(let g=0;g<16;g++,t+=4)Bt[g]=e.getUint32(t),At[g]=e.getUint32(t+=4);for(let g=16;g<80;g++){let B=Bt[g-15]|0,C=At[g-15]|0,L=D.rotrSH(B,C,1)^D.rotrSH(B,C,8)^D.shrSH(B,C,7),S=D.rotrSL(B,C,1)^D.rotrSL(B,C,8)^D.shrSL(B,C,7),I=Bt[g-2]|0,_=At[g-2]|0,ne=D.rotrSH(I,_,19)^D.rotrBH(I,_,61)^D.shrSH(I,_,6),q=D.rotrSL(I,_,19)^D.rotrBL(I,_,61)^D.shrSL(I,_,6),V=D.add4L(S,q,At[g-7],At[g-16]),se=D.add4H(V,L,ne,Bt[g-7],Bt[g-16]);Bt[g]=se|0,At[g]=V|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:x,Gh:y,Gl:d,Hh:w,Hl:E}=this;for(let g=0;g<80;g++){let B=D.rotrSH(l,h,14)^D.rotrSH(l,h,18)^D.rotrBH(l,h,41),C=D.rotrSL(l,h,14)^D.rotrSL(l,h,18)^D.rotrBL(l,h,41),L=l&m^~l&y,S=h&x^~h&d,I=D.add5L(E,C,S,Ff[g],At[g]),_=D.add5H(I,w,B,L,Kf[g],Bt[g]),ne=I|0,q=D.rotrSH(n,s,28)^D.rotrBH(n,s,34)^D.rotrBH(n,s,39),V=D.rotrSL(n,s,28)^D.rotrBL(n,s,34)^D.rotrBL(n,s,39),se=n&i^n&a^i&a,A=s&o^s&c^o&c;w=y|0,E=d|0,y=m|0,d=x|0,m=l|0,x=h|0,{h:l,l:h}=D.add(f|0,u|0,_|0,ne|0),f=a|0,u=c|0,a=i|0,c=o|0,i=n|0,o=s|0;let N=D.add3L(ne,V,A);n=D.add3H(N,_,q,se),s=N|0}({h:n,l:s}=D.add(this.Ah|0,this.Al|0,n|0,s|0)),{h:i,l:o}=D.add(this.Bh|0,this.Bl|0,i|0,o|0),{h:a,l:c}=D.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=D.add(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:h}=D.add(this.Eh|0,this.El|0,l|0,h|0),{h:m,l:x}=D.add(this.Fh|0,this.Fl|0,m|0,x|0),{h:y,l:d}=D.add(this.Gh|0,this.Gl|0,y|0,d|0),{h:w,l:E}=D.add(this.Hh|0,this.Hl|0,w|0,E|0),this.set(n,s,i,o,a,c,f,u,l,h,m,x,y,d,w,E)}roundClean(){Bt.fill(0),At.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 Mr=En(()=>new hi);var kn={};ue(kn,{aInRange:()=>_e,abool:()=>Ke,abytes:()=>gr,bitGet:()=>Wf,bitLen:()=>yi,bitMask:()=>Kr,bitSet:()=>Yf,bytesToHex:()=>ot,bytesToNumberBE:()=>at,bytesToNumberLE:()=>St,concatBytes:()=>ct,createHmacDrbg:()=>bi,ensureBytes:()=>te,equalBytes:()=>Gf,hexToBytes:()=>Ft,hexToNumber:()=>mi,inRange:()=>Hr,isBytes:()=>kt,memoized:()=>$t,notImplemented:()=>Jf,numberToBytesBE:()=>It,numberToBytesLE:()=>qt,numberToHexUnpadded:()=>Kt,numberToVarBytesBE:()=>zf,utf8ToBytes:()=>jf,validateObject:()=>We});var gi=BigInt(0),An=BigInt(1),qf=BigInt(2);function kt(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function gr(r){if(!kt(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 $f=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function ot(r){gr(r);let e="";for(let t=0;t<r.length;t++)e+=$f[r[t]];return e}function Kt(r){let e=r.toString(16);return e.length&1?`0${e}`:e}function mi(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var it={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function Ra(r){if(r>=it._0&&r<=it._9)return r-it._0;if(r>=it._A&&r<=it._F)return r-(it._A-10);if(r>=it._a&&r<=it._f)return r-(it._a-10)}function Ft(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=Ra(r.charCodeAt(i)),a=Ra(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 at(r){return mi(ot(r))}function St(r){return gr(r),mi(ot(Uint8Array.from(r).reverse()))}function It(r,e){return Ft(r.toString(16).padStart(e*2,"0"))}function qt(r,e){return It(r,e).reverse()}function zf(r){return Ft(Kt(r))}function te(r,e,t){let n;if(typeof e=="string")try{n=Ft(e)}catch(i){throw new Error(`${r} must be valid hex string, got "${e}". Cause: ${i}`)}else if(kt(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 ct(...r){let e=0;for(let n=0;n<r.length;n++){let s=r[n];gr(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 Gf(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 jf(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}var di=r=>typeof r=="bigint"&&gi<=r;function Hr(r,e,t){return di(r)&&di(e)&&di(t)&&e<=r&&r<t}function _e(r,e,t,n){if(!Hr(e,t,n))throw new Error(`expected valid ${r}: ${t} <= n < ${n}, got ${typeof e} ${e}`)}function yi(r){let e;for(e=0;r>gi;r>>=An,e+=1);return e}function Wf(r,e){return r>>BigInt(e)&An}function Yf(r,e,t){return r|(t?An:gi)<<BigInt(e)}var Kr=r=>(qf<<BigInt(r-1))-An,pi=r=>new Uint8Array(r),Na=r=>Uint8Array.from(r);function bi(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=pi(r),s=pi(r),i=0,o=()=>{n.fill(1),s.fill(0),i=0},a=(...l)=>t(s,n,...l),c=(l=pi())=>{s=a(Na([0]),l),n=a(),l.length!==0&&(s=a(Na([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 ct(...h)};return(l,h)=>{o(),c(l);let m;for(;!(m=h(f()));)c();return o(),m}}var Zf={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||kt(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=Zf[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 Jf=()=>{throw new Error("not implemented")};function $t(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),Z=BigInt(1),zt=BigInt(2),Xf=BigInt(3),wi=BigInt(4),Ta=BigInt(5),_a=BigInt(8),Qf=BigInt(9),eh=BigInt(16);function j(r,e){let t=r%e;return t>=ae?t:e+t}function th(r,e,t){if(t<=ae||e<ae)throw new Error("Expected power/modulo > 0");if(t===Z)return ae;let n=Z;for(;e>ae;)e&Z&&(n=n*r%t),r=r*r%t,e>>=Z;return n}function J(r,e,t){let n=r;for(;e-- >ae;)n*=n,n%=t;return n}function Sn(r,e){if(r===ae||e<=ae)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=j(r,e),n=e,s=ae,i=Z,o=Z,a=ae;for(;t!==ae;){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 rh(r){let e=(r-Z)/zt,t,n,s;for(t=r-Z,n=0;t%zt===ae;t/=zt,n++);for(s=zt;s<r&&th(s,e,r)!==r-Z;s++);if(n===1){let o=(r+Z)/wi;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)/zt;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 y=a.sqr(h);m<f&&!a.eql(y,a.ONE);m++)y=a.sqr(y);let x=a.pow(u,Z<<BigInt(f-m-1));u=a.sqr(x),l=a.mul(l,x),h=a.mul(h,u),f=m}return l}}function nh(r){if(r%wi===Xf){let e=(r+Z)/wi;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%_a===Ta){let e=(r-Ta)/_a;return function(n,s){let i=n.mul(s,zt),o=n.pow(i,e),a=n.mul(s,o),c=n.mul(n.mul(a,zt),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%eh,rh(r)}var La=(r,e)=>(j(r,e)&Z)===Z,sh=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function xi(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=sh.reduce((n,s)=>(n[s]="function",n),e);return We(r,t)}function ih(r,e,t){if(t<ae)throw new Error("Expected power > 0");if(t===ae)return r.ONE;if(t===Z)return e;let n=r.ONE,s=e;for(;t>ae;)t&Z&&(n=r.mul(n,s)),s=r.sqr(s),t>>=Z;return n}function oh(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 vi(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function Rt(r,e,t=!1,n={}){if(r<=ae)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:s,nByteLength:i}=vi(r,e);if(i>2048)throw new Error("Field lengths over 2048 bytes are not supported");let o=nh(r),a=Object.freeze({ORDER:r,BITS:s,BYTES:i,MASK:Kr(s),ZERO:ae,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 ae<=c&&c<r},is0:c=>c===ae,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)=>ih(a,c,f),div:(c,f)=>j(c*Sn(f,r),r),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>Sn(c,r),sqrt:n.sqrt||(c=>o(a,c)),invertBatch:c=>oh(a,c),cmov:(c,f,u)=>u?f:c,toBytes:c=>t?qt(c,i):It(c,i),fromBytes:c=>{if(c.length!==i)throw new Error(`Fp.fromBytes: expected ${i}, got ${c.length}`);return t?St(c):at(c)}});return Object.freeze(a)}function Ca(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 Ei(r){let e=Ca(r);return e+Math.ceil(e/2)}function Ua(r,e,t=!1){let n=r.length,s=Ca(e),i=Ei(e);if(n<16||n<i||n>1024)throw new Error(`expected ${i}-1024 bytes of input, got ${n}`);let o=t?at(r):St(r),a=j(o,e-Z)+Z;return t?qt(a,s):It(a,s)}var ch=BigInt(0),Bi=BigInt(1),Ai=new WeakMap,Pa=new WeakMap;function In(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>ch;)o&Bi&&(a=a.add(c)),c=c.double(),o>>=Bi;return a},precomputeWindow(i,o){let{windows:a,windowSize:c}=s(o),f=[],u=i,l=u;for(let h=0;h<a;h++){l=u,f.push(l);for(let m=1;m<c;m++)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,h=BigInt(2**i-1),m=2**i,x=BigInt(i);for(let y=0;y<c;y++){let d=y*f,w=Number(a&h);a>>=x,w>f&&(w-=m,a+=Bi);let E=d,g=d+Math.abs(w)-1,B=y%2!==0,C=w<0;w===0?l=l.add(t(B,o[E])):u=u.add(t(C,o[g]))}return{p:u,f:l}},wNAFCached(i,o,a){let c=Pa.get(i)||1,f=Ai.get(i);return f||(f=this.precomputeWindow(i,c),c!==1&&Ai.set(i,a(f))),this.wNAF(c,f,o)},setWindowSize(i,o){n(o),Pa.set(i,o),Ai.delete(i)}}}function Rn(r,e,t,n){if(!Array.isArray(t)||!Array.isArray(n)||n.length!==t.length)throw new Error("arrays of points and scalars must have equal length");n.forEach((u,l)=>{if(!e.isValid(u))throw new Error(`wrong scalar at index ${l}`)}),t.forEach((u,l)=>{if(!(u instanceof r))throw new Error(`wrong point at index ${l}`)});let s=yi(BigInt(t.length)),i=s>12?s-3:s>4?s-2:s?2:1,o=(1<<i)-1,a=new Array(o+1).fill(r.ZERO),c=Math.floor((e.BITS-1)/i)*i,f=r.ZERO;for(let u=c;u>=0;u-=i){a.fill(r.ZERO);for(let h=0;h<n.length;h++){let m=n[h],x=Number(m>>BigInt(u)&BigInt(o));a[x]=a[x].add(t[h])}let l=r.ZERO;for(let h=a.length-1,m=r.ZERO;h>0;h--)m=m.add(a[h]),l=l.add(m);if(f=f.add(l),u!==0)for(let h=0;h<i;h++)f=f.double()}return f}function Fr(r){return xi(r.Fp),We(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...vi(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Fe=BigInt(0),Le=BigInt(1),Nn=BigInt(2),lh=BigInt(8),uh={zip215:!0};function fh(r){let e=Fr(r);return We(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function Da(r){let e=fh(r),{Fp:t,n,prehash:s,hash:i,randomBytes:o,nByteLength:a,h:c}=e,f=Nn<<BigInt(a*8)-Le,u=t.create,l=Rt(e.n,e.nBitLength),h=e.uvRatio||((b,p)=>{try{return{isValid:!0,value:t.sqrt(b*t.inv(p))}}catch{return{isValid:!1,value:Fe}}}),m=e.adjustScalarBytes||(b=>b),x=e.domain||((b,p,v)=>{if(Ke("phflag",v),p.length||v)throw new Error("Contexts/pre-hash are not supported");return b});function y(b,p){_e("coordinate "+b,p,Fe,f)}function d(b){if(!(b instanceof g))throw new Error("ExtendedPoint expected")}let w=$t((b,p)=>{let{ex:v,ey:T,ez:U}=b,P=b.is0();p==null&&(p=P?lh:t.inv(U));let O=u(v*p),F=u(T*p),M=u(U*p);if(P)return{x:Fe,y:Le};if(M!==Le)throw new Error("invZ was invalid");return{x:O,y:F}}),E=$t(b=>{let{a:p,d:v}=e;if(b.is0())throw new Error("bad point: ZERO");let{ex:T,ey:U,ez:P,et:O}=b,F=u(T*T),M=u(U*U),G=u(P*P),Y=u(G*G),ce=u(F*p),le=u(G*u(ce+M)),de=u(Y+u(v*u(F*M)));if(le!==de)throw new Error("bad point: equation left != right (1)");let ve=u(T*U),ie=u(P*O);if(ve!==ie)throw new Error("bad point: equation left != right (2)");return!0});class g{constructor(p,v,T,U){this.ex=p,this.ey=v,this.ez=T,this.et=U,y("x",p),y("y",v),y("z",T),y("t",U),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(p){if(p instanceof g)throw new Error("extended point not allowed");let{x:v,y:T}=p||{};return y("x",v),y("y",T),new g(v,T,Le,u(v*T))}static normalizeZ(p){let v=t.invertBatch(p.map(T=>T.ez));return p.map((T,U)=>T.toAffine(v[U])).map(g.fromAffine)}static msm(p,v){return Rn(g,l,p,v)}_setWindowSize(p){L.setWindowSize(this,p)}assertValidity(){E(this)}equals(p){d(p);let{ex:v,ey:T,ez:U}=this,{ex:P,ey:O,ez:F}=p,M=u(v*F),G=u(P*U),Y=u(T*F),ce=u(O*U);return M===G&&Y===ce}is0(){return this.equals(g.ZERO)}negate(){return new g(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:p}=e,{ex:v,ey:T,ez:U}=this,P=u(v*v),O=u(T*T),F=u(Nn*u(U*U)),M=u(p*P),G=v+T,Y=u(u(G*G)-P-O),ce=M+O,le=ce-F,de=M-O,ve=u(Y*le),ie=u(ce*de),Ne=u(Y*de),tt=u(le*ce);return new g(ve,ie,tt,Ne)}add(p){d(p);let{a:v,d:T}=e,{ex:U,ey:P,ez:O,et:F}=this,{ex:M,ey:G,ez:Y,et:ce}=p;if(v===BigInt(-1)){let $o=u((P-U)*(G+M)),zo=u((P+U)*(G-M)),Ks=u(zo-$o);if(Ks===Fe)return this.double();let Go=u(O*Nn*ce),jo=u(F*Nn*Y),Wo=jo+Go,Yo=zo+$o,Zo=jo-Go,Ql=u(Wo*Ks),eu=u(Yo*Zo),tu=u(Wo*Zo),ru=u(Ks*Yo);return new g(Ql,eu,ru,tu)}let le=u(U*M),de=u(P*G),ve=u(F*T*ce),ie=u(O*Y),Ne=u((U+P)*(M+G)-le-de),tt=ie-ve,Ur=ie+ve,Pr=u(de-v*le),Yl=u(Ne*tt),Zl=u(Ur*Pr),Jl=u(Ne*Pr),Xl=u(tt*Ur);return new g(Yl,Zl,Xl,Jl)}subtract(p){return this.add(p.negate())}wNAF(p){return L.wNAFCached(this,p,g.normalizeZ)}multiply(p){let v=p;_e("scalar",v,Le,n);let{p:T,f:U}=this.wNAF(v);return g.normalizeZ([T,U])[0]}multiplyUnsafe(p){let v=p;return _e("scalar",v,Fe,n),v===Fe?C:this.equals(C)||v===Le?this:this.equals(B)?this.wNAF(v).p:L.unsafeLadder(this,v)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return L.unsafeLadder(this,n).is0()}toAffine(p){return w(this,p)}clearCofactor(){let{h:p}=e;return p===Le?this:this.multiplyUnsafe(p)}static fromHex(p,v=!1){let{d:T,a:U}=e,P=t.BYTES;p=te("pointHex",p,P),Ke("zip215",v);let O=p.slice(),F=p[P-1];O[P-1]=F&-129;let M=St(O),G=v?f:t.ORDER;_e("pointHex.y",M,Fe,G);let Y=u(M*M),ce=u(Y-Le),le=u(T*Y-U),{isValid:de,value:ve}=h(ce,le);if(!de)throw new Error("Point.fromHex: invalid y coordinate");let ie=(ve&Le)===Le,Ne=(F&128)!==0;if(!v&&ve===Fe&&Ne)throw new Error("Point.fromHex: x=0 and x_0=1");return Ne!==ie&&(ve=u(-ve)),g.fromAffine({x:ve,y:M})}static fromPrivateKey(p){return _(p).point}toRawBytes(){let{x:p,y:v}=this.toAffine(),T=qt(v,t.BYTES);return T[T.length-1]|=p&Le?128:0,T}toHex(){return ot(this.toRawBytes())}}g.BASE=new g(e.Gx,e.Gy,Le,u(e.Gx*e.Gy)),g.ZERO=new g(Fe,Le,Le,Fe);let{BASE:B,ZERO:C}=g,L=In(g,a*8);function S(b){return j(b,n)}function I(b){return S(St(b))}function _(b){let p=a;b=te("private key",b,p);let v=te("hashed private key",i(b),2*p),T=m(v.slice(0,p)),U=v.slice(p,2*p),P=I(T),O=B.multiply(P),F=O.toRawBytes();return{head:T,prefix:U,scalar:P,point:O,pointBytes:F}}function ne(b){return _(b).pointBytes}function q(b=new Uint8Array,...p){let v=ct(...p);return I(i(x(v,te("context",b),!!s)))}function V(b,p,v={}){b=te("message",b),s&&(b=s(b));let{prefix:T,scalar:U,pointBytes:P}=_(p),O=q(v.context,T,b),F=B.multiply(O).toRawBytes(),M=q(v.context,F,P,b),G=S(O+M*U);_e("signature.s",G,Fe,n);let Y=ct(F,qt(G,t.BYTES));return te("result",Y,a*2)}let se=uh;function A(b,p,v,T=se){let{context:U,zip215:P}=T,O=t.BYTES;b=te("signature",b,2*O),p=te("message",p),P!==void 0&&Ke("zip215",P),s&&(p=s(p));let F=St(b.slice(O,2*O)),M,G,Y;try{M=g.fromHex(v,P),G=g.fromHex(b.slice(0,O),P),Y=B.multiplyUnsafe(F)}catch{return!1}if(!P&&M.isSmallOrder())return!1;let ce=q(U,G.toRawBytes(),M.toRawBytes(),p);return G.add(M.multiplyUnsafe(ce)).subtract(Y).clearCofactor().equals(g.ZERO)}return B._setWindowSize(8),{CURVE:e,getPublicKey:ne,sign:V,verify:A,ExtendedPoint:g,utils:{getExtendedPublicKey:_,randomPrivateKey:()=>o(t.BYTES),precompute(b=8,p=g.BASE){return p._setWindowSize(b),p.multiply(BigInt(3)),p}}}}var ki=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Va=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),P0=BigInt(0),hh=BigInt(1),Oa=BigInt(2),D0=BigInt(3),dh=BigInt(5),ph=BigInt(8);function gh(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),s=BigInt(80),i=ki,a=r*r%i*r%i,c=J(a,Oa,i)*a%i,f=J(c,hh,i)*r%i,u=J(f,dh,i)*f%i,l=J(u,e,i)*u%i,h=J(l,t,i)*l%i,m=J(h,n,i)*h%i,x=J(m,s,i)*m%i,y=J(x,s,i)*m%i,d=J(y,e,i)*u%i;return{pow_p_5_8:J(d,Oa,i)*r%i,b2:a}}function mh(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function yh(r,e){let t=ki,n=j(e*e*e,t),s=j(n*n*e,t),i=gh(r*s).pow_p_5_8,o=j(r*n*i,t),a=j(e*o*o,t),c=o,f=j(o*Va,t),u=a===r,l=a===j(-r,t),h=a===j(-r*Va,t);return u&&(o=c),(l||h)&&(o=f),La(o,t)&&(o=j(-o,t)),{isValid:u||l,value:o}}var bh=Rt(ki,void 0,!0),wh={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:bh,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:ph,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Mr,randomBytes:dr,adjustScalarBytes:mh,uvRatio:yh},mr=Da(wh);var yr=32,lt=64,Tn=32;function Ma(){let r=mr.utils.randomPrivateKey(),e=mr.getPublicKey(r);return{privateKey:qa(r,e),publicKey:e}}function Ha(r){if(r.length!==Tn)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=mr.getPublicKey(e);return{privateKey:qa(e,t),publicKey:t}}function Ka(r,e){let t=r.subarray(0,Tn);return mr.sign(e instanceof Uint8Array?e:e.subarray(),t)}function Fa(r,e,t){return mr.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}function qa(r,e){let t=new Uint8Array(lt);for(let n=0;n<Tn;n++)t[n]=r[n],t[Tn+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 Si={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function $a(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)),x=a.getRandomValues(new Uint8Array(n)),y={name:e,iv:x};typeof h=="string"&&(h=$(h));let d;if(h.length===0){d=await a.subtle.importKey("jwk",Si,{name:"AES-GCM"},!0,["encrypt"]);try{let E={name:"PBKDF2",salt:m,iterations:o,hash:{name:s}},g=await a.subtle.importKey("raw",h,{name:"PBKDF2"},!1,["deriveKey"]);d=await a.subtle.deriveKey(E,g,{name:e,length:t},!0,["encrypt"])}catch{d=await a.subtle.importKey("jwk",Si,{name:"AES-GCM"},!0,["encrypt"])}}else{let E={name:"PBKDF2",salt:m,iterations:o,hash:{name:s}},g=await a.subtle.importKey("raw",h,{name:"PBKDF2"},!1,["deriveKey"]);d=await a.subtle.deriveKey(E,g,{name:e,length:t},!0,["encrypt"])}let w=await a.subtle.encrypt(y,d,l);return Ee([m,y.iv,new Uint8Array(w)])}async function f(l,h){let m=l.subarray(0,i),x=l.subarray(i,i+n),y=l.subarray(i+n),d={name:e,iv:x};typeof h=="string"&&(h=$(h));let w;if(h.length===0)try{let g={name:"PBKDF2",salt:m,iterations:o,hash:{name:s}},B=await a.subtle.importKey("raw",h,{name:"PBKDF2"},!1,["deriveKey"]);w=await a.subtle.deriveKey(g,B,{name:e,length:t},!0,["decrypt"])}catch{w=await a.subtle.importKey("jwk",Si,{name:"AES-GCM"},!0,["decrypt"])}else{let g={name:"PBKDF2",salt:m,iterations:o,hash:{name:s}},B=await a.subtle.importKey("raw",h,{name:"PBKDF2"},!1,["deriveKey"]);w=await a.subtle.deriveKey(g,B,{name:e,length:t},!0,["decrypt"])}let E=await a.subtle.decrypt(d,w,y);return new Uint8Array(E)}return{encrypt:c,decrypt:f}}async function br(r,e){let n=await $a().encrypt(r,e);return si.encode(n)}var Eh=Math.pow(2,7),Bh=Math.pow(2,14),Ah=Math.pow(2,21),Ii=Math.pow(2,28),Ri=Math.pow(2,35),Ni=Math.pow(2,42),Ti=Math.pow(2,49),z=128,ye=127;function Ce(r){if(r<Eh)return 1;if(r<Bh)return 2;if(r<Ah)return 3;if(r<Ii)return 4;if(r<Ri)return 5;if(r<Ni)return 6;if(r<Ti)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function _i(r,e,t=0){switch(Ce(r)){case 8:e[t++]=r&255|z,r/=128;case 7:e[t++]=r&255|z,r/=128;case 6:e[t++]=r&255|z,r/=128;case 5:e[t++]=r&255|z,r/=128;case 4:e[t++]=r&255|z,r>>>=7;case 3:e[t++]=r&255|z,r>>>=7;case 2:e[t++]=r&255|z,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function kh(r,e,t=0){switch(Ce(r)){case 8:e.set(t++,r&255|z),r/=128;case 7:e.set(t++,r&255|z),r/=128;case 6:e.set(t++,r&255|z),r/=128;case 5:e.set(t++,r&255|z),r/=128;case 4:e.set(t++,r&255|z),r>>>=7;case 3:e.set(t++,r&255|z),r>>>=7;case 2:e.set(t++,r&255|z),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Li(r,e){let t=r[e],n=0;if(n+=t&ye,t<z||(t=r[e+1],n+=(t&ye)<<7,t<z)||(t=r[e+2],n+=(t&ye)<<14,t<z)||(t=r[e+3],n+=(t&ye)<<21,t<z)||(t=r[e+4],n+=(t&ye)*Ii,t<z)||(t=r[e+5],n+=(t&ye)*Ri,t<z)||(t=r[e+6],n+=(t&ye)*Ni,t<z)||(t=r[e+7],n+=(t&ye)*Ti,t<z))return n;throw new RangeError("Could not decode varint")}function Sh(r,e){let t=r.get(e),n=0;if(n+=t&ye,t<z||(t=r.get(e+1),n+=(t&ye)<<7,t<z)||(t=r.get(e+2),n+=(t&ye)<<14,t<z)||(t=r.get(e+3),n+=(t&ye)<<21,t<z)||(t=r.get(e+4),n+=(t&ye)*Ii,t<z)||(t=r.get(e+5),n+=(t&ye)*Ri,t<z)||(t=r.get(e+6),n+=(t&ye)*Ni,t<z)||(t=r.get(e+7),n+=(t&ye)*Ti,t<z))return n;throw new RangeError("Could not decode varint")}function Ye(r,e,t=0){return e==null&&(e=Te(Ce(r))),e instanceof Uint8Array?_i(r,e,t):kh(r,e,t)}function Gt(r,e=0){return r instanceof Uint8Array?Li(r,e):Sh(r,e)}var Ui=new Float32Array([-0]),Nt=new Uint8Array(Ui.buffer);function za(r,e,t){Ui[0]=r,e[t]=Nt[0],e[t+1]=Nt[1],e[t+2]=Nt[2],e[t+3]=Nt[3]}function Ga(r,e){return Nt[0]=r[e],Nt[1]=r[e+1],Nt[2]=r[e+2],Nt[3]=r[e+3],Ui[0]}var Pi=new Float64Array([-0]),be=new Uint8Array(Pi.buffer);function ja(r,e,t){Pi[0]=r,e[t]=be[0],e[t+1]=be[1],e[t+2]=be[2],e[t+3]=be[3],e[t+4]=be[4],e[t+5]=be[5],e[t+6]=be[6],e[t+7]=be[7]}function Wa(r,e){return be[0]=r[e],be[1]=r[e+1],be[2]=r[e+2],be[3]=r[e+3],be[4]=r[e+4],be[5]=r[e+5],be[6]=r[e+6],be[7]=r[e+7],Pi[0]}var Ih=BigInt(Number.MAX_SAFE_INTEGER),Rh=BigInt(Number.MIN_SAFE_INTEGER),Pe=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 jt;if(e<Ih&&e>Rh)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>Ya&&(s=0n,++n>Ya&&(n=0n))),new r(Number(s),Number(n))}static fromNumber(e){if(e===0)return jt;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):jt}},jt=new Pe(0,0);jt.toBigInt=function(){return 0n};jt.zzEncode=jt.zzDecode=function(){return this};jt.length=function(){return 1};var Ya=4294967296n;function Za(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 Ja(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 Di(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 _n(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Vi=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 _n(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw qe(this,4);return _n(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw qe(this,4);let e=Ga(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw qe(this,4);let e=Wa(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 Ja(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 Pe(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=_n(this.buf,this.pos+=4),t=_n(this.buf,this.pos+=4);return new Pe(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=Li(this.buf,this.pos);return this.pos+=Ce(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 Oi(r){return new Vi(r instanceof Uint8Array?r:r.subarray())}function Ae(r,e,t){let n=Oi(r);return e.decode(n,void 0,t)}function Mi(r){let e=r??8192,t=e>>>1,n,s=e;return function(o){if(o<1||o>t)return Te(o);s+o>e&&(n=Te(e),s=0);let a=n.subarray(s,s+=o);return s&7&&(s=(s|7)+1),a}}var Wt=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function Hi(){}var Fi=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Nh=Mi();function Th(r){return globalThis.Buffer!=null?Te(r):Nh(r)}var $r=class{len;head;tail;states;constructor(){this.len=0,this.head=new Wt(Hi,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new Wt(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new qi((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(Ln,10,Pe.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=Pe.fromBigInt(e);return this._push(Ln,t.length(),t)}uint64Number(e){return this._push(_i,Ce(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=Pe.fromBigInt(e).zzEncode();return this._push(Ln,t.length(),t)}sint64Number(e){let t=Pe.fromNumber(e).zzEncode();return this._push(Ln,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Ki,1,e?1:0)}fixed32(e){return this._push(qr,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=Pe.fromBigInt(e);return this._push(qr,4,t.lo)._push(qr,4,t.hi)}fixed64Number(e){let t=Pe.fromNumber(e);return this._push(qr,4,t.lo)._push(qr,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(za,4,e)}double(e){return this._push(ja,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Ki,1,0):this.uint32(t)._push(Lh,t,e)}string(e){let t=Za(e);return t!==0?this.uint32(t)._push(Di,t,e):this._push(Ki,1,0)}fork(){return this.states=new Fi(this),this.head=this.tail=new Wt(Hi,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 Wt(Hi,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=Th(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function Ki(r,e,t){e[t]=r&255}function _h(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var qi=class extends Wt{next;constructor(e,t){super(_h,e,t),this.next=void 0}};function Ln(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 qr(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 Lh(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&($r.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(Ch,e,r),this},$r.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(Uh,e,r),this});function Ch(r,e,t){e.set(r,t)}function Uh(r,e,t){r.length<40?Di(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set($(r),t)}function $i(){return new $r}function ke(r,e){let t=$i();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var wr;(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"})(wr||(wr={}));function Cn(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function zi(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 Cn("enum",wr.VARINT,t,n)}function Se(r,e){return Cn("message",wr.LENGTH_DELIMITED,r,e)}var X;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1"})(X||(X={}));var Gi;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1"})(Gi||(Gi={}));(function(r){r.codec=()=>zi(Gi)})(X||(X={}));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 Je;(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())})(Je||(Je={}));var zr=class{_key;constructor(e){this._key=xr(e,yr)}verify(e,t){return Fa(this._key,t,e)}marshal(){return this._key}get bytes(){return Ze.encode({Type:X.Ed25519,Data:this.marshal()}).subarray()}equals(e){return ee(this.bytes,e.bytes)}hash(){let e=pe.digest(this.bytes);return Ve(e)?e.then(({bytes:t})=>t):e.bytes}},Yt=class{_key;_publicKey;constructor(e,t){this._key=xr(e,lt),this._publicKey=xr(t,yr)}sign(e){return Ka(this._key,e)}get public(){return new zr(this._publicKey)}marshal(){return this._key}get bytes(){return Je.encode({Type:X.Ed25519,Data:this.marshal()}).subarray()}equals(e){return ee(this.bytes,e.bytes)}async hash(){let e=pe.digest(this.bytes),t;return Ve(e)?{bytes:t}=await e:t=e.bytes,t}async id(){let e=nt.digest(this.public.bytes);return oe.encode(e.bytes).substring(1)}async export(e,t="libp2p-key"){if(t==="libp2p-key")return br(this.bytes,e);throw new R(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function Ph(r){if(r.length>lt){r=xr(r,lt+yr);let n=r.subarray(0,lt),s=r.subarray(lt,r.length);return new Yt(n,s)}r=xr(r,lt);let e=r.subarray(0,lt),t=r.subarray(yr);return new Yt(e,t)}function Dh(r){return r=xr(r,yr),new zr(r)}async function Vh(){let{privateKey:r,publicKey:e}=Ma();return new Yt(r,e)}async function Qa(r){let{privateKey:e,publicKey:t}=Ha(r);return new Yt(e,t)}function xr(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 H(r,e="utf8"){let t=xn[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var no={};ue(no,{MAX_RSA_KEY_SIZE:()=>nn,RsaPrivateKey:()=>kr,RsaPublicKey:()=>rn,fromJwk:()=>ud,generateKeyPair:()=>fd,unmarshalRsaPrivateKey:()=>to,unmarshalRsaPublicKey:()=>ld});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 dr(r)}var Ct={};ue(Ct,{exportToPem:()=>sd,importFromPem:()=>id,jwkToPkcs1:()=>ed,jwkToPkix:()=>rd,pkcs1ToJwk:()=>Qh,pkixToJwk:()=>td});var Pn=class extends fr{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,vn(e);let n=Et(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 ur(this),this.iHash.update(e),this}digestInto(e){ur(this),lr(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()}},Gr=(r,e,t)=>new Pn(r,e).update(t).digest();Gr.create=(r,e)=>new Pn(r,e);function Oh(r,e,t,n){vn(r);let s=Aa({dkLen:32,asyncTick:10},n),{c:i,dkLen:o,asyncTick:a}=s;if(cr(i),cr(o),cr(a),i<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=Et(e),f=Et(t),u=new Uint8Array(o),l=Gr.create(r,c),h=l._cloneInto().update(f);return{c:i,dkLen:o,asyncTick:a,DK:u,PRF:l,PRFSalt:h}}function Mh(r,e,t,n,s){return r.destroy(),e.destroy(),n&&n.destroy(),s.fill(0),t}async function Wi(r,e,t,n){let{c:s,dkLen:i,asyncTick:o,DK:a,PRF:c,PRFSalt:f}=Oh(r,e,t,n),u,l=new Uint8Array(4),h=hr(l),m=new Uint8Array(c.outputLen);for(let x=1,y=0;y<i;x++,y+=c.outputLen){let d=a.subarray(y,y+c.outputLen);h.setInt32(0,x,!1),(u=f._cloneInto(u)).update(l).digestInto(m),d.set(m.subarray(0,d.length)),await Ea(s-1,o,()=>{c._cloneInto(u).update(m).digestInto(m);for(let w=0;w<d.length;w++)d[w]^=m[w]})}return Mh(c,f,a,u,m)}var K=Qo(ec());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 Tt(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 On(...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 Zi(){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 tc(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=Tt(o,8,n),c=new Uint8Array(a);return c[0]|=128,a}let s=Tt(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 rc(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 Ue(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 $g=Math.log(2);function Mn(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Ji(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 pt(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 Wr=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return Ji(this.items)}},jr=[new Uint8Array([1])],nc="0123456789";var Br="",ze=new ArrayBuffer(0),Xi=new Uint8Array(0),Yr="EndOfContent",ic="OCTET STRING",oc="BIT STRING";function gt(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?K.BufferSourceConverter.toUint8Array(i.valueHex):Xi}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(!pt(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:K.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var ft=class{constructor({blockLength:e=0,error:t=Br,warnings:n=[],valueBeforeDecode:s=Xi}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=K.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:K.Convert.ToHex(this.valueBeforeDecodeView)}}};ft.NAME="baseBlock";var we=class extends ft{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'")}};we.NAME="valueBlock";var Hn=class extends gt(ft){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?K.BufferSourceConverter.toUint8Array(e.valueHex):Xi,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=Tt(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=K.BufferSourceConverter.toUint8Array(e);if(!pt(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=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}}};Hn.NAME="identificationBlock";var Kn=class extends ft{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=K.BufferSourceConverter.toUint8Array(e);if(!pt(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=Tt(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}}};Kn.NAME="lengthBlock";var k={},ge=class extends ft{constructor({name:e=Br,optional:t=!1,primitiveSchema:n,...s}={},i){super(s),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new Hn(s),this.lenBlock=new Kn(s),this.valueBlock=i?new i(s):new we(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 Wr;t||ac(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():K.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${K.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 rc(t,n)}};ge.NAME="BaseBlock";function ac(r){if(r instanceof k.Constructed)for(let e of r.valueBlock.value)ac(e)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var Fn=class extends ge{constructor({value:e=Br,...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}'`}};Fn.NAME="BaseStringBlock";var qn=class extends gt(we){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};qn.NAME="PrimitiveValueBlock";var cc,$n=class extends ge{constructor(e={}){super(e,qn),this.idBlock.isConstructed=!1}};cc=$n;k.Primitive=cc;$n.NAME="PRIMITIVE";function Wh(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({},we),i=new ft;if(!pt(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=Wh(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 Ar(r){if(!r.byteLength){let e=new ge({},we);return e.error="Input buffer has zero length",{offset:-1,result:e}}return Bs(K.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function Yh(r,e){return r?1:e}var Xe=class extends we{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let s=K.BufferSourceConverter.toUint8Array(e);if(!pt(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(;Yh(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===Yr)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===Yr?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(e,t){let n=t||new Wr;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 lc,_t=class extends ge{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} :`}};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);})();
|
|
6
|
+
`)}`:`${t} :`}};lc=_t;k.Constructed=lc;_t.NAME="CONSTRUCTED";var zn=class extends we{fromBER(e,t,n){return t}toBER(e){return ze}};zn.override="EndOfContentValueBlock";var uc,Gn=class extends ge{constructor(e={}){super(e,zn),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};uc=Gn;k.EndOfContent=uc;Gn.NAME=Yr;var fc,Lt=class extends ge{constructor(e={}){super(e,we),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}`}};fc=Lt;k.Null=fc;Lt.NAME="NULL";var jn=class extends gt(we){constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=K.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=K.BufferSourceConverter.toUint8Array(e);return pt(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,Zi.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};jn.NAME="BooleanValueBlock";var hc,Wn=class extends ge{constructor(e={}){super(e,jn),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}`}};hc=Wn;k.Boolean=hc;Wn.NAME="BOOLEAN";var Yn=class extends gt(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===Yr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(o!==ic)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}}};Yn.NAME="OctetStringValueBlock";var dc,ht=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},Yn),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?_t.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${K.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 K.BufferSourceConverter.concat(e)}};dc=ht;k.OctetString=dc;ht.NAME=ic;var Zn=class extends gt(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===Yr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==oc)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=K.BufferSourceConverter.toUint8Array(e);if(!pt(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 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}}};Zn.NAME="BitStringValueBlock";var pc,Er=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 _t.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)}`}}};pc=Er;k.BitString=pc;Er.NAME=oc;var gc;function Zh(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=On(new Uint8Array([f%10]),i);break;default:i[o-l]=f%10}}return t[0]>0&&(i=On(t,i)),i}function sc(r){if(r>=jr.length)for(let e=jr.length;e<=r;e++){let t=new Uint8Array([0]),n=jr[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=On(t,n)),jr.push(n)}return jr[r]}function Jh(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 Zr=class extends gt(we){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=Zi.call(this)))}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(tc(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=Jh(sc(n),t),o="-";break;default:t=Zh(t,sc(n))}n++,s>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(o+=nc.charAt(t[c]));return a===!1&&(o+=nc.charAt(0)),o}};gc=Zr;Zr.NAME="IntegerValueBlock";Object.defineProperty(gc.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var mc,re=class r extends ge{constructor(e={}){super(e,Zr),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Mn(),BigInt(this.valueBlock.toString())}static fromBigInt(e){Mn();let t=BigInt(e),n=new Wr,s=t.toString(16).replace(/^-/,""),i=new Uint8Array(K.Convert.FromHex(s));if(t<0){let a=new Uint8Array(i.length+(i[0]&128?1:0));a[0]|=128;let f=BigInt(`0x${K.Convert.ToHex(a)}`)+t,u=K.BufferSourceConverter.toUint8Array(K.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()}`}};mc=re;k.Integer=mc;re.NAME="INTEGER";var yc,Jn=class extends re{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};yc=Jn;k.Enumerated=yc;Jn.NAME="ENUMERATED";var Jr=class extends gt(we){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=K.BufferSourceConverter.toUint8Array(e);if(!pt(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){Mn();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=Tt(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=K.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 Xn=class extends we{constructor({value:e=Br,...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 Ji(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){Mn();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}};Xn.NAME="ObjectIdentifierValueBlock";var bc,$e=class extends ge{constructor(e={}){super(e,Xn),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()}}};bc=$e;k.ObjectIdentifier=bc;$e.NAME="OBJECT IDENTIFIER";var Xr=class extends gt(ft){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let s=K.BufferSourceConverter.toUint8Array(e);if(!pt(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=Tt(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=K.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};Xr.NAME="relativeSidBlock";var Qn=class extends we{constructor({value:e=Br,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let s=t;for(;n>0;){let i=new Xr;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 Ji(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 Xr;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}};Qn.NAME="RelativeObjectIdentifierValueBlock";var wc,es=class extends ge{constructor(e={}){super(e,Qn),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()}}};wc=es;k.RelativeObjectIdentifier=wc;es.NAME="RelativeObjectIdentifier";var xc,fe=class extends _t{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};xc=fe;k.Sequence=xc;fe.NAME="SEQUENCE";var vc,ts=class extends _t{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};vc=ts;k.Set=vc;ts.NAME="SET";var rs=class extends gt(we){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=Br}toJSON(){return{...super.toJSON(),value:this.value}}};rs.NAME="StringValueBlock";var ns=class extends rs{};ns.NAME="SimpleStringValueBlock";var Ie=class extends Fn{constructor({...e}={}){super(e,ns)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,K.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 ss=class extends Ie{fromBuffer(e){this.valueBlock.valueHexView=K.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=K.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=K.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(K.Convert.FromUtf8String(e)),this.valueBlock.value=e}};ss.NAME="Utf8StringValueBlock";var Ec,dt=class extends ss{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};Ec=dt;k.Utf8String=Ec;dt.NAME="UTF8String";var is=class extends Ie{fromBuffer(e){this.valueBlock.value=K.Convert.ToUtf16String(e),this.valueBlock.valueHexView=K.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(K.Convert.FromUtf16String(e))}};is.NAME="BmpStringValueBlock";var Bc,os=class extends is{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};Bc=os;k.BmpString=Bc;os.NAME="BMPString";var as=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=Tt(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}};as.NAME="UniversalStringValueBlock";var Ac,cs=class extends as{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};Ac=cs;k.UniversalString=Ac;cs.NAME="UniversalString";var kc,ls=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};kc=ls;k.NumericString=kc;ls.NAME="NumericString";var Sc,us=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};Sc=us;k.PrintableString=Sc;us.NAME="PrintableString";var Ic,fs=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};Ic=fs;k.TeletexString=Ic;fs.NAME="TeletexString";var Rc,hs=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};Rc=hs;k.VideotexString=Rc;hs.NAME="VideotexString";var Nc,ds=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};Nc=ds;k.IA5String=Nc;ds.NAME="IA5String";var Tc,ps=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};Tc=ps;k.GraphicString=Tc;ps.NAME="GraphicString";var _c,Qr=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};_c=Qr;k.VisibleString=_c;Qr.NAME="VisibleString";var Lc,gs=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};Lc=gs;k.GeneralString=Lc;gs.NAME="GeneralString";var Cc,ms=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};Cc=ms;k.CharacterString=Cc;ms.NAME="CharacterString";var Uc,en=class extends Qr{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,K.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]=Ue(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=Ue(this.month,2),t[2]=Ue(this.day,2),t[3]=Ue(this.hour,2),t[4]=Ue(this.minute,2),t[5]=Ue(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}}};Uc=en;k.UTCTime=Uc;en.NAME="UTCTime";var Pc,ys=class extends en{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 x=parseInt(m.substring(0,2),10);if(isNaN(x.valueOf()))throw new Error("Wrong input string for conversion");if(a=l*x,m.length===4){if(x=parseInt(m.substring(2,4),10),isNaN(x.valueOf()))throw new Error("Wrong input string for conversion");c=l*x}}}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(Ue(this.year,4)),t.push(Ue(this.month,2)),t.push(Ue(this.day,2)),t.push(Ue(this.hour,2)),t.push(Ue(this.minute,2)),t.push(Ue(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(Ue(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};Pc=ys;k.GeneralizedTime=Pc;ys.NAME="GeneralizedTime";var Dc,bs=class extends dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};Dc=bs;k.DATE=Dc;bs.NAME="DATE";var Vc,ws=class extends dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};Vc=ws;k.TimeOfDay=Vc;ws.NAME="TimeOfDay";var Oc,xs=class extends dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};Oc=xs;k.DateTime=Oc;xs.NAME="DateTime";var Mc,vs=class extends dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};Mc=vs;k.Duration=Mc;vs.NAME="Duration";var Hc,Es=class extends dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};Hc=Es;k.TIME=Hc;Es.NAME="TIME";function Qh(r){let{result:e}=Ar(r),t=e.valueBlock.value;return{n:H(Qe(t[1].toBigInt()),"base64url"),e:H(Qe(t[2].toBigInt()),"base64url"),d:H(Qe(t[3].toBigInt()),"base64url"),p:H(Qe(t[4].toBigInt()),"base64url"),q:H(Qe(t[5].toBigInt()),"base64url"),dp:H(Qe(t[6].toBigInt()),"base64url"),dq:H(Qe(t[7].toBigInt()),"base64url"),qi:H(Qe(t[8].toBigInt()),"base64url"),kty:"RSA",alg:"RS256"}}function ed(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 re({value:0}),re.fromBigInt(et($(r.n,"base64url"))),re.fromBigInt(et($(r.e,"base64url"))),re.fromBigInt(et($(r.d,"base64url"))),re.fromBigInt(et($(r.p,"base64url"))),re.fromBigInt(et($(r.q,"base64url"))),re.fromBigInt(et($(r.dp,"base64url"))),re.fromBigInt(et($(r.dq,"base64url"))),re.fromBigInt(et($(r.qi,"base64url")))]}).toBER();return new Uint8Array(t,0,t.byteLength)}function td(r){let{result:e}=Ar(r),t=e.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:H(Qe(t[0].toBigInt()),"base64url"),e:H(Qe(t[1].toBigInt()),"base64url")}}function rd(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 $e({value:"1.2.840.113549.1.1.1"}),new Lt]}),new Er({valueHex:new fe({value:[re.fromBigInt(et($(r.n,"base64url"))),re.fromBigInt(et($(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 nd=16,Qi=32,eo=1e4;async function sd(r,e){let t=Be.get(),s=new fe({value:[new re({value:0}),new fe({value:[new $e({value:"1.2.840.113549.1.1.1"}),new Lt]}),new ht({valueHex:r.marshal()})]}).toBER(),i=new Uint8Array(s,0,s.byteLength),o=Zt(nd),a=await Wi(Mr,e,o,{c:eo,dkLen:Qi}),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 ht({valueHex:o}),new re({value:eo}),new re({value:Qi}),new fe({value:[new $e({value:"1.2.840.113549.2.11"}),new Lt]})]}),h=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 ht({valueHex:c})]})]})]}),x=new fe({value:[h,new ht({valueHex:u})]}).toBER(),y=new Uint8Array(x,0,x.byteLength);return["-----BEGIN ENCRYPTED PRIVATE KEY-----",...H(y,"base64pad").split(/(.{64})/).filter(Boolean),"-----END ENCRYPTED PRIVATE KEY-----"].join(`
|
|
7
|
+
`)}async function id(r,e){let t=Be.get(),n;if(r.includes("-----BEGIN ENCRYPTED PRIVATE KEY-----")){let s=$(r.replace("-----BEGIN ENCRYPTED PRIVATE KEY-----","").replace("-----END ENCRYPTED PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:i}=Ar(s),{iv:o,salt:a,iterations:c,keySize:f,cipherText:u}=od(i),l=await Wi(Mr,e,a,{c,dkLen:f}),h=await t.subtle.importKey("raw",l,"AES-CBC",!1,["decrypt"]),m=tn(await t.subtle.decrypt({name:"AES-CBC",iv:o},h,u)),{result:x}=Ar(m);n=Kc(x)}else if(r.includes("-----BEGIN PRIVATE KEY-----")){let s=$(r.replace("-----BEGIN PRIVATE KEY-----","").replace("-----END PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:i}=Ar(s);n=Kc(i)}else throw new R("Could not parse private key from PEM data","ERR_INVALID_PARAMETERS");return to(n)}function od(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=tn(i.valueBlock.value[0].getValue()),a=eo,c=Qi;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=tn(f.valueBlock.value[1].getValue());return{cipherText:tn(r.valueBlock.value[1].getValue()),salt:o,iterations:a,keySize:c,iv:l}}function Kc(r){return tn(r.valueBlock.value[2].getValue())}function tn(r){return new Uint8Array(r,0,r.byteLength)}async function Fc(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 zc(e);return{privateKey:t[0],publicKey:t[1]}}async function ro(r){let t=[await Be.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),await ad(r)],n=await zc({privateKey:t[0],publicKey:t[1]});return{privateKey:n[0],publicKey:n[1]}}async function qc(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 $c(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 zc(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 ad(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 As(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 $(r.n,"base64url").length*8}var nn=8192,rn=class{_key;constructor(e){this._key=e}verify(e,t){return $c(this._key,t,e)}marshal(){return Ct.jwkToPkix(this._key)}get bytes(){return Ze.encode({Type:X.RSA,Data:this.marshal()}).subarray()}equals(e){return ee(this.bytes,e.bytes)}hash(){let e=pe.digest(this.bytes);return Ve(e)?e.then(({bytes:t})=>t):e.bytes}},kr=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t}genSecret(){return Zt(16)}sign(e){return qc(this._key,e)}get public(){if(this._publicKey==null)throw new R("public key not provided","ERR_PUBKEY_NOT_PROVIDED");return new rn(this._publicKey)}marshal(){return Ct.jwkToPkcs1(this._key)}get bytes(){return Je.encode({Type:X.RSA,Data:this.marshal()}).subarray()}equals(e){return ee(this.bytes,e.bytes)}hash(){let e=pe.digest(this.bytes);return Ve(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return H(e,"base58btc")}async export(e,t="pkcs-8"){if(t==="pkcs-8")return Ct.exportToPem(this,e);if(t==="libp2p-key")return br(this.bytes,e);throw new R(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};async function to(r){let e=Ct.pkcs1ToJwk(r);if(As(e)>nn)throw new R("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await ro(e);return new kr(t.privateKey,t.publicKey)}function ld(r){let e=Ct.pkixToJwk(r);if(As(e)>nn)throw new R("key size is too large","ERR_KEY_SIZE_TOO_LARGE");return new rn(e)}async function ud(r){if(As(r)>nn)throw new R("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await ro(r);return new kr(e.privateKey,e.publicKey)}async function fd(r){if(r>nn)throw new R("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await Fc(r);return new kr(e.privateKey,e.publicKey)}var co={};ue(co,{Secp256k1PrivateKey:()=>on,Secp256k1PublicKey:()=>sn,generateKeyPair:()=>Ad,unmarshalSecp256k1PrivateKey:()=>Ed,unmarshalSecp256k1PublicKey:()=>Bd});var hd=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]),Ut=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Pt=new Uint32Array(64),so=class extends pr{constructor(){super(64,32,8,!1),this.A=Ut[0]|0,this.B=Ut[1]|0,this.C=Ut[2]|0,this.D=Ut[3]|0,this.E=Ut[4]|0,this.F=Ut[5]|0,this.G=Ut[6]|0,this.H=Ut[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)Pt[l]=e.getUint32(t,!1);for(let l=16;l<64;l++){let h=Pt[l-15],m=Pt[l-2],x=He(h,7)^He(h,18)^h>>>3,y=He(m,17)^He(m,19)^m>>>10;Pt[l]=y+Pt[l-7]+x+Pt[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+ka(a,c,f)+hd[l]+Pt[l]|0,y=(He(n,2)^He(n,13)^He(n,22))+Sa(n,s,i)|0;u=f,f=c,c=a,a=o+m|0,o=i,i=s,s=n,n=m+y|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(){Pt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Gc=En(()=>new so);function jc(r){r.lowS!==void 0&&Ke("lowS",r.lowS),r.prehash!==void 0&&Ke("prehash",r.prehash)}function dd(r){let e=Fr(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:pd,hexToBytes:gd}=kn,mt={Err:class extends Error{constructor(e=""){super(e)}},_tlv:{encode:(r,e)=>{let{Err:t}=mt;if(r<0||r>256)throw new t("tlv.encode: wrong tag");if(e.length&1)throw new t("tlv.encode: unpadded data");let n=e.length/2,s=Kt(n);if(s.length/2&128)throw new t("tlv.encode: long form length too big");let i=n>127?Kt(s.length/2|128):"";return`${Kt(r)}${i}${s}${e}`},decode(r,e){let{Err:t}=mt,n=0;if(r<0||r>256)throw new t("tlv.encode: wrong tag");if(e.length<2||e[n++]!==r)throw new t("tlv.decode: wrong tlv");let s=e[n++],i=!!(s&128),o=0;if(!i)o=s;else{let c=s&127;if(!c)throw new t("tlv.decode(long): indefinite length not supported");if(c>4)throw new t("tlv.decode(long): byte length is too big");let f=e.subarray(n,n+c);if(f.length!==c)throw new t("tlv.decode: length bytes not complete");if(f[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(let u of f)o=o<<8|u;if(n+=c,o<128)throw new t("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+o);if(a.length!==o)throw new t("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+o)}}},_int:{encode(r){let{Err:e}=mt;if(r<yt)throw new e("integer: negative integers are not allowed");let t=Kt(r);if(Number.parseInt(t[0],16)&8&&(t="00"+t),t.length&1)throw new e("unexpected assertion");return t},decode(r){let{Err:e}=mt;if(r[0]&128)throw new e("Invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new e("Invalid signature integer: unnecessary leading zero");return pd(r)}},toSig(r){let{Err:e,_int:t,_tlv:n}=mt,s=typeof r=="string"?gd(r):r;gr(s);let{v:i,l:o}=n.decode(48,s);if(o.length)throw new e("Invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:f,l:u}=n.decode(2,c);if(u.length)throw new e("Invalid signature: left bytes after parsing");return{r:t.decode(a),s:t.decode(f)}},hexFromSig(r){let{_tlv:e,_int:t}=mt,n=`${e.encode(2,t.encode(r.r))}${e.encode(2,t.encode(r.s))}`;return e.encode(48,n)}},yt=BigInt(0),he=BigInt(1),mm=BigInt(2),Wc=BigInt(3),ym=BigInt(4);function md(r){let e=dd(r),{Fp:t}=e,n=Rt(e.n,e.nBitLength),s=e.toBytes||((y,d,w)=>{let E=d.toAffine();return ct(Uint8Array.from([4]),t.toBytes(E.x),t.toBytes(E.y))}),i=e.fromBytes||(y=>{let d=y.subarray(1),w=t.fromBytes(d.subarray(0,t.BYTES)),E=t.fromBytes(d.subarray(t.BYTES,2*t.BYTES));return{x:w,y:E}});function o(y){let{a:d,b:w}=e,E=t.sqr(y),g=t.mul(E,y);return t.add(t.add(g,t.mul(y,d)),w)}if(!t.eql(t.sqr(e.Gy),o(e.Gx)))throw new Error("bad generator point: equation left != right");function a(y){return Hr(y,he,e.n)}function c(y){let{allowedPrivateKeyLengths:d,nByteLength:w,wrapPrivateKey:E,n:g}=e;if(d&&typeof y!="bigint"){if(kt(y)&&(y=ot(y)),typeof y!="string"||!d.includes(y.length))throw new Error("Invalid key");y=y.padStart(w*2,"0")}let B;try{B=typeof y=="bigint"?y:at(te("private key",y,w))}catch{throw new Error(`private key must be ${w} bytes, hex or bigint, not ${typeof y}`)}return E&&(B=j(B,g)),_e("private key",B,he,g),B}function f(y){if(!(y instanceof h))throw new Error("ProjectivePoint expected")}let u=$t((y,d)=>{let{px:w,py:E,pz:g}=y;if(t.eql(g,t.ONE))return{x:w,y:E};let B=y.is0();d==null&&(d=B?t.ONE:t.inv(g));let C=t.mul(w,d),L=t.mul(E,d),S=t.mul(g,d);if(B)return{x:t.ZERO,y:t.ZERO};if(!t.eql(S,t.ONE))throw new Error("invZ was invalid");return{x:C,y:L}}),l=$t(y=>{if(y.is0()){if(e.allowInfinityPoint&&!t.is0(y.py))return;throw new Error("bad point: ZERO")}let{x:d,y:w}=y.toAffine();if(!t.isValid(d)||!t.isValid(w))throw new Error("bad point: x or y not FE");let E=t.sqr(w),g=o(d);if(!t.eql(E,g))throw new Error("bad point: equation left != right");if(!y.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class h{constructor(d,w,E){if(this.px=d,this.py=w,this.pz=E,d==null||!t.isValid(d))throw new Error("x required");if(w==null||!t.isValid(w))throw new Error("y required");if(E==null||!t.isValid(E))throw new Error("z required");Object.freeze(this)}static fromAffine(d){let{x:w,y:E}=d||{};if(!d||!t.isValid(w)||!t.isValid(E))throw new Error("invalid affine point");if(d instanceof h)throw new Error("projective point not allowed");let g=B=>t.eql(B,t.ZERO);return g(w)&&g(E)?h.ZERO:new h(w,E,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){let w=t.invertBatch(d.map(E=>E.pz));return d.map((E,g)=>E.toAffine(w[g])).map(h.fromAffine)}static fromHex(d){let w=h.fromAffine(i(te("pointHex",d)));return w.assertValidity(),w}static fromPrivateKey(d){return h.BASE.multiply(c(d))}static msm(d,w){return Rn(h,n,d,w)}_setWindowSize(d){x.setWindowSize(this,d)}assertValidity(){l(this)}hasEvenY(){let{y:d}=this.toAffine();if(t.isOdd)return!t.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){f(d);let{px:w,py:E,pz:g}=this,{px:B,py:C,pz:L}=d,S=t.eql(t.mul(w,L),t.mul(B,g)),I=t.eql(t.mul(E,L),t.mul(C,g));return S&&I}negate(){return new h(this.px,t.neg(this.py),this.pz)}double(){let{a:d,b:w}=e,E=t.mul(w,Wc),{px:g,py:B,pz:C}=this,L=t.ZERO,S=t.ZERO,I=t.ZERO,_=t.mul(g,g),ne=t.mul(B,B),q=t.mul(C,C),V=t.mul(g,B);return V=t.add(V,V),I=t.mul(g,C),I=t.add(I,I),L=t.mul(d,I),S=t.mul(E,q),S=t.add(L,S),L=t.sub(ne,S),S=t.add(ne,S),S=t.mul(L,S),L=t.mul(V,L),I=t.mul(E,I),q=t.mul(d,q),V=t.sub(_,q),V=t.mul(d,V),V=t.add(V,I),I=t.add(_,_),_=t.add(I,_),_=t.add(_,q),_=t.mul(_,V),S=t.add(S,_),q=t.mul(B,C),q=t.add(q,q),_=t.mul(q,V),L=t.sub(L,_),I=t.mul(q,ne),I=t.add(I,I),I=t.add(I,I),new h(L,S,I)}add(d){f(d);let{px:w,py:E,pz:g}=this,{px:B,py:C,pz:L}=d,S=t.ZERO,I=t.ZERO,_=t.ZERO,ne=e.a,q=t.mul(e.b,Wc),V=t.mul(w,B),se=t.mul(E,C),A=t.mul(g,L),N=t.add(w,E),b=t.add(B,C);N=t.mul(N,b),b=t.add(V,se),N=t.sub(N,b),b=t.add(w,g);let p=t.add(B,L);return b=t.mul(b,p),p=t.add(V,A),b=t.sub(b,p),p=t.add(E,g),S=t.add(C,L),p=t.mul(p,S),S=t.add(se,A),p=t.sub(p,S),_=t.mul(ne,b),S=t.mul(q,A),_=t.add(S,_),S=t.sub(se,_),_=t.add(se,_),I=t.mul(S,_),se=t.add(V,V),se=t.add(se,V),A=t.mul(ne,A),b=t.mul(q,b),se=t.add(se,A),A=t.sub(V,A),A=t.mul(ne,A),b=t.add(b,A),V=t.mul(se,b),I=t.add(I,V),V=t.mul(p,b),S=t.mul(N,S),S=t.sub(S,V),V=t.mul(N,se),_=t.mul(p,_),_=t.add(_,V),new h(S,I,_)}subtract(d){return this.add(d.negate())}is0(){return this.equals(h.ZERO)}wNAF(d){return x.wNAFCached(this,d,h.normalizeZ)}multiplyUnsafe(d){_e("scalar",d,yt,e.n);let w=h.ZERO;if(d===yt)return w;if(d===he)return this;let{endo:E}=e;if(!E)return x.unsafeLadder(this,d);let{k1neg:g,k1:B,k2neg:C,k2:L}=E.splitScalar(d),S=w,I=w,_=this;for(;B>yt||L>yt;)B&he&&(S=S.add(_)),L&he&&(I=I.add(_)),_=_.double(),B>>=he,L>>=he;return g&&(S=S.negate()),C&&(I=I.negate()),I=new h(t.mul(I.px,E.beta),I.py,I.pz),S.add(I)}multiply(d){let{endo:w,n:E}=e;_e("scalar",d,he,E);let g,B;if(w){let{k1neg:C,k1:L,k2neg:S,k2:I}=w.splitScalar(d),{p:_,f:ne}=this.wNAF(L),{p:q,f:V}=this.wNAF(I);_=x.constTimeNegate(C,_),q=x.constTimeNegate(S,q),q=new h(t.mul(q.px,w.beta),q.py,q.pz),g=_.add(q),B=ne.add(V)}else{let{p:C,f:L}=this.wNAF(d);g=C,B=L}return h.normalizeZ([g,B])[0]}multiplyAndAddUnsafe(d,w,E){let g=h.BASE,B=(L,S)=>S===yt||S===he||!L.equals(g)?L.multiplyUnsafe(S):L.multiply(S),C=B(this,w).add(B(d,E));return C.is0()?void 0:C}toAffine(d){return u(this,d)}isTorsionFree(){let{h:d,isTorsionFree:w}=e;if(d===he)return!0;if(w)return w(h,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:d,clearCofactor:w}=e;return d===he?this:w?w(h,this):this.multiplyUnsafe(e.h)}toRawBytes(d=!0){return Ke("isCompressed",d),this.assertValidity(),s(h,this,d)}toHex(d=!0){return Ke("isCompressed",d),ot(this.toRawBytes(d))}}h.BASE=new h(e.Gx,e.Gy,t.ONE),h.ZERO=new h(t.ZERO,t.ONE,t.ZERO);let m=e.nBitLength,x=In(h,e.endo?Math.ceil(m/2):m);return{CURVE:e,ProjectivePoint:h,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:a}}function yd(r){let e=Fr(r);return We(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function Yc(r){let e=yd(r),{Fp:t,n}=e,s=t.BYTES+1,i=2*t.BYTES+1;function o(A){return j(A,n)}function a(A){return Sn(A,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:f,weierstrassEquation:u,isWithinCurveOrder:l}=md({...e,toBytes(A,N,b){let p=N.toAffine(),v=t.toBytes(p.x),T=ct;return Ke("isCompressed",b),b?T(Uint8Array.from([N.hasEvenY()?2:3]),v):T(Uint8Array.from([4]),v,t.toBytes(p.y))},fromBytes(A){let N=A.length,b=A[0],p=A.subarray(1);if(N===s&&(b===2||b===3)){let v=at(p);if(!Hr(v,he,t.ORDER))throw new Error("Point is not on curve");let T=u(v),U;try{U=t.sqrt(T)}catch(F){let M=F instanceof Error?": "+F.message:"";throw new Error("Point is not on curve"+M)}let P=(U&he)===he;return(b&1)===1!==P&&(U=t.neg(U)),{x:v,y:U}}else if(N===i&&b===4){let v=t.fromBytes(p.subarray(0,t.BYTES)),T=t.fromBytes(p.subarray(t.BYTES,2*t.BYTES));return{x:v,y:T}}else throw new Error(`Point of length ${N} was invalid. Expected ${s} compressed bytes or ${i} uncompressed bytes`)}}),h=A=>ot(It(A,e.nByteLength));function m(A){let N=n>>he;return A>N}function x(A){return m(A)?o(-A):A}let y=(A,N,b)=>at(A.slice(N,b));class d{constructor(N,b,p){this.r=N,this.s=b,this.recovery=p,this.assertValidity()}static fromCompact(N){let b=e.nByteLength;return N=te("compactSignature",N,b*2),new d(y(N,0,b),y(N,b,2*b))}static fromDER(N){let{r:b,s:p}=mt.toSig(te("DER",N));return new d(b,p)}assertValidity(){_e("r",this.r,he,n),_e("s",this.s,he,n)}addRecoveryBit(N){return new d(this.r,this.s,N)}recoverPublicKey(N){let{r:b,s:p,recovery:v}=this,T=L(te("msgHash",N));if(v==null||![0,1,2,3].includes(v))throw new Error("recovery id invalid");let U=v===2||v===3?b+e.n:b;if(U>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let P=v&1?"03":"02",O=c.fromHex(P+h(U)),F=a(U),M=o(-T*F),G=o(p*F),Y=c.BASE.multiplyAndAddUnsafe(O,M,G);if(!Y)throw new Error("point at infinify");return Y.assertValidity(),Y}hasHighS(){return m(this.s)}normalizeS(){return this.hasHighS()?new d(this.r,o(-this.s),this.recovery):this}toDERRawBytes(){return Ft(this.toDERHex())}toDERHex(){return mt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Ft(this.toCompactHex())}toCompactHex(){return h(this.r)+h(this.s)}}let w={isValidPrivateKey(A){try{return f(A),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let A=Ei(e.n);return Ua(e.randomBytes(A),e.n)},precompute(A=8,N=c.BASE){return N._setWindowSize(A),N.multiply(BigInt(3)),N}};function E(A,N=!0){return c.fromPrivateKey(A).toRawBytes(N)}function g(A){let N=kt(A),b=typeof A=="string",p=(N||b)&&A.length;return N?p===s||p===i:b?p===2*s||p===2*i:A instanceof c}function B(A,N,b=!0){if(g(A))throw new Error("first arg must be private key");if(!g(N))throw new Error("second arg must be public key");return c.fromHex(N).multiply(f(A)).toRawBytes(b)}let C=e.bits2int||function(A){let N=at(A),b=A.length*8-e.nBitLength;return b>0?N>>BigInt(b):N},L=e.bits2int_modN||function(A){return o(C(A))},S=Kr(e.nBitLength);function I(A){return _e(`num < 2^${e.nBitLength}`,A,yt,S),It(A,e.nByteLength)}function _(A,N,b=ne){if(["recovered","canonical"].some(le=>le in b))throw new Error("sign() legacy options not supported");let{hash:p,randomBytes:v}=e,{lowS:T,prehash:U,extraEntropy:P}=b;T==null&&(T=!0),A=te("msgHash",A),jc(b),U&&(A=te("prehashed msgHash",p(A)));let O=L(A),F=f(N),M=[I(F),I(O)];if(P!=null&&P!==!1){let le=P===!0?v(t.BYTES):P;M.push(te("extraEntropy",le))}let G=ct(...M),Y=O;function ce(le){let de=C(le);if(!l(de))return;let ve=a(de),ie=c.BASE.multiply(de).toAffine(),Ne=o(ie.x);if(Ne===yt)return;let tt=o(ve*o(Y+Ne*F));if(tt===yt)return;let Ur=(ie.x===Ne?0:2)|Number(ie.y&he),Pr=tt;return T&&m(tt)&&(Pr=x(tt),Ur^=1),new d(Ne,Pr,Ur)}return{seed:G,k2sig:ce}}let ne={lowS:e.lowS,prehash:!1},q={lowS:e.lowS,prehash:!1};function V(A,N,b=ne){let{seed:p,k2sig:v}=_(A,N,b),T=e;return bi(T.hash.outputLen,T.nByteLength,T.hmac)(p,v)}c.BASE._setWindowSize(8);function se(A,N,b,p=q){let v=A;if(N=te("msgHash",N),b=te("publicKey",b),"strict"in p)throw new Error("options.strict was renamed to lowS");jc(p);let{lowS:T,prehash:U}=p,P,O;try{if(typeof v=="string"||kt(v))try{P=d.fromDER(v)}catch(ie){if(!(ie instanceof mt.Err))throw ie;P=d.fromCompact(v)}else if(typeof v=="object"&&typeof v.r=="bigint"&&typeof v.s=="bigint"){let{r:ie,s:Ne}=v;P=new d(ie,Ne)}else throw new Error("PARSE");O=c.fromHex(b)}catch(ie){if(ie.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(T&&P.hasHighS())return!1;U&&(N=e.hash(N));let{r:F,s:M}=P,G=L(N),Y=a(M),ce=o(G*Y),le=o(F*Y),de=c.BASE.multiplyAndAddUnsafe(O,ce,le)?.toAffine();return de?o(de.x)===F:!1}return{CURVE:e,getPublicKey:E,getSharedSecret:B,sign:V,verify:se,ProjectivePoint:c,Signature:d,utils:w}}function bd(r){return{hash:r,hmac:(e,...t)=>Gr(r,e,ui(...t)),randomBytes:dr}}function Zc(r,e){let t=n=>Yc({...r,...bd(n)});return Object.freeze({...t(e),create:t})}var Qc=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Jc=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),wd=BigInt(1),io=BigInt(2),Xc=(r,e)=>(r+e/io)/e;function xd(r){let e=Qc,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,io,e)*f%e,x=J(m,s,e)*m%e,y=J(x,i,e)*x%e,d=J(y,a,e)*y%e,w=J(d,c,e)*d%e,E=J(w,a,e)*y%e,g=J(E,t,e)*u%e,B=J(g,o,e)*x%e,C=J(B,n,e)*f%e,L=J(C,io,e);if(!oo.eql(oo.sqr(L),r))throw new Error("Cannot find square root");return L}var oo=Rt(Qc,void 0,void 0,{sqrt:xd}),Ge=Zc({a:BigInt(0),b:BigInt(7),Fp:oo,n:Jc,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=Jc,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-wd*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=t,o=BigInt("0x100000000000000000000000000000000"),a=Xc(i*r,e),c=Xc(-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}}}},Gc),Sm=BigInt(0);var Im=Ge.ProjectivePoint;function el(){return Ge.utils.randomPrivateKey()}function tl(r,e){let t=pe.digest(e instanceof Uint8Array?e:e.subarray());if(Ve(t))return t.then(({digest:n})=>Ge.sign(n,r).toDERRawBytes()).catch(n=>{throw new R(String(n),"ERR_INVALID_INPUT")});try{return Ge.sign(t.digest,r).toDERRawBytes()}catch(n){throw new R(String(n),"ERR_INVALID_INPUT")}}function rl(r,e,t){let n=pe.digest(t instanceof Uint8Array?t:t.subarray());if(Ve(n))return n.then(({digest:s})=>Ge.verify(e,s,r)).catch(s=>{throw new R(String(s),"ERR_INVALID_INPUT")});try{return Ge.verify(e,n.digest,r)}catch(s){throw new R(String(s),"ERR_INVALID_INPUT")}}function nl(r){return Ge.ProjectivePoint.fromHex(r).toRawBytes(!0)}function sl(r){try{Ge.getPublicKey(r,!0)}catch(e){throw new R(String(e),"ERR_INVALID_PRIVATE_KEY")}}function ao(r){try{Ge.ProjectivePoint.fromHex(r)}catch(e){throw new R(String(e),"ERR_INVALID_PUBLIC_KEY")}}function il(r){try{return Ge.getPublicKey(r,!0)}catch(e){throw new R(String(e),"ERR_INVALID_PRIVATE_KEY")}}var sn=class{_key;constructor(e){ao(e),this._key=e}verify(e,t){return rl(this._key,t,e)}marshal(){return nl(this._key)}get bytes(){return Ze.encode({Type:X.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return ee(this.bytes,e.bytes)}async hash(){let e=pe.digest(this.bytes),t;return Ve(e)?{bytes:t}=await e:t=e.bytes,t}},on=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t??il(e),sl(this._key),ao(this._publicKey)}sign(e){return tl(this._key,e)}get public(){return new sn(this._publicKey)}marshal(){return this._key}get bytes(){return Je.encode({Type:X.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return ee(this.bytes,e.bytes)}hash(){let e=pe.digest(this.bytes);return Ve(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return H(e,"base58btc")}async export(e,t="libp2p-key"){if(t==="libp2p-key")return br(this.bytes,e);throw new R(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function Ed(r){return new on(r)}function Bd(r){return new sn(r)}async function Ad(){let r=el();return new on(r)}var Xt={rsa:no,ed25519:ji,secp256k1:co};function ol(r){let e=Object.keys(Xt).join(" / ");return new R(`invalid or unsupported key type ${r}. Must be ${e}`,"ERR_UNSUPPORTED_KEY_TYPE")}function al(r){let e=Ze.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case X.RSA:return Xt.rsa.unmarshalRsaPublicKey(t);case X.Ed25519:return Xt.ed25519.unmarshalEd25519PublicKey(t);case X.Secp256k1:return Xt.secp256k1.unmarshalSecp256k1PublicKey(t);default:throw ol(e.Type??"unknown")}}async function cl(r){let e=Je.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case X.RSA:return Xt.rsa.unmarshalRsaPrivateKey(t);case X.Ed25519:return Xt.ed25519.unmarshalEd25519PrivateKey(t);case X.Secp256k1:return Xt.secp256k1.unmarshalSecp256k1PrivateKey(t);default:throw ol(e.Type??"RSA")}}var ul=Symbol.for("nodejs.util.inspect.custom"),ll=Object.values(vt).map(r=>r.decoder).reduce((r,e)=>r.or(e),vt.identity.decoder),fl=114,fo=36,ho=37,an=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()})`}[bn]=!0;toString(){return this.string==null&&(this.string=oe.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return De.createV1(fl,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 cn(e).equals(this);if(e?.multihash?.bytes!=null)return ee(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[ul](){return`PeerId(${this.toString()})`}},Qt=class extends an{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},er=class extends an{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}},tr=class extends an{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}},lo=2336,uo=class{type="url";multihash;privateKey;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=nt.digest($(this.url))}[ul](){return`PeerId(${this.url})`}[bn]=!0;toString(){return this.toCID().toString()}toCID(){return De.createV1(lo,this.multihash)}toBytes(){return this.toCID().bytes}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=H(e)),e.toString()===this.toString())}};function hl(r){if(r.type==="RSA")return new Qt(r);if(r.type==="Ed25519")return new er(r);if(r.type==="secp256k1")return new tr(r);throw new R("Not a PeerId","ERR_INVALID_PARAMETERS")}function cn(r,e){if(e=e??ll,r.charAt(0)==="1"||r.charAt(0)==="Q"){let t=Ot(oe.decode(`z${r}`));return r.startsWith("12D")?new er({multihash:t}):r.startsWith("16U")?new tr({multihash:t}):new Qt({multihash:t})}return ln(ll.decode(r))}function ln(r){try{let e=Ot(r);if(e.code===nt.code){if(e.digest.length===fo)return new er({multihash:e});if(e.digest.length===ho)return new tr({multihash:e})}if(e.code===pe.code)return new Qt({multihash:e})}catch{return kd(De.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function kd(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==fl&&r.code!==lo)throw new Error("Supplied PeerID CID is invalid");if(r.code===lo){let t=H(r.multihash.digest);return new uo(new URL(t))}let e=r.multihash;if(e.code===pe.code)return new Qt({multihash:r.multihash});if(e.code===nt.code){if(e.digest.length===fo)return new er({multihash:r.multihash});if(e.digest.length===ho)return new tr({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function dl(r,e){return r.length===fo?new er({multihash:je(nt.code,r),privateKey:e}):r.length===ho?new tr({multihash:je(nt.code,r),privateKey:e}):new Qt({multihash:await pe.digest(r),publicKey:r,privateKey:e})}var gl=Symbol.for("@achingbrain/uint8arraylist");function pl(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 ks(r){return!!r?.[gl]}var Ss=class r{bufs;length;[gl]=!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(ks(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(ks(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=pl(this.bufs,e);return t.buf[t.index]}set(e,t){let n=pl(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(ks(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(!ks(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=Te(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=st(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=st(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=st(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=Te(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=st(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=st(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=st(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=st(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=st(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 ml={ERR_SIGNATURE_NOT_VALID:"ERR_SIGNATURE_NOT_VALID"};var un;(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())})(un||(un={}));var Sr=class r{static createFromProtobuf=async e=>{let t=un.decode(e),n=await dl(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=yl(n,s,i),c=await(await cl(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",ml.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=un.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=yl(e,this.payloadType,this.payload);if(this.peerId.publicKey==null)throw new Error("Missing public key");return al(this.peerId.publicKey).verify(t.subarray(),this.signature)}},yl=(r,e,t)=>{let n=$(r),s=Ye(n.byteLength),i=Ye(e.length),o=Ye(t.length);return new Ss(s,n,i,e,o,t)};function bl(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 Is=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 wl=45,Sd=15,Ir=new Is;function po(r){if(!(r.length>Sd))return Ir.new(r).parseWith(()=>Ir.readIPv4Addr())}function go(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>wl))return Ir.new(r).parseWith(()=>Ir.readIPv6Addr())}function Rs(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>wl))return Ir.new(r).parseWith(()=>Ir.readIPAddr())}var Ay=parseInt("0xFFFF",16),ky=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function El(r){return!!po(r)}function Bl(r){return!!go(r)}function Ns(r){return!!Rs(r)}var Al=El,_d=Bl,mo=function(r){let e=0;if(r=r.toString().trim(),Al(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(_d(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=Al(t[n]),o;i&&(o=mo(t[n]),t[n]=H(o.slice(0,2),"base16")),o!=null&&++n<8&&t.splice(n,0,H(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")},kl=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 Rr={},yo={},Cd=[[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"]];Cd.forEach(r=>{let e=Ud(...r);yo[e.code]=e,Rr[e.name]=e});function Ud(r,e,t,n,s){return{code:r,size:e,name:t,resolvable:!!n,path:!!s}}function W(r){if(typeof r=="number"){if(yo[r]!=null)return yo[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Rr[r]!=null)return Rr[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var cb=W("ip4"),lb=W("ip6"),ub=W("ipcidr");function vo(r,e){switch(W(r).code){case 4:case 41:return Dd(e);case 42:return xo(e);case 6:case 273:case 33:case 132:return Rl(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return xo(e);case 421:return Hd(e);case 444:return Il(e);case 445:return Il(e);case 466:return Md(e);case 481:return globalThis.encodeURIComponent(xo(e));default:return H(e,"base16")}}function Eo(r,e){switch(W(r).code){case 4:return Sl(e);case 41:return Sl(e);case 42:return wo(e);case 6:case 273:case 33:case 132:return Bo(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return wo(e);case 421:return Vd(e);case 444:return Kd(e);case 445:return Fd(e);case 466:return Od(e);case 481:return wo(globalThis.decodeURIComponent(e));default:return $(e,"base16")}}var bo=Object.values(vt).map(r=>r.decoder),Pd=function(){let r=bo[0].or(bo[1]);return bo.slice(2).forEach(e=>r=r.or(e)),r}();function Sl(r){if(!Ns(r))throw new Error("invalid ip address");return mo(r)}function Dd(r){let e=kl(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!Ns(e))throw new Error("invalid ip address");return e}function Bo(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function Rl(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function wo(r){let e=$(r),t=Uint8Array.from(Ye(e.length));return Ee([t,e],t.length+e.length)}function xo(r){let e=Gt(r);if(r=r.slice(Ce(e)),r.length!==e)throw new Error("inconsistent lengths");return H(r)}function Vd(r){let e;r[0]==="Q"||r[0]==="1"?e=Ot(oe.decode(`z${r}`)).bytes:e=De.parse(r).multihash.bytes;let t=Uint8Array.from(Ye(e.length));return Ee([t,e],t.length+e.length)}function Od(r){let e=Pd.decode(r),t=Uint8Array.from(Ye(e.length));return Ee([t,e],t.length+e.length)}function Md(r){let e=Gt(r),t=r.slice(Ce(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+H(t,"base64url")}function Hd(r){let e=Gt(r),t=r.slice(Ce(e));if(t.length!==e)throw new Error("inconsistent lengths");return H(t,"base58btc")}function Kd(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=Bo(n);return Ee([t,s],t.length+s.length)}function Fd(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=Bo(n);return Ee([t,s],t.length+s.length)}function Il(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=H(e,"base32"),s=Rl(t);return`${n}:${s}`}function Nl(r){r=Ao(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=W(o);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(i++,i>=s.length)throw _l("invalid address: "+r);if(a.path===!0){n=Ao(s.slice(i).join("/")),e.push([a.code,Eo(a.code,n)]),t.push([a.code,n]);break}let c=Eo(a.code,s[i]);e.push([a.code,c]),t.push([a.code,vo(a.code,c)])}return{string:Tl(t),bytes:So(e),tuples:e,stringTuples:t,path:n}}function ko(r){let e=[],t=[],n=null,s=0;for(;s<r.length;){let i=Gt(r,s),o=Ce(i),a=W(i),c=qd(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 _l("Invalid address Uint8Array: "+H(r,"base16"));e.push([i,f]);let u=vo(i,f);if(t.push([i,u]),a.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:Tl(t),tuples:e,stringTuples:t,path:n}}function Tl(r){let e=[];return r.map(t=>{let n=W(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),Ao(e.join("/"))}function So(r){return Ee(r.map(e=>{let t=W(e[0]),n=Uint8Array.from(Ye(t.code));return e.length>1&&e[1]!=null&&(n=Ee([n,e[1]])),n}))}function qd(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=Gt(e instanceof Uint8Array?e:Uint8Array.from(e));return t+Ce(t)}}function Ao(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function _l(r){return new Error("Error parsing address: "+r)}var $d=Symbol.for("nodejs.util.inspect.custom"),Io=Symbol.for("@multiformats/js-multiaddr/multiaddr"),zd=[W("dns").code,W("dns4").code,W("dns6").code,W("dnsaddr").code],Ts=class r{bytes;#e;#t;#i;#a;[Io]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=ko(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=Nl(e)}else if(_s(e))t=ko(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=W("tcp"),a=W("udp"),c=W("ip4"),f=W("ip6"),u=W("dns6"),l=W("ip6zone");for(let[m,x]of this.stringTuples())m===l.code&&(i=`%${x??""}`),zd.includes(m)&&(t=o.name,s=443,n=`${x??""}${i}`,e=m===u.code?6:4),(m===o.code||m===a.code)&&(t=W(m).name,s=parseInt(x??"")),(m===c.code||m===f.code)&&(t=W(m).name,n=`${x??""}${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({},W(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>W(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(So(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,s])=>{n===Rr.p2p.code&&e.push([n,s]),n===Rr["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?H(oe.decode(`z${n}`),"base58btc"):H(De.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=Ll.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=>bt(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)}[$d](){return`Multiaddr(${this.#e})`}};var Ll=new Map;function _s(r){return!!r?.[Io]}function bt(r){return new Ts(r)}var Cl="libp2p-peer-record",Ul=Uint8Array.from([3,1]);var fn;(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())})(fn||(fn={}));var rr=class r{static createFromProtobuf=e=>{let t=fn.decode(e),n=ln(t.peerId),s=(t.addresses??[]).map(o=>bt(o.multiaddr)),i=t.seq;return new r({peerId:n,multiaddrs:s,seqNumber:i})};static DOMAIN=Cl;static CODEC=Ul;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=fn.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||!bl(this.multiaddrs,e.multiaddrs))}};function Gd(r){return r[Symbol.asyncIterator]!=null}function jd(r){if(Gd(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 Pl=jd;function Ro(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 hn=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 Ro(this.map.entries(),e=>[cn(e[0]),e[1]])}forEach(e){this.map.forEach((t,n)=>{e(t,cn(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 Ro(this.map.keys(),e=>cn(e))}values(){return this.map.values()}get size(){return this.map.size}};var To=Qo(Vl(),1);var pn=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},_o=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Ol=r=>globalThis.DOMException===void 0?new _o(r):new DOMException(r),Ml=r=>{let e=r.reason===void 0?Ol("This operation was aborted."):r.reason;return e instanceof Error?e:Ol(e)};function gn(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(Ml(h)),h.addEventListener("abort",()=>{u(Ml(h))})}if(t===Number.POSITIVE_INFINITY){r.then(f,u);return}let l=new pn;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 Lo(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 mn=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=Lo(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 Nr=class extends To.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:mn,...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=gn(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 pn&&!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 Dt={},Tr=r=>{r.addEventListener("message",e=>{Tr.dispatchEvent("message",r,e)}),r.port!=null&&r.port.addEventListener("message",e=>{Tr.dispatchEvent("message",r,e)})};Tr.addEventListener=(r,e)=>{Dt[r]==null&&(Dt[r]=[]),Dt[r].push(e)};Tr.removeEventListener=(r,e)=>{Dt[r]!=null&&(Dt[r]=Dt[r].filter(t=>t===e))};Tr.dispatchEvent=function(r,e,t){Dt[r]!=null&&Dt[r].forEach(n=>n(e,t))};var Co=Tr;var Uo="lock:worker:request-read",Po="lock:worker:release-read",Do="lock:master:grant-read",Vo="lock:worker:request-write",Oo="lock:worker:release-write",Mo="lock:master:grant-write";var Hl=(r=21)=>Math.random().toString().substring(2);var Kl=(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)})}}}))},Fl=(r,e,t,n)=>async()=>{let s=Hl();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)})},Zd={singleProcess:!1},ql=r=>{if(r=Object.assign({},Zd,r),!!globalThis.document||r.singleProcess){let t=new EventTarget;return Co.addEventListener("message",Kl(t,"requestReadLock",Uo,Po,Do)),Co.addEventListener("message",Kl(t,"requestWriteLock",Vo,Oo,Mo)),t}return{isWorker:!0,readLock:t=>Fl(t,Uo,Do,Po),writeLock:t=>Fl(t,Vo,Mo,Oo)}};var nr={},Vt;async function Ho(r,e){let t,n=new Promise(s=>{t=s});return r.add(async()=>gn((async()=>{await new Promise(s=>{t(()=>{s()})})})(),{milliseconds:e.timeout})),n}var Jd=(r,e)=>{if(Vt.isWorker===!0)return{readLock:Vt.readLock(r,e),writeLock:Vt.writeLock(r,e)};let t=new Nr({concurrency:1}),n;return{async readLock(){if(n!=null)return Ho(n,e);n=new Nr({concurrency:e.concurrency,autoStart:!1});let s=n,i=Ho(n,e);return t.add(async()=>{s.start(),await s.onIdle().then(()=>{n===s&&(n=null)})}),i},async writeLock(){return n=null,Ho(t,e)}}},Xd={name:"lock",concurrency:1/0,timeout:846e5,singleProcess:!1};function Ko(r){let e=Object.assign({},Xd,r);return Vt==null&&(Vt=ql(e),Vt.isWorker!==!0&&(Vt.addEventListener("requestReadLock",t=>{nr[t.data.name]!=null&&nr[t.data.name].readLock().then(async n=>t.data.handler().finally(()=>{n()}))}),Vt.addEventListener("requestWriteLock",async t=>{nr[t.data.name]!=null&&nr[t.data.name].writeLock().then(async n=>t.data.handler().finally(()=>{n()}))}))),nr[e.name]==null&&(nr[e.name]=Jd(e.name,e)),nr[e.name]}var me={ERR_INVALID_PARAMETERS:"ERR_INVALID_PARAMETERS"};var _r;(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),Us.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=Us.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),Cs.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(Cs.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())})(_r||(_r={}));var Cs;(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())})(Cs||(Cs={}));var Us;(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())})(Us||(Us={}));function Lr(r,e){let t=_r.decode(e);t.publicKey!=null&&r.publicKey==null&&(r=hl({...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:bt(i),isCertified:o??!1})),metadata:t.metadata,peerRecordEnvelope:t.peerRecordEnvelope??void 0,tags:n}}var wt="/",$l=new TextEncoder().encode(wt),Ps=$l[0],Ds=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=$(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]!==Ps)throw new Error("Invalid key")}toString(e="utf8"){return H(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new r(e.join(wt))}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=$l),this._buf[0]!==Ps){let e=new Uint8Array(this._buf.byteLength+1);e.fill(Ps,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Ps;)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(wt).slice(1)}type(){return Qd(this.baseNamespace())}name(){return ep(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(wt)||(e+=wt),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(wt):new r(e.slice(0,-1).join(wt))}child(e){return this.toString()===wt?e:e.toString()===wt?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(),...tp(e.map(t=>t.namespaces()))])}};function Qd(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function ep(r){let e=r.split(":");return e[e.length-1]}function tp(r){return[].concat(...r)}var Fo="/peers/";function Cr(r){if(!ea(r)||r.type==null)throw new R("Invalid PeerId",me.ERR_INVALID_PARAMETERS);let e=r.toCID().toString();return new Ds(`${Fo}${e}`)}async function zl(r,e,t){let n=new Map;for(let s of t){if(s==null)continue;if(s.multiaddr instanceof Uint8Array&&(s.multiaddr=bt(s.multiaddr)),!_s(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 Os(r,e,t,n){if(e==null)throw new R("Invalid PeerData",me.ERR_INVALID_PARAMETERS);if(e.publicKey!=null&&r.publicKey!=null&&!ee(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=Vs(l,{validate:Gl})}if(e.tags!=null){let l=e.tags instanceof Map?[...e.tags.entries()]:Object.entries(e.tags);c=Vs(l,{validate:jl,map:Wl})}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=Vs([...a.entries()],{validate:Gl})}if(e.tags!=null){let l=e.tags instanceof Map?[...e.tags.entries()]:Object.entries(e.tags),h=new Map(c);for(let[m,x]of l)x==null?h.delete(m):h.set(m,x);c=Vs([...h.entries()],{validate:jl,map:Wl})}e.peerRecordEnvelope!=null&&(f=e.peerRecordEnvelope)}let u={addresses:await zl(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 Vs(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 Gl(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 jl(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 Wl(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 Ms(r,e,t){let n=r.toString().split("/")[2],s=Me.decode(n),i=ln(s),o=t.get(i);if(o!=null)return o;let a=Lr(i,e);return t.set(i,a),a}function rp(r,e){return r==null?{}:{prefix:Fo,filters:(r.filters??[]).map(t=>({key:n,value:s})=>t(Ms(n,s,e))),orders:(r.orders??[]).map(t=>(n,s)=>t(Ms(n.key,n.value,e),Ms(s.key,s.value,e)))}}var Hs=class{peerId;datastore;lock;addressFilter;constructor(e,t={}){this.peerId=e.peerId,this.datastore=e.datastore,this.addressFilter=t.addressFilter,this.lock=Ko({name:"peer-store",singleProcess:!0})}async has(e){return this.datastore.has(Cr(e))}async delete(e){if(this.peerId.equals(e))throw new R("Cannot delete self peer",me.ERR_INVALID_PARAMETERS);await this.datastore.delete(Cr(e))}async load(e){let t=await this.datastore.get(Cr(e));return Lr(e,t)}async save(e,t){let{existingBuf:n,existingPeer:s}=await this.#e(e),i=await Os(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 Os(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 Os(e,t,"merge",{addressFilter:this.addressFilter,existingPeer:s});return this.#t(e,i,n,s)}async*all(e){let t=new hn;for await(let{key:n,value:s}of this.datastore.query(rp(e??{},t))){let i=Ms(n,s,t);i.id.equals(this.peerId)||(yield i)}}async#e(e){try{let t=await this.datastore.get(Cr(e)),n=Lr(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=_r.encode(t);return n!=null&&ee(i,n)?{peer:Lr(e,i),previous:s,updated:!1}:(await this.datastore.put(Cr(e),i),{peer:Lr(e,i),previous:s,updated:!0})}};var qo=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 Hs(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 Pl(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 Sr.openAndCertify(e,rr.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=rr.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 Sr.createFromProtobuf(i.peerRecordEnvelope),a=rr.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 cu(np);})();
|
|
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.5-
|
|
3
|
+
"version": "10.1.5-2265e59ba",
|
|
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.7.0-
|
|
63
|
-
"@libp2p/peer-collections": "5.2.9-
|
|
64
|
-
"@libp2p/peer-id": "4.2.4-
|
|
65
|
-
"@libp2p/peer-record": "7.0.25-
|
|
62
|
+
"@libp2p/interface": "1.7.0-2265e59ba",
|
|
63
|
+
"@libp2p/peer-collections": "5.2.9-2265e59ba",
|
|
64
|
+
"@libp2p/peer-id": "4.2.4-2265e59ba",
|
|
65
|
+
"@libp2p/peer-record": "7.0.25-2265e59ba",
|
|
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.20-
|
|
77
|
-
"@libp2p/peer-id-factory": "4.2.4-
|
|
76
|
+
"@libp2p/logger": "4.0.20-2265e59ba",
|
|
77
|
+
"@libp2p/peer-id-factory": "4.2.4-2265e59ba",
|
|
78
78
|
"@types/sinon": "^17.0.3",
|
|
79
79
|
"aegir": "^44.0.1",
|
|
80
80
|
"datastore-core": "^9.2.9",
|