@libp2p/peer-store 11.2.5 → 11.2.6

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 CHANGED
@@ -1,5 +1,5 @@
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 Yn=Object.defineProperty;var Tc=Object.getOwnPropertyDescriptor;var Bc=Object.getOwnPropertyNames;var Dc=Object.prototype.hasOwnProperty;var mt=(r,t)=>{for(var e in t)Yn(r,e,{get:t[e],enumerable:!0})},Rc=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Bc(t))!Dc.call(r,o)&&o!==e&&Yn(r,o,{get:()=>t[o],enumerable:!(n=Tc(t,o))||n.enumerable});return r};var Lc=r=>Rc(Yn({},"__esModule",{value:!0}),r);var Ad={};mt(Ad,{persistentPeerStore:()=>Sd});var Rr=Symbol.for("@libp2p/peer-id");function xe(r){return!!r?.[Rr]}var N=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},we=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Ge=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var Lr=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},Pr=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 Ee=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){super.addEventListener(t,e,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==e),this.#t.set(t,o))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var eo={};mt(eo,{base58btc:()=>H,base58flickr:()=>Mc});var Bd=new Uint8Array(0);function Ys(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 Kt(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 Xs(r){return new TextEncoder().encode(r)}function Qs(r){return new TextDecoder().decode(r)}function Pc(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),l=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function f(w){if(w instanceof Uint8Array||(ArrayBuffer.isView(w)?w=new Uint8Array(w.buffer,w.byteOffset,w.byteLength):Array.isArray(w)&&(w=Uint8Array.from(w))),!(w instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(w.length===0)return"";for(var E=0,p=0,S=0,T=w.length;S!==T&&w[S]===0;)S++,E++;for(var A=(T-S)*u+1>>>0,L=new Uint8Array(A);S!==T;){for(var b=w[S],R=0,D=A-1;(b!==0||R<p)&&D!==-1;D--,R++)b+=256*L[D]>>>0,L[D]=b%a>>>0,b=b/a>>>0;if(b!==0)throw new Error("Non-zero carry");p=R,S++}for(var _=A-p;_!==A&&L[_]===0;)_++;for(var d=c.repeat(E);_<A;++_)d+=r.charAt(L[_]);return d}function h(w){if(typeof w!="string")throw new TypeError("Expected String");if(w.length===0)return new Uint8Array;var E=0;if(w[E]!==" "){for(var p=0,S=0;w[E]===c;)p++,E++;for(var T=(w.length-E)*l+1>>>0,A=new Uint8Array(T);w[E];){var L=e[w.charCodeAt(E)];if(L===255)return;for(var b=0,R=T-1;(L!==0||b<S)&&R!==-1;R--,b++)L+=a*A[R]>>>0,A[R]=L%256>>>0,L=L/256>>>0;if(L!==0)throw new Error("Non-zero carry");S=b,E++}if(w[E]!==" "){for(var D=T-S;D!==T&&A[D]===0;)D++;for(var _=new Uint8Array(p+(T-D)),d=p;D!==T;)_[d++]=A[D++];return _}}}function m(w){var E=h(w);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:h,decode:m}}var Oc=Pc,kc=Oc,ti=kc;var Xn=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")}},Qn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return ei(this,t)}},Jn=class{decoders;constructor(t){this.decoders=t}or(t){return ei(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 ei(r,t){return new Jn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var to=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new Xn(t,e,n),this.decoder=new Qn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ve({name:r,prefix:t,encode:e,decode:n}){return new to(r,t,e,n)}function $t({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=ti(e,r);return ve({prefix:t,name:r,encode:n,decode:s=>Kt(o(s))})}function Kc(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let l=0;l<o;++l){let u=t[r[l]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|u,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Nc(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function Uc(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function $({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=Uc(n);return ve({prefix:t,name:r,encode(s){return Nc(s,n,e)},decode(s){return Kc(s,o,e,r)}})}var H=$t({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Mc=$t({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ro={};mt(ro,{base32:()=>Dt,base32hex:()=>Vc,base32hexpad:()=>Wc,base32hexpadupper:()=>Gc,base32hexupper:()=>Fc,base32pad:()=>zc,base32padupper:()=>Hc,base32upper:()=>qc,base32z:()=>$c});var Dt=$({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),qc=$({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),zc=$({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Hc=$({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Vc=$({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Fc=$({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Wc=$({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Gc=$({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),$c=$({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var no={};mt(no,{base36:()=>$e,base36upper:()=>Zc});var $e=$t({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Zc=$t({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var jc=oi,ri=128,Yc=127,Xc=~Yc,Qc=Math.pow(2,31);function oi(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Qc;)t[e++]=r&255|ri,r/=128;for(;r&Xc;)t[e++]=r&255|ri,r>>>=7;return t[e]=r|0,oi.bytes=e-n+1,t}var Jc=oo,tu=128,ni=127;function oo(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw oo.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&ni)<<o:(i&ni)*Math.pow(2,o),o+=7}while(i>=tu);return oo.bytes=s-n,e}var eu=Math.pow(2,7),ru=Math.pow(2,14),nu=Math.pow(2,21),ou=Math.pow(2,28),su=Math.pow(2,35),iu=Math.pow(2,42),au=Math.pow(2,49),cu=Math.pow(2,56),uu=Math.pow(2,63),lu=function(r){return r<eu?1:r<ru?2:r<nu?3:r<ou?4:r<su?5:r<iu?6:r<au?7:r<cu?8:r<uu?9:10},fu={encode:jc,decode:Jc,encodingLength:lu},du=fu,Ze=du;function je(r,t=0){return[Ze.decode(r,t),Ze.decode.bytes]}function Se(r,t,e=0){return Ze.encode(r,t,e),t}function Ae(r){return Ze.encodingLength(r)}function At(r,t){let e=t.byteLength,n=Ae(r),o=n+Ae(e),s=new Uint8Array(o+e);return Se(r,s,0),Se(e,s,n),s.set(t,o),new Ie(r,e,t,s)}function _e(r){let t=Kt(r),[e,n]=je(t),[o,s]=je(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ie(e,o,i,t)}function si(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Ys(r.bytes,e.bytes)}}var Ie=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function ii(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return pu(e,so(r),t??H.encoder);default:return mu(e,so(r),t??Dt.encoder)}}var ai=new WeakMap;function so(r){let t=ai.get(r);if(t==null){let e=new Map;return ai.set(r,e),e}return t}var Z=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==Ye)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==yu)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=At(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&&si(t.multihash,n.multihash)}toString(t){return ii(this,t)}toJSON(){return{"/":ii(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??ci(n,o,s.bytes))}else if(e[bu]===!0){let{version:n,multihash:o,code:s}=e,i=_e(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==Ye)throw new Error(`Version 0 CID must use dag-pb (code: ${Ye}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=ci(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Ye,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Kt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new Ie(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[f,h]=je(t.subarray(e));return e+=h,f},o=n(),s=Ye;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),l=e+c,u=l-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:l}}static parse(t,e){let[n,o]=hu(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return so(s).set(n,t),s}};function hu(r,t){switch(r[0]){case"Q":{let e=t??H;return[H.prefix,e.decode(`${H.prefix}${r}`)]}case H.prefix:{let e=t??H;return[H.prefix,e.decode(r)]}case Dt.prefix:{let e=t??Dt;return[Dt.prefix,e.decode(r)]}case $e.prefix:{let e=t??$e;return[$e.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function pu(r,t,e){let{prefix:n}=e;if(n!==H.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function mu(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var Ye=112,yu=18;function ci(r,t,e){let n=Ae(r),o=n+Ae(t),s=new Uint8Array(o+e.byteLength);return Se(r,s,0),Se(t,s,n),s.set(e,o),s}var bu=Symbol.for("@ipld/js-cid/CID");var io={};mt(io,{identity:()=>It});var ui=0,gu="identity",li=Kt;function xu(r){return At(ui,li(r))}var It={code:ui,name:gu,encode:li,digest:xu};function V(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 Q(r=0){return new Uint8Array(r)}function yt(r=0){return new Uint8Array(r)}function Nt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=yt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var di=Symbol.for("@achingbrain/uint8arraylist");function fi(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function kr(r){return!!r?.[di]}var ut=class r{bufs;length;[di]=!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(kr(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(kr(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=fi(this.bufs,t);return e.buf[e.index]}set(t,e){let n=fi(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(kr(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return Nt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Nt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let l=t>=a&&t<c,u=e>a&&e<=c;if(l&&u){if(t===a&&e===c){n.push(i);break}let f=t-a;n.push(i.subarray(f,f+(e-t)));break}if(l){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(u){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!kr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,l=n.byteLength-1,u;for(let f=e;f<=c;f+=u){u=0;for(let h=l;h>=0;h--){let m=this.get(f+h);if(n[h]!==m){u=Math.max(1,h-a[m]);break}}if(u===0)return f}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=yt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=Q(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=Q(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=Q(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=yt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=Q(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=Q(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=Q(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=Q(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=Q(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!V(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var ao={};mt(ao,{base10:()=>wu});var wu=$t({prefix:"9",name:"base10",alphabet:"0123456789"});var co={};mt(co,{base16:()=>Eu,base16upper:()=>vu});var Eu=$({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),vu=$({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var uo={};mt(uo,{base2:()=>Su});var Su=$({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var lo={};mt(lo,{base256emoji:()=>Tu});var hi=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}"),Au=hi.reduce((r,t,e)=>(r[e]=t,r),[]),Iu=hi.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function _u(r){return r.reduce((t,e)=>(t+=Au[e],t),"")}function Cu(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Iu[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Tu=ve({prefix:"\u{1F680}",name:"base256emoji",encode:_u,decode:Cu});var ho={};mt(ho,{base64:()=>Bu,base64pad:()=>Du,base64url:()=>fo,base64urlpad:()=>Ru});var Bu=$({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Du=$({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),fo=$({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ru=$({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var po={};mt(po,{base8:()=>Lu});var Lu=$({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var mo={};mt(mo,{identity:()=>Pu});var Pu=ve({prefix:"\0",name:"identity",encode:r=>Qs(r),decode:r=>Xs(r)});var dh=new TextEncoder,hh=new TextDecoder;var go={};mt(go,{sha256:()=>Xe,sha512:()=>Ku});function bo({name:r,code:t,encode:e}){return new yo(r,t,e)}var yo=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?At(this.code,e):e.then(n=>At(this.code,n))}else throw Error("Unknown type, must be binary type")}};function mi(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Xe=bo({name:"sha2-256",code:18,encode:mi("SHA-256")}),Ku=bo({name:"sha2-512",code:19,encode:mi("SHA-512")});var Qe={...mo,...uo,...po,...ao,...co,...ro,...no,...eo,...ho,...lo},Ih={...go,...io};function bi(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var yi=bi("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),xo=bi("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=yt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Nu={utf8:yi,"utf-8":yi,hex:Qe.base16,latin1:xo,ascii:xo,binary:xo,...Qe},Kr=Nu;function U(r,t="utf8"){let e=Kr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function K(r,t="utf8"){let e=Kr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Uu=parseInt("11111",2),wo=parseInt("10000000",2),Mu=parseInt("01111111",2),gi={0:Je,1:Je,2:qu,3:Vu,4:Fu,5:Hu,6:zu,16:Je,22:Je,48:Je};function Ut(r,t={offset:0}){let e=r[t.offset]&Uu;if(t.offset++,gi[e]!=null)return gi[e](r,t);throw new Error("No decoder for tag "+e)}function tr(r,t){let e=0;if((r[t.offset]&wo)===wo){let n=r[t.offset]&Mu,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function Je(r,t){tr(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Ut(r,t);if(n===null)break;e.push(n)}return e}function qu(r,t){let e=tr(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function zu(r,t){let e=tr(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let l=r[t.offset];if(t.offset++,c.push(l&127),l<128){c.reverse();let u=0;for(let f=0;f<c.length;f++)u+=c[f]<<f*7;a+=`.${u}`,c=[]}}return a}function Hu(r,t){return t.offset++,null}function Vu(r,t){let e=tr(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Fu(r,t){let e=tr(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Wu(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new ut;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Eo(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Wu(r.byteLength);return new ut(Uint8Array.from([t.byteLength|wo]),t)}function bt(r){let t=new ut,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new ut(Uint8Array.from([2]),Eo(t),t)}function Nr(r){let t=Uint8Array.from([0]),e=new ut(t,r);return new ut(Uint8Array.from([3]),Eo(e),e)}function jt(r,t=48){let e=new ut;for(let n of r)e.append(n);return new ut(Uint8Array.from([t]),Eo(e),e)}async function xi(r,t,e,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,e.subarray());return n?.signal?.throwIfAborted(),s}var Gu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),$u=Uint8Array.from([6,5,43,129,4,0,34]),Zu=Uint8Array.from([6,5,43,129,4,0,35]),ju={ext:!0,kty:"EC",crv:"P-256"},Yu={ext:!0,kty:"EC",crv:"P-384"},Xu={ext:!0,kty:"EC",crv:"P-521"},vo=32,So=48,Ao=66;function Io(r){let t=Ut(r);return wi(t)}function wi(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===vo*2+1)return n=K(t.subarray(e,e+vo),"base64url"),o=K(t.subarray(e+vo),"base64url"),new Ce({...ju,key_ops:["verify"],x:n,y:o});if(t.byteLength===So*2+1)return n=K(t.subarray(e,e+So),"base64url"),o=K(t.subarray(e+So),"base64url"),new Ce({...Yu,key_ops:["verify"],x:n,y:o});if(t.byteLength===Ao*2+1)return n=K(t.subarray(e,e+Ao),"base64url"),o=K(t.subarray(e+Ao),"base64url"),new Ce({...Xu,key_ops:["verify"],x:n,y:o});throw new N(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Ei(r){return jt([bt(Uint8Array.from([1])),jt([Qu(r.crv)],160),jt([Nr(new ut(Uint8Array.from([4]),U(r.x??"","base64url"),U(r.y??"","base64url")))],161)]).subarray()}function Qu(r){if(r==="P-256")return Gu;if(r==="P-384")return $u;if(r==="P-521")return Zu;throw new N(`Invalid curve ${r}`)}var Ce=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Ei(this.jwk)),this._raw}toMultihash(){return It.digest(Et(this))}toCID(){return Z.createV1(114,this.toMultihash())}toString(){return H.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:V(this.raw,t.raw)}async verify(t,e,n){return xi(this.jwk,e,t,n)}};var oe=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Be(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function er(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function st(r,...t){if(!Be(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error("Uint8Array expected of length "+t+", got length="+r.length)}function Si(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");er(r.outputLen),er(r.blockLen)}function De(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 Ai(r,t){st(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}function qt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Ur(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function _t(r,t){return r<<32-t|r>>>t}var Ii=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Ju=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Rt(r){if(st(r),Ii)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=Ju[r[e]];return t}var Mt={_0:48,_9:57,A:65,F:70,a:97,f:102};function vi(r){if(r>=Mt._0&&r<=Mt._9)return r-Mt._0;if(r>=Mt.A&&r<=Mt.F)return r-(Mt.A-10);if(r>=Mt.a&&r<=Mt.f)return r-(Mt.a-10)}function Re(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(Ii)return Uint8Array.fromHex(r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=vi(r.charCodeAt(s)),a=vi(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function _i(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function rr(r){return typeof r=="string"&&(r=_i(r)),st(r),r}function gt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];st(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}var Te=class{};function _o(r){let t=n=>r().update(rr(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function nr(r=32){if(oe&&typeof oe.getRandomValues=="function")return oe.getRandomValues(new Uint8Array(r));if(oe&&typeof oe.randomBytes=="function")return Uint8Array.from(oe.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function tl(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(e>>o&s),a=Number(e&s),c=n?4:0,l=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+l,a,n)}function Ci(r,t,e){return r&t^~r&e}function Ti(r,t,e){return r&t^r&e^t&e}var or=class extends Te{constructor(t,e,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Ur(this.buffer)}update(t){De(this),t=rr(t),st(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Ur(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){De(this),Ai(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,qt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)e[f]=0;tl(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=Ur(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=c/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<l;f++)a.setUint32(4*f,u[f],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},zt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var et=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Mr=BigInt(4294967295),Bi=BigInt(32);function el(r,t=!1){return t?{h:Number(r&Mr),l:Number(r>>Bi&Mr)}:{h:Number(r>>Bi&Mr)|0,l:Number(r&Mr)|0}}function Di(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:a}=el(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Co=(r,t,e)=>r>>>e,To=(r,t,e)=>r<<32-e|t>>>e,se=(r,t,e)=>r>>>e|t<<32-e,ie=(r,t,e)=>r<<32-e|t>>>e,sr=(r,t,e)=>r<<64-e|t>>>e-32,ir=(r,t,e)=>r>>>e-32|t<<64-e;function Lt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Ri=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Li=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Pi=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Oi=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,ki=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Ki=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var nl=Uint32Array.from([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]),Yt=new Uint32Array(64),qr=class extends or{constructor(t=32){super(64,t,8,!1),this.A=zt[0]|0,this.B=zt[1]|0,this.C=zt[2]|0,this.D=zt[3]|0,this.E=zt[4]|0,this.F=zt[5]|0,this.G=zt[6]|0,this.H=zt[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let f=0;f<16;f++,e+=4)Yt[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let h=Yt[f-15],m=Yt[f-2],w=_t(h,7)^_t(h,18)^h>>>3,E=_t(m,17)^_t(m,19)^m>>>10;Yt[f]=E+Yt[f-7]+w+Yt[f-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:l,H:u}=this;for(let f=0;f<64;f++){let h=_t(a,6)^_t(a,11)^_t(a,25),m=u+h+Ci(a,c,l)+nl[f]+Yt[f]|0,E=(_t(n,2)^_t(n,13)^_t(n,22))+Ti(n,o,s)|0;u=l,l=c,c=a,a=i+m|0,i=s,s=o,o=n,n=m+E|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,u=u+this.H|0,this.set(n,o,s,i,a,c,l,u)}roundClean(){qt(Yt)}destroy(){this.set(0,0,0,0,0,0,0,0),qt(this.buffer)}};var Ni=Di(["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))),ol=Ni[0],sl=Ni[1],Xt=new Uint32Array(80),Qt=new Uint32Array(80),Bo=class extends or{constructor(t=64){super(128,t,16,!1),this.Ah=et[0]|0,this.Al=et[1]|0,this.Bh=et[2]|0,this.Bl=et[3]|0,this.Ch=et[4]|0,this.Cl=et[5]|0,this.Dh=et[6]|0,this.Dl=et[7]|0,this.Eh=et[8]|0,this.El=et[9]|0,this.Fh=et[10]|0,this.Fl=et[11]|0,this.Gh=et[12]|0,this.Gl=et[13]|0,this.Hh=et[14]|0,this.Hl=et[15]|0}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:l,El:u,Fh:f,Fl:h,Gh:m,Gl:w,Hh:E,Hl:p}=this;return[t,e,n,o,s,i,a,c,l,u,f,h,m,w,E,p]}set(t,e,n,o,s,i,a,c,l,u,f,h,m,w,E,p){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=l|0,this.El=u|0,this.Fh=f|0,this.Fl=h|0,this.Gh=m|0,this.Gl=w|0,this.Hh=E|0,this.Hl=p|0}process(t,e){for(let A=0;A<16;A++,e+=4)Xt[A]=t.getUint32(e),Qt[A]=t.getUint32(e+=4);for(let A=16;A<80;A++){let L=Xt[A-15]|0,b=Qt[A-15]|0,R=se(L,b,1)^se(L,b,8)^Co(L,b,7),D=ie(L,b,1)^ie(L,b,8)^To(L,b,7),_=Xt[A-2]|0,d=Qt[A-2]|0,x=se(_,d,19)^sr(_,d,61)^Co(_,d,6),y=ie(_,d,19)^ir(_,d,61)^To(_,d,6),g=Pi(D,y,Qt[A-7],Qt[A-16]),v=Oi(g,R,x,Xt[A-7],Xt[A-16]);Xt[A]=v|0,Qt[A]=g|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:l,Dl:u,Eh:f,El:h,Fh:m,Fl:w,Gh:E,Gl:p,Hh:S,Hl:T}=this;for(let A=0;A<80;A++){let L=se(f,h,14)^se(f,h,18)^sr(f,h,41),b=ie(f,h,14)^ie(f,h,18)^ir(f,h,41),R=f&m^~f&E,D=h&w^~h&p,_=ki(T,b,D,sl[A],Qt[A]),d=Ki(_,S,L,R,ol[A],Xt[A]),x=_|0,y=se(n,o,28)^sr(n,o,34)^sr(n,o,39),g=ie(n,o,28)^ir(n,o,34)^ir(n,o,39),v=n&s^n&a^s&a,C=o&i^o&c^i&c;S=E|0,T=p|0,E=m|0,p=w|0,m=f|0,w=h|0,{h:f,l:h}=Lt(l|0,u|0,d|0,x|0),l=a|0,u=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let I=Ri(x,g,C);n=Li(I,d,y,v),o=I|0}({h:n,l:o}=Lt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Lt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Lt(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:u}=Lt(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:h}=Lt(this.Eh|0,this.El|0,f|0,h|0),{h:m,l:w}=Lt(this.Fh|0,this.Fl|0,m|0,w|0),{h:E,l:p}=Lt(this.Gh|0,this.Gl|0,E|0,p|0),{h:S,l:T}=Lt(this.Hh|0,this.Hl|0,S|0,T|0),this.set(n,o,s,i,a,c,l,u,f,h,m,w,E,p,S,T)}roundClean(){qt(Xt,Qt)}destroy(){qt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var zr=_o(()=>new qr);var Ui=_o(()=>new Bo);var Lo=BigInt(0),Ro=BigInt(1);function Ht(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function ar(r){let t=r.toString(16);return t.length&1?"0"+t:t}function Mi(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Lo:BigInt("0x"+r)}function Le(r){return Mi(Rt(r))}function ae(r){return st(r),Mi(Rt(Uint8Array.from(r).reverse()))}function Hr(r,t){return Re(r.toString(16).padStart(t*2,"0"))}function Pe(r,t){return Hr(r,t).reverse()}function F(r,t,e){let n;if(typeof t=="string")try{n=Re(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(Be(t))n=Uint8Array.from(t);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof e=="number"&&o!==e)throw new Error(r+" of length "+e+" expected, got "+o);return n}var Do=r=>typeof r=="bigint"&&Lo<=r;function qi(r,t,e){return Do(r)&&Do(t)&&Do(e)&&t<=r&&r<e}function Jt(r,t,e,n){if(!qi(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function zi(r){let t;for(t=0;r>Lo;r>>=Ro,t+=1);return t}var ce=r=>(Ro<<BigInt(r))-Ro;function Hi(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=m=>new Uint8Array(m),o=m=>Uint8Array.of(m),s=n(r),i=n(r),a=0,c=()=>{s.fill(1),i.fill(0),a=0},l=(...m)=>e(i,s,...m),u=(m=n(0))=>{i=l(o(0),m),s=l(),m.length!==0&&(i=l(o(1),m),s=l())},f=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let m=0,w=[];for(;m<t;){s=l();let E=s.slice();w.push(E),m+=s.length}return gt(...w)};return(m,w)=>{c(),u(m);let E;for(;!(E=w(f()));)u();return c(),E}}function te(r,t,e={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(o,s,i){let a=r[o];if(i&&a===void 0)return;let c=typeof a;if(c!==s||a===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${c}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(e).forEach(([o,s])=>n(o,s,!0))}function Oe(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var lt=BigInt(0),tt=BigInt(1),ue=BigInt(2),il=BigInt(3),Wi=BigInt(4),Gi=BigInt(5),$i=BigInt(8);function G(r,t){let e=r%t;return e>=lt?e:t+e}function W(r,t,e){let n=r;for(;t-- >lt;)n*=n,n%=e;return n}function Vi(r,t){if(r===lt)throw new Error("invert: expected non-zero number");if(t<=lt)throw new Error("invert: expected positive modulus, got "+t);let e=G(r,t),n=t,o=lt,s=tt,i=tt,a=lt;for(;e!==lt;){let l=n/e,u=n%e,f=o-i*l,h=s-a*l;n=e,e=u,o=i,s=a,i=f,a=h}if(n!==tt)throw new Error("invert: does not exist");return G(o,t)}function Zi(r,t){let e=(r.ORDER+tt)/Wi,n=r.pow(t,e);if(!r.eql(r.sqr(n),t))throw new Error("Cannot find square root");return n}function al(r,t){let e=(r.ORDER-Gi)/$i,n=r.mul(t,ue),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,ue),o),a=r.mul(s,r.sub(i,r.ONE));if(!r.eql(r.sqr(a),t))throw new Error("Cannot find square root");return a}function cl(r){if(r<BigInt(3))throw new Error("sqrt is not defined for small field");let t=r-tt,e=0;for(;t%ue===lt;)t/=ue,e++;let n=ue,o=Ct(r);for(;Fi(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return Zi;let s=o.pow(n,t),i=(t+tt)/ue;return function(c,l){if(c.is0(l))return l;if(Fi(c,l)!==1)throw new Error("Cannot find square root");let u=e,f=c.mul(c.ONE,s),h=c.pow(l,t),m=c.pow(l,i);for(;!c.eql(h,c.ONE);){if(c.is0(h))return c.ZERO;let w=1,E=c.sqr(h);for(;!c.eql(E,c.ONE);)if(w++,E=c.sqr(E),w===u)throw new Error("Cannot find square root");let p=tt<<BigInt(u-w-1),S=c.pow(f,p);u=w,f=c.sqr(S),h=c.mul(h,f),m=c.mul(m,S)}return m}}function ul(r){return r%Wi===il?Zi:r%$i===Gi?al:cl(r)}var ji=(r,t)=>(G(r,t)&tt)===tt,ll=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Po(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},e=ll.reduce((n,o)=>(n[o]="function",n),t);return te(r,e),r}function fl(r,t,e){if(e<lt)throw new Error("invalid exponent, negatives unsupported");if(e===lt)return r.ONE;if(e===tt)return t;let n=r.ONE,o=t;for(;e>lt;)e&tt&&(n=r.mul(n,o)),o=r.sqr(o),e>>=tt;return n}function cr(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,a,c)=>r.is0(a)?i:(n[c]=i,r.mul(i,a)),r.ONE),s=r.inv(o);return t.reduceRight((i,a,c)=>r.is0(a)?i:(n[c]=r.mul(i,n[c]),r.mul(i,a)),s),n}function Fi(r,t){let e=(r.ORDER-tt)/ue,n=r.pow(t,e),o=r.eql(n,r.ONE),s=r.eql(n,r.ZERO),i=r.eql(n,r.neg(r.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Yi(r,t){t!==void 0&&er(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Ct(r,t,e=!1,n={}){if(r<=lt)throw new Error("invalid field: expected ORDER > 0, got "+r);let o,s;if(typeof t=="object"&&t!=null){if(n.sqrt||e)throw new Error("cannot specify opts in two arguments");let u=t;u.BITS&&(o=u.BITS),u.sqrt&&(s=u.sqrt),typeof u.isLE=="boolean"&&(e=u.isLE)}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:i,nByteLength:a}=Yi(r,o);if(a>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let c,l=Object.freeze({ORDER:r,isLE:e,BITS:i,BYTES:a,MASK:ce(i),ZERO:lt,ONE:tt,create:u=>G(u,r),isValid:u=>{if(typeof u!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof u);return lt<=u&&u<r},is0:u=>u===lt,isValidNot0:u=>!l.is0(u)&&l.isValid(u),isOdd:u=>(u&tt)===tt,neg:u=>G(-u,r),eql:(u,f)=>u===f,sqr:u=>G(u*u,r),add:(u,f)=>G(u+f,r),sub:(u,f)=>G(u-f,r),mul:(u,f)=>G(u*f,r),pow:(u,f)=>fl(l,u,f),div:(u,f)=>G(u*Vi(f,r),r),sqrN:u=>u*u,addN:(u,f)=>u+f,subN:(u,f)=>u-f,mulN:(u,f)=>u*f,inv:u=>Vi(u,r),sqrt:s||(u=>(c||(c=ul(r)),c(l,u))),toBytes:u=>e?Pe(u,a):Hr(u,a),fromBytes:u=>{if(u.length!==a)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+u.length);return e?ae(u):Le(u)},invertBatch:u=>cr(l,u),cmov:(u,f,h)=>h?f:u});return Object.freeze(l)}function Xi(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 Oo(r){let t=Xi(r);return t+Math.ceil(t/2)}function Qi(r,t,e=!1){let n=r.length,o=Xi(t),s=Oo(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?ae(r):Le(r),a=G(i,t-tt)+tt;return e?Pe(a,o):Hr(a,o)}var Ke=BigInt(0),le=BigInt(1);function ke(r,t){let e=t.negate();return r?e:t}function Vr(r,t,e){let n=t==="pz"?i=>i.pz:i=>i.ez,o=cr(r.Fp,e.map(n));return e.map((i,a)=>i.toAffine(o[a])).map(r.fromAffine)}function ra(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function ko(r,t){ra(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=ce(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Ji(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),c=r>>i;a>n&&(a-=s,c+=le);let l=t*n,u=l+Math.abs(a)-1,f=a===0,h=a<0,m=t%2!==0;return{nextN:c,offset:u,isZero:f,isNeg:h,isNegF:m,offsetF:l}}function dl(r,t){if(!Array.isArray(r))throw new Error("array expected");r.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})}function hl(r,t){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}var Ko=new WeakMap,na=new WeakMap;function No(r){return na.get(r)||1}function ta(r){if(r!==Ke)throw new Error("invalid wNAF")}function Fr(r,t){return{constTimeNegate:ke,hasPrecomputes(e){return No(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>Ke;)n&le&&(o=o.add(s)),s=s.double(),n>>=le;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=ko(n,t),i=[],a=e,c=a;for(let l=0;l<o;l++){c=a,i.push(c);for(let u=1;u<s;u++)c=c.add(a),i.push(c);a=c.double()}return i},wNAF(e,n,o){let s=r.ZERO,i=r.BASE,a=ko(e,t);for(let c=0;c<a.windows;c++){let{nextN:l,offset:u,isZero:f,isNeg:h,isNegF:m,offsetF:w}=Ji(o,c,a);o=l,f?i=i.add(ke(m,n[w])):s=s.add(ke(h,n[u]))}return ta(o),{p:s,f:i}},wNAFUnsafe(e,n,o,s=r.ZERO){let i=ko(e,t);for(let a=0;a<i.windows&&o!==Ke;a++){let{nextN:c,offset:l,isZero:u,isNeg:f}=Ji(o,a,i);if(o=c,!u){let h=n[l];s=s.add(f?h.negate():h)}}return ta(o),s},getPrecomputes(e,n,o){let s=Ko.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&(typeof o=="function"&&(s=o(s)),Ko.set(n,s))),s},wNAFCached(e,n,o){let s=No(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=No(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){ra(n,t),na.set(e,n),Ko.delete(e)}}}function oa(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>Ke||n>Ke;)e&le&&(s=s.add(o)),n&le&&(i=i.add(o)),o=o.double(),e>>=le,n>>=le;return{p1:s,p2:i}}function Wr(r,t,e,n){dl(e,r),hl(n,t);let o=e.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=r.ZERO,a=zi(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let l=ce(c),u=new Array(Number(l)+1).fill(i),f=Math.floor((t.BITS-1)/c)*c,h=i;for(let m=f;m>=0;m-=c){u.fill(i);for(let E=0;E<s;E++){let p=n[E],S=Number(p>>BigInt(m)&l);u[S]=u[S].add(e[E])}let w=i;for(let E=u.length-1,p=i;E>0;E--)p=p.add(u[E]),w=w.add(p);if(h=h.add(w),m!==0)for(let E=0;E<c;E++)h=h.double()}return h}function ea(r,t){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Po(t),t}else return Ct(r)}function Gr(r,t,e={}){if(!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let a of["p","n","h"]){let c=t[a];if(!(typeof c=="bigint"&&c>Ke))throw new Error(`CURVE.${a} must be positive bigint`)}let n=ea(t.p,e.Fp),o=ea(t.n,e.Fn),i=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let a of i)if(!n.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return{Fp:n,Fn:o}}var Pt=BigInt(0),ft=BigInt(1),Uo=BigInt(2),pl=BigInt(8),ml={zip215:!0};function yl(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),a=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,a)}function bl(r,t={}){let{Fp:e,Fn:n}=Gr("edwards",r,t),{h:o,n:s}=r;te(t,{},{uvRatio:"function"});let i=Uo<<BigInt(n.BYTES*8)-ft,a=E=>e.create(E),c=t.uvRatio||((E,p)=>{try{return{isValid:!0,value:e.sqrt(e.div(E,p))}}catch{return{isValid:!1,value:Pt}}});if(!yl(e,r,r.Gx,r.Gy))throw new Error("bad curve params: generator point");function l(E,p,S=!1){let T=S?ft:Pt;return Jt("coordinate "+E,p,T,i),p}function u(E){if(!(E instanceof m))throw new Error("ExtendedPoint expected")}let f=Oe((E,p)=>{let{ex:S,ey:T,ez:A}=E,L=E.is0();p==null&&(p=L?pl:e.inv(A));let b=a(S*p),R=a(T*p),D=a(A*p);if(L)return{x:Pt,y:ft};if(D!==ft)throw new Error("invZ was invalid");return{x:b,y:R}}),h=Oe(E=>{let{a:p,d:S}=r;if(E.is0())throw new Error("bad point: ZERO");let{ex:T,ey:A,ez:L,et:b}=E,R=a(T*T),D=a(A*A),_=a(L*L),d=a(_*_),x=a(R*p),y=a(_*a(x+D)),g=a(d+a(S*a(R*D)));if(y!==g)throw new Error("bad point: equation left != right (1)");let v=a(T*A),C=a(L*b);if(v!==C)throw new Error("bad point: equation left != right (2)");return!0});class m{constructor(p,S,T,A){this.ex=l("x",p),this.ey=l("y",S),this.ez=l("z",T,!0),this.et=l("t",A),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:S,y:T}=p||{};return l("x",S),l("y",T),new m(S,T,ft,a(S*T))}static normalizeZ(p){return Vr(m,"ez",p)}static msm(p,S){return Wr(m,n,p,S)}_setWindowSize(p){this.precompute(p)}precompute(p=8,S=!0){return w.setWindowSize(this,p),S||this.multiply(Uo),this}assertValidity(){h(this)}equals(p){u(p);let{ex:S,ey:T,ez:A}=this,{ex:L,ey:b,ez:R}=p,D=a(S*R),_=a(L*A),d=a(T*R),x=a(b*A);return D===_&&d===x}is0(){return this.equals(m.ZERO)}negate(){return new m(a(-this.ex),this.ey,this.ez,a(-this.et))}double(){let{a:p}=r,{ex:S,ey:T,ez:A}=this,L=a(S*S),b=a(T*T),R=a(Uo*a(A*A)),D=a(p*L),_=S+T,d=a(a(_*_)-L-b),x=D+b,y=x-R,g=D-b,v=a(d*y),C=a(x*g),I=a(d*g),B=a(y*x);return new m(v,C,B,I)}add(p){u(p);let{a:S,d:T}=r,{ex:A,ey:L,ez:b,et:R}=this,{ex:D,ey:_,ez:d,et:x}=p,y=a(A*D),g=a(L*_),v=a(R*T*x),C=a(b*d),I=a((A+L)*(D+_)-y-g),B=C-v,O=C+v,P=a(g-S*y),j=a(I*B),q=a(O*P),k=a(I*P),X=a(B*O);return new m(j,q,X,k)}subtract(p){return this.add(p.negate())}multiply(p){let S=p;Jt("scalar",S,ft,s);let{p:T,f:A}=w.wNAFCached(this,S,m.normalizeZ);return m.normalizeZ([T,A])[0]}multiplyUnsafe(p,S=m.ZERO){let T=p;return Jt("scalar",T,Pt,s),T===Pt?m.ZERO:this.is0()||T===ft?this:w.wNAFCachedUnsafe(this,T,m.normalizeZ,S)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return w.wNAFCachedUnsafe(this,s).is0()}toAffine(p){return f(this,p)}clearCofactor(){return o===ft?this:this.multiplyUnsafe(o)}static fromBytes(p,S=!1){return st(p),this.fromHex(p,S)}static fromHex(p,S=!1){let{d:T,a:A}=r,L=e.BYTES;p=F("pointHex",p,L),Ht("zip215",S);let b=p.slice(),R=p[L-1];b[L-1]=R&-129;let D=ae(b),_=S?i:e.ORDER;Jt("pointHex.y",D,Pt,_);let d=a(D*D),x=a(d-ft),y=a(T*d-A),{isValid:g,value:v}=c(x,y);if(!g)throw new Error("Point.fromHex: invalid y coordinate");let C=(v&ft)===ft,I=(R&128)!==0;if(!S&&v===Pt&&I)throw new Error("Point.fromHex: x=0 and x_0=1");return I!==C&&(v=a(-v)),m.fromAffine({x:v,y:D})}static fromPrivateScalar(p){return m.BASE.multiply(p)}toBytes(){let{x:p,y:S}=this.toAffine(),T=Pe(S,e.BYTES);return T[T.length-1]|=p&ft?128:0,T}toRawBytes(){return this.toBytes()}toHex(){return Rt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}m.BASE=new m(r.Gx,r.Gy,ft,a(r.Gx*r.Gy)),m.ZERO=new m(Pt,ft,ft,Pt),m.Fp=e,m.Fn=n;let w=Fr(m,n.BYTES*8);return m}function gl(r,t){te(t,{hash:"function"},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:e,hash:n}=t,{BASE:o,Fp:s,Fn:i}=r,a=i.ORDER,c=t.randomBytes||nr,l=t.adjustScalarBytes||(b=>b),u=t.domain||((b,R,D)=>{if(Ht("phflag",D),R.length||D)throw new Error("Contexts/pre-hash are not supported");return b});function f(b){return i.create(b)}function h(b){return f(ae(b))}function m(b){let R=s.BYTES;b=F("private key",b,R);let D=F("hashed private key",n(b),2*R),_=l(D.slice(0,R)),d=D.slice(R,2*R),x=h(_);return{head:_,prefix:d,scalar:x}}function w(b){let{head:R,prefix:D,scalar:_}=m(b),d=o.multiply(_),x=d.toBytes();return{head:R,prefix:D,scalar:_,point:d,pointBytes:x}}function E(b){return w(b).pointBytes}function p(b=Uint8Array.of(),...R){let D=gt(...R);return h(n(u(D,F("context",b),!!e)))}function S(b,R,D={}){b=F("message",b),e&&(b=e(b));let{prefix:_,scalar:d,pointBytes:x}=w(R),y=p(D.context,_,b),g=o.multiply(y).toBytes(),v=p(D.context,g,x,b),C=f(y+v*d);Jt("signature.s",C,Pt,a);let I=s.BYTES,B=gt(g,Pe(C,I));return F("result",B,I*2)}let T=ml;function A(b,R,D,_=T){let{context:d,zip215:x}=_,y=s.BYTES;b=F("signature",b,2*y),R=F("message",R),D=F("publicKey",D,y),x!==void 0&&Ht("zip215",x),e&&(R=e(R));let g=ae(b.slice(y,2*y)),v,C,I;try{v=r.fromHex(D,x),C=r.fromHex(b.slice(0,y),x),I=o.multiplyUnsafe(g)}catch{return!1}if(!x&&v.isSmallOrder())return!1;let B=p(d,C.toBytes(),v.toBytes(),R);return C.add(v.multiplyUnsafe(B)).subtract(I).clearCofactor().is0()}return o.precompute(8),{getPublicKey:E,sign:S,verify:A,utils:{getExtendedPublicKey:w,randomPrivateKey:()=>c(s.BYTES),precompute(b=8,R=r.BASE){return R.precompute(b,!1)}},Point:r}}function xl(r){let t={a:r.a,d:r.d,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},e=r.Fp,n=Ct(t.n,r.nBitLength,!0),o={Fp:e,Fn:n,uvRatio:r.uvRatio},s={hash:r.hash,randomBytes:r.randomBytes,adjustScalarBytes:r.adjustScalarBytes,domain:r.domain,prehash:r.prehash,mapToCurve:r.mapToCurve};return{CURVE:t,curveOpts:o,eddsaOpts:s}}function wl(r,t){return Object.assign({},t,{ExtendedPoint:t.Point,CURVE:r})}function sa(r){let{CURVE:t,curveOpts:e,eddsaOpts:n}=xl(r),o=bl(t,e),s=gl(o,n);return wl(r,s)}var Dp=BigInt(0),El=BigInt(1),ia=BigInt(2),Rp=BigInt(3),vl=BigInt(5),Sl=BigInt(8),$r={p:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Sl,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Al(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=$r.p,a=r*r%s*r%s,c=W(a,ia,s)*a%s,l=W(c,El,s)*r%s,u=W(l,vl,s)*l%s,f=W(u,t,s)*u%s,h=W(f,e,s)*f%s,m=W(h,n,s)*h%s,w=W(m,o,s)*m%s,E=W(w,o,s)*m%s,p=W(E,t,s)*u%s;return{pow_p_5_8:W(p,ia,s)*r%s,b2:a}}function Il(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var aa=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function _l(r,t){let e=$r.p,n=G(t*t*t,e),o=G(n*n*t,e),s=Al(r*o).pow_p_5_8,i=G(r*n*s,e),a=G(t*i*i,e),c=i,l=G(i*aa,e),u=a===r,f=a===G(-r,e),h=a===G(-r*aa,e);return u&&(i=c),(f||h)&&(i=l),ji(i,e)&&(i=G(-i,e)),{isValid:u||f,value:i}}var Cl=Ct($r.p,void 0,!0),Tl={...$r,Fp:Cl,hash:Ui,adjustScalarBytes:Il,uvRatio:_l},ca=sa(Tl);var ur=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Zr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var ua={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Zr("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 vt=ua;var jr=32;var Mo,Bl=(async()=>{try{return await vt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Dl(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await vt.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await vt.get().subtle.verify({name:"Ed25519"},n,t,e instanceof Uint8Array?e:e.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Rl(r,t,e){return ca.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function la(r,t,e){return Mo==null&&(Mo=await Bl),Mo?Dl(r,t,e):Rl(r,t,e)}function Yr(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Xr=class{type="Ed25519";raw;constructor(t){this.raw=qo(t,jr)}toMultihash(){return It.digest(Et(this))}toCID(){return Z.createV1(114,this.toMultihash())}toString(){return H.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:V(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=la(this.raw,e,t);return Yr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function zo(r){return r=qo(r,jr),new Xr(r)}function qo(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new N(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var Pl=Math.pow(2,7),Ol=Math.pow(2,14),kl=Math.pow(2,21),Ho=Math.pow(2,28),Vo=Math.pow(2,35),Fo=Math.pow(2,42),Wo=Math.pow(2,49),M=128,it=127;function St(r){if(r<Pl)return 1;if(r<Ol)return 2;if(r<kl)return 3;if(r<Ho)return 4;if(r<Vo)return 5;if(r<Fo)return 6;if(r<Wo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ne(r,t,e=0){switch(St(r)){case 8:t[e++]=r&255|M,r/=128;case 7:t[e++]=r&255|M,r/=128;case 6:t[e++]=r&255|M,r/=128;case 5:t[e++]=r&255|M,r/=128;case 4:t[e++]=r&255|M,r>>>=7;case 3:t[e++]=r&255|M,r>>>=7;case 2:t[e++]=r&255|M,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Kl(r,t,e=0){switch(St(r)){case 8:t.set(e++,r&255|M),r/=128;case 7:t.set(e++,r&255|M),r/=128;case 6:t.set(e++,r&255|M),r/=128;case 5:t.set(e++,r&255|M),r/=128;case 4:t.set(e++,r&255|M),r>>>=7;case 3:t.set(e++,r&255|M),r>>>=7;case 2:t.set(e++,r&255|M),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Go(r,t){let e=r[t],n=0;if(n+=e&it,e<M||(e=r[t+1],n+=(e&it)<<7,e<M)||(e=r[t+2],n+=(e&it)<<14,e<M)||(e=r[t+3],n+=(e&it)<<21,e<M)||(e=r[t+4],n+=(e&it)*Ho,e<M)||(e=r[t+5],n+=(e&it)*Vo,e<M)||(e=r[t+6],n+=(e&it)*Fo,e<M)||(e=r[t+7],n+=(e&it)*Wo,e<M))return n;throw new RangeError("Could not decode varint")}function Nl(r,t){let e=r.get(t),n=0;if(n+=e&it,e<M||(e=r.get(t+1),n+=(e&it)<<7,e<M)||(e=r.get(t+2),n+=(e&it)<<14,e<M)||(e=r.get(t+3),n+=(e&it)<<21,e<M)||(e=r.get(t+4),n+=(e&it)*Ho,e<M)||(e=r.get(t+5),n+=(e&it)*Vo,e<M)||(e=r.get(t+6),n+=(e&it)*Fo,e<M)||(e=r.get(t+7),n+=(e&it)*Wo,e<M))return n;throw new RangeError("Could not decode varint")}function Qr(r,t,e=0){return t==null&&(t=yt(St(r))),t instanceof Uint8Array?Ne(r,t,e):Kl(r,t,e)}function $o(r,t=0){return r instanceof Uint8Array?Go(r,t):Nl(r,t)}var Zo=new Float32Array([-0]),ee=new Uint8Array(Zo.buffer);function ha(r,t,e){Zo[0]=r,t[e]=ee[0],t[e+1]=ee[1],t[e+2]=ee[2],t[e+3]=ee[3]}function pa(r,t){return ee[0]=r[t],ee[1]=r[t+1],ee[2]=r[t+2],ee[3]=r[t+3],Zo[0]}var jo=new Float64Array([-0]),at=new Uint8Array(jo.buffer);function ma(r,t,e){jo[0]=r,t[e]=at[0],t[e+1]=at[1],t[e+2]=at[2],t[e+3]=at[3],t[e+4]=at[4],t[e+5]=at[5],t[e+6]=at[6],t[e+7]=at[7]}function ya(r,t){return at[0]=r[t],at[1]=r[t+1],at[2]=r[t+2],at[3]=r[t+3],at[4]=r[t+4],at[5]=r[t+5],at[6]=r[t+6],at[7]=r[t+7],jo[0]}var Ul=BigInt(Number.MAX_SAFE_INTEGER),Ml=BigInt(Number.MIN_SAFE_INTEGER),xt=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 fe;if(t<Ul&&t>Ml)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>ba&&(o=0n,++n>ba&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return fe;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):fe}},fe=new xt(0,0);fe.toBigInt=function(){return 0n};fe.zzEncode=fe.zzDecode=function(){return this};fe.length=function(){return 1};var ba=4294967296n;function ga(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function xa(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(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,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Yo(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function Tt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Jr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Xo=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,Tt(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 Tt(this,4);return Jr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Tt(this,4);return Jr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Tt(this,4);let t=pa(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Tt(this,4);let t=ya(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 Tt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return xa(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Tt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Tt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new xt(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 Tt(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 Tt(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 Tt(this,8);let t=Jr(this.buf,this.pos+=4),e=Jr(this.buf,this.pos+=4);return new xt(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=Go(this.buf,this.pos);return this.pos+=St(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 Qo(r){return new Xo(r instanceof Uint8Array?r:r.subarray())}function dt(r,t,e){let n=Qo(r);return t.decode(n,void 0,e)}function Jo(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return yt(i);o+i>t&&(n=yt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var de=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function ts(){}var rs=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},ql=Jo();function zl(r){return globalThis.Buffer!=null?yt(r):ql(r)}var fr=class{len;head;tail;states;constructor(){this.len=0,this.head=new de(ts,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new de(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new ns((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(tn,10,xt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=xt.fromBigInt(t);return this._push(tn,e.length(),e)}uint64Number(t){return this._push(Ne,St(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=xt.fromBigInt(t).zzEncode();return this._push(tn,e.length(),e)}sint64Number(t){let e=xt.fromNumber(t).zzEncode();return this._push(tn,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(es,1,t?1:0)}fixed32(t){return this._push(lr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=xt.fromBigInt(t);return this._push(lr,4,e.lo)._push(lr,4,e.hi)}fixed64Number(t){let e=xt.fromNumber(t);return this._push(lr,4,e.lo)._push(lr,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(ha,4,t)}double(t){return this._push(ma,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(es,1,0):this.uint32(e)._push(Vl,e,t)}string(t){let e=ga(t);return e!==0?this.uint32(e)._push(Yo,e,t):this._push(es,1,0)}fork(){return this.states=new rs(this),this.head=this.tail=new de(ts,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 de(ts,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=zl(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function es(r,t,e){t[e]=r&255}function Hl(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var ns=class extends de{next;constructor(t,e){super(Hl,t,e),this.next=void 0}};function tn(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 lr(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 Vl(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(fr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Fl,t,r),this},fr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Wl,t,r),this});function Fl(r,t,e){t.set(r,e)}function Wl(r,t,e){r.length<40?Yo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(U(r),e)}function os(){return new fr}function ht(r,t){let e=os();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Ue;(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"})(Ue||(Ue={}));function en(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function ss(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return en("enum",Ue.VARINT,e,n)}function pt(r,t){return en("message",Ue.LENGTH_DELIMITED,r,t)}var he=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"},dr=class extends Error{code="ERR_MAX_SIZE";name="MaxSizeError"};var Y;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(Y||(Y={}));var is;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(is||(is={}));(function(r){r.codec=()=>ss(is)})(Y||(Y={}));var Ot;(function(r){let t;r.codec=()=>(t==null&&(t=pt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),Y.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=Y.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>ht(e,r.codec()),r.decode=(e,n)=>dt(e,r.codec(),n)})(Ot||(Ot={}));var as;(function(r){let t;r.codec=()=>(t==null&&(t=pt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),Y.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=Y.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>ht(e,r.codec()),r.decode=(e,n)=>dt(e,r.codec(),n)})(as||(as={}));var pr={};mt(pr,{MAX_RSA_KEY_SIZE:()=>cs,generateRSAKeyPair:()=>Ia,jwkToJWKKeyPair:()=>_a,jwkToPkcs1:()=>jl,jwkToPkix:()=>ds,jwkToRSAPrivateKey:()=>ys,pkcs1MessageToJwk:()=>ls,pkcs1MessageToRSAPrivateKey:()=>hs,pkcs1ToJwk:()=>Zl,pkcs1ToRSAPrivateKey:()=>Aa,pkixMessageToJwk:()=>fs,pkixMessageToRSAPublicKey:()=>ms,pkixToJwk:()=>Yl,pkixToRSAPublicKey:()=>ps});var rn=zr;var Me=class{type="RSA";jwk;_raw;_multihash;constructor(t,e){this.jwk=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=pr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return Z.createV1(114,this._multihash)}toString(){return H.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:V(this.raw,t.raw)}verify(t,e,n){return Sa(this.jwk,e,t,n)}},hr=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=pr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:V(this.raw,t.raw)}sign(t,e){return va(this.jwk,t,e)}};var cs=8192,us=18,Gl=1062,$l=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Zl(r){let t=Ut(r);return ls(t)}function ls(r){return{n:K(r[1],"base64url"),e:K(r[2],"base64url"),d:K(r[3],"base64url"),p:K(r[4],"base64url"),q:K(r[5],"base64url"),dp:K(r[6],"base64url"),dq:K(r[7],"base64url"),qi:K(r[8],"base64url"),kty:"RSA"}}function jl(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new N("JWK was missing components");return jt([bt(Uint8Array.from([0])),bt(U(r.n,"base64url")),bt(U(r.e,"base64url")),bt(U(r.d,"base64url")),bt(U(r.p,"base64url")),bt(U(r.q,"base64url")),bt(U(r.dp,"base64url")),bt(U(r.dq,"base64url")),bt(U(r.qi,"base64url"))]).subarray()}function Yl(r){let t=Ut(r,{offset:0});return fs(t)}function fs(r){let t=Ut(r[1],{offset:0});return{kty:"RSA",n:K(t[0],"base64url"),e:K(t[1],"base64url")}}function ds(r){if(r.n==null||r.e==null)throw new N("JWK was missing components");return jt([$l,Nr(jt([bt(U(r.n,"base64url")),bt(U(r.e,"base64url"))]))]).subarray()}function Aa(r){let t=Ut(r);return hs(t)}function hs(r){let t=ls(r);return ys(t)}function ps(r,t){if(r.byteLength>=Gl)throw new we("Key size is too large");let e=Ut(r,{offset:0});return ms(e,r,t)}function ms(r,t,e){let n=fs(r);if(e==null){let o=rn(Ot.encode({Type:Y.RSA,Data:t}));e=At(us,o)}return new Me(n,e)}function ys(r){if(Ta(r)>cs)throw new N("Key size is too large");let t=_a(r),e=rn(Ot.encode({Type:Y.RSA,Data:ds(t.publicKey)})),n=At(us,e);return new hr(t.privateKey,new Me(t.publicKey,n))}async function Ia(r){if(r>cs)throw new N("Key size is too large");let t=await Ca(r),e=rn(Ot.encode({Type:Y.RSA,Data:ds(t.publicKey)})),n=At(us,e);return new hr(t.privateKey,new Me(t.publicKey,n))}function _a(r){if(r==null)throw new N("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function Ca(r,t){let e=await vt.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await Xl(e,t);return{privateKey:n[0],publicKey:n[1]}}async function va(r,t,e){let n=await vt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);e?.signal?.throwIfAborted();let o=await vt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return e?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Sa(r,t,e,n){let o=await vt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await vt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,e instanceof Uint8Array?e:e.subarray());return n?.signal?.throwIfAborted(),s}async function Xl(r,t){if(r.privateKey==null||r.publicKey==null)throw new N("Private and public key are required");let e=await Promise.all([vt.get().subtle.exportKey("jwk",r.privateKey),vt.get().subtle.exportKey("jwk",r.publicKey)]);return t?.signal?.throwIfAborted(),e}function Ta(r){if(r.kty!=="RSA")throw new N("invalid key type");if(r.n==null)throw new N("invalid key modulus");return U(r.n,"base64url").length*8}var nn=class extends Te{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Si(t);let n=rr(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),qt(s)}update(t){return De(this),this.iHash.update(t),this}digestInto(t){De(this),st(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},bs=(r,t,e)=>new nn(r,t).update(e).digest();bs.create=(r,t)=>new nn(r,t);function Ba(r){r.lowS!==void 0&&Ht("lowS",r.lowS),r.prehash!==void 0&&Ht("prehash",r.prehash)}var gs=class extends Error{constructor(t=""){super(t)}},Vt={Err:gs,_tlv:{encode:(r,t)=>{let{Err:e}=Vt;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=ar(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?ar(o.length/2|128):"";return ar(r)+s+o+t},decode(r,t){let{Err:e}=Vt,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&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 l=t.subarray(n,n+c);if(l.length!==c)throw new e("tlv.decode: length bytes not complete");if(l[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let u of l)i=i<<8|u;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=Vt;if(r<mr)throw new t("integer: negative integers are not allowed");let e=ar(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=Vt;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 Le(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Vt,o=F("signature",r),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:l,l:u}=n.decode(2,c);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(l)}},hexFromSig(r){let{_tlv:t,_int:e}=Vt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},mr=BigInt(0),yr=BigInt(1),Ql=BigInt(2),on=BigInt(3),Jl=BigInt(4);function tf(r,t,e){function n(o){let s=r.sqr(o),i=r.mul(s,o);return r.add(r.add(i,r.mul(o,t)),e)}return n}function Da(r,t,e){let{BYTES:n}=r;function o(s){let i;if(typeof s=="bigint")i=s;else{let a=F("private key",s);if(t){if(!t.includes(a.length*2))throw new Error("invalid private key");let c=new Uint8Array(n);c.set(a,c.length-a.length),a=c}try{i=r.fromBytes(a)}catch{throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof s}`)}}if(e&&(i=r.create(i)),!r.isValidNot0(i))throw new Error("invalid private key: out of range [1..N-1]");return i}return o}function ef(r,t={}){let{Fp:e,Fn:n}=Gr("weierstrass",r,t),{h:o,n:s}=r;te(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:i}=t;if(i&&(!e.is0(r.a)||typeof i.beta!="bigint"||typeof i.splitScalar!="function"))throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');function a(){if(!e.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function c(_,d,x){let{x:y,y:g}=d.toAffine(),v=e.toBytes(y);if(Ht("isCompressed",x),x){a();let C=!e.isOdd(g);return gt(Ra(C),v)}else return gt(Uint8Array.of(4),v,e.toBytes(g))}function l(_){st(_);let d=e.BYTES,x=d+1,y=2*d+1,g=_.length,v=_[0],C=_.subarray(1);if(g===x&&(v===2||v===3)){let I=e.fromBytes(C);if(!e.isValid(I))throw new Error("bad point: is not on curve, wrong x");let B=h(I),O;try{O=e.sqrt(B)}catch(q){let k=q instanceof Error?": "+q.message:"";throw new Error("bad point: is not on curve, sqrt error"+k)}a();let P=e.isOdd(O);return(v&1)===1!==P&&(O=e.neg(O)),{x:I,y:O}}else if(g===y&&v===4){let I=e.fromBytes(C.subarray(d*0,d*1)),B=e.fromBytes(C.subarray(d*1,d*2));if(!m(I,B))throw new Error("bad point: is not on curve");return{x:I,y:B}}else throw new Error(`bad point: got length ${g}, expected compressed=${x} or uncompressed=${y}`)}let u=t.toBytes||c,f=t.fromBytes||l,h=tf(e,r.a,r.b);function m(_,d){let x=e.sqr(d),y=h(_);return e.eql(x,y)}if(!m(r.Gx,r.Gy))throw new Error("bad curve params: generator point");let w=e.mul(e.pow(r.a,on),Jl),E=e.mul(e.sqr(r.b),BigInt(27));if(e.is0(e.add(w,E)))throw new Error("bad curve params: a or b");function p(_,d,x=!1){if(!e.isValid(d)||x&&e.is0(d))throw new Error(`bad point coordinate ${_}`);return d}function S(_){if(!(_ instanceof b))throw new Error("ProjectivePoint expected")}let T=Oe((_,d)=>{let{px:x,py:y,pz:g}=_;if(e.eql(g,e.ONE))return{x,y};let v=_.is0();d==null&&(d=v?e.ONE:e.inv(g));let C=e.mul(x,d),I=e.mul(y,d),B=e.mul(g,d);if(v)return{x:e.ZERO,y:e.ZERO};if(!e.eql(B,e.ONE))throw new Error("invZ was invalid");return{x:C,y:I}}),A=Oe(_=>{if(_.is0()){if(t.allowInfinityPoint&&!e.is0(_.py))return;throw new Error("bad point: ZERO")}let{x:d,y:x}=_.toAffine();if(!e.isValid(d)||!e.isValid(x))throw new Error("bad point: x or y not field elements");if(!m(d,x))throw new Error("bad point: equation left != right");if(!_.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function L(_,d,x,y,g){return x=new b(e.mul(x.px,_),x.py,x.pz),d=ke(y,d),x=ke(g,x),d.add(x)}class b{constructor(d,x,y){this.px=p("x",d),this.py=p("y",x,!0),this.pz=p("z",y),Object.freeze(this)}static fromAffine(d){let{x,y}=d||{};if(!d||!e.isValid(x)||!e.isValid(y))throw new Error("invalid affine point");if(d instanceof b)throw new Error("projective point not allowed");return e.is0(x)&&e.is0(y)?b.ZERO:new b(x,y,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){return Vr(b,"pz",d)}static fromBytes(d){return st(d),b.fromHex(d)}static fromHex(d){let x=b.fromAffine(f(F("pointHex",d)));return x.assertValidity(),x}static fromPrivateKey(d){let x=Da(n,t.allowedPrivateKeyLengths,t.wrapPrivateKey);return b.BASE.multiply(x(d))}static msm(d,x){return Wr(b,n,d,x)}precompute(d=8,x=!0){return D.setWindowSize(this,d),x||this.multiply(on),this}_setWindowSize(d){this.precompute(d)}assertValidity(){A(this)}hasEvenY(){let{y:d}=this.toAffine();if(!e.isOdd)throw new Error("Field doesn't support isOdd");return!e.isOdd(d)}equals(d){S(d);let{px:x,py:y,pz:g}=this,{px:v,py:C,pz:I}=d,B=e.eql(e.mul(x,I),e.mul(v,g)),O=e.eql(e.mul(y,I),e.mul(C,g));return B&&O}negate(){return new b(this.px,e.neg(this.py),this.pz)}double(){let{a:d,b:x}=r,y=e.mul(x,on),{px:g,py:v,pz:C}=this,I=e.ZERO,B=e.ZERO,O=e.ZERO,P=e.mul(g,g),j=e.mul(v,v),q=e.mul(C,C),k=e.mul(g,v);return k=e.add(k,k),O=e.mul(g,C),O=e.add(O,O),I=e.mul(d,O),B=e.mul(y,q),B=e.add(I,B),I=e.sub(j,B),B=e.add(j,B),B=e.mul(I,B),I=e.mul(k,I),O=e.mul(y,O),q=e.mul(d,q),k=e.sub(P,q),k=e.mul(d,k),k=e.add(k,O),O=e.add(P,P),P=e.add(O,P),P=e.add(P,q),P=e.mul(P,k),B=e.add(B,P),q=e.mul(v,C),q=e.add(q,q),P=e.mul(q,k),I=e.sub(I,P),O=e.mul(q,j),O=e.add(O,O),O=e.add(O,O),new b(I,B,O)}add(d){S(d);let{px:x,py:y,pz:g}=this,{px:v,py:C,pz:I}=d,B=e.ZERO,O=e.ZERO,P=e.ZERO,j=r.a,q=e.mul(r.b,on),k=e.mul(x,v),X=e.mul(y,C),J=e.mul(g,I),ot=e.add(x,y),z=e.add(v,C);ot=e.mul(ot,z),z=e.add(k,X),ot=e.sub(ot,z),z=e.add(x,g);let ct=e.add(v,I);return z=e.mul(z,ct),ct=e.add(k,J),z=e.sub(z,ct),ct=e.add(y,g),B=e.add(C,I),ct=e.mul(ct,B),B=e.add(X,J),ct=e.sub(ct,B),P=e.mul(j,z),B=e.mul(q,J),P=e.add(B,P),B=e.sub(X,P),P=e.add(X,P),O=e.mul(B,P),X=e.add(k,k),X=e.add(X,k),J=e.mul(j,J),z=e.mul(q,z),X=e.add(X,J),J=e.sub(k,J),J=e.mul(j,J),z=e.add(z,J),k=e.mul(X,z),O=e.add(O,k),k=e.mul(ct,z),B=e.mul(ot,B),B=e.sub(B,k),k=e.mul(ot,X),P=e.mul(ct,P),P=e.add(P,k),new b(B,O,P)}subtract(d){return this.add(d.negate())}is0(){return this.equals(b.ZERO)}multiply(d){let{endo:x}=t;if(!n.isValidNot0(d))throw new Error("invalid scalar: out of range");let y,g,v=C=>D.wNAFCached(this,C,b.normalizeZ);if(x){let{k1neg:C,k1:I,k2neg:B,k2:O}=x.splitScalar(d),{p:P,f:j}=v(I),{p:q,f:k}=v(O);g=j.add(k),y=L(x.beta,P,q,C,B)}else{let{p:C,f:I}=v(d);y=C,g=I}return b.normalizeZ([y,g])[0]}multiplyUnsafe(d){let{endo:x}=t,y=this;if(!n.isValid(d))throw new Error("invalid scalar: out of range");if(d===mr||y.is0())return b.ZERO;if(d===yr)return y;if(D.hasPrecomputes(this))return this.multiply(d);if(x){let{k1neg:g,k1:v,k2neg:C,k2:I}=x.splitScalar(d),{p1:B,p2:O}=oa(b,y,v,I);return L(x.beta,B,O,g,C)}else return D.wNAFCachedUnsafe(y,d)}multiplyAndAddUnsafe(d,x,y){let g=this.multiplyUnsafe(x).add(d.multiplyUnsafe(y));return g.is0()?void 0:g}toAffine(d){return T(this,d)}isTorsionFree(){let{isTorsionFree:d}=t;return o===yr?!0:d?d(b,this):D.wNAFCachedUnsafe(this,s).is0()}clearCofactor(){let{clearCofactor:d}=t;return o===yr?this:d?d(b,this):this.multiplyUnsafe(o)}toBytes(d=!0){return Ht("isCompressed",d),this.assertValidity(),u(b,this,d)}toRawBytes(d=!0){return this.toBytes(d)}toHex(d=!0){return Rt(this.toBytes(d))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}b.BASE=new b(r.Gx,r.Gy,e.ONE),b.ZERO=new b(e.ZERO,e.ONE,e.ZERO),b.Fp=e,b.Fn=n;let R=n.BITS,D=Fr(b,t.endo?Math.ceil(R/2):R);return b}function Ra(r){return Uint8Array.of(r?2:3)}function rf(r,t,e={}){te(t,{hash:"function"},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=t.randomBytes||nr,o=t.hmac||((y,...g)=>bs(t.hash,y,gt(...g))),{Fp:s,Fn:i}=r,{ORDER:a,BITS:c}=i;function l(y){let g=a>>yr;return y>g}function u(y){return l(y)?i.neg(y):y}function f(y,g){if(!i.isValidNot0(g))throw new Error(`invalid signature ${y}: out of range 1..CURVE.n`)}class h{constructor(g,v,C){f("r",g),f("s",v),this.r=g,this.s=v,C!=null&&(this.recovery=C),Object.freeze(this)}static fromCompact(g){let v=i.BYTES,C=F("compactSignature",g,v*2);return new h(i.fromBytes(C.subarray(0,v)),i.fromBytes(C.subarray(v,v*2)))}static fromDER(g){let{r:v,s:C}=Vt.toSig(F("DER",g));return new h(v,C)}assertValidity(){}addRecoveryBit(g){return new h(this.r,this.s,g)}recoverPublicKey(g){let v=s.ORDER,{r:C,s:I,recovery:B}=this;if(B==null||![0,1,2,3].includes(B))throw new Error("recovery id invalid");if(a*Ql<v&&B>1)throw new Error("recovery id is ambiguous for h>1 curve");let P=B===2||B===3?C+a:C;if(!s.isValid(P))throw new Error("recovery id 2 or 3 invalid");let j=s.toBytes(P),q=r.fromHex(gt(Ra((B&1)===0),j)),k=i.inv(P),X=A(F("msgHash",g)),J=i.create(-X*k),ot=i.create(I*k),z=r.BASE.multiplyUnsafe(J).add(q.multiplyUnsafe(ot));if(z.is0())throw new Error("point at infinify");return z.assertValidity(),z}hasHighS(){return l(this.s)}normalizeS(){return this.hasHighS()?new h(this.r,i.neg(this.s),this.recovery):this}toBytes(g){if(g==="compact")return gt(i.toBytes(this.r),i.toBytes(this.s));if(g==="der")return Re(Vt.hexFromSig(this));throw new Error("invalid format")}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Rt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Rt(this.toBytes("compact"))}}let m=Da(i,e.allowedPrivateKeyLengths,e.wrapPrivateKey),w={isValidPrivateKey(y){try{return m(y),!0}catch{return!1}},normPrivateKeyToScalar:m,randomPrivateKey:()=>{let y=a;return Qi(n(Oo(y)),y)},precompute(y=8,g=r.BASE){return g.precompute(y,!1)}};function E(y,g=!0){return r.fromPrivateKey(y).toBytes(g)}function p(y){if(typeof y=="bigint")return!1;if(y instanceof r)return!0;let v=F("key",y).length,C=s.BYTES,I=C+1,B=2*C+1;if(!(e.allowedPrivateKeyLengths||i.BYTES===I))return v===I||v===B}function S(y,g,v=!0){if(p(y)===!0)throw new Error("first arg must be private key");if(p(g)===!1)throw new Error("second arg must be public key");return r.fromHex(g).multiply(m(y)).toBytes(v)}let T=t.bits2int||function(y){if(y.length>8192)throw new Error("input is too large");let g=Le(y),v=y.length*8-c;return v>0?g>>BigInt(v):g},A=t.bits2int_modN||function(y){return i.create(T(y))},L=ce(c);function b(y){return Jt("num < 2^"+c,y,mr,L),i.toBytes(y)}function R(y,g,v=D){if(["recovered","canonical"].some(ot=>ot in v))throw new Error("sign() legacy options not supported");let{hash:C}=t,{lowS:I,prehash:B,extraEntropy:O}=v;I==null&&(I=!0),y=F("msgHash",y),Ba(v),B&&(y=F("prehashed msgHash",C(y)));let P=A(y),j=m(g),q=[b(j),b(P)];if(O!=null&&O!==!1){let ot=O===!0?n(s.BYTES):O;q.push(F("extraEntropy",ot))}let k=gt(...q),X=P;function J(ot){let z=T(ot);if(!i.isValidNot0(z))return;let ct=i.inv(z),We=r.BASE.multiply(z).toAffine(),be=i.create(We.x);if(be===mr)return;let re=i.create(ct*i.create(X+be*j));if(re===mr)return;let jn=(We.x===be?0:2)|Number(We.y&yr),ge=re;return I&&l(re)&&(ge=u(re),jn^=1),new h(be,ge,jn)}return{seed:k,k2sig:J}}let D={lowS:t.lowS,prehash:!1},_={lowS:t.lowS,prehash:!1};function d(y,g,v=D){let{seed:C,k2sig:I}=R(y,g,v);return Hi(t.hash.outputLen,i.BYTES,o)(C,I)}r.BASE.precompute(8);function x(y,g,v,C=_){let I=y;g=F("msgHash",g),v=F("publicKey",v),Ba(C);let{lowS:B,prehash:O,format:P}=C;if("strict"in C)throw new Error("options.strict was renamed to lowS");if(P!==void 0&&!["compact","der","js"].includes(P))throw new Error('format must be "compact", "der" or "js"');let j=typeof I=="string"||Be(I),q=!j&&!P&&typeof I=="object"&&I!==null&&typeof I.r=="bigint"&&typeof I.s=="bigint";if(!j&&!q)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let k,X;try{if(q)if(P===void 0||P==="js")k=new h(I.r,I.s);else throw new Error("invalid format");if(j){try{P!=="compact"&&(k=h.fromDER(I))}catch(ge){if(!(ge instanceof Vt.Err))throw ge}!k&&P!=="der"&&(k=h.fromCompact(I))}X=r.fromHex(v)}catch{return!1}if(!k||B&&k.hasHighS())return!1;O&&(g=t.hash(g));let{r:J,s:ot}=k,z=A(g),ct=i.inv(ot),We=i.create(z*ct),be=i.create(J*ct),re=r.BASE.multiplyUnsafe(We).add(X.multiplyUnsafe(be));return re.is0()?!1:i.create(re.x)===J}return Object.freeze({getPublicKey:E,getSharedSecret:S,sign:d,verify:x,utils:w,Point:r,Signature:h})}function nf(r){let t={a:r.a,b:r.b,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},e=r.Fp,n=Ct(t.n,r.nBitLength),o={Fp:e,Fn:n,allowedPrivateKeyLengths:r.allowedPrivateKeyLengths,allowInfinityPoint:r.allowInfinityPoint,endo:r.endo,wrapPrivateKey:r.wrapPrivateKey,isTorsionFree:r.isTorsionFree,clearCofactor:r.clearCofactor,fromBytes:r.fromBytes,toBytes:r.toBytes};return{CURVE:t,curveOpts:o}}function of(r){let{CURVE:t,curveOpts:e}=nf(r),n={hash:r.hash,hmac:r.hmac,randomBytes:r.randomBytes,lowS:r.lowS,bits2int:r.bits2int,bits2int_modN:r.bits2int_modN};return{CURVE:t,curveOpts:e,ecdsaOpts:n}}function sf(r,t){return Object.assign({},t,{ProjectivePoint:t.Point,CURVE:r})}function La(r){let{CURVE:t,curveOpts:e,ecdsaOpts:n}=of(r),o=ef(t,e),s=rf(o,n,e);return sf(r,s)}function Pa(r,t){let e=n=>La({...r,hash:n});return{...e(t),create:e}}var sn={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},b0=BigInt(0),af=BigInt(1),xs=BigInt(2),Oa=(r,t)=>(r+t/xs)/t;function cf(r){let t=sn.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),l=r*r*r%t,u=l*l*r%t,f=W(u,e,t)*u%t,h=W(f,e,t)*u%t,m=W(h,xs,t)*l%t,w=W(m,o,t)*m%t,E=W(w,s,t)*w%t,p=W(E,a,t)*E%t,S=W(p,c,t)*p%t,T=W(S,a,t)*E%t,A=W(T,e,t)*u%t,L=W(A,i,t)*w%t,b=W(L,n,t)*l%t,R=W(b,xs,t);if(!ws.eql(ws.sqr(R),r))throw new Error("Cannot find square root");return R}var ws=Ct(sn.p,void 0,void 0,{sqrt:cf}),qe=Pa({...sn,Fp:ws,lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=sn.n,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-af*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),a=Oa(s*r,t),c=Oa(-n*r,t),l=G(r-a*e-c*o,t),u=G(-a*n-c*s,t),f=l>i,h=u>i;if(f&&(l=t-l),h&&(u=t-u),l>i||u>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:l,k2neg:h,k2:u}}}},zr);function ka(r,t,e,n){let o=Xe.digest(e instanceof Uint8Array?e:e.subarray());if(Yr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),qe.verify(t,s,r))).catch(s=>{throw s.name==="AbortError"?s:new ur(String(s))});try{return n?.signal?.throwIfAborted(),qe.verify(t,o.digest,r)}catch(s){throw new ur(String(s))}}var an=class{type="secp256k1";raw;_key;constructor(t){this._key=Na(t),this.raw=Ka(this._key)}toMultihash(){return It.digest(Et(this))}toCID(){return Z.createV1(114,this.toMultihash())}toString(){return H.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:V(this.raw,t.raw)}verify(t,e,n){return ka(this._key,e,t,n)}};function Es(r){return new an(r)}function Ka(r){return qe.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Na(r){try{return qe.ProjectivePoint.fromHex(r),r}catch(t){throw new we(String(t))}}function cn(r,t){let{Type:e,Data:n}=Ot.decode(r),o=n??new Uint8Array;switch(e){case Y.RSA:return ps(o,t);case Y.Ed25519:return zo(o);case Y.secp256k1:return Es(o);case Y.ECDSA:return Io(o);default:throw new ne}}function Ua(r){let{Type:t,Data:e}=Ot.decode(r.digest),n=e??new Uint8Array;switch(t){case Y.Ed25519:return zo(n);case Y.secp256k1:return Es(n);case Y.ECDSA:return Io(n);default:throw new ne}}function Et(r){return Ot.encode({Type:Y[r.type],Data:r.raw})}var Ma=Symbol.for("nodejs.util.inspect.custom"),uf=114,br=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()})`}[Rr]=!0;toString(){return this.string==null&&(this.string=H.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return Z.createV1(uf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return V(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return V(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Ma](){return`PeerId(${this.toString()})`}},gr=class extends br{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},xr=class extends br{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},wr=class extends br{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},lf=2336,Er=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=It.digest(U(this.url))}[Ma](){return`PeerId(${this.url})`}[Rr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return Z.createV1(lf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=K(t)),t.toString()===this.toString())}};var ff=114,qa=2336;function za(r){if(r.type==="Ed25519")return new xr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new wr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new gr({multihash:r.toCID().multihash,publicKey:r});throw new ne}function vs(r){if(hf(r))return new gr({multihash:r});if(df(r))try{let t=Ua(r);if(t.type==="Ed25519")return new xr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new wr({multihash:r,publicKey:t})}catch{let e=K(r.digest);return new Er(new URL(e))}throw new Pr("Supplied PeerID Multihash is invalid")}function un(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==ff&&r.code!==qa)throw new Lr("Supplied PeerID CID is invalid");if(r.code===qa){let t=K(r.multihash.digest);return new Er(new URL(t))}return vs(r.multihash)}function df(r){return r.code===It.code}function hf(r){return r.code===Xe.code}var vr;(function(r){let t;r.codec=()=>(t==null&&(t=pt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.publicKey!=null&&e.publicKey.byteLength>0&&(n.uint32(10),n.bytes(e.publicKey)),e.payloadType!=null&&e.payloadType.byteLength>0&&(n.uint32(18),n.bytes(e.payloadType)),e.payload!=null&&e.payload.byteLength>0&&(n.uint32(26),n.bytes(e.payload)),e.signature!=null&&e.signature.byteLength>0&&(n.uint32(42),n.bytes(e.signature)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={publicKey:Q(0),payloadType:Q(0),payload:Q(0),signature:Q(0)},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.publicKey=e.bytes();break}case 2:{s.payloadType=e.bytes();break}case 3:{s.payload=e.bytes();break}case 5:{s.signature=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>ht(e,r.codec()),r.decode=(e,n)=>dt(e,r.codec(),n)})(vr||(vr={}));var ln=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var ze=class r{static createFromProtobuf=t=>{let e=vr.decode(t),n=cn(e.publicKey);return new r({publicKey:n,payloadType:e.payloadType,payload:e.payload,signature:e.signature})};static seal=async(t,e,n)=>{if(e==null)throw new Error("Missing private key");let o=t.domain,s=t.codec,i=t.marshal(),a=Ha(o,s,i),c=await e.sign(a.subarray(),n);return new r({publicKey:e.publicKey,payloadType:s,payload:i,signature:c})};static openAndCertify=async(t,e,n)=>{let o=r.createFromProtobuf(t);if(!await o.validate(e,n))throw new ln("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(t){let{publicKey:e,payloadType:n,payload:o,signature:s}=t;this.publicKey=e,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=vr.encode({publicKey:Et(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return t==null?!1:V(this.marshal(),t.marshal())}async validate(t,e){let n=Ha(t,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,e)}},Ha=(r,t,e)=>{let n=U(r),o=Qr(n.byteLength),s=Qr(t.length),i=Qr(e.length);return new ut(o,n,s,t,i,e)};function Va(r,t){let e=(n,o)=>n.toString().localeCompare(o.toString());return r.length!==t.length?!1:(t.sort(e),r.sort(e).every((n,o)=>t[o].equals(n)))}var rt=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Ft=class extends Error{static name="ValidationError";name="ValidationError"},Sr=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},fn=class extends Error{static name="InvalidProtocolError";name="InvalidProtocolError"};var dn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",l=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let h=Number.parseInt(f,t);if(!Number.isNaN(h))return h});if(u===void 0)break;if(s*=t,s+=u,s>l||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];e[o]=s>>8,e[o+1]=s&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return e.set(s.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var pf=45,mf=15,hn=new dn;function Ss(r){if(!(r.length>mf))return hn.new(r).parseWith(()=>hn.readIPv4Addr())}function As(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>pf))return hn.new(r).parseWith(()=>hn.readIPv6Addr())}function pn(r){return!!Ss(r)}function Wa(r){return!!As(r)}function _s(r){return t=>K(t,r)}function Cs(r){return t=>U(t,r)}function He(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function pe(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(t)}function Ga(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=U(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=pe(n);return Nt([e,o],e.length+o.length)}function $a(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=Dt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=pe(n);return Nt([e,o],e.length+o.length)}function Ts(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=K(t,"base32"),o=He(e);return`${n}:${o}`}var Bs=function(r){r=r.toString().trim();let t=new Uint8Array(4);return r.split(/\./g).forEach((e,n)=>{let o=parseInt(e,10);if(isNaN(o)||o<0||o>255)throw new rt("Invalid byte value in IP address");t[n]=o}),t},Za=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=pn(e[n]),i;s&&(i=Bs(e[n]),e[n]=K(i.subarray(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,K(i.subarray(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let s=[n,1];for(n=9-e.length;n>0;n--)s.push("0");e.splice.apply(e,s)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){e[n]===""&&(e[n]="0");let s=parseInt(e[n],16);if(isNaN(s)||s<0||s>65535)throw new rt("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},ja=function(r){if(r.byteLength!==4)throw new rt("IPv4 address was incorrect length");let t=[];for(let e=0;e<r.byteLength;e++)t.push(r[e]);return t.join(".")},Ya=function(r){if(r.byteLength!==16)throw new rt("IPv6 address was incorrect length");let t=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],s=r[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let e=t.join(":");try{let n=new URL(`http://[${e}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new rt(`Invalid IPv6 address "${e}"`)}};function Xa(r){try{let t=new URL(`http://[${r}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new rt(`Invalid IPv6 address "${r}"`)}}var Is=Object.values(Qe).map(r=>r.decoder),yf=function(){let r=Is[0].or(Is[1]);return Is.slice(2).forEach(t=>r=r.or(t)),r}();function Qa(r){return yf.decode(r)}function Ja(r){return t=>r.encoder.encode(t)}function bf(r){if(parseInt(r).toString()!==r)throw new Ft("Value must be an integer")}function gf(r){if(r<0)throw new Ft("Value must be a positive integer, or zero")}function xf(r){return t=>{if(t>r)throw new Ft(`Value must be smaller than or equal to ${r}`)}}function wf(...r){return t=>{for(let e of r)e(t)}}var Ar=wf(bf,gf,xf(65535));var nt=-1,Ds=class{protocolsByCode=new Map;protocolsByName=new Map;getCodec(t){let e;if(typeof t=="string"?e=this.protocolsByName.get(t):e=this.protocolsByCode.get(t),e==null)throw new fn(`Protocol ${t} was unknown`);return e}addCodec(t,e,n){this.protocolsByCode.set(t,e),this.protocolsByName.set(e.name,e),n?.forEach(o=>{this.protocolsByName.set(o,e)})}deleteCodec(t){let e=this.getCodec(t);e!=null&&(this.protocolsByCode.delete(e.code),this.protocolsByName.delete(e.name),e.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},wt=new Ds,Yf=[{code:4,name:"ip4",size:32,valueToBytes:Bs,bytesToValue:ja,validate:r=>{if(!pn(r))throw new Ft(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:pe,bytesToValue:He,validate:Ar},{code:273,name:"udp",size:16,valueToBytes:pe,bytesToValue:He,validate:Ar},{code:33,name:"dccp",size:16,valueToBytes:pe,bytesToValue:He,validate:Ar},{code:41,name:"ip6",size:128,valueToBytes:Za,bytesToValue:Ya,stringToValue:Xa,validate:r=>{if(!Wa(r))throw new Ft(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:nt},{code:43,name:"ipcidr",size:8,bytesToValue:_s("base10"),valueToBytes:Cs("base10")},{code:53,name:"dns",size:nt,resolvable:!0},{code:54,name:"dns4",size:nt,resolvable:!0},{code:55,name:"dns6",size:nt,resolvable:!0},{code:56,name:"dnsaddr",size:nt,resolvable:!0},{code:132,name:"sctp",size:16,valueToBytes:pe,bytesToValue:He,validate:Ar},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:nt,path:!0,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:nt,bytesToValue:_s("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?Cs("base58btc")(r):Z.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Ts,valueToBytes:Ga},{code:445,name:"onion3",size:296,bytesToValue:Ts,valueToBytes:$a},{code:446,name:"garlic64",size:nt},{code:447,name:"garlic32",size:nt},{code:448,name:"tls"},{code:449,name:"sni",size:nt},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:nt,bytesToValue:Ja(fo),valueToBytes:Qa},{code:480,name:"http"},{code:481,name:"http-path",size:nt,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:nt}];Yf.forEach(r=>{wt.addCodec(r.code,r,r.aliases)});function tc(r){let t=[],e=0;for(;e<r.length;){let n=$o(r,e),o=wt.getCodec(n),s=St(n),i=Xf(o,r,e+s),a=0;i>0&&o.size===nt&&(a=St(i));let c=s+a+i,l={code:n,name:o.name,bytes:r.subarray(e,e+c)};if(i>0){let u=e+s+a,f=r.subarray(u,u+i);l.value=o.bytesToValue?.(f)??K(f)}t.push(l),e+=c}return t}function ec(r){let t=0,e=[];for(let n of r){if(n.bytes==null){let o=wt.getCodec(n.code),s=St(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??U(n.value),a=i.byteLength,o.size===nt&&(c=St(a)));let l=new Uint8Array(s+c+a),u=0;Ne(n.code,l,u),u+=s,i!=null&&(o.size===nt&&(Ne(a,l,u),u+=c),l.set(i,u)),n.bytes=l}e.push(n.bytes),t+=n.bytes.byteLength}return Nt(e,t)}function rc(r){if(r.charAt(0)!=="/")throw new rt('String multiaddr must start with "/"');let t=[],e="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(e==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let a=s===r.length-1;if(i==="/"||a){let c=wt.getCodec(o);if(e==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",e="protocol";continue}else if(a)throw new rt(`Component ${o} was missing value`);e="value"}else if(e==="value"){let l={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new rt(`Component ${o} was missing value`);l.value=c.stringToValue?.(n)??n}t.push(l),n="",o="",e="protocol"}}}if(o!==""&&n!=="")throw new rt("Incomplete multiaddr");return t}function nc(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=wt.getCodec(t.code);if(e==null)throw new rt(`Unknown protocol code ${t.code}`);return[t.name,e.valueToString?.(t.value)??t.value]}).join("/")}`}function Xf(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:$o(t,e)}var Qf=Symbol.for("nodejs.util.inspect.custom"),Us=Symbol.for("@multiformats/multiaddr"),Jf=[53,54,55,56],Ns=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}};function td(r){if(r==null&&(r="/"),wn(r))return r.getComponents();if(r instanceof Uint8Array)return tc(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),rc(r);if(Array.isArray(r))return r;throw new rt("Must be a string, Uint8Array, Component[], or another Multiaddr")}var xn=class r{[Us]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=td(t),e.validate!==!1&&ed(this)}get bytes(){return this.#r==null&&(this.#r=ec(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=nc(this.#t)),this.#e}toJSON(){return this.toString()}toOptions(){let t,e,n,o,s="";for(let{code:a,name:c,value:l}of this.#t)a===42&&(s=`%${l??""}`),Jf.includes(a)&&(e="tcp",o=443,n=`${l??""}${s}`,t=a===55?6:4),(a===6||a===273)&&(e=c==="tcp"?"tcp":"udp",o=parseInt(l??"")),(a===4||a===41)&&(e="tcp",n=`${l??""}${s}`,t=a===41?6:4);if(t==null||e==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:t,host:n,transport:e,port:o}}getComponents(){return[...this.#t]}protos(){return this.#t.map(({code:t,value:e})=>{let n=wt.getCodec(t);return{code:t,size:n.size??0,name:n.name,resolvable:!!n.resolvable,path:!!n.path}})}protoCodes(){return this.#t.map(({code:t})=>t)}protoNames(){return this.#t.map(({name:t})=>t)}tuples(){return this.#t.map(({code:t,value:e})=>{if(e==null)return[t];let n=wt.getCodec(t),o=[t];return e!=null&&o.push(n.valueToBytes?.(e)??U(e)),o})}stringTuples(){return this.#t.map(({code:t,value:e})=>e==null?[t]:[t,e])}encapsulate(t){let e=new r(t);return new r([...this.#t,...e.getComponents()],{validate:!1})}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new Sr(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(t){let e;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){e=n;break}return new r(this.#t.slice(0,e),{validate:!1})}getPeerId(){try{let t=[];this.#t.forEach(({code:n,value:o})=>{n===421&&t.push([n,o]),n===290&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?K(H.decode(`z${n}`),"base58btc"):K(Z.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){for(let t of this.#t)if(wt.getCodec(t.code).path)return t.value??null;return null}equals(t){return V(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(s=>s.resolvable);if(e==null)return[this];let n=oc.get(e.name);if(n==null)throw new Ns(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>kt(s))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(){return!(this.#t.length!==2||this.#t[0].code!==4&&this.#t[0].code!==41||this.#t[1].code!==6&&this.#t[1].code!==273)}[Qf](){return`Multiaddr(${this.toString()})`}};function ed(r){r.getComponents().forEach(t=>{let e=wt.getCodec(t.code);t.value!=null&&e.validate?.(t.value)})}var Ib=parseInt("0xFFFF",16),_b=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var oc=new Map;function wn(r){return!!r?.[Us]}function kt(r){return new xn(r)}var ac="libp2p-peer-record",cc=Uint8Array.from([3,1]);var _r;(function(r){let t;(function(n){let o;n.codec=()=>(o==null&&(o=pt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.multiaddr!=null&&s.multiaddr.byteLength>0&&(i.uint32(10),i.bytes(s.multiaddr)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={multiaddr:Q(0)},l=i==null?s.len:s.pos+i;for(;s.pos<l;){let u=s.uint32();switch(u>>>3){case 1:{c.multiaddr=s.bytes();break}default:{s.skipType(u&7);break}}}return c})),o),n.encode=s=>ht(s,n.codec()),n.decode=(s,i)=>dt(s,n.codec(),i)})(t=r.AddressInfo||(r.AddressInfo={}));let e;r.codec=()=>(e==null&&(e=pt((n,o,s={})=>{if(s.lengthDelimited!==!1&&o.fork(),n.peerId!=null&&n.peerId.byteLength>0&&(o.uint32(10),o.bytes(n.peerId)),n.seq!=null&&n.seq!==0n&&(o.uint32(16),o.uint64(n.seq)),n.addresses!=null)for(let i of n.addresses)o.uint32(26),r.AddressInfo.codec().encode(i,o);s.lengthDelimited!==!1&&o.ldelim()},(n,o,s={})=>{let i={peerId:Q(0),seq:0n,addresses:[]},a=o==null?n.len:n.pos+o;for(;n.pos<a;){let c=n.uint32();switch(c>>>3){case 1:{i.peerId=n.bytes();break}case 2:{i.seq=n.uint64();break}case 3:{if(s.limits?.addresses!=null&&i.addresses.length===s.limits.addresses)throw new he('Decode error - map field "addresses" had too many elements');i.addresses.push(r.AddressInfo.codec().decode(n,n.uint32(),{limits:s.limits?.addresses$}));break}default:{n.skipType(c&7);break}}}return i})),e),r.encode=n=>ht(n,r.codec()),r.decode=(n,o)=>dt(n,r.codec(),o)})(_r||(_r={}));var me=class r{static createFromProtobuf=t=>{let e=_r.decode(t),n=vs(_e(e.peerId)),o=(e.addresses??[]).map(i=>kt(i.multiaddr)),s=e.seq;return new r({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=ac;static CODEC=cc;peerId;multiaddrs;seqNumber;domain=r.DOMAIN;codec=r.CODEC;marshaled;constructor(t){let{peerId:e,multiaddrs:n,seqNumber:o}=t;this.peerId=e,this.multiaddrs=n??[],this.seqNumber=o??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=_r.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||!Va(this.multiaddrs,t.multiaddrs))}};function id(r){return r[Symbol.asyncIterator]!=null}function ad(r){if(id(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 uc=ad;function En(r,t){let e={[Symbol.iterator]:()=>e,next:()=>{let n=r.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return e}var Cr=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 En(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 En(this.map.values(),t=>t.key)}values(){return En(this.map.values(),t=>t.value)}get size(){return this.map.size}};var Ms=class extends Cr{metric;constructor(t){super();let{name:e,metrics:n}=t;this.metric=n.registerMetric(e),this.updateComponentMetric()}set(t,e){return super.set(t,e),this.updateComponentMetric(),this}delete(t){let e=super.delete(t);return this.updateComponentMetric(),e}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function qs(r){let{name:t,metrics:e}=r,n;return e!=null?n=new Ms({name:t,metrics:e}):n=new Cr,n}var Bt=class extends Error{static name="AbortError";name="AbortError";constructor(t="The operation was aborted",...e){super(t,...e)}};function vn(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Sn=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},Ve=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Sn(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new Sn(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var zs=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function lc(r={}){return cd(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function cd(r,t){t=t??{};let e=t.onEnd,n=new Ve,o,s,i,a=vn(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((p,S)=>{s=T=>{s=null,n.push(T);try{p(r(n))}catch(A){S(A)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=vn()})}},l=p=>s!=null?s(p):(n.push(p),o),u=p=>(n=new Ve,s!=null?s({error:p}):(n.push({error:p}),o)),f=p=>{if(i)return o;if(t?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:p})},h=p=>i?o:(i=!0,p!=null?u(p):l({done:!0})),m=()=>(n=new Ve,h(),{done:!0}),w=p=>(h(p),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:m,throw:w,push:f,end:h,get readableLength(){return n.size},onEmpty:async p=>{let S=p?.signal;if(S?.throwIfAborted(),n.isEmpty())return;let T,A;S!=null&&(T=new Promise((L,b)=>{A=()=>{b(new zs)},S.addEventListener("abort",A)}));try{await Promise.race([a.promise,T])}finally{A!=null&&S!=null&&S?.removeEventListener("abort",A)}}},e==null)return o;let E=o;return o={[Symbol.asyncIterator](){return this},next(){return E.next()},throw(p){return E.throw(p),e!=null&&(e(p),e=void 0),{done:!0}},return(){return E.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(p){return E.end(p),e!=null&&(e(p),e=void 0),o},get readableLength(){return E.readableLength},onEmpty:p=>E.onEmpty(p)},o}var Hs=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=e??"ABORT_ERR"}};async function An(r,t,e,n){let o=new Hs(n?.errorMessage,n?.errorCode);return e?.aborted===!0?Promise.reject(o):new Promise((s,i)=>{function a(){e?.removeEventListener("abort",u),r.removeEventListener(t,c),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,l)}let c=f=>{try{if(n?.filter?.(f)===!1)return}catch(h){a(),i(h);return}a(),s(f)},l=f=>{a(),i(f.detail)},u=()=>{a(),i(o)};e?.addEventListener("abort",u),r.addEventListener(t,c),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,l)})}var In=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};var _n=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function fc(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new _n(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new _n(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((s,i)=>{n=()=>{i(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var Cn=class{deferred;signal;constructor(t){this.signal=t,this.deferred=Promise.withResolvers(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Bt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function ud(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Tn=class{id;fn;options;recipients;status;timeline;controller;constructor(t,e){this.id=ud(),this.status="queued",this.fn=t,this.options=e,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(t){this.controller.abort(t)}onAbort(){this.recipients.reduce((e,n)=>e&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new Bt),this.cleanup())}async join(t={}){let e=new Cn(t.signal);return this.recipients.push(e),t.signal?.addEventListener("abort",this.onAbort),e.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let t=await fc(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(e=>{e.deferred.resolve(t)}),this.status="complete"}catch(t){this.recipients.forEach(e=>{e.deferred.reject(t)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(t=>{t.cleanup(),t.signal?.removeEventListener("abort",this.onAbort)})}};function Vs(r,t){let e,n=function(){let o=function(){e=void 0,r()};clearTimeout(e),e=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(e)},n}var Tr=class extends Ee{concurrency;maxSize;queue;pending;sort;autoStart;constructor(t={}){super(),this.concurrency=t.concurrency??Number.POSITIVE_INFINITY,this.maxSize=t.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.autoStart=t.autoStart??!0,this.sort=t.sort,this.queue=[],this.emitEmpty=Vs(this.emitEmpty.bind(this),1),this.emitIdle=Vs(this.emitIdle.bind(this),1)}[Symbol.asyncIterator](){return this.toGenerator()}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}tryToStartAnother(){if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let t;for(let e of this.queue)if(e.status==="queued"){t=e;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let e=0;e<this.queue.length;e++)if(this.queue[e]===t){this.queue.splice(e,1);break}this.pending--,this.safeDispatchEvent("next"),this.autoStart&&this.tryToStartAnother()}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}start(){this.autoStart===!1&&(this.autoStart=!0,this.tryToStartAnother())}pause(){this.autoStart=!1}async add(t,e){if(e?.signal?.throwIfAborted(),this.size===this.maxSize)throw new In;let n=new Tn(t,e);return this.enqueue(n),this.safeDispatchEvent("add"),this.autoStart&&this.tryToStartAnother(),n.join(e).then(o=>(this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(t=>{t.abort(new Bt)}),this.clear()}async onEmpty(t){this.size!==0&&await An(this,"empty",t?.signal)}async onSizeLessThan(t,e){this.size<t||await An(this,"next",e?.signal,{filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await An(this,"idle",t?.signal)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(t){t?.signal?.throwIfAborted();let e=lc({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),e.end(c)},o=c=>{c.detail!=null&&e.push(c.detail.result)},s=c=>{n(c.detail.error)},i=()=>{n()},a=()=>{n(new Bt("Queue aborted"))};this.addEventListener("success",o),this.addEventListener("failure",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*e}finally{this.removeEventListener("success",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};var Bn="lock:worker:request-read",Dn="lock:worker:abort-read-request",Rn="lock:worker:release-read",Ln="lock:master:grant-read",Pn="lock:master:error-read",On="lock:worker:request-write",kn="lock:worker:abort-write-request",Kn="lock:worker:release-write",Nn="lock:master:grant-write",Un="lock:master:error-write",Mn="lock:worker:finalize",qn="mortice",dc={singleProcess:!1};var Fs=(r,t,e,n,o,s,i,a,c)=>l=>{if(l.data==null)return;let u={type:l.data.type,name:l.data.name,identifier:l.data.identifier};u.type===o&&r.safeDispatchEvent(e,{detail:{name:u.name,identifier:u.identifier,handler:async()=>{t.postMessage({type:c,name:u.name,identifier:u.identifier}),await new Promise(f=>{let h=m=>{if(m?.data==null)return;let w={type:m.data.type,name:m.data.name,identifier:m.data.identifier};w.type===a&&w.identifier===u.identifier&&(t.removeEventListener("message",h),f())};t.addEventListener("message",h)})},onError:f=>{t.postMessage({type:i,name:u.name,identifier:u.identifier,error:{message:f.message,name:f.name,stack:f.stack}})}}}),u.type===s&&r.safeDispatchEvent(n,{detail:{name:u.name,identifier:u.identifier}}),u.type===Mn&&r.safeDispatchEvent("finalizeRequest",{detail:{name:u.name}})};var hc=(r=10)=>Math.random().toString().substring(2,r+2);var zn=class{name;channel;constructor(t){this.name=t,this.channel=new BroadcastChannel(qn)}readLock(t){return this.sendRequest(Bn,Dn,Ln,Pn,Rn,t)}writeLock(t){return this.sendRequest(On,kn,Nn,Un,Kn,t)}finalize(){this.channel.postMessage({type:Mn,name:this.name}),this.channel.close()}async sendRequest(t,e,n,o,s,i){i?.signal?.throwIfAborted();let a=hc();return this.channel.postMessage({type:t,identifier:a,name:this.name}),new Promise((c,l)=>{let u=()=>{this.channel.postMessage({type:e,identifier:a,name:this.name})};i?.signal?.addEventListener("abort",u,{once:!0});let f=h=>{if(h.data?.identifier===a&&(h.data?.type===n&&(this.channel.removeEventListener("message",f),i?.signal?.removeEventListener("abort",u),c(()=>{this.channel.postMessage({type:s,identifier:a,name:this.name})})),h.data.type===o)){this.channel.removeEventListener("message",f),i?.signal?.removeEventListener("abort",u);let m=new Error;h.data.error!=null&&(m.message=h.data.error.message,m.name=h.data.error.name,m.stack=h.data.error.stack),l(m)}};this.channel.addEventListener("message",f)})}};var pc=r=>{if(r=Object.assign({},dc,r),!!globalThis.document||r.singleProcess){let e=new BroadcastChannel(qn),n=new Ee;return e.addEventListener("message",Fs(n,e,"requestReadLock","abortReadLockRequest",Bn,Dn,Pn,Rn,Ln)),e.addEventListener("message",Fs(n,e,"requestWriteLock","abortWriteLockRequest",On,kn,Un,Kn,Nn)),n}return new zn(r.name)};var ye=new Map,Br;function mc(r){return typeof r?.readLock=="function"&&typeof r?.writeLock=="function"}function ld(r){if(Br==null&&(Br=pc(r),!mc(Br))){let t=Br;t.addEventListener("requestReadLock",e=>{let n=e.detail.name,o=e.detail.identifier,s=ye.get(n);if(s==null)return;let i=new AbortController,a=c=>{c.detail.name!==n||c.detail.identifier!==o||i.abort()};t.addEventListener("abortReadLockRequest",a),s.readLock({signal:i.signal}).then(async c=>{await e.detail.handler().finally(()=>{c()})}).catch(c=>{e.detail.onError(c)}).finally(()=>{t.removeEventListener("abortReadLockRequest",a)})}),t.addEventListener("requestWriteLock",e=>{let n=e.detail.name,o=e.detail.identifier,s=ye.get(n);if(s==null)return;let i=new AbortController,a=c=>{c.detail.name!==n||c.detail.identifier!==o||i.abort()};t.addEventListener("abortWriteLockRequest",a),s.writeLock({signal:i.signal}).then(async c=>{await e.detail.handler().finally(()=>{c()})}).catch(c=>{e.detail.onError(c)}).finally(()=>{t.removeEventListener("abortWriteLockRequest",a)})}),t.addEventListener("finalizeRequest",e=>{let n=e.detail.name,o=ye.get(n);o?.finalize()})}return Br}async function Ws(r,t){let e,n,o=new Promise((i,a)=>{e=i,n=a}),s=()=>{n(new Bt)};return t?.signal?.addEventListener("abort",s,{once:!0}),r.add(async()=>{await new Promise(i=>{e(()=>{t?.signal?.removeEventListener("abort",s),i()})})},{signal:t?.signal}).catch(i=>{n(i)}),o}var yc=(r,t)=>{let e=ye.get(r);if(e!=null)return e;let n=ld(t);if(mc(n))return e=n,ye.set(r,e),e;let o=new Tr({concurrency:1}),s;return e={async readLock(i){if(s!=null)return Ws(s,i);s=new Tr({concurrency:t.concurrency,autoStart:!1});let a=s,c=Ws(s,i);return o.add(async()=>{a.start(),await a.onIdle().then(()=>{s===a&&(s=null)})}),c},async writeLock(i){return s=null,Ws(o,i)},finalize:()=>{ye.delete(r)},queue:o},ye.set(r,e),t.autoFinalize===!0&&o.addEventListener("idle",()=>{e.finalize()},{once:!0}),e};var fd={name:"lock",concurrency:1/0,singleProcess:!1,autoFinalize:!1};function Gs(r){let t=Object.assign({},fd,r);return yc(t.name,t)}var Wt;(function(r){let t;(function(o){let s;o.codec=()=>(s==null&&(s=pt((i,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),i.key!=null&&i.key!==""&&(a.uint32(10),a.string(i.key)),i.value!=null&&i.value.byteLength>0&&(a.uint32(18),a.bytes(i.value)),c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let l={key:"",value:Q(0)},u=a==null?i.len:i.pos+a;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{l.key=i.string();break}case 2:{l.value=i.bytes();break}default:{i.skipType(f&7);break}}}return l})),s),o.encode=i=>ht(i,o.codec()),o.decode=(i,a)=>dt(i,o.codec(),a)})(t=r.Peer$metadataEntry||(r.Peer$metadataEntry={}));let e;(function(o){let s;o.codec=()=>(s==null&&(s=pt((i,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),i.key!=null&&i.key!==""&&(a.uint32(10),a.string(i.key)),i.value!=null&&(a.uint32(18),Vn.codec().encode(i.value,a)),c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let l={key:""},u=a==null?i.len:i.pos+a;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{l.key=i.string();break}case 2:{l.value=Vn.codec().decode(i,i.uint32(),{limits:c.limits?.value});break}default:{i.skipType(f&7);break}}}return l})),s),o.encode=i=>ht(i,o.codec()),o.decode=(i,a)=>dt(i,o.codec(),a)})(e=r.Peer$tagsEntry||(r.Peer$tagsEntry={}));let n;r.codec=()=>(n==null&&(n=pt((o,s,i={})=>{if(i.lengthDelimited!==!1&&s.fork(),o.addresses!=null)for(let a of o.addresses)s.uint32(10),Hn.codec().encode(a,s);if(o.protocols!=null)for(let a of o.protocols)s.uint32(18),s.string(a);if(o.publicKey!=null&&(s.uint32(34),s.bytes(o.publicKey)),o.peerRecordEnvelope!=null&&(s.uint32(42),s.bytes(o.peerRecordEnvelope)),o.metadata!=null&&o.metadata.size!==0)for(let[a,c]of o.metadata.entries())s.uint32(50),r.Peer$metadataEntry.codec().encode({key:a,value:c},s);if(o.tags!=null&&o.tags.size!==0)for(let[a,c]of o.tags.entries())s.uint32(58),r.Peer$tagsEntry.codec().encode({key:a,value:c},s);o.updated!=null&&(s.uint32(64),s.uint64Number(o.updated)),i.lengthDelimited!==!1&&s.ldelim()},(o,s,i={})=>{let a={addresses:[],protocols:[],metadata:new Map,tags:new Map},c=s==null?o.len:o.pos+s;for(;o.pos<c;){let l=o.uint32();switch(l>>>3){case 1:{if(i.limits?.addresses!=null&&a.addresses.length===i.limits.addresses)throw new he('Decode error - map field "addresses" had too many elements');a.addresses.push(Hn.codec().decode(o,o.uint32(),{limits:i.limits?.addresses$}));break}case 2:{if(i.limits?.protocols!=null&&a.protocols.length===i.limits.protocols)throw new he('Decode error - map field "protocols" had too many elements');a.protocols.push(o.string());break}case 4:{a.publicKey=o.bytes();break}case 5:{a.peerRecordEnvelope=o.bytes();break}case 6:{if(i.limits?.metadata!=null&&a.metadata.size===i.limits.metadata)throw new dr('Decode error - map field "metadata" had too many elements');let u=r.Peer$metadataEntry.codec().decode(o,o.uint32());a.metadata.set(u.key,u.value);break}case 7:{if(i.limits?.tags!=null&&a.tags.size===i.limits.tags)throw new dr('Decode error - map field "tags" had too many elements');let u=r.Peer$tagsEntry.codec().decode(o,o.uint32(),{limits:{value:i.limits?.tags$value}});a.tags.set(u.key,u.value);break}case 8:{a.updated=o.uint64Number();break}default:{o.skipType(l&7);break}}}return a})),n),r.encode=o=>ht(o,r.codec()),r.decode=(o,s)=>dt(o,r.codec(),s)})(Wt||(Wt={}));var Hn;(function(r){let t;r.codec=()=>(t==null&&(t=pt((e,n,o={})=>{o.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)),e.observed!=null&&(n.uint32(24),n.uint64Number(e.observed)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={multiaddr:Q(0)},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.multiaddr=e.bytes();break}case 2:{s.isCertified=e.bool();break}case 3:{s.observed=e.uint64Number();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>ht(e,r.codec()),r.decode=(e,n)=>dt(e,r.codec(),n)})(Hn||(Hn={}));var Vn;(function(r){let t;r.codec=()=>(t==null&&(t=pt((e,n,o={})=>{o.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)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={value:0},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.value=e.uint32();break}case 2:{s.expiry=e.uint64();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>ht(e,r.codec()),r.decode=(e,n)=>dt(e,r.codec(),n)})(Vn||(Vn={}));function dd(r,t){if(r.publicKey!=null||t.publicKey==null)return r;let e;r.type==="RSA"&&(e=r.toMultihash());let n=cn(t.publicKey,e);return za(n)}function bc(r,t,e){let n=Wt.decode(t);return Fe(r,n,e)}function Fe(r,t,e){let n=new Map,o=BigInt(Date.now());for(let[s,i]of t.tags.entries())i.expiry!=null&&i.expiry<o||n.set(s,i);return{...t,id:dd(r,t),addresses:t.addresses.filter(({observed:s})=>s!=null&&s>Date.now()-e).map(({multiaddr:s,isCertified:i})=>({multiaddr:kt(s),isCertified:i??!1})),metadata:t.metadata,peerRecordEnvelope:t.peerRecordEnvelope??void 0,tags:n}}function gc(r,t){return hd(r.addresses,t.addresses)&&pd(r.protocols,t.protocols)&&md(r.publicKey,t.publicKey)&&yd(r.peerRecordEnvelope,t.peerRecordEnvelope)&&bd(r.metadata,t.metadata)&&gd(r.tags,t.tags)}function hd(r,t){return wc(r,t,(e,n)=>!(e.isCertified!==n.isCertified||!V(e.multiaddr,n.multiaddr)))}function pd(r,t){return wc(r,t,(e,n)=>e===n)}function md(r,t){return xc(r,t)}function yd(r,t){return xc(r,t)}function bd(r,t){return Ec(r,t,(e,n)=>V(e,n))}function gd(r,t){return Ec(r,t,(e,n)=>e.value===n.value&&e.expiry===n.expiry)}function xc(r,t){return r==null&&t==null?!0:r!=null&&t!=null?V(r,t):!1}function wc(r,t,e){if(r.length!==t.length)return!1;for(let n=0;n<r.length;n++)if(!e(r[n],t[n]))return!1;return!0}function Ec(r,t,e){if(r.size!==t.size)return!1;for(let[n,o]of r.entries()){let s=t.get(n);if(s==null||!e(o,s))return!1}return!0}var Gt="/",vc=new TextEncoder().encode(Gt),Fn=vc[0],Wn=class r{_buf;constructor(t,e){if(typeof t=="string")this._buf=U(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]!==Fn)throw new Error("Invalid key")}toString(t="utf8"){return K(this._buf,t)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(t){return new r(t.join(Gt))}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=vc),this._buf[0]!==Fn){let t=new Uint8Array(this._buf.byteLength+1);t.fill(Fn,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Fn;)this._buf=this._buf.subarray(0,-1)}less(t){let e=this.list(),n=t.list();for(let o=0;o<e.length;o++){if(n.length<o+1)return!1;let s=e[o],i=n[o];if(s<i)return!0;if(s>i)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(Gt).slice(1)}type(){return xd(this.baseNamespace())}name(){return wd(this.baseNamespace())}instance(t){return new r(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(Gt)||(t+=Gt),t+=this.type(),new r(t)}parent(){let t=this.list();return t.length===1?new r(Gt):new r(t.slice(0,-1).join(Gt))}child(t){return this.toString()===Gt?t:t.toString()===Gt?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(),...Ed(t.map(e=>e.namespaces()))])}};function xd(r){let t=r.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function wd(r){let t=r.split(":");return t[t.length-1]}function Ed(r){return[].concat(...r)}var $s="/peers/";function Dr(r){if(!xe(r)||r.type==null)throw new N("Invalid PeerId");let t=r.toCID().toString();return new Wn(`${$s}${t}`)}async function Sc(r,t,e,n,o){let s=new Map;for(let i of e){if(i==null)continue;if(i.multiaddr instanceof Uint8Array&&(i.multiaddr=kt(i.multiaddr)),!wn(i.multiaddr))throw new N("Multiaddr was invalid");if(!await t(r,i.multiaddr,o))continue;let a=i.isCertified??!1,c=i.multiaddr.toString(),l=s.get(c);l!=null?i.isCertified=l.isCertified||a:s.set(c,{multiaddr:i.multiaddr,isCertified:a})}return[...s.values()].sort((i,a)=>i.multiaddr.toString().localeCompare(a.multiaddr.toString())).map(({isCertified:i,multiaddr:a})=>{let c=a.getPeerId();return r.equals(c)&&(a=a.decapsulate(kt(`/p2p/${r}`))),{isCertified:i,multiaddr:a.bytes}})}async function $n(r,t,e,n){if(t==null)throw new N("Invalid PeerData");if(t.publicKey!=null&&r.publicKey!=null&&!t.publicKey.equals(r.publicKey))throw new N("publicKey bytes do not match peer id publicKey bytes");let o=n.existingPeer?.peer;if(o!=null&&!r.equals(o.id))throw new N("peer id did not match existing peer id");let s=o?.addresses??[],i=new Set(o?.protocols??[]),a=o?.metadata??new Map,c=o?.tags??new Map,l=o?.peerRecordEnvelope;if(e==="patch"){if((t.multiaddrs!=null||t.addresses!=null)&&(s=[],t.multiaddrs!=null&&s.push(...t.multiaddrs.map(h=>({isCertified:!1,multiaddr:h}))),t.addresses!=null&&s.push(...t.addresses)),t.protocols!=null&&(i=new Set(t.protocols)),t.metadata!=null){let h=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);a=Gn(h,{validate:Ac})}if(t.tags!=null){let h=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags);c=Gn(h,{validate:Ic,map:_c})}t.peerRecordEnvelope!=null&&(l=t.peerRecordEnvelope)}if(e==="merge"){if(t.multiaddrs!=null&&s.push(...t.multiaddrs.map(h=>({isCertified:!1,multiaddr:h}))),t.addresses!=null&&s.push(...t.addresses),t.protocols!=null&&(i=new Set([...i,...t.protocols])),t.metadata!=null){let h=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);for(let[m,w]of h)w==null?a.delete(m):a.set(m,w);a=Gn([...a.entries()],{validate:Ac})}if(t.tags!=null){let h=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags),m=new Map(c);for(let[w,E]of h)E==null?m.delete(w):m.set(w,E);c=Gn([...m.entries()],{validate:Ic,map:_c})}t.peerRecordEnvelope!=null&&(l=t.peerRecordEnvelope)}let u;o?.id.publicKey!=null?u=Et(o.id.publicKey):t.publicKey!=null?u=Et(t.publicKey):r.publicKey!=null&&(u=Et(r.publicKey));let f={addresses:await Sc(r,n.addressFilter??(async()=>!0),s,n.existingPeer?.peerPB.addresses,n),protocols:[...i.values()].sort((h,m)=>h.localeCompare(m)),metadata:a,tags:c,publicKey:u,peerRecordEnvelope:l};return f.addresses.forEach(h=>{h.observed=n.existingPeer?.peerPB.addresses?.find(m=>V(m.multiaddr,m.multiaddr))?.observed??Date.now()}),r.type!=="RSA"&&delete f.publicKey,f}function Gn(r,t){let e=new Map;for(let[n,o]of r)o!=null&&t.validate(n,o);for(let[n,o]of r.sort(([s],[i])=>s.localeCompare(i)))o!=null&&e.set(n,t.map?.(n,o)??o);return e}function Ac(r,t){if(typeof r!="string")throw new N("Metadata key must be a string");if(!(t instanceof Uint8Array))throw new N("Metadata value must be a Uint8Array")}function Ic(r,t){if(typeof r!="string")throw new N("Tag name must be a string");if(t.value!=null){if(parseInt(`${t.value}`,10)!==t.value)throw new N("Tag value must be an integer");if(t.value<0||t.value>100)throw new N("Tag value must be between 0-100")}if(t.ttl!=null){if(parseInt(`${t.ttl}`,10)!==t.ttl)throw new N("Tag ttl must be an integer");if(t.ttl<0)throw new N("Tag ttl must be between greater than 0")}}function _c(r,t){let e;t.expiry!=null&&(e=t.expiry),t.ttl!=null&&(e=BigInt(Date.now()+Number(t.ttl)));let n={value:t.value??0};return e!=null&&(n.expiry=e),n}function Cc(r){let t=r.toString().split("/")[2],e=Z.parse(t,Dt);return un(e)}function Zs(r,t,e){let n=Cc(r);return bc(n,t,e)}function vd(r,t){return{prefix:$s,filters:(r.filters??[]).map(e=>({key:n,value:o})=>e(Zs(n,o,t))),orders:(r.orders??[]).map(e=>(n,o)=>e(Zs(n.key,n.value,t),Zs(o.key,o.value,t)))}}var Zn=class{peerId;datastore;locks;addressFilter;log;maxAddressAge;maxPeerAge;constructor(t,e={}){this.log=t.logger.forComponent("libp2p:peer-store"),this.peerId=t.peerId,this.datastore=t.datastore,this.addressFilter=e.addressFilter,this.locks=qs({name:"libp2p_peer_store_locks",metrics:t.metrics}),this.maxAddressAge=e.maxAddressAge??36e5,this.maxPeerAge=e.maxPeerAge??216e5}getLock(t){let e=this.locks.get(t);return e==null&&(e={refs:0,lock:Gs({name:t.toString(),singleProcess:!0})},this.locks.set(t,e)),e.refs++,e}maybeRemoveLock(t,e){e.refs--,e.refs===0&&(e.lock.finalize(),this.locks.delete(t))}async getReadLock(t,e){let n=this.getLock(t);try{let o=await n.lock.readLock(e);return()=>{o(),this.maybeRemoveLock(t,n)}}catch(o){throw this.maybeRemoveLock(t,n),o}}async getWriteLock(t,e){let n=this.getLock(t);try{let o=await n.lock.writeLock(e);return()=>{o(),this.maybeRemoveLock(t,n)}}catch(o){throw this.maybeRemoveLock(t,n),o}}async has(t,e){try{return await this.load(t,e),!0}catch(n){if(n.name!=="NotFoundError")throw n}return!1}async delete(t,e){this.peerId.equals(t)||await this.datastore.delete(Dr(t),e)}async load(t,e){let n=Dr(t),o=await this.datastore.get(n,e),s=Wt.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,e),new Ge;return Fe(t,s,this.peerId.equals(t)?1/0:this.maxAddressAge)}async save(t,e,n){let o=await this.#t(t,n),s=await $n(t,e,"patch",{...n,addressFilter:this.addressFilter});return this.#e(t,s,o)}async patch(t,e,n){let o=await this.#t(t,n),s=await $n(t,e,"patch",{...n,addressFilter:this.addressFilter,existingPeer:o});return this.#e(t,s,o)}async merge(t,e,n){let o=await this.#t(t,n),s=await $n(t,e,"merge",{addressFilter:this.addressFilter,existingPeer:o});return this.#e(t,s,o)}async*all(t){for await(let{key:e,value:n}of this.datastore.query(vd(t??{},this.maxAddressAge),t)){let o=Cc(e);if(o.equals(this.peerId))continue;let s=Wt.decode(n);if(this.#r(o,s)){await this.datastore.delete(e,t);continue}yield Fe(o,s,this.peerId.equals(o)?1/0:this.maxAddressAge)}}async#t(t,e){try{let n=Dr(t),o=await this.datastore.get(n,e),s=Wt.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,e),new Ge;return{peerPB:s,peer:Fe(t,s,this.maxAddressAge)}}catch(n){n.name!=="NotFoundError"&&this.log.error("invalid peer data found in peer store - %e",n)}}async#e(t,e,n,o){e.updated=Date.now();let s=Wt.encode(e);return await this.datastore.put(Dr(t),s,o),{peer:Fe(t,e,this.maxAddressAge),previous:n?.peer,updated:n==null||!gc(e,n.peerPB)}}#r(t,e){if(e.updated==null)return!0;if(this.peerId.equals(t))return!1;let n=e.updated<Date.now()-this.maxPeerAge,o=Date.now()-this.maxAddressAge,s=e.addresses.filter(i=>i.observed!=null&&i.observed>o);return n&&s.length===0}};var js=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 Zn(t,e)}[Symbol.toStringTag]="@libp2p/peer-store";async forEach(t,e){for await(let n of this.store.all(e))t(n)}async all(t){return uc(this.store.all(t))}async delete(t,e){let n=await this.store.getReadLock(t,e);try{await this.store.delete(t,e)}finally{n()}}async has(t,e){let n=await this.store.getReadLock(t,e);try{return await this.store.has(t,e)}finally{this.log.trace("has release read lock"),n?.()}}async get(t,e){let n=await this.store.getReadLock(t,e);try{return await this.store.load(t,e)}finally{n?.()}}async getInfo(t,e){let n=await this.get(t,e);return{id:n.id,multiaddrs:n.addresses.map(({multiaddr:o})=>o)}}async save(t,e,n){let o=await this.store.getWriteLock(t,n);try{let s=await this.store.save(t,e,n);return this.#t(t,s),s.peer}finally{o?.()}}async patch(t,e,n){let o=await this.store.getWriteLock(t,n);try{let s=await this.store.patch(t,e,n);return this.#t(t,s),s.peer}finally{o?.()}}async merge(t,e,n){let o=await this.store.getWriteLock(t,n);try{let s=await this.store.merge(t,e,n);return this.#t(t,s),s.peer}finally{o?.()}}async consumePeerRecord(t,e,n){let o=xe(e)?e:xe(e?.expectedPeer)?e.expectedPeer:void 0,s=xe(e)||e===void 0?n:e,i=await ze.openAndCertify(t,me.DOMAIN,s),a=un(i.publicKey.toCID());if(o?.equals(a)===!1)return this.log("envelope peer id was not the expected peer id - expected: %p received: %p",o,a),!1;let c=me.createFromProtobuf(i.payload),l;try{l=await this.get(a,s)}catch(u){if(u.name!=="NotFoundError")throw u}if(l?.peerRecordEnvelope!=null){let u=ze.createFromProtobuf(l.peerRecordEnvelope),f=me.createFromProtobuf(u.payload);if(f.seqNumber>=c.seqNumber)return this.log("sequence number was lower or equal to existing sequence number - stored: %d received: %d",f.seqNumber,c.seqNumber),!1}return await this.patch(c.peerId,{peerRecordEnvelope:t,addresses:c.multiaddrs.map(u=>({isCertified:!0,multiaddr:u}))},s),!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}))}};function Sd(r,t={}){return new js(r,t)}return Lc(Ad);})();
2
+ "use strict";var Libp2PPeerStore=(()=>{var Yn=Object.defineProperty;var Cc=Object.getOwnPropertyDescriptor;var Bc=Object.getOwnPropertyNames;var Dc=Object.prototype.hasOwnProperty;var mt=(r,t)=>{for(var e in t)Yn(r,e,{get:t[e],enumerable:!0})},Rc=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Bc(t))!Dc.call(r,o)&&o!==e&&Yn(r,o,{get:()=>t[o],enumerable:!(n=Cc(t,o))||n.enumerable});return r};var Lc=r=>Rc(Yn({},"__esModule",{value:!0}),r);var Ad={};mt(Ad,{persistentPeerStore:()=>Sd});var Rr=Symbol.for("@libp2p/peer-id");function xe(r){return!!r?.[Rr]}var N=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},we=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Ge=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var Lr=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},Pr=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 Ee=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){super.addEventListener(t,e,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==e),this.#t.set(t,o))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var eo={};mt(eo,{base58btc:()=>H,base58flickr:()=>Mc});var Bd=new Uint8Array(0);function Ys(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 Kt(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 Xs(r){return new TextEncoder().encode(r)}function Qs(r){return new TextDecoder().decode(r)}function Pc(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),l=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function f(w){if(w instanceof Uint8Array||(ArrayBuffer.isView(w)?w=new Uint8Array(w.buffer,w.byteOffset,w.byteLength):Array.isArray(w)&&(w=Uint8Array.from(w))),!(w instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(w.length===0)return"";for(var E=0,p=0,S=0,C=w.length;S!==C&&w[S]===0;)S++,E++;for(var A=(C-S)*u+1>>>0,L=new Uint8Array(A);S!==C;){for(var b=w[S],R=0,D=A-1;(b!==0||R<p)&&D!==-1;D--,R++)b+=256*L[D]>>>0,L[D]=b%a>>>0,b=b/a>>>0;if(b!==0)throw new Error("Non-zero carry");p=R,S++}for(var _=A-p;_!==A&&L[_]===0;)_++;for(var d=c.repeat(E);_<A;++_)d+=r.charAt(L[_]);return d}function h(w){if(typeof w!="string")throw new TypeError("Expected String");if(w.length===0)return new Uint8Array;var E=0;if(w[E]!==" "){for(var p=0,S=0;w[E]===c;)p++,E++;for(var C=(w.length-E)*l+1>>>0,A=new Uint8Array(C);w[E];){var L=e[w.charCodeAt(E)];if(L===255)return;for(var b=0,R=C-1;(L!==0||b<S)&&R!==-1;R--,b++)L+=a*A[R]>>>0,A[R]=L%256>>>0,L=L/256>>>0;if(L!==0)throw new Error("Non-zero carry");S=b,E++}if(w[E]!==" "){for(var D=C-S;D!==C&&A[D]===0;)D++;for(var _=new Uint8Array(p+(C-D)),d=p;D!==C;)_[d++]=A[D++];return _}}}function m(w){var E=h(w);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:h,decode:m}}var kc=Pc,Oc=kc,ti=Oc;var Xn=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")}},Qn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return ei(this,t)}},Jn=class{decoders;constructor(t){this.decoders=t}or(t){return ei(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 ei(r,t){return new Jn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var to=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new Xn(t,e,n),this.decoder=new Qn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ve({name:r,prefix:t,encode:e,decode:n}){return new to(r,t,e,n)}function $t({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=ti(e,r);return ve({prefix:t,name:r,encode:n,decode:s=>Kt(o(s))})}function Kc(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let l=0;l<o;++l){let u=t[r[l]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|u,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Nc(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function Uc(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function $({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=Uc(n);return ve({prefix:t,name:r,encode(s){return Nc(s,n,e)},decode(s){return Kc(s,o,e,r)}})}var H=$t({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Mc=$t({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ro={};mt(ro,{base32:()=>Dt,base32hex:()=>Vc,base32hexpad:()=>Wc,base32hexpadupper:()=>Gc,base32hexupper:()=>Fc,base32pad:()=>zc,base32padupper:()=>Hc,base32upper:()=>qc,base32z:()=>$c});var Dt=$({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),qc=$({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),zc=$({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Hc=$({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Vc=$({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Fc=$({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Wc=$({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Gc=$({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),$c=$({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var no={};mt(no,{base36:()=>$e,base36upper:()=>Zc});var $e=$t({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Zc=$t({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var jc=oi,ri=128,Yc=127,Xc=~Yc,Qc=Math.pow(2,31);function oi(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Qc;)t[e++]=r&255|ri,r/=128;for(;r&Xc;)t[e++]=r&255|ri,r>>>=7;return t[e]=r|0,oi.bytes=e-n+1,t}var Jc=oo,tu=128,ni=127;function oo(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw oo.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&ni)<<o:(i&ni)*Math.pow(2,o),o+=7}while(i>=tu);return oo.bytes=s-n,e}var eu=Math.pow(2,7),ru=Math.pow(2,14),nu=Math.pow(2,21),ou=Math.pow(2,28),su=Math.pow(2,35),iu=Math.pow(2,42),au=Math.pow(2,49),cu=Math.pow(2,56),uu=Math.pow(2,63),lu=function(r){return r<eu?1:r<ru?2:r<nu?3:r<ou?4:r<su?5:r<iu?6:r<au?7:r<cu?8:r<uu?9:10},fu={encode:jc,decode:Jc,encodingLength:lu},du=fu,Ze=du;function je(r,t=0){return[Ze.decode(r,t),Ze.decode.bytes]}function Se(r,t,e=0){return Ze.encode(r,t,e),t}function Ae(r){return Ze.encodingLength(r)}function At(r,t){let e=t.byteLength,n=Ae(r),o=n+Ae(e),s=new Uint8Array(o+e);return Se(r,s,0),Se(e,s,n),s.set(t,o),new Ie(r,e,t,s)}function _e(r){let t=Kt(r),[e,n]=je(t),[o,s]=je(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ie(e,o,i,t)}function si(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Ys(r.bytes,e.bytes)}}var Ie=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function ii(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return pu(e,so(r),t??H.encoder);default:return mu(e,so(r),t??Dt.encoder)}}var ai=new WeakMap;function so(r){let t=ai.get(r);if(t==null){let e=new Map;return ai.set(r,e),e}return t}var Z=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==Ye)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==yu)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=At(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&&si(t.multihash,n.multihash)}toString(t){return ii(this,t)}toJSON(){return{"/":ii(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??ci(n,o,s.bytes))}else if(e[bu]===!0){let{version:n,multihash:o,code:s}=e,i=_e(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==Ye)throw new Error(`Version 0 CID must use dag-pb (code: ${Ye}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=ci(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Ye,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Kt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new Ie(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[f,h]=je(t.subarray(e));return e+=h,f},o=n(),s=Ye;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),l=e+c,u=l-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:l}}static parse(t,e){let[n,o]=hu(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return so(s).set(n,t),s}};function hu(r,t){switch(r[0]){case"Q":{let e=t??H;return[H.prefix,e.decode(`${H.prefix}${r}`)]}case H.prefix:{let e=t??H;return[H.prefix,e.decode(r)]}case Dt.prefix:{let e=t??Dt;return[Dt.prefix,e.decode(r)]}case $e.prefix:{let e=t??$e;return[$e.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function pu(r,t,e){let{prefix:n}=e;if(n!==H.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function mu(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var Ye=112,yu=18;function ci(r,t,e){let n=Ae(r),o=n+Ae(t),s=new Uint8Array(o+e.byteLength);return Se(r,s,0),Se(t,s,n),s.set(e,o),s}var bu=Symbol.for("@ipld/js-cid/CID");var io={};mt(io,{identity:()=>It});var ui=0,gu="identity",li=Kt;function xu(r){return At(ui,li(r))}var It={code:ui,name:gu,encode:li,digest:xu};function V(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 Q(r=0){return new Uint8Array(r)}function yt(r=0){return new Uint8Array(r)}function Nt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=yt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var di=Symbol.for("@achingbrain/uint8arraylist");function fi(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function Or(r){return!!r?.[di]}var ut=class r{bufs;length;[di]=!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(Or(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(Or(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=fi(this.bufs,t);return e.buf[e.index]}set(t,e){let n=fi(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(Or(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return Nt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Nt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let l=t>=a&&t<c,u=e>a&&e<=c;if(l&&u){if(t===a&&e===c){n.push(i);break}let f=t-a;n.push(i.subarray(f,f+(e-t)));break}if(l){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(u){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Or(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,l=n.byteLength-1,u;for(let f=e;f<=c;f+=u){u=0;for(let h=l;h>=0;h--){let m=this.get(f+h);if(n[h]!==m){u=Math.max(1,h-a[m]);break}}if(u===0)return f}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=yt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=Q(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=Q(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=Q(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=yt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=Q(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=Q(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=Q(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=Q(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=Q(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!V(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var ao={};mt(ao,{base10:()=>wu});var wu=$t({prefix:"9",name:"base10",alphabet:"0123456789"});var co={};mt(co,{base16:()=>Eu,base16upper:()=>vu});var Eu=$({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),vu=$({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var uo={};mt(uo,{base2:()=>Su});var Su=$({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var lo={};mt(lo,{base256emoji:()=>Cu});var hi=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}"),Au=hi.reduce((r,t,e)=>(r[e]=t,r),[]),Iu=hi.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function _u(r){return r.reduce((t,e)=>(t+=Au[e],t),"")}function Tu(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Iu[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Cu=ve({prefix:"\u{1F680}",name:"base256emoji",encode:_u,decode:Tu});var ho={};mt(ho,{base64:()=>Bu,base64pad:()=>Du,base64url:()=>fo,base64urlpad:()=>Ru});var Bu=$({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Du=$({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),fo=$({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ru=$({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var po={};mt(po,{base8:()=>Lu});var Lu=$({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var mo={};mt(mo,{identity:()=>Pu});var Pu=ve({prefix:"\0",name:"identity",encode:r=>Qs(r),decode:r=>Xs(r)});var dh=new TextEncoder,hh=new TextDecoder;var go={};mt(go,{sha256:()=>Xe,sha512:()=>Ku});function bo({name:r,code:t,encode:e}){return new yo(r,t,e)}var yo=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?At(this.code,e):e.then(n=>At(this.code,n))}else throw Error("Unknown type, must be binary type")}};function mi(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Xe=bo({name:"sha2-256",code:18,encode:mi("SHA-256")}),Ku=bo({name:"sha2-512",code:19,encode:mi("SHA-512")});var Qe={...mo,...uo,...po,...ao,...co,...ro,...no,...eo,...ho,...lo},Ih={...go,...io};function bi(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var yi=bi("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),xo=bi("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=yt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Nu={utf8:yi,"utf-8":yi,hex:Qe.base16,latin1:xo,ascii:xo,binary:xo,...Qe},Kr=Nu;function U(r,t="utf8"){let e=Kr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function K(r,t="utf8"){let e=Kr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Uu=parseInt("11111",2),wo=parseInt("10000000",2),Mu=parseInt("01111111",2),gi={0:Je,1:Je,2:qu,3:Vu,4:Fu,5:Hu,6:zu,16:Je,22:Je,48:Je};function Ut(r,t={offset:0}){let e=r[t.offset]&Uu;if(t.offset++,gi[e]!=null)return gi[e](r,t);throw new Error("No decoder for tag "+e)}function tr(r,t){let e=0;if((r[t.offset]&wo)===wo){let n=r[t.offset]&Mu,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function Je(r,t){tr(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Ut(r,t);if(n===null)break;e.push(n)}return e}function qu(r,t){let e=tr(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function zu(r,t){let e=tr(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let l=r[t.offset];if(t.offset++,c.push(l&127),l<128){c.reverse();let u=0;for(let f=0;f<c.length;f++)u+=c[f]<<f*7;a+=`.${u}`,c=[]}}return a}function Hu(r,t){return t.offset++,null}function Vu(r,t){let e=tr(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Fu(r,t){let e=tr(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Wu(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new ut;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Eo(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Wu(r.byteLength);return new ut(Uint8Array.from([t.byteLength|wo]),t)}function bt(r){let t=new ut,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new ut(Uint8Array.from([2]),Eo(t),t)}function Nr(r){let t=Uint8Array.from([0]),e=new ut(t,r);return new ut(Uint8Array.from([3]),Eo(e),e)}function jt(r,t=48){let e=new ut;for(let n of r)e.append(n);return new ut(Uint8Array.from([t]),Eo(e),e)}async function xi(r,t,e,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,e.subarray());return n?.signal?.throwIfAborted(),s}var Gu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),$u=Uint8Array.from([6,5,43,129,4,0,34]),Zu=Uint8Array.from([6,5,43,129,4,0,35]),ju={ext:!0,kty:"EC",crv:"P-256"},Yu={ext:!0,kty:"EC",crv:"P-384"},Xu={ext:!0,kty:"EC",crv:"P-521"},vo=32,So=48,Ao=66;function Io(r){let t=Ut(r);return wi(t)}function wi(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===vo*2+1)return n=K(t.subarray(e,e+vo),"base64url"),o=K(t.subarray(e+vo),"base64url"),new Te({...ju,key_ops:["verify"],x:n,y:o});if(t.byteLength===So*2+1)return n=K(t.subarray(e,e+So),"base64url"),o=K(t.subarray(e+So),"base64url"),new Te({...Yu,key_ops:["verify"],x:n,y:o});if(t.byteLength===Ao*2+1)return n=K(t.subarray(e,e+Ao),"base64url"),o=K(t.subarray(e+Ao),"base64url"),new Te({...Xu,key_ops:["verify"],x:n,y:o});throw new N(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Ei(r){return jt([bt(Uint8Array.from([1])),jt([Qu(r.crv)],160),jt([Nr(new ut(Uint8Array.from([4]),U(r.x??"","base64url"),U(r.y??"","base64url")))],161)]).subarray()}function Qu(r){if(r==="P-256")return Gu;if(r==="P-384")return $u;if(r==="P-521")return Zu;throw new N(`Invalid curve ${r}`)}var Te=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Ei(this.jwk)),this._raw}toMultihash(){return It.digest(Et(this))}toCID(){return Z.createV1(114,this.toMultihash())}toString(){return H.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:V(this.raw,t.raw)}async verify(t,e,n){return xi(this.jwk,e,t,n)}};var oe=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Be(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function er(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function st(r,...t){if(!Be(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error("Uint8Array expected of length "+t+", got length="+r.length)}function Si(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");er(r.outputLen),er(r.blockLen)}function De(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 Ai(r,t){st(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}function qt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Ur(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function _t(r,t){return r<<32-t|r>>>t}var Ii=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Ju=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Rt(r){if(st(r),Ii)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=Ju[r[e]];return t}var Mt={_0:48,_9:57,A:65,F:70,a:97,f:102};function vi(r){if(r>=Mt._0&&r<=Mt._9)return r-Mt._0;if(r>=Mt.A&&r<=Mt.F)return r-(Mt.A-10);if(r>=Mt.a&&r<=Mt.f)return r-(Mt.a-10)}function Re(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(Ii)return Uint8Array.fromHex(r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=vi(r.charCodeAt(s)),a=vi(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function _i(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function rr(r){return typeof r=="string"&&(r=_i(r)),st(r),r}function gt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];st(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}var Ce=class{};function _o(r){let t=n=>r().update(rr(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function nr(r=32){if(oe&&typeof oe.getRandomValues=="function")return oe.getRandomValues(new Uint8Array(r));if(oe&&typeof oe.randomBytes=="function")return Uint8Array.from(oe.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function tl(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(e>>o&s),a=Number(e&s),c=n?4:0,l=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+l,a,n)}function Ti(r,t,e){return r&t^~r&e}function Ci(r,t,e){return r&t^r&e^t&e}var or=class extends Ce{constructor(t,e,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Ur(this.buffer)}update(t){De(this),t=rr(t),st(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Ur(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){De(this),Ai(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,qt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)e[f]=0;tl(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=Ur(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=c/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<l;f++)a.setUint32(4*f,u[f],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},zt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var rt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Mr=BigInt(4294967295),Bi=BigInt(32);function el(r,t=!1){return t?{h:Number(r&Mr),l:Number(r>>Bi&Mr)}:{h:Number(r>>Bi&Mr)|0,l:Number(r&Mr)|0}}function Di(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:a}=el(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var To=(r,t,e)=>r>>>e,Co=(r,t,e)=>r<<32-e|t>>>e,se=(r,t,e)=>r>>>e|t<<32-e,ie=(r,t,e)=>r<<32-e|t>>>e,sr=(r,t,e)=>r<<64-e|t>>>e-32,ir=(r,t,e)=>r>>>e-32|t<<64-e;function Lt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Ri=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Li=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Pi=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),ki=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Oi=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Ki=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var nl=Uint32Array.from([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]),Yt=new Uint32Array(64),qr=class extends or{constructor(t=32){super(64,t,8,!1),this.A=zt[0]|0,this.B=zt[1]|0,this.C=zt[2]|0,this.D=zt[3]|0,this.E=zt[4]|0,this.F=zt[5]|0,this.G=zt[6]|0,this.H=zt[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let f=0;f<16;f++,e+=4)Yt[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let h=Yt[f-15],m=Yt[f-2],w=_t(h,7)^_t(h,18)^h>>>3,E=_t(m,17)^_t(m,19)^m>>>10;Yt[f]=E+Yt[f-7]+w+Yt[f-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:l,H:u}=this;for(let f=0;f<64;f++){let h=_t(a,6)^_t(a,11)^_t(a,25),m=u+h+Ti(a,c,l)+nl[f]+Yt[f]|0,E=(_t(n,2)^_t(n,13)^_t(n,22))+Ci(n,o,s)|0;u=l,l=c,c=a,a=i+m|0,i=s,s=o,o=n,n=m+E|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,u=u+this.H|0,this.set(n,o,s,i,a,c,l,u)}roundClean(){qt(Yt)}destroy(){this.set(0,0,0,0,0,0,0,0),qt(this.buffer)}};var Ni=Di(["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))),ol=Ni[0],sl=Ni[1],Xt=new Uint32Array(80),Qt=new Uint32Array(80),Bo=class extends or{constructor(t=64){super(128,t,16,!1),this.Ah=rt[0]|0,this.Al=rt[1]|0,this.Bh=rt[2]|0,this.Bl=rt[3]|0,this.Ch=rt[4]|0,this.Cl=rt[5]|0,this.Dh=rt[6]|0,this.Dl=rt[7]|0,this.Eh=rt[8]|0,this.El=rt[9]|0,this.Fh=rt[10]|0,this.Fl=rt[11]|0,this.Gh=rt[12]|0,this.Gl=rt[13]|0,this.Hh=rt[14]|0,this.Hl=rt[15]|0}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:l,El:u,Fh:f,Fl:h,Gh:m,Gl:w,Hh:E,Hl:p}=this;return[t,e,n,o,s,i,a,c,l,u,f,h,m,w,E,p]}set(t,e,n,o,s,i,a,c,l,u,f,h,m,w,E,p){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=l|0,this.El=u|0,this.Fh=f|0,this.Fl=h|0,this.Gh=m|0,this.Gl=w|0,this.Hh=E|0,this.Hl=p|0}process(t,e){for(let A=0;A<16;A++,e+=4)Xt[A]=t.getUint32(e),Qt[A]=t.getUint32(e+=4);for(let A=16;A<80;A++){let L=Xt[A-15]|0,b=Qt[A-15]|0,R=se(L,b,1)^se(L,b,8)^To(L,b,7),D=ie(L,b,1)^ie(L,b,8)^Co(L,b,7),_=Xt[A-2]|0,d=Qt[A-2]|0,x=se(_,d,19)^sr(_,d,61)^To(_,d,6),y=ie(_,d,19)^ir(_,d,61)^Co(_,d,6),g=Pi(D,y,Qt[A-7],Qt[A-16]),v=ki(g,R,x,Xt[A-7],Xt[A-16]);Xt[A]=v|0,Qt[A]=g|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:l,Dl:u,Eh:f,El:h,Fh:m,Fl:w,Gh:E,Gl:p,Hh:S,Hl:C}=this;for(let A=0;A<80;A++){let L=se(f,h,14)^se(f,h,18)^sr(f,h,41),b=ie(f,h,14)^ie(f,h,18)^ir(f,h,41),R=f&m^~f&E,D=h&w^~h&p,_=Oi(C,b,D,sl[A],Qt[A]),d=Ki(_,S,L,R,ol[A],Xt[A]),x=_|0,y=se(n,o,28)^sr(n,o,34)^sr(n,o,39),g=ie(n,o,28)^ir(n,o,34)^ir(n,o,39),v=n&s^n&a^s&a,T=o&i^o&c^i&c;S=E|0,C=p|0,E=m|0,p=w|0,m=f|0,w=h|0,{h:f,l:h}=Lt(l|0,u|0,d|0,x|0),l=a|0,u=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let I=Ri(x,g,T);n=Li(I,d,y,v),o=I|0}({h:n,l:o}=Lt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Lt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Lt(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:u}=Lt(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:h}=Lt(this.Eh|0,this.El|0,f|0,h|0),{h:m,l:w}=Lt(this.Fh|0,this.Fl|0,m|0,w|0),{h:E,l:p}=Lt(this.Gh|0,this.Gl|0,E|0,p|0),{h:S,l:C}=Lt(this.Hh|0,this.Hl|0,S|0,C|0),this.set(n,o,s,i,a,c,l,u,f,h,m,w,E,p,S,C)}roundClean(){qt(Xt,Qt)}destroy(){qt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var zr=_o(()=>new qr);var Ui=_o(()=>new Bo);var Lo=BigInt(0),Ro=BigInt(1);function Ht(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function ar(r){let t=r.toString(16);return t.length&1?"0"+t:t}function Mi(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Lo:BigInt("0x"+r)}function Le(r){return Mi(Rt(r))}function ae(r){return st(r),Mi(Rt(Uint8Array.from(r).reverse()))}function Hr(r,t){return Re(r.toString(16).padStart(t*2,"0"))}function Pe(r,t){return Hr(r,t).reverse()}function F(r,t,e){let n;if(typeof t=="string")try{n=Re(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(Be(t))n=Uint8Array.from(t);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof e=="number"&&o!==e)throw new Error(r+" of length "+e+" expected, got "+o);return n}var Do=r=>typeof r=="bigint"&&Lo<=r;function qi(r,t,e){return Do(r)&&Do(t)&&Do(e)&&t<=r&&r<e}function Jt(r,t,e,n){if(!qi(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function zi(r){let t;for(t=0;r>Lo;r>>=Ro,t+=1);return t}var ce=r=>(Ro<<BigInt(r))-Ro;function Hi(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=m=>new Uint8Array(m),o=m=>Uint8Array.of(m),s=n(r),i=n(r),a=0,c=()=>{s.fill(1),i.fill(0),a=0},l=(...m)=>e(i,s,...m),u=(m=n(0))=>{i=l(o(0),m),s=l(),m.length!==0&&(i=l(o(1),m),s=l())},f=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let m=0,w=[];for(;m<t;){s=l();let E=s.slice();w.push(E),m+=s.length}return gt(...w)};return(m,w)=>{c(),u(m);let E;for(;!(E=w(f()));)u();return c(),E}}function te(r,t,e={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(o,s,i){let a=r[o];if(i&&a===void 0)return;let c=typeof a;if(c!==s||a===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${c}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(e).forEach(([o,s])=>n(o,s,!0))}function ke(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var lt=BigInt(0),tt=BigInt(1),ue=BigInt(2),il=BigInt(3),Wi=BigInt(4),Gi=BigInt(5),$i=BigInt(8);function G(r,t){let e=r%t;return e>=lt?e:t+e}function W(r,t,e){let n=r;for(;t-- >lt;)n*=n,n%=e;return n}function Vi(r,t){if(r===lt)throw new Error("invert: expected non-zero number");if(t<=lt)throw new Error("invert: expected positive modulus, got "+t);let e=G(r,t),n=t,o=lt,s=tt,i=tt,a=lt;for(;e!==lt;){let l=n/e,u=n%e,f=o-i*l,h=s-a*l;n=e,e=u,o=i,s=a,i=f,a=h}if(n!==tt)throw new Error("invert: does not exist");return G(o,t)}function Zi(r,t){let e=(r.ORDER+tt)/Wi,n=r.pow(t,e);if(!r.eql(r.sqr(n),t))throw new Error("Cannot find square root");return n}function al(r,t){let e=(r.ORDER-Gi)/$i,n=r.mul(t,ue),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,ue),o),a=r.mul(s,r.sub(i,r.ONE));if(!r.eql(r.sqr(a),t))throw new Error("Cannot find square root");return a}function cl(r){if(r<BigInt(3))throw new Error("sqrt is not defined for small field");let t=r-tt,e=0;for(;t%ue===lt;)t/=ue,e++;let n=ue,o=Tt(r);for(;Fi(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return Zi;let s=o.pow(n,t),i=(t+tt)/ue;return function(c,l){if(c.is0(l))return l;if(Fi(c,l)!==1)throw new Error("Cannot find square root");let u=e,f=c.mul(c.ONE,s),h=c.pow(l,t),m=c.pow(l,i);for(;!c.eql(h,c.ONE);){if(c.is0(h))return c.ZERO;let w=1,E=c.sqr(h);for(;!c.eql(E,c.ONE);)if(w++,E=c.sqr(E),w===u)throw new Error("Cannot find square root");let p=tt<<BigInt(u-w-1),S=c.pow(f,p);u=w,f=c.sqr(S),h=c.mul(h,f),m=c.mul(m,S)}return m}}function ul(r){return r%Wi===il?Zi:r%$i===Gi?al:cl(r)}var ji=(r,t)=>(G(r,t)&tt)===tt,ll=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Po(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},e=ll.reduce((n,o)=>(n[o]="function",n),t);return te(r,e),r}function fl(r,t,e){if(e<lt)throw new Error("invalid exponent, negatives unsupported");if(e===lt)return r.ONE;if(e===tt)return t;let n=r.ONE,o=t;for(;e>lt;)e&tt&&(n=r.mul(n,o)),o=r.sqr(o),e>>=tt;return n}function cr(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,a,c)=>r.is0(a)?i:(n[c]=i,r.mul(i,a)),r.ONE),s=r.inv(o);return t.reduceRight((i,a,c)=>r.is0(a)?i:(n[c]=r.mul(i,n[c]),r.mul(i,a)),s),n}function Fi(r,t){let e=(r.ORDER-tt)/ue,n=r.pow(t,e),o=r.eql(n,r.ONE),s=r.eql(n,r.ZERO),i=r.eql(n,r.neg(r.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Yi(r,t){t!==void 0&&er(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Tt(r,t,e=!1,n={}){if(r<=lt)throw new Error("invalid field: expected ORDER > 0, got "+r);let o,s;if(typeof t=="object"&&t!=null){if(n.sqrt||e)throw new Error("cannot specify opts in two arguments");let u=t;u.BITS&&(o=u.BITS),u.sqrt&&(s=u.sqrt),typeof u.isLE=="boolean"&&(e=u.isLE)}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:i,nByteLength:a}=Yi(r,o);if(a>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let c,l=Object.freeze({ORDER:r,isLE:e,BITS:i,BYTES:a,MASK:ce(i),ZERO:lt,ONE:tt,create:u=>G(u,r),isValid:u=>{if(typeof u!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof u);return lt<=u&&u<r},is0:u=>u===lt,isValidNot0:u=>!l.is0(u)&&l.isValid(u),isOdd:u=>(u&tt)===tt,neg:u=>G(-u,r),eql:(u,f)=>u===f,sqr:u=>G(u*u,r),add:(u,f)=>G(u+f,r),sub:(u,f)=>G(u-f,r),mul:(u,f)=>G(u*f,r),pow:(u,f)=>fl(l,u,f),div:(u,f)=>G(u*Vi(f,r),r),sqrN:u=>u*u,addN:(u,f)=>u+f,subN:(u,f)=>u-f,mulN:(u,f)=>u*f,inv:u=>Vi(u,r),sqrt:s||(u=>(c||(c=ul(r)),c(l,u))),toBytes:u=>e?Pe(u,a):Hr(u,a),fromBytes:u=>{if(u.length!==a)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+u.length);return e?ae(u):Le(u)},invertBatch:u=>cr(l,u),cmov:(u,f,h)=>h?f:u});return Object.freeze(l)}function Xi(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 ko(r){let t=Xi(r);return t+Math.ceil(t/2)}function Qi(r,t,e=!1){let n=r.length,o=Xi(t),s=ko(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?ae(r):Le(r),a=G(i,t-tt)+tt;return e?Pe(a,o):Hr(a,o)}var Ke=BigInt(0),le=BigInt(1);function Oe(r,t){let e=t.negate();return r?e:t}function Vr(r,t,e){let n=t==="pz"?i=>i.pz:i=>i.ez,o=cr(r.Fp,e.map(n));return e.map((i,a)=>i.toAffine(o[a])).map(r.fromAffine)}function ra(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function Oo(r,t){ra(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=ce(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Ji(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),c=r>>i;a>n&&(a-=s,c+=le);let l=t*n,u=l+Math.abs(a)-1,f=a===0,h=a<0,m=t%2!==0;return{nextN:c,offset:u,isZero:f,isNeg:h,isNegF:m,offsetF:l}}function dl(r,t){if(!Array.isArray(r))throw new Error("array expected");r.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})}function hl(r,t){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}var Ko=new WeakMap,na=new WeakMap;function No(r){return na.get(r)||1}function ta(r){if(r!==Ke)throw new Error("invalid wNAF")}function Fr(r,t){return{constTimeNegate:Oe,hasPrecomputes(e){return No(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>Ke;)n&le&&(o=o.add(s)),s=s.double(),n>>=le;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=Oo(n,t),i=[],a=e,c=a;for(let l=0;l<o;l++){c=a,i.push(c);for(let u=1;u<s;u++)c=c.add(a),i.push(c);a=c.double()}return i},wNAF(e,n,o){let s=r.ZERO,i=r.BASE,a=Oo(e,t);for(let c=0;c<a.windows;c++){let{nextN:l,offset:u,isZero:f,isNeg:h,isNegF:m,offsetF:w}=Ji(o,c,a);o=l,f?i=i.add(Oe(m,n[w])):s=s.add(Oe(h,n[u]))}return ta(o),{p:s,f:i}},wNAFUnsafe(e,n,o,s=r.ZERO){let i=Oo(e,t);for(let a=0;a<i.windows&&o!==Ke;a++){let{nextN:c,offset:l,isZero:u,isNeg:f}=Ji(o,a,i);if(o=c,!u){let h=n[l];s=s.add(f?h.negate():h)}}return ta(o),s},getPrecomputes(e,n,o){let s=Ko.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&(typeof o=="function"&&(s=o(s)),Ko.set(n,s))),s},wNAFCached(e,n,o){let s=No(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=No(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){ra(n,t),na.set(e,n),Ko.delete(e)}}}function oa(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>Ke||n>Ke;)e&le&&(s=s.add(o)),n&le&&(i=i.add(o)),o=o.double(),e>>=le,n>>=le;return{p1:s,p2:i}}function Wr(r,t,e,n){dl(e,r),hl(n,t);let o=e.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=r.ZERO,a=zi(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let l=ce(c),u=new Array(Number(l)+1).fill(i),f=Math.floor((t.BITS-1)/c)*c,h=i;for(let m=f;m>=0;m-=c){u.fill(i);for(let E=0;E<s;E++){let p=n[E],S=Number(p>>BigInt(m)&l);u[S]=u[S].add(e[E])}let w=i;for(let E=u.length-1,p=i;E>0;E--)p=p.add(u[E]),w=w.add(p);if(h=h.add(w),m!==0)for(let E=0;E<c;E++)h=h.double()}return h}function ea(r,t){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Po(t),t}else return Tt(r)}function Gr(r,t,e={}){if(!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let a of["p","n","h"]){let c=t[a];if(!(typeof c=="bigint"&&c>Ke))throw new Error(`CURVE.${a} must be positive bigint`)}let n=ea(t.p,e.Fp),o=ea(t.n,e.Fn),i=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let a of i)if(!n.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return{Fp:n,Fn:o}}var Pt=BigInt(0),ft=BigInt(1),Uo=BigInt(2),pl=BigInt(8),ml={zip215:!0};function yl(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),a=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,a)}function bl(r,t={}){let{Fp:e,Fn:n}=Gr("edwards",r,t),{h:o,n:s}=r;te(t,{},{uvRatio:"function"});let i=Uo<<BigInt(n.BYTES*8)-ft,a=E=>e.create(E),c=t.uvRatio||((E,p)=>{try{return{isValid:!0,value:e.sqrt(e.div(E,p))}}catch{return{isValid:!1,value:Pt}}});if(!yl(e,r,r.Gx,r.Gy))throw new Error("bad curve params: generator point");function l(E,p,S=!1){let C=S?ft:Pt;return Jt("coordinate "+E,p,C,i),p}function u(E){if(!(E instanceof m))throw new Error("ExtendedPoint expected")}let f=ke((E,p)=>{let{ex:S,ey:C,ez:A}=E,L=E.is0();p==null&&(p=L?pl:e.inv(A));let b=a(S*p),R=a(C*p),D=a(A*p);if(L)return{x:Pt,y:ft};if(D!==ft)throw new Error("invZ was invalid");return{x:b,y:R}}),h=ke(E=>{let{a:p,d:S}=r;if(E.is0())throw new Error("bad point: ZERO");let{ex:C,ey:A,ez:L,et:b}=E,R=a(C*C),D=a(A*A),_=a(L*L),d=a(_*_),x=a(R*p),y=a(_*a(x+D)),g=a(d+a(S*a(R*D)));if(y!==g)throw new Error("bad point: equation left != right (1)");let v=a(C*A),T=a(L*b);if(v!==T)throw new Error("bad point: equation left != right (2)");return!0});class m{constructor(p,S,C,A){this.ex=l("x",p),this.ey=l("y",S),this.ez=l("z",C,!0),this.et=l("t",A),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:S,y:C}=p||{};return l("x",S),l("y",C),new m(S,C,ft,a(S*C))}static normalizeZ(p){return Vr(m,"ez",p)}static msm(p,S){return Wr(m,n,p,S)}_setWindowSize(p){this.precompute(p)}precompute(p=8,S=!0){return w.setWindowSize(this,p),S||this.multiply(Uo),this}assertValidity(){h(this)}equals(p){u(p);let{ex:S,ey:C,ez:A}=this,{ex:L,ey:b,ez:R}=p,D=a(S*R),_=a(L*A),d=a(C*R),x=a(b*A);return D===_&&d===x}is0(){return this.equals(m.ZERO)}negate(){return new m(a(-this.ex),this.ey,this.ez,a(-this.et))}double(){let{a:p}=r,{ex:S,ey:C,ez:A}=this,L=a(S*S),b=a(C*C),R=a(Uo*a(A*A)),D=a(p*L),_=S+C,d=a(a(_*_)-L-b),x=D+b,y=x-R,g=D-b,v=a(d*y),T=a(x*g),I=a(d*g),B=a(y*x);return new m(v,T,B,I)}add(p){u(p);let{a:S,d:C}=r,{ex:A,ey:L,ez:b,et:R}=this,{ex:D,ey:_,ez:d,et:x}=p,y=a(A*D),g=a(L*_),v=a(R*C*x),T=a(b*d),I=a((A+L)*(D+_)-y-g),B=T-v,k=T+v,P=a(g-S*y),j=a(I*B),q=a(k*P),O=a(I*P),X=a(B*k);return new m(j,q,X,O)}subtract(p){return this.add(p.negate())}multiply(p){let S=p;Jt("scalar",S,ft,s);let{p:C,f:A}=w.wNAFCached(this,S,m.normalizeZ);return m.normalizeZ([C,A])[0]}multiplyUnsafe(p,S=m.ZERO){let C=p;return Jt("scalar",C,Pt,s),C===Pt?m.ZERO:this.is0()||C===ft?this:w.wNAFCachedUnsafe(this,C,m.normalizeZ,S)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return w.wNAFCachedUnsafe(this,s).is0()}toAffine(p){return f(this,p)}clearCofactor(){return o===ft?this:this.multiplyUnsafe(o)}static fromBytes(p,S=!1){return st(p),this.fromHex(p,S)}static fromHex(p,S=!1){let{d:C,a:A}=r,L=e.BYTES;p=F("pointHex",p,L),Ht("zip215",S);let b=p.slice(),R=p[L-1];b[L-1]=R&-129;let D=ae(b),_=S?i:e.ORDER;Jt("pointHex.y",D,Pt,_);let d=a(D*D),x=a(d-ft),y=a(C*d-A),{isValid:g,value:v}=c(x,y);if(!g)throw new Error("Point.fromHex: invalid y coordinate");let T=(v&ft)===ft,I=(R&128)!==0;if(!S&&v===Pt&&I)throw new Error("Point.fromHex: x=0 and x_0=1");return I!==T&&(v=a(-v)),m.fromAffine({x:v,y:D})}static fromPrivateScalar(p){return m.BASE.multiply(p)}toBytes(){let{x:p,y:S}=this.toAffine(),C=Pe(S,e.BYTES);return C[C.length-1]|=p&ft?128:0,C}toRawBytes(){return this.toBytes()}toHex(){return Rt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}m.BASE=new m(r.Gx,r.Gy,ft,a(r.Gx*r.Gy)),m.ZERO=new m(Pt,ft,ft,Pt),m.Fp=e,m.Fn=n;let w=Fr(m,n.BYTES*8);return m}function gl(r,t){te(t,{hash:"function"},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:e,hash:n}=t,{BASE:o,Fp:s,Fn:i}=r,a=i.ORDER,c=t.randomBytes||nr,l=t.adjustScalarBytes||(b=>b),u=t.domain||((b,R,D)=>{if(Ht("phflag",D),R.length||D)throw new Error("Contexts/pre-hash are not supported");return b});function f(b){return i.create(b)}function h(b){return f(ae(b))}function m(b){let R=s.BYTES;b=F("private key",b,R);let D=F("hashed private key",n(b),2*R),_=l(D.slice(0,R)),d=D.slice(R,2*R),x=h(_);return{head:_,prefix:d,scalar:x}}function w(b){let{head:R,prefix:D,scalar:_}=m(b),d=o.multiply(_),x=d.toBytes();return{head:R,prefix:D,scalar:_,point:d,pointBytes:x}}function E(b){return w(b).pointBytes}function p(b=Uint8Array.of(),...R){let D=gt(...R);return h(n(u(D,F("context",b),!!e)))}function S(b,R,D={}){b=F("message",b),e&&(b=e(b));let{prefix:_,scalar:d,pointBytes:x}=w(R),y=p(D.context,_,b),g=o.multiply(y).toBytes(),v=p(D.context,g,x,b),T=f(y+v*d);Jt("signature.s",T,Pt,a);let I=s.BYTES,B=gt(g,Pe(T,I));return F("result",B,I*2)}let C=ml;function A(b,R,D,_=C){let{context:d,zip215:x}=_,y=s.BYTES;b=F("signature",b,2*y),R=F("message",R),D=F("publicKey",D,y),x!==void 0&&Ht("zip215",x),e&&(R=e(R));let g=ae(b.slice(y,2*y)),v,T,I;try{v=r.fromHex(D,x),T=r.fromHex(b.slice(0,y),x),I=o.multiplyUnsafe(g)}catch{return!1}if(!x&&v.isSmallOrder())return!1;let B=p(d,T.toBytes(),v.toBytes(),R);return T.add(v.multiplyUnsafe(B)).subtract(I).clearCofactor().is0()}return o.precompute(8),{getPublicKey:E,sign:S,verify:A,utils:{getExtendedPublicKey:w,randomPrivateKey:()=>c(s.BYTES),precompute(b=8,R=r.BASE){return R.precompute(b,!1)}},Point:r}}function xl(r){let t={a:r.a,d:r.d,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},e=r.Fp,n=Tt(t.n,r.nBitLength,!0),o={Fp:e,Fn:n,uvRatio:r.uvRatio},s={hash:r.hash,randomBytes:r.randomBytes,adjustScalarBytes:r.adjustScalarBytes,domain:r.domain,prehash:r.prehash,mapToCurve:r.mapToCurve};return{CURVE:t,curveOpts:o,eddsaOpts:s}}function wl(r,t){return Object.assign({},t,{ExtendedPoint:t.Point,CURVE:r})}function sa(r){let{CURVE:t,curveOpts:e,eddsaOpts:n}=xl(r),o=bl(t,e),s=gl(o,n);return wl(r,s)}var Dp=BigInt(0),El=BigInt(1),ia=BigInt(2),Rp=BigInt(3),vl=BigInt(5),Sl=BigInt(8),$r={p:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Sl,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Al(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=$r.p,a=r*r%s*r%s,c=W(a,ia,s)*a%s,l=W(c,El,s)*r%s,u=W(l,vl,s)*l%s,f=W(u,t,s)*u%s,h=W(f,e,s)*f%s,m=W(h,n,s)*h%s,w=W(m,o,s)*m%s,E=W(w,o,s)*m%s,p=W(E,t,s)*u%s;return{pow_p_5_8:W(p,ia,s)*r%s,b2:a}}function Il(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var aa=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function _l(r,t){let e=$r.p,n=G(t*t*t,e),o=G(n*n*t,e),s=Al(r*o).pow_p_5_8,i=G(r*n*s,e),a=G(t*i*i,e),c=i,l=G(i*aa,e),u=a===r,f=a===G(-r,e),h=a===G(-r*aa,e);return u&&(i=c),(f||h)&&(i=l),ji(i,e)&&(i=G(-i,e)),{isValid:u||f,value:i}}var Tl=Tt($r.p,void 0,!0),Cl={...$r,Fp:Tl,hash:Ui,adjustScalarBytes:Il,uvRatio:_l},ca=sa(Cl);var ur=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Zr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var ua={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Zr("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 vt=ua;var jr=32;var Mo,Bl=(async()=>{try{return await vt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Dl(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await vt.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await vt.get().subtle.verify({name:"Ed25519"},n,t,e instanceof Uint8Array?e:e.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Rl(r,t,e){return ca.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function la(r,t,e){return Mo==null&&(Mo=await Bl),Mo?Dl(r,t,e):Rl(r,t,e)}function Yr(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Xr=class{type="Ed25519";raw;constructor(t){this.raw=qo(t,jr)}toMultihash(){return It.digest(Et(this))}toCID(){return Z.createV1(114,this.toMultihash())}toString(){return H.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:V(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=la(this.raw,e,t);return Yr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function zo(r){return r=qo(r,jr),new Xr(r)}function qo(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new N(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var Pl=Math.pow(2,7),kl=Math.pow(2,14),Ol=Math.pow(2,21),Ho=Math.pow(2,28),Vo=Math.pow(2,35),Fo=Math.pow(2,42),Wo=Math.pow(2,49),M=128,it=127;function St(r){if(r<Pl)return 1;if(r<kl)return 2;if(r<Ol)return 3;if(r<Ho)return 4;if(r<Vo)return 5;if(r<Fo)return 6;if(r<Wo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ne(r,t,e=0){switch(St(r)){case 8:t[e++]=r&255|M,r/=128;case 7:t[e++]=r&255|M,r/=128;case 6:t[e++]=r&255|M,r/=128;case 5:t[e++]=r&255|M,r/=128;case 4:t[e++]=r&255|M,r>>>=7;case 3:t[e++]=r&255|M,r>>>=7;case 2:t[e++]=r&255|M,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Kl(r,t,e=0){switch(St(r)){case 8:t.set(e++,r&255|M),r/=128;case 7:t.set(e++,r&255|M),r/=128;case 6:t.set(e++,r&255|M),r/=128;case 5:t.set(e++,r&255|M),r/=128;case 4:t.set(e++,r&255|M),r>>>=7;case 3:t.set(e++,r&255|M),r>>>=7;case 2:t.set(e++,r&255|M),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Go(r,t){let e=r[t],n=0;if(n+=e&it,e<M||(e=r[t+1],n+=(e&it)<<7,e<M)||(e=r[t+2],n+=(e&it)<<14,e<M)||(e=r[t+3],n+=(e&it)<<21,e<M)||(e=r[t+4],n+=(e&it)*Ho,e<M)||(e=r[t+5],n+=(e&it)*Vo,e<M)||(e=r[t+6],n+=(e&it)*Fo,e<M)||(e=r[t+7],n+=(e&it)*Wo,e<M))return n;throw new RangeError("Could not decode varint")}function Nl(r,t){let e=r.get(t),n=0;if(n+=e&it,e<M||(e=r.get(t+1),n+=(e&it)<<7,e<M)||(e=r.get(t+2),n+=(e&it)<<14,e<M)||(e=r.get(t+3),n+=(e&it)<<21,e<M)||(e=r.get(t+4),n+=(e&it)*Ho,e<M)||(e=r.get(t+5),n+=(e&it)*Vo,e<M)||(e=r.get(t+6),n+=(e&it)*Fo,e<M)||(e=r.get(t+7),n+=(e&it)*Wo,e<M))return n;throw new RangeError("Could not decode varint")}function Qr(r,t,e=0){return t==null&&(t=yt(St(r))),t instanceof Uint8Array?Ne(r,t,e):Kl(r,t,e)}function $o(r,t=0){return r instanceof Uint8Array?Go(r,t):Nl(r,t)}var Zo=new Float32Array([-0]),ee=new Uint8Array(Zo.buffer);function ha(r,t,e){Zo[0]=r,t[e]=ee[0],t[e+1]=ee[1],t[e+2]=ee[2],t[e+3]=ee[3]}function pa(r,t){return ee[0]=r[t],ee[1]=r[t+1],ee[2]=r[t+2],ee[3]=r[t+3],Zo[0]}var jo=new Float64Array([-0]),at=new Uint8Array(jo.buffer);function ma(r,t,e){jo[0]=r,t[e]=at[0],t[e+1]=at[1],t[e+2]=at[2],t[e+3]=at[3],t[e+4]=at[4],t[e+5]=at[5],t[e+6]=at[6],t[e+7]=at[7]}function ya(r,t){return at[0]=r[t],at[1]=r[t+1],at[2]=r[t+2],at[3]=r[t+3],at[4]=r[t+4],at[5]=r[t+5],at[6]=r[t+6],at[7]=r[t+7],jo[0]}var Ul=BigInt(Number.MAX_SAFE_INTEGER),Ml=BigInt(Number.MIN_SAFE_INTEGER),xt=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 fe;if(t<Ul&&t>Ml)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>ba&&(o=0n,++n>ba&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return fe;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):fe}},fe=new xt(0,0);fe.toBigInt=function(){return 0n};fe.zzEncode=fe.zzDecode=function(){return this};fe.length=function(){return 1};var ba=4294967296n;function ga(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function xa(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(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,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Yo(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function Ct(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Jr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Xo=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,Ct(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 Ct(this,4);return Jr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ct(this,4);return Jr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ct(this,4);let t=pa(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Ct(this,4);let t=ya(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 Ct(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return xa(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Ct(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Ct(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new xt(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 Ct(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 Ct(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 Ct(this,8);let t=Jr(this.buf,this.pos+=4),e=Jr(this.buf,this.pos+=4);return new xt(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=Go(this.buf,this.pos);return this.pos+=St(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 Qo(r){return new Xo(r instanceof Uint8Array?r:r.subarray())}function dt(r,t,e){let n=Qo(r);return t.decode(n,void 0,e)}function Jo(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return yt(i);o+i>t&&(n=yt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var de=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function ts(){}var rs=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},ql=Jo();function zl(r){return globalThis.Buffer!=null?yt(r):ql(r)}var fr=class{len;head;tail;states;constructor(){this.len=0,this.head=new de(ts,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new de(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new ns((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(tn,10,xt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=xt.fromBigInt(t);return this._push(tn,e.length(),e)}uint64Number(t){return this._push(Ne,St(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=xt.fromBigInt(t).zzEncode();return this._push(tn,e.length(),e)}sint64Number(t){let e=xt.fromNumber(t).zzEncode();return this._push(tn,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(es,1,t?1:0)}fixed32(t){return this._push(lr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=xt.fromBigInt(t);return this._push(lr,4,e.lo)._push(lr,4,e.hi)}fixed64Number(t){let e=xt.fromNumber(t);return this._push(lr,4,e.lo)._push(lr,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(ha,4,t)}double(t){return this._push(ma,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(es,1,0):this.uint32(e)._push(Vl,e,t)}string(t){let e=ga(t);return e!==0?this.uint32(e)._push(Yo,e,t):this._push(es,1,0)}fork(){return this.states=new rs(this),this.head=this.tail=new de(ts,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 de(ts,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=zl(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function es(r,t,e){t[e]=r&255}function Hl(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var ns=class extends de{next;constructor(t,e){super(Hl,t,e),this.next=void 0}};function tn(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 lr(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 Vl(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(fr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Fl,t,r),this},fr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Wl,t,r),this});function Fl(r,t,e){t.set(r,e)}function Wl(r,t,e){r.length<40?Yo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(U(r),e)}function os(){return new fr}function ht(r,t){let e=os();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Ue;(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"})(Ue||(Ue={}));function en(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function ss(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return en("enum",Ue.VARINT,e,n)}function pt(r,t){return en("message",Ue.LENGTH_DELIMITED,r,t)}var he=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"},dr=class extends Error{code="ERR_MAX_SIZE";name="MaxSizeError"};var Y;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(Y||(Y={}));var is;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(is||(is={}));(function(r){r.codec=()=>ss(is)})(Y||(Y={}));var kt;(function(r){let t;r.codec=()=>(t==null&&(t=pt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),Y.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=Y.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>ht(e,r.codec()),r.decode=(e,n)=>dt(e,r.codec(),n)})(kt||(kt={}));var as;(function(r){let t;r.codec=()=>(t==null&&(t=pt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),Y.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=Y.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>ht(e,r.codec()),r.decode=(e,n)=>dt(e,r.codec(),n)})(as||(as={}));var pr={};mt(pr,{MAX_RSA_KEY_SIZE:()=>cs,generateRSAKeyPair:()=>Ia,jwkToJWKKeyPair:()=>_a,jwkToPkcs1:()=>jl,jwkToPkix:()=>ds,jwkToRSAPrivateKey:()=>ys,pkcs1MessageToJwk:()=>ls,pkcs1MessageToRSAPrivateKey:()=>hs,pkcs1ToJwk:()=>Zl,pkcs1ToRSAPrivateKey:()=>Aa,pkixMessageToJwk:()=>fs,pkixMessageToRSAPublicKey:()=>ms,pkixToJwk:()=>Yl,pkixToRSAPublicKey:()=>ps});var rn=zr;var Me=class{type="RSA";jwk;_raw;_multihash;constructor(t,e){this.jwk=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=pr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return Z.createV1(114,this._multihash)}toString(){return H.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:V(this.raw,t.raw)}verify(t,e,n){return Sa(this.jwk,e,t,n)}},hr=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=pr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:V(this.raw,t.raw)}sign(t,e){return va(this.jwk,t,e)}};var cs=8192,us=18,Gl=1062,$l=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Zl(r){let t=Ut(r);return ls(t)}function ls(r){return{n:K(r[1],"base64url"),e:K(r[2],"base64url"),d:K(r[3],"base64url"),p:K(r[4],"base64url"),q:K(r[5],"base64url"),dp:K(r[6],"base64url"),dq:K(r[7],"base64url"),qi:K(r[8],"base64url"),kty:"RSA"}}function jl(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new N("JWK was missing components");return jt([bt(Uint8Array.from([0])),bt(U(r.n,"base64url")),bt(U(r.e,"base64url")),bt(U(r.d,"base64url")),bt(U(r.p,"base64url")),bt(U(r.q,"base64url")),bt(U(r.dp,"base64url")),bt(U(r.dq,"base64url")),bt(U(r.qi,"base64url"))]).subarray()}function Yl(r){let t=Ut(r,{offset:0});return fs(t)}function fs(r){let t=Ut(r[1],{offset:0});return{kty:"RSA",n:K(t[0],"base64url"),e:K(t[1],"base64url")}}function ds(r){if(r.n==null||r.e==null)throw new N("JWK was missing components");return jt([$l,Nr(jt([bt(U(r.n,"base64url")),bt(U(r.e,"base64url"))]))]).subarray()}function Aa(r){let t=Ut(r);return hs(t)}function hs(r){let t=ls(r);return ys(t)}function ps(r,t){if(r.byteLength>=Gl)throw new we("Key size is too large");let e=Ut(r,{offset:0});return ms(e,r,t)}function ms(r,t,e){let n=fs(r);if(e==null){let o=rn(kt.encode({Type:Y.RSA,Data:t}));e=At(us,o)}return new Me(n,e)}function ys(r){if(Ca(r)>cs)throw new N("Key size is too large");let t=_a(r),e=rn(kt.encode({Type:Y.RSA,Data:ds(t.publicKey)})),n=At(us,e);return new hr(t.privateKey,new Me(t.publicKey,n))}async function Ia(r){if(r>cs)throw new N("Key size is too large");let t=await Ta(r),e=rn(kt.encode({Type:Y.RSA,Data:ds(t.publicKey)})),n=At(us,e);return new hr(t.privateKey,new Me(t.publicKey,n))}function _a(r){if(r==null)throw new N("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function Ta(r,t){let e=await vt.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await Xl(e,t);return{privateKey:n[0],publicKey:n[1]}}async function va(r,t,e){let n=await vt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);e?.signal?.throwIfAborted();let o=await vt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return e?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Sa(r,t,e,n){let o=await vt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await vt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,e instanceof Uint8Array?e:e.subarray());return n?.signal?.throwIfAborted(),s}async function Xl(r,t){if(r.privateKey==null||r.publicKey==null)throw new N("Private and public key are required");let e=await Promise.all([vt.get().subtle.exportKey("jwk",r.privateKey),vt.get().subtle.exportKey("jwk",r.publicKey)]);return t?.signal?.throwIfAborted(),e}function Ca(r){if(r.kty!=="RSA")throw new N("invalid key type");if(r.n==null)throw new N("invalid key modulus");return U(r.n,"base64url").length*8}var nn=class extends Ce{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Si(t);let n=rr(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),qt(s)}update(t){return De(this),this.iHash.update(t),this}digestInto(t){De(this),st(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},bs=(r,t,e)=>new nn(r,t).update(e).digest();bs.create=(r,t)=>new nn(r,t);function Ba(r){r.lowS!==void 0&&Ht("lowS",r.lowS),r.prehash!==void 0&&Ht("prehash",r.prehash)}var gs=class extends Error{constructor(t=""){super(t)}},Vt={Err:gs,_tlv:{encode:(r,t)=>{let{Err:e}=Vt;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=ar(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?ar(o.length/2|128):"";return ar(r)+s+o+t},decode(r,t){let{Err:e}=Vt,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&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 l=t.subarray(n,n+c);if(l.length!==c)throw new e("tlv.decode: length bytes not complete");if(l[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let u of l)i=i<<8|u;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=Vt;if(r<mr)throw new t("integer: negative integers are not allowed");let e=ar(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=Vt;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 Le(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Vt,o=F("signature",r),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:l,l:u}=n.decode(2,c);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(l)}},hexFromSig(r){let{_tlv:t,_int:e}=Vt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},mr=BigInt(0),yr=BigInt(1),Ql=BigInt(2),on=BigInt(3),Jl=BigInt(4);function tf(r,t,e){function n(o){let s=r.sqr(o),i=r.mul(s,o);return r.add(r.add(i,r.mul(o,t)),e)}return n}function Da(r,t,e){let{BYTES:n}=r;function o(s){let i;if(typeof s=="bigint")i=s;else{let a=F("private key",s);if(t){if(!t.includes(a.length*2))throw new Error("invalid private key");let c=new Uint8Array(n);c.set(a,c.length-a.length),a=c}try{i=r.fromBytes(a)}catch{throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof s}`)}}if(e&&(i=r.create(i)),!r.isValidNot0(i))throw new Error("invalid private key: out of range [1..N-1]");return i}return o}function ef(r,t={}){let{Fp:e,Fn:n}=Gr("weierstrass",r,t),{h:o,n:s}=r;te(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:i}=t;if(i&&(!e.is0(r.a)||typeof i.beta!="bigint"||typeof i.splitScalar!="function"))throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');function a(){if(!e.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function c(_,d,x){let{x:y,y:g}=d.toAffine(),v=e.toBytes(y);if(Ht("isCompressed",x),x){a();let T=!e.isOdd(g);return gt(Ra(T),v)}else return gt(Uint8Array.of(4),v,e.toBytes(g))}function l(_){st(_);let d=e.BYTES,x=d+1,y=2*d+1,g=_.length,v=_[0],T=_.subarray(1);if(g===x&&(v===2||v===3)){let I=e.fromBytes(T);if(!e.isValid(I))throw new Error("bad point: is not on curve, wrong x");let B=h(I),k;try{k=e.sqrt(B)}catch(q){let O=q instanceof Error?": "+q.message:"";throw new Error("bad point: is not on curve, sqrt error"+O)}a();let P=e.isOdd(k);return(v&1)===1!==P&&(k=e.neg(k)),{x:I,y:k}}else if(g===y&&v===4){let I=e.fromBytes(T.subarray(d*0,d*1)),B=e.fromBytes(T.subarray(d*1,d*2));if(!m(I,B))throw new Error("bad point: is not on curve");return{x:I,y:B}}else throw new Error(`bad point: got length ${g}, expected compressed=${x} or uncompressed=${y}`)}let u=t.toBytes||c,f=t.fromBytes||l,h=tf(e,r.a,r.b);function m(_,d){let x=e.sqr(d),y=h(_);return e.eql(x,y)}if(!m(r.Gx,r.Gy))throw new Error("bad curve params: generator point");let w=e.mul(e.pow(r.a,on),Jl),E=e.mul(e.sqr(r.b),BigInt(27));if(e.is0(e.add(w,E)))throw new Error("bad curve params: a or b");function p(_,d,x=!1){if(!e.isValid(d)||x&&e.is0(d))throw new Error(`bad point coordinate ${_}`);return d}function S(_){if(!(_ instanceof b))throw new Error("ProjectivePoint expected")}let C=ke((_,d)=>{let{px:x,py:y,pz:g}=_;if(e.eql(g,e.ONE))return{x,y};let v=_.is0();d==null&&(d=v?e.ONE:e.inv(g));let T=e.mul(x,d),I=e.mul(y,d),B=e.mul(g,d);if(v)return{x:e.ZERO,y:e.ZERO};if(!e.eql(B,e.ONE))throw new Error("invZ was invalid");return{x:T,y:I}}),A=ke(_=>{if(_.is0()){if(t.allowInfinityPoint&&!e.is0(_.py))return;throw new Error("bad point: ZERO")}let{x:d,y:x}=_.toAffine();if(!e.isValid(d)||!e.isValid(x))throw new Error("bad point: x or y not field elements");if(!m(d,x))throw new Error("bad point: equation left != right");if(!_.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function L(_,d,x,y,g){return x=new b(e.mul(x.px,_),x.py,x.pz),d=Oe(y,d),x=Oe(g,x),d.add(x)}class b{constructor(d,x,y){this.px=p("x",d),this.py=p("y",x,!0),this.pz=p("z",y),Object.freeze(this)}static fromAffine(d){let{x,y}=d||{};if(!d||!e.isValid(x)||!e.isValid(y))throw new Error("invalid affine point");if(d instanceof b)throw new Error("projective point not allowed");return e.is0(x)&&e.is0(y)?b.ZERO:new b(x,y,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){return Vr(b,"pz",d)}static fromBytes(d){return st(d),b.fromHex(d)}static fromHex(d){let x=b.fromAffine(f(F("pointHex",d)));return x.assertValidity(),x}static fromPrivateKey(d){let x=Da(n,t.allowedPrivateKeyLengths,t.wrapPrivateKey);return b.BASE.multiply(x(d))}static msm(d,x){return Wr(b,n,d,x)}precompute(d=8,x=!0){return D.setWindowSize(this,d),x||this.multiply(on),this}_setWindowSize(d){this.precompute(d)}assertValidity(){A(this)}hasEvenY(){let{y:d}=this.toAffine();if(!e.isOdd)throw new Error("Field doesn't support isOdd");return!e.isOdd(d)}equals(d){S(d);let{px:x,py:y,pz:g}=this,{px:v,py:T,pz:I}=d,B=e.eql(e.mul(x,I),e.mul(v,g)),k=e.eql(e.mul(y,I),e.mul(T,g));return B&&k}negate(){return new b(this.px,e.neg(this.py),this.pz)}double(){let{a:d,b:x}=r,y=e.mul(x,on),{px:g,py:v,pz:T}=this,I=e.ZERO,B=e.ZERO,k=e.ZERO,P=e.mul(g,g),j=e.mul(v,v),q=e.mul(T,T),O=e.mul(g,v);return O=e.add(O,O),k=e.mul(g,T),k=e.add(k,k),I=e.mul(d,k),B=e.mul(y,q),B=e.add(I,B),I=e.sub(j,B),B=e.add(j,B),B=e.mul(I,B),I=e.mul(O,I),k=e.mul(y,k),q=e.mul(d,q),O=e.sub(P,q),O=e.mul(d,O),O=e.add(O,k),k=e.add(P,P),P=e.add(k,P),P=e.add(P,q),P=e.mul(P,O),B=e.add(B,P),q=e.mul(v,T),q=e.add(q,q),P=e.mul(q,O),I=e.sub(I,P),k=e.mul(q,j),k=e.add(k,k),k=e.add(k,k),new b(I,B,k)}add(d){S(d);let{px:x,py:y,pz:g}=this,{px:v,py:T,pz:I}=d,B=e.ZERO,k=e.ZERO,P=e.ZERO,j=r.a,q=e.mul(r.b,on),O=e.mul(x,v),X=e.mul(y,T),J=e.mul(g,I),ot=e.add(x,y),z=e.add(v,T);ot=e.mul(ot,z),z=e.add(O,X),ot=e.sub(ot,z),z=e.add(x,g);let ct=e.add(v,I);return z=e.mul(z,ct),ct=e.add(O,J),z=e.sub(z,ct),ct=e.add(y,g),B=e.add(T,I),ct=e.mul(ct,B),B=e.add(X,J),ct=e.sub(ct,B),P=e.mul(j,z),B=e.mul(q,J),P=e.add(B,P),B=e.sub(X,P),P=e.add(X,P),k=e.mul(B,P),X=e.add(O,O),X=e.add(X,O),J=e.mul(j,J),z=e.mul(q,z),X=e.add(X,J),J=e.sub(O,J),J=e.mul(j,J),z=e.add(z,J),O=e.mul(X,z),k=e.add(k,O),O=e.mul(ct,z),B=e.mul(ot,B),B=e.sub(B,O),O=e.mul(ot,X),P=e.mul(ct,P),P=e.add(P,O),new b(B,k,P)}subtract(d){return this.add(d.negate())}is0(){return this.equals(b.ZERO)}multiply(d){let{endo:x}=t;if(!n.isValidNot0(d))throw new Error("invalid scalar: out of range");let y,g,v=T=>D.wNAFCached(this,T,b.normalizeZ);if(x){let{k1neg:T,k1:I,k2neg:B,k2:k}=x.splitScalar(d),{p:P,f:j}=v(I),{p:q,f:O}=v(k);g=j.add(O),y=L(x.beta,P,q,T,B)}else{let{p:T,f:I}=v(d);y=T,g=I}return b.normalizeZ([y,g])[0]}multiplyUnsafe(d){let{endo:x}=t,y=this;if(!n.isValid(d))throw new Error("invalid scalar: out of range");if(d===mr||y.is0())return b.ZERO;if(d===yr)return y;if(D.hasPrecomputes(this))return this.multiply(d);if(x){let{k1neg:g,k1:v,k2neg:T,k2:I}=x.splitScalar(d),{p1:B,p2:k}=oa(b,y,v,I);return L(x.beta,B,k,g,T)}else return D.wNAFCachedUnsafe(y,d)}multiplyAndAddUnsafe(d,x,y){let g=this.multiplyUnsafe(x).add(d.multiplyUnsafe(y));return g.is0()?void 0:g}toAffine(d){return C(this,d)}isTorsionFree(){let{isTorsionFree:d}=t;return o===yr?!0:d?d(b,this):D.wNAFCachedUnsafe(this,s).is0()}clearCofactor(){let{clearCofactor:d}=t;return o===yr?this:d?d(b,this):this.multiplyUnsafe(o)}toBytes(d=!0){return Ht("isCompressed",d),this.assertValidity(),u(b,this,d)}toRawBytes(d=!0){return this.toBytes(d)}toHex(d=!0){return Rt(this.toBytes(d))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}b.BASE=new b(r.Gx,r.Gy,e.ONE),b.ZERO=new b(e.ZERO,e.ONE,e.ZERO),b.Fp=e,b.Fn=n;let R=n.BITS,D=Fr(b,t.endo?Math.ceil(R/2):R);return b}function Ra(r){return Uint8Array.of(r?2:3)}function rf(r,t,e={}){te(t,{hash:"function"},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=t.randomBytes||nr,o=t.hmac||((y,...g)=>bs(t.hash,y,gt(...g))),{Fp:s,Fn:i}=r,{ORDER:a,BITS:c}=i;function l(y){let g=a>>yr;return y>g}function u(y){return l(y)?i.neg(y):y}function f(y,g){if(!i.isValidNot0(g))throw new Error(`invalid signature ${y}: out of range 1..CURVE.n`)}class h{constructor(g,v,T){f("r",g),f("s",v),this.r=g,this.s=v,T!=null&&(this.recovery=T),Object.freeze(this)}static fromCompact(g){let v=i.BYTES,T=F("compactSignature",g,v*2);return new h(i.fromBytes(T.subarray(0,v)),i.fromBytes(T.subarray(v,v*2)))}static fromDER(g){let{r:v,s:T}=Vt.toSig(F("DER",g));return new h(v,T)}assertValidity(){}addRecoveryBit(g){return new h(this.r,this.s,g)}recoverPublicKey(g){let v=s.ORDER,{r:T,s:I,recovery:B}=this;if(B==null||![0,1,2,3].includes(B))throw new Error("recovery id invalid");if(a*Ql<v&&B>1)throw new Error("recovery id is ambiguous for h>1 curve");let P=B===2||B===3?T+a:T;if(!s.isValid(P))throw new Error("recovery id 2 or 3 invalid");let j=s.toBytes(P),q=r.fromHex(gt(Ra((B&1)===0),j)),O=i.inv(P),X=A(F("msgHash",g)),J=i.create(-X*O),ot=i.create(I*O),z=r.BASE.multiplyUnsafe(J).add(q.multiplyUnsafe(ot));if(z.is0())throw new Error("point at infinify");return z.assertValidity(),z}hasHighS(){return l(this.s)}normalizeS(){return this.hasHighS()?new h(this.r,i.neg(this.s),this.recovery):this}toBytes(g){if(g==="compact")return gt(i.toBytes(this.r),i.toBytes(this.s));if(g==="der")return Re(Vt.hexFromSig(this));throw new Error("invalid format")}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Rt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Rt(this.toBytes("compact"))}}let m=Da(i,e.allowedPrivateKeyLengths,e.wrapPrivateKey),w={isValidPrivateKey(y){try{return m(y),!0}catch{return!1}},normPrivateKeyToScalar:m,randomPrivateKey:()=>{let y=a;return Qi(n(ko(y)),y)},precompute(y=8,g=r.BASE){return g.precompute(y,!1)}};function E(y,g=!0){return r.fromPrivateKey(y).toBytes(g)}function p(y){if(typeof y=="bigint")return!1;if(y instanceof r)return!0;let v=F("key",y).length,T=s.BYTES,I=T+1,B=2*T+1;if(!(e.allowedPrivateKeyLengths||i.BYTES===I))return v===I||v===B}function S(y,g,v=!0){if(p(y)===!0)throw new Error("first arg must be private key");if(p(g)===!1)throw new Error("second arg must be public key");return r.fromHex(g).multiply(m(y)).toBytes(v)}let C=t.bits2int||function(y){if(y.length>8192)throw new Error("input is too large");let g=Le(y),v=y.length*8-c;return v>0?g>>BigInt(v):g},A=t.bits2int_modN||function(y){return i.create(C(y))},L=ce(c);function b(y){return Jt("num < 2^"+c,y,mr,L),i.toBytes(y)}function R(y,g,v=D){if(["recovered","canonical"].some(ot=>ot in v))throw new Error("sign() legacy options not supported");let{hash:T}=t,{lowS:I,prehash:B,extraEntropy:k}=v;I==null&&(I=!0),y=F("msgHash",y),Ba(v),B&&(y=F("prehashed msgHash",T(y)));let P=A(y),j=m(g),q=[b(j),b(P)];if(k!=null&&k!==!1){let ot=k===!0?n(s.BYTES):k;q.push(F("extraEntropy",ot))}let O=gt(...q),X=P;function J(ot){let z=C(ot);if(!i.isValidNot0(z))return;let ct=i.inv(z),We=r.BASE.multiply(z).toAffine(),be=i.create(We.x);if(be===mr)return;let re=i.create(ct*i.create(X+be*j));if(re===mr)return;let jn=(We.x===be?0:2)|Number(We.y&yr),ge=re;return I&&l(re)&&(ge=u(re),jn^=1),new h(be,ge,jn)}return{seed:O,k2sig:J}}let D={lowS:t.lowS,prehash:!1},_={lowS:t.lowS,prehash:!1};function d(y,g,v=D){let{seed:T,k2sig:I}=R(y,g,v);return Hi(t.hash.outputLen,i.BYTES,o)(T,I)}r.BASE.precompute(8);function x(y,g,v,T=_){let I=y;g=F("msgHash",g),v=F("publicKey",v),Ba(T);let{lowS:B,prehash:k,format:P}=T;if("strict"in T)throw new Error("options.strict was renamed to lowS");if(P!==void 0&&!["compact","der","js"].includes(P))throw new Error('format must be "compact", "der" or "js"');let j=typeof I=="string"||Be(I),q=!j&&!P&&typeof I=="object"&&I!==null&&typeof I.r=="bigint"&&typeof I.s=="bigint";if(!j&&!q)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let O,X;try{if(q)if(P===void 0||P==="js")O=new h(I.r,I.s);else throw new Error("invalid format");if(j){try{P!=="compact"&&(O=h.fromDER(I))}catch(ge){if(!(ge instanceof Vt.Err))throw ge}!O&&P!=="der"&&(O=h.fromCompact(I))}X=r.fromHex(v)}catch{return!1}if(!O||B&&O.hasHighS())return!1;k&&(g=t.hash(g));let{r:J,s:ot}=O,z=A(g),ct=i.inv(ot),We=i.create(z*ct),be=i.create(J*ct),re=r.BASE.multiplyUnsafe(We).add(X.multiplyUnsafe(be));return re.is0()?!1:i.create(re.x)===J}return Object.freeze({getPublicKey:E,getSharedSecret:S,sign:d,verify:x,utils:w,Point:r,Signature:h})}function nf(r){let t={a:r.a,b:r.b,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},e=r.Fp,n=Tt(t.n,r.nBitLength),o={Fp:e,Fn:n,allowedPrivateKeyLengths:r.allowedPrivateKeyLengths,allowInfinityPoint:r.allowInfinityPoint,endo:r.endo,wrapPrivateKey:r.wrapPrivateKey,isTorsionFree:r.isTorsionFree,clearCofactor:r.clearCofactor,fromBytes:r.fromBytes,toBytes:r.toBytes};return{CURVE:t,curveOpts:o}}function of(r){let{CURVE:t,curveOpts:e}=nf(r),n={hash:r.hash,hmac:r.hmac,randomBytes:r.randomBytes,lowS:r.lowS,bits2int:r.bits2int,bits2int_modN:r.bits2int_modN};return{CURVE:t,curveOpts:e,ecdsaOpts:n}}function sf(r,t){return Object.assign({},t,{ProjectivePoint:t.Point,CURVE:r})}function La(r){let{CURVE:t,curveOpts:e,ecdsaOpts:n}=of(r),o=ef(t,e),s=rf(o,n,e);return sf(r,s)}function Pa(r,t){let e=n=>La({...r,hash:n});return{...e(t),create:e}}var sn={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},b0=BigInt(0),af=BigInt(1),xs=BigInt(2),ka=(r,t)=>(r+t/xs)/t;function cf(r){let t=sn.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),l=r*r*r%t,u=l*l*r%t,f=W(u,e,t)*u%t,h=W(f,e,t)*u%t,m=W(h,xs,t)*l%t,w=W(m,o,t)*m%t,E=W(w,s,t)*w%t,p=W(E,a,t)*E%t,S=W(p,c,t)*p%t,C=W(S,a,t)*E%t,A=W(C,e,t)*u%t,L=W(A,i,t)*w%t,b=W(L,n,t)*l%t,R=W(b,xs,t);if(!ws.eql(ws.sqr(R),r))throw new Error("Cannot find square root");return R}var ws=Tt(sn.p,void 0,void 0,{sqrt:cf}),qe=Pa({...sn,Fp:ws,lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=sn.n,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-af*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),a=ka(s*r,t),c=ka(-n*r,t),l=G(r-a*e-c*o,t),u=G(-a*n-c*s,t),f=l>i,h=u>i;if(f&&(l=t-l),h&&(u=t-u),l>i||u>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:l,k2neg:h,k2:u}}}},zr);function Oa(r,t,e,n){let o=Xe.digest(e instanceof Uint8Array?e:e.subarray());if(Yr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),qe.verify(t,s,r))).catch(s=>{throw s.name==="AbortError"?s:new ur(String(s))});try{return n?.signal?.throwIfAborted(),qe.verify(t,o.digest,r)}catch(s){throw new ur(String(s))}}var an=class{type="secp256k1";raw;_key;constructor(t){this._key=Na(t),this.raw=Ka(this._key)}toMultihash(){return It.digest(Et(this))}toCID(){return Z.createV1(114,this.toMultihash())}toString(){return H.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:V(this.raw,t.raw)}verify(t,e,n){return Oa(this._key,e,t,n)}};function Es(r){return new an(r)}function Ka(r){return qe.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Na(r){try{return qe.ProjectivePoint.fromHex(r),r}catch(t){throw new we(String(t))}}function cn(r,t){let{Type:e,Data:n}=kt.decode(r),o=n??new Uint8Array;switch(e){case Y.RSA:return ps(o,t);case Y.Ed25519:return zo(o);case Y.secp256k1:return Es(o);case Y.ECDSA:return Io(o);default:throw new ne}}function Ua(r){let{Type:t,Data:e}=kt.decode(r.digest),n=e??new Uint8Array;switch(t){case Y.Ed25519:return zo(n);case Y.secp256k1:return Es(n);case Y.ECDSA:return Io(n);default:throw new ne}}function Et(r){return kt.encode({Type:Y[r.type],Data:r.raw})}var Ma=Symbol.for("nodejs.util.inspect.custom"),uf=114,br=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()})`}[Rr]=!0;toString(){return this.string==null&&(this.string=H.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return Z.createV1(uf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return V(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return V(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Ma](){return`PeerId(${this.toString()})`}},gr=class extends br{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},xr=class extends br{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},wr=class extends br{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},lf=2336,Er=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=It.digest(U(this.url))}[Ma](){return`PeerId(${this.url})`}[Rr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return Z.createV1(lf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=K(t)),t.toString()===this.toString())}};var ff=114,qa=2336;function za(r){if(r.type==="Ed25519")return new xr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new wr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new gr({multihash:r.toCID().multihash,publicKey:r});throw new ne}function vs(r){if(hf(r))return new gr({multihash:r});if(df(r))try{let t=Ua(r);if(t.type==="Ed25519")return new xr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new wr({multihash:r,publicKey:t})}catch{let e=K(r.digest);return new Er(new URL(e))}throw new Pr("Supplied PeerID Multihash is invalid")}function un(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==ff&&r.code!==qa)throw new Lr("Supplied PeerID CID is invalid");if(r.code===qa){let t=K(r.multihash.digest);return new Er(new URL(t))}return vs(r.multihash)}function df(r){return r.code===It.code}function hf(r){return r.code===Xe.code}var vr;(function(r){let t;r.codec=()=>(t==null&&(t=pt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.publicKey!=null&&e.publicKey.byteLength>0&&(n.uint32(10),n.bytes(e.publicKey)),e.payloadType!=null&&e.payloadType.byteLength>0&&(n.uint32(18),n.bytes(e.payloadType)),e.payload!=null&&e.payload.byteLength>0&&(n.uint32(26),n.bytes(e.payload)),e.signature!=null&&e.signature.byteLength>0&&(n.uint32(42),n.bytes(e.signature)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={publicKey:Q(0),payloadType:Q(0),payload:Q(0),signature:Q(0)},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.publicKey=e.bytes();break}case 2:{s.payloadType=e.bytes();break}case 3:{s.payload=e.bytes();break}case 5:{s.signature=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>ht(e,r.codec()),r.decode=(e,n)=>dt(e,r.codec(),n)})(vr||(vr={}));var ln=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var ze=class r{static createFromProtobuf=t=>{let e=vr.decode(t),n=cn(e.publicKey);return new r({publicKey:n,payloadType:e.payloadType,payload:e.payload,signature:e.signature})};static seal=async(t,e,n)=>{if(e==null)throw new Error("Missing private key");let o=t.domain,s=t.codec,i=t.marshal(),a=Ha(o,s,i),c=await e.sign(a.subarray(),n);return new r({publicKey:e.publicKey,payloadType:s,payload:i,signature:c})};static openAndCertify=async(t,e,n)=>{let o=r.createFromProtobuf(t);if(!await o.validate(e,n))throw new ln("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(t){let{publicKey:e,payloadType:n,payload:o,signature:s}=t;this.publicKey=e,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=vr.encode({publicKey:Et(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return t==null?!1:V(this.marshal(),t.marshal())}async validate(t,e){let n=Ha(t,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,e)}},Ha=(r,t,e)=>{let n=U(r),o=Qr(n.byteLength),s=Qr(t.length),i=Qr(e.length);return new ut(o,n,s,t,i,e)};function Va(r,t){let e=(n,o)=>n.toString().localeCompare(o.toString());return r.length!==t.length?!1:(t.sort(e),r.sort(e).every((n,o)=>t[o].equals(n)))}var nt=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Ft=class extends Error{static name="ValidationError";name="ValidationError"},Sr=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},fn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var dn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",l=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let h=Number.parseInt(f,t);if(!Number.isNaN(h))return h});if(u===void 0)break;if(s*=t,s+=u,s>l||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];e[o]=s>>8,e[o+1]=s&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return e.set(s.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var pf=45,mf=15,hn=new dn;function Ss(r){if(!(r.length>mf))return hn.new(r).parseWith(()=>hn.readIPv4Addr())}function As(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>pf))return hn.new(r).parseWith(()=>hn.readIPv6Addr())}function pn(r){return!!Ss(r)}function Wa(r){return!!As(r)}function _s(r){return t=>K(t,r)}function Ts(r){return t=>U(t,r)}function He(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function pe(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(t)}function Ga(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=U(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=pe(n);return Nt([e,o],e.length+o.length)}function $a(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=Dt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=pe(n);return Nt([e,o],e.length+o.length)}function Cs(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=K(t,"base32"),o=He(e);return`${n}:${o}`}var Bs=function(r){r=r.toString().trim();let t=new Uint8Array(4);return r.split(/\./g).forEach((e,n)=>{let o=parseInt(e,10);if(isNaN(o)||o<0||o>255)throw new nt("Invalid byte value in IP address");t[n]=o}),t},Za=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=pn(e[n]),i;s&&(i=Bs(e[n]),e[n]=K(i.subarray(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,K(i.subarray(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let s=[n,1];for(n=9-e.length;n>0;n--)s.push("0");e.splice.apply(e,s)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){e[n]===""&&(e[n]="0");let s=parseInt(e[n],16);if(isNaN(s)||s<0||s>65535)throw new nt("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},ja=function(r){if(r.byteLength!==4)throw new nt("IPv4 address was incorrect length");let t=[];for(let e=0;e<r.byteLength;e++)t.push(r[e]);return t.join(".")},Ya=function(r){if(r.byteLength!==16)throw new nt("IPv6 address was incorrect length");let t=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],s=r[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let e=t.join(":");try{let n=new URL(`http://[${e}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new nt(`Invalid IPv6 address "${e}"`)}};function Xa(r){try{let t=new URL(`http://[${r}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new nt(`Invalid IPv6 address "${r}"`)}}var Is=Object.values(Qe).map(r=>r.decoder),yf=function(){let r=Is[0].or(Is[1]);return Is.slice(2).forEach(t=>r=r.or(t)),r}();function Qa(r){return yf.decode(r)}function Ja(r){return t=>r.encoder.encode(t)}function bf(r){if(parseInt(r).toString()!==r)throw new Ft("Value must be an integer")}function gf(r){if(r<0)throw new Ft("Value must be a positive integer, or zero")}function xf(r){return t=>{if(t>r)throw new Ft(`Value must be smaller than or equal to ${r}`)}}function wf(...r){return t=>{for(let e of r)e(t)}}var Ar=wf(bf,gf,xf(65535));var et=-1,Ds=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let e;if(typeof t=="string"?e=this.protocolsByName.get(t):e=this.protocolsByCode.get(t),e==null)throw new fn(`Protocol ${t} was unknown`);return e}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(e=>{this.protocolsByName.set(e,t)})}removeProtocol(t){let e=this.protocolsByCode.get(t);e!=null&&(this.protocolsByCode.delete(e.code),this.protocolsByName.delete(e.name),e.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},wt=new Ds,Yf=[{code:4,name:"ip4",size:32,valueToBytes:Bs,bytesToValue:ja,validate:r=>{if(!pn(r))throw new Ft(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:pe,bytesToValue:He,validate:Ar},{code:273,name:"udp",size:16,valueToBytes:pe,bytesToValue:He,validate:Ar},{code:33,name:"dccp",size:16,valueToBytes:pe,bytesToValue:He,validate:Ar},{code:41,name:"ip6",size:128,valueToBytes:Za,bytesToValue:Ya,stringToValue:Xa,validate:r=>{if(!Wa(r))throw new Ft(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:et},{code:43,name:"ipcidr",size:8,bytesToValue:_s("base10"),valueToBytes:Ts("base10")},{code:53,name:"dns",size:et,resolvable:!0},{code:54,name:"dns4",size:et,resolvable:!0},{code:55,name:"dns6",size:et,resolvable:!0},{code:56,name:"dnsaddr",size:et,resolvable:!0},{code:132,name:"sctp",size:16,valueToBytes:pe,bytesToValue:He,validate:Ar},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:et,path:!0,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:et,bytesToValue:_s("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?Ts("base58btc")(r):Z.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Cs,valueToBytes:Ga},{code:445,name:"onion3",size:296,bytesToValue:Cs,valueToBytes:$a},{code:446,name:"garlic64",size:et},{code:447,name:"garlic32",size:et},{code:448,name:"tls"},{code:449,name:"sni",size:et},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:et,bytesToValue:Ja(fo),valueToBytes:Qa},{code:480,name:"http"},{code:481,name:"http-path",size:et,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:et}];Yf.forEach(r=>{wt.addProtocol(r)});function tc(r){let t=[],e=0;for(;e<r.length;){let n=$o(r,e),o=wt.getProtocol(n),s=St(n),i=Xf(o,r,e+s),a=0;i>0&&o.size===et&&(a=St(i));let c=s+a+i,l={code:n,name:o.name,bytes:r.subarray(e,e+c)};if(i>0){let u=e+s+a,f=r.subarray(u,u+i);l.value=o.bytesToValue?.(f)??K(f)}t.push(l),e+=c}return t}function ec(r){let t=0,e=[];for(let n of r){if(n.bytes==null){let o=wt.getProtocol(n.code),s=St(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??U(n.value),a=i.byteLength,o.size===et&&(c=St(a)));let l=new Uint8Array(s+c+a),u=0;Ne(n.code,l,u),u+=s,i!=null&&(o.size===et&&(Ne(a,l,u),u+=c),l.set(i,u)),n.bytes=l}e.push(n.bytes),t+=n.bytes.byteLength}return Nt(e,t)}function rc(r){if(r.charAt(0)!=="/")throw new nt('String multiaddr must start with "/"');let t=[],e="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(e==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let a=s===r.length-1;if(i==="/"||a){let c=wt.getProtocol(o);if(e==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",e="protocol";continue}else if(a)throw new nt(`Component ${o} was missing value`);e="value"}else if(e==="value"){let l={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new nt(`Component ${o} was missing value`);l.value=c.stringToValue?.(n)??n}t.push(l),n="",o="",e="protocol"}}}if(o!==""&&n!=="")throw new nt("Incomplete multiaddr");return t}function nc(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=wt.getProtocol(t.code);if(e==null)throw new nt(`Unknown protocol code ${t.code}`);return[t.name,e.valueToString?.(t.value)??t.value]}).join("/")}`}function Xf(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:$o(t,e)}var Qf=Symbol.for("nodejs.util.inspect.custom"),Us=Symbol.for("@multiformats/multiaddr"),Jf=[53,54,55,56],Ns=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}};function td(r){if(r==null&&(r="/"),wn(r))return r.getComponents();if(r instanceof Uint8Array)return tc(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),rc(r);if(Array.isArray(r))return r;throw new nt("Must be a string, Uint8Array, Component[], or another Multiaddr")}var xn=class r{[Us]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=td(t),e.validate!==!1&&ed(this)}get bytes(){return this.#r==null&&(this.#r=ec(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=nc(this.#t)),this.#e}toJSON(){return this.toString()}toOptions(){let t,e,n,o,s="";for(let{code:a,name:c,value:l}of this.#t)a===42&&(s=`%${l??""}`),Jf.includes(a)&&(e="tcp",o=443,n=`${l??""}${s}`,t=a===55?6:4),(a===6||a===273)&&(e=c==="tcp"?"tcp":"udp",o=parseInt(l??"")),(a===4||a===41)&&(e="tcp",n=`${l??""}${s}`,t=a===41?6:4);if(t==null||e==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:t,host:n,transport:e,port:o}}getComponents(){return[...this.#t]}protos(){return this.#t.map(({code:t,value:e})=>{let n=wt.getProtocol(t);return{code:t,size:n.size??0,name:n.name,resolvable:!!n.resolvable,path:!!n.path}})}protoCodes(){return this.#t.map(({code:t})=>t)}protoNames(){return this.#t.map(({name:t})=>t)}tuples(){return this.#t.map(({code:t,value:e})=>{if(e==null)return[t];let n=wt.getProtocol(t),o=[t];return e!=null&&o.push(n.valueToBytes?.(e)??U(e)),o})}stringTuples(){return this.#t.map(({code:t,value:e})=>e==null?[t]:[t,e])}encapsulate(t){let e=new r(t);return new r([...this.#t,...e.getComponents()],{validate:!1})}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new Sr(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(t){let e;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){e=n;break}return new r(this.#t.slice(0,e),{validate:!1})}getPeerId(){try{let t=[];this.#t.forEach(({code:n,value:o})=>{n===421&&t.push([n,o]),n===290&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?K(H.decode(`z${n}`),"base58btc"):K(Z.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){for(let t of this.#t)if(wt.getProtocol(t.code).path)return t.value??null;return null}equals(t){return V(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(s=>s.resolvable);if(e==null)return[this];let n=oc.get(e.name);if(n==null)throw new Ns(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>Ot(s))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(){return!(this.#t.length!==2||this.#t[0].code!==4&&this.#t[0].code!==41||this.#t[1].code!==6&&this.#t[1].code!==273)}[Qf](){return`Multiaddr(${this.toString()})`}};function ed(r){r.getComponents().forEach(t=>{let e=wt.getProtocol(t.code);t.value!=null&&e.validate?.(t.value)})}var Ib=parseInt("0xFFFF",16),_b=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var oc=new Map;function wn(r){return!!r?.[Us]}function Ot(r){return new xn(r)}var ac="libp2p-peer-record",cc=Uint8Array.from([3,1]);var _r;(function(r){let t;(function(n){let o;n.codec=()=>(o==null&&(o=pt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.multiaddr!=null&&s.multiaddr.byteLength>0&&(i.uint32(10),i.bytes(s.multiaddr)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={multiaddr:Q(0)},l=i==null?s.len:s.pos+i;for(;s.pos<l;){let u=s.uint32();switch(u>>>3){case 1:{c.multiaddr=s.bytes();break}default:{s.skipType(u&7);break}}}return c})),o),n.encode=s=>ht(s,n.codec()),n.decode=(s,i)=>dt(s,n.codec(),i)})(t=r.AddressInfo||(r.AddressInfo={}));let e;r.codec=()=>(e==null&&(e=pt((n,o,s={})=>{if(s.lengthDelimited!==!1&&o.fork(),n.peerId!=null&&n.peerId.byteLength>0&&(o.uint32(10),o.bytes(n.peerId)),n.seq!=null&&n.seq!==0n&&(o.uint32(16),o.uint64(n.seq)),n.addresses!=null)for(let i of n.addresses)o.uint32(26),r.AddressInfo.codec().encode(i,o);s.lengthDelimited!==!1&&o.ldelim()},(n,o,s={})=>{let i={peerId:Q(0),seq:0n,addresses:[]},a=o==null?n.len:n.pos+o;for(;n.pos<a;){let c=n.uint32();switch(c>>>3){case 1:{i.peerId=n.bytes();break}case 2:{i.seq=n.uint64();break}case 3:{if(s.limits?.addresses!=null&&i.addresses.length===s.limits.addresses)throw new he('Decode error - map field "addresses" had too many elements');i.addresses.push(r.AddressInfo.codec().decode(n,n.uint32(),{limits:s.limits?.addresses$}));break}default:{n.skipType(c&7);break}}}return i})),e),r.encode=n=>ht(n,r.codec()),r.decode=(n,o)=>dt(n,r.codec(),o)})(_r||(_r={}));var me=class r{static createFromProtobuf=t=>{let e=_r.decode(t),n=vs(_e(e.peerId)),o=(e.addresses??[]).map(i=>Ot(i.multiaddr)),s=e.seq;return new r({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=ac;static CODEC=cc;peerId;multiaddrs;seqNumber;domain=r.DOMAIN;codec=r.CODEC;marshaled;constructor(t){let{peerId:e,multiaddrs:n,seqNumber:o}=t;this.peerId=e,this.multiaddrs=n??[],this.seqNumber=o??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=_r.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||!Va(this.multiaddrs,t.multiaddrs))}};function id(r){return r[Symbol.asyncIterator]!=null}function ad(r){if(id(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 uc=ad;function En(r,t){let e={[Symbol.iterator]:()=>e,next:()=>{let n=r.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return e}var Tr=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 En(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 En(this.map.values(),t=>t.key)}values(){return En(this.map.values(),t=>t.value)}get size(){return this.map.size}};var Ms=class extends Tr{metric;constructor(t){super();let{name:e,metrics:n}=t;this.metric=n.registerMetric(e),this.updateComponentMetric()}set(t,e){return super.set(t,e),this.updateComponentMetric(),this}delete(t){let e=super.delete(t);return this.updateComponentMetric(),e}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function qs(r){let{name:t,metrics:e}=r,n;return e!=null?n=new Ms({name:t,metrics:e}):n=new Tr,n}var Bt=class extends Error{static name="AbortError";name="AbortError";constructor(t="The operation was aborted",...e){super(t,...e)}};function vn(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Sn=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},Ve=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Sn(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new Sn(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var zs=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function lc(r={}){return cd(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function cd(r,t){t=t??{};let e=t.onEnd,n=new Ve,o,s,i,a=vn(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((p,S)=>{s=C=>{s=null,n.push(C);try{p(r(n))}catch(A){S(A)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=vn()})}},l=p=>s!=null?s(p):(n.push(p),o),u=p=>(n=new Ve,s!=null?s({error:p}):(n.push({error:p}),o)),f=p=>{if(i)return o;if(t?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:p})},h=p=>i?o:(i=!0,p!=null?u(p):l({done:!0})),m=()=>(n=new Ve,h(),{done:!0}),w=p=>(h(p),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:m,throw:w,push:f,end:h,get readableLength(){return n.size},onEmpty:async p=>{let S=p?.signal;if(S?.throwIfAborted(),n.isEmpty())return;let C,A;S!=null&&(C=new Promise((L,b)=>{A=()=>{b(new zs)},S.addEventListener("abort",A)}));try{await Promise.race([a.promise,C])}finally{A!=null&&S!=null&&S?.removeEventListener("abort",A)}}},e==null)return o;let E=o;return o={[Symbol.asyncIterator](){return this},next(){return E.next()},throw(p){return E.throw(p),e!=null&&(e(p),e=void 0),{done:!0}},return(){return E.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(p){return E.end(p),e!=null&&(e(p),e=void 0),o},get readableLength(){return E.readableLength},onEmpty:p=>E.onEmpty(p)},o}var Hs=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=e??"ABORT_ERR"}};async function An(r,t,e,n){let o=new Hs(n?.errorMessage,n?.errorCode);return e?.aborted===!0?Promise.reject(o):new Promise((s,i)=>{function a(){e?.removeEventListener("abort",u),r.removeEventListener(t,c),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,l)}let c=f=>{try{if(n?.filter?.(f)===!1)return}catch(h){a(),i(h);return}a(),s(f)},l=f=>{a(),i(f.detail)},u=()=>{a(),i(o)};e?.addEventListener("abort",u),r.addEventListener(t,c),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,l)})}var In=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};var _n=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function fc(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new _n(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new _n(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((s,i)=>{n=()=>{i(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var Tn=class{deferred;signal;constructor(t){this.signal=t,this.deferred=Promise.withResolvers(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Bt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function ud(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Cn=class{id;fn;options;recipients;status;timeline;controller;constructor(t,e){this.id=ud(),this.status="queued",this.fn=t,this.options=e,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(t){this.controller.abort(t)}onAbort(){this.recipients.reduce((e,n)=>e&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new Bt),this.cleanup())}async join(t={}){let e=new Tn(t.signal);return this.recipients.push(e),t.signal?.addEventListener("abort",this.onAbort),e.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let t=await fc(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(e=>{e.deferred.resolve(t)}),this.status="complete"}catch(t){this.recipients.forEach(e=>{e.deferred.reject(t)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(t=>{t.cleanup(),t.signal?.removeEventListener("abort",this.onAbort)})}};function Vs(r,t){let e,n=function(){let o=function(){e=void 0,r()};clearTimeout(e),e=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(e)},n}var Cr=class extends Ee{concurrency;maxSize;queue;pending;sort;autoStart;constructor(t={}){super(),this.concurrency=t.concurrency??Number.POSITIVE_INFINITY,this.maxSize=t.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.autoStart=t.autoStart??!0,this.sort=t.sort,this.queue=[],this.emitEmpty=Vs(this.emitEmpty.bind(this),1),this.emitIdle=Vs(this.emitIdle.bind(this),1)}[Symbol.asyncIterator](){return this.toGenerator()}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}tryToStartAnother(){if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let t;for(let e of this.queue)if(e.status==="queued"){t=e;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let e=0;e<this.queue.length;e++)if(this.queue[e]===t){this.queue.splice(e,1);break}this.pending--,this.safeDispatchEvent("next"),this.autoStart&&this.tryToStartAnother()}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}start(){this.autoStart===!1&&(this.autoStart=!0,this.tryToStartAnother())}pause(){this.autoStart=!1}async add(t,e){if(e?.signal?.throwIfAborted(),this.size===this.maxSize)throw new In;let n=new Cn(t,e);return this.enqueue(n),this.safeDispatchEvent("add"),this.autoStart&&this.tryToStartAnother(),n.join(e).then(o=>(this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(t=>{t.abort(new Bt)}),this.clear()}async onEmpty(t){this.size!==0&&await An(this,"empty",t?.signal)}async onSizeLessThan(t,e){this.size<t||await An(this,"next",e?.signal,{filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await An(this,"idle",t?.signal)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(t){t?.signal?.throwIfAborted();let e=lc({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),e.end(c)},o=c=>{c.detail!=null&&e.push(c.detail.result)},s=c=>{n(c.detail.error)},i=()=>{n()},a=()=>{n(new Bt("Queue aborted"))};this.addEventListener("success",o),this.addEventListener("failure",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*e}finally{this.removeEventListener("success",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};var Bn="lock:worker:request-read",Dn="lock:worker:abort-read-request",Rn="lock:worker:release-read",Ln="lock:master:grant-read",Pn="lock:master:error-read",kn="lock:worker:request-write",On="lock:worker:abort-write-request",Kn="lock:worker:release-write",Nn="lock:master:grant-write",Un="lock:master:error-write",Mn="lock:worker:finalize",qn="mortice",dc={singleProcess:!1};var Fs=(r,t,e,n,o,s,i,a,c)=>l=>{if(l.data==null)return;let u={type:l.data.type,name:l.data.name,identifier:l.data.identifier};u.type===o&&r.safeDispatchEvent(e,{detail:{name:u.name,identifier:u.identifier,handler:async()=>{t.postMessage({type:c,name:u.name,identifier:u.identifier}),await new Promise(f=>{let h=m=>{if(m?.data==null)return;let w={type:m.data.type,name:m.data.name,identifier:m.data.identifier};w.type===a&&w.identifier===u.identifier&&(t.removeEventListener("message",h),f())};t.addEventListener("message",h)})},onError:f=>{t.postMessage({type:i,name:u.name,identifier:u.identifier,error:{message:f.message,name:f.name,stack:f.stack}})}}}),u.type===s&&r.safeDispatchEvent(n,{detail:{name:u.name,identifier:u.identifier}}),u.type===Mn&&r.safeDispatchEvent("finalizeRequest",{detail:{name:u.name}})};var hc=(r=10)=>Math.random().toString().substring(2,r+2);var zn=class{name;channel;constructor(t){this.name=t,this.channel=new BroadcastChannel(qn)}readLock(t){return this.sendRequest(Bn,Dn,Ln,Pn,Rn,t)}writeLock(t){return this.sendRequest(kn,On,Nn,Un,Kn,t)}finalize(){this.channel.postMessage({type:Mn,name:this.name}),this.channel.close()}async sendRequest(t,e,n,o,s,i){i?.signal?.throwIfAborted();let a=hc();return this.channel.postMessage({type:t,identifier:a,name:this.name}),new Promise((c,l)=>{let u=()=>{this.channel.postMessage({type:e,identifier:a,name:this.name})};i?.signal?.addEventListener("abort",u,{once:!0});let f=h=>{if(h.data?.identifier===a&&(h.data?.type===n&&(this.channel.removeEventListener("message",f),i?.signal?.removeEventListener("abort",u),c(()=>{this.channel.postMessage({type:s,identifier:a,name:this.name})})),h.data.type===o)){this.channel.removeEventListener("message",f),i?.signal?.removeEventListener("abort",u);let m=new Error;h.data.error!=null&&(m.message=h.data.error.message,m.name=h.data.error.name,m.stack=h.data.error.stack),l(m)}};this.channel.addEventListener("message",f)})}};var pc=r=>{if(r=Object.assign({},dc,r),!!globalThis.document||r.singleProcess){let e=new BroadcastChannel(qn),n=new Ee;return e.addEventListener("message",Fs(n,e,"requestReadLock","abortReadLockRequest",Bn,Dn,Pn,Rn,Ln)),e.addEventListener("message",Fs(n,e,"requestWriteLock","abortWriteLockRequest",kn,On,Un,Kn,Nn)),n}return new zn(r.name)};var ye=new Map,Br;function mc(r){return typeof r?.readLock=="function"&&typeof r?.writeLock=="function"}function ld(r){if(Br==null&&(Br=pc(r),!mc(Br))){let t=Br;t.addEventListener("requestReadLock",e=>{let n=e.detail.name,o=e.detail.identifier,s=ye.get(n);if(s==null)return;let i=new AbortController,a=c=>{c.detail.name!==n||c.detail.identifier!==o||i.abort()};t.addEventListener("abortReadLockRequest",a),s.readLock({signal:i.signal}).then(async c=>{await e.detail.handler().finally(()=>{c()})}).catch(c=>{e.detail.onError(c)}).finally(()=>{t.removeEventListener("abortReadLockRequest",a)})}),t.addEventListener("requestWriteLock",e=>{let n=e.detail.name,o=e.detail.identifier,s=ye.get(n);if(s==null)return;let i=new AbortController,a=c=>{c.detail.name!==n||c.detail.identifier!==o||i.abort()};t.addEventListener("abortWriteLockRequest",a),s.writeLock({signal:i.signal}).then(async c=>{await e.detail.handler().finally(()=>{c()})}).catch(c=>{e.detail.onError(c)}).finally(()=>{t.removeEventListener("abortWriteLockRequest",a)})}),t.addEventListener("finalizeRequest",e=>{let n=e.detail.name,o=ye.get(n);o?.finalize()})}return Br}async function Ws(r,t){let e,n,o=new Promise((i,a)=>{e=i,n=a}),s=()=>{n(new Bt)};return t?.signal?.addEventListener("abort",s,{once:!0}),r.add(async()=>{await new Promise(i=>{e(()=>{t?.signal?.removeEventListener("abort",s),i()})})},{signal:t?.signal}).catch(i=>{n(i)}),o}var yc=(r,t)=>{let e=ye.get(r);if(e!=null)return e;let n=ld(t);if(mc(n))return e=n,ye.set(r,e),e;let o=new Cr({concurrency:1}),s;return e={async readLock(i){if(s!=null)return Ws(s,i);s=new Cr({concurrency:t.concurrency,autoStart:!1});let a=s,c=Ws(s,i);return o.add(async()=>{a.start(),await a.onIdle().then(()=>{s===a&&(s=null)})}),c},async writeLock(i){return s=null,Ws(o,i)},finalize:()=>{ye.delete(r)},queue:o},ye.set(r,e),t.autoFinalize===!0&&o.addEventListener("idle",()=>{e.finalize()},{once:!0}),e};var fd={name:"lock",concurrency:1/0,singleProcess:!1,autoFinalize:!1};function Gs(r){let t=Object.assign({},fd,r);return yc(t.name,t)}var Wt;(function(r){let t;(function(o){let s;o.codec=()=>(s==null&&(s=pt((i,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),i.key!=null&&i.key!==""&&(a.uint32(10),a.string(i.key)),i.value!=null&&i.value.byteLength>0&&(a.uint32(18),a.bytes(i.value)),c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let l={key:"",value:Q(0)},u=a==null?i.len:i.pos+a;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{l.key=i.string();break}case 2:{l.value=i.bytes();break}default:{i.skipType(f&7);break}}}return l})),s),o.encode=i=>ht(i,o.codec()),o.decode=(i,a)=>dt(i,o.codec(),a)})(t=r.Peer$metadataEntry||(r.Peer$metadataEntry={}));let e;(function(o){let s;o.codec=()=>(s==null&&(s=pt((i,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),i.key!=null&&i.key!==""&&(a.uint32(10),a.string(i.key)),i.value!=null&&(a.uint32(18),Vn.codec().encode(i.value,a)),c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let l={key:""},u=a==null?i.len:i.pos+a;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{l.key=i.string();break}case 2:{l.value=Vn.codec().decode(i,i.uint32(),{limits:c.limits?.value});break}default:{i.skipType(f&7);break}}}return l})),s),o.encode=i=>ht(i,o.codec()),o.decode=(i,a)=>dt(i,o.codec(),a)})(e=r.Peer$tagsEntry||(r.Peer$tagsEntry={}));let n;r.codec=()=>(n==null&&(n=pt((o,s,i={})=>{if(i.lengthDelimited!==!1&&s.fork(),o.addresses!=null)for(let a of o.addresses)s.uint32(10),Hn.codec().encode(a,s);if(o.protocols!=null)for(let a of o.protocols)s.uint32(18),s.string(a);if(o.publicKey!=null&&(s.uint32(34),s.bytes(o.publicKey)),o.peerRecordEnvelope!=null&&(s.uint32(42),s.bytes(o.peerRecordEnvelope)),o.metadata!=null&&o.metadata.size!==0)for(let[a,c]of o.metadata.entries())s.uint32(50),r.Peer$metadataEntry.codec().encode({key:a,value:c},s);if(o.tags!=null&&o.tags.size!==0)for(let[a,c]of o.tags.entries())s.uint32(58),r.Peer$tagsEntry.codec().encode({key:a,value:c},s);o.updated!=null&&(s.uint32(64),s.uint64Number(o.updated)),i.lengthDelimited!==!1&&s.ldelim()},(o,s,i={})=>{let a={addresses:[],protocols:[],metadata:new Map,tags:new Map},c=s==null?o.len:o.pos+s;for(;o.pos<c;){let l=o.uint32();switch(l>>>3){case 1:{if(i.limits?.addresses!=null&&a.addresses.length===i.limits.addresses)throw new he('Decode error - map field "addresses" had too many elements');a.addresses.push(Hn.codec().decode(o,o.uint32(),{limits:i.limits?.addresses$}));break}case 2:{if(i.limits?.protocols!=null&&a.protocols.length===i.limits.protocols)throw new he('Decode error - map field "protocols" had too many elements');a.protocols.push(o.string());break}case 4:{a.publicKey=o.bytes();break}case 5:{a.peerRecordEnvelope=o.bytes();break}case 6:{if(i.limits?.metadata!=null&&a.metadata.size===i.limits.metadata)throw new dr('Decode error - map field "metadata" had too many elements');let u=r.Peer$metadataEntry.codec().decode(o,o.uint32());a.metadata.set(u.key,u.value);break}case 7:{if(i.limits?.tags!=null&&a.tags.size===i.limits.tags)throw new dr('Decode error - map field "tags" had too many elements');let u=r.Peer$tagsEntry.codec().decode(o,o.uint32(),{limits:{value:i.limits?.tags$value}});a.tags.set(u.key,u.value);break}case 8:{a.updated=o.uint64Number();break}default:{o.skipType(l&7);break}}}return a})),n),r.encode=o=>ht(o,r.codec()),r.decode=(o,s)=>dt(o,r.codec(),s)})(Wt||(Wt={}));var Hn;(function(r){let t;r.codec=()=>(t==null&&(t=pt((e,n,o={})=>{o.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)),e.observed!=null&&(n.uint32(24),n.uint64Number(e.observed)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={multiaddr:Q(0)},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.multiaddr=e.bytes();break}case 2:{s.isCertified=e.bool();break}case 3:{s.observed=e.uint64Number();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>ht(e,r.codec()),r.decode=(e,n)=>dt(e,r.codec(),n)})(Hn||(Hn={}));var Vn;(function(r){let t;r.codec=()=>(t==null&&(t=pt((e,n,o={})=>{o.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)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={value:0},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.value=e.uint32();break}case 2:{s.expiry=e.uint64();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>ht(e,r.codec()),r.decode=(e,n)=>dt(e,r.codec(),n)})(Vn||(Vn={}));function dd(r,t){if(r.publicKey!=null||t.publicKey==null)return r;let e;r.type==="RSA"&&(e=r.toMultihash());let n=cn(t.publicKey,e);return za(n)}function bc(r,t,e){let n=Wt.decode(t);return Fe(r,n,e)}function Fe(r,t,e){let n=new Map,o=BigInt(Date.now());for(let[s,i]of t.tags.entries())i.expiry!=null&&i.expiry<o||n.set(s,i);return{...t,id:dd(r,t),addresses:t.addresses.filter(({observed:s})=>s!=null&&s>Date.now()-e).map(({multiaddr:s,isCertified:i})=>({multiaddr:Ot(s),isCertified:i??!1})),metadata:t.metadata,peerRecordEnvelope:t.peerRecordEnvelope??void 0,tags:n}}function gc(r,t){return hd(r.addresses,t.addresses)&&pd(r.protocols,t.protocols)&&md(r.publicKey,t.publicKey)&&yd(r.peerRecordEnvelope,t.peerRecordEnvelope)&&bd(r.metadata,t.metadata)&&gd(r.tags,t.tags)}function hd(r,t){return wc(r,t,(e,n)=>!(e.isCertified!==n.isCertified||!V(e.multiaddr,n.multiaddr)))}function pd(r,t){return wc(r,t,(e,n)=>e===n)}function md(r,t){return xc(r,t)}function yd(r,t){return xc(r,t)}function bd(r,t){return Ec(r,t,(e,n)=>V(e,n))}function gd(r,t){return Ec(r,t,(e,n)=>e.value===n.value&&e.expiry===n.expiry)}function xc(r,t){return r==null&&t==null?!0:r!=null&&t!=null?V(r,t):!1}function wc(r,t,e){if(r.length!==t.length)return!1;for(let n=0;n<r.length;n++)if(!e(r[n],t[n]))return!1;return!0}function Ec(r,t,e){if(r.size!==t.size)return!1;for(let[n,o]of r.entries()){let s=t.get(n);if(s==null||!e(o,s))return!1}return!0}var Gt="/",vc=new TextEncoder().encode(Gt),Fn=vc[0],Wn=class r{_buf;constructor(t,e){if(typeof t=="string")this._buf=U(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]!==Fn)throw new Error("Invalid key")}toString(t="utf8"){return K(this._buf,t)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(t){return new r(t.join(Gt))}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=vc),this._buf[0]!==Fn){let t=new Uint8Array(this._buf.byteLength+1);t.fill(Fn,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Fn;)this._buf=this._buf.subarray(0,-1)}less(t){let e=this.list(),n=t.list();for(let o=0;o<e.length;o++){if(n.length<o+1)return!1;let s=e[o],i=n[o];if(s<i)return!0;if(s>i)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(Gt).slice(1)}type(){return xd(this.baseNamespace())}name(){return wd(this.baseNamespace())}instance(t){return new r(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(Gt)||(t+=Gt),t+=this.type(),new r(t)}parent(){let t=this.list();return t.length===1?new r(Gt):new r(t.slice(0,-1).join(Gt))}child(t){return this.toString()===Gt?t:t.toString()===Gt?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(),...Ed(t.map(e=>e.namespaces()))])}};function xd(r){let t=r.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function wd(r){let t=r.split(":");return t[t.length-1]}function Ed(r){return[].concat(...r)}var $s="/peers/";function Dr(r){if(!xe(r)||r.type==null)throw new N("Invalid PeerId");let t=r.toCID().toString();return new Wn(`${$s}${t}`)}async function Sc(r,t,e,n,o){let s=new Map;for(let i of e){if(i==null)continue;if(i.multiaddr instanceof Uint8Array&&(i.multiaddr=Ot(i.multiaddr)),!wn(i.multiaddr))throw new N("Multiaddr was invalid");if(!await t(r,i.multiaddr,o))continue;let a=i.isCertified??!1,c=i.multiaddr.toString(),l=s.get(c);l!=null?i.isCertified=l.isCertified||a:s.set(c,{multiaddr:i.multiaddr,isCertified:a})}return[...s.values()].sort((i,a)=>i.multiaddr.toString().localeCompare(a.multiaddr.toString())).map(({isCertified:i,multiaddr:a})=>{let c=a.getPeerId();return r.equals(c)&&(a=a.decapsulate(Ot(`/p2p/${r}`))),{isCertified:i,multiaddr:a.bytes}})}async function $n(r,t,e,n){if(t==null)throw new N("Invalid PeerData");if(t.publicKey!=null&&r.publicKey!=null&&!t.publicKey.equals(r.publicKey))throw new N("publicKey bytes do not match peer id publicKey bytes");let o=n.existingPeer?.peer;if(o!=null&&!r.equals(o.id))throw new N("peer id did not match existing peer id");let s=o?.addresses??[],i=new Set(o?.protocols??[]),a=o?.metadata??new Map,c=o?.tags??new Map,l=o?.peerRecordEnvelope;if(e==="patch"){if((t.multiaddrs!=null||t.addresses!=null)&&(s=[],t.multiaddrs!=null&&s.push(...t.multiaddrs.map(h=>({isCertified:!1,multiaddr:h}))),t.addresses!=null&&s.push(...t.addresses)),t.protocols!=null&&(i=new Set(t.protocols)),t.metadata!=null){let h=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);a=Gn(h,{validate:Ac})}if(t.tags!=null){let h=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags);c=Gn(h,{validate:Ic,map:_c})}t.peerRecordEnvelope!=null&&(l=t.peerRecordEnvelope)}if(e==="merge"){if(t.multiaddrs!=null&&s.push(...t.multiaddrs.map(h=>({isCertified:!1,multiaddr:h}))),t.addresses!=null&&s.push(...t.addresses),t.protocols!=null&&(i=new Set([...i,...t.protocols])),t.metadata!=null){let h=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);for(let[m,w]of h)w==null?a.delete(m):a.set(m,w);a=Gn([...a.entries()],{validate:Ac})}if(t.tags!=null){let h=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags),m=new Map(c);for(let[w,E]of h)E==null?m.delete(w):m.set(w,E);c=Gn([...m.entries()],{validate:Ic,map:_c})}t.peerRecordEnvelope!=null&&(l=t.peerRecordEnvelope)}let u;o?.id.publicKey!=null?u=Et(o.id.publicKey):t.publicKey!=null?u=Et(t.publicKey):r.publicKey!=null&&(u=Et(r.publicKey));let f={addresses:await Sc(r,n.addressFilter??(async()=>!0),s,n.existingPeer?.peerPB.addresses,n),protocols:[...i.values()].sort((h,m)=>h.localeCompare(m)),metadata:a,tags:c,publicKey:u,peerRecordEnvelope:l};return f.addresses.forEach(h=>{h.observed=n.existingPeer?.peerPB.addresses?.find(m=>V(m.multiaddr,m.multiaddr))?.observed??Date.now()}),r.type!=="RSA"&&delete f.publicKey,f}function Gn(r,t){let e=new Map;for(let[n,o]of r)o!=null&&t.validate(n,o);for(let[n,o]of r.sort(([s],[i])=>s.localeCompare(i)))o!=null&&e.set(n,t.map?.(n,o)??o);return e}function Ac(r,t){if(typeof r!="string")throw new N("Metadata key must be a string");if(!(t instanceof Uint8Array))throw new N("Metadata value must be a Uint8Array")}function Ic(r,t){if(typeof r!="string")throw new N("Tag name must be a string");if(t.value!=null){if(parseInt(`${t.value}`,10)!==t.value)throw new N("Tag value must be an integer");if(t.value<0||t.value>100)throw new N("Tag value must be between 0-100")}if(t.ttl!=null){if(parseInt(`${t.ttl}`,10)!==t.ttl)throw new N("Tag ttl must be an integer");if(t.ttl<0)throw new N("Tag ttl must be between greater than 0")}}function _c(r,t){let e;t.expiry!=null&&(e=t.expiry),t.ttl!=null&&(e=BigInt(Date.now()+Number(t.ttl)));let n={value:t.value??0};return e!=null&&(n.expiry=e),n}function Tc(r){let t=r.toString().split("/")[2],e=Z.parse(t,Dt);return un(e)}function Zs(r,t,e){let n=Tc(r);return bc(n,t,e)}function vd(r,t){return{prefix:$s,filters:(r.filters??[]).map(e=>({key:n,value:o})=>e(Zs(n,o,t))),orders:(r.orders??[]).map(e=>(n,o)=>e(Zs(n.key,n.value,t),Zs(o.key,o.value,t)))}}var Zn=class{peerId;datastore;locks;addressFilter;log;maxAddressAge;maxPeerAge;constructor(t,e={}){this.log=t.logger.forComponent("libp2p:peer-store"),this.peerId=t.peerId,this.datastore=t.datastore,this.addressFilter=e.addressFilter,this.locks=qs({name:"libp2p_peer_store_locks",metrics:t.metrics}),this.maxAddressAge=e.maxAddressAge??36e5,this.maxPeerAge=e.maxPeerAge??216e5}getLock(t){let e=this.locks.get(t);return e==null&&(e={refs:0,lock:Gs({name:t.toString(),singleProcess:!0})},this.locks.set(t,e)),e.refs++,e}maybeRemoveLock(t,e){e.refs--,e.refs===0&&(e.lock.finalize(),this.locks.delete(t))}async getReadLock(t,e){let n=this.getLock(t);try{let o=await n.lock.readLock(e);return()=>{o(),this.maybeRemoveLock(t,n)}}catch(o){throw this.maybeRemoveLock(t,n),o}}async getWriteLock(t,e){let n=this.getLock(t);try{let o=await n.lock.writeLock(e);return()=>{o(),this.maybeRemoveLock(t,n)}}catch(o){throw this.maybeRemoveLock(t,n),o}}async has(t,e){try{return await this.load(t,e),!0}catch(n){if(n.name!=="NotFoundError")throw n}return!1}async delete(t,e){this.peerId.equals(t)||await this.datastore.delete(Dr(t),e)}async load(t,e){let n=Dr(t),o=await this.datastore.get(n,e),s=Wt.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,e),new Ge;return Fe(t,s,this.peerId.equals(t)?1/0:this.maxAddressAge)}async save(t,e,n){let o=await this.#t(t,n),s=await $n(t,e,"patch",{...n,addressFilter:this.addressFilter});return this.#e(t,s,o)}async patch(t,e,n){let o=await this.#t(t,n),s=await $n(t,e,"patch",{...n,addressFilter:this.addressFilter,existingPeer:o});return this.#e(t,s,o)}async merge(t,e,n){let o=await this.#t(t,n),s=await $n(t,e,"merge",{addressFilter:this.addressFilter,existingPeer:o});return this.#e(t,s,o)}async*all(t){for await(let{key:e,value:n}of this.datastore.query(vd(t??{},this.maxAddressAge),t)){let o=Tc(e);if(o.equals(this.peerId))continue;let s=Wt.decode(n);if(this.#r(o,s)){await this.datastore.delete(e,t);continue}yield Fe(o,s,this.peerId.equals(o)?1/0:this.maxAddressAge)}}async#t(t,e){try{let n=Dr(t),o=await this.datastore.get(n,e),s=Wt.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,e),new Ge;return{peerPB:s,peer:Fe(t,s,this.maxAddressAge)}}catch(n){n.name!=="NotFoundError"&&this.log.error("invalid peer data found in peer store - %e",n)}}async#e(t,e,n,o){e.updated=Date.now();let s=Wt.encode(e);return await this.datastore.put(Dr(t),s,o),{peer:Fe(t,e,this.maxAddressAge),previous:n?.peer,updated:n==null||!gc(e,n.peerPB)}}#r(t,e){if(e.updated==null)return!0;if(this.peerId.equals(t))return!1;let n=e.updated<Date.now()-this.maxPeerAge,o=Date.now()-this.maxAddressAge,s=e.addresses.filter(i=>i.observed!=null&&i.observed>o);return n&&s.length===0}};var js=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 Zn(t,e)}[Symbol.toStringTag]="@libp2p/peer-store";async forEach(t,e){for await(let n of this.store.all(e))t(n)}async all(t){return uc(this.store.all(t))}async delete(t,e){let n=await this.store.getReadLock(t,e);try{await this.store.delete(t,e)}finally{n()}}async has(t,e){let n=await this.store.getReadLock(t,e);try{return await this.store.has(t,e)}finally{this.log.trace("has release read lock"),n?.()}}async get(t,e){let n=await this.store.getReadLock(t,e);try{return await this.store.load(t,e)}finally{n?.()}}async getInfo(t,e){let n=await this.get(t,e);return{id:n.id,multiaddrs:n.addresses.map(({multiaddr:o})=>o)}}async save(t,e,n){let o=await this.store.getWriteLock(t,n);try{let s=await this.store.save(t,e,n);return this.#t(t,s),s.peer}finally{o?.()}}async patch(t,e,n){let o=await this.store.getWriteLock(t,n);try{let s=await this.store.patch(t,e,n);return this.#t(t,s),s.peer}finally{o?.()}}async merge(t,e,n){let o=await this.store.getWriteLock(t,n);try{let s=await this.store.merge(t,e,n);return this.#t(t,s),s.peer}finally{o?.()}}async consumePeerRecord(t,e,n){let o=xe(e)?e:xe(e?.expectedPeer)?e.expectedPeer:void 0,s=xe(e)||e===void 0?n:e,i=await ze.openAndCertify(t,me.DOMAIN,s),a=un(i.publicKey.toCID());if(o?.equals(a)===!1)return this.log("envelope peer id was not the expected peer id - expected: %p received: %p",o,a),!1;let c=me.createFromProtobuf(i.payload),l;try{l=await this.get(a,s)}catch(u){if(u.name!=="NotFoundError")throw u}if(l?.peerRecordEnvelope!=null){let u=ze.createFromProtobuf(l.peerRecordEnvelope),f=me.createFromProtobuf(u.payload);if(f.seqNumber>=c.seqNumber)return this.log("sequence number was lower or equal to existing sequence number - stored: %d received: %d",f.seqNumber,c.seqNumber),!1}return await this.patch(c.peerId,{peerRecordEnvelope:t,addresses:c.multiaddrs.map(u=>({isCertified:!0,multiaddr:u}))},s),!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}))}};function Sd(r,t={}){return new js(r,t)}return Lc(Ad);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/hashes/esm/utils.js: