@libp2p/peer-store 11.2.2 → 11.2.3-ae595d8db

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,11 +1,11 @@
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 hc=Object.create;var kr=Object.defineProperty;var pc=Object.getOwnPropertyDescriptor;var mc=Object.getOwnPropertyNames;var yc=Object.getPrototypeOf,gc=Object.prototype.hasOwnProperty;var bc=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),At=(r,t)=>{for(var e in t)kr(r,e,{get:t[e],enumerable:!0})},Ks=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of mc(t))!gc.call(r,o)&&o!==e&&kr(r,o,{get:()=>t[o],enumerable:!(n=pc(t,o))||n.enumerable});return r};var wc=(r,t,e)=>(e=r!=null?hc(yc(r)):{},Ks(t||!r||!r.__esModule?kr(e,"default",{value:r,enumerable:!0}):e,r)),xc=r=>Ks(kr({},"__esModule",{value:!0}),r);var Wa=bc((gg,bs)=>{"use strict";var gf=Object.prototype.hasOwnProperty,Et="~";function Br(){}Object.create&&(Br.prototype=Object.create(null),new Br().__proto__||(Et=!1));function bf(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function Ga(r,t,e,n,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var s=new bf(e,n||r,o),i=Et?Et+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 mn(r,t){--r._eventsCount===0?r._events=new Br:delete r._events[t]}function pt(){this._events=new Br,this._eventsCount=0}pt.prototype.eventNames=function(){var t=[],e,n;if(this._eventsCount===0)return t;for(n in e=this._events)gf.call(e,n)&&t.push(Et?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};pt.prototype.listeners=function(t){var e=Et?Et+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};pt.prototype.listenerCount=function(t){var e=Et?Et+t:t,n=this._events[e];return n?n.fn?1:n.length:0};pt.prototype.emit=function(t,e,n,o,s,i){var a=Et?Et+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 p=c.length,y;for(l=0;l<p;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 Ga(this,t,e,n,!1)};pt.prototype.once=function(t,e,n){return Ga(this,t,e,n,!0)};pt.prototype.removeListener=function(t,e,n,o){var s=Et?Et+t:t;if(!this._events[s])return this;if(!e)return mn(this,s),this;var i=this._events[s];if(i.fn)i.fn===e&&(!o||i.once)&&(!n||i.context===n)&&mn(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:mn(this,s)}return this};pt.prototype.removeAllListeners=function(t){var e;return t?(e=Et?Et+t:t,this._events[e]&&mn(this,e)):(this._events=new Br,this._eventsCount=0),this};pt.prototype.off=pt.prototype.removeListener;pt.prototype.addListener=pt.prototype.on;pt.prefixed=Et;pt.EventEmitter=pt;typeof bs<"u"&&(bs.exports=pt)});var Df={};At(Df,{persistentPeerStore:()=>Rf});var Cr=Symbol.for("@libp2p/peer-id");function Us(r){return!!r?.[Cr]}var H=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Le=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Xe=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var Rr=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},Dr=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 _n={};At(_n,{base58btc:()=>Z,base58flickr:()=>Tc});var Of=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 Ft(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 Ec(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(A){if(A instanceof Uint8Array||(ArrayBuffer.isView(A)?A=new Uint8Array(A.buffer,A.byteOffset,A.byteLength):Array.isArray(A)&&(A=Uint8Array.from(A))),!(A instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(A.length===0)return"";for(var g=0,R=0,D=0,F=A.length;D!==F&&A[D]===0;)D++,g++;for(var S=(F-D)*u+1>>>0,d=new Uint8Array(S);D!==F;){for(var b=A[D],I=0,B=S-1;(b!==0||I<R)&&B!==-1;B--,I++)b+=256*d[B]>>>0,d[B]=b%a>>>0,b=b/a>>>0;if(b!==0)throw new Error("Non-zero carry");R=I,D++}for(var T=S-R;T!==S&&d[T]===0;)T++;for(var C=c.repeat(g);T<S;++T)C+=r.charAt(d[T]);return C}function p(A){if(typeof A!="string")throw new TypeError("Expected String");if(A.length===0)return new Uint8Array;var g=0;if(A[g]!==" "){for(var R=0,D=0;A[g]===c;)R++,g++;for(var F=(A.length-g)*f+1>>>0,S=new Uint8Array(F);A[g];){var d=e[A.charCodeAt(g)];if(d===255)return;for(var b=0,I=F-1;(d!==0||b<D)&&I!==-1;I--,b++)d+=a*S[I]>>>0,S[I]=d%256>>>0,d=d/256>>>0;if(d!==0)throw new Error("Non-zero carry");D=b,g++}if(A[g]!==" "){for(var B=F-D;B!==F&&S[B]===0;)B++;for(var T=new Uint8Array(R+(F-B)),C=R;B!==F;)T[C++]=S[B++];return T}}}function y(A){var g=p(A);if(g)return g;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:p,decode:y}}var vc=Ec,Ac=vc,Hs=Ac;var In=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")}},Bn=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)}},Tn=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 Tn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Pn=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 In(t,e,n),this.decoder=new Bn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ke({name:r,prefix:t,encode:e,decode:n}){return new Pn(r,t,e,n)}function oe({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Hs(e,r);return ke({prefix:t,name:r,encode:n,decode:s=>Ft(o(s))})}function Sc(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let f=0;f<o;++f){let u=t[r[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|u,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Ic(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 Bc(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function J({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=Bc(n);return ke({prefix:t,name:r,encode(s){return Ic(s,n,e)},decode(s){return Sc(s,o,e,r)}})}var Z=oe({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Tc=oe({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ln={};At(Ln,{base32:()=>Rt,base32hex:()=>kc,base32hexpad:()=>Rc,base32hexpadupper:()=>Dc,base32hexupper:()=>Cc,base32pad:()=>_c,base32padupper:()=>Lc,base32upper:()=>Pc,base32z:()=>Kc});var Rt=J({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Pc=J({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),_c=J({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Lc=J({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),kc=J({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Cc=J({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Rc=J({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Dc=J({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Kc=J({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var kn={};At(kn,{base36:()=>Qe,base36upper:()=>Uc});var Qe=oe({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Uc=oe({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Nc=Gs,zs=128,Oc=127,Mc=~Oc,qc=Math.pow(2,31);function Gs(r,t,e){t=t||[],e=e||0;for(var n=e;r>=qc;)t[e++]=r&255|zs,r/=128;for(;r&Mc;)t[e++]=r&255|zs,r>>>=7;return t[e]=r|0,Gs.bytes=e-n+1,t}var Hc=Cn,Vc=128,Fs=127;function Cn(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Cn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Fs)<<o:(i&Fs)*Math.pow(2,o),o+=7}while(i>=Vc);return Cn.bytes=s-n,e}var zc=Math.pow(2,7),Fc=Math.pow(2,14),Gc=Math.pow(2,21),Wc=Math.pow(2,28),$c=Math.pow(2,35),Zc=Math.pow(2,42),Yc=Math.pow(2,49),jc=Math.pow(2,56),Xc=Math.pow(2,63),Qc=function(r){return r<zc?1:r<Fc?2:r<Gc?3:r<Wc?4:r<$c?5:r<Zc?6:r<Yc?7:r<jc?8:r<Xc?9:10},Jc={encode:Nc,decode:Hc,encodingLength:Qc},tu=Jc,Je=tu;function tr(r,t=0){return[Je.decode(r,t),Je.decode.bytes]}function Ce(r,t,e=0){return Je.encode(r,t,e),t}function Re(r){return Je.encodingLength(r)}function Dt(r,t){let e=t.byteLength,n=Re(r),o=n+Re(e),s=new Uint8Array(o+e);return Ce(r,s,0),Ce(e,s,n),s.set(t,o),new De(r,e,t,s)}function Gt(r){let t=Ft(r),[e,n]=tr(t),[o,s]=tr(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new De(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 De=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 ru(e,Rn(r),t??Z.encoder);default:return nu(e,Rn(r),t??Rt.encoder)}}var Zs=new WeakMap;function Rn(r){let t=Zs.get(r);if(t==null){let e=new Map;return Zs.set(r,e),e}return t}var tt=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!==er)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==ou)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&&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[su]===!0){let{version:n,multihash:o,code:s}=e,i=Gt(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!==er)throw new Error(`Version 0 CID must use dag-pb (code: ${er}) 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,er,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=Ft(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 De(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,p]=tr(t.subarray(e));return e+=p,l},o=n(),s=er;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]=eu(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 Rn(s).set(n,t),s}};function eu(r,t){switch(r[0]){case"Q":{let e=t??Z;return[Z.prefix,e.decode(`${Z.prefix}${r}`)]}case Z.prefix:{let e=t??Z;return[Z.prefix,e.decode(r)]}case Rt.prefix:{let e=t??Rt;return[Rt.prefix,e.decode(r)]}case Qe.prefix:{let e=t??Qe;return[Qe.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 ru(r,t,e){let{prefix:n}=e;if(n!==Z.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 nu(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 er=112,ou=18;function Ys(r,t,e){let n=Re(r),o=n+Re(t),s=new Uint8Array(o+e.byteLength);return Ce(r,s,0),Ce(t,s,n),s.set(e,o),s}var su=Symbol.for("@ipld/js-cid/CID");var Dn={};At(Dn,{identity:()=>Kt});var js=0,iu="identity",Xs=Ft;function au(r){return Dt(js,Xs(r))}var Kt={code:js,name:iu,encode:Xs,digest:au};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 st(r=0){return new Uint8Array(r)}function St(r=0){return new Uint8Array(r)}function Pt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=St(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 Ur(r){return!!r?.[Js]}var mt=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(Ur(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(Ur(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(Ur(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 Pt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Pt(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(!Ur(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 p=f;p>=0;p--){let y=this.get(l+p);if(n[p]!==y){u=Math.max(1,p-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=st(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=st(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=st(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=st(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=st(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=st(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=st(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=st(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={};At(Kn,{base10:()=>cu});var cu=oe({prefix:"9",name:"base10",alphabet:"0123456789"});var Un={};At(Un,{base16:()=>uu,base16upper:()=>lu});var uu=J({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),lu=J({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Nn={};At(Nn,{base2:()=>fu});var fu=J({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var On={};At(On,{base256emoji:()=>yu});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}"),du=ti.reduce((r,t,e)=>(r[e]=t,r),[]),hu=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 pu(r){return r.reduce((t,e)=>(t+=du[e],t),"")}function mu(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=hu[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var yu=ke({prefix:"\u{1F680}",name:"base256emoji",encode:pu,decode:mu});var Mn={};At(Mn,{base64:()=>gu,base64pad:()=>bu,base64url:()=>wu,base64urlpad:()=>xu});var gu=J({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),bu=J({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),wu=J({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),xu=J({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var qn={};At(qn,{base8:()=>Eu});var Eu=J({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Hn={};At(Hn,{identity:()=>vu});var vu=ke({prefix:"\0",name:"identity",encode:r=>Ms(r),decode:r=>Os(r)});var Ed=new TextEncoder,vd=new TextDecoder;var Fn={};At(Fn,{sha256:()=>rr,sha512:()=>Iu});function zn({name:r,code:t,encode:e}){return new Vn(r,t,e)}var Vn=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 ri(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var rr=zn({name:"sha2-256",code:18,encode:ri("SHA-256")}),Iu=zn({name:"sha2-512",code:19,encode:ri("SHA-512")});var nr={...Hn,...Nn,...qn,...Kn,...Un,...Ln,...kn,..._n,...Mn,...On},Dd={...Fn,...Dn};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))),Gn=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=St(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Bu={utf8:ni,"utf-8":ni,hex:nr.base16,latin1:Gn,ascii:Gn,binary:Gn,...nr},Nr=Bu;function W(r,t="utf8"){let e=Nr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function N(r,t="utf8"){let e=Nr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Tu=parseInt("11111",2),Wn=parseInt("10000000",2),Pu=parseInt("01111111",2),si={0:or,1:or,2:_u,3:Cu,4:Ru,5:ku,6:Lu,16:or,22:or,48:or};function $t(r,t={offset:0}){let e=r[t.offset]&Tu;if(t.offset++,si[e]!=null)return si[e](r,t);throw new Error("No decoder for tag "+e)}function sr(r,t){let e=0;if((r[t.offset]&Wn)===Wn){let n=r[t.offset]&Pu,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 or(r,t){sr(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=$t(r,t);if(n===null)break;e.push(n)}return e}function _u(r,t){let e=sr(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 Lu(r,t){let e=sr(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 ku(r,t){return t.offset++,null}function Cu(r,t){let e=sr(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 Ru(r,t){let e=sr(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 $n(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Du(r.byteLength);return new mt(Uint8Array.from([t.byteLength|Wn]),t)}function It(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]),$n(t),t)}function Or(r){let t=Uint8Array.from([0]),e=new mt(t,r);return new mt(Uint8Array.from([3]),$n(e),e)}function se(r,t=48){let e=new mt;for(let n of r)e.append(n);return new mt(Uint8Array.from([t]),$n(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 Ku=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Uu=Uint8Array.from([6,5,43,129,4,0,34]),Nu=Uint8Array.from([6,5,43,129,4,0,35]),Ou={ext:!0,kty:"EC",crv:"P-256"},Mu={ext:!0,kty:"EC",crv:"P-384"},qu={ext:!0,kty:"EC",crv:"P-521"},Zn=32,Yn=48,jn=66;function Xn(r){let t=$t(r);return ai(t)}function ai(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===Zn*2+1)return n=N(t.subarray(e,e+Zn),"base64url"),o=N(t.subarray(e+Zn),"base64url"),new Ke({...Ou,key_ops:["verify"],x:n,y:o});if(t.byteLength===Yn*2+1)return n=N(t.subarray(e,e+Yn),"base64url"),o=N(t.subarray(e+Yn),"base64url"),new Ke({...Mu,key_ops:["verify"],x:n,y:o});if(t.byteLength===jn*2+1)return n=N(t.subarray(e,e+jn),"base64url"),o=N(t.subarray(e+jn),"base64url"),new Ke({...qu,key_ops:["verify"],x:n,y:o});throw new H(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function ci(r){return se([It(Uint8Array.from([1])),se([Hu(r.crv)],160),se([Or(new mt(Uint8Array.from([4]),W(r.x??"","base64url"),W(r.y??"","base64url")))],161)]).subarray()}function Hu(r){if(r==="P-256")return Ku;if(r==="P-384")return Uu;if(r==="P-521")return Nu;throw new H(`Invalid curve ${r}`)}var Ke=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(kt(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return Z.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)}};var ye=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Vu(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Mr(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function ge(r,...t){if(!Vu(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 ui(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Mr(r.outputLen),Mr(r.blockLen)}function Ne(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 li(r,t){ge(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}function Zt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function qr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Ut(r,t){return r<<32-t|r>>>t}function fi(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function ir(r){return typeof r=="string"&&(r=fi(r)),ge(r),r}function Qn(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];ge(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 Ue=class{};function Jn(r){let t=n=>r().update(ir(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function Hr(r=32){if(ye&&typeof ye.getRandomValues=="function")return ye.getRandomValues(new Uint8Array(r));if(ye&&typeof ye.randomBytes=="function")return Uint8Array.from(ye.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function zu(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 di(r,t,e){return r&t^~r&e}function hi(r,t,e){return r&t^r&e^t&e}var ar=class extends Ue{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=qr(this.buffer)}update(t){Ne(this),t=ir(t),ge(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=qr(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){Ne(this),li(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Zt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)e[l]=0;zu(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=qr(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.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Yt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var lt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Vr=BigInt(4294967295),pi=BigInt(32);function Fu(r,t=!1){return t?{h:Number(r&Vr),l:Number(r>>pi&Vr)}:{h:Number(r>>pi&Vr)|0,l:Number(r&Vr)|0}}function mi(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:a}=Fu(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var to=(r,t,e)=>r>>>e,eo=(r,t,e)=>r<<32-e|t>>>e,be=(r,t,e)=>r>>>e|t<<32-e,we=(r,t,e)=>r<<32-e|t>>>e,cr=(r,t,e)=>r<<64-e|t>>>e-32,ur=(r,t,e)=>r>>>e-32|t<<64-e;function Ot(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var yi=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),gi=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,bi=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),wi=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,xi=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Ei=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Wu=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),ie=new Uint32Array(64),zr=class extends ar{constructor(t=32){super(64,t,8,!1),this.A=Yt[0]|0,this.B=Yt[1]|0,this.C=Yt[2]|0,this.D=Yt[3]|0,this.E=Yt[4]|0,this.F=Yt[5]|0,this.G=Yt[6]|0,this.H=Yt[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)ie[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let p=ie[l-15],y=ie[l-2],A=Ut(p,7)^Ut(p,18)^p>>>3,g=Ut(y,17)^Ut(y,19)^y>>>10;ie[l]=g+ie[l-7]+A+ie[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 p=Ut(a,6)^Ut(a,11)^Ut(a,25),y=u+p+di(a,c,f)+Wu[l]+ie[l]|0,g=(Ut(n,2)^Ut(n,13)^Ut(n,22))+hi(n,o,s)|0;u=f,f=c,c=a,a=i+y|0,i=s,s=o,o=n,n=y+g|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(){Zt(ie)}destroy(){this.set(0,0,0,0,0,0,0,0),Zt(this.buffer)}};var vi=mi(["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))),$u=vi[0],Zu=vi[1],ae=new Uint32Array(80),ce=new Uint32Array(80),ro=class extends ar{constructor(t=64){super(128,t,16,!1),this.Ah=lt[0]|0,this.Al=lt[1]|0,this.Bh=lt[2]|0,this.Bl=lt[3]|0,this.Ch=lt[4]|0,this.Cl=lt[5]|0,this.Dh=lt[6]|0,this.Dl=lt[7]|0,this.Eh=lt[8]|0,this.El=lt[9]|0,this.Fh=lt[10]|0,this.Fl=lt[11]|0,this.Gh=lt[12]|0,this.Gl=lt[13]|0,this.Hh=lt[14]|0,this.Hl=lt[15]|0}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:p,Gh:y,Gl:A,Hh:g,Hl:R}=this;return[t,e,n,o,s,i,a,c,f,u,l,p,y,A,g,R]}set(t,e,n,o,s,i,a,c,f,u,l,p,y,A,g,R){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=p|0,this.Gh=y|0,this.Gl=A|0,this.Hh=g|0,this.Hl=R|0}process(t,e){for(let S=0;S<16;S++,e+=4)ae[S]=t.getUint32(e),ce[S]=t.getUint32(e+=4);for(let S=16;S<80;S++){let d=ae[S-15]|0,b=ce[S-15]|0,I=be(d,b,1)^be(d,b,8)^to(d,b,7),B=we(d,b,1)^we(d,b,8)^eo(d,b,7),T=ae[S-2]|0,C=ce[S-2]|0,O=be(T,C,19)^cr(T,C,61)^to(T,C,6),_=we(T,C,19)^ur(T,C,61)^eo(T,C,6),K=bi(B,_,ce[S-7],ce[S-16]),k=wi(K,I,O,ae[S-7],ae[S-16]);ae[S]=k|0,ce[S]=K|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:f,Dl:u,Eh:l,El:p,Fh:y,Fl:A,Gh:g,Gl:R,Hh:D,Hl:F}=this;for(let S=0;S<80;S++){let d=be(l,p,14)^be(l,p,18)^cr(l,p,41),b=we(l,p,14)^we(l,p,18)^ur(l,p,41),I=l&y^~l&g,B=p&A^~p&R,T=xi(F,b,B,Zu[S],ce[S]),C=Ei(T,D,d,I,$u[S],ae[S]),O=T|0,_=be(n,o,28)^cr(n,o,34)^cr(n,o,39),K=we(n,o,28)^ur(n,o,34)^ur(n,o,39),k=n&s^n&a^s&a,nt=o&i^o&c^i&c;D=g|0,F=R|0,g=y|0,R=A|0,y=l|0,A=p|0,{h:l,l:p}=Ot(f|0,u|0,C|0,O|0),f=a|0,u=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let E=yi(O,K,nt);n=gi(E,C,_,k),o=E|0}({h:n,l:o}=Ot(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Ot(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Ot(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=Ot(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:p}=Ot(this.Eh|0,this.El|0,l|0,p|0),{h:y,l:A}=Ot(this.Fh|0,this.Fl|0,y|0,A|0),{h:g,l:R}=Ot(this.Gh|0,this.Gl|0,g|0,R|0),{h:D,l:F}=Ot(this.Hh|0,this.Hl|0,D|0,F|0),this.set(n,o,s,i,a,c,f,u,l,p,y,A,g,R,D,F)}roundClean(){Zt(ae,ce)}destroy(){Zt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Fr=Jn(()=>new zr);var Ai=Jn(()=>new ro);var io=BigInt(0),so=BigInt(1);function Oe(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function ao(r){if(!Oe(r))throw new Error("Uint8Array expected")}function Mt(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function lr(r){let t=r.toString(16);return t.length&1?"0"+t:t}function Bi(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?io:BigInt("0x"+r)}var Ti=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Yu=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function ue(r){if(ao(r),Ti)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=Yu[r[e]];return t}var jt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Si(r){if(r>=jt._0&&r<=jt._9)return r-jt._0;if(r>=jt.A&&r<=jt.F)return r-(jt.A-10);if(r>=jt.a&&r<=jt.f)return r-(jt.a-10)}function fr(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(Ti)return Uint8Array.fromHex(r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=Si(r.charCodeAt(s)),a=Si(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 Xt(r){return Bi(ue(r))}function xe(r){return ao(r),Bi(ue(Uint8Array.from(r).reverse()))}function Ee(r,t){return fr(r.toString(16).padStart(t*2,"0"))}function Me(r,t){return Ee(r,t).reverse()}function X(r,t,e){let n;if(typeof t=="string")try{n=fr(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(Oe(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 le(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];ao(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 no=r=>typeof r=="bigint"&&io<=r;function Gr(r,t,e){return no(r)&&no(t)&&no(e)&&t<=r&&r<e}function _t(r,t,e,n){if(!Gr(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Pi(r){let t;for(t=0;r>io;r>>=so,t+=1);return t}var ve=r=>(so<<BigInt(r))-so,oo=r=>new Uint8Array(r),Ii=r=>Uint8Array.from(r);function _i(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=oo(r),o=oo(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},a=(...l)=>e(o,n,...l),c=(l=oo(0))=>{o=a(Ii([0]),l),n=a(),l.length!==0&&(o=a(Ii([1]),l),n=a())},f=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,p=[];for(;l<t;){n=a();let y=n.slice();p.push(y),l+=n.length}return le(...p)};return(l,p)=>{i(),c(l);let y;for(;!(y=p(f()));)c();return i(),y}}var ju={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"||Oe(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 Qt(r,t,e={}){let n=(o,s,i)=>{let a=ju[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}function qe(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 yt=BigInt(0),at=BigInt(1),Ae=BigInt(2),Xu=BigInt(3),ki=BigInt(4),Ci=BigInt(5),Ri=BigInt(8);function $(r,t){let e=r%t;return e>=yt?e:t+e}function Q(r,t,e){let n=r;for(;t-- >yt;)n*=n,n%=e;return n}function Wr(r,t){if(r===yt)throw new Error("invert: expected non-zero number");if(t<=yt)throw new Error("invert: expected positive modulus, got "+t);let e=$(r,t),n=t,o=yt,s=at,i=at,a=yt;for(;e!==yt;){let f=n/e,u=n%e,l=o-i*f,p=s-a*f;n=e,e=u,o=i,s=a,i=l,a=p}if(n!==at)throw new Error("invert: does not exist");return $(o,t)}function Di(r,t){let e=(r.ORDER+at)/ki,n=r.pow(t,e);if(!r.eql(r.sqr(n),t))throw new Error("Cannot find square root");return n}function Qu(r,t){let e=(r.ORDER-Ci)/Ri,n=r.mul(t,Ae),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,Ae),o),a=r.mul(s,r.sub(i,r.ONE));if(!r.eql(r.sqr(a),t))throw new Error("Cannot find square root");return a}function Ju(r){if(r<BigInt(3))throw new Error("sqrt is not defined for small field");let t=r-at,e=0;for(;t%Ae===yt;)t/=Ae,e++;let n=Ae,o=Jt(r);for(;Li(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return Di;let s=o.pow(n,t),i=(t+at)/Ae;return function(c,f){if(c.is0(f))return f;if(Li(c,f)!==1)throw new Error("Cannot find square root");let u=e,l=c.mul(c.ONE,s),p=c.pow(f,t),y=c.pow(f,i);for(;!c.eql(p,c.ONE);){if(c.is0(p))return c.ZERO;let A=1,g=c.sqr(p);for(;!c.eql(g,c.ONE);)if(A++,g=c.sqr(g),A===u)throw new Error("Cannot find square root");let R=at<<BigInt(u-A-1),D=c.pow(l,R);u=A,l=c.sqr(D),p=c.mul(p,l),y=c.mul(y,D)}return y}}function tl(r){return r%ki===Xu?Di:r%Ri===Ci?Qu:Ju(r)}var Ki=(r,t)=>($(r,t)&at)===at,el=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function co(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=el.reduce((n,o)=>(n[o]="function",n),t);return Qt(r,e)}function rl(r,t,e){if(e<yt)throw new Error("invalid exponent, negatives unsupported");if(e===yt)return r.ONE;if(e===at)return t;let n=r.ONE,o=t;for(;e>yt;)e&at&&(n=r.mul(n,o)),o=r.sqr(o),e>>=at;return n}function He(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,a,c)=>r.is0(a)?i:(n[c]=i,r.mul(i,a)),r.ONE),s=r.inv(o);return t.reduceRight((i,a,c)=>r.is0(a)?i:(n[c]=r.mul(i,n[c]),r.mul(i,a)),s),n}function Li(r,t){let e=(r.ORDER-at)/Ae,n=r.pow(t,e),o=r.eql(n,r.ONE),s=r.eql(n,r.ZERO),i=r.eql(n,r.neg(r.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function uo(r,t){t!==void 0&&Mr(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Jt(r,t,e=!1,n={}){if(r<=yt)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:s}=uo(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:ve(o),ZERO:yt,ONE:at,create:c=>$(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return yt<=c&&c<r},is0:c=>c===yt,isOdd:c=>(c&at)===at,neg:c=>$(-c,r),eql:(c,f)=>c===f,sqr:c=>$(c*c,r),add:(c,f)=>$(c+f,r),sub:(c,f)=>$(c-f,r),mul:(c,f)=>$(c*f,r),pow:(c,f)=>rl(a,c,f),div:(c,f)=>$(c*Wr(f,r),r),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>Wr(c,r),sqrt:n.sqrt||(c=>(i||(i=tl(r)),i(a,c))),toBytes:c=>e?Me(c,s):Ee(c,s),fromBytes:c=>{if(c.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+c.length);return e?xe(c):Xt(c)},invertBatch:c=>He(a,c),cmov:(c,f,u)=>u?f:c});return Object.freeze(a)}function Ui(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 lo(r){let t=Ui(r);return t+Math.ceil(t/2)}function Ni(r,t,e=!1){let n=r.length,o=Ui(t),s=lo(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?xe(r):Xt(r),a=$(i,t-at)+at;return e?Me(a,o):Ee(a,o)}var Oi=BigInt(0),yo=BigInt(1);function fo(r,t){let e=t.negate();return r?e:t}function qi(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function ho(r,t){qi(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=ve(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Mi(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),c=r>>i;a>n&&(a-=s,c+=yo);let f=t*n,u=f+Math.abs(a)-1,l=a===0,p=a<0,y=t%2!==0;return{nextN:c,offset:u,isZero:l,isNeg:p,isNegF:y,offsetF:f}}function nl(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 ol(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 po=new WeakMap,Hi=new WeakMap;function mo(r){return Hi.get(r)||1}function $r(r,t){return{constTimeNegate:fo,hasPrecomputes(e){return mo(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>Oi;)n&yo&&(o=o.add(s)),s=s.double(),n>>=yo;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=ho(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 s=r.ZERO,i=r.BASE,a=ho(e,t);for(let c=0;c<a.windows;c++){let{nextN:f,offset:u,isZero:l,isNeg:p,isNegF:y,offsetF:A}=Mi(o,c,a);o=f,l?i=i.add(fo(y,n[A])):s=s.add(fo(p,n[u]))}return{p:s,f:i}},wNAFUnsafe(e,n,o,s=r.ZERO){let i=ho(e,t);for(let a=0;a<i.windows&&o!==Oi;a++){let{nextN:c,offset:f,isZero:u,isNeg:l}=Mi(o,a,i);if(o=c,!u){let p=n[f];s=s.add(l?p.negate():p)}}return s},getPrecomputes(e,n,o){let s=po.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&po.set(n,o(s))),s},wNAFCached(e,n,o){let s=mo(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=mo(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){qi(n,t),Hi.set(e,n),po.delete(e)}}}function Zr(r,t,e,n){nl(e,r),ol(n,t);let o=e.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=r.ZERO,a=Pi(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let f=ve(c),u=new Array(Number(f)+1).fill(i),l=Math.floor((t.BITS-1)/c)*c,p=i;for(let y=l;y>=0;y-=c){u.fill(i);for(let g=0;g<s;g++){let R=n[g],D=Number(R>>BigInt(y)&f);u[D]=u[D].add(e[g])}let A=i;for(let g=u.length-1,R=i;g>0;g--)R=R.add(u[g]),A=A.add(R);if(p=p.add(A),y!==0)for(let g=0;g<c;g++)p=p.double()}return p}function dr(r){return co(r.Fp),Qt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...uo(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var qt=BigInt(0),gt=BigInt(1),Vi=BigInt(2),sl=BigInt(8),il={zip215:!0};function al(r){let t=dr(r);return Qt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function zi(r){let t=al(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:a,h:c}=t,f=Vi<<BigInt(a*8)-gt,u=e.create,l=Jt(t.n,t.nBitLength);function p(w,h){let m=e.sqr(w),v=e.sqr(h),L=e.add(e.mul(t.a,m),v),U=e.add(e.ONE,e.mul(t.d,e.mul(m,v)));return e.eql(L,U)}if(!p(t.Gx,t.Gy))throw new Error("bad curve params: generator point");let y=t.uvRatio||((w,h)=>{try{return{isValid:!0,value:e.sqrt(w*e.inv(h))}}catch{return{isValid:!1,value:qt}}}),A=t.adjustScalarBytes||(w=>w),g=t.domain||((w,h,m)=>{if(Mt("phflag",m),h.length||m)throw new Error("Contexts/pre-hash are not supported");return w});function R(w,h,m=!1){let v=m?gt:qt;_t("coordinate "+w,h,v,f)}function D(w){if(!(w instanceof d))throw new Error("ExtendedPoint expected")}let F=qe((w,h)=>{let{ex:m,ey:v,ez:L}=w,U=w.is0();h==null&&(h=U?sl:e.inv(L));let M=u(m*h),q=u(v*h),V=u(L*h);if(U)return{x:qt,y:gt};if(V!==gt)throw new Error("invZ was invalid");return{x:M,y:q}}),S=qe(w=>{let{a:h,d:m}=t;if(w.is0())throw new Error("bad point: ZERO");let{ex:v,ey:L,ez:U,et:M}=w,q=u(v*v),V=u(L*L),G=u(U*U),ot=u(G*G),et=u(q*h),ut=u(G*u(et+V)),vt=u(ot+u(m*u(q*V)));if(ut!==vt)throw new Error("bad point: equation left != right (1)");let it=u(v*L),ft=u(U*M);if(it!==ft)throw new Error("bad point: equation left != right (2)");return!0});class d{constructor(h,m,v,L){R("x",h),R("y",m),R("z",v,!0),R("t",L),this.ex=h,this.ey=m,this.ez=v,this.et=L,Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(h){if(h instanceof d)throw new Error("extended point not allowed");let{x:m,y:v}=h||{};return R("x",m),R("y",v),new d(m,v,gt,u(m*v))}static normalizeZ(h){let m=He(e,h.map(v=>v.ez));return h.map((v,L)=>v.toAffine(m[L])).map(d.fromAffine)}static msm(h,m){return Zr(d,l,h,m)}_setWindowSize(h){B.setWindowSize(this,h)}assertValidity(){S(this)}equals(h){D(h);let{ex:m,ey:v,ez:L}=this,{ex:U,ey:M,ez:q}=h,V=u(m*q),G=u(U*L),ot=u(v*q),et=u(M*L);return V===G&&ot===et}is0(){return this.equals(d.ZERO)}negate(){return new d(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:h}=t,{ex:m,ey:v,ez:L}=this,U=u(m*m),M=u(v*v),q=u(Vi*u(L*L)),V=u(h*U),G=m+v,ot=u(u(G*G)-U-M),et=V+M,ut=et-q,vt=V-M,it=u(ot*ut),ft=u(et*vt),Tt=u(ot*vt),Ct=u(ut*et);return new d(it,ft,Ct,Tt)}add(h){D(h);let{a:m,d:v}=t,{ex:L,ey:U,ez:M,et:q}=this,{ex:V,ey:G,ez:ot,et}=h,ut=u(L*V),vt=u(U*G),it=u(q*v*et),ft=u(M*ot),Tt=u((L+U)*(V+G)-ut-vt),Ct=ft-it,je=ft+it,Ds=u(vt-m*ut),uc=u(Tt*Ct),lc=u(je*Ds),fc=u(Tt*Ds),dc=u(Ct*je);return new d(uc,lc,dc,fc)}subtract(h){return this.add(h.negate())}wNAF(h){return B.wNAFCached(this,h,d.normalizeZ)}multiply(h){let m=h;_t("scalar",m,gt,n);let{p:v,f:L}=this.wNAF(m);return d.normalizeZ([v,L])[0]}multiplyUnsafe(h,m=d.ZERO){let v=h;return _t("scalar",v,qt,n),v===qt?I:this.is0()||v===gt?this:B.wNAFCachedUnsafe(this,v,d.normalizeZ,m)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return B.unsafeLadder(this,n).is0()}toAffine(h){return F(this,h)}clearCofactor(){let{h}=t;return h===gt?this:this.multiplyUnsafe(h)}static fromHex(h,m=!1){let{d:v,a:L}=t,U=e.BYTES;h=X("pointHex",h,U),Mt("zip215",m);let M=h.slice(),q=h[U-1];M[U-1]=q&-129;let V=xe(M),G=m?f:e.ORDER;_t("pointHex.y",V,qt,G);let ot=u(V*V),et=u(ot-gt),ut=u(v*ot-L),{isValid:vt,value:it}=y(et,ut);if(!vt)throw new Error("Point.fromHex: invalid y coordinate");let ft=(it&gt)===gt,Tt=(q&128)!==0;if(!m&&it===qt&&Tt)throw new Error("Point.fromHex: x=0 and x_0=1");return Tt!==ft&&(it=u(-it)),d.fromAffine({x:it,y:V})}static fromPrivateKey(h){let{scalar:m}=O(h);return b.multiply(m)}toRawBytes(){let{x:h,y:m}=this.toAffine(),v=Me(m,e.BYTES);return v[v.length-1]|=h&gt?128:0,v}toHex(){return ue(this.toRawBytes())}}d.BASE=new d(t.Gx,t.Gy,gt,u(t.Gx*t.Gy)),d.ZERO=new d(qt,gt,gt,qt);let{BASE:b,ZERO:I}=d,B=$r(d,a*8);function T(w){return $(w,n)}function C(w){return T(xe(w))}function O(w){let h=e.BYTES;w=X("private key",w,h);let m=X("hashed private key",s(w),2*h),v=A(m.slice(0,h)),L=m.slice(h,2*h),U=C(v);return{head:v,prefix:L,scalar:U}}function _(w){let{head:h,prefix:m,scalar:v}=O(w),L=b.multiply(v),U=L.toRawBytes();return{head:h,prefix:m,scalar:v,point:L,pointBytes:U}}function K(w){return _(w).pointBytes}function k(w=Uint8Array.of(),...h){let m=le(...h);return C(s(g(m,X("context",w),!!o)))}function nt(w,h,m={}){w=X("message",w),o&&(w=o(w));let{prefix:v,scalar:L,pointBytes:U}=_(h),M=k(m.context,v,w),q=b.multiply(M).toRawBytes(),V=k(m.context,q,U,w),G=T(M+V*L);_t("signature.s",G,qt,n);let ot=le(q,Me(G,e.BYTES));return X("result",ot,e.BYTES*2)}let E=il;function x(w,h,m,v=E){let{context:L,zip215:U}=v,M=e.BYTES;w=X("signature",w,2*M),h=X("message",h),m=X("publicKey",m,M),U!==void 0&&Mt("zip215",U),o&&(h=o(h));let q=xe(w.slice(M,2*M)),V,G,ot;try{V=d.fromHex(m,U),G=d.fromHex(w.slice(0,M),U),ot=b.multiplyUnsafe(q)}catch{return!1}if(!U&&V.isSmallOrder())return!1;let et=k(L,G.toRawBytes(),V.toRawBytes(),h);return G.add(V.multiplyUnsafe(et)).subtract(ot).clearCofactor().equals(d.ZERO)}return b._setWindowSize(8),{CURVE:t,getPublicKey:K,sign:nt,verify:x,ExtendedPoint:d,utils:{getExtendedPublicKey:_,randomPrivateKey:()=>i(e.BYTES),precompute(w=8,h=d.BASE){return h._setWindowSize(w),h.multiply(BigInt(3)),h}}}}var go=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Fi=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Nh=BigInt(0),cl=BigInt(1),Gi=BigInt(2),Oh=BigInt(3),ul=BigInt(5),ll=BigInt(8);function fl(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=go,a=r*r%s*r%s,c=Q(a,Gi,s)*a%s,f=Q(c,cl,s)*r%s,u=Q(f,ul,s)*f%s,l=Q(u,t,s)*u%s,p=Q(l,e,s)*l%s,y=Q(p,n,s)*p%s,A=Q(y,o,s)*y%s,g=Q(A,o,s)*y%s,R=Q(g,t,s)*u%s;return{pow_p_5_8:Q(R,Gi,s)*r%s,b2:a}}function dl(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function hl(r,t){let e=go,n=$(t*t*t,e),o=$(n*n*t,e),s=fl(r*o).pow_p_5_8,i=$(r*n*s,e),a=$(t*i*i,e),c=i,f=$(i*Fi,e),u=a===r,l=a===$(-r,e),p=a===$(-r*Fi,e);return u&&(i=c),(l||p)&&(i=f),Ki(i,e)&&(i=$(-i,e)),{isValid:u||l,value:i}}var Wi=Jt(go,void 0,!0),pl={a:Wi.create(BigInt(-1)),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Wi,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:ll,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Ai,randomBytes:Hr,adjustScalarBytes:dl,uvRatio:hl},$i=zi(pl);var Yr=32;function Zi(r,t,e){return $i.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var jr=class{type="Ed25519";raw;constructor(t){this.raw=bo(t,Yr)}toMultihash(){return Kt.digest(kt(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return Z.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.raw,e,t)}};function wo(r){return r=bo(r,Yr),new jr(r)}function bo(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new H(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var yl=Math.pow(2,7),gl=Math.pow(2,14),bl=Math.pow(2,21),xo=Math.pow(2,28),Eo=Math.pow(2,35),vo=Math.pow(2,42),Ao=Math.pow(2,49),z=128,dt=127;function Bt(r){if(r<yl)return 1;if(r<gl)return 2;if(r<bl)return 3;if(r<xo)return 4;if(r<Eo)return 5;if(r<vo)return 6;if(r<Ao)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function So(r,t,e=0){switch(Bt(r)){case 8:t[e++]=r&255|z,r/=128;case 7:t[e++]=r&255|z,r/=128;case 6:t[e++]=r&255|z,r/=128;case 5:t[e++]=r&255|z,r/=128;case 4:t[e++]=r&255|z,r>>>=7;case 3:t[e++]=r&255|z,r>>>=7;case 2:t[e++]=r&255|z,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function wl(r,t,e=0){switch(Bt(r)){case 8:t.set(e++,r&255|z),r/=128;case 7:t.set(e++,r&255|z),r/=128;case 6:t.set(e++,r&255|z),r/=128;case 5:t.set(e++,r&255|z),r/=128;case 4:t.set(e++,r&255|z),r>>>=7;case 3:t.set(e++,r&255|z),r>>>=7;case 2:t.set(e++,r&255|z),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Io(r,t){let e=r[t],n=0;if(n+=e&dt,e<z||(e=r[t+1],n+=(e&dt)<<7,e<z)||(e=r[t+2],n+=(e&dt)<<14,e<z)||(e=r[t+3],n+=(e&dt)<<21,e<z)||(e=r[t+4],n+=(e&dt)*xo,e<z)||(e=r[t+5],n+=(e&dt)*Eo,e<z)||(e=r[t+6],n+=(e&dt)*vo,e<z)||(e=r[t+7],n+=(e&dt)*Ao,e<z))return n;throw new RangeError("Could not decode varint")}function xl(r,t){let e=r.get(t),n=0;if(n+=e&dt,e<z||(e=r.get(t+1),n+=(e&dt)<<7,e<z)||(e=r.get(t+2),n+=(e&dt)<<14,e<z)||(e=r.get(t+3),n+=(e&dt)<<21,e<z)||(e=r.get(t+4),n+=(e&dt)*xo,e<z)||(e=r.get(t+5),n+=(e&dt)*Eo,e<z)||(e=r.get(t+6),n+=(e&dt)*vo,e<z)||(e=r.get(t+7),n+=(e&dt)*Ao,e<z))return n;throw new RangeError("Could not decode varint")}function Ht(r,t,e=0){return t==null&&(t=St(Bt(r))),t instanceof Uint8Array?So(r,t,e):wl(r,t,e)}function Se(r,t=0){return r instanceof Uint8Array?Io(r,t):xl(r,t)}var To=new Float32Array([-0]),fe=new Uint8Array(To.buffer);function ji(r,t,e){To[0]=r,t[e]=fe[0],t[e+1]=fe[1],t[e+2]=fe[2],t[e+3]=fe[3]}function Xi(r,t){return fe[0]=r[t],fe[1]=r[t+1],fe[2]=r[t+2],fe[3]=r[t+3],To[0]}var Po=new Float64Array([-0]),ht=new Uint8Array(Po.buffer);function Qi(r,t,e){Po[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 Ji(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],Po[0]}var El=BigInt(Number.MAX_SAFE_INTEGER),vl=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 Ie;if(t<El&&t>vl)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>ta&&(o=0n,++n>ta&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return Ie;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):Ie}},Ie=new Lt(0,0);Ie.toBigInt=function(){return 0n};Ie.zzEncode=Ie.zzDecode=function(){return this};Ie.length=function(){return 1};var ta=4294967296n;function ea(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function ra(r,t,e){if(e-t<1)return"";let 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 _o(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 Nt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Xr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Lo=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,Nt(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 Nt(this,4);return Xr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Nt(this,4);return Xr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Nt(this,4);let t=Xi(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Nt(this,4);let t=Ji(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 Nt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return ra(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Nt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Nt(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 Nt(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 Nt(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 Nt(this,8);let t=Xr(this.buf,this.pos+=4),e=Xr(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=Io(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 ko(r){return new Lo(r instanceof Uint8Array?r:r.subarray())}function bt(r,t,e){let n=ko(r);return t.decode(n,void 0,e)}function Co(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return St(i);o+i>t&&(n=St(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Be=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Ro(){}var Ko=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Al=Co();function Sl(r){return globalThis.Buffer!=null?St(r):Al(r)}var pr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Be(Ro,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Be(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Uo((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(Qr,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(Qr,e.length(),e)}uint64Number(t){return this._push(So,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(Qr,e.length(),e)}sint64Number(t){let e=Lt.fromNumber(t).zzEncode();return this._push(Qr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Do,1,t?1:0)}fixed32(t){return this._push(hr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Lt.fromBigInt(t);return this._push(hr,4,e.lo)._push(hr,4,e.hi)}fixed64Number(t){let e=Lt.fromNumber(t);return this._push(hr,4,e.lo)._push(hr,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(ji,4,t)}double(t){return this._push(Qi,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Do,1,0):this.uint32(e)._push(Bl,e,t)}string(t){let e=ea(t);return e!==0?this.uint32(e)._push(_o,e,t):this._push(Do,1,0)}fork(){return this.states=new Ko(this),this.head=this.tail=new Be(Ro,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 Be(Ro,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=Sl(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Do(r,t,e){t[e]=r&255}function Il(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Uo=class extends Be{next;constructor(t,e){super(Il,t,e),this.next=void 0}};function Qr(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 hr(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 Bl(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(pr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Tl,t,r),this},pr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Pl,t,r),this});function Tl(r,t,e){t.set(r,e)}function Pl(r,t,e){r.length<40?_o(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(W(r),e)}function No(){return new pr}function wt(r,t){let e=No();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Ve;(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"})(Ve||(Ve={}));function Jr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Oo(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",Ve.VARINT,e,n)}function xt(r,t){return Jr("message",Ve.LENGTH_DELIMITED,r,t)}var Te=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"},mr=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 Mo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Mo||(Mo={}));(function(r){r.codec=()=>Oo(Mo)})(rt||(rt={}));var Vt;(function(r){let t;r.codec=()=>(t==null&&(t=xt((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=>wt(e,r.codec()),r.decode=(e,n)=>bt(e,r.codec(),n)})(Vt||(Vt={}));var qo;(function(r){let t;r.codec=()=>(t==null&&(t=xt((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=>wt(e,r.codec()),r.decode=(e,n)=>bt(e,r.codec(),n)})(qo||(qo={}));var yr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},tn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var sa={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new tn("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 de=sa;var br={};At(br,{MAX_RSA_KEY_SIZE:()=>Ho,generateRSAKeyPair:()=>ua,jwkToJWKKeyPair:()=>la,jwkToPkcs1:()=>Cl,jwkToPkix:()=>Go,jwkToRSAPrivateKey:()=>Yo,pkcs1MessageToJwk:()=>zo,pkcs1MessageToRSAPrivateKey:()=>Wo,pkcs1ToJwk:()=>kl,pkcs1ToRSAPrivateKey:()=>ca,pkixMessageToJwk:()=>Fo,pkixMessageToRSAPublicKey:()=>Zo,pkixToJwk:()=>Rl,pkixToRSAPublicKey:()=>$o});var en=Fr;var ze=class{type="RSA";jwk;_raw;_multihash;constructor(t,e){this.jwk=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=br.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return tt.createV1(114,this._multihash)}toString(){return Z.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 aa(this.jwk,e,t)}},gr=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=br.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:j(this.raw,t.raw)}sign(t){return ia(this.jwk,t)}};var Ho=8192,Vo=18,_l=1062,Ll=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function kl(r){let t=$t(r);return zo(t)}function zo(r){return{n:N(r[1],"base64url"),e:N(r[2],"base64url"),d:N(r[3],"base64url"),p:N(r[4],"base64url"),q:N(r[5],"base64url"),dp:N(r[6],"base64url"),dq:N(r[7],"base64url"),qi:N(r[8],"base64url"),kty:"RSA"}}function Cl(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 H("JWK was missing components");return se([It(Uint8Array.from([0])),It(W(r.n,"base64url")),It(W(r.e,"base64url")),It(W(r.d,"base64url")),It(W(r.p,"base64url")),It(W(r.q,"base64url")),It(W(r.dp,"base64url")),It(W(r.dq,"base64url")),It(W(r.qi,"base64url"))]).subarray()}function Rl(r){let t=$t(r,{offset:0});return Fo(t)}function Fo(r){let t=$t(r[1],{offset:0});return{kty:"RSA",n:N(t[0],"base64url"),e:N(t[1],"base64url")}}function Go(r){if(r.n==null||r.e==null)throw new H("JWK was missing components");return se([Ll,Or(se([It(W(r.n,"base64url")),It(W(r.e,"base64url"))]))]).subarray()}function ca(r){let t=$t(r);return Wo(t)}function Wo(r){let t=zo(r);return Yo(t)}function $o(r,t){if(r.byteLength>=_l)throw new Le("Key size is too large");let e=$t(r,{offset:0});return Zo(e,r,t)}function Zo(r,t,e){let n=Fo(r);if(e==null){let o=en(Vt.encode({Type:rt.RSA,Data:t}));e=Dt(Vo,o)}return new ze(n,e)}function Yo(r){if(da(r)>Ho)throw new H("Key size is too large");let t=la(r),e=en(Vt.encode({Type:rt.RSA,Data:Go(t.publicKey)})),n=Dt(Vo,e);return new gr(t.privateKey,new ze(t.publicKey,n))}async function ua(r){if(r>Ho)throw new H("Key size is too large");let t=await fa(r),e=en(Vt.encode({Type:rt.RSA,Data:Go(t.publicKey)})),n=Dt(Vo,e);return new gr(t.privateKey,new ze(t.publicKey,n))}function la(r){if(r==null)throw new H("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function fa(r){let t=await de.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 Dl(t);return{privateKey:e[0],publicKey:e[1]}}async function ia(r,t){let e=await de.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await de.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function aa(r,t,e){let n=await de.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return de.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function Dl(r){if(r.privateKey==null||r.publicKey==null)throw new H("Private and public key are required");return Promise.all([de.get().subtle.exportKey("jwk",r.privateKey),de.get().subtle.exportKey("jwk",r.publicKey)])}function da(r){if(r.kty!=="RSA")throw new H("invalid key type");if(r.n==null)throw new H("invalid key modulus");return W(r.n,"base64url").length*8}var rn=class extends Ue{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,ui(t);let n=ir(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),Zt(s)}update(t){return Ne(this),this.iHash.update(t),this}digestInto(t){Ne(this),ge(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},jo=(r,t,e)=>new rn(r,t).update(e).digest();jo.create=(r,t)=>new rn(r,t);function ha(r){r.lowS!==void 0&&Mt("lowS",r.lowS),r.prehash!==void 0&&Mt("prehash",r.prehash)}function Kl(r){let t=dr(r);Qt(t,{a:"field",b:"field"},{allowInfinityPoint:"boolean",allowedPrivateKeyLengths:"array",clearCofactor:"function",fromBytes:"function",isTorsionFree:"function",toBytes:"function",wrapPrivateKey:"boolean"});let{endo:e,Fp:n,a:o}=t;if(e){if(!n.eql(o,n.ZERO))throw new Error("invalid endo: CURVE.a must be 0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function')}return Object.freeze({...t})}var Jo=class extends Error{constructor(t=""){super(t)}},te={Err:Jo,_tlv:{encode:(r,t)=>{let{Err:e}=te;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=lr(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?lr(o.length/2|128):"";return lr(r)+s+o+t},decode(r,t){let{Err:e}=te,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}=te;if(r<ee)throw new t("integer: negative integers are not allowed");let e=lr(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}=te;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 Xt(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=te,o=X("signature",r),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v: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}=te,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}};function Xo(r,t){return ue(Ee(r,t))}var ee=BigInt(0),ct=BigInt(1),f0=BigInt(2),Qo=BigInt(3),Ul=BigInt(4);function Nl(r){let t=Kl(r),{Fp:e}=t,n=Jt(t.n,t.nBitLength),o=t.toBytes||((S,d,b)=>{let I=d.toAffine();return le(Uint8Array.from([4]),e.toBytes(I.x),e.toBytes(I.y))}),s=t.fromBytes||(S=>{let d=S.subarray(1),b=e.fromBytes(d.subarray(0,e.BYTES)),I=e.fromBytes(d.subarray(e.BYTES,2*e.BYTES));return{x:b,y:I}});function i(S){let{a:d,b}=t,I=e.sqr(S),B=e.mul(I,S);return e.add(e.add(B,e.mul(S,d)),b)}function a(S,d){let b=e.sqr(d),I=i(S);return e.eql(b,I)}if(!a(t.Gx,t.Gy))throw new Error("bad curve params: generator point");let c=e.mul(e.pow(t.a,Qo),Ul),f=e.mul(e.sqr(t.b),BigInt(27));if(e.is0(e.add(c,f)))throw new Error("bad curve params: a or b");function u(S){return Gr(S,ct,t.n)}function l(S){let{allowedPrivateKeyLengths:d,nByteLength:b,wrapPrivateKey:I,n:B}=t;if(d&&typeof S!="bigint"){if(Oe(S)&&(S=ue(S)),typeof S!="string"||!d.includes(S.length))throw new Error("invalid private key");S=S.padStart(b*2,"0")}let T;try{T=typeof S=="bigint"?S:Xt(X("private key",S,b))}catch{throw new Error("invalid private key, expected hex or "+b+" bytes, got "+typeof S)}return I&&(T=$(T,B)),_t("private key",T,ct,B),T}function p(S){if(!(S instanceof g))throw new Error("ProjectivePoint expected")}let y=qe((S,d)=>{let{px:b,py:I,pz:B}=S;if(e.eql(B,e.ONE))return{x:b,y:I};let T=S.is0();d==null&&(d=T?e.ONE:e.inv(B));let C=e.mul(b,d),O=e.mul(I,d),_=e.mul(B,d);if(T)return{x:e.ZERO,y:e.ZERO};if(!e.eql(_,e.ONE))throw new Error("invZ was invalid");return{x:C,y:O}}),A=qe(S=>{if(S.is0()){if(t.allowInfinityPoint&&!e.is0(S.py))return;throw new Error("bad point: ZERO")}let{x:d,y:b}=S.toAffine();if(!e.isValid(d)||!e.isValid(b))throw new Error("bad point: x or y not FE");if(!a(d,b))throw new Error("bad point: equation left != right");if(!S.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class g{constructor(d,b,I){if(d==null||!e.isValid(d))throw new Error("x required");if(b==null||!e.isValid(b)||e.is0(b))throw new Error("y required");if(I==null||!e.isValid(I))throw new Error("z required");this.px=d,this.py=b,this.pz=I,Object.freeze(this)}static fromAffine(d){let{x:b,y:I}=d||{};if(!d||!e.isValid(b)||!e.isValid(I))throw new Error("invalid affine point");if(d instanceof g)throw new Error("projective point not allowed");let B=T=>e.eql(T,e.ZERO);return B(b)&&B(I)?g.ZERO:new g(b,I,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){let b=He(e,d.map(I=>I.pz));return d.map((I,B)=>I.toAffine(b[B])).map(g.fromAffine)}static fromHex(d){let b=g.fromAffine(s(X("pointHex",d)));return b.assertValidity(),b}static fromPrivateKey(d){return g.BASE.multiply(l(d))}static msm(d,b){return Zr(g,n,d,b)}_setWindowSize(d){F.setWindowSize(this,d)}assertValidity(){A(this)}hasEvenY(){let{y:d}=this.toAffine();if(e.isOdd)return!e.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){p(d);let{px:b,py:I,pz:B}=this,{px:T,py:C,pz:O}=d,_=e.eql(e.mul(b,O),e.mul(T,B)),K=e.eql(e.mul(I,O),e.mul(C,B));return _&&K}negate(){return new g(this.px,e.neg(this.py),this.pz)}double(){let{a:d,b}=t,I=e.mul(b,Qo),{px:B,py:T,pz:C}=this,O=e.ZERO,_=e.ZERO,K=e.ZERO,k=e.mul(B,B),nt=e.mul(T,T),E=e.mul(C,C),x=e.mul(B,T);return x=e.add(x,x),K=e.mul(B,C),K=e.add(K,K),O=e.mul(d,K),_=e.mul(I,E),_=e.add(O,_),O=e.sub(nt,_),_=e.add(nt,_),_=e.mul(O,_),O=e.mul(x,O),K=e.mul(I,K),E=e.mul(d,E),x=e.sub(k,E),x=e.mul(d,x),x=e.add(x,K),K=e.add(k,k),k=e.add(K,k),k=e.add(k,E),k=e.mul(k,x),_=e.add(_,k),E=e.mul(T,C),E=e.add(E,E),k=e.mul(E,x),O=e.sub(O,k),K=e.mul(E,nt),K=e.add(K,K),K=e.add(K,K),new g(O,_,K)}add(d){p(d);let{px:b,py:I,pz:B}=this,{px:T,py:C,pz:O}=d,_=e.ZERO,K=e.ZERO,k=e.ZERO,nt=t.a,E=e.mul(t.b,Qo),x=e.mul(b,T),P=e.mul(I,C),w=e.mul(B,O),h=e.add(b,I),m=e.add(T,C);h=e.mul(h,m),m=e.add(x,P),h=e.sub(h,m),m=e.add(b,B);let v=e.add(T,O);return m=e.mul(m,v),v=e.add(x,w),m=e.sub(m,v),v=e.add(I,B),_=e.add(C,O),v=e.mul(v,_),_=e.add(P,w),v=e.sub(v,_),k=e.mul(nt,m),_=e.mul(E,w),k=e.add(_,k),_=e.sub(P,k),k=e.add(P,k),K=e.mul(_,k),P=e.add(x,x),P=e.add(P,x),w=e.mul(nt,w),m=e.mul(E,m),P=e.add(P,w),w=e.sub(x,w),w=e.mul(nt,w),m=e.add(m,w),x=e.mul(P,m),K=e.add(K,x),x=e.mul(v,m),_=e.mul(h,_),_=e.sub(_,x),x=e.mul(h,P),k=e.mul(v,k),k=e.add(k,x),new g(_,K,k)}subtract(d){return this.add(d.negate())}is0(){return this.equals(g.ZERO)}wNAF(d){return F.wNAFCached(this,d,g.normalizeZ)}multiplyUnsafe(d){let{endo:b,n:I}=t;_t("scalar",d,ee,I);let B=g.ZERO;if(d===ee)return B;if(this.is0()||d===ct)return this;if(!b||F.hasPrecomputes(this))return F.wNAFCachedUnsafe(this,d,g.normalizeZ);let{k1neg:T,k1:C,k2neg:O,k2:_}=b.splitScalar(d),K=B,k=B,nt=this;for(;C>ee||_>ee;)C&ct&&(K=K.add(nt)),_&ct&&(k=k.add(nt)),nt=nt.double(),C>>=ct,_>>=ct;return T&&(K=K.negate()),O&&(k=k.negate()),k=new g(e.mul(k.px,b.beta),k.py,k.pz),K.add(k)}multiply(d){let{endo:b,n:I}=t;_t("scalar",d,ct,I);let B,T;if(b){let{k1neg:C,k1:O,k2neg:_,k2:K}=b.splitScalar(d),{p:k,f:nt}=this.wNAF(O),{p:E,f:x}=this.wNAF(K);k=F.constTimeNegate(C,k),E=F.constTimeNegate(_,E),E=new g(e.mul(E.px,b.beta),E.py,E.pz),B=k.add(E),T=nt.add(x)}else{let{p:C,f:O}=this.wNAF(d);B=C,T=O}return g.normalizeZ([B,T])[0]}multiplyAndAddUnsafe(d,b,I){let B=g.BASE,T=(O,_)=>_===ee||_===ct||!O.equals(B)?O.multiplyUnsafe(_):O.multiply(_),C=T(this,b).add(T(d,I));return C.is0()?void 0:C}toAffine(d){return y(this,d)}isTorsionFree(){let{h:d,isTorsionFree:b}=t;if(d===ct)return!0;if(b)return b(g,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:d,clearCofactor:b}=t;return d===ct?this:b?b(g,this):this.multiplyUnsafe(t.h)}toRawBytes(d=!0){return Mt("isCompressed",d),this.assertValidity(),o(g,this,d)}toHex(d=!0){return Mt("isCompressed",d),ue(this.toRawBytes(d))}}g.BASE=new g(t.Gx,t.Gy,e.ONE),g.ZERO=new g(e.ZERO,e.ONE,e.ZERO);let{endo:R,nBitLength:D}=t,F=$r(g,R?Math.ceil(D/2):D);return{CURVE:t,ProjectivePoint:g,normPrivateKeyToScalar:l,weierstrassEquation:i,isWithinCurveOrder:u}}function Ol(r){let t=dr(r);return Qt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function pa(r){let t=Ol(r),{Fp:e,n,nByteLength:o,nBitLength:s}=t,i=e.BYTES+1,a=2*e.BYTES+1;function c(E){return $(E,n)}function f(E){return Wr(E,n)}let{ProjectivePoint:u,normPrivateKeyToScalar:l,weierstrassEquation:p,isWithinCurveOrder:y}=Nl({...t,toBytes(E,x,P){let w=x.toAffine(),h=e.toBytes(w.x),m=le;return Mt("isCompressed",P),P?m(Uint8Array.from([x.hasEvenY()?2:3]),h):m(Uint8Array.from([4]),h,e.toBytes(w.y))},fromBytes(E){let x=E.length,P=E[0],w=E.subarray(1);if(x===i&&(P===2||P===3)){let h=Xt(w);if(!Gr(h,ct,e.ORDER))throw new Error("Point is not on curve");let m=p(h),v;try{v=e.sqrt(m)}catch(M){let q=M instanceof Error?": "+M.message:"";throw new Error("Point is not on curve"+q)}let L=(v&ct)===ct;return(P&1)===1!==L&&(v=e.neg(v)),{x:h,y:v}}else if(x===a&&P===4){let h=e.fromBytes(w.subarray(0,e.BYTES)),m=e.fromBytes(w.subarray(e.BYTES,2*e.BYTES));return{x:h,y:m}}else{let h=i,m=a;throw new Error("invalid Point, expected length of "+h+", or uncompressed "+m+", got "+x)}}});function A(E){let x=n>>ct;return E>x}function g(E){return A(E)?c(-E):E}let R=(E,x,P)=>Xt(E.slice(x,P));class D{constructor(x,P,w){_t("r",x,ct,n),_t("s",P,ct,n),this.r=x,this.s=P,w!=null&&(this.recovery=w),Object.freeze(this)}static fromCompact(x){let P=o;return x=X("compactSignature",x,P*2),new D(R(x,0,P),R(x,P,2*P))}static fromDER(x){let{r:P,s:w}=te.toSig(X("DER",x));return new D(P,w)}assertValidity(){}addRecoveryBit(x){return new D(this.r,this.s,x)}recoverPublicKey(x){let{r:P,s:w,recovery:h}=this,m=B(X("msgHash",x));if(h==null||![0,1,2,3].includes(h))throw new Error("recovery id invalid");let v=h===2||h===3?P+t.n:P;if(v>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let L=(h&1)===0?"02":"03",U=u.fromHex(L+Xo(v,e.BYTES)),M=f(v),q=c(-m*M),V=c(w*M),G=u.BASE.multiplyAndAddUnsafe(U,q,V);if(!G)throw new Error("point at infinify");return G.assertValidity(),G}hasHighS(){return A(this.s)}normalizeS(){return this.hasHighS()?new D(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return fr(this.toDERHex())}toDERHex(){return te.hexFromSig(this)}toCompactRawBytes(){return fr(this.toCompactHex())}toCompactHex(){let x=o;return Xo(this.r,x)+Xo(this.s,x)}}let F={isValidPrivateKey(E){try{return l(E),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let E=lo(t.n);return Ni(t.randomBytes(E),t.n)},precompute(E=8,x=u.BASE){return x._setWindowSize(E),x.multiply(BigInt(3)),x}};function S(E,x=!0){return u.fromPrivateKey(E).toRawBytes(x)}function d(E){if(typeof E=="bigint")return!1;if(E instanceof u)return!0;let P=X("key",E).length,w=e.BYTES,h=w+1,m=2*w+1;if(!(t.allowedPrivateKeyLengths||o===h))return P===h||P===m}function b(E,x,P=!0){if(d(E)===!0)throw new Error("first arg must be private key");if(d(x)===!1)throw new Error("second arg must be public key");return u.fromHex(x).multiply(l(E)).toRawBytes(P)}let I=t.bits2int||function(E){if(E.length>8192)throw new Error("input is too large");let x=Xt(E),P=E.length*8-s;return P>0?x>>BigInt(P):x},B=t.bits2int_modN||function(E){return c(I(E))},T=ve(s);function C(E){return _t("num < 2^"+s,E,ee,T),Ee(E,o)}function O(E,x,P=_){if(["recovered","canonical"].some(et=>et in P))throw new Error("sign() legacy options not supported");let{hash:w,randomBytes:h}=t,{lowS:m,prehash:v,extraEntropy:L}=P;m==null&&(m=!0),E=X("msgHash",E),ha(P),v&&(E=X("prehashed msgHash",w(E)));let U=B(E),M=l(x),q=[C(M),C(U)];if(L!=null&&L!==!1){let et=L===!0?h(e.BYTES):L;q.push(X("extraEntropy",et))}let V=le(...q),G=U;function ot(et){let ut=I(et);if(!y(ut))return;let vt=f(ut),it=u.BASE.multiply(ut).toAffine(),ft=c(it.x);if(ft===ee)return;let Tt=c(vt*c(G+ft*M));if(Tt===ee)return;let Ct=(it.x===ft?0:2)|Number(it.y&ct),je=Tt;return m&&A(Tt)&&(je=g(Tt),Ct^=1),new D(ft,je,Ct)}return{seed:V,k2sig:ot}}let _={lowS:t.lowS,prehash:!1},K={lowS:t.lowS,prehash:!1};function k(E,x,P=_){let{seed:w,k2sig:h}=O(E,x,P),m=t;return _i(m.hash.outputLen,m.nByteLength,m.hmac)(w,h)}u.BASE._setWindowSize(8);function nt(E,x,P,w=K){let h=E;x=X("msgHash",x),P=X("publicKey",P);let{lowS:m,prehash:v,format:L}=w;if(ha(w),"strict"in w)throw new Error("options.strict was renamed to lowS");if(L!==void 0&&L!=="compact"&&L!=="der")throw new Error("format must be compact or der");let U=typeof h=="string"||Oe(h),M=!U&&!L&&typeof h=="object"&&h!==null&&typeof h.r=="bigint"&&typeof h.s=="bigint";if(!U&&!M)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let q,V;try{if(M&&(q=new D(h.r,h.s)),U){try{L!=="compact"&&(q=D.fromDER(h))}catch(Ct){if(!(Ct instanceof te.Err))throw Ct}!q&&L!=="der"&&(q=D.fromCompact(h))}V=u.fromHex(P)}catch{return!1}if(!q||m&&q.hasHighS())return!1;v&&(x=t.hash(x));let{r:G,s:ot}=q,et=B(x),ut=f(ot),vt=c(et*ut),it=c(G*ut),ft=u.BASE.multiplyAndAddUnsafe(V,vt,it)?.toAffine();return ft?c(ft.x)===G:!1}return{CURVE:t,getPublicKey:S,getSharedSecret:b,sign:k,verify:nt,ProjectivePoint:u,Signature:D,utils:F}}function Ml(r){return{hash:r,hmac:(t,...e)=>jo(r,t,Qn(...e)),randomBytes:Hr}}function ma(r,t){let e=n=>pa({...r,...Ml(n)});return{...e(t),create:e}}var ba=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),ya=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),ql=BigInt(0),Hl=BigInt(1),ts=BigInt(2),ga=(r,t)=>(r+t/ts)/t;function Vl(r){let t=ba,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,p=Q(l,e,t)*u%t,y=Q(p,ts,t)*f%t,A=Q(y,o,t)*y%t,g=Q(A,s,t)*A%t,R=Q(g,a,t)*g%t,D=Q(R,c,t)*R%t,F=Q(D,a,t)*g%t,S=Q(F,e,t)*u%t,d=Q(S,i,t)*A%t,b=Q(d,n,t)*f%t,I=Q(b,ts,t);if(!es.eql(es.sqr(I),r))throw new Error("Cannot find square root");return I}var es=Jt(ba,void 0,void 0,{sqrt:Vl}),Fe=ma({a:ql,b:BigInt(7),Fp:es,n:ya,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=ya,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Hl*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),a=ga(s*r,t),c=ga(-n*r,t),f=$(r-a*e-c*o,t),u=$(-a*n-c*s,t),l=f>i,p=u>i;if(l&&(f=t-f),p&&(u=t-u),f>i||u>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:l,k1:f,k2neg:p,k2:u}}}},Fr);function wa(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function xa(r,t,e){let n=rr.digest(e instanceof Uint8Array?e:e.subarray());if(wa(n))return n.then(({digest:o})=>Fe.verify(t,o,r)).catch(o=>{throw new yr(String(o))});try{return Fe.verify(t,n.digest,r)}catch(o){throw new yr(String(o))}}var nn=class{type="secp256k1";raw;_key;constructor(t){this._key=va(t),this.raw=Ea(this._key)}toMultihash(){return Kt.digest(kt(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return Z.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 xa(this._key,e,t)}};function rs(r){return new nn(r)}function Ea(r){return Fe.ProjectivePoint.fromHex(r).toRawBytes(!0)}function va(r){try{return Fe.ProjectivePoint.fromHex(r),r}catch(t){throw new Le(String(t))}}function on(r,t){let{Type:e,Data:n}=Vt.decode(r),o=n??new Uint8Array;switch(e){case rt.RSA:return $o(o,t);case rt.Ed25519:return wo(o);case rt.secp256k1:return rs(o);case rt.ECDSA:return Xn(o);default:throw new me}}function Aa(r){let{Type:t,Data:e}=Vt.decode(r.digest),n=e??new Uint8Array;switch(t){case rt.Ed25519:return wo(n);case rt.secp256k1:return rs(n);case rt.ECDSA:return Xn(n);default:throw new me}}function kt(r){return Vt.encode({Type:rt[r.type],Data:r.raw})}var Sa=Symbol.for("nodejs.util.inspect.custom"),zl=114,wr=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()})`}[Cr]=!0;toString(){return this.string==null&&(this.string=Z.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return tt.createV1(zl,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")}[Sa](){return`PeerId(${this.toString()})`}},xr=class extends wr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Er=class extends wr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},vr=class extends wr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Fl=2336,Ar=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Kt.digest(W(this.url))}[Sa](){return`PeerId(${this.url})`}[Cr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return tt.createV1(Fl,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=N(t)),t.toString()===this.toString())}};var Gl=114,Ia=2336;function Ba(r){if(r.type==="Ed25519")return new Er({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new vr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new xr({multihash:r.toCID().multihash,publicKey:r});throw new me}function ns(r){if($l(r))return new xr({multihash:r});if(Wl(r))try{let t=Aa(r);if(t.type==="Ed25519")return new Er({multihash:r,publicKey:t});if(t.type==="secp256k1")return new vr({multihash:r,publicKey:t})}catch{let e=N(r.digest);return new Ar(new URL(e))}throw new Dr("Supplied PeerID Multihash is invalid")}function sn(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==Gl&&r.code!==Ia)throw new Rr("Supplied PeerID CID is invalid");if(r.code===Ia){let t=N(r.multihash.digest);return new Ar(new URL(t))}return ns(r.multihash)}function Wl(r){return r.code===Kt.code}function $l(r){return r.code===rr.code}var Sr;(function(r){let t;r.codec=()=>(t==null&&(t=xt((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:st(0),payloadType:st(0),payload:st(0),signature:st(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=>wt(e,r.codec()),r.decode=(e,n)=>bt(e,r.codec(),n)})(Sr||(Sr={}));var an=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var Ge=class r{static createFromProtobuf=async t=>{let e=Sr.decode(t),n=on(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=Ta(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 an("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=Sr.encode({publicKey:kt(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return t==null?!1:j(this.marshal(),t.marshal())}async validate(t){let e=Ta(t,this.payloadType,this.payload);return this.publicKey.verify(e.subarray(),this.signature)}},Ta=(r,t,e)=>{let n=W(r),o=Ht(n.byteLength),s=Ht(t.length),i=Ht(e.length);return new mt(o,n,s,t,i,e)};function Pa(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 cn=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 p=Number.parseInt(l,t);if(!Number.isNaN(p))return p});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 _a=45,Zl=15,We=new cn;function os(r){if(!(r.length>Zl))return We.new(r).parseWith(()=>We.readIPv4Addr())}function ss(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>_a))return We.new(r).parseWith(()=>We.readIPv6Addr())}function un(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>_a)return;let e=We.new(r).parseWith(()=>We.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 Gm=parseInt("0xFFFF",16),Wm=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Ca(r){return!!os(r)}function Ra(r){return!!ss(r)}function ln(r){return!!un(r)}var Da=Ca,Jl=Ra,is=function(r){let t=0;if(r=r.toString().trim(),Da(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(Jl(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=Da(e[n]),i;s&&(i=is(e[n]),e[n]=N(i.slice(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,N(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")},Ka=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 $e={},as={},ef=[[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"]];ef.forEach(r=>{let t=rf(...r);as[t.code]=t,$e[t.name]=t});function rf(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function Y(r){if(typeof r=="number"){if(as[r]!=null)return as[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if($e[r]!=null)return $e[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var _y=Y("ip4"),Ly=Y("ip6"),ky=Y("ipcidr");function fs(r,t){switch(Y(r).code){case 4:case 41:return of(t);case 42:return ls(t);case 43:return N(t,"base10");case 6:case 273:case 33:case 132:return Oa(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return ls(t);case 421:return uf(t);case 444:return Na(t);case 445:return Na(t);case 466:return cf(t);case 481:return globalThis.encodeURIComponent(ls(t));default:return N(t,"base16")}}function ds(r,t){switch(Y(r).code){case 4:return Ua(t);case 41:return Ua(t);case 42:return us(t);case 43:return W(t,"base10");case 6:case 273:case 33:case 132:return hs(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return us(t);case 421:return sf(t);case 444:return lf(t);case 445:return ff(t);case 466:return af(t);case 481:return us(globalThis.decodeURIComponent(t));default:return W(t,"base16")}}var cs=Object.values(nr).map(r=>r.decoder),nf=function(){let r=cs[0].or(cs[1]);return cs.slice(2).forEach(t=>r=r.or(t)),r}();function Ua(r){if(!ln(r))throw new Error("invalid ip address");return is(r)}function of(r){let t=Ka(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!ln(t))throw new Error("invalid ip address");return t}function hs(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Oa(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function us(r){let t=W(r),e=Uint8Array.from(Ht(t.length));return Pt([e,t],e.length+t.length)}function ls(r){let t=Se(r);if(r=r.slice(Bt(t)),r.length!==t)throw new Error("inconsistent lengths");return N(r)}function sf(r){let t;r[0]==="Q"||r[0]==="1"?t=Gt(Z.decode(`z${r}`)).bytes:t=tt.parse(r).multihash.bytes;let e=Uint8Array.from(Ht(t.length));return Pt([e,t],e.length+t.length)}function af(r){let t=nf.decode(r),e=Uint8Array.from(Ht(t.length));return Pt([e,t],e.length+t.length)}function cf(r){let t=Se(r),e=r.slice(Bt(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+N(e,"base64url")}function uf(r){let t=Se(r),e=r.slice(Bt(t));if(e.length!==t)throw new Error("inconsistent lengths");return N(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=Rt.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=hs(n);return Pt([e,o],e.length+o.length)}function ff(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=Rt.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=hs(n);return Pt([e,o],e.length+o.length)}function Na(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=N(t,"base32"),o=Oa(e);return`${n}:${o}`}function Ma(r){r=ps(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=Y(i);if(a.size===0){t.push([a.code]),e.push([a.code]);continue}if(s++,s>=o.length)throw new fn("invalid address: "+r);if(a.path===!0){n=ps(o.slice(s).join("/")),t.push([a.code,ds(a.code,n)]),e.push([a.code,n]);break}let c=ds(a.code,o[s]);t.push([a.code,c]),e.push([a.code,fs(a.code,c)])}return{string:qa(e),bytes:dn(t),tuples:t,stringTuples:e,path:n}}function ms(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let s=Se(r,o),i=Bt(s),a=Y(s),c=df(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 fn("Invalid address Uint8Array: "+N(r,"base16"));t.push([s,f]);let u=fs(s,f);if(e.push([s,u]),a.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:qa(e),tuples:t,stringTuples:e,path:n}}function qa(r){let t=[];return r.map(e=>{let n=Y(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),ps(t.join("/"))}function dn(r){return Pt(r.map(t=>{let e=Y(t[0]),n=Uint8Array.from(Ht(e.code));return t.length>1&&t[1]!=null&&(n=Pt([n,t[1]])),n}))}function df(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=Se(t instanceof Uint8Array?t:Uint8Array.from(t));return e+Bt(e)}}function ps(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}var fn=class extends Error{static name="ParseError";name="ParseError";constructor(t){super(`Error parsing address: ${t}`)}};var hf=Symbol.for("nodejs.util.inspect.custom"),gs=Symbol.for("@multiformats/js-multiaddr/multiaddr"),pf=[Y("dns").code,Y("dns4").code,Y("dns6").code,Y("dnsaddr").code],ys=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},hn=class r{bytes;#t;#e;#r;#a;[gs]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=ms(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Ma(t)}else if(pn(t))e=ms(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=Y("tcp"),a=Y("udp"),c=Y("ip4"),f=Y("ip6"),u=Y("dns6"),l=Y("ip6zone");for(let[y,A]of this.stringTuples())y===l.code&&(s=`%${A??""}`),pf.includes(y)&&(e=i.name==="tcp"?"tcp":"udp",o=443,n=`${A??""}${s}`,t=y===u.code?6:4),(y===i.code||y===a.code)&&(e=Y(y).name==="tcp"?"tcp":"udp",o=parseInt(A??"")),(y===c.code||y===f.code)&&(e=Y(y).name==="tcp"?"tcp":"udp",n=`${A??""}${s}`,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({},Y(t)))}protoCodes(){return this.#e.map(([t])=>t)}protoNames(){return this.#e.map(([t])=>Y(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(dn(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===$e.p2p.code&&t.push([n,o]),n===$e["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?N(Z.decode(`z${n}`),"base58btc"):N(tt.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=Ha.get(e.name);if(n==null)throw new ys(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>zt(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)}[hf](){return`Multiaddr(${this.#t})`}};var Ha=new Map;function pn(r){return!!r?.[gs]}function zt(r){return new hn(r)}var Va="libp2p-peer-record",za=Uint8Array.from([3,1]);var Ir;(function(r){let t;(function(n){let o;n.codec=()=>(o==null&&(o=xt((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:st(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=>wt(s,n.codec()),n.decode=(s,i)=>bt(s,n.codec(),i)})(t=r.AddressInfo||(r.AddressInfo={}));let e;r.codec=()=>(e==null&&(e=xt((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:st(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 Te('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=>wt(n,r.codec()),r.decode=(n,o)=>bt(n,r.codec(),o)})(Ir||(Ir={}));var Pe=class r{static createFromProtobuf=t=>{let e=Ir.decode(t),n=ns(Gt(e.peerId)),o=(e.addresses??[]).map(i=>zt(i.multiaddr)),s=e.seq;return new r({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Va;static CODEC=za;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=Ir.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||!Pa(this.multiaddrs,t.multiaddrs))}};function mf(r){return r[Symbol.asyncIterator]!=null}function yf(r){if(mf(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 Fa=yf;var ws=wc(Wa(),1);var Tr=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},xs=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},$a=r=>globalThis.DOMException===void 0?new xs(r):new DOMException(r),Za=r=>{let t=r.reason===void 0?$a("This operation was aborted."):r.reason;return t instanceof Error?t:$a(t)};function Pr(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:y}=t;y.aborted&&l(Za(y)),a=()=>{l(Za(y))},y.addEventListener("abort",a,{once:!0})}if(e===Number.POSITIVE_INFINITY){r.then(u,l);return}let p=new Tr;i=s.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):(p.message=o??`Promise timed out after ${e} milliseconds`,l(p))},e),(async()=>{try{u(await r)}catch(y){l(y)}})()}).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 Es(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 _r=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=Es(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 Ze=class extends ws.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:_r,...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")}#A(){this.#b(),this.#g(),this.#u=void 0}get#S(){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.#A()},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.#S;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=Pr(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 Tr&&!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={},Ye=r=>{r.addEventListener("message",t=>{Ye.dispatchEvent("message",r,t)}),r.port!=null&&r.port.addEventListener("message",t=>{Ye.dispatchEvent("message",r,t)})};Ye.addEventListener=(r,t)=>{he[r]==null&&(he[r]=[]),he[r].push(t)};Ye.removeEventListener=(r,t)=>{he[r]!=null&&(he[r]=he[r].filter(e=>e===t))};Ye.dispatchEvent=function(r,t,e){he[r]!=null&&he[r].forEach(n=>n(t,e))};var vs=Ye;var As="lock:worker:request-read",Ss="lock:worker:release-read",Is="lock:master:grant-read",Bs="lock:worker:request-write",Ts="lock:worker:release-write",Ps="lock:master:grant-write";var Ya=(r=21)=>Math.random().toString().substring(2);var ja=(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)})}}}))},Xa=(r,t,e,n)=>async()=>{let o=Ya();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)})},wf={singleProcess:!1},Qa=r=>{if(r=Object.assign({},wf,r),!!globalThis.document||r.singleProcess){let e=new EventTarget;return vs.addEventListener("message",ja(e,"requestReadLock",As,Ss,Is)),vs.addEventListener("message",ja(e,"requestWriteLock",Bs,Ts,Ps)),e}return{isWorker:!0,readLock:e=>Xa(e,As,Is,Ss),writeLock:e=>Xa(e,Bs,Ps,Ts)}};var _e={},pe;async function _s(r,t){let e,n=new Promise(o=>{e=o});return r.add(async()=>Pr((async()=>{await new Promise(o=>{e(()=>{o()})})})(),{milliseconds:t.timeout})),n}var xf=(r,t)=>{if(pe.isWorker===!0)return{readLock:pe.readLock(r,t),writeLock:pe.writeLock(r,t)};let e=new Ze({concurrency:1}),n;return{async readLock(){if(n!=null)return _s(n,t);n=new Ze({concurrency:t.concurrency,autoStart:!1});let o=n,s=_s(n,t);return e.add(async()=>{o.start(),await o.onIdle().then(()=>{n===o&&(n=null)})}),s},async writeLock(){return n=null,_s(e,t)}}},Ef={name:"lock",concurrency:1/0,timeout:846e5,singleProcess:!1};function Ls(r){let t=Object.assign({},Ef,r);return pe==null&&(pe=Qa(t),pe.isWorker!==!0&&(pe.addEventListener("requestReadLock",e=>{_e[e.data.name]!=null&&_e[e.data.name].readLock().then(async n=>e.data.handler().finally(()=>{n()}))}),pe.addEventListener("requestWriteLock",async e=>{_e[e.data.name]!=null&&_e[e.data.name].writeLock().then(async n=>e.data.handler().finally(()=>{n()}))}))),_e[t.name]==null&&(_e[t.name]=xf(t.name,t)),_e[t.name]}var re;(function(r){let t;(function(o){let s;o.codec=()=>(s==null&&(s=xt((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:st(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=>wt(i,o.codec()),o.decode=(i,a)=>bt(i,o.codec(),a)})(t=r.Peer$metadataEntry||(r.Peer$metadataEntry={}));let e;(function(o){let s;o.codec=()=>(s==null&&(s=xt((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),gn.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=gn.codec().decode(i,i.uint32(),{limits:c.limits?.value});break}default:{i.skipType(l&7);break}}}return f})),s),o.encode=i=>wt(i,o.codec()),o.decode=(i,a)=>bt(i,o.codec(),a)})(e=r.Peer$tagsEntry||(r.Peer$tagsEntry={}));let n;r.codec=()=>(n==null&&(n=xt((o,s,i={})=>{if(i.lengthDelimited!==!1&&s.fork(),o.addresses!=null)for(let a of o.addresses)s.uint32(10),yn.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 Te('Decode error - map field "addresses" had too many elements');a.addresses.push(yn.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 Te('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 mr('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 mr('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=>wt(o,r.codec()),r.decode=(o,s)=>bt(o,r.codec(),s)})(re||(re={}));var yn;(function(r){let t;r.codec=()=>(t==null&&(t=xt((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:st(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=>wt(e,r.codec()),r.decode=(e,n)=>bt(e,r.codec(),n)})(yn||(yn={}));var gn;(function(r){let t;r.codec=()=>(t==null&&(t=xt((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=>wt(e,r.codec()),r.decode=(e,n)=>bt(e,r.codec(),n)})(gn||(gn={}));function vf(r,t){if(r.publicKey!=null||t.publicKey==null)return r;let e;if(r.type==="RSA"){let o=Z.decode(`z${r}`);e=Gt(o)}let n=on(t.publicKey,e);return Ba(n)}function bn(r,t,e){let n=re.decode(t);return wn(r,n,e)}function wn(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:vf(r,t),addresses:t.addresses.filter(({observed:s})=>s!=null&&s>Date.now()-e).map(({multiaddr:s,isCertified:i})=>({multiaddr:zt(s),isCertified:i??!1})),metadata:t.metadata,peerRecordEnvelope:t.peerRecordEnvelope??void 0,tags:n}}function Ja(r,t){return Af(r.addresses,t.addresses)&&Sf(r.protocols,t.protocols)&&If(r.publicKey,t.publicKey)&&Bf(r.peerRecordEnvelope,t.peerRecordEnvelope)&&Tf(r.metadata,t.metadata)&&Pf(r.tags,t.tags)}function Af(r,t){return ec(r,t,(e,n)=>!(e.isCertified!==n.isCertified||!j(e.multiaddr,n.multiaddr)))}function Sf(r,t){return ec(r,t,(e,n)=>e===n)}function If(r,t){return tc(r,t)}function Bf(r,t){return tc(r,t)}function Tf(r,t){return rc(r,t,(e,n)=>j(e,n))}function Pf(r,t){return rc(r,t,(e,n)=>e.value===n.value&&e.expiry===n.expiry)}function tc(r,t){return r==null&&t==null?!0:r!=null&&t!=null?j(r,t):!1}function ec(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 rc(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 ne="/",nc=new TextEncoder().encode(ne),xn=nc[0],En=class r{_buf;constructor(t,e){if(typeof t=="string")this._buf=W(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]!==xn)throw new Error("Invalid key")}toString(t="utf8"){return N(this._buf,t)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(t){return new r(t.join(ne))}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=nc),this._buf[0]!==xn){let t=new Uint8Array(this._buf.byteLength+1);t.fill(xn,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===xn;)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(ne).slice(1)}type(){return _f(this.baseNamespace())}name(){return Lf(this.baseNamespace())}instance(t){return new r(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(ne)||(t+=ne),t+=this.type(),new r(t)}parent(){let t=this.list();return t.length===1?new r(ne):new r(t.slice(0,-1).join(ne))}child(t){return this.toString()===ne?t:t.toString()===ne?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(),...kf(t.map(e=>e.namespaces()))])}};function _f(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 kf(r){return[].concat(...r)}var ks="/peers/";function Lr(r){if(!Us(r)||r.type==null)throw new H("Invalid PeerId");let t=r.toCID().toString();return new En(`${ks}${t}`)}async function oc(r,t,e,n){let o=new Map;for(let s of e){if(s==null)continue;if(s.multiaddr instanceof Uint8Array&&(s.multiaddr=zt(s.multiaddr)),!pn(s.multiaddr))throw new H("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})=>{let a=i.getPeerId();return r.equals(a)&&(i=i.decapsulate(zt(`/p2p/${r}`))),{isCertified:s,multiaddr:i.bytes}})}async function An(r,t,e,n){if(t==null)throw new H("Invalid PeerData");if(t.publicKey!=null&&r.publicKey!=null&&!t.publicKey.equals(r.publicKey))throw new H("publicKey bytes do not match peer id publicKey bytes");let o=n.existingPeer?.peer;if(o!=null&&!r.equals(o.id))throw new H("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(p=>({isCertified:!1,multiaddr:p}))),t.addresses!=null&&s.push(...t.addresses)),t.protocols!=null&&(i=new Set(t.protocols)),t.metadata!=null){let p=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);a=vn(p,{validate:sc})}if(t.tags!=null){let p=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags);c=vn(p,{validate:ic,map:ac})}t.peerRecordEnvelope!=null&&(f=t.peerRecordEnvelope)}if(e==="merge"){if(t.multiaddrs!=null&&s.push(...t.multiaddrs.map(p=>({isCertified:!1,multiaddr:p}))),t.addresses!=null&&s.push(...t.addresses),t.protocols!=null&&(i=new Set([...i,...t.protocols])),t.metadata!=null){let p=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);for(let[y,A]of p)A==null?a.delete(y):a.set(y,A);a=vn([...a.entries()],{validate:sc})}if(t.tags!=null){let p=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags),y=new Map(c);for(let[A,g]of p)g==null?y.delete(A):y.set(A,g);c=vn([...y.entries()],{validate:ic,map:ac})}t.peerRecordEnvelope!=null&&(f=t.peerRecordEnvelope)}let u;o?.id.publicKey!=null?u=kt(o.id.publicKey):t.publicKey!=null?u=kt(t.publicKey):r.publicKey!=null&&(u=kt(r.publicKey));let l={addresses:await oc(r,n.addressFilter??(async()=>!0),s,n.existingPeer?.peerPB.addresses),protocols:[...i.values()].sort((p,y)=>p.localeCompare(y)),metadata:a,tags:c,publicKey:u,peerRecordEnvelope:f};return l.addresses.forEach(p=>{p.observed=n.existingPeer?.peerPB.addresses?.find(y=>j(y.multiaddr,y.multiaddr))?.observed??Date.now()}),r.type!=="RSA"&&delete l.publicKey,l}function vn(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 sc(r,t){if(typeof r!="string")throw new H("Metadata key must be a string");if(!(t instanceof Uint8Array))throw new H("Metadata value must be a Uint8Array")}function ic(r,t){if(typeof r!="string")throw new H("Tag name must be a string");if(t.value!=null){if(parseInt(`${t.value}`,10)!==t.value)throw new H("Tag value must be an integer");if(t.value<0||t.value>100)throw new H("Tag value must be between 0-100")}if(t.ttl!=null){if(parseInt(`${t.ttl}`,10)!==t.ttl)throw new H("Tag ttl must be an integer");if(t.ttl<0)throw new H("Tag ttl must be between greater than 0")}}function ac(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 cc(r){let t=r.toString().split("/")[2],e=tt.parse(t,Rt);return sn(e)}function Cs(r,t,e){let n=cc(r);return bn(n,t,e)}function Cf(r,t){return{prefix:ks,filters:(r.filters??[]).map(e=>({key:n,value:o})=>e(Cs(n,o,t))),orders:(r.orders??[]).map(e=>(n,o)=>e(Cs(n.key,n.value,t),Cs(o.key,o.value,t)))}}var Sn=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=Ls({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(Lr(t))}async load(t){let e=Lr(t),n=await this.datastore.get(e),o=re.decode(n);if(this.#r(t,o))throw await this.datastore.delete(e),new Xe;return wn(t,o,this.peerId.equals(t)?1/0:this.maxAddressAge)}async save(t,e){let n=await this.#t(t),o=await An(t,e,"patch",{addressFilter:this.addressFilter});return this.#e(t,o,n)}async patch(t,e){let n=await this.#t(t),o=await An(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 An(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=cc(e);if(o.equals(this.peerId))continue;let s=re.decode(n);if(this.#r(o,s)){await this.datastore.delete(e);continue}yield wn(o,s,this.peerId.equals(o)?1/0:this.maxAddressAge)}}async#t(t){try{let e=Lr(t),n=await this.datastore.get(e),o=re.decode(n);if(this.#r(t,o))throw await this.datastore.delete(e),new Xe;return{peerPB:o,peer:bn(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=re.encode(e);return await this.datastore.put(Lr(t),o),{peer:bn(t,o,this.maxAddressAge),previous:n?.peer,updated:n==null||!Ja(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 Rs=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 Sn(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 Fa(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 getInfo(t){let e=await this.get(t);return{id:e.id,multiaddrs:e.addresses.map(({multiaddr:n})=>n)}}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 Ge.openAndCertify(t,Pe.DOMAIN),o=sn(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=Pe.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 Ge.createFromProtobuf(i.peerRecordEnvelope),c=Pe.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 Rf(r,t={}){return new Rs(r,t)}return xc(Df);})();
2
+ "use strict";var Libp2PPeerStore=(()=>{var Hn=Object.defineProperty;var dc=Object.getOwnPropertyDescriptor;var hc=Object.getOwnPropertyNames;var pc=Object.prototype.hasOwnProperty;var pt=(r,t)=>{for(var e in t)Hn(r,e,{get:t[e],enumerable:!0})},mc=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of hc(t))!pc.call(r,o)&&o!==e&&Hn(r,o,{get:()=>t[o],enumerable:!(n=dc(t,o))||n.enumerable});return r};var yc=r=>mc(Hn({},"__esModule",{value:!0}),r);var Uf={};pt(Uf,{persistentPeerStore:()=>Nf});var _r=Symbol.for("@libp2p/peer-id");function ge(r){return!!r?.[_r]}var U=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},we=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Ve=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"}},Lr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var re=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var xe=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){super.addEventListener(t,e,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==e),this.#t.set(t,o))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var Gn={};pt(Gn,{base58btc:()=>z,base58flickr:()=>Sc});var zf=new Uint8Array(0);function Ms(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){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 qs(r){return new TextEncoder().encode(r)}function Hs(r){return new TextDecoder().decode(r)}function bc(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 E=0,m=0,S=0,L=w.length;S!==L&&w[S]===0;)S++,E++;for(var A=(L-S)*u+1>>>0,k=new Uint8Array(A);S!==L;){for(var b=w[S],P=0,T=A-1;(b!==0||P<m)&&T!==-1;T--,P++)b+=256*k[T]>>>0,k[T]=b%a>>>0,b=b/a>>>0;if(b!==0)throw new Error("Non-zero carry");m=P,S++}for(var _=A-m;_!==A&&k[_]===0;)_++;for(var h=c.repeat(E);_<A;++_)h+=r.charAt(k[_]);return h}function p(w){if(typeof w!="string")throw new TypeError("Expected String");if(w.length===0)return new Uint8Array;var E=0;if(w[E]!==" "){for(var m=0,S=0;w[E]===c;)m++,E++;for(var L=(w.length-E)*f+1>>>0,A=new Uint8Array(L);w[E];){var k=e[w.charCodeAt(E)];if(k===255)return;for(var b=0,P=L-1;(k!==0||b<S)&&P!==-1;P--,b++)k+=a*A[P]>>>0,A[P]=k%256>>>0,k=k/256>>>0;if(k!==0)throw new Error("Non-zero carry");S=b,E++}if(w[E]!==" "){for(var T=L-S;T!==L&&A[T]===0;)T++;for(var _=new Uint8Array(m+(L-T)),h=m;T!==L;)_[h++]=A[T++];return _}}}function d(w){var E=p(w);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:p,decode:d}}var gc=bc,wc=gc,Fs=wc;var zn=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")}},Fn=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)}},Vn=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 Vn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Wn=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 zn(t,e,n),this.decoder=new Fn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ee({name:r,prefix:t,encode:e,decode:n}){return new Wn(r,t,e,n)}function Gt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Fs(e,r);return Ee({prefix:t,name:r,encode:n,decode:s=>Nt(o(s))})}function xc(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let f=0;f<o;++f){let u=t[r[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|u,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Ec(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 vc(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function j({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=vc(n);return Ee({prefix:t,name:r,encode(s){return Ec(s,n,e)},decode(s){return xc(s,o,e,r)}})}var z=Gt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Sc=Gt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var $n={};pt($n,{base32:()=>St,base32hex:()=>Bc,base32hexpad:()=>Rc,base32hexpadupper:()=>Tc,base32hexupper:()=>Lc,base32pad:()=>Ic,base32padupper:()=>_c,base32upper:()=>Ac,base32z:()=>Pc});var St=j({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ac=j({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ic=j({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),_c=j({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Bc=j({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Lc=j({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Rc=j({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Tc=j({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Pc=j({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var jn={};pt(jn,{base36:()=>We,base36upper:()=>kc});var We=Gt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),kc=Gt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Cc=$s,Ws=128,Kc=127,Dc=~Kc,Nc=Math.pow(2,31);function $s(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Nc;)t[e++]=r&255|Ws,r/=128;for(;r&Dc;)t[e++]=r&255|Ws,r>>>=7;return t[e]=r|0,$s.bytes=e-n+1,t}var Uc=Zn,Oc=128,Gs=127;function Zn(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Zn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Gs)<<o:(i&Gs)*Math.pow(2,o),o+=7}while(i>=Oc);return Zn.bytes=s-n,e}var Mc=Math.pow(2,7),qc=Math.pow(2,14),Hc=Math.pow(2,21),zc=Math.pow(2,28),Fc=Math.pow(2,35),Vc=Math.pow(2,42),Wc=Math.pow(2,49),Gc=Math.pow(2,56),$c=Math.pow(2,63),jc=function(r){return r<Mc?1:r<qc?2:r<Hc?3:r<zc?4:r<Fc?5:r<Vc?6:r<Wc?7:r<Gc?8:r<$c?9:10},Zc={encode:Cc,decode:Uc,encodingLength:jc},Yc=Zc,Ge=Yc;function $e(r,t=0){return[Ge.decode(r,t),Ge.decode.bytes]}function ve(r,t,e=0){return Ge.encode(r,t,e),t}function Se(r){return Ge.encodingLength(r)}function At(r,t){let e=t.byteLength,n=Se(r),o=n+Se(e),s=new Uint8Array(o+e);return ve(r,s,0),ve(e,s,n),s.set(t,o),new Ae(r,e,t,s)}function $t(r){let t=Nt(r),[e,n]=$e(t),[o,s]=$e(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ae(e,o,i,t)}function js(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Ms(r.bytes,e.bytes)}}var Ae=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function Zs(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Qc(e,Yn(r),t??z.encoder);default:return Jc(e,Yn(r),t??St.encoder)}}var Ys=new WeakMap;function Yn(r){let t=Ys.get(r);if(t==null){let e=new Map;return Ys.set(r,e),e}return t}var Z=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==je)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==tu)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=At(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&js(t.multihash,n.multihash)}toString(t){return Zs(this,t)}toJSON(){return{"/":Zs(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??Xs(n,o,s.bytes))}else if(e[eu]===!0){let{version:n,multihash:o,code:s}=e,i=$t(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=Xs(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=Nt(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 Ae(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,p]=$e(t.subarray(e));return e+=p,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]=Xc(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 Yn(s).set(n,t),s}};function Xc(r,t){switch(r[0]){case"Q":{let e=t??z;return[z.prefix,e.decode(`${z.prefix}${r}`)]}case z.prefix:{let e=t??z;return[z.prefix,e.decode(r)]}case St.prefix:{let e=t??St;return[St.prefix,e.decode(r)]}case We.prefix:{let e=t??We;return[We.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 Qc(r,t,e){let{prefix:n}=e;if(n!==z.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 Jc(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,tu=18;function Xs(r,t,e){let n=Se(r),o=n+Se(t),s=new Uint8Array(o+e.byteLength);return ve(r,s,0),ve(t,s,n),s.set(e,o),s}var eu=Symbol.for("@ipld/js-cid/CID");var Xn={};pt(Xn,{identity:()=>It});var Qs=0,ru="identity",Js=Nt;function nu(r){return At(Qs,Js(r))}var It={code:Qs,name:ru,encode:Js,digest:nu};function V(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function J(r=0){return new Uint8Array(r)}function mt(r=0){return new Uint8Array(r)}function gt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=mt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var ei=Symbol.for("@achingbrain/uint8arraylist");function ti(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 Tr(r){return!!r?.[ei]}var ct=class r{bufs;length;[ei]=!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(Tr(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(Tr(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=ti(this.bufs,t);return e.buf[e.index]}set(t,e){let n=ti(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(Tr(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 gt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:gt(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(!Tr(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 p=f;p>=0;p--){let d=this.get(l+p);if(n[p]!==d){u=Math.max(1,p-a[d]);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=mt(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=J(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=J(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=J(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=mt(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=J(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=J(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=J(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=J(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=J(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!V(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var Qn={};pt(Qn,{base10:()=>ou});var ou=Gt({prefix:"9",name:"base10",alphabet:"0123456789"});var Jn={};pt(Jn,{base16:()=>su,base16upper:()=>iu});var su=j({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),iu=j({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var to={};pt(to,{base2:()=>au});var au=j({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var eo={};pt(eo,{base256emoji:()=>du});var ri=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}"),cu=ri.reduce((r,t,e)=>(r[e]=t,r),[]),uu=ri.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function lu(r){return r.reduce((t,e)=>(t+=cu[e],t),"")}function fu(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=uu[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var du=Ee({prefix:"\u{1F680}",name:"base256emoji",encode:lu,decode:fu});var ro={};pt(ro,{base64:()=>hu,base64pad:()=>pu,base64url:()=>mu,base64urlpad:()=>yu});var hu=j({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),pu=j({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),mu=j({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),yu=j({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var no={};pt(no,{base8:()=>bu});var bu=j({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var oo={};pt(oo,{identity:()=>gu});var gu=Ee({prefix:"\0",name:"identity",encode:r=>Hs(r),decode:r=>qs(r)});var Id=new TextEncoder,_d=new TextDecoder;var ao={};pt(ao,{sha256:()=>Ze,sha512:()=>Eu});function io({name:r,code:t,encode:e}){return new so(r,t,e)}var so=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?At(this.code,e):e.then(n=>At(this.code,n))}else throw Error("Unknown type, must be binary type")}};function oi(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Ze=io({name:"sha2-256",code:18,encode:oi("SHA-256")}),Eu=io({name:"sha2-512",code:19,encode:oi("SHA-512")});var Ye={...oo,...to,...no,...Qn,...Jn,...$n,...jn,...Gn,...ro,...eo},Od={...ao,...Xn};function ii(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var si=ii("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),co=ii("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=mt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),vu={utf8:si,"utf-8":si,hex:Ye.base16,latin1:co,ascii:co,binary:co,...Ye},Pr=vu;function q(r,t="utf8"){let e=Pr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function N(r,t="utf8"){let e=Pr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Su=parseInt("11111",2),uo=parseInt("10000000",2),Au=parseInt("01111111",2),ai={0:Xe,1:Xe,2:Iu,3:Lu,4:Ru,5:Bu,6:_u,16:Xe,22:Xe,48:Xe};function Ot(r,t={offset:0}){let e=r[t.offset]&Su;if(t.offset++,ai[e]!=null)return ai[e](r,t);throw new Error("No decoder for tag "+e)}function Qe(r,t){let e=0;if((r[t.offset]&uo)===uo){let n=r[t.offset]&Au,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 Xe(r,t){Qe(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Ot(r,t);if(n===null)break;e.push(n)}return e}function Iu(r,t){let e=Qe(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 _u(r,t){let e=Qe(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 Lu(r,t){let e=Qe(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 Ru(r,t){let e=Qe(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Tu(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new ct;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function lo(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Tu(r.byteLength);return new ct(Uint8Array.from([t.byteLength|uo]),t)}function yt(r){let t=new ct,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new ct(Uint8Array.from([2]),lo(t),t)}function kr(r){let t=Uint8Array.from([0]),e=new ct(t,r);return new ct(Uint8Array.from([3]),lo(e),e)}function jt(r,t=48){let e=new ct;for(let n of r)e.append(n);return new ct(Uint8Array.from([t]),lo(e),e)}async function ci(r,t,e,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,e.subarray());return n?.signal?.throwIfAborted(),s}var Pu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),ku=Uint8Array.from([6,5,43,129,4,0,34]),Cu=Uint8Array.from([6,5,43,129,4,0,35]),Ku={ext:!0,kty:"EC",crv:"P-256"},Du={ext:!0,kty:"EC",crv:"P-384"},Nu={ext:!0,kty:"EC",crv:"P-521"},fo=32,ho=48,po=66;function mo(r){let t=Ot(r);return ui(t)}function ui(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===fo*2+1)return n=N(t.subarray(e,e+fo),"base64url"),o=N(t.subarray(e+fo),"base64url"),new Ie({...Ku,key_ops:["verify"],x:n,y:o});if(t.byteLength===ho*2+1)return n=N(t.subarray(e,e+ho),"base64url"),o=N(t.subarray(e+ho),"base64url"),new Ie({...Du,key_ops:["verify"],x:n,y:o});if(t.byteLength===po*2+1)return n=N(t.subarray(e,e+po),"base64url"),o=N(t.subarray(e+po),"base64url"),new Ie({...Nu,key_ops:["verify"],x:n,y:o});throw new U(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function li(r){return jt([yt(Uint8Array.from([1])),jt([Uu(r.crv)],160),jt([kr(new ct(Uint8Array.from([4]),q(r.x??"","base64url"),q(r.y??"","base64url")))],161)]).subarray()}function Uu(r){if(r==="P-256")return Pu;if(r==="P-384")return ku;if(r==="P-521")return Cu;throw new U(`Invalid curve ${r}`)}var Ie=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=li(this.jwk)),this._raw}toMultihash(){return It.digest(Et(this))}toCID(){return Z.createV1(114,this.toMultihash())}toString(){return z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:V(this.raw,t.raw)}async verify(t,e,n){return ci(this.jwk,e,t,n)}};var ne=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Be(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Je(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function ot(r,...t){if(!Be(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error("Uint8Array expected of length "+t+", got length="+r.length)}function di(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Je(r.outputLen),Je(r.blockLen)}function Le(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 hi(r,t){ot(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}function qt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Cr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function _t(r,t){return r<<32-t|r>>>t}var pi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Ou=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Tt(r){if(ot(r),pi)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=Ou[r[e]];return t}var Mt={_0:48,_9:57,A:65,F:70,a:97,f:102};function fi(r){if(r>=Mt._0&&r<=Mt._9)return r-Mt._0;if(r>=Mt.A&&r<=Mt.F)return r-(Mt.A-10);if(r>=Mt.a&&r<=Mt.f)return r-(Mt.a-10)}function Re(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(pi)return Uint8Array.fromHex(r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=fi(r.charCodeAt(s)),a=fi(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 mi(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function tr(r){return typeof r=="string"&&(r=mi(r)),ot(r),r}function wt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];ot(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 _e=class{};function yo(r){let t=n=>r().update(tr(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function er(r=32){if(ne&&typeof ne.getRandomValues=="function")return ne.getRandomValues(new Uint8Array(r));if(ne&&typeof ne.randomBytes=="function")return Uint8Array.from(ne.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function Mu(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 yi(r,t,e){return r&t^~r&e}function bi(r,t,e){return r&t^r&e^t&e}var rr=class extends _e{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=Cr(this.buffer)}update(t){Le(this),t=tr(t),ot(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Cr(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){Le(this),hi(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,qt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)e[l]=0;Mu(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=Cr(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.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Ht=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var rt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Kr=BigInt(4294967295),gi=BigInt(32);function qu(r,t=!1){return t?{h:Number(r&Kr),l:Number(r>>gi&Kr)}:{h:Number(r>>gi&Kr)|0,l:Number(r&Kr)|0}}function wi(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:a}=qu(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var bo=(r,t,e)=>r>>>e,go=(r,t,e)=>r<<32-e|t>>>e,oe=(r,t,e)=>r>>>e|t<<32-e,se=(r,t,e)=>r<<32-e|t>>>e,nr=(r,t,e)=>r<<64-e|t>>>e-32,or=(r,t,e)=>r>>>e-32|t<<64-e;function Pt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var xi=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Ei=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,vi=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Si=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Ai=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Ii=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var zu=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Zt=new Uint32Array(64),Dr=class extends rr{constructor(t=32){super(64,t,8,!1),this.A=Ht[0]|0,this.B=Ht[1]|0,this.C=Ht[2]|0,this.D=Ht[3]|0,this.E=Ht[4]|0,this.F=Ht[5]|0,this.G=Ht[6]|0,this.H=Ht[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)Zt[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let p=Zt[l-15],d=Zt[l-2],w=_t(p,7)^_t(p,18)^p>>>3,E=_t(d,17)^_t(d,19)^d>>>10;Zt[l]=E+Zt[l-7]+w+Zt[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 p=_t(a,6)^_t(a,11)^_t(a,25),d=u+p+yi(a,c,f)+zu[l]+Zt[l]|0,E=(_t(n,2)^_t(n,13)^_t(n,22))+bi(n,o,s)|0;u=f,f=c,c=a,a=i+d|0,i=s,s=o,o=n,n=d+E|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,o,s,i,a,c,f,u)}roundClean(){qt(Zt)}destroy(){this.set(0,0,0,0,0,0,0,0),qt(this.buffer)}};var _i=wi(["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))),Fu=_i[0],Vu=_i[1],Yt=new Uint32Array(80),Xt=new Uint32Array(80),wo=class extends rr{constructor(t=64){super(128,t,16,!1),this.Ah=rt[0]|0,this.Al=rt[1]|0,this.Bh=rt[2]|0,this.Bl=rt[3]|0,this.Ch=rt[4]|0,this.Cl=rt[5]|0,this.Dh=rt[6]|0,this.Dl=rt[7]|0,this.Eh=rt[8]|0,this.El=rt[9]|0,this.Fh=rt[10]|0,this.Fl=rt[11]|0,this.Gh=rt[12]|0,this.Gl=rt[13]|0,this.Hh=rt[14]|0,this.Hl=rt[15]|0}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:f,El:u,Fh:l,Fl:p,Gh:d,Gl:w,Hh:E,Hl:m}=this;return[t,e,n,o,s,i,a,c,f,u,l,p,d,w,E,m]}set(t,e,n,o,s,i,a,c,f,u,l,p,d,w,E,m){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=p|0,this.Gh=d|0,this.Gl=w|0,this.Hh=E|0,this.Hl=m|0}process(t,e){for(let A=0;A<16;A++,e+=4)Yt[A]=t.getUint32(e),Xt[A]=t.getUint32(e+=4);for(let A=16;A<80;A++){let k=Yt[A-15]|0,b=Xt[A-15]|0,P=oe(k,b,1)^oe(k,b,8)^bo(k,b,7),T=se(k,b,1)^se(k,b,8)^go(k,b,7),_=Yt[A-2]|0,h=Xt[A-2]|0,x=oe(_,h,19)^nr(_,h,61)^bo(_,h,6),y=se(_,h,19)^or(_,h,61)^go(_,h,6),g=vi(T,y,Xt[A-7],Xt[A-16]),v=Si(g,P,x,Yt[A-7],Yt[A-16]);Yt[A]=v|0,Xt[A]=g|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:f,Dl:u,Eh:l,El:p,Fh:d,Fl:w,Gh:E,Gl:m,Hh:S,Hl:L}=this;for(let A=0;A<80;A++){let k=oe(l,p,14)^oe(l,p,18)^nr(l,p,41),b=se(l,p,14)^se(l,p,18)^or(l,p,41),P=l&d^~l&E,T=p&w^~p&m,_=Ai(L,b,T,Vu[A],Xt[A]),h=Ii(_,S,k,P,Fu[A],Yt[A]),x=_|0,y=oe(n,o,28)^nr(n,o,34)^nr(n,o,39),g=se(n,o,28)^or(n,o,34)^or(n,o,39),v=n&s^n&a^s&a,B=o&i^o&c^i&c;S=E|0,L=m|0,E=d|0,m=w|0,d=l|0,w=p|0,{h:l,l:p}=Pt(f|0,u|0,h|0,x|0),f=a|0,u=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let I=xi(x,g,B);n=Ei(I,h,y,v),o=I|0}({h:n,l:o}=Pt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Pt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Pt(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=Pt(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:p}=Pt(this.Eh|0,this.El|0,l|0,p|0),{h:d,l:w}=Pt(this.Fh|0,this.Fl|0,d|0,w|0),{h:E,l:m}=Pt(this.Gh|0,this.Gl|0,E|0,m|0),{h:S,l:L}=Pt(this.Hh|0,this.Hl|0,S|0,L|0),this.set(n,o,s,i,a,c,f,u,l,p,d,w,E,m,S,L)}roundClean(){qt(Yt,Xt)}destroy(){qt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Nr=yo(()=>new Dr);var Bi=yo(()=>new wo);var vo=BigInt(0),Eo=BigInt(1);function zt(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function sr(r){let t=r.toString(16);return t.length&1?"0"+t:t}function Li(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?vo:BigInt("0x"+r)}function Te(r){return Li(Tt(r))}function ie(r){return ot(r),Li(Tt(Uint8Array.from(r).reverse()))}function Ur(r,t){return Re(r.toString(16).padStart(t*2,"0"))}function Pe(r,t){return Ur(r,t).reverse()}function W(r,t,e){let n;if(typeof t=="string")try{n=Re(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(Be(t))n=Uint8Array.from(t);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof e=="number"&&o!==e)throw new Error(r+" of length "+e+" expected, got "+o);return n}var xo=r=>typeof r=="bigint"&&vo<=r;function Ri(r,t,e){return xo(r)&&xo(t)&&xo(e)&&t<=r&&r<e}function Qt(r,t,e,n){if(!Ri(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Ti(r){let t;for(t=0;r>vo;r>>=Eo,t+=1);return t}var ae=r=>(Eo<<BigInt(r))-Eo;function Pi(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=d=>new Uint8Array(d),o=d=>Uint8Array.of(d),s=n(r),i=n(r),a=0,c=()=>{s.fill(1),i.fill(0),a=0},f=(...d)=>e(i,s,...d),u=(d=n(0))=>{i=f(o(0),d),s=f(),d.length!==0&&(i=f(o(1),d),s=f())},l=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let d=0,w=[];for(;d<t;){s=f();let E=s.slice();w.push(E),d+=s.length}return wt(...w)};return(d,w)=>{c(),u(d);let E;for(;!(E=w(l()));)u();return c(),E}}function Jt(r,t,e={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(o,s,i){let a=r[o];if(i&&a===void 0)return;let c=typeof a;if(c!==s||a===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${c}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(e).forEach(([o,s])=>n(o,s,!0))}function ke(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var ut=BigInt(0),et=BigInt(1),ce=BigInt(2),Wu=BigInt(3),Ki=BigInt(4),Di=BigInt(5),Ni=BigInt(8);function $(r,t){let e=r%t;return e>=ut?e:t+e}function G(r,t,e){let n=r;for(;t-- >ut;)n*=n,n%=e;return n}function ki(r,t){if(r===ut)throw new Error("invert: expected non-zero number");if(t<=ut)throw new Error("invert: expected positive modulus, got "+t);let e=$(r,t),n=t,o=ut,s=et,i=et,a=ut;for(;e!==ut;){let f=n/e,u=n%e,l=o-i*f,p=s-a*f;n=e,e=u,o=i,s=a,i=l,a=p}if(n!==et)throw new Error("invert: does not exist");return $(o,t)}function Ui(r,t){let e=(r.ORDER+et)/Ki,n=r.pow(t,e);if(!r.eql(r.sqr(n),t))throw new Error("Cannot find square root");return n}function Gu(r,t){let e=(r.ORDER-Di)/Ni,n=r.mul(t,ce),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,ce),o),a=r.mul(s,r.sub(i,r.ONE));if(!r.eql(r.sqr(a),t))throw new Error("Cannot find square root");return a}function $u(r){if(r<BigInt(3))throw new Error("sqrt is not defined for small field");let t=r-et,e=0;for(;t%ce===ut;)t/=ce,e++;let n=ce,o=Bt(r);for(;Ci(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return Ui;let s=o.pow(n,t),i=(t+et)/ce;return function(c,f){if(c.is0(f))return f;if(Ci(c,f)!==1)throw new Error("Cannot find square root");let u=e,l=c.mul(c.ONE,s),p=c.pow(f,t),d=c.pow(f,i);for(;!c.eql(p,c.ONE);){if(c.is0(p))return c.ZERO;let w=1,E=c.sqr(p);for(;!c.eql(E,c.ONE);)if(w++,E=c.sqr(E),w===u)throw new Error("Cannot find square root");let m=et<<BigInt(u-w-1),S=c.pow(l,m);u=w,l=c.sqr(S),p=c.mul(p,l),d=c.mul(d,S)}return d}}function ju(r){return r%Ki===Wu?Ui:r%Ni===Di?Gu:$u(r)}var Oi=(r,t)=>($(r,t)&et)===et,Zu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function So(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},e=Zu.reduce((n,o)=>(n[o]="function",n),t);return Jt(r,e),r}function Yu(r,t,e){if(e<ut)throw new Error("invalid exponent, negatives unsupported");if(e===ut)return r.ONE;if(e===et)return t;let n=r.ONE,o=t;for(;e>ut;)e&et&&(n=r.mul(n,o)),o=r.sqr(o),e>>=et;return n}function ir(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,a,c)=>r.is0(a)?i:(n[c]=i,r.mul(i,a)),r.ONE),s=r.inv(o);return t.reduceRight((i,a,c)=>r.is0(a)?i:(n[c]=r.mul(i,n[c]),r.mul(i,a)),s),n}function Ci(r,t){let e=(r.ORDER-et)/ce,n=r.pow(t,e),o=r.eql(n,r.ONE),s=r.eql(n,r.ZERO),i=r.eql(n,r.neg(r.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Mi(r,t){t!==void 0&&Je(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Bt(r,t,e=!1,n={}){if(r<=ut)throw new Error("invalid field: expected ORDER > 0, got "+r);let o,s;if(typeof t=="object"&&t!=null){if(n.sqrt||e)throw new Error("cannot specify opts in two arguments");let u=t;u.BITS&&(o=u.BITS),u.sqrt&&(s=u.sqrt),typeof u.isLE=="boolean"&&(e=u.isLE)}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:i,nByteLength:a}=Mi(r,o);if(a>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let c,f=Object.freeze({ORDER:r,isLE:e,BITS:i,BYTES:a,MASK:ae(i),ZERO:ut,ONE:et,create:u=>$(u,r),isValid:u=>{if(typeof u!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof u);return ut<=u&&u<r},is0:u=>u===ut,isValidNot0:u=>!f.is0(u)&&f.isValid(u),isOdd:u=>(u&et)===et,neg:u=>$(-u,r),eql:(u,l)=>u===l,sqr:u=>$(u*u,r),add:(u,l)=>$(u+l,r),sub:(u,l)=>$(u-l,r),mul:(u,l)=>$(u*l,r),pow:(u,l)=>Yu(f,u,l),div:(u,l)=>$(u*ki(l,r),r),sqrN:u=>u*u,addN:(u,l)=>u+l,subN:(u,l)=>u-l,mulN:(u,l)=>u*l,inv:u=>ki(u,r),sqrt:s||(u=>(c||(c=ju(r)),c(f,u))),toBytes:u=>e?Pe(u,a):Ur(u,a),fromBytes:u=>{if(u.length!==a)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+u.length);return e?ie(u):Te(u)},invertBatch:u=>ir(f,u),cmov:(u,l,p)=>p?l:u});return Object.freeze(f)}function qi(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 Ao(r){let t=qi(r);return t+Math.ceil(t/2)}function Hi(r,t,e=!1){let n=r.length,o=qi(t),s=Ao(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?ie(r):Te(r),a=$(i,t-et)+et;return e?Pe(a,o):Ur(a,o)}var Ke=BigInt(0),ue=BigInt(1);function Ce(r,t){let e=t.negate();return r?e:t}function Or(r,t,e){let n=t==="pz"?i=>i.pz:i=>i.ez,o=ir(r.Fp,e.map(n));return e.map((i,a)=>i.toAffine(o[a])).map(r.fromAffine)}function Wi(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function Io(r,t){Wi(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=ae(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function zi(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),c=r>>i;a>n&&(a-=s,c+=ue);let f=t*n,u=f+Math.abs(a)-1,l=a===0,p=a<0,d=t%2!==0;return{nextN:c,offset:u,isZero:l,isNeg:p,isNegF:d,offsetF:f}}function Xu(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 Qu(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 _o=new WeakMap,Gi=new WeakMap;function Bo(r){return Gi.get(r)||1}function Fi(r){if(r!==Ke)throw new Error("invalid wNAF")}function Mr(r,t){return{constTimeNegate:Ce,hasPrecomputes(e){return Bo(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>Ke;)n&ue&&(o=o.add(s)),s=s.double(),n>>=ue;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=Io(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 s=r.ZERO,i=r.BASE,a=Io(e,t);for(let c=0;c<a.windows;c++){let{nextN:f,offset:u,isZero:l,isNeg:p,isNegF:d,offsetF:w}=zi(o,c,a);o=f,l?i=i.add(Ce(d,n[w])):s=s.add(Ce(p,n[u]))}return Fi(o),{p:s,f:i}},wNAFUnsafe(e,n,o,s=r.ZERO){let i=Io(e,t);for(let a=0;a<i.windows&&o!==Ke;a++){let{nextN:c,offset:f,isZero:u,isNeg:l}=zi(o,a,i);if(o=c,!u){let p=n[f];s=s.add(l?p.negate():p)}}return Fi(o),s},getPrecomputes(e,n,o){let s=_o.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&(typeof o=="function"&&(s=o(s)),_o.set(n,s))),s},wNAFCached(e,n,o){let s=Bo(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=Bo(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){Wi(n,t),Gi.set(e,n),_o.delete(e)}}}function $i(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>Ke||n>Ke;)e&ue&&(s=s.add(o)),n&ue&&(i=i.add(o)),o=o.double(),e>>=ue,n>>=ue;return{p1:s,p2:i}}function qr(r,t,e,n){Xu(e,r),Qu(n,t);let o=e.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=r.ZERO,a=Ti(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let f=ae(c),u=new Array(Number(f)+1).fill(i),l=Math.floor((t.BITS-1)/c)*c,p=i;for(let d=l;d>=0;d-=c){u.fill(i);for(let E=0;E<s;E++){let m=n[E],S=Number(m>>BigInt(d)&f);u[S]=u[S].add(e[E])}let w=i;for(let E=u.length-1,m=i;E>0;E--)m=m.add(u[E]),w=w.add(m);if(p=p.add(w),d!==0)for(let E=0;E<c;E++)p=p.double()}return p}function Vi(r,t){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return So(t),t}else return Bt(r)}function Hr(r,t,e={}){if(!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let a of["p","n","h"]){let c=t[a];if(!(typeof c=="bigint"&&c>Ke))throw new Error(`CURVE.${a} must be positive bigint`)}let n=Vi(t.p,e.Fp),o=Vi(t.n,e.Fn),i=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let a of i)if(!n.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return{Fp:n,Fn:o}}var kt=BigInt(0),lt=BigInt(1),Lo=BigInt(2),Ju=BigInt(8),tl={zip215:!0};function el(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),a=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,a)}function rl(r,t={}){let{Fp:e,Fn:n}=Hr("edwards",r,t),{h:o,n:s}=r;Jt(t,{},{uvRatio:"function"});let i=Lo<<BigInt(n.BYTES*8)-lt,a=E=>e.create(E),c=t.uvRatio||((E,m)=>{try{return{isValid:!0,value:e.sqrt(e.div(E,m))}}catch{return{isValid:!1,value:kt}}});if(!el(e,r,r.Gx,r.Gy))throw new Error("bad curve params: generator point");function f(E,m,S=!1){let L=S?lt:kt;return Qt("coordinate "+E,m,L,i),m}function u(E){if(!(E instanceof d))throw new Error("ExtendedPoint expected")}let l=ke((E,m)=>{let{ex:S,ey:L,ez:A}=E,k=E.is0();m==null&&(m=k?Ju:e.inv(A));let b=a(S*m),P=a(L*m),T=a(A*m);if(k)return{x:kt,y:lt};if(T!==lt)throw new Error("invZ was invalid");return{x:b,y:P}}),p=ke(E=>{let{a:m,d:S}=r;if(E.is0())throw new Error("bad point: ZERO");let{ex:L,ey:A,ez:k,et:b}=E,P=a(L*L),T=a(A*A),_=a(k*k),h=a(_*_),x=a(P*m),y=a(_*a(x+T)),g=a(h+a(S*a(P*T)));if(y!==g)throw new Error("bad point: equation left != right (1)");let v=a(L*A),B=a(k*b);if(v!==B)throw new Error("bad point: equation left != right (2)");return!0});class d{constructor(m,S,L,A){this.ex=f("x",m),this.ey=f("y",S),this.ez=f("z",L,!0),this.et=f("t",A),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(m){if(m instanceof d)throw new Error("extended point not allowed");let{x:S,y:L}=m||{};return f("x",S),f("y",L),new d(S,L,lt,a(S*L))}static normalizeZ(m){return Or(d,"ez",m)}static msm(m,S){return qr(d,n,m,S)}_setWindowSize(m){this.precompute(m)}precompute(m=8,S=!0){return w.setWindowSize(this,m),S||this.multiply(Lo),this}assertValidity(){p(this)}equals(m){u(m);let{ex:S,ey:L,ez:A}=this,{ex:k,ey:b,ez:P}=m,T=a(S*P),_=a(k*A),h=a(L*P),x=a(b*A);return T===_&&h===x}is0(){return this.equals(d.ZERO)}negate(){return new d(a(-this.ex),this.ey,this.ez,a(-this.et))}double(){let{a:m}=r,{ex:S,ey:L,ez:A}=this,k=a(S*S),b=a(L*L),P=a(Lo*a(A*A)),T=a(m*k),_=S+L,h=a(a(_*_)-k-b),x=T+b,y=x-P,g=T-b,v=a(h*y),B=a(x*g),I=a(h*g),R=a(y*x);return new d(v,B,R,I)}add(m){u(m);let{a:S,d:L}=r,{ex:A,ey:k,ez:b,et:P}=this,{ex:T,ey:_,ez:h,et:x}=m,y=a(A*T),g=a(k*_),v=a(P*L*x),B=a(b*h),I=a((A+k)*(T+_)-y-g),R=B-v,K=B+v,C=a(g-S*y),Y=a(I*R),M=a(K*C),D=a(I*C),Q=a(R*K);return new d(Y,M,Q,D)}subtract(m){return this.add(m.negate())}multiply(m){let S=m;Qt("scalar",S,lt,s);let{p:L,f:A}=w.wNAFCached(this,S,d.normalizeZ);return d.normalizeZ([L,A])[0]}multiplyUnsafe(m,S=d.ZERO){let L=m;return Qt("scalar",L,kt,s),L===kt?d.ZERO:this.is0()||L===lt?this:w.wNAFCachedUnsafe(this,L,d.normalizeZ,S)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return w.wNAFCachedUnsafe(this,s).is0()}toAffine(m){return l(this,m)}clearCofactor(){return o===lt?this:this.multiplyUnsafe(o)}static fromBytes(m,S=!1){return ot(m),this.fromHex(m,S)}static fromHex(m,S=!1){let{d:L,a:A}=r,k=e.BYTES;m=W("pointHex",m,k),zt("zip215",S);let b=m.slice(),P=m[k-1];b[k-1]=P&-129;let T=ie(b),_=S?i:e.ORDER;Qt("pointHex.y",T,kt,_);let h=a(T*T),x=a(h-lt),y=a(L*h-A),{isValid:g,value:v}=c(x,y);if(!g)throw new Error("Point.fromHex: invalid y coordinate");let B=(v&lt)===lt,I=(P&128)!==0;if(!S&&v===kt&&I)throw new Error("Point.fromHex: x=0 and x_0=1");return I!==B&&(v=a(-v)),d.fromAffine({x:v,y:T})}static fromPrivateScalar(m){return d.BASE.multiply(m)}toBytes(){let{x:m,y:S}=this.toAffine(),L=Pe(S,e.BYTES);return L[L.length-1]|=m&lt?128:0,L}toRawBytes(){return this.toBytes()}toHex(){return Tt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}d.BASE=new d(r.Gx,r.Gy,lt,a(r.Gx*r.Gy)),d.ZERO=new d(kt,lt,lt,kt),d.Fp=e,d.Fn=n;let w=Mr(d,n.BYTES*8);return d}function nl(r,t){Jt(t,{hash:"function"},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:e,hash:n}=t,{BASE:o,Fp:s,Fn:i}=r,a=i.ORDER,c=t.randomBytes||er,f=t.adjustScalarBytes||(b=>b),u=t.domain||((b,P,T)=>{if(zt("phflag",T),P.length||T)throw new Error("Contexts/pre-hash are not supported");return b});function l(b){return i.create(b)}function p(b){return l(ie(b))}function d(b){let P=s.BYTES;b=W("private key",b,P);let T=W("hashed private key",n(b),2*P),_=f(T.slice(0,P)),h=T.slice(P,2*P),x=p(_);return{head:_,prefix:h,scalar:x}}function w(b){let{head:P,prefix:T,scalar:_}=d(b),h=o.multiply(_),x=h.toBytes();return{head:P,prefix:T,scalar:_,point:h,pointBytes:x}}function E(b){return w(b).pointBytes}function m(b=Uint8Array.of(),...P){let T=wt(...P);return p(n(u(T,W("context",b),!!e)))}function S(b,P,T={}){b=W("message",b),e&&(b=e(b));let{prefix:_,scalar:h,pointBytes:x}=w(P),y=m(T.context,_,b),g=o.multiply(y).toBytes(),v=m(T.context,g,x,b),B=l(y+v*h);Qt("signature.s",B,kt,a);let I=s.BYTES,R=wt(g,Pe(B,I));return W("result",R,I*2)}let L=tl;function A(b,P,T,_=L){let{context:h,zip215:x}=_,y=s.BYTES;b=W("signature",b,2*y),P=W("message",P),T=W("publicKey",T,y),x!==void 0&&zt("zip215",x),e&&(P=e(P));let g=ie(b.slice(y,2*y)),v,B,I;try{v=r.fromHex(T,x),B=r.fromHex(b.slice(0,y),x),I=o.multiplyUnsafe(g)}catch{return!1}if(!x&&v.isSmallOrder())return!1;let R=m(h,B.toBytes(),v.toBytes(),P);return B.add(v.multiplyUnsafe(R)).subtract(I).clearCofactor().is0()}return o.precompute(8),{getPublicKey:E,sign:S,verify:A,utils:{getExtendedPublicKey:w,randomPrivateKey:()=>c(s.BYTES),precompute(b=8,P=r.BASE){return P.precompute(b,!1)}},Point:r}}function ol(r){let t={a:r.a,d:r.d,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},e=r.Fp,n=Bt(t.n,r.nBitLength,!0),o={Fp:e,Fn:n,uvRatio:r.uvRatio},s={hash:r.hash,randomBytes:r.randomBytes,adjustScalarBytes:r.adjustScalarBytes,domain:r.domain,prehash:r.prehash,mapToCurve:r.mapToCurve};return{CURVE:t,curveOpts:o,eddsaOpts:s}}function sl(r,t){return Object.assign({},t,{ExtendedPoint:t.Point,CURVE:r})}function ji(r){let{CURVE:t,curveOpts:e,eddsaOpts:n}=ol(r),o=rl(t,e),s=nl(o,n);return sl(r,s)}var Fh=BigInt(0),il=BigInt(1),Zi=BigInt(2),Vh=BigInt(3),al=BigInt(5),cl=BigInt(8),zr={p:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:cl,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function ul(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=zr.p,a=r*r%s*r%s,c=G(a,Zi,s)*a%s,f=G(c,il,s)*r%s,u=G(f,al,s)*f%s,l=G(u,t,s)*u%s,p=G(l,e,s)*l%s,d=G(p,n,s)*p%s,w=G(d,o,s)*d%s,E=G(w,o,s)*d%s,m=G(E,t,s)*u%s;return{pow_p_5_8:G(m,Zi,s)*r%s,b2:a}}function ll(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var Yi=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function fl(r,t){let e=zr.p,n=$(t*t*t,e),o=$(n*n*t,e),s=ul(r*o).pow_p_5_8,i=$(r*n*s,e),a=$(t*i*i,e),c=i,f=$(i*Yi,e),u=a===r,l=a===$(-r,e),p=a===$(-r*Yi,e);return u&&(i=c),(l||p)&&(i=f),Oi(i,e)&&(i=$(-i,e)),{isValid:u||l,value:i}}var dl=Bt(zr.p,void 0,!0),hl={...zr,Fp:dl,hash:Bi,adjustScalarBytes:ll,uvRatio:fl},Xi=ji(hl);var ar=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Fr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Qi={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Fr("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var vt=Qi;var Vr=32;var Ro,pl=(async()=>{try{return await vt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function ml(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await vt.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await vt.get().subtle.verify({name:"Ed25519"},n,t,e instanceof Uint8Array?e:e.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function yl(r,t,e){return Xi.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function Ji(r,t,e){return Ro==null&&(Ro=await pl),Ro?ml(r,t,e):yl(r,t,e)}function Wr(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Gr=class{type="Ed25519";raw;constructor(t){this.raw=To(t,Vr)}toMultihash(){return It.digest(Et(this))}toCID(){return Z.createV1(114,this.toMultihash())}toString(){return z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:V(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=Ji(this.raw,e,t);return Wr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Po(r){return r=To(r,Vr),new Gr(r)}function To(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new U(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var gl=Math.pow(2,7),wl=Math.pow(2,14),xl=Math.pow(2,21),ko=Math.pow(2,28),Co=Math.pow(2,35),Ko=Math.pow(2,42),Do=Math.pow(2,49),O=128,st=127;function bt(r){if(r<gl)return 1;if(r<wl)return 2;if(r<xl)return 3;if(r<ko)return 4;if(r<Co)return 5;if(r<Ko)return 6;if(r<Do)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function No(r,t,e=0){switch(bt(r)){case 8:t[e++]=r&255|O,r/=128;case 7:t[e++]=r&255|O,r/=128;case 6:t[e++]=r&255|O,r/=128;case 5:t[e++]=r&255|O,r/=128;case 4:t[e++]=r&255|O,r>>>=7;case 3:t[e++]=r&255|O,r>>>=7;case 2:t[e++]=r&255|O,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function El(r,t,e=0){switch(bt(r)){case 8:t.set(e++,r&255|O),r/=128;case 7:t.set(e++,r&255|O),r/=128;case 6:t.set(e++,r&255|O),r/=128;case 5:t.set(e++,r&255|O),r/=128;case 4:t.set(e++,r&255|O),r>>>=7;case 3:t.set(e++,r&255|O),r>>>=7;case 2:t.set(e++,r&255|O),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Uo(r,t){let e=r[t],n=0;if(n+=e&st,e<O||(e=r[t+1],n+=(e&st)<<7,e<O)||(e=r[t+2],n+=(e&st)<<14,e<O)||(e=r[t+3],n+=(e&st)<<21,e<O)||(e=r[t+4],n+=(e&st)*ko,e<O)||(e=r[t+5],n+=(e&st)*Co,e<O)||(e=r[t+6],n+=(e&st)*Ko,e<O)||(e=r[t+7],n+=(e&st)*Do,e<O))return n;throw new RangeError("Could not decode varint")}function vl(r,t){let e=r.get(t),n=0;if(n+=e&st,e<O||(e=r.get(t+1),n+=(e&st)<<7,e<O)||(e=r.get(t+2),n+=(e&st)<<14,e<O)||(e=r.get(t+3),n+=(e&st)<<21,e<O)||(e=r.get(t+4),n+=(e&st)*ko,e<O)||(e=r.get(t+5),n+=(e&st)*Co,e<O)||(e=r.get(t+6),n+=(e&st)*Ko,e<O)||(e=r.get(t+7),n+=(e&st)*Do,e<O))return n;throw new RangeError("Could not decode varint")}function Ct(r,t,e=0){return t==null&&(t=mt(bt(r))),t instanceof Uint8Array?No(r,t,e):El(r,t,e)}function le(r,t=0){return r instanceof Uint8Array?Uo(r,t):vl(r,t)}var Mo=new Float32Array([-0]),te=new Uint8Array(Mo.buffer);function ea(r,t,e){Mo[0]=r,t[e]=te[0],t[e+1]=te[1],t[e+2]=te[2],t[e+3]=te[3]}function ra(r,t){return te[0]=r[t],te[1]=r[t+1],te[2]=r[t+2],te[3]=r[t+3],Mo[0]}var qo=new Float64Array([-0]),it=new Uint8Array(qo.buffer);function na(r,t,e){qo[0]=r,t[e]=it[0],t[e+1]=it[1],t[e+2]=it[2],t[e+3]=it[3],t[e+4]=it[4],t[e+5]=it[5],t[e+6]=it[6],t[e+7]=it[7]}function oa(r,t){return it[0]=r[t],it[1]=r[t+1],it[2]=r[t+2],it[3]=r[t+3],it[4]=r[t+4],it[5]=r[t+5],it[6]=r[t+6],it[7]=r[t+7],qo[0]}var Sl=BigInt(Number.MAX_SAFE_INTEGER),Al=BigInt(Number.MIN_SAFE_INTEGER),xt=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return fe;if(t<Sl&&t>Al)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>sa&&(o=0n,++n>sa&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return fe;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):fe}},fe=new xt(0,0);fe.toBigInt=function(){return 0n};fe.zzEncode=fe.zzDecode=function(){return this};fe.length=function(){return 1};var sa=4294967296n;function ia(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 aa(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 Ho(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 Lt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function $r(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var zo=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,Lt(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 Lt(this,4);return $r(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Lt(this,4);return $r(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Lt(this,4);let t=ra(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Lt(this,4);let t=oa(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 Lt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return aa(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Lt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Lt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new xt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw Lt(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 Lt(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 Lt(this,8);let t=$r(this.buf,this.pos+=4),e=$r(this.buf,this.pos+=4);return new xt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Uo(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 Fo(r){return new zo(r instanceof Uint8Array?r:r.subarray())}function ft(r,t,e){let n=Fo(r);return t.decode(n,void 0,e)}function Vo(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return mt(i);o+i>t&&(n=mt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var de=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Wo(){}var $o=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Il=Vo();function _l(r){return globalThis.Buffer!=null?mt(r):Il(r)}var ur=class{len;head;tail;states;constructor(){this.len=0,this.head=new de(Wo,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new de(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new jo((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(jr,10,xt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=xt.fromBigInt(t);return this._push(jr,e.length(),e)}uint64Number(t){return this._push(No,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=xt.fromBigInt(t).zzEncode();return this._push(jr,e.length(),e)}sint64Number(t){let e=xt.fromNumber(t).zzEncode();return this._push(jr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Go,1,t?1:0)}fixed32(t){return this._push(cr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=xt.fromBigInt(t);return this._push(cr,4,e.lo)._push(cr,4,e.hi)}fixed64Number(t){let e=xt.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(ea,4,t)}double(t){return this._push(na,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Go,1,0):this.uint32(e)._push(Ll,e,t)}string(t){let e=ia(t);return e!==0?this.uint32(e)._push(Ho,e,t):this._push(Go,1,0)}fork(){return this.states=new $o(this),this.head=this.tail=new de(Wo,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new de(Wo,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=_l(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Go(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 jo=class extends de{next;constructor(t,e){super(Bl,t,e),this.next=void 0}};function jr(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 Ll(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(Rl,t,r),this},ur.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Tl,t,r),this});function Rl(r,t,e){t.set(r,e)}function Tl(r,t,e){r.length<40?Ho(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(q(r),e)}function Zo(){return new ur}function dt(r,t){let e=Zo();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var De;(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"})(De||(De={}));function Zr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Yo(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 Zr("enum",De.VARINT,e,n)}function ht(r,t){return Zr("message",De.LENGTH_DELIMITED,r,t)}var he=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"},lr=class extends Error{code="ERR_MAX_SIZE";name="MaxSizeError"};var X;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(X||(X={}));var Xo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Xo||(Xo={}));(function(r){r.codec=()=>Yo(Xo)})(X||(X={}));var Kt;(function(r){let t;r.codec=()=>(t==null&&(t=ht((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),X.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=X.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>dt(e,r.codec()),r.decode=(e,n)=>ft(e,r.codec(),n)})(Kt||(Kt={}));var Qo;(function(r){let t;r.codec=()=>(t==null&&(t=ht((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),X.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=X.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>dt(e,r.codec()),r.decode=(e,n)=>ft(e,r.codec(),n)})(Qo||(Qo={}));var dr={};pt(dr,{MAX_RSA_KEY_SIZE:()=>Jo,generateRSAKeyPair:()=>ha,jwkToJWKKeyPair:()=>pa,jwkToPkcs1:()=>Kl,jwkToPkix:()=>ns,jwkToRSAPrivateKey:()=>as,pkcs1MessageToJwk:()=>es,pkcs1MessageToRSAPrivateKey:()=>os,pkcs1ToJwk:()=>Cl,pkcs1ToRSAPrivateKey:()=>da,pkixMessageToJwk:()=>rs,pkixMessageToRSAPublicKey:()=>is,pkixToJwk:()=>Dl,pkixToRSAPublicKey:()=>ss});var Yr=Nr;var Ne=class{type="RSA";jwk;_raw;_multihash;constructor(t,e){this.jwk=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=dr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return Z.createV1(114,this._multihash)}toString(){return z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:V(this.raw,t.raw)}verify(t,e,n){return fa(this.jwk,e,t,n)}},fr=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=dr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:V(this.raw,t.raw)}sign(t,e){return la(this.jwk,t,e)}};var Jo=8192,ts=18,Pl=1062,kl=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Cl(r){let t=Ot(r);return es(t)}function es(r){return{n:N(r[1],"base64url"),e:N(r[2],"base64url"),d:N(r[3],"base64url"),p:N(r[4],"base64url"),q:N(r[5],"base64url"),dp:N(r[6],"base64url"),dq:N(r[7],"base64url"),qi:N(r[8],"base64url"),kty:"RSA"}}function Kl(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 U("JWK was missing components");return jt([yt(Uint8Array.from([0])),yt(q(r.n,"base64url")),yt(q(r.e,"base64url")),yt(q(r.d,"base64url")),yt(q(r.p,"base64url")),yt(q(r.q,"base64url")),yt(q(r.dp,"base64url")),yt(q(r.dq,"base64url")),yt(q(r.qi,"base64url"))]).subarray()}function Dl(r){let t=Ot(r,{offset:0});return rs(t)}function rs(r){let t=Ot(r[1],{offset:0});return{kty:"RSA",n:N(t[0],"base64url"),e:N(t[1],"base64url")}}function ns(r){if(r.n==null||r.e==null)throw new U("JWK was missing components");return jt([kl,kr(jt([yt(q(r.n,"base64url")),yt(q(r.e,"base64url"))]))]).subarray()}function da(r){let t=Ot(r);return os(t)}function os(r){let t=es(r);return as(t)}function ss(r,t){if(r.byteLength>=Pl)throw new we("Key size is too large");let e=Ot(r,{offset:0});return is(e,r,t)}function is(r,t,e){let n=rs(r);if(e==null){let o=Yr(Kt.encode({Type:X.RSA,Data:t}));e=At(ts,o)}return new Ne(n,e)}function as(r){if(ya(r)>Jo)throw new U("Key size is too large");let t=pa(r),e=Yr(Kt.encode({Type:X.RSA,Data:ns(t.publicKey)})),n=At(ts,e);return new fr(t.privateKey,new Ne(t.publicKey,n))}async function ha(r){if(r>Jo)throw new U("Key size is too large");let t=await ma(r),e=Yr(Kt.encode({Type:X.RSA,Data:ns(t.publicKey)})),n=At(ts,e);return new fr(t.privateKey,new Ne(t.publicKey,n))}function pa(r){if(r==null)throw new U("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function ma(r,t){let e=await vt.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await Nl(e,t);return{privateKey:n[0],publicKey:n[1]}}async function la(r,t,e){let n=await vt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);e?.signal?.throwIfAborted();let o=await vt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return e?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function fa(r,t,e,n){let o=await vt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await vt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,e instanceof Uint8Array?e:e.subarray());return n?.signal?.throwIfAborted(),s}async function Nl(r,t){if(r.privateKey==null||r.publicKey==null)throw new U("Private and public key are required");let e=await Promise.all([vt.get().subtle.exportKey("jwk",r.privateKey),vt.get().subtle.exportKey("jwk",r.publicKey)]);return t?.signal?.throwIfAborted(),e}function ya(r){if(r.kty!=="RSA")throw new U("invalid key type");if(r.n==null)throw new U("invalid key modulus");return q(r.n,"base64url").length*8}var Xr=class extends _e{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,di(t);let n=tr(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),qt(s)}update(t){return Le(this),this.iHash.update(t),this}digestInto(t){Le(this),ot(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},cs=(r,t,e)=>new Xr(r,t).update(e).digest();cs.create=(r,t)=>new Xr(r,t);function ba(r){r.lowS!==void 0&&zt("lowS",r.lowS),r.prehash!==void 0&&zt("prehash",r.prehash)}var us=class extends Error{constructor(t=""){super(t)}},Ft={Err:us,_tlv:{encode:(r,t)=>{let{Err:e}=Ft;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=sr(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?sr(o.length/2|128):"";return sr(r)+s+o+t},decode(r,t){let{Err:e}=Ft,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}=Ft;if(r<hr)throw new t("integer: negative integers are not allowed");let e=sr(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}=Ft;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 Te(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Ft,o=W("signature",r),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v: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}=Ft,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},hr=BigInt(0),pr=BigInt(1),Ul=BigInt(2),Qr=BigInt(3),Ol=BigInt(4);function Ml(r,t,e){function n(o){let s=r.sqr(o),i=r.mul(s,o);return r.add(r.add(i,r.mul(o,t)),e)}return n}function ga(r,t,e){let{BYTES:n}=r;function o(s){let i;if(typeof s=="bigint")i=s;else{let a=W("private key",s);if(t){if(!t.includes(a.length*2))throw new Error("invalid private key");let c=new Uint8Array(n);c.set(a,c.length-a.length),a=c}try{i=r.fromBytes(a)}catch{throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof s}`)}}if(e&&(i=r.create(i)),!r.isValidNot0(i))throw new Error("invalid private key: out of range [1..N-1]");return i}return o}function ql(r,t={}){let{Fp:e,Fn:n}=Hr("weierstrass",r,t),{h:o,n:s}=r;Jt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:i}=t;if(i&&(!e.is0(r.a)||typeof i.beta!="bigint"||typeof i.splitScalar!="function"))throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');function a(){if(!e.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function c(_,h,x){let{x:y,y:g}=h.toAffine(),v=e.toBytes(y);if(zt("isCompressed",x),x){a();let B=!e.isOdd(g);return wt(wa(B),v)}else return wt(Uint8Array.of(4),v,e.toBytes(g))}function f(_){ot(_);let h=e.BYTES,x=h+1,y=2*h+1,g=_.length,v=_[0],B=_.subarray(1);if(g===x&&(v===2||v===3)){let I=e.fromBytes(B);if(!e.isValid(I))throw new Error("bad point: is not on curve, wrong x");let R=p(I),K;try{K=e.sqrt(R)}catch(M){let D=M instanceof Error?": "+M.message:"";throw new Error("bad point: is not on curve, sqrt error"+D)}a();let C=e.isOdd(K);return(v&1)===1!==C&&(K=e.neg(K)),{x:I,y:K}}else if(g===y&&v===4){let I=e.fromBytes(B.subarray(h*0,h*1)),R=e.fromBytes(B.subarray(h*1,h*2));if(!d(I,R))throw new Error("bad point: is not on curve");return{x:I,y:R}}else throw new Error(`bad point: got length ${g}, expected compressed=${x} or uncompressed=${y}`)}let u=t.toBytes||c,l=t.fromBytes||f,p=Ml(e,r.a,r.b);function d(_,h){let x=e.sqr(h),y=p(_);return e.eql(x,y)}if(!d(r.Gx,r.Gy))throw new Error("bad curve params: generator point");let w=e.mul(e.pow(r.a,Qr),Ol),E=e.mul(e.sqr(r.b),BigInt(27));if(e.is0(e.add(w,E)))throw new Error("bad curve params: a or b");function m(_,h,x=!1){if(!e.isValid(h)||x&&e.is0(h))throw new Error(`bad point coordinate ${_}`);return h}function S(_){if(!(_ instanceof b))throw new Error("ProjectivePoint expected")}let L=ke((_,h)=>{let{px:x,py:y,pz:g}=_;if(e.eql(g,e.ONE))return{x,y};let v=_.is0();h==null&&(h=v?e.ONE:e.inv(g));let B=e.mul(x,h),I=e.mul(y,h),R=e.mul(g,h);if(v)return{x:e.ZERO,y:e.ZERO};if(!e.eql(R,e.ONE))throw new Error("invZ was invalid");return{x:B,y:I}}),A=ke(_=>{if(_.is0()){if(t.allowInfinityPoint&&!e.is0(_.py))return;throw new Error("bad point: ZERO")}let{x:h,y:x}=_.toAffine();if(!e.isValid(h)||!e.isValid(x))throw new Error("bad point: x or y not field elements");if(!d(h,x))throw new Error("bad point: equation left != right");if(!_.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function k(_,h,x,y,g){return x=new b(e.mul(x.px,_),x.py,x.pz),h=Ce(y,h),x=Ce(g,x),h.add(x)}class b{constructor(h,x,y){this.px=m("x",h),this.py=m("y",x,!0),this.pz=m("z",y),Object.freeze(this)}static fromAffine(h){let{x,y}=h||{};if(!h||!e.isValid(x)||!e.isValid(y))throw new Error("invalid affine point");if(h instanceof b)throw new Error("projective point not allowed");return e.is0(x)&&e.is0(y)?b.ZERO:new b(x,y,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){return Or(b,"pz",h)}static fromBytes(h){return ot(h),b.fromHex(h)}static fromHex(h){let x=b.fromAffine(l(W("pointHex",h)));return x.assertValidity(),x}static fromPrivateKey(h){let x=ga(n,t.allowedPrivateKeyLengths,t.wrapPrivateKey);return b.BASE.multiply(x(h))}static msm(h,x){return qr(b,n,h,x)}precompute(h=8,x=!0){return T.setWindowSize(this,h),x||this.multiply(Qr),this}_setWindowSize(h){this.precompute(h)}assertValidity(){A(this)}hasEvenY(){let{y:h}=this.toAffine();if(!e.isOdd)throw new Error("Field doesn't support isOdd");return!e.isOdd(h)}equals(h){S(h);let{px:x,py:y,pz:g}=this,{px:v,py:B,pz:I}=h,R=e.eql(e.mul(x,I),e.mul(v,g)),K=e.eql(e.mul(y,I),e.mul(B,g));return R&&K}negate(){return new b(this.px,e.neg(this.py),this.pz)}double(){let{a:h,b:x}=r,y=e.mul(x,Qr),{px:g,py:v,pz:B}=this,I=e.ZERO,R=e.ZERO,K=e.ZERO,C=e.mul(g,g),Y=e.mul(v,v),M=e.mul(B,B),D=e.mul(g,v);return D=e.add(D,D),K=e.mul(g,B),K=e.add(K,K),I=e.mul(h,K),R=e.mul(y,M),R=e.add(I,R),I=e.sub(Y,R),R=e.add(Y,R),R=e.mul(I,R),I=e.mul(D,I),K=e.mul(y,K),M=e.mul(h,M),D=e.sub(C,M),D=e.mul(h,D),D=e.add(D,K),K=e.add(C,C),C=e.add(K,C),C=e.add(C,M),C=e.mul(C,D),R=e.add(R,C),M=e.mul(v,B),M=e.add(M,M),C=e.mul(M,D),I=e.sub(I,C),K=e.mul(M,Y),K=e.add(K,K),K=e.add(K,K),new b(I,R,K)}add(h){S(h);let{px:x,py:y,pz:g}=this,{px:v,py:B,pz:I}=h,R=e.ZERO,K=e.ZERO,C=e.ZERO,Y=r.a,M=e.mul(r.b,Qr),D=e.mul(x,v),Q=e.mul(y,B),tt=e.mul(g,I),nt=e.add(x,y),F=e.add(v,B);nt=e.mul(nt,F),F=e.add(D,Q),nt=e.sub(nt,F),F=e.add(x,g);let at=e.add(v,I);return F=e.mul(F,at),at=e.add(D,tt),F=e.sub(F,at),at=e.add(y,g),R=e.add(B,I),at=e.mul(at,R),R=e.add(Q,tt),at=e.sub(at,R),C=e.mul(Y,F),R=e.mul(M,tt),C=e.add(R,C),R=e.sub(Q,C),C=e.add(Q,C),K=e.mul(R,C),Q=e.add(D,D),Q=e.add(Q,D),tt=e.mul(Y,tt),F=e.mul(M,F),Q=e.add(Q,tt),tt=e.sub(D,tt),tt=e.mul(Y,tt),F=e.add(F,tt),D=e.mul(Q,F),K=e.add(K,D),D=e.mul(at,F),R=e.mul(nt,R),R=e.sub(R,D),D=e.mul(nt,Q),C=e.mul(at,C),C=e.add(C,D),new b(R,K,C)}subtract(h){return this.add(h.negate())}is0(){return this.equals(b.ZERO)}multiply(h){let{endo:x}=t;if(!n.isValidNot0(h))throw new Error("invalid scalar: out of range");let y,g,v=B=>T.wNAFCached(this,B,b.normalizeZ);if(x){let{k1neg:B,k1:I,k2neg:R,k2:K}=x.splitScalar(h),{p:C,f:Y}=v(I),{p:M,f:D}=v(K);g=Y.add(D),y=k(x.beta,C,M,B,R)}else{let{p:B,f:I}=v(h);y=B,g=I}return b.normalizeZ([y,g])[0]}multiplyUnsafe(h){let{endo:x}=t,y=this;if(!n.isValid(h))throw new Error("invalid scalar: out of range");if(h===hr||y.is0())return b.ZERO;if(h===pr)return y;if(T.hasPrecomputes(this))return this.multiply(h);if(x){let{k1neg:g,k1:v,k2neg:B,k2:I}=x.splitScalar(h),{p1:R,p2:K}=$i(b,y,v,I);return k(x.beta,R,K,g,B)}else return T.wNAFCachedUnsafe(y,h)}multiplyAndAddUnsafe(h,x,y){let g=this.multiplyUnsafe(x).add(h.multiplyUnsafe(y));return g.is0()?void 0:g}toAffine(h){return L(this,h)}isTorsionFree(){let{isTorsionFree:h}=t;return o===pr?!0:h?h(b,this):T.wNAFCachedUnsafe(this,s).is0()}clearCofactor(){let{clearCofactor:h}=t;return o===pr?this:h?h(b,this):this.multiplyUnsafe(o)}toBytes(h=!0){return zt("isCompressed",h),this.assertValidity(),u(b,this,h)}toRawBytes(h=!0){return this.toBytes(h)}toHex(h=!0){return Tt(this.toBytes(h))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}b.BASE=new b(r.Gx,r.Gy,e.ONE),b.ZERO=new b(e.ZERO,e.ONE,e.ZERO),b.Fp=e,b.Fn=n;let P=n.BITS,T=Mr(b,t.endo?Math.ceil(P/2):P);return b}function wa(r){return Uint8Array.of(r?2:3)}function Hl(r,t,e={}){Jt(t,{hash:"function"},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=t.randomBytes||er,o=t.hmac||((y,...g)=>cs(t.hash,y,wt(...g))),{Fp:s,Fn:i}=r,{ORDER:a,BITS:c}=i;function f(y){let g=a>>pr;return y>g}function u(y){return f(y)?i.neg(y):y}function l(y,g){if(!i.isValidNot0(g))throw new Error(`invalid signature ${y}: out of range 1..CURVE.n`)}class p{constructor(g,v,B){l("r",g),l("s",v),this.r=g,this.s=v,B!=null&&(this.recovery=B),Object.freeze(this)}static fromCompact(g){let v=i.BYTES,B=W("compactSignature",g,v*2);return new p(i.fromBytes(B.subarray(0,v)),i.fromBytes(B.subarray(v,v*2)))}static fromDER(g){let{r:v,s:B}=Ft.toSig(W("DER",g));return new p(v,B)}assertValidity(){}addRecoveryBit(g){return new p(this.r,this.s,g)}recoverPublicKey(g){let v=s.ORDER,{r:B,s:I,recovery:R}=this;if(R==null||![0,1,2,3].includes(R))throw new Error("recovery id invalid");if(a*Ul<v&&R>1)throw new Error("recovery id is ambiguous for h>1 curve");let C=R===2||R===3?B+a:B;if(!s.isValid(C))throw new Error("recovery id 2 or 3 invalid");let Y=s.toBytes(C),M=r.fromHex(wt(wa((R&1)===0),Y)),D=i.inv(C),Q=A(W("msgHash",g)),tt=i.create(-Q*D),nt=i.create(I*D),F=r.BASE.multiplyUnsafe(tt).add(M.multiplyUnsafe(nt));if(F.is0())throw new Error("point at infinify");return F.assertValidity(),F}hasHighS(){return f(this.s)}normalizeS(){return this.hasHighS()?new p(this.r,i.neg(this.s),this.recovery):this}toBytes(g){if(g==="compact")return wt(i.toBytes(this.r),i.toBytes(this.s));if(g==="der")return Re(Ft.hexFromSig(this));throw new Error("invalid format")}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Tt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Tt(this.toBytes("compact"))}}let d=ga(i,e.allowedPrivateKeyLengths,e.wrapPrivateKey),w={isValidPrivateKey(y){try{return d(y),!0}catch{return!1}},normPrivateKeyToScalar:d,randomPrivateKey:()=>{let y=a;return Hi(n(Ao(y)),y)},precompute(y=8,g=r.BASE){return g.precompute(y,!1)}};function E(y,g=!0){return r.fromPrivateKey(y).toBytes(g)}function m(y){if(typeof y=="bigint")return!1;if(y instanceof r)return!0;let v=W("key",y).length,B=s.BYTES,I=B+1,R=2*B+1;if(!(e.allowedPrivateKeyLengths||i.BYTES===I))return v===I||v===R}function S(y,g,v=!0){if(m(y)===!0)throw new Error("first arg must be private key");if(m(g)===!1)throw new Error("second arg must be public key");return r.fromHex(g).multiply(d(y)).toBytes(v)}let L=t.bits2int||function(y){if(y.length>8192)throw new Error("input is too large");let g=Te(y),v=y.length*8-c;return v>0?g>>BigInt(v):g},A=t.bits2int_modN||function(y){return i.create(L(y))},k=ae(c);function b(y){return Qt("num < 2^"+c,y,hr,k),i.toBytes(y)}function P(y,g,v=T){if(["recovered","canonical"].some(nt=>nt in v))throw new Error("sign() legacy options not supported");let{hash:B}=t,{lowS:I,prehash:R,extraEntropy:K}=v;I==null&&(I=!0),y=W("msgHash",y),ba(v),R&&(y=W("prehashed msgHash",B(y)));let C=A(y),Y=d(g),M=[b(Y),b(C)];if(K!=null&&K!==!1){let nt=K===!0?n(s.BYTES):K;M.push(W("extraEntropy",nt))}let D=wt(...M),Q=C;function tt(nt){let F=L(nt);if(!i.isValidNot0(F))return;let at=i.inv(F),Fe=r.BASE.multiply(F).toAffine(),ye=i.create(Fe.x);if(ye===hr)return;let ee=i.create(at*i.create(Q+ye*Y));if(ee===hr)return;let qn=(Fe.x===ye?0:2)|Number(Fe.y&pr),be=ee;return I&&f(ee)&&(be=u(ee),qn^=1),new p(ye,be,qn)}return{seed:D,k2sig:tt}}let T={lowS:t.lowS,prehash:!1},_={lowS:t.lowS,prehash:!1};function h(y,g,v=T){let{seed:B,k2sig:I}=P(y,g,v);return Pi(t.hash.outputLen,i.BYTES,o)(B,I)}r.BASE.precompute(8);function x(y,g,v,B=_){let I=y;g=W("msgHash",g),v=W("publicKey",v),ba(B);let{lowS:R,prehash:K,format:C}=B;if("strict"in B)throw new Error("options.strict was renamed to lowS");if(C!==void 0&&!["compact","der","js"].includes(C))throw new Error('format must be "compact", "der" or "js"');let Y=typeof I=="string"||Be(I),M=!Y&&!C&&typeof I=="object"&&I!==null&&typeof I.r=="bigint"&&typeof I.s=="bigint";if(!Y&&!M)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let D,Q;try{if(M)if(C===void 0||C==="js")D=new p(I.r,I.s);else throw new Error("invalid format");if(Y){try{C!=="compact"&&(D=p.fromDER(I))}catch(be){if(!(be instanceof Ft.Err))throw be}!D&&C!=="der"&&(D=p.fromCompact(I))}Q=r.fromHex(v)}catch{return!1}if(!D||R&&D.hasHighS())return!1;K&&(g=t.hash(g));let{r:tt,s:nt}=D,F=A(g),at=i.inv(nt),Fe=i.create(F*at),ye=i.create(tt*at),ee=r.BASE.multiplyUnsafe(Fe).add(Q.multiplyUnsafe(ye));return ee.is0()?!1:i.create(ee.x)===tt}return Object.freeze({getPublicKey:E,getSharedSecret:S,sign:h,verify:x,utils:w,Point:r,Signature:p})}function zl(r){let t={a:r.a,b:r.b,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},e=r.Fp,n=Bt(t.n,r.nBitLength),o={Fp:e,Fn:n,allowedPrivateKeyLengths:r.allowedPrivateKeyLengths,allowInfinityPoint:r.allowInfinityPoint,endo:r.endo,wrapPrivateKey:r.wrapPrivateKey,isTorsionFree:r.isTorsionFree,clearCofactor:r.clearCofactor,fromBytes:r.fromBytes,toBytes:r.toBytes};return{CURVE:t,curveOpts:o}}function Fl(r){let{CURVE:t,curveOpts:e}=zl(r),n={hash:r.hash,hmac:r.hmac,randomBytes:r.randomBytes,lowS:r.lowS,bits2int:r.bits2int,bits2int_modN:r.bits2int_modN};return{CURVE:t,curveOpts:e,ecdsaOpts:n}}function Vl(r,t){return Object.assign({},t,{ProjectivePoint:t.Point,CURVE:r})}function xa(r){let{CURVE:t,curveOpts:e,ecdsaOpts:n}=Fl(r),o=ql(t,e),s=Hl(o,n,e);return Vl(r,s)}function Ea(r,t){let e=n=>xa({...r,hash:n});return{...e(t),create:e}}var Jr={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Tm=BigInt(0),Wl=BigInt(1),ls=BigInt(2),va=(r,t)=>(r+t/ls)/t;function Gl(r){let t=Jr.p,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=G(u,e,t)*u%t,p=G(l,e,t)*u%t,d=G(p,ls,t)*f%t,w=G(d,o,t)*d%t,E=G(w,s,t)*w%t,m=G(E,a,t)*E%t,S=G(m,c,t)*m%t,L=G(S,a,t)*E%t,A=G(L,e,t)*u%t,k=G(A,i,t)*w%t,b=G(k,n,t)*f%t,P=G(b,ls,t);if(!fs.eql(fs.sqr(P),r))throw new Error("Cannot find square root");return P}var fs=Bt(Jr.p,void 0,void 0,{sqrt:Gl}),Ue=Ea({...Jr,Fp:fs,lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Jr.n,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Wl*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),a=va(s*r,t),c=va(-n*r,t),f=$(r-a*e-c*o,t),u=$(-a*n-c*s,t),l=f>i,p=u>i;if(l&&(f=t-f),p&&(u=t-u),f>i||u>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:l,k1:f,k2neg:p,k2:u}}}},Nr);function Sa(r,t,e,n){let o=Ze.digest(e instanceof Uint8Array?e:e.subarray());if(Wr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ue.verify(t,s,r))).catch(s=>{throw s.name==="AbortError"?s:new ar(String(s))});try{return n?.signal?.throwIfAborted(),Ue.verify(t,o.digest,r)}catch(s){throw new ar(String(s))}}var tn=class{type="secp256k1";raw;_key;constructor(t){this._key=Ia(t),this.raw=Aa(this._key)}toMultihash(){return It.digest(Et(this))}toCID(){return Z.createV1(114,this.toMultihash())}toString(){return z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:V(this.raw,t.raw)}verify(t,e,n){return Sa(this._key,e,t,n)}};function ds(r){return new tn(r)}function Aa(r){return Ue.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Ia(r){try{return Ue.ProjectivePoint.fromHex(r),r}catch(t){throw new we(String(t))}}function en(r,t){let{Type:e,Data:n}=Kt.decode(r),o=n??new Uint8Array;switch(e){case X.RSA:return ss(o,t);case X.Ed25519:return Po(o);case X.secp256k1:return ds(o);case X.ECDSA:return mo(o);default:throw new re}}function _a(r){let{Type:t,Data:e}=Kt.decode(r.digest),n=e??new Uint8Array;switch(t){case X.Ed25519:return Po(n);case X.secp256k1:return ds(n);case X.ECDSA:return mo(n);default:throw new re}}function Et(r){return Kt.encode({Type:X[r.type],Data:r.raw})}var Ba=Symbol.for("nodejs.util.inspect.custom"),$l=114,mr=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()})`}[_r]=!0;toString(){return this.string==null&&(this.string=z.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return Z.createV1($l,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return V(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return V(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Ba](){return`PeerId(${this.toString()})`}},yr=class extends mr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},br=class extends mr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},gr=class extends mr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},jl=2336,wr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=It.digest(q(this.url))}[Ba](){return`PeerId(${this.url})`}[_r]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return Z.createV1(jl,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=N(t)),t.toString()===this.toString())}};var Zl=114,La=2336;function Ra(r){if(r.type==="Ed25519")return new br({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 yr({multihash:r.toCID().multihash,publicKey:r});throw new re}function hs(r){if(Xl(r))return new yr({multihash:r});if(Yl(r))try{let t=_a(r);if(t.type==="Ed25519")return new br({multihash:r,publicKey:t});if(t.type==="secp256k1")return new gr({multihash:r,publicKey:t})}catch{let e=N(r.digest);return new wr(new URL(e))}throw new Lr("Supplied PeerID Multihash is invalid")}function rn(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==Zl&&r.code!==La)throw new Br("Supplied PeerID CID is invalid");if(r.code===La){let t=N(r.multihash.digest);return new wr(new URL(t))}return hs(r.multihash)}function Yl(r){return r.code===It.code}function Xl(r){return r.code===Ze.code}var xr;(function(r){let t;r.codec=()=>(t==null&&(t=ht((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:J(0),payloadType:J(0),payload:J(0),signature:J(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=>dt(e,r.codec()),r.decode=(e,n)=>ft(e,r.codec(),n)})(xr||(xr={}));var nn=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var Oe=class r{static createFromProtobuf=t=>{let e=xr.decode(t),n=en(e.publicKey);return new r({publicKey:n,payloadType:e.payloadType,payload:e.payload,signature:e.signature})};static seal=async(t,e,n)=>{if(e==null)throw new Error("Missing private key");let o=t.domain,s=t.codec,i=t.marshal(),a=Ta(o,s,i),c=await e.sign(a.subarray(),n);return new r({publicKey:e.publicKey,payloadType:s,payload:i,signature:c})};static openAndCertify=async(t,e,n)=>{let o=r.createFromProtobuf(t);if(!await o.validate(e,n))throw new nn("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(t){let{publicKey:e,payloadType:n,payload:o,signature:s}=t;this.publicKey=e,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=xr.encode({publicKey:Et(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return t==null?!1:V(this.marshal(),t.marshal())}async validate(t,e){let n=Ta(t,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,e)}},Ta=(r,t,e)=>{let n=q(r),o=Ct(n.byteLength),s=Ct(t.length),i=Ct(e.length);return new ct(o,n,s,t,i,e)};function Pa(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 on=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 p=Number.parseInt(l,t);if(!Number.isNaN(p))return p});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 ka=45,Ql=15,Me=new on;function ps(r){if(!(r.length>Ql))return Me.new(r).parseWith(()=>Me.readIPv4Addr())}function ms(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>ka))return Me.new(r).parseWith(()=>Me.readIPv6Addr())}function sn(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>ka)return;let e=Me.new(r).parseWith(()=>Me.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 J0=parseInt("0xFFFF",16),ty=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Da(r){return!!ps(r)}function Na(r){return!!ms(r)}function an(r){return!!sn(r)}var Ua=Da,nf=Na,ys=function(r){let t=0;if(r=r.toString().trim(),Ua(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(nf(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=Ua(e[n]),i;s&&(i=ys(e[n]),e[n]=N(i.slice(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,N(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")},Oa=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 qe={},bs={},sf=[[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"]];sf.forEach(r=>{let t=af(...r);bs[t.code]=t,qe[t.name]=t});function af(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function H(r){if(typeof r=="number"){if(bs[r]!=null)return bs[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(qe[r]!=null)return qe[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Uy=H("ip4"),Oy=H("ip6"),My=H("ipcidr");function Es(r,t){switch(H(r).code){case 4:case 41:return uf(t);case 42:return xs(t);case 43:return N(t,"base10");case 6:case 273:case 33:case 132:return Ha(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return xs(t);case 421:return hf(t);case 444:return qa(t);case 445:return qa(t);case 466:return df(t);case 481:return globalThis.encodeURIComponent(xs(t));default:return N(t,"base16")}}function vs(r,t){switch(H(r).code){case 4:return Ma(t);case 41:return Ma(t);case 42:return ws(t);case 43:return q(t,"base10");case 6:case 273:case 33:case 132:return Ss(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return ws(t);case 421:return lf(t);case 444:return pf(t);case 445:return mf(t);case 466:return ff(t);case 481:return ws(globalThis.decodeURIComponent(t));default:return q(t,"base16")}}var gs=Object.values(Ye).map(r=>r.decoder),cf=function(){let r=gs[0].or(gs[1]);return gs.slice(2).forEach(t=>r=r.or(t)),r}();function Ma(r){if(!an(r))throw new Error("invalid ip address");return ys(r)}function uf(r){let t=Oa(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!an(t))throw new Error("invalid ip address");return t}function Ss(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Ha(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function ws(r){let t=q(r),e=Uint8Array.from(Ct(t.length));return gt([e,t],e.length+t.length)}function xs(r){let t=le(r);if(r=r.slice(bt(t)),r.length!==t)throw new Error("inconsistent lengths");return N(r)}function lf(r){let t;r[0]==="Q"||r[0]==="1"?t=$t(z.decode(`z${r}`)).bytes:t=Z.parse(r).multihash.bytes;let e=Uint8Array.from(Ct(t.length));return gt([e,t],e.length+t.length)}function ff(r){let t=cf.decode(r),e=Uint8Array.from(Ct(t.length));return gt([e,t],e.length+t.length)}function df(r){let t=le(r),e=r.slice(bt(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+N(e,"base64url")}function hf(r){let t=le(r),e=r.slice(bt(t));if(e.length!==t)throw new Error("inconsistent lengths");return N(e,"base58btc")}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!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=St.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=Ss(n);return gt([e,o],e.length+o.length)}function mf(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=St.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=Ss(n);return gt([e,o],e.length+o.length)}function qa(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=N(t,"base32"),o=Ha(e);return`${n}:${o}`}function za(r){r=As(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=H(i);if(a.size===0){t.push([a.code]),e.push([a.code]);continue}if(s++,s>=o.length)throw new cn("invalid address: "+r);if(a.path===!0){n=As(o.slice(s).join("/")),t.push([a.code,vs(a.code,n)]),e.push([a.code,n]);break}let c=vs(a.code,o[s]);t.push([a.code,c]),e.push([a.code,Es(a.code,c)])}return{string:Fa(e),bytes:un(t),tuples:t,stringTuples:e,path:n}}function Is(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let s=le(r,o),i=bt(s),a=H(s),c=yf(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 cn("Invalid address Uint8Array: "+N(r,"base16"));t.push([s,f]);let u=Es(s,f);if(e.push([s,u]),a.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:Fa(e),tuples:t,stringTuples:e,path:n}}function Fa(r){let t=[];return r.map(e=>{let n=H(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),As(t.join("/"))}function un(r){return gt(r.map(t=>{let e=H(t[0]),n=Uint8Array.from(Ct(e.code));return t.length>1&&t[1]!=null&&(n=gt([n,t[1]])),n}))}function yf(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=le(t instanceof Uint8Array?t:Uint8Array.from(t));return e+bt(e)}}function As(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}var cn=class extends Error{static name="ParseError";name="ParseError";constructor(t){super(`Error parsing address: ${t}`)}};var bf=Symbol.for("nodejs.util.inspect.custom"),Bs=Symbol.for("@multiformats/js-multiaddr/multiaddr"),gf=[H("dns").code,H("dns4").code,H("dns6").code,H("dnsaddr").code],_s=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},ln=class r{bytes;#t;#e;#r;#n;[Bs]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=Is(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=za(t)}else if(fn(t))e=Is(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.#n=e.path}toString(){return this.#t}toJSON(){return this.toString()}toOptions(){let t,e,n,o,s="",i=H("tcp"),a=H("udp"),c=H("ip4"),f=H("ip6"),u=H("dns6"),l=H("ip6zone");for(let[d,w]of this.stringTuples())d===l.code&&(s=`%${w??""}`),gf.includes(d)&&(e=i.name==="tcp"?"tcp":"udp",o=443,n=`${w??""}${s}`,t=d===u.code?6:4),(d===i.code||d===a.code)&&(e=H(d).name==="tcp"?"tcp":"udp",o=parseInt(w??"")),(d===c.code||d===f.code)&&(e=H(d).name==="tcp"?"tcp":"udp",n=`${w??""}${s}`,t=d===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({},H(t)))}protoCodes(){return this.#e.map(([t])=>t)}protoNames(){return this.#e.map(([t])=>H(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(un(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===qe.p2p.code&&t.push([n,o]),n===qe["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?N(z.decode(`z${n}`),"base58btc"):N(Z.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return V(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(s=>s.resolvable);if(e==null)return[this];let n=Va.get(e.name);if(n==null)throw new _s(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>Dt(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)}[bf](){return`Multiaddr(${this.#t})`}};var Va=new Map;function fn(r){return!!r?.[Bs]}function Dt(r){return new ln(r)}var Wa="libp2p-peer-record",Ga=Uint8Array.from([3,1]);var Er;(function(r){let t;(function(n){let o;n.codec=()=>(o==null&&(o=ht((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:J(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=>dt(s,n.codec()),n.decode=(s,i)=>ft(s,n.codec(),i)})(t=r.AddressInfo||(r.AddressInfo={}));let e;r.codec=()=>(e==null&&(e=ht((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:J(0),seq:0n,addresses:[]},a=o==null?n.len:n.pos+o;for(;n.pos<a;){let c=n.uint32();switch(c>>>3){case 1:{i.peerId=n.bytes();break}case 2:{i.seq=n.uint64();break}case 3:{if(s.limits?.addresses!=null&&i.addresses.length===s.limits.addresses)throw new he('Decode error - map field "addresses" had too many elements');i.addresses.push(r.AddressInfo.codec().decode(n,n.uint32(),{limits:s.limits?.addresses$}));break}default:{n.skipType(c&7);break}}}return i})),e),r.encode=n=>dt(n,r.codec()),r.decode=(n,o)=>ft(n,r.codec(),o)})(Er||(Er={}));var pe=class r{static createFromProtobuf=t=>{let e=Er.decode(t),n=hs($t(e.peerId)),o=(e.addresses??[]).map(i=>Dt(i.multiaddr)),s=e.seq;return new r({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Wa;static CODEC=Ga;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=Er.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||!Pa(this.multiaddrs,t.multiaddrs))}};function wf(r){return r[Symbol.asyncIterator]!=null}function xf(r){if(wf(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 $a=xf;function dn(r,t){let e={[Symbol.iterator]:()=>e,next:()=>{let n=r.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return e}var vr=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[e,n]of t.entries())this.map.set(e.toString(),{key:e,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return dn(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((e,n)=>{t(e.value,e.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,e){this.map.set(t.toString(),{key:t,value:e})}keys(){return dn(this.map.values(),t=>t.key)}values(){return dn(this.map.values(),t=>t.value)}get size(){return this.map.size}};var Ls=class extends vr{metric;constructor(t){super();let{name:e,metrics:n}=t;this.metric=n.registerMetric(e),this.updateComponentMetric()}set(t,e){return super.set(t,e),this.updateComponentMetric(),this}delete(t){let e=super.delete(t);return this.updateComponentMetric(),e}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function Rs(r){let{name:t,metrics:e}=r,n;return e!=null?n=new Ls({name:t,metrics:e}):n=new vr,n}var Rt=class extends Error{static name="AbortError";name="AbortError";constructor(t="The operation was aborted",...e){super(t,...e)}};function hn(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var pn=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},He=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new pn(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new pn(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var Ts=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function ja(r={}){return Ef(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function Ef(r,t){t=t??{};let e=t.onEnd,n=new He,o,s,i,a=hn(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((m,S)=>{s=L=>{s=null,n.push(L);try{m(r(n))}catch(A){S(A)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=hn()})}},f=m=>s!=null?s(m):(n.push(m),o),u=m=>(n=new He,s!=null?s({error:m}):(n.push({error:m}),o)),l=m=>{if(i)return o;if(t?.objectMode!==!0&&m?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:m})},p=m=>i?o:(i=!0,m!=null?u(m):f({done:!0})),d=()=>(n=new He,p(),{done:!0}),w=m=>(p(m),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:d,throw:w,push:l,end:p,get readableLength(){return n.size},onEmpty:async m=>{let S=m?.signal;if(S?.throwIfAborted(),n.isEmpty())return;let L,A;S!=null&&(L=new Promise((k,b)=>{A=()=>{b(new Ts)},S.addEventListener("abort",A)}));try{await Promise.race([a.promise,L])}finally{A!=null&&S!=null&&S?.removeEventListener("abort",A)}}},e==null)return o;let E=o;return o={[Symbol.asyncIterator](){return this},next(){return E.next()},throw(m){return E.throw(m),e!=null&&(e(m),e=void 0),{done:!0}},return(){return E.return(),e!=null&&(e(),e=void 0),{done:!0}},push:l,end(m){return E.end(m),e!=null&&(e(m),e=void 0),o},get readableLength(){return E.readableLength},onEmpty:m=>E.onEmpty(m)},o}var Ps=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=e??"ABORT_ERR"}};async function mn(r,t,e,n){let o=new Ps(n?.errorMessage,n?.errorCode);return e?.aborted===!0?Promise.reject(o):new Promise((s,i)=>{function a(){e?.removeEventListener("abort",u),r.removeEventListener(t,c),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,f)}let c=l=>{try{if(n?.filter?.(l)===!1)return}catch(p){a(),i(p);return}a(),s(l)},f=l=>{a(),i(l.detail)},u=()=>{a(),i(o)};e?.addEventListener("abort",u),r.addEventListener(t,c),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,f)})}var yn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};var bn=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function Za(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new bn(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new bn(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((s,i)=>{n=()=>{i(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var gn=class{deferred;signal;constructor(t){this.signal=t,this.deferred=Promise.withResolvers(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Rt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function vf(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var wn=class{id;fn;options;recipients;status;timeline;controller;constructor(t,e){this.id=vf(),this.status="queued",this.fn=t,this.options=e,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(t){this.controller.abort(t)}onAbort(){this.recipients.reduce((e,n)=>e&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new Rt),this.cleanup())}async join(t={}){let e=new gn(t.signal);return this.recipients.push(e),t.signal?.addEventListener("abort",this.onAbort),e.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let t=await Za(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(e=>{e.deferred.resolve(t)}),this.status="complete"}catch(t){this.recipients.forEach(e=>{e.deferred.reject(t)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(t=>{t.cleanup(),t.signal?.removeEventListener("abort",this.onAbort)})}};function ks(r,t){let e,n=function(){let o=function(){e=void 0,r()};clearTimeout(e),e=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(e)},n}var Sr=class extends xe{concurrency;maxSize;queue;pending;sort;autoStart;constructor(t={}){super(),this.concurrency=t.concurrency??Number.POSITIVE_INFINITY,this.maxSize=t.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.autoStart=t.autoStart??!0,this.sort=t.sort,this.queue=[],this.emitEmpty=ks(this.emitEmpty.bind(this),1),this.emitIdle=ks(this.emitIdle.bind(this),1)}[Symbol.asyncIterator](){return this.toGenerator()}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}tryToStartAnother(){if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let t;for(let e of this.queue)if(e.status==="queued"){t=e;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let e=0;e<this.queue.length;e++)if(this.queue[e]===t){this.queue.splice(e,1);break}this.pending--,this.safeDispatchEvent("next"),this.autoStart&&this.tryToStartAnother()}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}start(){this.autoStart===!1&&(this.autoStart=!0,this.tryToStartAnother())}pause(){this.autoStart=!1}async add(t,e){if(e?.signal?.throwIfAborted(),this.size===this.maxSize)throw new yn;let n=new wn(t,e);return this.enqueue(n),this.safeDispatchEvent("add"),this.autoStart&&this.tryToStartAnother(),n.join(e).then(o=>(this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(t=>{t.abort(new Rt)}),this.clear()}async onEmpty(t){this.size!==0&&await mn(this,"empty",t?.signal)}async onSizeLessThan(t,e){this.size<t||await mn(this,"next",e?.signal,{filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await mn(this,"idle",t?.signal)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(t){t?.signal?.throwIfAborted();let e=ja({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),e.end(c)},o=c=>{c.detail!=null&&e.push(c.detail.result)},s=c=>{n(c.detail.error)},i=()=>{n()},a=()=>{n(new Rt("Queue aborted"))};this.addEventListener("success",o),this.addEventListener("failure",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*e}finally{this.removeEventListener("success",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};var xn="lock:worker:request-read",En="lock:worker:abort-read-request",vn="lock:worker:release-read",Sn="lock:master:grant-read",An="lock:master:error-read",In="lock:worker:request-write",_n="lock:worker:abort-write-request",Bn="lock:worker:release-write",Ln="lock:master:grant-write",Rn="lock:master:error-write",Tn="lock:worker:finalize",Pn="mortice",Ya={singleProcess:!1};var Cs=(r,t,e,n,o,s,i,a,c)=>f=>{if(f.data==null)return;let u={type:f.data.type,name:f.data.name,identifier:f.data.identifier};u.type===o&&r.safeDispatchEvent(e,{detail:{name:u.name,identifier:u.identifier,handler:async()=>{t.postMessage({type:c,name:u.name,identifier:u.identifier}),await new Promise(l=>{let p=d=>{if(d?.data==null)return;let w={type:d.data.type,name:d.data.name,identifier:d.data.identifier};w.type===a&&w.identifier===u.identifier&&(t.removeEventListener("message",p),l())};t.addEventListener("message",p)})},onError:l=>{t.postMessage({type:i,name:u.name,identifier:u.identifier,error:{message:l.message,name:l.name,stack:l.stack}})}}}),u.type===s&&r.safeDispatchEvent(n,{detail:{name:u.name,identifier:u.identifier}}),u.type===Tn&&r.safeDispatchEvent("finalizeRequest",{detail:{name:u.name}})};var Xa=(r=10)=>Math.random().toString().substring(2,r+2);var kn=class{name;channel;constructor(t){this.name=t,this.channel=new BroadcastChannel(Pn)}readLock(t){return this.sendRequest(xn,En,Sn,An,vn,t)}writeLock(t){return this.sendRequest(In,_n,Ln,Rn,Bn,t)}finalize(){this.channel.postMessage({type:Tn,name:this.name}),this.channel.close()}async sendRequest(t,e,n,o,s,i){i?.signal?.throwIfAborted();let a=Xa();return this.channel.postMessage({type:t,identifier:a,name:this.name}),new Promise((c,f)=>{let u=()=>{this.channel.postMessage({type:e,identifier:a,name:this.name})};i?.signal?.addEventListener("abort",u,{once:!0});let l=p=>{if(p.data?.identifier===a&&(p.data?.type===n&&(this.channel.removeEventListener("message",l),i?.signal?.removeEventListener("abort",u),c(()=>{this.channel.postMessage({type:s,identifier:a,name:this.name})})),p.data.type===o)){this.channel.removeEventListener("message",l),i?.signal?.removeEventListener("abort",u);let d=new Error;p.data.error!=null&&(d.message=p.data.error.message,d.name=p.data.error.name,d.stack=p.data.error.stack),f(d)}};this.channel.addEventListener("message",l)})}};var Qa=r=>{if(r=Object.assign({},Ya,r),!!globalThis.document||r.singleProcess){let e=new BroadcastChannel(Pn),n=new xe;return e.addEventListener("message",Cs(n,e,"requestReadLock","abortReadLockRequest",xn,En,An,vn,Sn)),e.addEventListener("message",Cs(n,e,"requestWriteLock","abortWriteLockRequest",In,_n,Rn,Bn,Ln)),n}return new kn(r.name)};var me=new Map,Ar;function Ja(r){return typeof r?.readLock=="function"&&typeof r?.writeLock=="function"}function Sf(r){if(Ar==null&&(Ar=Qa(r),!Ja(Ar))){let t=Ar;t.addEventListener("requestReadLock",e=>{let n=e.detail.name,o=e.detail.identifier,s=me.get(n);if(s==null)return;let i=new AbortController,a=c=>{c.detail.name!==n||c.detail.identifier!==o||i.abort()};t.addEventListener("abortReadLockRequest",a),s.readLock({signal:i.signal}).then(async c=>{await e.detail.handler().finally(()=>{c()})}).catch(c=>{e.detail.onError(c)}).finally(()=>{t.removeEventListener("abortReadLockRequest",a)})}),t.addEventListener("requestWriteLock",e=>{let n=e.detail.name,o=e.detail.identifier,s=me.get(n);if(s==null)return;let i=new AbortController,a=c=>{c.detail.name!==n||c.detail.identifier!==o||i.abort()};t.addEventListener("abortWriteLockRequest",a),s.writeLock({signal:i.signal}).then(async c=>{await e.detail.handler().finally(()=>{c()})}).catch(c=>{e.detail.onError(c)}).finally(()=>{t.removeEventListener("abortWriteLockRequest",a)})}),t.addEventListener("finalizeRequest",e=>{let n=e.detail.name,o=me.get(n);o?.finalize()})}return Ar}async function Ks(r,t){let e,n,o=new Promise((i,a)=>{e=i,n=a}),s=()=>{n(new Rt)};return t?.signal?.addEventListener("abort",s,{once:!0}),r.add(async()=>{await new Promise(i=>{e(()=>{t?.signal?.removeEventListener("abort",s),i()})})},{signal:t?.signal}).catch(i=>{n(i)}),o}var tc=(r,t)=>{let e=me.get(r);if(e!=null)return e;let n=Sf(t);if(Ja(n))return e=n,me.set(r,e),e;let o=new Sr({concurrency:1}),s;return e={async readLock(i){if(s!=null)return Ks(s,i);s=new Sr({concurrency:t.concurrency,autoStart:!1});let a=s,c=Ks(s,i);return o.add(async()=>{a.start(),await a.onIdle().then(()=>{s===a&&(s=null)})}),c},async writeLock(i){return s=null,Ks(o,i)},finalize:()=>{me.delete(r)},queue:o},me.set(r,e),t.autoFinalize===!0&&o.addEventListener("idle",()=>{e.finalize()},{once:!0}),e};var Af={name:"lock",concurrency:1/0,singleProcess:!1,autoFinalize:!1};function Ds(r){let t=Object.assign({},Af,r);return tc(t.name,t)}var Vt;(function(r){let t;(function(o){let s;o.codec=()=>(s==null&&(s=ht((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:J(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=>dt(i,o.codec()),o.decode=(i,a)=>ft(i,o.codec(),a)})(t=r.Peer$metadataEntry||(r.Peer$metadataEntry={}));let e;(function(o){let s;o.codec=()=>(s==null&&(s=ht((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),Kn.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=Kn.codec().decode(i,i.uint32(),{limits:c.limits?.value});break}default:{i.skipType(l&7);break}}}return f})),s),o.encode=i=>dt(i,o.codec()),o.decode=(i,a)=>ft(i,o.codec(),a)})(e=r.Peer$tagsEntry||(r.Peer$tagsEntry={}));let n;r.codec=()=>(n==null&&(n=ht((o,s,i={})=>{if(i.lengthDelimited!==!1&&s.fork(),o.addresses!=null)for(let a of o.addresses)s.uint32(10),Cn.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 he('Decode error - map field "addresses" had too many elements');a.addresses.push(Cn.codec().decode(o,o.uint32(),{limits:i.limits?.addresses$}));break}case 2:{if(i.limits?.protocols!=null&&a.protocols.length===i.limits.protocols)throw new he('Decode error - map field "protocols" had too many elements');a.protocols.push(o.string());break}case 4:{a.publicKey=o.bytes();break}case 5:{a.peerRecordEnvelope=o.bytes();break}case 6:{if(i.limits?.metadata!=null&&a.metadata.size===i.limits.metadata)throw new 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=>dt(o,r.codec()),r.decode=(o,s)=>ft(o,r.codec(),s)})(Vt||(Vt={}));var Cn;(function(r){let t;r.codec=()=>(t==null&&(t=ht((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:J(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=>dt(e,r.codec()),r.decode=(e,n)=>ft(e,r.codec(),n)})(Cn||(Cn={}));var Kn;(function(r){let t;r.codec=()=>(t==null&&(t=ht((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=>dt(e,r.codec()),r.decode=(e,n)=>ft(e,r.codec(),n)})(Kn||(Kn={}));function If(r,t){if(r.publicKey!=null||t.publicKey==null)return r;let e;r.type==="RSA"&&(e=r.toMultihash());let n=en(t.publicKey,e);return Ra(n)}function ec(r,t,e){let n=Vt.decode(t);return ze(r,n,e)}function ze(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:If(r,t),addresses:t.addresses.filter(({observed:s})=>s!=null&&s>Date.now()-e).map(({multiaddr:s,isCertified:i})=>({multiaddr:Dt(s),isCertified:i??!1})),metadata:t.metadata,peerRecordEnvelope:t.peerRecordEnvelope??void 0,tags:n}}function rc(r,t){return _f(r.addresses,t.addresses)&&Bf(r.protocols,t.protocols)&&Lf(r.publicKey,t.publicKey)&&Rf(r.peerRecordEnvelope,t.peerRecordEnvelope)&&Tf(r.metadata,t.metadata)&&Pf(r.tags,t.tags)}function _f(r,t){return oc(r,t,(e,n)=>!(e.isCertified!==n.isCertified||!V(e.multiaddr,n.multiaddr)))}function Bf(r,t){return oc(r,t,(e,n)=>e===n)}function Lf(r,t){return nc(r,t)}function Rf(r,t){return nc(r,t)}function Tf(r,t){return sc(r,t,(e,n)=>V(e,n))}function Pf(r,t){return sc(r,t,(e,n)=>e.value===n.value&&e.expiry===n.expiry)}function nc(r,t){return r==null&&t==null?!0:r!=null&&t!=null?V(r,t):!1}function oc(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 sc(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 Wt="/",ic=new TextEncoder().encode(Wt),Dn=ic[0],Nn=class r{_buf;constructor(t,e){if(typeof t=="string")this._buf=q(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]!==Dn)throw new Error("Invalid key")}toString(t="utf8"){return N(this._buf,t)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(t){return new r(t.join(Wt))}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=ic),this._buf[0]!==Dn){let t=new Uint8Array(this._buf.byteLength+1);t.fill(Dn,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Dn;)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(Wt).slice(1)}type(){return kf(this.baseNamespace())}name(){return Cf(this.baseNamespace())}instance(t){return new r(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(Wt)||(t+=Wt),t+=this.type(),new r(t)}parent(){let t=this.list();return t.length===1?new r(Wt):new r(t.slice(0,-1).join(Wt))}child(t){return this.toString()===Wt?t:t.toString()===Wt?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(),...Kf(t.map(e=>e.namespaces()))])}};function kf(r){let t=r.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function Cf(r){let t=r.split(":");return t[t.length-1]}function Kf(r){return[].concat(...r)}var Ns="/peers/";function Ir(r){if(!ge(r)||r.type==null)throw new U("Invalid PeerId");let t=r.toCID().toString();return new Nn(`${Ns}${t}`)}async function ac(r,t,e,n,o){let s=new Map;for(let i of e){if(i==null)continue;if(i.multiaddr instanceof Uint8Array&&(i.multiaddr=Dt(i.multiaddr)),!fn(i.multiaddr))throw new U("Multiaddr was invalid");if(!await t(r,i.multiaddr,o))continue;let a=i.isCertified??!1,c=i.multiaddr.toString(),f=s.get(c);f!=null?i.isCertified=f.isCertified||a:s.set(c,{multiaddr:i.multiaddr,isCertified:a})}return[...s.values()].sort((i,a)=>i.multiaddr.toString().localeCompare(a.multiaddr.toString())).map(({isCertified:i,multiaddr:a})=>{let c=a.getPeerId();return r.equals(c)&&(a=a.decapsulate(Dt(`/p2p/${r}`))),{isCertified:i,multiaddr:a.bytes}})}async function On(r,t,e,n){if(t==null)throw new U("Invalid PeerData");if(t.publicKey!=null&&r.publicKey!=null&&!t.publicKey.equals(r.publicKey))throw new U("publicKey bytes do not match peer id publicKey bytes");let o=n.existingPeer?.peer;if(o!=null&&!r.equals(o.id))throw new U("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(p=>({isCertified:!1,multiaddr:p}))),t.addresses!=null&&s.push(...t.addresses)),t.protocols!=null&&(i=new Set(t.protocols)),t.metadata!=null){let p=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);a=Un(p,{validate:cc})}if(t.tags!=null){let p=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags);c=Un(p,{validate:uc,map:lc})}t.peerRecordEnvelope!=null&&(f=t.peerRecordEnvelope)}if(e==="merge"){if(t.multiaddrs!=null&&s.push(...t.multiaddrs.map(p=>({isCertified:!1,multiaddr:p}))),t.addresses!=null&&s.push(...t.addresses),t.protocols!=null&&(i=new Set([...i,...t.protocols])),t.metadata!=null){let p=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);for(let[d,w]of p)w==null?a.delete(d):a.set(d,w);a=Un([...a.entries()],{validate:cc})}if(t.tags!=null){let p=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags),d=new Map(c);for(let[w,E]of p)E==null?d.delete(w):d.set(w,E);c=Un([...d.entries()],{validate:uc,map:lc})}t.peerRecordEnvelope!=null&&(f=t.peerRecordEnvelope)}let u;o?.id.publicKey!=null?u=Et(o.id.publicKey):t.publicKey!=null?u=Et(t.publicKey):r.publicKey!=null&&(u=Et(r.publicKey));let l={addresses:await ac(r,n.addressFilter??(async()=>!0),s,n.existingPeer?.peerPB.addresses,n),protocols:[...i.values()].sort((p,d)=>p.localeCompare(d)),metadata:a,tags:c,publicKey:u,peerRecordEnvelope:f};return l.addresses.forEach(p=>{p.observed=n.existingPeer?.peerPB.addresses?.find(d=>V(d.multiaddr,d.multiaddr))?.observed??Date.now()}),r.type!=="RSA"&&delete l.publicKey,l}function Un(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 cc(r,t){if(typeof r!="string")throw new U("Metadata key must be a string");if(!(t instanceof Uint8Array))throw new U("Metadata value must be a Uint8Array")}function uc(r,t){if(typeof r!="string")throw new U("Tag name must be a string");if(t.value!=null){if(parseInt(`${t.value}`,10)!==t.value)throw new U("Tag value must be an integer");if(t.value<0||t.value>100)throw new U("Tag value must be between 0-100")}if(t.ttl!=null){if(parseInt(`${t.ttl}`,10)!==t.ttl)throw new U("Tag ttl must be an integer");if(t.ttl<0)throw new U("Tag ttl must be between greater than 0")}}function lc(r,t){let e;t.expiry!=null&&(e=t.expiry),t.ttl!=null&&(e=BigInt(Date.now()+Number(t.ttl)));let n={value:t.value??0};return e!=null&&(n.expiry=e),n}function fc(r){let t=r.toString().split("/")[2],e=Z.parse(t,St);return rn(e)}function Us(r,t,e){let n=fc(r);return ec(n,t,e)}function Df(r,t){return{prefix:Ns,filters:(r.filters??[]).map(e=>({key:n,value:o})=>e(Us(n,o,t))),orders:(r.orders??[]).map(e=>(n,o)=>e(Us(n.key,n.value,t),Us(o.key,o.value,t)))}}var Mn=class{peerId;datastore;locks;addressFilter;log;maxAddressAge;maxPeerAge;constructor(t,e={}){this.log=t.logger.forComponent("libp2p:peer-store"),this.peerId=t.peerId,this.datastore=t.datastore,this.addressFilter=e.addressFilter,this.locks=Rs({name:"libp2p_peer_store_locks",metrics:t.metrics}),this.maxAddressAge=e.maxAddressAge??36e5,this.maxPeerAge=e.maxPeerAge??216e5}getLock(t){let e=this.locks.get(t);return e==null&&(e={refs:0,lock:Ds({name:t.toString(),singleProcess:!0})},this.locks.set(t,e)),e.refs++,e}maybeRemoveLock(t,e){e.refs--,e.refs===0&&(e.lock.finalize(),this.locks.delete(t))}async getReadLock(t,e){let n=this.getLock(t);try{let o=await n.lock.readLock(e);return()=>{o(),this.maybeRemoveLock(t,n)}}catch(o){throw this.maybeRemoveLock(t,n),o}}async getWriteLock(t,e){let n=this.getLock(t);try{let o=await n.lock.writeLock(e);return()=>{o(),this.maybeRemoveLock(t,n)}}catch(o){throw this.maybeRemoveLock(t,n),o}}async has(t,e){try{return await this.load(t,e),!0}catch(n){if(n.name!=="NotFoundError")throw n}return!1}async delete(t,e){this.peerId.equals(t)||await this.datastore.delete(Ir(t),e)}async load(t,e){let n=Ir(t),o=await this.datastore.get(n,e),s=Vt.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,e),new Ve;return ze(t,s,this.peerId.equals(t)?1/0:this.maxAddressAge)}async save(t,e,n){let o=await this.#t(t,n),s=await On(t,e,"patch",{...n,addressFilter:this.addressFilter});return this.#e(t,s,o)}async patch(t,e,n){let o=await this.#t(t,n),s=await On(t,e,"patch",{...n,addressFilter:this.addressFilter,existingPeer:o});return this.#e(t,s,o)}async merge(t,e,n){let o=await this.#t(t,n),s=await On(t,e,"merge",{addressFilter:this.addressFilter,existingPeer:o});return this.#e(t,s,o)}async*all(t){for await(let{key:e,value:n}of this.datastore.query(Df(t??{},this.maxAddressAge),t)){let o=fc(e);if(o.equals(this.peerId))continue;let s=Vt.decode(n);if(this.#r(o,s)){await this.datastore.delete(e,t);continue}yield ze(o,s,this.peerId.equals(o)?1/0:this.maxAddressAge)}}async#t(t,e){try{let n=Ir(t),o=await this.datastore.get(n,e),s=Vt.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,e),new Ve;return{peerPB:s,peer:ze(t,s,this.maxAddressAge)}}catch(n){n.name!=="NotFoundError"&&this.log.error("invalid peer data found in peer store - %e",n)}}async#e(t,e,n,o){e.updated=Date.now();let s=Vt.encode(e);return await this.datastore.put(Ir(t),s,o),{peer:ze(t,e,this.maxAddressAge),previous:n?.peer,updated:n==null||!rc(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 Os=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 Mn(t,e)}[Symbol.toStringTag]="@libp2p/peer-store";async forEach(t,e){for await(let n of this.store.all(e))t(n)}async all(t){return $a(this.store.all(t))}async delete(t,e){let n=await this.store.getReadLock(t,e);try{await this.store.delete(t,e)}finally{n()}}async has(t,e){let n=await this.store.getReadLock(t,e);try{return await this.store.has(t,e)}finally{this.log.trace("has release read lock"),n?.()}}async get(t,e){let n=await this.store.getReadLock(t,e);try{return await this.store.load(t,e)}finally{n?.()}}async getInfo(t,e){let n=await this.get(t,e);return{id:n.id,multiaddrs:n.addresses.map(({multiaddr:o})=>o)}}async save(t,e,n){let o=await this.store.getWriteLock(t,n);try{let s=await this.store.save(t,e,n);return this.#t(t,s),s.peer}finally{o?.()}}async patch(t,e,n){let o=await this.store.getWriteLock(t,n);try{let s=await this.store.patch(t,e,n);return this.#t(t,s),s.peer}finally{o?.()}}async merge(t,e,n){let o=await this.store.getWriteLock(t,n);try{let s=await this.store.merge(t,e,n);return this.#t(t,s),s.peer}finally{o?.()}}async consumePeerRecord(t,e,n){let o=ge(e)?e:ge(e?.expectedPeer)?e.expectedPeer:void 0,s=ge(e)||e===void 0?n:e,i=await Oe.openAndCertify(t,pe.DOMAIN,s),a=rn(i.publicKey.toCID());if(o?.equals(a)===!1)return this.log("envelope peer id was not the expected peer id - expected: %p received: %p",o,a),!1;let c=pe.createFromProtobuf(i.payload),f;try{f=await this.get(a,s)}catch(u){if(u.name!=="NotFoundError")throw u}if(f?.peerRecordEnvelope!=null){let u=Oe.createFromProtobuf(f.peerRecordEnvelope),l=pe.createFromProtobuf(u.payload);if(l.seqNumber>=c.seqNumber)return this.log("sequence number was lower or equal to existing sequence number - stored: %d received: %d",l.seqNumber,c.seqNumber),!1}return await this.patch(c.peerId,{peerRecordEnvelope:t,addresses:c.multiaddrs.map(u=>({isCertified:!0,multiaddr:u}))},s),!0}#t(t,e){e.updated&&(this.peerId.equals(t)?this.events.safeDispatchEvent("self:peer:update",{detail:e}):this.events.safeDispatchEvent("peer:update",{detail:e}))}};function Nf(r,t={}){return new Os(r,t)}return yc(Uf);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/hashes/esm/utils.js:
6
6
  (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
7
7
 
8
- @noble/curves/esm/abstract/utils.js:
8
+ @noble/curves/esm/utils.js:
9
9
  @noble/curves/esm/abstract/modular.js:
10
10
  @noble/curves/esm/abstract/curve.js:
11
11
  @noble/curves/esm/abstract/edwards.js: