@libp2p/peer-store 11.2.2-5b004c0c4 → 11.2.2-8e87be9e6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PPeerStore = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PPeerStore=(()=>{var yc=Object.create;var Rr=Object.defineProperty;var gc=Object.getOwnPropertyDescriptor;var bc=Object.getOwnPropertyNames;var wc=Object.getPrototypeOf,xc=Object.prototype.hasOwnProperty;var Ec=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),At=(r,t)=>{for(var e in t)Rr(r,e,{get:t[e],enumerable:!0})},Ms=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of bc(t))!xc.call(r,o)&&o!==e&&Rr(r,o,{get:()=>t[o],enumerable:!(n=gc(t,o))||n.enumerable});return r};var vc=(r,t,e)=>(e=r!=null?yc(wc(r)):{},Ms(t||!r||!r.__esModule?Rr(e,"default",{value:r,enumerable:!0}):e,r)),Ac=r=>Ms(Rr({},"__esModule",{value:!0}),r);var Ya=Ec((Eg,ws)=>{"use strict";var xf=Object.prototype.hasOwnProperty,Et="~";function Lr(){}Object.create&&(Lr.prototype=Object.create(null),new Lr().__proto__||(Et=!1));function Ef(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function Za(r,t,e,n,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var s=new Ef(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 yn(r,t){--r._eventsCount===0?r._events=new Lr:delete r._events[t]}function pt(){this._events=new Lr,this._eventsCount=0}pt.prototype.eventNames=function(){var t=[],e,n;if(this._eventsCount===0)return t;for(n in e=this._events)xf.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],l=arguments.length,u,f;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),l){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(f=1,u=new Array(l-1);f<l;f++)u[f-1]=arguments[f];c.fn.apply(c.context,u)}else{var p=c.length,y;for(f=0;f<p;f++)switch(c[f].once&&this.removeListener(t,c[f].fn,void 0,!0),l){case 1:c[f].fn.call(c[f].context);break;case 2:c[f].fn.call(c[f].context,e);break;case 3:c[f].fn.call(c[f].context,e,n);break;case 4:c[f].fn.call(c[f].context,e,n,o);break;default:if(!u)for(y=1,u=new Array(l-1);y<l;y++)u[y-1]=arguments[y];c[f].fn.apply(c[f].context,u)}}return!0};pt.prototype.on=function(t,e,n){return Za(this,t,e,n,!1)};pt.prototype.once=function(t,e,n){return Za(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 yn(this,s),this;var i=this._events[s];if(i.fn)i.fn===e&&(!o||i.once)&&(!n||i.context===n)&&yn(this,s);else{for(var a=0,c=[],l=i.length;a<l;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:yn(this,s)}return this};pt.prototype.removeAllListeners=function(t){var e;return t?(e=Et?Et+t:t,this._events[e]&&yn(this,e)):(this._events=new Lr,this._eventsCount=0),this};pt.prototype.off=pt.prototype.removeListener;pt.prototype.addListener=pt.prototype.on;pt.prefixed=Et;pt.EventEmitter=pt;typeof ws<"u"&&(ws.exports=pt)});var Nf={};At(Nf,{persistentPeerStore:()=>Uf});var kr=Symbol.for("@libp2p/peer-id");function _e(r){return!!r?.[kr]}var H=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Ce=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Je=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var Kr=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:()=>_c});var Hf=new Uint8Array(0);function qs(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 Wt(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 Hs(r){return new TextEncoder().encode(r)}function Vs(r){return new TextDecoder().decode(r)}function Sc(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),l=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function f(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,k=0,K=0,F=A.length;K!==F&&A[K]===0;)K++,g++;for(var S=(F-K)*u+1>>>0,d=new Uint8Array(S);K!==F;){for(var b=A[K],I=0,B=S-1;(b!==0||I<k)&&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");k=I,K++}for(var T=S-k;T!==S&&d[T]===0;)T++;for(var R=c.repeat(g);T<S;++T)R+=r.charAt(d[T]);return R}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 k=0,K=0;A[g]===c;)k++,g++;for(var F=(A.length-g)*l+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<K)&&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");K=b,g++}if(A[g]!==" "){for(var B=F-K;B!==F&&S[B]===0;)B++;for(var T=new Uint8Array(k+(F-B)),R=k;B!==F;)T[R++]=S[B++];return T}}}function y(A){var g=p(A);if(g)return g;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:p,decode:y}}var Ic=Sc,Bc=Ic,Fs=Bc;var Bn=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")}},Tn=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 Ws(this,t)}},Ln=class{decoders;constructor(t){this.decoders=t}or(t){return Ws(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 Ws(r,t){return new Ln({...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 Bn(t,e,n),this.decoder=new Tn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Re({name:r,prefix:t,encode:e,decode:n}){return new Pn(r,t,e,n)}function se({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Fs(e,r);return Re({prefix:t,name:r,encode:n,decode:s=>Wt(o(s))})}function Tc(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let l=0;l<o;++l){let u=t[r[l]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|u,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Lc(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 Pc(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=Pc(n);return Re({prefix:t,name:r,encode(s){return Lc(s,n,e)},decode(s){return Tc(s,o,e,r)}})}var Z=se({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),_c=se({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Cn={};At(Cn,{base32:()=>Kt,base32hex:()=>Kc,base32hexpad:()=>Uc,base32hexpadupper:()=>Nc,base32hexupper:()=>Dc,base32pad:()=>Rc,base32padupper:()=>kc,base32upper:()=>Cc,base32z:()=>Oc});var Kt=J({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Cc=J({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Rc=J({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),kc=J({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Kc=J({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Dc=J({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Uc=J({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Nc=J({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Oc=J({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Rn={};At(Rn,{base36:()=>tr,base36upper:()=>Mc});var tr=se({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Mc=se({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var qc=Zs,Gs=128,Hc=127,Vc=~Hc,zc=Math.pow(2,31);function Zs(r,t,e){t=t||[],e=e||0;for(var n=e;r>=zc;)t[e++]=r&255|Gs,r/=128;for(;r&Vc;)t[e++]=r&255|Gs,r>>>=7;return t[e]=r|0,Zs.bytes=e-n+1,t}var Fc=kn,Wc=128,$s=127;function kn(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw kn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&$s)<<o:(i&$s)*Math.pow(2,o),o+=7}while(i>=Wc);return kn.bytes=s-n,e}var Gc=Math.pow(2,7),$c=Math.pow(2,14),Zc=Math.pow(2,21),Yc=Math.pow(2,28),jc=Math.pow(2,35),Xc=Math.pow(2,42),Qc=Math.pow(2,49),Jc=Math.pow(2,56),tu=Math.pow(2,63),eu=function(r){return r<Gc?1:r<$c?2:r<Zc?3:r<Yc?4:r<jc?5:r<Xc?6:r<Qc?7:r<Jc?8:r<tu?9:10},ru={encode:qc,decode:Fc,encodingLength:eu},nu=ru,er=nu;function rr(r,t=0){return[er.decode(r,t),er.decode.bytes]}function ke(r,t,e=0){return er.encode(r,t,e),t}function Ke(r){return er.encodingLength(r)}function Dt(r,t){let e=t.byteLength,n=Ke(r),o=n+Ke(e),s=new Uint8Array(o+e);return ke(r,s,0),ke(e,s,n),s.set(t,o),new De(r,e,t,s)}function Gt(r){let t=Wt(r),[e,n]=rr(t),[o,s]=rr(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 Ys(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&qs(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 js(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return su(e,Kn(r),t??Z.encoder);default:return iu(e,Kn(r),t??Kt.encoder)}}var Xs=new WeakMap;function Kn(r){let t=Xs.get(r);if(t==null){let e=new Map;return Xs.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!==nr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==au)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&&Ys(t.multihash,n.multihash)}toString(t){return js(this,t)}toJSON(){return{"/":js(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??Qs(n,o,s.bytes))}else if(e[cu]===!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!==nr)throw new Error(`Version 0 CID must use dag-pb (code: ${nr}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Qs(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,nr,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=Wt(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[f,p]=rr(t.subarray(e));return e+=p,f},o=n(),s=nr;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),l=e+c,u=l-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:l}}static parse(t,e){let[n,o]=ou(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 Kn(s).set(n,t),s}};function ou(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 Kt.prefix:{let e=t??Kt;return[Kt.prefix,e.decode(r)]}case tr.prefix:{let e=t??tr;return[tr.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 su(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 iu(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 nr=112,au=18;function Qs(r,t,e){let n=Ke(r),o=n+Ke(t),s=new Uint8Array(o+e.byteLength);return ke(r,s,0),ke(t,s,n),s.set(e,o),s}var cu=Symbol.for("@ipld/js-cid/CID");var Dn={};At(Dn,{identity:()=>Ut});var Js=0,uu="identity",ti=Wt;function lu(r){return Dt(Js,ti(r))}var Ut={code:Js,name:uu,encode:ti,digest:lu};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 Lt(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 ri=Symbol.for("@achingbrain/uint8arraylist");function ei(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 Nr(r){return!!r?.[ri]}var mt=class r{bufs;length;[ri]=!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(Nr(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(Nr(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=ei(this.bufs,t);return e.buf[e.index]}set(t,e){let n=ei(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(Nr(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 Lt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Lt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let l=t>=a&&t<c,u=e>a&&e<=c;if(l&&u){if(t===a&&e===c){n.push(i);break}let f=t-a;n.push(i.subarray(f,f+(e-t)));break}if(l){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(u){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Nr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,l=n.byteLength-1,u;for(let f=e;f<=c;f+=u){u=0;for(let p=l;p>=0;p--){let y=this.get(f+p);if(n[p]!==y){u=Math.max(1,p-a[y]);break}}if(u===0)return f}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=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 Un={};At(Un,{base10:()=>fu});var fu=se({prefix:"9",name:"base10",alphabet:"0123456789"});var Nn={};At(Nn,{base16:()=>du,base16upper:()=>hu});var du=J({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),hu=J({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var On={};At(On,{base2:()=>pu});var pu=J({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Mn={};At(Mn,{base256emoji:()=>wu});var ni=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}"),mu=ni.reduce((r,t,e)=>(r[e]=t,r),[]),yu=ni.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function gu(r){return r.reduce((t,e)=>(t+=mu[e],t),"")}function bu(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=yu[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var wu=Re({prefix:"\u{1F680}",name:"base256emoji",encode:gu,decode:bu});var qn={};At(qn,{base64:()=>xu,base64pad:()=>Eu,base64url:()=>vu,base64urlpad:()=>Au});var xu=J({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Eu=J({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),vu=J({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Au=J({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Hn={};At(Hn,{base8:()=>Su});var Su=J({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Vn={};At(Vn,{identity:()=>Iu});var Iu=Re({prefix:"\0",name:"identity",encode:r=>Vs(r),decode:r=>Hs(r)});var Sd=new TextEncoder,Id=new TextDecoder;var Wn={};At(Wn,{sha256:()=>or,sha512:()=>Lu});function Fn({name:r,code:t,encode:e}){return new zn(r,t,e)}var zn=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 si(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var or=Fn({name:"sha2-256",code:18,encode:si("SHA-256")}),Lu=Fn({name:"sha2-512",code:19,encode:si("SHA-512")});var sr={...Vn,...On,...Hn,...Un,...Nn,...Cn,...Rn,..._n,...qn,...Mn},Nd={...Wn,...Dn};function ai(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var ii=ai("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Gn=ai("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}),Pu={utf8:ii,"utf-8":ii,hex:sr.base16,latin1:Gn,ascii:Gn,binary:Gn,...sr},Or=Pu;function G(r,t="utf8"){let e=Or[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function N(r,t="utf8"){let e=Or[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var _u=parseInt("11111",2),$n=parseInt("10000000",2),Cu=parseInt("01111111",2),ci={0:ir,1:ir,2:Ru,3:Du,4:Uu,5:Ku,6:ku,16:ir,22:ir,48:ir};function Zt(r,t={offset:0}){let e=r[t.offset]&_u;if(t.offset++,ci[e]!=null)return ci[e](r,t);throw new Error("No decoder for tag "+e)}function ar(r,t){let e=0;if((r[t.offset]&$n)===$n){let n=r[t.offset]&Cu,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 ir(r,t){ar(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Zt(r,t);if(n===null)break;e.push(n)}return e}function Ru(r,t){let e=ar(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 ku(r,t){let e=ar(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let l=r[t.offset];if(t.offset++,c.push(l&127),l<128){c.reverse();let u=0;for(let f=0;f<c.length;f++)u+=c[f]<<f*7;a+=`.${u}`,c=[]}}return a}function Ku(r,t){return t.offset++,null}function Du(r,t){let e=ar(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 Uu(r,t){let e=ar(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Nu(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 Zn(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Nu(r.byteLength);return new mt(Uint8Array.from([t.byteLength|$n]),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]),Zn(t),t)}function Mr(r){let t=Uint8Array.from([0]),e=new mt(t,r);return new mt(Uint8Array.from([3]),Zn(e),e)}function ie(r,t=48){let e=new mt;for(let n of r)e.append(n);return new mt(Uint8Array.from([t]),Zn(e),e)}async function ui(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 Ou=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Mu=Uint8Array.from([6,5,43,129,4,0,34]),qu=Uint8Array.from([6,5,43,129,4,0,35]),Hu={ext:!0,kty:"EC",crv:"P-256"},Vu={ext:!0,kty:"EC",crv:"P-384"},zu={ext:!0,kty:"EC",crv:"P-521"},Yn=32,jn=48,Xn=66;function Qn(r){let t=Zt(r);return li(t)}function li(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===Yn*2+1)return n=N(t.subarray(e,e+Yn),"base64url"),o=N(t.subarray(e+Yn),"base64url"),new Ue({...Hu,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 Ue({...Vu,key_ops:["verify"],x:n,y:o});if(t.byteLength===Xn*2+1)return n=N(t.subarray(e,e+Xn),"base64url"),o=N(t.subarray(e+Xn),"base64url"),new Ue({...zu,key_ops:["verify"],x:n,y:o});throw new H(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function fi(r){return ie([It(Uint8Array.from([1])),ie([Fu(r.crv)],160),ie([Mr(new mt(Uint8Array.from([4]),G(r.x??"","base64url"),G(r.y??"","base64url")))],161)]).subarray()}function Fu(r){if(r==="P-256")return Ou;if(r==="P-384")return Mu;if(r==="P-521")return qu;throw new H(`Invalid curve ${r}`)}var Ue=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=fi(this.jwk)),this._raw}toMultihash(){return Ut.digest(Ct(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,n){return ui(this.jwk,e,t,n)}};var ye=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Wu(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function qr(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function ge(r,...t){if(!Wu(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");qr(r.outputLen),qr(r.blockLen)}function Oe(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){ge(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}function Yt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Hr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Nt(r,t){return r<<32-t|r>>>t}function pi(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function cr(r){return typeof r=="string"&&(r=pi(r)),ge(r),r}function Jn(...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 Ne=class{};function to(r){let t=n=>r().update(cr(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function Vr(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 Gu(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(e>>o&s),a=Number(e&s),c=n?4:0,l=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+l,a,n)}function mi(r,t,e){return r&t^~r&e}function yi(r,t,e){return r&t^r&e^t&e}var ur=class extends Ne{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=Hr(this.buffer)}update(t){Oe(this),t=cr(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=Hr(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){Oe(this),hi(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Yt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)e[f]=0;Gu(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=Hr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=c/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<l;f++)a.setUint32(4*f,u[f],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},jt=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 zr=BigInt(4294967295),gi=BigInt(32);function $u(r,t=!1){return t?{h:Number(r&zr),l:Number(r>>gi&zr)}:{h:Number(r>>gi&zr)|0,l:Number(r&zr)|0}}function bi(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}=$u(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var eo=(r,t,e)=>r>>>e,ro=(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,lr=(r,t,e)=>r<<64-e|t>>>e-32,fr=(r,t,e)=>r>>>e-32|t<<64-e;function Mt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var wi=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),xi=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Ei=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),vi=(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),Si=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Yu=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]),ae=new Uint32Array(64),Fr=class extends ur{constructor(t=32){super(64,t,8,!1),this.A=jt[0]|0,this.B=jt[1]|0,this.C=jt[2]|0,this.D=jt[3]|0,this.E=jt[4]|0,this.F=jt[5]|0,this.G=jt[6]|0,this.H=jt[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let f=0;f<16;f++,e+=4)ae[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let p=ae[f-15],y=ae[f-2],A=Nt(p,7)^Nt(p,18)^p>>>3,g=Nt(y,17)^Nt(y,19)^y>>>10;ae[f]=g+ae[f-7]+A+ae[f-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:l,H:u}=this;for(let f=0;f<64;f++){let p=Nt(a,6)^Nt(a,11)^Nt(a,25),y=u+p+mi(a,c,l)+Yu[f]+ae[f]|0,g=(Nt(n,2)^Nt(n,13)^Nt(n,22))+yi(n,o,s)|0;u=l,l=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,l=l+this.G|0,u=u+this.H|0,this.set(n,o,s,i,a,c,l,u)}roundClean(){Yt(ae)}destroy(){this.set(0,0,0,0,0,0,0,0),Yt(this.buffer)}};var Ii=bi(["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))),ju=Ii[0],Xu=Ii[1],ce=new Uint32Array(80),ue=new Uint32Array(80),no=class extends ur{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:l,El:u,Fh:f,Fl:p,Gh:y,Gl:A,Hh:g,Hl:k}=this;return[t,e,n,o,s,i,a,c,l,u,f,p,y,A,g,k]}set(t,e,n,o,s,i,a,c,l,u,f,p,y,A,g,k){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=l|0,this.El=u|0,this.Fh=f|0,this.Fl=p|0,this.Gh=y|0,this.Gl=A|0,this.Hh=g|0,this.Hl=k|0}process(t,e){for(let S=0;S<16;S++,e+=4)ce[S]=t.getUint32(e),ue[S]=t.getUint32(e+=4);for(let S=16;S<80;S++){let d=ce[S-15]|0,b=ue[S-15]|0,I=be(d,b,1)^be(d,b,8)^eo(d,b,7),B=we(d,b,1)^we(d,b,8)^ro(d,b,7),T=ce[S-2]|0,R=ue[S-2]|0,O=be(T,R,19)^lr(T,R,61)^eo(T,R,6),P=we(T,R,19)^fr(T,R,61)^ro(T,R,6),D=Ei(B,P,ue[S-7],ue[S-16]),C=vi(D,I,O,ce[S-7],ce[S-16]);ce[S]=C|0,ue[S]=D|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:l,Dl:u,Eh:f,El:p,Fh:y,Fl:A,Gh:g,Gl:k,Hh:K,Hl:F}=this;for(let S=0;S<80;S++){let d=be(f,p,14)^be(f,p,18)^lr(f,p,41),b=we(f,p,14)^we(f,p,18)^fr(f,p,41),I=f&y^~f&g,B=p&A^~p&k,T=Ai(F,b,B,Xu[S],ue[S]),R=Si(T,K,d,I,ju[S],ce[S]),O=T|0,P=be(n,o,28)^lr(n,o,34)^lr(n,o,39),D=we(n,o,28)^fr(n,o,34)^fr(n,o,39),C=n&s^n&a^s&a,nt=o&i^o&c^i&c;K=g|0,F=k|0,g=y|0,k=A|0,y=f|0,A=p|0,{h:f,l:p}=Mt(l|0,u|0,R|0,O|0),l=a|0,u=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let E=wi(O,D,nt);n=xi(E,R,P,C),o=E|0}({h:n,l:o}=Mt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Mt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Mt(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:u}=Mt(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:p}=Mt(this.Eh|0,this.El|0,f|0,p|0),{h:y,l:A}=Mt(this.Fh|0,this.Fl|0,y|0,A|0),{h:g,l:k}=Mt(this.Gh|0,this.Gl|0,g|0,k|0),{h:K,l:F}=Mt(this.Hh|0,this.Hl|0,K|0,F|0),this.set(n,o,s,i,a,c,l,u,f,p,y,A,g,k,K,F)}roundClean(){Yt(ce,ue)}destroy(){Yt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Wr=to(()=>new Fr);var Bi=to(()=>new no);var ao=BigInt(0),io=BigInt(1);function Me(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function co(r){if(!Me(r))throw new Error("Uint8Array expected")}function qt(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function dr(r){let t=r.toString(16);return t.length&1?"0"+t:t}function Pi(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?ao:BigInt("0x"+r)}var _i=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Qu=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function le(r){if(co(r),_i)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=Qu[r[e]];return t}var Xt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ti(r){if(r>=Xt._0&&r<=Xt._9)return r-Xt._0;if(r>=Xt.A&&r<=Xt.F)return r-(Xt.A-10);if(r>=Xt.a&&r<=Xt.f)return r-(Xt.a-10)}function hr(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(_i)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=Ti(r.charCodeAt(s)),a=Ti(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 Qt(r){return Pi(le(r))}function xe(r){return co(r),Pi(le(Uint8Array.from(r).reverse()))}function Ee(r,t){return hr(r.toString(16).padStart(t*2,"0"))}function qe(r,t){return Ee(r,t).reverse()}function X(r,t,e){let n;if(typeof t=="string")try{n=hr(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(Me(t))n=Uint8Array.from(t);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof e=="number"&&o!==e)throw new Error(r+" of length "+e+" expected, got "+o);return n}function fe(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];co(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 oo=r=>typeof r=="bigint"&&ao<=r;function Gr(r,t,e){return oo(r)&&oo(t)&&oo(e)&&t<=r&&r<e}function Pt(r,t,e,n){if(!Gr(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Ci(r){let t;for(t=0;r>ao;r>>=io,t+=1);return t}var ve=r=>(io<<BigInt(r))-io,so=r=>new Uint8Array(r),Li=r=>Uint8Array.from(r);function Ri(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=so(r),o=so(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},a=(...f)=>e(o,n,...f),c=(f=so(0))=>{o=a(Li([0]),f),n=a(),f.length!==0&&(o=a(Li([1]),f),n=a())},l=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,p=[];for(;f<t;){n=a();let y=n.slice();p.push(y),f+=n.length}return fe(...p)};return(f,p)=>{i(),c(f);let y;for(;!(y=p(l()));)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"||Me(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function Jt(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 He(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),tl=BigInt(3),Ki=BigInt(4),Di=BigInt(5),Ui=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 $r(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 l=n/e,u=n%e,f=o-i*l,p=s-a*l;n=e,e=u,o=i,s=a,i=f,a=p}if(n!==at)throw new Error("invert: does not exist");return $(o,t)}function Ni(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 el(r,t){let e=(r.ORDER-Di)/Ui,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 rl(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=te(r);for(;ki(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return Ni;let s=o.pow(n,t),i=(t+at)/Ae;return function(c,l){if(c.is0(l))return l;if(ki(c,l)!==1)throw new Error("Cannot find square root");let u=e,f=c.mul(c.ONE,s),p=c.pow(l,t),y=c.pow(l,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 k=at<<BigInt(u-A-1),K=c.pow(f,k);u=A,f=c.sqr(K),p=c.mul(p,f),y=c.mul(y,K)}return y}}function nl(r){return r%Ki===tl?Ni:r%Ui===Di?el:rl(r)}var Oi=(r,t)=>($(r,t)&at)===at,ol=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function uo(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=ol.reduce((n,o)=>(n[o]="function",n),t);return Jt(r,e)}function sl(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 Ve(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 ki(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 lo(r,t){t!==void 0&&qr(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function te(r,t,e=!1,n={}){if(r<=yt)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:s}=lo(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,l)=>c===l,sqr:c=>$(c*c,r),add:(c,l)=>$(c+l,r),sub:(c,l)=>$(c-l,r),mul:(c,l)=>$(c*l,r),pow:(c,l)=>sl(a,c,l),div:(c,l)=>$(c*$r(l,r),r),sqrN:c=>c*c,addN:(c,l)=>c+l,subN:(c,l)=>c-l,mulN:(c,l)=>c*l,inv:c=>$r(c,r),sqrt:n.sqrt||(c=>(i||(i=nl(r)),i(a,c))),toBytes:c=>e?qe(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):Qt(c)},invertBatch:c=>Ve(a,c),cmov:(c,l,u)=>u?l:c});return Object.freeze(a)}function Mi(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 fo(r){let t=Mi(r);return t+Math.ceil(t/2)}function qi(r,t,e=!1){let n=r.length,o=Mi(t),s=fo(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?xe(r):Qt(r),a=$(i,t-at)+at;return e?qe(a,o):Ee(a,o)}var Hi=BigInt(0),go=BigInt(1);function ho(r,t){let e=t.negate();return r?e:t}function zi(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function po(r,t){zi(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 Vi(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+=go);let l=t*n,u=l+Math.abs(a)-1,f=a===0,p=a<0,y=t%2!==0;return{nextN:c,offset:u,isZero:f,isNeg:p,isNegF:y,offsetF:l}}function il(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 al(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 mo=new WeakMap,Fi=new WeakMap;function yo(r){return Fi.get(r)||1}function Zr(r,t){return{constTimeNegate:ho,hasPrecomputes(e){return yo(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>Hi;)n&go&&(o=o.add(s)),s=s.double(),n>>=go;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=po(n,t),i=[],a=e,c=a;for(let l=0;l<o;l++){c=a,i.push(c);for(let u=1;u<s;u++)c=c.add(a),i.push(c);a=c.double()}return i},wNAF(e,n,o){let s=r.ZERO,i=r.BASE,a=po(e,t);for(let c=0;c<a.windows;c++){let{nextN:l,offset:u,isZero:f,isNeg:p,isNegF:y,offsetF:A}=Vi(o,c,a);o=l,f?i=i.add(ho(y,n[A])):s=s.add(ho(p,n[u]))}return{p:s,f:i}},wNAFUnsafe(e,n,o,s=r.ZERO){let i=po(e,t);for(let a=0;a<i.windows&&o!==Hi;a++){let{nextN:c,offset:l,isZero:u,isNeg:f}=Vi(o,a,i);if(o=c,!u){let p=n[l];s=s.add(f?p.negate():p)}}return s},getPrecomputes(e,n,o){let s=mo.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&mo.set(n,o(s))),s},wNAFCached(e,n,o){let s=yo(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=yo(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){zi(n,t),Fi.set(e,n),mo.delete(e)}}}function Yr(r,t,e,n){il(e,r),al(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=Ci(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let l=ve(c),u=new Array(Number(l)+1).fill(i),f=Math.floor((t.BITS-1)/c)*c,p=i;for(let y=f;y>=0;y-=c){u.fill(i);for(let g=0;g<s;g++){let k=n[g],K=Number(k>>BigInt(y)&l);u[K]=u[K].add(e[g])}let A=i;for(let g=u.length-1,k=i;g>0;g--)k=k.add(u[g]),A=A.add(k);if(p=p.add(A),y!==0)for(let g=0;g<c;g++)p=p.double()}return p}function pr(r){return uo(r.Fp),Jt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...lo(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Ht=BigInt(0),gt=BigInt(1),Wi=BigInt(2),cl=BigInt(8),ul={zip215:!0};function ll(r){let t=pr(r);return Jt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Gi(r){let t=ll(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:a,h:c}=t,l=Wi<<BigInt(a*8)-gt,u=e.create,f=te(t.n,t.nBitLength);function p(w,h){let m=e.sqr(w),v=e.sqr(h),_=e.add(e.mul(t.a,m),v),U=e.add(e.ONE,e.mul(t.d,e.mul(m,v)));return e.eql(_,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:Ht}}}),A=t.adjustScalarBytes||(w=>w),g=t.domain||((w,h,m)=>{if(qt("phflag",m),h.length||m)throw new Error("Contexts/pre-hash are not supported");return w});function k(w,h,m=!1){let v=m?gt:Ht;Pt("coordinate "+w,h,v,l)}function K(w){if(!(w instanceof d))throw new Error("ExtendedPoint expected")}let F=He((w,h)=>{let{ex:m,ey:v,ez:_}=w,U=w.is0();h==null&&(h=U?cl:e.inv(_));let M=u(m*h),q=u(v*h),V=u(_*h);if(U)return{x:Ht,y:gt};if(V!==gt)throw new Error("invZ was invalid");return{x:M,y:q}}),S=He(w=>{let{a:h,d:m}=t;if(w.is0())throw new Error("bad point: ZERO");let{ex:v,ey:_,ez:U,et:M}=w,q=u(v*v),V=u(_*_),W=u(U*U),ot=u(W*W),et=u(q*h),ut=u(W*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*_),ft=u(U*M);if(it!==ft)throw new Error("bad point: equation left != right (2)");return!0});class d{constructor(h,m,v,_){k("x",h),k("y",m),k("z",v,!0),k("t",_),this.ex=h,this.ey=m,this.ez=v,this.et=_,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 k("x",m),k("y",v),new d(m,v,gt,u(m*v))}static normalizeZ(h){let m=Ve(e,h.map(v=>v.ez));return h.map((v,_)=>v.toAffine(m[_])).map(d.fromAffine)}static msm(h,m){return Yr(d,f,h,m)}_setWindowSize(h){B.setWindowSize(this,h)}assertValidity(){S(this)}equals(h){K(h);let{ex:m,ey:v,ez:_}=this,{ex:U,ey:M,ez:q}=h,V=u(m*q),W=u(U*_),ot=u(v*q),et=u(M*_);return V===W&&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:_}=this,U=u(m*m),M=u(v*v),q=u(Wi*u(_*_)),V=u(h*U),W=m+v,ot=u(u(W*W)-U-M),et=V+M,ut=et-q,vt=V-M,it=u(ot*ut),ft=u(et*vt),Tt=u(ot*vt),kt=u(ut*et);return new d(it,ft,kt,Tt)}add(h){K(h);let{a:m,d:v}=t,{ex:_,ey:U,ez:M,et:q}=this,{ex:V,ey:W,ez:ot,et}=h,ut=u(_*V),vt=u(U*W),it=u(q*v*et),ft=u(M*ot),Tt=u((_+U)*(V+W)-ut-vt),kt=ft-it,Qe=ft+it,Os=u(vt-m*ut),dc=u(Tt*kt),hc=u(Qe*Os),pc=u(Tt*Os),mc=u(kt*Qe);return new d(dc,hc,mc,pc)}subtract(h){return this.add(h.negate())}wNAF(h){return B.wNAFCached(this,h,d.normalizeZ)}multiply(h){let m=h;Pt("scalar",m,gt,n);let{p:v,f:_}=this.wNAF(m);return d.normalizeZ([v,_])[0]}multiplyUnsafe(h,m=d.ZERO){let v=h;return Pt("scalar",v,Ht,n),v===Ht?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:_}=t,U=e.BYTES;h=X("pointHex",h,U),qt("zip215",m);let M=h.slice(),q=h[U-1];M[U-1]=q&-129;let V=xe(M),W=m?l:e.ORDER;Pt("pointHex.y",V,Ht,W);let ot=u(V*V),et=u(ot-gt),ut=u(v*ot-_),{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===Ht&&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=qe(m,e.BYTES);return v[v.length-1]|=h&gt?128:0,v}toHex(){return le(this.toRawBytes())}}d.BASE=new d(t.Gx,t.Gy,gt,u(t.Gx*t.Gy)),d.ZERO=new d(Ht,gt,gt,Ht);let{BASE:b,ZERO:I}=d,B=Zr(d,a*8);function T(w){return $(w,n)}function R(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)),_=m.slice(h,2*h),U=R(v);return{head:v,prefix:_,scalar:U}}function P(w){let{head:h,prefix:m,scalar:v}=O(w),_=b.multiply(v),U=_.toRawBytes();return{head:h,prefix:m,scalar:v,point:_,pointBytes:U}}function D(w){return P(w).pointBytes}function C(w=Uint8Array.of(),...h){let m=fe(...h);return R(s(g(m,X("context",w),!!o)))}function nt(w,h,m={}){w=X("message",w),o&&(w=o(w));let{prefix:v,scalar:_,pointBytes:U}=P(h),M=C(m.context,v,w),q=b.multiply(M).toRawBytes(),V=C(m.context,q,U,w),W=T(M+V*_);Pt("signature.s",W,Ht,n);let ot=fe(q,qe(W,e.BYTES));return X("result",ot,e.BYTES*2)}let E=ul;function x(w,h,m,v=E){let{context:_,zip215:U}=v,M=e.BYTES;w=X("signature",w,2*M),h=X("message",h),m=X("publicKey",m,M),U!==void 0&&qt("zip215",U),o&&(h=o(h));let q=xe(w.slice(M,2*M)),V,W,ot;try{V=d.fromHex(m,U),W=d.fromHex(w.slice(0,M),U),ot=b.multiplyUnsafe(q)}catch{return!1}if(!U&&V.isSmallOrder())return!1;let et=C(_,W.toRawBytes(),V.toRawBytes(),h);return W.add(V.multiplyUnsafe(et)).subtract(ot).clearCofactor().equals(d.ZERO)}return b._setWindowSize(8),{CURVE:t,getPublicKey:D,sign:nt,verify:x,ExtendedPoint:d,utils:{getExtendedPublicKey:P,randomPrivateKey:()=>i(e.BYTES),precompute(w=8,h=d.BASE){return h._setWindowSize(w),h.multiply(BigInt(3)),h}}}}var bo=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),$i=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),qh=BigInt(0),fl=BigInt(1),Zi=BigInt(2),Hh=BigInt(3),dl=BigInt(5),hl=BigInt(8);function pl(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=bo,a=r*r%s*r%s,c=Q(a,Zi,s)*a%s,l=Q(c,fl,s)*r%s,u=Q(l,dl,s)*l%s,f=Q(u,t,s)*u%s,p=Q(f,e,s)*f%s,y=Q(p,n,s)*p%s,A=Q(y,o,s)*y%s,g=Q(A,o,s)*y%s,k=Q(g,t,s)*u%s;return{pow_p_5_8:Q(k,Zi,s)*r%s,b2:a}}function ml(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function yl(r,t){let e=bo,n=$(t*t*t,e),o=$(n*n*t,e),s=pl(r*o).pow_p_5_8,i=$(r*n*s,e),a=$(t*i*i,e),c=i,l=$(i*$i,e),u=a===r,f=a===$(-r,e),p=a===$(-r*$i,e);return u&&(i=c),(f||p)&&(i=l),Oi(i,e)&&(i=$(-i,e)),{isValid:u||f,value:i}}var Yi=te(bo,void 0,!0),gl={a:Yi.create(BigInt(-1)),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Yi,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:hl,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Bi,randomBytes:Vr,adjustScalarBytes:ml,uvRatio:yl},ji=Gi(gl);var jr=32;function Xi(r,t,e){return ji.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var Xr=class{type="Ed25519";raw;constructor(t){this.raw=wo(t,jr)}toMultihash(){return Ut.digest(Ct(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,n){return n?.signal?.throwIfAborted(),Xi(this.raw,e,t)}};function xo(r){return r=wo(r,jr),new Xr(r)}function wo(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 wl=Math.pow(2,7),xl=Math.pow(2,14),El=Math.pow(2,21),Eo=Math.pow(2,28),vo=Math.pow(2,35),Ao=Math.pow(2,42),So=Math.pow(2,49),z=128,dt=127;function Bt(r){if(r<wl)return 1;if(r<xl)return 2;if(r<El)return 3;if(r<Eo)return 4;if(r<vo)return 5;if(r<Ao)return 6;if(r<So)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Io(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 vl(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 Bo(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)*Eo,e<z)||(e=r[t+5],n+=(e&dt)*vo,e<z)||(e=r[t+6],n+=(e&dt)*Ao,e<z)||(e=r[t+7],n+=(e&dt)*So,e<z))return n;throw new RangeError("Could not decode varint")}function Al(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)*Eo,e<z)||(e=r.get(t+5),n+=(e&dt)*vo,e<z)||(e=r.get(t+6),n+=(e&dt)*Ao,e<z)||(e=r.get(t+7),n+=(e&dt)*So,e<z))return n;throw new RangeError("Could not decode varint")}function Vt(r,t,e=0){return t==null&&(t=St(Bt(r))),t instanceof Uint8Array?Io(r,t,e):vl(r,t,e)}function Se(r,t=0){return r instanceof Uint8Array?Bo(r,t):Al(r,t)}var Lo=new Float32Array([-0]),de=new Uint8Array(Lo.buffer);function Ji(r,t,e){Lo[0]=r,t[e]=de[0],t[e+1]=de[1],t[e+2]=de[2],t[e+3]=de[3]}function ta(r,t){return de[0]=r[t],de[1]=r[t+1],de[2]=r[t+2],de[3]=r[t+3],Lo[0]}var Po=new Float64Array([-0]),ht=new Uint8Array(Po.buffer);function ea(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 ra(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 Sl=BigInt(Number.MAX_SAFE_INTEGER),Il=BigInt(Number.MIN_SAFE_INTEGER),_t=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<Sl&&t>Il)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>na&&(o=0n,++n>na&&(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 _t(0,0);Ie.toBigInt=function(){return 0n};Ie.zzEncode=Ie.zzDecode=function(){return this};Ie.length=function(){return 1};var na=4294967296n;function oa(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 sa(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 Ot(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Qr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Co=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,Ot(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 Ot(this,4);return Qr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ot(this,4);return Qr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ot(this,4);let t=ta(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Ot(this,4);let t=ra(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 Ot(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return sa(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Ot(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Ot(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 _t(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 Ot(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 Ot(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 Ot(this,8);let t=Qr(this.buf,this.pos+=4),e=Qr(this.buf,this.pos+=4);return new _t(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=Bo(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 Ro(r){return new Co(r instanceof Uint8Array?r:r.subarray())}function bt(r,t,e){let n=Ro(r);return t.decode(n,void 0,e)}function ko(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 Ko(){}var Uo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Bl=ko();function Tl(r){return globalThis.Buffer!=null?St(r):Bl(r)}var yr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Be(Ko,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 No((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,_t.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=_t.fromBigInt(t);return this._push(Jr,e.length(),e)}uint64Number(t){return this._push(Io,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=_t.fromBigInt(t).zzEncode();return this._push(Jr,e.length(),e)}sint64Number(t){let e=_t.fromNumber(t).zzEncode();return this._push(Jr,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(mr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=_t.fromBigInt(t);return this._push(mr,4,e.lo)._push(mr,4,e.hi)}fixed64Number(t){let e=_t.fromNumber(t);return this._push(mr,4,e.lo)._push(mr,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(ea,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Do,1,0):this.uint32(e)._push(Pl,e,t)}string(t){let e=oa(t);return e!==0?this.uint32(e)._push(_o,e,t):this._push(Do,1,0)}fork(){return this.states=new Uo(this),this.head=this.tail=new Be(Ko,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(Ko,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=Tl(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 Ll(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var No=class extends Be{next;constructor(t,e){super(Ll,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 mr(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 Pl(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(yr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(_l,t,r),this},yr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Cl,t,r),this});function _l(r,t,e){t.set(r,e)}function Cl(r,t,e){r.length<40?_o(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(G(r),e)}function Oo(){return new yr}function wt(r,t){let e=Oo();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var ze;(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"})(ze||(ze={}));function tn(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Mo(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 tn("enum",ze.VARINT,e,n)}function xt(r,t){return tn("message",ze.LENGTH_DELIMITED,r,t)}var Te=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"},gr=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 qo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(qo||(qo={}));(function(r){r.codec=()=>Mo(qo)})(rt||(rt={}));var zt;(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)})(zt||(zt={}));var Ho;(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)})(Ho||(Ho={}));var br=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},en=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var ca={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new en("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 he=ca;var xr={};At(xr,{MAX_RSA_KEY_SIZE:()=>Vo,generateRSAKeyPair:()=>da,jwkToJWKKeyPair:()=>ha,jwkToPkcs1:()=>Dl,jwkToPkix:()=>Go,jwkToRSAPrivateKey:()=>jo,pkcs1MessageToJwk:()=>Fo,pkcs1MessageToRSAPrivateKey:()=>$o,pkcs1ToJwk:()=>Kl,pkcs1ToRSAPrivateKey:()=>fa,pkixMessageToJwk:()=>Wo,pkixMessageToRSAPublicKey:()=>Yo,pkixToJwk:()=>Ul,pkixToRSAPublicKey:()=>Zo});var rn=Wr;var Fe=class{type="RSA";jwk;_raw;_multihash;constructor(t,e){this.jwk=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=xr.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,n){return la(this.jwk,e,t,n)}},wr=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=xr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:j(this.raw,t.raw)}sign(t,e){return ua(this.jwk,t,e)}};var Vo=8192,zo=18,Rl=1062,kl=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Kl(r){let t=Zt(r);return Fo(t)}function Fo(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 Dl(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new H("JWK was missing components");return ie([It(Uint8Array.from([0])),It(G(r.n,"base64url")),It(G(r.e,"base64url")),It(G(r.d,"base64url")),It(G(r.p,"base64url")),It(G(r.q,"base64url")),It(G(r.dp,"base64url")),It(G(r.dq,"base64url")),It(G(r.qi,"base64url"))]).subarray()}function Ul(r){let t=Zt(r,{offset:0});return Wo(t)}function Wo(r){let t=Zt(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 ie([kl,Mr(ie([It(G(r.n,"base64url")),It(G(r.e,"base64url"))]))]).subarray()}function fa(r){let t=Zt(r);return $o(t)}function $o(r){let t=Fo(r);return jo(t)}function Zo(r,t){if(r.byteLength>=Rl)throw new Ce("Key size is too large");let e=Zt(r,{offset:0});return Yo(e,r,t)}function Yo(r,t,e){let n=Wo(r);if(e==null){let o=rn(zt.encode({Type:rt.RSA,Data:t}));e=Dt(zo,o)}return new Fe(n,e)}function jo(r){if(ma(r)>Vo)throw new H("Key size is too large");let t=ha(r),e=rn(zt.encode({Type:rt.RSA,Data:Go(t.publicKey)})),n=Dt(zo,e);return new wr(t.privateKey,new Fe(t.publicKey,n))}async function da(r){if(r>Vo)throw new H("Key size is too large");let t=await pa(r),e=rn(zt.encode({Type:rt.RSA,Data:Go(t.publicKey)})),n=Dt(zo,e);return new wr(t.privateKey,new Fe(t.publicKey,n))}function ha(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 pa(r,t){let e=await he.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 ua(r,t,e){let n=await he.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);e?.signal?.throwIfAborted();let o=await he.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 la(r,t,e,n){let o=await he.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await he.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 H("Private and public key are required");let e=await Promise.all([he.get().subtle.exportKey("jwk",r.privateKey),he.get().subtle.exportKey("jwk",r.publicKey)]);return t?.signal?.throwIfAborted(),e}function ma(r){if(r.kty!=="RSA")throw new H("invalid key type");if(r.n==null)throw new H("invalid key modulus");return G(r.n,"base64url").length*8}var nn=class extends Ne{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,di(t);let n=cr(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),Yt(s)}update(t){return Oe(this),this.iHash.update(t),this}digestInto(t){Oe(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()}},Xo=(r,t,e)=>new nn(r,t).update(e).digest();Xo.create=(r,t)=>new nn(r,t);function ya(r){r.lowS!==void 0&&qt("lowS",r.lowS),r.prehash!==void 0&&qt("prehash",r.prehash)}function Ol(r){let t=pr(r);Jt(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 ts=class extends Error{constructor(t=""){super(t)}},ee={Err:ts,_tlv:{encode:(r,t)=>{let{Err:e}=ee;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=dr(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?dr(o.length/2|128):"";return dr(r)+s+o+t},decode(r,t){let{Err:e}=ee,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let l=t.subarray(n,n+c);if(l.length!==c)throw new e("tlv.decode: length bytes not complete");if(l[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let u of l)i=i<<8|u;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=ee;if(r<re)throw new t("integer: negative integers are not allowed");let e=dr(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}=ee;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 Qt(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=ee,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:l,l:u}=n.decode(2,c);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(l)}},hexFromSig(r){let{_tlv:t,_int:e}=ee,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 Qo(r,t){return le(Ee(r,t))}var re=BigInt(0),ct=BigInt(1),p0=BigInt(2),Jo=BigInt(3),Ml=BigInt(4);function ql(r){let t=Ol(r),{Fp:e}=t,n=te(t.n,t.nBitLength),o=t.toBytes||((S,d,b)=>{let I=d.toAffine();return fe(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,Jo),Ml),l=e.mul(e.sqr(t.b),BigInt(27));if(e.is0(e.add(c,l)))throw new Error("bad curve params: a or b");function u(S){return Gr(S,ct,t.n)}function f(S){let{allowedPrivateKeyLengths:d,nByteLength:b,wrapPrivateKey:I,n:B}=t;if(d&&typeof S!="bigint"){if(Me(S)&&(S=le(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:Qt(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)),Pt("private key",T,ct,B),T}function p(S){if(!(S instanceof g))throw new Error("ProjectivePoint expected")}let y=He((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 R=e.mul(b,d),O=e.mul(I,d),P=e.mul(B,d);if(T)return{x:e.ZERO,y:e.ZERO};if(!e.eql(P,e.ONE))throw new Error("invZ was invalid");return{x:R,y:O}}),A=He(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=Ve(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(f(d))}static msm(d,b){return Yr(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:R,pz:O}=d,P=e.eql(e.mul(b,O),e.mul(T,B)),D=e.eql(e.mul(I,O),e.mul(R,B));return P&&D}negate(){return new g(this.px,e.neg(this.py),this.pz)}double(){let{a:d,b}=t,I=e.mul(b,Jo),{px:B,py:T,pz:R}=this,O=e.ZERO,P=e.ZERO,D=e.ZERO,C=e.mul(B,B),nt=e.mul(T,T),E=e.mul(R,R),x=e.mul(B,T);return x=e.add(x,x),D=e.mul(B,R),D=e.add(D,D),O=e.mul(d,D),P=e.mul(I,E),P=e.add(O,P),O=e.sub(nt,P),P=e.add(nt,P),P=e.mul(O,P),O=e.mul(x,O),D=e.mul(I,D),E=e.mul(d,E),x=e.sub(C,E),x=e.mul(d,x),x=e.add(x,D),D=e.add(C,C),C=e.add(D,C),C=e.add(C,E),C=e.mul(C,x),P=e.add(P,C),E=e.mul(T,R),E=e.add(E,E),C=e.mul(E,x),O=e.sub(O,C),D=e.mul(E,nt),D=e.add(D,D),D=e.add(D,D),new g(O,P,D)}add(d){p(d);let{px:b,py:I,pz:B}=this,{px:T,py:R,pz:O}=d,P=e.ZERO,D=e.ZERO,C=e.ZERO,nt=t.a,E=e.mul(t.b,Jo),x=e.mul(b,T),L=e.mul(I,R),w=e.mul(B,O),h=e.add(b,I),m=e.add(T,R);h=e.mul(h,m),m=e.add(x,L),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),P=e.add(R,O),v=e.mul(v,P),P=e.add(L,w),v=e.sub(v,P),C=e.mul(nt,m),P=e.mul(E,w),C=e.add(P,C),P=e.sub(L,C),C=e.add(L,C),D=e.mul(P,C),L=e.add(x,x),L=e.add(L,x),w=e.mul(nt,w),m=e.mul(E,m),L=e.add(L,w),w=e.sub(x,w),w=e.mul(nt,w),m=e.add(m,w),x=e.mul(L,m),D=e.add(D,x),x=e.mul(v,m),P=e.mul(h,P),P=e.sub(P,x),x=e.mul(h,L),C=e.mul(v,C),C=e.add(C,x),new g(P,D,C)}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;Pt("scalar",d,re,I);let B=g.ZERO;if(d===re)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:R,k2neg:O,k2:P}=b.splitScalar(d),D=B,C=B,nt=this;for(;R>re||P>re;)R&ct&&(D=D.add(nt)),P&ct&&(C=C.add(nt)),nt=nt.double(),R>>=ct,P>>=ct;return T&&(D=D.negate()),O&&(C=C.negate()),C=new g(e.mul(C.px,b.beta),C.py,C.pz),D.add(C)}multiply(d){let{endo:b,n:I}=t;Pt("scalar",d,ct,I);let B,T;if(b){let{k1neg:R,k1:O,k2neg:P,k2:D}=b.splitScalar(d),{p:C,f:nt}=this.wNAF(O),{p:E,f:x}=this.wNAF(D);C=F.constTimeNegate(R,C),E=F.constTimeNegate(P,E),E=new g(e.mul(E.px,b.beta),E.py,E.pz),B=C.add(E),T=nt.add(x)}else{let{p:R,f:O}=this.wNAF(d);B=R,T=O}return g.normalizeZ([B,T])[0]}multiplyAndAddUnsafe(d,b,I){let B=g.BASE,T=(O,P)=>P===re||P===ct||!O.equals(B)?O.multiplyUnsafe(P):O.multiply(P),R=T(this,b).add(T(d,I));return R.is0()?void 0:R}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 qt("isCompressed",d),this.assertValidity(),o(g,this,d)}toHex(d=!0){return qt("isCompressed",d),le(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:k,nBitLength:K}=t,F=Zr(g,k?Math.ceil(K/2):K);return{CURVE:t,ProjectivePoint:g,normPrivateKeyToScalar:f,weierstrassEquation:i,isWithinCurveOrder:u}}function Hl(r){let t=pr(r);return Jt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function ga(r){let t=Hl(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 l(E){return $r(E,n)}let{ProjectivePoint:u,normPrivateKeyToScalar:f,weierstrassEquation:p,isWithinCurveOrder:y}=ql({...t,toBytes(E,x,L){let w=x.toAffine(),h=e.toBytes(w.x),m=fe;return qt("isCompressed",L),L?m(Uint8Array.from([x.hasEvenY()?2:3]),h):m(Uint8Array.from([4]),h,e.toBytes(w.y))},fromBytes(E){let x=E.length,L=E[0],w=E.subarray(1);if(x===i&&(L===2||L===3)){let h=Qt(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 _=(v&ct)===ct;return(L&1)===1!==_&&(v=e.neg(v)),{x:h,y:v}}else if(x===a&&L===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 k=(E,x,L)=>Qt(E.slice(x,L));class K{constructor(x,L,w){Pt("r",x,ct,n),Pt("s",L,ct,n),this.r=x,this.s=L,w!=null&&(this.recovery=w),Object.freeze(this)}static fromCompact(x){let L=o;return x=X("compactSignature",x,L*2),new K(k(x,0,L),k(x,L,2*L))}static fromDER(x){let{r:L,s:w}=ee.toSig(X("DER",x));return new K(L,w)}assertValidity(){}addRecoveryBit(x){return new K(this.r,this.s,x)}recoverPublicKey(x){let{r:L,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?L+t.n:L;if(v>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let _=(h&1)===0?"02":"03",U=u.fromHex(_+Qo(v,e.BYTES)),M=l(v),q=c(-m*M),V=c(w*M),W=u.BASE.multiplyAndAddUnsafe(U,q,V);if(!W)throw new Error("point at infinify");return W.assertValidity(),W}hasHighS(){return A(this.s)}normalizeS(){return this.hasHighS()?new K(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return hr(this.toDERHex())}toDERHex(){return ee.hexFromSig(this)}toCompactRawBytes(){return hr(this.toCompactHex())}toCompactHex(){let x=o;return Qo(this.r,x)+Qo(this.s,x)}}let F={isValidPrivateKey(E){try{return f(E),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let E=fo(t.n);return qi(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 L=X("key",E).length,w=e.BYTES,h=w+1,m=2*w+1;if(!(t.allowedPrivateKeyLengths||o===h))return L===h||L===m}function b(E,x,L=!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(f(E)).toRawBytes(L)}let I=t.bits2int||function(E){if(E.length>8192)throw new Error("input is too large");let x=Qt(E),L=E.length*8-s;return L>0?x>>BigInt(L):x},B=t.bits2int_modN||function(E){return c(I(E))},T=ve(s);function R(E){return Pt("num < 2^"+s,E,re,T),Ee(E,o)}function O(E,x,L=P){if(["recovered","canonical"].some(et=>et in L))throw new Error("sign() legacy options not supported");let{hash:w,randomBytes:h}=t,{lowS:m,prehash:v,extraEntropy:_}=L;m==null&&(m=!0),E=X("msgHash",E),ya(L),v&&(E=X("prehashed msgHash",w(E)));let U=B(E),M=f(x),q=[R(M),R(U)];if(_!=null&&_!==!1){let et=_===!0?h(e.BYTES):_;q.push(X("extraEntropy",et))}let V=fe(...q),W=U;function ot(et){let ut=I(et);if(!y(ut))return;let vt=l(ut),it=u.BASE.multiply(ut).toAffine(),ft=c(it.x);if(ft===re)return;let Tt=c(vt*c(W+ft*M));if(Tt===re)return;let kt=(it.x===ft?0:2)|Number(it.y&ct),Qe=Tt;return m&&A(Tt)&&(Qe=g(Tt),kt^=1),new K(ft,Qe,kt)}return{seed:V,k2sig:ot}}let P={lowS:t.lowS,prehash:!1},D={lowS:t.lowS,prehash:!1};function C(E,x,L=P){let{seed:w,k2sig:h}=O(E,x,L),m=t;return Ri(m.hash.outputLen,m.nByteLength,m.hmac)(w,h)}u.BASE._setWindowSize(8);function nt(E,x,L,w=D){let h=E;x=X("msgHash",x),L=X("publicKey",L);let{lowS:m,prehash:v,format:_}=w;if(ya(w),"strict"in w)throw new Error("options.strict was renamed to lowS");if(_!==void 0&&_!=="compact"&&_!=="der")throw new Error("format must be compact or der");let U=typeof h=="string"||Me(h),M=!U&&!_&&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 K(h.r,h.s)),U){try{_!=="compact"&&(q=K.fromDER(h))}catch(kt){if(!(kt instanceof ee.Err))throw kt}!q&&_!=="der"&&(q=K.fromCompact(h))}V=u.fromHex(L)}catch{return!1}if(!q||m&&q.hasHighS())return!1;v&&(x=t.hash(x));let{r:W,s:ot}=q,et=B(x),ut=l(ot),vt=c(et*ut),it=c(W*ut),ft=u.BASE.multiplyAndAddUnsafe(V,vt,it)?.toAffine();return ft?c(ft.x)===W:!1}return{CURVE:t,getPublicKey:S,getSharedSecret:b,sign:C,verify:nt,ProjectivePoint:u,Signature:K,utils:F}}function Vl(r){return{hash:r,hmac:(t,...e)=>Xo(r,t,Jn(...e)),randomBytes:Vr}}function ba(r,t){let e=n=>ga({...r,...Vl(n)});return{...e(t),create:e}}var Ea=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),wa=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),zl=BigInt(0),Fl=BigInt(1),es=BigInt(2),xa=(r,t)=>(r+t/es)/t;function Wl(r){let t=Ea,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),l=r*r*r%t,u=l*l*r%t,f=Q(u,e,t)*u%t,p=Q(f,e,t)*u%t,y=Q(p,es,t)*l%t,A=Q(y,o,t)*y%t,g=Q(A,s,t)*A%t,k=Q(g,a,t)*g%t,K=Q(k,c,t)*k%t,F=Q(K,a,t)*g%t,S=Q(F,e,t)*u%t,d=Q(S,i,t)*A%t,b=Q(d,n,t)*l%t,I=Q(b,es,t);if(!rs.eql(rs.sqr(I),r))throw new Error("Cannot find square root");return I}var rs=te(Ea,void 0,void 0,{sqrt:Wl}),We=ba({a:zl,b:BigInt(7),Fp:rs,n:wa,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=wa,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Fl*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),a=xa(s*r,t),c=xa(-n*r,t),l=$(r-a*e-c*o,t),u=$(-a*n-c*s,t),f=l>i,p=u>i;if(f&&(l=t-l),p&&(u=t-u),l>i||u>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:l,k2neg:p,k2:u}}}},Wr);function va(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Aa(r,t,e,n){let o=or.digest(e instanceof Uint8Array?e:e.subarray());if(va(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),We.verify(t,s,r))).catch(s=>{throw s.name==="AbortError"?s:new br(String(s))});try{return n?.signal?.throwIfAborted(),We.verify(t,o.digest,r)}catch(s){throw new br(String(s))}}var on=class{type="secp256k1";raw;_key;constructor(t){this._key=Ia(t),this.raw=Sa(this._key)}toMultihash(){return Ut.digest(Ct(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,n){return Aa(this._key,e,t,n)}};function ns(r){return new on(r)}function Sa(r){return We.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Ia(r){try{return We.ProjectivePoint.fromHex(r),r}catch(t){throw new Ce(String(t))}}function sn(r,t){let{Type:e,Data:n}=zt.decode(r),o=n??new Uint8Array;switch(e){case rt.RSA:return Zo(o,t);case rt.Ed25519:return xo(o);case rt.secp256k1:return ns(o);case rt.ECDSA:return Qn(o);default:throw new me}}function Ba(r){let{Type:t,Data:e}=zt.decode(r.digest),n=e??new Uint8Array;switch(t){case rt.Ed25519:return xo(n);case rt.secp256k1:return ns(n);case rt.ECDSA:return Qn(n);default:throw new me}}function Ct(r){return zt.encode({Type:rt[r.type],Data:r.raw})}var Ta=Symbol.for("nodejs.util.inspect.custom"),Gl=114,Er=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()})`}[kr]=!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(Gl,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")}[Ta](){return`PeerId(${this.toString()})`}},vr=class extends Er{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Ar=class extends Er{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Sr=class extends Er{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},$l=2336,Ir=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Ut.digest(G(this.url))}[Ta](){return`PeerId(${this.url})`}[kr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return tt.createV1($l,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 Pa(r){if(r.type==="Ed25519")return new Ar({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new Sr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new vr({multihash:r.toCID().multihash,publicKey:r});throw new me}function os(r){if(jl(r))return new vr({multihash:r});if(Yl(r))try{let t=Ba(r);if(t.type==="Ed25519")return new Ar({multihash:r,publicKey:t});if(t.type==="secp256k1")return new Sr({multihash:r,publicKey:t})}catch{let e=N(r.digest);return new Ir(new URL(e))}throw new Dr("Supplied PeerID Multihash is invalid")}function an(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==Zl&&r.code!==La)throw new Kr("Supplied PeerID CID is invalid");if(r.code===La){let t=N(r.multihash.digest);return new Ir(new URL(t))}return os(r.multihash)}function Yl(r){return r.code===Ut.code}function jl(r){return r.code===or.code}var Br;(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)})(Br||(Br={}));var cn=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var Ge=class r{static createFromProtobuf=t=>{let e=Br.decode(t),n=sn(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=_a(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 cn("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=Br.encode({publicKey:Ct(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,e){let n=_a(t,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,e)}},_a=(r,t,e)=>{let n=G(r),o=Vt(n.byteLength),s=Vt(t.length),i=Vt(e.length);return new mt(o,n,s,t,i,e)};function Ca(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 un=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",l=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let p=Number.parseInt(f,t);if(!Number.isNaN(p))return p});if(u===void 0)break;if(s*=t,s+=u,s>l||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];e[o]=s>>8,e[o+1]=s&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return e.set(s.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Ra=45,Xl=15,$e=new un;function ss(r){if(!(r.length>Xl))return $e.new(r).parseWith(()=>$e.readIPv4Addr())}function is(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Ra))return $e.new(r).parseWith(()=>$e.readIPv6Addr())}function ln(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>Ra)return;let e=$e.new(r).parseWith(()=>$e.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 Zm=parseInt("0xFFFF",16),Ym=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Da(r){return!!ss(r)}function Ua(r){return!!is(r)}function fn(r){return!!ln(r)}var Na=Da,rf=Ua,as=function(r){let t=0;if(r=r.toString().trim(),Na(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(rf(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=Na(e[n]),i;s&&(i=as(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 Ze={},cs={},of=[[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"]];of.forEach(r=>{let t=sf(...r);cs[t.code]=t,Ze[t.name]=t});function sf(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function Y(r){if(typeof r=="number"){if(cs[r]!=null)return cs[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Ze[r]!=null)return Ze[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Ry=Y("ip4"),ky=Y("ip6"),Ky=Y("ipcidr");function ds(r,t){switch(Y(r).code){case 4:case 41:return cf(t);case 42:return fs(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 fs(t);case 421:return df(t);case 444:return qa(t);case 445:return qa(t);case 466:return ff(t);case 481:return globalThis.encodeURIComponent(fs(t));default:return N(t,"base16")}}function hs(r,t){switch(Y(r).code){case 4:return Ma(t);case 41:return Ma(t);case 42:return ls(t);case 43:return G(t,"base10");case 6:case 273:case 33:case 132:return ps(parseInt(t,10));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 hf(t);case 445:return pf(t);case 466:return lf(t);case 481:return ls(globalThis.decodeURIComponent(t));default:return G(t,"base16")}}var us=Object.values(sr).map(r=>r.decoder),af=function(){let r=us[0].or(us[1]);return us.slice(2).forEach(t=>r=r.or(t)),r}();function Ma(r){if(!fn(r))throw new Error("invalid ip address");return as(r)}function cf(r){let t=Oa(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!fn(t))throw new Error("invalid ip address");return t}function ps(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 ls(r){let t=G(r),e=Uint8Array.from(Vt(t.length));return Lt([e,t],e.length+t.length)}function fs(r){let t=Se(r);if(r=r.slice(Bt(t)),r.length!==t)throw new Error("inconsistent lengths");return N(r)}function uf(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(Vt(t.length));return Lt([e,t],e.length+t.length)}function lf(r){let t=af.decode(r),e=Uint8Array.from(Vt(t.length));return Lt([e,t],e.length+t.length)}function ff(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 df(r){let t=Se(r),e=r.slice(Bt(t));if(e.length!==t)throw new Error("inconsistent lengths");return N(e,"base58btc")}function hf(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=Kt.decode("b"+t[0]),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ps(n);return Lt([e,o],e.length+o.length)}function pf(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=Kt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ps(n);return Lt([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 Va(r){r=ms(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 dn("invalid address: "+r);if(a.path===!0){n=ms(o.slice(s).join("/")),t.push([a.code,hs(a.code,n)]),e.push([a.code,n]);break}let c=hs(a.code,o[s]);t.push([a.code,c]),e.push([a.code,ds(a.code,c)])}return{string:za(e),bytes:hn(t),tuples:t,stringTuples:e,path:n}}function ys(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let s=Se(r,o),i=Bt(s),a=Y(s),c=mf(a,r.slice(o+i));if(c===0){t.push([s]),e.push([s]),o+=i;continue}let l=r.slice(o+i,o+i+c);if(o+=c+i,o>r.length)throw new dn("Invalid address Uint8Array: "+N(r,"base16"));t.push([s,l]);let u=ds(s,l);if(e.push([s,u]),a.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:za(e),tuples:t,stringTuples:e,path:n}}function za(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}),ms(t.join("/"))}function hn(r){return Lt(r.map(t=>{let e=Y(t[0]),n=Uint8Array.from(Vt(e.code));return t.length>1&&t[1]!=null&&(n=Lt([n,t[1]])),n}))}function mf(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 ms(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}var dn=class extends Error{static name="ParseError";name="ParseError";constructor(t){super(`Error parsing address: ${t}`)}};var yf=Symbol.for("nodejs.util.inspect.custom"),bs=Symbol.for("@multiformats/js-multiaddr/multiaddr"),gf=[Y("dns").code,Y("dns4").code,Y("dns6").code,Y("dnsaddr").code],gs=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},pn=class r{bytes;#t;#e;#r;#a;[bs]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=ys(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Va(t)}else if(mn(t))e=ys(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"),l=Y("ip6"),u=Y("dns6"),f=Y("ip6zone");for(let[y,A]of this.stringTuples())y===f.code&&(s=`%${A??""}`),gf.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===l.code)&&(e=Y(y).name==="tcp"?"tcp":"udp",n=`${A??""}${s}`,t=y===l.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(hn(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===Ze.p2p.code&&t.push([n,o]),n===Ze["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=Fa.get(e.name);if(n==null)throw new gs(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>Ft(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)}[yf](){return`Multiaddr(${this.#t})`}};var Fa=new Map;function mn(r){return!!r?.[bs]}function Ft(r){return new pn(r)}var Wa="libp2p-peer-record",Ga=Uint8Array.from([3,1]);var Tr;(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)},l=i==null?s.len:s.pos+i;for(;s.pos<l;){let u=s.uint32();switch(u>>>3){case 1:{c.multiaddr=s.bytes();break}default:{s.skipType(u&7);break}}}return c})),o),n.encode=s=>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)})(Tr||(Tr={}));var Le=class r{static createFromProtobuf=t=>{let e=Tr.decode(t),n=os(Gt(e.peerId)),o=(e.addresses??[]).map(i=>Ft(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=Tr.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||!Ca(this.multiaddrs,t.multiaddrs))}};function bf(r){return r[Symbol.asyncIterator]!=null}function wf(r){if(bf(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=wf;var Ye=class extends Error{static name="AbortError";name="AbortError";constructor(t="The operation was aborted",...e){super(t,...e)}};var xs=vc(Ya(),1);var Pr=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},Es=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},ja=r=>globalThis.DOMException===void 0?new Es(r):new DOMException(r),Xa=r=>{let t=r.reason===void 0?ja("This operation was aborted."):r.reason;return t instanceof Error?t:ja(t)};function vs(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,a,l=new Promise((u,f)=>{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&&f(Xa(y)),a=()=>{f(Xa(y))},y.addEventListener("abort",a,{once:!0})}if(e===Number.POSITIVE_INFINITY){r.then(u,f);return}let p=new Pr;i=s.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(y){f(y)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?u():o instanceof Error?f(o):(p.message=o??`Promise timed out after ${e} milliseconds`,f(p))},e),(async()=>{try{u(await r)}catch(y){f(y)}})()}).finally(()=>{l.clear(),a&&t.signal&&t.signal.removeEventListener("abort",a)});return l.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},l}function As(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=As(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 je=class extends xs.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=vs(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 Pr&&!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 pe={},Xe=r=>{r.addEventListener("message",t=>{Xe.dispatchEvent("message",r,t)}),r.port!=null&&r.port.addEventListener("message",t=>{Xe.dispatchEvent("message",r,t)})};Xe.addEventListener=(r,t)=>{pe[r]==null&&(pe[r]=[]),pe[r].push(t)};Xe.removeEventListener=(r,t)=>{pe[r]!=null&&(pe[r]=pe[r].filter(e=>e===t))};Xe.dispatchEvent=function(r,t,e){pe[r]!=null&&pe[r].forEach(n=>n(t,e))};var Ss=Xe;var Is="lock:worker:request-read",Bs="lock:worker:abort-read-request",Ts="lock:worker:release-read",Ls="lock:master:grant-read",Ps="lock:worker:request-write",_s="lock:worker:abort-write-request",Cs="lock:worker:release-write",Rs="lock:master:grant-write";var Qa=(r=10)=>Math.random().toString().substring(2,r+2);var Ja=(r,t,e,n,o,s,i)=>(a,c)=>{if(c.data==null)return;let l={type:c.data.type,name:c.data.name,identifier:c.data.identifier};c.data.type===n&&r.dispatchEvent(new MessageEvent(t,{data:{name:l.name,handler:async()=>{a.postMessage({type:i,name:l.name,identifier:l.identifier}),await new Promise(u=>{let f=p=>{if(p?.data==null)return;let y={type:p.data.type,name:p.data.name,identifier:p.data.identifier};y.type===s&&y.identifier===l.identifier&&(a.removeEventListener("message",f),u())};a.addEventListener("message",f)})}}})),l.type===o&&(a.postMessage({type:o,name:l.name,identifier:l.identifier}),r.dispatchEvent(new MessageEvent(e,{data:{name:l.name}})))},tc=(r,t,e,n,o)=>async s=>{s?.signal?.throwIfAborted();let i=Qa();return globalThis.postMessage({type:t,identifier:i,name:r}),new Promise((a,c)=>{let l=()=>{process.send?.({type:e,identifier:i,name:r}),c(new Ye)};s?.signal?.addEventListener("abort",l,{once:!0});let u=f=>{if(f?.data==null)return;let p={type:f.data.type,identifier:f.data.identifier};p.type===n&&p.identifier===i&&(globalThis.removeEventListener("message",u),s?.signal?.removeEventListener("abort",l),a(()=>{globalThis.postMessage({type:o,identifier:i,name:r})}))};globalThis.addEventListener("message",u)})},vf={singleProcess:!1},ec=r=>{if(r=Object.assign({},vf,r),!!globalThis.document||r.singleProcess){let e=new EventTarget;return Ss.addEventListener("message",Ja(e,"requestReadLock","abortReadLockRequest",Is,Bs,Ts,Ls)),Ss.addEventListener("message",Ja(e,"requestWriteLock","abortWriteLockRequest",Ps,_s,Cs,Rs)),e}return{isWorker:!0,readLock:e=>tc(e,Is,Bs,Ls,Ts),writeLock:e=>tc(e,Ps,_s,Rs,Cs)}};var Pe={},Rt;async function ks(r,t){let e,n,o=new Promise((i,a)=>{e=i,n=a}),s=()=>{n(new Ye)};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 Af=(r,t)=>{if(Rt.isWorker===!0)return{readLock:Rt.readLock(r,t),writeLock:Rt.writeLock(r,t)};let e=new je({concurrency:1}),n;return{async readLock(o){if(n!=null)return ks(n,o);n=new je({concurrency:t.concurrency,autoStart:!1});let s=n,i=ks(n,o);return e.add(async()=>{s.start(),await s.onIdle().then(()=>{n===s&&(n=null)})}),i},async writeLock(o){return n=null,ks(e,o)}}},Sf={name:"lock",concurrency:1/0,singleProcess:!1};function Ks(r){let t=Object.assign({},Sf,r);return Rt==null&&(Rt=ec(t),Rt.isWorker!==!0&&(Rt.addEventListener("requestReadLock",e=>{let n=e.data.name;if(Pe[n]==null)return;let o=new AbortController,s=i=>{i.data.name===n&&o.abort()};Rt.addEventListener("abortReadLockRequest",s),Pe[n].readLock({signal:o.signal}).then(async i=>e.data.handler().finally(()=>{i()})).finally(()=>{Rt.removeEventListener("abortReadLockRequest",s)})}),Rt.addEventListener("requestWriteLock",async e=>{let n=e.data.name;if(Pe[n]==null)return;let o=new AbortController,s=i=>{i.data.name===n&&o.abort()};Rt.addEventListener("abortWriteLockRequest",s),Pe[e.data.name].writeLock({signal:o.signal}).then(async i=>e.data.handler().finally(()=>{i()})).finally(()=>{Rt.removeEventListener("abortWriteLockRequest",s)})}))),Pe[t.name]==null&&(Pe[t.name]=Af(t.name,t)),Pe[t.name]}var ne;(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 l={key:"",value:st(0)},u=a==null?i.len:i.pos+a;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{l.key=i.string();break}case 2:{l.value=i.bytes();break}default:{i.skipType(f&7);break}}}return l})),s),o.encode=i=>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),bn.codec().encode(i.value,a)),c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let l={key:""},u=a==null?i.len:i.pos+a;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{l.key=i.string();break}case 2:{l.value=bn.codec().decode(i,i.uint32(),{limits:c.limits?.value});break}default:{i.skipType(f&7);break}}}return l})),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),gn.codec().encode(a,s);if(o.protocols!=null)for(let a of o.protocols)s.uint32(18),s.string(a);if(o.publicKey!=null&&(s.uint32(34),s.bytes(o.publicKey)),o.peerRecordEnvelope!=null&&(s.uint32(42),s.bytes(o.peerRecordEnvelope)),o.metadata!=null&&o.metadata.size!==0)for(let[a,c]of o.metadata.entries())s.uint32(50),r.Peer$metadataEntry.codec().encode({key:a,value:c},s);if(o.tags!=null&&o.tags.size!==0)for(let[a,c]of o.tags.entries())s.uint32(58),r.Peer$tagsEntry.codec().encode({key:a,value:c},s);o.updated!=null&&(s.uint32(64),s.uint64Number(o.updated)),i.lengthDelimited!==!1&&s.ldelim()},(o,s,i={})=>{let a={addresses:[],protocols:[],metadata:new Map,tags:new Map},c=s==null?o.len:o.pos+s;for(;o.pos<c;){let l=o.uint32();switch(l>>>3){case 1:{if(i.limits?.addresses!=null&&a.addresses.length===i.limits.addresses)throw new Te('Decode error - map field "addresses" had too many elements');a.addresses.push(gn.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 gr('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 gr('Decode error - map field "tags" had too many elements');let u=r.Peer$tagsEntry.codec().decode(o,o.uint32(),{limits:{value:i.limits?.tags$value}});a.tags.set(u.key,u.value);break}case 8:{a.updated=o.uint64Number();break}default:{o.skipType(l&7);break}}}return a})),n),r.encode=o=>wt(o,r.codec()),r.decode=(o,s)=>bt(o,r.codec(),s)})(ne||(ne={}));var gn;(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)})(gn||(gn={}));var bn;(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)})(bn||(bn={}));function If(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=sn(t.publicKey,e);return Pa(n)}function wn(r,t,e){let n=ne.decode(t);return xn(r,n,e)}function xn(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:Ft(s),isCertified:i??!1})),metadata:t.metadata,peerRecordEnvelope:t.peerRecordEnvelope??void 0,tags:n}}function rc(r,t){return Bf(r.addresses,t.addresses)&&Tf(r.protocols,t.protocols)&&Lf(r.publicKey,t.publicKey)&&Pf(r.peerRecordEnvelope,t.peerRecordEnvelope)&&_f(r.metadata,t.metadata)&&Cf(r.tags,t.tags)}function Bf(r,t){return oc(r,t,(e,n)=>!(e.isCertified!==n.isCertified||!j(e.multiaddr,n.multiaddr)))}function Tf(r,t){return oc(r,t,(e,n)=>e===n)}function Lf(r,t){return nc(r,t)}function Pf(r,t){return nc(r,t)}function _f(r,t){return sc(r,t,(e,n)=>j(e,n))}function Cf(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?j(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 oe="/",ic=new TextEncoder().encode(oe),En=ic[0],vn=class r{_buf;constructor(t,e){if(typeof t=="string")this._buf=G(t);else if(t instanceof Uint8Array)this._buf=t;else throw new Error("Invalid key, should be String of Uint8Array");if(e==null&&(e=!0),e&&this.clean(),this._buf.byteLength===0||this._buf[0]!==En)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(oe))}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]!==En){let t=new Uint8Array(this._buf.byteLength+1);t.fill(En,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===En;)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(oe).slice(1)}type(){return Rf(this.baseNamespace())}name(){return kf(this.baseNamespace())}instance(t){return new r(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(oe)||(t+=oe),t+=this.type(),new r(t)}parent(){let t=this.list();return t.length===1?new r(oe):new r(t.slice(0,-1).join(oe))}child(t){return this.toString()===oe?t:t.toString()===oe?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 Rf(r){let t=r.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function kf(r){let t=r.split(":");return t[t.length-1]}function Kf(r){return[].concat(...r)}var Ds="/peers/";function Cr(r){if(!_e(r)||r.type==null)throw new H("Invalid PeerId");let t=r.toCID().toString();return new vn(`${Ds}${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=Ft(i.multiaddr)),!mn(i.multiaddr))throw new H("Multiaddr was invalid");if(!await t(r,i.multiaddr,o))continue;let a=i.isCertified??!1,c=i.multiaddr.toString(),l=s.get(c);l!=null?i.isCertified=l.isCertified||a:s.set(c,{multiaddr:i.multiaddr,isCertified:a})}return[...s.values()].sort((i,a)=>i.multiaddr.toString().localeCompare(a.multiaddr.toString())).map(({isCertified:i,multiaddr:a})=>{let c=a.getPeerId();return r.equals(c)&&(a=a.decapsulate(Ft(`/p2p/${r}`))),{isCertified:i,multiaddr:a.bytes}})}async function Sn(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,l=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=An(p,{validate:cc})}if(t.tags!=null){let p=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags);c=An(p,{validate:uc,map:lc})}t.peerRecordEnvelope!=null&&(l=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=An([...a.entries()],{validate:cc})}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=An([...y.entries()],{validate:uc,map:lc})}t.peerRecordEnvelope!=null&&(l=t.peerRecordEnvelope)}let u;o?.id.publicKey!=null?u=Ct(o.id.publicKey):t.publicKey!=null?u=Ct(t.publicKey):r.publicKey!=null&&(u=Ct(r.publicKey));let f={addresses:await ac(r,n.addressFilter??(async()=>!0),s,n.existingPeer?.peerPB.addresses,n),protocols:[...i.values()].sort((p,y)=>p.localeCompare(y)),metadata:a,tags:c,publicKey:u,peerRecordEnvelope:l};return f.addresses.forEach(p=>{p.observed=n.existingPeer?.peerPB.addresses?.find(y=>j(y.multiaddr,y.multiaddr))?.observed??Date.now()}),r.type!=="RSA"&&delete f.publicKey,f}function An(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 H("Metadata key must be a string");if(!(t instanceof Uint8Array))throw new H("Metadata value must be a Uint8Array")}function uc(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 lc(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 fc(r){let t=r.toString().split("/")[2],e=tt.parse(t,Kt);return an(e)}function Us(r,t,e){let n=fc(r);return wn(n,t,e)}function Df(r,t){return{prefix:Ds,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 In=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=Ks({name:"peer-store",singleProcess:!0}),this.maxAddressAge=e.maxAddressAge??36e5,this.maxPeerAge=e.maxPeerAge??216e5}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(Cr(t),e)}async load(t,e){let n=Cr(t),o=await this.datastore.get(n,e),s=ne.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,e),new Je;return xn(t,s,this.peerId.equals(t)?1/0:this.maxAddressAge)}async save(t,e,n){let o=await this.#t(t,n),s=await Sn(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 Sn(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 Sn(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=ne.decode(n);if(this.#r(o,s)){await this.datastore.delete(e,t);continue}yield xn(o,s,this.peerId.equals(o)?1/0:this.maxAddressAge)}}async#t(t,e){try{let n=Cr(t),o=await this.datastore.get(n,e),s=ne.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,e),new Je;return{peerPB:s,peer:wn(t,o,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=ne.encode(e);return await this.datastore.put(Cr(t),s,o),{peer:wn(t,s,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 Ns=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 In(t,e)}[Symbol.toStringTag]="@libp2p/peer-store";async forEach(t,e){let n=await this.store.lock.readLock(e);try{for await(let o of this.store.all(e))t(o)}finally{n()}}async all(t){let e=await this.store.lock.readLock(t);try{return await $a(this.store.all(t))}finally{e()}}async delete(t,e){let n=await this.store.lock.writeLock(e);try{await this.store.delete(t,e)}finally{n()}}async has(t,e){let n=await this.store.lock.readLock(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.lock.readLock(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.lock.writeLock(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.lock.writeLock(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.lock.writeLock(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=_e(e)?e:_e(e?.expectedPeer)?e.expectedPeer:void 0,s=_e(e)||e===void 0?n:e,i=await Ge.openAndCertify(t,Le.DOMAIN,s),a=an(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=Le.createFromProtobuf(i.payload),l;try{l=await this.get(a,s)}catch(u){if(u.name!=="NotFoundError")throw u}if(l?.peerRecordEnvelope!=null){let u=Ge.createFromProtobuf(l.peerRecordEnvelope),f=Le.createFromProtobuf(u.payload);if(f.seqNumber>=c.seqNumber)return this.log("sequence number was lower or equal to existing sequence number - stored: %d received: %d",f.seqNumber,c.seqNumber),!1}return await this.patch(c.peerId,{peerRecordEnvelope:t,addresses:c.multiaddrs.map(u=>({isCertified:!0,multiaddr:u}))},s),!0}#t(t,e){e.updated&&(this.peerId.equals(t)?this.events.safeDispatchEvent("self:peer:update",{detail:e}):this.events.safeDispatchEvent("peer:update",{detail:e}))}};function Uf(r,t={}){return new Ns(r,t)}return Ac(Nf);})();
2
+ "use strict";var Libp2PPeerStore=(()=>{var Hn=Object.defineProperty;var vc=Object.getOwnPropertyDescriptor;var Sc=Object.getOwnPropertyNames;var Ic=Object.prototype.hasOwnProperty;var Et=(r,t)=>{for(var e in t)Hn(r,e,{get:t[e],enumerable:!0})},Lc=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Sc(t))!Ic.call(r,o)&&o!==e&&Hn(r,o,{get:()=>t[o],enumerable:!(n=vc(t,o))||n.enumerable});return r};var Rc=r=>Lc(Hn({},"__esModule",{value:!0}),r);var Vf={};Et(Vf,{persistentPeerStore:()=>zf});var Tr=Symbol.for("@libp2p/peer-id");function Re(r){return!!r?.[Tr]}var z=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Be=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Ye=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var _r=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},Pr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var de=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Te=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={};Et(Gn,{base58btc:()=>$,base58flickr:()=>Kc});var jf=new Uint8Array(0);function js(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 $s(r){return new TextEncoder().encode(r)}function Ys(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),l=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function f(E){if(E instanceof Uint8Array||(ArrayBuffer.isView(E)?E=new Uint8Array(E.buffer,E.byteOffset,E.byteLength):Array.isArray(E)&&(E=Uint8Array.from(E))),!(E instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(E.length===0)return"";for(var y=0,I=0,_=0,q=E.length;_!==q&&E[_]===0;)_++,y++;for(var x=(q-_)*u+1>>>0,d=new Uint8Array(x);_!==q;){for(var b=E[_],L=0,R=x-1;(b!==0||L<I)&&R!==-1;R--,L++)b+=256*d[R]>>>0,d[R]=b%a>>>0,b=b/a>>>0;if(b!==0)throw new Error("Non-zero carry");I=L,_++}for(var B=x-I;B!==x&&d[B]===0;)B++;for(var K=c.repeat(y);B<x;++B)K+=r.charAt(d[B]);return K}function p(E){if(typeof E!="string")throw new TypeError("Expected String");if(E.length===0)return new Uint8Array;var y=0;if(E[y]!==" "){for(var I=0,_=0;E[y]===c;)I++,y++;for(var q=(E.length-y)*l+1>>>0,x=new Uint8Array(q);E[y];){var d=e[E.charCodeAt(y)];if(d===255)return;for(var b=0,L=q-1;(d!==0||b<_)&&L!==-1;L--,b++)d+=a*x[L]>>>0,x[L]=d%256>>>0,d=d/256>>>0;if(d!==0)throw new Error("Non-zero carry");_=b,y++}if(E[y]!==" "){for(var R=q-_;R!==q&&x[R]===0;)R++;for(var B=new Uint8Array(I+(q-R)),K=I;R!==q;)B[K++]=x[R++];return B}}}function g(E){var y=p(E);if(y)return y;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:p,decode:g}}var Tc=Bc,_c=Tc,Qs=_c;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")}},Vn=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 Js(this,t)}},Fn=class{decoders;constructor(t){this.decoders=t}or(t){return Js(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 Js(r,t){return new Fn({...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 Vn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function _e({name:r,prefix:t,encode:e,decode:n}){return new Wn(r,t,e,n)}function ne({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Qs(e,r);return _e({prefix:t,name:r,encode:n,decode:s=>Ft(o(s))})}function Pc(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let l=0;l<o;++l){let u=t[r[l]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|u,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function kc(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 Cc(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=Cc(n);return _e({prefix:t,name:r,encode(s){return kc(s,n,e)},decode(s){return Pc(s,o,e,r)}})}var $=ne({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Kc=ne({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Zn={};Et(Zn,{base32:()=>kt,base32hex:()=>Oc,base32hexpad:()=>qc,base32hexpadupper:()=>Hc,base32hexupper:()=>Mc,base32pad:()=>Uc,base32padupper:()=>Nc,base32upper:()=>Dc,base32z:()=>zc});var kt=J({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Dc=J({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Uc=J({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Nc=J({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Oc=J({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Mc=J({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),qc=J({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Hc=J({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),zc=J({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var jn={};Et(jn,{base36:()=>Xe,base36upper:()=>Vc});var Xe=ne({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Vc=ne({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Fc=ri,ti=128,Wc=127,Gc=~Wc,Zc=Math.pow(2,31);function ri(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Zc;)t[e++]=r&255|ti,r/=128;for(;r&Gc;)t[e++]=r&255|ti,r>>>=7;return t[e]=r|0,ri.bytes=e-n+1,t}var jc=$n,$c=128,ei=127;function $n(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw $n.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&ei)<<o:(i&ei)*Math.pow(2,o),o+=7}while(i>=$c);return $n.bytes=s-n,e}var Yc=Math.pow(2,7),Xc=Math.pow(2,14),Qc=Math.pow(2,21),Jc=Math.pow(2,28),tu=Math.pow(2,35),eu=Math.pow(2,42),ru=Math.pow(2,49),nu=Math.pow(2,56),ou=Math.pow(2,63),su=function(r){return r<Yc?1:r<Xc?2:r<Qc?3:r<Jc?4:r<tu?5:r<eu?6:r<ru?7:r<nu?8:r<ou?9:10},iu={encode:Fc,decode:jc,encodingLength:su},au=iu,Qe=au;function Je(r,t=0){return[Qe.decode(r,t),Qe.decode.bytes]}function Pe(r,t,e=0){return Qe.encode(r,t,e),t}function ke(r){return Qe.encodingLength(r)}function Ct(r,t){let e=t.byteLength,n=ke(r),o=n+ke(e),s=new Uint8Array(o+e);return Pe(r,s,0),Pe(e,s,n),s.set(t,o),new Ce(r,e,t,s)}function oe(r){let t=Ft(r),[e,n]=Je(t),[o,s]=Je(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ce(e,o,i,t)}function ni(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&js(r.bytes,e.bytes)}}var Ce=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function oi(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return uu(e,Yn(r),t??$.encoder);default:return lu(e,Yn(r),t??kt.encoder)}}var si=new WeakMap;function Yn(r){let t=si.get(r);if(t==null){let e=new Map;return si.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!==tr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==fu)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=Ct(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&&ni(t.multihash,n.multihash)}toString(t){return oi(this,t)}toJSON(){return{"/":oi(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??ii(n,o,s.bytes))}else if(e[du]===!0){let{version:n,multihash:o,code:s}=e,i=oe(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!==tr)throw new Error(`Version 0 CID must use dag-pb (code: ${tr}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=ii(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,tr,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 Ce(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[f,p]=Je(t.subarray(e));return e+=p,f},o=n(),s=tr;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),l=e+c,u=l-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:l}}static parse(t,e){let[n,o]=cu(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 cu(r,t){switch(r[0]){case"Q":{let e=t??$;return[$.prefix,e.decode(`${$.prefix}${r}`)]}case $.prefix:{let e=t??$;return[$.prefix,e.decode(r)]}case kt.prefix:{let e=t??kt;return[kt.prefix,e.decode(r)]}case Xe.prefix:{let e=t??Xe;return[Xe.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 uu(r,t,e){let{prefix:n}=e;if(n!==$.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function lu(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 tr=112,fu=18;function ii(r,t,e){let n=ke(r),o=n+ke(t),s=new Uint8Array(o+e.byteLength);return Pe(r,s,0),Pe(t,s,n),s.set(e,o),s}var du=Symbol.for("@ipld/js-cid/CID");var Xn={};Et(Xn,{identity:()=>Kt});var ai=0,hu="identity",ci=Ft;function pu(r){return Ct(ai,ci(r))}var Kt={code:ai,name:hu,encode:ci,digest:pu};function Y(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 At(r=0){return new Uint8Array(r)}function Lt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=At(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var li=Symbol.for("@achingbrain/uint8arraylist");function ui(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 Cr(r){return!!r?.[li]}var pt=class r{bufs;length;[li]=!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(Cr(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(Cr(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=ui(this.bufs,t);return e.buf[e.index]}set(t,e){let n=ui(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(Cr(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 Lt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Lt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let l=t>=a&&t<c,u=e>a&&e<=c;if(l&&u){if(t===a&&e===c){n.push(i);break}let f=t-a;n.push(i.subarray(f,f+(e-t)));break}if(l){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(u){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Cr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,l=n.byteLength-1,u;for(let f=e;f<=c;f+=u){u=0;for(let p=l;p>=0;p--){let g=this.get(f+p);if(n[p]!==g){u=Math.max(1,p-a[g]);break}}if(u===0)return f}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=At(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=At(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(!Y(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={};Et(Qn,{base10:()=>mu});var mu=ne({prefix:"9",name:"base10",alphabet:"0123456789"});var Jn={};Et(Jn,{base16:()=>yu,base16upper:()=>gu});var yu=J({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),gu=J({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var to={};Et(to,{base2:()=>bu});var bu=J({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var eo={};Et(eo,{base256emoji:()=>vu});var fi=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}"),wu=fi.reduce((r,t,e)=>(r[e]=t,r),[]),xu=fi.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Eu(r){return r.reduce((t,e)=>(t+=wu[e],t),"")}function Au(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=xu[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var vu=_e({prefix:"\u{1F680}",name:"base256emoji",encode:Eu,decode:Au});var ro={};Et(ro,{base64:()=>Su,base64pad:()=>Iu,base64url:()=>Lu,base64urlpad:()=>Ru});var Su=J({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Iu=J({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Lu=J({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ru=J({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var no={};Et(no,{base8:()=>Bu});var Bu=J({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var oo={};Et(oo,{identity:()=>Tu});var Tu=_e({prefix:"\0",name:"identity",encode:r=>Ys(r),decode:r=>$s(r)});var Pd=new TextEncoder,kd=new TextDecoder;var ao={};Et(ao,{sha256:()=>er,sha512:()=>ku});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?Ct(this.code,e):e.then(n=>Ct(this.code,n))}else throw Error("Unknown type, must be binary type")}};function hi(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var er=io({name:"sha2-256",code:18,encode:hi("SHA-256")}),ku=io({name:"sha2-512",code:19,encode:hi("SHA-512")});var rr={...oo,...to,...no,...Qn,...Jn,...Zn,...jn,...Gn,...ro,...eo},Fd={...ao,...Xn};function mi(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var pi=mi("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),co=mi("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=At(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Cu={utf8:pi,"utf-8":pi,hex:rr.base16,latin1:co,ascii:co,binary:co,...rr},Kr=Cu;function G(r,t="utf8"){let e=Kr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function N(r,t="utf8"){let e=Kr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Ku=parseInt("11111",2),uo=parseInt("10000000",2),Du=parseInt("01111111",2),yi={0:nr,1:nr,2:Uu,3:Mu,4:qu,5:Ou,6:Nu,16:nr,22:nr,48:nr};function Gt(r,t={offset:0}){let e=r[t.offset]&Ku;if(t.offset++,yi[e]!=null)return yi[e](r,t);throw new Error("No decoder for tag "+e)}function or(r,t){let e=0;if((r[t.offset]&uo)===uo){let n=r[t.offset]&Du,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 nr(r,t){or(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Gt(r,t);if(n===null)break;e.push(n)}return e}function Uu(r,t){let e=or(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 Nu(r,t){let e=or(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let l=r[t.offset];if(t.offset++,c.push(l&127),l<128){c.reverse();let u=0;for(let f=0;f<c.length;f++)u+=c[f]<<f*7;a+=`.${u}`,c=[]}}return a}function Ou(r,t){return t.offset++,null}function Mu(r,t){let e=or(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 qu(r,t){let e=or(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Hu(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new pt;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=Hu(r.byteLength);return new pt(Uint8Array.from([t.byteLength|uo]),t)}function vt(r){let t=new pt,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new pt(Uint8Array.from([2]),lo(t),t)}function Dr(r){let t=Uint8Array.from([0]),e=new pt(t,r);return new pt(Uint8Array.from([3]),lo(e),e)}function se(r,t=48){let e=new pt;for(let n of r)e.append(n);return new pt(Uint8Array.from([t]),lo(e),e)}async function gi(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 zu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Vu=Uint8Array.from([6,5,43,129,4,0,34]),Fu=Uint8Array.from([6,5,43,129,4,0,35]),Wu={ext:!0,kty:"EC",crv:"P-256"},Gu={ext:!0,kty:"EC",crv:"P-384"},Zu={ext:!0,kty:"EC",crv:"P-521"},fo=32,ho=48,po=66;function mo(r){let t=Gt(r);return bi(t)}function bi(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 Ke({...Wu,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 Ke({...Gu,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 Ke({...Zu,key_ops:["verify"],x:n,y:o});throw new z(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function wi(r){return se([vt(Uint8Array.from([1])),se([ju(r.crv)],160),se([Dr(new pt(Uint8Array.from([4]),G(r.x??"","base64url"),G(r.y??"","base64url")))],161)]).subarray()}function ju(r){if(r==="P-256")return zu;if(r==="P-384")return Vu;if(r==="P-521")return Fu;throw new z(`Invalid curve ${r}`)}var Ke=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=wi(this.jwk)),this._raw}toMultihash(){return Kt.digest(Tt(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return $.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Y(this.raw,t.raw)}async verify(t,e,n){return gi(this.jwk,e,t,n)}};var he=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function $u(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Ur(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function pe(r,...t){if(!$u(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 xi(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Ur(r.outputLen),Ur(r.blockLen)}function Ue(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function Ei(r,t){pe(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 Nr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Dt(r,t){return r<<32-t|r>>>t}function Ai(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function sr(r){return typeof r=="string"&&(r=Ai(r)),pe(r),r}function yo(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];pe(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 De=class{};function go(r){let t=n=>r().update(sr(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function Or(r=32){if(he&&typeof he.getRandomValues=="function")return he.getRandomValues(new Uint8Array(r));if(he&&typeof he.randomBytes=="function")return Uint8Array.from(he.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function Yu(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(e>>o&s),a=Number(e&s),c=n?4:0,l=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+l,a,n)}function vi(r,t,e){return r&t^~r&e}function Si(r,t,e){return r&t^r&e^t&e}var ir=class extends De{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=Nr(this.buffer)}update(t){Ue(this),t=sr(t),pe(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=Nr(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ue(this),Ei(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 f=i;f<o;f++)e[f]=0;Yu(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=Nr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=c/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<l;f++)a.setUint32(4*f,u[f],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},jt=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 Mr=BigInt(4294967295),Ii=BigInt(32);function Xu(r,t=!1){return t?{h:Number(r&Mr),l:Number(r>>Ii&Mr)}:{h:Number(r>>Ii&Mr)|0,l:Number(r&Mr)|0}}function Li(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}=Xu(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var bo=(r,t,e)=>r>>>e,wo=(r,t,e)=>r<<32-e|t>>>e,me=(r,t,e)=>r>>>e|t<<32-e,ye=(r,t,e)=>r<<32-e|t>>>e,ar=(r,t,e)=>r<<64-e|t>>>e-32,cr=(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 Ri=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Bi=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Ti=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),_i=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Pi=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),ki=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Ju=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),qr=class extends ir{constructor(t=32){super(64,t,8,!1),this.A=jt[0]|0,this.B=jt[1]|0,this.C=jt[2]|0,this.D=jt[3]|0,this.E=jt[4]|0,this.F=jt[5]|0,this.G=jt[6]|0,this.H=jt[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let f=0;f<16;f++,e+=4)ie[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let p=ie[f-15],g=ie[f-2],E=Dt(p,7)^Dt(p,18)^p>>>3,y=Dt(g,17)^Dt(g,19)^g>>>10;ie[f]=y+ie[f-7]+E+ie[f-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:l,H:u}=this;for(let f=0;f<64;f++){let p=Dt(a,6)^Dt(a,11)^Dt(a,25),g=u+p+vi(a,c,l)+Ju[f]+ie[f]|0,y=(Dt(n,2)^Dt(n,13)^Dt(n,22))+Si(n,o,s)|0;u=l,l=c,c=a,a=i+g|0,i=s,s=o,o=n,n=g+y|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,u=u+this.H|0,this.set(n,o,s,i,a,c,l,u)}roundClean(){Zt(ie)}destroy(){this.set(0,0,0,0,0,0,0,0),Zt(this.buffer)}};var Ci=Li(["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))),tl=Ci[0],el=Ci[1],ae=new Uint32Array(80),ce=new Uint32Array(80),xo=class extends ir{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:l,El:u,Fh:f,Fl:p,Gh:g,Gl:E,Hh:y,Hl:I}=this;return[t,e,n,o,s,i,a,c,l,u,f,p,g,E,y,I]}set(t,e,n,o,s,i,a,c,l,u,f,p,g,E,y,I){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=l|0,this.El=u|0,this.Fh=f|0,this.Fl=p|0,this.Gh=g|0,this.Gl=E|0,this.Hh=y|0,this.Hl=I|0}process(t,e){for(let x=0;x<16;x++,e+=4)ae[x]=t.getUint32(e),ce[x]=t.getUint32(e+=4);for(let x=16;x<80;x++){let d=ae[x-15]|0,b=ce[x-15]|0,L=me(d,b,1)^me(d,b,8)^bo(d,b,7),R=ye(d,b,1)^ye(d,b,8)^wo(d,b,7),B=ae[x-2]|0,K=ce[x-2]|0,O=me(B,K,19)^ar(B,K,61)^bo(B,K,6),P=ye(B,K,19)^cr(B,K,61)^wo(B,K,6),D=Ti(R,P,ce[x-7],ce[x-16]),C=_i(D,L,O,ae[x-7],ae[x-16]);ae[x]=C|0,ce[x]=D|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:l,Dl:u,Eh:f,El:p,Fh:g,Fl:E,Gh:y,Gl:I,Hh:_,Hl:q}=this;for(let x=0;x<80;x++){let d=me(f,p,14)^me(f,p,18)^ar(f,p,41),b=ye(f,p,14)^ye(f,p,18)^cr(f,p,41),L=f&g^~f&y,R=p&E^~p&I,B=Pi(q,b,R,el[x],ce[x]),K=ki(B,_,d,L,tl[x],ae[x]),O=B|0,P=me(n,o,28)^ar(n,o,34)^ar(n,o,39),D=ye(n,o,28)^cr(n,o,34)^cr(n,o,39),C=n&s^n&a^s&a,nt=o&i^o&c^i&c;_=y|0,q=I|0,y=g|0,I=E|0,g=f|0,E=p|0,{h:f,l:p}=Ot(l|0,u|0,K|0,O|0),l=a|0,u=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let v=Ri(O,D,nt);n=Bi(v,K,P,C),o=v|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:l,l:u}=Ot(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:p}=Ot(this.Eh|0,this.El|0,f|0,p|0),{h:g,l:E}=Ot(this.Fh|0,this.Fl|0,g|0,E|0),{h:y,l:I}=Ot(this.Gh|0,this.Gl|0,y|0,I|0),{h:_,l:q}=Ot(this.Hh|0,this.Hl|0,_|0,q|0),this.set(n,o,s,i,a,c,l,u,f,p,g,E,y,I,_,q)}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 Hr=go(()=>new qr);var Ki=go(()=>new xo);var So=BigInt(0),vo=BigInt(1);function Ne(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Io(r){if(!Ne(r))throw new Error("Uint8Array expected")}function Mt(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function ur(r){let t=r.toString(16);return t.length&1?"0"+t:t}function Ni(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?So:BigInt("0x"+r)}var Oi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",rl=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function ue(r){if(Io(r),Oi)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=rl[r[e]];return t}var $t={_0:48,_9:57,A:65,F:70,a:97,f:102};function Di(r){if(r>=$t._0&&r<=$t._9)return r-$t._0;if(r>=$t.A&&r<=$t.F)return r-($t.A-10);if(r>=$t.a&&r<=$t.f)return r-($t.a-10)}function lr(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(Oi)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=Di(r.charCodeAt(s)),a=Di(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 Yt(r){return Ni(ue(r))}function ge(r){return Io(r),Ni(ue(Uint8Array.from(r).reverse()))}function be(r,t){return lr(r.toString(16).padStart(t*2,"0"))}function Oe(r,t){return be(r,t).reverse()}function X(r,t,e){let n;if(typeof t=="string")try{n=lr(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(Ne(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];Io(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 Eo=r=>typeof r=="bigint"&&So<=r;function zr(r,t,e){return Eo(r)&&Eo(t)&&Eo(e)&&t<=r&&r<e}function Rt(r,t,e,n){if(!zr(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Mi(r){let t;for(t=0;r>So;r>>=vo,t+=1);return t}var we=r=>(vo<<BigInt(r))-vo,Ao=r=>new Uint8Array(r),Ui=r=>Uint8Array.from(r);function qi(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=Ao(r),o=Ao(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},a=(...f)=>e(o,n,...f),c=(f=Ao(0))=>{o=a(Ui([0]),f),n=a(),f.length!==0&&(o=a(Ui([1]),f),n=a())},l=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,p=[];for(;f<t;){n=a();let g=n.slice();p.push(g),f+=n.length}return le(...p)};return(f,p)=>{i(),c(f);let g;for(;!(g=p(l()));)c();return i(),g}}var nl={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"||Ne(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 Xt(r,t,e={}){let n=(o,s,i)=>{let a=nl[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 Me(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 mt=BigInt(0),at=BigInt(1),xe=BigInt(2),ol=BigInt(3),zi=BigInt(4),Vi=BigInt(5),Fi=BigInt(8);function Z(r,t){let e=r%t;return e>=mt?e:t+e}function Q(r,t,e){let n=r;for(;t-- >mt;)n*=n,n%=e;return n}function Vr(r,t){if(r===mt)throw new Error("invert: expected non-zero number");if(t<=mt)throw new Error("invert: expected positive modulus, got "+t);let e=Z(r,t),n=t,o=mt,s=at,i=at,a=mt;for(;e!==mt;){let l=n/e,u=n%e,f=o-i*l,p=s-a*l;n=e,e=u,o=i,s=a,i=f,a=p}if(n!==at)throw new Error("invert: does not exist");return Z(o,t)}function Wi(r,t){let e=(r.ORDER+at)/zi,n=r.pow(t,e);if(!r.eql(r.sqr(n),t))throw new Error("Cannot find square root");return n}function sl(r,t){let e=(r.ORDER-Vi)/Fi,n=r.mul(t,xe),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,xe),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 il(r){if(r<BigInt(3))throw new Error("sqrt is not defined for small field");let t=r-at,e=0;for(;t%xe===mt;)t/=xe,e++;let n=xe,o=Qt(r);for(;Hi(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return Wi;let s=o.pow(n,t),i=(t+at)/xe;return function(c,l){if(c.is0(l))return l;if(Hi(c,l)!==1)throw new Error("Cannot find square root");let u=e,f=c.mul(c.ONE,s),p=c.pow(l,t),g=c.pow(l,i);for(;!c.eql(p,c.ONE);){if(c.is0(p))return c.ZERO;let E=1,y=c.sqr(p);for(;!c.eql(y,c.ONE);)if(E++,y=c.sqr(y),E===u)throw new Error("Cannot find square root");let I=at<<BigInt(u-E-1),_=c.pow(f,I);u=E,f=c.sqr(_),p=c.mul(p,f),g=c.mul(g,_)}return g}}function al(r){return r%zi===ol?Wi:r%Fi===Vi?sl:il(r)}var Gi=(r,t)=>(Z(r,t)&at)===at,cl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Lo(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=cl.reduce((n,o)=>(n[o]="function",n),t);return Xt(r,e)}function ul(r,t,e){if(e<mt)throw new Error("invalid exponent, negatives unsupported");if(e===mt)return r.ONE;if(e===at)return t;let n=r.ONE,o=t;for(;e>mt;)e&at&&(n=r.mul(n,o)),o=r.sqr(o),e>>=at;return n}function qe(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 Hi(r,t){let e=(r.ORDER-at)/xe,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 Ro(r,t){t!==void 0&&Ur(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Qt(r,t,e=!1,n={}){if(r<=mt)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:s}=Ro(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:we(o),ZERO:mt,ONE:at,create:c=>Z(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return mt<=c&&c<r},is0:c=>c===mt,isOdd:c=>(c&at)===at,neg:c=>Z(-c,r),eql:(c,l)=>c===l,sqr:c=>Z(c*c,r),add:(c,l)=>Z(c+l,r),sub:(c,l)=>Z(c-l,r),mul:(c,l)=>Z(c*l,r),pow:(c,l)=>ul(a,c,l),div:(c,l)=>Z(c*Vr(l,r),r),sqrN:c=>c*c,addN:(c,l)=>c+l,subN:(c,l)=>c-l,mulN:(c,l)=>c*l,inv:c=>Vr(c,r),sqrt:n.sqrt||(c=>(i||(i=al(r)),i(a,c))),toBytes:c=>e?Oe(c,s):be(c,s),fromBytes:c=>{if(c.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+c.length);return e?ge(c):Yt(c)},invertBatch:c=>qe(a,c),cmov:(c,l,u)=>u?l:c});return Object.freeze(a)}function Zi(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 Bo(r){let t=Zi(r);return t+Math.ceil(t/2)}function ji(r,t,e=!1){let n=r.length,o=Zi(t),s=Bo(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?ge(r):Yt(r),a=Z(i,t-at)+at;return e?Oe(a,o):be(a,o)}var $i=BigInt(0),Co=BigInt(1);function To(r,t){let e=t.negate();return r?e:t}function Xi(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function _o(r,t){Xi(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=we(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Yi(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+=Co);let l=t*n,u=l+Math.abs(a)-1,f=a===0,p=a<0,g=t%2!==0;return{nextN:c,offset:u,isZero:f,isNeg:p,isNegF:g,offsetF:l}}function ll(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 fl(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,Qi=new WeakMap;function ko(r){return Qi.get(r)||1}function Fr(r,t){return{constTimeNegate:To,hasPrecomputes(e){return ko(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>$i;)n&Co&&(o=o.add(s)),s=s.double(),n>>=Co;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=_o(n,t),i=[],a=e,c=a;for(let l=0;l<o;l++){c=a,i.push(c);for(let u=1;u<s;u++)c=c.add(a),i.push(c);a=c.double()}return i},wNAF(e,n,o){let s=r.ZERO,i=r.BASE,a=_o(e,t);for(let c=0;c<a.windows;c++){let{nextN:l,offset:u,isZero:f,isNeg:p,isNegF:g,offsetF:E}=Yi(o,c,a);o=l,f?i=i.add(To(g,n[E])):s=s.add(To(p,n[u]))}return{p:s,f:i}},wNAFUnsafe(e,n,o,s=r.ZERO){let i=_o(e,t);for(let a=0;a<i.windows&&o!==$i;a++){let{nextN:c,offset:l,isZero:u,isNeg:f}=Yi(o,a,i);if(o=c,!u){let p=n[l];s=s.add(f?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=ko(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=ko(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){Xi(n,t),Qi.set(e,n),Po.delete(e)}}}function Wr(r,t,e,n){ll(e,r),fl(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=Mi(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let l=we(c),u=new Array(Number(l)+1).fill(i),f=Math.floor((t.BITS-1)/c)*c,p=i;for(let g=f;g>=0;g-=c){u.fill(i);for(let y=0;y<s;y++){let I=n[y],_=Number(I>>BigInt(g)&l);u[_]=u[_].add(e[y])}let E=i;for(let y=u.length-1,I=i;y>0;y--)I=I.add(u[y]),E=E.add(I);if(p=p.add(E),g!==0)for(let y=0;y<c;y++)p=p.double()}return p}function fr(r){return Lo(r.Fp),Xt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Ro(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var qt=BigInt(0),yt=BigInt(1),Ji=BigInt(2),dl=BigInt(8),hl={zip215:!0};function pl(r){let t=fr(r);return Xt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function ta(r){let t=pl(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:a,h:c}=t,l=Ji<<BigInt(a*8)-yt,u=e.create,f=Qt(t.n,t.nBitLength);function p(w,h){let m=e.sqr(w),S=e.sqr(h),k=e.add(e.mul(t.a,m),S),U=e.add(e.ONE,e.mul(t.d,e.mul(m,S)));return e.eql(k,U)}if(!p(t.Gx,t.Gy))throw new Error("bad curve params: generator point");let g=t.uvRatio||((w,h)=>{try{return{isValid:!0,value:e.sqrt(w*e.inv(h))}}catch{return{isValid:!1,value:qt}}}),E=t.adjustScalarBytes||(w=>w),y=t.domain||((w,h,m)=>{if(Mt("phflag",m),h.length||m)throw new Error("Contexts/pre-hash are not supported");return w});function I(w,h,m=!1){let S=m?yt:qt;Rt("coordinate "+w,h,S,l)}function _(w){if(!(w instanceof d))throw new Error("ExtendedPoint expected")}let q=Me((w,h)=>{let{ex:m,ey:S,ez:k}=w,U=w.is0();h==null&&(h=U?dl:e.inv(k));let M=u(m*h),H=u(S*h),V=u(k*h);if(U)return{x:qt,y:yt};if(V!==yt)throw new Error("invZ was invalid");return{x:M,y:H}}),x=Me(w=>{let{a:h,d:m}=t;if(w.is0())throw new Error("bad point: ZERO");let{ex:S,ey:k,ez:U,et:M}=w,H=u(S*S),V=u(k*k),W=u(U*U),ot=u(W*W),et=u(H*h),ut=u(W*u(et+V)),xt=u(ot+u(m*u(H*V)));if(ut!==xt)throw new Error("bad point: equation left != right (1)");let it=u(S*k),ft=u(U*M);if(it!==ft)throw new Error("bad point: equation left != right (2)");return!0});class d{constructor(h,m,S,k){I("x",h),I("y",m),I("z",S,!0),I("t",k),this.ex=h,this.ey=m,this.ez=S,this.et=k,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:S}=h||{};return I("x",m),I("y",S),new d(m,S,yt,u(m*S))}static normalizeZ(h){let m=qe(e,h.map(S=>S.ez));return h.map((S,k)=>S.toAffine(m[k])).map(d.fromAffine)}static msm(h,m){return Wr(d,f,h,m)}_setWindowSize(h){R.setWindowSize(this,h)}assertValidity(){x(this)}equals(h){_(h);let{ex:m,ey:S,ez:k}=this,{ex:U,ey:M,ez:H}=h,V=u(m*H),W=u(U*k),ot=u(S*H),et=u(M*k);return V===W&&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:S,ez:k}=this,U=u(m*m),M=u(S*S),H=u(Ji*u(k*k)),V=u(h*U),W=m+S,ot=u(u(W*W)-U-M),et=V+M,ut=et-H,xt=V-M,it=u(ot*ut),ft=u(et*xt),It=u(ot*xt),Pt=u(ut*et);return new d(it,ft,Pt,It)}add(h){_(h);let{a:m,d:S}=t,{ex:k,ey:U,ez:M,et:H}=this,{ex:V,ey:W,ez:ot,et}=h,ut=u(k*V),xt=u(U*W),it=u(H*S*et),ft=u(M*ot),It=u((k+U)*(V+W)-ut-xt),Pt=ft-it,$e=ft+it,Zs=u(xt-m*ut),wc=u(It*Pt),xc=u($e*Zs),Ec=u(It*Zs),Ac=u(Pt*$e);return new d(wc,xc,Ac,Ec)}subtract(h){return this.add(h.negate())}wNAF(h){return R.wNAFCached(this,h,d.normalizeZ)}multiply(h){let m=h;Rt("scalar",m,yt,n);let{p:S,f:k}=this.wNAF(m);return d.normalizeZ([S,k])[0]}multiplyUnsafe(h,m=d.ZERO){let S=h;return Rt("scalar",S,qt,n),S===qt?L:this.is0()||S===yt?this:R.wNAFCachedUnsafe(this,S,d.normalizeZ,m)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return R.unsafeLadder(this,n).is0()}toAffine(h){return q(this,h)}clearCofactor(){let{h}=t;return h===yt?this:this.multiplyUnsafe(h)}static fromHex(h,m=!1){let{d:S,a:k}=t,U=e.BYTES;h=X("pointHex",h,U),Mt("zip215",m);let M=h.slice(),H=h[U-1];M[U-1]=H&-129;let V=ge(M),W=m?l:e.ORDER;Rt("pointHex.y",V,qt,W);let ot=u(V*V),et=u(ot-yt),ut=u(S*ot-k),{isValid:xt,value:it}=g(et,ut);if(!xt)throw new Error("Point.fromHex: invalid y coordinate");let ft=(it&yt)===yt,It=(H&128)!==0;if(!m&&it===qt&&It)throw new Error("Point.fromHex: x=0 and x_0=1");return It!==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(),S=Oe(m,e.BYTES);return S[S.length-1]|=h&yt?128:0,S}toHex(){return ue(this.toRawBytes())}}d.BASE=new d(t.Gx,t.Gy,yt,u(t.Gx*t.Gy)),d.ZERO=new d(qt,yt,yt,qt);let{BASE:b,ZERO:L}=d,R=Fr(d,a*8);function B(w){return Z(w,n)}function K(w){return B(ge(w))}function O(w){let h=e.BYTES;w=X("private key",w,h);let m=X("hashed private key",s(w),2*h),S=E(m.slice(0,h)),k=m.slice(h,2*h),U=K(S);return{head:S,prefix:k,scalar:U}}function P(w){let{head:h,prefix:m,scalar:S}=O(w),k=b.multiply(S),U=k.toRawBytes();return{head:h,prefix:m,scalar:S,point:k,pointBytes:U}}function D(w){return P(w).pointBytes}function C(w=Uint8Array.of(),...h){let m=le(...h);return K(s(y(m,X("context",w),!!o)))}function nt(w,h,m={}){w=X("message",w),o&&(w=o(w));let{prefix:S,scalar:k,pointBytes:U}=P(h),M=C(m.context,S,w),H=b.multiply(M).toRawBytes(),V=C(m.context,H,U,w),W=B(M+V*k);Rt("signature.s",W,qt,n);let ot=le(H,Oe(W,e.BYTES));return X("result",ot,e.BYTES*2)}let v=hl;function A(w,h,m,S=v){let{context:k,zip215:U}=S,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 H=ge(w.slice(M,2*M)),V,W,ot;try{V=d.fromHex(m,U),W=d.fromHex(w.slice(0,M),U),ot=b.multiplyUnsafe(H)}catch{return!1}if(!U&&V.isSmallOrder())return!1;let et=C(k,W.toRawBytes(),V.toRawBytes(),h);return W.add(V.multiplyUnsafe(et)).subtract(ot).clearCofactor().equals(d.ZERO)}return b._setWindowSize(8),{CURVE:t,getPublicKey:D,sign:nt,verify:A,ExtendedPoint:d,utils:{getExtendedPublicKey:P,randomPrivateKey:()=>i(e.BYTES),precompute(w=8,h=d.BASE){return h._setWindowSize(w),h.multiply(BigInt(3)),h}}}}var Ko=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),ea=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Zh=BigInt(0),ml=BigInt(1),ra=BigInt(2),jh=BigInt(3),yl=BigInt(5),gl=BigInt(8);function bl(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=Ko,a=r*r%s*r%s,c=Q(a,ra,s)*a%s,l=Q(c,ml,s)*r%s,u=Q(l,yl,s)*l%s,f=Q(u,t,s)*u%s,p=Q(f,e,s)*f%s,g=Q(p,n,s)*p%s,E=Q(g,o,s)*g%s,y=Q(E,o,s)*g%s,I=Q(y,t,s)*u%s;return{pow_p_5_8:Q(I,ra,s)*r%s,b2:a}}function wl(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function xl(r,t){let e=Ko,n=Z(t*t*t,e),o=Z(n*n*t,e),s=bl(r*o).pow_p_5_8,i=Z(r*n*s,e),a=Z(t*i*i,e),c=i,l=Z(i*ea,e),u=a===r,f=a===Z(-r,e),p=a===Z(-r*ea,e);return u&&(i=c),(f||p)&&(i=l),Gi(i,e)&&(i=Z(-i,e)),{isValid:u||f,value:i}}var na=Qt(Ko,void 0,!0),El={a:na.create(BigInt(-1)),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:na,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:gl,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Ki,randomBytes:Or,adjustScalarBytes:wl,uvRatio:xl},oa=ta(El);var dr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Gr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var sa={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Gr("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var _t=sa;var Zr=32;var Do,Al=(async()=>{try{return await _t.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function vl(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await _t.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await _t.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 Sl(r,t,e){return oa.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function ia(r,t,e){return Do==null&&(Do=await Al),Do?vl(r,t,e):Sl(r,t,e)}function jr(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var $r=class{type="Ed25519";raw;constructor(t){this.raw=Uo(t,Zr)}toMultihash(){return Kt.digest(Tt(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return $.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Y(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=ia(this.raw,e,t);return jr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function No(r){return r=Uo(r,Zr),new $r(r)}function Uo(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new z(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var Ll=Math.pow(2,7),Rl=Math.pow(2,14),Bl=Math.pow(2,21),Oo=Math.pow(2,28),Mo=Math.pow(2,35),qo=Math.pow(2,42),Ho=Math.pow(2,49),F=128,dt=127;function St(r){if(r<Ll)return 1;if(r<Rl)return 2;if(r<Bl)return 3;if(r<Oo)return 4;if(r<Mo)return 5;if(r<qo)return 6;if(r<Ho)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function zo(r,t,e=0){switch(St(r)){case 8:t[e++]=r&255|F,r/=128;case 7:t[e++]=r&255|F,r/=128;case 6:t[e++]=r&255|F,r/=128;case 5:t[e++]=r&255|F,r/=128;case 4:t[e++]=r&255|F,r>>>=7;case 3:t[e++]=r&255|F,r>>>=7;case 2:t[e++]=r&255|F,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Tl(r,t,e=0){switch(St(r)){case 8:t.set(e++,r&255|F),r/=128;case 7:t.set(e++,r&255|F),r/=128;case 6:t.set(e++,r&255|F),r/=128;case 5:t.set(e++,r&255|F),r/=128;case 4:t.set(e++,r&255|F),r>>>=7;case 3:t.set(e++,r&255|F),r>>>=7;case 2:t.set(e++,r&255|F),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Vo(r,t){let e=r[t],n=0;if(n+=e&dt,e<F||(e=r[t+1],n+=(e&dt)<<7,e<F)||(e=r[t+2],n+=(e&dt)<<14,e<F)||(e=r[t+3],n+=(e&dt)<<21,e<F)||(e=r[t+4],n+=(e&dt)*Oo,e<F)||(e=r[t+5],n+=(e&dt)*Mo,e<F)||(e=r[t+6],n+=(e&dt)*qo,e<F)||(e=r[t+7],n+=(e&dt)*Ho,e<F))return n;throw new RangeError("Could not decode varint")}function _l(r,t){let e=r.get(t),n=0;if(n+=e&dt,e<F||(e=r.get(t+1),n+=(e&dt)<<7,e<F)||(e=r.get(t+2),n+=(e&dt)<<14,e<F)||(e=r.get(t+3),n+=(e&dt)<<21,e<F)||(e=r.get(t+4),n+=(e&dt)*Oo,e<F)||(e=r.get(t+5),n+=(e&dt)*Mo,e<F)||(e=r.get(t+6),n+=(e&dt)*qo,e<F)||(e=r.get(t+7),n+=(e&dt)*Ho,e<F))return n;throw new RangeError("Could not decode varint")}function Ht(r,t,e=0){return t==null&&(t=At(St(r))),t instanceof Uint8Array?zo(r,t,e):Tl(r,t,e)}function Ee(r,t=0){return r instanceof Uint8Array?Vo(r,t):_l(r,t)}var Wo=new Float32Array([-0]),fe=new Uint8Array(Wo.buffer);function ca(r,t,e){Wo[0]=r,t[e]=fe[0],t[e+1]=fe[1],t[e+2]=fe[2],t[e+3]=fe[3]}function ua(r,t){return fe[0]=r[t],fe[1]=r[t+1],fe[2]=r[t+2],fe[3]=r[t+3],Wo[0]}var Go=new Float64Array([-0]),ht=new Uint8Array(Go.buffer);function la(r,t,e){Go[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 fa(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],Go[0]}var Pl=BigInt(Number.MAX_SAFE_INTEGER),kl=BigInt(Number.MIN_SAFE_INTEGER),Bt=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 Ae;if(t<Pl&&t>kl)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>da&&(o=0n,++n>da&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return Ae;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):Ae}},Ae=new Bt(0,0);Ae.toBigInt=function(){return 0n};Ae.zzEncode=Ae.zzDecode=function(){return this};Ae.length=function(){return 1};var da=4294967296n;function ha(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 pa(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 Zo(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function Ut(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Yr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var jo=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Ut(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ut(this,4);return Yr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ut(this,4);return Yr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ut(this,4);let t=ua(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Ut(this,4);let t=fa(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw Ut(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return pa(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Ut(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Ut(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Bt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw Ut(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw Ut(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ut(this,8);let t=Yr(this.buf,this.pos+=4),e=Yr(this.buf,this.pos+=4);return new Bt(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=Vo(this.buf,this.pos);return this.pos+=St(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function $o(r){return new jo(r instanceof Uint8Array?r:r.subarray())}function gt(r,t,e){let n=$o(r);return t.decode(n,void 0,e)}function Yo(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return At(i);o+i>t&&(n=At(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var ve=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Xo(){}var Jo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Cl=Yo();function Kl(r){return globalThis.Buffer!=null?At(r):Cl(r)}var pr=class{len;head;tail;states;constructor(){this.len=0,this.head=new ve(Xo,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new ve(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new ts((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(Xr,10,Bt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Bt.fromBigInt(t);return this._push(Xr,e.length(),e)}uint64Number(t){return this._push(zo,St(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=Bt.fromBigInt(t).zzEncode();return this._push(Xr,e.length(),e)}sint64Number(t){let e=Bt.fromNumber(t).zzEncode();return this._push(Xr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Qo,1,t?1:0)}fixed32(t){return this._push(hr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Bt.fromBigInt(t);return this._push(hr,4,e.lo)._push(hr,4,e.hi)}fixed64Number(t){let e=Bt.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(ca,4,t)}double(t){return this._push(la,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Qo,1,0):this.uint32(e)._push(Ul,e,t)}string(t){let e=ha(t);return e!==0?this.uint32(e)._push(Zo,e,t):this._push(Qo,1,0)}fork(){return this.states=new Jo(this),this.head=this.tail=new ve(Xo,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new ve(Xo,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=Kl(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Qo(r,t,e){t[e]=r&255}function Dl(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var ts=class extends ve{next;constructor(t,e){super(Dl,t,e),this.next=void 0}};function Xr(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 Ul(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(Nl,t,r),this},pr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Ol,t,r),this});function Nl(r,t,e){t.set(r,e)}function Ol(r,t,e){r.length<40?Zo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(G(r),e)}function es(){return new pr}function bt(r,t){let e=es();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var He;(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"})(He||(He={}));function Qr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function rs(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 Qr("enum",He.VARINT,e,n)}function wt(r,t){return Qr("message",He.LENGTH_DELIMITED,r,t)}var Se=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 ns;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(ns||(ns={}));(function(r){r.codec=()=>rs(ns)})(rt||(rt={}));var zt;(function(r){let t;r.codec=()=>(t==null&&(t=wt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),rt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=rt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>bt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(zt||(zt={}));var os;(function(r){let t;r.codec=()=>(t==null&&(t=wt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),rt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=rt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>bt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(os||(os={}));var gr={};Et(gr,{MAX_RSA_KEY_SIZE:()=>ss,generateRSAKeyPair:()=>xa,jwkToJWKKeyPair:()=>Ea,jwkToPkcs1:()=>zl,jwkToPkix:()=>us,jwkToRSAPrivateKey:()=>hs,pkcs1MessageToJwk:()=>as,pkcs1MessageToRSAPrivateKey:()=>ls,pkcs1ToJwk:()=>Hl,pkcs1ToRSAPrivateKey:()=>wa,pkixMessageToJwk:()=>cs,pkixMessageToRSAPublicKey:()=>ds,pkixToJwk:()=>Vl,pkixToRSAPublicKey:()=>fs});var Jr=Hr;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=gr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return tt.createV1(114,this._multihash)}toString(){return $.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Y(this.raw,t.raw)}verify(t,e,n){return ba(this.jwk,e,t,n)}},yr=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=gr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Y(this.raw,t.raw)}sign(t,e){return ga(this.jwk,t,e)}};var ss=8192,is=18,Ml=1062,ql=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Hl(r){let t=Gt(r);return as(t)}function as(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 zl(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 z("JWK was missing components");return se([vt(Uint8Array.from([0])),vt(G(r.n,"base64url")),vt(G(r.e,"base64url")),vt(G(r.d,"base64url")),vt(G(r.p,"base64url")),vt(G(r.q,"base64url")),vt(G(r.dp,"base64url")),vt(G(r.dq,"base64url")),vt(G(r.qi,"base64url"))]).subarray()}function Vl(r){let t=Gt(r,{offset:0});return cs(t)}function cs(r){let t=Gt(r[1],{offset:0});return{kty:"RSA",n:N(t[0],"base64url"),e:N(t[1],"base64url")}}function us(r){if(r.n==null||r.e==null)throw new z("JWK was missing components");return se([ql,Dr(se([vt(G(r.n,"base64url")),vt(G(r.e,"base64url"))]))]).subarray()}function wa(r){let t=Gt(r);return ls(t)}function ls(r){let t=as(r);return hs(t)}function fs(r,t){if(r.byteLength>=Ml)throw new Be("Key size is too large");let e=Gt(r,{offset:0});return ds(e,r,t)}function ds(r,t,e){let n=cs(r);if(e==null){let o=Jr(zt.encode({Type:rt.RSA,Data:t}));e=Ct(is,o)}return new ze(n,e)}function hs(r){if(va(r)>ss)throw new z("Key size is too large");let t=Ea(r),e=Jr(zt.encode({Type:rt.RSA,Data:us(t.publicKey)})),n=Ct(is,e);return new yr(t.privateKey,new ze(t.publicKey,n))}async function xa(r){if(r>ss)throw new z("Key size is too large");let t=await Aa(r),e=Jr(zt.encode({Type:rt.RSA,Data:us(t.publicKey)})),n=Ct(is,e);return new yr(t.privateKey,new ze(t.publicKey,n))}function Ea(r){if(r==null)throw new z("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function Aa(r,t){let e=await _t.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 Fl(e,t);return{privateKey:n[0],publicKey:n[1]}}async function ga(r,t,e){let n=await _t.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);e?.signal?.throwIfAborted();let o=await _t.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 ba(r,t,e,n){let o=await _t.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await _t.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,e instanceof Uint8Array?e:e.subarray());return n?.signal?.throwIfAborted(),s}async function Fl(r,t){if(r.privateKey==null||r.publicKey==null)throw new z("Private and public key are required");let e=await Promise.all([_t.get().subtle.exportKey("jwk",r.privateKey),_t.get().subtle.exportKey("jwk",r.publicKey)]);return t?.signal?.throwIfAborted(),e}function va(r){if(r.kty!=="RSA")throw new z("invalid key type");if(r.n==null)throw new z("invalid key modulus");return G(r.n,"base64url").length*8}var tn=class extends De{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,xi(t);let n=sr(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 Ue(this),this.iHash.update(t),this}digestInto(t){Ue(this),pe(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()}},ps=(r,t,e)=>new tn(r,t).update(e).digest();ps.create=(r,t)=>new tn(r,t);function Sa(r){r.lowS!==void 0&&Mt("lowS",r.lowS),r.prehash!==void 0&&Mt("prehash",r.prehash)}function Wl(r){let t=fr(r);Xt(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 gs=class extends Error{constructor(t=""){super(t)}},Jt={Err:gs,_tlv:{encode:(r,t)=>{let{Err:e}=Jt;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=ur(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?ur(o.length/2|128):"";return ur(r)+s+o+t},decode(r,t){let{Err:e}=Jt,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let l=t.subarray(n,n+c);if(l.length!==c)throw new e("tlv.decode: length bytes not complete");if(l[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let u of l)i=i<<8|u;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=Jt;if(r<te)throw new t("integer: negative integers are not allowed");let e=ur(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=Jt;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Yt(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Jt,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:l,l:u}=n.decode(2,c);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(l)}},hexFromSig(r){let{_tlv:t,_int:e}=Jt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}};function ms(r,t){return ue(be(r,t))}var te=BigInt(0),ct=BigInt(1),R0=BigInt(2),ys=BigInt(3),Gl=BigInt(4);function Zl(r){let t=Wl(r),{Fp:e}=t,n=Qt(t.n,t.nBitLength),o=t.toBytes||((x,d,b)=>{let L=d.toAffine();return le(Uint8Array.from([4]),e.toBytes(L.x),e.toBytes(L.y))}),s=t.fromBytes||(x=>{let d=x.subarray(1),b=e.fromBytes(d.subarray(0,e.BYTES)),L=e.fromBytes(d.subarray(e.BYTES,2*e.BYTES));return{x:b,y:L}});function i(x){let{a:d,b}=t,L=e.sqr(x),R=e.mul(L,x);return e.add(e.add(R,e.mul(x,d)),b)}function a(x,d){let b=e.sqr(d),L=i(x);return e.eql(b,L)}if(!a(t.Gx,t.Gy))throw new Error("bad curve params: generator point");let c=e.mul(e.pow(t.a,ys),Gl),l=e.mul(e.sqr(t.b),BigInt(27));if(e.is0(e.add(c,l)))throw new Error("bad curve params: a or b");function u(x){return zr(x,ct,t.n)}function f(x){let{allowedPrivateKeyLengths:d,nByteLength:b,wrapPrivateKey:L,n:R}=t;if(d&&typeof x!="bigint"){if(Ne(x)&&(x=ue(x)),typeof x!="string"||!d.includes(x.length))throw new Error("invalid private key");x=x.padStart(b*2,"0")}let B;try{B=typeof x=="bigint"?x:Yt(X("private key",x,b))}catch{throw new Error("invalid private key, expected hex or "+b+" bytes, got "+typeof x)}return L&&(B=Z(B,R)),Rt("private key",B,ct,R),B}function p(x){if(!(x instanceof y))throw new Error("ProjectivePoint expected")}let g=Me((x,d)=>{let{px:b,py:L,pz:R}=x;if(e.eql(R,e.ONE))return{x:b,y:L};let B=x.is0();d==null&&(d=B?e.ONE:e.inv(R));let K=e.mul(b,d),O=e.mul(L,d),P=e.mul(R,d);if(B)return{x:e.ZERO,y:e.ZERO};if(!e.eql(P,e.ONE))throw new Error("invZ was invalid");return{x:K,y:O}}),E=Me(x=>{if(x.is0()){if(t.allowInfinityPoint&&!e.is0(x.py))return;throw new Error("bad point: ZERO")}let{x:d,y:b}=x.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(!x.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class y{constructor(d,b,L){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(L==null||!e.isValid(L))throw new Error("z required");this.px=d,this.py=b,this.pz=L,Object.freeze(this)}static fromAffine(d){let{x:b,y:L}=d||{};if(!d||!e.isValid(b)||!e.isValid(L))throw new Error("invalid affine point");if(d instanceof y)throw new Error("projective point not allowed");let R=B=>e.eql(B,e.ZERO);return R(b)&&R(L)?y.ZERO:new y(b,L,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){let b=qe(e,d.map(L=>L.pz));return d.map((L,R)=>L.toAffine(b[R])).map(y.fromAffine)}static fromHex(d){let b=y.fromAffine(s(X("pointHex",d)));return b.assertValidity(),b}static fromPrivateKey(d){return y.BASE.multiply(f(d))}static msm(d,b){return Wr(y,n,d,b)}_setWindowSize(d){q.setWindowSize(this,d)}assertValidity(){E(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:L,pz:R}=this,{px:B,py:K,pz:O}=d,P=e.eql(e.mul(b,O),e.mul(B,R)),D=e.eql(e.mul(L,O),e.mul(K,R));return P&&D}negate(){return new y(this.px,e.neg(this.py),this.pz)}double(){let{a:d,b}=t,L=e.mul(b,ys),{px:R,py:B,pz:K}=this,O=e.ZERO,P=e.ZERO,D=e.ZERO,C=e.mul(R,R),nt=e.mul(B,B),v=e.mul(K,K),A=e.mul(R,B);return A=e.add(A,A),D=e.mul(R,K),D=e.add(D,D),O=e.mul(d,D),P=e.mul(L,v),P=e.add(O,P),O=e.sub(nt,P),P=e.add(nt,P),P=e.mul(O,P),O=e.mul(A,O),D=e.mul(L,D),v=e.mul(d,v),A=e.sub(C,v),A=e.mul(d,A),A=e.add(A,D),D=e.add(C,C),C=e.add(D,C),C=e.add(C,v),C=e.mul(C,A),P=e.add(P,C),v=e.mul(B,K),v=e.add(v,v),C=e.mul(v,A),O=e.sub(O,C),D=e.mul(v,nt),D=e.add(D,D),D=e.add(D,D),new y(O,P,D)}add(d){p(d);let{px:b,py:L,pz:R}=this,{px:B,py:K,pz:O}=d,P=e.ZERO,D=e.ZERO,C=e.ZERO,nt=t.a,v=e.mul(t.b,ys),A=e.mul(b,B),T=e.mul(L,K),w=e.mul(R,O),h=e.add(b,L),m=e.add(B,K);h=e.mul(h,m),m=e.add(A,T),h=e.sub(h,m),m=e.add(b,R);let S=e.add(B,O);return m=e.mul(m,S),S=e.add(A,w),m=e.sub(m,S),S=e.add(L,R),P=e.add(K,O),S=e.mul(S,P),P=e.add(T,w),S=e.sub(S,P),C=e.mul(nt,m),P=e.mul(v,w),C=e.add(P,C),P=e.sub(T,C),C=e.add(T,C),D=e.mul(P,C),T=e.add(A,A),T=e.add(T,A),w=e.mul(nt,w),m=e.mul(v,m),T=e.add(T,w),w=e.sub(A,w),w=e.mul(nt,w),m=e.add(m,w),A=e.mul(T,m),D=e.add(D,A),A=e.mul(S,m),P=e.mul(h,P),P=e.sub(P,A),A=e.mul(h,T),C=e.mul(S,C),C=e.add(C,A),new y(P,D,C)}subtract(d){return this.add(d.negate())}is0(){return this.equals(y.ZERO)}wNAF(d){return q.wNAFCached(this,d,y.normalizeZ)}multiplyUnsafe(d){let{endo:b,n:L}=t;Rt("scalar",d,te,L);let R=y.ZERO;if(d===te)return R;if(this.is0()||d===ct)return this;if(!b||q.hasPrecomputes(this))return q.wNAFCachedUnsafe(this,d,y.normalizeZ);let{k1neg:B,k1:K,k2neg:O,k2:P}=b.splitScalar(d),D=R,C=R,nt=this;for(;K>te||P>te;)K&ct&&(D=D.add(nt)),P&ct&&(C=C.add(nt)),nt=nt.double(),K>>=ct,P>>=ct;return B&&(D=D.negate()),O&&(C=C.negate()),C=new y(e.mul(C.px,b.beta),C.py,C.pz),D.add(C)}multiply(d){let{endo:b,n:L}=t;Rt("scalar",d,ct,L);let R,B;if(b){let{k1neg:K,k1:O,k2neg:P,k2:D}=b.splitScalar(d),{p:C,f:nt}=this.wNAF(O),{p:v,f:A}=this.wNAF(D);C=q.constTimeNegate(K,C),v=q.constTimeNegate(P,v),v=new y(e.mul(v.px,b.beta),v.py,v.pz),R=C.add(v),B=nt.add(A)}else{let{p:K,f:O}=this.wNAF(d);R=K,B=O}return y.normalizeZ([R,B])[0]}multiplyAndAddUnsafe(d,b,L){let R=y.BASE,B=(O,P)=>P===te||P===ct||!O.equals(R)?O.multiplyUnsafe(P):O.multiply(P),K=B(this,b).add(B(d,L));return K.is0()?void 0:K}toAffine(d){return g(this,d)}isTorsionFree(){let{h:d,isTorsionFree:b}=t;if(d===ct)return!0;if(b)return b(y,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(y,this):this.multiplyUnsafe(t.h)}toRawBytes(d=!0){return Mt("isCompressed",d),this.assertValidity(),o(y,this,d)}toHex(d=!0){return Mt("isCompressed",d),ue(this.toRawBytes(d))}}y.BASE=new y(t.Gx,t.Gy,e.ONE),y.ZERO=new y(e.ZERO,e.ONE,e.ZERO);let{endo:I,nBitLength:_}=t,q=Fr(y,I?Math.ceil(_/2):_);return{CURVE:t,ProjectivePoint:y,normPrivateKeyToScalar:f,weierstrassEquation:i,isWithinCurveOrder:u}}function jl(r){let t=fr(r);return Xt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Ia(r){let t=jl(r),{Fp:e,n,nByteLength:o,nBitLength:s}=t,i=e.BYTES+1,a=2*e.BYTES+1;function c(v){return Z(v,n)}function l(v){return Vr(v,n)}let{ProjectivePoint:u,normPrivateKeyToScalar:f,weierstrassEquation:p,isWithinCurveOrder:g}=Zl({...t,toBytes(v,A,T){let w=A.toAffine(),h=e.toBytes(w.x),m=le;return Mt("isCompressed",T),T?m(Uint8Array.from([A.hasEvenY()?2:3]),h):m(Uint8Array.from([4]),h,e.toBytes(w.y))},fromBytes(v){let A=v.length,T=v[0],w=v.subarray(1);if(A===i&&(T===2||T===3)){let h=Yt(w);if(!zr(h,ct,e.ORDER))throw new Error("Point is not on curve");let m=p(h),S;try{S=e.sqrt(m)}catch(M){let H=M instanceof Error?": "+M.message:"";throw new Error("Point is not on curve"+H)}let k=(S&ct)===ct;return(T&1)===1!==k&&(S=e.neg(S)),{x:h,y:S}}else if(A===a&&T===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 "+A)}}});function E(v){let A=n>>ct;return v>A}function y(v){return E(v)?c(-v):v}let I=(v,A,T)=>Yt(v.slice(A,T));class _{constructor(A,T,w){Rt("r",A,ct,n),Rt("s",T,ct,n),this.r=A,this.s=T,w!=null&&(this.recovery=w),Object.freeze(this)}static fromCompact(A){let T=o;return A=X("compactSignature",A,T*2),new _(I(A,0,T),I(A,T,2*T))}static fromDER(A){let{r:T,s:w}=Jt.toSig(X("DER",A));return new _(T,w)}assertValidity(){}addRecoveryBit(A){return new _(this.r,this.s,A)}recoverPublicKey(A){let{r:T,s:w,recovery:h}=this,m=R(X("msgHash",A));if(h==null||![0,1,2,3].includes(h))throw new Error("recovery id invalid");let S=h===2||h===3?T+t.n:T;if(S>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let k=(h&1)===0?"02":"03",U=u.fromHex(k+ms(S,e.BYTES)),M=l(S),H=c(-m*M),V=c(w*M),W=u.BASE.multiplyAndAddUnsafe(U,H,V);if(!W)throw new Error("point at infinify");return W.assertValidity(),W}hasHighS(){return E(this.s)}normalizeS(){return this.hasHighS()?new _(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return lr(this.toDERHex())}toDERHex(){return Jt.hexFromSig(this)}toCompactRawBytes(){return lr(this.toCompactHex())}toCompactHex(){let A=o;return ms(this.r,A)+ms(this.s,A)}}let q={isValidPrivateKey(v){try{return f(v),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let v=Bo(t.n);return ji(t.randomBytes(v),t.n)},precompute(v=8,A=u.BASE){return A._setWindowSize(v),A.multiply(BigInt(3)),A}};function x(v,A=!0){return u.fromPrivateKey(v).toRawBytes(A)}function d(v){if(typeof v=="bigint")return!1;if(v instanceof u)return!0;let T=X("key",v).length,w=e.BYTES,h=w+1,m=2*w+1;if(!(t.allowedPrivateKeyLengths||o===h))return T===h||T===m}function b(v,A,T=!0){if(d(v)===!0)throw new Error("first arg must be private key");if(d(A)===!1)throw new Error("second arg must be public key");return u.fromHex(A).multiply(f(v)).toRawBytes(T)}let L=t.bits2int||function(v){if(v.length>8192)throw new Error("input is too large");let A=Yt(v),T=v.length*8-s;return T>0?A>>BigInt(T):A},R=t.bits2int_modN||function(v){return c(L(v))},B=we(s);function K(v){return Rt("num < 2^"+s,v,te,B),be(v,o)}function O(v,A,T=P){if(["recovered","canonical"].some(et=>et in T))throw new Error("sign() legacy options not supported");let{hash:w,randomBytes:h}=t,{lowS:m,prehash:S,extraEntropy:k}=T;m==null&&(m=!0),v=X("msgHash",v),Sa(T),S&&(v=X("prehashed msgHash",w(v)));let U=R(v),M=f(A),H=[K(M),K(U)];if(k!=null&&k!==!1){let et=k===!0?h(e.BYTES):k;H.push(X("extraEntropy",et))}let V=le(...H),W=U;function ot(et){let ut=L(et);if(!g(ut))return;let xt=l(ut),it=u.BASE.multiply(ut).toAffine(),ft=c(it.x);if(ft===te)return;let It=c(xt*c(W+ft*M));if(It===te)return;let Pt=(it.x===ft?0:2)|Number(it.y&ct),$e=It;return m&&E(It)&&($e=y(It),Pt^=1),new _(ft,$e,Pt)}return{seed:V,k2sig:ot}}let P={lowS:t.lowS,prehash:!1},D={lowS:t.lowS,prehash:!1};function C(v,A,T=P){let{seed:w,k2sig:h}=O(v,A,T),m=t;return qi(m.hash.outputLen,m.nByteLength,m.hmac)(w,h)}u.BASE._setWindowSize(8);function nt(v,A,T,w=D){let h=v;A=X("msgHash",A),T=X("publicKey",T);let{lowS:m,prehash:S,format:k}=w;if(Sa(w),"strict"in w)throw new Error("options.strict was renamed to lowS");if(k!==void 0&&k!=="compact"&&k!=="der")throw new Error("format must be compact or der");let U=typeof h=="string"||Ne(h),M=!U&&!k&&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 H,V;try{if(M&&(H=new _(h.r,h.s)),U){try{k!=="compact"&&(H=_.fromDER(h))}catch(Pt){if(!(Pt instanceof Jt.Err))throw Pt}!H&&k!=="der"&&(H=_.fromCompact(h))}V=u.fromHex(T)}catch{return!1}if(!H||m&&H.hasHighS())return!1;S&&(A=t.hash(A));let{r:W,s:ot}=H,et=R(A),ut=l(ot),xt=c(et*ut),it=c(W*ut),ft=u.BASE.multiplyAndAddUnsafe(V,xt,it)?.toAffine();return ft?c(ft.x)===W:!1}return{CURVE:t,getPublicKey:x,getSharedSecret:b,sign:C,verify:nt,ProjectivePoint:u,Signature:_,utils:q}}function $l(r){return{hash:r,hmac:(t,...e)=>ps(r,t,yo(...e)),randomBytes:Or}}function La(r,t){let e=n=>Ia({...r,...$l(n)});return{...e(t),create:e}}var Ta=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Ra=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Yl=BigInt(0),Xl=BigInt(1),bs=BigInt(2),Ba=(r,t)=>(r+t/bs)/t;function Ql(r){let t=Ta,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),l=r*r*r%t,u=l*l*r%t,f=Q(u,e,t)*u%t,p=Q(f,e,t)*u%t,g=Q(p,bs,t)*l%t,E=Q(g,o,t)*g%t,y=Q(E,s,t)*E%t,I=Q(y,a,t)*y%t,_=Q(I,c,t)*I%t,q=Q(_,a,t)*y%t,x=Q(q,e,t)*u%t,d=Q(x,i,t)*E%t,b=Q(d,n,t)*l%t,L=Q(b,bs,t);if(!ws.eql(ws.sqr(L),r))throw new Error("Cannot find square root");return L}var ws=Qt(Ta,void 0,void 0,{sqrt:Ql}),Ve=La({a:Yl,b:BigInt(7),Fp:ws,n:Ra,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Ra,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Xl*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),a=Ba(s*r,t),c=Ba(-n*r,t),l=Z(r-a*e-c*o,t),u=Z(-a*n-c*s,t),f=l>i,p=u>i;if(f&&(l=t-l),p&&(u=t-u),l>i||u>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:l,k2neg:p,k2:u}}}},Hr);function _a(r,t,e,n){let o=er.digest(e instanceof Uint8Array?e:e.subarray());if(jr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ve.verify(t,s,r))).catch(s=>{throw s.name==="AbortError"?s:new dr(String(s))});try{return n?.signal?.throwIfAborted(),Ve.verify(t,o.digest,r)}catch(s){throw new dr(String(s))}}var en=class{type="secp256k1";raw;_key;constructor(t){this._key=ka(t),this.raw=Pa(this._key)}toMultihash(){return Kt.digest(Tt(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return $.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Y(this.raw,t.raw)}verify(t,e,n){return _a(this._key,e,t,n)}};function xs(r){return new en(r)}function Pa(r){return Ve.ProjectivePoint.fromHex(r).toRawBytes(!0)}function ka(r){try{return Ve.ProjectivePoint.fromHex(r),r}catch(t){throw new Be(String(t))}}function rn(r,t){let{Type:e,Data:n}=zt.decode(r),o=n??new Uint8Array;switch(e){case rt.RSA:return fs(o,t);case rt.Ed25519:return No(o);case rt.secp256k1:return xs(o);case rt.ECDSA:return mo(o);default:throw new de}}function Ca(r){let{Type:t,Data:e}=zt.decode(r.digest),n=e??new Uint8Array;switch(t){case rt.Ed25519:return No(n);case rt.secp256k1:return xs(n);case rt.ECDSA:return mo(n);default:throw new de}}function Tt(r){return zt.encode({Type:rt[r.type],Data:r.raw})}var Ka=Symbol.for("nodejs.util.inspect.custom"),Jl=114,br=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Tr]=!0;toString(){return this.string==null&&(this.string=$.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return tt.createV1(Jl,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return Y(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return Y(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Ka](){return`PeerId(${this.toString()})`}},wr=class extends br{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},xr=class extends br{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Er=class extends br{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},tf=2336,Ar=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Kt.digest(G(this.url))}[Ka](){return`PeerId(${this.url})`}[Tr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return tt.createV1(tf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=N(t)),t.toString()===this.toString())}};var ef=114,Da=2336;function Ua(r){if(r.type==="Ed25519")return new xr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new Er({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new wr({multihash:r.toCID().multihash,publicKey:r});throw new de}function Es(r){if(nf(r))return new wr({multihash:r});if(rf(r))try{let t=Ca(r);if(t.type==="Ed25519")return new xr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new Er({multihash:r,publicKey:t})}catch{let e=N(r.digest);return new Ar(new URL(e))}throw new Pr("Supplied PeerID Multihash is invalid")}function nn(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==ef&&r.code!==Da)throw new _r("Supplied PeerID CID is invalid");if(r.code===Da){let t=N(r.multihash.digest);return new Ar(new URL(t))}return Es(r.multihash)}function rf(r){return r.code===Kt.code}function nf(r){return r.code===er.code}var vr;(function(r){let t;r.codec=()=>(t==null&&(t=wt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.publicKey!=null&&e.publicKey.byteLength>0&&(n.uint32(10),n.bytes(e.publicKey)),e.payloadType!=null&&e.payloadType.byteLength>0&&(n.uint32(18),n.bytes(e.payloadType)),e.payload!=null&&e.payload.byteLength>0&&(n.uint32(26),n.bytes(e.payload)),e.signature!=null&&e.signature.byteLength>0&&(n.uint32(42),n.bytes(e.signature)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={publicKey: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=>bt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(vr||(vr={}));var on=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var Fe=class r{static createFromProtobuf=t=>{let e=vr.decode(t),n=rn(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=Na(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 on("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(t){let{publicKey:e,payloadType:n,payload:o,signature:s}=t;this.publicKey=e,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=vr.encode({publicKey:Tt(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return t==null?!1:Y(this.marshal(),t.marshal())}async validate(t,e){let n=Na(t,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,e)}},Na=(r,t,e)=>{let n=G(r),o=Ht(n.byteLength),s=Ht(t.length),i=Ht(e.length);return new pt(o,n,s,t,i,e)};function Oa(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 sn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",l=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let p=Number.parseInt(f,t);if(!Number.isNaN(p))return p});if(u===void 0)break;if(s*=t,s+=u,s>l||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];e[o]=s>>8,e[o+1]=s&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return e.set(s.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Ma=45,of=15,We=new sn;function As(r){if(!(r.length>of))return We.new(r).parseWith(()=>We.readIPv4Addr())}function vs(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Ma))return We.new(r).parseWith(()=>We.readIPv6Addr())}function an(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>Ma)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 oy=parseInt("0xFFFF",16),sy=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function za(r){return!!As(r)}function Va(r){return!!vs(r)}function cn(r){return!!an(r)}var Fa=za,lf=Va,Ss=function(r){let t=0;if(r=r.toString().trim(),Fa(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(lf(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=Fa(e[n]),i;s&&(i=Ss(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")},Wa=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let o=[];for(let s=0;s<e;s++)o.push(r[t+s]);return o.join(".")}if(e===16){let o=[];for(let s=0;s<e;s+=2)o.push(n.getUint16(t+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var Ge={},Is={},df=[[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"]];df.forEach(r=>{let t=hf(...r);Is[t.code]=t,Ge[t.name]=t});function hf(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function j(r){if(typeof r=="number"){if(Is[r]!=null)return Is[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Ge[r]!=null)return Ge[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var zy=j("ip4"),Vy=j("ip6"),Fy=j("ipcidr");function Ts(r,t){switch(j(r).code){case 4:case 41:return mf(t);case 42:return Bs(t);case 43:return N(t,"base10");case 6:case 273:case 33:case 132:return ja(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Bs(t);case 421:return wf(t);case 444:return Za(t);case 445:return Za(t);case 466:return bf(t);case 481:return globalThis.encodeURIComponent(Bs(t));default:return N(t,"base16")}}function _s(r,t){switch(j(r).code){case 4:return Ga(t);case 41:return Ga(t);case 42:return Rs(t);case 43:return G(t,"base10");case 6:case 273:case 33:case 132:return Ps(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Rs(t);case 421:return yf(t);case 444:return xf(t);case 445:return Ef(t);case 466:return gf(t);case 481:return Rs(globalThis.decodeURIComponent(t));default:return G(t,"base16")}}var Ls=Object.values(rr).map(r=>r.decoder),pf=function(){let r=Ls[0].or(Ls[1]);return Ls.slice(2).forEach(t=>r=r.or(t)),r}();function Ga(r){if(!cn(r))throw new Error("invalid ip address");return Ss(r)}function mf(r){let t=Wa(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!cn(t))throw new Error("invalid ip address");return t}function Ps(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function ja(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Rs(r){let t=G(r),e=Uint8Array.from(Ht(t.length));return Lt([e,t],e.length+t.length)}function Bs(r){let t=Ee(r);if(r=r.slice(St(t)),r.length!==t)throw new Error("inconsistent lengths");return N(r)}function yf(r){let t;r[0]==="Q"||r[0]==="1"?t=oe($.decode(`z${r}`)).bytes:t=tt.parse(r).multihash.bytes;let e=Uint8Array.from(Ht(t.length));return Lt([e,t],e.length+t.length)}function gf(r){let t=pf.decode(r),e=Uint8Array.from(Ht(t.length));return Lt([e,t],e.length+t.length)}function bf(r){let t=Ee(r),e=r.slice(St(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+N(e,"base64url")}function wf(r){let t=Ee(r),e=r.slice(St(t));if(e.length!==t)throw new Error("inconsistent lengths");return N(e,"base58btc")}function xf(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=kt.decode("b"+t[0]),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Ps(n);return Lt([e,o],e.length+o.length)}function Ef(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=kt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Ps(n);return Lt([e,o],e.length+o.length)}function Za(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=N(t,"base32"),o=ja(e);return`${n}:${o}`}function $a(r){r=ks(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=j(i);if(a.size===0){t.push([a.code]),e.push([a.code]);continue}if(s++,s>=o.length)throw new un("invalid address: "+r);if(a.path===!0){n=ks(o.slice(s).join("/")),t.push([a.code,_s(a.code,n)]),e.push([a.code,n]);break}let c=_s(a.code,o[s]);t.push([a.code,c]),e.push([a.code,Ts(a.code,c)])}return{string:Ya(e),bytes:ln(t),tuples:t,stringTuples:e,path:n}}function Cs(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let s=Ee(r,o),i=St(s),a=j(s),c=Af(a,r.slice(o+i));if(c===0){t.push([s]),e.push([s]),o+=i;continue}let l=r.slice(o+i,o+i+c);if(o+=c+i,o>r.length)throw new un("Invalid address Uint8Array: "+N(r,"base16"));t.push([s,l]);let u=Ts(s,l);if(e.push([s,u]),a.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:Ya(e),tuples:t,stringTuples:e,path:n}}function Ya(r){let t=[];return r.map(e=>{let n=j(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),ks(t.join("/"))}function ln(r){return Lt(r.map(t=>{let e=j(t[0]),n=Uint8Array.from(Ht(e.code));return t.length>1&&t[1]!=null&&(n=Lt([n,t[1]])),n}))}function Af(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=Ee(t instanceof Uint8Array?t:Uint8Array.from(t));return e+St(e)}}function ks(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}var un=class extends Error{static name="ParseError";name="ParseError";constructor(t){super(`Error parsing address: ${t}`)}};var vf=Symbol.for("nodejs.util.inspect.custom"),Ds=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Sf=[j("dns").code,j("dns4").code,j("dns6").code,j("dnsaddr").code],Ks=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},fn=class r{bytes;#t;#e;#r;#n;[Ds]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=Cs(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=$a(t)}else if(dn(t))e=Cs(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=j("tcp"),a=j("udp"),c=j("ip4"),l=j("ip6"),u=j("dns6"),f=j("ip6zone");for(let[g,E]of this.stringTuples())g===f.code&&(s=`%${E??""}`),Sf.includes(g)&&(e=i.name==="tcp"?"tcp":"udp",o=443,n=`${E??""}${s}`,t=g===u.code?6:4),(g===i.code||g===a.code)&&(e=j(g).name==="tcp"?"tcp":"udp",o=parseInt(E??"")),(g===c.code||g===l.code)&&(e=j(g).name==="tcp"?"tcp":"udp",n=`${E??""}${s}`,t=g===l.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({},j(t)))}protoCodes(){return this.#e.map(([t])=>t)}protoNames(){return this.#e.map(([t])=>j(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(ln(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===Ge.p2p.code&&t.push([n,o]),n===Ge["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?N($.decode(`z${n}`),"base58btc"):N(tt.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return Y(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(s=>s.resolvable);if(e==null)return[this];let n=Xa.get(e.name);if(n==null)throw new Ks(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>Vt(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)}[vf](){return`Multiaddr(${this.#t})`}};var Xa=new Map;function dn(r){return!!r?.[Ds]}function Vt(r){return new fn(r)}var Qa="libp2p-peer-record",Ja=Uint8Array.from([3,1]);var Sr;(function(r){let t;(function(n){let o;n.codec=()=>(o==null&&(o=wt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.multiaddr!=null&&s.multiaddr.byteLength>0&&(i.uint32(10),i.bytes(s.multiaddr)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={multiaddr:st(0)},l=i==null?s.len:s.pos+i;for(;s.pos<l;){let u=s.uint32();switch(u>>>3){case 1:{c.multiaddr=s.bytes();break}default:{s.skipType(u&7);break}}}return c})),o),n.encode=s=>bt(s,n.codec()),n.decode=(s,i)=>gt(s,n.codec(),i)})(t=r.AddressInfo||(r.AddressInfo={}));let e;r.codec=()=>(e==null&&(e=wt((n,o,s={})=>{if(s.lengthDelimited!==!1&&o.fork(),n.peerId!=null&&n.peerId.byteLength>0&&(o.uint32(10),o.bytes(n.peerId)),n.seq!=null&&n.seq!==0n&&(o.uint32(16),o.uint64(n.seq)),n.addresses!=null)for(let i of n.addresses)o.uint32(26),r.AddressInfo.codec().encode(i,o);s.lengthDelimited!==!1&&o.ldelim()},(n,o,s={})=>{let i={peerId: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 Se('Decode error - map field "addresses" had too many elements');i.addresses.push(r.AddressInfo.codec().decode(n,n.uint32(),{limits:s.limits?.addresses$}));break}default:{n.skipType(c&7);break}}}return i})),e),r.encode=n=>bt(n,r.codec()),r.decode=(n,o)=>gt(n,r.codec(),o)})(Sr||(Sr={}));var Ie=class r{static createFromProtobuf=t=>{let e=Sr.decode(t),n=Es(oe(e.peerId)),o=(e.addresses??[]).map(i=>Vt(i.multiaddr)),s=e.seq;return new r({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Qa;static CODEC=Ja;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=Sr.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||!Oa(this.multiaddrs,t.multiaddrs))}};function If(r){return r[Symbol.asyncIterator]!=null}function Lf(r){if(If(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 tc=Lf;function hn(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 Ir=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 hn(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 hn(this.map.values(),t=>t.key)}values(){return hn(this.map.values(),t=>t.value)}get size(){return this.map.size}};var Us=class extends Ir{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 Ns(r){let{name:t,metrics:e}=r,n;return e!=null?n=new Us({name:t,metrics:e}):n=new Ir,n}var Nt=class extends Error{static name="AbortError";name="AbortError";constructor(t="The operation was aborted",...e){super(t,...e)}};function pn(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var mn=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}},Ze=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new mn(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 mn(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 Os=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function ec(r={}){return Rf(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 Rf(r,t){t=t??{};let e=t.onEnd,n=new Ze,o,s,i,a=pn(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((I,_)=>{s=q=>{s=null,n.push(q);try{I(r(n))}catch(x){_(x)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=pn()})}},l=I=>s!=null?s(I):(n.push(I),o),u=I=>(n=new Ze,s!=null?s({error:I}):(n.push({error:I}),o)),f=I=>{if(i)return o;if(t?.objectMode!==!0&&I?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:I})},p=I=>i?o:(i=!0,I!=null?u(I):l({done:!0})),g=()=>(n=new Ze,p(),{done:!0}),E=I=>(p(I),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:g,throw:E,push:f,end:p,get readableLength(){return n.size},onEmpty:async I=>{let _=I?.signal;if(_?.throwIfAborted(),n.isEmpty())return;let q,x;_!=null&&(q=new Promise((d,b)=>{x=()=>{b(new Os)},_.addEventListener("abort",x)}));try{await Promise.race([a.promise,q])}finally{x!=null&&_!=null&&_?.removeEventListener("abort",x)}}},e==null)return o;let y=o;return o={[Symbol.asyncIterator](){return this},next(){return y.next()},throw(I){return y.throw(I),e!=null&&(e(I),e=void 0),{done:!0}},return(){return y.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(I){return y.end(I),e!=null&&(e(I),e=void 0),o},get readableLength(){return y.readableLength},onEmpty:I=>y.onEmpty(I)},o}var Ms=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 yn(r,t,e,n){let o=new Ms(n?.errorMessage,n?.errorCode);return e?.aborted===!0?Promise.reject(o):new Promise((s,i)=>{function a(){e?.removeEventListener("abort",u),r.removeEventListener(t,c),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,l)}let c=f=>{try{if(n?.filter?.(f)===!1)return}catch(p){a(),i(p);return}a(),s(f)},l=f=>{a(),i(f.detail)},u=()=>{a(),i(o)};e?.addEventListener("abort",u),r.addEventListener(t,c),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,l)})}var gn=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 rc(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 wn=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 Nt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Bf(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var xn=class{id;fn;options;recipients;status;timeline;controller;constructor(t,e){this.id=Bf(),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 Nt),this.cleanup())}async join(t={}){let e=new wn(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 rc(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 qs(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 Lr=class extends Te{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=qs(this.emitEmpty.bind(this),1),this.emitIdle=qs(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 gn;let n=new xn(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 Nt)}),this.clear()}async onEmpty(t){this.size!==0&&await yn(this,"empty",t?.signal)}async onSizeLessThan(t,e){this.size<t||await yn(this,"next",e?.signal,{filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await yn(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=ec({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 Nt("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 En="lock:worker:request-read",An="lock:worker:abort-read-request",vn="lock:worker:release-read",Sn="lock:master:grant-read",In="lock:master:error-read",Ln="lock:worker:request-write",Rn="lock:worker:abort-write-request",Bn="lock:worker:release-write",Tn="lock:master:grant-write",_n="lock:master:error-write",Pn="lock:worker:finalize",kn="mortice",nc={singleProcess:!1};var Hs=(r,t,e,n,o,s,i,a,c)=>l=>{if(l.data==null)return;let u={type:l.data.type,name:l.data.name,identifier:l.data.identifier};u.type===o&&r.safeDispatchEvent(e,{detail:{name:u.name,identifier:u.identifier,handler:async()=>{t.postMessage({type:c,name:u.name,identifier:u.identifier}),await new Promise(f=>{let p=g=>{if(g?.data==null)return;let E={type:g.data.type,name:g.data.name,identifier:g.data.identifier};E.type===a&&E.identifier===u.identifier&&(t.removeEventListener("message",p),f())};t.addEventListener("message",p)})},onError:f=>{t.postMessage({type:i,name:u.name,identifier:u.identifier,error:{message:f.message,name:f.name,stack:f.stack}})}}}),u.type===s&&r.safeDispatchEvent(n,{detail:{name:u.name,identifier:u.identifier}}),u.type===Pn&&r.safeDispatchEvent("finalizeRequest",{detail:{name:u.name}})};var oc=(r=10)=>Math.random().toString().substring(2,r+2);var Cn=class{name;channel;constructor(t){this.name=t,this.channel=new BroadcastChannel(kn)}readLock(t){return this.sendRequest(En,An,Sn,In,vn,t)}writeLock(t){return this.sendRequest(Ln,Rn,Tn,_n,Bn,t)}finalize(){this.channel.postMessage({type:Pn,name:this.name}),this.channel.close()}async sendRequest(t,e,n,o,s,i){i?.signal?.throwIfAborted();let a=oc();return this.channel.postMessage({type:t,identifier:a,name:this.name}),new Promise((c,l)=>{let u=()=>{this.channel.postMessage({type:e,identifier:a,name:this.name})};i?.signal?.addEventListener("abort",u,{once:!0});let f=p=>{if(p.data?.identifier===a&&(p.data?.type===n&&(this.channel.removeEventListener("message",f),i?.signal?.removeEventListener("abort",u),c(()=>{this.channel.postMessage({type:s,identifier:a,name:this.name})})),p.data.type===o)){this.channel.removeEventListener("message",f),i?.signal?.removeEventListener("abort",u);let g=new Error;p.data.error!=null&&(g.message=p.data.error.message,g.name=p.data.error.name,g.stack=p.data.error.stack),l(g)}};this.channel.addEventListener("message",f)})}};var sc=r=>{if(r=Object.assign({},nc,r),!!globalThis.document||r.singleProcess){let e=new BroadcastChannel(kn),n=new Te;return e.addEventListener("message",Hs(n,e,"requestReadLock","abortReadLockRequest",En,An,In,vn,Sn)),e.addEventListener("message",Hs(n,e,"requestWriteLock","abortWriteLockRequest",Ln,Rn,_n,Bn,Tn)),n}return new Cn(r.name)};var Le=new Map,Rr;function ic(r){return typeof r?.readLock=="function"&&typeof r?.writeLock=="function"}function Tf(r){if(Rr==null&&(Rr=sc(r),!ic(Rr))){let t=Rr;t.addEventListener("requestReadLock",e=>{let n=e.detail.name,o=e.detail.identifier,s=Le.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=Le.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=Le.get(n);o?.finalize()})}return Rr}async function zs(r,t){let e,n,o=new Promise((i,a)=>{e=i,n=a}),s=()=>{n(new Nt)};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 ac=(r,t)=>{let e=Le.get(r);if(e!=null)return e;let n=Tf(t);if(ic(n))return e=n,Le.set(r,e),e;let o=new Lr({concurrency:1}),s;return e={async readLock(i){if(s!=null)return zs(s,i);s=new Lr({concurrency:t.concurrency,autoStart:!1});let a=s,c=zs(s,i);return o.add(async()=>{a.start(),await a.onIdle().then(()=>{s===a&&(s=null)})}),c},async writeLock(i){return s=null,zs(o,i)},finalize:()=>{Le.delete(r)},queue:o},Le.set(r,e),e};var _f={name:"lock",concurrency:1/0,singleProcess:!1};function Vs(r){let t=Object.assign({},_f,r);return ac(t.name,t)}var ee;(function(r){let t;(function(o){let s;o.codec=()=>(s==null&&(s=wt((i,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),i.key!=null&&i.key!==""&&(a.uint32(10),a.string(i.key)),i.value!=null&&i.value.byteLength>0&&(a.uint32(18),a.bytes(i.value)),c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let l={key:"",value:st(0)},u=a==null?i.len:i.pos+a;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{l.key=i.string();break}case 2:{l.value=i.bytes();break}default:{i.skipType(f&7);break}}}return l})),s),o.encode=i=>bt(i,o.codec()),o.decode=(i,a)=>gt(i,o.codec(),a)})(t=r.Peer$metadataEntry||(r.Peer$metadataEntry={}));let e;(function(o){let s;o.codec=()=>(s==null&&(s=wt((i,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),i.key!=null&&i.key!==""&&(a.uint32(10),a.string(i.key)),i.value!=null&&(a.uint32(18),Dn.codec().encode(i.value,a)),c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let l={key:""},u=a==null?i.len:i.pos+a;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{l.key=i.string();break}case 2:{l.value=Dn.codec().decode(i,i.uint32(),{limits:c.limits?.value});break}default:{i.skipType(f&7);break}}}return l})),s),o.encode=i=>bt(i,o.codec()),o.decode=(i,a)=>gt(i,o.codec(),a)})(e=r.Peer$tagsEntry||(r.Peer$tagsEntry={}));let n;r.codec=()=>(n==null&&(n=wt((o,s,i={})=>{if(i.lengthDelimited!==!1&&s.fork(),o.addresses!=null)for(let a of o.addresses)s.uint32(10),Kn.codec().encode(a,s);if(o.protocols!=null)for(let a of o.protocols)s.uint32(18),s.string(a);if(o.publicKey!=null&&(s.uint32(34),s.bytes(o.publicKey)),o.peerRecordEnvelope!=null&&(s.uint32(42),s.bytes(o.peerRecordEnvelope)),o.metadata!=null&&o.metadata.size!==0)for(let[a,c]of o.metadata.entries())s.uint32(50),r.Peer$metadataEntry.codec().encode({key:a,value:c},s);if(o.tags!=null&&o.tags.size!==0)for(let[a,c]of o.tags.entries())s.uint32(58),r.Peer$tagsEntry.codec().encode({key:a,value:c},s);o.updated!=null&&(s.uint32(64),s.uint64Number(o.updated)),i.lengthDelimited!==!1&&s.ldelim()},(o,s,i={})=>{let a={addresses:[],protocols:[],metadata:new Map,tags:new Map},c=s==null?o.len:o.pos+s;for(;o.pos<c;){let l=o.uint32();switch(l>>>3){case 1:{if(i.limits?.addresses!=null&&a.addresses.length===i.limits.addresses)throw new Se('Decode error - map field "addresses" had too many elements');a.addresses.push(Kn.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 Se('Decode error - map field "protocols" had too many elements');a.protocols.push(o.string());break}case 4:{a.publicKey=o.bytes();break}case 5:{a.peerRecordEnvelope=o.bytes();break}case 6:{if(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(l&7);break}}}return a})),n),r.encode=o=>bt(o,r.codec()),r.decode=(o,s)=>gt(o,r.codec(),s)})(ee||(ee={}));var Kn;(function(r){let t;r.codec=()=>(t==null&&(t=wt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.multiaddr!=null&&e.multiaddr.byteLength>0&&(n.uint32(10),n.bytes(e.multiaddr)),e.isCertified!=null&&(n.uint32(16),n.bool(e.isCertified)),e.observed!=null&&(n.uint32(24),n.uint64Number(e.observed)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={multiaddr: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=>bt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Kn||(Kn={}));var Dn;(function(r){let t;r.codec=()=>(t==null&&(t=wt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.value!=null&&e.value!==0&&(n.uint32(8),n.uint32(e.value)),e.expiry!=null&&(n.uint32(16),n.uint64(e.expiry)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={value:0},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.value=e.uint32();break}case 2:{s.expiry=e.uint64();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>bt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Dn||(Dn={}));function Pf(r,t){if(r.publicKey!=null||t.publicKey==null)return r;let e;r.type==="RSA"&&(e=r.toMultihash());let n=rn(t.publicKey,e);return Ua(n)}function cc(r,t,e){let n=ee.decode(t);return je(r,n,e)}function je(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:Pf(r,t),addresses:t.addresses.filter(({observed:s})=>s!=null&&s>Date.now()-e).map(({multiaddr:s,isCertified:i})=>({multiaddr:Vt(s),isCertified:i??!1})),metadata:t.metadata,peerRecordEnvelope:t.peerRecordEnvelope??void 0,tags:n}}function uc(r,t){return kf(r.addresses,t.addresses)&&Cf(r.protocols,t.protocols)&&Kf(r.publicKey,t.publicKey)&&Df(r.peerRecordEnvelope,t.peerRecordEnvelope)&&Uf(r.metadata,t.metadata)&&Nf(r.tags,t.tags)}function kf(r,t){return fc(r,t,(e,n)=>!(e.isCertified!==n.isCertified||!Y(e.multiaddr,n.multiaddr)))}function Cf(r,t){return fc(r,t,(e,n)=>e===n)}function Kf(r,t){return lc(r,t)}function Df(r,t){return lc(r,t)}function Uf(r,t){return dc(r,t,(e,n)=>Y(e,n))}function Nf(r,t){return dc(r,t,(e,n)=>e.value===n.value&&e.expiry===n.expiry)}function lc(r,t){return r==null&&t==null?!0:r!=null&&t!=null?Y(r,t):!1}function fc(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 dc(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 re="/",hc=new TextEncoder().encode(re),Un=hc[0],Nn=class r{_buf;constructor(t,e){if(typeof t=="string")this._buf=G(t);else if(t instanceof Uint8Array)this._buf=t;else throw new Error("Invalid key, should be String of Uint8Array");if(e==null&&(e=!0),e&&this.clean(),this._buf.byteLength===0||this._buf[0]!==Un)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(re))}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=hc),this._buf[0]!==Un){let t=new Uint8Array(this._buf.byteLength+1);t.fill(Un,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Un;)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(re).slice(1)}type(){return Of(this.baseNamespace())}name(){return Mf(this.baseNamespace())}instance(t){return new r(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(re)||(t+=re),t+=this.type(),new r(t)}parent(){let t=this.list();return t.length===1?new r(re):new r(t.slice(0,-1).join(re))}child(t){return this.toString()===re?t:t.toString()===re?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(),...qf(t.map(e=>e.namespaces()))])}};function Of(r){let t=r.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function Mf(r){let t=r.split(":");return t[t.length-1]}function qf(r){return[].concat(...r)}var Fs="/peers/";function Br(r){if(!Re(r)||r.type==null)throw new z("Invalid PeerId");let t=r.toCID().toString();return new Nn(`${Fs}${t}`)}async function pc(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=Vt(i.multiaddr)),!dn(i.multiaddr))throw new z("Multiaddr was invalid");if(!await t(r,i.multiaddr,o))continue;let a=i.isCertified??!1,c=i.multiaddr.toString(),l=s.get(c);l!=null?i.isCertified=l.isCertified||a:s.set(c,{multiaddr:i.multiaddr,isCertified:a})}return[...s.values()].sort((i,a)=>i.multiaddr.toString().localeCompare(a.multiaddr.toString())).map(({isCertified:i,multiaddr:a})=>{let c=a.getPeerId();return r.equals(c)&&(a=a.decapsulate(Vt(`/p2p/${r}`))),{isCertified:i,multiaddr:a.bytes}})}async function Mn(r,t,e,n){if(t==null)throw new z("Invalid PeerData");if(t.publicKey!=null&&r.publicKey!=null&&!t.publicKey.equals(r.publicKey))throw new z("publicKey bytes do not match peer id publicKey bytes");let o=n.existingPeer?.peer;if(o!=null&&!r.equals(o.id))throw new z("peer id did not match existing peer id");let s=o?.addresses??[],i=new Set(o?.protocols??[]),a=o?.metadata??new Map,c=o?.tags??new Map,l=o?.peerRecordEnvelope;if(e==="patch"){if((t.multiaddrs!=null||t.addresses!=null)&&(s=[],t.multiaddrs!=null&&s.push(...t.multiaddrs.map(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=On(p,{validate:mc})}if(t.tags!=null){let p=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags);c=On(p,{validate:yc,map:gc})}t.peerRecordEnvelope!=null&&(l=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[g,E]of p)E==null?a.delete(g):a.set(g,E);a=On([...a.entries()],{validate:mc})}if(t.tags!=null){let p=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags),g=new Map(c);for(let[E,y]of p)y==null?g.delete(E):g.set(E,y);c=On([...g.entries()],{validate:yc,map:gc})}t.peerRecordEnvelope!=null&&(l=t.peerRecordEnvelope)}let u;o?.id.publicKey!=null?u=Tt(o.id.publicKey):t.publicKey!=null?u=Tt(t.publicKey):r.publicKey!=null&&(u=Tt(r.publicKey));let f={addresses:await pc(r,n.addressFilter??(async()=>!0),s,n.existingPeer?.peerPB.addresses,n),protocols:[...i.values()].sort((p,g)=>p.localeCompare(g)),metadata:a,tags:c,publicKey:u,peerRecordEnvelope:l};return f.addresses.forEach(p=>{p.observed=n.existingPeer?.peerPB.addresses?.find(g=>Y(g.multiaddr,g.multiaddr))?.observed??Date.now()}),r.type!=="RSA"&&delete f.publicKey,f}function On(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 mc(r,t){if(typeof r!="string")throw new z("Metadata key must be a string");if(!(t instanceof Uint8Array))throw new z("Metadata value must be a Uint8Array")}function yc(r,t){if(typeof r!="string")throw new z("Tag name must be a string");if(t.value!=null){if(parseInt(`${t.value}`,10)!==t.value)throw new z("Tag value must be an integer");if(t.value<0||t.value>100)throw new z("Tag value must be between 0-100")}if(t.ttl!=null){if(parseInt(`${t.ttl}`,10)!==t.ttl)throw new z("Tag ttl must be an integer");if(t.ttl<0)throw new z("Tag ttl must be between greater than 0")}}function gc(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 bc(r){let t=r.toString().split("/")[2],e=tt.parse(t,kt);return nn(e)}function Ws(r,t,e){let n=bc(r);return cc(n,t,e)}function Hf(r,t){return{prefix:Fs,filters:(r.filters??[]).map(e=>({key:n,value:o})=>e(Ws(n,o,t))),orders:(r.orders??[]).map(e=>(n,o)=>e(Ws(n.key,n.value,t),Ws(o.key,o.value,t)))}}var qn=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=Ns({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:Vs({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(Br(t),e)}async load(t,e){let n=Br(t),o=await this.datastore.get(n,e),s=ee.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,e),new Ye;return je(t,s,this.peerId.equals(t)?1/0:this.maxAddressAge)}async save(t,e,n){let o=await this.#t(t,n),s=await Mn(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 Mn(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 Mn(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(Hf(t??{},this.maxAddressAge),t)){let o=bc(e);if(o.equals(this.peerId))continue;let s=ee.decode(n);if(this.#r(o,s)){await this.datastore.delete(e,t);continue}yield je(o,s,this.peerId.equals(o)?1/0:this.maxAddressAge)}}async#t(t,e){try{let n=Br(t),o=await this.datastore.get(n,e),s=ee.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,e),new Ye;return{peerPB:s,peer:je(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=ee.encode(e);return await this.datastore.put(Br(t),s,o),{peer:je(t,e,this.maxAddressAge),previous:n?.peer,updated:n==null||!uc(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 Gs=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 qn(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 tc(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=Re(e)?e:Re(e?.expectedPeer)?e.expectedPeer:void 0,s=Re(e)||e===void 0?n:e,i=await Fe.openAndCertify(t,Ie.DOMAIN,s),a=nn(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=Ie.createFromProtobuf(i.payload),l;try{l=await this.get(a,s)}catch(u){if(u.name!=="NotFoundError")throw u}if(l?.peerRecordEnvelope!=null){let u=Fe.createFromProtobuf(l.peerRecordEnvelope),f=Ie.createFromProtobuf(u.payload);if(f.seqNumber>=c.seqNumber)return this.log("sequence number was lower or equal to existing sequence number - stored: %d received: %d",f.seqNumber,c.seqNumber),!1}return await this.patch(c.peerId,{peerRecordEnvelope:t,addresses:c.multiaddrs.map(u=>({isCertified:!0,multiaddr:u}))},s),!0}#t(t,e){e.updated&&(this.peerId.equals(t)?this.events.safeDispatchEvent("self:peer:update",{detail:e}):this.events.safeDispatchEvent("peer:update",{detail:e}))}};function zf(r,t={}){return new Gs(r,t)}return Rc(Vf);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/hashes/esm/utils.js: