@libp2p/peer-store 10.1.5 → 11.0.0-18dd3cb26
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 +4 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +6 -4
- package/dist/src/index.js.map +1 -1
- package/dist/src/pb/peer.d.ts +6 -6
- package/dist/src/pb/peer.d.ts.map +1 -1
- package/dist/src/pb/peer.js +76 -38
- package/dist/src/pb/peer.js.map +1 -1
- package/dist/src/store.js +7 -7
- package/dist/src/store.js.map +1 -1
- package/dist/src/utils/bytes-to-peer.d.ts.map +1 -1
- package/dist/src/utils/bytes-to-peer.js +4 -5
- package/dist/src/utils/bytes-to-peer.js.map +1 -1
- package/dist/src/utils/dedupe-addresses.d.ts.map +1 -1
- package/dist/src/utils/dedupe-addresses.js +2 -3
- package/dist/src/utils/dedupe-addresses.js.map +1 -1
- package/dist/src/utils/peer-data-to-datastore-peer.d.ts.map +1 -1
- package/dist/src/utils/peer-data-to-datastore-peer.js +14 -15
- package/dist/src/utils/peer-data-to-datastore-peer.js.map +1 -1
- package/dist/src/utils/peer-id-to-datastore-key.d.ts.map +1 -1
- package/dist/src/utils/peer-id-to-datastore-key.js +2 -3
- package/dist/src/utils/peer-id-to-datastore-key.js.map +1 -1
- package/dist/src/utils/to-peer-pb.d.ts.map +1 -1
- package/dist/src/utils/to-peer-pb.js +24 -15
- package/dist/src/utils/to-peer-pb.js.map +1 -1
- package/package.json +9 -9
- package/src/index.ts +6 -4
- package/src/pb/peer.ts +80 -39
- package/src/store.ts +7 -7
- package/src/utils/bytes-to-peer.ts +4 -5
- package/src/utils/dedupe-addresses.ts +2 -3
- package/src/utils/peer-data-to-datastore-peer.ts +14 -15
- package/src/utils/peer-id-to-datastore-key.ts +2 -3
- package/src/utils/to-peer-pb.ts +24 -16
- package/dist/src/errors.d.ts +0 -4
- package/dist/src/errors.d.ts.map +0 -1
- package/dist/src/errors.js +0 -4
- package/dist/src/errors.js.map +0 -1
- package/dist/typedoc-urls.json +0 -10
- package/src/errors.ts +0 -3
package/dist/index.min.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
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 Fl=Object.create;var Qr=Object.defineProperty;var Kl=Object.getOwnPropertyDescriptor;var ql=Object.getOwnPropertyNames;var $l=Object.getPrototypeOf,zl=Object.prototype.hasOwnProperty;var Ho=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),xt=(r,t)=>{for(var e in t)Qr(r,e,{get:t[e],enumerable:!0})},Fo=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of ql(t))!zl.call(r,s)&&s!==e&&Qr(r,s,{get:()=>t[s],enumerable:!(n=Kl(t,s))||n.enumerable});return r};var Ko=(r,t,e)=>(e=r!=null?Fl($l(r)):{},Fo(t||!r||!r.__esModule?Qr(e,"default",{value:r,enumerable:!0}):e,r)),Gl=r=>Fo(Qr({},"__esModule",{value:!0}),r);var Fa=Ho(rr=>{"use strict";var bh="[object ArrayBuffer]",ne=class r{static isArrayBuffer(t){return Object.prototype.toString.call(t)===bh}static toArrayBuffer(t){return this.isArrayBuffer(t)?t:t.byteLength===t.buffer.byteLength||t.byteOffset===0&&t.byteLength===t.buffer.byteLength?t.buffer:this.toUint8Array(t.buffer).slice(t.byteOffset,t.byteOffset+t.byteLength).buffer}static toUint8Array(t){return this.toView(t,Uint8Array)}static toView(t,e){if(t.constructor===e)return t;if(this.isArrayBuffer(t))return new e(t);if(this.isArrayBufferView(t))return new e(t.buffer,t.byteOffset,t.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(t){return this.isArrayBufferView(t)||this.isArrayBuffer(t)}static isArrayBufferView(t){return ArrayBuffer.isView(t)||t&&this.isArrayBuffer(t.buffer)}static isEqual(t,e){let n=r.toUint8Array(t),s=r.toUint8Array(e);if(n.length!==s.byteLength)return!1;for(let i=0;i<n.length;i++)if(n[i]!==s[i])return!1;return!0}static concat(...t){let e;Array.isArray(t[0])&&!(t[1]instanceof Function)||Array.isArray(t[0])&&t[1]instanceof Function?e=t[0]:t[t.length-1]instanceof Function?e=t.slice(0,t.length-1):e=t;let n=0;for(let o of e)n+=o.byteLength;let s=new Uint8Array(n),i=0;for(let o of e){let a=this.toUint8Array(o);s.set(a,i),i+=a.length}return t[t.length-1]instanceof Function?this.toView(s,t[t.length-1]):s.buffer}},Ki="string",wh=/^[0-9a-f]+$/i,xh=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,vh=/^[a-zA-Z0-9-_]+$/,vn=class{static fromString(t){let e=unescape(encodeURIComponent(t)),n=new Uint8Array(e.length);for(let s=0;s<e.length;s++)n[s]=e.charCodeAt(s);return n.buffer}static toString(t){let e=ne.toUint8Array(t),n="";for(let i=0;i<e.length;i++)n+=String.fromCharCode(e[i]);return decodeURIComponent(escape(n))}},_t=class{static toString(t,e=!1){let n=ne.toArrayBuffer(t),s=new DataView(n),i="";for(let o=0;o<n.byteLength;o+=2){let a=s.getUint16(o,e);i+=String.fromCharCode(a)}return i}static fromString(t,e=!1){let n=new ArrayBuffer(t.length*2),s=new DataView(n);for(let i=0;i<t.length;i++)s.setUint16(i*2,t.charCodeAt(i),e);return n}},En=class r{static isHex(t){return typeof t===Ki&&wh.test(t)}static isBase64(t){return typeof t===Ki&&xh.test(t)}static isBase64Url(t){return typeof t===Ki&&vh.test(t)}static ToString(t,e="utf8"){let n=ne.toUint8Array(t);switch(e.toLowerCase()){case"utf8":return this.ToUtf8String(n);case"binary":return this.ToBinary(n);case"hex":return this.ToHex(n);case"base64":return this.ToBase64(n);case"base64url":return this.ToBase64Url(n);case"utf16le":return _t.toString(n,!0);case"utf16":case"utf16be":return _t.toString(n);default:throw new Error(`Unknown type of encoding '${e}'`)}}static FromString(t,e="utf8"){if(!t)return new ArrayBuffer(0);switch(e.toLowerCase()){case"utf8":return this.FromUtf8String(t);case"binary":return this.FromBinary(t);case"hex":return this.FromHex(t);case"base64":return this.FromBase64(t);case"base64url":return this.FromBase64Url(t);case"utf16le":return _t.fromString(t,!0);case"utf16":case"utf16be":return _t.fromString(t);default:throw new Error(`Unknown type of encoding '${e}'`)}}static ToBase64(t){let e=ne.toUint8Array(t);if(typeof btoa<"u"){let n=this.ToString(e,"binary");return btoa(n)}else return Buffer.from(e).toString("base64")}static FromBase64(t){let e=this.formatString(t);if(!e)return new ArrayBuffer(0);if(!r.isBase64(e))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(e)):new Uint8Array(Buffer.from(e,"base64")).buffer}static FromBase64Url(t){let e=this.formatString(t);if(!e)return new ArrayBuffer(0);if(!r.isBase64Url(e))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(e.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(t){return this.ToBase64(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(t,e=r.DEFAULT_UTF8_ENCODING){switch(e){case"ascii":return this.FromBinary(t);case"utf8":return vn.fromString(t);case"utf16":case"utf16be":return _t.fromString(t);case"utf16le":case"usc2":return _t.fromString(t,!0);default:throw new Error(`Unknown type of encoding '${e}'`)}}static ToUtf8String(t,e=r.DEFAULT_UTF8_ENCODING){switch(e){case"ascii":return this.ToBinary(t);case"utf8":return vn.toString(t);case"utf16":case"utf16be":return _t.toString(t);case"utf16le":case"usc2":return _t.toString(t,!0);default:throw new Error(`Unknown type of encoding '${e}'`)}}static FromBinary(t){let e=t.length,n=new Uint8Array(e);for(let s=0;s<e;s++)n[s]=t.charCodeAt(s);return n.buffer}static ToBinary(t){let e=ne.toUint8Array(t),n="";for(let s=0;s<e.length;s++)n+=String.fromCharCode(e[s]);return n}static ToHex(t){let e=ne.toUint8Array(t),n="",s=e.length;for(let i=0;i<s;i++){let o=e[i];o<16&&(n+="0"),n+=o.toString(16)}return n}static FromHex(t){let e=this.formatString(t);if(!e)return new ArrayBuffer(0);if(!r.isHex(e))throw new TypeError("Argument 'hexString' is not HEX encoded");e.length%2&&(e=`0${e}`);let n=new Uint8Array(e.length/2);for(let s=0;s<e.length;s=s+2){let i=e.slice(s,s+2);n[s/2]=parseInt(i,16)}return n.buffer}static ToUtf16String(t,e=!1){return _t.toString(t,e)}static FromUtf16String(t,e=!1){return _t.fromString(t,e)}static Base64Padding(t){let e=4-t.length%4;if(e<4)for(let n=0;n<e;n++)t+="=";return t}static formatString(t){return t?.replace(/[\n\r\t ]/g,"")||""}};En.DEFAULT_UTF8_ENCODING="utf8";function Eh(r,...t){let e=arguments[0];for(let n=1;n<arguments.length;n++){let s=arguments[n];for(let i in s)e[i]=s[i]}return e}function Bh(...r){let t=r.map(s=>s.byteLength).reduce((s,i)=>s+i),e=new Uint8Array(t),n=0;return r.map(s=>new Uint8Array(s)).forEach(s=>{for(let i of s)e[n++]=i}),e.buffer}function Ah(r,t){if(!(r&&t)||r.byteLength!==t.byteLength)return!1;let e=new Uint8Array(r),n=new Uint8Array(t);for(let s=0;s<r.byteLength;s++)if(e[s]!==n[s])return!1;return!0}rr.BufferSourceConverter=ne;rr.Convert=En;rr.assign=Eh;rr.combine=Bh;rr.isEqual=Ah});var vl=Ho((Wb,bo)=>{"use strict";var pd=Object.prototype.hasOwnProperty,kt="~";function jr(){}Object.create&&(jr.prototype=Object.create(null),new jr().__proto__||(kt=!1));function md(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function xl(r,t,e,n,s){if(typeof e!="function")throw new TypeError("The listener must be a function");var i=new md(e,n||r,s),o=kt?kt+t:t;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 ks(r,t){--r._eventsCount===0?r._events=new jr:delete r._events[t]}function bt(){this._events=new jr,this._eventsCount=0}bt.prototype.eventNames=function(){var t=[],e,n;if(this._eventsCount===0)return t;for(n in e=this._events)pd.call(e,n)&&t.push(kt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};bt.prototype.listeners=function(t){var e=kt?kt+t:t,n=this._events[e];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};bt.prototype.listenerCount=function(t){var e=kt?kt+t:t,n=this._events[e];return n?n.fn?1:n.length:0};bt.prototype.emit=function(t,e,n,s,i,o){var a=kt?kt+t:t;if(!this._events[a])return!1;var c=this._events[a],f=arguments.length,l,u;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),f){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,e),!0;case 3:return c.fn.call(c.context,e,n),!0;case 4:return c.fn.call(c.context,e,n,s),!0;case 5:return c.fn.call(c.context,e,n,s,i),!0;case 6:return c.fn.call(c.context,e,n,s,i,o),!0}for(u=1,l=new Array(f-1);u<f;u++)l[u-1]=arguments[u];c.fn.apply(c.context,l)}else{var h=c.length,g;for(u=0;u<h;u++)switch(c[u].once&&this.removeListener(t,c[u].fn,void 0,!0),f){case 1:c[u].fn.call(c[u].context);break;case 2:c[u].fn.call(c[u].context,e);break;case 3:c[u].fn.call(c[u].context,e,n);break;case 4:c[u].fn.call(c[u].context,e,n,s);break;default:if(!l)for(g=1,l=new Array(f-1);g<f;g++)l[g-1]=arguments[g];c[u].fn.apply(c[u].context,l)}}return!0};bt.prototype.on=function(t,e,n){return xl(this,t,e,n,!1)};bt.prototype.once=function(t,e,n){return xl(this,t,e,n,!0)};bt.prototype.removeListener=function(t,e,n,s){var i=kt?kt+t:t;if(!this._events[i])return this;if(!e)return ks(this,i),this;var o=this._events[i];if(o.fn)o.fn===e&&(!s||o.once)&&(!n||o.context===n)&&ks(this,i);else{for(var a=0,c=[],f=o.length;a<f;a++)(o[a].fn!==e||s&&!o[a].once||n&&o[a].context!==n)&&c.push(o[a]);c.length?this._events[i]=c.length===1?c[0]:c:ks(this,i)}return this};bt.prototype.removeAllListeners=function(t){var e;return t?(e=kt?kt+t:t,this._events[e]&&ks(this,e)):(this._events=new jr,this._eventsCount=0),this};bt.prototype.off=bt.prototype.removeListener;bt.prototype.addListener=bt.prototype.on;bt.prefixed=kt;bt.EventEmitter=bt;typeof bo<"u"&&(bo.exports=bt)});var Bd={};xt(Bd,{PersistentPeerStore:()=>Uo});var tn=Symbol.for("@libp2p/peer-id");function qo(r){return!!r?.[tn]}var K=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},$e=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var en=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},rn=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Ne=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Ms={};xt(Ms,{base58btc:()=>Y,base58flickr:()=>Xl});var Id=new Uint8Array(0);function $o(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Yt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function zo(r){return new TextEncoder().encode(r)}function Go(r){return new TextDecoder().decode(r)}function Wl(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var s=0;s<r.length;s++){var i=r.charAt(s),o=i.charCodeAt(0);if(e[o]!==255)throw new TypeError(i+" is ambiguous");e[o]=s}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function u(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 b=0,d=0,w=0,B=x.length;w!==B&&x[w]===0;)w++,b++;for(var m=(B-w)*l+1>>>0,k=new Uint8Array(m);w!==B;){for(var U=x[w],L=0,S=m-1;(U!==0||L<d)&&S!==-1;S--,L++)U+=256*k[S]>>>0,k[S]=U%a>>>0,U=U/a>>>0;if(U!==0)throw new Error("Non-zero carry");d=L,w++}for(var I=m-d;I!==m&&k[I]===0;)I++;for(var C=c.repeat(b);I<m;++I)C+=r.charAt(k[I]);return C}function h(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var b=0;if(x[b]!==" "){for(var d=0,w=0;x[b]===c;)d++,b++;for(var B=(x.length-b)*f+1>>>0,m=new Uint8Array(B);x[b];){var k=e[x.charCodeAt(b)];if(k===255)return;for(var U=0,L=B-1;(k!==0||U<w)&&L!==-1;L--,U++)k+=a*m[L]>>>0,m[L]=k%256>>>0,k=k/256>>>0;if(k!==0)throw new Error("Non-zero carry");w=U,b++}if(x[b]!==" "){for(var S=B-w;S!==B&&m[S]===0;)S++;for(var I=new Uint8Array(d+(B-S)),C=d;S!==B;)I[C++]=m[S++];return I}}}function g(x){var b=h(x);if(b)return b;throw new Error(`Non-${t} character`)}return{encode:u,decodeUnsafe:h,decode:g}}var Zl=Wl,jl=Zl,Zo=jl;var Vs=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Os=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return jo(this,t)}},Ds=class{decoders;constructor(t){this.decoders=t}or(t){return jo(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function jo(r,t){return new Ds({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Ps=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,s){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=s,this.encoder=new Vs(t,e,n),this.decoder=new Os(t,e,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ze({name:r,prefix:t,encode:e,decode:n}){return new Ps(r,t,e,n)}function de({name:r,prefix:t,alphabet:e}){let{encode:n,decode:s}=Zo(e,r);return ze({prefix:t,name:r,encode:n,decode:i=>Yt(s(i))})}function Yl(r,t,e,n){let s={};for(let l=0;l<t.length;++l)s[t[l]]=l;let i=r.length;for(;r[i-1]==="=";)--i;let o=new Uint8Array(i*e/8|0),a=0,c=0,f=0;for(let l=0;l<i;++l){let u=s[r[l]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|u,a+=e,a>=8&&(a-=8,o[f++]=255&c>>a)}if(a>=e||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o}function Jl(r,t,e){let n=t[t.length-1]==="=",s=(1<<e)-1,i="",o=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],o+=8;o>e;)o-=e,i+=t[s&a>>o];if(o!==0&&(i+=t[s&a<<e-o]),n)for(;i.length*e&7;)i+="=";return i}function Q({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return ze({prefix:t,name:r,encode(s){return Jl(s,n,e)},decode(s){return Yl(s,n,e,r)}})}var Y=de({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Xl=de({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Hs={};xt(Hs,{base32:()=>Vt,base32hex:()=>ru,base32hexpad:()=>su,base32hexpadupper:()=>iu,base32hexupper:()=>nu,base32pad:()=>tu,base32padupper:()=>eu,base32upper:()=>Ql,base32z:()=>ou});var Vt=Q({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ql=Q({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),tu=Q({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),eu=Q({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ru=Q({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),nu=Q({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),su=Q({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),iu=Q({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ou=Q({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var au=Xo,Yo=128,cu=127,lu=~cu,uu=Math.pow(2,31);function Xo(r,t,e){t=t||[],e=e||0;for(var n=e;r>=uu;)t[e++]=r&255|Yo,r/=128;for(;r&lu;)t[e++]=r&255|Yo,r>>>=7;return t[e]=r|0,Xo.bytes=e-n+1,t}var fu=Fs,hu=128,Jo=127;function Fs(r,n){var e=0,n=n||0,s=0,i=n,o,a=r.length;do{if(i>=a)throw Fs.bytes=0,new RangeError("Could not decode varint");o=r[i++],e+=s<28?(o&Jo)<<s:(o&Jo)*Math.pow(2,s),s+=7}while(o>=hu);return Fs.bytes=i-n,e}var du=Math.pow(2,7),pu=Math.pow(2,14),mu=Math.pow(2,21),gu=Math.pow(2,28),yu=Math.pow(2,35),bu=Math.pow(2,42),wu=Math.pow(2,49),xu=Math.pow(2,56),vu=Math.pow(2,63),Eu=function(r){return r<du?1:r<pu?2:r<mu?3:r<gu?4:r<yu?5:r<bu?6:r<wu?7:r<xu?8:r<vu?9:10},Bu={encode:au,decode:fu,encodingLength:Eu},Au=Bu,br=Au;function wr(r,t=0){return[br.decode(r,t),br.decode.bytes]}function Ge(r,t,e=0){return br.encode(r,t,e),t}function We(r){return br.encodingLength(r)}function Ot(r,t){let e=t.byteLength,n=We(r),s=n+We(e),i=new Uint8Array(s+e);return Ge(r,i,0),Ge(e,i,n),i.set(t,s),new Ze(r,e,t,i)}function pe(r){let t=Yt(r),[e,n]=wr(t),[s,i]=wr(t.subarray(n)),o=t.subarray(n+i);if(o.byteLength!==s)throw new Error("Incorrect length");return new Ze(e,s,o,t)}function Qo(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&$o(r.bytes,e.bytes)}}var Ze=class{code;size;digest;bytes;constructor(t,e,n,s){this.code=t,this.size=e,this.digest=n,this.bytes=s}};function ta(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Su(e,Ks(r),t??Y.encoder);default:return Iu(e,Ks(r),t??Vt.encoder)}}var ea=new WeakMap;function Ks(r){let t=ea.get(r);if(t==null){let e=new Map;return ea.set(r,e),e}return t}var it=class r{code;version;multihash;bytes;"/";constructor(t,e,n,s){this.code=e,this.version=t,this.multihash=n,this.bytes=s,this["/"]=s}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==xr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Tu)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=Ot(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&Qo(t.multihash,n.multihash)}toString(t){return ta(this,t)}toJSON(){return{"/":ta(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:s,multihash:i,bytes:o}=e;return new r(n,s,i,o??ra(n,s,i.bytes))}else if(e[Nu]===!0){let{version:n,multihash:s,code:i}=e,o=pe(s);return r.create(n,i,o)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==xr)throw new Error(`Version 0 CID must use dag-pb (code: ${xr}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let s=ra(t,e,n.bytes);return new r(t,e,n,s)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,xr,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,s=Yt(t.subarray(n,n+e.multihashSize));if(s.byteLength!==e.multihashSize)throw new Error("Incorrect length");let i=s.subarray(e.multihashSize-e.digestSize),o=new Ze(e.multihashCode,e.digestSize,i,s);return[e.version===0?r.createV0(o):r.createV1(e.codec,o),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[u,h]=wr(t.subarray(e));return e+=h,u},s=n(),i=xr;if(s===18?(s=0,e=0):i=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let o=e,a=n(),c=n(),f=e+c,l=f-o;return{version:s,codec:i,multihashCode:a,digestSize:c,multihashSize:l,size:f}}static parse(t,e){let[n,s]=ku(t,e),i=r.decode(s);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ks(i).set(n,t),i}};function ku(r,t){switch(r[0]){case"Q":{let e=t??Y;return[Y.prefix,e.decode(`${Y.prefix}${r}`)]}case Y.prefix:{let e=t??Y;return[Y.prefix,e.decode(r)]}case Vt.prefix:{let e=t??Vt;return[Vt.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Su(r,t,e){let{prefix:n}=e;if(n!==Y.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let s=t.get(n);if(s==null){let i=e.encode(r).slice(1);return t.set(n,i),i}else return s}function Iu(r,t,e){let{prefix:n}=e,s=t.get(n);if(s==null){let i=e.encode(r);return t.set(n,i),i}else return s}var xr=112,Tu=18;function ra(r,t,e){let n=We(r),s=n+We(t),i=new Uint8Array(s+e.byteLength);return Ge(r,i,0),Ge(t,i,n),i.set(e,s),i}var Nu=Symbol.for("@ipld/js-cid/CID");var qs={};xt(qs,{identity:()=>Xt});var na=0,Cu="identity",sa=Yt;function Lu(r){return Ot(na,sa(r))}var Xt={code:na,name:Cu,encode:sa,digest:Lu};function ut(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function ia(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function Uu(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function je(r,...t){if(!Uu(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${r.length}`)}function oa(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");ia(r.outputLen),ia(r.blockLen)}function Ye(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function aa(r,t){je(r);let e=t.outputLen;if(r.length<e)throw new Error(`digestInto() expects output buffer of length at least ${e}`)}var Ce=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var sn=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Dt=(r,t)=>r<<32-t|r>>>t;var Zd=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function ca(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function vr(r){return typeof r=="string"&&(r=ca(r)),je(r),r}function $s(...r){let t=0;for(let n=0;n<r.length;n++){let s=r[n];je(s),t+=s.length}let e=new Uint8Array(t);for(let n=0,s=0;n<r.length;n++){let i=r[n];e.set(i,s),s+=i.length}return e}var Je=class{clone(){return this._cloneInto()}},jd={}.toString;function on(r){let t=n=>r().update(vr(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function an(r=32){if(Ce&&typeof Ce.getRandomValues=="function")return Ce.getRandomValues(new Uint8Array(r));if(Ce&&typeof Ce.randomBytes=="function")return Ce.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function Ru(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let s=BigInt(32),i=BigInt(4294967295),o=Number(e>>s&i),a=Number(e&i),c=n?4:0,f=n?0:4;r.setUint32(t+c,o,n),r.setUint32(t+f,a,n)}var la=(r,t,e)=>r&t^~r&e,ua=(r,t,e)=>r&t^r&e^t&e,Xe=class extends Je{constructor(t,e,n,s){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=sn(this.buffer)}update(t){Ye(this);let{view:e,buffer:n,blockLen:s}=this;t=vr(t);let i=t.length;for(let o=0;o<i;){let a=Math.min(s-this.pos,i-o);if(a===s){let c=sn(t);for(;s<=i-o;o+=s)this.process(c,o);continue}n.set(t.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===s&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ye(this),aa(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:s,isLE:i}=this,{pos:o}=this;e[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>s-o&&(this.process(n,0),o=0);for(let u=o;u<s;u++)e[u]=0;Ru(n,s-8,BigInt(this.length*8),i),this.process(n,0);let a=sn(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=c/4,l=this.get();if(f>l.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<f;u++)a.setUint32(4*u,l[u],i)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:s,finished:i,destroyed:o,pos:a}=this;return t.length=s,t.pos=a,t.finished=i,t.destroyed=o,s%e&&t.buffer.set(n),t}};var cn=BigInt(4294967295),zs=BigInt(32);function fa(r,t=!1){return t?{h:Number(r&cn),l:Number(r>>zs&cn)}:{h:Number(r>>zs&cn)|0,l:Number(r&cn)|0}}function _u(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let s=0;s<r.length;s++){let{h:i,l:o}=fa(r[s],t);[e[s],n[s]]=[i,o]}return[e,n]}var Vu=(r,t)=>BigInt(r>>>0)<<zs|BigInt(t>>>0),Ou=(r,t,e)=>r>>>e,Du=(r,t,e)=>r<<32-e|t>>>e,Pu=(r,t,e)=>r>>>e|t<<32-e,Mu=(r,t,e)=>r<<32-e|t>>>e,Hu=(r,t,e)=>r<<64-e|t>>>e-32,Fu=(r,t,e)=>r>>>e-32|t<<64-e,Ku=(r,t)=>t,qu=(r,t)=>r,$u=(r,t,e)=>r<<e|t>>>32-e,zu=(r,t,e)=>t<<e|r>>>32-e,Gu=(r,t,e)=>t<<e-32|r>>>64-e,Wu=(r,t,e)=>r<<e-32|t>>>64-e;function Zu(r,t,e,n){let s=(t>>>0)+(n>>>0);return{h:r+e+(s/2**32|0)|0,l:s|0}}var ju=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Yu=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Ju=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Xu=(r,t,e,n,s)=>t+e+n+s+(r/2**32|0)|0,Qu=(r,t,e,n,s)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(s>>>0),tf=(r,t,e,n,s,i)=>t+e+n+s+i+(r/2**32|0)|0;var ef={fromBig:fa,split:_u,toBig:Vu,shrSH:Ou,shrSL:Du,rotrSH:Pu,rotrSL:Mu,rotrBH:Hu,rotrBL:Fu,rotr32H:Ku,rotr32L:qu,rotlSH:$u,rotlSL:zu,rotlBH:Gu,rotlBL:Wu,add:Zu,add3L:ju,add3H:Yu,add4L:Ju,add4H:Xu,add5H:tf,add5L:Qu},V=ef;var[rf,nf]=V.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),me=new Uint32Array(80),ge=new Uint32Array(80),Gs=class extends Xe{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:t,Al:e,Bh:n,Bl:s,Ch:i,Cl:o,Dh:a,Dl:c,Eh:f,El:l,Fh:u,Fl:h,Gh:g,Gl:x,Hh:b,Hl:d}=this;return[t,e,n,s,i,o,a,c,f,l,u,h,g,x,b,d]}set(t,e,n,s,i,o,a,c,f,l,u,h,g,x,b,d){this.Ah=t|0,this.Al=e|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=l|0,this.Fh=u|0,this.Fl=h|0,this.Gh=g|0,this.Gl=x|0,this.Hh=b|0,this.Hl=d|0}process(t,e){for(let m=0;m<16;m++,e+=4)me[m]=t.getUint32(e),ge[m]=t.getUint32(e+=4);for(let m=16;m<80;m++){let k=me[m-15]|0,U=ge[m-15]|0,L=V.rotrSH(k,U,1)^V.rotrSH(k,U,8)^V.shrSH(k,U,7),S=V.rotrSL(k,U,1)^V.rotrSL(k,U,8)^V.shrSL(k,U,7),I=me[m-2]|0,C=ge[m-2]|0,rt=V.rotrSH(I,C,19)^V.rotrBH(I,C,61)^V.shrSH(I,C,6),F=V.rotrSL(I,C,19)^V.rotrBL(I,C,61)^V.shrSL(I,C,6),O=V.add4L(S,F,ge[m-7],ge[m-16]),nt=V.add4H(O,L,rt,me[m-7],me[m-16]);me[m]=nt|0,ge[m]=O|0}let{Ah:n,Al:s,Bh:i,Bl:o,Ch:a,Cl:c,Dh:f,Dl:l,Eh:u,El:h,Fh:g,Fl:x,Gh:b,Gl:d,Hh:w,Hl:B}=this;for(let m=0;m<80;m++){let k=V.rotrSH(u,h,14)^V.rotrSH(u,h,18)^V.rotrBH(u,h,41),U=V.rotrSL(u,h,14)^V.rotrSL(u,h,18)^V.rotrBL(u,h,41),L=u&g^~u&b,S=h&x^~h&d,I=V.add5L(B,U,S,nf[m],ge[m]),C=V.add5H(I,w,k,L,rf[m],me[m]),rt=I|0,F=V.rotrSH(n,s,28)^V.rotrBH(n,s,34)^V.rotrBH(n,s,39),O=V.rotrSL(n,s,28)^V.rotrBL(n,s,34)^V.rotrBL(n,s,39),nt=n&i^n&a^i&a,E=s&o^s&c^o&c;w=b|0,B=d|0,b=g|0,d=x|0,g=u|0,x=h|0,{h:u,l:h}=V.add(f|0,l|0,C|0,rt|0),f=a|0,l=c|0,a=i|0,c=o|0,i=n|0,o=s|0;let T=V.add3L(rt,O,E);n=V.add3H(T,C,F,nt),s=T|0}({h:n,l:s}=V.add(this.Ah|0,this.Al|0,n|0,s|0)),{h:i,l:o}=V.add(this.Bh|0,this.Bl|0,i|0,o|0),{h:a,l:c}=V.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l}=V.add(this.Dh|0,this.Dl|0,f|0,l|0),{h:u,l:h}=V.add(this.Eh|0,this.El|0,u|0,h|0),{h:g,l:x}=V.add(this.Fh|0,this.Fl|0,g|0,x|0),{h:b,l:d}=V.add(this.Gh|0,this.Gl|0,b|0,d|0),{h:w,l:B}=V.add(this.Hh|0,this.Hl|0,w|0,B|0),this.set(n,s,i,o,a,c,f,l,u,h,g,x,b,d,w,B)}roundClean(){me.fill(0),ge.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 ha=on(()=>new Gs);var un={};xt(un,{aInRange:()=>It,abool:()=>Pt,abytes:()=>Qe,bitGet:()=>uf,bitLen:()=>Js,bitMask:()=>Br,bitSet:()=>ff,bytesToHex:()=>te,bytesToNumberBE:()=>ee,bytesToNumberLE:()=>be,concatBytes:()=>re,createHmacDrbg:()=>Xs,ensureBytes:()=>tt,equalBytes:()=>cf,hexToBytes:()=>Ue,hexToNumber:()=>Ys,inRange:()=>Er,isBytes:()=>ye,memoized:()=>_e,notImplemented:()=>df,numberToBytesBE:()=>we,numberToBytesLE:()=>Re,numberToHexUnpadded:()=>Le,numberToVarBytesBE:()=>af,utf8ToBytes:()=>lf,validateObject:()=>Kt});var js=BigInt(0),ln=BigInt(1),sf=BigInt(2);function ye(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Qe(r){if(!ye(r))throw new Error("Uint8Array expected")}function Pt(r,t){if(typeof t!="boolean")throw new Error(`${r} must be valid boolean, got "${t}".`)}var of=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function te(r){Qe(r);let t="";for(let e=0;e<r.length;e++)t+=of[r[e]];return t}function Le(r){let t=r.toString(16);return t.length&1?`0${t}`:t}function Ys(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var Qt={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function da(r){if(r>=Qt._0&&r<=Qt._9)return r-Qt._0;if(r>=Qt._A&&r<=Qt._F)return r-(Qt._A-10);if(r>=Qt._a&&r<=Qt._f)return r-(Qt._a-10)}function Ue(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let t=r.length,e=t/2;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let s=0,i=0;s<e;s++,i+=2){let o=da(r.charCodeAt(i)),a=da(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 ee(r){return Ys(te(r))}function be(r){return Qe(r),Ys(te(Uint8Array.from(r).reverse()))}function we(r,t){return Ue(r.toString(16).padStart(t*2,"0"))}function Re(r,t){return we(r,t).reverse()}function af(r){return Ue(Le(r))}function tt(r,t,e){let n;if(typeof t=="string")try{n=Ue(t)}catch(i){throw new Error(`${r} must be valid hex string, got "${t}". Cause: ${i}`)}else if(ye(t))n=Uint8Array.from(t);else throw new Error(`${r} must be hex string or Uint8Array`);let s=n.length;if(typeof e=="number"&&s!==e)throw new Error(`${r} expected ${e} bytes, got ${s}`);return n}function re(...r){let t=0;for(let n=0;n<r.length;n++){let s=r[n];Qe(s),t+=s.length}let e=new Uint8Array(t);for(let n=0,s=0;n<r.length;n++){let i=r[n];e.set(i,s),s+=i.length}return e}function cf(r,t){if(r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}function lf(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}var Ws=r=>typeof r=="bigint"&&js<=r;function Er(r,t,e){return Ws(r)&&Ws(t)&&Ws(e)&&t<=r&&r<e}function It(r,t,e,n){if(!Er(t,e,n))throw new Error(`expected valid ${r}: ${e} <= n < ${n}, got ${typeof t} ${t}`)}function Js(r){let t;for(t=0;r>js;r>>=ln,t+=1);return t}function uf(r,t){return r>>BigInt(t)&ln}function ff(r,t,e){return r|(e?ln:js)<<BigInt(t)}var Br=r=>(sf<<BigInt(r-1))-ln,Zs=r=>new Uint8Array(r),pa=r=>Uint8Array.from(r);function Xs(r,t,e){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof e!="function")throw new Error("hmacFn must be a function");let n=Zs(r),s=Zs(r),i=0,o=()=>{n.fill(1),s.fill(0),i=0},a=(...u)=>e(s,n,...u),c=(u=Zs())=>{s=a(pa([0]),u),n=a(),u.length!==0&&(s=a(pa([1]),u),n=a())},f=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let u=0,h=[];for(;u<t;){n=a();let g=n.slice();h.push(g),u+=n.length}return re(...h)};return(u,h)=>{o(),c(u);let g;for(;!(g=h(f()));)c();return o(),g}}var hf={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"||ye(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function Kt(r,t,e={}){let n=(s,i,o)=>{let a=hf[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(t))n(s,i,!1);for(let[s,i]of Object.entries(e))n(s,i,!0);return r}var df=()=>{throw new Error("not implemented")};function _e(r){let t=new WeakMap;return(e,...n)=>{let s=t.get(e);if(s!==void 0)return s;let i=r(e,...n);return t.set(e,i),i}}var ot=BigInt(0),J=BigInt(1),Ve=BigInt(2),pf=BigInt(3),Qs=BigInt(4),ma=BigInt(5),ga=BigInt(8),mf=BigInt(9),gf=BigInt(16);function G(r,t){let e=r%t;return e>=ot?e:t+e}function yf(r,t,e){if(e<=ot||t<ot)throw new Error("Expected power/modulo > 0");if(e===J)return ot;let n=J;for(;t>ot;)t&J&&(n=n*r%e),r=r*r%e,t>>=J;return n}function X(r,t,e){let n=r;for(;t-- >ot;)n*=n,n%=e;return n}function fn(r,t){if(r===ot||t<=ot)throw new Error(`invert: expected positive integers, got n=${r} mod=${t}`);let e=G(r,t),n=t,s=ot,i=J,o=J,a=ot;for(;e!==ot;){let f=n/e,l=n%e,u=s-o*f,h=i-a*f;n=e,e=l,s=o,i=a,o=u,a=h}if(n!==J)throw new Error("invert: does not exist");return G(s,t)}function bf(r){let t=(r-J)/Ve,e,n,s;for(e=r-J,n=0;e%Ve===ot;e/=Ve,n++);for(s=Ve;s<r&&yf(s,t,r)!==r-J;s++);if(n===1){let o=(r+J)/Qs;return function(c,f){let l=c.pow(f,o);if(!c.eql(c.sqr(l),f))throw new Error("Cannot find square root");return l}}let i=(e+J)/Ve;return function(a,c){if(a.pow(c,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let f=n,l=a.pow(a.mul(a.ONE,s),e),u=a.pow(c,i),h=a.pow(c,e);for(;!a.eql(h,a.ONE);){if(a.eql(h,a.ZERO))return a.ZERO;let g=1;for(let b=a.sqr(h);g<f&&!a.eql(b,a.ONE);g++)b=a.sqr(b);let x=a.pow(l,J<<BigInt(f-g-1));l=a.sqr(x),u=a.mul(u,x),h=a.mul(h,l),f=g}return u}}function wf(r){if(r%Qs===pf){let t=(r+J)/Qs;return function(n,s){let i=n.pow(s,t);if(!n.eql(n.sqr(i),s))throw new Error("Cannot find square root");return i}}if(r%ga===ma){let t=(r-ma)/ga;return function(n,s){let i=n.mul(s,Ve),o=n.pow(i,t),a=n.mul(s,o),c=n.mul(n.mul(a,Ve),o),f=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(f),s))throw new Error("Cannot find square root");return f}}return r%gf,bf(r)}var ya=(r,t)=>(G(r,t)&J)===J,xf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ti(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=xf.reduce((n,s)=>(n[s]="function",n),t);return Kt(r,e)}function vf(r,t,e){if(e<ot)throw new Error("Expected power > 0");if(e===ot)return r.ONE;if(e===J)return t;let n=r.ONE,s=t;for(;e>ot;)e&J&&(n=r.mul(n,s)),s=r.sqr(s),e>>=J;return n}function Ef(r,t){let e=new Array(t.length),n=t.reduce((i,o,a)=>r.is0(o)?i:(e[a]=i,r.mul(i,o)),r.ONE),s=r.inv(n);return t.reduceRight((i,o,a)=>r.is0(o)?i:(e[a]=r.mul(i,e[a]),r.mul(i,o)),s),e}function ei(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function xe(r,t,e=!1,n={}){if(r<=ot)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:s,nByteLength:i}=ei(r,t);if(i>2048)throw new Error("Field lengths over 2048 bytes are not supported");let o=wf(r),a=Object.freeze({ORDER:r,BITS:s,BYTES:i,MASK:Br(s),ZERO:ot,ONE:J,create:c=>G(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return ot<=c&&c<r},is0:c=>c===ot,isOdd:c=>(c&J)===J,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)=>vf(a,c,f),div:(c,f)=>G(c*fn(f,r),r),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>fn(c,r),sqrt:n.sqrt||(c=>o(a,c)),invertBatch:c=>Ef(a,c),cmov:(c,f,l)=>l?f:c,toBytes:c=>e?Re(c,i):we(c,i),fromBytes:c=>{if(c.length!==i)throw new Error(`Fp.fromBytes: expected ${i}, got ${c.length}`);return e?be(c):ee(c)}});return Object.freeze(a)}function ba(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function ri(r){let t=ba(r);return t+Math.ceil(t/2)}function wa(r,t,e=!1){let n=r.length,s=ba(t),i=ri(t);if(n<16||n<i||n>1024)throw new Error(`expected ${i}-1024 bytes of input, got ${n}`);let o=e?ee(r):be(r),a=G(o,t-J)+J;return e?Re(a,s):we(a,s)}var Af=BigInt(0),ni=BigInt(1),si=new WeakMap,xa=new WeakMap;function hn(r,t){let e=(i,o)=>{let a=o.negate();return i?a:o},n=i=>{if(!Number.isSafeInteger(i)||i<=0||i>t)throw new Error(`Wrong window size=${i}, should be [1..${t}]`)},s=i=>{n(i);let o=Math.ceil(t/i)+1,a=2**(i-1);return{windows:o,windowSize:a}};return{constTimeNegate:e,unsafeLadder(i,o){let a=r.ZERO,c=i;for(;o>Af;)o&ni&&(a=a.add(c)),c=c.double(),o>>=ni;return a},precomputeWindow(i,o){let{windows:a,windowSize:c}=s(o),f=[],l=i,u=l;for(let h=0;h<a;h++){u=l,f.push(u);for(let g=1;g<c;g++)u=u.add(l),f.push(u);l=u.double()}return f},wNAF(i,o,a){let{windows:c,windowSize:f}=s(i),l=r.ZERO,u=r.BASE,h=BigInt(2**i-1),g=2**i,x=BigInt(i);for(let b=0;b<c;b++){let d=b*f,w=Number(a&h);a>>=x,w>f&&(w-=g,a+=ni);let B=d,m=d+Math.abs(w)-1,k=b%2!==0,U=w<0;w===0?u=u.add(e(k,o[B])):l=l.add(e(U,o[m]))}return{p:l,f:u}},wNAFCached(i,o,a){let c=xa.get(i)||1,f=si.get(i);return f||(f=this.precomputeWindow(i,c),c!==1&&si.set(i,a(f))),this.wNAF(c,f,o)},setWindowSize(i,o){n(o),xa.set(i,o),si.delete(i)}}}function dn(r,t,e,n){if(!Array.isArray(e)||!Array.isArray(n)||n.length!==e.length)throw new Error("arrays of points and scalars must have equal length");n.forEach((l,u)=>{if(!t.isValid(l))throw new Error(`wrong scalar at index ${u}`)}),e.forEach((l,u)=>{if(!(l instanceof r))throw new Error(`wrong point at index ${u}`)});let s=Js(BigInt(e.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((t.BITS-1)/i)*i,f=r.ZERO;for(let l=c;l>=0;l-=i){a.fill(r.ZERO);for(let h=0;h<n.length;h++){let g=n[h],x=Number(g>>BigInt(l)&BigInt(o));a[x]=a[x].add(e[h])}let u=r.ZERO;for(let h=a.length-1,g=r.ZERO;h>0;h--)g=g.add(a[h]),u=u.add(g);if(f=f.add(u),l!==0)for(let h=0;h<i;h++)f=f.double()}return f}function Ar(r){return ti(r.Fp),Kt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...ei(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Mt=BigInt(0),Tt=BigInt(1),pn=BigInt(2),kf=BigInt(8),Sf={zip215:!0};function If(r){let t=Ar(r);return Kt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function va(r){let t=If(r),{Fp:e,n,prehash:s,hash:i,randomBytes:o,nByteLength:a,h:c}=t,f=pn<<BigInt(a*8)-Tt,l=e.create,u=xe(t.n,t.nBitLength),h=t.uvRatio||((y,p)=>{try{return{isValid:!0,value:e.sqrt(y*e.inv(p))}}catch{return{isValid:!1,value:Mt}}}),g=t.adjustScalarBytes||(y=>y),x=t.domain||((y,p,v)=>{if(Pt("phflag",v),p.length||v)throw new Error("Contexts/pre-hash are not supported");return y});function b(y,p){It("coordinate "+y,p,Mt,f)}function d(y){if(!(y instanceof m))throw new Error("ExtendedPoint expected")}let w=_e((y,p)=>{let{ex:v,ey:N,ez:R}=y,_=y.is0();p==null&&(p=_?kf:e.inv(R));let D=l(v*p),H=l(N*p),P=l(R*p);if(_)return{x:Mt,y:Tt};if(P!==Tt)throw new Error("invZ was invalid");return{x:D,y:H}}),B=_e(y=>{let{a:p,d:v}=t;if(y.is0())throw new Error("bad point: ZERO");let{ex:N,ey:R,ez:_,et:D}=y,H=l(N*N),P=l(R*R),z=l(_*_),Z=l(z*z),ct=l(H*p),lt=l(z*l(ct+P)),ht=l(Z+l(v*l(H*P)));if(lt!==ht)throw new Error("bad point: equation left != right (1)");let wt=l(N*R),st=l(_*D);if(wt!==st)throw new Error("bad point: equation left != right (2)");return!0});class m{constructor(p,v,N,R){this.ex=p,this.ey=v,this.ez=N,this.et=R,b("x",p),b("y",v),b("z",N),b("t",R),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(p){if(p instanceof m)throw new Error("extended point not allowed");let{x:v,y:N}=p||{};return b("x",v),b("y",N),new m(v,N,Tt,l(v*N))}static normalizeZ(p){let v=e.invertBatch(p.map(N=>N.ez));return p.map((N,R)=>N.toAffine(v[R])).map(m.fromAffine)}static msm(p,v){return dn(m,u,p,v)}_setWindowSize(p){L.setWindowSize(this,p)}assertValidity(){B(this)}equals(p){d(p);let{ex:v,ey:N,ez:R}=this,{ex:_,ey:D,ez:H}=p,P=l(v*H),z=l(_*R),Z=l(N*H),ct=l(D*R);return P===z&&Z===ct}is0(){return this.equals(m.ZERO)}negate(){return new m(l(-this.ex),this.ey,this.ez,l(-this.et))}double(){let{a:p}=t,{ex:v,ey:N,ez:R}=this,_=l(v*v),D=l(N*N),H=l(pn*l(R*R)),P=l(p*_),z=v+N,Z=l(l(z*z)-_-D),ct=P+D,lt=ct-H,ht=P-D,wt=l(Z*lt),st=l(ct*ht),St=l(Z*ht),jt=l(lt*ct);return new m(wt,st,jt,St)}add(p){d(p);let{a:v,d:N}=t,{ex:R,ey:_,ez:D,et:H}=this,{ex:P,ey:z,ez:Z,et:ct}=p;if(v===BigInt(-1)){let Ro=l((_-R)*(z+P)),_o=l((_+R)*(z-P)),_s=l(_o-Ro);if(_s===Mt)return this.double();let Vo=l(D*pn*ct),Oo=l(H*pn*Z),Do=Oo+Vo,Po=_o+Ro,Mo=Oo-Vo,Dl=l(Do*_s),Pl=l(Po*Mo),Ml=l(Do*Mo),Hl=l(_s*Po);return new m(Dl,Pl,Hl,Ml)}let lt=l(R*P),ht=l(_*z),wt=l(H*N*ct),st=l(D*Z),St=l((R+_)*(P+z)-lt-ht),jt=st-wt,gr=st+wt,yr=l(ht-v*lt),Rl=l(St*jt),_l=l(gr*yr),Vl=l(St*yr),Ol=l(jt*gr);return new m(Rl,_l,Ol,Vl)}subtract(p){return this.add(p.negate())}wNAF(p){return L.wNAFCached(this,p,m.normalizeZ)}multiply(p){let v=p;It("scalar",v,Tt,n);let{p:N,f:R}=this.wNAF(v);return m.normalizeZ([N,R])[0]}multiplyUnsafe(p){let v=p;return It("scalar",v,Mt,n),v===Mt?U:this.equals(U)||v===Tt?this:this.equals(k)?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}=t;return p===Tt?this:this.multiplyUnsafe(p)}static fromHex(p,v=!1){let{d:N,a:R}=t,_=e.BYTES;p=tt("pointHex",p,_),Pt("zip215",v);let D=p.slice(),H=p[_-1];D[_-1]=H&-129;let P=be(D),z=v?f:e.ORDER;It("pointHex.y",P,Mt,z);let Z=l(P*P),ct=l(Z-Tt),lt=l(N*Z-R),{isValid:ht,value:wt}=h(ct,lt);if(!ht)throw new Error("Point.fromHex: invalid y coordinate");let st=(wt&Tt)===Tt,St=(H&128)!==0;if(!v&&wt===Mt&&St)throw new Error("Point.fromHex: x=0 and x_0=1");return St!==st&&(wt=l(-wt)),m.fromAffine({x:wt,y:P})}static fromPrivateKey(p){return C(p).point}toRawBytes(){let{x:p,y:v}=this.toAffine(),N=Re(v,e.BYTES);return N[N.length-1]|=p&Tt?128:0,N}toHex(){return te(this.toRawBytes())}}m.BASE=new m(t.Gx,t.Gy,Tt,l(t.Gx*t.Gy)),m.ZERO=new m(Mt,Tt,Tt,Mt);let{BASE:k,ZERO:U}=m,L=hn(m,a*8);function S(y){return G(y,n)}function I(y){return S(be(y))}function C(y){let p=a;y=tt("private key",y,p);let v=tt("hashed private key",i(y),2*p),N=g(v.slice(0,p)),R=v.slice(p,2*p),_=I(N),D=k.multiply(_),H=D.toRawBytes();return{head:N,prefix:R,scalar:_,point:D,pointBytes:H}}function rt(y){return C(y).pointBytes}function F(y=new Uint8Array,...p){let v=re(...p);return I(i(x(v,tt("context",y),!!s)))}function O(y,p,v={}){y=tt("message",y),s&&(y=s(y));let{prefix:N,scalar:R,pointBytes:_}=C(p),D=F(v.context,N,y),H=k.multiply(D).toRawBytes(),P=F(v.context,H,_,y),z=S(D+P*R);It("signature.s",z,Mt,n);let Z=re(H,Re(z,e.BYTES));return tt("result",Z,a*2)}let nt=Sf;function E(y,p,v,N=nt){let{context:R,zip215:_}=N,D=e.BYTES;y=tt("signature",y,2*D),p=tt("message",p),_!==void 0&&Pt("zip215",_),s&&(p=s(p));let H=be(y.slice(D,2*D)),P,z,Z;try{P=m.fromHex(v,_),z=m.fromHex(y.slice(0,D),_),Z=k.multiplyUnsafe(H)}catch{return!1}if(!_&&P.isSmallOrder())return!1;let ct=F(R,z.toRawBytes(),P.toRawBytes(),p);return z.add(P.multiplyUnsafe(ct)).subtract(Z).clearCofactor().equals(m.ZERO)}return k._setWindowSize(8),{CURVE:t,getPublicKey:rt,sign:O,verify:E,ExtendedPoint:m,utils:{getExtendedPublicKey:C,randomPrivateKey:()=>o(e.BYTES),precompute(y=8,p=m.BASE){return p._setWindowSize(y),p.multiply(BigInt(3)),p}}}}var ii=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Ea=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),b0=BigInt(0),Tf=BigInt(1),Ba=BigInt(2),w0=BigInt(3),Nf=BigInt(5),Cf=BigInt(8);function Lf(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),s=BigInt(80),i=ii,a=r*r%i*r%i,c=X(a,Ba,i)*a%i,f=X(c,Tf,i)*r%i,l=X(f,Nf,i)*f%i,u=X(l,t,i)*l%i,h=X(u,e,i)*u%i,g=X(h,n,i)*h%i,x=X(g,s,i)*g%i,b=X(x,s,i)*g%i,d=X(b,t,i)*l%i;return{pow_p_5_8:X(d,Ba,i)*r%i,b2:a}}function Uf(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Rf(r,t){let e=ii,n=G(t*t*t,e),s=G(n*n*t,e),i=Lf(r*s).pow_p_5_8,o=G(r*n*i,e),a=G(t*o*o,e),c=o,f=G(o*Ea,e),l=a===r,u=a===G(-r,e),h=a===G(-r*Ea,e);return l&&(o=c),(u||h)&&(o=f),ya(o,e)&&(o=G(-o,e)),{isValid:l||u,value:o}}var _f=xe(ii,void 0,!0),Vf={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:_f,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:Cf,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:ha,randomBytes:an,adjustScalarBytes:Uf,uvRatio:Rf},Aa=va(Vf);var mn=32;function ka(r,t,e){return Aa.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var gn=class{type="Ed25519";raw;constructor(t){this.raw=oi(t,mn)}toMultihash(){return Xt.digest(qt(this))}toCID(){return it.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ut(this.raw,t.raw)}verify(t,e){return ka(this.raw,e,t)}};function ai(r){return r=oi(r,mn),new gn(r)}function oi(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new K(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}function et(r=0){return new Uint8Array(r)}function Nt(r=0){return new Uint8Array(r)}var Df=Math.pow(2,7),Pf=Math.pow(2,14),Mf=Math.pow(2,21),ci=Math.pow(2,28),li=Math.pow(2,35),ui=Math.pow(2,42),fi=Math.pow(2,49),$=128,mt=127;function Ct(r){if(r<Df)return 1;if(r<Pf)return 2;if(r<Mf)return 3;if(r<ci)return 4;if(r<li)return 5;if(r<ui)return 6;if(r<fi)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function hi(r,t,e=0){switch(Ct(r)){case 8:t[e++]=r&255|$,r/=128;case 7:t[e++]=r&255|$,r/=128;case 6:t[e++]=r&255|$,r/=128;case 5:t[e++]=r&255|$,r/=128;case 4:t[e++]=r&255|$,r>>>=7;case 3:t[e++]=r&255|$,r>>>=7;case 2:t[e++]=r&255|$,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Hf(r,t,e=0){switch(Ct(r)){case 8:t.set(e++,r&255|$),r/=128;case 7:t.set(e++,r&255|$),r/=128;case 6:t.set(e++,r&255|$),r/=128;case 5:t.set(e++,r&255|$),r/=128;case 4:t.set(e++,r&255|$),r>>>=7;case 3:t.set(e++,r&255|$),r>>>=7;case 2:t.set(e++,r&255|$),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function di(r,t){let e=r[t],n=0;if(n+=e&mt,e<$||(e=r[t+1],n+=(e&mt)<<7,e<$)||(e=r[t+2],n+=(e&mt)<<14,e<$)||(e=r[t+3],n+=(e&mt)<<21,e<$)||(e=r[t+4],n+=(e&mt)*ci,e<$)||(e=r[t+5],n+=(e&mt)*li,e<$)||(e=r[t+6],n+=(e&mt)*ui,e<$)||(e=r[t+7],n+=(e&mt)*fi,e<$))return n;throw new RangeError("Could not decode varint")}function Ff(r,t){let e=r.get(t),n=0;if(n+=e&mt,e<$||(e=r.get(t+1),n+=(e&mt)<<7,e<$)||(e=r.get(t+2),n+=(e&mt)<<14,e<$)||(e=r.get(t+3),n+=(e&mt)<<21,e<$)||(e=r.get(t+4),n+=(e&mt)*ci,e<$)||(e=r.get(t+5),n+=(e&mt)*li,e<$)||(e=r.get(t+6),n+=(e&mt)*ui,e<$)||(e=r.get(t+7),n+=(e&mt)*fi,e<$))return n;throw new RangeError("Could not decode varint")}function $t(r,t,e=0){return t==null&&(t=Nt(Ct(r))),t instanceof Uint8Array?hi(r,t,e):Hf(r,t,e)}function Oe(r,t=0){return r instanceof Uint8Array?di(r,t):Ff(r,t)}var mi=new Float32Array([-0]),ve=new Uint8Array(mi.buffer);function Ia(r,t,e){mi[0]=r,t[e]=ve[0],t[e+1]=ve[1],t[e+2]=ve[2],t[e+3]=ve[3]}function Ta(r,t){return ve[0]=r[t],ve[1]=r[t+1],ve[2]=r[t+2],ve[3]=r[t+3],mi[0]}var gi=new Float64Array([-0]),gt=new Uint8Array(gi.buffer);function Na(r,t,e){gi[0]=r,t[e]=gt[0],t[e+1]=gt[1],t[e+2]=gt[2],t[e+3]=gt[3],t[e+4]=gt[4],t[e+5]=gt[5],t[e+6]=gt[6],t[e+7]=gt[7]}function Ca(r,t){return gt[0]=r[t],gt[1]=r[t+1],gt[2]=r[t+2],gt[3]=r[t+3],gt[4]=r[t+4],gt[5]=r[t+5],gt[6]=r[t+6],gt[7]=r[t+7],gi[0]}var Kf=BigInt(Number.MAX_SAFE_INTEGER),qf=BigInt(Number.MIN_SAFE_INTEGER),Ut=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return De;if(t<Kf&&t>qf)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,s=t-(n<<32n);return e&&(n=~n|0n,s=~s|0n,++s>La&&(s=0n,++n>La&&(n=0n))),new r(Number(s),Number(n))}static fromNumber(t){if(t===0)return De;let e=t<0;e&&(t=-t);let n=t>>>0,s=(t-n)/4294967296>>>0;return e&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new r(n,s)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):De}},De=new Ut(0,0);De.toBigInt=function(){return 0n};De.zzEncode=De.zzDecode=function(){return this};De.length=function(){return 1};var La=4294967296n;function Ua(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Ra(r,t,e){if(e-t<1)return"";let s,i=[],o=0,a;for(;t<e;)a=r[t++],a<128?i[o++]=a:a>191&&a<224?i[o++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,i[o++]=55296+(a>>10),i[o++]=56320+(a&1023)):i[o++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&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 yi(r,t,e){let n=e,s,i;for(let o=0;o<r.length;++o)s=r.charCodeAt(o),s<128?t[e++]=s:s<2048?(t[e++]=s>>6|192,t[e++]=s&63|128):(s&64512)===55296&&((i=r.charCodeAt(o+1))&64512)===56320?(s=65536+((s&1023)<<10)+(i&1023),++o,t[e++]=s>>18|240,t[e++]=s>>12&63|128,t[e++]=s>>6&63|128,t[e++]=s&63|128):(t[e++]=s>>12|224,t[e++]=s>>6&63|128,t[e++]=s&63|128);return e-n}function Ht(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function yn(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var bi=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Ht(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ht(this,4);return yn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ht(this,4);return yn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ht(this,4);let t=Ta(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Ht(this,4);let t=Ca(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw Ht(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Ra(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Ht(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Ht(this);while(this.buf[this.pos++]&128);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Ut(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw Ht(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw Ht(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ht(this,8);let t=yn(this.buf,this.pos+=4),e=yn(this.buf,this.pos+=4);return new Ut(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=di(this.buf,this.pos);return this.pos+=Ct(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function wi(r){return new bi(r instanceof Uint8Array?r:r.subarray())}function vt(r,t,e){let n=wi(r);return t.decode(n,void 0,e)}var xi={};xt(xi,{base10:()=>$f});var $f=de({prefix:"9",name:"base10",alphabet:"0123456789"});var vi={};xt(vi,{base16:()=>zf,base16upper:()=>Gf});var zf=Q({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Gf=Q({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Ei={};xt(Ei,{base2:()=>Wf});var Wf=Q({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Bi={};xt(Bi,{base256emoji:()=>Xf});var Va=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}"),Zf=Va.reduce((r,t,e)=>(r[e]=t,r),[]),jf=Va.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function Yf(r){return r.reduce((t,e)=>(t+=Zf[e],t),"")}function Jf(r){let t=[];for(let e of r){let n=jf[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var Xf=ze({prefix:"\u{1F680}",name:"base256emoji",encode:Yf,decode:Jf});var Ai={};xt(Ai,{base36:()=>Qf,base36upper:()=>th});var Qf=de({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),th=de({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ki={};xt(ki,{base64:()=>eh,base64pad:()=>rh,base64url:()=>nh,base64urlpad:()=>sh});var eh=Q({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),rh=Q({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),nh=Q({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),sh=Q({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Si={};xt(Si,{base8:()=>ih});var ih=Q({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ii={};xt(Ii,{identity:()=>oh});var oh=ze({prefix:"\0",name:"identity",encode:r=>Go(r),decode:r=>zo(r)});var rp=new TextEncoder,np=new TextDecoder;var Ci={};xt(Ci,{sha256:()=>kr,sha512:()=>lh});function Ni({name:r,code:t,encode:e}){return new Ti(r,t,e)}var Ti=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?Ot(this.code,e):e.then(n=>Ot(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Da(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var kr=Ni({name:"sha2-256",code:18,encode:Da("SHA-256")}),lh=Ni({name:"sha2-512",code:19,encode:Da("SHA-512")});var Sr={...Ii,...Ei,...Si,...xi,...vi,...Hs,...Ai,...Ms,...ki,...Bi},mp={...Ci,...qs};function Ma(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Pa=Ma("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Li=Ma("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=Nt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),uh={utf8:Pa,"utf-8":Pa,hex:Sr.base16,latin1:Li,ascii:Li,binary:Li,...Sr},bn=uh;function j(r,t="utf8"){let e=bn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function Ui(r){let t=r??8192,e=t>>>1,n,s=t;return function(o){if(o<1||o>e)return Nt(o);s+o>t&&(n=Nt(t),s=0);let a=n.subarray(s,s+=o);return s&7&&(s=(s|7)+1),a}}var Pe=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Ri(){}var Vi=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},fh=Ui();function hh(r){return globalThis.Buffer!=null?Nt(r):fh(r)}var Tr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Pe(Ri,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Pe(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Oi((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(wn,10,Ut.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Ut.fromBigInt(t);return this._push(wn,e.length(),e)}uint64Number(t){return this._push(hi,Ct(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=Ut.fromBigInt(t).zzEncode();return this._push(wn,e.length(),e)}sint64Number(t){let e=Ut.fromNumber(t).zzEncode();return this._push(wn,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(_i,1,t?1:0)}fixed32(t){return this._push(Ir,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Ut.fromBigInt(t);return this._push(Ir,4,e.lo)._push(Ir,4,e.hi)}fixed64Number(t){let e=Ut.fromNumber(t);return this._push(Ir,4,e.lo)._push(Ir,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Ia,4,t)}double(t){return this._push(Na,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(_i,1,0):this.uint32(e)._push(ph,e,t)}string(t){let e=Ua(t);return e!==0?this.uint32(e)._push(yi,e,t):this._push(_i,1,0)}fork(){return this.states=new Vi(this),this.head=this.tail=new Pe(Ri,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Pe(Ri,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=hh(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function _i(r,t,e){t[e]=r&255}function dh(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Oi=class extends Pe{next;constructor(t,e){super(dh,t,e),this.next=void 0}};function wn(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function Ir(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function ph(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Tr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(mh,t,r),this},Tr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(gh,t,r),this});function mh(r,t,e){t.set(r,e)}function gh(r,t,e){r.length<40?yi(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(j(r),e)}function Di(){return new Tr}function Et(r,t){let e=Di();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var tr;(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"})(tr||(tr={}));function xn(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Pi(r){function t(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let e=function(i,o){let a=t(i);o.int32(a)},n=function(i){let o=i.int32();return t(o)};return xn("enum",tr.VARINT,e,n)}function Bt(r,t){return xn("message",tr.LENGTH_DELIMITED,r,t)}var Me=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"},Nr=class extends Error{code="ERR_MAX_SIZE";name="MaxSizeError"};var at;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1"})(at||(at={}));var Mi;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1"})(Mi||(Mi={}));(function(r){r.codec=()=>Pi(Mi)})(at||(at={}));var zt;(function(r){let t;r.codec=()=>(t==null&&(t=Bt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),at.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let i={},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let a=e.uint32();switch(a>>>3){case 1:{i.Type=at.codec().decode(e);break}case 2:{i.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>Et(e,r.codec()),r.decode=(e,n)=>vt(e,r.codec(),n)})(zt||(zt={}));var Hi;(function(r){let t;r.codec=()=>(t==null&&(t=Bt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),at.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let i={},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let a=e.uint32();switch(a>>>3){case 1:{i.Type=at.codec().decode(e);break}case 2:{i.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>Et(e,r.codec()),r.decode=(e,n)=>vt(e,r.codec(),n)})(Hi||(Hi={}));var Mr={};xt(Mr,{MAX_RSA_KEY_SIZE:()=>fs,generateRSAKeyPair:()=>Oc,jwkToJWKKeyPair:()=>Dc,jwkToPkcs1:()=>Uh,jwkToPkix:()=>ji,jwkToRSAPrivateKey:()=>Vc,pkcs1ToJwk:()=>Uc,pkcs1ToRSAPrivateKey:()=>_c,pkixToJwk:()=>Rc,pkixToRSAPublicKey:()=>Yi});var yh=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]),Ee=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Be=new Uint32Array(64),Fi=class extends Xe{constructor(){super(64,32,8,!1),this.A=Ee[0]|0,this.B=Ee[1]|0,this.C=Ee[2]|0,this.D=Ee[3]|0,this.E=Ee[4]|0,this.F=Ee[5]|0,this.G=Ee[6]|0,this.H=Ee[7]|0}get(){let{A:t,B:e,C:n,D:s,E:i,F:o,G:a,H:c}=this;return[t,e,n,s,i,o,a,c]}set(t,e,n,s,i,o,a,c){this.A=t|0,this.B=e|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(t,e){for(let u=0;u<16;u++,e+=4)Be[u]=t.getUint32(e,!1);for(let u=16;u<64;u++){let h=Be[u-15],g=Be[u-2],x=Dt(h,7)^Dt(h,18)^h>>>3,b=Dt(g,17)^Dt(g,19)^g>>>10;Be[u]=b+Be[u-7]+x+Be[u-16]|0}let{A:n,B:s,C:i,D:o,E:a,F:c,G:f,H:l}=this;for(let u=0;u<64;u++){let h=Dt(a,6)^Dt(a,11)^Dt(a,25),g=l+h+la(a,c,f)+yh[u]+Be[u]|0,b=(Dt(n,2)^Dt(n,13)^Dt(n,22))+ua(n,s,i)|0;l=f,f=c,c=a,a=o+g|0,o=i,i=s,s=n,n=g+b|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,l=l+this.H|0,this.set(n,s,i,o,a,c,f,l)}roundClean(){Be.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var er=on(()=>new Fi);var M=Ko(Fa());function He(r,t){let e=0;if(r.length===1)return r[0];for(let n=r.length-1;n>=0;n--)e+=r[r.length-1-n]*Math.pow(2,t*n);return e}function Ae(r,t,e=-1){let n=e,s=r,i=0,o=Math.pow(2,t);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 l=a-1;l>=0;l--){let u=Math.pow(2,l*t);f[i-l-1]=Math.floor(s/u),s-=f[i-l-1]*u}return c}o*=Math.pow(2,t)}return new ArrayBuffer(0)}function Bn(...r){let t=0,e=0;for(let i of r)t+=i.length;let n=new ArrayBuffer(t),s=new Uint8Array(n);for(let i of r)s.set(i,e),e+=i.length;return s}function qi(){let r=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){let a=r[0]===255&&r[1]&128,c=r[0]===0&&(r[1]&128)===0;(a||c)&&this.warnings.push("Needlessly long format")}let t=new ArrayBuffer(this.valueHex.byteLength),e=new Uint8Array(t);for(let a=0;a<this.valueHex.byteLength;a++)e[a]=0;e[0]=r[0]&128;let n=He(e,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,He(i,8)-n}function Ka(r){let t=r<0?r*-1:r,e=128;for(let n=1;n<8;n++){if(t<=e){if(r<0){let o=e-t,a=Ae(o,8,n),c=new Uint8Array(a);return c[0]|=128,a}let s=Ae(t,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}e*=Math.pow(2,8)}return new ArrayBuffer(0)}function qa(r,t){if(r.byteLength!==t.byteLength)return!1;let e=new Uint8Array(r),n=new Uint8Array(t);for(let s=0;s<e.length;s++)if(e[s]!==n[s])return!1;return!0}function Lt(r,t){let e=r.toString(10);if(t<e.length)return"";let n=t-e.length,s=new Array(n);for(let o=0;o<n;o++)s[o]="0";return s.join("").concat(e)}var Yp=Math.log(2);function An(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function $i(r){let t=0,e=0;for(let s=0;s<r.length;s++){let i=r[s];t+=i.byteLength}let n=new Uint8Array(t);for(let s=0;s<r.length;s++){let i=r[s];n.set(new Uint8Array(i),e),e+=i.byteLength}return n.buffer}function ae(r,t,e,n){return t instanceof Uint8Array?t.byteLength?e<0?(r.error="Wrong parameter: inputOffset less than zero",!1):n<0?(r.error="Wrong parameter: inputLength less than zero",!1):t.byteLength-e-n<0?(r.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):!0:(r.error="Wrong parameter: inputBuffer has zero length",!1):(r.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}var Lr=class{constructor(){this.items=[]}write(t){this.items.push(t)}final(){return $i(this.items)}},Cr=[new Uint8Array([1])],$a="0123456789";var or="",Ft=new ArrayBuffer(0),zi=new Uint8Array(0),Ur="EndOfContent",Ga="OCTET STRING",Wa="BIT STRING";function ce(r){var t;return t=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?M.BufferSourceConverter.toUint8Array(i.valueHex):zi}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(!ae(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",Ft)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:M.Convert.ToHex(this.valueHexView)}}},t.NAME="hexBlock",t}var se=class{constructor({blockLength:t=0,error:e=or,warnings:n=[],valueBeforeDecode:s=zi}={}){this.blockLength=t,this.error=e,this.warnings=n,this.valueBeforeDecodeView=M.BufferSourceConverter.toUint8Array(s)}static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(t){this.valueBeforeDecodeView=new Uint8Array(t)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:M.Convert.ToHex(this.valueBeforeDecodeView)}}};se.NAME="baseBlock";var yt=class extends se{fromBER(t,e,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(t,e){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}};yt.NAME="valueBlock";var kn=class extends ce(se){constructor({idBlock:t={}}={}){var e,n,s,i;super(),t?(this.isHexOnly=(e=t.isHexOnly)!==null&&e!==void 0?e:!1,this.valueHexView=t.valueHex?M.BufferSourceConverter.toUint8Array(t.valueHex):zi,this.tagClass=(n=t.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(s=t.tagNumber)!==null&&s!==void 0?s:-1,this.isConstructed=(i=t.isConstructed)!==null&&i!==void 0?i:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(t=!1){let e=0;switch(this.tagClass){case 1:e|=0;break;case 2:e|=64;break;case 3:e|=128;break;case 4:e|=192;break;default:return this.error="Unknown tag class",Ft}if(this.isConstructed&&(e|=32),this.tagNumber<31&&!this.isHexOnly){let s=new Uint8Array(1);if(!t){let i=this.tagNumber;i&=31,e|=i,s[0]=e}return s.buffer}if(!this.isHexOnly){let s=Ae(this.tagNumber,7),i=new Uint8Array(s),o=s.byteLength,a=new Uint8Array(o+1);if(a[0]=e|31,!t){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]=e|31,!t){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(t,e,n){let s=M.BufferSourceConverter.toUint8Array(t);if(!ae(this,s,e,n))return-1;let i=s.subarray(e,e+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),l=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===l){l+=255;let h=new Uint8Array(l);for(let g=0;g<f.length;g++)h[g]=f[g];f=this.valueHexView=new Uint8Array(l)}}this.blockLength=c+1,f[c-1]=i[c]&127;let u=new Uint8Array(c);for(let h=0;h<c;h++)u[h]=f[h];f=this.valueHexView=new Uint8Array(c),f.set(u),this.blockLength<=9?this.tagNumber=He(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 e+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}};kn.NAME="identificationBlock";var Sn=class extends se{constructor({lenBlock:t={}}={}){var e,n,s;super(),this.isIndefiniteForm=(e=t.isIndefiniteForm)!==null&&e!==void 0?e:!1,this.longFormUsed=(n=t.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(s=t.length)!==null&&s!==void 0?s:0}fromBER(t,e,n){let s=M.BufferSourceConverter.toUint8Array(t);if(!ae(this,s,e,n))return-1;let i=s.subarray(e,e+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,e+this.blockLength;if(this.longFormUsed=!!(i[0]&128),this.longFormUsed===!1)return this.length=i[0],this.blockLength=1,e+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=e+1,c=s.subarray(a,a+o);return c[o-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=He(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=o+1,e+this.blockLength}toBER(t=!1){let e,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return e=new ArrayBuffer(1),t===!1&&(n=new Uint8Array(e),n[0]=128),e;if(this.longFormUsed){let s=Ae(this.length,8);if(s.byteLength>127)return this.error="Too big length",Ft;if(e=new ArrayBuffer(s.byteLength+1),t)return e;let i=new Uint8Array(s);n=new Uint8Array(e),n[0]=s.byteLength|128;for(let o=0;o<s.byteLength;o++)n[o+1]=i[o];return e}return e=new ArrayBuffer(1),t===!1&&(n=new Uint8Array(e),n[0]=this.length),e}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};Sn.NAME="lengthBlock";var A={},dt=class extends se{constructor({name:t=or,optional:e=!1,primitiveSchema:n,...s}={},i){super(s),this.name=t,this.optional=e,n&&(this.primitiveSchema=n),this.idBlock=new kn(s),this.lenBlock=new Sn(s),this.valueBlock=i?new i(s):new yt(s)}fromBER(t,e,n){let s=this.valueBlock.fromBER(t,e,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),s)}toBER(t,e){let n=e||new Lr;e||Za(this);let s=this.idBlock.toBER(t);if(n.write(s),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(t,n),n.write(new ArrayBuffer(2));else{let i=this.valueBlock.toBER(t);this.lenBlock.length=i.byteLength;let o=this.lenBlock.toBER(t);n.write(o),n.write(i)}return e?Ft:n.final()}toJSON(){let t={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(t.primitiveSchema=this.primitiveSchema.toJSON()),t}toString(t="ascii"){return t==="ascii"?this.onAsciiEncoding():M.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${M.Convert.ToHex(this.valueBlock.valueBeforeDecodeView)}`}isEqual(t){if(this===t)return!0;if(!(t instanceof this.constructor))return!1;let e=this.toBER(),n=t.toBER();return qa(e,n)}};dt.NAME="BaseBlock";function Za(r){if(r instanceof A.Constructed)for(let t of r.valueBlock.value)Za(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var In=class extends dt{constructor({value:t=or,...e}={},n){super(e,n),t&&this.fromString(t)}getValue(){return this.valueBlock.value}setValue(t){this.valueBlock.value=t}fromBER(t,e,n){let s=this.valueBlock.fromBER(t,e,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),s)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};In.NAME="BaseStringBlock";var Tn=class extends ce(yt){constructor({isHexOnly:t=!0,...e}={}){super(e),this.isHexOnly=t}};Tn.NAME="PrimitiveValueBlock";var ja,Nn=class extends dt{constructor(t={}){super(t,Tn),this.idBlock.isConstructed=!1}};ja=Nn;A.Primitive=ja;Nn.NAME="PRIMITIVE";function Sh(r,t){if(r instanceof t)return r;let e=new t;return e.idBlock=r.idBlock,e.lenBlock=r.lenBlock,e.warnings=r.warnings,e.valueBeforeDecodeView=r.valueBeforeDecodeView,e}function ls(r,t=0,e=r.length){let n=t,s=new dt({},yt),i=new se;if(!ae(i,r,t,e))return s.error=i.error,{offset:-1,result:s};if(!r.subarray(t,t+e).length)return s.error="Zero buffer length",{offset:-1,result:s};let a=s.idBlock.fromBER(r,t,e);if(s.idBlock.warnings.length&&s.warnings.concat(s.idBlock.warnings),a===-1)return s.error=s.idBlock.error,{offset:-1,result:s};if(t=a,e-=s.idBlock.blockLength,a=s.lenBlock.fromBER(r,t,e),s.lenBlock.warnings.length&&s.warnings.concat(s.lenBlock.warnings),a===-1)return s.error=s.lenBlock.error,{offset:-1,result:s};if(t=a,e-=s.lenBlock.blockLength,!s.idBlock.isConstructed&&s.lenBlock.isIndefiniteForm)return s.error="Indefinite length form used for primitive encoding form",{offset:-1,result:s};let c=dt;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=Sh(s,c),a=s.fromBER(r,t,s.lenBlock.isIndefiniteForm?e:s.lenBlock.length),s.valueBeforeDecodeView=r.subarray(n,n+s.blockLength),{offset:a,result:s}}function Gi(r){if(!r.byteLength){let t=new dt({},yt);return t.error="Input buffer has zero length",{offset:-1,result:t}}return ls(M.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function Ih(r,t){return r?1:t}var Gt=class extends yt{constructor({value:t=[],isIndefiniteForm:e=!1,...n}={}){super(n),this.value=t,this.isIndefiniteForm=e}fromBER(t,e,n){let s=M.BufferSourceConverter.toUint8Array(t);if(!ae(this,s,e,n))return-1;if(this.valueBeforeDecodeView=s.subarray(e,e+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),e;let i=e;for(;Ih(this.isIndefiniteForm,n)>0;){let o=ls(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===Ur)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===Ur?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(t,e){let n=e||new Lr;for(let s=0;s<this.value.length;s++)this.value[s].toBER(t,n);return e?Ft:n.final()}toJSON(){let t={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let e of this.value)t.value.push(e.toJSON());return t}};Gt.NAME="ConstructedValueBlock";var Ya,ke=class extends dt{constructor(t={}){super(t,Gt),this.idBlock.isConstructed=!0}fromBER(t,e,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let s=this.valueBlock.fromBER(t,e,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),s)}onAsciiEncoding(){let t=[];for(let n of this.valueBlock.value)t.push(n.toString("ascii").split(`
|
|
3
3
|
`).map(s=>` ${s}`).join(`
|
|
4
|
-
`));let
|
|
5
|
-
${
|
|
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);})();
|
|
4
|
+
`));let e=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return t.length?`${e} :
|
|
5
|
+
${t.join(`
|
|
6
|
+
`)}`:`${e} :`}};Ya=ke;A.Constructed=Ya;ke.NAME="CONSTRUCTED";var Cn=class extends yt{fromBER(t,e,n){return e}toBER(t){return Ft}};Cn.override="EndOfContentValueBlock";var Ja,Ln=class extends dt{constructor(t={}){super(t,Cn),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};Ja=Ln;A.EndOfContent=Ja;Ln.NAME=Ur;var Xa,nr=class extends dt{constructor(t={}){super(t,yt),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(t,e,n){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=n,e+n>t.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):e+n}toBER(t,e){let n=new ArrayBuffer(2);if(!t){let s=new Uint8Array(n);s[0]=5,s[1]=0}return e&&e.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};Xa=nr;A.Null=Xa;nr.NAME="NULL";var Un=class extends ce(yt){constructor({value:t,...e}={}){super(e),e.valueHex?this.valueHexView=M.BufferSourceConverter.toUint8Array(e.valueHex):this.valueHexView=new Uint8Array(1),t&&(this.value=t)}get value(){for(let t of this.valueHexView)if(t>0)return!0;return!1}set value(t){this.valueHexView[0]=t?255:0}fromBER(t,e,n){let s=M.BufferSourceConverter.toUint8Array(t);return ae(this,s,e,n)?(this.valueHexView=s.subarray(e,e+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,qi.call(this),this.blockLength=n,e+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};Un.NAME="BooleanValueBlock";var Qa,Rn=class extends dt{constructor(t={}){super(t,Un),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}getValue(){return this.valueBlock.value}setValue(t){this.valueBlock.value=t}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};Qa=Rn;A.Boolean=Qa;Rn.NAME="BOOLEAN";var _n=class extends ce(Gt){constructor({isConstructed:t=!1,...e}={}){super(e),this.isConstructed=t}fromBER(t,e,n){let s=0;if(this.isConstructed){if(this.isHexOnly=!1,s=Gt.prototype.fromBER.call(this,t,e,n),s===-1)return s;for(let i=0;i<this.value.length;i++){let o=this.value[i].constructor.NAME;if(o===Ur){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(o!==Ga)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,s=super.fromBER(t,e,n),this.blockLength=n;return s}toBER(t,e){return this.isConstructed?Gt.prototype.toBER.call(this,t,e):t?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};_n.NAME="OctetStringValueBlock";var tc,Vn=class r extends dt{constructor({idBlock:t={},lenBlock:e={},...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,...t},lenBlock:{...e,isIndefiniteForm:!!n.isIndefiniteForm},...n},_n),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(t,e,n){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,n===0)return this.idBlock.error.length===0&&(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length===0&&(this.blockLength+=this.lenBlock.blockLength),e;if(!this.valueBlock.isConstructed){let i=(t instanceof ArrayBuffer?new Uint8Array(t):t).subarray(e,e+n);try{if(i.byteLength){let o=ls(i,0,i.byteLength);o.offset!==-1&&o.offset===n&&(this.valueBlock.value=[o.result])}}catch{}}return super.fromBER(t,e,n)}onAsciiEncoding(){return this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length?ke.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${M.Convert.ToHex(this.valueBlock.valueHexView)}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let t=[];for(let e of this.valueBlock.value)e instanceof r&&t.push(e.valueBlock.valueHexView);return M.BufferSourceConverter.concat(t)}};tc=Vn;A.OctetString=tc;Vn.NAME=Ga;var On=class extends ce(Gt){constructor({unusedBits:t=0,isConstructed:e=!1,...n}={}){super(n),this.unusedBits=t,this.isConstructed=e,this.blockLength=this.valueHexView.byteLength}fromBER(t,e,n){if(!n)return e;let s=-1;if(this.isConstructed){if(s=Gt.prototype.fromBER.call(this,t,e,n),s===-1)return s;for(let a of this.value){let c=a.constructor.NAME;if(c===Ur){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==Wa)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=M.BufferSourceConverter.toUint8Array(t);if(!ae(this,i,e,n))return-1;let o=i.subarray(e,e+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=ls(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,e+n}toBER(t,e){if(this.isConstructed)return Gt.prototype.toBER.call(this,t,e);if(t)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return Ft;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}}};On.NAME="BitStringValueBlock";var ec,sr=class extends dt{constructor({idBlock:t={},lenBlock:e={},...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,...t},lenBlock:{...e,isIndefiniteForm:!!n.isIndefiniteForm},...n},On),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(t,e,n){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(t,e,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return ke.prototype.onAsciiEncoding.call(this);{let t=[],e=this.valueBlock.valueHexView;for(let s of e)t.push(s.toString(2).padStart(8,"0"));let n=t.join("");return`${this.constructor.NAME} : ${n.substring(0,n.length-this.valueBlock.unusedBits)}`}}};ec=sr;A.BitString=ec;sr.NAME=Wa;var rc;function Th(r,t){let e=new Uint8Array([0]),n=new Uint8Array(r),s=new Uint8Array(t),i=n.slice(0),o=i.length-1,a=s.slice(0),c=a.length-1,f=0,l=c<o?o:c,u=0;for(let h=l;h>=0;h--,u++){switch(!0){case u<a.length:f=i[o-u]+a[c-u]+e[0];break;default:f=i[o-u]+e[0]}switch(e[0]=f/10,!0){case u>=i.length:i=Bn(new Uint8Array([f%10]),i);break;default:i[o-u]=f%10}}return e[0]>0&&(i=Bn(e,i)),i}function za(r){if(r>=Cr.length)for(let t=Cr.length;t<=r;t++){let e=new Uint8Array([0]),n=Cr[t-1].slice(0);for(let s=n.length-1;s>=0;s--){let i=new Uint8Array([(n[s]<<1)+e[0]]);e[0]=i[0]/10,n[s]=i[0]%10}e[0]>0&&(n=Bn(e,n)),Cr.push(n)}return Cr[r]}function Nh(r,t){let e=0,n=new Uint8Array(r),s=new Uint8Array(t),i=n.slice(0),o=i.length-1,a=s.slice(0),c=a.length-1,f,l=0;for(let u=c;u>=0;u--,l++)switch(f=i[o-l]-a[c-l]-e,!0){case f<0:e=1,i[o-l]=f+10;break;default:e=0,i[o-l]=f}if(e>0)for(let u=o-c+1;u>=0;u--,l++)if(f=i[o-l]-e,f<0)e=1,i[o-l]=f+10;else{e=0,i[o-l]=f;break}return i.slice()}var Rr=class extends ce(yt){constructor({value:t,...e}={}){super(e),this._valueDec=0,e.valueHex&&this.setValueHex(),t!==void 0&&(this.valueDec=t)}setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=qi.call(this)))}set valueDec(t){this._valueDec=t,this.isHexOnly=!1,this.valueHexView=new Uint8Array(Ka(t))}get valueDec(){return this._valueDec}fromDER(t,e,n,s=0){let i=this.fromBER(t,e,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(t=!1){let e=this.valueHexView;switch(!0){case(e[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(e,1),this.valueHexView=n}break;case(e[0]===0&&(e[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(t)}fromBER(t,e,n){let s=super.fromBER(t,e,n);return s===-1||this.setValueHex(),s}toBER(t){return t?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let t=this.valueHexView.length*8-1,e=new Uint8Array(this.valueHexView.length*8/3),n=0,s,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 t:e=Nh(za(n),e),o="-";break;default:e=Th(e,za(n))}n++,s>>=1}}for(let c=0;c<e.length;c++)e[c]&&(a=!0),a&&(o+=$a.charAt(e[c]));return a===!1&&(o+=$a.charAt(0)),o}};rc=Rr;Rr.NAME="IntegerValueBlock";Object.defineProperty(rc.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var nc,pt=class r extends dt{constructor(t={}){super(t,Rr),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return An(),BigInt(this.valueBlock.toString())}static fromBigInt(t){An();let e=BigInt(t),n=new Lr,s=e.toString(16).replace(/^-/,""),i=new Uint8Array(M.Convert.FromHex(s));if(e<0){let a=new Uint8Array(i.length+(i[0]&128?1:0));a[0]|=128;let f=BigInt(`0x${M.Convert.ToHex(a)}`)+e,l=M.BufferSourceConverter.toUint8Array(M.Convert.FromHex(f.toString(16)));l[0]|=128,n.write(l)}else i[0]&128&&n.write(new Uint8Array([0])),n.write(i);return new r({valueHex:n.final()})}convertToDER(){let t=new r({valueHex:this.valueBlock.valueHexView});return t.valueBlock.toDER(),t}convertFromDER(){return new r({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};nc=pt;A.Integer=nc;pt.NAME="INTEGER";var sc,Dn=class extends pt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};sc=Dn;A.Enumerated=sc;Dn.NAME="ENUMERATED";var _r=class extends ce(yt){constructor({valueDec:t=-1,isFirstSid:e=!1,...n}={}){super(n),this.valueDec=t,this.isFirstSid=e}fromBER(t,e,n){if(!n)return e;let s=M.BufferSourceConverter.toUint8Array(t);if(!ae(this,s,e,n))return-1;let i=s.subarray(e,e+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=He(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),e+this.blockLength)}set valueBigInt(t){An();let e=BigInt(t).toString(2);for(;e.length%7;)e="0"+e;let n=new Uint8Array(e.length/7);for(let s=0;s<n.length;s++)n[s]=parseInt(e.slice(s*7,s*7+7),2)+(s+1<n.length?128:0);this.fromBER(n.buffer,0,n.length)}toBER(t){if(this.isHexOnly){if(t)return new ArrayBuffer(this.valueHexView.byteLength);let s=this.valueHexView,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 e=Ae(this.valueDec,7);if(e.byteLength===0)return this.error="Error during encoding SID value",Ft;let n=new Uint8Array(e.byteLength);if(!t){let s=new Uint8Array(e),i=e.byteLength-1;for(let o=0;o<i;o++)n[o]=s[o]|128;n[i]=s[i]}return n}toString(){let t="";if(this.isHexOnly)t=M.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let e=this.valueDec;this.valueDec<=39?t="0.":this.valueDec<=79?(t="1.",e-=40):(t="2.",e-=80),t+=e.toString()}else t=this.valueDec.toString();return t}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};_r.NAME="sidBlock";var Pn=class extends yt{constructor({value:t=or,...e}={}){super(e),this.value=[],t&&this.fromString(t)}fromBER(t,e,n){let s=e;for(;n>0;){let i=new _r;if(s=i.fromBER(t,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(t){let e=[];for(let n=0;n<this.value.length;n++){let s=this.value[n].toBER(t);if(s.byteLength===0)return this.error=this.value[n].error,Ft;e.push(s)}return $i(e)}fromString(t){this.value=[];let e=0,n=0,s="",i=!1;do if(n=t.indexOf(".",e),n===-1?s=t.substring(e):s=t.substring(e,n),e=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 _r;if(s>Number.MAX_SAFE_INTEGER){An();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 t="",e=!1;for(let n=0;n<this.value.length;n++){e=this.value[n].isHexOnly;let s=this.value[n].toString();n!==0&&(t=`${t}.`),e?(s=`{${s}}`,this.value[n].isFirstSid?t=`2.{${s} - 80}`:t+=s):t+=s}return t}toJSON(){let t={...super.toJSON(),value:this.toString(),sidArray:[]};for(let e=0;e<this.value.length;e++)t.sidArray.push(this.value[e].toJSON());return t}};Pn.NAME="ObjectIdentifierValueBlock";var ic,ir=class extends dt{constructor(t={}){super(t,Pn),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}getValue(){return this.valueBlock.toString()}setValue(t){this.valueBlock.fromString(t)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};ic=ir;A.ObjectIdentifier=ic;ir.NAME="OBJECT IDENTIFIER";var Vr=class extends ce(se){constructor({valueDec:t=0,...e}={}){super(e),this.valueDec=t}fromBER(t,e,n){if(n===0)return e;let s=M.BufferSourceConverter.toUint8Array(t);if(!ae(this,s,e,n))return-1;let i=s.subarray(e,e+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=He(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),e+this.blockLength)}toBER(t){if(this.isHexOnly){if(t)return new ArrayBuffer(this.valueHexView.byteLength);let s=this.valueHexView,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 e=Ae(this.valueDec,7);if(e.byteLength===0)return this.error="Error during encoding SID value",Ft;let n=new Uint8Array(e.byteLength);if(!t){let s=new Uint8Array(e),i=e.byteLength-1;for(let o=0;o<i;o++)n[o]=s[o]|128;n[i]=s[i]}return n.buffer}toString(){let t="";return this.isHexOnly?t=M.Convert.ToHex(this.valueHexView):t=this.valueDec.toString(),t}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};Vr.NAME="relativeSidBlock";var Mn=class extends yt{constructor({value:t=or,...e}={}){super(e),this.value=[],t&&this.fromString(t)}fromBER(t,e,n){let s=e;for(;n>0;){let i=new Vr;if(s=i.fromBER(t,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(t,e){let n=[];for(let s=0;s<this.value.length;s++){let i=this.value[s].toBER(t);if(i.byteLength===0)return this.error=this.value[s].error,Ft;n.push(i)}return $i(n)}fromString(t){this.value=[];let e=0,n=0,s="";do{n=t.indexOf(".",e),n===-1?s=t.substring(e):s=t.substring(e,n),e=n+1;let i=new Vr;if(i.valueDec=parseInt(s,10),isNaN(i.valueDec))return!0;this.value.push(i)}while(n!==-1);return!0}toString(){let t="",e=!1;for(let n=0;n<this.value.length;n++){e=this.value[n].isHexOnly;let s=this.value[n].toString();n!==0&&(t=`${t}.`),e&&(s=`{${s}}`),t+=s}return t}toJSON(){let t={...super.toJSON(),value:this.toString(),sidArray:[]};for(let e=0;e<this.value.length;e++)t.sidArray.push(this.value[e].toJSON());return t}};Mn.NAME="RelativeObjectIdentifierValueBlock";var oc,Hn=class extends dt{constructor(t={}){super(t,Mn),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}getValue(){return this.valueBlock.toString()}setValue(t){this.valueBlock.fromString(t)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};oc=Hn;A.RelativeObjectIdentifier=oc;Hn.NAME="RelativeObjectIdentifier";var ac,ie=class extends ke{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};ac=ie;A.Sequence=ac;ie.NAME="SEQUENCE";var cc,Fn=class extends ke{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};cc=Fn;A.Set=cc;Fn.NAME="SET";var Kn=class extends ce(yt){constructor({...t}={}){super(t),this.isHexOnly=!0,this.value=or}toJSON(){return{...super.toJSON(),value:this.value}}};Kn.NAME="StringValueBlock";var qn=class extends Kn{};qn.NAME="SimpleStringValueBlock";var At=class extends In{constructor({...t}={}){super(t,qn)}fromBuffer(t){this.valueBlock.value=String.fromCharCode.apply(null,M.BufferSourceConverter.toUint8Array(t))}fromString(t){let e=t.length,n=this.valueBlock.valueHexView=new Uint8Array(e);for(let s=0;s<e;s++)n[s]=t.charCodeAt(s);this.valueBlock.value=t}};At.NAME="SIMPLE STRING";var $n=class extends At{fromBuffer(t){this.valueBlock.valueHexView=M.BufferSourceConverter.toUint8Array(t);try{this.valueBlock.value=M.Convert.ToUtf8String(t)}catch(e){this.warnings.push(`Error during "decodeURIComponent": ${e}, using raw string`),this.valueBlock.value=M.Convert.ToBinary(t)}}fromString(t){this.valueBlock.valueHexView=new Uint8Array(M.Convert.FromUtf8String(t)),this.valueBlock.value=t}};$n.NAME="Utf8StringValueBlock";var lc,oe=class extends $n{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};lc=oe;A.Utf8String=lc;oe.NAME="UTF8String";var zn=class extends At{fromBuffer(t){this.valueBlock.value=M.Convert.ToUtf16String(t),this.valueBlock.valueHexView=M.BufferSourceConverter.toUint8Array(t)}fromString(t){this.valueBlock.value=t,this.valueBlock.valueHexView=new Uint8Array(M.Convert.FromUtf16String(t))}};zn.NAME="BmpStringValueBlock";var uc,Gn=class extends zn{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};uc=Gn;A.BmpString=uc;Gn.NAME="BMPString";var Wn=class extends At{fromBuffer(t){let e=ArrayBuffer.isView(t)?t.slice().buffer:t.slice(0),n=new Uint8Array(e);for(let s=0;s<n.length;s+=4)n[s]=n[s+3],n[s+1]=n[s+2],n[s+2]=0,n[s+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(e))}fromString(t){let e=t.length,n=this.valueBlock.valueHexView=new Uint8Array(e*4);for(let s=0;s<e;s++){let i=Ae(t.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=t}};Wn.NAME="UniversalStringValueBlock";var fc,Zn=class extends Wn{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};fc=Zn;A.UniversalString=fc;Zn.NAME="UniversalString";var hc,jn=class extends At{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};hc=jn;A.NumericString=hc;jn.NAME="NumericString";var dc,Yn=class extends At{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};dc=Yn;A.PrintableString=dc;Yn.NAME="PrintableString";var pc,Jn=class extends At{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};pc=Jn;A.TeletexString=pc;Jn.NAME="TeletexString";var mc,Xn=class extends At{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};mc=Xn;A.VideotexString=mc;Xn.NAME="VideotexString";var gc,Qn=class extends At{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};gc=Qn;A.IA5String=gc;Qn.NAME="IA5String";var yc,ts=class extends At{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};yc=ts;A.GraphicString=yc;ts.NAME="GraphicString";var bc,Or=class extends At{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};bc=Or;A.VisibleString=bc;Or.NAME="VisibleString";var wc,es=class extends At{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};wc=es;A.GeneralString=wc;es.NAME="GeneralString";var xc,rs=class extends At{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};xc=rs;A.CharacterString=xc;rs.NAME="CharacterString";var vc,Dr=class extends Or{constructor({value:t,valueDate:e,...n}={}){if(super(n),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,t){this.fromString(t),this.valueBlock.valueHexView=new Uint8Array(t.length);for(let s=0;s<t.length;s++)this.valueBlock.valueHexView[s]=t.charCodeAt(s)}e&&(this.fromDate(e),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(t){this.fromString(String.fromCharCode.apply(null,M.BufferSourceConverter.toUint8Array(t)))}toBuffer(){let t=this.toString(),e=new ArrayBuffer(t.length),n=new Uint8Array(e);for(let s=0;s<t.length;s++)n[s]=t.charCodeAt(s);return e}fromDate(t){this.year=t.getUTCFullYear(),this.month=t.getUTCMonth()+1,this.day=t.getUTCDate(),this.hour=t.getUTCHours(),this.minute=t.getUTCMinutes(),this.second=t.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(t){let n=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(t);if(n===null){this.error="Wrong input string for conversion";return}let s=parseInt(n[1],10);s>=50?this.year=1900+s:this.year=2e3+s,this.month=parseInt(n[2],10),this.day=parseInt(n[3],10),this.hour=parseInt(n[4],10),this.minute=parseInt(n[5],10),this.second=parseInt(n[6],10)}toString(t="iso"){if(t==="iso"){let e=new Array(7);return e[0]=Lt(this.year<2e3?this.year-1900:this.year-2e3,2),e[1]=Lt(this.month,2),e[2]=Lt(this.day,2),e[3]=Lt(this.hour,2),e[4]=Lt(this.minute,2),e[5]=Lt(this.second,2),e[6]="Z",e.join("")}return super.toString(t)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}};vc=Dr;A.UTCTime=vc;Dr.NAME="UTCTime";var Ec,ns=class extends Dr{constructor(t={}){var e;super(t),(e=this.millisecond)!==null&&e!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(t){super.fromDate(t),this.millisecond=t.getUTCMilliseconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond))}fromString(t){let e=!1,n="",s="",i=0,o,a=0,c=0;if(t[t.length-1]==="Z")n=t.substring(0,t.length-1),e=!0;else{let u=new Number(t[t.length-1]);if(isNaN(u.valueOf()))throw new Error("Wrong input string for conversion");n=t}if(e){if(n.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(n.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let u=1,h=n.indexOf("+"),g="";if(h===-1&&(h=n.indexOf("-"),u=-1),h!==-1){if(g=n.substring(h+1),n=n.substring(0,h),g.length!==2&&g.length!==4)throw new Error("Wrong input string for conversion");let x=parseInt(g.substring(0,2),10);if(isNaN(x.valueOf()))throw new Error("Wrong input string for conversion");if(a=u*x,g.length===4){if(x=parseInt(g.substring(2,4),10),isNaN(x.valueOf()))throw new Error("Wrong input string for conversion");c=u*x}}}let f=n.indexOf(".");if(f===-1&&(f=n.indexOf(",")),f!==-1){let u=new Number(`0${n.substring(f)}`);if(isNaN(u.valueOf()))throw new Error("Wrong input string for conversion");i=u.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 u=60*i;this.minute=Math.floor(u),u=60*(u-this.minute),this.second=Math.floor(u),u=1e3*(u-this.second),this.millisecond=Math.floor(u)}break;case s.length===12:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let u=60*i;this.second=Math.floor(u),u=1e3*(u-this.second),this.millisecond=Math.floor(u)}break;case s.length===14:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let u=1e3*i;this.millisecond=Math.floor(u)}break;default:throw new Error("Wrong input string for conversion")}let l=o.exec(s);if(l===null)throw new Error("Wrong input string for conversion");for(let u=1;u<l.length;u++)switch(u){case 1:this.year=parseInt(l[u],10);break;case 2:this.month=parseInt(l[u],10);break;case 3:this.day=parseInt(l[u],10);break;case 4:this.hour=parseInt(l[u],10)+a;break;case 5:this.minute=parseInt(l[u],10)+c;break;case 6:this.second=parseInt(l[u],10);break;default:throw new Error("Wrong input string for conversion")}if(e===!1){let u=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=u.getUTCFullYear(),this.month=u.getUTCMonth(),this.day=u.getUTCDay(),this.hour=u.getUTCHours(),this.minute=u.getUTCMinutes(),this.second=u.getUTCSeconds(),this.millisecond=u.getUTCMilliseconds()}}toString(t="iso"){if(t==="iso"){let e=[];return e.push(Lt(this.year,4)),e.push(Lt(this.month,2)),e.push(Lt(this.day,2)),e.push(Lt(this.hour,2)),e.push(Lt(this.minute,2)),e.push(Lt(this.second,2)),this.millisecond!==0&&(e.push("."),e.push(Lt(this.millisecond,3))),e.push("Z"),e.join("")}return super.toString(t)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};Ec=ns;A.GeneralizedTime=Ec;ns.NAME="GeneralizedTime";var Bc,ss=class extends oe{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};Bc=ss;A.DATE=Bc;ss.NAME="DATE";var Ac,is=class extends oe{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};Ac=is;A.TimeOfDay=Ac;is.NAME="TimeOfDay";var kc,os=class extends oe{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};kc=os;A.DateTime=kc;os.NAME="DateTime";var Sc,as=class extends oe{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};Sc=as;A.Duration=Sc;as.NAME="Duration";var Ic,cs=class extends oe{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};Ic=cs;A.TIME=Ic;cs.NAME="TIME";function q(r,t="utf8"){let e=bn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Pr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},us=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Tc={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new us("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var Se=Tc;async function Nc(r){let t=await Se.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),e=await Lh(t);return{privateKey:e[0],publicKey:e[1]}}async function Cc(r,t){let e=await Se.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await Se.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function Lc(r,t,e){let n=await Se.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return Se.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function Lh(r){if(r.privateKey==null||r.publicKey==null)throw new K("Private and public key are required");return Promise.all([Se.get().subtle.exportKey("jwk",r.privateKey),Se.get().subtle.exportKey("jwk",r.publicKey)])}function Wi(r){if(r.kty!=="RSA")throw new K("invalid key type");if(r.n==null)throw new K("invalid key modulus");return j(r.n,"base64url").length*8}var ar=class{type="RSA";_key;_raw;_multihash;constructor(t,e){this._key=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=Mr.jwkToPkix(this._key)),this._raw}toMultihash(){return this._multihash}toCID(){return it.createV1(114,this._multihash)}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ut(this.raw,t.raw)}verify(t,e){return Lc(this._key,e,t)}},Hr=class{type="RSA";_key;_raw;publicKey;constructor(t,e){this._key=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=Mr.jwkToPkcs1(this._key)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ut(this.raw,t.raw)}sign(t){return Cc(this._key,t)}};var fs=8192,Zi=18;function Uc(r){let{result:t}=Gi(r),e=t.valueBlock.value;return{n:q(Wt(e[1].toBigInt()),"base64url"),e:q(Wt(e[2].toBigInt()),"base64url"),d:q(Wt(e[3].toBigInt()),"base64url"),p:q(Wt(e[4].toBigInt()),"base64url"),q:q(Wt(e[5].toBigInt()),"base64url"),dp:q(Wt(e[6].toBigInt()),"base64url"),dq:q(Wt(e[7].toBigInt()),"base64url"),qi:q(Wt(e[8].toBigInt()),"base64url"),kty:"RSA",alg:"RS256"}}function Uh(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 K("JWK was missing components");let e=new ie({value:[new pt({value:0}),pt.fromBigInt(Zt(j(r.n,"base64url"))),pt.fromBigInt(Zt(j(r.e,"base64url"))),pt.fromBigInt(Zt(j(r.d,"base64url"))),pt.fromBigInt(Zt(j(r.p,"base64url"))),pt.fromBigInt(Zt(j(r.q,"base64url"))),pt.fromBigInt(Zt(j(r.dp,"base64url"))),pt.fromBigInt(Zt(j(r.dq,"base64url"))),pt.fromBigInt(Zt(j(r.qi,"base64url")))]}).toBER();return new Uint8Array(e,0,e.byteLength)}function Rc(r){let{result:t}=Gi(r),e=t.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:q(Wt(e[0].toBigInt()),"base64url"),e:q(Wt(e[1].toBigInt()),"base64url")}}function ji(r){if(r.n==null||r.e==null)throw new K("JWK was missing components");let e=new ie({value:[new ie({value:[new ir({value:"1.2.840.113549.1.1.1"}),new nr]}),new sr({valueHex:new ie({value:[pt.fromBigInt(Zt(j(r.n,"base64url"))),pt.fromBigInt(Zt(j(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(e,0,e.byteLength)}function Wt(r){let t=r.toString(16);t.length%2>0&&(t=`0${t}`);let e=t.length/2,n=new Uint8Array(e),s=0,i=0;for(;s<e;)n[s]=parseInt(t.slice(i,i+2),16),s+=1,i+=2;return n}function Zt(r){let t=[];return r.forEach(function(e){let n=e.toString(16);n.length%2>0&&(n=`0${n}`),t.push(n)}),BigInt("0x"+t.join(""))}function _c(r){let t=Uc(r);return Vc(t)}function Yi(r){let t=Rc(r);if(Wi(t)>fs)throw new $e("Key size is too large");let e=er(zt.encode({Type:at.RSA,Data:r})),n=Ot(Zi,e);return new ar(t,n)}function Vc(r){if(Wi(r)>fs)throw new K("Key size is too large");let t=Dc(r),e=er(zt.encode({Type:at.RSA,Data:ji(t.publicKey)})),n=Ot(Zi,e);return new Hr(t.privateKey,new ar(t.publicKey,n))}async function Oc(r){if(r>fs)throw new K("Key size is too large");let t=await Nc(r),e=er(zt.encode({Type:at.RSA,Data:ji(t.publicKey)})),n=Ot(Zi,e);return new Hr(t.privateKey,new ar(t.publicKey,n))}function Dc(r){if(r==null)throw new K("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}var hs=class extends Je{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,oa(t);let n=vr(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let s=this.blockLen,i=new Uint8Array(s);i.set(n.length>s?t.create().update(n).digest():n);for(let o=0;o<i.length;o++)i[o]^=54;this.iHash.update(i),this.oHash=t.create();for(let o=0;o<i.length;o++)i[o]^=106;this.oHash.update(i),i.fill(0)}update(t){return Ye(this),this.iHash.update(t),this}digestInto(t){Ye(this),je(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:s,destroyed:i,blockLen:o,outputLen:a}=this;return t=t,t.finished=s,t.destroyed=i,t.blockLen=o,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ji=(r,t,e)=>new hs(r,t).update(e).digest();Ji.create=(r,t)=>new hs(r,t);function Pc(r){r.lowS!==void 0&&Pt("lowS",r.lowS),r.prehash!==void 0&&Pt("prehash",r.prehash)}function Rh(r){let t=Ar(r);Kt(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:s}=t;if(e){if(!n.eql(s,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:_h,hexToBytes:Vh}=un,le={Err:class extends Error{constructor(t=""){super(t)}},_tlv:{encode:(r,t)=>{let{Err:e}=le;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,s=Le(n);if(s.length/2&128)throw new e("tlv.encode: long form length too big");let i=n>127?Le(s.length/2|128):"";return`${Le(r)}${i}${s}${t}`},decode(r,t){let{Err:e}=le,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let s=t[n++],i=!!(s&128),o=0;if(!i)o=s;else{let c=s&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+c);if(f.length!==c)throw new e("tlv.decode: length bytes not complete");if(f[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let l of f)o=o<<8|l;if(n+=c,o<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+o);if(a.length!==o)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+o)}}},_int:{encode(r){let{Err:t}=le;if(r<ue)throw new t("integer: negative integers are not allowed");let e=Le(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected assertion");return e},decode(r){let{Err:t}=le;if(r[0]&128)throw new t("Invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("Invalid signature integer: unnecessary leading zero");return _h(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=le,s=typeof r=="string"?Vh(r):r;Qe(s);let{v:i,l:o}=n.decode(48,s);if(o.length)throw new t("Invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:f,l}=n.decode(2,c);if(l.length)throw new t("Invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(f)}},hexFromSig(r){let{_tlv:t,_int:e}=le,n=`${t.encode(2,e.encode(r.r))}${t.encode(2,e.encode(r.s))}`;return t.encode(48,n)}},ue=BigInt(0),ft=BigInt(1),Tm=BigInt(2),Mc=BigInt(3),Nm=BigInt(4);function Oh(r){let t=Rh(r),{Fp:e}=t,n=xe(t.n,t.nBitLength),s=t.toBytes||((b,d,w)=>{let B=d.toAffine();return re(Uint8Array.from([4]),e.toBytes(B.x),e.toBytes(B.y))}),i=t.fromBytes||(b=>{let d=b.subarray(1),w=e.fromBytes(d.subarray(0,e.BYTES)),B=e.fromBytes(d.subarray(e.BYTES,2*e.BYTES));return{x:w,y:B}});function o(b){let{a:d,b:w}=t,B=e.sqr(b),m=e.mul(B,b);return e.add(e.add(m,e.mul(b,d)),w)}if(!e.eql(e.sqr(t.Gy),o(t.Gx)))throw new Error("bad generator point: equation left != right");function a(b){return Er(b,ft,t.n)}function c(b){let{allowedPrivateKeyLengths:d,nByteLength:w,wrapPrivateKey:B,n:m}=t;if(d&&typeof b!="bigint"){if(ye(b)&&(b=te(b)),typeof b!="string"||!d.includes(b.length))throw new Error("Invalid key");b=b.padStart(w*2,"0")}let k;try{k=typeof b=="bigint"?b:ee(tt("private key",b,w))}catch{throw new Error(`private key must be ${w} bytes, hex or bigint, not ${typeof b}`)}return B&&(k=G(k,m)),It("private key",k,ft,m),k}function f(b){if(!(b instanceof h))throw new Error("ProjectivePoint expected")}let l=_e((b,d)=>{let{px:w,py:B,pz:m}=b;if(e.eql(m,e.ONE))return{x:w,y:B};let k=b.is0();d==null&&(d=k?e.ONE:e.inv(m));let U=e.mul(w,d),L=e.mul(B,d),S=e.mul(m,d);if(k)return{x:e.ZERO,y:e.ZERO};if(!e.eql(S,e.ONE))throw new Error("invZ was invalid");return{x:U,y:L}}),u=_e(b=>{if(b.is0()){if(t.allowInfinityPoint&&!e.is0(b.py))return;throw new Error("bad point: ZERO")}let{x:d,y:w}=b.toAffine();if(!e.isValid(d)||!e.isValid(w))throw new Error("bad point: x or y not FE");let B=e.sqr(w),m=o(d);if(!e.eql(B,m))throw new Error("bad point: equation left != right");if(!b.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class h{constructor(d,w,B){if(this.px=d,this.py=w,this.pz=B,d==null||!e.isValid(d))throw new Error("x required");if(w==null||!e.isValid(w))throw new Error("y required");if(B==null||!e.isValid(B))throw new Error("z required");Object.freeze(this)}static fromAffine(d){let{x:w,y:B}=d||{};if(!d||!e.isValid(w)||!e.isValid(B))throw new Error("invalid affine point");if(d instanceof h)throw new Error("projective point not allowed");let m=k=>e.eql(k,e.ZERO);return m(w)&&m(B)?h.ZERO:new h(w,B,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){let w=e.invertBatch(d.map(B=>B.pz));return d.map((B,m)=>B.toAffine(w[m])).map(h.fromAffine)}static fromHex(d){let w=h.fromAffine(i(tt("pointHex",d)));return w.assertValidity(),w}static fromPrivateKey(d){return h.BASE.multiply(c(d))}static msm(d,w){return dn(h,n,d,w)}_setWindowSize(d){x.setWindowSize(this,d)}assertValidity(){u(this)}hasEvenY(){let{y:d}=this.toAffine();if(e.isOdd)return!e.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){f(d);let{px:w,py:B,pz:m}=this,{px:k,py:U,pz:L}=d,S=e.eql(e.mul(w,L),e.mul(k,m)),I=e.eql(e.mul(B,L),e.mul(U,m));return S&&I}negate(){return new h(this.px,e.neg(this.py),this.pz)}double(){let{a:d,b:w}=t,B=e.mul(w,Mc),{px:m,py:k,pz:U}=this,L=e.ZERO,S=e.ZERO,I=e.ZERO,C=e.mul(m,m),rt=e.mul(k,k),F=e.mul(U,U),O=e.mul(m,k);return O=e.add(O,O),I=e.mul(m,U),I=e.add(I,I),L=e.mul(d,I),S=e.mul(B,F),S=e.add(L,S),L=e.sub(rt,S),S=e.add(rt,S),S=e.mul(L,S),L=e.mul(O,L),I=e.mul(B,I),F=e.mul(d,F),O=e.sub(C,F),O=e.mul(d,O),O=e.add(O,I),I=e.add(C,C),C=e.add(I,C),C=e.add(C,F),C=e.mul(C,O),S=e.add(S,C),F=e.mul(k,U),F=e.add(F,F),C=e.mul(F,O),L=e.sub(L,C),I=e.mul(F,rt),I=e.add(I,I),I=e.add(I,I),new h(L,S,I)}add(d){f(d);let{px:w,py:B,pz:m}=this,{px:k,py:U,pz:L}=d,S=e.ZERO,I=e.ZERO,C=e.ZERO,rt=t.a,F=e.mul(t.b,Mc),O=e.mul(w,k),nt=e.mul(B,U),E=e.mul(m,L),T=e.add(w,B),y=e.add(k,U);T=e.mul(T,y),y=e.add(O,nt),T=e.sub(T,y),y=e.add(w,m);let p=e.add(k,L);return y=e.mul(y,p),p=e.add(O,E),y=e.sub(y,p),p=e.add(B,m),S=e.add(U,L),p=e.mul(p,S),S=e.add(nt,E),p=e.sub(p,S),C=e.mul(rt,y),S=e.mul(F,E),C=e.add(S,C),S=e.sub(nt,C),C=e.add(nt,C),I=e.mul(S,C),nt=e.add(O,O),nt=e.add(nt,O),E=e.mul(rt,E),y=e.mul(F,y),nt=e.add(nt,E),E=e.sub(O,E),E=e.mul(rt,E),y=e.add(y,E),O=e.mul(nt,y),I=e.add(I,O),O=e.mul(p,y),S=e.mul(T,S),S=e.sub(S,O),O=e.mul(T,nt),C=e.mul(p,C),C=e.add(C,O),new h(S,I,C)}subtract(d){return this.add(d.negate())}is0(){return this.equals(h.ZERO)}wNAF(d){return x.wNAFCached(this,d,h.normalizeZ)}multiplyUnsafe(d){It("scalar",d,ue,t.n);let w=h.ZERO;if(d===ue)return w;if(d===ft)return this;let{endo:B}=t;if(!B)return x.unsafeLadder(this,d);let{k1neg:m,k1:k,k2neg:U,k2:L}=B.splitScalar(d),S=w,I=w,C=this;for(;k>ue||L>ue;)k&ft&&(S=S.add(C)),L&ft&&(I=I.add(C)),C=C.double(),k>>=ft,L>>=ft;return m&&(S=S.negate()),U&&(I=I.negate()),I=new h(e.mul(I.px,B.beta),I.py,I.pz),S.add(I)}multiply(d){let{endo:w,n:B}=t;It("scalar",d,ft,B);let m,k;if(w){let{k1neg:U,k1:L,k2neg:S,k2:I}=w.splitScalar(d),{p:C,f:rt}=this.wNAF(L),{p:F,f:O}=this.wNAF(I);C=x.constTimeNegate(U,C),F=x.constTimeNegate(S,F),F=new h(e.mul(F.px,w.beta),F.py,F.pz),m=C.add(F),k=rt.add(O)}else{let{p:U,f:L}=this.wNAF(d);m=U,k=L}return h.normalizeZ([m,k])[0]}multiplyAndAddUnsafe(d,w,B){let m=h.BASE,k=(L,S)=>S===ue||S===ft||!L.equals(m)?L.multiplyUnsafe(S):L.multiply(S),U=k(this,w).add(k(d,B));return U.is0()?void 0:U}toAffine(d){return l(this,d)}isTorsionFree(){let{h:d,isTorsionFree:w}=t;if(d===ft)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}=t;return d===ft?this:w?w(h,this):this.multiplyUnsafe(t.h)}toRawBytes(d=!0){return Pt("isCompressed",d),this.assertValidity(),s(h,this,d)}toHex(d=!0){return Pt("isCompressed",d),te(this.toRawBytes(d))}}h.BASE=new h(t.Gx,t.Gy,e.ONE),h.ZERO=new h(e.ZERO,e.ONE,e.ZERO);let g=t.nBitLength,x=hn(h,t.endo?Math.ceil(g/2):g);return{CURVE:t,ProjectivePoint:h,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:a}}function Dh(r){let t=Ar(r);return Kt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Hc(r){let t=Dh(r),{Fp:e,n}=t,s=e.BYTES+1,i=2*e.BYTES+1;function o(E){return G(E,n)}function a(E){return fn(E,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:f,weierstrassEquation:l,isWithinCurveOrder:u}=Oh({...t,toBytes(E,T,y){let p=T.toAffine(),v=e.toBytes(p.x),N=re;return Pt("isCompressed",y),y?N(Uint8Array.from([T.hasEvenY()?2:3]),v):N(Uint8Array.from([4]),v,e.toBytes(p.y))},fromBytes(E){let T=E.length,y=E[0],p=E.subarray(1);if(T===s&&(y===2||y===3)){let v=ee(p);if(!Er(v,ft,e.ORDER))throw new Error("Point is not on curve");let N=l(v),R;try{R=e.sqrt(N)}catch(H){let P=H instanceof Error?": "+H.message:"";throw new Error("Point is not on curve"+P)}let _=(R&ft)===ft;return(y&1)===1!==_&&(R=e.neg(R)),{x:v,y:R}}else if(T===i&&y===4){let v=e.fromBytes(p.subarray(0,e.BYTES)),N=e.fromBytes(p.subarray(e.BYTES,2*e.BYTES));return{x:v,y:N}}else throw new Error(`Point of length ${T} was invalid. Expected ${s} compressed bytes or ${i} uncompressed bytes`)}}),h=E=>te(we(E,t.nByteLength));function g(E){let T=n>>ft;return E>T}function x(E){return g(E)?o(-E):E}let b=(E,T,y)=>ee(E.slice(T,y));class d{constructor(T,y,p){this.r=T,this.s=y,this.recovery=p,this.assertValidity()}static fromCompact(T){let y=t.nByteLength;return T=tt("compactSignature",T,y*2),new d(b(T,0,y),b(T,y,2*y))}static fromDER(T){let{r:y,s:p}=le.toSig(tt("DER",T));return new d(y,p)}assertValidity(){It("r",this.r,ft,n),It("s",this.s,ft,n)}addRecoveryBit(T){return new d(this.r,this.s,T)}recoverPublicKey(T){let{r:y,s:p,recovery:v}=this,N=L(tt("msgHash",T));if(v==null||![0,1,2,3].includes(v))throw new Error("recovery id invalid");let R=v===2||v===3?y+t.n:y;if(R>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let _=v&1?"03":"02",D=c.fromHex(_+h(R)),H=a(R),P=o(-N*H),z=o(p*H),Z=c.BASE.multiplyAndAddUnsafe(D,P,z);if(!Z)throw new Error("point at infinify");return Z.assertValidity(),Z}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new d(this.r,o(-this.s),this.recovery):this}toDERRawBytes(){return Ue(this.toDERHex())}toDERHex(){return le.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Ue(this.toCompactHex())}toCompactHex(){return h(this.r)+h(this.s)}}let w={isValidPrivateKey(E){try{return f(E),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let E=ri(t.n);return wa(t.randomBytes(E),t.n)},precompute(E=8,T=c.BASE){return T._setWindowSize(E),T.multiply(BigInt(3)),T}};function B(E,T=!0){return c.fromPrivateKey(E).toRawBytes(T)}function m(E){let T=ye(E),y=typeof E=="string",p=(T||y)&&E.length;return T?p===s||p===i:y?p===2*s||p===2*i:E instanceof c}function k(E,T,y=!0){if(m(E))throw new Error("first arg must be private key");if(!m(T))throw new Error("second arg must be public key");return c.fromHex(T).multiply(f(E)).toRawBytes(y)}let U=t.bits2int||function(E){let T=ee(E),y=E.length*8-t.nBitLength;return y>0?T>>BigInt(y):T},L=t.bits2int_modN||function(E){return o(U(E))},S=Br(t.nBitLength);function I(E){return It(`num < 2^${t.nBitLength}`,E,ue,S),we(E,t.nByteLength)}function C(E,T,y=rt){if(["recovered","canonical"].some(lt=>lt in y))throw new Error("sign() legacy options not supported");let{hash:p,randomBytes:v}=t,{lowS:N,prehash:R,extraEntropy:_}=y;N==null&&(N=!0),E=tt("msgHash",E),Pc(y),R&&(E=tt("prehashed msgHash",p(E)));let D=L(E),H=f(T),P=[I(H),I(D)];if(_!=null&&_!==!1){let lt=_===!0?v(e.BYTES):_;P.push(tt("extraEntropy",lt))}let z=re(...P),Z=D;function ct(lt){let ht=U(lt);if(!u(ht))return;let wt=a(ht),st=c.BASE.multiply(ht).toAffine(),St=o(st.x);if(St===ue)return;let jt=o(wt*o(Z+St*H));if(jt===ue)return;let gr=(st.x===St?0:2)|Number(st.y&ft),yr=jt;return N&&g(jt)&&(yr=x(jt),gr^=1),new d(St,yr,gr)}return{seed:z,k2sig:ct}}let rt={lowS:t.lowS,prehash:!1},F={lowS:t.lowS,prehash:!1};function O(E,T,y=rt){let{seed:p,k2sig:v}=C(E,T,y),N=t;return Xs(N.hash.outputLen,N.nByteLength,N.hmac)(p,v)}c.BASE._setWindowSize(8);function nt(E,T,y,p=F){let v=E;if(T=tt("msgHash",T),y=tt("publicKey",y),"strict"in p)throw new Error("options.strict was renamed to lowS");Pc(p);let{lowS:N,prehash:R}=p,_,D;try{if(typeof v=="string"||ye(v))try{_=d.fromDER(v)}catch(st){if(!(st instanceof le.Err))throw st;_=d.fromCompact(v)}else if(typeof v=="object"&&typeof v.r=="bigint"&&typeof v.s=="bigint"){let{r:st,s:St}=v;_=new d(st,St)}else throw new Error("PARSE");D=c.fromHex(y)}catch(st){if(st.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(N&&_.hasHighS())return!1;R&&(T=t.hash(T));let{r:H,s:P}=_,z=L(T),Z=a(P),ct=o(z*Z),lt=o(H*Z),ht=c.BASE.multiplyAndAddUnsafe(D,ct,lt)?.toAffine();return ht?o(ht.x)===H:!1}return{CURVE:t,getPublicKey:B,getSharedSecret:k,sign:O,verify:nt,ProjectivePoint:c,Signature:d,utils:w}}function Ph(r){return{hash:r,hmac:(t,...e)=>Ji(r,t,$s(...e)),randomBytes:an}}function Fc(r,t){let e=n=>Hc({...r,...Ph(n)});return Object.freeze({...e(t),create:e})}var $c=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Kc=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Mh=BigInt(1),Xi=BigInt(2),qc=(r,t)=>(r+t/Xi)/t;function Hh(r){let t=$c,e=BigInt(3),n=BigInt(6),s=BigInt(11),i=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%t,l=f*f*r%t,u=X(l,e,t)*l%t,h=X(u,e,t)*l%t,g=X(h,Xi,t)*f%t,x=X(g,s,t)*g%t,b=X(x,i,t)*x%t,d=X(b,a,t)*b%t,w=X(d,c,t)*d%t,B=X(w,a,t)*b%t,m=X(B,e,t)*l%t,k=X(m,o,t)*x%t,U=X(k,n,t)*f%t,L=X(U,Xi,t);if(!Qi.eql(Qi.sqr(L),r))throw new Error("Cannot find square root");return L}var Qi=xe($c,void 0,void 0,{sqrt:Hh}),Fe=Fc({a:BigInt(0),b:BigInt(7),Fp:Qi,n:Kc,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Kc,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Mh*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=e,o=BigInt("0x100000000000000000000000000000000"),a=qc(i*r,t),c=qc(-n*r,t),f=G(r-a*e-c*s,t),l=G(-a*n-c*i,t),u=f>o,h=l>o;if(u&&(f=t-f),h&&(l=t-l),f>o||l>o)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:u,k1:f,k2neg:h,k2:l}}}},er),Pm=BigInt(0);var Mm=Fe.ProjectivePoint;function Rt(r,t){t==null&&(t=r.reduce((s,i)=>s+i.length,0));let e=Nt(t),n=0;for(let s of r)e.set(s,n),n+=s.length;return e}function zc(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Gc(r,t,e){let n=kr.digest(e instanceof Uint8Array?e:e.subarray());if(zc(n))return n.then(({digest:s})=>Fe.verify(t,s,r)).catch(s=>{throw new Pr(String(s))});try{return Fe.verify(t,n.digest,r)}catch(s){throw new Pr(String(s))}}var ds=class{type="secp256k1";raw;_key;constructor(t){this._key=Zc(t),this.raw=Wc(this._key)}toMultihash(){return Xt.digest(qt(this))}toCID(){return it.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ut(this.raw,t.raw)}verify(t,e){return Gc(this._key,e,t)}};function to(r){return new ds(r)}function Wc(r){return Fe.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Zc(r){try{return Fe.ProjectivePoint.fromHex(r),r}catch(t){throw new $e(String(t))}}function ps(r){let{Type:t,Data:e}=zt.decode(r),n=e??new Uint8Array;switch(t){case at.RSA:return Yi(n);case at.Ed25519:return ai(n);case at.secp256k1:return to(n);default:throw new Ne}}function jc(r){let{Type:t,Data:e}=zt.decode(r.digest),n=e??new Uint8Array;switch(t){case at.Ed25519:return ai(n);case at.secp256k1:return to(n);default:throw new Ne}}function qt(r){return zt.encode({Type:at[r.type],Data:r.raw})}var Yc=Symbol.for("nodejs.util.inspect.custom"),Fh=114,Fr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[tn]=!0;toString(){return this.string==null&&(this.string=Y.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return it.createV1(Fh,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return ut(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return ut(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Yc](){return`PeerId(${this.toString()})`}},Kr=class extends Fr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},qr=class extends Fr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},$r=class extends Fr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Kh=2336,zr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Xt.digest(j(this.url))}[Yc](){return`PeerId(${this.url})`}[tn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return it.createV1(Kh,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=q(t)),t.toString()===this.toString())}};var qh=114,Jc=2336;function Xc(r){if(r.type==="Ed25519")return new qr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new $r({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new Kr({multihash:r.toCID().multihash,publicKey:r});throw new Ne}function eo(r){if(zh(r))return new Kr({multihash:r});if($h(r))try{let t=jc(r);if(t.type==="Ed25519")return new qr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new $r({multihash:r,publicKey:t})}catch{let e=q(r.digest);return new zr(new URL(e))}throw new rn("Supplied PeerID Multihash is invalid")}function ms(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==qh&&r.code!==Jc)throw new en("Supplied PeerID CID is invalid");if(r.code===Jc){let t=q(r.multihash.digest);return new zr(new URL(t))}return eo(r.multihash)}function $h(r){return r.code===Xt.code}function zh(r){return r.code===kr.code}var tl=Symbol.for("@achingbrain/uint8arraylist");function Qc(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let s=e+n.byteLength;if(t<s)return{buf:n,index:t-e};e=s}throw new RangeError("index is out of bounds")}function gs(r){return!!r?.[tl]}var ys=class r{bufs;length;[tl]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(gs(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(gs(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=Qc(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Qc(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(gs(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:s}=this._subList(t,e);return Rt(n,s)}subarray(t,e){let{bufs:n,length:s}=this._subList(t,e);return n.length===1?n[0]:Rt(n,s)}sublist(t,e){let{bufs:n,length:s}=this._subList(t,e),i=new r;return i.length=s,i.bufs=[...n],i}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],s=0;for(let i=0;i<this.bufs.length;i++){let o=this.bufs[i],a=s,c=a+o.byteLength;if(s=c,t>=c)continue;let f=t>=a&&t<c,l=e>a&&e<=c;if(f&&l){if(t===a&&e===c){n.push(o);break}let u=t-a;n.push(o.subarray(u,u+(e-t)));break}if(f){if(t===0){n.push(o);continue}n.push(o.subarray(t-a));continue}if(l){if(e===c){n.push(o);break}n.push(o.subarray(0,e-a));break}n.push(o)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!gs(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let i=256,o=new Int32Array(i);for(let u=0;u<i;u++)o[u]=-1;for(let u=0;u<s;u++)o[n[u]]=u;let a=o,c=this.byteLength-n.byteLength,f=n.byteLength-1,l;for(let u=e;u<=c;u+=l){l=0;for(let h=f;h>=0;h--){let g=this.get(u+h);if(n[h]!==g){l=Math.max(1,h-a[g]);break}}if(l===0)return u}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=Nt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let s=et(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,e,n),this.write(s,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let s=et(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,e,n),this.write(s,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let s=et(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,e,n),this.write(s,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=Nt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let s=et(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,e,n),this.write(s,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let s=et(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,e,n),this.write(s,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let s=et(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,e,n),this.write(s,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let s=et(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,e,n),this.write(s,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let s=et(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,e,n),this.write(s,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!ut(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((s,i)=>s+i.byteLength,0)),n.length=e,n}};var Gr;(function(r){let t;r.codec=()=>(t==null&&(t=Bt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.publicKey!=null&&e.publicKey.byteLength>0&&(n.uint32(10),n.bytes(e.publicKey)),e.payloadType!=null&&e.payloadType.byteLength>0&&(n.uint32(18),n.bytes(e.payloadType)),e.payload!=null&&e.payload.byteLength>0&&(n.uint32(26),n.bytes(e.payload)),e.signature!=null&&e.signature.byteLength>0&&(n.uint32(42),n.bytes(e.signature)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let i={publicKey:et(0),payloadType:et(0),payload:et(0),signature:et(0)},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let a=e.uint32();switch(a>>>3){case 1:{i.publicKey=e.bytes();break}case 2:{i.payloadType=e.bytes();break}case 3:{i.payload=e.bytes();break}case 5:{i.signature=e.bytes();break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>Et(e,r.codec()),r.decode=(e,n)=>vt(e,r.codec(),n)})(Gr||(Gr={}));var bs=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var cr=class r{static createFromProtobuf=async t=>{let e=Gr.decode(t),n=ps(e.publicKey);return new r({publicKey:n,payloadType:e.payloadType,payload:e.payload,signature:e.signature})};static seal=async(t,e)=>{if(e==null)throw new Error("Missing private key");let n=t.domain,s=t.codec,i=t.marshal(),o=el(n,s,i),a=await e.sign(o.subarray());return new r({publicKey:e.publicKey,payloadType:s,payload:i,signature:a})};static openAndCertify=async(t,e)=>{let n=await r.createFromProtobuf(t);if(!await n.validate(e))throw new bs("Envelope signature is not valid for the given domain");return n};publicKey;payloadType;payload;signature;marshaled;constructor(t){let{publicKey:e,payloadType:n,payload:s,signature:i}=t;this.publicKey=e,this.payloadType=n,this.payload=s,this.signature=i}marshal(){return this.marshaled==null&&(this.marshaled=Gr.encode({publicKey:qt(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return ut(this.marshal(),t.marshal())}async validate(t){let e=el(t,this.payloadType,this.payload);return this.publicKey.verify(e.subarray(),this.signature)}},el=(r,t,e)=>{let n=j(r),s=$t(n.byteLength),i=$t(t.length),o=$t(e.length);return new ys(s,n,i,t,o,e)};function rl(r,t){let e=(n,s)=>n.toString().localeCompare(s.toString());return r.length!==t.length?!1:(t.sort(e),r.sort(e).every((n,s)=>t[s].equals(n)))}var ws=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,s){return this.readAtomically(()=>{let i=0,o=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",f=2**(8*s)-1;for(;;){let l=this.readAtomically(()=>{let u=this.readChar();if(u===void 0)return;let h=Number.parseInt(u,t);if(!Number.isNaN(h))return h});if(l===void 0)break;if(i*=t,i+=l,i>f||(o+=1,e!==void 0&&o>e))return}if(o!==0)return!n&&c&&o>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let s=n*2;if(n<e.length-3){let o=this.readSeparator(":",n,()=>this.readIPv4Addr());if(o!==void 0)return e[s]=o[0],e[s+1]=o[1],e[s+2]=o[2],e[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];e[s]=i>>8,e[s+1]=i&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,s]=t(e);if(n===16)return e;if(s||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),o=16-(n+2),[a]=t(i.subarray(0,o));return e.set(i.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var nl=45,Gh=15,lr=new ws;function ro(r){if(!(r.length>Gh))return lr.new(r).parseWith(()=>lr.readIPv4Addr())}function no(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>nl))return lr.new(r).parseWith(()=>lr.readIPv6Addr())}function xs(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>nl))return lr.new(r).parseWith(()=>lr.readIPAddr())}var gy=parseInt("0xFFFF",16),yy=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function ol(r){return!!ro(r)}function al(r){return!!no(r)}function vs(r){return!!xs(r)}var cl=ol,Jh=al,so=function(r){let t=0;if(r=r.toString().trim(),cl(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(Jh(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let i=cl(e[n]),o;i&&(o=so(e[n]),e[n]=q(o.slice(0,2),"base16")),o!=null&&++n<8&&e.splice(n,0,q(o.slice(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let i=[n,1];for(n=9-e.length;n>0;n--)i.push("0");e.splice.apply(e,i)}let s=new Uint8Array(t+16);for(n=0;n<e.length;n++){let i=parseInt(e[n],16);s[t++]=i>>8&255,s[t++]=i&255}return s}throw new Error("invalid ip address")},ll=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let s=[];for(let i=0;i<e;i++)s.push(r[t+i]);return s.join(".")}if(e===16){let s=[];for(let i=0;i<e;i+=2)s.push(n.getUint16(t+i).toString(16));return s.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var ur={},io={},Qh=[[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"]];Qh.forEach(r=>{let t=td(...r);io[t.code]=t,ur[t.name]=t});function td(r,t,e,n,s){return{code:r,size:t,name:e,resolvable:!!n,path:!!s}}function W(r){if(typeof r=="number"){if(io[r]!=null)return io[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(ur[r]!=null)return ur[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var tb=W("ip4"),eb=W("ip6"),rb=W("ipcidr");function lo(r,t){switch(W(r).code){case 4:case 41:return rd(t);case 42:return co(t);case 6:case 273:case 33:case 132:return hl(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return co(t);case 421:return od(t);case 444:return fl(t);case 445:return fl(t);case 466:return id(t);case 481:return globalThis.encodeURIComponent(co(t));default:return q(t,"base16")}}function uo(r,t){switch(W(r).code){case 4:return ul(t);case 41:return ul(t);case 42:return ao(t);case 6:case 273:case 33:case 132:return fo(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return ao(t);case 421:return nd(t);case 444:return ad(t);case 445:return cd(t);case 466:return sd(t);case 481:return ao(globalThis.decodeURIComponent(t));default:return j(t,"base16")}}var oo=Object.values(Sr).map(r=>r.decoder),ed=function(){let r=oo[0].or(oo[1]);return oo.slice(2).forEach(t=>r=r.or(t)),r}();function ul(r){if(!vs(r))throw new Error("invalid ip address");return so(r)}function rd(r){let t=ll(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!vs(t))throw new Error("invalid ip address");return t}function fo(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function hl(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function ao(r){let t=j(r),e=Uint8Array.from($t(t.length));return Rt([e,t],e.length+t.length)}function co(r){let t=Oe(r);if(r=r.slice(Ct(t)),r.length!==t)throw new Error("inconsistent lengths");return q(r)}function nd(r){let t;r[0]==="Q"||r[0]==="1"?t=pe(Y.decode(`z${r}`)).bytes:t=it.parse(r).multihash.bytes;let e=Uint8Array.from($t(t.length));return Rt([e,t],e.length+t.length)}function sd(r){let t=ed.decode(r),e=Uint8Array.from($t(t.length));return Rt([e,t],e.length+t.length)}function id(r){let t=Oe(r),e=r.slice(Ct(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+q(e,"base64url")}function od(r){let t=Oe(r),e=r.slice(Ct(t));if(e.length!==t)throw new Error("inconsistent lengths");return q(e,"base58btc")}function ad(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=Vt.decode("b"+t[0]),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let s=fo(n);return Rt([e,s],e.length+s.length)}function cd(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=Vt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let s=fo(n);return Rt([e,s],e.length+s.length)}function fl(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=q(t,"base32"),s=hl(e);return`${n}:${s}`}function dl(r){r=ho(r);let t=[],e=[],n=null,s=r.split("/").slice(1);if(s.length===1&&s[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let i=0;i<s.length;i++){let o=s[i],a=W(o);if(a.size===0){t.push([a.code]),e.push([a.code]);continue}if(i++,i>=s.length)throw ml("invalid address: "+r);if(a.path===!0){n=ho(s.slice(i).join("/")),t.push([a.code,uo(a.code,n)]),e.push([a.code,n]);break}let c=uo(a.code,s[i]);t.push([a.code,c]),e.push([a.code,lo(a.code,c)])}return{string:pl(e),bytes:mo(t),tuples:t,stringTuples:e,path:n}}function po(r){let t=[],e=[],n=null,s=0;for(;s<r.length;){let i=Oe(r,s),o=Ct(i),a=W(i),c=ld(a,r.slice(s+o));if(c===0){t.push([i]),e.push([i]),s+=o;continue}let f=r.slice(s+o,s+o+c);if(s+=c+o,s>r.length)throw ml("Invalid address Uint8Array: "+q(r,"base16"));t.push([i,f]);let l=lo(i,f);if(e.push([i,l]),a.path===!0){n=l;break}}return{bytes:Uint8Array.from(r),string:pl(e),tuples:t,stringTuples:e,path:n}}function pl(r){let t=[];return r.map(e=>{let n=W(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),ho(t.join("/"))}function mo(r){return Rt(r.map(t=>{let e=W(t[0]),n=Uint8Array.from($t(e.code));return t.length>1&&t[1]!=null&&(n=Rt([n,t[1]])),n}))}function ld(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=Oe(t instanceof Uint8Array?t:Uint8Array.from(t));return e+Ct(e)}}function ho(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}function ml(r){return new Error("Error parsing address: "+r)}var ud=Symbol.for("nodejs.util.inspect.custom"),yo=Symbol.for("@multiformats/js-multiaddr/multiaddr"),fd=[W("dns").code,W("dns4").code,W("dns6").code,W("dnsaddr").code],go=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},Es=class r{bytes;#t;#e;#i;#a;[yo]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=po(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=dl(t)}else if(Bs(t))e=po(t.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=e.bytes,this.#t=e.string,this.#e=e.tuples,this.#i=e.stringTuples,this.#a=e.path}toString(){return this.#t}toJSON(){return this.toString()}toOptions(){let t,e,n,s,i="",o=W("tcp"),a=W("udp"),c=W("ip4"),f=W("ip6"),l=W("dns6"),u=W("ip6zone");for(let[g,x]of this.stringTuples())g===u.code&&(i=`%${x??""}`),fd.includes(g)&&(e=o.name,s=443,n=`${x??""}${i}`,t=g===l.code?6:4),(g===o.code||g===a.code)&&(e=W(g).name,s=parseInt(x??"")),(g===c.code||g===f.code)&&(e=W(g).name,n=`${x??""}${i}`,t=g===f.code?6:4);if(t==null||e==null||n==null||s==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:t,host:n,transport:e,port:s}}protos(){return this.#e.map(([t])=>Object.assign({},W(t)))}protoCodes(){return this.#e.map(([t])=>t)}protoNames(){return this.#e.map(([t])=>W(t).name)}tuples(){return this.#e}stringTuples(){return this.#i}encapsulate(t){return t=new r(t),new r(this.toString()+t.toString())}decapsulate(t){let e=t.toString(),n=this.toString(),s=n.lastIndexOf(e);if(s<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,s))}decapsulateCode(t){let e=this.tuples();for(let n=e.length-1;n>=0;n--)if(e[n][0]===t)return new r(mo(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,s])=>{n===ur.p2p.code&&t.push([n,s]),n===ur["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?q(Y.decode(`z${n}`),"base58btc"):q(it.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#a}equals(t){return ut(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(i=>i.resolvable);if(e==null)return[this];let n=gl.get(e.name);if(n==null)throw new go(`no available resolver for ${e.name}`);return(await n(this,t)).map(i=>fe(i))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[ud](){return`Multiaddr(${this.#t})`}};var gl=new Map;function Bs(r){return!!r?.[yo]}function fe(r){return new Es(r)}var yl="libp2p-peer-record",bl=Uint8Array.from([3,1]);var Wr;(function(r){let t;(function(n){let s;n.codec=()=>(s==null&&(s=Bt((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,a={})=>{let c={multiaddr:et(0)},f=o==null?i.len:i.pos+o;for(;i.pos<f;){let l=i.uint32();switch(l>>>3){case 1:{c.multiaddr=i.bytes();break}default:{i.skipType(l&7);break}}}return c})),s),n.encode=i=>Et(i,n.codec()),n.decode=(i,o)=>vt(i,n.codec(),o)})(t=r.AddressInfo||(r.AddressInfo={}));let e;r.codec=()=>(e==null&&(e=Bt((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,i={})=>{let o={peerId:et(0),seq:0n,addresses:[]},a=s==null?n.len:n.pos+s;for(;n.pos<a;){let c=n.uint32();switch(c>>>3){case 1:{o.peerId=n.bytes();break}case 2:{o.seq=n.uint64();break}case 3:{if(i.limits?.addresses!=null&&o.addresses.length===i.limits.addresses)throw new Me('Decode error - map field "addresses" had too many elements');o.addresses.push(r.AddressInfo.codec().decode(n,n.uint32(),{limits:i.limits?.addresses$}));break}default:{n.skipType(c&7);break}}}return o})),e),r.encode=n=>Et(n,r.codec()),r.decode=(n,s)=>vt(n,r.codec(),s)})(Wr||(Wr={}));var Ke=class r{static createFromProtobuf=t=>{let e=Wr.decode(t),n=eo(pe(e.peerId)),s=(e.addresses??[]).map(o=>fe(o.multiaddr)),i=e.seq;return new r({peerId:n,multiaddrs:s,seqNumber:i})};static DOMAIN=yl;static CODEC=bl;peerId;multiaddrs;seqNumber;domain=r.DOMAIN;codec=r.CODEC;marshaled;constructor(t){let{peerId:e,multiaddrs:n,seqNumber:s}=t;this.peerId=e,this.multiaddrs=n??[],this.seqNumber=s??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=Wr.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(t=>({multiaddr:t.bytes}))})),this.marshaled}equals(t){return!(!(t instanceof r)||!this.peerId.equals(t.peerId)||this.seqNumber!==t.seqNumber||!rl(this.multiaddrs,t.multiaddrs))}};function hd(r){return r[Symbol.asyncIterator]!=null}function dd(r){if(hd(r))return(async()=>{let e=[];for await(let n of r)e.push(n);return e})();let t=[];for(let e of r)t.push(e);return t}var wl=dd;function As(r,t){let e={[Symbol.iterator]:()=>e,next:()=>{let n=r.next(),s=n.value;return n.done===!0||s==null?{done:!0,value:void 0}:{done:!1,value:t(s)}}};return e}var Zr=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[e,n]of t.entries())this.map.set(e.toString(),{key:e,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return As(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((e,n)=>{t(e.value,e.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,e){this.map.set(t.toString(),{key:t,value:e})}keys(){return As(this.map.values(),t=>t.key)}values(){return As(this.map.values(),t=>t.value)}get size(){return this.map.size}};var wo=Ko(vl(),1);var Yr=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},xo=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},El=r=>globalThis.DOMException===void 0?new xo(r):new DOMException(r),Bl=r=>{let t=r.reason===void 0?El("This operation was aborted."):r.reason;return t instanceof Error?t:El(t)};function Jr(r,t){let{milliseconds:e,fallback:n,message:s,customTimers:i={setTimeout,clearTimeout}}=t,o,c=new Promise((f,l)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(t.signal){let{signal:h}=t;h.aborted&&l(Bl(h)),h.addEventListener("abort",()=>{l(Bl(h))})}if(e===Number.POSITIVE_INFINITY){r.then(f,l);return}let u=new Yr;o=i.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(h){l(h)}return}typeof r.cancel=="function"&&r.cancel(),s===!1?f():s instanceof Error?l(s):(u.message=s??`Promise timed out after ${e} milliseconds`,l(u))},e),(async()=>{try{f(await r)}catch(h){l(h)}})()}).finally(()=>{c.clear()});return c.clear=()=>{i.clearTimeout.call(void 0,o),o=void 0},c}function vo(r,t,e){let n=0,s=r.length;for(;s>0;){let i=Math.trunc(s/2),o=n+i;e(r[o],t)<=0?(n=++o,s-=i+1):s=i}return n}var Xr=class{#t=[];enqueue(t,e){e={priority:0,...e};let n={priority:e.priority,run:t};if(this.size&&this.#t[this.size-1].priority>=e.priority){this.#t.push(n);return}let s=vo(this.#t,n,(i,o)=>o.priority-i.priority);this.#t.splice(s,0,n)}dequeue(){return this.#t.shift()?.run}filter(t){return this.#t.filter(e=>e.priority===t.priority).map(e=>e.run)}get size(){return this.#t.length}};var fr=class extends wo.default{#t;#e;#i=0;#a;#c;#p=0;#n;#l;#r;#m;#s=0;#u;#o;#g;timeout;constructor(t){if(super(),t={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Xr,...t},!(typeof t.intervalCap=="number"&&t.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${t.intervalCap?.toString()??""}\` (${typeof t.intervalCap})`);if(t.interval===void 0||!(Number.isFinite(t.interval)&&t.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${t.interval?.toString()??""}\` (${typeof t.interval})`);this.#t=t.carryoverConcurrencyCount,this.#e=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#a=t.intervalCap,this.#c=t.interval,this.#r=new t.queueClass,this.#m=t.queueClass,this.concurrency=t.concurrency,this.timeout=t.timeout,this.#g=t.throwOnTimeout===!0,this.#o=t.autoStart===!1}get#w(){return this.#e||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 t=Date.now();if(this.#n===void 0){let e=this.#p-t;if(e<0)this.#i=this.#t?this.#s:0;else return this.#l===void 0&&(this.#l=setTimeout(()=>{this.#E()},e)),!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 t=!this.#B;if(this.#w&&this.#x){let e=this.#r.dequeue();return e?(this.emit("active"),e(),t&&this.#y(),!0):!1}}return!1}#y(){this.#e||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.#t?this.#s:0,this.#h()}#h(){for(;this.#f(););}get concurrency(){return this.#u}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this.#u=t,this.#h()}async#A(t){return new Promise((e,n)=>{t.addEventListener("abort",()=>{n(t.reason)},{once:!0})})}async add(t,e={}){return e={timeout:this.timeout,throwOnTimeout:this.#g,...e},new Promise((n,s)=>{this.#r.enqueue(async()=>{this.#s++,this.#i++;try{e.signal?.throwIfAborted();let i=t({signal:e.signal});e.timeout&&(i=Jr(Promise.resolve(i),{milliseconds:e.timeout})),e.signal&&(i=Promise.race([i,this.#A(e.signal)]));let o=await i;n(o),this.emit("completed",o)}catch(i){if(i instanceof Yr&&!e.throwOnTimeout){n();return}s(i),this.emit("error",i)}finally{this.#v()}},e),this.emit("add"),this.#f()})}async addAll(t,e){return Promise.all(t.map(async n=>this.add(n,e)))}start(){return this.#o?(this.#o=!1,this.#h(),this):this}pause(){this.#o=!0}clear(){this.#r=new this.#m}async onEmpty(){this.#r.size!==0&&await this.#d("empty")}async onSizeLessThan(t){this.#r.size<t||await this.#d("next",()=>this.#r.size<t)}async onIdle(){this.#s===0&&this.#r.size===0||await this.#d("idle")}async#d(t,e){return new Promise(n=>{let s=()=>{e&&!e()||(this.off(t,s),n())};this.on(t,s)})}get size(){return this.#r.size}sizeBy(t){return this.#r.filter(t).length}get pending(){return this.#s}get isPaused(){return this.#o}};var Ie={},hr=r=>{r.addEventListener("message",t=>{hr.dispatchEvent("message",r,t)}),r.port!=null&&r.port.addEventListener("message",t=>{hr.dispatchEvent("message",r,t)})};hr.addEventListener=(r,t)=>{Ie[r]==null&&(Ie[r]=[]),Ie[r].push(t)};hr.removeEventListener=(r,t)=>{Ie[r]!=null&&(Ie[r]=Ie[r].filter(e=>e===t))};hr.dispatchEvent=function(r,t,e){Ie[r]!=null&&Ie[r].forEach(n=>n(t,e))};var Eo=hr;var Bo="lock:worker:request-read",Ao="lock:worker:release-read",ko="lock:master:grant-read",So="lock:worker:request-write",Io="lock:worker:release-write",To="lock:master:grant-write";var Al=(r=21)=>Math.random().toString().substring(2);var kl=(r,t,e,n,s)=>(i,o)=>{if(o.data.type!==e)return;let a={type:o.data.type,name:o.data.name,identifier:o.data.identifier};r.dispatchEvent(new MessageEvent(t,{data:{name:a.name,handler:async()=>{i.postMessage({type:s,name:a.name,identifier:a.identifier}),await new Promise(c=>{let f=l=>{if(l==null||l.data==null)return;let u={type:l.data.type,name:l.data.name,identifier:l.data.identifier};u.type===n&&u.identifier===a.identifier&&(i.removeEventListener("message",f),c())};i.addEventListener("message",f)})}}}))},Sl=(r,t,e,n)=>async()=>{let s=Al();return globalThis.postMessage({type:t,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===e&&c.identifier===s&&(globalThis.removeEventListener("message",o),i(()=>{globalThis.postMessage({type:n,identifier:s,name:r})}))};globalThis.addEventListener("message",o)})},gd={singleProcess:!1},Il=r=>{if(r=Object.assign({},gd,r),!!globalThis.document||r.singleProcess){let e=new EventTarget;return Eo.addEventListener("message",kl(e,"requestReadLock",Bo,Ao,ko)),Eo.addEventListener("message",kl(e,"requestWriteLock",So,Io,To)),e}return{isWorker:!0,readLock:e=>Sl(e,Bo,ko,Ao),writeLock:e=>Sl(e,So,To,Io)}};var qe={},Te;async function No(r,t){let e,n=new Promise(s=>{e=s});return r.add(async()=>Jr((async()=>{await new Promise(s=>{e(()=>{s()})})})(),{milliseconds:t.timeout})),n}var yd=(r,t)=>{if(Te.isWorker===!0)return{readLock:Te.readLock(r,t),writeLock:Te.writeLock(r,t)};let e=new fr({concurrency:1}),n;return{async readLock(){if(n!=null)return No(n,t);n=new fr({concurrency:t.concurrency,autoStart:!1});let s=n,i=No(n,t);return e.add(async()=>{s.start(),await s.onIdle().then(()=>{n===s&&(n=null)})}),i},async writeLock(){return n=null,No(e,t)}}},bd={name:"lock",concurrency:1/0,timeout:846e5,singleProcess:!1};function Co(r){let t=Object.assign({},bd,r);return Te==null&&(Te=Il(t),Te.isWorker!==!0&&(Te.addEventListener("requestReadLock",e=>{qe[e.data.name]!=null&&qe[e.data.name].readLock().then(async n=>e.data.handler().finally(()=>{n()}))}),Te.addEventListener("requestWriteLock",async e=>{qe[e.data.name]!=null&&qe[e.data.name].writeLock().then(async n=>e.data.handler().finally(()=>{n()}))}))),qe[t.name]==null&&(qe[t.name]=yd(t.name,t)),qe[t.name]}var dr;(function(r){let t;(function(s){let i;s.codec=()=>(i==null&&(i=Bt((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,c={})=>{let f={key:"",value:et(0)},l=a==null?o.len:o.pos+a;for(;o.pos<l;){let u=o.uint32();switch(u>>>3){case 1:{f.key=o.string();break}case 2:{f.value=o.bytes();break}default:{o.skipType(u&7);break}}}return f})),i),s.encode=o=>Et(o,s.codec()),s.decode=(o,a)=>vt(o,s.codec(),a)})(t=r.Peer$metadataEntry||(r.Peer$metadataEntry={}));let e;(function(s){let i;s.codec=()=>(i==null&&(i=Bt((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),Is.codec().encode(o.value,a)),c.lengthDelimited!==!1&&a.ldelim()},(o,a,c={})=>{let f={key:""},l=a==null?o.len:o.pos+a;for(;o.pos<l;){let u=o.uint32();switch(u>>>3){case 1:{f.key=o.string();break}case 2:{f.value=Is.codec().decode(o,o.uint32(),{limits:c.limits?.value});break}default:{o.skipType(u&7);break}}}return f})),i),s.encode=o=>Et(o,s.codec()),s.decode=(o,a)=>vt(o,s.codec(),a)})(e=r.Peer$tagsEntry||(r.Peer$tagsEntry={}));let n;r.codec=()=>(n==null&&(n=Bt((s,i,o={})=>{if(o.lengthDelimited!==!1&&i.fork(),s.addresses!=null)for(let a of s.addresses)i.uint32(10),Ss.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,o={})=>{let a={addresses:[],protocols:[],metadata:new Map,tags:new Map},c=i==null?s.len:s.pos+i;for(;s.pos<c;){let f=s.uint32();switch(f>>>3){case 1:{if(o.limits?.addresses!=null&&a.addresses.length===o.limits.addresses)throw new Me('Decode error - map field "addresses" had too many elements');a.addresses.push(Ss.codec().decode(s,s.uint32(),{limits:o.limits?.addresses$}));break}case 2:{if(o.limits?.protocols!=null&&a.protocols.length===o.limits.protocols)throw new Me('Decode error - map field "protocols" had too many elements');a.protocols.push(s.string());break}case 4:{a.publicKey=s.bytes();break}case 5:{a.peerRecordEnvelope=s.bytes();break}case 6:{if(o.limits?.metadata!=null&&a.metadata.size===o.limits.metadata)throw new Nr('Decode error - map field "metadata" had too many elements');let l=r.Peer$metadataEntry.codec().decode(s,s.uint32());a.metadata.set(l.key,l.value);break}case 7:{if(o.limits?.tags!=null&&a.tags.size===o.limits.tags)throw new Nr('Decode error - map field "tags" had too many elements');let l=r.Peer$tagsEntry.codec().decode(s,s.uint32(),{limits:{value:o.limits?.tags$value}});a.tags.set(l.key,l.value);break}default:{s.skipType(f&7);break}}}return a})),n),r.encode=s=>Et(s,r.codec()),r.decode=(s,i)=>vt(s,r.codec(),i)})(dr||(dr={}));var Ss;(function(r){let t;r.codec=()=>(t==null&&(t=Bt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.multiaddr!=null&&e.multiaddr.byteLength>0&&(n.uint32(10),n.bytes(e.multiaddr)),e.isCertified!=null&&(n.uint32(16),n.bool(e.isCertified)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let i={multiaddr:et(0)},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let a=e.uint32();switch(a>>>3){case 1:{i.multiaddr=e.bytes();break}case 2:{i.isCertified=e.bool();break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>Et(e,r.codec()),r.decode=(e,n)=>vt(e,r.codec(),n)})(Ss||(Ss={}));var Is;(function(r){let t;r.codec=()=>(t==null&&(t=Bt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.value!=null&&e.value!==0&&(n.uint32(8),n.uint32(e.value)),e.expiry!=null&&(n.uint32(16),n.uint64(e.expiry)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let i={value:0},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let a=e.uint32();switch(a>>>3){case 1:{i.value=e.uint32();break}case 2:{i.expiry=e.uint64();break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>Et(e,r.codec()),r.decode=(e,n)=>vt(e,r.codec(),n)})(Is||(Is={}));function pr(r,t){let e=dr.decode(t);if(e.publicKey!=null&&r.publicKey==null){let i=ps(e.publicKey);r=Xc(i)}let n=new Map,s=BigInt(Date.now());for(let[i,o]of e.tags.entries())o.expiry!=null&&o.expiry<s||n.set(i,o);return{...e,id:r,addresses:e.addresses.map(({multiaddr:i,isCertified:o})=>({multiaddr:fe(i),isCertified:o??!1})),metadata:e.metadata,peerRecordEnvelope:e.peerRecordEnvelope??void 0,tags:n}}var he="/",Tl=new TextEncoder().encode(he),Ts=Tl[0],Ns=class r{_buf;constructor(t,e){if(typeof t=="string")this._buf=j(t);else if(t instanceof Uint8Array)this._buf=t;else throw new Error("Invalid key, should be String of Uint8Array");if(e==null&&(e=!0),e&&this.clean(),this._buf.byteLength===0||this._buf[0]!==Ts)throw new Error("Invalid key")}toString(t="utf8"){return q(this._buf,t)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(t){return new r(t.join(he))}static random(){return new r(Math.random().toString().substring(2))}static asKey(t){return t instanceof Uint8Array||typeof t=="string"?new r(t):typeof t.uint8Array=="function"?new r(t.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=Tl),this._buf[0]!==Ts){let t=new Uint8Array(this._buf.byteLength+1);t.fill(Ts,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Ts;)this._buf=this._buf.subarray(0,-1)}less(t){let e=this.list(),n=t.list();for(let s=0;s<e.length;s++){if(n.length<s+1)return!1;let i=e[s],o=n[s];if(i<o)return!0;if(i>o)return!1}return e.length<n.length}reverse(){return r.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let t=this.namespaces();return t[t.length-1]}list(){return this.toString().split(he).slice(1)}type(){return wd(this.baseNamespace())}name(){return xd(this.baseNamespace())}instance(t){return new r(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(he)||(t+=he),t+=this.type(),new r(t)}parent(){let t=this.list();return t.length===1?new r(he):new r(t.slice(0,-1).join(he))}child(t){return this.toString()===he?t:t.toString()===he?this:new r(this.toString()+t.toString(),!1)}isAncestorOf(t){return t.toString()===this.toString()?!1:t.toString().startsWith(this.toString())}isDecendantOf(t){return t.toString()===this.toString()?!1:this.toString().startsWith(t.toString())}isTopLevel(){return this.list().length===1}concat(...t){return r.withNamespaces([...this.namespaces(),...vd(t.map(e=>e.namespaces()))])}};function wd(r){let t=r.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function xd(r){let t=r.split(":");return t[t.length-1]}function vd(r){return[].concat(...r)}var Lo="/peers/";function mr(r){if(!qo(r)||r.type==null)throw new K("Invalid PeerId");let t=r.toCID().toString();return new Ns(`${Lo}${t}`)}async function Nl(r,t,e){let n=new Map;for(let s of e){if(s==null)continue;if(s.multiaddr instanceof Uint8Array&&(s.multiaddr=fe(s.multiaddr)),!Bs(s.multiaddr))throw new K("Multiaddr was invalid");if(!await t(r,s.multiaddr))continue;let i=s.isCertified??!1,o=s.multiaddr.toString(),a=n.get(o);a!=null?s.isCertified=a.isCertified||i:n.set(o,{multiaddr:s.multiaddr,isCertified:i})}return[...n.values()].sort((s,i)=>s.multiaddr.toString().localeCompare(i.multiaddr.toString())).map(({isCertified:s,multiaddr:i})=>({isCertified:s,multiaddr:i.bytes}))}async function Ls(r,t,e,n){if(t==null)throw new K("Invalid PeerData");if(t.publicKey!=null&&r.publicKey!=null&&!t.publicKey.equals(r.publicKey))throw new K("publicKey bytes do not match peer id publicKey bytes");let s=n.existingPeer;if(s!=null&&!r.equals(s.id))throw new K("peer id did not match existing peer id");let i=s?.addresses??[],o=new Set(s?.protocols??[]),a=s?.metadata??new Map,c=s?.tags??new Map,f=s?.peerRecordEnvelope;if(e==="patch"){if((t.multiaddrs!=null||t.addresses!=null)&&(i=[],t.multiaddrs!=null&&i.push(...t.multiaddrs.map(h=>({isCertified:!1,multiaddr:h}))),t.addresses!=null&&i.push(...t.addresses)),t.protocols!=null&&(o=new Set(t.protocols)),t.metadata!=null){let h=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);a=Cs(h,{validate:Cl})}if(t.tags!=null){let h=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags);c=Cs(h,{validate:Ll,map:Ul})}t.peerRecordEnvelope!=null&&(f=t.peerRecordEnvelope)}if(e==="merge"){if(t.multiaddrs!=null&&i.push(...t.multiaddrs.map(h=>({isCertified:!1,multiaddr:h}))),t.addresses!=null&&i.push(...t.addresses),t.protocols!=null&&(o=new Set([...o,...t.protocols])),t.metadata!=null){let h=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);for(let[g,x]of h)x==null?a.delete(g):a.set(g,x);a=Cs([...a.entries()],{validate:Cl})}if(t.tags!=null){let h=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags),g=new Map(c);for(let[x,b]of h)b==null?g.delete(x):g.set(x,b);c=Cs([...g.entries()],{validate:Ll,map:Ul})}t.peerRecordEnvelope!=null&&(f=t.peerRecordEnvelope)}let l;s?.id.publicKey!=null?l=qt(s.id.publicKey):t.publicKey!=null?l=qt(t.publicKey):r.publicKey!=null&&(l=qt(r.publicKey));let u={addresses:await Nl(r,n.addressFilter??(async()=>!0),i),protocols:[...o.values()].sort((h,g)=>h.localeCompare(g)),metadata:a,tags:c,publicKey:l,peerRecordEnvelope:f};return r.type!=="RSA"&&delete u.publicKey,u}function Cs(r,t){let e=new Map;for(let[n,s]of r)s!=null&&t.validate(n,s);for(let[n,s]of r.sort(([i],[o])=>i.localeCompare(o)))s!=null&&e.set(n,t.map?.(n,s)??s);return e}function Cl(r,t){if(typeof r!="string")throw new K("Metadata key must be a string");if(!(t instanceof Uint8Array))throw new K("Metadata value must be a Uint8Array")}function Ll(r,t){if(typeof r!="string")throw new K("Tag name must be a string");if(t.value!=null){if(parseInt(`${t.value}`,10)!==t.value)throw new K("Tag value must be an integer");if(t.value<0||t.value>100)throw new K("Tag value must be between 0-100")}if(t.ttl!=null){if(parseInt(`${t.ttl}`,10)!==t.ttl)throw new K("Tag ttl must be an integer");if(t.ttl<0)throw new K("Tag ttl must be between greater than 0")}}function Ul(r,t){let e;return t.expiry!=null&&(e=t.expiry),t.ttl!=null&&(e=BigInt(Date.now()+Number(t.ttl))),{value:t.value??0,expiry:e}}function Us(r,t,e){let n=r.toString().split("/")[2],s=it.parse(n,Vt),i=ms(s),o=e.get(i);if(o!=null)return o;let a=pr(i,t);return e.set(i,a),a}function Ed(r,t){return r==null?{}:{prefix:Lo,filters:(r.filters??[]).map(e=>({key:n,value:s})=>e(Us(n,s,t))),orders:(r.orders??[]).map(e=>(n,s)=>e(Us(n.key,n.value,t),Us(s.key,s.value,t)))}}var Rs=class{peerId;datastore;lock;addressFilter;constructor(t,e={}){this.peerId=t.peerId,this.datastore=t.datastore,this.addressFilter=e.addressFilter,this.lock=Co({name:"peer-store",singleProcess:!0})}async has(t){return this.datastore.has(mr(t))}async delete(t){if(this.peerId.equals(t))throw new K("Cannot delete self peer");await this.datastore.delete(mr(t))}async load(t){let e=await this.datastore.get(mr(t));return pr(t,e)}async save(t,e){let{existingBuf:n,existingPeer:s}=await this.#t(t),i=await Ls(t,e,"patch",{addressFilter:this.addressFilter});return this.#e(t,i,n,s)}async patch(t,e){let{existingBuf:n,existingPeer:s}=await this.#t(t),i=await Ls(t,e,"patch",{addressFilter:this.addressFilter,existingPeer:s});return this.#e(t,i,n,s)}async merge(t,e){let{existingBuf:n,existingPeer:s}=await this.#t(t),i=await Ls(t,e,"merge",{addressFilter:this.addressFilter,existingPeer:s});return this.#e(t,i,n,s)}async*all(t){let e=new Zr;for await(let{key:n,value:s}of this.datastore.query(Ed(t??{},e))){let i=Us(n,s,e);i.id.equals(this.peerId)||(yield i)}}async#t(t){try{let e=await this.datastore.get(mr(t)),n=pr(t,e);return{existingBuf:e,existingPeer:n}}catch(e){if(e.name!=="NotFoundError")throw e}return{}}async#e(t,e,n,s){let i=dr.encode(e);return n!=null&&ut(i,n)?{peer:pr(t,i),previous:s,updated:!1}:(await this.datastore.put(mr(t),i),{peer:pr(t,i),previous:s,updated:!0})}};var Uo=class{store;events;peerId;log;constructor(t,e={}){this.log=t.logger.forComponent("libp2p:peer-store"),this.events=t.events,this.peerId=t.peerId,this.store=new Rs(t,e)}[Symbol.toStringTag]="@libp2p/peer-store";async forEach(t,e){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(e))t(s)}finally{this.log.trace("forEach release read lock"),n()}}async all(t){this.log.trace("all await read lock");let e=await this.store.lock.readLock();this.log.trace("all got read lock");try{return await wl(this.store.all(t))}finally{this.log.trace("all release read lock"),e()}}async delete(t){this.log.trace("delete await write lock");let e=await this.store.lock.writeLock();this.log.trace("delete got write lock");try{await this.store.delete(t)}finally{this.log.trace("delete release write lock"),e()}}async has(t){this.log.trace("has await read lock");let e=await this.store.lock.readLock();this.log.trace("has got read lock");try{return await this.store.has(t)}finally{this.log.trace("has release read lock"),e()}}async get(t){this.log.trace("get await read lock");let e=await this.store.lock.readLock();this.log.trace("get got read lock");try{return await this.store.load(t)}finally{this.log.trace("get release read lock"),e()}}async save(t,e){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(t,e);return this.#t(t,s),s.peer}finally{this.log.trace("save release write lock"),n()}}async patch(t,e){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(t,e);return this.#t(t,s),s.peer}finally{this.log.trace("patch release write lock"),n()}}async merge(t,e){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(t,e);return this.#t(t,s),s.peer}finally{this.log.trace("merge release write lock"),n()}}async consumePeerRecord(t,e){let n=await cr.openAndCertify(t,Ke.DOMAIN),s=ms(n.publicKey.toCID());if(e?.equals(s)===!1)return this.log("envelope peer id was not the expected peer id - expected: %p received: %p",e,s),!1;let i=Ke.createFromProtobuf(n.payload),o;try{o=await this.get(s)}catch(a){if(a.name!=="NotFoundError")throw a}if(o?.peerRecordEnvelope!=null){let a=await cr.createFromProtobuf(o.peerRecordEnvelope),c=Ke.createFromProtobuf(a.payload);if(c.seqNumber>=i.seqNumber)return this.log("sequence number was lower or equal to existing sequence number - stored: %d received: %d",c.seqNumber,i.seqNumber),!1}return await this.patch(i.peerId,{peerRecordEnvelope:t,addresses:i.multiaddrs.map(a=>({isCertified:!0,multiaddr:a}))}),!0}#t(t,e){e.updated&&(this.peerId.equals(t)?this.events.safeDispatchEvent("self:peer:update",{detail:e}):this.events.safeDispatchEvent("peer:update",{detail:e}))}};return Gl(Bd);})();
|
|
8
7
|
/*! Bundled license information:
|
|
9
8
|
|
|
10
9
|
pvtsutils/build/index.js:
|