@libp2p/peer-store 11.1.3 → 11.1.4

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 ec=Object.create;var Br=Object.defineProperty;var rc=Object.getOwnPropertyDescriptor;var nc=Object.getOwnPropertyNames;var oc=Object.getPrototypeOf,sc=Object.prototype.hasOwnProperty;var ic=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),mt=(r,t)=>{for(var e in t)Br(r,e,{get:t[e],enumerable:!0})},Ks=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of nc(t))!sc.call(r,o)&&o!==e&&Br(r,o,{get:()=>t[o],enumerable:!(n=rc(t,o))||n.enumerable});return r};var ac=(r,t,e)=>(e=r!=null?ec(oc(r)):{},Ks(t||!r||!r.__esModule?Br(e,"default",{value:r,enumerable:!0}):e,r)),cc=r=>Ks(Br({},"__esModule",{value:!0}),r);var Ca=ic((Hg,ds)=>{"use strict";var Kf=Object.prototype.hasOwnProperty,xt="~";function Er(){}Object.create&&(Er.prototype=Object.create(null),new Er().__proto__||(xt=!1));function Uf(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function Pa(r,t,e,n,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var s=new Uf(e,n||r,o),i=xt?xt+t:t;return r._events[i]?r._events[i].fn?r._events[i]=[r._events[i],s]:r._events[i].push(s):(r._events[i]=s,r._eventsCount++),r}function fn(r,t){--r._eventsCount===0?r._events=new Er:delete r._events[t]}function ht(){this._events=new Er,this._eventsCount=0}ht.prototype.eventNames=function(){var t=[],e,n;if(this._eventsCount===0)return t;for(n in e=this._events)Kf.call(e,n)&&t.push(xt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};ht.prototype.listeners=function(t){var e=xt?xt+t:t,n=this._events[e];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,s=n.length,i=new Array(s);o<s;o++)i[o]=n[o].fn;return i};ht.prototype.listenerCount=function(t){var e=xt?xt+t:t,n=this._events[e];return n?n.fn?1:n.length:0};ht.prototype.emit=function(t,e,n,o,s,i){var a=xt?xt+t:t;if(!this._events[a])return!1;var c=this._events[a],f=arguments.length,u,l;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),f){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,e),!0;case 3:return c.fn.call(c.context,e,n),!0;case 4:return c.fn.call(c.context,e,n,o),!0;case 5:return c.fn.call(c.context,e,n,o,s),!0;case 6:return c.fn.call(c.context,e,n,o,s,i),!0}for(l=1,u=new Array(f-1);l<f;l++)u[l-1]=arguments[l];c.fn.apply(c.context,u)}else{var d=c.length,m;for(l=0;l<d;l++)switch(c[l].once&&this.removeListener(t,c[l].fn,void 0,!0),f){case 1:c[l].fn.call(c[l].context);break;case 2:c[l].fn.call(c[l].context,e);break;case 3:c[l].fn.call(c[l].context,e,n);break;case 4:c[l].fn.call(c[l].context,e,n,o);break;default:if(!u)for(m=1,u=new Array(f-1);m<f;m++)u[m-1]=arguments[m];c[l].fn.apply(c[l].context,u)}}return!0};ht.prototype.on=function(t,e,n){return Pa(this,t,e,n,!1)};ht.prototype.once=function(t,e,n){return Pa(this,t,e,n,!0)};ht.prototype.removeListener=function(t,e,n,o){var s=xt?xt+t:t;if(!this._events[s])return this;if(!e)return fn(this,s),this;var i=this._events[s];if(i.fn)i.fn===e&&(!o||i.once)&&(!n||i.context===n)&&fn(this,s);else{for(var a=0,c=[],f=i.length;a<f;a++)(i[a].fn!==e||o&&!i[a].once||n&&i[a].context!==n)&&c.push(i[a]);c.length?this._events[s]=c.length===1?c[0]:c:fn(this,s)}return this};ht.prototype.removeAllListeners=function(t){var e;return t?(e=xt?xt+t:t,this._events[e]&&fn(this,e)):(this._events=new Er,this._eventsCount=0),this};ht.prototype.off=ht.prototype.removeListener;ht.prototype.addListener=ht.prototype.on;ht.prefixed=xt;ht.EventEmitter=ht;typeof ds<"u"&&(ds.exports=ht)});var Qf={};mt(Qf,{persistentPeerStore:()=>Xf});var Tr=Symbol.for("@libp2p/peer-id");function Us(r){return!!r?.[Tr]}var q=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Pe=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Ye=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 me=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Bn={};mt(Bn,{base58btc:()=>W,base58flickr:()=>pc});var rd=new Uint8Array(0);function Ns(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 Vt(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 Os(r){return new TextEncoder().encode(r)}function Ms(r){return new TextDecoder().decode(r)}function uc(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),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function l(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 b=0,h=0,E=0,S=w.length;E!==S&&w[E]===0;)E++,b++;for(var y=(S-E)*u+1>>>0,I=new Uint8Array(y);E!==S;){for(var _=w[E],C=0,B=y-1;(_!==0||C<h)&&B!==-1;B--,C++)_+=256*I[B]>>>0,I[B]=_%a>>>0,_=_/a>>>0;if(_!==0)throw new Error("Non-zero carry");h=C,E++}for(var P=y-h;P!==y&&I[P]===0;)P++;for(var T=c.repeat(b);P<y;++P)T+=r.charAt(I[P]);return T}function d(w){if(typeof w!="string")throw new TypeError("Expected String");if(w.length===0)return new Uint8Array;var b=0;if(w[b]!==" "){for(var h=0,E=0;w[b]===c;)h++,b++;for(var S=(w.length-b)*f+1>>>0,y=new Uint8Array(S);w[b];){var I=e[w.charCodeAt(b)];if(I===255)return;for(var _=0,C=S-1;(I!==0||_<E)&&C!==-1;C--,_++)I+=a*y[C]>>>0,y[C]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");E=_,b++}if(w[b]!==" "){for(var B=S-E;B!==S&&y[B]===0;)B++;for(var P=new Uint8Array(h+(S-B)),T=h;B!==S;)P[T++]=y[B++];return P}}}function m(w){var b=d(w);if(b)return b;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:d,decode:m}}var lc=uc,fc=lc,Hs=fc;var vn=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")}},Sn=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 Vs(this,t)}},An=class{decoders;constructor(t){this.decoders=t}or(t){return Vs(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 Vs(r,t){return new An({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var In=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 vn(t,e,n),this.decoder=new Sn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ce({name:r,prefix:t,encode:e,decode:n}){return new In(r,t,e,n)}function ee({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Hs(e,r);return Ce({prefix:t,name:r,encode:n,decode:s=>Vt(o(s))})}function dc(r,t,e,n){let o={};for(let u=0;u<t.length;++u)o[t[u]]=u;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*e/8|0),a=0,c=0,f=0;for(let u=0;u<s;++u){let l=o[r[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|l,a+=e,a>=8&&(a-=8,i[f++]=255&c>>a)}if(a>=e||(255&c<<8-a)!==0)throw new SyntaxError("Unexpected end of data");return i}function hc(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 tt({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return Ce({prefix:t,name:r,encode(o){return hc(o,n,e)},decode(o){return dc(o,n,e,r)}})}var W=ee({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),pc=ee({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Tn={};mt(Tn,{base32:()=>Ct,base32hex:()=>bc,base32hexpad:()=>xc,base32hexpadupper:()=>Ec,base32hexupper:()=>wc,base32pad:()=>yc,base32padupper:()=>gc,base32upper:()=>mc,base32z:()=>vc});var Ct=tt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),mc=tt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),yc=tt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),gc=tt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),bc=tt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),wc=tt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),xc=tt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ec=tt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),vc=tt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ln={};mt(Ln,{base36:()=>je,base36upper:()=>Sc});var je=ee({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Sc=ee({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ac=Gs,Fs=128,Ic=127,Bc=~Ic,Tc=Math.pow(2,31);function Gs(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Tc;)t[e++]=r&255|Fs,r/=128;for(;r&Bc;)t[e++]=r&255|Fs,r>>>=7;return t[e]=r|0,Gs.bytes=e-n+1,t}var Lc=Pn,Pc=128,zs=127;function Pn(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Pn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&zs)<<o:(i&zs)*Math.pow(2,o),o+=7}while(i>=Pc);return Pn.bytes=s-n,e}var Cc=Math.pow(2,7),_c=Math.pow(2,14),kc=Math.pow(2,21),Rc=Math.pow(2,28),Dc=Math.pow(2,35),Kc=Math.pow(2,42),Uc=Math.pow(2,49),Nc=Math.pow(2,56),Oc=Math.pow(2,63),Mc=function(r){return r<Cc?1:r<_c?2:r<kc?3:r<Rc?4:r<Dc?5:r<Kc?6:r<Uc?7:r<Nc?8:r<Oc?9:10},qc={encode:Ac,decode:Lc,encodingLength:Mc},Hc=qc,Xe=Hc;function Qe(r,t=0){return[Xe.decode(r,t),Xe.decode.bytes]}function _e(r,t,e=0){return Xe.encode(r,t,e),t}function ke(r){return Xe.encodingLength(r)}function _t(r,t){let e=t.byteLength,n=ke(r),o=n+ke(e),s=new Uint8Array(o+e);return _e(r,s,0),_e(e,s,n),s.set(t,o),new Re(r,e,t,s)}function Ft(r){let t=Vt(r),[e,n]=Qe(t),[o,s]=Qe(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Re(e,o,i,t)}function Ws(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Ns(r.bytes,e.bytes)}}var Re=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function $s(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Fc(e,Cn(r),t??W.encoder);default:return zc(e,Cn(r),t??Ct.encoder)}}var Zs=new WeakMap;function Cn(r){let t=Zs.get(r);if(t==null){let e=new Map;return Zs.set(r,e),e}return t}var et=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!==Je)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Gc)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=_t(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&&Ws(t.multihash,n.multihash)}toString(t){return $s(this,t)}toJSON(){return{"/":$s(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??Ys(n,o,s.bytes))}else if(e[Wc]===!0){let{version:n,multihash:o,code:s}=e,i=Ft(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!==Je)throw new Error(`Version 0 CID must use dag-pb (code: ${Je}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Ys(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Je,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=Vt(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 Re(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[l,d]=Qe(t.subarray(e));return e+=d,l},o=n(),s=Je;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(),f=e+c,u=f-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(t,e){let[n,o]=Vc(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 Cn(s).set(n,t),s}};function Vc(r,t){switch(r[0]){case"Q":{let e=t??W;return[W.prefix,e.decode(`${W.prefix}${r}`)]}case W.prefix:{let e=t??W;return[W.prefix,e.decode(r)]}case Ct.prefix:{let e=t??Ct;return[Ct.prefix,e.decode(r)]}case je.prefix:{let e=t??je;return[je.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 Fc(r,t,e){let{prefix:n}=e;if(n!==W.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 zc(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 Je=112,Gc=18;function Ys(r,t,e){let n=ke(r),o=n+ke(t),s=new Uint8Array(o+e.byteLength);return _e(r,s,0),_e(t,s,n),s.set(e,o),s}var Wc=Symbol.for("@ipld/js-cid/CID");var _n={};mt(_n,{identity:()=>kt});var js=0,$c="identity",Xs=Vt;function Zc(r){return _t(js,Xs(r))}var kt={code:js,name:$c,encode:Xs,digest:Zc};function j(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 nt(r=0){return new Uint8Array(r)}function vt(r=0){return new Uint8Array(r)}function Tt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=vt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var Js=Symbol.for("@achingbrain/uint8arraylist");function Qs(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 _r(r){return!!r?.[Js]}var yt=class r{bufs;length;[Js]=!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(_r(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(_r(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=Qs(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Qs(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(_r(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 Tt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Tt(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 f=t>=a&&t<c,u=e>a&&e<=c;if(f&&u){if(t===a&&e===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(e-t)));break}if(f){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(!_r(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 l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let l=e;l<=c;l+=u){u=0;for(let d=f;d>=0;d--){let m=this.get(l+d);if(n[d]!==m){u=Math.max(1,d-a[m]);break}}if(u===0)return l}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=vt(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=nt(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=nt(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=nt(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=vt(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=nt(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=nt(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=nt(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=nt(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=nt(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(!j(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 kn={};mt(kn,{base10:()=>Yc});var Yc=ee({prefix:"9",name:"base10",alphabet:"0123456789"});var Rn={};mt(Rn,{base16:()=>jc,base16upper:()=>Xc});var jc=tt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Xc=tt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Dn={};mt(Dn,{base2:()=>Qc});var Qc=tt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Kn={};mt(Kn,{base256emoji:()=>nu});var ti=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}"),Jc=ti.reduce((r,t,e)=>(r[e]=t,r),[]),tu=ti.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function eu(r){return r.reduce((t,e)=>(t+=Jc[e],t),"")}function ru(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=tu[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var nu=Ce({prefix:"\u{1F680}",name:"base256emoji",encode:eu,decode:ru});var Un={};mt(Un,{base64:()=>ou,base64pad:()=>su,base64url:()=>iu,base64urlpad:()=>au});var ou=tt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),su=tt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),iu=tt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),au=tt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Nn={};mt(Nn,{base8:()=>cu});var cu=tt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var On={};mt(On,{identity:()=>uu});var uu=Ce({prefix:"\0",name:"identity",encode:r=>Ms(r),decode:r=>Os(r)});var Md=new TextEncoder,qd=new TextDecoder;var Hn={};mt(Hn,{sha256:()=>tr,sha512:()=>du});function qn({name:r,code:t,encode:e}){return new Mn(r,t,e)}var Mn=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?_t(this.code,e):e.then(n=>_t(this.code,n))}else throw Error("Unknown type, must be binary type")}};function ri(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var tr=qn({name:"sha2-256",code:18,encode:ri("SHA-256")}),du=qn({name:"sha2-512",code:19,encode:ri("SHA-512")});var er={...On,...Dn,...Nn,...kn,...Rn,...Tn,...Ln,...Bn,...Un,...Kn},Qd={...Hn,..._n};function oi(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var ni=oi("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Vn=oi("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=vt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),hu={utf8:ni,"utf-8":ni,hex:er.base16,latin1:Vn,ascii:Vn,binary:Vn,...er},kr=hu;function z(r,t="utf8"){let e=kr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function U(r,t="utf8"){let e=kr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var pu=parseInt("11111",2),Fn=parseInt("10000000",2),mu=parseInt("01111111",2),si={0:rr,1:rr,2:yu,3:wu,4:xu,5:bu,6:gu,16:rr,22:rr,48:rr};function Gt(r,t={offset:0}){let e=r[t.offset]&pu;if(t.offset++,si[e]!=null)return si[e](r,t);throw new Error("No decoder for tag "+e)}function nr(r,t){let e=0;if((r[t.offset]&Fn)===Fn){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 rr(r,t){nr(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Gt(r,t);if(n===null)break;e.push(n)}return e}function yu(r,t){let e=nr(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 gu(r,t){let e=nr(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 f=r[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let u=0;for(let l=0;l<c.length;l++)u+=c[l]<<l*7;a+=`.${u}`,c=[]}}return a}function bu(r,t){return t.offset++,null}function wu(r,t){let e=nr(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 xu(r,t){let e=nr(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Eu(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new yt;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function zn(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Eu(r.byteLength);return new yt(Uint8Array.from([t.byteLength|Fn]),t)}function St(r){let t=new yt,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new yt(Uint8Array.from([2]),zn(t),t)}function Rr(r){let t=Uint8Array.from([0]),e=new yt(t,r);return new yt(Uint8Array.from([3]),zn(e),e)}function re(r,t=48){let e=new yt;for(let n of r)e.append(n);return new yt(Uint8Array.from([t]),zn(e),e)}async function ii(r,t,e){let n=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);return crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},n,t,e.subarray())}var vu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Su=Uint8Array.from([6,5,43,129,4,0,34]),Au=Uint8Array.from([6,5,43,129,4,0,35]),Iu={ext:!0,kty:"EC",crv:"P-256"},Bu={ext:!0,kty:"EC",crv:"P-384"},Tu={ext:!0,kty:"EC",crv:"P-521"},Gn=32,Wn=48,$n=66;function Zn(r){let t=Gt(r);return ai(t)}function ai(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===Gn*2+1)return n=U(t.subarray(e,e+Gn),"base64url"),o=U(t.subarray(e+Gn),"base64url"),new De({...Iu,key_ops:["verify"],x:n,y:o});if(t.byteLength===Wn*2+1)return n=U(t.subarray(e,e+Wn),"base64url"),o=U(t.subarray(e+Wn),"base64url"),new De({...Bu,key_ops:["verify"],x:n,y:o});if(t.byteLength===$n*2+1)return n=U(t.subarray(e,e+$n),"base64url"),o=U(t.subarray(e+$n),"base64url"),new De({...Tu,key_ops:["verify"],x:n,y:o});throw new q(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function ci(r){return re([St(Uint8Array.from([1])),re([Lu(r.crv)],160),re([Rr(new yt(Uint8Array.from([4]),z(r.x??"","base64url"),z(r.y??"","base64url")))],161)]).subarray()}function Lu(r){if(r==="P-256")return vu;if(r==="P-384")return Su;if(r==="P-521")return Au;throw new q(`Invalid curve ${r}`)}var De=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=ci(this.jwk)),this._raw}toMultihash(){return kt.digest(Pt(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:j(this.raw,t.raw)}async verify(t,e){return ii(this.jwk,e,t)}};function ui(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function Pu(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Ke(r,...t){if(!Pu(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 li(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");ui(r.outputLen),ui(r.blockLen)}function Ue(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 fi(r,t){Ke(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}var ye=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Dr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Rt(r,t){return r<<32-t|r>>>t}function di(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function or(r){return typeof r=="string"&&(r=di(r)),Ke(r),r}function Yn(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Ke(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 Ne=class{clone(){return this._cloneInto()}};function Kr(r){let t=n=>r().update(or(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function Ur(r=32){if(ye&&typeof ye.getRandomValues=="function")return ye.getRandomValues(new Uint8Array(r));if(ye&&typeof ye.randomBytes=="function")return ye.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function Cu(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,f=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+f,a,n)}function hi(r,t,e){return r&t^~r&e}function pi(r,t,e){return r&t^r&e^t&e}var Oe=class extends Ne{constructor(t,e,n,o){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=Dr(this.buffer)}update(t){Ue(this);let{view:e,buffer:n,blockLen:o}=this;t=or(t);let s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Dr(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){Ue(this),fi(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)e[l]=0;Cu(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=Dr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)a.setUint32(4*l,u[l],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.length=o,t.pos=a,t.finished=s,t.destroyed=i,o%e&&t.buffer.set(n),t}};var Nr=BigInt(4294967295),jn=BigInt(32);function mi(r,t=!1){return t?{h:Number(r&Nr),l:Number(r>>jn&Nr)}:{h:Number(r>>jn&Nr)|0,l:Number(r&Nr)|0}}function _u(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:s,l:i}=mi(r[o],t);[e[o],n[o]]=[s,i]}return[e,n]}var ku=(r,t)=>BigInt(r>>>0)<<jn|BigInt(t>>>0),Ru=(r,t,e)=>r>>>e,Du=(r,t,e)=>r<<32-e|t>>>e,Ku=(r,t,e)=>r>>>e|t<<32-e,Uu=(r,t,e)=>r<<32-e|t>>>e,Nu=(r,t,e)=>r<<64-e|t>>>e-32,Ou=(r,t,e)=>r>>>e-32|t<<64-e,Mu=(r,t)=>t,qu=(r,t)=>r,Hu=(r,t,e)=>r<<e|t>>>32-e,Vu=(r,t,e)=>t<<e|r>>>32-e,Fu=(r,t,e)=>t<<e-32|r>>>64-e,zu=(r,t,e)=>r<<e-32|t>>>64-e;function Gu(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Wu=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),$u=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Zu=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Yu=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,ju=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Xu=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Qu={fromBig:mi,split:_u,toBig:ku,shrSH:Ru,shrSL:Du,rotrSH:Ku,rotrSL:Uu,rotrBH:Nu,rotrBL:Ou,rotr32H:Mu,rotr32L:qu,rotlSH:Hu,rotlSL:Vu,rotlBH:Fu,rotlBL:zu,add:Gu,add3L:Wu,add3H:$u,add4L:Zu,add4H:Yu,add5H:Xu,add5L:ju},K=Qu;var[Ju,tl]=K.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),ne=new Uint32Array(80),oe=new Uint32Array(80),Xn=class extends Oe{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:f,El:u,Fh:l,Fl:d,Gh:m,Gl:w,Hh:b,Hl:h}=this;return[t,e,n,o,s,i,a,c,f,u,l,d,m,w,b,h]}set(t,e,n,o,s,i,a,c,f,u,l,d,m,w,b,h){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=f|0,this.El=u|0,this.Fh=l|0,this.Fl=d|0,this.Gh=m|0,this.Gl=w|0,this.Hh=b|0,this.Hl=h|0}process(t,e){for(let y=0;y<16;y++,e+=4)ne[y]=t.getUint32(e),oe[y]=t.getUint32(e+=4);for(let y=16;y<80;y++){let I=ne[y-15]|0,_=oe[y-15]|0,C=K.rotrSH(I,_,1)^K.rotrSH(I,_,8)^K.shrSH(I,_,7),B=K.rotrSL(I,_,1)^K.rotrSL(I,_,8)^K.shrSL(I,_,7),P=ne[y-2]|0,T=oe[y-2]|0,Y=K.rotrSH(P,T,19)^K.rotrBH(P,T,61)^K.shrSH(P,T,6),H=K.rotrSL(P,T,19)^K.rotrBL(P,T,61)^K.shrSL(P,T,6),O=K.add4L(B,H,oe[y-7],oe[y-16]),ot=K.add4H(O,C,Y,ne[y-7],ne[y-16]);ne[y]=ot|0,oe[y]=O|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:f,Dl:u,Eh:l,El:d,Fh:m,Fl:w,Gh:b,Gl:h,Hh:E,Hl:S}=this;for(let y=0;y<80;y++){let I=K.rotrSH(l,d,14)^K.rotrSH(l,d,18)^K.rotrBH(l,d,41),_=K.rotrSL(l,d,14)^K.rotrSL(l,d,18)^K.rotrBL(l,d,41),C=l&m^~l&b,B=d&w^~d&h,P=K.add5L(S,_,B,tl[y],oe[y]),T=K.add5H(P,E,I,C,Ju[y],ne[y]),Y=P|0,H=K.rotrSH(n,o,28)^K.rotrBH(n,o,34)^K.rotrBH(n,o,39),O=K.rotrSL(n,o,28)^K.rotrBL(n,o,34)^K.rotrBL(n,o,39),ot=n&s^n&a^s&a,v=o&i^o&c^i&c;E=b|0,S=h|0,b=m|0,h=w|0,m=l|0,w=d|0,{h:l,l:d}=K.add(f|0,u|0,T|0,Y|0),f=a|0,u=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let L=K.add3L(Y,O,v);n=K.add3H(L,T,H,ot),o=L|0}({h:n,l:o}=K.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=K.add(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=K.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=K.add(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:d}=K.add(this.Eh|0,this.El|0,l|0,d|0),{h:m,l:w}=K.add(this.Fh|0,this.Fl|0,m|0,w|0),{h:b,l:h}=K.add(this.Gh|0,this.Gl|0,b|0,h|0),{h:E,l:S}=K.add(this.Hh|0,this.Hl|0,E|0,S|0),this.set(n,o,s,i,a,c,f,u,l,d,m,w,b,h,E,S)}roundClean(){ne.fill(0),oe.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var yi=Kr(()=>new Xn);var qr={};mt(qr,{aInRange:()=>At,abool:()=>Dt,abytes:()=>Me,bitGet:()=>il,bitLen:()=>eo,bitMask:()=>ir,bitSet:()=>al,bytesToHex:()=>$t,bytesToNumberBE:()=>Zt,bytesToNumberLE:()=>ie,concatBytes:()=>Yt,createHmacDrbg:()=>ro,ensureBytes:()=>J,equalBytes:()=>ol,hexToBytes:()=>be,hexToNumber:()=>to,inRange:()=>sr,isBytes:()=>se,memoized:()=>xe,notImplemented:()=>ul,numberToBytesBE:()=>ae,numberToBytesLE:()=>we,numberToHexUnpadded:()=>ge,numberToVarBytesBE:()=>nl,utf8ToBytes:()=>sl,validateObject:()=>Ot});var Or=BigInt(0),Mr=BigInt(1),el=BigInt(2);function se(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Me(r){if(!se(r))throw new Error("Uint8Array expected")}function Dt(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}var rl=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function $t(r){Me(r);let t="";for(let e=0;e<r.length;e++)t+=rl[r[e]];return t}function ge(r){let t=r.toString(16);return t.length&1?"0"+t:t}function to(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Or:BigInt("0x"+r)}var Wt={_0:48,_9:57,A:65,F:70,a:97,f:102};function gi(r){if(r>=Wt._0&&r<=Wt._9)return r-Wt._0;if(r>=Wt.A&&r<=Wt.F)return r-(Wt.A-10);if(r>=Wt.a&&r<=Wt.f)return r-(Wt.a-10)}function be(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let t=r.length,e=t/2;if(t%2)throw new Error("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=gi(r.charCodeAt(s)),a=gi(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 Zt(r){return to($t(r))}function ie(r){return Me(r),to($t(Uint8Array.from(r).reverse()))}function ae(r,t){return be(r.toString(16).padStart(t*2,"0"))}function we(r,t){return ae(r,t).reverse()}function nl(r){return be(ge(r))}function J(r,t,e){let n;if(typeof t=="string")try{n=be(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(se(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}function Yt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Me(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}function ol(r,t){if(r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}function sl(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}var Qn=r=>typeof r=="bigint"&&Or<=r;function sr(r,t,e){return Qn(r)&&Qn(t)&&Qn(e)&&t<=r&&r<e}function At(r,t,e,n){if(!sr(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function eo(r){let t;for(t=0;r>Or;r>>=Mr,t+=1);return t}function il(r,t){return r>>BigInt(t)&Mr}function al(r,t,e){return r|(e?Mr:Or)<<BigInt(t)}var ir=r=>(el<<BigInt(r-1))-Mr,Jn=r=>new Uint8Array(r),bi=r=>Uint8Array.from(r);function ro(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=Jn(r),o=Jn(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},a=(...l)=>e(o,n,...l),c=(l=Jn())=>{o=a(bi([0]),l),n=a(),l.length!==0&&(o=a(bi([1]),l),n=a())},f=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,d=[];for(;l<t;){n=a();let m=n.slice();d.push(m),l+=n.length}return Yt(...d)};return(l,d)=>{i(),c(l);let m;for(;!(m=d(f()));)c();return i(),m}}var cl={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||se(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function Ot(r,t,e={}){let n=(o,s,i)=>{let a=cl[s];if(typeof a!="function")throw new Error("invalid validator function");let c=r[o];if(!(i&&c===void 0)&&!a(c,r))throw new Error("param "+String(o)+" is invalid. Expected "+s+", got "+c)};for(let[o,s]of Object.entries(t))n(o,s,!1);for(let[o,s]of Object.entries(e))n(o,s,!0);return r}var ul=()=>{throw new Error("not implemented")};function xe(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 st=BigInt(0),X=BigInt(1),Ee=BigInt(2),ll=BigInt(3),no=BigInt(4),wi=BigInt(5),xi=BigInt(8),fl=BigInt(9),dl=BigInt(16);function G(r,t){let e=r%t;return e>=st?e:t+e}function hl(r,t,e){if(t<st)throw new Error("invalid exponent, negatives unsupported");if(e<=st)throw new Error("invalid modulus");if(e===X)return st;let n=X;for(;t>st;)t&X&&(n=n*r%e),r=r*r%e,t>>=X;return n}function Q(r,t,e){let n=r;for(;t-- >st;)n*=n,n%=e;return n}function Hr(r,t){if(r===st)throw new Error("invert: expected non-zero number");if(t<=st)throw new Error("invert: expected positive modulus, got "+t);let e=G(r,t),n=t,o=st,s=X,i=X,a=st;for(;e!==st;){let f=n/e,u=n%e,l=o-i*f,d=s-a*f;n=e,e=u,o=i,s=a,i=l,a=d}if(n!==X)throw new Error("invert: does not exist");return G(o,t)}function pl(r){let t=(r-X)/Ee,e,n,o;for(e=r-X,n=0;e%Ee===st;e/=Ee,n++);for(o=Ee;o<r&&hl(o,t,r)!==r-X;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let i=(r+X)/no;return function(c,f){let u=c.pow(f,i);if(!c.eql(c.sqr(u),f))throw new Error("Cannot find square root");return u}}let s=(e+X)/Ee;return function(a,c){if(a.pow(c,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let f=n,u=a.pow(a.mul(a.ONE,o),e),l=a.pow(c,s),d=a.pow(c,e);for(;!a.eql(d,a.ONE);){if(a.eql(d,a.ZERO))return a.ZERO;let m=1;for(let b=a.sqr(d);m<f&&!a.eql(b,a.ONE);m++)b=a.sqr(b);let w=a.pow(u,X<<BigInt(f-m-1));u=a.sqr(w),l=a.mul(l,w),d=a.mul(d,u),f=m}return l}}function ml(r){if(r%no===ll){let t=(r+X)/no;return function(n,o){let s=n.pow(o,t);if(!n.eql(n.sqr(s),o))throw new Error("Cannot find square root");return s}}if(r%xi===wi){let t=(r-wi)/xi;return function(n,o){let s=n.mul(o,Ee),i=n.pow(s,t),a=n.mul(o,i),c=n.mul(n.mul(a,Ee),i),f=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(f),o))throw new Error("Cannot find square root");return f}}return r%dl,pl(r)}var Ei=(r,t)=>(G(r,t)&X)===X,yl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function oo(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=yl.reduce((n,o)=>(n[o]="function",n),t);return Ot(r,e)}function gl(r,t,e){if(e<st)throw new Error("invalid exponent, negatives unsupported");if(e===st)return r.ONE;if(e===X)return t;let n=r.ONE,o=t;for(;e>st;)e&X&&(n=r.mul(n,o)),o=r.sqr(o),e>>=X;return n}function bl(r,t){let e=new Array(t.length),n=t.reduce((s,i,a)=>r.is0(i)?s:(e[a]=s,r.mul(s,i)),r.ONE),o=r.inv(n);return t.reduceRight((s,i,a)=>r.is0(i)?s:(e[a]=r.mul(s,e[a]),r.mul(s,i)),o),e}function so(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function ce(r,t,e=!1,n={}){if(r<=st)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:s}=so(r,t);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let i,a=Object.freeze({ORDER:r,isLE:e,BITS:o,BYTES:s,MASK:ir(o),ZERO:st,ONE:X,create:c=>G(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return st<=c&&c<r},is0:c=>c===st,isOdd:c=>(c&X)===X,neg:c=>G(-c,r),eql:(c,f)=>c===f,sqr:c=>G(c*c,r),add:(c,f)=>G(c+f,r),sub:(c,f)=>G(c-f,r),mul:(c,f)=>G(c*f,r),pow:(c,f)=>gl(a,c,f),div:(c,f)=>G(c*Hr(f,r),r),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>Hr(c,r),sqrt:n.sqrt||(c=>(i||(i=ml(r)),i(a,c))),invertBatch:c=>bl(a,c),cmov:(c,f,u)=>u?f:c,toBytes:c=>e?we(c,s):ae(c,s),fromBytes:c=>{if(c.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+c.length);return e?ie(c):Zt(c)}});return Object.freeze(a)}function vi(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 io(r){let t=vi(r);return t+Math.ceil(t/2)}function Si(r,t,e=!1){let n=r.length,o=vi(t),s=io(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?ie(r):Zt(r),a=G(i,t-X)+X;return e?we(a,o):ae(a,o)}var Ai=BigInt(0),Vr=BigInt(1);function ao(r,t){let e=t.negate();return r?e:t}function Ii(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function co(r,t){Ii(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1);return{windows:e,windowSize:n}}function wl(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 xl(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 uo=new WeakMap,Bi=new WeakMap;function lo(r){return Bi.get(r)||1}function Fr(r,t){return{constTimeNegate:ao,hasPrecomputes(e){return lo(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>Ai;)n&Vr&&(o=o.add(s)),s=s.double(),n>>=Vr;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=co(n,t),i=[],a=e,c=a;for(let f=0;f<o;f++){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{windows:s,windowSize:i}=co(e,t),a=r.ZERO,c=r.BASE,f=BigInt(2**e-1),u=2**e,l=BigInt(e);for(let d=0;d<s;d++){let m=d*i,w=Number(o&f);o>>=l,w>i&&(w-=u,o+=Vr);let b=m,h=m+Math.abs(w)-1,E=d%2!==0,S=w<0;w===0?c=c.add(ao(E,n[b])):a=a.add(ao(S,n[h]))}return{p:a,f:c}},wNAFUnsafe(e,n,o,s=r.ZERO){let{windows:i,windowSize:a}=co(e,t),c=BigInt(2**e-1),f=2**e,u=BigInt(e);for(let l=0;l<i;l++){let d=l*a;if(o===Ai)break;let m=Number(o&c);if(o>>=u,m>a&&(m-=f,o+=Vr),m===0)continue;let w=n[d+Math.abs(m)-1];m<0&&(w=w.negate()),s=s.add(w)}return s},getPrecomputes(e,n,o){let s=uo.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&uo.set(n,o(s))),s},wNAFCached(e,n,o){let s=lo(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=lo(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){Ii(n,t),Bi.set(e,n),uo.delete(e)}}}function zr(r,t,e,n){if(wl(e,r),xl(n,t),e.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=r.ZERO,s=eo(BigInt(e.length)),i=s>12?s-3:s>4?s-2:s?2:1,a=(1<<i)-1,c=new Array(a+1).fill(o),f=Math.floor((t.BITS-1)/i)*i,u=o;for(let l=f;l>=0;l-=i){c.fill(o);for(let m=0;m<n.length;m++){let w=n[m],b=Number(w>>BigInt(l)&BigInt(a));c[b]=c[b].add(e[m])}let d=o;for(let m=c.length-1,w=o;m>0;m--)w=w.add(c[m]),d=d.add(w);if(u=u.add(d),l!==0)for(let m=0;m<i;m++)u=u.double()}return u}function ar(r){return oo(r.Fp),Ot(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...so(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Kt=BigInt(0),It=BigInt(1),Gr=BigInt(2),El=BigInt(8),vl={zip215:!0};function Sl(r){let t=ar(r);return Ot(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Ti(r){let t=Sl(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:a,h:c}=t,f=Gr<<BigInt(a*8)-It,u=e.create,l=ce(t.n,t.nBitLength),d=t.uvRatio||((g,p)=>{try{return{isValid:!0,value:e.sqrt(g*e.inv(p))}}catch{return{isValid:!1,value:Kt}}}),m=t.adjustScalarBytes||(g=>g),w=t.domain||((g,p,x)=>{if(Dt("phflag",x),p.length||x)throw new Error("Contexts/pre-hash are not supported");return g});function b(g,p){At("coordinate "+g,p,Kt,f)}function h(g){if(!(g instanceof y))throw new Error("ExtendedPoint expected")}let E=xe((g,p)=>{let{ex:x,ey:A,ez:k}=g,R=g.is0();p==null&&(p=R?El:e.inv(k));let N=u(x*p),M=u(A*p),D=u(k*p);if(R)return{x:Kt,y:It};if(D!==It)throw new Error("invZ was invalid");return{x:N,y:M}}),S=xe(g=>{let{a:p,d:x}=t;if(g.is0())throw new Error("bad point: ZERO");let{ex:A,ey:k,ez:R,et:N}=g,M=u(A*A),D=u(k*k),F=u(R*R),Z=u(F*F),it=u(M*p),at=u(F*u(it+D)),ut=u(Z+u(x*u(M*D)));if(at!==ut)throw new Error("bad point: equation left != right (1)");let lt=u(A*k),Et=u(R*N);if(lt!==Et)throw new Error("bad point: equation left != right (2)");return!0});class y{constructor(p,x,A,k){this.ex=p,this.ey=x,this.ez=A,this.et=k,b("x",p),b("y",x),b("z",A),b("t",k),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(p){if(p instanceof y)throw new Error("extended point not allowed");let{x,y:A}=p||{};return b("x",x),b("y",A),new y(x,A,It,u(x*A))}static normalizeZ(p){let x=e.invertBatch(p.map(A=>A.ez));return p.map((A,k)=>A.toAffine(x[k])).map(y.fromAffine)}static msm(p,x){return zr(y,l,p,x)}_setWindowSize(p){C.setWindowSize(this,p)}assertValidity(){S(this)}equals(p){h(p);let{ex:x,ey:A,ez:k}=this,{ex:R,ey:N,ez:M}=p,D=u(x*M),F=u(R*k),Z=u(A*M),it=u(N*k);return D===F&&Z===it}is0(){return this.equals(y.ZERO)}negate(){return new y(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:p}=t,{ex:x,ey:A,ez:k}=this,R=u(x*x),N=u(A*A),M=u(Gr*u(k*k)),D=u(p*R),F=x+A,Z=u(u(F*F)-R-N),it=D+N,at=it-M,ut=D-N,lt=u(Z*at),Et=u(it*ut),pt=u(Z*ut),Nt=u(at*it);return new y(lt,Et,Nt,pt)}add(p){h(p);let{a:x,d:A}=t,{ex:k,ey:R,ez:N,et:M}=this,{ex:D,ey:F,ez:Z,et:it}=p;if(x===BigInt(-1)){let Ls=u((R-k)*(F+D)),Ps=u((R+k)*(F-D)),En=u(Ps-Ls);if(En===Kt)return this.double();let Cs=u(N*Gr*it),_s=u(M*Gr*Z),ks=_s+Cs,Rs=Ps+Ls,Ds=_s-Cs,Xa=u(ks*En),Qa=u(Rs*Ds),Ja=u(ks*Ds),tc=u(En*Rs);return new y(Xa,Qa,tc,Ja)}let at=u(k*D),ut=u(R*F),lt=u(M*A*it),Et=u(N*Z),pt=u((k+R)*(D+F)-at-ut),Nt=Et-lt,Ht=Et+lt,Ze=u(ut-x*at),$a=u(pt*Nt),Za=u(Ht*Ze),Ya=u(pt*Ze),ja=u(Nt*Ht);return new y($a,Za,ja,Ya)}subtract(p){return this.add(p.negate())}wNAF(p){return C.wNAFCached(this,p,y.normalizeZ)}multiply(p){let x=p;At("scalar",x,It,n);let{p:A,f:k}=this.wNAF(x);return y.normalizeZ([A,k])[0]}multiplyUnsafe(p,x=y.ZERO){let A=p;return At("scalar",A,Kt,n),A===Kt?_:this.is0()||A===It?this:C.wNAFCachedUnsafe(this,A,y.normalizeZ,x)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return C.unsafeLadder(this,n).is0()}toAffine(p){return E(this,p)}clearCofactor(){let{h:p}=t;return p===It?this:this.multiplyUnsafe(p)}static fromHex(p,x=!1){let{d:A,a:k}=t,R=e.BYTES;p=J("pointHex",p,R),Dt("zip215",x);let N=p.slice(),M=p[R-1];N[R-1]=M&-129;let D=ie(N),F=x?f:e.ORDER;At("pointHex.y",D,Kt,F);let Z=u(D*D),it=u(Z-It),at=u(A*Z-k),{isValid:ut,value:lt}=d(it,at);if(!ut)throw new Error("Point.fromHex: invalid y coordinate");let Et=(lt&It)===It,pt=(M&128)!==0;if(!x&&lt===Kt&&pt)throw new Error("Point.fromHex: x=0 and x_0=1");return pt!==Et&&(lt=u(-lt)),y.fromAffine({x:lt,y:D})}static fromPrivateKey(p){return T(p).point}toRawBytes(){let{x:p,y:x}=this.toAffine(),A=we(x,e.BYTES);return A[A.length-1]|=p&It?128:0,A}toHex(){return $t(this.toRawBytes())}}y.BASE=new y(t.Gx,t.Gy,It,u(t.Gx*t.Gy)),y.ZERO=new y(Kt,It,It,Kt);let{BASE:I,ZERO:_}=y,C=Fr(y,a*8);function B(g){return G(g,n)}function P(g){return B(ie(g))}function T(g){let p=e.BYTES;g=J("private key",g,p);let x=J("hashed private key",s(g),2*p),A=m(x.slice(0,p)),k=x.slice(p,2*p),R=P(A),N=I.multiply(R),M=N.toRawBytes();return{head:A,prefix:k,scalar:R,point:N,pointBytes:M}}function Y(g){return T(g).pointBytes}function H(g=new Uint8Array,...p){let x=Yt(...p);return P(s(w(x,J("context",g),!!o)))}function O(g,p,x={}){g=J("message",g),o&&(g=o(g));let{prefix:A,scalar:k,pointBytes:R}=T(p),N=H(x.context,A,g),M=I.multiply(N).toRawBytes(),D=H(x.context,M,R,g),F=B(N+D*k);At("signature.s",F,Kt,n);let Z=Yt(M,we(F,e.BYTES));return J("result",Z,e.BYTES*2)}let ot=vl;function v(g,p,x,A=ot){let{context:k,zip215:R}=A,N=e.BYTES;g=J("signature",g,2*N),p=J("message",p),x=J("publicKey",x,N),R!==void 0&&Dt("zip215",R),o&&(p=o(p));let M=ie(g.slice(N,2*N)),D,F,Z;try{D=y.fromHex(x,R),F=y.fromHex(g.slice(0,N),R),Z=I.multiplyUnsafe(M)}catch{return!1}if(!R&&D.isSmallOrder())return!1;let it=H(k,F.toRawBytes(),D.toRawBytes(),p);return F.add(D.multiplyUnsafe(it)).subtract(Z).clearCofactor().equals(y.ZERO)}return I._setWindowSize(8),{CURVE:t,getPublicKey:Y,sign:O,verify:v,ExtendedPoint:y,utils:{getExtendedPublicKey:T,randomPrivateKey:()=>i(e.BYTES),precompute(g=8,p=y.BASE){return p._setWindowSize(g),p.multiply(BigInt(3)),p}}}}var fo=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Li=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),rp=BigInt(0),Al=BigInt(1),Pi=BigInt(2),np=BigInt(3),Il=BigInt(5),Bl=BigInt(8);function Tl(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=fo,a=r*r%s*r%s,c=Q(a,Pi,s)*a%s,f=Q(c,Al,s)*r%s,u=Q(f,Il,s)*f%s,l=Q(u,t,s)*u%s,d=Q(l,e,s)*l%s,m=Q(d,n,s)*d%s,w=Q(m,o,s)*m%s,b=Q(w,o,s)*m%s,h=Q(b,t,s)*u%s;return{pow_p_5_8:Q(h,Pi,s)*r%s,b2:a}}function Ll(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Pl(r,t){let e=fo,n=G(t*t*t,e),o=G(n*n*t,e),s=Tl(r*o).pow_p_5_8,i=G(r*n*s,e),a=G(t*i*i,e),c=i,f=G(i*Li,e),u=a===r,l=a===G(-r,e),d=a===G(-r*Li,e);return u&&(i=c),(l||d)&&(i=f),Ei(i,e)&&(i=G(-i,e)),{isValid:u||l,value:i}}var Cl=ce(fo,void 0,!0),_l={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Cl,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:Bl,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:yi,randomBytes:Ur,adjustScalarBytes:Ll,uvRatio:Pl},Ci=Ti(_l);var Wr=32;function _i(r,t,e){return Ci.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var $r=class{type="Ed25519";raw;constructor(t){this.raw=ho(t,Wr)}toMultihash(){return kt.digest(Pt(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:j(this.raw,t.raw)}verify(t,e){return _i(this.raw,e,t)}};function po(r){return r=ho(r,Wr),new $r(r)}function ho(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new q(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var Rl=Math.pow(2,7),Dl=Math.pow(2,14),Kl=Math.pow(2,21),mo=Math.pow(2,28),yo=Math.pow(2,35),go=Math.pow(2,42),bo=Math.pow(2,49),V=128,ft=127;function Bt(r){if(r<Rl)return 1;if(r<Dl)return 2;if(r<Kl)return 3;if(r<mo)return 4;if(r<yo)return 5;if(r<go)return 6;if(r<bo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function wo(r,t,e=0){switch(Bt(r)){case 8:t[e++]=r&255|V,r/=128;case 7:t[e++]=r&255|V,r/=128;case 6:t[e++]=r&255|V,r/=128;case 5:t[e++]=r&255|V,r/=128;case 4:t[e++]=r&255|V,r>>>=7;case 3:t[e++]=r&255|V,r>>>=7;case 2:t[e++]=r&255|V,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Ul(r,t,e=0){switch(Bt(r)){case 8:t.set(e++,r&255|V),r/=128;case 7:t.set(e++,r&255|V),r/=128;case 6:t.set(e++,r&255|V),r/=128;case 5:t.set(e++,r&255|V),r/=128;case 4:t.set(e++,r&255|V),r>>>=7;case 3:t.set(e++,r&255|V),r>>>=7;case 2:t.set(e++,r&255|V),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function xo(r,t){let e=r[t],n=0;if(n+=e&ft,e<V||(e=r[t+1],n+=(e&ft)<<7,e<V)||(e=r[t+2],n+=(e&ft)<<14,e<V)||(e=r[t+3],n+=(e&ft)<<21,e<V)||(e=r[t+4],n+=(e&ft)*mo,e<V)||(e=r[t+5],n+=(e&ft)*yo,e<V)||(e=r[t+6],n+=(e&ft)*go,e<V)||(e=r[t+7],n+=(e&ft)*bo,e<V))return n;throw new RangeError("Could not decode varint")}function Nl(r,t){let e=r.get(t),n=0;if(n+=e&ft,e<V||(e=r.get(t+1),n+=(e&ft)<<7,e<V)||(e=r.get(t+2),n+=(e&ft)<<14,e<V)||(e=r.get(t+3),n+=(e&ft)<<21,e<V)||(e=r.get(t+4),n+=(e&ft)*mo,e<V)||(e=r.get(t+5),n+=(e&ft)*yo,e<V)||(e=r.get(t+6),n+=(e&ft)*go,e<V)||(e=r.get(t+7),n+=(e&ft)*bo,e<V))return n;throw new RangeError("Could not decode varint")}function Mt(r,t,e=0){return t==null&&(t=vt(Bt(r))),t instanceof Uint8Array?wo(r,t,e):Ul(r,t,e)}function ve(r,t=0){return r instanceof Uint8Array?xo(r,t):Nl(r,t)}var vo=new Float32Array([-0]),ue=new Uint8Array(vo.buffer);function Ri(r,t,e){vo[0]=r,t[e]=ue[0],t[e+1]=ue[1],t[e+2]=ue[2],t[e+3]=ue[3]}function Di(r,t){return ue[0]=r[t],ue[1]=r[t+1],ue[2]=r[t+2],ue[3]=r[t+3],vo[0]}var So=new Float64Array([-0]),dt=new Uint8Array(So.buffer);function Ki(r,t,e){So[0]=r,t[e]=dt[0],t[e+1]=dt[1],t[e+2]=dt[2],t[e+3]=dt[3],t[e+4]=dt[4],t[e+5]=dt[5],t[e+6]=dt[6],t[e+7]=dt[7]}function Ui(r,t){return dt[0]=r[t],dt[1]=r[t+1],dt[2]=r[t+2],dt[3]=r[t+3],dt[4]=r[t+4],dt[5]=r[t+5],dt[6]=r[t+6],dt[7]=r[t+7],So[0]}var Ol=BigInt(Number.MAX_SAFE_INTEGER),Ml=BigInt(Number.MIN_SAFE_INTEGER),Lt=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 Se;if(t<Ol&&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>Ni&&(o=0n,++n>Ni&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return Se;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):Se}},Se=new Lt(0,0);Se.toBigInt=function(){return 0n};Se.zzEncode=Se.zzDecode=function(){return this};Se.length=function(){return 1};var Ni=4294967296n;function Oi(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 Mi(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 Ao(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 Ut(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Zr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Io=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,Ut(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 Ut(this,4);return Zr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ut(this,4);return Zr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ut(this,4);let t=Di(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Ut(this,4);let t=Ui(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 Ut(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Mi(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Ut(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Ut(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 Lt(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 Ut(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 Ut(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 Ut(this,8);let t=Zr(this.buf,this.pos+=4),e=Zr(this.buf,this.pos+=4);return new Lt(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=xo(this.buf,this.pos);return this.pos+=Bt(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 Bo(r){return new Io(r instanceof Uint8Array?r:r.subarray())}function gt(r,t,e){let n=Bo(r);return t.decode(n,void 0,e)}function To(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return vt(i);o+i>t&&(n=vt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Ae=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Lo(){}var Co=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},ql=To();function Hl(r){return globalThis.Buffer!=null?vt(r):ql(r)}var ur=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ae(Lo,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Ae(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new _o((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(Yr,10,Lt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Lt.fromBigInt(t);return this._push(Yr,e.length(),e)}uint64Number(t){return this._push(wo,Bt(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=Lt.fromBigInt(t).zzEncode();return this._push(Yr,e.length(),e)}sint64Number(t){let e=Lt.fromNumber(t).zzEncode();return this._push(Yr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Po,1,t?1:0)}fixed32(t){return this._push(cr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Lt.fromBigInt(t);return this._push(cr,4,e.lo)._push(cr,4,e.hi)}fixed64Number(t){let e=Lt.fromNumber(t);return this._push(cr,4,e.lo)._push(cr,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(Ri,4,t)}double(t){return this._push(Ki,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Po,1,0):this.uint32(e)._push(Fl,e,t)}string(t){let e=Oi(t);return e!==0?this.uint32(e)._push(Ao,e,t):this._push(Po,1,0)}fork(){return this.states=new Co(this),this.head=this.tail=new Ae(Lo,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 Ae(Lo,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=Hl(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Po(r,t,e){t[e]=r&255}function Vl(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var _o=class extends Ae{next;constructor(t,e){super(Vl,t,e),this.next=void 0}};function Yr(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 cr(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 Fl(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(ur.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(zl,t,r),this},ur.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Gl,t,r),this});function zl(r,t,e){t.set(r,e)}function Gl(r,t,e){r.length<40?Ao(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(z(r),e)}function ko(){return new ur}function bt(r,t){let e=ko();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var qe;(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"})(qe||(qe={}));function jr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Ro(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 jr("enum",qe.VARINT,e,n)}function wt(r,t){return jr("message",qe.LENGTH_DELIMITED,r,t)}var Ie=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"},lr=class extends Error{code="ERR_MAX_SIZE";name="MaxSizeError"};var rt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(rt||(rt={}));var Do;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Do||(Do={}));(function(r){r.codec=()=>Ro(Do)})(rt||(rt={}));var qt;(function(r){let t;r.codec=()=>(t==null&&(t=wt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),rt.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=rt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>bt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(qt||(qt={}));var Ko;(function(r){let t;r.codec=()=>(t==null&&(t=wt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),rt.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=rt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>bt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Ko||(Ko={}));var fr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Xr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Vi={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Xr("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 le=Vi;var hr={};mt(hr,{MAX_RSA_KEY_SIZE:()=>No,generateRSAKeyPair:()=>Wi,jwkToJWKKeyPair:()=>$i,jwkToPkcs1:()=>jl,jwkToPkix:()=>Ho,jwkToRSAPrivateKey:()=>Go,pkcs1MessageToJwk:()=>Mo,pkcs1MessageToRSAPrivateKey:()=>Vo,pkcs1ToJwk:()=>Yl,pkcs1ToRSAPrivateKey:()=>Gi,pkixMessageToJwk:()=>qo,pkixMessageToRSAPublicKey:()=>zo,pkixToJwk:()=>Xl,pkixToRSAPublicKey:()=>Fo});var Wl=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),fe=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),de=new Uint32Array(64),Uo=class extends Oe{constructor(){super(64,32,8,!1),this.A=fe[0]|0,this.B=fe[1]|0,this.C=fe[2]|0,this.D=fe[3]|0,this.E=fe[4]|0,this.F=fe[5]|0,this.G=fe[6]|0,this.H=fe[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 l=0;l<16;l++,e+=4)de[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let d=de[l-15],m=de[l-2],w=Rt(d,7)^Rt(d,18)^d>>>3,b=Rt(m,17)^Rt(m,19)^m>>>10;de[l]=b+de[l-7]+w+de[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:f,H:u}=this;for(let l=0;l<64;l++){let d=Rt(a,6)^Rt(a,11)^Rt(a,25),m=u+d+hi(a,c,f)+Wl[l]+de[l]|0,b=(Rt(n,2)^Rt(n,13)^Rt(n,22))+pi(n,o,s)|0;u=f,f=c,c=a,a=i+m|0,i=s,s=o,o=n,n=m+b|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,f=f+this.G|0,u=u+this.H|0,this.set(n,o,s,i,a,c,f,u)}roundClean(){de.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var He=Kr(()=>new Uo);var Ve=class{type="RSA";jwk;_raw;_multihash;constructor(t,e){this.jwk=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=hr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return et.createV1(114,this._multihash)}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:j(this.raw,t.raw)}verify(t,e){return zi(this.jwk,e,t)}},dr=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=hr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:j(this.raw,t.raw)}sign(t){return Fi(this.jwk,t)}};var No=8192,Oo=18,$l=1062,Zl=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Yl(r){let t=Gt(r);return Mo(t)}function Mo(r){return{n:U(r[1],"base64url"),e:U(r[2],"base64url"),d:U(r[3],"base64url"),p:U(r[4],"base64url"),q:U(r[5],"base64url"),dp:U(r[6],"base64url"),dq:U(r[7],"base64url"),qi:U(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 q("JWK was missing components");return re([St(Uint8Array.from([0])),St(z(r.n,"base64url")),St(z(r.e,"base64url")),St(z(r.d,"base64url")),St(z(r.p,"base64url")),St(z(r.q,"base64url")),St(z(r.dp,"base64url")),St(z(r.dq,"base64url")),St(z(r.qi,"base64url"))]).subarray()}function Xl(r){let t=Gt(r,{offset:0});return qo(t)}function qo(r){let t=Gt(r[1],{offset:0});return{kty:"RSA",n:U(t[0],"base64url"),e:U(t[1],"base64url")}}function Ho(r){if(r.n==null||r.e==null)throw new q("JWK was missing components");return re([Zl,Rr(re([St(z(r.n,"base64url")),St(z(r.e,"base64url"))]))]).subarray()}function Gi(r){let t=Gt(r);return Vo(t)}function Vo(r){let t=Mo(r);return Go(t)}function Fo(r,t){if(r.byteLength>=$l)throw new Pe("Key size is too large");let e=Gt(r,{offset:0});return zo(e,r,t)}function zo(r,t,e){let n=qo(r);if(e==null){let o=He(qt.encode({Type:rt.RSA,Data:t}));e=_t(Oo,o)}return new Ve(n,e)}function Go(r){if(Yi(r)>No)throw new q("Key size is too large");let t=$i(r),e=He(qt.encode({Type:rt.RSA,Data:Ho(t.publicKey)})),n=_t(Oo,e);return new dr(t.privateKey,new Ve(t.publicKey,n))}async function Wi(r){if(r>No)throw new q("Key size is too large");let t=await Zi(r),e=He(qt.encode({Type:rt.RSA,Data:Ho(t.publicKey)})),n=_t(Oo,e);return new dr(t.privateKey,new Ve(t.publicKey,n))}function $i(r){if(r==null)throw new q("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function Zi(r){let t=await le.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),e=await Ql(t);return{privateKey:e[0],publicKey:e[1]}}async function Fi(r,t){let e=await le.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await le.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function zi(r,t,e){let n=await le.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return le.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function Ql(r){if(r.privateKey==null||r.publicKey==null)throw new q("Private and public key are required");return Promise.all([le.get().subtle.exportKey("jwk",r.privateKey),le.get().subtle.exportKey("jwk",r.publicKey)])}function Yi(r){if(r.kty!=="RSA")throw new q("invalid key type");if(r.n==null)throw new q("invalid key modulus");return z(r.n,"base64url").length*8}var Qr=class extends Ne{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,li(t);let n=or(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),s.fill(0)}update(t){return Ue(this),this.iHash.update(t),this}digestInto(t){Ue(this),Ke(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}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Wo=(r,t,e)=>new Qr(r,t).update(e).digest();Wo.create=(r,t)=>new Qr(r,t);function ji(r){r.lowS!==void 0&&Dt("lowS",r.lowS),r.prehash!==void 0&&Dt("prehash",r.prehash)}function Jl(r){let t=ar(r);Ot(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:o}=t;if(e){if(!n.eql(o,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:tf,hexToBytes:ef}=qr,$o=class extends Error{constructor(t=""){super(t)}},jt={Err:$o,_tlv:{encode:(r,t)=>{let{Err:e}=jt;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=ge(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?ge(o.length/2|128):"";return ge(r)+s+o+t},decode(r,t){let{Err:e}=jt,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 f=t.subarray(n,n+c);if(f.length!==c)throw new e("tlv.decode: length bytes not complete");if(f[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let u of f)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}=jt;if(r<Xt)throw new t("integer: negative integers are not allowed");let e=ge(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}=jt;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 tf(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=jt,o=typeof r=="string"?ef(r):r;Me(o);let{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:f,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(f)}},hexFromSig(r){let{_tlv:t,_int:e}=jt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},Xt=BigInt(0),ct=BigInt(1),k0=BigInt(2),Xi=BigInt(3),R0=BigInt(4);function rf(r){let t=Jl(r),{Fp:e}=t,n=ce(t.n,t.nBitLength),o=t.toBytes||((b,h,E)=>{let S=h.toAffine();return Yt(Uint8Array.from([4]),e.toBytes(S.x),e.toBytes(S.y))}),s=t.fromBytes||(b=>{let h=b.subarray(1),E=e.fromBytes(h.subarray(0,e.BYTES)),S=e.fromBytes(h.subarray(e.BYTES,2*e.BYTES));return{x:E,y:S}});function i(b){let{a:h,b:E}=t,S=e.sqr(b),y=e.mul(S,b);return e.add(e.add(y,e.mul(b,h)),E)}if(!e.eql(e.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function a(b){return sr(b,ct,t.n)}function c(b){let{allowedPrivateKeyLengths:h,nByteLength:E,wrapPrivateKey:S,n:y}=t;if(h&&typeof b!="bigint"){if(se(b)&&(b=$t(b)),typeof b!="string"||!h.includes(b.length))throw new Error("invalid private key");b=b.padStart(E*2,"0")}let I;try{I=typeof b=="bigint"?b:Zt(J("private key",b,E))}catch{throw new Error("invalid private key, expected hex or "+E+" bytes, got "+typeof b)}return S&&(I=G(I,y)),At("private key",I,ct,y),I}function f(b){if(!(b instanceof d))throw new Error("ProjectivePoint expected")}let u=xe((b,h)=>{let{px:E,py:S,pz:y}=b;if(e.eql(y,e.ONE))return{x:E,y:S};let I=b.is0();h==null&&(h=I?e.ONE:e.inv(y));let _=e.mul(E,h),C=e.mul(S,h),B=e.mul(y,h);if(I)return{x:e.ZERO,y:e.ZERO};if(!e.eql(B,e.ONE))throw new Error("invZ was invalid");return{x:_,y:C}}),l=xe(b=>{if(b.is0()){if(t.allowInfinityPoint&&!e.is0(b.py))return;throw new Error("bad point: ZERO")}let{x:h,y:E}=b.toAffine();if(!e.isValid(h)||!e.isValid(E))throw new Error("bad point: x or y not FE");let S=e.sqr(E),y=i(h);if(!e.eql(S,y))throw new Error("bad point: equation left != right");if(!b.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class d{constructor(h,E,S){if(this.px=h,this.py=E,this.pz=S,h==null||!e.isValid(h))throw new Error("x required");if(E==null||!e.isValid(E))throw new Error("y required");if(S==null||!e.isValid(S))throw new Error("z required");Object.freeze(this)}static fromAffine(h){let{x:E,y:S}=h||{};if(!h||!e.isValid(E)||!e.isValid(S))throw new Error("invalid affine point");if(h instanceof d)throw new Error("projective point not allowed");let y=I=>e.eql(I,e.ZERO);return y(E)&&y(S)?d.ZERO:new d(E,S,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let E=e.invertBatch(h.map(S=>S.pz));return h.map((S,y)=>S.toAffine(E[y])).map(d.fromAffine)}static fromHex(h){let E=d.fromAffine(s(J("pointHex",h)));return E.assertValidity(),E}static fromPrivateKey(h){return d.BASE.multiply(c(h))}static msm(h,E){return zr(d,n,h,E)}_setWindowSize(h){w.setWindowSize(this,h)}assertValidity(){l(this)}hasEvenY(){let{y:h}=this.toAffine();if(e.isOdd)return!e.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){f(h);let{px:E,py:S,pz:y}=this,{px:I,py:_,pz:C}=h,B=e.eql(e.mul(E,C),e.mul(I,y)),P=e.eql(e.mul(S,C),e.mul(_,y));return B&&P}negate(){return new d(this.px,e.neg(this.py),this.pz)}double(){let{a:h,b:E}=t,S=e.mul(E,Xi),{px:y,py:I,pz:_}=this,C=e.ZERO,B=e.ZERO,P=e.ZERO,T=e.mul(y,y),Y=e.mul(I,I),H=e.mul(_,_),O=e.mul(y,I);return O=e.add(O,O),P=e.mul(y,_),P=e.add(P,P),C=e.mul(h,P),B=e.mul(S,H),B=e.add(C,B),C=e.sub(Y,B),B=e.add(Y,B),B=e.mul(C,B),C=e.mul(O,C),P=e.mul(S,P),H=e.mul(h,H),O=e.sub(T,H),O=e.mul(h,O),O=e.add(O,P),P=e.add(T,T),T=e.add(P,T),T=e.add(T,H),T=e.mul(T,O),B=e.add(B,T),H=e.mul(I,_),H=e.add(H,H),T=e.mul(H,O),C=e.sub(C,T),P=e.mul(H,Y),P=e.add(P,P),P=e.add(P,P),new d(C,B,P)}add(h){f(h);let{px:E,py:S,pz:y}=this,{px:I,py:_,pz:C}=h,B=e.ZERO,P=e.ZERO,T=e.ZERO,Y=t.a,H=e.mul(t.b,Xi),O=e.mul(E,I),ot=e.mul(S,_),v=e.mul(y,C),L=e.add(E,S),g=e.add(I,_);L=e.mul(L,g),g=e.add(O,ot),L=e.sub(L,g),g=e.add(E,y);let p=e.add(I,C);return g=e.mul(g,p),p=e.add(O,v),g=e.sub(g,p),p=e.add(S,y),B=e.add(_,C),p=e.mul(p,B),B=e.add(ot,v),p=e.sub(p,B),T=e.mul(Y,g),B=e.mul(H,v),T=e.add(B,T),B=e.sub(ot,T),T=e.add(ot,T),P=e.mul(B,T),ot=e.add(O,O),ot=e.add(ot,O),v=e.mul(Y,v),g=e.mul(H,g),ot=e.add(ot,v),v=e.sub(O,v),v=e.mul(Y,v),g=e.add(g,v),O=e.mul(ot,g),P=e.add(P,O),O=e.mul(p,g),B=e.mul(L,B),B=e.sub(B,O),O=e.mul(L,ot),T=e.mul(p,T),T=e.add(T,O),new d(B,P,T)}subtract(h){return this.add(h.negate())}is0(){return this.equals(d.ZERO)}wNAF(h){return w.wNAFCached(this,h,d.normalizeZ)}multiplyUnsafe(h){let{endo:E,n:S}=t;At("scalar",h,Xt,S);let y=d.ZERO;if(h===Xt)return y;if(this.is0()||h===ct)return this;if(!E||w.hasPrecomputes(this))return w.wNAFCachedUnsafe(this,h,d.normalizeZ);let{k1neg:I,k1:_,k2neg:C,k2:B}=E.splitScalar(h),P=y,T=y,Y=this;for(;_>Xt||B>Xt;)_&ct&&(P=P.add(Y)),B&ct&&(T=T.add(Y)),Y=Y.double(),_>>=ct,B>>=ct;return I&&(P=P.negate()),C&&(T=T.negate()),T=new d(e.mul(T.px,E.beta),T.py,T.pz),P.add(T)}multiply(h){let{endo:E,n:S}=t;At("scalar",h,ct,S);let y,I;if(E){let{k1neg:_,k1:C,k2neg:B,k2:P}=E.splitScalar(h),{p:T,f:Y}=this.wNAF(C),{p:H,f:O}=this.wNAF(P);T=w.constTimeNegate(_,T),H=w.constTimeNegate(B,H),H=new d(e.mul(H.px,E.beta),H.py,H.pz),y=T.add(H),I=Y.add(O)}else{let{p:_,f:C}=this.wNAF(h);y=_,I=C}return d.normalizeZ([y,I])[0]}multiplyAndAddUnsafe(h,E,S){let y=d.BASE,I=(C,B)=>B===Xt||B===ct||!C.equals(y)?C.multiplyUnsafe(B):C.multiply(B),_=I(this,E).add(I(h,S));return _.is0()?void 0:_}toAffine(h){return u(this,h)}isTorsionFree(){let{h,isTorsionFree:E}=t;if(h===ct)return!0;if(E)return E(d,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:E}=t;return h===ct?this:E?E(d,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return Dt("isCompressed",h),this.assertValidity(),o(d,this,h)}toHex(h=!0){return Dt("isCompressed",h),$t(this.toRawBytes(h))}}d.BASE=new d(t.Gx,t.Gy,e.ONE),d.ZERO=new d(e.ZERO,e.ONE,e.ZERO);let m=t.nBitLength,w=Fr(d,t.endo?Math.ceil(m/2):m);return{CURVE:t,ProjectivePoint:d,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:a}}function nf(r){let t=ar(r);return Ot(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Qi(r){let t=nf(r),{Fp:e,n}=t,o=e.BYTES+1,s=2*e.BYTES+1;function i(v){return G(v,n)}function a(v){return Hr(v,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:f,weierstrassEquation:u,isWithinCurveOrder:l}=rf({...t,toBytes(v,L,g){let p=L.toAffine(),x=e.toBytes(p.x),A=Yt;return Dt("isCompressed",g),g?A(Uint8Array.from([L.hasEvenY()?2:3]),x):A(Uint8Array.from([4]),x,e.toBytes(p.y))},fromBytes(v){let L=v.length,g=v[0],p=v.subarray(1);if(L===o&&(g===2||g===3)){let x=Zt(p);if(!sr(x,ct,e.ORDER))throw new Error("Point is not on curve");let A=u(x),k;try{k=e.sqrt(A)}catch(M){let D=M instanceof Error?": "+M.message:"";throw new Error("Point is not on curve"+D)}let R=(k&ct)===ct;return(g&1)===1!==R&&(k=e.neg(k)),{x,y:k}}else if(L===s&&g===4){let x=e.fromBytes(p.subarray(0,e.BYTES)),A=e.fromBytes(p.subarray(e.BYTES,2*e.BYTES));return{x,y:A}}else{let x=o,A=s;throw new Error("invalid Point, expected length of "+x+", or uncompressed "+A+", got "+L)}}}),d=v=>$t(ae(v,t.nByteLength));function m(v){let L=n>>ct;return v>L}function w(v){return m(v)?i(-v):v}let b=(v,L,g)=>Zt(v.slice(L,g));class h{constructor(L,g,p){this.r=L,this.s=g,this.recovery=p,this.assertValidity()}static fromCompact(L){let g=t.nByteLength;return L=J("compactSignature",L,g*2),new h(b(L,0,g),b(L,g,2*g))}static fromDER(L){let{r:g,s:p}=jt.toSig(J("DER",L));return new h(g,p)}assertValidity(){At("r",this.r,ct,n),At("s",this.s,ct,n)}addRecoveryBit(L){return new h(this.r,this.s,L)}recoverPublicKey(L){let{r:g,s:p,recovery:x}=this,A=C(J("msgHash",L));if(x==null||![0,1,2,3].includes(x))throw new Error("recovery id invalid");let k=x===2||x===3?g+t.n:g;if(k>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let R=(x&1)===0?"02":"03",N=c.fromHex(R+d(k)),M=a(k),D=i(-A*M),F=i(p*M),Z=c.BASE.multiplyAndAddUnsafe(N,D,F);if(!Z)throw new Error("point at infinify");return Z.assertValidity(),Z}hasHighS(){return m(this.s)}normalizeS(){return this.hasHighS()?new h(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return be(this.toDERHex())}toDERHex(){return jt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return be(this.toCompactHex())}toCompactHex(){return d(this.r)+d(this.s)}}let E={isValidPrivateKey(v){try{return f(v),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let v=io(t.n);return Si(t.randomBytes(v),t.n)},precompute(v=8,L=c.BASE){return L._setWindowSize(v),L.multiply(BigInt(3)),L}};function S(v,L=!0){return c.fromPrivateKey(v).toRawBytes(L)}function y(v){let L=se(v),g=typeof v=="string",p=(L||g)&&v.length;return L?p===o||p===s:g?p===2*o||p===2*s:v instanceof c}function I(v,L,g=!0){if(y(v))throw new Error("first arg must be private key");if(!y(L))throw new Error("second arg must be public key");return c.fromHex(L).multiply(f(v)).toRawBytes(g)}let _=t.bits2int||function(v){if(v.length>8192)throw new Error("input is too large");let L=Zt(v),g=v.length*8-t.nBitLength;return g>0?L>>BigInt(g):L},C=t.bits2int_modN||function(v){return i(_(v))},B=ir(t.nBitLength);function P(v){return At("num < 2^"+t.nBitLength,v,Xt,B),ae(v,t.nByteLength)}function T(v,L,g=Y){if(["recovered","canonical"].some(at=>at in g))throw new Error("sign() legacy options not supported");let{hash:p,randomBytes:x}=t,{lowS:A,prehash:k,extraEntropy:R}=g;A==null&&(A=!0),v=J("msgHash",v),ji(g),k&&(v=J("prehashed msgHash",p(v)));let N=C(v),M=f(L),D=[P(M),P(N)];if(R!=null&&R!==!1){let at=R===!0?x(e.BYTES):R;D.push(J("extraEntropy",at))}let F=Yt(...D),Z=N;function it(at){let ut=_(at);if(!l(ut))return;let lt=a(ut),Et=c.BASE.multiply(ut).toAffine(),pt=i(Et.x);if(pt===Xt)return;let Nt=i(lt*i(Z+pt*M));if(Nt===Xt)return;let Ht=(Et.x===pt?0:2)|Number(Et.y&ct),Ze=Nt;return A&&m(Nt)&&(Ze=w(Nt),Ht^=1),new h(pt,Ze,Ht)}return{seed:F,k2sig:it}}let Y={lowS:t.lowS,prehash:!1},H={lowS:t.lowS,prehash:!1};function O(v,L,g=Y){let{seed:p,k2sig:x}=T(v,L,g),A=t;return ro(A.hash.outputLen,A.nByteLength,A.hmac)(p,x)}c.BASE._setWindowSize(8);function ot(v,L,g,p=H){let x=v;L=J("msgHash",L),g=J("publicKey",g);let{lowS:A,prehash:k,format:R}=p;if(ji(p),"strict"in p)throw new Error("options.strict was renamed to lowS");if(R!==void 0&&R!=="compact"&&R!=="der")throw new Error("format must be compact or der");let N=typeof x=="string"||se(x),M=!N&&!R&&typeof x=="object"&&x!==null&&typeof x.r=="bigint"&&typeof x.s=="bigint";if(!N&&!M)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let D,F;try{if(M&&(D=new h(x.r,x.s)),N){try{R!=="compact"&&(D=h.fromDER(x))}catch(Ht){if(!(Ht instanceof jt.Err))throw Ht}!D&&R!=="der"&&(D=h.fromCompact(x))}F=c.fromHex(g)}catch{return!1}if(!D||A&&D.hasHighS())return!1;k&&(L=t.hash(L));let{r:Z,s:it}=D,at=C(L),ut=a(it),lt=i(at*ut),Et=i(Z*ut),pt=c.BASE.multiplyAndAddUnsafe(F,lt,Et)?.toAffine();return pt?i(pt.x)===Z:!1}return{CURVE:t,getPublicKey:S,getSharedSecret:I,sign:O,verify:ot,ProjectivePoint:c,Signature:h,utils:E}}function of(r){return{hash:r,hmac:(t,...e)=>Wo(r,t,Yn(...e)),randomBytes:Ur}}function Ji(r,t){let e=n=>Qi({...r,...of(n)});return{...e(t),create:e}}var ra=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),ta=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),sf=BigInt(1),Zo=BigInt(2),ea=(r,t)=>(r+t/Zo)/t;function af(r){let t=ra,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%t,u=f*f*r%t,l=Q(u,e,t)*u%t,d=Q(l,e,t)*u%t,m=Q(d,Zo,t)*f%t,w=Q(m,o,t)*m%t,b=Q(w,s,t)*w%t,h=Q(b,a,t)*b%t,E=Q(h,c,t)*h%t,S=Q(E,a,t)*b%t,y=Q(S,e,t)*u%t,I=Q(y,i,t)*w%t,_=Q(I,n,t)*f%t,C=Q(_,Zo,t);if(!Yo.eql(Yo.sqr(C),r))throw new Error("Cannot find square root");return C}var Yo=ce(ra,void 0,void 0,{sqrt:af}),Be=Ji({a:BigInt(0),b:BigInt(7),Fp:Yo,n:ta,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=ta,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-sf*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),a=ea(s*r,t),c=ea(-n*r,t),f=G(r-a*e-c*o,t),u=G(-a*n-c*s,t),l=f>i,d=u>i;if(l&&(f=t-f),d&&(u=t-u),f>i||u>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:l,k1:f,k2neg:d,k2:u}}}},He),V0=BigInt(0);var F0=Be.ProjectivePoint;function na(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function oa(r,t,e){let n=tr.digest(e instanceof Uint8Array?e:e.subarray());if(na(n))return n.then(({digest:o})=>Be.verify(t,o,r)).catch(o=>{throw new fr(String(o))});try{return Be.verify(t,n.digest,r)}catch(o){throw new fr(String(o))}}var Jr=class{type="secp256k1";raw;_key;constructor(t){this._key=ia(t),this.raw=sa(this._key)}toMultihash(){return kt.digest(Pt(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:j(this.raw,t.raw)}verify(t,e){return oa(this._key,e,t)}};function jo(r){return new Jr(r)}function sa(r){return Be.ProjectivePoint.fromHex(r).toRawBytes(!0)}function ia(r){try{return Be.ProjectivePoint.fromHex(r),r}catch(t){throw new Pe(String(t))}}function tn(r,t){let{Type:e,Data:n}=qt.decode(r),o=n??new Uint8Array;switch(e){case rt.RSA:return Fo(o,t);case rt.Ed25519:return po(o);case rt.secp256k1:return jo(o);case rt.ECDSA:return Zn(o);default:throw new me}}function aa(r){let{Type:t,Data:e}=qt.decode(r.digest),n=e??new Uint8Array;switch(t){case rt.Ed25519:return po(n);case rt.secp256k1:return jo(n);case rt.ECDSA:return Zn(n);default:throw new me}}function Pt(r){return qt.encode({Type:rt[r.type],Data:r.raw})}var ca=Symbol.for("nodejs.util.inspect.custom"),cf=114,pr=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()})`}[Tr]=!0;toString(){return this.string==null&&(this.string=W.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return et.createV1(cf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return j(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return j(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[ca](){return`PeerId(${this.toString()})`}},mr=class extends pr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},yr=class extends pr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},gr=class extends pr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},uf=2336,br=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=kt.digest(z(this.url))}[ca](){return`PeerId(${this.url})`}[Tr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return et.createV1(uf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=U(t)),t.toString()===this.toString())}};var lf=114,ua=2336;function la(r){if(r.type==="Ed25519")return new yr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new gr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new mr({multihash:r.toCID().multihash,publicKey:r});throw new me}function Xo(r){if(df(r))return new mr({multihash:r});if(ff(r))try{let t=aa(r);if(t.type==="Ed25519")return new yr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new gr({multihash:r,publicKey:t})}catch{let e=U(r.digest);return new br(new URL(e))}throw new Pr("Supplied PeerID Multihash is invalid")}function en(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==lf&&r.code!==ua)throw new Lr("Supplied PeerID CID is invalid");if(r.code===ua){let t=U(r.multihash.digest);return new br(new URL(t))}return Xo(r.multihash)}function ff(r){return r.code===kt.code}function df(r){return r.code===tr.code}var wr;(function(r){let t;r.codec=()=>(t==null&&(t=wt((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:nt(0),payloadType:nt(0),payload:nt(0),signature:nt(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=>bt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(wr||(wr={}));var rn=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var Fe=class r{static createFromProtobuf=async t=>{let e=wr.decode(t),n=tn(e.publicKey);return new r({publicKey:n,payloadType:e.payloadType,payload:e.payload,signature:e.signature})};static seal=async(t,e)=>{if(e==null)throw new Error("Missing private key");let n=t.domain,o=t.codec,s=t.marshal(),i=fa(n,o,s),a=await e.sign(i.subarray());return new r({publicKey:e.publicKey,payloadType:o,payload:s,signature:a})};static openAndCertify=async(t,e)=>{let n=await r.createFromProtobuf(t);if(!await n.validate(e))throw new rn("Envelope signature is not valid for the given domain");return n};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=wr.encode({publicKey:Pt(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return j(this.marshal(),t.marshal())}async validate(t){let e=fa(t,this.payloadType,this.payload);return this.publicKey.verify(e.subarray(),this.signature)}},fa=(r,t,e)=>{let n=z(r),o=Mt(n.byteLength),s=Mt(t.length),i=Mt(e.length);return new yt(o,n,s,t,i,e)};function da(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 nn=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",f=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let d=Number.parseInt(l,t);if(!Number.isNaN(d))return d});if(u===void 0)break;if(s*=t,s+=u,s>f||(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 ha=45,hf=15,ze=new nn;function Qo(r){if(!(r.length>hf))return ze.new(r).parseWith(()=>ze.readIPv4Addr())}function Jo(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>ha))return ze.new(r).parseWith(()=>ze.readIPv6Addr())}function on(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>ha)return;let e=ze.new(r).parseWith(()=>ze.readIPAddr());if(e)return t&&e.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,e[0],e[1],e[2],e[3]]):e}var my=parseInt("0xFFFF",16),yy=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function ya(r){return!!Qo(r)}function ga(r){return!!Jo(r)}function sn(r){return!!on(r)}var ba=ya,bf=ga,ts=function(r){let t=0;if(r=r.toString().trim(),ba(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(bf(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=ba(e[n]),i;s&&(i=ts(e[n]),e[n]=U(i.slice(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,U(i.slice(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let 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++){let s=parseInt(e[n],16);o[t++]=s>>8&255,o[t++]=s&255}return o}throw new Error("invalid ip address")},wa=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let o=[];for(let s=0;s<e;s++)o.push(r[t+s]);return o.join(".")}if(e===16){let o=[];for(let s=0;s<e;s+=2)o.push(n.getUint16(t+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var Ge={},es={},xf=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];xf.forEach(r=>{let t=Ef(...r);es[t.code]=t,Ge[t.name]=t});function Ef(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function $(r){if(typeof r=="number"){if(es[r]!=null)return es[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Ge[r]!=null)return Ge[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Jy=$("ip4"),tg=$("ip6"),eg=$("ipcidr");function ss(r,t){switch($(r).code){case 4:case 41:return Sf(t);case 42:return os(t);case 43:return U(t,"base10");case 6:case 273:case 33:case 132:return va(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return os(t);case 421:return Tf(t);case 444:return Ea(t);case 445:return Ea(t);case 466:return Bf(t);case 481:return globalThis.encodeURIComponent(os(t));default:return U(t,"base16")}}function is(r,t){switch($(r).code){case 4:return xa(t);case 41:return xa(t);case 42:return ns(t);case 43:return z(t,"base10");case 6:case 273:case 33:case 132:return as(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return ns(t);case 421:return Af(t);case 444:return Lf(t);case 445:return Pf(t);case 466:return If(t);case 481:return ns(globalThis.decodeURIComponent(t));default:return z(t,"base16")}}var rs=Object.values(er).map(r=>r.decoder),vf=function(){let r=rs[0].or(rs[1]);return rs.slice(2).forEach(t=>r=r.or(t)),r}();function xa(r){if(!sn(r))throw new Error("invalid ip address");return ts(r)}function Sf(r){let t=wa(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!sn(t))throw new Error("invalid ip address");return t}function as(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function va(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function ns(r){let t=z(r),e=Uint8Array.from(Mt(t.length));return Tt([e,t],e.length+t.length)}function os(r){let t=ve(r);if(r=r.slice(Bt(t)),r.length!==t)throw new Error("inconsistent lengths");return U(r)}function Af(r){let t;r[0]==="Q"||r[0]==="1"?t=Ft(W.decode(`z${r}`)).bytes:t=et.parse(r).multihash.bytes;let e=Uint8Array.from(Mt(t.length));return Tt([e,t],e.length+t.length)}function If(r){let t=vf.decode(r),e=Uint8Array.from(Mt(t.length));return Tt([e,t],e.length+t.length)}function Bf(r){let t=ve(r),e=r.slice(Bt(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+U(e,"base64url")}function Tf(r){let t=ve(r),e=r.slice(Bt(t));if(e.length!==t)throw new Error("inconsistent lengths");return U(e,"base58btc")}function Lf(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=Ct.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=as(n);return Tt([e,o],e.length+o.length)}function Pf(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=Ct.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=as(n);return Tt([e,o],e.length+o.length)}function Ea(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=U(t,"base32"),o=va(e);return`${n}:${o}`}function Sa(r){r=cs(r);let t=[],e=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let s=0;s<o.length;s++){let i=o[s],a=$(i);if(a.size===0){t.push([a.code]),e.push([a.code]);continue}if(s++,s>=o.length)throw new an("invalid address: "+r);if(a.path===!0){n=cs(o.slice(s).join("/")),t.push([a.code,is(a.code,n)]),e.push([a.code,n]);break}let c=is(a.code,o[s]);t.push([a.code,c]),e.push([a.code,ss(a.code,c)])}return{string:Aa(e),bytes:cn(t),tuples:t,stringTuples:e,path:n}}function us(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let s=ve(r,o),i=Bt(s),a=$(s),c=Cf(a,r.slice(o+i));if(c===0){t.push([s]),e.push([s]),o+=i;continue}let f=r.slice(o+i,o+i+c);if(o+=c+i,o>r.length)throw new an("Invalid address Uint8Array: "+U(r,"base16"));t.push([s,f]);let u=ss(s,f);if(e.push([s,u]),a.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:Aa(e),tuples:t,stringTuples:e,path:n}}function Aa(r){let t=[];return r.map(e=>{let n=$(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),cs(t.join("/"))}function cn(r){return Tt(r.map(t=>{let e=$(t[0]),n=Uint8Array.from(Mt(e.code));return t.length>1&&t[1]!=null&&(n=Tt([n,t[1]])),n}))}function Cf(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=ve(t instanceof Uint8Array?t:Uint8Array.from(t));return e+Bt(e)}}function cs(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}var an=class extends Error{static name="ParseError";name="ParseError";constructor(t){super(`Error parsing address: ${t}`)}};var _f=Symbol.for("nodejs.util.inspect.custom"),fs=Symbol.for("@multiformats/js-multiaddr/multiaddr"),kf=[$("dns").code,$("dns4").code,$("dns6").code,$("dnsaddr").code],ls=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},un=class r{bytes;#t;#e;#r;#a;[fs]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=us(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Sa(t)}else if(ln(t))e=us(t.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=e.bytes,this.#t=e.string,this.#e=e.tuples,this.#r=e.stringTuples,this.#a=e.path}toString(){return this.#t}toJSON(){return this.toString()}toOptions(){let t,e,n,o,s="",i=$("tcp"),a=$("udp"),c=$("ip4"),f=$("ip6"),u=$("dns6"),l=$("ip6zone");for(let[m,w]of this.stringTuples())m===l.code&&(s=`%${w??""}`),kf.includes(m)&&(e=i.name==="tcp"?"tcp":"udp",o=443,n=`${w??""}${s}`,t=m===u.code?6:4),(m===i.code||m===a.code)&&(e=$(m).name==="tcp"?"tcp":"udp",o=parseInt(w??"")),(m===c.code||m===f.code)&&(e=$(m).name==="tcp"?"tcp":"udp",n=`${w??""}${s}`,t=m===f.code?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}}protos(){return this.#e.map(([t])=>Object.assign({},$(t)))}protoCodes(){return this.#e.map(([t])=>t)}protoNames(){return this.#e.map(([t])=>$(t).name)}tuples(){return this.#e.map(([t,e])=>e==null?[t]:[t,e])}stringTuples(){return this.#r.map(([t,e])=>e==null?[t]:[t,e])}encapsulate(t){return t=new r(t),new r(this.toString()+t.toString())}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o))}decapsulateCode(t){let e=this.tuples();for(let n=e.length-1;n>=0;n--)if(e[n][0]===t)return new r(cn(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===Ge.p2p.code&&t.push([n,o]),n===Ge["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?U(W.decode(`z${n}`),"base58btc"):U(et.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#a}equals(t){return j(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(s=>s.resolvable);if(e==null)return[this];let n=Ia.get(e.name);if(n==null)throw new ls(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>Qt(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(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[_f](){return`Multiaddr(${this.#t})`}};var Ia=new Map;function ln(r){return!!r?.[fs]}function Qt(r){return new un(r)}var Ba="libp2p-peer-record",Ta=Uint8Array.from([3,1]);var xr;(function(r){let t;(function(n){let o;n.codec=()=>(o==null&&(o=wt((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:nt(0)},f=i==null?s.len:s.pos+i;for(;s.pos<f;){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=>bt(s,n.codec()),n.decode=(s,i)=>gt(s,n.codec(),i)})(t=r.AddressInfo||(r.AddressInfo={}));let e;r.codec=()=>(e==null&&(e=wt((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:nt(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 Ie('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=>bt(n,r.codec()),r.decode=(n,o)=>gt(n,r.codec(),o)})(xr||(xr={}));var Te=class r{static createFromProtobuf=t=>{let e=xr.decode(t),n=Xo(Ft(e.peerId)),o=(e.addresses??[]).map(i=>Qt(i.multiaddr)),s=e.seq;return new r({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Ba;static CODEC=Ta;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=xr.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||!da(this.multiaddrs,t.multiaddrs))}};function Rf(r){return r[Symbol.asyncIterator]!=null}function Df(r){if(Rf(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 La=Df;var hs=ac(Ca(),1);var vr=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},ps=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},_a=r=>globalThis.DOMException===void 0?new ps(r):new DOMException(r),ka=r=>{let t=r.reason===void 0?_a("This operation was aborted."):r.reason;return t instanceof Error?t:_a(t)};function Sr(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,a,f=new Promise((u,l)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(t.signal){let{signal:m}=t;m.aborted&&l(ka(m)),a=()=>{l(ka(m))},m.addEventListener("abort",a,{once:!0})}if(e===Number.POSITIVE_INFINITY){r.then(u,l);return}let d=new vr;i=s.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(m){l(m)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?u():o instanceof Error?l(o):(d.message=o??`Promise timed out after ${e} milliseconds`,l(d))},e),(async()=>{try{u(await r)}catch(m){l(m)}})()}).finally(()=>{f.clear(),a&&t.signal&&t.signal.removeEventListener("abort",a)});return f.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},f}function ms(r,t,e){let n=0,o=r.length;for(;o>0;){let s=Math.trunc(o/2),i=n+s;e(r[i],t)<=0?(n=++i,o-=s+1):o=s}return n}var Ar=class{#t=[];enqueue(t,e){e={priority:0,...e};let n={priority:e.priority,id:e.id,run:t};if(this.size===0||this.#t[this.size-1].priority>=e.priority){this.#t.push(n);return}let o=ms(this.#t,n,(s,i)=>i.priority-s.priority);this.#t.splice(o,0,n)}setPriority(t,e){let n=this.#t.findIndex(s=>s.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[o]=this.#t.splice(n,1);this.enqueue(o.run,{priority:e,id:t})}dequeue(){return this.#t.shift()?.run}filter(t){return this.#t.filter(e=>e.priority===t.priority).map(e=>e.run)}get size(){return this.#t.length}};var We=class extends hs.default{#t;#e;#r=0;#a;#c;#p=0;#o;#u;#n;#m;#s=0;#l;#i;#y;#w=1n;timeout;constructor(t){if(super(),t={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Ar,...t},!(typeof t.intervalCap=="number"&&t.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${t.intervalCap?.toString()??""}\` (${typeof t.intervalCap})`);if(t.interval===void 0||!(Number.isFinite(t.interval)&&t.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${t.interval?.toString()??""}\` (${typeof t.interval})`);this.#t=t.carryoverConcurrencyCount,this.#e=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#a=t.intervalCap,this.#c=t.interval,this.#n=new t.queueClass,this.#m=t.queueClass,this.concurrency=t.concurrency,this.timeout=t.timeout,this.#y=t.throwOnTimeout===!0,this.#i=t.autoStart===!1}get#x(){return this.#e||this.#r<this.#a}get#E(){return this.#s<this.#l}#v(){this.#s--,this.#f(),this.emit("next")}#S(){this.#b(),this.#g(),this.#u=void 0}get#A(){let t=Date.now();if(this.#o===void 0){let e=this.#p-t;if(e<0)this.#r=this.#t?this.#s:0;else return this.#u===void 0&&(this.#u=setTimeout(()=>{this.#S()},e)),!0}return!1}#f(){if(this.#n.size===0)return this.#o&&clearInterval(this.#o),this.#o=void 0,this.emit("empty"),this.#s===0&&this.emit("idle"),!1;if(!this.#i){let t=!this.#A;if(this.#x&&this.#E){let e=this.#n.dequeue();return e?(this.emit("active"),e(),t&&this.#g(),!0):!1}}return!1}#g(){this.#e||this.#o!==void 0||(this.#o=setInterval(()=>{this.#b()},this.#c),this.#p=Date.now()+this.#c)}#b(){this.#r===0&&this.#s===0&&this.#o&&(clearInterval(this.#o),this.#o=void 0),this.#r=this.#t?this.#s:0,this.#d()}#d(){for(;this.#f(););}get concurrency(){return this.#l}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this.#l=t,this.#d()}async#I(t){return new Promise((e,n)=>{t.addEventListener("abort",()=>{n(t.reason)},{once:!0})})}setPriority(t,e){this.#n.setPriority(t,e)}async add(t,e={}){return e.id??=(this.#w++).toString(),e={timeout:this.timeout,throwOnTimeout:this.#y,...e},new Promise((n,o)=>{this.#n.enqueue(async()=>{this.#s++,this.#r++;try{e.signal?.throwIfAborted();let s=t({signal:e.signal});e.timeout&&(s=Sr(Promise.resolve(s),{milliseconds:e.timeout})),e.signal&&(s=Promise.race([s,this.#I(e.signal)]));let i=await s;n(i),this.emit("completed",i)}catch(s){if(s instanceof vr&&!e.throwOnTimeout){n();return}o(s),this.emit("error",s)}finally{this.#v()}},e),this.emit("add"),this.#f()})}async addAll(t,e){return Promise.all(t.map(async n=>this.add(n,e)))}start(){return this.#i?(this.#i=!1,this.#d(),this):this}pause(){this.#i=!0}clear(){this.#n=new this.#m}async onEmpty(){this.#n.size!==0&&await this.#h("empty")}async onSizeLessThan(t){this.#n.size<t||await this.#h("next",()=>this.#n.size<t)}async onIdle(){this.#s===0&&this.#n.size===0||await this.#h("idle")}async#h(t,e){return new Promise(n=>{let o=()=>{e&&!e()||(this.off(t,o),n())};this.on(t,o)})}get size(){return this.#n.size}sizeBy(t){return this.#n.filter(t).length}get pending(){return this.#s}get isPaused(){return this.#i}};var he={},$e=r=>{r.addEventListener("message",t=>{$e.dispatchEvent("message",r,t)}),r.port!=null&&r.port.addEventListener("message",t=>{$e.dispatchEvent("message",r,t)})};$e.addEventListener=(r,t)=>{he[r]==null&&(he[r]=[]),he[r].push(t)};$e.removeEventListener=(r,t)=>{he[r]!=null&&(he[r]=he[r].filter(e=>e===t))};$e.dispatchEvent=function(r,t,e){he[r]!=null&&he[r].forEach(n=>n(t,e))};var ys=$e;var gs="lock:worker:request-read",bs="lock:worker:release-read",ws="lock:master:grant-read",xs="lock:worker:request-write",Es="lock:worker:release-write",vs="lock:master:grant-write";var Ra=(r=21)=>Math.random().toString().substring(2);var Da=(r,t,e,n,o)=>(s,i)=>{if(i.data.type!==e)return;let a={type:i.data.type,name:i.data.name,identifier:i.data.identifier};r.dispatchEvent(new MessageEvent(t,{data:{name:a.name,handler:async()=>{s.postMessage({type:o,name:a.name,identifier:a.identifier}),await new Promise(c=>{let f=u=>{if(u?.data==null)return;let l={type:u.data.type,name:u.data.name,identifier:u.data.identifier};l.type===n&&l.identifier===a.identifier&&(s.removeEventListener("message",f),c())};s.addEventListener("message",f)})}}}))},Ka=(r,t,e,n)=>async()=>{let o=Ra();return globalThis.postMessage({type:t,identifier:o,name:r}),new Promise(s=>{let i=a=>{if(a?.data==null)return;let c={type:a.data.type,identifier:a.data.identifier};c.type===e&&c.identifier===o&&(globalThis.removeEventListener("message",i),s(()=>{globalThis.postMessage({type:n,identifier:o,name:r})}))};globalThis.addEventListener("message",i)})},Nf={singleProcess:!1},Ua=r=>{if(r=Object.assign({},Nf,r),!!globalThis.document||r.singleProcess){let e=new EventTarget;return ys.addEventListener("message",Da(e,"requestReadLock",gs,bs,ws)),ys.addEventListener("message",Da(e,"requestWriteLock",xs,Es,vs)),e}return{isWorker:!0,readLock:e=>Ka(e,gs,ws,bs),writeLock:e=>Ka(e,xs,vs,Es)}};var Le={},pe;async function Ss(r,t){let e,n=new Promise(o=>{e=o});return r.add(async()=>Sr((async()=>{await new Promise(o=>{e(()=>{o()})})})(),{milliseconds:t.timeout})),n}var Of=(r,t)=>{if(pe.isWorker===!0)return{readLock:pe.readLock(r,t),writeLock:pe.writeLock(r,t)};let e=new We({concurrency:1}),n;return{async readLock(){if(n!=null)return Ss(n,t);n=new We({concurrency:t.concurrency,autoStart:!1});let o=n,s=Ss(n,t);return e.add(async()=>{o.start(),await o.onIdle().then(()=>{n===o&&(n=null)})}),s},async writeLock(){return n=null,Ss(e,t)}}},Mf={name:"lock",concurrency:1/0,timeout:846e5,singleProcess:!1};function As(r){let t=Object.assign({},Mf,r);return pe==null&&(pe=Ua(t),pe.isWorker!==!0&&(pe.addEventListener("requestReadLock",e=>{Le[e.data.name]!=null&&Le[e.data.name].readLock().then(async n=>e.data.handler().finally(()=>{n()}))}),pe.addEventListener("requestWriteLock",async e=>{Le[e.data.name]!=null&&Le[e.data.name].writeLock().then(async n=>e.data.handler().finally(()=>{n()}))}))),Le[t.name]==null&&(Le[t.name]=Of(t.name,t)),Le[t.name]}var Jt;(function(r){let t;(function(o){let s;o.codec=()=>(s==null&&(s=wt((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 f={key:"",value:nt(0)},u=a==null?i.len:i.pos+a;for(;i.pos<u;){let l=i.uint32();switch(l>>>3){case 1:{f.key=i.string();break}case 2:{f.value=i.bytes();break}default:{i.skipType(l&7);break}}}return f})),s),o.encode=i=>bt(i,o.codec()),o.decode=(i,a)=>gt(i,o.codec(),a)})(t=r.Peer$metadataEntry||(r.Peer$metadataEntry={}));let e;(function(o){let s;o.codec=()=>(s==null&&(s=wt((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),hn.codec().encode(i.value,a)),c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let f={key:""},u=a==null?i.len:i.pos+a;for(;i.pos<u;){let l=i.uint32();switch(l>>>3){case 1:{f.key=i.string();break}case 2:{f.value=hn.codec().decode(i,i.uint32(),{limits:c.limits?.value});break}default:{i.skipType(l&7);break}}}return f})),s),o.encode=i=>bt(i,o.codec()),o.decode=(i,a)=>gt(i,o.codec(),a)})(e=r.Peer$tagsEntry||(r.Peer$tagsEntry={}));let n;r.codec=()=>(n==null&&(n=wt((o,s,i={})=>{if(i.lengthDelimited!==!1&&s.fork(),o.addresses!=null)for(let a of o.addresses)s.uint32(10),dn.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 f=o.uint32();switch(f>>>3){case 1:{if(i.limits?.addresses!=null&&a.addresses.length===i.limits.addresses)throw new Ie('Decode error - map field "addresses" had too many elements');a.addresses.push(dn.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 Ie('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 lr('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 lr('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(f&7);break}}}return a})),n),r.encode=o=>bt(o,r.codec()),r.decode=(o,s)=>gt(o,r.codec(),s)})(Jt||(Jt={}));var dn;(function(r){let t;r.codec=()=>(t==null&&(t=wt((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:nt(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=>bt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(dn||(dn={}));var hn;(function(r){let t;r.codec=()=>(t==null&&(t=wt((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=>bt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(hn||(hn={}));function qf(r,t){if(r.publicKey!=null||t.publicKey==null)return r;let e;if(r.type==="RSA"){let o=W.decode(`z${r}`);e=Ft(o)}let n=tn(t.publicKey,e);return la(n)}function pn(r,t,e){let n=Jt.decode(t);return mn(r,n,e)}function mn(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:qf(r,t),addresses:t.addresses.filter(({observed:s})=>s!=null&&s>Date.now()-e).map(({multiaddr:s,isCertified:i})=>({multiaddr:Qt(s),isCertified:i??!1})),metadata:t.metadata,peerRecordEnvelope:t.peerRecordEnvelope??void 0,tags:n}}function Na(r,t){return Hf(r.addresses,t.addresses)&&Vf(r.protocols,t.protocols)&&Ff(r.publicKey,t.publicKey)&&zf(r.peerRecordEnvelope,t.peerRecordEnvelope)&&Gf(r.metadata,t.metadata)&&Wf(r.tags,t.tags)}function Hf(r,t){return Ma(r,t,(e,n)=>!(e.isCertified!==n.isCertified||!j(e.multiaddr,n.multiaddr)))}function Vf(r,t){return Ma(r,t,(e,n)=>e===n)}function Ff(r,t){return Oa(r,t)}function zf(r,t){return Oa(r,t)}function Gf(r,t){return qa(r,t,(e,n)=>j(e,n))}function Wf(r,t){return qa(r,t,(e,n)=>e.value===n.value&&e.expiry===n.expiry)}function Oa(r,t){return r==null&&t==null?!0:r!=null&&t!=null?j(r,t):!1}function Ma(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 qa(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 te="/",Ha=new TextEncoder().encode(te),yn=Ha[0],gn=class r{_buf;constructor(t,e){if(typeof t=="string")this._buf=z(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]!==yn)throw new Error("Invalid key")}toString(t="utf8"){return U(this._buf,t)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(t){return new r(t.join(te))}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=Ha),this._buf[0]!==yn){let t=new Uint8Array(this._buf.byteLength+1);t.fill(yn,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===yn;)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(te).slice(1)}type(){return $f(this.baseNamespace())}name(){return Zf(this.baseNamespace())}instance(t){return new r(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(te)||(t+=te),t+=this.type(),new r(t)}parent(){let t=this.list();return t.length===1?new r(te):new r(t.slice(0,-1).join(te))}child(t){return this.toString()===te?t:t.toString()===te?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(),...Yf(t.map(e=>e.namespaces()))])}};function $f(r){let t=r.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function Zf(r){let t=r.split(":");return t[t.length-1]}function Yf(r){return[].concat(...r)}var Is="/peers/";function Ir(r){if(!Us(r)||r.type==null)throw new q("Invalid PeerId");let t=r.toCID().toString();return new gn(`${Is}${t}`)}async function Va(r,t,e,n){let o=new Map;for(let s of e){if(s==null)continue;if(s.multiaddr instanceof Uint8Array&&(s.multiaddr=Qt(s.multiaddr)),!ln(s.multiaddr))throw new q("Multiaddr was invalid");if(!await t(r,s.multiaddr))continue;let i=s.isCertified??!1,a=s.multiaddr.toString(),c=o.get(a);c!=null?s.isCertified=c.isCertified||i:o.set(a,{multiaddr:s.multiaddr,isCertified:i})}return[...o.values()].sort((s,i)=>s.multiaddr.toString().localeCompare(i.multiaddr.toString())).map(({isCertified:s,multiaddr:i})=>({isCertified:s,multiaddr:i.bytes}))}async function wn(r,t,e,n){if(t==null)throw new q("Invalid PeerData");if(t.publicKey!=null&&r.publicKey!=null&&!t.publicKey.equals(r.publicKey))throw new q("publicKey bytes do not match peer id publicKey bytes");let o=n.existingPeer?.peer;if(o!=null&&!r.equals(o.id))throw new q("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,f=o?.peerRecordEnvelope;if(e==="patch"){if((t.multiaddrs!=null||t.addresses!=null)&&(s=[],t.multiaddrs!=null&&s.push(...t.multiaddrs.map(d=>({isCertified:!1,multiaddr:d}))),t.addresses!=null&&s.push(...t.addresses)),t.protocols!=null&&(i=new Set(t.protocols)),t.metadata!=null){let d=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);a=bn(d,{validate:Fa})}if(t.tags!=null){let d=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags);c=bn(d,{validate:za,map:Ga})}t.peerRecordEnvelope!=null&&(f=t.peerRecordEnvelope)}if(e==="merge"){if(t.multiaddrs!=null&&s.push(...t.multiaddrs.map(d=>({isCertified:!1,multiaddr:d}))),t.addresses!=null&&s.push(...t.addresses),t.protocols!=null&&(i=new Set([...i,...t.protocols])),t.metadata!=null){let d=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);for(let[m,w]of d)w==null?a.delete(m):a.set(m,w);a=bn([...a.entries()],{validate:Fa})}if(t.tags!=null){let d=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags),m=new Map(c);for(let[w,b]of d)b==null?m.delete(w):m.set(w,b);c=bn([...m.entries()],{validate:za,map:Ga})}t.peerRecordEnvelope!=null&&(f=t.peerRecordEnvelope)}let u;o?.id.publicKey!=null?u=Pt(o.id.publicKey):t.publicKey!=null?u=Pt(t.publicKey):r.publicKey!=null&&(u=Pt(r.publicKey));let l={addresses:await Va(r,n.addressFilter??(async()=>!0),s,n.existingPeer?.peerPB.addresses),protocols:[...i.values()].sort((d,m)=>d.localeCompare(m)),metadata:a,tags:c,publicKey:u,peerRecordEnvelope:f};return l.addresses.forEach(d=>{d.observed=n.existingPeer?.peerPB.addresses?.find(m=>j(m.multiaddr,m.multiaddr))?.observed??Date.now()}),r.type!=="RSA"&&delete l.publicKey,l}function bn(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 Fa(r,t){if(typeof r!="string")throw new q("Metadata key must be a string");if(!(t instanceof Uint8Array))throw new q("Metadata value must be a Uint8Array")}function za(r,t){if(typeof r!="string")throw new q("Tag name must be a string");if(t.value!=null){if(parseInt(`${t.value}`,10)!==t.value)throw new q("Tag value must be an integer");if(t.value<0||t.value>100)throw new q("Tag value must be between 0-100")}if(t.ttl!=null){if(parseInt(`${t.ttl}`,10)!==t.ttl)throw new q("Tag ttl must be an integer");if(t.ttl<0)throw new q("Tag ttl must be between greater than 0")}}function Ga(r,t){let e;return t.expiry!=null&&(e=t.expiry),t.ttl!=null&&(e=BigInt(Date.now()+Number(t.ttl))),{value:t.value??0,expiry:e}}function Wa(r){let t=r.toString().split("/")[2],e=et.parse(t,Ct);return en(e)}function Bs(r,t,e){let n=Wa(r);return pn(n,t,e)}function jf(r,t){return{prefix:Is,filters:(r.filters??[]).map(e=>({key:n,value:o})=>e(Bs(n,o,t))),orders:(r.orders??[]).map(e=>(n,o)=>e(Bs(n.key,n.value,t),Bs(o.key,o.value,t)))}}var xn=class{peerId;datastore;lock;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.lock=As({name:"peer-store",singleProcess:!0}),this.maxAddressAge=e.maxAddressAge??36e5,this.maxPeerAge=e.maxPeerAge??216e5}async has(t){try{return await this.load(t),!0}catch(e){if(e.name!=="NotFoundError")throw e}return!1}async delete(t){this.peerId.equals(t)||await this.datastore.delete(Ir(t))}async load(t){let e=Ir(t),n=await this.datastore.get(e),o=Jt.decode(n);if(this.#r(t,o))throw await this.datastore.delete(e),new Ye;return mn(t,o,this.peerId.equals(t)?1/0:this.maxAddressAge)}async save(t,e){let n=await this.#t(t),o=await wn(t,e,"patch",{addressFilter:this.addressFilter});return this.#e(t,o,n)}async patch(t,e){let n=await this.#t(t),o=await wn(t,e,"patch",{addressFilter:this.addressFilter,existingPeer:n});return this.#e(t,o,n)}async merge(t,e){let n=await this.#t(t),o=await wn(t,e,"merge",{addressFilter:this.addressFilter,existingPeer:n});return this.#e(t,o,n)}async*all(t){for await(let{key:e,value:n}of this.datastore.query(jf(t??{},this.maxAddressAge))){let o=Wa(e);if(o.equals(this.peerId))continue;let s=Jt.decode(n);if(this.#r(o,s)){await this.datastore.delete(e);continue}yield mn(o,s,this.peerId.equals(o)?1/0:this.maxAddressAge)}}async#t(t){try{let e=Ir(t),n=await this.datastore.get(e),o=Jt.decode(n);if(this.#r(t,o))throw await this.datastore.delete(e),new Ye;return{peerPB:o,peer:pn(t,n,this.maxAddressAge)}}catch(e){e.name!=="NotFoundError"&&this.log.error("invalid peer data found in peer store - %e",e)}}async#e(t,e,n){e.updated=Date.now();let o=Jt.encode(e);return await this.datastore.put(Ir(t),o),{peer:pn(t,o,this.maxAddressAge),previous:n?.peer,updated:n==null||!Na(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 Ts=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 xn(t,e)}[Symbol.toStringTag]="@libp2p/peer-store";async forEach(t,e){this.log.trace("forEach await read lock");let n=await this.store.lock.readLock();this.log.trace("forEach got read lock");try{for await(let o of this.store.all(e))t(o)}finally{this.log.trace("forEach release read lock"),n()}}async all(t){this.log.trace("all await read lock");let e=await this.store.lock.readLock();this.log.trace("all got read lock");try{return await La(this.store.all(t))}finally{this.log.trace("all release read lock"),e()}}async delete(t){this.log.trace("delete await write lock");let e=await this.store.lock.writeLock();this.log.trace("delete got write lock");try{await this.store.delete(t)}finally{this.log.trace("delete release write lock"),e()}}async has(t){this.log.trace("has await read lock");let e=await this.store.lock.readLock();this.log.trace("has got read lock");try{return await this.store.has(t)}finally{this.log.trace("has release read lock"),e()}}async get(t){this.log.trace("get await read lock");let e=await this.store.lock.readLock();this.log.trace("get got read lock");try{return await this.store.load(t)}finally{this.log.trace("get release read lock"),e()}}async save(t,e){this.log.trace("save await write lock");let n=await this.store.lock.writeLock();this.log.trace("save got write lock");try{let o=await this.store.save(t,e);return this.#t(t,o),o.peer}finally{this.log.trace("save release write lock"),n()}}async patch(t,e){this.log.trace("patch await write lock");let n=await this.store.lock.writeLock();this.log.trace("patch got write lock");try{let o=await this.store.patch(t,e);return this.#t(t,o),o.peer}finally{this.log.trace("patch release write lock"),n()}}async merge(t,e){this.log.trace("merge await write lock");let n=await this.store.lock.writeLock();this.log.trace("merge got write lock");try{let o=await this.store.merge(t,e);return this.#t(t,o),o.peer}finally{this.log.trace("merge release write lock"),n()}}async consumePeerRecord(t,e){let n=await Fe.openAndCertify(t,Te.DOMAIN),o=en(n.publicKey.toCID());if(e?.equals(o)===!1)return this.log("envelope peer id was not the expected peer id - expected: %p received: %p",e,o),!1;let s=Te.createFromProtobuf(n.payload),i;try{i=await this.get(o)}catch(a){if(a.name!=="NotFoundError")throw a}if(i?.peerRecordEnvelope!=null){let a=await Fe.createFromProtobuf(i.peerRecordEnvelope),c=Te.createFromProtobuf(a.payload);if(c.seqNumber>=s.seqNumber)return this.log("sequence number was lower or equal to existing sequence number - stored: %d received: %d",c.seqNumber,s.seqNumber),!1}return await this.patch(s.peerId,{peerRecordEnvelope:t,addresses:s.multiaddrs.map(a=>({isCertified:!0,multiaddr:a}))}),!0}#t(t,e){e.updated&&(this.peerId.equals(t)?this.events.safeDispatchEvent("self:peer:update",{detail:e}):this.events.safeDispatchEvent("peer:update",{detail:e}))}};function Xf(r,t={}){return new Ts(r,t)}return cc(Qf);})();
2
+ "use strict";var Libp2PPeerStore=(()=>{var Wa=Object.create;var Ar=Object.defineProperty;var $a=Object.getOwnPropertyDescriptor;var Za=Object.getOwnPropertyNames;var Ya=Object.getPrototypeOf,ja=Object.prototype.hasOwnProperty;var Xa=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),vt=(r,t)=>{for(var e in t)Ar(r,e,{get:t[e],enumerable:!0})},Ai=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Za(t))!ja.call(r,o)&&o!==e&&Ar(r,o,{get:()=>t[o],enumerable:!(n=$a(t,o))||n.enumerable});return r};var Qa=(r,t,e)=>(e=r!=null?Wa(Ya(r)):{},Ai(t||!r||!r.__esModule?Ar(e,"default",{value:r,enumerable:!0}):e,r)),Ja=r=>Ai(Ar({},"__esModule",{value:!0}),r);var Ia=Xa((Cg,ai)=>{"use strict";var yf=Object.prototype.hasOwnProperty,xt="~";function wr(){}Object.create&&(wr.prototype=Object.create(null),new wr().__proto__||(xt=!1));function gf(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function Aa(r,t,e,n,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var i=new gf(e,n||r,o),s=xt?xt+t:t;return r._events[s]?r._events[s].fn?r._events[s]=[r._events[s],i]:r._events[s].push(i):(r._events[s]=i,r._eventsCount++),r}function on(r,t){--r._eventsCount===0?r._events=new wr:delete r._events[t]}function pt(){this._events=new wr,this._eventsCount=0}pt.prototype.eventNames=function(){var t=[],e,n;if(this._eventsCount===0)return t;for(n in e=this._events)yf.call(e,n)&&t.push(xt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};pt.prototype.listeners=function(t){var e=xt?xt+t:t,n=this._events[e];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,i=n.length,s=new Array(i);o<i;o++)s[o]=n[o].fn;return s};pt.prototype.listenerCount=function(t){var e=xt?xt+t:t,n=this._events[e];return n?n.fn?1:n.length:0};pt.prototype.emit=function(t,e,n,o,i,s){var a=xt?xt+t:t;if(!this._events[a])return!1;var c=this._events[a],f=arguments.length,u,l;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),f){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,e),!0;case 3:return c.fn.call(c.context,e,n),!0;case 4:return c.fn.call(c.context,e,n,o),!0;case 5:return c.fn.call(c.context,e,n,o,i),!0;case 6:return c.fn.call(c.context,e,n,o,i,s),!0}for(l=1,u=new Array(f-1);l<f;l++)u[l-1]=arguments[l];c.fn.apply(c.context,u)}else{var d=c.length,y;for(l=0;l<d;l++)switch(c[l].once&&this.removeListener(t,c[l].fn,void 0,!0),f){case 1:c[l].fn.call(c[l].context);break;case 2:c[l].fn.call(c[l].context,e);break;case 3:c[l].fn.call(c[l].context,e,n);break;case 4:c[l].fn.call(c[l].context,e,n,o);break;default:if(!u)for(y=1,u=new Array(f-1);y<f;y++)u[y-1]=arguments[y];c[l].fn.apply(c[l].context,u)}}return!0};pt.prototype.on=function(t,e,n){return Aa(this,t,e,n,!1)};pt.prototype.once=function(t,e,n){return Aa(this,t,e,n,!0)};pt.prototype.removeListener=function(t,e,n,o){var i=xt?xt+t:t;if(!this._events[i])return this;if(!e)return on(this,i),this;var s=this._events[i];if(s.fn)s.fn===e&&(!o||s.once)&&(!n||s.context===n)&&on(this,i);else{for(var a=0,c=[],f=s.length;a<f;a++)(s[a].fn!==e||o&&!s[a].once||n&&s[a].context!==n)&&c.push(s[a]);c.length?this._events[i]=c.length===1?c[0]:c:on(this,i)}return this};pt.prototype.removeAllListeners=function(t){var e;return t?(e=xt?xt+t:t,this._events[e]&&on(this,e)):(this._events=new wr,this._eventsCount=0),this};pt.prototype.off=pt.prototype.removeListener;pt.prototype.addListener=pt.prototype.on;pt.prefixed=xt;pt.EventEmitter=pt;typeof ai<"u"&&(ai.exports=pt)});var Df={};vt(Df,{persistentPeerStore:()=>kf});var Ir=Symbol.for("@libp2p/peer-id");function Ii(r){return!!r?.[Ir]}var q=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Te=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var $e=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var Br=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},Tr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var de=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var wn={};vt(wn,{base58btc:()=>$,base58flickr:()=>ic});var Nf=new Uint8Array(0);function Bi(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 Ht(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 Ti(r){return new TextEncoder().encode(r)}function Pi(r){return new TextDecoder().decode(r)}function tc(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 i=r.charAt(o),s=i.charCodeAt(0);if(e[s]!==255)throw new TypeError(i+" is ambiguous");e[s]=o}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function l(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 g=0,h=0,x=0,A=w.length;x!==A&&w[x]===0;)x++,g++;for(var m=(A-x)*u+1>>>0,I=new Uint8Array(m);x!==A;){for(var k=w[x],C=0,T=m-1;(k!==0||C<h)&&T!==-1;T--,C++)k+=256*I[T]>>>0,I[T]=k%a>>>0,k=k/a>>>0;if(k!==0)throw new Error("Non-zero carry");h=C,x++}for(var P=m-h;P!==m&&I[P]===0;)P++;for(var L=c.repeat(g);P<m;++P)L+=r.charAt(I[P]);return L}function d(w){if(typeof w!="string")throw new TypeError("Expected String");if(w.length===0)return new Uint8Array;var g=0;if(w[g]!==" "){for(var h=0,x=0;w[g]===c;)h++,g++;for(var A=(w.length-g)*f+1>>>0,m=new Uint8Array(A);w[g];){var I=e[w.charCodeAt(g)];if(I===255)return;for(var k=0,C=A-1;(I!==0||k<x)&&C!==-1;C--,k++)I+=a*m[C]>>>0,m[C]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");x=k,g++}if(w[g]!==" "){for(var T=A-x;T!==A&&m[T]===0;)T++;for(var P=new Uint8Array(h+(A-T)),L=h;T!==A;)P[L++]=m[T++];return P}}}function y(w){var g=d(w);if(g)return g;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:d,decode:y}}var ec=tc,rc=ec,_i=rc;var mn=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")}},yn=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 Ci(this,t)}},gn=class{decoders;constructor(t){this.decoders=t}or(t){return Ci(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 Ci(r,t){return new gn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var bn=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 mn(t,e,n),this.decoder=new yn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Pe({name:r,prefix:t,encode:e,decode:n}){return new bn(r,t,e,n)}function Jt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=_i(e,r);return Pe({prefix:t,name:r,encode:n,decode:i=>Ht(o(i))})}function nc(r,t,e,n){let o={};for(let u=0;u<t.length;++u)o[t[u]]=u;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*e/8|0),a=0,c=0,f=0;for(let u=0;u<i;++u){let l=o[r[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|l,a+=e,a>=8&&(a-=8,s[f++]=255&c>>a)}if(a>=e||(255&c<<8-a)!==0)throw new SyntaxError("Unexpected end of data");return s}function oc(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,i="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>e;)s-=e,i+=t[o&a>>s];if(s!==0&&(i+=t[o&a<<e-s]),n)for(;(i.length*e&7)!==0;)i+="=";return i}function tt({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return Pe({prefix:t,name:r,encode(o){return oc(o,n,e)},decode(o){return nc(o,n,e,r)}})}var $=Jt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ic=Jt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var xn={};vt(xn,{base32:()=>kt,base32hex:()=>uc,base32hexpad:()=>fc,base32hexpadupper:()=>dc,base32hexupper:()=>lc,base32pad:()=>ac,base32padupper:()=>cc,base32upper:()=>sc,base32z:()=>hc});var kt=tt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),sc=tt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),ac=tt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),cc=tt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),uc=tt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),lc=tt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),fc=tt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),dc=tt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),hc=tt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var En={};vt(En,{base36:()=>Ze,base36upper:()=>pc});var Ze=Jt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),pc=Jt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var mc=Ki,ki=128,yc=127,gc=~yc,bc=Math.pow(2,31);function Ki(r,t,e){t=t||[],e=e||0;for(var n=e;r>=bc;)t[e++]=r&255|ki,r/=128;for(;r&gc;)t[e++]=r&255|ki,r>>>=7;return t[e]=r|0,Ki.bytes=e-n+1,t}var wc=vn,xc=128,Di=127;function vn(r,n){var e=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw vn.bytes=0,new RangeError("Could not decode varint");s=r[i++],e+=o<28?(s&Di)<<o:(s&Di)*Math.pow(2,o),o+=7}while(s>=xc);return vn.bytes=i-n,e}var Ec=Math.pow(2,7),vc=Math.pow(2,14),Sc=Math.pow(2,21),Ac=Math.pow(2,28),Ic=Math.pow(2,35),Bc=Math.pow(2,42),Tc=Math.pow(2,49),Pc=Math.pow(2,56),Lc=Math.pow(2,63),_c=function(r){return r<Ec?1:r<vc?2:r<Sc?3:r<Ac?4:r<Ic?5:r<Bc?6:r<Tc?7:r<Pc?8:r<Lc?9:10},Cc={encode:mc,decode:wc,encodingLength:_c},kc=Cc,Ye=kc;function je(r,t=0){return[Ye.decode(r,t),Ye.decode.bytes]}function Le(r,t,e=0){return Ye.encode(r,t,e),t}function _e(r){return Ye.encodingLength(r)}function Dt(r,t){let e=t.byteLength,n=_e(r),o=n+_e(e),i=new Uint8Array(o+e);return Le(r,i,0),Le(e,i,n),i.set(t,o),new Ce(r,e,t,i)}function Ft(r){let t=Ht(r),[e,n]=je(t),[o,i]=je(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Ce(e,o,s,t)}function Ri(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Bi(r.bytes,e.bytes)}}var Ce=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function Ui(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Kc(e,Sn(r),t??$.encoder);default:return Rc(e,Sn(r),t??kt.encoder)}}var Ni=new WeakMap;function Sn(r){let t=Ni.get(r);if(t==null){let e=new Map;return Ni.set(r,e),e}return t}var et=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!==Xe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Uc)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=Dt(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&&Ri(t.multihash,n.multihash)}toString(t){return Ui(this,t)}toJSON(){return{"/":Ui(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:i,bytes:s}=e;return new r(n,o,i,s??Oi(n,o,i.bytes))}else if(e[Nc]===!0){let{version:n,multihash:o,code:i}=e,s=Ft(o);return r.create(n,i,s)}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!==Xe)throw new Error(`Version 0 CID must use dag-pb (code: ${Xe}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Oi(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Xe,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=Ht(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let i=o.subarray(e.multihashSize-e.digestSize),s=new Ce(e.multihashCode,e.digestSize,i,o);return[e.version===0?r.createV0(s):r.createV1(e.codec,s),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[l,d]=je(t.subarray(e));return e+=d,l},o=n(),i=Xe;if(o===18?(o=0,e=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=e,a=n(),c=n(),f=e+c,u=f-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(t,e){let[n,o]=Dc(t,e),i=r.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Sn(i).set(n,t),i}};function Dc(r,t){switch(r[0]){case"Q":{let e=t??$;return[$.prefix,e.decode(`${$.prefix}${r}`)]}case $.prefix:{let e=t??$;return[$.prefix,e.decode(r)]}case kt.prefix:{let e=t??kt;return[kt.prefix,e.decode(r)]}case Ze.prefix:{let e=t??Ze;return[Ze.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 Kc(r,t,e){let{prefix:n}=e;if(n!==$.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let i=e.encode(r).slice(1);return t.set(n,i),i}else return o}function Rc(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let i=e.encode(r);return t.set(n,i),i}else return o}var Xe=112,Uc=18;function Oi(r,t,e){let n=_e(r),o=n+_e(t),i=new Uint8Array(o+e.byteLength);return Le(r,i,0),Le(t,i,n),i.set(e,o),i}var Nc=Symbol.for("@ipld/js-cid/CID");var An={};vt(An,{identity:()=>Kt});var Mi=0,Oc="identity",qi=Ht;function Mc(r){return Dt(Mi,qi(r))}var Kt={code:Mi,name:Oc,encode:qi,digest:Mc};function j(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 it(r=0){return new Uint8Array(r)}function St(r=0){return new Uint8Array(r)}function Tt(r,t){t==null&&(t=r.reduce((o,i)=>o+i.length,0));let e=St(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var Fi=Symbol.for("@achingbrain/uint8arraylist");function Hi(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 Lr(r){return!!r?.[Fi]}var mt=class r{bufs;length;[Fi]=!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(Lr(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(Lr(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=Hi(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Hi(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(Lr(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 Tt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Tt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),i=new r;return i.length=o,i.bufs=[...n],i}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=c,t>=c)continue;let f=t>=a&&t<c,u=e>a&&e<=c;if(f&&u){if(t===a&&e===c){n.push(s);break}let l=t-a;n.push(s.subarray(l,l+(e-t)));break}if(f){if(t===0){n.push(s);continue}n.push(s.subarray(t-a));continue}if(u){if(e===c){n.push(s);break}n.push(s.subarray(0,e-a));break}n.push(s)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Lr(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 i=256,s=new Int32Array(i);for(let l=0;l<i;l++)s[l]=-1;for(let l=0;l<o;l++)s[n[l]]=l;let a=s,c=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let l=e;l<=c;l+=u){u=0;for(let d=f;d>=0;d--){let y=this.get(l+d);if(n[d]!==y){u=Math.max(1,d-a[y]);break}}if(u===0)return l}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=St(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=it(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=it(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=it(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=St(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=it(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=it(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=it(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=it(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=it(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(!j(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,i)=>o+i.byteLength,0)),n.length=e,n}};var In={};vt(In,{base10:()=>qc});var qc=Jt({prefix:"9",name:"base10",alphabet:"0123456789"});var Bn={};vt(Bn,{base16:()=>Hc,base16upper:()=>Fc});var Hc=tt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Fc=tt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Tn={};vt(Tn,{base2:()=>Vc});var Vc=tt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Pn={};vt(Pn,{base256emoji:()=>Zc});var Vi=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}"),zc=Vi.reduce((r,t,e)=>(r[e]=t,r),[]),Gc=Vi.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Wc(r){return r.reduce((t,e)=>(t+=zc[e],t),"")}function $c(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Gc[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Zc=Pe({prefix:"\u{1F680}",name:"base256emoji",encode:Wc,decode:$c});var Ln={};vt(Ln,{base64:()=>Yc,base64pad:()=>jc,base64url:()=>Xc,base64urlpad:()=>Qc});var Yc=tt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),jc=tt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Xc=tt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Qc=tt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var _n={};vt(_n,{base8:()=>Jc});var Jc=tt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Cn={};vt(Cn,{identity:()=>tu});var tu=Pe({prefix:"\0",name:"identity",encode:r=>Pi(r),decode:r=>Ti(r)});var xd=new TextEncoder,Ed=new TextDecoder;var Kn={};vt(Kn,{sha256:()=>Qe,sha512:()=>nu});function Dn({name:r,code:t,encode:e}){return new kn(r,t,e)}var kn=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?Dt(this.code,e):e.then(n=>Dt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Gi(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Qe=Dn({name:"sha2-256",code:18,encode:Gi("SHA-256")}),nu=Dn({name:"sha2-512",code:19,encode:Gi("SHA-512")});var Je={...Cn,...Tn,..._n,...In,...Bn,...xn,...En,...wn,...Ln,...Pn},Dd={...Kn,...An};function $i(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Wi=$i("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Rn=$i("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=St(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),ou={utf8:Wi,"utf-8":Wi,hex:Je.base16,latin1:Rn,ascii:Rn,binary:Rn,...Je},_r=ou;function G(r,t="utf8"){let e=_r[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function U(r,t="utf8"){let e=_r[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var iu=parseInt("11111",2),Un=parseInt("10000000",2),su=parseInt("01111111",2),Zi={0:tr,1:tr,2:au,3:lu,4:fu,5:uu,6:cu,16:tr,22:tr,48:tr};function zt(r,t={offset:0}){let e=r[t.offset]&iu;if(t.offset++,Zi[e]!=null)return Zi[e](r,t);throw new Error("No decoder for tag "+e)}function er(r,t){let e=0;if((r[t.offset]&Un)===Un){let n=r[t.offset]&su,o="0x";t.offset++;for(let i=0;i<n;i++,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 tr(r,t){er(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=zt(r,t);if(n===null)break;e.push(n)}return e}function au(r,t){let e=er(r,t),n=t.offset,o=t.offset+e,i=[];for(let s=n;s<o;s++)s===n&&r[s]===0||i.push(r[s]);return t.offset+=e,Uint8Array.from(i)}function cu(r,t){let e=er(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let i=0,s=0;o<40?(i=0,s=o):o<80?(i=1,s=o-40):(i=2,s=o-80);let a=`${i}.${s}`,c=[];for(;t.offset<n;){let f=r[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let u=0;for(let l=0;l<c.length;l++)u+=c[l]<<l*7;a+=`.${u}`,c=[]}}return a}function uu(r,t){return t.offset++,null}function lu(r,t){let e=er(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=er(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function du(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new mt;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Nn(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=du(r.byteLength);return new mt(Uint8Array.from([t.byteLength|Un]),t)}function At(r){let t=new mt,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new mt(Uint8Array.from([2]),Nn(t),t)}function Cr(r){let t=Uint8Array.from([0]),e=new mt(t,r);return new mt(Uint8Array.from([3]),Nn(e),e)}function te(r,t=48){let e=new mt;for(let n of r)e.append(n);return new mt(Uint8Array.from([t]),Nn(e),e)}async function Yi(r,t,e){let n=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);return crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},n,t,e.subarray())}var hu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),pu=Uint8Array.from([6,5,43,129,4,0,34]),mu=Uint8Array.from([6,5,43,129,4,0,35]),yu={ext:!0,kty:"EC",crv:"P-256"},gu={ext:!0,kty:"EC",crv:"P-384"},bu={ext:!0,kty:"EC",crv:"P-521"},On=32,Mn=48,qn=66;function Hn(r){let t=zt(r);return ji(t)}function ji(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===On*2+1)return n=U(t.subarray(e,e+On),"base64url"),o=U(t.subarray(e+On),"base64url"),new ke({...yu,key_ops:["verify"],x:n,y:o});if(t.byteLength===Mn*2+1)return n=U(t.subarray(e,e+Mn),"base64url"),o=U(t.subarray(e+Mn),"base64url"),new ke({...gu,key_ops:["verify"],x:n,y:o});if(t.byteLength===qn*2+1)return n=U(t.subarray(e,e+qn),"base64url"),o=U(t.subarray(e+qn),"base64url"),new ke({...bu,key_ops:["verify"],x:n,y:o});throw new q(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Xi(r){return te([At(Uint8Array.from([1])),te([wu(r.crv)],160),te([Cr(new mt(Uint8Array.from([4]),G(r.x??"","base64url"),G(r.y??"","base64url")))],161)]).subarray()}function wu(r){if(r==="P-256")return hu;if(r==="P-384")return pu;if(r==="P-521")return mu;throw new q(`Invalid curve ${r}`)}var ke=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Xi(this.jwk)),this._raw}toMultihash(){return Kt.digest(_t(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return $.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:j(this.raw,t.raw)}async verify(t,e){return Yi(this.jwk,e,t)}};function Qi(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function xu(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function De(r,...t){if(!xu(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 Ji(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Qi(r.outputLen),Qi(r.blockLen)}function Ke(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 ts(r,t){De(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}var he=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function kr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Rt(r,t){return r<<32-t|r>>>t}var ph=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function";function es(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function rr(r){return typeof r=="string"&&(r=es(r)),De(r),r}function Fn(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];De(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let i=r[n];e.set(i,o),o+=i.length}return e}var Re=class{clone(){return this._cloneInto()}};function Dr(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 Kr(r=32){if(he&&typeof he.getRandomValues=="function")return he.getRandomValues(new Uint8Array(r));if(he&&typeof he.randomBytes=="function")return Uint8Array.from(he.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function Eu(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(e>>o&i),a=Number(e&i),c=n?4:0,f=n?0:4;r.setUint32(t+c,s,n),r.setUint32(t+f,a,n)}function rs(r,t,e){return r&t^~r&e}function ns(r,t,e){return r&t^r&e^t&e}var Ue=class extends Re{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=kr(this.buffer)}update(t){Ke(this);let{view:e,buffer:n,blockLen:o}=this;t=rr(t);let i=t.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=kr(t);for(;o<=i-s;s+=o)this.process(c,s);continue}n.set(t.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ke(this),ts(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;e[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>o-s&&(this.process(n,0),s=0);for(let l=s;l<o;l++)e[l]=0;Eu(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=kr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)a.setUint32(4*l,u[l],i)}digest(){let{buffer: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:i,destroyed:s,pos:a}=this;return t.length=o,t.pos=a,t.finished=i,t.destroyed=s,o%e&&t.buffer.set(n),t}};var vu=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),ee=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),re=new Uint32Array(64),Vn=class extends Ue{constructor(t=32){super(64,t,8,!1),this.A=ee[0]|0,this.B=ee[1]|0,this.C=ee[2]|0,this.D=ee[3]|0,this.E=ee[4]|0,this.F=ee[5]|0,this.G=ee[6]|0,this.H=ee[7]|0}get(){let{A:t,B:e,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[t,e,n,o,i,s,a,c]}set(t,e,n,o,i,s,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(t,e){for(let l=0;l<16;l++,e+=4)re[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let d=re[l-15],y=re[l-2],w=Rt(d,7)^Rt(d,18)^d>>>3,g=Rt(y,17)^Rt(y,19)^y>>>10;re[l]=g+re[l-7]+w+re[l-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:f,H:u}=this;for(let l=0;l<64;l++){let d=Rt(a,6)^Rt(a,11)^Rt(a,25),y=u+d+rs(a,c,f)+vu[l]+re[l]|0,g=(Rt(n,2)^Rt(n,13)^Rt(n,22))+ns(n,o,i)|0;u=f,f=c,c=a,a=s+y|0,s=i,i=o,o=n,n=y+g|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,o,i,s,a,c,f,u)}roundClean(){re.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var pe=Dr(()=>new Vn);var Rr=BigInt(4294967295),zn=BigInt(32);function os(r,t=!1){return t?{h:Number(r&Rr),l:Number(r>>zn&Rr)}:{h:Number(r>>zn&Rr)|0,l:Number(r&Rr)|0}}function Su(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:i,l:s}=os(r[o],t);[e[o],n[o]]=[i,s]}return[e,n]}var Au=(r,t)=>BigInt(r>>>0)<<zn|BigInt(t>>>0),Iu=(r,t,e)=>r>>>e,Bu=(r,t,e)=>r<<32-e|t>>>e,Tu=(r,t,e)=>r>>>e|t<<32-e,Pu=(r,t,e)=>r<<32-e|t>>>e,Lu=(r,t,e)=>r<<64-e|t>>>e-32,_u=(r,t,e)=>r>>>e-32|t<<64-e,Cu=(r,t)=>t,ku=(r,t)=>r,Du=(r,t,e)=>r<<e|t>>>32-e,Ku=(r,t,e)=>t<<e|r>>>32-e,Ru=(r,t,e)=>t<<e-32|r>>>64-e,Uu=(r,t,e)=>r<<e-32|t>>>64-e;function Nu(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Ou=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Mu=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,qu=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Hu=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Fu=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Vu=(r,t,e,n,o,i)=>t+e+n+o+i+(r/2**32|0)|0;var zu={fromBig:os,split:Su,toBig:Au,shrSH:Iu,shrSL:Bu,rotrSH:Tu,rotrSL:Pu,rotrBH:Lu,rotrBL:_u,rotr32H:Cu,rotr32L:ku,rotlSH:Du,rotlSL:Ku,rotlBH:Ru,rotlBL:Uu,add:Nu,add3L:Ou,add3H:Mu,add4L:qu,add4H:Hu,add5H:Vu,add5L:Fu},K=zu;var[Gu,Wu]=K.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),ne=new Uint32Array(80),oe=new Uint32Array(80),Gn=class extends Ue{constructor(t=64){super(128,t,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:f,El:u,Fh:l,Fl:d,Gh:y,Gl:w,Hh:g,Hl:h}=this;return[t,e,n,o,i,s,a,c,f,u,l,d,y,w,g,h]}set(t,e,n,o,i,s,a,c,f,u,l,d,y,w,g,h){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=l|0,this.Fl=d|0,this.Gh=y|0,this.Gl=w|0,this.Hh=g|0,this.Hl=h|0}process(t,e){for(let m=0;m<16;m++,e+=4)ne[m]=t.getUint32(e),oe[m]=t.getUint32(e+=4);for(let m=16;m<80;m++){let I=ne[m-15]|0,k=oe[m-15]|0,C=K.rotrSH(I,k,1)^K.rotrSH(I,k,8)^K.shrSH(I,k,7),T=K.rotrSL(I,k,1)^K.rotrSL(I,k,8)^K.shrSL(I,k,7),P=ne[m-2]|0,L=oe[m-2]|0,Y=K.rotrSH(P,L,19)^K.rotrBH(P,L,61)^K.shrSH(P,L,6),F=K.rotrSL(P,L,19)^K.rotrBL(P,L,61)^K.shrSL(P,L,6),N=K.add4L(T,F,oe[m-7],oe[m-16]),st=K.add4H(N,C,Y,ne[m-7],ne[m-16]);ne[m]=st|0,oe[m]=N|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:f,Dl:u,Eh:l,El:d,Fh:y,Fl:w,Gh:g,Gl:h,Hh:x,Hl:A}=this;for(let m=0;m<80;m++){let I=K.rotrSH(l,d,14)^K.rotrSH(l,d,18)^K.rotrBH(l,d,41),k=K.rotrSL(l,d,14)^K.rotrSL(l,d,18)^K.rotrBL(l,d,41),C=l&y^~l&g,T=d&w^~d&h,P=K.add5L(A,k,T,Wu[m],oe[m]),L=K.add5H(P,x,I,C,Gu[m],ne[m]),Y=P|0,F=K.rotrSH(n,o,28)^K.rotrBH(n,o,34)^K.rotrBH(n,o,39),N=K.rotrSL(n,o,28)^K.rotrBL(n,o,34)^K.rotrBL(n,o,39),st=n&i^n&a^i&a,v=o&s^o&c^s&c;x=g|0,A=h|0,g=y|0,h=w|0,y=l|0,w=d|0,{h:l,l:d}=K.add(f|0,u|0,L|0,Y|0),f=a|0,u=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let B=K.add3L(Y,N,v);n=K.add3H(B,L,F,st),o=B|0}({h:n,l:o}=K.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=K.add(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=K.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=K.add(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:d}=K.add(this.Eh|0,this.El|0,l|0,d|0),{h:y,l:w}=K.add(this.Fh|0,this.Fl|0,y|0,w|0),{h:g,l:h}=K.add(this.Gh|0,this.Gl|0,g|0,h|0),{h:x,l:A}=K.add(this.Hh|0,this.Hl|0,x|0,A|0),this.set(n,o,i,s,a,c,f,u,l,d,y,w,g,h,x,A)}roundClean(){ne.fill(0),oe.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Wn=Dr(()=>new Gn);var jn=BigInt(0),Yn=BigInt(1);function me(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Xn(r){if(!me(r))throw new Error("Uint8Array expected")}function Nt(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function nr(r){let t=r.toString(16);return t.length&1?"0"+t:t}function as(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?jn:BigInt("0x"+r)}var cs=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",$u=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function ie(r){if(Xn(r),cs)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=$u[r[e]];return t}var Gt={_0:48,_9:57,A:65,F:70,a:97,f:102};function is(r){if(r>=Gt._0&&r<=Gt._9)return r-Gt._0;if(r>=Gt.A&&r<=Gt.F)return r-(Gt.A-10);if(r>=Gt.a&&r<=Gt.f)return r-(Gt.a-10)}function or(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(cs)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,i=0;o<e;o++,i+=2){let s=is(r.charCodeAt(i)),a=is(r.charCodeAt(i+1));if(s===void 0||a===void 0){let c=r[i]+r[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function Wt(r){return as(ie(r))}function ye(r){return Xn(r),as(ie(Uint8Array.from(r).reverse()))}function ge(r,t){return or(r.toString(16).padStart(t*2,"0"))}function Ne(r,t){return ge(r,t).reverse()}function J(r,t,e){let n;if(typeof t=="string")try{n=or(t)}catch(i){throw new Error(r+" must be hex string or Uint8Array, cause: "+i)}else if(me(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}function se(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Xn(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let i=r[n];e.set(i,o),o+=i.length}return e}var $n=r=>typeof r=="bigint"&&jn<=r;function Ur(r,t,e){return $n(r)&&$n(t)&&$n(e)&&t<=r&&r<e}function Pt(r,t,e,n){if(!Ur(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function us(r){let t;for(t=0;r>jn;r>>=Yn,t+=1);return t}var be=r=>(Yn<<BigInt(r))-Yn,Zn=r=>new Uint8Array(r),ss=r=>Uint8Array.from(r);function ls(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=Zn(r),o=Zn(r),i=0,s=()=>{n.fill(1),o.fill(0),i=0},a=(...l)=>e(o,n,...l),c=(l=Zn(0))=>{o=a(ss([0]),l),n=a(),l.length!==0&&(o=a(ss([1]),l),n=a())},f=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,d=[];for(;l<t;){n=a();let y=n.slice();d.push(y),l+=n.length}return se(...d)};return(l,d)=>{s(),c(l);let y;for(;!(y=d(f()));)c();return s(),y}}var Zu={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||me(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function $t(r,t,e={}){let n=(o,i,s)=>{let a=Zu[i];if(typeof a!="function")throw new Error("invalid validator function");let c=r[o];if(!(s&&c===void 0)&&!a(c,r))throw new Error("param "+String(o)+" is invalid. Expected "+i+", got "+c)};for(let[o,i]of Object.entries(t))n(o,i,!1);for(let[o,i]of Object.entries(e))n(o,i,!0);return r}function Oe(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let i=r(e,...n);return t.set(e,i),i}}var at=BigInt(0),X=BigInt(1),we=BigInt(2),Yu=BigInt(3),Qn=BigInt(4),fs=BigInt(5),ds=BigInt(8),ju=BigInt(9),Xu=BigInt(16);function W(r,t){let e=r%t;return e>=at?e:t+e}function Qu(r,t,e){if(t<at)throw new Error("invalid exponent, negatives unsupported");if(e<=at)throw new Error("invalid modulus");if(e===X)return at;let n=X;for(;t>at;)t&X&&(n=n*r%e),r=r*r%e,t>>=X;return n}function Q(r,t,e){let n=r;for(;t-- >at;)n*=n,n%=e;return n}function Nr(r,t){if(r===at)throw new Error("invert: expected non-zero number");if(t<=at)throw new Error("invert: expected positive modulus, got "+t);let e=W(r,t),n=t,o=at,i=X,s=X,a=at;for(;e!==at;){let f=n/e,u=n%e,l=o-s*f,d=i-a*f;n=e,e=u,o=s,i=a,s=l,a=d}if(n!==X)throw new Error("invert: does not exist");return W(o,t)}function Ju(r){let t=(r-X)/we,e,n,o;for(e=r-X,n=0;e%we===at;e/=we,n++);for(o=we;o<r&&Qu(o,t,r)!==r-X;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let s=(r+X)/Qn;return function(c,f){let u=c.pow(f,s);if(!c.eql(c.sqr(u),f))throw new Error("Cannot find square root");return u}}let i=(e+X)/we;return function(a,c){if(a.pow(c,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let f=n,u=a.pow(a.mul(a.ONE,o),e),l=a.pow(c,i),d=a.pow(c,e);for(;!a.eql(d,a.ONE);){if(a.eql(d,a.ZERO))return a.ZERO;let y=1;for(let g=a.sqr(d);y<f&&!a.eql(g,a.ONE);y++)g=a.sqr(g);let w=a.pow(u,X<<BigInt(f-y-1));u=a.sqr(w),l=a.mul(l,w),d=a.mul(d,u),f=y}return l}}function tl(r){if(r%Qn===Yu){let t=(r+X)/Qn;return function(n,o){let i=n.pow(o,t);if(!n.eql(n.sqr(i),o))throw new Error("Cannot find square root");return i}}if(r%ds===fs){let t=(r-fs)/ds;return function(n,o){let i=n.mul(o,we),s=n.pow(i,t),a=n.mul(o,s),c=n.mul(n.mul(a,we),s),f=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(f),o))throw new Error("Cannot find square root");return f}}return r%Xu,Ju(r)}var hs=(r,t)=>(W(r,t)&X)===X,el=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Jn(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=el.reduce((n,o)=>(n[o]="function",n),t);return $t(r,e)}function rl(r,t,e){if(e<at)throw new Error("invalid exponent, negatives unsupported");if(e===at)return r.ONE;if(e===X)return t;let n=r.ONE,o=t;for(;e>at;)e&X&&(n=r.mul(n,o)),o=r.sqr(o),e>>=X;return n}function nl(r,t){let e=new Array(t.length),n=t.reduce((i,s,a)=>r.is0(s)?i:(e[a]=i,r.mul(i,s)),r.ONE),o=r.inv(n);return t.reduceRight((i,s,a)=>r.is0(s)?i:(e[a]=r.mul(i,e[a]),r.mul(i,s)),o),e}function to(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function ae(r,t,e=!1,n={}){if(r<=at)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:i}=to(r,t);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let s,a=Object.freeze({ORDER:r,isLE:e,BITS:o,BYTES:i,MASK:be(o),ZERO:at,ONE:X,create:c=>W(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return at<=c&&c<r},is0:c=>c===at,isOdd:c=>(c&X)===X,neg:c=>W(-c,r),eql:(c,f)=>c===f,sqr:c=>W(c*c,r),add:(c,f)=>W(c+f,r),sub:(c,f)=>W(c-f,r),mul:(c,f)=>W(c*f,r),pow:(c,f)=>rl(a,c,f),div:(c,f)=>W(c*Nr(f,r),r),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>Nr(c,r),sqrt:n.sqrt||(c=>(s||(s=tl(r)),s(a,c))),invertBatch:c=>nl(a,c),cmov:(c,f,u)=>u?f:c,toBytes:c=>e?Ne(c,i):ge(c,i),fromBytes:c=>{if(c.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+c.length);return e?ye(c):Wt(c)}});return Object.freeze(a)}function ps(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 eo(r){let t=ps(r);return t+Math.ceil(t/2)}function ms(r,t,e=!1){let n=r.length,o=ps(t),i=eo(t);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=e?ye(r):Wt(r),a=W(s,t-X)+X;return e?Ne(a,o):ge(a,o)}var ys=BigInt(0),so=BigInt(1);function ro(r,t){let e=t.negate();return r?e:t}function bs(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function no(r,t){bs(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,i=be(r),s=BigInt(r);return{windows:e,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function gs(r,t,e){let{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=e,a=Number(r&o),c=r>>s;a>n&&(a-=i,c+=so);let f=t*n,u=f+Math.abs(a)-1,l=a===0,d=a<0,y=t%2!==0;return{nextN:c,offset:u,isZero:l,isNeg:d,isNegF:y,offsetF:f}}function ol(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 il(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 oo=new WeakMap,ws=new WeakMap;function io(r){return ws.get(r)||1}function Or(r,t){return{constTimeNegate:ro,hasPrecomputes(e){return io(e)!==1},unsafeLadder(e,n,o=r.ZERO){let i=e;for(;n>ys;)n&so&&(o=o.add(i)),i=i.double(),n>>=so;return o},precomputeWindow(e,n){let{windows:o,windowSize:i}=no(n,t),s=[],a=e,c=a;for(let f=0;f<o;f++){c=a,s.push(c);for(let u=1;u<i;u++)c=c.add(a),s.push(c);a=c.double()}return s},wNAF(e,n,o){let i=r.ZERO,s=r.BASE,a=no(e,t);for(let c=0;c<a.windows;c++){let{nextN:f,offset:u,isZero:l,isNeg:d,isNegF:y,offsetF:w}=gs(o,c,a);o=f,l?s=s.add(ro(y,n[w])):i=i.add(ro(d,n[u]))}return{p:i,f:s}},wNAFUnsafe(e,n,o,i=r.ZERO){let s=no(e,t);for(let a=0;a<s.windows&&o!==ys;a++){let{nextN:c,offset:f,isZero:u,isNeg:l}=gs(o,a,s);if(o=c,!u){let d=n[f];i=i.add(l?d.negate():d)}}return i},getPrecomputes(e,n,o){let i=oo.get(n);return i||(i=this.precomputeWindow(n,e),e!==1&&oo.set(n,o(i))),i},wNAFCached(e,n,o){let i=io(e);return this.wNAF(i,this.getPrecomputes(i,e,o),n)},wNAFCachedUnsafe(e,n,o,i){let s=io(e);return s===1?this.unsafeLadder(e,n,i):this.wNAFUnsafe(s,this.getPrecomputes(s,e,o),n,i)},setWindowSize(e,n){bs(n,t),ws.set(e,n),oo.delete(e)}}}function Mr(r,t,e,n){if(ol(e,r),il(n,t),e.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=r.ZERO,i=us(BigInt(e.length)),s=i>12?i-3:i>4?i-2:i?2:1,a=be(s),c=new Array(Number(a)+1).fill(o),f=Math.floor((t.BITS-1)/s)*s,u=o;for(let l=f;l>=0;l-=s){c.fill(o);for(let y=0;y<n.length;y++){let w=n[y],g=Number(w>>BigInt(l)&a);c[g]=c[g].add(e[y])}let d=o;for(let y=c.length-1,w=o;y>0;y--)w=w.add(c[y]),d=d.add(w);if(u=u.add(d),l!==0)for(let y=0;y<s;y++)u=u.double()}return u}function ir(r){return Jn(r.Fp),$t(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...to(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Ot=BigInt(0),yt=BigInt(1),xs=BigInt(2),sl=BigInt(8),al={zip215:!0};function cl(r){let t=ir(r);return $t(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Es(r){let t=cl(r),{Fp:e,n,prehash:o,hash:i,randomBytes:s,nByteLength:a,h:c}=t,f=xs<<BigInt(a*8)-yt,u=e.create,l=ae(t.n,t.nBitLength),d=t.uvRatio||((b,p)=>{try{return{isValid:!0,value:e.sqrt(b*e.inv(p))}}catch{return{isValid:!1,value:Ot}}}),y=t.adjustScalarBytes||(b=>b),w=t.domain||((b,p,E)=>{if(Nt("phflag",E),p.length||E)throw new Error("Contexts/pre-hash are not supported");return b});function g(b,p,E=!1){let S=E?yt:Ot;Pt("coordinate "+b,p,S,f)}function h(b){if(!(b instanceof m))throw new Error("ExtendedPoint expected")}let x=Oe((b,p)=>{let{ex:E,ey:S,ez:D}=b,R=b.is0();p==null&&(p=R?sl:e.inv(D));let O=u(E*p),M=u(S*p),H=u(D*p);if(R)return{x:Ot,y:yt};if(H!==yt)throw new Error("invZ was invalid");return{x:O,y:M}}),A=Oe(b=>{let{a:p,d:E}=t;if(b.is0())throw new Error("bad point: ZERO");let{ex:S,ey:D,ez:R,et:O}=b,M=u(S*S),H=u(D*D),z=u(R*R),ot=u(z*z),rt=u(M*p),lt=u(z*u(rt+H)),Et=u(ot+u(E*u(M*H)));if(lt!==Et)throw new Error("bad point: equation left != right (1)");let ct=u(S*D),ft=u(R*O);if(ct!==ft)throw new Error("bad point: equation left != right (2)");return!0});class m{constructor(p,E,S,D){g("x",p),g("y",E),g("z",S,!0),g("t",D),this.ex=p,this.ey=E,this.ez=S,this.et=D,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:E,y:S}=p||{};return g("x",E),g("y",S),new m(E,S,yt,u(E*S))}static normalizeZ(p){let E=e.invertBatch(p.map(S=>S.ez));return p.map((S,D)=>S.toAffine(E[D])).map(m.fromAffine)}static msm(p,E){return Mr(m,l,p,E)}_setWindowSize(p){C.setWindowSize(this,p)}assertValidity(){A(this)}equals(p){h(p);let{ex:E,ey:S,ez:D}=this,{ex:R,ey:O,ez:M}=p,H=u(E*M),z=u(R*D),ot=u(S*M),rt=u(O*D);return H===z&&ot===rt}is0(){return this.equals(m.ZERO)}negate(){return new m(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:p}=t,{ex:E,ey:S,ez:D}=this,R=u(E*E),O=u(S*S),M=u(xs*u(D*D)),H=u(p*R),z=E+S,ot=u(u(z*z)-R-O),rt=H+O,lt=rt-M,Et=H-O,ct=u(ot*lt),ft=u(rt*Et),Bt=u(ot*Et),Ct=u(lt*rt);return new m(ct,ft,Ct,Bt)}add(p){h(p);let{a:E,d:S}=t,{ex:D,ey:R,ez:O,et:M}=this,{ex:H,ey:z,ez:ot,et:rt}=p,lt=u(D*H),Et=u(R*z),ct=u(M*S*rt),ft=u(O*ot),Bt=u((D+R)*(H+z)-lt-Et),Ct=ft-ct,We=ft+ct,Si=u(Et-E*lt),Fa=u(Bt*Ct),Va=u(We*Si),za=u(Bt*Si),Ga=u(Ct*We);return new m(Fa,Va,Ga,za)}subtract(p){return this.add(p.negate())}wNAF(p){return C.wNAFCached(this,p,m.normalizeZ)}multiply(p){let E=p;Pt("scalar",E,yt,n);let{p:S,f:D}=this.wNAF(E);return m.normalizeZ([S,D])[0]}multiplyUnsafe(p,E=m.ZERO){let S=p;return Pt("scalar",S,Ot,n),S===Ot?k:this.is0()||S===yt?this:C.wNAFCachedUnsafe(this,S,m.normalizeZ,E)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return C.unsafeLadder(this,n).is0()}toAffine(p){return x(this,p)}clearCofactor(){let{h:p}=t;return p===yt?this:this.multiplyUnsafe(p)}static fromHex(p,E=!1){let{d:S,a:D}=t,R=e.BYTES;p=J("pointHex",p,R),Nt("zip215",E);let O=p.slice(),M=p[R-1];O[R-1]=M&-129;let H=ye(O),z=E?f:e.ORDER;Pt("pointHex.y",H,Ot,z);let ot=u(H*H),rt=u(ot-yt),lt=u(S*ot-D),{isValid:Et,value:ct}=d(rt,lt);if(!Et)throw new Error("Point.fromHex: invalid y coordinate");let ft=(ct&yt)===yt,Bt=(M&128)!==0;if(!E&&ct===Ot&&Bt)throw new Error("Point.fromHex: x=0 and x_0=1");return Bt!==ft&&(ct=u(-ct)),m.fromAffine({x:ct,y:H})}static fromPrivateKey(p){let{scalar:E}=L(p);return I.multiply(E)}toRawBytes(){let{x:p,y:E}=this.toAffine(),S=Ne(E,e.BYTES);return S[S.length-1]|=p&yt?128:0,S}toHex(){return ie(this.toRawBytes())}}m.BASE=new m(t.Gx,t.Gy,yt,u(t.Gx*t.Gy)),m.ZERO=new m(Ot,yt,yt,Ot);let{BASE:I,ZERO:k}=m,C=Or(m,a*8);function T(b){return W(b,n)}function P(b){return T(ye(b))}function L(b){let p=e.BYTES;b=J("private key",b,p);let E=J("hashed private key",i(b),2*p),S=y(E.slice(0,p)),D=E.slice(p,2*p),R=P(S);return{head:S,prefix:D,scalar:R}}function Y(b){let{head:p,prefix:E,scalar:S}=L(b),D=I.multiply(S),R=D.toRawBytes();return{head:p,prefix:E,scalar:S,point:D,pointBytes:R}}function F(b){return Y(b).pointBytes}function N(b=new Uint8Array,...p){let E=se(...p);return P(i(w(E,J("context",b),!!o)))}function st(b,p,E={}){b=J("message",b),o&&(b=o(b));let{prefix:S,scalar:D,pointBytes:R}=Y(p),O=N(E.context,S,b),M=I.multiply(O).toRawBytes(),H=N(E.context,M,R,b),z=T(O+H*D);Pt("signature.s",z,Ot,n);let ot=se(M,Ne(z,e.BYTES));return J("result",ot,e.BYTES*2)}let v=al;function B(b,p,E,S=v){let{context:D,zip215:R}=S,O=e.BYTES;b=J("signature",b,2*O),p=J("message",p),E=J("publicKey",E,O),R!==void 0&&Nt("zip215",R),o&&(p=o(p));let M=ye(b.slice(O,2*O)),H,z,ot;try{H=m.fromHex(E,R),z=m.fromHex(b.slice(0,O),R),ot=I.multiplyUnsafe(M)}catch{return!1}if(!R&&H.isSmallOrder())return!1;let rt=N(D,z.toRawBytes(),H.toRawBytes(),p);return z.add(H.multiplyUnsafe(rt)).subtract(ot).clearCofactor().equals(m.ZERO)}return I._setWindowSize(8),{CURVE:t,getPublicKey:F,sign:st,verify:B,ExtendedPoint:m,utils:{getExtendedPublicKey:Y,randomPrivateKey:()=>s(e.BYTES),precompute(b=8,p=m.BASE){return p._setWindowSize(b),p.multiply(BigInt(3)),p}}}}var ao=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),vs=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Yh=BigInt(0),ul=BigInt(1),Ss=BigInt(2),jh=BigInt(3),ll=BigInt(5),fl=BigInt(8);function dl(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),i=ao,a=r*r%i*r%i,c=Q(a,Ss,i)*a%i,f=Q(c,ul,i)*r%i,u=Q(f,ll,i)*f%i,l=Q(u,t,i)*u%i,d=Q(l,e,i)*l%i,y=Q(d,n,i)*d%i,w=Q(y,o,i)*y%i,g=Q(w,o,i)*y%i,h=Q(g,t,i)*u%i;return{pow_p_5_8:Q(h,Ss,i)*r%i,b2:a}}function hl(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function pl(r,t){let e=ao,n=W(t*t*t,e),o=W(n*n*t,e),i=dl(r*o).pow_p_5_8,s=W(r*n*i,e),a=W(t*s*s,e),c=s,f=W(s*vs,e),u=a===r,l=a===W(-r,e),d=a===W(-r*vs,e);return u&&(s=c),(l||d)&&(s=f),hs(s,e)&&(s=W(-s,e)),{isValid:u||l,value:s}}var As=ae(ao,void 0,!0),ml={a:As.create(BigInt(-1)),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:As,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:fl,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Wn,randomBytes:Kr,adjustScalarBytes:hl,uvRatio:pl},Is=Es(ml);var qr=32;function Bs(r,t,e){return Is.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var Hr=class{type="Ed25519";raw;constructor(t){this.raw=co(t,qr)}toMultihash(){return Kt.digest(_t(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return $.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:j(this.raw,t.raw)}verify(t,e){return Bs(this.raw,e,t)}};function uo(r){return r=co(r,qr),new Hr(r)}function co(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new q(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var gl=Math.pow(2,7),bl=Math.pow(2,14),wl=Math.pow(2,21),lo=Math.pow(2,28),fo=Math.pow(2,35),ho=Math.pow(2,42),po=Math.pow(2,49),V=128,dt=127;function It(r){if(r<gl)return 1;if(r<bl)return 2;if(r<wl)return 3;if(r<lo)return 4;if(r<fo)return 5;if(r<ho)return 6;if(r<po)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function mo(r,t,e=0){switch(It(r)){case 8:t[e++]=r&255|V,r/=128;case 7:t[e++]=r&255|V,r/=128;case 6:t[e++]=r&255|V,r/=128;case 5:t[e++]=r&255|V,r/=128;case 4:t[e++]=r&255|V,r>>>=7;case 3:t[e++]=r&255|V,r>>>=7;case 2:t[e++]=r&255|V,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function xl(r,t,e=0){switch(It(r)){case 8:t.set(e++,r&255|V),r/=128;case 7:t.set(e++,r&255|V),r/=128;case 6:t.set(e++,r&255|V),r/=128;case 5:t.set(e++,r&255|V),r/=128;case 4:t.set(e++,r&255|V),r>>>=7;case 3:t.set(e++,r&255|V),r>>>=7;case 2:t.set(e++,r&255|V),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function yo(r,t){let e=r[t],n=0;if(n+=e&dt,e<V||(e=r[t+1],n+=(e&dt)<<7,e<V)||(e=r[t+2],n+=(e&dt)<<14,e<V)||(e=r[t+3],n+=(e&dt)<<21,e<V)||(e=r[t+4],n+=(e&dt)*lo,e<V)||(e=r[t+5],n+=(e&dt)*fo,e<V)||(e=r[t+6],n+=(e&dt)*ho,e<V)||(e=r[t+7],n+=(e&dt)*po,e<V))return n;throw new RangeError("Could not decode varint")}function El(r,t){let e=r.get(t),n=0;if(n+=e&dt,e<V||(e=r.get(t+1),n+=(e&dt)<<7,e<V)||(e=r.get(t+2),n+=(e&dt)<<14,e<V)||(e=r.get(t+3),n+=(e&dt)<<21,e<V)||(e=r.get(t+4),n+=(e&dt)*lo,e<V)||(e=r.get(t+5),n+=(e&dt)*fo,e<V)||(e=r.get(t+6),n+=(e&dt)*ho,e<V)||(e=r.get(t+7),n+=(e&dt)*po,e<V))return n;throw new RangeError("Could not decode varint")}function Mt(r,t,e=0){return t==null&&(t=St(It(r))),t instanceof Uint8Array?mo(r,t,e):xl(r,t,e)}function xe(r,t=0){return r instanceof Uint8Array?yo(r,t):El(r,t)}var bo=new Float32Array([-0]),ce=new Uint8Array(bo.buffer);function Ps(r,t,e){bo[0]=r,t[e]=ce[0],t[e+1]=ce[1],t[e+2]=ce[2],t[e+3]=ce[3]}function Ls(r,t){return ce[0]=r[t],ce[1]=r[t+1],ce[2]=r[t+2],ce[3]=r[t+3],bo[0]}var wo=new Float64Array([-0]),ht=new Uint8Array(wo.buffer);function _s(r,t,e){wo[0]=r,t[e]=ht[0],t[e+1]=ht[1],t[e+2]=ht[2],t[e+3]=ht[3],t[e+4]=ht[4],t[e+5]=ht[5],t[e+6]=ht[6],t[e+7]=ht[7]}function Cs(r,t){return ht[0]=r[t],ht[1]=r[t+1],ht[2]=r[t+2],ht[3]=r[t+3],ht[4]=r[t+4],ht[5]=r[t+5],ht[6]=r[t+6],ht[7]=r[t+7],wo[0]}var vl=BigInt(Number.MAX_SAFE_INTEGER),Sl=BigInt(Number.MIN_SAFE_INTEGER),Lt=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 Ee;if(t<vl&&t>Sl)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>ks&&(o=0n,++n>ks&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return Ee;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):Ee}},Ee=new Lt(0,0);Ee.toBigInt=function(){return 0n};Ee.zzEncode=Ee.zzDecode=function(){return this};Ee.length=function(){return 1};var ks=4294967296n;function Ds(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 Ks(r,t,e){if(e-t<1)return"";let o,i=[],s=0,a;for(;t<e;)a=r[t++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function xo(r,t,e){let n=e,o,i;for(let s=0;s<r.length;++s)o=r.charCodeAt(s),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((i=r.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,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 Ut(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Fr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Eo=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,Ut(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 Ut(this,4);return Fr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ut(this,4);return Fr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ut(this,4);let t=Ls(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Ut(this,4);let t=Cs(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 Ut(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Ks(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Ut(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Ut(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 Lt(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 Ut(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 Ut(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 Ut(this,8);let t=Fr(this.buf,this.pos+=4),e=Fr(this.buf,this.pos+=4);return new Lt(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=yo(this.buf,this.pos);return this.pos+=It(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 vo(r){return new Eo(r instanceof Uint8Array?r:r.subarray())}function gt(r,t,e){let n=vo(r);return t.decode(n,void 0,e)}function So(r){let t=r??8192,e=t>>>1,n,o=t;return function(s){if(s<1||s>e)return St(s);o+s>t&&(n=St(t),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var ve=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Ao(){}var Bo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Al=So();function Il(r){return globalThis.Buffer!=null?St(r):Al(r)}var ar=class{len;head;tail;states;constructor(){this.len=0,this.head=new ve(Ao,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new ve(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new To((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(Vr,10,Lt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Lt.fromBigInt(t);return this._push(Vr,e.length(),e)}uint64Number(t){return this._push(mo,It(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=Lt.fromBigInt(t).zzEncode();return this._push(Vr,e.length(),e)}sint64Number(t){let e=Lt.fromNumber(t).zzEncode();return this._push(Vr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Io,1,t?1:0)}fixed32(t){return this._push(sr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Lt.fromBigInt(t);return this._push(sr,4,e.lo)._push(sr,4,e.hi)}fixed64Number(t){let e=Lt.fromNumber(t);return this._push(sr,4,e.lo)._push(sr,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(Ps,4,t)}double(t){return this._push(_s,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Io,1,0):this.uint32(e)._push(Tl,e,t)}string(t){let e=Ds(t);return e!==0?this.uint32(e)._push(xo,e,t):this._push(Io,1,0)}fork(){return this.states=new Bo(this),this.head=this.tail=new ve(Ao,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 ve(Ao,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=Il(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Io(r,t,e){t[e]=r&255}function Bl(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var To=class extends ve{next;constructor(t,e){super(Bl,t,e),this.next=void 0}};function Vr(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 sr(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 Tl(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(ar.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Pl,t,r),this},ar.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Ll,t,r),this});function Pl(r,t,e){t.set(r,e)}function Ll(r,t,e){r.length<40?xo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(G(r),e)}function Po(){return new ar}function bt(r,t){let e=Po();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Me;(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"})(Me||(Me={}));function zr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Lo(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(i,s){let a=t(i);s.int32(a)},n=function(i){let s=i.int32();return t(s)};return zr("enum",Me.VARINT,e,n)}function wt(r,t){return zr("message",Me.LENGTH_DELIMITED,r,t)}var Se=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"},cr=class extends Error{code="ERR_MAX_SIZE";name="MaxSizeError"};var nt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(nt||(nt={}));var _o;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(_o||(_o={}));(function(r){r.codec=()=>Lo(_o)})(nt||(nt={}));var qt;(function(r){let t;r.codec=()=>(t==null&&(t=wt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),nt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let i={},s=n==null?e.len:e.pos+n;for(;e.pos<s;){let a=e.uint32();switch(a>>>3){case 1:{i.Type=nt.codec().decode(e);break}case 2:{i.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>bt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(qt||(qt={}));var Co;(function(r){let t;r.codec=()=>(t==null&&(t=wt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),nt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let i={},s=n==null?e.len:e.pos+n;for(;e.pos<s;){let a=e.uint32();switch(a>>>3){case 1:{i.Type=nt.codec().decode(e);break}case 2:{i.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>bt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Co||(Co={}));var ur=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Gr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Ns={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Gr("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 ue=Ns;var fr={};vt(fr,{MAX_RSA_KEY_SIZE:()=>ko,generateRSAKeyPair:()=>Hs,jwkToJWKKeyPair:()=>Fs,jwkToPkcs1:()=>Dl,jwkToPkix:()=>Uo,jwkToRSAPrivateKey:()=>qo,pkcs1MessageToJwk:()=>Ko,pkcs1MessageToRSAPrivateKey:()=>No,pkcs1ToJwk:()=>kl,pkcs1ToRSAPrivateKey:()=>qs,pkixMessageToJwk:()=>Ro,pkixMessageToRSAPublicKey:()=>Mo,pkixToJwk:()=>Kl,pkixToRSAPublicKey:()=>Oo});var qe=class{type="RSA";jwk;_raw;_multihash;constructor(t,e){this.jwk=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=fr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return et.createV1(114,this._multihash)}toString(){return $.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:j(this.raw,t.raw)}verify(t,e){return Ms(this.jwk,e,t)}},lr=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=fr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:j(this.raw,t.raw)}sign(t){return Os(this.jwk,t)}};var ko=8192,Do=18,_l=1062,Cl=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function kl(r){let t=zt(r);return Ko(t)}function Ko(r){return{n:U(r[1],"base64url"),e:U(r[2],"base64url"),d:U(r[3],"base64url"),p:U(r[4],"base64url"),q:U(r[5],"base64url"),dp:U(r[6],"base64url"),dq:U(r[7],"base64url"),qi:U(r[8],"base64url"),kty:"RSA"}}function Dl(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 q("JWK was missing components");return te([At(Uint8Array.from([0])),At(G(r.n,"base64url")),At(G(r.e,"base64url")),At(G(r.d,"base64url")),At(G(r.p,"base64url")),At(G(r.q,"base64url")),At(G(r.dp,"base64url")),At(G(r.dq,"base64url")),At(G(r.qi,"base64url"))]).subarray()}function Kl(r){let t=zt(r,{offset:0});return Ro(t)}function Ro(r){let t=zt(r[1],{offset:0});return{kty:"RSA",n:U(t[0],"base64url"),e:U(t[1],"base64url")}}function Uo(r){if(r.n==null||r.e==null)throw new q("JWK was missing components");return te([Cl,Cr(te([At(G(r.n,"base64url")),At(G(r.e,"base64url"))]))]).subarray()}function qs(r){let t=zt(r);return No(t)}function No(r){let t=Ko(r);return qo(t)}function Oo(r,t){if(r.byteLength>=_l)throw new Te("Key size is too large");let e=zt(r,{offset:0});return Mo(e,r,t)}function Mo(r,t,e){let n=Ro(r);if(e==null){let o=pe(qt.encode({Type:nt.RSA,Data:t}));e=Dt(Do,o)}return new qe(n,e)}function qo(r){if(zs(r)>ko)throw new q("Key size is too large");let t=Fs(r),e=pe(qt.encode({Type:nt.RSA,Data:Uo(t.publicKey)})),n=Dt(Do,e);return new lr(t.privateKey,new qe(t.publicKey,n))}async function Hs(r){if(r>ko)throw new q("Key size is too large");let t=await Vs(r),e=pe(qt.encode({Type:nt.RSA,Data:Uo(t.publicKey)})),n=Dt(Do,e);return new lr(t.privateKey,new qe(t.publicKey,n))}function Fs(r){if(r==null)throw new q("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function Vs(r){let t=await ue.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),e=await Rl(t);return{privateKey:e[0],publicKey:e[1]}}async function Os(r,t){let e=await ue.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await ue.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function Ms(r,t,e){let n=await ue.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return ue.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function Rl(r){if(r.privateKey==null||r.publicKey==null)throw new q("Private and public key are required");return Promise.all([ue.get().subtle.exportKey("jwk",r.privateKey),ue.get().subtle.exportKey("jwk",r.publicKey)])}function zs(r){if(r.kty!=="RSA")throw new q("invalid key type");if(r.n==null)throw new q("invalid key modulus");return G(r.n,"base64url").length*8}var Wr=class extends Re{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Ji(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,i=new Uint8Array(o);i.set(n.length>o?t.create().update(n).digest():n);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=t.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),i.fill(0)}update(t){return Ke(this),this.iHash.update(t),this}digestInto(t){Ke(this),De(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:i,blockLen:s,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=i,t.blockLen=s,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ho=(r,t,e)=>new Wr(r,t).update(e).digest();Ho.create=(r,t)=>new Wr(r,t);function Gs(r){r.lowS!==void 0&&Nt("lowS",r.lowS),r.prehash!==void 0&&Nt("prehash",r.prehash)}function Ul(r){let t=ir(r);$t(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:o}=t;if(e){if(!n.eql(o,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...t})}var Fo=class extends Error{constructor(t=""){super(t)}},Zt={Err:Fo,_tlv:{encode:(r,t)=>{let{Err:e}=Zt;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=nr(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let i=n>127?nr(o.length/2|128):"";return nr(r)+i+o+t},decode(r,t){let{Err:e}=Zt,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++],i=!!(o&128),s=0;if(!i)s=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 f=t.subarray(n,n+c);if(f.length!==c)throw new e("tlv.decode: length bytes not complete");if(f[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let u of f)s=s<<8|u;if(n+=c,s<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+s);if(a.length!==s)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+s)}}},_int:{encode(r){let{Err:t}=Zt;if(r<Yt)throw new t("integer: negative integers are not allowed");let e=nr(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}=Zt;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 Wt(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Zt,o=J("signature",r),{v:i,l:s}=n.decode(48,o);if(s.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:f,l:u}=n.decode(2,c);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(f)}},hexFromSig(r){let{_tlv:t,_int:e}=Zt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),i=n+o;return t.encode(48,i)}},Yt=BigInt(0),ut=BigInt(1),v0=BigInt(2),Ws=BigInt(3),S0=BigInt(4);function Nl(r){let t=Ul(r),{Fp:e}=t,n=ae(t.n,t.nBitLength),o=t.toBytes||((g,h,x)=>{let A=h.toAffine();return se(Uint8Array.from([4]),e.toBytes(A.x),e.toBytes(A.y))}),i=t.fromBytes||(g=>{let h=g.subarray(1),x=e.fromBytes(h.subarray(0,e.BYTES)),A=e.fromBytes(h.subarray(e.BYTES,2*e.BYTES));return{x,y:A}});function s(g){let{a:h,b:x}=t,A=e.sqr(g),m=e.mul(A,g);return e.add(e.add(m,e.mul(g,h)),x)}if(!e.eql(e.sqr(t.Gy),s(t.Gx)))throw new Error("bad generator point: equation left != right");function a(g){return Ur(g,ut,t.n)}function c(g){let{allowedPrivateKeyLengths:h,nByteLength:x,wrapPrivateKey:A,n:m}=t;if(h&&typeof g!="bigint"){if(me(g)&&(g=ie(g)),typeof g!="string"||!h.includes(g.length))throw new Error("invalid private key");g=g.padStart(x*2,"0")}let I;try{I=typeof g=="bigint"?g:Wt(J("private key",g,x))}catch{throw new Error("invalid private key, expected hex or "+x+" bytes, got "+typeof g)}return A&&(I=W(I,m)),Pt("private key",I,ut,m),I}function f(g){if(!(g instanceof d))throw new Error("ProjectivePoint expected")}let u=Oe((g,h)=>{let{px:x,py:A,pz:m}=g;if(e.eql(m,e.ONE))return{x,y:A};let I=g.is0();h==null&&(h=I?e.ONE:e.inv(m));let k=e.mul(x,h),C=e.mul(A,h),T=e.mul(m,h);if(I)return{x:e.ZERO,y:e.ZERO};if(!e.eql(T,e.ONE))throw new Error("invZ was invalid");return{x:k,y:C}}),l=Oe(g=>{if(g.is0()){if(t.allowInfinityPoint&&!e.is0(g.py))return;throw new Error("bad point: ZERO")}let{x:h,y:x}=g.toAffine();if(!e.isValid(h)||!e.isValid(x))throw new Error("bad point: x or y not FE");let A=e.sqr(x),m=s(h);if(!e.eql(A,m))throw new Error("bad point: equation left != right");if(!g.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class d{constructor(h,x,A){if(h==null||!e.isValid(h))throw new Error("x required");if(x==null||!e.isValid(x))throw new Error("y required");if(A==null||!e.isValid(A))throw new Error("z required");this.px=h,this.py=x,this.pz=A,Object.freeze(this)}static fromAffine(h){let{x,y:A}=h||{};if(!h||!e.isValid(x)||!e.isValid(A))throw new Error("invalid affine point");if(h instanceof d)throw new Error("projective point not allowed");let m=I=>e.eql(I,e.ZERO);return m(x)&&m(A)?d.ZERO:new d(x,A,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let x=e.invertBatch(h.map(A=>A.pz));return h.map((A,m)=>A.toAffine(x[m])).map(d.fromAffine)}static fromHex(h){let x=d.fromAffine(i(J("pointHex",h)));return x.assertValidity(),x}static fromPrivateKey(h){return d.BASE.multiply(c(h))}static msm(h,x){return Mr(d,n,h,x)}_setWindowSize(h){w.setWindowSize(this,h)}assertValidity(){l(this)}hasEvenY(){let{y:h}=this.toAffine();if(e.isOdd)return!e.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){f(h);let{px:x,py:A,pz:m}=this,{px:I,py:k,pz:C}=h,T=e.eql(e.mul(x,C),e.mul(I,m)),P=e.eql(e.mul(A,C),e.mul(k,m));return T&&P}negate(){return new d(this.px,e.neg(this.py),this.pz)}double(){let{a:h,b:x}=t,A=e.mul(x,Ws),{px:m,py:I,pz:k}=this,C=e.ZERO,T=e.ZERO,P=e.ZERO,L=e.mul(m,m),Y=e.mul(I,I),F=e.mul(k,k),N=e.mul(m,I);return N=e.add(N,N),P=e.mul(m,k),P=e.add(P,P),C=e.mul(h,P),T=e.mul(A,F),T=e.add(C,T),C=e.sub(Y,T),T=e.add(Y,T),T=e.mul(C,T),C=e.mul(N,C),P=e.mul(A,P),F=e.mul(h,F),N=e.sub(L,F),N=e.mul(h,N),N=e.add(N,P),P=e.add(L,L),L=e.add(P,L),L=e.add(L,F),L=e.mul(L,N),T=e.add(T,L),F=e.mul(I,k),F=e.add(F,F),L=e.mul(F,N),C=e.sub(C,L),P=e.mul(F,Y),P=e.add(P,P),P=e.add(P,P),new d(C,T,P)}add(h){f(h);let{px:x,py:A,pz:m}=this,{px:I,py:k,pz:C}=h,T=e.ZERO,P=e.ZERO,L=e.ZERO,Y=t.a,F=e.mul(t.b,Ws),N=e.mul(x,I),st=e.mul(A,k),v=e.mul(m,C),B=e.add(x,A),_=e.add(I,k);B=e.mul(B,_),_=e.add(N,st),B=e.sub(B,_),_=e.add(x,m);let b=e.add(I,C);return _=e.mul(_,b),b=e.add(N,v),_=e.sub(_,b),b=e.add(A,m),T=e.add(k,C),b=e.mul(b,T),T=e.add(st,v),b=e.sub(b,T),L=e.mul(Y,_),T=e.mul(F,v),L=e.add(T,L),T=e.sub(st,L),L=e.add(st,L),P=e.mul(T,L),st=e.add(N,N),st=e.add(st,N),v=e.mul(Y,v),_=e.mul(F,_),st=e.add(st,v),v=e.sub(N,v),v=e.mul(Y,v),_=e.add(_,v),N=e.mul(st,_),P=e.add(P,N),N=e.mul(b,_),T=e.mul(B,T),T=e.sub(T,N),N=e.mul(B,st),L=e.mul(b,L),L=e.add(L,N),new d(T,P,L)}subtract(h){return this.add(h.negate())}is0(){return this.equals(d.ZERO)}wNAF(h){return w.wNAFCached(this,h,d.normalizeZ)}multiplyUnsafe(h){let{endo:x,n:A}=t;Pt("scalar",h,Yt,A);let m=d.ZERO;if(h===Yt)return m;if(this.is0()||h===ut)return this;if(!x||w.hasPrecomputes(this))return w.wNAFCachedUnsafe(this,h,d.normalizeZ);let{k1neg:I,k1:k,k2neg:C,k2:T}=x.splitScalar(h),P=m,L=m,Y=this;for(;k>Yt||T>Yt;)k&ut&&(P=P.add(Y)),T&ut&&(L=L.add(Y)),Y=Y.double(),k>>=ut,T>>=ut;return I&&(P=P.negate()),C&&(L=L.negate()),L=new d(e.mul(L.px,x.beta),L.py,L.pz),P.add(L)}multiply(h){let{endo:x,n:A}=t;Pt("scalar",h,ut,A);let m,I;if(x){let{k1neg:k,k1:C,k2neg:T,k2:P}=x.splitScalar(h),{p:L,f:Y}=this.wNAF(C),{p:F,f:N}=this.wNAF(P);L=w.constTimeNegate(k,L),F=w.constTimeNegate(T,F),F=new d(e.mul(F.px,x.beta),F.py,F.pz),m=L.add(F),I=Y.add(N)}else{let{p:k,f:C}=this.wNAF(h);m=k,I=C}return d.normalizeZ([m,I])[0]}multiplyAndAddUnsafe(h,x,A){let m=d.BASE,I=(C,T)=>T===Yt||T===ut||!C.equals(m)?C.multiplyUnsafe(T):C.multiply(T),k=I(this,x).add(I(h,A));return k.is0()?void 0:k}toAffine(h){return u(this,h)}isTorsionFree(){let{h,isTorsionFree:x}=t;if(h===ut)return!0;if(x)return x(d,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:x}=t;return h===ut?this:x?x(d,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return Nt("isCompressed",h),this.assertValidity(),o(d,this,h)}toHex(h=!0){return Nt("isCompressed",h),ie(this.toRawBytes(h))}}d.BASE=new d(t.Gx,t.Gy,e.ONE),d.ZERO=new d(e.ZERO,e.ONE,e.ZERO);let y=t.nBitLength,w=Or(d,t.endo?Math.ceil(y/2):y);return{CURVE:t,ProjectivePoint:d,normPrivateKeyToScalar:c,weierstrassEquation:s,isWithinCurveOrder:a}}function Ol(r){let t=ir(r);return $t(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function $s(r){let t=Ol(r),{Fp:e,n}=t,o=e.BYTES+1,i=2*e.BYTES+1;function s(v){return W(v,n)}function a(v){return Nr(v,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:f,weierstrassEquation:u,isWithinCurveOrder:l}=Nl({...t,toBytes(v,B,_){let b=B.toAffine(),p=e.toBytes(b.x),E=se;return Nt("isCompressed",_),_?E(Uint8Array.from([B.hasEvenY()?2:3]),p):E(Uint8Array.from([4]),p,e.toBytes(b.y))},fromBytes(v){let B=v.length,_=v[0],b=v.subarray(1);if(B===o&&(_===2||_===3)){let p=Wt(b);if(!Ur(p,ut,e.ORDER))throw new Error("Point is not on curve");let E=u(p),S;try{S=e.sqrt(E)}catch(O){let M=O instanceof Error?": "+O.message:"";throw new Error("Point is not on curve"+M)}let D=(S&ut)===ut;return(_&1)===1!==D&&(S=e.neg(S)),{x:p,y:S}}else if(B===i&&_===4){let p=e.fromBytes(b.subarray(0,e.BYTES)),E=e.fromBytes(b.subarray(e.BYTES,2*e.BYTES));return{x:p,y:E}}else{let p=o,E=i;throw new Error("invalid Point, expected length of "+p+", or uncompressed "+E+", got "+B)}}}),d=v=>ie(ge(v,t.nByteLength));function y(v){let B=n>>ut;return v>B}function w(v){return y(v)?s(-v):v}let g=(v,B,_)=>Wt(v.slice(B,_));class h{constructor(B,_,b){Pt("r",B,ut,n),Pt("s",_,ut,n),this.r=B,this.s=_,b!=null&&(this.recovery=b),Object.freeze(this)}static fromCompact(B){let _=t.nByteLength;return B=J("compactSignature",B,_*2),new h(g(B,0,_),g(B,_,2*_))}static fromDER(B){let{r:_,s:b}=Zt.toSig(J("DER",B));return new h(_,b)}assertValidity(){}addRecoveryBit(B){return new h(this.r,this.s,B)}recoverPublicKey(B){let{r:_,s:b,recovery:p}=this,E=C(J("msgHash",B));if(p==null||![0,1,2,3].includes(p))throw new Error("recovery id invalid");let S=p===2||p===3?_+t.n:_;if(S>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let D=(p&1)===0?"02":"03",R=c.fromHex(D+d(S)),O=a(S),M=s(-E*O),H=s(b*O),z=c.BASE.multiplyAndAddUnsafe(R,M,H);if(!z)throw new Error("point at infinify");return z.assertValidity(),z}hasHighS(){return y(this.s)}normalizeS(){return this.hasHighS()?new h(this.r,s(-this.s),this.recovery):this}toDERRawBytes(){return or(this.toDERHex())}toDERHex(){return Zt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return or(this.toCompactHex())}toCompactHex(){return d(this.r)+d(this.s)}}let x={isValidPrivateKey(v){try{return f(v),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let v=eo(t.n);return ms(t.randomBytes(v),t.n)},precompute(v=8,B=c.BASE){return B._setWindowSize(v),B.multiply(BigInt(3)),B}};function A(v,B=!0){return c.fromPrivateKey(v).toRawBytes(B)}function m(v){let B=me(v),_=typeof v=="string",b=(B||_)&&v.length;return B?b===o||b===i:_?b===2*o||b===2*i:v instanceof c}function I(v,B,_=!0){if(m(v))throw new Error("first arg must be private key");if(!m(B))throw new Error("second arg must be public key");return c.fromHex(B).multiply(f(v)).toRawBytes(_)}let k=t.bits2int||function(v){if(v.length>8192)throw new Error("input is too large");let B=Wt(v),_=v.length*8-t.nBitLength;return _>0?B>>BigInt(_):B},C=t.bits2int_modN||function(v){return s(k(v))},T=be(t.nBitLength);function P(v){return Pt("num < 2^"+t.nBitLength,v,Yt,T),ge(v,t.nByteLength)}function L(v,B,_=Y){if(["recovered","canonical"].some(rt=>rt in _))throw new Error("sign() legacy options not supported");let{hash:b,randomBytes:p}=t,{lowS:E,prehash:S,extraEntropy:D}=_;E==null&&(E=!0),v=J("msgHash",v),Gs(_),S&&(v=J("prehashed msgHash",b(v)));let R=C(v),O=f(B),M=[P(O),P(R)];if(D!=null&&D!==!1){let rt=D===!0?p(e.BYTES):D;M.push(J("extraEntropy",rt))}let H=se(...M),z=R;function ot(rt){let lt=k(rt);if(!l(lt))return;let Et=a(lt),ct=c.BASE.multiply(lt).toAffine(),ft=s(ct.x);if(ft===Yt)return;let Bt=s(Et*s(z+ft*O));if(Bt===Yt)return;let Ct=(ct.x===ft?0:2)|Number(ct.y&ut),We=Bt;return E&&y(Bt)&&(We=w(Bt),Ct^=1),new h(ft,We,Ct)}return{seed:H,k2sig:ot}}let Y={lowS:t.lowS,prehash:!1},F={lowS:t.lowS,prehash:!1};function N(v,B,_=Y){let{seed:b,k2sig:p}=L(v,B,_),E=t;return ls(E.hash.outputLen,E.nByteLength,E.hmac)(b,p)}c.BASE._setWindowSize(8);function st(v,B,_,b=F){let p=v;B=J("msgHash",B),_=J("publicKey",_);let{lowS:E,prehash:S,format:D}=b;if(Gs(b),"strict"in b)throw new Error("options.strict was renamed to lowS");if(D!==void 0&&D!=="compact"&&D!=="der")throw new Error("format must be compact or der");let R=typeof p=="string"||me(p),O=!R&&!D&&typeof p=="object"&&p!==null&&typeof p.r=="bigint"&&typeof p.s=="bigint";if(!R&&!O)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let M,H;try{if(O&&(M=new h(p.r,p.s)),R){try{D!=="compact"&&(M=h.fromDER(p))}catch(Ct){if(!(Ct instanceof Zt.Err))throw Ct}!M&&D!=="der"&&(M=h.fromCompact(p))}H=c.fromHex(_)}catch{return!1}if(!M||E&&M.hasHighS())return!1;S&&(B=t.hash(B));let{r:z,s:ot}=M,rt=C(B),lt=a(ot),Et=s(rt*lt),ct=s(z*lt),ft=c.BASE.multiplyAndAddUnsafe(H,Et,ct)?.toAffine();return ft?s(ft.x)===z:!1}return{CURVE:t,getPublicKey:A,getSharedSecret:I,sign:N,verify:st,ProjectivePoint:c,Signature:h,utils:x}}function Ml(r){return{hash:r,hmac:(t,...e)=>Ho(r,t,Fn(...e)),randomBytes:Kr}}function Zs(r,t){let e=n=>$s({...r,...Ml(n)});return{...e(t),create:e}}var Xs=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Ys=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),ql=BigInt(1),Vo=BigInt(2),js=(r,t)=>(r+t/Vo)/t;function Hl(r){let t=Xs,e=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%t,u=f*f*r%t,l=Q(u,e,t)*u%t,d=Q(l,e,t)*u%t,y=Q(d,Vo,t)*f%t,w=Q(y,o,t)*y%t,g=Q(w,i,t)*w%t,h=Q(g,a,t)*g%t,x=Q(h,c,t)*h%t,A=Q(x,a,t)*g%t,m=Q(A,e,t)*u%t,I=Q(m,s,t)*w%t,k=Q(I,n,t)*f%t,C=Q(k,Vo,t);if(!zo.eql(zo.sqr(C),r))throw new Error("Cannot find square root");return C}var zo=ae(Xs,void 0,void 0,{sqrt:Hl}),Ae=Zs({a:BigInt(0),b:BigInt(7),Fp:zo,n:Ys,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Ys,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-ql*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=e,s=BigInt("0x100000000000000000000000000000000"),a=js(i*r,t),c=js(-n*r,t),f=W(r-a*e-c*o,t),u=W(-a*n-c*i,t),l=f>s,d=u>s;if(l&&(f=t-f),d&&(u=t-u),f>s||u>s)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:l,k1:f,k2neg:d,k2:u}}}},pe),k0=BigInt(0);var D0=Ae.ProjectivePoint;function Qs(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Js(r,t,e){let n=Qe.digest(e instanceof Uint8Array?e:e.subarray());if(Qs(n))return n.then(({digest:o})=>Ae.verify(t,o,r)).catch(o=>{throw new ur(String(o))});try{return Ae.verify(t,n.digest,r)}catch(o){throw new ur(String(o))}}var $r=class{type="secp256k1";raw;_key;constructor(t){this._key=ea(t),this.raw=ta(this._key)}toMultihash(){return Kt.digest(_t(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return $.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:j(this.raw,t.raw)}verify(t,e){return Js(this._key,e,t)}};function Go(r){return new $r(r)}function ta(r){return Ae.ProjectivePoint.fromHex(r).toRawBytes(!0)}function ea(r){try{return Ae.ProjectivePoint.fromHex(r),r}catch(t){throw new Te(String(t))}}function Zr(r,t){let{Type:e,Data:n}=qt.decode(r),o=n??new Uint8Array;switch(e){case nt.RSA:return Oo(o,t);case nt.Ed25519:return uo(o);case nt.secp256k1:return Go(o);case nt.ECDSA:return Hn(o);default:throw new de}}function ra(r){let{Type:t,Data:e}=qt.decode(r.digest),n=e??new Uint8Array;switch(t){case nt.Ed25519:return uo(n);case nt.secp256k1:return Go(n);case nt.ECDSA:return Hn(n);default:throw new de}}function _t(r){return qt.encode({Type:nt[r.type],Data:r.raw})}var na=Symbol.for("nodejs.util.inspect.custom"),Fl=114,dr=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()})`}[Ir]=!0;toString(){return this.string==null&&(this.string=$.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return et.createV1(Fl,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return j(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return j(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[na](){return`PeerId(${this.toString()})`}},hr=class extends dr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},pr=class extends dr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},mr=class extends dr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Vl=2336,yr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Kt.digest(G(this.url))}[na](){return`PeerId(${this.url})`}[Ir]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return et.createV1(Vl,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=U(t)),t.toString()===this.toString())}};var zl=114,oa=2336;function ia(r){if(r.type==="Ed25519")return new pr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new mr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new hr({multihash:r.toCID().multihash,publicKey:r});throw new de}function Wo(r){if(Wl(r))return new hr({multihash:r});if(Gl(r))try{let t=ra(r);if(t.type==="Ed25519")return new pr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new mr({multihash:r,publicKey:t})}catch{let e=U(r.digest);return new yr(new URL(e))}throw new Tr("Supplied PeerID Multihash is invalid")}function Yr(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==zl&&r.code!==oa)throw new Br("Supplied PeerID CID is invalid");if(r.code===oa){let t=U(r.multihash.digest);return new yr(new URL(t))}return Wo(r.multihash)}function Gl(r){return r.code===Kt.code}function Wl(r){return r.code===Qe.code}var gr;(function(r){let t;r.codec=()=>(t==null&&(t=wt((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 i={publicKey:it(0),payloadType:it(0),payload:it(0),signature:it(0)},s=n==null?e.len:e.pos+n;for(;e.pos<s;){let a=e.uint32();switch(a>>>3){case 1:{i.publicKey=e.bytes();break}case 2:{i.payloadType=e.bytes();break}case 3:{i.payload=e.bytes();break}case 5:{i.signature=e.bytes();break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>bt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(gr||(gr={}));var jr=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var He=class r{static createFromProtobuf=async t=>{let e=gr.decode(t),n=Zr(e.publicKey);return new r({publicKey:n,payloadType:e.payloadType,payload:e.payload,signature:e.signature})};static seal=async(t,e)=>{if(e==null)throw new Error("Missing private key");let n=t.domain,o=t.codec,i=t.marshal(),s=sa(n,o,i),a=await e.sign(s.subarray());return new r({publicKey:e.publicKey,payloadType:o,payload:i,signature:a})};static openAndCertify=async(t,e)=>{let n=await r.createFromProtobuf(t);if(!await n.validate(e))throw new jr("Envelope signature is not valid for the given domain");return n};publicKey;payloadType;payload;signature;marshaled;constructor(t){let{publicKey:e,payloadType:n,payload:o,signature:i}=t;this.publicKey=e,this.payloadType=n,this.payload=o,this.signature=i}marshal(){return this.marshaled==null&&(this.marshaled=gr.encode({publicKey:_t(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return j(this.marshal(),t.marshal())}async validate(t){let e=sa(t,this.payloadType,this.payload);return this.publicKey.verify(e.subarray(),this.signature)}},sa=(r,t,e)=>{let n=G(r),o=Mt(n.byteLength),i=Mt(t.length),s=Mt(e.length);return new mt(o,n,i,t,s,e)};function aa(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 Xr=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 i=0,s=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",f=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let d=Number.parseInt(l,t);if(!Number.isNaN(d))return d});if(u===void 0)break;if(i*=t,i+=u,i>f||(s+=1,e!==void 0&&s>e))return}if(s!==0)return!n&&c&&s>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return e[o]=s[0],e[o+1]=s[1],e[o+2]=s[2],e[o+3]=s[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];e[o]=i>>8,e[o+1]=i&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 i=new Uint8Array(14),s=16-(n+2),[a]=t(i.subarray(0,s));return e.set(i.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var ca=45,$l=15,Fe=new Xr;function $o(r){if(!(r.length>$l))return Fe.new(r).parseWith(()=>Fe.readIPv4Addr())}function Zo(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>ca))return Fe.new(r).parseWith(()=>Fe.readIPv6Addr())}function Qr(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>ca)return;let e=Fe.new(r).parseWith(()=>Fe.readIPAddr());if(e)return t&&e.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,e[0],e[1],e[2],e[3]]):e}var iy=parseInt("0xFFFF",16),sy=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function fa(r){return!!$o(r)}function da(r){return!!Zo(r)}function Jr(r){return!!Qr(r)}var ha=fa,Ql=da,Yo=function(r){let t=0;if(r=r.toString().trim(),ha(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(Ql(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let i=ha(e[n]),s;i&&(s=Yo(e[n]),e[n]=U(s.slice(0,2),"base16")),s!=null&&++n<8&&e.splice(n,0,U(s.slice(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let i=[n,1];for(n=9-e.length;n>0;n--)i.push("0");e.splice.apply(e,i)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){let i=parseInt(e[n],16);o[t++]=i>>8&255,o[t++]=i&255}return o}throw new Error("invalid ip address")},pa=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let o=[];for(let i=0;i<e;i++)o.push(r[t+i]);return o.join(".")}if(e===16){let o=[];for(let i=0;i<e;i+=2)o.push(n.getUint16(t+i).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var Ve={},jo={},tf=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];tf.forEach(r=>{let t=ef(...r);jo[t.code]=t,Ve[t.name]=t});function ef(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function Z(r){if(typeof r=="number"){if(jo[r]!=null)return jo[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Ve[r]!=null)return Ve[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Vy=Z("ip4"),zy=Z("ip6"),Gy=Z("ipcidr");function ti(r,t){switch(Z(r).code){case 4:case 41:return nf(t);case 42:return Jo(t);case 43:return U(t,"base10");case 6:case 273:case 33:case 132:return ga(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Jo(t);case 421:return cf(t);case 444:return ya(t);case 445:return ya(t);case 466:return af(t);case 481:return globalThis.encodeURIComponent(Jo(t));default:return U(t,"base16")}}function ei(r,t){switch(Z(r).code){case 4:return ma(t);case 41:return ma(t);case 42:return Qo(t);case 43:return G(t,"base10");case 6:case 273:case 33:case 132:return ri(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Qo(t);case 421:return of(t);case 444:return uf(t);case 445:return lf(t);case 466:return sf(t);case 481:return Qo(globalThis.decodeURIComponent(t));default:return G(t,"base16")}}var Xo=Object.values(Je).map(r=>r.decoder),rf=function(){let r=Xo[0].or(Xo[1]);return Xo.slice(2).forEach(t=>r=r.or(t)),r}();function ma(r){if(!Jr(r))throw new Error("invalid ip address");return Yo(r)}function nf(r){let t=pa(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!Jr(t))throw new Error("invalid ip address");return t}function ri(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function ga(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Qo(r){let t=G(r),e=Uint8Array.from(Mt(t.length));return Tt([e,t],e.length+t.length)}function Jo(r){let t=xe(r);if(r=r.slice(It(t)),r.length!==t)throw new Error("inconsistent lengths");return U(r)}function of(r){let t;r[0]==="Q"||r[0]==="1"?t=Ft($.decode(`z${r}`)).bytes:t=et.parse(r).multihash.bytes;let e=Uint8Array.from(Mt(t.length));return Tt([e,t],e.length+t.length)}function sf(r){let t=rf.decode(r),e=Uint8Array.from(Mt(t.length));return Tt([e,t],e.length+t.length)}function af(r){let t=xe(r),e=r.slice(It(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+U(e,"base64url")}function cf(r){let t=xe(r),e=r.slice(It(t));if(e.length!==t)throw new Error("inconsistent lengths");return U(e,"base58btc")}function uf(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=kt.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=ri(n);return Tt([e,o],e.length+o.length)}function lf(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=kt.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=ri(n);return Tt([e,o],e.length+o.length)}function ya(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=U(t,"base32"),o=ga(e);return`${n}:${o}`}function ba(r){r=ni(r);let t=[],e=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let i=0;i<o.length;i++){let s=o[i],a=Z(s);if(a.size===0){t.push([a.code]),e.push([a.code]);continue}if(i++,i>=o.length)throw new tn("invalid address: "+r);if(a.path===!0){n=ni(o.slice(i).join("/")),t.push([a.code,ei(a.code,n)]),e.push([a.code,n]);break}let c=ei(a.code,o[i]);t.push([a.code,c]),e.push([a.code,ti(a.code,c)])}return{string:wa(e),bytes:en(t),tuples:t,stringTuples:e,path:n}}function oi(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let i=xe(r,o),s=It(i),a=Z(i),c=ff(a,r.slice(o+s));if(c===0){t.push([i]),e.push([i]),o+=s;continue}let f=r.slice(o+s,o+s+c);if(o+=c+s,o>r.length)throw new tn("Invalid address Uint8Array: "+U(r,"base16"));t.push([i,f]);let u=ti(i,f);if(e.push([i,u]),a.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:wa(e),tuples:t,stringTuples:e,path:n}}function wa(r){let t=[];return r.map(e=>{let n=Z(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),ni(t.join("/"))}function en(r){return Tt(r.map(t=>{let e=Z(t[0]),n=Uint8Array.from(Mt(e.code));return t.length>1&&t[1]!=null&&(n=Tt([n,t[1]])),n}))}function ff(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=xe(t instanceof Uint8Array?t:Uint8Array.from(t));return e+It(e)}}function ni(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}var tn=class extends Error{static name="ParseError";name="ParseError";constructor(t){super(`Error parsing address: ${t}`)}};var df=Symbol.for("nodejs.util.inspect.custom"),si=Symbol.for("@multiformats/js-multiaddr/multiaddr"),hf=[Z("dns").code,Z("dns4").code,Z("dns6").code,Z("dnsaddr").code],ii=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},rn=class r{bytes;#t;#e;#r;#a;[si]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=oi(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=ba(t)}else if(nn(t))e=oi(t.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=e.bytes,this.#t=e.string,this.#e=e.tuples,this.#r=e.stringTuples,this.#a=e.path}toString(){return this.#t}toJSON(){return this.toString()}toOptions(){let t,e,n,o,i="",s=Z("tcp"),a=Z("udp"),c=Z("ip4"),f=Z("ip6"),u=Z("dns6"),l=Z("ip6zone");for(let[y,w]of this.stringTuples())y===l.code&&(i=`%${w??""}`),hf.includes(y)&&(e=s.name==="tcp"?"tcp":"udp",o=443,n=`${w??""}${i}`,t=y===u.code?6:4),(y===s.code||y===a.code)&&(e=Z(y).name==="tcp"?"tcp":"udp",o=parseInt(w??"")),(y===c.code||y===f.code)&&(e=Z(y).name==="tcp"?"tcp":"udp",n=`${w??""}${i}`,t=y===f.code?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}}protos(){return this.#e.map(([t])=>Object.assign({},Z(t)))}protoCodes(){return this.#e.map(([t])=>t)}protoNames(){return this.#e.map(([t])=>Z(t).name)}tuples(){return this.#e.map(([t,e])=>e==null?[t]:[t,e])}stringTuples(){return this.#r.map(([t,e])=>e==null?[t]:[t,e])}encapsulate(t){return t=new r(t),new r(this.toString()+t.toString())}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o))}decapsulateCode(t){let e=this.tuples();for(let n=e.length-1;n>=0;n--)if(e[n][0]===t)return new r(en(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===Ve.p2p.code&&t.push([n,o]),n===Ve["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?U($.decode(`z${n}`),"base58btc"):U(et.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#a}equals(t){return j(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(i=>i.resolvable);if(e==null)return[this];let n=xa.get(e.name);if(n==null)throw new ii(`no available resolver for ${e.name}`);return(await n(this,t)).map(i=>jt(i))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[df](){return`Multiaddr(${this.#t})`}};var xa=new Map;function nn(r){return!!r?.[si]}function jt(r){return new rn(r)}var Ea="libp2p-peer-record",va=Uint8Array.from([3,1]);var br;(function(r){let t;(function(n){let o;n.codec=()=>(o==null&&(o=wt((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.multiaddr!=null&&i.multiaddr.byteLength>0&&(s.uint32(10),s.bytes(i.multiaddr)),a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let c={multiaddr:it(0)},f=s==null?i.len:i.pos+s;for(;i.pos<f;){let u=i.uint32();switch(u>>>3){case 1:{c.multiaddr=i.bytes();break}default:{i.skipType(u&7);break}}}return c})),o),n.encode=i=>bt(i,n.codec()),n.decode=(i,s)=>gt(i,n.codec(),s)})(t=r.AddressInfo||(r.AddressInfo={}));let e;r.codec=()=>(e==null&&(e=wt((n,o,i={})=>{if(i.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 s of n.addresses)o.uint32(26),r.AddressInfo.codec().encode(s,o);i.lengthDelimited!==!1&&o.ldelim()},(n,o,i={})=>{let s={peerId:it(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:{s.peerId=n.bytes();break}case 2:{s.seq=n.uint64();break}case 3:{if(i.limits?.addresses!=null&&s.addresses.length===i.limits.addresses)throw new Se('Decode error - map field "addresses" had too many elements');s.addresses.push(r.AddressInfo.codec().decode(n,n.uint32(),{limits:i.limits?.addresses$}));break}default:{n.skipType(c&7);break}}}return s})),e),r.encode=n=>bt(n,r.codec()),r.decode=(n,o)=>gt(n,r.codec(),o)})(br||(br={}));var Ie=class r{static createFromProtobuf=t=>{let e=br.decode(t),n=Wo(Ft(e.peerId)),o=(e.addresses??[]).map(s=>jt(s.multiaddr)),i=e.seq;return new r({peerId:n,multiaddrs:o,seqNumber:i})};static DOMAIN=Ea;static CODEC=va;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=br.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||!aa(this.multiaddrs,t.multiaddrs))}};function pf(r){return r[Symbol.asyncIterator]!=null}function mf(r){if(pf(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 Sa=mf;var ci=Qa(Ia(),1);var xr=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},ui=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},Ba=r=>globalThis.DOMException===void 0?new ui(r):new DOMException(r),Ta=r=>{let t=r.reason===void 0?Ba("This operation was aborted."):r.reason;return t instanceof Error?t:Ba(t)};function Er(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=t,s,a,f=new Promise((u,l)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(t.signal){let{signal:y}=t;y.aborted&&l(Ta(y)),a=()=>{l(Ta(y))},y.addEventListener("abort",a,{once:!0})}if(e===Number.POSITIVE_INFINITY){r.then(u,l);return}let d=new xr;s=i.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(y){l(y)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?u():o instanceof Error?l(o):(d.message=o??`Promise timed out after ${e} milliseconds`,l(d))},e),(async()=>{try{u(await r)}catch(y){l(y)}})()}).finally(()=>{f.clear(),a&&t.signal&&t.signal.removeEventListener("abort",a)});return f.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},f}function li(r,t,e){let n=0,o=r.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;e(r[s],t)<=0?(n=++s,o-=i+1):o=i}return n}var vr=class{#t=[];enqueue(t,e){e={priority:0,...e};let n={priority:e.priority,id:e.id,run:t};if(this.size===0||this.#t[this.size-1].priority>=e.priority){this.#t.push(n);return}let o=li(this.#t,n,(i,s)=>s.priority-i.priority);this.#t.splice(o,0,n)}setPriority(t,e){let n=this.#t.findIndex(i=>i.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[o]=this.#t.splice(n,1);this.enqueue(o.run,{priority:e,id:t})}dequeue(){return this.#t.shift()?.run}filter(t){return this.#t.filter(e=>e.priority===t.priority).map(e=>e.run)}get size(){return this.#t.length}};var ze=class extends ci.default{#t;#e;#r=0;#a;#c;#p=0;#o;#u;#n;#m;#i=0;#l;#s;#y;#w=1n;timeout;constructor(t){if(super(),t={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:vr,...t},!(typeof t.intervalCap=="number"&&t.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${t.intervalCap?.toString()??""}\` (${typeof t.intervalCap})`);if(t.interval===void 0||!(Number.isFinite(t.interval)&&t.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${t.interval?.toString()??""}\` (${typeof t.interval})`);this.#t=t.carryoverConcurrencyCount,this.#e=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#a=t.intervalCap,this.#c=t.interval,this.#n=new t.queueClass,this.#m=t.queueClass,this.concurrency=t.concurrency,this.timeout=t.timeout,this.#y=t.throwOnTimeout===!0,this.#s=t.autoStart===!1}get#x(){return this.#e||this.#r<this.#a}get#E(){return this.#i<this.#l}#v(){this.#i--,this.#f(),this.emit("next")}#S(){this.#b(),this.#g(),this.#u=void 0}get#A(){let t=Date.now();if(this.#o===void 0){let e=this.#p-t;if(e<0)this.#r=this.#t?this.#i:0;else return this.#u===void 0&&(this.#u=setTimeout(()=>{this.#S()},e)),!0}return!1}#f(){if(this.#n.size===0)return this.#o&&clearInterval(this.#o),this.#o=void 0,this.emit("empty"),this.#i===0&&this.emit("idle"),!1;if(!this.#s){let t=!this.#A;if(this.#x&&this.#E){let e=this.#n.dequeue();return e?(this.emit("active"),e(),t&&this.#g(),!0):!1}}return!1}#g(){this.#e||this.#o!==void 0||(this.#o=setInterval(()=>{this.#b()},this.#c),this.#p=Date.now()+this.#c)}#b(){this.#r===0&&this.#i===0&&this.#o&&(clearInterval(this.#o),this.#o=void 0),this.#r=this.#t?this.#i:0,this.#d()}#d(){for(;this.#f(););}get concurrency(){return this.#l}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this.#l=t,this.#d()}async#I(t){return new Promise((e,n)=>{t.addEventListener("abort",()=>{n(t.reason)},{once:!0})})}setPriority(t,e){this.#n.setPriority(t,e)}async add(t,e={}){return e.id??=(this.#w++).toString(),e={timeout:this.timeout,throwOnTimeout:this.#y,...e},new Promise((n,o)=>{this.#n.enqueue(async()=>{this.#i++,this.#r++;try{e.signal?.throwIfAborted();let i=t({signal:e.signal});e.timeout&&(i=Er(Promise.resolve(i),{milliseconds:e.timeout})),e.signal&&(i=Promise.race([i,this.#I(e.signal)]));let s=await i;n(s),this.emit("completed",s)}catch(i){if(i instanceof xr&&!e.throwOnTimeout){n();return}o(i),this.emit("error",i)}finally{this.#v()}},e),this.emit("add"),this.#f()})}async addAll(t,e){return Promise.all(t.map(async n=>this.add(n,e)))}start(){return this.#s?(this.#s=!1,this.#d(),this):this}pause(){this.#s=!0}clear(){this.#n=new this.#m}async onEmpty(){this.#n.size!==0&&await this.#h("empty")}async onSizeLessThan(t){this.#n.size<t||await this.#h("next",()=>this.#n.size<t)}async onIdle(){this.#i===0&&this.#n.size===0||await this.#h("idle")}async#h(t,e){return new Promise(n=>{let o=()=>{e&&!e()||(this.off(t,o),n())};this.on(t,o)})}get size(){return this.#n.size}sizeBy(t){return this.#n.filter(t).length}get pending(){return this.#i}get isPaused(){return this.#s}};var le={},Ge=r=>{r.addEventListener("message",t=>{Ge.dispatchEvent("message",r,t)}),r.port!=null&&r.port.addEventListener("message",t=>{Ge.dispatchEvent("message",r,t)})};Ge.addEventListener=(r,t)=>{le[r]==null&&(le[r]=[]),le[r].push(t)};Ge.removeEventListener=(r,t)=>{le[r]!=null&&(le[r]=le[r].filter(e=>e===t))};Ge.dispatchEvent=function(r,t,e){le[r]!=null&&le[r].forEach(n=>n(t,e))};var fi=Ge;var di="lock:worker:request-read",hi="lock:worker:release-read",pi="lock:master:grant-read",mi="lock:worker:request-write",yi="lock:worker:release-write",gi="lock:master:grant-write";var Pa=(r=21)=>Math.random().toString().substring(2);var La=(r,t,e,n,o)=>(i,s)=>{if(s.data.type!==e)return;let a={type:s.data.type,name:s.data.name,identifier:s.data.identifier};r.dispatchEvent(new MessageEvent(t,{data:{name:a.name,handler:async()=>{i.postMessage({type:o,name:a.name,identifier:a.identifier}),await new Promise(c=>{let f=u=>{if(u?.data==null)return;let l={type:u.data.type,name:u.data.name,identifier:u.data.identifier};l.type===n&&l.identifier===a.identifier&&(i.removeEventListener("message",f),c())};i.addEventListener("message",f)})}}}))},_a=(r,t,e,n)=>async()=>{let o=Pa();return globalThis.postMessage({type:t,identifier:o,name:r}),new Promise(i=>{let s=a=>{if(a?.data==null)return;let c={type:a.data.type,identifier:a.data.identifier};c.type===e&&c.identifier===o&&(globalThis.removeEventListener("message",s),i(()=>{globalThis.postMessage({type:n,identifier:o,name:r})}))};globalThis.addEventListener("message",s)})},bf={singleProcess:!1},Ca=r=>{if(r=Object.assign({},bf,r),!!globalThis.document||r.singleProcess){let e=new EventTarget;return fi.addEventListener("message",La(e,"requestReadLock",di,hi,pi)),fi.addEventListener("message",La(e,"requestWriteLock",mi,yi,gi)),e}return{isWorker:!0,readLock:e=>_a(e,di,pi,hi),writeLock:e=>_a(e,mi,gi,yi)}};var Be={},fe;async function bi(r,t){let e,n=new Promise(o=>{e=o});return r.add(async()=>Er((async()=>{await new Promise(o=>{e(()=>{o()})})})(),{milliseconds:t.timeout})),n}var wf=(r,t)=>{if(fe.isWorker===!0)return{readLock:fe.readLock(r,t),writeLock:fe.writeLock(r,t)};let e=new ze({concurrency:1}),n;return{async readLock(){if(n!=null)return bi(n,t);n=new ze({concurrency:t.concurrency,autoStart:!1});let o=n,i=bi(n,t);return e.add(async()=>{o.start(),await o.onIdle().then(()=>{n===o&&(n=null)})}),i},async writeLock(){return n=null,bi(e,t)}}},xf={name:"lock",concurrency:1/0,timeout:846e5,singleProcess:!1};function wi(r){let t=Object.assign({},xf,r);return fe==null&&(fe=Ca(t),fe.isWorker!==!0&&(fe.addEventListener("requestReadLock",e=>{Be[e.data.name]!=null&&Be[e.data.name].readLock().then(async n=>e.data.handler().finally(()=>{n()}))}),fe.addEventListener("requestWriteLock",async e=>{Be[e.data.name]!=null&&Be[e.data.name].writeLock().then(async n=>e.data.handler().finally(()=>{n()}))}))),Be[t.name]==null&&(Be[t.name]=wf(t.name,t)),Be[t.name]}var Xt;(function(r){let t;(function(o){let i;o.codec=()=>(i==null&&(i=wt((s,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),s.key!=null&&s.key!==""&&(a.uint32(10),a.string(s.key)),s.value!=null&&s.value.byteLength>0&&(a.uint32(18),a.bytes(s.value)),c.lengthDelimited!==!1&&a.ldelim()},(s,a,c={})=>{let f={key:"",value:it(0)},u=a==null?s.len:s.pos+a;for(;s.pos<u;){let l=s.uint32();switch(l>>>3){case 1:{f.key=s.string();break}case 2:{f.value=s.bytes();break}default:{s.skipType(l&7);break}}}return f})),i),o.encode=s=>bt(s,o.codec()),o.decode=(s,a)=>gt(s,o.codec(),a)})(t=r.Peer$metadataEntry||(r.Peer$metadataEntry={}));let e;(function(o){let i;o.codec=()=>(i==null&&(i=wt((s,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),s.key!=null&&s.key!==""&&(a.uint32(10),a.string(s.key)),s.value!=null&&(a.uint32(18),an.codec().encode(s.value,a)),c.lengthDelimited!==!1&&a.ldelim()},(s,a,c={})=>{let f={key:""},u=a==null?s.len:s.pos+a;for(;s.pos<u;){let l=s.uint32();switch(l>>>3){case 1:{f.key=s.string();break}case 2:{f.value=an.codec().decode(s,s.uint32(),{limits:c.limits?.value});break}default:{s.skipType(l&7);break}}}return f})),i),o.encode=s=>bt(s,o.codec()),o.decode=(s,a)=>gt(s,o.codec(),a)})(e=r.Peer$tagsEntry||(r.Peer$tagsEntry={}));let n;r.codec=()=>(n==null&&(n=wt((o,i,s={})=>{if(s.lengthDelimited!==!1&&i.fork(),o.addresses!=null)for(let a of o.addresses)i.uint32(10),sn.codec().encode(a,i);if(o.protocols!=null)for(let a of o.protocols)i.uint32(18),i.string(a);if(o.publicKey!=null&&(i.uint32(34),i.bytes(o.publicKey)),o.peerRecordEnvelope!=null&&(i.uint32(42),i.bytes(o.peerRecordEnvelope)),o.metadata!=null&&o.metadata.size!==0)for(let[a,c]of o.metadata.entries())i.uint32(50),r.Peer$metadataEntry.codec().encode({key:a,value:c},i);if(o.tags!=null&&o.tags.size!==0)for(let[a,c]of o.tags.entries())i.uint32(58),r.Peer$tagsEntry.codec().encode({key:a,value:c},i);o.updated!=null&&(i.uint32(64),i.uint64Number(o.updated)),s.lengthDelimited!==!1&&i.ldelim()},(o,i,s={})=>{let a={addresses:[],protocols:[],metadata:new Map,tags:new Map},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let f=o.uint32();switch(f>>>3){case 1:{if(s.limits?.addresses!=null&&a.addresses.length===s.limits.addresses)throw new Se('Decode error - map field "addresses" had too many elements');a.addresses.push(sn.codec().decode(o,o.uint32(),{limits:s.limits?.addresses$}));break}case 2:{if(s.limits?.protocols!=null&&a.protocols.length===s.limits.protocols)throw new Se('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(s.limits?.metadata!=null&&a.metadata.size===s.limits.metadata)throw new cr('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(s.limits?.tags!=null&&a.tags.size===s.limits.tags)throw new cr('Decode error - map field "tags" had too many elements');let u=r.Peer$tagsEntry.codec().decode(o,o.uint32(),{limits:{value:s.limits?.tags$value}});a.tags.set(u.key,u.value);break}case 8:{a.updated=o.uint64Number();break}default:{o.skipType(f&7);break}}}return a})),n),r.encode=o=>bt(o,r.codec()),r.decode=(o,i)=>gt(o,r.codec(),i)})(Xt||(Xt={}));var sn;(function(r){let t;r.codec=()=>(t==null&&(t=wt((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 i={multiaddr:it(0)},s=n==null?e.len:e.pos+n;for(;e.pos<s;){let a=e.uint32();switch(a>>>3){case 1:{i.multiaddr=e.bytes();break}case 2:{i.isCertified=e.bool();break}case 3:{i.observed=e.uint64Number();break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>bt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(sn||(sn={}));var an;(function(r){let t;r.codec=()=>(t==null&&(t=wt((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 i={value:0},s=n==null?e.len:e.pos+n;for(;e.pos<s;){let a=e.uint32();switch(a>>>3){case 1:{i.value=e.uint32();break}case 2:{i.expiry=e.uint64();break}default:{e.skipType(a&7);break}}}return i})),t),r.encode=e=>bt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(an||(an={}));function Ef(r,t){if(r.publicKey!=null||t.publicKey==null)return r;let e;if(r.type==="RSA"){let o=$.decode(`z${r}`);e=Ft(o)}let n=Zr(t.publicKey,e);return ia(n)}function cn(r,t,e){let n=Xt.decode(t);return un(r,n,e)}function un(r,t,e){let n=new Map,o=BigInt(Date.now());for(let[i,s]of t.tags.entries())s.expiry!=null&&s.expiry<o||n.set(i,s);return{...t,id:Ef(r,t),addresses:t.addresses.filter(({observed:i})=>i!=null&&i>Date.now()-e).map(({multiaddr:i,isCertified:s})=>({multiaddr:jt(i),isCertified:s??!1})),metadata:t.metadata,peerRecordEnvelope:t.peerRecordEnvelope??void 0,tags:n}}function ka(r,t){return vf(r.addresses,t.addresses)&&Sf(r.protocols,t.protocols)&&Af(r.publicKey,t.publicKey)&&If(r.peerRecordEnvelope,t.peerRecordEnvelope)&&Bf(r.metadata,t.metadata)&&Tf(r.tags,t.tags)}function vf(r,t){return Ka(r,t,(e,n)=>!(e.isCertified!==n.isCertified||!j(e.multiaddr,n.multiaddr)))}function Sf(r,t){return Ka(r,t,(e,n)=>e===n)}function Af(r,t){return Da(r,t)}function If(r,t){return Da(r,t)}function Bf(r,t){return Ra(r,t,(e,n)=>j(e,n))}function Tf(r,t){return Ra(r,t,(e,n)=>e.value===n.value&&e.expiry===n.expiry)}function Da(r,t){return r==null&&t==null?!0:r!=null&&t!=null?j(r,t):!1}function Ka(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 Ra(r,t,e){if(r.size!==t.size)return!1;for(let[n,o]of r.entries()){let i=t.get(n);if(i==null||!e(o,i))return!1}return!0}var Qt="/",Ua=new TextEncoder().encode(Qt),ln=Ua[0],fn=class r{_buf;constructor(t,e){if(typeof t=="string")this._buf=G(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]!==ln)throw new Error("Invalid key")}toString(t="utf8"){return U(this._buf,t)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(t){return new r(t.join(Qt))}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=Ua),this._buf[0]!==ln){let t=new Uint8Array(this._buf.byteLength+1);t.fill(ln,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===ln;)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 i=e[o],s=n[o];if(i<s)return!0;if(i>s)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(Qt).slice(1)}type(){return Pf(this.baseNamespace())}name(){return Lf(this.baseNamespace())}instance(t){return new r(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(Qt)||(t+=Qt),t+=this.type(),new r(t)}parent(){let t=this.list();return t.length===1?new r(Qt):new r(t.slice(0,-1).join(Qt))}child(t){return this.toString()===Qt?t:t.toString()===Qt?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(),..._f(t.map(e=>e.namespaces()))])}};function Pf(r){let t=r.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function Lf(r){let t=r.split(":");return t[t.length-1]}function _f(r){return[].concat(...r)}var xi="/peers/";function Sr(r){if(!Ii(r)||r.type==null)throw new q("Invalid PeerId");let t=r.toCID().toString();return new fn(`${xi}${t}`)}async function Na(r,t,e,n){let o=new Map;for(let i of e){if(i==null)continue;if(i.multiaddr instanceof Uint8Array&&(i.multiaddr=jt(i.multiaddr)),!nn(i.multiaddr))throw new q("Multiaddr was invalid");if(!await t(r,i.multiaddr))continue;let s=i.isCertified??!1,a=i.multiaddr.toString(),c=o.get(a);c!=null?i.isCertified=c.isCertified||s:o.set(a,{multiaddr:i.multiaddr,isCertified:s})}return[...o.values()].sort((i,s)=>i.multiaddr.toString().localeCompare(s.multiaddr.toString())).map(({isCertified:i,multiaddr:s})=>({isCertified:i,multiaddr:s.bytes}))}async function hn(r,t,e,n){if(t==null)throw new q("Invalid PeerData");if(t.publicKey!=null&&r.publicKey!=null&&!t.publicKey.equals(r.publicKey))throw new q("publicKey bytes do not match peer id publicKey bytes");let o=n.existingPeer?.peer;if(o!=null&&!r.equals(o.id))throw new q("peer id did not match existing peer id");let i=o?.addresses??[],s=new Set(o?.protocols??[]),a=o?.metadata??new Map,c=o?.tags??new Map,f=o?.peerRecordEnvelope;if(e==="patch"){if((t.multiaddrs!=null||t.addresses!=null)&&(i=[],t.multiaddrs!=null&&i.push(...t.multiaddrs.map(d=>({isCertified:!1,multiaddr:d}))),t.addresses!=null&&i.push(...t.addresses)),t.protocols!=null&&(s=new Set(t.protocols)),t.metadata!=null){let d=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);a=dn(d,{validate:Oa})}if(t.tags!=null){let d=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags);c=dn(d,{validate:Ma,map:qa})}t.peerRecordEnvelope!=null&&(f=t.peerRecordEnvelope)}if(e==="merge"){if(t.multiaddrs!=null&&i.push(...t.multiaddrs.map(d=>({isCertified:!1,multiaddr:d}))),t.addresses!=null&&i.push(...t.addresses),t.protocols!=null&&(s=new Set([...s,...t.protocols])),t.metadata!=null){let d=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);for(let[y,w]of d)w==null?a.delete(y):a.set(y,w);a=dn([...a.entries()],{validate:Oa})}if(t.tags!=null){let d=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags),y=new Map(c);for(let[w,g]of d)g==null?y.delete(w):y.set(w,g);c=dn([...y.entries()],{validate:Ma,map:qa})}t.peerRecordEnvelope!=null&&(f=t.peerRecordEnvelope)}let u;o?.id.publicKey!=null?u=_t(o.id.publicKey):t.publicKey!=null?u=_t(t.publicKey):r.publicKey!=null&&(u=_t(r.publicKey));let l={addresses:await Na(r,n.addressFilter??(async()=>!0),i,n.existingPeer?.peerPB.addresses),protocols:[...s.values()].sort((d,y)=>d.localeCompare(y)),metadata:a,tags:c,publicKey:u,peerRecordEnvelope:f};return l.addresses.forEach(d=>{d.observed=n.existingPeer?.peerPB.addresses?.find(y=>j(y.multiaddr,y.multiaddr))?.observed??Date.now()}),r.type!=="RSA"&&delete l.publicKey,l}function dn(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(([i],[s])=>i.localeCompare(s)))o!=null&&e.set(n,t.map?.(n,o)??o);return e}function Oa(r,t){if(typeof r!="string")throw new q("Metadata key must be a string");if(!(t instanceof Uint8Array))throw new q("Metadata value must be a Uint8Array")}function Ma(r,t){if(typeof r!="string")throw new q("Tag name must be a string");if(t.value!=null){if(parseInt(`${t.value}`,10)!==t.value)throw new q("Tag value must be an integer");if(t.value<0||t.value>100)throw new q("Tag value must be between 0-100")}if(t.ttl!=null){if(parseInt(`${t.ttl}`,10)!==t.ttl)throw new q("Tag ttl must be an integer");if(t.ttl<0)throw new q("Tag ttl must be between greater than 0")}}function qa(r,t){let e;return t.expiry!=null&&(e=t.expiry),t.ttl!=null&&(e=BigInt(Date.now()+Number(t.ttl))),{value:t.value??0,expiry:e}}function Ha(r){let t=r.toString().split("/")[2],e=et.parse(t,kt);return Yr(e)}function Ei(r,t,e){let n=Ha(r);return cn(n,t,e)}function Cf(r,t){return{prefix:xi,filters:(r.filters??[]).map(e=>({key:n,value:o})=>e(Ei(n,o,t))),orders:(r.orders??[]).map(e=>(n,o)=>e(Ei(n.key,n.value,t),Ei(o.key,o.value,t)))}}var pn=class{peerId;datastore;lock;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.lock=wi({name:"peer-store",singleProcess:!0}),this.maxAddressAge=e.maxAddressAge??36e5,this.maxPeerAge=e.maxPeerAge??216e5}async has(t){try{return await this.load(t),!0}catch(e){if(e.name!=="NotFoundError")throw e}return!1}async delete(t){this.peerId.equals(t)||await this.datastore.delete(Sr(t))}async load(t){let e=Sr(t),n=await this.datastore.get(e),o=Xt.decode(n);if(this.#r(t,o))throw await this.datastore.delete(e),new $e;return un(t,o,this.peerId.equals(t)?1/0:this.maxAddressAge)}async save(t,e){let n=await this.#t(t),o=await hn(t,e,"patch",{addressFilter:this.addressFilter});return this.#e(t,o,n)}async patch(t,e){let n=await this.#t(t),o=await hn(t,e,"patch",{addressFilter:this.addressFilter,existingPeer:n});return this.#e(t,o,n)}async merge(t,e){let n=await this.#t(t),o=await hn(t,e,"merge",{addressFilter:this.addressFilter,existingPeer:n});return this.#e(t,o,n)}async*all(t){for await(let{key:e,value:n}of this.datastore.query(Cf(t??{},this.maxAddressAge))){let o=Ha(e);if(o.equals(this.peerId))continue;let i=Xt.decode(n);if(this.#r(o,i)){await this.datastore.delete(e);continue}yield un(o,i,this.peerId.equals(o)?1/0:this.maxAddressAge)}}async#t(t){try{let e=Sr(t),n=await this.datastore.get(e),o=Xt.decode(n);if(this.#r(t,o))throw await this.datastore.delete(e),new $e;return{peerPB:o,peer:cn(t,n,this.maxAddressAge)}}catch(e){e.name!=="NotFoundError"&&this.log.error("invalid peer data found in peer store - %e",e)}}async#e(t,e,n){e.updated=Date.now();let o=Xt.encode(e);return await this.datastore.put(Sr(t),o),{peer:cn(t,o,this.maxAddressAge),previous:n?.peer,updated:n==null||!ka(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,i=e.addresses.filter(s=>s.observed!=null&&s.observed>o);return n&&i.length===0}};var vi=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 pn(t,e)}[Symbol.toStringTag]="@libp2p/peer-store";async forEach(t,e){this.log.trace("forEach await read lock");let n=await this.store.lock.readLock();this.log.trace("forEach got read lock");try{for await(let o of this.store.all(e))t(o)}finally{this.log.trace("forEach release read lock"),n()}}async all(t){this.log.trace("all await read lock");let e=await this.store.lock.readLock();this.log.trace("all got read lock");try{return await Sa(this.store.all(t))}finally{this.log.trace("all release read lock"),e()}}async delete(t){this.log.trace("delete await write lock");let e=await this.store.lock.writeLock();this.log.trace("delete got write lock");try{await this.store.delete(t)}finally{this.log.trace("delete release write lock"),e()}}async has(t){this.log.trace("has await read lock");let e=await this.store.lock.readLock();this.log.trace("has got read lock");try{return await this.store.has(t)}finally{this.log.trace("has release read lock"),e()}}async get(t){this.log.trace("get await read lock");let e=await this.store.lock.readLock();this.log.trace("get got read lock");try{return await this.store.load(t)}finally{this.log.trace("get release read lock"),e()}}async save(t,e){this.log.trace("save await write lock");let n=await this.store.lock.writeLock();this.log.trace("save got write lock");try{let o=await this.store.save(t,e);return this.#t(t,o),o.peer}finally{this.log.trace("save release write lock"),n()}}async patch(t,e){this.log.trace("patch await write lock");let n=await this.store.lock.writeLock();this.log.trace("patch got write lock");try{let o=await this.store.patch(t,e);return this.#t(t,o),o.peer}finally{this.log.trace("patch release write lock"),n()}}async merge(t,e){this.log.trace("merge await write lock");let n=await this.store.lock.writeLock();this.log.trace("merge got write lock");try{let o=await this.store.merge(t,e);return this.#t(t,o),o.peer}finally{this.log.trace("merge release write lock"),n()}}async consumePeerRecord(t,e){let n=await He.openAndCertify(t,Ie.DOMAIN),o=Yr(n.publicKey.toCID());if(e?.equals(o)===!1)return this.log("envelope peer id was not the expected peer id - expected: %p received: %p",e,o),!1;let i=Ie.createFromProtobuf(n.payload),s;try{s=await this.get(o)}catch(a){if(a.name!=="NotFoundError")throw a}if(s?.peerRecordEnvelope!=null){let a=await He.createFromProtobuf(s.peerRecordEnvelope),c=Ie.createFromProtobuf(a.payload);if(c.seqNumber>=i.seqNumber)return this.log("sequence number was lower or equal to existing sequence number - stored: %d received: %d",c.seqNumber,i.seqNumber),!1}return await this.patch(i.peerId,{peerRecordEnvelope:t,addresses:i.multiaddrs.map(a=>({isCertified:!0,multiaddr:a}))}),!0}#t(t,e){e.updated&&(this.peerId.equals(t)?this.events.safeDispatchEvent("self:peer:update",{detail:e}):this.events.safeDispatchEvent("peer:update",{detail:e}))}};function kf(r,t={}){return new vi(r,t)}return Ja(Df);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/hashes/esm/utils.js:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/peer-store",
3
- "version": "11.1.3",
3
+ "version": "11.1.4",
4
4
  "description": "Stores information about peers libp2p knows on the network",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/peer-store#readme",
@@ -59,10 +59,10 @@
59
59
  "test:electron-main": "aegir test -t electron-main"
60
60
  },
61
61
  "dependencies": {
62
- "@libp2p/crypto": "^5.1.0",
63
- "@libp2p/interface": "^2.8.0",
64
- "@libp2p/peer-id": "^5.1.1",
65
- "@libp2p/peer-record": "^8.0.26",
62
+ "@libp2p/crypto": "^5.1.1",
63
+ "@libp2p/interface": "^2.9.0",
64
+ "@libp2p/peer-id": "^5.1.2",
65
+ "@libp2p/peer-record": "^8.0.27",
66
66
  "@multiformats/multiaddr": "^12.3.3",
67
67
  "interface-datastore": "^8.3.1",
68
68
  "it-all": "^3.0.6",
@@ -73,7 +73,7 @@
73
73
  "uint8arrays": "^5.1.0"
74
74
  },
75
75
  "devDependencies": {
76
- "@libp2p/logger": "^5.1.14",
76
+ "@libp2p/logger": "^5.1.15",
77
77
  "@types/sinon": "^17.0.3",
78
78
  "aegir": "^45.1.1",
79
79
  "benchmark": "^2.1.4",