@libp2p/peer-store 10.1.5-dd7b329c4 → 10.1.5-e1ca9cced
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/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 nu=Object.create;var yn=Object.defineProperty;var su=Object.getOwnPropertyDescriptor;var iu=Object.getOwnPropertyNames;var ou=Object.getPrototypeOf,au=Object.prototype.hasOwnProperty;var Jo=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),ue=(r,e)=>{for(var t in e)yn(r,t,{get:e[t],enumerable:!0})},Xo=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of iu(e))!au.call(r,s)&&s!==t&&yn(r,s,{get:()=>e[s],enumerable:!(n=su(e,s))||n.enumerable});return r};var Qo=(r,e,t)=>(t=r!=null?nu(ou(r)):{},Xo(e||!r||!r.__esModule?yn(t,"default",{value:r,enumerable:!0}):t,r)),cu=r=>Xo(yn({},"__esModule",{value:!0}),r);var ec=Jo(vr=>{"use strict";var Hh="[object ArrayBuffer]",ut=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===Hh}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,t){let n=r.toUint8Array(e),s=r.toUint8Array(t);if(n.length!==s.byteLength)return!1;for(let i=0;i<n.length;i++)if(n[i]!==s[i])return!1;return!0}static concat(...e){let t;Array.isArray(e[0])&&!(e[1]instanceof Function)||Array.isArray(e[0])&&e[1]instanceof Function?t=e[0]:e[e.length-1]instanceof Function?t=e.slice(0,e.length-1):t=e;let n=0;for(let o of t)n+=o.byteLength;let s=new Uint8Array(n),i=0;for(let o of t){let a=this.toUint8Array(o);s.set(a,i),i+=a.length}return e[e.length-1]instanceof Function?this.toView(s,e[e.length-1]):s.buffer}},Yi="string",Kh=/^[0-9a-f]+$/i,Fh=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,qh=/^[a-zA-Z0-9-_]+$/,Dn=class{static fromString(e){let t=unescape(encodeURIComponent(e)),n=new Uint8Array(t.length);for(let s=0;s<t.length;s++)n[s]=t.charCodeAt(s);return n.buffer}static toString(e){let t=ut.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return decodeURIComponent(escape(n))}},Oe=class{static toString(e,t=!1){let n=ut.toArrayBuffer(e),s=new DataView(n),i="";for(let o=0;o<n.byteLength;o+=2){let a=s.getUint16(o,t);i+=String.fromCharCode(a)}return i}static fromString(e,t=!1){let n=new ArrayBuffer(e.length*2),s=new DataView(n);for(let i=0;i<e.length;i++)s.setUint16(i*2,e.charCodeAt(i),t);return n}},Vn=class r{static isHex(e){return typeof e===Yi&&Kh.test(e)}static isBase64(e){return typeof e===Yi&&Fh.test(e)}static isBase64Url(e){return typeof e===Yi&&qh.test(e)}static ToString(e,t="utf8"){let n=ut.toUint8Array(e);switch(t.toLowerCase()){case"utf8":return this.ToUtf8String(n);case"binary":return this.ToBinary(n);case"hex":return this.ToHex(n);case"base64":return this.ToBase64(n);case"base64url":return this.ToBase64Url(n);case"utf16le":return Oe.toString(n,!0);case"utf16":case"utf16be":return Oe.toString(n);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromString(e,t="utf8"){if(!e)return new ArrayBuffer(0);switch(t.toLowerCase()){case"utf8":return this.FromUtf8String(e);case"binary":return this.FromBinary(e);case"hex":return this.FromHex(e);case"base64":return this.FromBase64(e);case"base64url":return this.FromBase64Url(e);case"utf16le":return Oe.fromString(e,!0);case"utf16":case"utf16be":return Oe.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=ut.toUint8Array(e);if(typeof btoa<"u"){let n=this.ToString(t,"binary");return btoa(n)}else return Buffer.from(t).toString("base64")}static FromBase64(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64(t))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(t)):new Uint8Array(Buffer.from(t,"base64")).buffer}static FromBase64Url(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64Url(t))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(t.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(e){return this.ToBase64(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.FromBinary(e);case"utf8":return Dn.fromString(e);case"utf16":case"utf16be":return Oe.fromString(e);case"utf16le":case"usc2":return Oe.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return Dn.toString(e);case"utf16":case"utf16be":return Oe.toString(e);case"utf16le":case"usc2":return Oe.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){let t=e.length,n=new Uint8Array(t);for(let s=0;s<t;s++)n[s]=e.charCodeAt(s);return n.buffer}static ToBinary(e){let t=ut.toUint8Array(e),n="";for(let s=0;s<t.length;s++)n+=String.fromCharCode(t[s]);return n}static ToHex(e){let t=ut.toUint8Array(e),n="",s=t.length;for(let i=0;i<s;i++){let o=t[i];o<16&&(n+="0"),n+=o.toString(16)}return n}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);let n=new Uint8Array(t.length/2);for(let s=0;s<t.length;s=s+2){let i=t.slice(s,s+2);n[s/2]=parseInt(i,16)}return n.buffer}static ToUtf16String(e,t=!1){return Oe.toString(e,t)}static FromUtf16String(e,t=!1){return Oe.fromString(e,t)}static Base64Padding(e){let t=4-e.length%4;if(t<4)for(let n=0;n<t;n++)e+="=";return e}static formatString(e){return e?.replace(/[\n\r\t ]/g,"")||""}};Vn.DEFAULT_UTF8_ENCODING="utf8";function $h(r,...e){let t=arguments[0];for(let n=1;n<arguments.length;n++){let s=arguments[n];for(let i in s)t[i]=s[i]}return t}function zh(...r){let e=r.map(s=>s.byteLength).reduce((s,i)=>s+i),t=new Uint8Array(e),n=0;return r.map(s=>new Uint8Array(s)).forEach(s=>{for(let i of s)t[n++]=i}),t.buffer}function Gh(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let s=0;s<r.byteLength;s++)if(t[s]!==n[s])return!1;return!0}vr.BufferSourceConverter=ut;vr.Convert=Vn;vr.assign=$h;vr.combine=zh;vr.isEqual=Gh});var Vl=Jo((tw,No)=>{"use strict";var Wd=Object.prototype.hasOwnProperty,Re="~";function dn(){}Object.create&&(dn.prototype=Object.create(null),new dn().__proto__||(Re=!1));function Yd(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function Dl(r,e,t,n,s){if(typeof t!="function")throw new TypeError("The listener must be a function");var i=new Yd(t,n||r,s),o=Re?Re+e:e;return r._events[o]?r._events[o].fn?r._events[o]=[r._events[o],i]:r._events[o].push(i):(r._events[o]=i,r._eventsCount++),r}function Ls(r,e){--r._eventsCount===0?r._events=new dn:delete r._events[e]}function xe(){this._events=new dn,this._eventsCount=0}xe.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)Wd.call(t,n)&&e.push(Re?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};xe.prototype.listeners=function(e){var t=Re?Re+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var s=0,i=n.length,o=new Array(i);s<i;s++)o[s]=n[s].fn;return o};xe.prototype.listenerCount=function(e){var t=Re?Re+e:e,n=this._events[t];return n?n.fn?1:n.length:0};xe.prototype.emit=function(e,t,n,s,i,o){var a=Re?Re+e:e;if(!this._events[a])return!1;var c=this._events[a],f=arguments.length,u,l;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),f){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,s),!0;case 5:return c.fn.call(c.context,t,n,s,i),!0;case 6:return c.fn.call(c.context,t,n,s,i,o),!0}for(l=1,u=new Array(f-1);l<f;l++)u[l-1]=arguments[l];c.fn.apply(c.context,u)}else{var h=c.length,m;for(l=0;l<h;l++)switch(c[l].once&&this.removeListener(e,c[l].fn,void 0,!0),f){case 1:c[l].fn.call(c[l].context);break;case 2:c[l].fn.call(c[l].context,t);break;case 3:c[l].fn.call(c[l].context,t,n);break;case 4:c[l].fn.call(c[l].context,t,n,s);break;default:if(!u)for(m=1,u=new Array(f-1);m<f;m++)u[m-1]=arguments[m];c[l].fn.apply(c[l].context,u)}}return!0};xe.prototype.on=function(e,t,n){return Dl(this,e,t,n,!1)};xe.prototype.once=function(e,t,n){return Dl(this,e,t,n,!0)};xe.prototype.removeListener=function(e,t,n,s){var i=Re?Re+e:e;if(!this._events[i])return this;if(!t)return Ls(this,i),this;var o=this._events[i];if(o.fn)o.fn===t&&(!s||o.once)&&(!n||o.context===n)&&Ls(this,i);else{for(var a=0,c=[],f=o.length;a<f;a++)(o[a].fn!==t||s&&!o[a].once||n&&o[a].context!==n)&&c.push(o[a]);c.length?this._events[i]=c.length===1?c[0]:c:Ls(this,i)}return this};xe.prototype.removeAllListeners=function(e){var t;return e?(t=Re?Re+e:e,this._events[t]&&Ls(this,t)):(this._events=new dn,this._eventsCount=0),this};xe.prototype.off=xe.prototype.removeListener;xe.prototype.addListener=xe.prototype.on;xe.prefixed=Re;xe.EventEmitter=xe;typeof No<"u"&&(No.exports=xe)});var np={};ue(np,{PersistentPeerStore:()=>qo});var bn=Symbol.for("@libp2p/peer-id");function ea(r){return r!=null&&!!r[bn]}var R=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var ji={};ue(ji,{Ed25519PrivateKey:()=>Yt,Ed25519PublicKey:()=>zr,generateKeyPair:()=>Vh,generateKeyPairFromSeed:()=>Qa,unmarshalEd25519PrivateKey:()=>Ph,unmarshalEd25519PublicKey:()=>Dh});var Gs={};ue(Gs,{base58btc:()=>oe,base58flickr:()=>pu});var ap=new Uint8Array(0);function ta(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function rt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function ra(r){return new TextEncoder().encode(r)}function na(r){return new TextDecoder().decode(r)}function lu(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var s=0;s<r.length;s++){var i=r.charAt(s),o=i.charCodeAt(0);if(t[o]!==255)throw new TypeError(i+" is ambiguous");t[o]=s}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function l(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var y=0,d=0,w=0,E=x.length;w!==E&&x[w]===0;)w++,y++;for(var g=(E-w)*u+1>>>0,B=new Uint8Array(g);w!==E;){for(var C=x[w],L=0,S=g-1;(C!==0||L<d)&&S!==-1;S--,L++)C+=256*B[S]>>>0,B[S]=C%a>>>0,C=C/a>>>0;if(C!==0)throw new Error("Non-zero carry");d=L,w++}for(var I=g-d;I!==g&&B[I]===0;)I++;for(var _=c.repeat(y);I<g;++I)_+=r.charAt(B[I]);return _}function h(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var y=0;if(x[y]!==" "){for(var d=0,w=0;x[y]===c;)d++,y++;for(var E=(x.length-y)*f+1>>>0,g=new Uint8Array(E);x[y];){var B=t[x.charCodeAt(y)];if(B===255)return;for(var C=0,L=E-1;(B!==0||C<w)&&L!==-1;L--,C++)B+=a*g[L]>>>0,g[L]=B%256>>>0,B=B/256>>>0;if(B!==0)throw new Error("Non-zero carry");w=C,y++}if(x[y]!==" "){for(var S=E-w;S!==E&&g[S]===0;)S++;for(var I=new Uint8Array(d+(E-S)),_=d;S!==E;)I[_++]=g[S++];return I}}}function m(x){var y=h(x);if(y)return y;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:h,decode:m}}var uu=lu,fu=uu,ia=fu;var Fs=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},qs=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return oa(this,e)}},$s=class{decoders;constructor(e){this.decoders=e}or(e){return oa(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function oa(r,e){return new $s({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var zs=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,s){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=s,this.encoder=new Fs(e,t,n),this.decoder=new qs(e,t,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function sr({name:r,prefix:e,encode:t,decode:n}){return new zs(r,e,t,n)}function xt({name:r,prefix:e,alphabet:t}){let{encode:n,decode:s}=ia(t,r);return sr({prefix:e,name:r,encode:n,decode:i=>rt(s(i))})}function hu(r,e,t,n){let s={};for(let u=0;u<e.length;++u)s[e[u]]=u;let i=r.length;for(;r[i-1]==="=";)--i;let o=new Uint8Array(i*t/8|0),a=0,c=0,f=0;for(let u=0;u<i;++u){let l=s[r[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|l,a+=t,a>=8&&(a-=8,o[f++]=255&c>>a)}if(a>=t||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o}function du(r,e,t){let n=e[e.length-1]==="=",s=(1<<t)-1,i="",o=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],o+=8;o>t;)o-=t,i+=e[s&a>>o];if(o!==0&&(i+=e[s&a<<t-o]),n)for(;i.length*t&7;)i+="=";return i}function Q({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return sr({prefix:e,name:r,encode(s){return du(s,n,t)},decode(s){return hu(s,n,t,r)}})}var oe=xt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),pu=xt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ws={};ue(Ws,{identity:()=>nt});var gu=la,aa=128,mu=127,yu=~mu,bu=Math.pow(2,31);function la(r,e,t){e=e||[],t=t||0;for(var n=t;r>=bu;)e[t++]=r&255|aa,r/=128;for(;r&yu;)e[t++]=r&255|aa,r>>>=7;return e[t]=r|0,la.bytes=t-n+1,e}var wu=js,xu=128,ca=127;function js(r,n){var t=0,n=n||0,s=0,i=n,o,a=r.length;do{if(i>=a)throw js.bytes=0,new RangeError("Could not decode varint");o=r[i++],t+=s<28?(o&ca)<<s:(o&ca)*Math.pow(2,s),s+=7}while(o>=xu);return js.bytes=i-n,t}var vu=Math.pow(2,7),Eu=Math.pow(2,14),Bu=Math.pow(2,21),Au=Math.pow(2,28),ku=Math.pow(2,35),Su=Math.pow(2,42),Iu=Math.pow(2,49),Ru=Math.pow(2,56),Nu=Math.pow(2,63),Tu=function(r){return r<vu?1:r<Eu?2:r<Bu?3:r<Au?4:r<ku?5:r<Su?6:r<Iu?7:r<Ru?8:r<Nu?9:10},_u={encode:gu,decode:wu,encodingLength:Tu},Lu=_u,Dr=Lu;function Vr(r,e=0){return[Dr.decode(r,e),Dr.decode.bytes]}function ir(r,e,t=0){return Dr.encode(r,e,t),e}function or(r){return Dr.encodingLength(r)}function je(r,e){let t=e.byteLength,n=or(r),s=n+or(t),i=new Uint8Array(s+t);return ir(r,i,0),ir(t,i,n),i.set(e,s),new ar(r,t,e,i)}function Ot(r){let e=rt(r),[t,n]=Vr(e),[s,i]=Vr(e.subarray(n)),o=e.subarray(n+i);if(o.byteLength!==s)throw new Error("Incorrect length");return new ar(t,s,o,e)}function ua(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&ta(r.bytes,t.bytes)}}var ar=class{code;size;digest;bytes;constructor(e,t,n,s){this.code=e,this.size=t,this.digest=n,this.bytes=s}};var fa=0,Cu="identity",ha=rt;function Uu(r){return je(fa,ha(r))}var nt={code:fa,name:Cu,encode:ha,digest:Uu};var Js={};ue(Js,{sha256:()=>pe,sha512:()=>Pu});function Zs({name:r,code:e,encode:t}){return new Ys(r,e,t)}var Ys=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?je(this.code,t):t.then(n=>je(this.code,n))}else throw Error("Unknown type, must be binary type")}};function pa(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var pe=Zs({name:"sha2-256",code:18,encode:pa("SHA-256")}),Pu=Zs({name:"sha2-512",code:19,encode:pa("SHA-512")});function ee(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function st(r=0){return new Uint8Array(r)}function Te(r=0){return new Uint8Array(r)}function Ee(r,e){e==null&&(e=r.reduce((s,i)=>s+i.length,0));let t=Te(e),n=0;for(let s of r)t.set(s,n),n+=s.length;return t}var Xs={};ue(Xs,{base10:()=>Du});var Du=xt({prefix:"9",name:"base10",alphabet:"0123456789"});var Qs={};ue(Qs,{base16:()=>Vu,base16upper:()=>Ou});var Vu=Q({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ou=Q({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ei={};ue(ei,{base2:()=>Mu});var Mu=Q({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ti={};ue(ti,{base256emoji:()=>$u});var ga=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Hu=ga.reduce((r,e,t)=>(r[t]=e,r),[]),Ku=ga.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function Fu(r){return r.reduce((e,t)=>(e+=Hu[t],e),"")}function qu(r){let e=[];for(let t of r){let n=Ku[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var $u=sr({prefix:"\u{1F680}",name:"base256emoji",encode:Fu,decode:qu});var ri={};ue(ri,{base32:()=>Me,base32hex:()=>Wu,base32hexpad:()=>Zu,base32hexpadupper:()=>Ju,base32hexupper:()=>Yu,base32pad:()=>Gu,base32padupper:()=>ju,base32upper:()=>zu,base32z:()=>Xu});var Me=Q({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),zu=Q({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Gu=Q({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ju=Q({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Wu=Q({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Yu=Q({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Zu=Q({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ju=Q({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Xu=Q({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ni={};ue(ni,{base36:()=>Qu,base36upper:()=>ef});var Qu=xt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ef=xt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ii={};ue(ii,{base64:()=>si,base64pad:()=>tf,base64url:()=>rf,base64urlpad:()=>nf});var si=Q({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),tf=Q({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),rf=Q({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),nf=Q({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var oi={};ue(oi,{base8:()=>sf});var sf=Q({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ai={};ue(ai,{identity:()=>of});var of=sr({prefix:"\0",name:"identity",encode:r=>na(r),decode:r=>ra(r)});var Pp=new TextEncoder,Dp=new TextDecoder;function ma(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return uf(t,ci(r),e??oe.encoder);default:return ff(t,ci(r),e??Me.encoder)}}var ya=new WeakMap;function ci(r){let e=ya.get(r);if(e==null){let t=new Map;return ya.set(r,t),t}return e}var De=class r{code;version;multihash;bytes;"/";constructor(e,t,n,s){this.code=t,this.version=e,this.multihash=n,this.bytes=s,this["/"]=s}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==Or)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==hf)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=je(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&ua(e.multihash,n.multihash)}toString(e){return ma(this,e)}toJSON(){return{"/":ma(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:s,multihash:i,bytes:o}=t;return new r(n,s,i,o??ba(n,s,i.bytes))}else if(t[df]===!0){let{version:n,multihash:s,code:i}=t,o=Ot(s);return r.create(n,i,o)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==Or)throw new Error(`Version 0 CID must use dag-pb (code: ${Or}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let s=ba(e,t,n.bytes);return new r(e,t,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Or,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,s=rt(e.subarray(n,n+t.multihashSize));if(s.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=s.subarray(t.multihashSize-t.digestSize),o=new ar(t.multihashCode,t.digestSize,i,s);return[t.version===0?r.createV0(o):r.createV1(t.codec,o),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[l,h]=Vr(e.subarray(t));return t+=h,l},s=n(),i=Or;if(s===18?(s=0,t=0):i=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let o=t,a=n(),c=n(),f=t+c,u=f-o;return{version:s,codec:i,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(e,t){let[n,s]=lf(e,t),i=r.decode(s);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ci(i).set(n,e),i}};function lf(r,e){switch(r[0]){case"Q":{let t=e??oe;return[oe.prefix,t.decode(`${oe.prefix}${r}`)]}case oe.prefix:{let t=e??oe;return[oe.prefix,t.decode(r)]}case Me.prefix:{let t=e??Me;return[Me.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function uf(r,e,t){let{prefix:n}=t;if(n!==oe.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let s=e.get(n);if(s==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return s}function ff(r,e,t){let{prefix:n}=t,s=e.get(n);if(s==null){let i=t.encode(r);return e.set(n,i),i}else return s}var Or=112,hf=18;function ba(r,e,t){let n=or(r),s=n+or(e),i=new Uint8Array(s+t.byteLength);return ir(r,i,0),ir(e,i,n),i.set(t,s),i}var df=Symbol.for("@ipld/js-cid/CID");var vt={...ai,...ei,...oi,...Xs,...Qs,...ri,...ni,...Gs,...ii,...ti},Xp={...Js,...Ws};function xa(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var wa=xa("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),li=xa("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=Te(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),pf={utf8:wa,"utf-8":wa,hex:vt.base16,latin1:li,ascii:li,binary:li,...vt},xn=pf;function $(r,e="utf8"){let t=xn[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function Ve(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function cr(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function gf(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function lr(r,...e){if(!gf(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${r.length}`)}function vn(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");cr(r.outputLen),cr(r.blockLen)}function ur(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function va(r,e){lr(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var Ht=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var hr=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),He=(r,e)=>r<<32-e|r>>>e;var h0=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var mf=async()=>{};async function Ea(r,e,t){let n=Date.now();for(let s=0;s<r;s++){t(s);let i=Date.now()-n;i>=0&&i<e||(await mf(),n+=i)}}function Ba(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Et(r){return typeof r=="string"&&(r=Ba(r)),lr(r),r}function ui(...r){let e=0;for(let n=0;n<r.length;n++){let s=r[n];lr(s),e+=s.length}let t=new Uint8Array(e);for(let n=0,s=0;n<r.length;n++){let i=r[n];t.set(i,s),s+=i.length}return t}var fr=class{clone(){return this._cloneInto()}},yf={}.toString;function Aa(r,e){if(e!==void 0&&yf.call(e)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(r,e)}function En(r){let e=n=>r().update(Et(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function dr(r=32){if(Ht&&typeof Ht.getRandomValues=="function")return Ht.getRandomValues(new Uint8Array(r));if(Ht&&typeof Ht.randomBytes=="function")return Ht.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function bf(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let s=BigInt(32),i=BigInt(4294967295),o=Number(t>>s&i),a=Number(t&i),c=n?4:0,f=n?0:4;r.setUint32(e+c,o,n),r.setUint32(e+f,a,n)}var ka=(r,e,t)=>r&e^~r&t,Sa=(r,e,t)=>r&e^r&t^e&t,pr=class extends fr{constructor(e,t,n,s){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=hr(this.buffer)}update(e){ur(this);let{view:t,buffer:n,blockLen:s}=this;e=Et(e);let i=e.length;for(let o=0;o<i;){let a=Math.min(s-this.pos,i-o);if(a===s){let c=hr(e);for(;s<=i-o;o+=s)this.process(c,o);continue}n.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===s&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){ur(this),va(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:s,isLE:i}=this,{pos:o}=this;t[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>s-o&&(this.process(n,0),o=0);for(let l=o;l<s;l++)t[l]=0;bf(n,s-8,BigInt(this.length*8),i),this.process(n,0);let a=hr(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)a.setUint32(4*l,u[l],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:s,finished:i,destroyed:o,pos:a}=this;return e.length=s,e.pos=a,e.finished=i,e.destroyed=o,s%t&&e.buffer.set(n),e}};var Bn=BigInt(4294967295),fi=BigInt(32);function Ia(r,e=!1){return e?{h:Number(r&Bn),l:Number(r>>fi&Bn)}:{h:Number(r>>fi&Bn)|0,l:Number(r&Bn)|0}}function wf(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let s=0;s<r.length;s++){let{h:i,l:o}=Ia(r[s],e);[t[s],n[s]]=[i,o]}return[t,n]}var xf=(r,e)=>BigInt(r>>>0)<<fi|BigInt(e>>>0),vf=(r,e,t)=>r>>>t,Ef=(r,e,t)=>r<<32-t|e>>>t,Bf=(r,e,t)=>r>>>t|e<<32-t,Af=(r,e,t)=>r<<32-t|e>>>t,kf=(r,e,t)=>r<<64-t|e>>>t-32,Sf=(r,e,t)=>r>>>t-32|e<<64-t,If=(r,e)=>e,Rf=(r,e)=>r,Nf=(r,e,t)=>r<<t|e>>>32-t,Tf=(r,e,t)=>e<<t|r>>>32-t,_f=(r,e,t)=>e<<t-32|r>>>64-t,Lf=(r,e,t)=>r<<t-32|e>>>64-t;function Cf(r,e,t,n){let s=(e>>>0)+(n>>>0);return{h:r+t+(s/2**32|0)|0,l:s|0}}var Uf=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),Pf=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,Df=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),Vf=(r,e,t,n,s)=>e+t+n+s+(r/2**32|0)|0,Of=(r,e,t,n,s)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(s>>>0),Mf=(r,e,t,n,s,i)=>e+t+n+s+i+(r/2**32|0)|0;var Hf={fromBig:Ia,split:wf,toBig:xf,shrSH:vf,shrSL:Ef,rotrSH:Bf,rotrSL:Af,rotrBH:kf,rotrBL:Sf,rotr32H:If,rotr32L:Rf,rotlSH:Nf,rotlSL:Tf,rotlBH:_f,rotlBL:Lf,add:Cf,add3L:Uf,add3H:Pf,add4L:Df,add4H:Vf,add5H:Mf,add5L:Of},D=Hf;var[Kf,Ff]=D.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),Bt=new Uint32Array(80),At=new Uint32Array(80),hi=class extends pr{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:e,Al:t,Bh:n,Bl:s,Ch:i,Cl:o,Dh:a,Dl:c,Eh:f,El:u,Fh:l,Fl:h,Gh:m,Gl:x,Hh:y,Hl:d}=this;return[e,t,n,s,i,o,a,c,f,u,l,h,m,x,y,d]}set(e,t,n,s,i,o,a,c,f,u,l,h,m,x,y,d){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=s|0,this.Ch=i|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=l|0,this.Fl=h|0,this.Gh=m|0,this.Gl=x|0,this.Hh=y|0,this.Hl=d|0}process(e,t){for(let g=0;g<16;g++,t+=4)Bt[g]=e.getUint32(t),At[g]=e.getUint32(t+=4);for(let g=16;g<80;g++){let B=Bt[g-15]|0,C=At[g-15]|0,L=D.rotrSH(B,C,1)^D.rotrSH(B,C,8)^D.shrSH(B,C,7),S=D.rotrSL(B,C,1)^D.rotrSL(B,C,8)^D.shrSL(B,C,7),I=Bt[g-2]|0,_=At[g-2]|0,ne=D.rotrSH(I,_,19)^D.rotrBH(I,_,61)^D.shrSH(I,_,6),q=D.rotrSL(I,_,19)^D.rotrBL(I,_,61)^D.shrSL(I,_,6),V=D.add4L(S,q,At[g-7],At[g-16]),se=D.add4H(V,L,ne,Bt[g-7],Bt[g-16]);Bt[g]=se|0,At[g]=V|0}let{Ah:n,Al:s,Bh:i,Bl:o,Ch:a,Cl:c,Dh:f,Dl:u,Eh:l,El:h,Fh:m,Fl:x,Gh:y,Gl:d,Hh:w,Hl:E}=this;for(let g=0;g<80;g++){let B=D.rotrSH(l,h,14)^D.rotrSH(l,h,18)^D.rotrBH(l,h,41),C=D.rotrSL(l,h,14)^D.rotrSL(l,h,18)^D.rotrBL(l,h,41),L=l&m^~l&y,S=h&x^~h&d,I=D.add5L(E,C,S,Ff[g],At[g]),_=D.add5H(I,w,B,L,Kf[g],Bt[g]),ne=I|0,q=D.rotrSH(n,s,28)^D.rotrBH(n,s,34)^D.rotrBH(n,s,39),V=D.rotrSL(n,s,28)^D.rotrBL(n,s,34)^D.rotrBL(n,s,39),se=n&i^n&a^i&a,A=s&o^s&c^o&c;w=y|0,E=d|0,y=m|0,d=x|0,m=l|0,x=h|0,{h:l,l:h}=D.add(f|0,u|0,_|0,ne|0),f=a|0,u=c|0,a=i|0,c=o|0,i=n|0,o=s|0;let N=D.add3L(ne,V,A);n=D.add3H(N,_,q,se),s=N|0}({h:n,l:s}=D.add(this.Ah|0,this.Al|0,n|0,s|0)),{h:i,l:o}=D.add(this.Bh|0,this.Bl|0,i|0,o|0),{h:a,l:c}=D.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=D.add(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:h}=D.add(this.Eh|0,this.El|0,l|0,h|0),{h:m,l:x}=D.add(this.Fh|0,this.Fl|0,m|0,x|0),{h:y,l:d}=D.add(this.Gh|0,this.Gl|0,y|0,d|0),{h:w,l:E}=D.add(this.Hh|0,this.Hl|0,w|0,E|0),this.set(n,s,i,o,a,c,f,u,l,h,m,x,y,d,w,E)}roundClean(){Bt.fill(0),At.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Mr=En(()=>new hi);var kn={};ue(kn,{aInRange:()=>_e,abool:()=>Ke,abytes:()=>gr,bitGet:()=>Wf,bitLen:()=>yi,bitMask:()=>Kr,bitSet:()=>Yf,bytesToHex:()=>ot,bytesToNumberBE:()=>at,bytesToNumberLE:()=>St,concatBytes:()=>ct,createHmacDrbg:()=>bi,ensureBytes:()=>te,equalBytes:()=>Gf,hexToBytes:()=>Ft,hexToNumber:()=>mi,inRange:()=>Hr,isBytes:()=>kt,memoized:()=>$t,notImplemented:()=>Jf,numberToBytesBE:()=>It,numberToBytesLE:()=>qt,numberToHexUnpadded:()=>Kt,numberToVarBytesBE:()=>zf,utf8ToBytes:()=>jf,validateObject:()=>We});var gi=BigInt(0),An=BigInt(1),qf=BigInt(2);function kt(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function gr(r){if(!kt(r))throw new Error("Uint8Array expected")}function Ke(r,e){if(typeof e!="boolean")throw new Error(`${r} must be valid boolean, got "${e}".`)}var $f=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function ot(r){gr(r);let e="";for(let t=0;t<r.length;t++)e+=$f[r[t]];return e}function Kt(r){let e=r.toString(16);return e.length&1?`0${e}`:e}function mi(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var it={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function Ra(r){if(r>=it._0&&r<=it._9)return r-it._0;if(r>=it._A&&r<=it._F)return r-(it._A-10);if(r>=it._a&&r<=it._f)return r-(it._a-10)}function Ft(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let e=r.length,t=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let s=0,i=0;s<t;s++,i+=2){let o=Ra(r.charCodeAt(i)),a=Ra(r.charCodeAt(i+1));if(o===void 0||a===void 0){let c=r[i]+r[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[s]=o*16+a}return n}function at(r){return mi(ot(r))}function St(r){return gr(r),mi(ot(Uint8Array.from(r).reverse()))}function It(r,e){return Ft(r.toString(16).padStart(e*2,"0"))}function qt(r,e){return It(r,e).reverse()}function zf(r){return Ft(Kt(r))}function te(r,e,t){let n;if(typeof e=="string")try{n=Ft(e)}catch(i){throw new Error(`${r} must be valid hex string, got "${e}". Cause: ${i}`)}else if(kt(e))n=Uint8Array.from(e);else throw new Error(`${r} must be hex string or Uint8Array`);let s=n.length;if(typeof t=="number"&&s!==t)throw new Error(`${r} expected ${t} bytes, got ${s}`);return n}function ct(...r){let e=0;for(let n=0;n<r.length;n++){let s=r[n];gr(s),e+=s.length}let t=new Uint8Array(e);for(let n=0,s=0;n<r.length;n++){let i=r[n];t.set(i,s),s+=i.length}return t}function Gf(r,e){if(r.length!==e.length)return!1;let t=0;for(let n=0;n<r.length;n++)t|=r[n]^e[n];return t===0}function jf(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}var di=r=>typeof r=="bigint"&&gi<=r;function Hr(r,e,t){return di(r)&&di(e)&&di(t)&&e<=r&&r<t}function _e(r,e,t,n){if(!Hr(e,t,n))throw new Error(`expected valid ${r}: ${t} <= n < ${n}, got ${typeof e} ${e}`)}function yi(r){let e;for(e=0;r>gi;r>>=An,e+=1);return e}function Wf(r,e){return r>>BigInt(e)&An}function Yf(r,e,t){return r|(t?An:gi)<<BigInt(e)}var Kr=r=>(qf<<BigInt(r-1))-An,pi=r=>new Uint8Array(r),Na=r=>Uint8Array.from(r);function bi(r,e,t){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof t!="function")throw new Error("hmacFn must be a function");let n=pi(r),s=pi(r),i=0,o=()=>{n.fill(1),s.fill(0),i=0},a=(...l)=>t(s,n,...l),c=(l=pi())=>{s=a(Na([0]),l),n=a(),l.length!==0&&(s=a(Na([1]),l),n=a())},f=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,h=[];for(;l<e;){n=a();let m=n.slice();h.push(m),l+=n.length}return ct(...h)};return(l,h)=>{o(),c(l);let m;for(;!(m=h(f()));)c();return o(),m}}var Zf={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||kt(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,e)=>e.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function We(r,e,t={}){let n=(s,i,o)=>{let a=Zf[i];if(typeof a!="function")throw new Error(`Invalid validator "${i}", expected function`);let c=r[s];if(!(o&&c===void 0)&&!a(c,r))throw new Error(`Invalid param ${String(s)}=${c} (${typeof c}), expected ${i}`)};for(let[s,i]of Object.entries(e))n(s,i,!1);for(let[s,i]of Object.entries(t))n(s,i,!0);return r}var Jf=()=>{throw new Error("not implemented")};function $t(r){let e=new WeakMap;return(t,...n)=>{let s=e.get(t);if(s!==void 0)return s;let i=r(t,...n);return e.set(t,i),i}}var ae=BigInt(0),Z=BigInt(1),zt=BigInt(2),Xf=BigInt(3),wi=BigInt(4),Ta=BigInt(5),_a=BigInt(8),Qf=BigInt(9),eh=BigInt(16);function j(r,e){let t=r%e;return t>=ae?t:e+t}function th(r,e,t){if(t<=ae||e<ae)throw new Error("Expected power/modulo > 0");if(t===Z)return ae;let n=Z;for(;e>ae;)e&Z&&(n=n*r%t),r=r*r%t,e>>=Z;return n}function J(r,e,t){let n=r;for(;e-- >ae;)n*=n,n%=t;return n}function Sn(r,e){if(r===ae||e<=ae)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=j(r,e),n=e,s=ae,i=Z,o=Z,a=ae;for(;t!==ae;){let f=n/t,u=n%t,l=s-o*f,h=i-a*f;n=t,t=u,s=o,i=a,o=l,a=h}if(n!==Z)throw new Error("invert: does not exist");return j(s,e)}function rh(r){let e=(r-Z)/zt,t,n,s;for(t=r-Z,n=0;t%zt===ae;t/=zt,n++);for(s=zt;s<r&&th(s,e,r)!==r-Z;s++);if(n===1){let o=(r+Z)/wi;return function(c,f){let u=c.pow(f,o);if(!c.eql(c.sqr(u),f))throw new Error("Cannot find square root");return u}}let i=(t+Z)/zt;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let f=n,u=a.pow(a.mul(a.ONE,s),t),l=a.pow(c,i),h=a.pow(c,t);for(;!a.eql(h,a.ONE);){if(a.eql(h,a.ZERO))return a.ZERO;let m=1;for(let y=a.sqr(h);m<f&&!a.eql(y,a.ONE);m++)y=a.sqr(y);let x=a.pow(u,Z<<BigInt(f-m-1));u=a.sqr(x),l=a.mul(l,x),h=a.mul(h,u),f=m}return l}}function nh(r){if(r%wi===Xf){let e=(r+Z)/wi;return function(n,s){let i=n.pow(s,e);if(!n.eql(n.sqr(i),s))throw new Error("Cannot find square root");return i}}if(r%_a===Ta){let e=(r-Ta)/_a;return function(n,s){let i=n.mul(s,zt),o=n.pow(i,e),a=n.mul(s,o),c=n.mul(n.mul(a,zt),o),f=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(f),s))throw new Error("Cannot find square root");return f}}return r%eh,rh(r)}var La=(r,e)=>(j(r,e)&Z)===Z,sh=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function xi(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=sh.reduce((n,s)=>(n[s]="function",n),e);return We(r,t)}function ih(r,e,t){if(t<ae)throw new Error("Expected power > 0");if(t===ae)return r.ONE;if(t===Z)return e;let n=r.ONE,s=e;for(;t>ae;)t&Z&&(n=r.mul(n,s)),s=r.sqr(s),t>>=Z;return n}function oh(r,e){let t=new Array(e.length),n=e.reduce((i,o,a)=>r.is0(o)?i:(t[a]=i,r.mul(i,o)),r.ONE),s=r.inv(n);return e.reduceRight((i,o,a)=>r.is0(o)?i:(t[a]=r.mul(i,t[a]),r.mul(i,o)),s),t}function vi(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function Rt(r,e,t=!1,n={}){if(r<=ae)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:s,nByteLength:i}=vi(r,e);if(i>2048)throw new Error("Field lengths over 2048 bytes are not supported");let o=nh(r),a=Object.freeze({ORDER:r,BITS:s,BYTES:i,MASK:Kr(s),ZERO:ae,ONE:Z,create:c=>j(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return ae<=c&&c<r},is0:c=>c===ae,isOdd:c=>(c&Z)===Z,neg:c=>j(-c,r),eql:(c,f)=>c===f,sqr:c=>j(c*c,r),add:(c,f)=>j(c+f,r),sub:(c,f)=>j(c-f,r),mul:(c,f)=>j(c*f,r),pow:(c,f)=>ih(a,c,f),div:(c,f)=>j(c*Sn(f,r),r),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>Sn(c,r),sqrt:n.sqrt||(c=>o(a,c)),invertBatch:c=>oh(a,c),cmov:(c,f,u)=>u?f:c,toBytes:c=>t?qt(c,i):It(c,i),fromBytes:c=>{if(c.length!==i)throw new Error(`Fp.fromBytes: expected ${i}, got ${c.length}`);return t?St(c):at(c)}});return Object.freeze(a)}function Ca(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let e=r.toString(2).length;return Math.ceil(e/8)}function Ei(r){let e=Ca(r);return e+Math.ceil(e/2)}function Ua(r,e,t=!1){let n=r.length,s=Ca(e),i=Ei(e);if(n<16||n<i||n>1024)throw new Error(`expected ${i}-1024 bytes of input, got ${n}`);let o=t?at(r):St(r),a=j(o,e-Z)+Z;return t?qt(a,s):It(a,s)}var ch=BigInt(0),Bi=BigInt(1),Ai=new WeakMap,Pa=new WeakMap;function In(r,e){let t=(i,o)=>{let a=o.negate();return i?a:o},n=i=>{if(!Number.isSafeInteger(i)||i<=0||i>e)throw new Error(`Wrong window size=${i}, should be [1..${e}]`)},s=i=>{n(i);let o=Math.ceil(e/i)+1,a=2**(i-1);return{windows:o,windowSize:a}};return{constTimeNegate:t,unsafeLadder(i,o){let a=r.ZERO,c=i;for(;o>ch;)o&Bi&&(a=a.add(c)),c=c.double(),o>>=Bi;return a},precomputeWindow(i,o){let{windows:a,windowSize:c}=s(o),f=[],u=i,l=u;for(let h=0;h<a;h++){l=u,f.push(l);for(let m=1;m<c;m++)l=l.add(u),f.push(l);u=l.double()}return f},wNAF(i,o,a){let{windows:c,windowSize:f}=s(i),u=r.ZERO,l=r.BASE,h=BigInt(2**i-1),m=2**i,x=BigInt(i);for(let y=0;y<c;y++){let d=y*f,w=Number(a&h);a>>=x,w>f&&(w-=m,a+=Bi);let E=d,g=d+Math.abs(w)-1,B=y%2!==0,C=w<0;w===0?l=l.add(t(B,o[E])):u=u.add(t(C,o[g]))}return{p:u,f:l}},wNAFCached(i,o,a){let c=Pa.get(i)||1,f=Ai.get(i);return f||(f=this.precomputeWindow(i,c),c!==1&&Ai.set(i,a(f))),this.wNAF(c,f,o)},setWindowSize(i,o){n(o),Pa.set(i,o),Ai.delete(i)}}}function Rn(r,e,t,n){if(!Array.isArray(t)||!Array.isArray(n)||n.length!==t.length)throw new Error("arrays of points and scalars must have equal length");n.forEach((u,l)=>{if(!e.isValid(u))throw new Error(`wrong scalar at index ${l}`)}),t.forEach((u,l)=>{if(!(u instanceof r))throw new Error(`wrong point at index ${l}`)});let s=yi(BigInt(t.length)),i=s>12?s-3:s>4?s-2:s?2:1,o=(1<<i)-1,a=new Array(o+1).fill(r.ZERO),c=Math.floor((e.BITS-1)/i)*i,f=r.ZERO;for(let u=c;u>=0;u-=i){a.fill(r.ZERO);for(let h=0;h<n.length;h++){let m=n[h],x=Number(m>>BigInt(u)&BigInt(o));a[x]=a[x].add(t[h])}let l=r.ZERO;for(let h=a.length-1,m=r.ZERO;h>0;h--)m=m.add(a[h]),l=l.add(m);if(f=f.add(l),u!==0)for(let h=0;h<i;h++)f=f.double()}return f}function Fr(r){return xi(r.Fp),We(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...vi(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Fe=BigInt(0),Le=BigInt(1),Nn=BigInt(2),lh=BigInt(8),uh={zip215:!0};function fh(r){let e=Fr(r);return We(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function Da(r){let e=fh(r),{Fp:t,n,prehash:s,hash:i,randomBytes:o,nByteLength:a,h:c}=e,f=Nn<<BigInt(a*8)-Le,u=t.create,l=Rt(e.n,e.nBitLength),h=e.uvRatio||((b,p)=>{try{return{isValid:!0,value:t.sqrt(b*t.inv(p))}}catch{return{isValid:!1,value:Fe}}}),m=e.adjustScalarBytes||(b=>b),x=e.domain||((b,p,v)=>{if(Ke("phflag",v),p.length||v)throw new Error("Contexts/pre-hash are not supported");return b});function y(b,p){_e("coordinate "+b,p,Fe,f)}function d(b){if(!(b instanceof g))throw new Error("ExtendedPoint expected")}let w=$t((b,p)=>{let{ex:v,ey:T,ez:U}=b,P=b.is0();p==null&&(p=P?lh:t.inv(U));let O=u(v*p),F=u(T*p),M=u(U*p);if(P)return{x:Fe,y:Le};if(M!==Le)throw new Error("invZ was invalid");return{x:O,y:F}}),E=$t(b=>{let{a:p,d:v}=e;if(b.is0())throw new Error("bad point: ZERO");let{ex:T,ey:U,ez:P,et:O}=b,F=u(T*T),M=u(U*U),G=u(P*P),Y=u(G*G),ce=u(F*p),le=u(G*u(ce+M)),de=u(Y+u(v*u(F*M)));if(le!==de)throw new Error("bad point: equation left != right (1)");let ve=u(T*U),ie=u(P*O);if(ve!==ie)throw new Error("bad point: equation left != right (2)");return!0});class g{constructor(p,v,T,U){this.ex=p,this.ey=v,this.ez=T,this.et=U,y("x",p),y("y",v),y("z",T),y("t",U),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(p){if(p instanceof g)throw new Error("extended point not allowed");let{x:v,y:T}=p||{};return y("x",v),y("y",T),new g(v,T,Le,u(v*T))}static normalizeZ(p){let v=t.invertBatch(p.map(T=>T.ez));return p.map((T,U)=>T.toAffine(v[U])).map(g.fromAffine)}static msm(p,v){return Rn(g,l,p,v)}_setWindowSize(p){L.setWindowSize(this,p)}assertValidity(){E(this)}equals(p){d(p);let{ex:v,ey:T,ez:U}=this,{ex:P,ey:O,ez:F}=p,M=u(v*F),G=u(P*U),Y=u(T*F),ce=u(O*U);return M===G&&Y===ce}is0(){return this.equals(g.ZERO)}negate(){return new g(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:p}=e,{ex:v,ey:T,ez:U}=this,P=u(v*v),O=u(T*T),F=u(Nn*u(U*U)),M=u(p*P),G=v+T,Y=u(u(G*G)-P-O),ce=M+O,le=ce-F,de=M-O,ve=u(Y*le),ie=u(ce*de),Ne=u(Y*de),tt=u(le*ce);return new g(ve,ie,tt,Ne)}add(p){d(p);let{a:v,d:T}=e,{ex:U,ey:P,ez:O,et:F}=this,{ex:M,ey:G,ez:Y,et:ce}=p;if(v===BigInt(-1)){let $o=u((P-U)*(G+M)),zo=u((P+U)*(G-M)),Ks=u(zo-$o);if(Ks===Fe)return this.double();let Go=u(O*Nn*ce),jo=u(F*Nn*Y),Wo=jo+Go,Yo=zo+$o,Zo=jo-Go,Ql=u(Wo*Ks),eu=u(Yo*Zo),tu=u(Wo*Zo),ru=u(Ks*Yo);return new g(Ql,eu,ru,tu)}let le=u(U*M),de=u(P*G),ve=u(F*T*ce),ie=u(O*Y),Ne=u((U+P)*(M+G)-le-de),tt=ie-ve,Ur=ie+ve,Pr=u(de-v*le),Yl=u(Ne*tt),Zl=u(Ur*Pr),Jl=u(Ne*Pr),Xl=u(tt*Ur);return new g(Yl,Zl,Xl,Jl)}subtract(p){return this.add(p.negate())}wNAF(p){return L.wNAFCached(this,p,g.normalizeZ)}multiply(p){let v=p;_e("scalar",v,Le,n);let{p:T,f:U}=this.wNAF(v);return g.normalizeZ([T,U])[0]}multiplyUnsafe(p){let v=p;return _e("scalar",v,Fe,n),v===Fe?C:this.equals(C)||v===Le?this:this.equals(B)?this.wNAF(v).p:L.unsafeLadder(this,v)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return L.unsafeLadder(this,n).is0()}toAffine(p){return w(this,p)}clearCofactor(){let{h:p}=e;return p===Le?this:this.multiplyUnsafe(p)}static fromHex(p,v=!1){let{d:T,a:U}=e,P=t.BYTES;p=te("pointHex",p,P),Ke("zip215",v);let O=p.slice(),F=p[P-1];O[P-1]=F&-129;let M=St(O),G=v?f:t.ORDER;_e("pointHex.y",M,Fe,G);let Y=u(M*M),ce=u(Y-Le),le=u(T*Y-U),{isValid:de,value:ve}=h(ce,le);if(!de)throw new Error("Point.fromHex: invalid y coordinate");let ie=(ve&Le)===Le,Ne=(F&128)!==0;if(!v&&ve===Fe&&Ne)throw new Error("Point.fromHex: x=0 and x_0=1");return Ne!==ie&&(ve=u(-ve)),g.fromAffine({x:ve,y:M})}static fromPrivateKey(p){return _(p).point}toRawBytes(){let{x:p,y:v}=this.toAffine(),T=qt(v,t.BYTES);return T[T.length-1]|=p&Le?128:0,T}toHex(){return ot(this.toRawBytes())}}g.BASE=new g(e.Gx,e.Gy,Le,u(e.Gx*e.Gy)),g.ZERO=new g(Fe,Le,Le,Fe);let{BASE:B,ZERO:C}=g,L=In(g,a*8);function S(b){return j(b,n)}function I(b){return S(St(b))}function _(b){let p=a;b=te("private key",b,p);let v=te("hashed private key",i(b),2*p),T=m(v.slice(0,p)),U=v.slice(p,2*p),P=I(T),O=B.multiply(P),F=O.toRawBytes();return{head:T,prefix:U,scalar:P,point:O,pointBytes:F}}function ne(b){return _(b).pointBytes}function q(b=new Uint8Array,...p){let v=ct(...p);return I(i(x(v,te("context",b),!!s)))}function V(b,p,v={}){b=te("message",b),s&&(b=s(b));let{prefix:T,scalar:U,pointBytes:P}=_(p),O=q(v.context,T,b),F=B.multiply(O).toRawBytes(),M=q(v.context,F,P,b),G=S(O+M*U);_e("signature.s",G,Fe,n);let Y=ct(F,qt(G,t.BYTES));return te("result",Y,a*2)}let se=uh;function A(b,p,v,T=se){let{context:U,zip215:P}=T,O=t.BYTES;b=te("signature",b,2*O),p=te("message",p),P!==void 0&&Ke("zip215",P),s&&(p=s(p));let F=St(b.slice(O,2*O)),M,G,Y;try{M=g.fromHex(v,P),G=g.fromHex(b.slice(0,O),P),Y=B.multiplyUnsafe(F)}catch{return!1}if(!P&&M.isSmallOrder())return!1;let ce=q(U,G.toRawBytes(),M.toRawBytes(),p);return G.add(M.multiplyUnsafe(ce)).subtract(Y).clearCofactor().equals(g.ZERO)}return B._setWindowSize(8),{CURVE:e,getPublicKey:ne,sign:V,verify:A,ExtendedPoint:g,utils:{getExtendedPublicKey:_,randomPrivateKey:()=>o(t.BYTES),precompute(b=8,p=g.BASE){return p._setWindowSize(b),p.multiply(BigInt(3)),p}}}}var ki=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Va=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),P0=BigInt(0),hh=BigInt(1),Oa=BigInt(2),D0=BigInt(3),dh=BigInt(5),ph=BigInt(8);function gh(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),s=BigInt(80),i=ki,a=r*r%i*r%i,c=J(a,Oa,i)*a%i,f=J(c,hh,i)*r%i,u=J(f,dh,i)*f%i,l=J(u,e,i)*u%i,h=J(l,t,i)*l%i,m=J(h,n,i)*h%i,x=J(m,s,i)*m%i,y=J(x,s,i)*m%i,d=J(y,e,i)*u%i;return{pow_p_5_8:J(d,Oa,i)*r%i,b2:a}}function mh(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function yh(r,e){let t=ki,n=j(e*e*e,t),s=j(n*n*e,t),i=gh(r*s).pow_p_5_8,o=j(r*n*i,t),a=j(e*o*o,t),c=o,f=j(o*Va,t),u=a===r,l=a===j(-r,t),h=a===j(-r*Va,t);return u&&(o=c),(l||h)&&(o=f),La(o,t)&&(o=j(-o,t)),{isValid:u||l,value:o}}var bh=Rt(ki,void 0,!0),wh={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:bh,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:ph,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Mr,randomBytes:dr,adjustScalarBytes:mh,uvRatio:yh},mr=Da(wh);var yr=32,lt=64,Tn=32;function Ma(){let r=mr.utils.randomPrivateKey(),e=mr.getPublicKey(r);return{privateKey:qa(r,e),publicKey:e}}function Ha(r){if(r.length!==Tn)throw new TypeError('"seed" must be 32 bytes in length.');if(!(r instanceof Uint8Array))throw new TypeError('"seed" must be a node.js Buffer, or Uint8Array.');let e=r,t=mr.getPublicKey(e);return{privateKey:qa(e,t),publicKey:t}}function Ka(r,e){let t=r.subarray(0,Tn);return mr.sign(e instanceof Uint8Array?e:e.subarray(),t)}function Fa(r,e,t){return mr.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}function qa(r,e){let t=new Uint8Array(lt);for(let n=0;n<Tn;n++)t[n]=r[n],t[Tn+n]=e[n];return t}var Be={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw Object.assign(new Error("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api"),{code:"ERR_MISSING_WEB_CRYPTO"});return e}};var Si={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function $a(r){let e=r?.algorithm??"AES-GCM",t=r?.keyLength??16,n=r?.nonceLength??12,s=r?.digest??"SHA-256",i=r?.saltLength??16,o=r?.iterations??32767,a=Be.get();t*=8;async function c(l,h){let m=a.getRandomValues(new Uint8Array(i)),x=a.getRandomValues(new Uint8Array(n)),y={name:e,iv:x};typeof h=="string"&&(h=$(h));let d;if(h.length===0){d=await a.subtle.importKey("jwk",Si,{name:"AES-GCM"},!0,["encrypt"]);try{let E={name:"PBKDF2",salt:m,iterations:o,hash:{name:s}},g=await a.subtle.importKey("raw",h,{name:"PBKDF2"},!1,["deriveKey"]);d=await a.subtle.deriveKey(E,g,{name:e,length:t},!0,["encrypt"])}catch{d=await a.subtle.importKey("jwk",Si,{name:"AES-GCM"},!0,["encrypt"])}}else{let E={name:"PBKDF2",salt:m,iterations:o,hash:{name:s}},g=await a.subtle.importKey("raw",h,{name:"PBKDF2"},!1,["deriveKey"]);d=await a.subtle.deriveKey(E,g,{name:e,length:t},!0,["encrypt"])}let w=await a.subtle.encrypt(y,d,l);return Ee([m,y.iv,new Uint8Array(w)])}async function f(l,h){let m=l.subarray(0,i),x=l.subarray(i,i+n),y=l.subarray(i+n),d={name:e,iv:x};typeof h=="string"&&(h=$(h));let w;if(h.length===0)try{let g={name:"PBKDF2",salt:m,iterations:o,hash:{name:s}},B=await a.subtle.importKey("raw",h,{name:"PBKDF2"},!1,["deriveKey"]);w=await a.subtle.deriveKey(g,B,{name:e,length:t},!0,["decrypt"])}catch{w=await a.subtle.importKey("jwk",Si,{name:"AES-GCM"},!0,["decrypt"])}else{let g={name:"PBKDF2",salt:m,iterations:o,hash:{name:s}},B=await a.subtle.importKey("raw",h,{name:"PBKDF2"},!1,["deriveKey"]);w=await a.subtle.deriveKey(g,B,{name:e,length:t},!0,["decrypt"])}let E=await a.subtle.decrypt(d,w,y);return new Uint8Array(E)}return{encrypt:c,decrypt:f}}async function br(r,e){let n=await $a().encrypt(r,e);return si.encode(n)}var Eh=Math.pow(2,7),Bh=Math.pow(2,14),Ah=Math.pow(2,21),Ii=Math.pow(2,28),Ri=Math.pow(2,35),Ni=Math.pow(2,42),Ti=Math.pow(2,49),z=128,ye=127;function Ce(r){if(r<Eh)return 1;if(r<Bh)return 2;if(r<Ah)return 3;if(r<Ii)return 4;if(r<Ri)return 5;if(r<Ni)return 6;if(r<Ti)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function _i(r,e,t=0){switch(Ce(r)){case 8:e[t++]=r&255|z,r/=128;case 7:e[t++]=r&255|z,r/=128;case 6:e[t++]=r&255|z,r/=128;case 5:e[t++]=r&255|z,r/=128;case 4:e[t++]=r&255|z,r>>>=7;case 3:e[t++]=r&255|z,r>>>=7;case 2:e[t++]=r&255|z,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function kh(r,e,t=0){switch(Ce(r)){case 8:e.set(t++,r&255|z),r/=128;case 7:e.set(t++,r&255|z),r/=128;case 6:e.set(t++,r&255|z),r/=128;case 5:e.set(t++,r&255|z),r/=128;case 4:e.set(t++,r&255|z),r>>>=7;case 3:e.set(t++,r&255|z),r>>>=7;case 2:e.set(t++,r&255|z),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Li(r,e){let t=r[e],n=0;if(n+=t&ye,t<z||(t=r[e+1],n+=(t&ye)<<7,t<z)||(t=r[e+2],n+=(t&ye)<<14,t<z)||(t=r[e+3],n+=(t&ye)<<21,t<z)||(t=r[e+4],n+=(t&ye)*Ii,t<z)||(t=r[e+5],n+=(t&ye)*Ri,t<z)||(t=r[e+6],n+=(t&ye)*Ni,t<z)||(t=r[e+7],n+=(t&ye)*Ti,t<z))return n;throw new RangeError("Could not decode varint")}function Sh(r,e){let t=r.get(e),n=0;if(n+=t&ye,t<z||(t=r.get(e+1),n+=(t&ye)<<7,t<z)||(t=r.get(e+2),n+=(t&ye)<<14,t<z)||(t=r.get(e+3),n+=(t&ye)<<21,t<z)||(t=r.get(e+4),n+=(t&ye)*Ii,t<z)||(t=r.get(e+5),n+=(t&ye)*Ri,t<z)||(t=r.get(e+6),n+=(t&ye)*Ni,t<z)||(t=r.get(e+7),n+=(t&ye)*Ti,t<z))return n;throw new RangeError("Could not decode varint")}function Ye(r,e,t=0){return e==null&&(e=Te(Ce(r))),e instanceof Uint8Array?_i(r,e,t):kh(r,e,t)}function Gt(r,e=0){return r instanceof Uint8Array?Li(r,e):Sh(r,e)}var Ui=new Float32Array([-0]),Nt=new Uint8Array(Ui.buffer);function za(r,e,t){Ui[0]=r,e[t]=Nt[0],e[t+1]=Nt[1],e[t+2]=Nt[2],e[t+3]=Nt[3]}function Ga(r,e){return Nt[0]=r[e],Nt[1]=r[e+1],Nt[2]=r[e+2],Nt[3]=r[e+3],Ui[0]}var Pi=new Float64Array([-0]),be=new Uint8Array(Pi.buffer);function ja(r,e,t){Pi[0]=r,e[t]=be[0],e[t+1]=be[1],e[t+2]=be[2],e[t+3]=be[3],e[t+4]=be[4],e[t+5]=be[5],e[t+6]=be[6],e[t+7]=be[7]}function Wa(r,e){return be[0]=r[e],be[1]=r[e+1],be[2]=r[e+2],be[3]=r[e+3],be[4]=r[e+4],be[5]=r[e+5],be[6]=r[e+6],be[7]=r[e+7],Pi[0]}var Ih=BigInt(Number.MAX_SAFE_INTEGER),Rh=BigInt(Number.MIN_SAFE_INTEGER),Pe=class r{lo;hi;constructor(e,t){this.lo=e|0,this.hi=t|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(t+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(BigInt(t)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return jt;if(e<Ih&&e>Rh)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,s=e-(n<<32n);return t&&(n=~n|0n,s=~s|0n,++s>Ya&&(s=0n,++n>Ya&&(n=0n))),new r(Number(s),Number(n))}static fromNumber(e){if(e===0)return jt;let t=e<0;t&&(e=-e);let n=e>>>0,s=(e-n)/4294967296>>>0;return t&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new r(n,s)}static from(e){return typeof e=="number"?r.fromNumber(e):typeof e=="bigint"?r.fromBigInt(e):typeof e=="string"?r.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new r(e.low>>>0,e.high>>>0):jt}},jt=new Pe(0,0);jt.toBigInt=function(){return 0n};jt.zzEncode=jt.zzDecode=function(){return this};jt.length=function(){return 1};var Ya=4294967296n;function Za(r){let e=0,t=0;for(let n=0;n<r.length;++n)t=r.charCodeAt(n),t<128?e+=1:t<2048?e+=2:(t&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function Ja(r,e,t){if(t-e<1)return"";let s,i=[],o=0,a;for(;e<t;)a=r[e++],a<128?i[o++]=a:a>191&&a<224?i[o++]=(a&31)<<6|r[e++]&63:a>239&&a<365?(a=((a&7)<<18|(r[e++]&63)<<12|(r[e++]&63)<<6|r[e++]&63)-65536,i[o++]=55296+(a>>10),i[o++]=56320+(a&1023)):i[o++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,o>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,i)),o=0);return s!=null?(o>0&&s.push(String.fromCharCode.apply(String,i.slice(0,o))),s.join("")):String.fromCharCode.apply(String,i.slice(0,o))}function Di(r,e,t){let n=t,s,i;for(let o=0;o<r.length;++o)s=r.charCodeAt(o),s<128?e[t++]=s:s<2048?(e[t++]=s>>6|192,e[t++]=s&63|128):(s&64512)===55296&&((i=r.charCodeAt(o+1))&64512)===56320?(s=65536+((s&1023)<<10)+(i&1023),++o,e[t++]=s>>18|240,e[t++]=s>>12&63|128,e[t++]=s>>6&63|128,e[t++]=s&63|128):(e[t++]=s>>12|224,e[t++]=s>>6&63|128,e[t++]=s&63|128);return t-n}function qe(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function _n(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Vi=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,qe(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw qe(this,4);return _n(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw qe(this,4);return _n(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw qe(this,4);let e=Ga(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw qe(this,4);let e=Wa(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),t=this.pos,n=this.pos+e;if(n>this.len)throw qe(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return Ja(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw qe(this,e);this.pos+=e}else do if(this.pos>=this.len)throw qe(this);while(this.buf[this.pos++]&128);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Pe(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw qe(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<t*7)>>>0,e}if(this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw qe(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw qe(this,8);let e=_n(this.buf,this.pos+=4),t=_n(this.buf,this.pos+=4);return new Pe(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Li(this.buf,this.pos);return this.pos+=Ce(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Oi(r){return new Vi(r instanceof Uint8Array?r:r.subarray())}function Ae(r,e,t){let n=Oi(r);return e.decode(n,void 0,t)}function Mi(r){let e=r??8192,t=e>>>1,n,s=e;return function(o){if(o<1||o>t)return Te(o);s+o>e&&(n=Te(e),s=0);let a=n.subarray(s,s+=o);return s&7&&(s=(s|7)+1),a}}var Wt=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function Hi(){}var Fi=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Nh=Mi();function Th(r){return globalThis.Buffer!=null?Te(r):Nh(r)}var $r=class{len;head;tail;states;constructor(){this.len=0,this.head=new Wt(Hi,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new Wt(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new qi((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(Ln,10,Pe.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=Pe.fromBigInt(e);return this._push(Ln,t.length(),t)}uint64Number(e){return this._push(_i,Ce(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=Pe.fromBigInt(e).zzEncode();return this._push(Ln,t.length(),t)}sint64Number(e){let t=Pe.fromNumber(e).zzEncode();return this._push(Ln,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Ki,1,e?1:0)}fixed32(e){return this._push(qr,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=Pe.fromBigInt(e);return this._push(qr,4,t.lo)._push(qr,4,t.hi)}fixed64Number(e){let t=Pe.fromNumber(e);return this._push(qr,4,t.lo)._push(qr,4,t.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(za,4,e)}double(e){return this._push(ja,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Ki,1,0):this.uint32(t)._push(Lh,t,e)}string(e){let t=Za(e);return t!==0?this.uint32(t)._push(Di,t,e):this._push(Ki,1,0)}fork(){return this.states=new Fi(this),this.head=this.tail=new Wt(Hi,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Wt(Hi,0,0),this.len=0),this}ldelim(){let e=this.head,t=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=t,this.len+=n),this}finish(){let e=this.head.next,t=Th(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function Ki(r,e,t){e[t]=r&255}function _h(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var qi=class extends Wt{next;constructor(e,t){super(_h,e,t),this.next=void 0}};function Ln(r,e,t){for(;r.hi!==0;)e[t++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)e[t++]=r.lo&127|128,r.lo=r.lo>>>7;e[t++]=r.lo}function qr(r,e,t){e[t]=r&255,e[t+1]=r>>>8&255,e[t+2]=r>>>16&255,e[t+3]=r>>>24}function Lh(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&($r.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(Ch,e,r),this},$r.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(Uh,e,r),this});function Ch(r,e,t){e.set(r,t)}function Uh(r,e,t){r.length<40?Di(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set($(r),t)}function $i(){return new $r}function ke(r,e){let t=$i();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var wr;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(wr||(wr={}));function Cn(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function zi(r){function e(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let t=function(i,o){let a=e(i);o.int32(a)},n=function(i){let o=i.int32();return e(o)};return Cn("enum",wr.VARINT,t,n)}function Se(r,e){return Cn("message",wr.LENGTH_DELIMITED,r,e)}var X;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1"})(X||(X={}));var Gi;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1"})(Gi||(Gi={}));(function(r){r.codec=()=>zi(Gi)})(X||(X={}));var Ze;(function(r){let e;r.codec=()=>(e==null&&(e=Se((t,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),X.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),s.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let s={},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let o=t.uint32();switch(o>>>3){case 1:s.Type=X.codec().decode(t);break;case 2:s.Data=t.bytes();break;default:t.skipType(o&7);break}}return s})),e),r.encode=t=>ke(t,r.codec()),r.decode=t=>Ae(t,r.codec())})(Ze||(Ze={}));var Je;(function(r){let e;r.codec=()=>(e==null&&(e=Se((t,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),X.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),s.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let s={},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let o=t.uint32();switch(o>>>3){case 1:s.Type=X.codec().decode(t);break;case 2:s.Data=t.bytes();break;default:t.skipType(o&7);break}}return s})),e),r.encode=t=>ke(t,r.codec()),r.decode=t=>Ae(t,r.codec())})(Je||(Je={}));var zr=class{_key;constructor(e){this._key=xr(e,yr)}verify(e,t){return Fa(this._key,t,e)}marshal(){return this._key}get bytes(){return Ze.encode({Type:X.Ed25519,Data:this.marshal()}).subarray()}equals(e){return ee(this.bytes,e.bytes)}hash(){let e=pe.digest(this.bytes);return Ve(e)?e.then(({bytes:t})=>t):e.bytes}},Yt=class{_key;_publicKey;constructor(e,t){this._key=xr(e,lt),this._publicKey=xr(t,yr)}sign(e){return Ka(this._key,e)}get public(){return new zr(this._publicKey)}marshal(){return this._key}get bytes(){return Je.encode({Type:X.Ed25519,Data:this.marshal()}).subarray()}equals(e){return ee(this.bytes,e.bytes)}async hash(){let e=pe.digest(this.bytes),t;return Ve(e)?{bytes:t}=await e:t=e.bytes,t}async id(){let e=nt.digest(this.public.bytes);return oe.encode(e.bytes).substring(1)}async export(e,t="libp2p-key"){if(t==="libp2p-key")return br(this.bytes,e);throw new R(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function Ph(r){if(r.length>lt){r=xr(r,lt+yr);let n=r.subarray(0,lt),s=r.subarray(lt,r.length);return new Yt(n,s)}r=xr(r,lt);let e=r.subarray(0,lt),t=r.subarray(yr);return new Yt(e,t)}function Dh(r){return r=xr(r,yr),new zr(r)}async function Vh(){let{privateKey:r,publicKey:e}=Ma();return new Yt(r,e)}async function Qa(r){let{privateKey:e,publicKey:t}=Ha(r);return new Yt(e,t)}function xr(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new R(`Key must be a Uint8Array of length ${e}, got ${r.length}`,"ERR_INVALID_KEY_TYPE");return r}function H(r,e="utf8"){let t=xn[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var no={};ue(no,{MAX_RSA_KEY_SIZE:()=>nn,RsaPrivateKey:()=>kr,RsaPublicKey:()=>rn,fromJwk:()=>ud,generateKeyPair:()=>fd,unmarshalRsaPrivateKey:()=>to,unmarshalRsaPublicKey:()=>ld});function Zt(r){if(isNaN(r)||r<=0)throw new R("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return dr(r)}var Ct={};ue(Ct,{exportToPem:()=>sd,importFromPem:()=>id,jwkToPkcs1:()=>ed,jwkToPkix:()=>rd,pkcs1ToJwk:()=>Qh,pkixToJwk:()=>td});var Pn=class extends fr{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,vn(e);let n=Et(t);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let s=this.blockLen,i=new Uint8Array(s);i.set(n.length>s?e.create().update(n).digest():n);for(let o=0;o<i.length;o++)i[o]^=54;this.iHash.update(i),this.oHash=e.create();for(let o=0;o<i.length;o++)i[o]^=106;this.oHash.update(i),i.fill(0)}update(e){return ur(this),this.iHash.update(e),this}digestInto(e){ur(this),lr(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:t,iHash:n,finished:s,destroyed:i,blockLen:o,outputLen:a}=this;return e=e,e.finished=s,e.destroyed=i,e.blockLen=o,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Gr=(r,e,t)=>new Pn(r,e).update(t).digest();Gr.create=(r,e)=>new Pn(r,e);function Oh(r,e,t,n){vn(r);let s=Aa({dkLen:32,asyncTick:10},n),{c:i,dkLen:o,asyncTick:a}=s;if(cr(i),cr(o),cr(a),i<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=Et(e),f=Et(t),u=new Uint8Array(o),l=Gr.create(r,c),h=l._cloneInto().update(f);return{c:i,dkLen:o,asyncTick:a,DK:u,PRF:l,PRFSalt:h}}function Mh(r,e,t,n,s){return r.destroy(),e.destroy(),n&&n.destroy(),s.fill(0),t}async function Wi(r,e,t,n){let{c:s,dkLen:i,asyncTick:o,DK:a,PRF:c,PRFSalt:f}=Oh(r,e,t,n),u,l=new Uint8Array(4),h=hr(l),m=new Uint8Array(c.outputLen);for(let x=1,y=0;y<i;x++,y+=c.outputLen){let d=a.subarray(y,y+c.outputLen);h.setInt32(0,x,!1),(u=f._cloneInto(u)).update(l).digestInto(m),d.set(m.subarray(0,d.length)),await Ea(s-1,o,()=>{c._cloneInto(u).update(m).digestInto(m);for(let w=0;w<d.length;w++)d[w]^=m[w]})}return Mh(c,f,a,u,m)}var K=Qo(ec());function Jt(r,e){let t=0;if(r.length===1)return r[0];for(let n=r.length-1;n>=0;n--)t+=r[r.length-1-n]*Math.pow(2,e*n);return t}function Tt(r,e,t=-1){let n=t,s=r,i=0,o=Math.pow(2,e);for(let a=1;a<8;a++){if(r<o){let c;if(n<0)c=new ArrayBuffer(a),i=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),i=n}let f=new Uint8Array(c);for(let u=a-1;u>=0;u--){let l=Math.pow(2,u*e);f[i-u-1]=Math.floor(s/l),s-=f[i-u-1]*l}return c}o*=Math.pow(2,e)}return new ArrayBuffer(0)}function On(...r){let e=0,t=0;for(let i of r)e+=i.length;let n=new ArrayBuffer(e),s=new Uint8Array(n);for(let i of r)s.set(i,t),t+=i.length;return s}function Zi(){let r=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){let a=r[0]===255&&r[1]&128,c=r[0]===0&&(r[1]&128)===0;(a||c)&&this.warnings.push("Needlessly long format")}let e=new ArrayBuffer(this.valueHex.byteLength),t=new Uint8Array(e);for(let a=0;a<this.valueHex.byteLength;a++)t[a]=0;t[0]=r[0]&128;let n=Jt(t,8),s=new ArrayBuffer(this.valueHex.byteLength),i=new Uint8Array(s);for(let a=0;a<this.valueHex.byteLength;a++)i[a]=r[a];return i[0]&=127,Jt(i,8)-n}function tc(r){let e=r<0?r*-1:r,t=128;for(let n=1;n<8;n++){if(e<=t){if(r<0){let o=t-e,a=Tt(o,8,n),c=new Uint8Array(a);return c[0]|=128,a}let s=Tt(e,8,n),i=new Uint8Array(s);if(i[0]&128){let o=s.slice(0),a=new Uint8Array(o);s=new ArrayBuffer(s.byteLength+1),i=new Uint8Array(s);for(let c=0;c<o.byteLength;c++)i[c+1]=a[c];i[0]=0}return s}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function rc(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let s=0;s<t.length;s++)if(t[s]!==n[s])return!1;return!0}function Ue(r,e){let t=r.toString(10);if(e<t.length)return"";let n=e-t.length,s=new Array(n);for(let o=0;o<n;o++)s[o]="0";return s.join("").concat(t)}var $g=Math.log(2);function Mn(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Ji(r){let e=0,t=0;for(let s=0;s<r.length;s++){let i=r[s];e+=i.byteLength}let n=new Uint8Array(e);for(let s=0;s<r.length;s++){let i=r[s];n.set(new Uint8Array(i),t),t+=i.byteLength}return n.buffer}function pt(r,e,t,n){return e instanceof Uint8Array?e.byteLength?t<0?(r.error="Wrong parameter: inputOffset less than zero",!1):n<0?(r.error="Wrong parameter: inputLength less than zero",!1):e.byteLength-t-n<0?(r.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):!0:(r.error="Wrong parameter: inputBuffer has zero length",!1):(r.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}var Wr=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return Ji(this.items)}},jr=[new Uint8Array([1])],nc="0123456789";var Br="",ze=new ArrayBuffer(0),Xi=new Uint8Array(0),Yr="EndOfContent",ic="OCTET STRING",oc="BIT STRING";function gt(r){var e;return e=class extends r{constructor(...n){var s;super(...n);let i=n[0]||{};this.isHexOnly=(s=i.isHexOnly)!==null&&s!==void 0?s:!1,this.valueHexView=i.valueHex?K.BufferSourceConverter.toUint8Array(i.valueHex):Xi}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}fromBER(n,s,i){let o=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!pt(this,o,s,i))return-1;let a=s+i;return this.valueHexView=o.subarray(s,a),this.valueHexView.length?(this.blockLength=i,a):(this.warnings.push("Zero buffer length"),s)}toBER(n=!1){return this.isHexOnly?n?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",ze)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:K.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var ft=class{constructor({blockLength:e=0,error:t=Br,warnings:n=[],valueBeforeDecode:s=Xi}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=K.BufferSourceConverter.toUint8Array(s)}static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:K.Convert.ToHex(this.valueBeforeDecodeView)}}};ft.NAME="baseBlock";var we=class extends ft{fromBER(e,t,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(e,t){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}};we.NAME="valueBlock";var Hn=class extends gt(ft){constructor({idBlock:e={}}={}){var t,n,s,i;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?K.BufferSourceConverter.toUint8Array(e.valueHex):Xi,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(s=e.tagNumber)!==null&&s!==void 0?s:-1,this.isConstructed=(i=e.isConstructed)!==null&&i!==void 0?i:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",ze}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let s=new Uint8Array(1);if(!e){let i=this.tagNumber;i&=31,t|=i,s[0]=t}return s.buffer}if(!this.isHexOnly){let s=Tt(this.tagNumber,7),i=new Uint8Array(s),o=s.byteLength,a=new Uint8Array(o+1);if(a[0]=t|31,!e){for(let c=0;c<o-1;c++)a[c+1]=i[c]|128;a[o]=i[o-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let s=this.valueHexView;for(let i=0;i<s.length-1;i++)n[i+1]=s[i]|128;n[this.valueHexView.byteLength]=s[s.length-1]}return n.buffer}fromBER(e,t,n){let s=K.BufferSourceConverter.toUint8Array(e);if(!pt(this,s,t,n))return-1;let i=s.subarray(t,t+n);if(i.length===0)return this.error="Zero buffer length",-1;switch(i[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(i[0]&32)===32,this.isHexOnly=!1;let a=i[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,f=this.valueHexView=new Uint8Array(255),u=255;for(;i[c]&128;){if(f[c-1]=i[c]&127,c++,c>=i.length)return this.error="End of input reached before message was fully decoded",-1;if(c===u){u+=255;let h=new Uint8Array(u);for(let m=0;m<f.length;m++)h[m]=f[m];f=this.valueHexView=new Uint8Array(u)}}this.blockLength=c+1,f[c-1]=i[c]&127;let l=new Uint8Array(c);for(let h=0;h<c;h++)l[h]=f[h];f=this.valueHexView=new Uint8Array(c),f.set(l),this.blockLength<=9?this.tagNumber=Jt(f,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(this.tagClass===1&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return t+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}};Hn.NAME="identificationBlock";var Kn=class extends ft{constructor({lenBlock:e={}}={}){var t,n,s;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0?t:!1,this.longFormUsed=(n=e.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(s=e.length)!==null&&s!==void 0?s:0}fromBER(e,t,n){let s=K.BufferSourceConverter.toUint8Array(e);if(!pt(this,s,t,n))return-1;let i=s.subarray(t,t+n);if(i.length===0)return this.error="Zero buffer length",-1;if(i[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=i[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(i[0]&128),this.longFormUsed===!1)return this.length=i[0],this.blockLength=1,t+this.blockLength;let o=i[0]&127;if(o>8)return this.error="Too big integer",-1;if(o+1>i.length)return this.error="End of input reached before message was fully decoded",-1;let a=t+1,c=s.subarray(a,a+o);return c[o-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=Jt(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=o+1,t+this.blockLength}toBER(e=!1){let t,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=128),t;if(this.longFormUsed){let s=Tt(this.length,8);if(s.byteLength>127)return this.error="Too big length",ze;if(t=new ArrayBuffer(s.byteLength+1),e)return t;let i=new Uint8Array(s);n=new Uint8Array(t),n[0]=s.byteLength|128;for(let o=0;o<s.byteLength;o++)n[o+1]=i[o];return t}return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};Kn.NAME="lengthBlock";var k={},ge=class extends ft{constructor({name:e=Br,optional:t=!1,primitiveSchema:n,...s}={},i){super(s),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new Hn(s),this.lenBlock=new Kn(s),this.valueBlock=i?new i(s):new we(s)}fromBER(e,t,n){let s=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),s)}toBER(e,t){let n=t||new Wr;t||ac(this);let s=this.idBlock.toBER(e);if(n.write(s),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,n),n.write(new ArrayBuffer(2));else{let i=this.valueBlock.toBER(e);this.lenBlock.length=i.byteLength;let o=this.lenBlock.toBER(e);n.write(o),n.write(i)}return t?ze:n.final()}toJSON(){let e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return e==="ascii"?this.onAsciiEncoding():K.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${K.Convert.ToHex(this.valueBlock.valueBeforeDecodeView)}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;let t=this.toBER(),n=e.toBER();return rc(t,n)}};ge.NAME="BaseBlock";function ac(r){if(r instanceof k.Constructed)for(let e of r.valueBlock.value)ac(e)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var Fn=class extends ge{constructor({value:e=Br,...t}={},n){super(t,n),e&&this.fromString(e)}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}fromBER(e,t,n){let s=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),s)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};Fn.NAME="BaseStringBlock";var qn=class extends gt(we){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};qn.NAME="PrimitiveValueBlock";var cc,$n=class extends ge{constructor(e={}){super(e,qn),this.idBlock.isConstructed=!1}};cc=$n;k.Primitive=cc;$n.NAME="PRIMITIVE";function Wh(r,e){if(r instanceof e)return r;let t=new e;return t.idBlock=r.idBlock,t.lenBlock=r.lenBlock,t.warnings=r.warnings,t.valueBeforeDecodeView=r.valueBeforeDecodeView,t}function Bs(r,e=0,t=r.length){let n=e,s=new ge({},we),i=new ft;if(!pt(i,r,e,t))return s.error=i.error,{offset:-1,result:s};if(!r.subarray(e,e+t).length)return s.error="Zero buffer length",{offset:-1,result:s};let a=s.idBlock.fromBER(r,e,t);if(s.idBlock.warnings.length&&s.warnings.concat(s.idBlock.warnings),a===-1)return s.error=s.idBlock.error,{offset:-1,result:s};if(e=a,t-=s.idBlock.blockLength,a=s.lenBlock.fromBER(r,e,t),s.lenBlock.warnings.length&&s.warnings.concat(s.lenBlock.warnings),a===-1)return s.error=s.lenBlock.error,{offset:-1,result:s};if(e=a,t-=s.lenBlock.blockLength,!s.idBlock.isConstructed&&s.lenBlock.isIndefiniteForm)return s.error="Indefinite length form used for primitive encoding form",{offset:-1,result:s};let c=ge;switch(s.idBlock.tagClass){case 1:if(s.idBlock.tagNumber>=37&&s.idBlock.isHexOnly===!1)return s.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:s};switch(s.idBlock.tagNumber){case 0:if(s.idBlock.isConstructed&&s.lenBlock.length>0)return s.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:s};c=k.EndOfContent;break;case 1:c=k.Boolean;break;case 2:c=k.Integer;break;case 3:c=k.BitString;break;case 4:c=k.OctetString;break;case 5:c=k.Null;break;case 6:c=k.ObjectIdentifier;break;case 10:c=k.Enumerated;break;case 12:c=k.Utf8String;break;case 13:c=k.RelativeObjectIdentifier;break;case 14:c=k.TIME;break;case 15:return s.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:s};case 16:c=k.Sequence;break;case 17:c=k.Set;break;case 18:c=k.NumericString;break;case 19:c=k.PrintableString;break;case 20:c=k.TeletexString;break;case 21:c=k.VideotexString;break;case 22:c=k.IA5String;break;case 23:c=k.UTCTime;break;case 24:c=k.GeneralizedTime;break;case 25:c=k.GraphicString;break;case 26:c=k.VisibleString;break;case 27:c=k.GeneralString;break;case 28:c=k.UniversalString;break;case 29:c=k.CharacterString;break;case 30:c=k.BmpString;break;case 31:c=k.DATE;break;case 32:c=k.TimeOfDay;break;case 33:c=k.DateTime;break;case 34:c=k.Duration;break;default:{let f=s.idBlock.isConstructed?new k.Constructed:new k.Primitive;f.idBlock=s.idBlock,f.lenBlock=s.lenBlock,f.warnings=s.warnings,s=f}}break;case 2:case 3:case 4:default:c=s.idBlock.isConstructed?k.Constructed:k.Primitive}return s=Wh(s,c),a=s.fromBER(r,e,s.lenBlock.isIndefiniteForm?t:s.lenBlock.length),s.valueBeforeDecodeView=r.subarray(n,n+s.blockLength),{offset:a,result:s}}function Ar(r){if(!r.byteLength){let e=new ge({},we);return e.error="Input buffer has zero length",{offset:-1,result:e}}return Bs(K.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function Yh(r,e){return r?1:e}var Xe=class extends we{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let s=K.BufferSourceConverter.toUint8Array(e);if(!pt(this,s,t,n))return-1;if(this.valueBeforeDecodeView=s.subarray(t,t+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let i=t;for(;Yh(this.isIndefiniteForm,n)>0;){let o=Bs(s,i,n);if(o.offset===-1)return this.error=o.result.error,this.warnings.concat(o.result.warnings),-1;if(i=o.offset,this.blockLength+=o.result.blockLength,n-=o.result.blockLength,this.value.push(o.result),this.isIndefiniteForm&&o.result.constructor.NAME===Yr)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===Yr?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(e,t){let n=t||new Wr;for(let s=0;s<this.value.length;s++)this.value[s].toBER(e,n);return t?ze:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};Xe.NAME="ConstructedValueBlock";var lc,_t=class extends ge{constructor(e={}){super(e,Xe),this.idBlock.isConstructed=!0}fromBER(e,t,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let s=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),s)}onAsciiEncoding(){let e=[];for(let n of this.valueBlock.value)e.push(n.toString("ascii").split(`
|
|
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} :`}};lc=_t;k.Constructed=lc;_t.NAME="CONSTRUCTED";var zn=class extends we{fromBER(e,t,n){return t}toBER(e){return ze}};zn.override="EndOfContentValueBlock";var uc,Gn=class extends ge{constructor(e={}){super(e,zn),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};uc=Gn;k.EndOfContent=uc;Gn.NAME=Yr;var fc,Lt=class extends ge{constructor(e={}){super(e,we),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,t,n){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=n,t+n>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+n}toBER(e,t){let n=new ArrayBuffer(2);if(!e){let s=new Uint8Array(n);s[0]=5,s[1]=0}return t&&t.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};fc=Lt;k.Null=fc;Lt.NAME="NULL";var jn=class extends gt(we){constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=K.BufferSourceConverter.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}get value(){for(let e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}fromBER(e,t,n){let s=K.BufferSourceConverter.toUint8Array(e);return pt(this,s,t,n)?(this.valueHexView=s.subarray(t,t+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,Zi.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};jn.NAME="BooleanValueBlock";var hc,Wn=class extends ge{constructor(e={}){super(e,jn),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};hc=Wn;k.Boolean=hc;Wn.NAME="BOOLEAN";var Yn=class extends gt(Xe){constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,n){let s=0;if(this.isConstructed){if(this.isHexOnly=!1,s=Xe.prototype.fromBER.call(this,e,t,n),s===-1)return s;for(let i=0;i<this.value.length;i++){let o=this.value[i].constructor.NAME;if(o===Yr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(o!==ic)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,s=super.fromBER(e,t,n),this.blockLength=n;return s}toBER(e,t){return this.isConstructed?Xe.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};Yn.NAME="OctetStringValueBlock";var dc,ht=class r extends ge{constructor({idBlock:e={},lenBlock:t={},...n}={}){var s,i;(s=n.isConstructed)!==null&&s!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},Yn),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,n){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,n===0)return this.idBlock.error.length===0&&(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length===0&&(this.blockLength+=this.lenBlock.blockLength),t;if(!this.valueBlock.isConstructed){let i=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+n);try{if(i.byteLength){let o=Bs(i,0,i.byteLength);o.offset!==-1&&o.offset===n&&(this.valueBlock.value=[o.result])}}catch{}}return super.fromBER(e,t,n)}onAsciiEncoding(){return this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length?_t.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${K.Convert.ToHex(this.valueBlock.valueHexView)}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let e=[];for(let t of this.valueBlock.value)t instanceof r&&e.push(t.valueBlock.valueHexView);return K.BufferSourceConverter.concat(e)}};dc=ht;k.OctetString=dc;ht.NAME=ic;var Zn=class extends gt(Xe){constructor({unusedBits:e=0,isConstructed:t=!1,...n}={}){super(n),this.unusedBits=e,this.isConstructed=t,this.blockLength=this.valueHexView.byteLength}fromBER(e,t,n){if(!n)return t;let s=-1;if(this.isConstructed){if(s=Xe.prototype.fromBER.call(this,e,t,n),s===-1)return s;for(let a of this.value){let c=a.constructor.NAME;if(c===Yr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==oc)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let f=a.valueBlock;if(this.unusedBits>0&&f.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=f.unusedBits}return s}let i=K.BufferSourceConverter.toUint8Array(e);if(!pt(this,i,t,n))return-1;let o=i.subarray(t,t+n);if(this.unusedBits=o[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let a=o.subarray(1);try{if(a.byteLength){let c=Bs(a,0,a.byteLength);c.offset!==-1&&c.offset===n-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=o.subarray(1),this.blockLength=o.length,t+n}toBER(e,t){if(this.isConstructed)return Xe.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return ze;let n=new Uint8Array(this.valueHexView.length+1);return n[0]=this.unusedBits,n.set(this.valueHexView,1),n.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}};Zn.NAME="BitStringValueBlock";var pc,Er=class extends ge{constructor({idBlock:e={},lenBlock:t={},...n}={}){var s,i;(s=n.isConstructed)!==null&&s!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},Zn),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,t,n){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,t,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return _t.prototype.onAsciiEncoding.call(this);{let e=[],t=this.valueBlock.valueHexView;for(let s of t)e.push(s.toString(2).padStart(8,"0"));let n=e.join("");return`${this.constructor.NAME} : ${n.substring(0,n.length-this.valueBlock.unusedBits)}`}}};pc=Er;k.BitString=pc;Er.NAME=oc;var gc;function Zh(r,e){let t=new Uint8Array([0]),n=new Uint8Array(r),s=new Uint8Array(e),i=n.slice(0),o=i.length-1,a=s.slice(0),c=a.length-1,f=0,u=c<o?o:c,l=0;for(let h=u;h>=0;h--,l++){switch(!0){case l<a.length:f=i[o-l]+a[c-l]+t[0];break;default:f=i[o-l]+t[0]}switch(t[0]=f/10,!0){case l>=i.length:i=On(new Uint8Array([f%10]),i);break;default:i[o-l]=f%10}}return t[0]>0&&(i=On(t,i)),i}function sc(r){if(r>=jr.length)for(let e=jr.length;e<=r;e++){let t=new Uint8Array([0]),n=jr[e-1].slice(0);for(let s=n.length-1;s>=0;s--){let i=new Uint8Array([(n[s]<<1)+t[0]]);t[0]=i[0]/10,n[s]=i[0]%10}t[0]>0&&(n=On(t,n)),jr.push(n)}return jr[r]}function Jh(r,e){let t=0,n=new Uint8Array(r),s=new Uint8Array(e),i=n.slice(0),o=i.length-1,a=s.slice(0),c=a.length-1,f,u=0;for(let l=c;l>=0;l--,u++)switch(f=i[o-u]-a[c-u]-t,!0){case f<0:t=1,i[o-u]=f+10;break;default:t=0,i[o-u]=f}if(t>0)for(let l=o-c+1;l>=0;l--,u++)if(f=i[o-u]-t,f<0)t=1,i[o-u]=f+10;else{t=0,i[o-u]=f;break}return i.slice()}var Zr=class extends gt(we){constructor({value:e,...t}={}){super(t),this._valueDec=0,t.valueHex&&this.setValueHex(),e!==void 0&&(this.valueDec=e)}setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=Zi.call(this)))}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(tc(e))}get valueDec(){return this._valueDec}fromDER(e,t,n,s=0){let i=this.fromBER(e,t,n);if(i===-1)return i;let o=this.valueHexView;return o[0]===0&&o[1]&128?this.valueHexView=o.subarray(1):s!==0&&o.length<s&&(s-o.length>1&&(s=o.length+1),this.valueHexView=o.subarray(s-o.length)),i}toDER(e=!1){let t=this.valueHexView;switch(!0){case(t[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(t,1),this.valueHexView=n}break;case(t[0]===0&&(t[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,t,n){let s=super.fromBER(e,t,n);return s===-1||this.setValueHex(),s}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let e=this.valueHexView.length*8-1,t=new Uint8Array(this.valueHexView.length*8/3),n=0,s,i=this.valueHexView,o="",a=!1;for(let c=i.byteLength-1;c>=0;c--){s=i[c];for(let f=0;f<8;f++){if((s&1)===1)switch(n){case e:t=Jh(sc(n),t),o="-";break;default:t=Zh(t,sc(n))}n++,s>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(o+=nc.charAt(t[c]));return a===!1&&(o+=nc.charAt(0)),o}};gc=Zr;Zr.NAME="IntegerValueBlock";Object.defineProperty(gc.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var mc,re=class r extends ge{constructor(e={}){super(e,Zr),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Mn(),BigInt(this.valueBlock.toString())}static fromBigInt(e){Mn();let t=BigInt(e),n=new Wr,s=t.toString(16).replace(/^-/,""),i=new Uint8Array(K.Convert.FromHex(s));if(t<0){let a=new Uint8Array(i.length+(i[0]&128?1:0));a[0]|=128;let f=BigInt(`0x${K.Convert.ToHex(a)}`)+t,u=K.BufferSourceConverter.toUint8Array(K.Convert.FromHex(f.toString(16)));u[0]|=128,n.write(u)}else i[0]&128&&n.write(new Uint8Array([0])),n.write(i);return new r({valueHex:n.final()})}convertToDER(){let e=new r({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new r({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};mc=re;k.Integer=mc;re.NAME="INTEGER";var yc,Jn=class extends re{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};yc=Jn;k.Enumerated=yc;Jn.NAME="ENUMERATED";var Jr=class extends gt(we){constructor({valueDec:e=-1,isFirstSid:t=!1,...n}={}){super(n),this.valueDec=e,this.isFirstSid=t}fromBER(e,t,n){if(!n)return t;let s=K.BufferSourceConverter.toUint8Array(e);if(!pt(this,s,t,n))return-1;let i=s.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=i[a]&127,this.blockLength++,!!(i[a]&128));a++);let o=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)o[a]=this.valueHexView[a];return this.valueHexView=o,i[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Jt(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){Mn();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;let n=new Uint8Array(t.length/7);for(let s=0;s<n.length;s++)n[s]=parseInt(t.slice(s*7,s*7+7),2)+(s+1<n.length?128:0);this.fromBER(n.buffer,0,n.length)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let s=this.valueHexView,i=new Uint8Array(this.blockLength);for(let o=0;o<this.blockLength-1;o++)i[o]=s[o]|128;return i[this.blockLength-1]=s[this.blockLength-1],i.buffer}let t=Tt(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",ze;let n=new Uint8Array(t.byteLength);if(!e){let s=new Uint8Array(t),i=t.byteLength-1;for(let o=0;o<i;o++)n[o]=s[o]|128;n[i]=s[i]}return n}toString(){let e="";if(this.isHexOnly)e=K.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let t=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",t-=40):(e="2.",t-=80),e+=t.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};Jr.NAME="sidBlock";var Xn=class extends we{constructor({value:e=Br,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let s=t;for(;n>0;){let i=new Jr;if(s=i.fromBER(e,s,n),s===-1)return this.blockLength=0,this.error=i.error,s;this.value.length===0&&(i.isFirstSid=!0),this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return s}toBER(e){let t=[];for(let n=0;n<this.value.length;n++){let s=this.value[n].toBER(e);if(s.byteLength===0)return this.error=this.value[n].error,ze;t.push(s)}return Ji(t)}fromString(e){this.value=[];let t=0,n=0,s="",i=!1;do if(n=e.indexOf(".",t),n===-1?s=e.substring(t):s=e.substring(t,n),t=n+1,i){let o=this.value[0],a=0;switch(o.valueDec){case 0:break;case 1:a=40;break;case 2:a=80;break;default:this.value=[];return}let c=parseInt(s,10);if(isNaN(c))return;o.valueDec=c+a,i=!1}else{let o=new Jr;if(s>Number.MAX_SAFE_INTEGER){Mn();let a=BigInt(s);o.valueBigInt=a}else if(o.valueDec=parseInt(s,10),isNaN(o.valueDec))return;this.value.length||(o.isFirstSid=!0,i=!0),this.value.push(o)}while(n!==-1)}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let s=this.value[n].toString();n!==0&&(e=`${e}.`),t?(s=`{${s}}`,this.value[n].isFirstSid?e=`2.{${s} - 80}`:e+=s):e+=s}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};Xn.NAME="ObjectIdentifierValueBlock";var bc,$e=class extends ge{constructor(e={}){super(e,Xn),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};bc=$e;k.ObjectIdentifier=bc;$e.NAME="OBJECT IDENTIFIER";var Xr=class extends gt(ft){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let s=K.BufferSourceConverter.toUint8Array(e);if(!pt(this,s,t,n))return-1;let i=s.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=i[a]&127,this.blockLength++,!!(i[a]&128));a++);let o=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)o[a]=this.valueHexView[a];return this.valueHexView=o,i[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Jt(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let s=this.valueHexView,i=new Uint8Array(this.blockLength);for(let o=0;o<this.blockLength-1;o++)i[o]=s[o]|128;return i[this.blockLength-1]=s[this.blockLength-1],i.buffer}let t=Tt(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",ze;let n=new Uint8Array(t.byteLength);if(!e){let s=new Uint8Array(t),i=t.byteLength-1;for(let o=0;o<i;o++)n[o]=s[o]|128;n[i]=s[i]}return n.buffer}toString(){let e="";return this.isHexOnly?e=K.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};Xr.NAME="relativeSidBlock";var Qn=class extends we{constructor({value:e=Br,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let s=t;for(;n>0;){let i=new Xr;if(s=i.fromBER(e,s,n),s===-1)return this.blockLength=0,this.error=i.error,s;this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return s}toBER(e,t){let n=[];for(let s=0;s<this.value.length;s++){let i=this.value[s].toBER(e);if(i.byteLength===0)return this.error=this.value[s].error,ze;n.push(i)}return Ji(n)}fromString(e){this.value=[];let t=0,n=0,s="";do{n=e.indexOf(".",t),n===-1?s=e.substring(t):s=e.substring(t,n),t=n+1;let i=new Xr;if(i.valueDec=parseInt(s,10),isNaN(i.valueDec))return!0;this.value.push(i)}while(n!==-1);return!0}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let s=this.value[n].toString();n!==0&&(e=`${e}.`),t&&(s=`{${s}}`),e+=s}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};Qn.NAME="RelativeObjectIdentifierValueBlock";var wc,es=class extends ge{constructor(e={}){super(e,Qn),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};wc=es;k.RelativeObjectIdentifier=wc;es.NAME="RelativeObjectIdentifier";var xc,fe=class extends _t{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};xc=fe;k.Sequence=xc;fe.NAME="SEQUENCE";var vc,ts=class extends _t{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};vc=ts;k.Set=vc;ts.NAME="SET";var rs=class extends gt(we){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=Br}toJSON(){return{...super.toJSON(),value:this.value}}};rs.NAME="StringValueBlock";var ns=class extends rs{};ns.NAME="SimpleStringValueBlock";var Ie=class extends Fn{constructor({...e}={}){super(e,ns)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,K.BufferSourceConverter.toUint8Array(e))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t);for(let s=0;s<t;s++)n[s]=e.charCodeAt(s);this.valueBlock.value=e}};Ie.NAME="SIMPLE STRING";var ss=class extends Ie{fromBuffer(e){this.valueBlock.valueHexView=K.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=K.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=K.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(K.Convert.FromUtf8String(e)),this.valueBlock.value=e}};ss.NAME="Utf8StringValueBlock";var Ec,dt=class extends ss{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};Ec=dt;k.Utf8String=Ec;dt.NAME="UTF8String";var is=class extends Ie{fromBuffer(e){this.valueBlock.value=K.Convert.ToUtf16String(e),this.valueBlock.valueHexView=K.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(K.Convert.FromUtf16String(e))}};is.NAME="BmpStringValueBlock";var Bc,os=class extends is{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};Bc=os;k.BmpString=Bc;os.NAME="BMPString";var as=class extends Ie{fromBuffer(e){let t=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),n=new Uint8Array(t);for(let s=0;s<n.length;s+=4)n[s]=n[s+3],n[s+1]=n[s+2],n[s+2]=0,n[s+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(t))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t*4);for(let s=0;s<t;s++){let i=Tt(e.charCodeAt(s),8),o=new Uint8Array(i);if(o.length>4)continue;let a=4-o.length;for(let c=o.length-1;c>=0;c--)n[s*4+c+a]=o[c]}this.valueBlock.value=e}};as.NAME="UniversalStringValueBlock";var Ac,cs=class extends as{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};Ac=cs;k.UniversalString=Ac;cs.NAME="UniversalString";var kc,ls=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};kc=ls;k.NumericString=kc;ls.NAME="NumericString";var Sc,us=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};Sc=us;k.PrintableString=Sc;us.NAME="PrintableString";var Ic,fs=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};Ic=fs;k.TeletexString=Ic;fs.NAME="TeletexString";var Rc,hs=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};Rc=hs;k.VideotexString=Rc;hs.NAME="VideotexString";var Nc,ds=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};Nc=ds;k.IA5String=Nc;ds.NAME="IA5String";var Tc,ps=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};Tc=ps;k.GraphicString=Tc;ps.NAME="GraphicString";var _c,Qr=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};_c=Qr;k.VisibleString=_c;Qr.NAME="VisibleString";var Lc,gs=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};Lc=gs;k.GeneralString=Lc;gs.NAME="GeneralString";var Cc,ms=class extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};Cc=ms;k.CharacterString=Cc;ms.NAME="CharacterString";var Uc,en=class extends Qr{constructor({value:e,valueDate:t,...n}={}){if(super(n),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let s=0;s<e.length;s++)this.valueBlock.valueHexView[s]=e.charCodeAt(s)}t&&(this.fromDate(t),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,K.BufferSourceConverter.toUint8Array(e)))}toBuffer(){let e=this.toString(),t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let s=0;s<e.length;s++)n[s]=e.charCodeAt(s);return t}fromDate(e){this.year=e.getUTCFullYear(),this.month=e.getUTCMonth()+1,this.day=e.getUTCDate(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(e){let n=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(e);if(n===null){this.error="Wrong input string for conversion";return}let s=parseInt(n[1],10);s>=50?this.year=1900+s:this.year=2e3+s,this.month=parseInt(n[2],10),this.day=parseInt(n[3],10),this.hour=parseInt(n[4],10),this.minute=parseInt(n[5],10),this.second=parseInt(n[6],10)}toString(e="iso"){if(e==="iso"){let t=new Array(7);return t[0]=Ue(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=Ue(this.month,2),t[2]=Ue(this.day,2),t[3]=Ue(this.hour,2),t[4]=Ue(this.minute,2),t[5]=Ue(this.second,2),t[6]="Z",t.join("")}return super.toString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}};Uc=en;k.UTCTime=Uc;en.NAME="UTCTime";var Pc,ys=class extends en{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond))}fromString(e){let t=!1,n="",s="",i=0,o,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),t=!0;else{let l=new Number(e[e.length-1]);if(isNaN(l.valueOf()))throw new Error("Wrong input string for conversion");n=e}if(t){if(n.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(n.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let l=1,h=n.indexOf("+"),m="";if(h===-1&&(h=n.indexOf("-"),l=-1),h!==-1){if(m=n.substring(h+1),n=n.substring(0,h),m.length!==2&&m.length!==4)throw new Error("Wrong input string for conversion");let x=parseInt(m.substring(0,2),10);if(isNaN(x.valueOf()))throw new Error("Wrong input string for conversion");if(a=l*x,m.length===4){if(x=parseInt(m.substring(2,4),10),isNaN(x.valueOf()))throw new Error("Wrong input string for conversion");c=l*x}}}let f=n.indexOf(".");if(f===-1&&(f=n.indexOf(",")),f!==-1){let l=new Number(`0${n.substring(f)}`);if(isNaN(l.valueOf()))throw new Error("Wrong input string for conversion");i=l.valueOf(),s=n.substring(0,f)}else s=n;switch(!0){case s.length===8:if(o=/(\d{4})(\d{2})(\d{2})/ig,f!==-1)throw new Error("Wrong input string for conversion");break;case s.length===10:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let l=60*i;this.minute=Math.floor(l),l=60*(l-this.minute),this.second=Math.floor(l),l=1e3*(l-this.second),this.millisecond=Math.floor(l)}break;case s.length===12:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let l=60*i;this.second=Math.floor(l),l=1e3*(l-this.second),this.millisecond=Math.floor(l)}break;case s.length===14:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let l=1e3*i;this.millisecond=Math.floor(l)}break;default:throw new Error("Wrong input string for conversion")}let u=o.exec(s);if(u===null)throw new Error("Wrong input string for conversion");for(let l=1;l<u.length;l++)switch(l){case 1:this.year=parseInt(u[l],10);break;case 2:this.month=parseInt(u[l],10);break;case 3:this.day=parseInt(u[l],10);break;case 4:this.hour=parseInt(u[l],10)+a;break;case 5:this.minute=parseInt(u[l],10)+c;break;case 6:this.second=parseInt(u[l],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){let l=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=l.getUTCFullYear(),this.month=l.getUTCMonth(),this.day=l.getUTCDay(),this.hour=l.getUTCHours(),this.minute=l.getUTCMinutes(),this.second=l.getUTCSeconds(),this.millisecond=l.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let t=[];return t.push(Ue(this.year,4)),t.push(Ue(this.month,2)),t.push(Ue(this.day,2)),t.push(Ue(this.hour,2)),t.push(Ue(this.minute,2)),t.push(Ue(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(Ue(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};Pc=ys;k.GeneralizedTime=Pc;ys.NAME="GeneralizedTime";var Dc,bs=class extends dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};Dc=bs;k.DATE=Dc;bs.NAME="DATE";var Vc,ws=class extends dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};Vc=ws;k.TimeOfDay=Vc;ws.NAME="TimeOfDay";var Oc,xs=class extends dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};Oc=xs;k.DateTime=Oc;xs.NAME="DateTime";var Mc,vs=class extends dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};Mc=vs;k.Duration=Mc;vs.NAME="Duration";var Hc,Es=class extends dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};Hc=Es;k.TIME=Hc;Es.NAME="TIME";function Qh(r){let{result:e}=Ar(r),t=e.valueBlock.value;return{n:H(Qe(t[1].toBigInt()),"base64url"),e:H(Qe(t[2].toBigInt()),"base64url"),d:H(Qe(t[3].toBigInt()),"base64url"),p:H(Qe(t[4].toBigInt()),"base64url"),q:H(Qe(t[5].toBigInt()),"base64url"),dp:H(Qe(t[6].toBigInt()),"base64url"),dq:H(Qe(t[7].toBigInt()),"base64url"),qi:H(Qe(t[8].toBigInt()),"base64url"),kty:"RSA",alg:"RS256"}}function ed(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new R("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new fe({value:[new re({value:0}),re.fromBigInt(et($(r.n,"base64url"))),re.fromBigInt(et($(r.e,"base64url"))),re.fromBigInt(et($(r.d,"base64url"))),re.fromBigInt(et($(r.p,"base64url"))),re.fromBigInt(et($(r.q,"base64url"))),re.fromBigInt(et($(r.dp,"base64url"))),re.fromBigInt(et($(r.dq,"base64url"))),re.fromBigInt(et($(r.qi,"base64url")))]}).toBER();return new Uint8Array(t,0,t.byteLength)}function td(r){let{result:e}=Ar(r),t=e.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:H(Qe(t[0].toBigInt()),"base64url"),e:H(Qe(t[1].toBigInt()),"base64url")}}function rd(r){if(r.n==null||r.e==null)throw new R("JWK was missing components","ERR_INVALID_PARAMETERS");let t=new fe({value:[new fe({value:[new $e({value:"1.2.840.113549.1.1.1"}),new Lt]}),new Er({valueHex:new fe({value:[re.fromBigInt(et($(r.n,"base64url"))),re.fromBigInt(et($(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(t,0,t.byteLength)}function Qe(r){let e=r.toString(16);e.length%2>0&&(e=`0${e}`);let t=e.length/2,n=new Uint8Array(t),s=0,i=0;for(;s<t;)n[s]=parseInt(e.slice(i,i+2),16),s+=1,i+=2;return n}function et(r){let e=[];return r.forEach(function(t){let n=t.toString(16);n.length%2>0&&(n=`0${n}`),e.push(n)}),BigInt("0x"+e.join(""))}var nd=16,Qi=32,eo=1e4;async function sd(r,e){let t=Be.get(),s=new fe({value:[new re({value:0}),new fe({value:[new $e({value:"1.2.840.113549.1.1.1"}),new Lt]}),new ht({valueHex:r.marshal()})]}).toBER(),i=new Uint8Array(s,0,s.byteLength),o=Zt(nd),a=await Wi(Mr,e,o,{c:eo,dkLen:Qi}),c=Zt(16),f=await t.subtle.importKey("raw",a,"AES-CBC",!1,["encrypt"]),u=await t.subtle.encrypt({name:"AES-CBC",iv:c},f,i),l=new fe({value:[new ht({valueHex:o}),new re({value:eo}),new re({value:Qi}),new fe({value:[new $e({value:"1.2.840.113549.2.11"}),new Lt]})]}),h=new fe({value:[new $e({value:"1.2.840.113549.1.5.13"}),new fe({value:[new fe({value:[new $e({value:"1.2.840.113549.1.5.12"}),l]}),new fe({value:[new $e({value:"2.16.840.1.101.3.4.1.42"}),new ht({valueHex:c})]})]})]}),x=new fe({value:[h,new ht({valueHex:u})]}).toBER(),y=new Uint8Array(x,0,x.byteLength);return["-----BEGIN ENCRYPTED PRIVATE KEY-----",...H(y,"base64pad").split(/(.{64})/).filter(Boolean),"-----END ENCRYPTED PRIVATE KEY-----"].join(`
|
|
7
|
-
`)}async function id(r,e){let t=Be.get(),n;if(r.includes("-----BEGIN ENCRYPTED PRIVATE KEY-----")){let s=$(r.replace("-----BEGIN ENCRYPTED PRIVATE KEY-----","").replace("-----END ENCRYPTED PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:i}=Ar(s),{iv:o,salt:a,iterations:c,keySize:f,cipherText:u}=od(i),l=await Wi(Mr,e,a,{c,dkLen:f}),h=await t.subtle.importKey("raw",l,"AES-CBC",!1,["decrypt"]),m=tn(await t.subtle.decrypt({name:"AES-CBC",iv:o},h,u)),{result:x}=Ar(m);n=Kc(x)}else if(r.includes("-----BEGIN PRIVATE KEY-----")){let s=$(r.replace("-----BEGIN PRIVATE KEY-----","").replace("-----END PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:i}=Ar(s);n=Kc(i)}else throw new R("Could not parse private key from PEM data","ERR_INVALID_PARAMETERS");return to(n)}function od(r){let e=r.valueBlock.value[0];if(e.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.13")throw new R("Only pkcs5PBES2 encrypted private keys are supported","ERR_INVALID_PARAMS");let n=e.valueBlock.value[1].valueBlock.value[0];if(n.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.12")throw new R("Only pkcs5PBKDF2 key derivation functions are supported","ERR_INVALID_PARAMS");let i=n.valueBlock.value[1],o=tn(i.valueBlock.value[0].getValue()),a=eo,c=Qi;if(i.valueBlock.value.length===3)a=Number(i.valueBlock.value[1].toBigInt()),c=Number(i.valueBlock.value[2].toBigInt());else if(i.valueBlock.value.length===2)throw new R("Could not derive key size and iterations from PEM file - please use @libp2p/rsa to re-import your key","ERR_INVALID_PARAMS");let f=e.valueBlock.value[1].valueBlock.value[1],u=f.valueBlock.value[0].toString();if(u!=="OBJECT IDENTIFIER : 1.2.840.113549.3.7"){if(u!=="OBJECT IDENTIFIER : 1.3.14.3.2.7"){if(u!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.2"){if(u!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.22"){if(u!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.42")throw new R("Only AES-CBC encryption schemes are supported","ERR_INVALID_PARAMS")}}}}let l=tn(f.valueBlock.value[1].getValue());return{cipherText:tn(r.valueBlock.value[1].getValue()),salt:o,iterations:a,keySize:c,iv:l}}function Kc(r){return tn(r.valueBlock.value[2].getValue())}function tn(r){return new Uint8Array(r,0,r.byteLength)}async function Fc(r){let e=await Be.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),t=await zc(e);return{privateKey:t[0],publicKey:t[1]}}async function ro(r){let t=[await Be.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),await ad(r)],n=await zc({privateKey:t[0],publicKey:t[1]});return{privateKey:n[0],publicKey:n[1]}}async function qc(r,e){let t=await Be.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await Be.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},t,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(n,0,n.byteLength)}async function $c(r,e,t){let n=await Be.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return Be.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,e,t instanceof Uint8Array?t:t.subarray())}async function zc(r){if(r.privateKey==null||r.publicKey==null)throw new R("Private and public key are required","ERR_INVALID_PARAMETERS");return Promise.all([Be.get().subtle.exportKey("jwk",r.privateKey),Be.get().subtle.exportKey("jwk",r.publicKey)])}async function ad(r){return Be.get().subtle.importKey("jwk",{kty:r.kty,n:r.n,e:r.e},{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])}function As(r){if(r.kty!=="RSA")throw new R("invalid key type","ERR_INVALID_KEY_TYPE");if(r.n==null)throw new R("invalid key modulus","ERR_INVALID_KEY_MODULUS");return $(r.n,"base64url").length*8}var nn=8192,rn=class{_key;constructor(e){this._key=e}verify(e,t){return $c(this._key,t,e)}marshal(){return Ct.jwkToPkix(this._key)}get bytes(){return Ze.encode({Type:X.RSA,Data:this.marshal()}).subarray()}equals(e){return ee(this.bytes,e.bytes)}hash(){let e=pe.digest(this.bytes);return Ve(e)?e.then(({bytes:t})=>t):e.bytes}},kr=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t}genSecret(){return Zt(16)}sign(e){return qc(this._key,e)}get public(){if(this._publicKey==null)throw new R("public key not provided","ERR_PUBKEY_NOT_PROVIDED");return new rn(this._publicKey)}marshal(){return Ct.jwkToPkcs1(this._key)}get bytes(){return Je.encode({Type:X.RSA,Data:this.marshal()}).subarray()}equals(e){return ee(this.bytes,e.bytes)}hash(){let e=pe.digest(this.bytes);return Ve(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return H(e,"base58btc")}async export(e,t="pkcs-8"){if(t==="pkcs-8")return Ct.exportToPem(this,e);if(t==="libp2p-key")return br(this.bytes,e);throw new R(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};async function to(r){let e=Ct.pkcs1ToJwk(r);if(As(e)>nn)throw new R("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await ro(e);return new kr(t.privateKey,t.publicKey)}function ld(r){let e=Ct.pkixToJwk(r);if(As(e)>nn)throw new R("key size is too large","ERR_KEY_SIZE_TOO_LARGE");return new rn(e)}async function ud(r){if(As(r)>nn)throw new R("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await ro(r);return new kr(e.privateKey,e.publicKey)}async function fd(r){if(r>nn)throw new R("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await Fc(r);return new kr(e.privateKey,e.publicKey)}var co={};ue(co,{Secp256k1PrivateKey:()=>on,Secp256k1PublicKey:()=>sn,generateKeyPair:()=>Ad,unmarshalSecp256k1PrivateKey:()=>Ed,unmarshalSecp256k1PublicKey:()=>Bd});var hd=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Ut=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Pt=new Uint32Array(64),so=class extends pr{constructor(){super(64,32,8,!1),this.A=Ut[0]|0,this.B=Ut[1]|0,this.C=Ut[2]|0,this.D=Ut[3]|0,this.E=Ut[4]|0,this.F=Ut[5]|0,this.G=Ut[6]|0,this.H=Ut[7]|0}get(){let{A:e,B:t,C:n,D:s,E:i,F:o,G:a,H:c}=this;return[e,t,n,s,i,o,a,c]}set(e,t,n,s,i,o,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=s|0,this.E=i|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,t){for(let l=0;l<16;l++,t+=4)Pt[l]=e.getUint32(t,!1);for(let l=16;l<64;l++){let h=Pt[l-15],m=Pt[l-2],x=He(h,7)^He(h,18)^h>>>3,y=He(m,17)^He(m,19)^m>>>10;Pt[l]=y+Pt[l-7]+x+Pt[l-16]|0}let{A:n,B:s,C:i,D:o,E:a,F:c,G:f,H:u}=this;for(let l=0;l<64;l++){let h=He(a,6)^He(a,11)^He(a,25),m=u+h+ka(a,c,f)+hd[l]+Pt[l]|0,y=(He(n,2)^He(n,13)^He(n,22))+Sa(n,s,i)|0;u=f,f=c,c=a,a=o+m|0,o=i,i=s,s=n,n=m+y|0}n=n+this.A|0,s=s+this.B|0,i=i+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,s,i,o,a,c,f,u)}roundClean(){Pt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Gc=En(()=>new so);function jc(r){r.lowS!==void 0&&Ke("lowS",r.lowS),r.prehash!==void 0&&Ke("prehash",r.prehash)}function dd(r){let e=Fr(r);We(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:t,Fp:n,a:s}=e;if(t){if(!n.eql(s,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof t!="object"||typeof t.beta!="bigint"||typeof t.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}var{bytesToNumberBE:pd,hexToBytes:gd}=kn,mt={Err:class extends Error{constructor(e=""){super(e)}},_tlv:{encode:(r,e)=>{let{Err:t}=mt;if(r<0||r>256)throw new t("tlv.encode: wrong tag");if(e.length&1)throw new t("tlv.encode: unpadded data");let n=e.length/2,s=Kt(n);if(s.length/2&128)throw new t("tlv.encode: long form length too big");let i=n>127?Kt(s.length/2|128):"";return`${Kt(r)}${i}${s}${e}`},decode(r,e){let{Err:t}=mt,n=0;if(r<0||r>256)throw new t("tlv.encode: wrong tag");if(e.length<2||e[n++]!==r)throw new t("tlv.decode: wrong tlv");let s=e[n++],i=!!(s&128),o=0;if(!i)o=s;else{let c=s&127;if(!c)throw new t("tlv.decode(long): indefinite length not supported");if(c>4)throw new t("tlv.decode(long): byte length is too big");let f=e.subarray(n,n+c);if(f.length!==c)throw new t("tlv.decode: length bytes not complete");if(f[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(let u of f)o=o<<8|u;if(n+=c,o<128)throw new t("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+o);if(a.length!==o)throw new t("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+o)}}},_int:{encode(r){let{Err:e}=mt;if(r<yt)throw new e("integer: negative integers are not allowed");let t=Kt(r);if(Number.parseInt(t[0],16)&8&&(t="00"+t),t.length&1)throw new e("unexpected assertion");return t},decode(r){let{Err:e}=mt;if(r[0]&128)throw new e("Invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new e("Invalid signature integer: unnecessary leading zero");return pd(r)}},toSig(r){let{Err:e,_int:t,_tlv:n}=mt,s=typeof r=="string"?gd(r):r;gr(s);let{v:i,l:o}=n.decode(48,s);if(o.length)throw new e("Invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:f,l:u}=n.decode(2,c);if(u.length)throw new e("Invalid signature: left bytes after parsing");return{r:t.decode(a),s:t.decode(f)}},hexFromSig(r){let{_tlv:e,_int:t}=mt,n=`${e.encode(2,t.encode(r.r))}${e.encode(2,t.encode(r.s))}`;return e.encode(48,n)}},yt=BigInt(0),he=BigInt(1),mm=BigInt(2),Wc=BigInt(3),ym=BigInt(4);function md(r){let e=dd(r),{Fp:t}=e,n=Rt(e.n,e.nBitLength),s=e.toBytes||((y,d,w)=>{let E=d.toAffine();return ct(Uint8Array.from([4]),t.toBytes(E.x),t.toBytes(E.y))}),i=e.fromBytes||(y=>{let d=y.subarray(1),w=t.fromBytes(d.subarray(0,t.BYTES)),E=t.fromBytes(d.subarray(t.BYTES,2*t.BYTES));return{x:w,y:E}});function o(y){let{a:d,b:w}=e,E=t.sqr(y),g=t.mul(E,y);return t.add(t.add(g,t.mul(y,d)),w)}if(!t.eql(t.sqr(e.Gy),o(e.Gx)))throw new Error("bad generator point: equation left != right");function a(y){return Hr(y,he,e.n)}function c(y){let{allowedPrivateKeyLengths:d,nByteLength:w,wrapPrivateKey:E,n:g}=e;if(d&&typeof y!="bigint"){if(kt(y)&&(y=ot(y)),typeof y!="string"||!d.includes(y.length))throw new Error("Invalid key");y=y.padStart(w*2,"0")}let B;try{B=typeof y=="bigint"?y:at(te("private key",y,w))}catch{throw new Error(`private key must be ${w} bytes, hex or bigint, not ${typeof y}`)}return E&&(B=j(B,g)),_e("private key",B,he,g),B}function f(y){if(!(y instanceof h))throw new Error("ProjectivePoint expected")}let u=$t((y,d)=>{let{px:w,py:E,pz:g}=y;if(t.eql(g,t.ONE))return{x:w,y:E};let B=y.is0();d==null&&(d=B?t.ONE:t.inv(g));let C=t.mul(w,d),L=t.mul(E,d),S=t.mul(g,d);if(B)return{x:t.ZERO,y:t.ZERO};if(!t.eql(S,t.ONE))throw new Error("invZ was invalid");return{x:C,y:L}}),l=$t(y=>{if(y.is0()){if(e.allowInfinityPoint&&!t.is0(y.py))return;throw new Error("bad point: ZERO")}let{x:d,y:w}=y.toAffine();if(!t.isValid(d)||!t.isValid(w))throw new Error("bad point: x or y not FE");let E=t.sqr(w),g=o(d);if(!t.eql(E,g))throw new Error("bad point: equation left != right");if(!y.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class h{constructor(d,w,E){if(this.px=d,this.py=w,this.pz=E,d==null||!t.isValid(d))throw new Error("x required");if(w==null||!t.isValid(w))throw new Error("y required");if(E==null||!t.isValid(E))throw new Error("z required");Object.freeze(this)}static fromAffine(d){let{x:w,y:E}=d||{};if(!d||!t.isValid(w)||!t.isValid(E))throw new Error("invalid affine point");if(d instanceof h)throw new Error("projective point not allowed");let g=B=>t.eql(B,t.ZERO);return g(w)&&g(E)?h.ZERO:new h(w,E,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){let w=t.invertBatch(d.map(E=>E.pz));return d.map((E,g)=>E.toAffine(w[g])).map(h.fromAffine)}static fromHex(d){let w=h.fromAffine(i(te("pointHex",d)));return w.assertValidity(),w}static fromPrivateKey(d){return h.BASE.multiply(c(d))}static msm(d,w){return Rn(h,n,d,w)}_setWindowSize(d){x.setWindowSize(this,d)}assertValidity(){l(this)}hasEvenY(){let{y:d}=this.toAffine();if(t.isOdd)return!t.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){f(d);let{px:w,py:E,pz:g}=this,{px:B,py:C,pz:L}=d,S=t.eql(t.mul(w,L),t.mul(B,g)),I=t.eql(t.mul(E,L),t.mul(C,g));return S&&I}negate(){return new h(this.px,t.neg(this.py),this.pz)}double(){let{a:d,b:w}=e,E=t.mul(w,Wc),{px:g,py:B,pz:C}=this,L=t.ZERO,S=t.ZERO,I=t.ZERO,_=t.mul(g,g),ne=t.mul(B,B),q=t.mul(C,C),V=t.mul(g,B);return V=t.add(V,V),I=t.mul(g,C),I=t.add(I,I),L=t.mul(d,I),S=t.mul(E,q),S=t.add(L,S),L=t.sub(ne,S),S=t.add(ne,S),S=t.mul(L,S),L=t.mul(V,L),I=t.mul(E,I),q=t.mul(d,q),V=t.sub(_,q),V=t.mul(d,V),V=t.add(V,I),I=t.add(_,_),_=t.add(I,_),_=t.add(_,q),_=t.mul(_,V),S=t.add(S,_),q=t.mul(B,C),q=t.add(q,q),_=t.mul(q,V),L=t.sub(L,_),I=t.mul(q,ne),I=t.add(I,I),I=t.add(I,I),new h(L,S,I)}add(d){f(d);let{px:w,py:E,pz:g}=this,{px:B,py:C,pz:L}=d,S=t.ZERO,I=t.ZERO,_=t.ZERO,ne=e.a,q=t.mul(e.b,Wc),V=t.mul(w,B),se=t.mul(E,C),A=t.mul(g,L),N=t.add(w,E),b=t.add(B,C);N=t.mul(N,b),b=t.add(V,se),N=t.sub(N,b),b=t.add(w,g);let p=t.add(B,L);return b=t.mul(b,p),p=t.add(V,A),b=t.sub(b,p),p=t.add(E,g),S=t.add(C,L),p=t.mul(p,S),S=t.add(se,A),p=t.sub(p,S),_=t.mul(ne,b),S=t.mul(q,A),_=t.add(S,_),S=t.sub(se,_),_=t.add(se,_),I=t.mul(S,_),se=t.add(V,V),se=t.add(se,V),A=t.mul(ne,A),b=t.mul(q,b),se=t.add(se,A),A=t.sub(V,A),A=t.mul(ne,A),b=t.add(b,A),V=t.mul(se,b),I=t.add(I,V),V=t.mul(p,b),S=t.mul(N,S),S=t.sub(S,V),V=t.mul(N,se),_=t.mul(p,_),_=t.add(_,V),new h(S,I,_)}subtract(d){return this.add(d.negate())}is0(){return this.equals(h.ZERO)}wNAF(d){return x.wNAFCached(this,d,h.normalizeZ)}multiplyUnsafe(d){_e("scalar",d,yt,e.n);let w=h.ZERO;if(d===yt)return w;if(d===he)return this;let{endo:E}=e;if(!E)return x.unsafeLadder(this,d);let{k1neg:g,k1:B,k2neg:C,k2:L}=E.splitScalar(d),S=w,I=w,_=this;for(;B>yt||L>yt;)B&he&&(S=S.add(_)),L&he&&(I=I.add(_)),_=_.double(),B>>=he,L>>=he;return g&&(S=S.negate()),C&&(I=I.negate()),I=new h(t.mul(I.px,E.beta),I.py,I.pz),S.add(I)}multiply(d){let{endo:w,n:E}=e;_e("scalar",d,he,E);let g,B;if(w){let{k1neg:C,k1:L,k2neg:S,k2:I}=w.splitScalar(d),{p:_,f:ne}=this.wNAF(L),{p:q,f:V}=this.wNAF(I);_=x.constTimeNegate(C,_),q=x.constTimeNegate(S,q),q=new h(t.mul(q.px,w.beta),q.py,q.pz),g=_.add(q),B=ne.add(V)}else{let{p:C,f:L}=this.wNAF(d);g=C,B=L}return h.normalizeZ([g,B])[0]}multiplyAndAddUnsafe(d,w,E){let g=h.BASE,B=(L,S)=>S===yt||S===he||!L.equals(g)?L.multiplyUnsafe(S):L.multiply(S),C=B(this,w).add(B(d,E));return C.is0()?void 0:C}toAffine(d){return u(this,d)}isTorsionFree(){let{h:d,isTorsionFree:w}=e;if(d===he)return!0;if(w)return w(h,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:d,clearCofactor:w}=e;return d===he?this:w?w(h,this):this.multiplyUnsafe(e.h)}toRawBytes(d=!0){return Ke("isCompressed",d),this.assertValidity(),s(h,this,d)}toHex(d=!0){return Ke("isCompressed",d),ot(this.toRawBytes(d))}}h.BASE=new h(e.Gx,e.Gy,t.ONE),h.ZERO=new h(t.ZERO,t.ONE,t.ZERO);let m=e.nBitLength,x=In(h,e.endo?Math.ceil(m/2):m);return{CURVE:e,ProjectivePoint:h,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:a}}function yd(r){let e=Fr(r);return We(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function Yc(r){let e=yd(r),{Fp:t,n}=e,s=t.BYTES+1,i=2*t.BYTES+1;function o(A){return j(A,n)}function a(A){return Sn(A,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:f,weierstrassEquation:u,isWithinCurveOrder:l}=md({...e,toBytes(A,N,b){let p=N.toAffine(),v=t.toBytes(p.x),T=ct;return Ke("isCompressed",b),b?T(Uint8Array.from([N.hasEvenY()?2:3]),v):T(Uint8Array.from([4]),v,t.toBytes(p.y))},fromBytes(A){let N=A.length,b=A[0],p=A.subarray(1);if(N===s&&(b===2||b===3)){let v=at(p);if(!Hr(v,he,t.ORDER))throw new Error("Point is not on curve");let T=u(v),U;try{U=t.sqrt(T)}catch(F){let M=F instanceof Error?": "+F.message:"";throw new Error("Point is not on curve"+M)}let P=(U&he)===he;return(b&1)===1!==P&&(U=t.neg(U)),{x:v,y:U}}else if(N===i&&b===4){let v=t.fromBytes(p.subarray(0,t.BYTES)),T=t.fromBytes(p.subarray(t.BYTES,2*t.BYTES));return{x:v,y:T}}else throw new Error(`Point of length ${N} was invalid. Expected ${s} compressed bytes or ${i} uncompressed bytes`)}}),h=A=>ot(It(A,e.nByteLength));function m(A){let N=n>>he;return A>N}function x(A){return m(A)?o(-A):A}let y=(A,N,b)=>at(A.slice(N,b));class d{constructor(N,b,p){this.r=N,this.s=b,this.recovery=p,this.assertValidity()}static fromCompact(N){let b=e.nByteLength;return N=te("compactSignature",N,b*2),new d(y(N,0,b),y(N,b,2*b))}static fromDER(N){let{r:b,s:p}=mt.toSig(te("DER",N));return new d(b,p)}assertValidity(){_e("r",this.r,he,n),_e("s",this.s,he,n)}addRecoveryBit(N){return new d(this.r,this.s,N)}recoverPublicKey(N){let{r:b,s:p,recovery:v}=this,T=L(te("msgHash",N));if(v==null||![0,1,2,3].includes(v))throw new Error("recovery id invalid");let U=v===2||v===3?b+e.n:b;if(U>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let P=v&1?"03":"02",O=c.fromHex(P+h(U)),F=a(U),M=o(-T*F),G=o(p*F),Y=c.BASE.multiplyAndAddUnsafe(O,M,G);if(!Y)throw new Error("point at infinify");return Y.assertValidity(),Y}hasHighS(){return m(this.s)}normalizeS(){return this.hasHighS()?new d(this.r,o(-this.s),this.recovery):this}toDERRawBytes(){return Ft(this.toDERHex())}toDERHex(){return mt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Ft(this.toCompactHex())}toCompactHex(){return h(this.r)+h(this.s)}}let w={isValidPrivateKey(A){try{return f(A),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let A=Ei(e.n);return Ua(e.randomBytes(A),e.n)},precompute(A=8,N=c.BASE){return N._setWindowSize(A),N.multiply(BigInt(3)),N}};function E(A,N=!0){return c.fromPrivateKey(A).toRawBytes(N)}function g(A){let N=kt(A),b=typeof A=="string",p=(N||b)&&A.length;return N?p===s||p===i:b?p===2*s||p===2*i:A instanceof c}function B(A,N,b=!0){if(g(A))throw new Error("first arg must be private key");if(!g(N))throw new Error("second arg must be public key");return c.fromHex(N).multiply(f(A)).toRawBytes(b)}let C=e.bits2int||function(A){let N=at(A),b=A.length*8-e.nBitLength;return b>0?N>>BigInt(b):N},L=e.bits2int_modN||function(A){return o(C(A))},S=Kr(e.nBitLength);function I(A){return _e(`num < 2^${e.nBitLength}`,A,yt,S),It(A,e.nByteLength)}function _(A,N,b=ne){if(["recovered","canonical"].some(le=>le in b))throw new Error("sign() legacy options not supported");let{hash:p,randomBytes:v}=e,{lowS:T,prehash:U,extraEntropy:P}=b;T==null&&(T=!0),A=te("msgHash",A),jc(b),U&&(A=te("prehashed msgHash",p(A)));let O=L(A),F=f(N),M=[I(F),I(O)];if(P!=null&&P!==!1){let le=P===!0?v(t.BYTES):P;M.push(te("extraEntropy",le))}let G=ct(...M),Y=O;function ce(le){let de=C(le);if(!l(de))return;let ve=a(de),ie=c.BASE.multiply(de).toAffine(),Ne=o(ie.x);if(Ne===yt)return;let tt=o(ve*o(Y+Ne*F));if(tt===yt)return;let Ur=(ie.x===Ne?0:2)|Number(ie.y&he),Pr=tt;return T&&m(tt)&&(Pr=x(tt),Ur^=1),new d(Ne,Pr,Ur)}return{seed:G,k2sig:ce}}let ne={lowS:e.lowS,prehash:!1},q={lowS:e.lowS,prehash:!1};function V(A,N,b=ne){let{seed:p,k2sig:v}=_(A,N,b),T=e;return bi(T.hash.outputLen,T.nByteLength,T.hmac)(p,v)}c.BASE._setWindowSize(8);function se(A,N,b,p=q){let v=A;if(N=te("msgHash",N),b=te("publicKey",b),"strict"in p)throw new Error("options.strict was renamed to lowS");jc(p);let{lowS:T,prehash:U}=p,P,O;try{if(typeof v=="string"||kt(v))try{P=d.fromDER(v)}catch(ie){if(!(ie instanceof mt.Err))throw ie;P=d.fromCompact(v)}else if(typeof v=="object"&&typeof v.r=="bigint"&&typeof v.s=="bigint"){let{r:ie,s:Ne}=v;P=new d(ie,Ne)}else throw new Error("PARSE");O=c.fromHex(b)}catch(ie){if(ie.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(T&&P.hasHighS())return!1;U&&(N=e.hash(N));let{r:F,s:M}=P,G=L(N),Y=a(M),ce=o(G*Y),le=o(F*Y),de=c.BASE.multiplyAndAddUnsafe(O,ce,le)?.toAffine();return de?o(de.x)===F:!1}return{CURVE:e,getPublicKey:E,getSharedSecret:B,sign:V,verify:se,ProjectivePoint:c,Signature:d,utils:w}}function bd(r){return{hash:r,hmac:(e,...t)=>Gr(r,e,ui(...t)),randomBytes:dr}}function Zc(r,e){let t=n=>Yc({...r,...bd(n)});return Object.freeze({...t(e),create:t})}var Qc=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Jc=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),wd=BigInt(1),io=BigInt(2),Xc=(r,e)=>(r+e/io)/e;function xd(r){let e=Qc,t=BigInt(3),n=BigInt(6),s=BigInt(11),i=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%e,u=f*f*r%e,l=J(u,t,e)*u%e,h=J(l,t,e)*u%e,m=J(h,io,e)*f%e,x=J(m,s,e)*m%e,y=J(x,i,e)*x%e,d=J(y,a,e)*y%e,w=J(d,c,e)*d%e,E=J(w,a,e)*y%e,g=J(E,t,e)*u%e,B=J(g,o,e)*x%e,C=J(B,n,e)*f%e,L=J(C,io,e);if(!oo.eql(oo.sqr(L),r))throw new Error("Cannot find square root");return L}var oo=Rt(Qc,void 0,void 0,{sqrt:xd}),Ge=Zc({a:BigInt(0),b:BigInt(7),Fp:oo,n:Jc,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=Jc,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-wd*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=t,o=BigInt("0x100000000000000000000000000000000"),a=Xc(i*r,e),c=Xc(-n*r,e),f=j(r-a*t-c*s,e),u=j(-a*n-c*i,e),l=f>o,h=u>o;if(l&&(f=e-f),h&&(u=e-u),f>o||u>o)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:l,k1:f,k2neg:h,k2:u}}}},Gc),Sm=BigInt(0);var Im=Ge.ProjectivePoint;function el(){return Ge.utils.randomPrivateKey()}function tl(r,e){let t=pe.digest(e instanceof Uint8Array?e:e.subarray());if(Ve(t))return t.then(({digest:n})=>Ge.sign(n,r).toDERRawBytes()).catch(n=>{throw new R(String(n),"ERR_INVALID_INPUT")});try{return Ge.sign(t.digest,r).toDERRawBytes()}catch(n){throw new R(String(n),"ERR_INVALID_INPUT")}}function rl(r,e,t){let n=pe.digest(t instanceof Uint8Array?t:t.subarray());if(Ve(n))return n.then(({digest:s})=>Ge.verify(e,s,r)).catch(s=>{throw new R(String(s),"ERR_INVALID_INPUT")});try{return Ge.verify(e,n.digest,r)}catch(s){throw new R(String(s),"ERR_INVALID_INPUT")}}function nl(r){return Ge.ProjectivePoint.fromHex(r).toRawBytes(!0)}function sl(r){try{Ge.getPublicKey(r,!0)}catch(e){throw new R(String(e),"ERR_INVALID_PRIVATE_KEY")}}function ao(r){try{Ge.ProjectivePoint.fromHex(r)}catch(e){throw new R(String(e),"ERR_INVALID_PUBLIC_KEY")}}function il(r){try{return Ge.getPublicKey(r,!0)}catch(e){throw new R(String(e),"ERR_INVALID_PRIVATE_KEY")}}var sn=class{_key;constructor(e){ao(e),this._key=e}verify(e,t){return rl(this._key,t,e)}marshal(){return nl(this._key)}get bytes(){return Ze.encode({Type:X.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return ee(this.bytes,e.bytes)}async hash(){let e=pe.digest(this.bytes),t;return Ve(e)?{bytes:t}=await e:t=e.bytes,t}},on=class{_key;_publicKey;constructor(e,t){this._key=e,this._publicKey=t??il(e),sl(this._key),ao(this._publicKey)}sign(e){return tl(this._key,e)}get public(){return new sn(this._publicKey)}marshal(){return this._key}get bytes(){return Je.encode({Type:X.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return ee(this.bytes,e.bytes)}hash(){let e=pe.digest(this.bytes);return Ve(e)?e.then(({bytes:t})=>t):e.bytes}async id(){let e=await this.public.hash();return H(e,"base58btc")}async export(e,t="libp2p-key"){if(t==="libp2p-key")return br(this.bytes,e);throw new R(`export format '${t}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function Ed(r){return new on(r)}function Bd(r){return new sn(r)}async function Ad(){let r=el();return new on(r)}var Xt={rsa:no,ed25519:ji,secp256k1:co};function ol(r){let e=Object.keys(Xt).join(" / ");return new R(`invalid or unsupported key type ${r}. Must be ${e}`,"ERR_UNSUPPORTED_KEY_TYPE")}function al(r){let e=Ze.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case X.RSA:return Xt.rsa.unmarshalRsaPublicKey(t);case X.Ed25519:return Xt.ed25519.unmarshalEd25519PublicKey(t);case X.Secp256k1:return Xt.secp256k1.unmarshalSecp256k1PublicKey(t);default:throw ol(e.Type??"unknown")}}async function cl(r){let e=Je.decode(r),t=e.Data??new Uint8Array;switch(e.Type){case X.RSA:return Xt.rsa.unmarshalRsaPrivateKey(t);case X.Ed25519:return Xt.ed25519.unmarshalEd25519PrivateKey(t);case X.Secp256k1:return Xt.secp256k1.unmarshalSecp256k1PrivateKey(t);default:throw ol(e.Type??"RSA")}}var ul=Symbol.for("nodejs.util.inspect.custom"),ll=Object.values(vt).map(r=>r.decoder).reduce((r,e)=>r.or(e),vt.identity.decoder),fl=114,fo=36,ho=37,an=class{type;multihash;privateKey;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,this.privateKey=e.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[bn]=!0;toString(){return this.string==null&&(this.string=oe.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return De.createV1(fl,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return ee(this.multihash.bytes,e);if(typeof e=="string")return cn(e).equals(this);if(e?.multihash?.bytes!=null)return ee(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[ul](){return`PeerId(${this.toString()})`}},Qt=class extends an{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},er=class extends an{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}},tr=class extends an{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}},lo=2336,uo=class{type="url";multihash;privateKey;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=nt.digest($(this.url))}[ul](){return`PeerId(${this.url})`}[bn]=!0;toString(){return this.toCID().toString()}toCID(){return De.createV1(lo,this.multihash)}toBytes(){return this.toCID().bytes}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=H(e)),e.toString()===this.toString())}};function hl(r){if(r.type==="RSA")return new Qt(r);if(r.type==="Ed25519")return new er(r);if(r.type==="secp256k1")return new tr(r);throw new R("Not a PeerId","ERR_INVALID_PARAMETERS")}function cn(r,e){if(e=e??ll,r.charAt(0)==="1"||r.charAt(0)==="Q"){let t=Ot(oe.decode(`z${r}`));return r.startsWith("12D")?new er({multihash:t}):r.startsWith("16U")?new tr({multihash:t}):new Qt({multihash:t})}return ln(ll.decode(r))}function ln(r){try{let e=Ot(r);if(e.code===nt.code){if(e.digest.length===fo)return new er({multihash:e});if(e.digest.length===ho)return new tr({multihash:e})}if(e.code===pe.code)return new Qt({multihash:e})}catch{return kd(De.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function kd(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==fl&&r.code!==lo)throw new Error("Supplied PeerID CID is invalid");if(r.code===lo){let t=H(r.multihash.digest);return new uo(new URL(t))}let e=r.multihash;if(e.code===pe.code)return new Qt({multihash:r.multihash});if(e.code===nt.code){if(e.digest.length===fo)return new er({multihash:r.multihash});if(e.digest.length===ho)return new tr({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function dl(r,e){return r.length===fo?new er({multihash:je(nt.code,r),privateKey:e}):r.length===ho?new tr({multihash:je(nt.code,r),privateKey:e}):new Qt({multihash:await pe.digest(r),publicKey:r,privateKey:e})}var gl=Symbol.for("@achingbrain/uint8arraylist");function pl(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let s=t+n.byteLength;if(e<s)return{buf:n,index:e-t};t=s}throw new RangeError("index is out of bounds")}function ks(r){return!!r?.[gl]}var Ss=class r{bufs;length;[gl]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if(ks(n))t+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if(ks(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=pl(this.bufs,e);return t.buf[t.index]}set(e,t){let n=pl(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if(ks(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:s}=this._subList(e,t);return Ee(n,s)}subarray(e,t){let{bufs:n,length:s}=this._subList(e,t);return n.length===1?n[0]:Ee(n,s)}sublist(e,t){let{bufs:n,length:s}=this._subList(e,t),i=new r;return i.length=s,i.bufs=[...n],i}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let n=[],s=0;for(let i=0;i<this.bufs.length;i++){let o=this.bufs[i],a=s,c=a+o.byteLength;if(s=c,e>=c)continue;let f=e>=a&&e<c,u=t>a&&t<=c;if(f&&u){if(e===a&&t===c){n.push(o);break}let l=e-a;n.push(o.subarray(l,l+(t-e)));break}if(f){if(e===0){n.push(o);continue}n.push(o.subarray(e-a));continue}if(u){if(t===c){n.push(o);break}n.push(o.subarray(0,t-a));break}n.push(o)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!ks(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let i=256,o=new Int32Array(i);for(let l=0;l<i;l++)o[l]=-1;for(let l=0;l<s;l++)o[n[l]]=l;let a=o,c=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let l=t;l<=c;l+=u){u=0;for(let h=f;h>=0;h--){let m=this.get(l+h);if(n[h]!==m){u=Math.max(1,h-a[m]);break}}if(u===0)return l}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=Te(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let s=st(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,t,n),this.write(s,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let s=st(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,t,n),this.write(s,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let s=st(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,t,n),this.write(s,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=Te(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let s=st(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,t,n),this.write(s,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let s=st(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,t,n),this.write(s,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let s=st(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,t,n),this.write(s,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let s=st(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,t,n),this.write(s,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let s=st(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,t,n),this.write(s,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!ee(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((s,i)=>s+i.byteLength,0)),n.length=t,n}};var ml={ERR_SIGNATURE_NOT_VALID:"ERR_SIGNATURE_NOT_VALID"};var un;(function(r){let e;r.codec=()=>(e==null&&(e=Se((t,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),t.publicKey!=null&&t.publicKey.byteLength>0&&(n.uint32(10),n.bytes(t.publicKey)),t.payloadType!=null&&t.payloadType.byteLength>0&&(n.uint32(18),n.bytes(t.payloadType)),t.payload!=null&&t.payload.byteLength>0&&(n.uint32(26),n.bytes(t.payload)),t.signature!=null&&t.signature.byteLength>0&&(n.uint32(42),n.bytes(t.signature)),s.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let s={publicKey:new Uint8Array(0),payloadType:new Uint8Array(0),payload:new Uint8Array(0),signature:new Uint8Array(0)},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let o=t.uint32();switch(o>>>3){case 1:s.publicKey=t.bytes();break;case 2:s.payloadType=t.bytes();break;case 3:s.payload=t.bytes();break;case 5:s.signature=t.bytes();break;default:t.skipType(o&7);break}}return s})),e),r.encode=t=>ke(t,r.codec()),r.decode=t=>Ae(t,r.codec())})(un||(un={}));var Sr=class r{static createFromProtobuf=async e=>{let t=un.decode(e),n=await dl(t.publicKey);return new r({peerId:n,payloadType:t.payloadType,payload:t.payload,signature:t.signature})};static seal=async(e,t)=>{if(t.privateKey==null)throw new Error("Missing private key");let n=e.domain,s=e.codec,i=e.marshal(),o=yl(n,s,i),c=await(await cl(t.privateKey)).sign(o.subarray());return new r({peerId:t,payloadType:s,payload:i,signature:c})};static openAndCertify=async(e,t)=>{let n=await r.createFromProtobuf(e);if(!await n.validate(t))throw new R("envelope signature is not valid for the given domain",ml.ERR_SIGNATURE_NOT_VALID);return n};peerId;payloadType;payload;signature;marshaled;constructor(e){let{peerId:t,payloadType:n,payload:s,signature:i}=e;this.peerId=t,this.payloadType=n,this.payload=s,this.signature=i}marshal(){if(this.peerId.publicKey==null)throw new Error("Missing public key");return this.marshaled==null&&(this.marshaled=un.encode({publicKey:this.peerId.publicKey,payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(e){return ee(this.marshal(),e.marshal())}async validate(e){let t=yl(e,this.payloadType,this.payload);if(this.peerId.publicKey==null)throw new Error("Missing public key");return al(this.peerId.publicKey).verify(t.subarray(),this.signature)}},yl=(r,e,t)=>{let n=$(r),s=Ye(n.byteLength),i=Ye(e.length),o=Ye(t.length);return new Ss(s,n,i,e,o,t)};function bl(r,e){let t=(n,s)=>n.toString().localeCompare(s.toString());return r.length!==e.length?!1:(e.sort(t),r.sort(t).every((n,s)=>e[s].equals(n)))}var Is=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,s){return this.readAtomically(()=>{let i=0,o=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",f=2**(8*s)-1;for(;;){let u=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let h=Number.parseInt(l,e);if(!Number.isNaN(h))return h});if(u===void 0)break;if(i*=e,i+=u,i>f||(o+=1,t!==void 0&&o>t))return}if(o!==0)return!n&&c&&o>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let s=n*2;if(n<t.length-3){let o=this.readSeparator(":",n,()=>this.readIPv4Addr());if(o!==void 0)return t[s]=o[0],t[s+1]=o[1],t[s+2]=o[2],t[s+3]=o[3],[s+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[s,!1];t[s]=i>>8,t[s+1]=i&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,s]=e(t);if(n===16)return t;if(s||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),o=16-(n+2),[a]=e(i.subarray(0,o));return t.set(i.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var wl=45,Sd=15,Ir=new Is;function po(r){if(!(r.length>Sd))return Ir.new(r).parseWith(()=>Ir.readIPv4Addr())}function go(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>wl))return Ir.new(r).parseWith(()=>Ir.readIPv6Addr())}function Rs(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>wl))return Ir.new(r).parseWith(()=>Ir.readIPAddr())}var Ay=parseInt("0xFFFF",16),ky=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function El(r){return!!po(r)}function Bl(r){return!!go(r)}function Ns(r){return!!Rs(r)}var Al=El,_d=Bl,mo=function(r){let e=0;if(r=r.toString().trim(),Al(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(_d(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=Al(t[n]),o;i&&(o=mo(t[n]),t[n]=H(o.slice(0,2),"base16")),o!=null&&++n<8&&t.splice(n,0,H(o.slice(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let i=[n,1];for(n=9-t.length;n>0;n--)i.push("0");t.splice.apply(t,i)}let s=new Uint8Array(e+16);for(n=0;n<t.length;n++){let i=parseInt(t[n],16);s[e++]=i>>8&255,s[e++]=i&255}return s}throw new Error("invalid ip address")},kl=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let s=[];for(let i=0;i<t;i++)s.push(r[e+i]);return s.join(".")}if(t===16){let s=[];for(let i=0;i<t;i+=2)s.push(n.getUint16(e+i).toString(16));return s.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var Rr={},yo={},Cd=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];Cd.forEach(r=>{let e=Ud(...r);yo[e.code]=e,Rr[e.name]=e});function Ud(r,e,t,n,s){return{code:r,size:e,name:t,resolvable:!!n,path:!!s}}function W(r){if(typeof r=="number"){if(yo[r]!=null)return yo[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Rr[r]!=null)return Rr[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var cb=W("ip4"),lb=W("ip6"),ub=W("ipcidr");function vo(r,e){switch(W(r).code){case 4:case 41:return Dd(e);case 42:return xo(e);case 6:case 273:case 33:case 132:return Rl(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return xo(e);case 421:return Hd(e);case 444:return Il(e);case 445:return Il(e);case 466:return Md(e);case 481:return globalThis.encodeURIComponent(xo(e));default:return H(e,"base16")}}function Eo(r,e){switch(W(r).code){case 4:return Sl(e);case 41:return Sl(e);case 42:return wo(e);case 6:case 273:case 33:case 132:return Bo(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return wo(e);case 421:return Vd(e);case 444:return Kd(e);case 445:return Fd(e);case 466:return Od(e);case 481:return wo(globalThis.decodeURIComponent(e));default:return $(e,"base16")}}var bo=Object.values(vt).map(r=>r.decoder),Pd=function(){let r=bo[0].or(bo[1]);return bo.slice(2).forEach(e=>r=r.or(e)),r}();function Sl(r){if(!Ns(r))throw new Error("invalid ip address");return mo(r)}function Dd(r){let e=kl(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!Ns(e))throw new Error("invalid ip address");return e}function Bo(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function Rl(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function wo(r){let e=$(r),t=Uint8Array.from(Ye(e.length));return Ee([t,e],t.length+e.length)}function xo(r){let e=Gt(r);if(r=r.slice(Ce(e)),r.length!==e)throw new Error("inconsistent lengths");return H(r)}function Vd(r){let e;r[0]==="Q"||r[0]==="1"?e=Ot(oe.decode(`z${r}`)).bytes:e=De.parse(r).multihash.bytes;let t=Uint8Array.from(Ye(e.length));return Ee([t,e],t.length+e.length)}function Od(r){let e=Pd.decode(r),t=Uint8Array.from(Ye(e.length));return Ee([t,e],t.length+e.length)}function Md(r){let e=Gt(r),t=r.slice(Ce(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+H(t,"base64url")}function Hd(r){let e=Gt(r),t=r.slice(Ce(e));if(t.length!==e)throw new Error("inconsistent lengths");return H(t,"base58btc")}function Kd(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=Me.decode("b"+e[0]),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let s=Bo(n);return Ee([t,s],t.length+s.length)}function Fd(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let t=Me.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let s=Bo(n);return Ee([t,s],t.length+s.length)}function Il(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=H(e,"base32"),s=Rl(t);return`${n}:${s}`}function Nl(r){r=Ao(r);let e=[],t=[],n=null,s=r.split("/").slice(1);if(s.length===1&&s[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let i=0;i<s.length;i++){let o=s[i],a=W(o);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(i++,i>=s.length)throw _l("invalid address: "+r);if(a.path===!0){n=Ao(s.slice(i).join("/")),e.push([a.code,Eo(a.code,n)]),t.push([a.code,n]);break}let c=Eo(a.code,s[i]);e.push([a.code,c]),t.push([a.code,vo(a.code,c)])}return{string:Tl(t),bytes:So(e),tuples:e,stringTuples:t,path:n}}function ko(r){let e=[],t=[],n=null,s=0;for(;s<r.length;){let i=Gt(r,s),o=Ce(i),a=W(i),c=qd(a,r.slice(s+o));if(c===0){e.push([i]),t.push([i]),s+=o;continue}let f=r.slice(s+o,s+o+c);if(s+=c+o,s>r.length)throw _l("Invalid address Uint8Array: "+H(r,"base16"));e.push([i,f]);let u=vo(i,f);if(t.push([i,u]),a.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:Tl(t),tuples:e,stringTuples:t,path:n}}function Tl(r){let e=[];return r.map(t=>{let n=W(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),Ao(e.join("/"))}function So(r){return Ee(r.map(e=>{let t=W(e[0]),n=Uint8Array.from(Ye(t.code));return e.length>1&&e[1]!=null&&(n=Ee([n,e[1]])),n}))}function qd(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=Gt(e instanceof Uint8Array?e:Uint8Array.from(e));return t+Ce(t)}}function Ao(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function _l(r){return new Error("Error parsing address: "+r)}var $d=Symbol.for("nodejs.util.inspect.custom"),Io=Symbol.for("@multiformats/js-multiaddr/multiaddr"),zd=[W("dns").code,W("dns4").code,W("dns6").code,W("dnsaddr").code],Ts=class r{bytes;#e;#t;#i;#a;[Io]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=ko(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=Nl(e)}else if(_s(e))t=ko(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#i=t.stringTuples,this.#a=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,s,i="",o=W("tcp"),a=W("udp"),c=W("ip4"),f=W("ip6"),u=W("dns6"),l=W("ip6zone");for(let[m,x]of this.stringTuples())m===l.code&&(i=`%${x??""}`),zd.includes(m)&&(t=o.name,s=443,n=`${x??""}${i}`,e=m===u.code?6:4),(m===o.code||m===a.code)&&(t=W(m).name,s=parseInt(x??"")),(m===c.code||m===f.code)&&(t=W(m).name,n=`${x??""}${i}`,e=m===f.code?6:4);if(e==null||t==null||n==null||s==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:s}}protos(){return this.#t.map(([e])=>Object.assign({},W(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>W(e).name)}tuples(){return this.#t}stringTuples(){return this.#i}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),s=n.lastIndexOf(t);if(s<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,s))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(So(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,s])=>{n===Rr.p2p.code&&e.push([n,s]),n===Rr["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?H(oe.decode(`z${n}`),"base58btc"):H(De.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#a}equals(e){return ee(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(i=>i.resolvable);if(t==null)return[this];let n=Ll.get(t.name);if(n==null)throw new R(`no available resolver for ${t.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,e)).map(i=>bt(i))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[$d](){return`Multiaddr(${this.#e})`}};var Ll=new Map;function _s(r){return!!r?.[Io]}function bt(r){return new Ts(r)}var Cl="libp2p-peer-record",Ul=Uint8Array.from([3,1]);var fn;(function(r){let e;(function(n){let s;n.codec=()=>(s==null&&(s=Se((i,o,a={})=>{a.lengthDelimited!==!1&&o.fork(),i.multiaddr!=null&&i.multiaddr.byteLength>0&&(o.uint32(10),o.bytes(i.multiaddr)),a.lengthDelimited!==!1&&o.ldelim()},(i,o)=>{let a={multiaddr:new Uint8Array(0)},c=o==null?i.len:i.pos+o;for(;i.pos<c;){let f=i.uint32();switch(f>>>3){case 1:a.multiaddr=i.bytes();break;default:i.skipType(f&7);break}}return a})),s),n.encode=i=>ke(i,n.codec()),n.decode=i=>Ae(i,n.codec())})(e=r.AddressInfo||(r.AddressInfo={}));let t;r.codec=()=>(t==null&&(t=Se((n,s,i={})=>{if(i.lengthDelimited!==!1&&s.fork(),n.peerId!=null&&n.peerId.byteLength>0&&(s.uint32(10),s.bytes(n.peerId)),n.seq!=null&&n.seq!==0n&&(s.uint32(16),s.uint64(n.seq)),n.addresses!=null)for(let o of n.addresses)s.uint32(26),r.AddressInfo.codec().encode(o,s);i.lengthDelimited!==!1&&s.ldelim()},(n,s)=>{let i={peerId:new Uint8Array(0),seq:0n,addresses:[]},o=s==null?n.len:n.pos+s;for(;n.pos<o;){let a=n.uint32();switch(a>>>3){case 1:i.peerId=n.bytes();break;case 2:i.seq=n.uint64();break;case 3:i.addresses.push(r.AddressInfo.codec().decode(n,n.uint32()));break;default:n.skipType(a&7);break}}return i})),t),r.encode=n=>ke(n,r.codec()),r.decode=n=>Ae(n,r.codec())})(fn||(fn={}));var rr=class r{static createFromProtobuf=e=>{let t=fn.decode(e),n=ln(t.peerId),s=(t.addresses??[]).map(o=>bt(o.multiaddr)),i=t.seq;return new r({peerId:n,multiaddrs:s,seqNumber:i})};static DOMAIN=Cl;static CODEC=Ul;peerId;multiaddrs;seqNumber;domain=r.DOMAIN;codec=r.CODEC;marshaled;constructor(e){let{peerId:t,multiaddrs:n,seqNumber:s}=e;this.peerId=t,this.multiaddrs=n??[],this.seqNumber=s??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=fn.encode({peerId:this.peerId.toBytes(),seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(e=>({multiaddr:e.bytes}))})),this.marshaled}equals(e){return!(!(e instanceof r)||!this.peerId.equals(e.peerId)||this.seqNumber!==e.seqNumber||!bl(this.multiaddrs,e.multiaddrs))}};function Gd(r){return r[Symbol.asyncIterator]!=null}function jd(r){if(Gd(r))return(async()=>{let t=[];for await(let n of r)t.push(n);return t})();let e=[];for(let t of r)e.push(t);return e}var Pl=jd;function Ro(r,e){let t={[Symbol.iterator]:()=>t,next:()=>{let n=r.next(),s=n.value;return n.done===!0||s==null?{done:!0,value:void 0}:{done:!1,value:e(s)}}};return t}var hn=class{map;constructor(e){if(this.map=new Map,e!=null)for(let[t,n]of e.entries())this.map.set(t.toString(),n)}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(e){return this.map.delete(e.toString())}entries(){return Ro(this.map.entries(),e=>[cn(e[0]),e[1]])}forEach(e){this.map.forEach((t,n)=>{e(t,cn(n),this)})}get(e){return this.map.get(e.toString())}has(e){return this.map.has(e.toString())}set(e,t){this.map.set(e.toString(),t)}keys(){return Ro(this.map.keys(),e=>cn(e))}values(){return this.map.values()}get size(){return this.map.size}};var To=Qo(Vl(),1);var pn=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},_o=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Ol=r=>globalThis.DOMException===void 0?new _o(r):new DOMException(r),Ml=r=>{let e=r.reason===void 0?Ol("This operation was aborted."):r.reason;return e instanceof Error?e:Ol(e)};function gn(r,e){let{milliseconds:t,fallback:n,message:s,customTimers:i={setTimeout,clearTimeout}}=e,o,c=new Promise((f,u)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:h}=e;h.aborted&&u(Ml(h)),h.addEventListener("abort",()=>{u(Ml(h))})}if(t===Number.POSITIVE_INFINITY){r.then(f,u);return}let l=new pn;o=i.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(h){u(h)}return}typeof r.cancel=="function"&&r.cancel(),s===!1?f():s instanceof Error?u(s):(l.message=s??`Promise timed out after ${t} milliseconds`,u(l))},t),(async()=>{try{f(await r)}catch(h){u(h)}})()}).finally(()=>{c.clear()});return c.clear=()=>{i.clearTimeout.call(void 0,o),o=void 0},c}function Lo(r,e,t){let n=0,s=r.length;for(;s>0;){let i=Math.trunc(s/2),o=n+i;t(r[o],e)<=0?(n=++o,s-=i+1):s=i}return n}var mn=class{#e=[];enqueue(e,t){t={priority:0,...t};let n={priority:t.priority,run:e};if(this.size&&this.#e[this.size-1].priority>=t.priority){this.#e.push(n);return}let s=Lo(this.#e,n,(i,o)=>o.priority-i.priority);this.#e.splice(s,0,n)}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(t=>t.priority===e.priority).map(t=>t.run)}get size(){return this.#e.length}};var Nr=class extends To.default{#e;#t;#i=0;#a;#c;#p=0;#n;#l;#r;#g;#s=0;#u;#o;#m;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:mn,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);this.#e=e.carryoverConcurrencyCount,this.#t=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#a=e.intervalCap,this.#c=e.interval,this.#r=new e.queueClass,this.#g=e.queueClass,this.concurrency=e.concurrency,this.timeout=e.timeout,this.#m=e.throwOnTimeout===!0,this.#o=e.autoStart===!1}get#w(){return this.#t||this.#i<this.#a}get#x(){return this.#s<this.#u}#v(){this.#s--,this.#f(),this.emit("next")}#E(){this.#b(),this.#y(),this.#l=void 0}get#B(){let e=Date.now();if(this.#n===void 0){let t=this.#p-e;if(t<0)this.#i=this.#e?this.#s:0;else return this.#l===void 0&&(this.#l=setTimeout(()=>{this.#E()},t)),!0}return!1}#f(){if(this.#r.size===0)return this.#n&&clearInterval(this.#n),this.#n=void 0,this.emit("empty"),this.#s===0&&this.emit("idle"),!1;if(!this.#o){let e=!this.#B;if(this.#w&&this.#x){let t=this.#r.dequeue();return t?(this.emit("active"),t(),e&&this.#y(),!0):!1}}return!1}#y(){this.#t||this.#n!==void 0||(this.#n=setInterval(()=>{this.#b()},this.#c),this.#p=Date.now()+this.#c)}#b(){this.#i===0&&this.#s===0&&this.#n&&(clearInterval(this.#n),this.#n=void 0),this.#i=this.#e?this.#s:0,this.#h()}#h(){for(;this.#f(););}get concurrency(){return this.#u}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#u=e,this.#h()}async#A(e){return new Promise((t,n)=>{e.addEventListener("abort",()=>{n(e.reason)},{once:!0})})}async add(e,t={}){return t={timeout:this.timeout,throwOnTimeout:this.#m,...t},new Promise((n,s)=>{this.#r.enqueue(async()=>{this.#s++,this.#i++;try{t.signal?.throwIfAborted();let i=e({signal:t.signal});t.timeout&&(i=gn(Promise.resolve(i),{milliseconds:t.timeout})),t.signal&&(i=Promise.race([i,this.#A(t.signal)]));let o=await i;n(o),this.emit("completed",o)}catch(i){if(i instanceof pn&&!t.throwOnTimeout){n();return}s(i),this.emit("error",i)}finally{this.#v()}},t),this.emit("add"),this.#f()})}async addAll(e,t){return Promise.all(e.map(async n=>this.add(n,t)))}start(){return this.#o?(this.#o=!1,this.#h(),this):this}pause(){this.#o=!0}clear(){this.#r=new this.#g}async onEmpty(){this.#r.size!==0&&await this.#d("empty")}async onSizeLessThan(e){this.#r.size<e||await this.#d("next",()=>this.#r.size<e)}async onIdle(){this.#s===0&&this.#r.size===0||await this.#d("idle")}async#d(e,t){return new Promise(n=>{let s=()=>{t&&!t()||(this.off(e,s),n())};this.on(e,s)})}get size(){return this.#r.size}sizeBy(e){return this.#r.filter(e).length}get pending(){return this.#s}get isPaused(){return this.#o}};var Dt={},Tr=r=>{r.addEventListener("message",e=>{Tr.dispatchEvent("message",r,e)}),r.port!=null&&r.port.addEventListener("message",e=>{Tr.dispatchEvent("message",r,e)})};Tr.addEventListener=(r,e)=>{Dt[r]==null&&(Dt[r]=[]),Dt[r].push(e)};Tr.removeEventListener=(r,e)=>{Dt[r]!=null&&(Dt[r]=Dt[r].filter(t=>t===e))};Tr.dispatchEvent=function(r,e,t){Dt[r]!=null&&Dt[r].forEach(n=>n(e,t))};var Co=Tr;var Uo="lock:worker:request-read",Po="lock:worker:release-read",Do="lock:master:grant-read",Vo="lock:worker:request-write",Oo="lock:worker:release-write",Mo="lock:master:grant-write";var Hl=(r=21)=>Math.random().toString().substring(2);var Kl=(r,e,t,n,s)=>(i,o)=>{if(o.data.type!==t)return;let a={type:o.data.type,name:o.data.name,identifier:o.data.identifier};r.dispatchEvent(new MessageEvent(e,{data:{name:a.name,handler:async()=>{i.postMessage({type:s,name:a.name,identifier:a.identifier}),await new Promise(c=>{let f=u=>{if(u==null||u.data==null)return;let l={type:u.data.type,name:u.data.name,identifier:u.data.identifier};l.type===n&&l.identifier===a.identifier&&(i.removeEventListener("message",f),c())};i.addEventListener("message",f)})}}}))},Fl=(r,e,t,n)=>async()=>{let s=Hl();return globalThis.postMessage({type:e,identifier:s,name:r}),new Promise(i=>{let o=a=>{if(a==null||a.data==null)return;let c={type:a.data.type,identifier:a.data.identifier};c.type===t&&c.identifier===s&&(globalThis.removeEventListener("message",o),i(()=>{globalThis.postMessage({type:n,identifier:s,name:r})}))};globalThis.addEventListener("message",o)})},Zd={singleProcess:!1},ql=r=>{if(r=Object.assign({},Zd,r),!!globalThis.document||r.singleProcess){let t=new EventTarget;return Co.addEventListener("message",Kl(t,"requestReadLock",Uo,Po,Do)),Co.addEventListener("message",Kl(t,"requestWriteLock",Vo,Oo,Mo)),t}return{isWorker:!0,readLock:t=>Fl(t,Uo,Do,Po),writeLock:t=>Fl(t,Vo,Mo,Oo)}};var nr={},Vt;async function Ho(r,e){let t,n=new Promise(s=>{t=s});return r.add(async()=>gn((async()=>{await new Promise(s=>{t(()=>{s()})})})(),{milliseconds:e.timeout})),n}var Jd=(r,e)=>{if(Vt.isWorker===!0)return{readLock:Vt.readLock(r,e),writeLock:Vt.writeLock(r,e)};let t=new Nr({concurrency:1}),n;return{async readLock(){if(n!=null)return Ho(n,e);n=new Nr({concurrency:e.concurrency,autoStart:!1});let s=n,i=Ho(n,e);return t.add(async()=>{s.start(),await s.onIdle().then(()=>{n===s&&(n=null)})}),i},async writeLock(){return n=null,Ho(t,e)}}},Xd={name:"lock",concurrency:1/0,timeout:846e5,singleProcess:!1};function Ko(r){let e=Object.assign({},Xd,r);return Vt==null&&(Vt=ql(e),Vt.isWorker!==!0&&(Vt.addEventListener("requestReadLock",t=>{nr[t.data.name]!=null&&nr[t.data.name].readLock().then(async n=>t.data.handler().finally(()=>{n()}))}),Vt.addEventListener("requestWriteLock",async t=>{nr[t.data.name]!=null&&nr[t.data.name].writeLock().then(async n=>t.data.handler().finally(()=>{n()}))}))),nr[e.name]==null&&(nr[e.name]=Jd(e.name,e)),nr[e.name]}var me={ERR_INVALID_PARAMETERS:"ERR_INVALID_PARAMETERS"};var _r;(function(r){let e;(function(s){let i;s.codec=()=>(i==null&&(i=Se((o,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),o.key!=null&&o.key!==""&&(a.uint32(10),a.string(o.key)),o.value!=null&&o.value.byteLength>0&&(a.uint32(18),a.bytes(o.value)),c.lengthDelimited!==!1&&a.ldelim()},(o,a)=>{let c={key:"",value:new Uint8Array(0)},f=a==null?o.len:o.pos+a;for(;o.pos<f;){let u=o.uint32();switch(u>>>3){case 1:c.key=o.string();break;case 2:c.value=o.bytes();break;default:o.skipType(u&7);break}}return c})),i),s.encode=o=>ke(o,s.codec()),s.decode=o=>Ae(o,s.codec())})(e=r.Peer$metadataEntry||(r.Peer$metadataEntry={}));let t;(function(s){let i;s.codec=()=>(i==null&&(i=Se((o,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),o.key!=null&&o.key!==""&&(a.uint32(10),a.string(o.key)),o.value!=null&&(a.uint32(18),Us.codec().encode(o.value,a)),c.lengthDelimited!==!1&&a.ldelim()},(o,a)=>{let c={key:""},f=a==null?o.len:o.pos+a;for(;o.pos<f;){let u=o.uint32();switch(u>>>3){case 1:c.key=o.string();break;case 2:c.value=Us.codec().decode(o,o.uint32());break;default:o.skipType(u&7);break}}return c})),i),s.encode=o=>ke(o,s.codec()),s.decode=o=>Ae(o,s.codec())})(t=r.Peer$tagsEntry||(r.Peer$tagsEntry={}));let n;r.codec=()=>(n==null&&(n=Se((s,i,o={})=>{if(o.lengthDelimited!==!1&&i.fork(),s.addresses!=null)for(let a of s.addresses)i.uint32(10),Cs.codec().encode(a,i);if(s.protocols!=null)for(let a of s.protocols)i.uint32(18),i.string(a);if(s.publicKey!=null&&(i.uint32(34),i.bytes(s.publicKey)),s.peerRecordEnvelope!=null&&(i.uint32(42),i.bytes(s.peerRecordEnvelope)),s.metadata!=null&&s.metadata.size!==0)for(let[a,c]of s.metadata.entries())i.uint32(50),r.Peer$metadataEntry.codec().encode({key:a,value:c},i);if(s.tags!=null&&s.tags.size!==0)for(let[a,c]of s.tags.entries())i.uint32(58),r.Peer$tagsEntry.codec().encode({key:a,value:c},i);o.lengthDelimited!==!1&&i.ldelim()},(s,i)=>{let o={addresses:[],protocols:[],metadata:new Map,tags:new Map},a=i==null?s.len:s.pos+i;for(;s.pos<a;){let c=s.uint32();switch(c>>>3){case 1:o.addresses.push(Cs.codec().decode(s,s.uint32()));break;case 2:o.protocols.push(s.string());break;case 4:o.publicKey=s.bytes();break;case 5:o.peerRecordEnvelope=s.bytes();break;case 6:{let f=r.Peer$metadataEntry.codec().decode(s,s.uint32());o.metadata.set(f.key,f.value);break}case 7:{let f=r.Peer$tagsEntry.codec().decode(s,s.uint32());o.tags.set(f.key,f.value);break}default:s.skipType(c&7);break}}return o})),n),r.encode=s=>ke(s,r.codec()),r.decode=s=>Ae(s,r.codec())})(_r||(_r={}));var Cs;(function(r){let e;r.codec=()=>(e==null&&(e=Se((t,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),t.multiaddr!=null&&t.multiaddr.byteLength>0&&(n.uint32(10),n.bytes(t.multiaddr)),t.isCertified!=null&&(n.uint32(16),n.bool(t.isCertified)),s.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let s={multiaddr:new Uint8Array(0)},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let o=t.uint32();switch(o>>>3){case 1:s.multiaddr=t.bytes();break;case 2:s.isCertified=t.bool();break;default:t.skipType(o&7);break}}return s})),e),r.encode=t=>ke(t,r.codec()),r.decode=t=>Ae(t,r.codec())})(Cs||(Cs={}));var Us;(function(r){let e;r.codec=()=>(e==null&&(e=Se((t,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),t.value!=null&&t.value!==0&&(n.uint32(8),n.uint32(t.value)),t.expiry!=null&&(n.uint32(16),n.uint64(t.expiry)),s.lengthDelimited!==!1&&n.ldelim()},(t,n)=>{let s={value:0},i=n==null?t.len:t.pos+n;for(;t.pos<i;){let o=t.uint32();switch(o>>>3){case 1:s.value=t.uint32();break;case 2:s.expiry=t.uint64();break;default:t.skipType(o&7);break}}return s})),e),r.encode=t=>ke(t,r.codec()),r.decode=t=>Ae(t,r.codec())})(Us||(Us={}));function Lr(r,e){let t=_r.decode(e);t.publicKey!=null&&r.publicKey==null&&(r=hl({...r,publicKey:r.publicKey}));let n=new Map,s=BigInt(Date.now());for(let[i,o]of t.tags.entries())o.expiry!=null&&o.expiry<s||n.set(i,o);return{...t,id:r,addresses:t.addresses.map(({multiaddr:i,isCertified:o})=>({multiaddr:bt(i),isCertified:o??!1})),metadata:t.metadata,peerRecordEnvelope:t.peerRecordEnvelope??void 0,tags:n}}var wt="/",$l=new TextEncoder().encode(wt),Ps=$l[0],Ds=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=$(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(t==null&&(t=!0),t&&this.clean(),this._buf.byteLength===0||this._buf[0]!==Ps)throw new Error("Invalid key")}toString(e="utf8"){return H(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new r(e.join(wt))}static random(){return new r(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new r(e):typeof e.uint8Array=="function"?new r(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=$l),this._buf[0]!==Ps){let e=new Uint8Array(this._buf.byteLength+1);e.fill(Ps,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Ps;)this._buf=this._buf.subarray(0,-1)}less(e){let t=this.list(),n=e.list();for(let s=0;s<t.length;s++){if(n.length<s+1)return!1;let i=t[s],o=n[s];if(i<o)return!0;if(i>o)return!1}return t.length<n.length}reverse(){return r.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(wt).slice(1)}type(){return Qd(this.baseNamespace())}name(){return ep(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(wt)||(e+=wt),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(wt):new r(e.slice(0,-1).join(wt))}child(e){return this.toString()===wt?e:e.toString()===wt?this:new r(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()===this.toString()?!1:e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()===this.toString()?!1:this.toString().startsWith(e.toString())}isTopLevel(){return this.list().length===1}concat(...e){return r.withNamespaces([...this.namespaces(),...tp(e.map(t=>t.namespaces()))])}};function Qd(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function ep(r){let e=r.split(":");return e[e.length-1]}function tp(r){return[].concat(...r)}var Fo="/peers/";function Cr(r){if(!ea(r)||r.type==null)throw new R("Invalid PeerId",me.ERR_INVALID_PARAMETERS);let e=r.toCID().toString();return new Ds(`${Fo}${e}`)}async function zl(r,e,t){let n=new Map;for(let s of t){if(s==null)continue;if(s.multiaddr instanceof Uint8Array&&(s.multiaddr=bt(s.multiaddr)),!_s(s.multiaddr))throw new R("Multiaddr was invalid",me.ERR_INVALID_PARAMETERS);if(!await e(r,s.multiaddr))continue;let i=s.isCertified??!1,o=s.multiaddr.toString(),a=n.get(o);a!=null?s.isCertified=a.isCertified||i:n.set(o,{multiaddr:s.multiaddr,isCertified:i})}return[...n.values()].sort((s,i)=>s.multiaddr.toString().localeCompare(i.multiaddr.toString())).map(({isCertified:s,multiaddr:i})=>({isCertified:s,multiaddr:i.bytes}))}async function Os(r,e,t,n){if(e==null)throw new R("Invalid PeerData",me.ERR_INVALID_PARAMETERS);if(e.publicKey!=null&&r.publicKey!=null&&!ee(e.publicKey,r.publicKey))throw new R("publicKey bytes do not match peer id publicKey bytes",me.ERR_INVALID_PARAMETERS);let s=n.existingPeer;if(s!=null&&!r.equals(s.id))throw new R("peer id did not match existing peer id",me.ERR_INVALID_PARAMETERS);let i=s?.addresses??[],o=new Set(s?.protocols??[]),a=s?.metadata??new Map,c=s?.tags??new Map,f=s?.peerRecordEnvelope;if(t==="patch"){if((e.multiaddrs!=null||e.addresses!=null)&&(i=[],e.multiaddrs!=null&&i.push(...e.multiaddrs.map(l=>({isCertified:!1,multiaddr:l}))),e.addresses!=null&&i.push(...e.addresses)),e.protocols!=null&&(o=new Set(e.protocols)),e.metadata!=null){let l=e.metadata instanceof Map?[...e.metadata.entries()]:Object.entries(e.metadata);a=Vs(l,{validate:Gl})}if(e.tags!=null){let l=e.tags instanceof Map?[...e.tags.entries()]:Object.entries(e.tags);c=Vs(l,{validate:jl,map:Wl})}e.peerRecordEnvelope!=null&&(f=e.peerRecordEnvelope)}if(t==="merge"){if(e.multiaddrs!=null&&i.push(...e.multiaddrs.map(l=>({isCertified:!1,multiaddr:l}))),e.addresses!=null&&i.push(...e.addresses),e.protocols!=null&&(o=new Set([...o,...e.protocols])),e.metadata!=null){let l=e.metadata instanceof Map?[...e.metadata.entries()]:Object.entries(e.metadata);for(let[h,m]of l)m==null?a.delete(h):a.set(h,m);a=Vs([...a.entries()],{validate:Gl})}if(e.tags!=null){let l=e.tags instanceof Map?[...e.tags.entries()]:Object.entries(e.tags),h=new Map(c);for(let[m,x]of l)x==null?h.delete(m):h.set(m,x);c=Vs([...h.entries()],{validate:jl,map:Wl})}e.peerRecordEnvelope!=null&&(f=e.peerRecordEnvelope)}let u={addresses:await zl(r,n.addressFilter??(async()=>!0),i),protocols:[...o.values()].sort((l,h)=>l.localeCompare(h)),metadata:a,tags:c,publicKey:s?.id.publicKey??e.publicKey??r.publicKey,peerRecordEnvelope:f};return r.type!=="RSA"&&delete u.publicKey,u}function Vs(r,e){let t=new Map;for(let[n,s]of r)s!=null&&e.validate(n,s);for(let[n,s]of r.sort(([i],[o])=>i.localeCompare(o)))s!=null&&t.set(n,e.map?.(n,s)??s);return t}function Gl(r,e){if(typeof r!="string")throw new R("Metadata key must be a string",me.ERR_INVALID_PARAMETERS);if(!(e instanceof Uint8Array))throw new R("Metadata value must be a Uint8Array",me.ERR_INVALID_PARAMETERS)}function jl(r,e){if(typeof r!="string")throw new R("Tag name must be a string",me.ERR_INVALID_PARAMETERS);if(e.value!=null){if(parseInt(`${e.value}`,10)!==e.value)throw new R("Tag value must be an integer",me.ERR_INVALID_PARAMETERS);if(e.value<0||e.value>100)throw new R("Tag value must be between 0-100",me.ERR_INVALID_PARAMETERS)}if(e.ttl!=null){if(parseInt(`${e.ttl}`,10)!==e.ttl)throw new R("Tag ttl must be an integer",me.ERR_INVALID_PARAMETERS);if(e.ttl<0)throw new R("Tag ttl must be between greater than 0",me.ERR_INVALID_PARAMETERS)}}function Wl(r,e){let t;return e.expiry!=null&&(t=e.expiry),e.ttl!=null&&(t=BigInt(Date.now()+Number(e.ttl))),{value:e.value??0,expiry:t}}function Ms(r,e,t){let n=r.toString().split("/")[2],s=Me.decode(n),i=ln(s),o=t.get(i);if(o!=null)return o;let a=Lr(i,e);return t.set(i,a),a}function rp(r,e){return r==null?{}:{prefix:Fo,filters:(r.filters??[]).map(t=>({key:n,value:s})=>t(Ms(n,s,e))),orders:(r.orders??[]).map(t=>(n,s)=>t(Ms(n.key,n.value,e),Ms(s.key,s.value,e)))}}var Hs=class{peerId;datastore;lock;addressFilter;constructor(e,t={}){this.peerId=e.peerId,this.datastore=e.datastore,this.addressFilter=t.addressFilter,this.lock=Ko({name:"peer-store",singleProcess:!0})}async has(e){return this.datastore.has(Cr(e))}async delete(e){if(this.peerId.equals(e))throw new R("Cannot delete self peer",me.ERR_INVALID_PARAMETERS);await this.datastore.delete(Cr(e))}async load(e){let t=await this.datastore.get(Cr(e));return Lr(e,t)}async save(e,t){let{existingBuf:n,existingPeer:s}=await this.#e(e),i=await Os(e,t,"patch",{addressFilter:this.addressFilter});return this.#t(e,i,n,s)}async patch(e,t){let{existingBuf:n,existingPeer:s}=await this.#e(e),i=await Os(e,t,"patch",{addressFilter:this.addressFilter,existingPeer:s});return this.#t(e,i,n,s)}async merge(e,t){let{existingBuf:n,existingPeer:s}=await this.#e(e),i=await Os(e,t,"merge",{addressFilter:this.addressFilter,existingPeer:s});return this.#t(e,i,n,s)}async*all(e){let t=new hn;for await(let{key:n,value:s}of this.datastore.query(rp(e??{},t))){let i=Ms(n,s,t);i.id.equals(this.peerId)||(yield i)}}async#e(e){try{let t=await this.datastore.get(Cr(e)),n=Lr(e,t);return{existingBuf:t,existingPeer:n}}catch(t){if(t.code!=="ERR_NOT_FOUND")throw t}return{}}async#t(e,t,n,s){let i=_r.encode(t);return n!=null&&ee(i,n)?{peer:Lr(e,i),previous:s,updated:!1}:(await this.datastore.put(Cr(e),i),{peer:Lr(e,i),previous:s,updated:!0})}};var qo=class{store;events;peerId;log;constructor(e,t={}){this.log=e.logger.forComponent("libp2p:peer-store"),this.events=e.events,this.peerId=e.peerId,this.store=new Hs(e,t)}[Symbol.toStringTag]="@libp2p/peer-store";async forEach(e,t){this.log.trace("forEach await read lock");let n=await this.store.lock.readLock();this.log.trace("forEach got read lock");try{for await(let s of this.store.all(t))e(s)}finally{this.log.trace("forEach release read lock"),n()}}async all(e){this.log.trace("all await read lock");let t=await this.store.lock.readLock();this.log.trace("all got read lock");try{return await Pl(this.store.all(e))}finally{this.log.trace("all release read lock"),t()}}async delete(e){this.log.trace("delete await write lock");let t=await this.store.lock.writeLock();this.log.trace("delete got write lock");try{await this.store.delete(e)}finally{this.log.trace("delete release write lock"),t()}}async has(e){this.log.trace("has await read lock");let t=await this.store.lock.readLock();this.log.trace("has got read lock");try{return await this.store.has(e)}finally{this.log.trace("has release read lock"),t()}}async get(e){this.log.trace("get await read lock");let t=await this.store.lock.readLock();this.log.trace("get got read lock");try{return await this.store.load(e)}finally{this.log.trace("get release read lock"),t()}}async save(e,t){this.log.trace("save await write lock");let n=await this.store.lock.writeLock();this.log.trace("save got write lock");try{let s=await this.store.save(e,t);return this.#e(e,s),s.peer}finally{this.log.trace("save release write lock"),n()}}async patch(e,t){this.log.trace("patch await write lock");let n=await this.store.lock.writeLock();this.log.trace("patch got write lock");try{let s=await this.store.patch(e,t);return this.#e(e,s),s.peer}finally{this.log.trace("patch release write lock"),n()}}async merge(e,t){this.log.trace("merge await write lock");let n=await this.store.lock.writeLock();this.log.trace("merge got write lock");try{let s=await this.store.merge(e,t);return this.#e(e,s),s.peer}finally{this.log.trace("merge release write lock"),n()}}async consumePeerRecord(e,t){let n=await Sr.openAndCertify(e,rr.DOMAIN);if(t?.equals(n.peerId)===!1)return this.log("envelope peer id was not the expected peer id - expected: %p received: %p",t,n.peerId),!1;let s=rr.createFromProtobuf(n.payload),i;try{i=await this.get(n.peerId)}catch(o){if(o.code!=="ERR_NOT_FOUND")throw o}if(i?.peerRecordEnvelope!=null){let o=await Sr.createFromProtobuf(i.peerRecordEnvelope),a=rr.createFromProtobuf(o.payload);if(a.seqNumber>=s.seqNumber)return this.log("sequence number was lower or equal to existing sequence number - stored: %d received: %d",a.seqNumber,s.seqNumber),!1}return await this.patch(s.peerId,{peerRecordEnvelope:e,addresses:s.multiaddrs.map(o=>({isCertified:!0,multiaddr:o}))}),!0}#e(e,t){t.updated&&(this.peerId.equals(e)?this.events.safeDispatchEvent("self:peer:update",{detail:t}):this.events.safeDispatchEvent("peer:update",{detail:t}))}};return cu(np);})();
|
|
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:
|