@libp2p/peer-store 11.2.2-b8600fce8 → 11.2.2-bb4ad31db

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 qn=Object.defineProperty;var vc=Object.getOwnPropertyDescriptor;var Ac=Object.getOwnPropertyNames;var Sc=Object.prototype.hasOwnProperty;var Et=(r,t)=>{for(var e in t)qn(r,e,{get:t[e],enumerable:!0})},Ic=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ac(t))!Sc.call(r,o)&&o!==e&&qn(r,o,{get:()=>t[o],enumerable:!(n=vc(t,o))||n.enumerable});return r};var Lc=r=>Ic(qn({},"__esModule",{value:!0}),r);var qf={};Et(qf,{persistentPeerStore:()=>Mf});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 Wn={};Et(Wn,{base58btc:()=>j,base58flickr:()=>Cc});var Ff=new Uint8Array(0);function Gs(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Vt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function Zs(r){return new TextEncoder().encode(r)}function $s(r){return new TextDecoder().decode(r)}function Rc(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 w=(q-_)*u+1>>>0,d=new Uint8Array(w);_!==q;){for(var b=E[_],L=0,R=w-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=w-I;B!==w&&d[B]===0;)B++;for(var K=c.repeat(y);B<w;++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,w=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*w[L]>>>0,w[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&&w[R]===0;)R++;for(var B=new Uint8Array(I+(q-R)),K=I;R!==q;)B[K++]=w[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 Bc=Rc,Tc=Bc,Ys=Tc;var Hn=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")}},zn=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 Xs(this,t)}},Vn=class{decoders;constructor(t){this.decoders=t}or(t){return Xs(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 Xs(r,t){return new Vn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Fn=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 Hn(t,e,n),this.decoder=new zn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Te({name:r,prefix:t,encode:e,decode:n}){return new Fn(r,t,e,n)}function re({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Ys(e,r);return Te({prefix:t,name:r,encode:n,decode:s=>Vt(o(s))})}function _c(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 Pc(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 kc(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=kc(n);return Te({prefix:t,name:r,encode(s){return Pc(s,n,e)},decode(s){return _c(s,o,e,r)}})}var j=re({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Cc=re({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Gn={};Et(Gn,{base32:()=>Pt,base32hex:()=>Nc,base32hexpad:()=>Mc,base32hexpadupper:()=>qc,base32hexupper:()=>Oc,base32pad:()=>Dc,base32padupper:()=>Uc,base32upper:()=>Kc,base32z:()=>Hc});var Pt=J({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Kc=J({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Dc=J({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Uc=J({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Nc=J({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Oc=J({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Mc=J({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),qc=J({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Hc=J({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Zn={};Et(Zn,{base36:()=>Xe,base36upper:()=>zc});var Xe=re({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),zc=re({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Vc=ti,Qs=128,Fc=127,Wc=~Fc,Gc=Math.pow(2,31);function ti(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Gc;)t[e++]=r&255|Qs,r/=128;for(;r&Wc;)t[e++]=r&255|Qs,r>>>=7;return t[e]=r|0,ti.bytes=e-n+1,t}var Zc=$n,$c=128,Js=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&Js)<<o:(i&Js)*Math.pow(2,o),o+=7}while(i>=$c);return $n.bytes=s-n,e}var jc=Math.pow(2,7),Yc=Math.pow(2,14),Xc=Math.pow(2,21),Qc=Math.pow(2,28),Jc=Math.pow(2,35),tu=Math.pow(2,42),eu=Math.pow(2,49),ru=Math.pow(2,56),nu=Math.pow(2,63),ou=function(r){return r<jc?1:r<Yc?2:r<Xc?3:r<Qc?4:r<Jc?5:r<tu?6:r<eu?7:r<ru?8:r<nu?9:10},su={encode:Vc,decode:Zc,encodingLength:ou},iu=su,Qe=iu;function Je(r,t=0){return[Qe.decode(r,t),Qe.decode.bytes]}function _e(r,t,e=0){return Qe.encode(r,t,e),t}function Pe(r){return Qe.encodingLength(r)}function kt(r,t){let e=t.byteLength,n=Pe(r),o=n+Pe(e),s=new Uint8Array(o+e);return _e(r,s,0),_e(e,s,n),s.set(t,o),new ke(r,e,t,s)}function ne(r){let t=Vt(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 ke(e,o,i,t)}function ei(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Gs(r.bytes,e.bytes)}}var ke=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function ri(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return cu(e,jn(r),t??j.encoder);default:return uu(e,jn(r),t??Pt.encoder)}}var ni=new WeakMap;function jn(r){let t=ni.get(r);if(t==null){let e=new Map;return ni.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!==lu)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=kt(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&&ei(t.multihash,n.multihash)}toString(t){return ri(this,t)}toJSON(){return{"/":ri(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??oi(n,o,s.bytes))}else if(e[fu]===!0){let{version:n,multihash:o,code:s}=e,i=ne(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=oi(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,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=Vt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new ke(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]=au(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 jn(s).set(n,t),s}};function au(r,t){switch(r[0]){case"Q":{let e=t??j;return[j.prefix,e.decode(`${j.prefix}${r}`)]}case j.prefix:{let e=t??j;return[j.prefix,e.decode(r)]}case Pt.prefix:{let e=t??Pt;return[Pt.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 cu(r,t,e){let{prefix:n}=e;if(n!==j.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 uu(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,lu=18;function oi(r,t,e){let n=Pe(r),o=n+Pe(t),s=new Uint8Array(o+e.byteLength);return _e(r,s,0),_e(t,s,n),s.set(e,o),s}var fu=Symbol.for("@ipld/js-cid/CID");var Yn={};Et(Yn,{identity:()=>Ct});var si=0,du="identity",ii=Vt;function hu(r){return kt(si,ii(r))}var Ct={code:si,name:du,encode:ii,digest:hu};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 vt(r=0){return new Uint8Array(r)}function Lt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=vt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var ci=Symbol.for("@achingbrain/uint8arraylist");function ai(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?.[ci]}var pt=class r{bufs;length;[ci]=!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=ai(this.bufs,t);return e.buf[e.index]}set(t,e){let n=ai(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=vt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=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=vt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=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 Xn={};Et(Xn,{base10:()=>pu});var pu=re({prefix:"9",name:"base10",alphabet:"0123456789"});var Qn={};Et(Qn,{base16:()=>mu,base16upper:()=>yu});var mu=J({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),yu=J({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Jn={};Et(Jn,{base2:()=>gu});var gu=J({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var to={};Et(to,{base256emoji:()=>vu});var ui=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}"),bu=ui.reduce((r,t,e)=>(r[e]=t,r),[]),xu=ui.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function wu(r){return r.reduce((t,e)=>(t+=bu[e],t),"")}function Eu(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=Te({prefix:"\u{1F680}",name:"base256emoji",encode:wu,decode:Eu});var eo={};Et(eo,{base64:()=>Au,base64pad:()=>Su,base64url:()=>Iu,base64urlpad:()=>Lu});var Au=J({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Su=J({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Iu=J({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Lu=J({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ro={};Et(ro,{base8:()=>Ru});var Ru=J({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var no={};Et(no,{identity:()=>Bu});var Bu=Te({prefix:"\0",name:"identity",encode:r=>$s(r),decode:r=>Zs(r)});var Rd=new TextEncoder,Bd=new TextDecoder;var io={};Et(io,{sha256:()=>er,sha512:()=>Pu});function so({name:r,code:t,encode:e}){return new oo(r,t,e)}var oo=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?kt(this.code,e):e.then(n=>kt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function fi(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var er=so({name:"sha2-256",code:18,encode:fi("SHA-256")}),Pu=so({name:"sha2-512",code:19,encode:fi("SHA-512")});var rr={...no,...Jn,...ro,...Xn,...Qn,...Gn,...Zn,...Wn,...eo,...to},qd={...io,...Yn};function hi(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var di=hi("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ao=hi("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=vt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),ku={utf8:di,"utf-8":di,hex:rr.base16,latin1:ao,ascii:ao,binary:ao,...rr},Kr=ku;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 Cu=parseInt("11111",2),co=parseInt("10000000",2),Ku=parseInt("01111111",2),pi={0:nr,1:nr,2:Du,3:Ou,4:Mu,5:Nu,6:Uu,16:nr,22:nr,48:nr};function Wt(r,t={offset:0}){let e=r[t.offset]&Cu;if(t.offset++,pi[e]!=null)return pi[e](r,t);throw new Error("No decoder for tag "+e)}function or(r,t){let e=0;if((r[t.offset]&co)===co){let n=r[t.offset]&Ku,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=Wt(r,t);if(n===null)break;e.push(n)}return e}function Du(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 Uu(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 Nu(r,t){return t.offset++,null}function Ou(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 Mu(r,t){let e=or(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function qu(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 uo(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=qu(r.byteLength);return new pt(Uint8Array.from([t.byteLength|co]),t)}function At(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]),uo(t),t)}function Dr(r){let t=Uint8Array.from([0]),e=new pt(t,r);return new pt(Uint8Array.from([3]),uo(e),e)}function oe(r,t=48){let e=new pt;for(let n of r)e.append(n);return new pt(Uint8Array.from([t]),uo(e),e)}async function mi(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 Hu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),zu=Uint8Array.from([6,5,43,129,4,0,34]),Vu=Uint8Array.from([6,5,43,129,4,0,35]),Fu={ext:!0,kty:"EC",crv:"P-256"},Wu={ext:!0,kty:"EC",crv:"P-384"},Gu={ext:!0,kty:"EC",crv:"P-521"},lo=32,fo=48,ho=66;function po(r){let t=Wt(r);return yi(t)}function yi(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===lo*2+1)return n=N(t.subarray(e,e+lo),"base64url"),o=N(t.subarray(e+lo),"base64url"),new Ce({...Fu,key_ops:["verify"],x:n,y:o});if(t.byteLength===fo*2+1)return n=N(t.subarray(e,e+fo),"base64url"),o=N(t.subarray(e+fo),"base64url"),new Ce({...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 Ce({...Gu,key_ops:["verify"],x:n,y:o});throw new z(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function gi(r){return oe([At(Uint8Array.from([1])),oe([Zu(r.crv)],160),oe([Dr(new pt(Uint8Array.from([4]),G(r.x??"","base64url"),G(r.y??"","base64url")))],161)]).subarray()}function Zu(r){if(r==="P-256")return Hu;if(r==="P-384")return zu;if(r==="P-521")return Vu;throw new z(`Invalid curve ${r}`)}var Ce=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=gi(this.jwk)),this._raw}toMultihash(){return Ct.digest(Tt(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return j.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 mi(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 bi(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 De(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function xi(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 Gt(...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 Kt(r,t){return r<<32-t|r>>>t}function wi(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=wi(r)),pe(r),r}function mo(...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 Ke=class{};function yo(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 ju(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 Ei(r,t,e){return r&t^~r&e}function vi(r,t,e){return r&t^r&e^t&e}var ir=class extends Ke{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){De(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){De(this),xi(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Gt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)e[f]=0;ju(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()}},Zt=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),Ai=BigInt(32);function Yu(r,t=!1){return t?{h:Number(r&Mr),l:Number(r>>Ai&Mr)}:{h:Number(r>>Ai&Mr)|0,l:Number(r&Mr)|0}}function Si(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}=Yu(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var go=(r,t,e)=>r>>>e,bo=(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 Nt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Ii=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Li=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Ri=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Bi=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Ti=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),_i=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Qu=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]),se=new Uint32Array(64),qr=class extends ir{constructor(t=32){super(64,t,8,!1),this.A=Zt[0]|0,this.B=Zt[1]|0,this.C=Zt[2]|0,this.D=Zt[3]|0,this.E=Zt[4]|0,this.F=Zt[5]|0,this.G=Zt[6]|0,this.H=Zt[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let f=0;f<16;f++,e+=4)se[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let p=se[f-15],g=se[f-2],E=Kt(p,7)^Kt(p,18)^p>>>3,y=Kt(g,17)^Kt(g,19)^g>>>10;se[f]=y+se[f-7]+E+se[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=Kt(a,6)^Kt(a,11)^Kt(a,25),g=u+p+Ei(a,c,l)+Qu[f]+se[f]|0,y=(Kt(n,2)^Kt(n,13)^Kt(n,22))+vi(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(){Gt(se)}destroy(){this.set(0,0,0,0,0,0,0,0),Gt(this.buffer)}};var Pi=Si(["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=Pi[0],tl=Pi[1],ie=new Uint32Array(80),ae=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 w=0;w<16;w++,e+=4)ie[w]=t.getUint32(e),ae[w]=t.getUint32(e+=4);for(let w=16;w<80;w++){let d=ie[w-15]|0,b=ae[w-15]|0,L=me(d,b,1)^me(d,b,8)^go(d,b,7),R=ye(d,b,1)^ye(d,b,8)^bo(d,b,7),B=ie[w-2]|0,K=ae[w-2]|0,O=me(B,K,19)^ar(B,K,61)^go(B,K,6),P=ye(B,K,19)^cr(B,K,61)^bo(B,K,6),D=Ri(R,P,ae[w-7],ae[w-16]),C=Bi(D,L,O,ie[w-7],ie[w-16]);ie[w]=C|0,ae[w]=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 w=0;w<80;w++){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=Ti(q,b,R,tl[w],ae[w]),K=_i(B,_,d,L,Ju[w],ie[w]),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}=Nt(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 A=Ii(O,D,nt);n=Li(A,K,P,C),o=A|0}({h:n,l:o}=Nt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Nt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Nt(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:u}=Nt(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:p}=Nt(this.Eh|0,this.El|0,f|0,p|0),{h:g,l:E}=Nt(this.Fh|0,this.Fl|0,g|0,E|0),{h:y,l:I}=Nt(this.Gh|0,this.Gl|0,y|0,I|0),{h:_,l:q}=Nt(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(){Gt(ie,ae)}destroy(){Gt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Hr=yo(()=>new qr);var ki=yo(()=>new xo);var Ao=BigInt(0),vo=BigInt(1);function Ue(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function So(r){if(!Ue(r))throw new Error("Uint8Array expected")}function Ot(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 Di(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Ao:BigInt("0x"+r)}var Ui=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",el=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function ce(r){if(So(r),Ui)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=el[r[e]];return t}var $t={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ci(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(Ui)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=Ci(r.charCodeAt(s)),a=Ci(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 jt(r){return Di(ce(r))}function ge(r){return So(r),Di(ce(Uint8Array.from(r).reverse()))}function be(r,t){return lr(r.toString(16).padStart(t*2,"0"))}function Ne(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(Ue(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 ue(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];So(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 wo=r=>typeof r=="bigint"&&Ao<=r;function zr(r,t,e){return wo(r)&&wo(t)&&wo(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 Ni(r){let t;for(t=0;r>Ao;r>>=vo,t+=1);return t}var xe=r=>(vo<<BigInt(r))-vo,Eo=r=>new Uint8Array(r),Ki=r=>Uint8Array.from(r);function Oi(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=Eo(r),o=Eo(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},a=(...f)=>e(o,n,...f),c=(f=Eo(0))=>{o=a(Ki([0]),f),n=a(),f.length!==0&&(o=a(Ki([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 ue(...p)};return(f,p)=>{i(),c(f);let g;for(;!(g=p(l()));)c();return i(),g}}var rl={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"||Ue(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 Yt(r,t,e={}){let n=(o,s,i)=>{let a=rl[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 Oe(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var mt=BigInt(0),at=BigInt(1),we=BigInt(2),nl=BigInt(3),qi=BigInt(4),Hi=BigInt(5),zi=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 Vi(r,t){let e=(r.ORDER+at)/qi,n=r.pow(t,e);if(!r.eql(r.sqr(n),t))throw new Error("Cannot find square root");return n}function ol(r,t){let e=(r.ORDER-Hi)/zi,n=r.mul(t,we),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,we),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 sl(r){if(r<BigInt(3))throw new Error("sqrt is not defined for small field");let t=r-at,e=0;for(;t%we===mt;)t/=we,e++;let n=we,o=Xt(r);for(;Mi(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return Vi;let s=o.pow(n,t),i=(t+at)/we;return function(c,l){if(c.is0(l))return l;if(Mi(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 il(r){return r%qi===nl?Vi:r%zi===Hi?ol:sl(r)}var Fi=(r,t)=>(Z(r,t)&at)===at,al=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Io(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=al.reduce((n,o)=>(n[o]="function",n),t);return Yt(r,e)}function cl(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 Me(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 Mi(r,t){let e=(r.ORDER-at)/we,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&&Ur(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Xt(r,t,e=!1,n={}){if(r<=mt)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:xe(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)=>cl(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=il(r)),i(a,c))),toBytes:c=>e?Ne(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):jt(c)},invertBatch:c=>Me(a,c),cmov:(c,l,u)=>u?l:c});return Object.freeze(a)}function Wi(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 Ro(r){let t=Wi(r);return t+Math.ceil(t/2)}function Gi(r,t,e=!1){let n=r.length,o=Wi(t),s=Ro(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?ge(r):jt(r),a=Z(i,t-at)+at;return e?Ne(a,o):be(a,o)}var Zi=BigInt(0),ko=BigInt(1);function Bo(r,t){let e=t.negate();return r?e:t}function ji(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function To(r,t){ji(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=xe(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function $i(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+=ko);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 ul(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 ll(r,t){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}var _o=new WeakMap,Yi=new WeakMap;function Po(r){return Yi.get(r)||1}function Fr(r,t){return{constTimeNegate:Bo,hasPrecomputes(e){return Po(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>Zi;)n&ko&&(o=o.add(s)),s=s.double(),n>>=ko;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=To(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=To(e,t);for(let c=0;c<a.windows;c++){let{nextN:l,offset:u,isZero:f,isNeg:p,isNegF:g,offsetF:E}=$i(o,c,a);o=l,f?i=i.add(Bo(g,n[E])):s=s.add(Bo(p,n[u]))}return{p:s,f:i}},wNAFUnsafe(e,n,o,s=r.ZERO){let i=To(e,t);for(let a=0;a<i.windows&&o!==Zi;a++){let{nextN:c,offset:l,isZero:u,isNeg:f}=$i(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=_o.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&_o.set(n,o(s))),s},wNAFCached(e,n,o){let s=Po(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=Po(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){ji(n,t),Yi.set(e,n),_o.delete(e)}}}function Wr(r,t,e,n){ul(e,r),ll(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=Ni(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let l=xe(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 Io(r.Fp),Yt(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 Mt=BigInt(0),yt=BigInt(1),Xi=BigInt(2),fl=BigInt(8),dl={zip215:!0};function hl(r){let t=fr(r);return Yt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Qi(r){let t=hl(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:a,h:c}=t,l=Xi<<BigInt(a*8)-yt,u=e.create,f=Xt(t.n,t.nBitLength);function p(x,h){let m=e.sqr(x),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||((x,h)=>{try{return{isValid:!0,value:e.sqrt(x*e.inv(h))}}catch{return{isValid:!1,value:Mt}}}),E=t.adjustScalarBytes||(x=>x),y=t.domain||((x,h,m)=>{if(Ot("phflag",m),h.length||m)throw new Error("Contexts/pre-hash are not supported");return x});function I(x,h,m=!1){let S=m?yt:Mt;Rt("coordinate "+x,h,S,l)}function _(x){if(!(x instanceof d))throw new Error("ExtendedPoint expected")}let q=Oe((x,h)=>{let{ex:m,ey:S,ez:k}=x,U=x.is0();h==null&&(h=U?fl:e.inv(k));let M=u(m*h),H=u(S*h),V=u(k*h);if(U)return{x:Mt,y:yt};if(V!==yt)throw new Error("invZ was invalid");return{x:M,y:H}}),w=Oe(x=>{let{a:h,d:m}=t;if(x.is0())throw new Error("bad point: ZERO");let{ex:S,ey:k,ez:U,et:M}=x,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)),wt=u(ot+u(m*u(H*V)));if(ut!==wt)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=Me(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(){w(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(Xi*u(k*k)),V=u(h*U),W=m+S,ot=u(u(W*W)-U-M),et=V+M,ut=et-H,wt=V-M,it=u(ot*ut),ft=u(et*wt),It=u(ot*wt),_t=u(ut*et);return new d(it,ft,_t,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),wt=u(U*W),it=u(H*S*et),ft=u(M*ot),It=u((k+U)*(V+W)-ut-wt),_t=ft-it,je=ft+it,Ws=u(wt-m*ut),bc=u(It*_t),xc=u(je*Ws),wc=u(It*Ws),Ec=u(_t*je);return new d(bc,xc,Ec,wc)}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,Mt,n),S===Mt?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),Ot("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,Mt,W);let ot=u(V*V),et=u(ot-yt),ut=u(S*ot-k),{isValid:wt,value:it}=g(et,ut);if(!wt)throw new Error("Point.fromHex: invalid y coordinate");let ft=(it&yt)===yt,It=(H&128)!==0;if(!m&&it===Mt&&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=Ne(m,e.BYTES);return S[S.length-1]|=h&yt?128:0,S}toHex(){return ce(this.toRawBytes())}}d.BASE=new d(t.Gx,t.Gy,yt,u(t.Gx*t.Gy)),d.ZERO=new d(Mt,yt,yt,Mt);let{BASE:b,ZERO:L}=d,R=Fr(d,a*8);function B(x){return Z(x,n)}function K(x){return B(ge(x))}function O(x){let h=e.BYTES;x=X("private key",x,h);let m=X("hashed private key",s(x),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(x){let{head:h,prefix:m,scalar:S}=O(x),k=b.multiply(S),U=k.toRawBytes();return{head:h,prefix:m,scalar:S,point:k,pointBytes:U}}function D(x){return P(x).pointBytes}function C(x=Uint8Array.of(),...h){let m=ue(...h);return K(s(y(m,X("context",x),!!o)))}function nt(x,h,m={}){x=X("message",x),o&&(x=o(x));let{prefix:S,scalar:k,pointBytes:U}=P(h),M=C(m.context,S,x),H=b.multiply(M).toRawBytes(),V=C(m.context,H,U,x),W=B(M+V*k);Rt("signature.s",W,Mt,n);let ot=ue(H,Ne(W,e.BYTES));return X("result",ot,e.BYTES*2)}let A=dl;function v(x,h,m,S=A){let{context:k,zip215:U}=S,M=e.BYTES;x=X("signature",x,2*M),h=X("message",h),m=X("publicKey",m,M),U!==void 0&&Ot("zip215",U),o&&(h=o(h));let H=ge(x.slice(M,2*M)),V,W,ot;try{V=d.fromHex(m,U),W=d.fromHex(x.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:v,ExtendedPoint:d,utils:{getExtendedPublicKey:P,randomPrivateKey:()=>i(e.BYTES),precompute(x=8,h=d.BASE){return h._setWindowSize(x),h.multiply(BigInt(3)),h}}}}var Co=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Ji=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Vh=BigInt(0),pl=BigInt(1),ta=BigInt(2),Fh=BigInt(3),ml=BigInt(5),yl=BigInt(8);function gl(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=Co,a=r*r%s*r%s,c=Q(a,ta,s)*a%s,l=Q(c,pl,s)*r%s,u=Q(l,ml,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,ta,s)*r%s,b2:a}}function bl(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function xl(r,t){let e=Co,n=Z(t*t*t,e),o=Z(n*n*t,e),s=gl(r*o).pow_p_5_8,i=Z(r*n*s,e),a=Z(t*i*i,e),c=i,l=Z(i*Ji,e),u=a===r,f=a===Z(-r,e),p=a===Z(-r*Ji,e);return u&&(i=c),(f||p)&&(i=l),Fi(i,e)&&(i=Z(-i,e)),{isValid:u||f,value:i}}var ea=Xt(Co,void 0,!0),wl={a:ea.create(BigInt(-1)),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:ea,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:yl,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:ki,randomBytes:Or,adjustScalarBytes:bl,uvRatio:xl},ra=Qi(wl);var Gr=32;function na(r,t,e){return ra.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var Zr=class{type="Ed25519";raw;constructor(t){this.raw=Ko(t,Gr)}toMultihash(){return Ct.digest(Tt(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return j.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 n?.signal?.throwIfAborted(),na(this.raw,e,t)}};function Do(r){return r=Ko(r,Gr),new Zr(r)}function Ko(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 vl=Math.pow(2,7),Al=Math.pow(2,14),Sl=Math.pow(2,21),Uo=Math.pow(2,28),No=Math.pow(2,35),Oo=Math.pow(2,42),Mo=Math.pow(2,49),F=128,dt=127;function St(r){if(r<vl)return 1;if(r<Al)return 2;if(r<Sl)return 3;if(r<Uo)return 4;if(r<No)return 5;if(r<Oo)return 6;if(r<Mo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function qo(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 Il(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 Ho(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)*Uo,e<F)||(e=r[t+5],n+=(e&dt)*No,e<F)||(e=r[t+6],n+=(e&dt)*Oo,e<F)||(e=r[t+7],n+=(e&dt)*Mo,e<F))return n;throw new RangeError("Could not decode varint")}function Ll(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)*Uo,e<F)||(e=r.get(t+5),n+=(e&dt)*No,e<F)||(e=r.get(t+6),n+=(e&dt)*Oo,e<F)||(e=r.get(t+7),n+=(e&dt)*Mo,e<F))return n;throw new RangeError("Could not decode varint")}function qt(r,t,e=0){return t==null&&(t=vt(St(r))),t instanceof Uint8Array?qo(r,t,e):Il(r,t,e)}function Ee(r,t=0){return r instanceof Uint8Array?Ho(r,t):Ll(r,t)}var Vo=new Float32Array([-0]),le=new Uint8Array(Vo.buffer);function sa(r,t,e){Vo[0]=r,t[e]=le[0],t[e+1]=le[1],t[e+2]=le[2],t[e+3]=le[3]}function ia(r,t){return le[0]=r[t],le[1]=r[t+1],le[2]=r[t+2],le[3]=r[t+3],Vo[0]}var Fo=new Float64Array([-0]),ht=new Uint8Array(Fo.buffer);function aa(r,t,e){Fo[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 ca(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],Fo[0]}var Rl=BigInt(Number.MAX_SAFE_INTEGER),Bl=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 ve;if(t<Rl&&t>Bl)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>ua&&(o=0n,++n>ua&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return ve;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):ve}},ve=new Bt(0,0);ve.toBigInt=function(){return 0n};ve.zzEncode=ve.zzDecode=function(){return this};ve.length=function(){return 1};var ua=4294967296n;function la(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 fa(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 Wo(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 Dt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function $r(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Go=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,Dt(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 Dt(this,4);return $r(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Dt(this,4);return $r(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Dt(this,4);let t=ia(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Dt(this,4);let t=ca(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw Dt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return fa(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Dt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Dt(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 Dt(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 Dt(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 Dt(this,8);let t=$r(this.buf,this.pos+=4),e=$r(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=Ho(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 Zo(r){return new Go(r instanceof Uint8Array?r:r.subarray())}function gt(r,t,e){let n=Zo(r);return t.decode(n,void 0,e)}function $o(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return vt(i);o+i>t&&(n=vt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Ae=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function jo(){}var Xo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Tl=$o();function _l(r){return globalThis.Buffer!=null?vt(r):Tl(r)}var hr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ae(jo,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Ae(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Qo((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,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(jr,e.length(),e)}uint64Number(t){return this._push(qo,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(jr,e.length(),e)}sint64Number(t){let e=Bt.fromNumber(t).zzEncode();return this._push(jr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Yo,1,t?1:0)}fixed32(t){return this._push(dr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Bt.fromBigInt(t);return this._push(dr,4,e.lo)._push(dr,4,e.hi)}fixed64Number(t){let e=Bt.fromNumber(t);return this._push(dr,4,e.lo)._push(dr,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(sa,4,t)}double(t){return this._push(aa,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Yo,1,0):this.uint32(e)._push(kl,e,t)}string(t){let e=la(t);return e!==0?this.uint32(e)._push(Wo,e,t):this._push(Yo,1,0)}fork(){return this.states=new Xo(this),this.head=this.tail=new Ae(jo,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Ae(jo,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=_l(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Yo(r,t,e){t[e]=r&255}function Pl(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Qo=class extends Ae{next;constructor(t,e){super(Pl,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 dr(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 kl(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(hr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Cl,t,r),this},hr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Kl,t,r),this});function Cl(r,t,e){t.set(r,e)}function Kl(r,t,e){r.length<40?Wo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(G(r),e)}function Jo(){return new hr}function bt(r,t){let e=Jo();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var qe;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(qe||(qe={}));function Yr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function ts(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 Yr("enum",qe.VARINT,e,n)}function xt(r,t){return Yr("message",qe.LENGTH_DELIMITED,r,t)}var Se=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"},pr=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 es;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(es||(es={}));(function(r){r.codec=()=>ts(es)})(rt||(rt={}));var Ht;(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=>bt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Ht||(Ht={}));var rs;(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=>bt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(rs||(rs={}));var mr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Xr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var pa={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Xr("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var fe=pa;var gr={};Et(gr,{MAX_RSA_KEY_SIZE:()=>ns,generateRSAKeyPair:()=>ba,jwkToJWKKeyPair:()=>xa,jwkToPkcs1:()=>Ol,jwkToPkix:()=>as,jwkToRSAPrivateKey:()=>fs,pkcs1MessageToJwk:()=>ss,pkcs1MessageToRSAPrivateKey:()=>cs,pkcs1ToJwk:()=>Nl,pkcs1ToRSAPrivateKey:()=>ga,pkixMessageToJwk:()=>is,pkixMessageToRSAPublicKey:()=>ls,pkixToJwk:()=>Ml,pkixToRSAPublicKey:()=>us});var Qr=Hr;var He=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 j.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 ya(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 ma(this.jwk,t,e)}};var ns=8192,os=18,Dl=1062,Ul=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Nl(r){let t=Wt(r);return ss(t)}function ss(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 Ol(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 oe([At(Uint8Array.from([0])),At(G(r.n,"base64url")),At(G(r.e,"base64url")),At(G(r.d,"base64url")),At(G(r.p,"base64url")),At(G(r.q,"base64url")),At(G(r.dp,"base64url")),At(G(r.dq,"base64url")),At(G(r.qi,"base64url"))]).subarray()}function Ml(r){let t=Wt(r,{offset:0});return is(t)}function is(r){let t=Wt(r[1],{offset:0});return{kty:"RSA",n:N(t[0],"base64url"),e:N(t[1],"base64url")}}function as(r){if(r.n==null||r.e==null)throw new z("JWK was missing components");return oe([Ul,Dr(oe([At(G(r.n,"base64url")),At(G(r.e,"base64url"))]))]).subarray()}function ga(r){let t=Wt(r);return cs(t)}function cs(r){let t=ss(r);return fs(t)}function us(r,t){if(r.byteLength>=Dl)throw new Be("Key size is too large");let e=Wt(r,{offset:0});return ls(e,r,t)}function ls(r,t,e){let n=is(r);if(e==null){let o=Qr(Ht.encode({Type:rt.RSA,Data:t}));e=kt(os,o)}return new He(n,e)}function fs(r){if(Ea(r)>ns)throw new z("Key size is too large");let t=xa(r),e=Qr(Ht.encode({Type:rt.RSA,Data:as(t.publicKey)})),n=kt(os,e);return new yr(t.privateKey,new He(t.publicKey,n))}async function ba(r){if(r>ns)throw new z("Key size is too large");let t=await wa(r),e=Qr(Ht.encode({Type:rt.RSA,Data:as(t.publicKey)})),n=kt(os,e);return new yr(t.privateKey,new He(t.publicKey,n))}function xa(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 wa(r,t){let e=await fe.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 ql(e,t);return{privateKey:n[0],publicKey:n[1]}}async function ma(r,t,e){let n=await fe.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);e?.signal?.throwIfAborted();let o=await fe.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 ya(r,t,e,n){let o=await fe.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await fe.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,e instanceof Uint8Array?e:e.subarray());return n?.signal?.throwIfAborted(),s}async function ql(r,t){if(r.privateKey==null||r.publicKey==null)throw new z("Private and public key are required");let e=await Promise.all([fe.get().subtle.exportKey("jwk",r.privateKey),fe.get().subtle.exportKey("jwk",r.publicKey)]);return t?.signal?.throwIfAborted(),e}function Ea(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 Jr=class extends Ke{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,bi(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),Gt(s)}update(t){return De(this),this.iHash.update(t),this}digestInto(t){De(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()}},ds=(r,t,e)=>new Jr(r,t).update(e).digest();ds.create=(r,t)=>new Jr(r,t);function va(r){r.lowS!==void 0&&Ot("lowS",r.lowS),r.prehash!==void 0&&Ot("prehash",r.prehash)}function Hl(r){let t=fr(r);Yt(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 ms=class extends Error{constructor(t=""){super(t)}},Qt={Err:ms,_tlv:{encode:(r,t)=>{let{Err:e}=Qt;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}=Qt,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}=Qt;if(r<Jt)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}=Qt;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 jt(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Qt,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}=Qt,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 hs(r,t){return ce(be(r,t))}var Jt=BigInt(0),ct=BigInt(1),g0=BigInt(2),ps=BigInt(3),zl=BigInt(4);function Vl(r){let t=Hl(r),{Fp:e}=t,n=Xt(t.n,t.nBitLength),o=t.toBytes||((w,d,b)=>{let L=d.toAffine();return ue(Uint8Array.from([4]),e.toBytes(L.x),e.toBytes(L.y))}),s=t.fromBytes||(w=>{let d=w.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(w){let{a:d,b}=t,L=e.sqr(w),R=e.mul(L,w);return e.add(e.add(R,e.mul(w,d)),b)}function a(w,d){let b=e.sqr(d),L=i(w);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,ps),zl),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(w){return zr(w,ct,t.n)}function f(w){let{allowedPrivateKeyLengths:d,nByteLength:b,wrapPrivateKey:L,n:R}=t;if(d&&typeof w!="bigint"){if(Ue(w)&&(w=ce(w)),typeof w!="string"||!d.includes(w.length))throw new Error("invalid private key");w=w.padStart(b*2,"0")}let B;try{B=typeof w=="bigint"?w:jt(X("private key",w,b))}catch{throw new Error("invalid private key, expected hex or "+b+" bytes, got "+typeof w)}return L&&(B=Z(B,R)),Rt("private key",B,ct,R),B}function p(w){if(!(w instanceof y))throw new Error("ProjectivePoint expected")}let g=Oe((w,d)=>{let{px:b,py:L,pz:R}=w;if(e.eql(R,e.ONE))return{x:b,y:L};let B=w.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=Oe(w=>{if(w.is0()){if(t.allowInfinityPoint&&!e.is0(w.py))return;throw new Error("bad point: ZERO")}let{x:d,y:b}=w.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(!w.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=Me(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,ps),{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),A=e.mul(K,K),v=e.mul(R,B);return v=e.add(v,v),D=e.mul(R,K),D=e.add(D,D),O=e.mul(d,D),P=e.mul(L,A),P=e.add(O,P),O=e.sub(nt,P),P=e.add(nt,P),P=e.mul(O,P),O=e.mul(v,O),D=e.mul(L,D),A=e.mul(d,A),v=e.sub(C,A),v=e.mul(d,v),v=e.add(v,D),D=e.add(C,C),C=e.add(D,C),C=e.add(C,A),C=e.mul(C,v),P=e.add(P,C),A=e.mul(B,K),A=e.add(A,A),C=e.mul(A,v),O=e.sub(O,C),D=e.mul(A,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,A=e.mul(t.b,ps),v=e.mul(b,B),T=e.mul(L,K),x=e.mul(R,O),h=e.add(b,L),m=e.add(B,K);h=e.mul(h,m),m=e.add(v,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(v,x),m=e.sub(m,S),S=e.add(L,R),P=e.add(K,O),S=e.mul(S,P),P=e.add(T,x),S=e.sub(S,P),C=e.mul(nt,m),P=e.mul(A,x),C=e.add(P,C),P=e.sub(T,C),C=e.add(T,C),D=e.mul(P,C),T=e.add(v,v),T=e.add(T,v),x=e.mul(nt,x),m=e.mul(A,m),T=e.add(T,x),x=e.sub(v,x),x=e.mul(nt,x),m=e.add(m,x),v=e.mul(T,m),D=e.add(D,v),v=e.mul(S,m),P=e.mul(h,P),P=e.sub(P,v),v=e.mul(h,T),C=e.mul(S,C),C=e.add(C,v),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,Jt,L);let R=y.ZERO;if(d===Jt)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>Jt||P>Jt;)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:A,f:v}=this.wNAF(D);C=q.constTimeNegate(K,C),A=q.constTimeNegate(P,A),A=new y(e.mul(A.px,b.beta),A.py,A.pz),R=C.add(A),B=nt.add(v)}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===Jt||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 Ot("isCompressed",d),this.assertValidity(),o(y,this,d)}toHex(d=!0){return Ot("isCompressed",d),ce(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 Fl(r){let t=fr(r);return Yt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Aa(r){let t=Fl(r),{Fp:e,n,nByteLength:o,nBitLength:s}=t,i=e.BYTES+1,a=2*e.BYTES+1;function c(A){return Z(A,n)}function l(A){return Vr(A,n)}let{ProjectivePoint:u,normPrivateKeyToScalar:f,weierstrassEquation:p,isWithinCurveOrder:g}=Vl({...t,toBytes(A,v,T){let x=v.toAffine(),h=e.toBytes(x.x),m=ue;return Ot("isCompressed",T),T?m(Uint8Array.from([v.hasEvenY()?2:3]),h):m(Uint8Array.from([4]),h,e.toBytes(x.y))},fromBytes(A){let v=A.length,T=A[0],x=A.subarray(1);if(v===i&&(T===2||T===3)){let h=jt(x);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(v===a&&T===4){let h=e.fromBytes(x.subarray(0,e.BYTES)),m=e.fromBytes(x.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 "+v)}}});function E(A){let v=n>>ct;return A>v}function y(A){return E(A)?c(-A):A}let I=(A,v,T)=>jt(A.slice(v,T));class _{constructor(v,T,x){Rt("r",v,ct,n),Rt("s",T,ct,n),this.r=v,this.s=T,x!=null&&(this.recovery=x),Object.freeze(this)}static fromCompact(v){let T=o;return v=X("compactSignature",v,T*2),new _(I(v,0,T),I(v,T,2*T))}static fromDER(v){let{r:T,s:x}=Qt.toSig(X("DER",v));return new _(T,x)}assertValidity(){}addRecoveryBit(v){return new _(this.r,this.s,v)}recoverPublicKey(v){let{r:T,s:x,recovery:h}=this,m=R(X("msgHash",v));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+hs(S,e.BYTES)),M=l(S),H=c(-m*M),V=c(x*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 Qt.hexFromSig(this)}toCompactRawBytes(){return lr(this.toCompactHex())}toCompactHex(){let v=o;return hs(this.r,v)+hs(this.s,v)}}let q={isValidPrivateKey(A){try{return f(A),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let A=Ro(t.n);return Gi(t.randomBytes(A),t.n)},precompute(A=8,v=u.BASE){return v._setWindowSize(A),v.multiply(BigInt(3)),v}};function w(A,v=!0){return u.fromPrivateKey(A).toRawBytes(v)}function d(A){if(typeof A=="bigint")return!1;if(A instanceof u)return!0;let T=X("key",A).length,x=e.BYTES,h=x+1,m=2*x+1;if(!(t.allowedPrivateKeyLengths||o===h))return T===h||T===m}function b(A,v,T=!0){if(d(A)===!0)throw new Error("first arg must be private key");if(d(v)===!1)throw new Error("second arg must be public key");return u.fromHex(v).multiply(f(A)).toRawBytes(T)}let L=t.bits2int||function(A){if(A.length>8192)throw new Error("input is too large");let v=jt(A),T=A.length*8-s;return T>0?v>>BigInt(T):v},R=t.bits2int_modN||function(A){return c(L(A))},B=xe(s);function K(A){return Rt("num < 2^"+s,A,Jt,B),be(A,o)}function O(A,v,T=P){if(["recovered","canonical"].some(et=>et in T))throw new Error("sign() legacy options not supported");let{hash:x,randomBytes:h}=t,{lowS:m,prehash:S,extraEntropy:k}=T;m==null&&(m=!0),A=X("msgHash",A),va(T),S&&(A=X("prehashed msgHash",x(A)));let U=R(A),M=f(v),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=ue(...H),W=U;function ot(et){let ut=L(et);if(!g(ut))return;let wt=l(ut),it=u.BASE.multiply(ut).toAffine(),ft=c(it.x);if(ft===Jt)return;let It=c(wt*c(W+ft*M));if(It===Jt)return;let _t=(it.x===ft?0:2)|Number(it.y&ct),je=It;return m&&E(It)&&(je=y(It),_t^=1),new _(ft,je,_t)}return{seed:V,k2sig:ot}}let P={lowS:t.lowS,prehash:!1},D={lowS:t.lowS,prehash:!1};function C(A,v,T=P){let{seed:x,k2sig:h}=O(A,v,T),m=t;return Oi(m.hash.outputLen,m.nByteLength,m.hmac)(x,h)}u.BASE._setWindowSize(8);function nt(A,v,T,x=D){let h=A;v=X("msgHash",v),T=X("publicKey",T);let{lowS:m,prehash:S,format:k}=x;if(va(x),"strict"in x)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"||Ue(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(_t){if(!(_t instanceof Qt.Err))throw _t}!H&&k!=="der"&&(H=_.fromCompact(h))}V=u.fromHex(T)}catch{return!1}if(!H||m&&H.hasHighS())return!1;S&&(v=t.hash(v));let{r:W,s:ot}=H,et=R(v),ut=l(ot),wt=c(et*ut),it=c(W*ut),ft=u.BASE.multiplyAndAddUnsafe(V,wt,it)?.toAffine();return ft?c(ft.x)===W:!1}return{CURVE:t,getPublicKey:w,getSharedSecret:b,sign:C,verify:nt,ProjectivePoint:u,Signature:_,utils:q}}function Wl(r){return{hash:r,hmac:(t,...e)=>ds(r,t,mo(...e)),randomBytes:Or}}function Sa(r,t){let e=n=>Aa({...r,...Wl(n)});return{...e(t),create:e}}var Ra=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Ia=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Gl=BigInt(0),Zl=BigInt(1),ys=BigInt(2),La=(r,t)=>(r+t/ys)/t;function $l(r){let t=Ra,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),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,ys,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,w=Q(q,e,t)*u%t,d=Q(w,i,t)*E%t,b=Q(d,n,t)*l%t,L=Q(b,ys,t);if(!gs.eql(gs.sqr(L),r))throw new Error("Cannot find square root");return L}var gs=Xt(Ra,void 0,void 0,{sqrt:$l}),ze=Sa({a:Gl,b:BigInt(7),Fp:gs,n:Ia,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Ia,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Zl*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),a=La(s*r,t),c=La(-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 Ba(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Ta(r,t,e,n){let o=er.digest(e instanceof Uint8Array?e:e.subarray());if(Ba(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),ze.verify(t,s,r))).catch(s=>{throw s.name==="AbortError"?s:new mr(String(s))});try{return n?.signal?.throwIfAborted(),ze.verify(t,o.digest,r)}catch(s){throw new mr(String(s))}}var tn=class{type="secp256k1";raw;_key;constructor(t){this._key=Pa(t),this.raw=_a(this._key)}toMultihash(){return Ct.digest(Tt(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return j.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 Ta(this._key,e,t,n)}};function bs(r){return new tn(r)}function _a(r){return ze.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Pa(r){try{return ze.ProjectivePoint.fromHex(r),r}catch(t){throw new Be(String(t))}}function en(r,t){let{Type:e,Data:n}=Ht.decode(r),o=n??new Uint8Array;switch(e){case rt.RSA:return us(o,t);case rt.Ed25519:return Do(o);case rt.secp256k1:return bs(o);case rt.ECDSA:return po(o);default:throw new de}}function ka(r){let{Type:t,Data:e}=Ht.decode(r.digest),n=e??new Uint8Array;switch(t){case rt.Ed25519:return Do(n);case rt.secp256k1:return bs(n);case rt.ECDSA:return po(n);default:throw new de}}function Tt(r){return Ht.encode({Type:rt[r.type],Data:r.raw})}var Ca=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=j.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")}[Ca](){return`PeerId(${this.toString()})`}},xr=class extends br{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},wr=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}},Yl=2336,vr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Ct.digest(G(this.url))}[Ca](){return`PeerId(${this.url})`}[Tr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return tt.createV1(Yl,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=N(t)),t.toString()===this.toString())}};var Xl=114,Ka=2336;function Da(r){if(r.type==="Ed25519")return new wr({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 xr({multihash:r.toCID().multihash,publicKey:r});throw new de}function xs(r){if(Jl(r))return new xr({multihash:r});if(Ql(r))try{let t=ka(r);if(t.type==="Ed25519")return new wr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new Er({multihash:r,publicKey:t})}catch{let e=N(r.digest);return new vr(new URL(e))}throw new Pr("Supplied PeerID Multihash is invalid")}function rn(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==Xl&&r.code!==Ka)throw new _r("Supplied PeerID CID is invalid");if(r.code===Ka){let t=N(r.multihash.digest);return new vr(new URL(t))}return xs(r.multihash)}function Ql(r){return r.code===Ct.code}function Jl(r){return r.code===er.code}var Ar;(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=>bt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Ar||(Ar={}));var nn=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var Ve=class r{static createFromProtobuf=t=>{let e=Ar.decode(t),n=en(e.publicKey);return new r({publicKey:n,payloadType:e.payloadType,payload:e.payload,signature:e.signature})};static seal=async(t,e,n)=>{if(e==null)throw new Error("Missing private key");let o=t.domain,s=t.codec,i=t.marshal(),a=Ua(o,s,i),c=await e.sign(a.subarray(),n);return new r({publicKey:e.publicKey,payloadType:s,payload:i,signature:c})};static openAndCertify=async(t,e,n)=>{let o=r.createFromProtobuf(t);if(!await o.validate(e,n))throw new nn("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(t){let{publicKey:e,payloadType:n,payload:o,signature:s}=t;this.publicKey=e,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=Ar.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=Ua(t,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,e)}},Ua=(r,t,e)=>{let n=G(r),o=qt(n.byteLength),s=qt(t.length),i=qt(e.length);return new pt(o,n,s,t,i,e)};function Na(r,t){let e=(n,o)=>n.toString().localeCompare(o.toString());return r.length!==t.length?!1:(t.sort(e),r.sort(e).every((n,o)=>t[o].equals(n)))}var on=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",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 Oa=45,tf=15,Fe=new on;function ws(r){if(!(r.length>tf))return Fe.new(r).parseWith(()=>Fe.readIPv4Addr())}function Es(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Oa))return Fe.new(r).parseWith(()=>Fe.readIPv6Addr())}function sn(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>Oa)return;let e=Fe.new(r).parseWith(()=>Fe.readIPAddr());if(e)return t&&e.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,e[0],e[1],e[2],e[3]]):e}var Xm=parseInt("0xFFFF",16),Qm=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Ha(r){return!!ws(r)}function za(r){return!!Es(r)}function an(r){return!!sn(r)}var Va=Ha,sf=za,vs=function(r){let t=0;if(r=r.toString().trim(),Va(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(sf(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=Va(e[n]),i;s&&(i=vs(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")},Fa=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 We={},As={},cf=[[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"]];cf.forEach(r=>{let t=uf(...r);As[t.code]=t,We[t.name]=t});function uf(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function $(r){if(typeof r=="number"){if(As[r]!=null)return As[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(We[r]!=null)return We[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Dy=$("ip4"),Uy=$("ip6"),Ny=$("ipcidr");function Rs(r,t){switch($(r).code){case 4:case 41:return ff(t);case 42:return Ls(t);case 43:return N(t,"base10");case 6:case 273:case 33:case 132:return Za(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Ls(t);case 421:return mf(t);case 444:return Ga(t);case 445:return Ga(t);case 466:return pf(t);case 481:return globalThis.encodeURIComponent(Ls(t));default:return N(t,"base16")}}function Bs(r,t){switch($(r).code){case 4:return Wa(t);case 41:return Wa(t);case 42:return Is(t);case 43:return G(t,"base10");case 6:case 273:case 33:case 132:return Ts(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Is(t);case 421:return df(t);case 444:return yf(t);case 445:return gf(t);case 466:return hf(t);case 481:return Is(globalThis.decodeURIComponent(t));default:return G(t,"base16")}}var Ss=Object.values(rr).map(r=>r.decoder),lf=function(){let r=Ss[0].or(Ss[1]);return Ss.slice(2).forEach(t=>r=r.or(t)),r}();function Wa(r){if(!an(r))throw new Error("invalid ip address");return vs(r)}function ff(r){let t=Fa(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!an(t))throw new Error("invalid ip address");return t}function Ts(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Za(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Is(r){let t=G(r),e=Uint8Array.from(qt(t.length));return Lt([e,t],e.length+t.length)}function Ls(r){let t=Ee(r);if(r=r.slice(St(t)),r.length!==t)throw new Error("inconsistent lengths");return N(r)}function df(r){let t;r[0]==="Q"||r[0]==="1"?t=ne(j.decode(`z${r}`)).bytes:t=tt.parse(r).multihash.bytes;let e=Uint8Array.from(qt(t.length));return Lt([e,t],e.length+t.length)}function hf(r){let t=lf.decode(r),e=Uint8Array.from(qt(t.length));return Lt([e,t],e.length+t.length)}function pf(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 mf(r){let t=Ee(r),e=r.slice(St(t));if(e.length!==t)throw new Error("inconsistent lengths");return N(e,"base58btc")}function yf(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=Pt.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=Ts(n);return Lt([e,o],e.length+o.length)}function gf(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=Pt.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=Ts(n);return Lt([e,o],e.length+o.length)}function Ga(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=N(t,"base32"),o=Za(e);return`${n}:${o}`}function $a(r){r=_s(r);let t=[],e=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let s=0;s<o.length;s++){let i=o[s],a=$(i);if(a.size===0){t.push([a.code]),e.push([a.code]);continue}if(s++,s>=o.length)throw new cn("invalid address: "+r);if(a.path===!0){n=_s(o.slice(s).join("/")),t.push([a.code,Bs(a.code,n)]),e.push([a.code,n]);break}let c=Bs(a.code,o[s]);t.push([a.code,c]),e.push([a.code,Rs(a.code,c)])}return{string:ja(e),bytes:un(t),tuples:t,stringTuples:e,path:n}}function Ps(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let s=Ee(r,o),i=St(s),a=$(s),c=bf(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 cn("Invalid address Uint8Array: "+N(r,"base16"));t.push([s,l]);let u=Rs(s,l);if(e.push([s,u]),a.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:ja(e),tuples:t,stringTuples:e,path:n}}function ja(r){let t=[];return r.map(e=>{let n=$(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),_s(t.join("/"))}function un(r){return Lt(r.map(t=>{let e=$(t[0]),n=Uint8Array.from(qt(e.code));return t.length>1&&t[1]!=null&&(n=Lt([n,t[1]])),n}))}function bf(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 _s(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}var cn=class extends Error{static name="ParseError";name="ParseError";constructor(t){super(`Error parsing address: ${t}`)}};var xf=Symbol.for("nodejs.util.inspect.custom"),Cs=Symbol.for("@multiformats/js-multiaddr/multiaddr"),wf=[$("dns").code,$("dns4").code,$("dns6").code,$("dnsaddr").code],ks=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},ln=class r{bytes;#t;#e;#r;#n;[Cs]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=Ps(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(fn(t))e=Ps(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=$("tcp"),a=$("udp"),c=$("ip4"),l=$("ip6"),u=$("dns6"),f=$("ip6zone");for(let[g,E]of this.stringTuples())g===f.code&&(s=`%${E??""}`),wf.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=$(g).name==="tcp"?"tcp":"udp",o=parseInt(E??"")),(g===c.code||g===l.code)&&(e=$(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({},$(t)))}protoCodes(){return this.#e.map(([t])=>t)}protoNames(){return this.#e.map(([t])=>$(t).name)}tuples(){return this.#e.map(([t,e])=>e==null?[t]:[t,e])}stringTuples(){return this.#r.map(([t,e])=>e==null?[t]:[t,e])}encapsulate(t){return t=new r(t),new r(this.toString()+t.toString())}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o))}decapsulateCode(t){let e=this.tuples();for(let n=e.length-1;n>=0;n--)if(e[n][0]===t)return new r(un(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===We.p2p.code&&t.push([n,o]),n===We["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?N(j.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=Ya.get(e.name);if(n==null)throw new ks(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>zt(s))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[xf](){return`Multiaddr(${this.#t})`}};var Ya=new Map;function fn(r){return!!r?.[Cs]}function zt(r){return new ln(r)}var Xa="libp2p-peer-record",Qa=Uint8Array.from([3,1]);var Sr;(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=>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=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 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=xs(ne(e.peerId)),o=(e.addresses??[]).map(i=>zt(i.multiaddr)),s=e.seq;return new r({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Xa;static CODEC=Qa;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||!Na(this.multiaddrs,t.multiaddrs))}};function Ef(r){return r[Symbol.asyncIterator]!=null}function vf(r){if(Ef(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 Ja=vf;function dn(r,t){let e={[Symbol.iterator]:()=>e,next:()=>{let n=r.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return e}var 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 dn(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((e,n)=>{t(e.value,e.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,e){this.map.set(t.toString(),{key:t,value:e})}keys(){return dn(this.map.values(),t=>t.key)}values(){return dn(this.map.values(),t=>t.value)}get size(){return this.map.size}};var Ks=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 Ds(r){let{name:t,metrics:e}=r,n;return e!=null?n=new Ks({name:t,metrics:e}):n=new Ir,n}var Ut=class extends Error{static name="AbortError";name="AbortError";constructor(t="The operation was aborted",...e){super(t,...e)}};function hn(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var pn=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},Ge=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new pn(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new pn(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var Us=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function tc(r={}){return Af(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 Af(r,t){t=t??{};let e=t.onEnd,n=new Ge,o,s,i,a=hn(),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(w){_(w)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=hn()})}},l=I=>s!=null?s(I):(n.push(I),o),u=I=>(n=new Ge,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 Ge,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,w;_!=null&&(q=new Promise((d,b)=>{w=()=>{b(new Us)},_.addEventListener("abort",w)}));try{await Promise.race([a.promise,q])}finally{w!=null&&_!=null&&_?.removeEventListener("abort",w)}}},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 Ze=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 Ns=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=e??"ABORT_ERR"}};async function mn(r,t,e,n){let o=new Ns(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 yn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};var gn=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 ec(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new gn(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new gn(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 bn=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 Ut)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function If(){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=If(),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 Ut),this.cleanup())}async join(t={}){let e=new bn(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 ec(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 Os(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 Ze{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=Os(this.emitEmpty.bind(this),1),this.emitIdle=Os(this.emitIdle.bind(this),1)}[Symbol.asyncIterator](){return this.toGenerator()}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}tryToStartAnother(){if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let t;for(let e of this.queue)if(e.status==="queued"){t=e;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let e=0;e<this.queue.length;e++)if(this.queue[e]===t){this.queue.splice(e,1);break}this.pending--,this.safeDispatchEvent("next"),this.autoStart&&this.tryToStartAnother()}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}start(){this.autoStart===!1&&(this.autoStart=!0,this.tryToStartAnother())}pause(){this.autoStart=!1}async add(t,e){if(e?.signal?.throwIfAborted(),this.size===this.maxSize)throw new yn;let n=new 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 Ut)}),this.clear()}async onEmpty(t){this.size!==0&&await mn(this,"empty",t?.signal)}async onSizeLessThan(t,e){this.size<t||await mn(this,"next",e?.signal,{filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await mn(this,"idle",t?.signal)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(t){t?.signal?.throwIfAborted();let e=tc({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 Ut("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 wn="lock:worker:request-read",En="lock:worker:abort-read-request",vn="lock:worker:release-read",An="lock:master:grant-read",Sn="lock:master:error-read",In="lock:worker:request-write",Ln="lock:worker:abort-write-request",Rn="lock:worker:release-write",Bn="lock:master:grant-write",Tn="lock:master:error-write",_n="lock:worker:finalize",Pn="mortice",rc={singleProcess:!1};var Ms=(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===_n&&r.safeDispatchEvent("finalizeRequest",{detail:{name:u.name}})};var nc=(r=10)=>Math.random().toString().substring(2,r+2);var kn=class{name;channel;constructor(t){this.name=t,this.channel=new BroadcastChannel(Pn)}readLock(t){return this.sendRequest(wn,En,An,Sn,vn,t)}writeLock(t){return this.sendRequest(In,Ln,Bn,Tn,Rn,t)}finalize(){this.channel.postMessage({type:_n,name:this.name}),this.channel.close()}async sendRequest(t,e,n,o,s,i){i?.signal?.throwIfAborted();let a=nc();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 oc=r=>{if(r=Object.assign({},rc,r),!!globalThis.document||r.singleProcess){let e=new BroadcastChannel(Pn),n=new Ze;return e.addEventListener("message",Ms(n,e,"requestReadLock","abortReadLockRequest",wn,En,Sn,vn,An)),e.addEventListener("message",Ms(n,e,"requestWriteLock","abortWriteLockRequest",In,Ln,Tn,Rn,Bn)),n}return new kn(r.name)};var Le=new Map,Rr;function sc(r){return typeof r?.readLock=="function"&&typeof r?.writeLock=="function"}function Lf(r){if(Rr==null&&(Rr=oc(r),!sc(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 qs(r,t){let e,n,o=new Promise((i,a)=>{e=i,n=a}),s=()=>{n(new Ut)};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 ic=(r,t)=>{let e=Le.get(r);if(e!=null)return e;let n=Lf(t);if(sc(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 qs(s,i);s=new Lr({concurrency:t.concurrency,autoStart:!1});let a=s,c=qs(s,i);return o.add(async()=>{a.start(),await a.onIdle().then(()=>{s===a&&(s=null)})}),c},async writeLock(i){return s=null,qs(o,i)},finalize:()=>{Le.delete(r)},queue:o},Le.set(r,e),e};var Rf={name:"lock",concurrency:1/0,singleProcess:!1};function Hs(r){let t=Object.assign({},Rf,r);return ic(t.name,t)}var te;(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=>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=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),Kn.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=Kn.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=xt((o,s,i={})=>{if(i.lengthDelimited!==!1&&s.fork(),o.addresses!=null)for(let a of o.addresses)s.uint32(10),Cn.codec().encode(a,s);if(o.protocols!=null)for(let a of o.protocols)s.uint32(18),s.string(a);if(o.publicKey!=null&&(s.uint32(34),s.bytes(o.publicKey)),o.peerRecordEnvelope!=null&&(s.uint32(42),s.bytes(o.peerRecordEnvelope)),o.metadata!=null&&o.metadata.size!==0)for(let[a,c]of o.metadata.entries())s.uint32(50),r.Peer$metadataEntry.codec().encode({key:a,value:c},s);if(o.tags!=null&&o.tags.size!==0)for(let[a,c]of o.tags.entries())s.uint32(58),r.Peer$tagsEntry.codec().encode({key:a,value:c},s);o.updated!=null&&(s.uint32(64),s.uint64Number(o.updated)),i.lengthDelimited!==!1&&s.ldelim()},(o,s,i={})=>{let a={addresses:[],protocols:[],metadata:new Map,tags:new Map},c=s==null?o.len:o.pos+s;for(;o.pos<c;){let 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(Cn.codec().decode(o,o.uint32(),{limits:i.limits?.addresses$}));break}case 2:{if(i.limits?.protocols!=null&&a.protocols.length===i.limits.protocols)throw new 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 pr('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 pr('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)})(te||(te={}));var Cn;(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=>bt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Cn||(Cn={}));var Kn;(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=>bt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Kn||(Kn={}));function Bf(r,t){if(r.publicKey!=null||t.publicKey==null)return r;let e;r.type==="RSA"&&(e=r.toMultihash());let n=en(t.publicKey,e);return Da(n)}function ac(r,t,e){let n=te.decode(t);return $e(r,n,e)}function $e(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:Bf(r,t),addresses:t.addresses.filter(({observed:s})=>s!=null&&s>Date.now()-e).map(({multiaddr:s,isCertified:i})=>({multiaddr:zt(s),isCertified:i??!1})),metadata:t.metadata,peerRecordEnvelope:t.peerRecordEnvelope??void 0,tags:n}}function cc(r,t){return Tf(r.addresses,t.addresses)&&_f(r.protocols,t.protocols)&&Pf(r.publicKey,t.publicKey)&&kf(r.peerRecordEnvelope,t.peerRecordEnvelope)&&Cf(r.metadata,t.metadata)&&Kf(r.tags,t.tags)}function Tf(r,t){return lc(r,t,(e,n)=>!(e.isCertified!==n.isCertified||!Y(e.multiaddr,n.multiaddr)))}function _f(r,t){return lc(r,t,(e,n)=>e===n)}function Pf(r,t){return uc(r,t)}function kf(r,t){return uc(r,t)}function Cf(r,t){return fc(r,t,(e,n)=>Y(e,n))}function Kf(r,t){return fc(r,t,(e,n)=>e.value===n.value&&e.expiry===n.expiry)}function uc(r,t){return r==null&&t==null?!0:r!=null&&t!=null?Y(r,t):!1}function lc(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 fc(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 ee="/",dc=new TextEncoder().encode(ee),Dn=dc[0],Un=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]!==Dn)throw new Error("Invalid key")}toString(t="utf8"){return N(this._buf,t)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(t){return new r(t.join(ee))}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=dc),this._buf[0]!==Dn){let t=new Uint8Array(this._buf.byteLength+1);t.fill(Dn,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Dn;)this._buf=this._buf.subarray(0,-1)}less(t){let e=this.list(),n=t.list();for(let o=0;o<e.length;o++){if(n.length<o+1)return!1;let s=e[o],i=n[o];if(s<i)return!0;if(s>i)return!1}return e.length<n.length}reverse(){return r.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let t=this.namespaces();return t[t.length-1]}list(){return this.toString().split(ee).slice(1)}type(){return Df(this.baseNamespace())}name(){return Uf(this.baseNamespace())}instance(t){return new r(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(ee)||(t+=ee),t+=this.type(),new r(t)}parent(){let t=this.list();return t.length===1?new r(ee):new r(t.slice(0,-1).join(ee))}child(t){return this.toString()===ee?t:t.toString()===ee?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(),...Nf(t.map(e=>e.namespaces()))])}};function Df(r){let t=r.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function Uf(r){let t=r.split(":");return t[t.length-1]}function Nf(r){return[].concat(...r)}var zs="/peers/";function Br(r){if(!Re(r)||r.type==null)throw new z("Invalid PeerId");let t=r.toCID().toString();return new Un(`${zs}${t}`)}async function hc(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=zt(i.multiaddr)),!fn(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(zt(`/p2p/${r}`))),{isCertified:i,multiaddr:a.bytes}})}async function On(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=Nn(p,{validate:pc})}if(t.tags!=null){let p=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags);c=Nn(p,{validate:mc,map:yc})}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=Nn([...a.entries()],{validate:pc})}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=Nn([...g.entries()],{validate:mc,map:yc})}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 hc(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 Nn(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 pc(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 mc(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 yc(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 gc(r){let t=r.toString().split("/")[2],e=tt.parse(t,Pt);return rn(e)}function Vs(r,t,e){let n=gc(r);return ac(n,t,e)}function Of(r,t){return{prefix:zs,filters:(r.filters??[]).map(e=>({key:n,value:o})=>e(Vs(n,o,t))),orders:(r.orders??[]).map(e=>(n,o)=>e(Vs(n.key,n.value,t),Vs(o.key,o.value,t)))}}var Mn=class{peerId;datastore;locks;addressFilter;log;maxAddressAge;maxPeerAge;constructor(t,e={}){this.log=t.logger.forComponent("libp2p:peer-store"),this.peerId=t.peerId,this.datastore=t.datastore,this.addressFilter=e.addressFilter,this.locks=Ds({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:Hs({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=te.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,e),new Ye;return $e(t,s,this.peerId.equals(t)?1/0:this.maxAddressAge)}async save(t,e,n){let o=await this.#t(t,n),s=await On(t,e,"patch",{...n,addressFilter:this.addressFilter});return this.#e(t,s,o)}async patch(t,e,n){let o=await this.#t(t,n),s=await On(t,e,"patch",{...n,addressFilter:this.addressFilter,existingPeer:o});return this.#e(t,s,o)}async merge(t,e,n){let o=await this.#t(t,n),s=await On(t,e,"merge",{addressFilter:this.addressFilter,existingPeer:o});return this.#e(t,s,o)}async*all(t){for await(let{key:e,value:n}of this.datastore.query(Of(t??{},this.maxAddressAge),t)){let o=gc(e);if(o.equals(this.peerId))continue;let s=te.decode(n);if(this.#r(o,s)){await this.datastore.delete(e,t);continue}yield $e(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=te.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,e),new Ye;return{peerPB:s,peer:$e(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=te.encode(e);return await this.datastore.put(Br(t),s,o),{peer:$e(t,e,this.maxAddressAge),previous:n?.peer,updated:n==null||!cc(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 Fs=class{store;events;peerId;log;constructor(t,e={}){this.log=t.logger.forComponent("libp2p:peer-store"),this.events=t.events,this.peerId=t.peerId,this.store=new Mn(t,e)}[Symbol.toStringTag]="@libp2p/peer-store";async forEach(t,e){for await(let n of this.store.all(e))t(n)}async all(t){return Ja(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 Ve.openAndCertify(t,Ie.DOMAIN,s),a=rn(i.publicKey.toCID());if(o?.equals(a)===!1)return this.log("envelope peer id was not the expected peer id - expected: %p received: %p",o,a),!1;let c=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=Ve.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 Mf(r,t={}){return new Fs(r,t)}return Lc(qf);})();
2
+ "use strict";var Libp2PPeerStore=(()=>{var qn=Object.defineProperty;var vc=Object.getOwnPropertyDescriptor;var Ac=Object.getOwnPropertyNames;var Sc=Object.prototype.hasOwnProperty;var Et=(r,t)=>{for(var e in t)qn(r,e,{get:t[e],enumerable:!0})},Ic=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ac(t))!Sc.call(r,o)&&o!==e&&qn(r,o,{get:()=>t[o],enumerable:!(n=vc(t,o))||n.enumerable});return r};var Lc=r=>Ic(qn({},"__esModule",{value:!0}),r);var Mf={};Et(Mf,{persistentPeerStore:()=>Of});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 Wn={};Et(Wn,{base58btc:()=>j,base58flickr:()=>Cc});var Ff=new Uint8Array(0);function Gs(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Vt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function Zs(r){return new TextEncoder().encode(r)}function $s(r){return new TextDecoder().decode(r)}function Rc(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 w=(q-_)*u+1>>>0,d=new Uint8Array(w);_!==q;){for(var b=E[_],L=0,R=w-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=w-I;B!==w&&d[B]===0;)B++;for(var K=c.repeat(y);B<w;++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,w=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*w[L]>>>0,w[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&&w[R]===0;)R++;for(var B=new Uint8Array(I+(q-R)),K=I;R!==q;)B[K++]=w[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 Bc=Rc,Tc=Bc,Ys=Tc;var Hn=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")}},zn=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 Xs(this,t)}},Vn=class{decoders;constructor(t){this.decoders=t}or(t){return Xs(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 Xs(r,t){return new Vn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Fn=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 Hn(t,e,n),this.decoder=new zn(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 Fn(r,t,e,n)}function re({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Ys(e,r);return _e({prefix:t,name:r,encode:n,decode:s=>Vt(o(s))})}function _c(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 Pc(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 kc(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=kc(n);return _e({prefix:t,name:r,encode(s){return Pc(s,n,e)},decode(s){return _c(s,o,e,r)}})}var j=re({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Cc=re({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Gn={};Et(Gn,{base32:()=>Pt,base32hex:()=>Nc,base32hexpad:()=>Mc,base32hexpadupper:()=>qc,base32hexupper:()=>Oc,base32pad:()=>Dc,base32padupper:()=>Uc,base32upper:()=>Kc,base32z:()=>Hc});var Pt=J({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Kc=J({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Dc=J({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Uc=J({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Nc=J({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Oc=J({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Mc=J({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),qc=J({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Hc=J({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Zn={};Et(Zn,{base36:()=>Xe,base36upper:()=>zc});var Xe=re({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),zc=re({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Vc=ti,Qs=128,Fc=127,Wc=~Fc,Gc=Math.pow(2,31);function ti(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Gc;)t[e++]=r&255|Qs,r/=128;for(;r&Wc;)t[e++]=r&255|Qs,r>>>=7;return t[e]=r|0,ti.bytes=e-n+1,t}var Zc=$n,$c=128,Js=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&Js)<<o:(i&Js)*Math.pow(2,o),o+=7}while(i>=$c);return $n.bytes=s-n,e}var jc=Math.pow(2,7),Yc=Math.pow(2,14),Xc=Math.pow(2,21),Qc=Math.pow(2,28),Jc=Math.pow(2,35),tu=Math.pow(2,42),eu=Math.pow(2,49),ru=Math.pow(2,56),nu=Math.pow(2,63),ou=function(r){return r<jc?1:r<Yc?2:r<Xc?3:r<Qc?4:r<Jc?5:r<tu?6:r<eu?7:r<ru?8:r<nu?9:10},su={encode:Vc,decode:Zc,encodingLength:ou},iu=su,Qe=iu;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 kt(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 ne(r){let t=Vt(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 ei(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Gs(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 ri(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return cu(e,jn(r),t??j.encoder);default:return uu(e,jn(r),t??Pt.encoder)}}var ni=new WeakMap;function jn(r){let t=ni.get(r);if(t==null){let e=new Map;return ni.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!==lu)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=kt(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&&ei(t.multihash,n.multihash)}toString(t){return ri(this,t)}toJSON(){return{"/":ri(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??oi(n,o,s.bytes))}else if(e[fu]===!0){let{version:n,multihash:o,code:s}=e,i=ne(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=oi(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,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=Vt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new 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]=au(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 jn(s).set(n,t),s}};function au(r,t){switch(r[0]){case"Q":{let e=t??j;return[j.prefix,e.decode(`${j.prefix}${r}`)]}case j.prefix:{let e=t??j;return[j.prefix,e.decode(r)]}case Pt.prefix:{let e=t??Pt;return[Pt.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 cu(r,t,e){let{prefix:n}=e;if(n!==j.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 uu(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,lu=18;function oi(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 fu=Symbol.for("@ipld/js-cid/CID");var Yn={};Et(Yn,{identity:()=>Ct});var si=0,du="identity",ii=Vt;function hu(r){return kt(si,ii(r))}var Ct={code:si,name:du,encode:ii,digest:hu};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 vt(r=0){return new Uint8Array(r)}function Lt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=vt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var ci=Symbol.for("@achingbrain/uint8arraylist");function ai(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?.[ci]}var pt=class r{bufs;length;[ci]=!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=ai(this.bufs,t);return e.buf[e.index]}set(t,e){let n=ai(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=vt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=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=vt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=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 Xn={};Et(Xn,{base10:()=>pu});var pu=re({prefix:"9",name:"base10",alphabet:"0123456789"});var Qn={};Et(Qn,{base16:()=>mu,base16upper:()=>yu});var mu=J({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),yu=J({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Jn={};Et(Jn,{base2:()=>gu});var gu=J({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var to={};Et(to,{base256emoji:()=>vu});var ui=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}"),bu=ui.reduce((r,t,e)=>(r[e]=t,r),[]),xu=ui.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function wu(r){return r.reduce((t,e)=>(t+=bu[e],t),"")}function Eu(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:wu,decode:Eu});var eo={};Et(eo,{base64:()=>Au,base64pad:()=>Su,base64url:()=>Iu,base64urlpad:()=>Lu});var Au=J({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Su=J({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Iu=J({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Lu=J({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ro={};Et(ro,{base8:()=>Ru});var Ru=J({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var no={};Et(no,{identity:()=>Bu});var Bu=_e({prefix:"\0",name:"identity",encode:r=>$s(r),decode:r=>Zs(r)});var Rd=new TextEncoder,Bd=new TextDecoder;var io={};Et(io,{sha256:()=>er,sha512:()=>Pu});function so({name:r,code:t,encode:e}){return new oo(r,t,e)}var oo=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?kt(this.code,e):e.then(n=>kt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function fi(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var er=so({name:"sha2-256",code:18,encode:fi("SHA-256")}),Pu=so({name:"sha2-512",code:19,encode:fi("SHA-512")});var rr={...no,...Jn,...ro,...Xn,...Qn,...Gn,...Zn,...Wn,...eo,...to},qd={...io,...Yn};function hi(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var di=hi("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ao=hi("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=vt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),ku={utf8:di,"utf-8":di,hex:rr.base16,latin1:ao,ascii:ao,binary:ao,...rr},Kr=ku;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 Cu=parseInt("11111",2),co=parseInt("10000000",2),Ku=parseInt("01111111",2),pi={0:nr,1:nr,2:Du,3:Ou,4:Mu,5:Nu,6:Uu,16:nr,22:nr,48:nr};function Wt(r,t={offset:0}){let e=r[t.offset]&Cu;if(t.offset++,pi[e]!=null)return pi[e](r,t);throw new Error("No decoder for tag "+e)}function or(r,t){let e=0;if((r[t.offset]&co)===co){let n=r[t.offset]&Ku,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=Wt(r,t);if(n===null)break;e.push(n)}return e}function Du(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 Uu(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 Nu(r,t){return t.offset++,null}function Ou(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 Mu(r,t){let e=or(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function qu(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 uo(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=qu(r.byteLength);return new pt(Uint8Array.from([t.byteLength|co]),t)}function At(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]),uo(t),t)}function Dr(r){let t=Uint8Array.from([0]),e=new pt(t,r);return new pt(Uint8Array.from([3]),uo(e),e)}function oe(r,t=48){let e=new pt;for(let n of r)e.append(n);return new pt(Uint8Array.from([t]),uo(e),e)}async function mi(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 Hu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),zu=Uint8Array.from([6,5,43,129,4,0,34]),Vu=Uint8Array.from([6,5,43,129,4,0,35]),Fu={ext:!0,kty:"EC",crv:"P-256"},Wu={ext:!0,kty:"EC",crv:"P-384"},Gu={ext:!0,kty:"EC",crv:"P-521"},lo=32,fo=48,ho=66;function po(r){let t=Wt(r);return yi(t)}function yi(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===lo*2+1)return n=N(t.subarray(e,e+lo),"base64url"),o=N(t.subarray(e+lo),"base64url"),new Ke({...Fu,key_ops:["verify"],x:n,y: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});throw new z(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function gi(r){return oe([At(Uint8Array.from([1])),oe([Zu(r.crv)],160),oe([Dr(new pt(Uint8Array.from([4]),G(r.x??"","base64url"),G(r.y??"","base64url")))],161)]).subarray()}function Zu(r){if(r==="P-256")return Hu;if(r==="P-384")return zu;if(r==="P-521")return Vu;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=gi(this.jwk)),this._raw}toMultihash(){return Ct.digest(Tt(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return j.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 mi(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 bi(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 xi(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 Gt(...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 Kt(r,t){return r<<32-t|r>>>t}function wi(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=wi(r)),pe(r),r}function mo(...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 yo(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 ju(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 Ei(r,t,e){return r&t^~r&e}function vi(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),xi(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Gt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)e[f]=0;ju(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()}},Zt=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),Ai=BigInt(32);function Yu(r,t=!1){return t?{h:Number(r&Mr),l:Number(r>>Ai&Mr)}:{h:Number(r>>Ai&Mr)|0,l:Number(r&Mr)|0}}function Si(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}=Yu(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var go=(r,t,e)=>r>>>e,bo=(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 Nt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Ii=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Li=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Ri=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Bi=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Ti=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),_i=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Qu=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]),se=new Uint32Array(64),qr=class extends ir{constructor(t=32){super(64,t,8,!1),this.A=Zt[0]|0,this.B=Zt[1]|0,this.C=Zt[2]|0,this.D=Zt[3]|0,this.E=Zt[4]|0,this.F=Zt[5]|0,this.G=Zt[6]|0,this.H=Zt[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let f=0;f<16;f++,e+=4)se[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let p=se[f-15],g=se[f-2],E=Kt(p,7)^Kt(p,18)^p>>>3,y=Kt(g,17)^Kt(g,19)^g>>>10;se[f]=y+se[f-7]+E+se[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=Kt(a,6)^Kt(a,11)^Kt(a,25),g=u+p+Ei(a,c,l)+Qu[f]+se[f]|0,y=(Kt(n,2)^Kt(n,13)^Kt(n,22))+vi(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(){Gt(se)}destroy(){this.set(0,0,0,0,0,0,0,0),Gt(this.buffer)}};var Pi=Si(["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=Pi[0],tl=Pi[1],ie=new Uint32Array(80),ae=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 w=0;w<16;w++,e+=4)ie[w]=t.getUint32(e),ae[w]=t.getUint32(e+=4);for(let w=16;w<80;w++){let d=ie[w-15]|0,b=ae[w-15]|0,L=me(d,b,1)^me(d,b,8)^go(d,b,7),R=ye(d,b,1)^ye(d,b,8)^bo(d,b,7),B=ie[w-2]|0,K=ae[w-2]|0,O=me(B,K,19)^ar(B,K,61)^go(B,K,6),P=ye(B,K,19)^cr(B,K,61)^bo(B,K,6),D=Ri(R,P,ae[w-7],ae[w-16]),C=Bi(D,L,O,ie[w-7],ie[w-16]);ie[w]=C|0,ae[w]=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 w=0;w<80;w++){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=Ti(q,b,R,tl[w],ae[w]),K=_i(B,_,d,L,Ju[w],ie[w]),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}=Nt(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 A=Ii(O,D,nt);n=Li(A,K,P,C),o=A|0}({h:n,l:o}=Nt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Nt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Nt(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:u}=Nt(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:p}=Nt(this.Eh|0,this.El|0,f|0,p|0),{h:g,l:E}=Nt(this.Fh|0,this.Fl|0,g|0,E|0),{h:y,l:I}=Nt(this.Gh|0,this.Gl|0,y|0,I|0),{h:_,l:q}=Nt(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(){Gt(ie,ae)}destroy(){Gt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Hr=yo(()=>new qr);var ki=yo(()=>new xo);var Ao=BigInt(0),vo=BigInt(1);function Ne(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function So(r){if(!Ne(r))throw new Error("Uint8Array expected")}function Ot(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 Di(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Ao:BigInt("0x"+r)}var Ui=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",el=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function ce(r){if(So(r),Ui)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=el[r[e]];return t}var $t={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ci(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(Ui)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=Ci(r.charCodeAt(s)),a=Ci(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 jt(r){return Di(ce(r))}function ge(r){return So(r),Di(ce(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 ue(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];So(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 wo=r=>typeof r=="bigint"&&Ao<=r;function zr(r,t,e){return wo(r)&&wo(t)&&wo(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 Ni(r){let t;for(t=0;r>Ao;r>>=vo,t+=1);return t}var xe=r=>(vo<<BigInt(r))-vo,Eo=r=>new Uint8Array(r),Ki=r=>Uint8Array.from(r);function Oi(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=Eo(r),o=Eo(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},a=(...f)=>e(o,n,...f),c=(f=Eo(0))=>{o=a(Ki([0]),f),n=a(),f.length!==0&&(o=a(Ki([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 ue(...p)};return(f,p)=>{i(),c(f);let g;for(;!(g=p(l()));)c();return i(),g}}var rl={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 Yt(r,t,e={}){let n=(o,s,i)=>{let a=rl[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),we=BigInt(2),nl=BigInt(3),qi=BigInt(4),Hi=BigInt(5),zi=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 Vi(r,t){let e=(r.ORDER+at)/qi,n=r.pow(t,e);if(!r.eql(r.sqr(n),t))throw new Error("Cannot find square root");return n}function ol(r,t){let e=(r.ORDER-Hi)/zi,n=r.mul(t,we),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,we),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 sl(r){if(r<BigInt(3))throw new Error("sqrt is not defined for small field");let t=r-at,e=0;for(;t%we===mt;)t/=we,e++;let n=we,o=Xt(r);for(;Mi(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return Vi;let s=o.pow(n,t),i=(t+at)/we;return function(c,l){if(c.is0(l))return l;if(Mi(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 il(r){return r%qi===nl?Vi:r%zi===Hi?ol:sl(r)}var Fi=(r,t)=>(Z(r,t)&at)===at,al=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Io(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=al.reduce((n,o)=>(n[o]="function",n),t);return Yt(r,e)}function cl(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 Mi(r,t){let e=(r.ORDER-at)/we,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&&Ur(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Xt(r,t,e=!1,n={}){if(r<=mt)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:xe(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)=>cl(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=il(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):jt(c)},invertBatch:c=>qe(a,c),cmov:(c,l,u)=>u?l:c});return Object.freeze(a)}function Wi(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 Ro(r){let t=Wi(r);return t+Math.ceil(t/2)}function Gi(r,t,e=!1){let n=r.length,o=Wi(t),s=Ro(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?ge(r):jt(r),a=Z(i,t-at)+at;return e?Oe(a,o):be(a,o)}var Zi=BigInt(0),ko=BigInt(1);function Bo(r,t){let e=t.negate();return r?e:t}function ji(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function To(r,t){ji(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=xe(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function $i(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+=ko);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 ul(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 ll(r,t){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}var _o=new WeakMap,Yi=new WeakMap;function Po(r){return Yi.get(r)||1}function Fr(r,t){return{constTimeNegate:Bo,hasPrecomputes(e){return Po(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>Zi;)n&ko&&(o=o.add(s)),s=s.double(),n>>=ko;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=To(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=To(e,t);for(let c=0;c<a.windows;c++){let{nextN:l,offset:u,isZero:f,isNeg:p,isNegF:g,offsetF:E}=$i(o,c,a);o=l,f?i=i.add(Bo(g,n[E])):s=s.add(Bo(p,n[u]))}return{p:s,f:i}},wNAFUnsafe(e,n,o,s=r.ZERO){let i=To(e,t);for(let a=0;a<i.windows&&o!==Zi;a++){let{nextN:c,offset:l,isZero:u,isNeg:f}=$i(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=_o.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&_o.set(n,o(s))),s},wNAFCached(e,n,o){let s=Po(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=Po(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){ji(n,t),Yi.set(e,n),_o.delete(e)}}}function Wr(r,t,e,n){ul(e,r),ll(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=Ni(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let l=xe(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 Io(r.Fp),Yt(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 Mt=BigInt(0),yt=BigInt(1),Xi=BigInt(2),fl=BigInt(8),dl={zip215:!0};function hl(r){let t=fr(r);return Yt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Qi(r){let t=hl(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:a,h:c}=t,l=Xi<<BigInt(a*8)-yt,u=e.create,f=Xt(t.n,t.nBitLength);function p(x,h){let m=e.sqr(x),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||((x,h)=>{try{return{isValid:!0,value:e.sqrt(x*e.inv(h))}}catch{return{isValid:!1,value:Mt}}}),E=t.adjustScalarBytes||(x=>x),y=t.domain||((x,h,m)=>{if(Ot("phflag",m),h.length||m)throw new Error("Contexts/pre-hash are not supported");return x});function I(x,h,m=!1){let S=m?yt:Mt;Rt("coordinate "+x,h,S,l)}function _(x){if(!(x instanceof d))throw new Error("ExtendedPoint expected")}let q=Me((x,h)=>{let{ex:m,ey:S,ez:k}=x,U=x.is0();h==null&&(h=U?fl:e.inv(k));let M=u(m*h),H=u(S*h),V=u(k*h);if(U)return{x:Mt,y:yt};if(V!==yt)throw new Error("invZ was invalid");return{x:M,y:H}}),w=Me(x=>{let{a:h,d:m}=t;if(x.is0())throw new Error("bad point: ZERO");let{ex:S,ey:k,ez:U,et:M}=x,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)),wt=u(ot+u(m*u(H*V)));if(ut!==wt)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(){w(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(Xi*u(k*k)),V=u(h*U),W=m+S,ot=u(u(W*W)-U-M),et=V+M,ut=et-H,wt=V-M,it=u(ot*ut),ft=u(et*wt),It=u(ot*wt),_t=u(ut*et);return new d(it,ft,_t,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),wt=u(U*W),it=u(H*S*et),ft=u(M*ot),It=u((k+U)*(V+W)-ut-wt),_t=ft-it,je=ft+it,Ws=u(wt-m*ut),bc=u(It*_t),xc=u(je*Ws),wc=u(It*Ws),Ec=u(_t*je);return new d(bc,xc,Ec,wc)}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,Mt,n),S===Mt?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),Ot("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,Mt,W);let ot=u(V*V),et=u(ot-yt),ut=u(S*ot-k),{isValid:wt,value:it}=g(et,ut);if(!wt)throw new Error("Point.fromHex: invalid y coordinate");let ft=(it&yt)===yt,It=(H&128)!==0;if(!m&&it===Mt&&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 ce(this.toRawBytes())}}d.BASE=new d(t.Gx,t.Gy,yt,u(t.Gx*t.Gy)),d.ZERO=new d(Mt,yt,yt,Mt);let{BASE:b,ZERO:L}=d,R=Fr(d,a*8);function B(x){return Z(x,n)}function K(x){return B(ge(x))}function O(x){let h=e.BYTES;x=X("private key",x,h);let m=X("hashed private key",s(x),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(x){let{head:h,prefix:m,scalar:S}=O(x),k=b.multiply(S),U=k.toRawBytes();return{head:h,prefix:m,scalar:S,point:k,pointBytes:U}}function D(x){return P(x).pointBytes}function C(x=Uint8Array.of(),...h){let m=ue(...h);return K(s(y(m,X("context",x),!!o)))}function nt(x,h,m={}){x=X("message",x),o&&(x=o(x));let{prefix:S,scalar:k,pointBytes:U}=P(h),M=C(m.context,S,x),H=b.multiply(M).toRawBytes(),V=C(m.context,H,U,x),W=B(M+V*k);Rt("signature.s",W,Mt,n);let ot=ue(H,Oe(W,e.BYTES));return X("result",ot,e.BYTES*2)}let A=dl;function v(x,h,m,S=A){let{context:k,zip215:U}=S,M=e.BYTES;x=X("signature",x,2*M),h=X("message",h),m=X("publicKey",m,M),U!==void 0&&Ot("zip215",U),o&&(h=o(h));let H=ge(x.slice(M,2*M)),V,W,ot;try{V=d.fromHex(m,U),W=d.fromHex(x.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:v,ExtendedPoint:d,utils:{getExtendedPublicKey:P,randomPrivateKey:()=>i(e.BYTES),precompute(x=8,h=d.BASE){return h._setWindowSize(x),h.multiply(BigInt(3)),h}}}}var Co=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Ji=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Vh=BigInt(0),pl=BigInt(1),ta=BigInt(2),Fh=BigInt(3),ml=BigInt(5),yl=BigInt(8);function gl(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=Co,a=r*r%s*r%s,c=Q(a,ta,s)*a%s,l=Q(c,pl,s)*r%s,u=Q(l,ml,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,ta,s)*r%s,b2:a}}function bl(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function xl(r,t){let e=Co,n=Z(t*t*t,e),o=Z(n*n*t,e),s=gl(r*o).pow_p_5_8,i=Z(r*n*s,e),a=Z(t*i*i,e),c=i,l=Z(i*Ji,e),u=a===r,f=a===Z(-r,e),p=a===Z(-r*Ji,e);return u&&(i=c),(f||p)&&(i=l),Fi(i,e)&&(i=Z(-i,e)),{isValid:u||f,value:i}}var ea=Xt(Co,void 0,!0),wl={a:ea.create(BigInt(-1)),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:ea,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:yl,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:ki,randomBytes:Or,adjustScalarBytes:bl,uvRatio:xl},ra=Qi(wl);var Gr=32;function na(r,t,e){return ra.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var Zr=class{type="Ed25519";raw;constructor(t){this.raw=Ko(t,Gr)}toMultihash(){return Ct.digest(Tt(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return j.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 n?.signal?.throwIfAborted(),na(this.raw,e,t)}};function Do(r){return r=Ko(r,Gr),new Zr(r)}function Ko(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 vl=Math.pow(2,7),Al=Math.pow(2,14),Sl=Math.pow(2,21),Uo=Math.pow(2,28),No=Math.pow(2,35),Oo=Math.pow(2,42),Mo=Math.pow(2,49),F=128,dt=127;function St(r){if(r<vl)return 1;if(r<Al)return 2;if(r<Sl)return 3;if(r<Uo)return 4;if(r<No)return 5;if(r<Oo)return 6;if(r<Mo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function qo(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 Il(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 Ho(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)*Uo,e<F)||(e=r[t+5],n+=(e&dt)*No,e<F)||(e=r[t+6],n+=(e&dt)*Oo,e<F)||(e=r[t+7],n+=(e&dt)*Mo,e<F))return n;throw new RangeError("Could not decode varint")}function Ll(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)*Uo,e<F)||(e=r.get(t+5),n+=(e&dt)*No,e<F)||(e=r.get(t+6),n+=(e&dt)*Oo,e<F)||(e=r.get(t+7),n+=(e&dt)*Mo,e<F))return n;throw new RangeError("Could not decode varint")}function qt(r,t,e=0){return t==null&&(t=vt(St(r))),t instanceof Uint8Array?qo(r,t,e):Il(r,t,e)}function Ee(r,t=0){return r instanceof Uint8Array?Ho(r,t):Ll(r,t)}var Vo=new Float32Array([-0]),le=new Uint8Array(Vo.buffer);function sa(r,t,e){Vo[0]=r,t[e]=le[0],t[e+1]=le[1],t[e+2]=le[2],t[e+3]=le[3]}function ia(r,t){return le[0]=r[t],le[1]=r[t+1],le[2]=r[t+2],le[3]=r[t+3],Vo[0]}var Fo=new Float64Array([-0]),ht=new Uint8Array(Fo.buffer);function aa(r,t,e){Fo[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 ca(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],Fo[0]}var Rl=BigInt(Number.MAX_SAFE_INTEGER),Bl=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 ve;if(t<Rl&&t>Bl)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>ua&&(o=0n,++n>ua&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return ve;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):ve}},ve=new Bt(0,0);ve.toBigInt=function(){return 0n};ve.zzEncode=ve.zzDecode=function(){return this};ve.length=function(){return 1};var ua=4294967296n;function la(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 fa(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 Wo(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 Dt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function $r(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Go=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,Dt(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 Dt(this,4);return $r(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Dt(this,4);return $r(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Dt(this,4);let t=ia(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Dt(this,4);let t=ca(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw Dt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return fa(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Dt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Dt(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 Dt(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 Dt(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 Dt(this,8);let t=$r(this.buf,this.pos+=4),e=$r(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=Ho(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 Zo(r){return new Go(r instanceof Uint8Array?r:r.subarray())}function gt(r,t,e){let n=Zo(r);return t.decode(n,void 0,e)}function $o(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return vt(i);o+i>t&&(n=vt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Ae=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function jo(){}var Xo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Tl=$o();function _l(r){return globalThis.Buffer!=null?vt(r):Tl(r)}var hr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ae(jo,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Ae(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Qo((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,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(jr,e.length(),e)}uint64Number(t){return this._push(qo,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(jr,e.length(),e)}sint64Number(t){let e=Bt.fromNumber(t).zzEncode();return this._push(jr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Yo,1,t?1:0)}fixed32(t){return this._push(dr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Bt.fromBigInt(t);return this._push(dr,4,e.lo)._push(dr,4,e.hi)}fixed64Number(t){let e=Bt.fromNumber(t);return this._push(dr,4,e.lo)._push(dr,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(sa,4,t)}double(t){return this._push(aa,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Yo,1,0):this.uint32(e)._push(kl,e,t)}string(t){let e=la(t);return e!==0?this.uint32(e)._push(Wo,e,t):this._push(Yo,1,0)}fork(){return this.states=new Xo(this),this.head=this.tail=new Ae(jo,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Ae(jo,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=_l(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Yo(r,t,e){t[e]=r&255}function Pl(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Qo=class extends Ae{next;constructor(t,e){super(Pl,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 dr(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 kl(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(hr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Cl,t,r),this},hr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Kl,t,r),this});function Cl(r,t,e){t.set(r,e)}function Kl(r,t,e){r.length<40?Wo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(G(r),e)}function Jo(){return new hr}function bt(r,t){let e=Jo();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 Yr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function ts(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 Yr("enum",He.VARINT,e,n)}function xt(r,t){return Yr("message",He.LENGTH_DELIMITED,r,t)}var Se=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"},pr=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 es;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(es||(es={}));(function(r){r.codec=()=>ts(es)})(rt||(rt={}));var Ht;(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=>bt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Ht||(Ht={}));var rs;(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=>bt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(rs||(rs={}));var mr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Xr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var pa={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Xr("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var fe=pa;var gr={};Et(gr,{MAX_RSA_KEY_SIZE:()=>ns,generateRSAKeyPair:()=>ba,jwkToJWKKeyPair:()=>xa,jwkToPkcs1:()=>Ol,jwkToPkix:()=>as,jwkToRSAPrivateKey:()=>fs,pkcs1MessageToJwk:()=>ss,pkcs1MessageToRSAPrivateKey:()=>cs,pkcs1ToJwk:()=>Nl,pkcs1ToRSAPrivateKey:()=>ga,pkixMessageToJwk:()=>is,pkixMessageToRSAPublicKey:()=>ls,pkixToJwk:()=>Ml,pkixToRSAPublicKey:()=>us});var Qr=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 j.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 ya(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 ma(this.jwk,t,e)}};var ns=8192,os=18,Dl=1062,Ul=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Nl(r){let t=Wt(r);return ss(t)}function ss(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 Ol(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 oe([At(Uint8Array.from([0])),At(G(r.n,"base64url")),At(G(r.e,"base64url")),At(G(r.d,"base64url")),At(G(r.p,"base64url")),At(G(r.q,"base64url")),At(G(r.dp,"base64url")),At(G(r.dq,"base64url")),At(G(r.qi,"base64url"))]).subarray()}function Ml(r){let t=Wt(r,{offset:0});return is(t)}function is(r){let t=Wt(r[1],{offset:0});return{kty:"RSA",n:N(t[0],"base64url"),e:N(t[1],"base64url")}}function as(r){if(r.n==null||r.e==null)throw new z("JWK was missing components");return oe([Ul,Dr(oe([At(G(r.n,"base64url")),At(G(r.e,"base64url"))]))]).subarray()}function ga(r){let t=Wt(r);return cs(t)}function cs(r){let t=ss(r);return fs(t)}function us(r,t){if(r.byteLength>=Dl)throw new Be("Key size is too large");let e=Wt(r,{offset:0});return ls(e,r,t)}function ls(r,t,e){let n=is(r);if(e==null){let o=Qr(Ht.encode({Type:rt.RSA,Data:t}));e=kt(os,o)}return new ze(n,e)}function fs(r){if(Ea(r)>ns)throw new z("Key size is too large");let t=xa(r),e=Qr(Ht.encode({Type:rt.RSA,Data:as(t.publicKey)})),n=kt(os,e);return new yr(t.privateKey,new ze(t.publicKey,n))}async function ba(r){if(r>ns)throw new z("Key size is too large");let t=await wa(r),e=Qr(Ht.encode({Type:rt.RSA,Data:as(t.publicKey)})),n=kt(os,e);return new yr(t.privateKey,new ze(t.publicKey,n))}function xa(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 wa(r,t){let e=await fe.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 ql(e,t);return{privateKey:n[0],publicKey:n[1]}}async function ma(r,t,e){let n=await fe.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);e?.signal?.throwIfAborted();let o=await fe.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 ya(r,t,e,n){let o=await fe.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await fe.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,e instanceof Uint8Array?e:e.subarray());return n?.signal?.throwIfAborted(),s}async function ql(r,t){if(r.privateKey==null||r.publicKey==null)throw new z("Private and public key are required");let e=await Promise.all([fe.get().subtle.exportKey("jwk",r.privateKey),fe.get().subtle.exportKey("jwk",r.publicKey)]);return t?.signal?.throwIfAborted(),e}function Ea(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 Jr=class extends De{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,bi(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),Gt(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()}},ds=(r,t,e)=>new Jr(r,t).update(e).digest();ds.create=(r,t)=>new Jr(r,t);function va(r){r.lowS!==void 0&&Ot("lowS",r.lowS),r.prehash!==void 0&&Ot("prehash",r.prehash)}function Hl(r){let t=fr(r);Yt(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 ms=class extends Error{constructor(t=""){super(t)}},Qt={Err:ms,_tlv:{encode:(r,t)=>{let{Err:e}=Qt;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}=Qt,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}=Qt;if(r<Jt)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}=Qt;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 jt(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Qt,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}=Qt,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 hs(r,t){return ce(be(r,t))}var Jt=BigInt(0),ct=BigInt(1),g0=BigInt(2),ps=BigInt(3),zl=BigInt(4);function Vl(r){let t=Hl(r),{Fp:e}=t,n=Xt(t.n,t.nBitLength),o=t.toBytes||((w,d,b)=>{let L=d.toAffine();return ue(Uint8Array.from([4]),e.toBytes(L.x),e.toBytes(L.y))}),s=t.fromBytes||(w=>{let d=w.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(w){let{a:d,b}=t,L=e.sqr(w),R=e.mul(L,w);return e.add(e.add(R,e.mul(w,d)),b)}function a(w,d){let b=e.sqr(d),L=i(w);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,ps),zl),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(w){return zr(w,ct,t.n)}function f(w){let{allowedPrivateKeyLengths:d,nByteLength:b,wrapPrivateKey:L,n:R}=t;if(d&&typeof w!="bigint"){if(Ne(w)&&(w=ce(w)),typeof w!="string"||!d.includes(w.length))throw new Error("invalid private key");w=w.padStart(b*2,"0")}let B;try{B=typeof w=="bigint"?w:jt(X("private key",w,b))}catch{throw new Error("invalid private key, expected hex or "+b+" bytes, got "+typeof w)}return L&&(B=Z(B,R)),Rt("private key",B,ct,R),B}function p(w){if(!(w instanceof y))throw new Error("ProjectivePoint expected")}let g=Me((w,d)=>{let{px:b,py:L,pz:R}=w;if(e.eql(R,e.ONE))return{x:b,y:L};let B=w.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(w=>{if(w.is0()){if(t.allowInfinityPoint&&!e.is0(w.py))return;throw new Error("bad point: ZERO")}let{x:d,y:b}=w.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(!w.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,ps),{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),A=e.mul(K,K),v=e.mul(R,B);return v=e.add(v,v),D=e.mul(R,K),D=e.add(D,D),O=e.mul(d,D),P=e.mul(L,A),P=e.add(O,P),O=e.sub(nt,P),P=e.add(nt,P),P=e.mul(O,P),O=e.mul(v,O),D=e.mul(L,D),A=e.mul(d,A),v=e.sub(C,A),v=e.mul(d,v),v=e.add(v,D),D=e.add(C,C),C=e.add(D,C),C=e.add(C,A),C=e.mul(C,v),P=e.add(P,C),A=e.mul(B,K),A=e.add(A,A),C=e.mul(A,v),O=e.sub(O,C),D=e.mul(A,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,A=e.mul(t.b,ps),v=e.mul(b,B),T=e.mul(L,K),x=e.mul(R,O),h=e.add(b,L),m=e.add(B,K);h=e.mul(h,m),m=e.add(v,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(v,x),m=e.sub(m,S),S=e.add(L,R),P=e.add(K,O),S=e.mul(S,P),P=e.add(T,x),S=e.sub(S,P),C=e.mul(nt,m),P=e.mul(A,x),C=e.add(P,C),P=e.sub(T,C),C=e.add(T,C),D=e.mul(P,C),T=e.add(v,v),T=e.add(T,v),x=e.mul(nt,x),m=e.mul(A,m),T=e.add(T,x),x=e.sub(v,x),x=e.mul(nt,x),m=e.add(m,x),v=e.mul(T,m),D=e.add(D,v),v=e.mul(S,m),P=e.mul(h,P),P=e.sub(P,v),v=e.mul(h,T),C=e.mul(S,C),C=e.add(C,v),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,Jt,L);let R=y.ZERO;if(d===Jt)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>Jt||P>Jt;)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:A,f:v}=this.wNAF(D);C=q.constTimeNegate(K,C),A=q.constTimeNegate(P,A),A=new y(e.mul(A.px,b.beta),A.py,A.pz),R=C.add(A),B=nt.add(v)}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===Jt||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 Ot("isCompressed",d),this.assertValidity(),o(y,this,d)}toHex(d=!0){return Ot("isCompressed",d),ce(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 Fl(r){let t=fr(r);return Yt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Aa(r){let t=Fl(r),{Fp:e,n,nByteLength:o,nBitLength:s}=t,i=e.BYTES+1,a=2*e.BYTES+1;function c(A){return Z(A,n)}function l(A){return Vr(A,n)}let{ProjectivePoint:u,normPrivateKeyToScalar:f,weierstrassEquation:p,isWithinCurveOrder:g}=Vl({...t,toBytes(A,v,T){let x=v.toAffine(),h=e.toBytes(x.x),m=ue;return Ot("isCompressed",T),T?m(Uint8Array.from([v.hasEvenY()?2:3]),h):m(Uint8Array.from([4]),h,e.toBytes(x.y))},fromBytes(A){let v=A.length,T=A[0],x=A.subarray(1);if(v===i&&(T===2||T===3)){let h=jt(x);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(v===a&&T===4){let h=e.fromBytes(x.subarray(0,e.BYTES)),m=e.fromBytes(x.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 "+v)}}});function E(A){let v=n>>ct;return A>v}function y(A){return E(A)?c(-A):A}let I=(A,v,T)=>jt(A.slice(v,T));class _{constructor(v,T,x){Rt("r",v,ct,n),Rt("s",T,ct,n),this.r=v,this.s=T,x!=null&&(this.recovery=x),Object.freeze(this)}static fromCompact(v){let T=o;return v=X("compactSignature",v,T*2),new _(I(v,0,T),I(v,T,2*T))}static fromDER(v){let{r:T,s:x}=Qt.toSig(X("DER",v));return new _(T,x)}assertValidity(){}addRecoveryBit(v){return new _(this.r,this.s,v)}recoverPublicKey(v){let{r:T,s:x,recovery:h}=this,m=R(X("msgHash",v));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+hs(S,e.BYTES)),M=l(S),H=c(-m*M),V=c(x*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 Qt.hexFromSig(this)}toCompactRawBytes(){return lr(this.toCompactHex())}toCompactHex(){let v=o;return hs(this.r,v)+hs(this.s,v)}}let q={isValidPrivateKey(A){try{return f(A),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let A=Ro(t.n);return Gi(t.randomBytes(A),t.n)},precompute(A=8,v=u.BASE){return v._setWindowSize(A),v.multiply(BigInt(3)),v}};function w(A,v=!0){return u.fromPrivateKey(A).toRawBytes(v)}function d(A){if(typeof A=="bigint")return!1;if(A instanceof u)return!0;let T=X("key",A).length,x=e.BYTES,h=x+1,m=2*x+1;if(!(t.allowedPrivateKeyLengths||o===h))return T===h||T===m}function b(A,v,T=!0){if(d(A)===!0)throw new Error("first arg must be private key");if(d(v)===!1)throw new Error("second arg must be public key");return u.fromHex(v).multiply(f(A)).toRawBytes(T)}let L=t.bits2int||function(A){if(A.length>8192)throw new Error("input is too large");let v=jt(A),T=A.length*8-s;return T>0?v>>BigInt(T):v},R=t.bits2int_modN||function(A){return c(L(A))},B=xe(s);function K(A){return Rt("num < 2^"+s,A,Jt,B),be(A,o)}function O(A,v,T=P){if(["recovered","canonical"].some(et=>et in T))throw new Error("sign() legacy options not supported");let{hash:x,randomBytes:h}=t,{lowS:m,prehash:S,extraEntropy:k}=T;m==null&&(m=!0),A=X("msgHash",A),va(T),S&&(A=X("prehashed msgHash",x(A)));let U=R(A),M=f(v),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=ue(...H),W=U;function ot(et){let ut=L(et);if(!g(ut))return;let wt=l(ut),it=u.BASE.multiply(ut).toAffine(),ft=c(it.x);if(ft===Jt)return;let It=c(wt*c(W+ft*M));if(It===Jt)return;let _t=(it.x===ft?0:2)|Number(it.y&ct),je=It;return m&&E(It)&&(je=y(It),_t^=1),new _(ft,je,_t)}return{seed:V,k2sig:ot}}let P={lowS:t.lowS,prehash:!1},D={lowS:t.lowS,prehash:!1};function C(A,v,T=P){let{seed:x,k2sig:h}=O(A,v,T),m=t;return Oi(m.hash.outputLen,m.nByteLength,m.hmac)(x,h)}u.BASE._setWindowSize(8);function nt(A,v,T,x=D){let h=A;v=X("msgHash",v),T=X("publicKey",T);let{lowS:m,prehash:S,format:k}=x;if(va(x),"strict"in x)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(_t){if(!(_t instanceof Qt.Err))throw _t}!H&&k!=="der"&&(H=_.fromCompact(h))}V=u.fromHex(T)}catch{return!1}if(!H||m&&H.hasHighS())return!1;S&&(v=t.hash(v));let{r:W,s:ot}=H,et=R(v),ut=l(ot),wt=c(et*ut),it=c(W*ut),ft=u.BASE.multiplyAndAddUnsafe(V,wt,it)?.toAffine();return ft?c(ft.x)===W:!1}return{CURVE:t,getPublicKey:w,getSharedSecret:b,sign:C,verify:nt,ProjectivePoint:u,Signature:_,utils:q}}function Wl(r){return{hash:r,hmac:(t,...e)=>ds(r,t,mo(...e)),randomBytes:Or}}function Sa(r,t){let e=n=>Aa({...r,...Wl(n)});return{...e(t),create:e}}var Ra=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Ia=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Gl=BigInt(0),Zl=BigInt(1),ys=BigInt(2),La=(r,t)=>(r+t/ys)/t;function $l(r){let t=Ra,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),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,ys,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,w=Q(q,e,t)*u%t,d=Q(w,i,t)*E%t,b=Q(d,n,t)*l%t,L=Q(b,ys,t);if(!gs.eql(gs.sqr(L),r))throw new Error("Cannot find square root");return L}var gs=Xt(Ra,void 0,void 0,{sqrt:$l}),Ve=Sa({a:Gl,b:BigInt(7),Fp:gs,n:Ia,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Ia,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Zl*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),a=La(s*r,t),c=La(-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 Ba(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Ta(r,t,e,n){let o=er.digest(e instanceof Uint8Array?e:e.subarray());if(Ba(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ve.verify(t,s,r))).catch(s=>{throw s.name==="AbortError"?s:new mr(String(s))});try{return n?.signal?.throwIfAborted(),Ve.verify(t,o.digest,r)}catch(s){throw new mr(String(s))}}var tn=class{type="secp256k1";raw;_key;constructor(t){this._key=Pa(t),this.raw=_a(this._key)}toMultihash(){return Ct.digest(Tt(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return j.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 Ta(this._key,e,t,n)}};function bs(r){return new tn(r)}function _a(r){return Ve.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Pa(r){try{return Ve.ProjectivePoint.fromHex(r),r}catch(t){throw new Be(String(t))}}function en(r,t){let{Type:e,Data:n}=Ht.decode(r),o=n??new Uint8Array;switch(e){case rt.RSA:return us(o,t);case rt.Ed25519:return Do(o);case rt.secp256k1:return bs(o);case rt.ECDSA:return po(o);default:throw new de}}function ka(r){let{Type:t,Data:e}=Ht.decode(r.digest),n=e??new Uint8Array;switch(t){case rt.Ed25519:return Do(n);case rt.secp256k1:return bs(n);case rt.ECDSA:return po(n);default:throw new de}}function Tt(r){return Ht.encode({Type:rt[r.type],Data:r.raw})}var Ca=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=j.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")}[Ca](){return`PeerId(${this.toString()})`}},xr=class extends br{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},wr=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}},Yl=2336,vr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Ct.digest(G(this.url))}[Ca](){return`PeerId(${this.url})`}[Tr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return tt.createV1(Yl,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=N(t)),t.toString()===this.toString())}};var Xl=114,Ka=2336;function Da(r){if(r.type==="Ed25519")return new wr({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 xr({multihash:r.toCID().multihash,publicKey:r});throw new de}function xs(r){if(Jl(r))return new xr({multihash:r});if(Ql(r))try{let t=ka(r);if(t.type==="Ed25519")return new wr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new Er({multihash:r,publicKey:t})}catch{let e=N(r.digest);return new vr(new URL(e))}throw new Pr("Supplied PeerID Multihash is invalid")}function rn(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==Xl&&r.code!==Ka)throw new _r("Supplied PeerID CID is invalid");if(r.code===Ka){let t=N(r.multihash.digest);return new vr(new URL(t))}return xs(r.multihash)}function Ql(r){return r.code===Ct.code}function Jl(r){return r.code===er.code}var Ar;(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=>bt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Ar||(Ar={}));var nn=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var Fe=class r{static createFromProtobuf=t=>{let e=Ar.decode(t),n=en(e.publicKey);return new r({publicKey:n,payloadType:e.payloadType,payload:e.payload,signature:e.signature})};static seal=async(t,e,n)=>{if(e==null)throw new Error("Missing private key");let o=t.domain,s=t.codec,i=t.marshal(),a=Ua(o,s,i),c=await e.sign(a.subarray(),n);return new r({publicKey:e.publicKey,payloadType:s,payload:i,signature:c})};static openAndCertify=async(t,e,n)=>{let o=r.createFromProtobuf(t);if(!await o.validate(e,n))throw new nn("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(t){let{publicKey:e,payloadType:n,payload:o,signature:s}=t;this.publicKey=e,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=Ar.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=Ua(t,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,e)}},Ua=(r,t,e)=>{let n=G(r),o=qt(n.byteLength),s=qt(t.length),i=qt(e.length);return new pt(o,n,s,t,i,e)};function Na(r,t){let e=(n,o)=>n.toString().localeCompare(o.toString());return r.length!==t.length?!1:(t.sort(e),r.sort(e).every((n,o)=>t[o].equals(n)))}var on=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",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 Oa=45,tf=15,We=new on;function ws(r){if(!(r.length>tf))return We.new(r).parseWith(()=>We.readIPv4Addr())}function Es(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Oa))return We.new(r).parseWith(()=>We.readIPv6Addr())}function sn(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>Oa)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 Xm=parseInt("0xFFFF",16),Qm=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Ha(r){return!!ws(r)}function za(r){return!!Es(r)}function an(r){return!!sn(r)}var Va=Ha,sf=za,vs=function(r){let t=0;if(r=r.toString().trim(),Va(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(sf(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=Va(e[n]),i;s&&(i=vs(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")},Fa=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={},As={},cf=[[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"]];cf.forEach(r=>{let t=uf(...r);As[t.code]=t,Ge[t.name]=t});function uf(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function $(r){if(typeof r=="number"){if(As[r]!=null)return As[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Ge[r]!=null)return Ge[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Dy=$("ip4"),Uy=$("ip6"),Ny=$("ipcidr");function Rs(r,t){switch($(r).code){case 4:case 41:return ff(t);case 42:return Ls(t);case 43:return N(t,"base10");case 6:case 273:case 33:case 132:return Za(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Ls(t);case 421:return mf(t);case 444:return Ga(t);case 445:return Ga(t);case 466:return pf(t);case 481:return globalThis.encodeURIComponent(Ls(t));default:return N(t,"base16")}}function Bs(r,t){switch($(r).code){case 4:return Wa(t);case 41:return Wa(t);case 42:return Is(t);case 43:return G(t,"base10");case 6:case 273:case 33:case 132:return Ts(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Is(t);case 421:return df(t);case 444:return yf(t);case 445:return gf(t);case 466:return hf(t);case 481:return Is(globalThis.decodeURIComponent(t));default:return G(t,"base16")}}var Ss=Object.values(rr).map(r=>r.decoder),lf=function(){let r=Ss[0].or(Ss[1]);return Ss.slice(2).forEach(t=>r=r.or(t)),r}();function Wa(r){if(!an(r))throw new Error("invalid ip address");return vs(r)}function ff(r){let t=Fa(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!an(t))throw new Error("invalid ip address");return t}function Ts(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Za(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Is(r){let t=G(r),e=Uint8Array.from(qt(t.length));return Lt([e,t],e.length+t.length)}function Ls(r){let t=Ee(r);if(r=r.slice(St(t)),r.length!==t)throw new Error("inconsistent lengths");return N(r)}function df(r){let t;r[0]==="Q"||r[0]==="1"?t=ne(j.decode(`z${r}`)).bytes:t=tt.parse(r).multihash.bytes;let e=Uint8Array.from(qt(t.length));return Lt([e,t],e.length+t.length)}function hf(r){let t=lf.decode(r),e=Uint8Array.from(qt(t.length));return Lt([e,t],e.length+t.length)}function pf(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 mf(r){let t=Ee(r),e=r.slice(St(t));if(e.length!==t)throw new Error("inconsistent lengths");return N(e,"base58btc")}function yf(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=Pt.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=Ts(n);return Lt([e,o],e.length+o.length)}function gf(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=Pt.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=Ts(n);return Lt([e,o],e.length+o.length)}function Ga(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=N(t,"base32"),o=Za(e);return`${n}:${o}`}function $a(r){r=_s(r);let t=[],e=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let s=0;s<o.length;s++){let i=o[s],a=$(i);if(a.size===0){t.push([a.code]),e.push([a.code]);continue}if(s++,s>=o.length)throw new cn("invalid address: "+r);if(a.path===!0){n=_s(o.slice(s).join("/")),t.push([a.code,Bs(a.code,n)]),e.push([a.code,n]);break}let c=Bs(a.code,o[s]);t.push([a.code,c]),e.push([a.code,Rs(a.code,c)])}return{string:ja(e),bytes:un(t),tuples:t,stringTuples:e,path:n}}function Ps(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let s=Ee(r,o),i=St(s),a=$(s),c=bf(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 cn("Invalid address Uint8Array: "+N(r,"base16"));t.push([s,l]);let u=Rs(s,l);if(e.push([s,u]),a.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:ja(e),tuples:t,stringTuples:e,path:n}}function ja(r){let t=[];return r.map(e=>{let n=$(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),_s(t.join("/"))}function un(r){return Lt(r.map(t=>{let e=$(t[0]),n=Uint8Array.from(qt(e.code));return t.length>1&&t[1]!=null&&(n=Lt([n,t[1]])),n}))}function bf(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 _s(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}var cn=class extends Error{static name="ParseError";name="ParseError";constructor(t){super(`Error parsing address: ${t}`)}};var xf=Symbol.for("nodejs.util.inspect.custom"),Cs=Symbol.for("@multiformats/js-multiaddr/multiaddr"),wf=[$("dns").code,$("dns4").code,$("dns6").code,$("dnsaddr").code],ks=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},ln=class r{bytes;#t;#e;#r;#n;[Cs]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=Ps(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(fn(t))e=Ps(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=$("tcp"),a=$("udp"),c=$("ip4"),l=$("ip6"),u=$("dns6"),f=$("ip6zone");for(let[g,E]of this.stringTuples())g===f.code&&(s=`%${E??""}`),wf.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=$(g).name==="tcp"?"tcp":"udp",o=parseInt(E??"")),(g===c.code||g===l.code)&&(e=$(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({},$(t)))}protoCodes(){return this.#e.map(([t])=>t)}protoNames(){return this.#e.map(([t])=>$(t).name)}tuples(){return this.#e.map(([t,e])=>e==null?[t]:[t,e])}stringTuples(){return this.#r.map(([t,e])=>e==null?[t]:[t,e])}encapsulate(t){return t=new r(t),new r(this.toString()+t.toString())}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o))}decapsulateCode(t){let e=this.tuples();for(let n=e.length-1;n>=0;n--)if(e[n][0]===t)return new r(un(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(j.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=Ya.get(e.name);if(n==null)throw new ks(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>zt(s))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[xf](){return`Multiaddr(${this.#t})`}};var Ya=new Map;function fn(r){return!!r?.[Cs]}function zt(r){return new ln(r)}var Xa="libp2p-peer-record",Qa=Uint8Array.from([3,1]);var Sr;(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=>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=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 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=xs(ne(e.peerId)),o=(e.addresses??[]).map(i=>zt(i.multiaddr)),s=e.seq;return new r({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Xa;static CODEC=Qa;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||!Na(this.multiaddrs,t.multiaddrs))}};function Ef(r){return r[Symbol.asyncIterator]!=null}function vf(r){if(Ef(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 Ja=vf;function dn(r,t){let e={[Symbol.iterator]:()=>e,next:()=>{let n=r.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return e}var 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 dn(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((e,n)=>{t(e.value,e.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,e){this.map.set(t.toString(),{key:t,value:e})}keys(){return dn(this.map.values(),t=>t.key)}values(){return dn(this.map.values(),t=>t.value)}get size(){return this.map.size}};var Ks=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 Ds(r){let{name:t,metrics:e}=r,n;return e!=null?n=new Ks({name:t,metrics:e}):n=new Ir,n}var Ut=class extends Error{static name="AbortError";name="AbortError";constructor(t="The operation was aborted",...e){super(t,...e)}};function hn(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var pn=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},Ze=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new pn(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new pn(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var Us=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function tc(r={}){return Af(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 Af(r,t){t=t??{};let e=t.onEnd,n=new Ze,o,s,i,a=hn(),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(w){_(w)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=hn()})}},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,w;_!=null&&(q=new Promise((d,b)=>{w=()=>{b(new Us)},_.addEventListener("abort",w)}));try{await Promise.race([a.promise,q])}finally{w!=null&&_!=null&&_?.removeEventListener("abort",w)}}},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 Ns=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=e??"ABORT_ERR"}};async function mn(r,t,e,n){let o=new Ns(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 yn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};var gn=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 ec(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new gn(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new gn(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 bn=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 Ut)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Sf(){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=Sf(),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 Ut),this.cleanup())}async join(t={}){let e=new bn(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 ec(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 Os(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=Os(this.emitEmpty.bind(this),1),this.emitIdle=Os(this.emitIdle.bind(this),1)}[Symbol.asyncIterator](){return this.toGenerator()}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}tryToStartAnother(){if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let t;for(let e of this.queue)if(e.status==="queued"){t=e;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let e=0;e<this.queue.length;e++)if(this.queue[e]===t){this.queue.splice(e,1);break}this.pending--,this.safeDispatchEvent("next"),this.autoStart&&this.tryToStartAnother()}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}start(){this.autoStart===!1&&(this.autoStart=!0,this.tryToStartAnother())}pause(){this.autoStart=!1}async add(t,e){if(e?.signal?.throwIfAborted(),this.size===this.maxSize)throw new yn;let n=new 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 Ut)}),this.clear()}async onEmpty(t){this.size!==0&&await mn(this,"empty",t?.signal)}async onSizeLessThan(t,e){this.size<t||await mn(this,"next",e?.signal,{filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await mn(this,"idle",t?.signal)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(t){t?.signal?.throwIfAborted();let e=tc({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 Ut("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 wn="lock:worker:request-read",En="lock:worker:abort-read-request",vn="lock:worker:release-read",An="lock:master:grant-read",Sn="lock:master:error-read",In="lock:worker:request-write",Ln="lock:worker:abort-write-request",Rn="lock:worker:release-write",Bn="lock:master:grant-write",Tn="lock:master:error-write",_n="lock:worker:finalize",Pn="mortice",rc={singleProcess:!1};var Ms=(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===_n&&r.safeDispatchEvent("finalizeRequest",{detail:{name:u.name}})};var nc=(r=10)=>Math.random().toString().substring(2,r+2);var kn=class{name;channel;constructor(t){this.name=t,this.channel=new BroadcastChannel(Pn)}readLock(t){return this.sendRequest(wn,En,An,Sn,vn,t)}writeLock(t){return this.sendRequest(In,Ln,Bn,Tn,Rn,t)}finalize(){this.channel.postMessage({type:_n,name:this.name}),this.channel.close()}async sendRequest(t,e,n,o,s,i){i?.signal?.throwIfAborted();let a=nc();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 oc=r=>{if(r=Object.assign({},rc,r),!!globalThis.document||r.singleProcess){let e=new BroadcastChannel(Pn),n=new Te;return e.addEventListener("message",Ms(n,e,"requestReadLock","abortReadLockRequest",wn,En,Sn,vn,An)),e.addEventListener("message",Ms(n,e,"requestWriteLock","abortWriteLockRequest",In,Ln,Tn,Rn,Bn)),n}return new kn(r.name)};var Le=new Map,Rr;function sc(r){return typeof r?.readLock=="function"&&typeof r?.writeLock=="function"}function If(r){if(Rr==null&&(Rr=oc(r),!sc(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 qs(r,t){let e,n,o=new Promise((i,a)=>{e=i,n=a}),s=()=>{n(new Ut)};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 ic=(r,t)=>{let e=Le.get(r);if(e!=null)return e;let n=If(t);if(sc(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 qs(s,i);s=new Lr({concurrency:t.concurrency,autoStart:!1});let a=s,c=qs(s,i);return o.add(async()=>{a.start(),await a.onIdle().then(()=>{s===a&&(s=null)})}),c},async writeLock(i){return s=null,qs(o,i)},finalize:()=>{Le.delete(r)},queue:o},Le.set(r,e),e};var Lf={name:"lock",concurrency:1/0,singleProcess:!1};function Hs(r){let t=Object.assign({},Lf,r);return ic(t.name,t)}var te;(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=>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=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),Kn.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=Kn.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=xt((o,s,i={})=>{if(i.lengthDelimited!==!1&&s.fork(),o.addresses!=null)for(let a of o.addresses)s.uint32(10),Cn.codec().encode(a,s);if(o.protocols!=null)for(let a of o.protocols)s.uint32(18),s.string(a);if(o.publicKey!=null&&(s.uint32(34),s.bytes(o.publicKey)),o.peerRecordEnvelope!=null&&(s.uint32(42),s.bytes(o.peerRecordEnvelope)),o.metadata!=null&&o.metadata.size!==0)for(let[a,c]of o.metadata.entries())s.uint32(50),r.Peer$metadataEntry.codec().encode({key:a,value:c},s);if(o.tags!=null&&o.tags.size!==0)for(let[a,c]of o.tags.entries())s.uint32(58),r.Peer$tagsEntry.codec().encode({key:a,value:c},s);o.updated!=null&&(s.uint32(64),s.uint64Number(o.updated)),i.lengthDelimited!==!1&&s.ldelim()},(o,s,i={})=>{let a={addresses:[],protocols:[],metadata:new Map,tags:new Map},c=s==null?o.len:o.pos+s;for(;o.pos<c;){let 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(Cn.codec().decode(o,o.uint32(),{limits:i.limits?.addresses$}));break}case 2:{if(i.limits?.protocols!=null&&a.protocols.length===i.limits.protocols)throw new 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 pr('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 pr('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)})(te||(te={}));var Cn;(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=>bt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Cn||(Cn={}));var Kn;(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=>bt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Kn||(Kn={}));function Rf(r,t){if(r.publicKey!=null||t.publicKey==null)return r;let e;r.type==="RSA"&&(e=r.toMultihash());let n=en(t.publicKey,e);return Da(n)}function ac(r,t,e){let n=te.decode(t);return $e(r,n,e)}function $e(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:Rf(r,t),addresses:t.addresses.filter(({observed:s})=>s!=null&&s>Date.now()-e).map(({multiaddr:s,isCertified:i})=>({multiaddr:zt(s),isCertified:i??!1})),metadata:t.metadata,peerRecordEnvelope:t.peerRecordEnvelope??void 0,tags:n}}function cc(r,t){return Bf(r.addresses,t.addresses)&&Tf(r.protocols,t.protocols)&&_f(r.publicKey,t.publicKey)&&Pf(r.peerRecordEnvelope,t.peerRecordEnvelope)&&kf(r.metadata,t.metadata)&&Cf(r.tags,t.tags)}function Bf(r,t){return lc(r,t,(e,n)=>!(e.isCertified!==n.isCertified||!Y(e.multiaddr,n.multiaddr)))}function Tf(r,t){return lc(r,t,(e,n)=>e===n)}function _f(r,t){return uc(r,t)}function Pf(r,t){return uc(r,t)}function kf(r,t){return fc(r,t,(e,n)=>Y(e,n))}function Cf(r,t){return fc(r,t,(e,n)=>e.value===n.value&&e.expiry===n.expiry)}function uc(r,t){return r==null&&t==null?!0:r!=null&&t!=null?Y(r,t):!1}function lc(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 fc(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 ee="/",dc=new TextEncoder().encode(ee),Dn=dc[0],Un=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]!==Dn)throw new Error("Invalid key")}toString(t="utf8"){return N(this._buf,t)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(t){return new r(t.join(ee))}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=dc),this._buf[0]!==Dn){let t=new Uint8Array(this._buf.byteLength+1);t.fill(Dn,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Dn;)this._buf=this._buf.subarray(0,-1)}less(t){let e=this.list(),n=t.list();for(let o=0;o<e.length;o++){if(n.length<o+1)return!1;let s=e[o],i=n[o];if(s<i)return!0;if(s>i)return!1}return e.length<n.length}reverse(){return r.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let t=this.namespaces();return t[t.length-1]}list(){return this.toString().split(ee).slice(1)}type(){return Kf(this.baseNamespace())}name(){return Df(this.baseNamespace())}instance(t){return new r(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(ee)||(t+=ee),t+=this.type(),new r(t)}parent(){let t=this.list();return t.length===1?new r(ee):new r(t.slice(0,-1).join(ee))}child(t){return this.toString()===ee?t:t.toString()===ee?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(),...Uf(t.map(e=>e.namespaces()))])}};function Kf(r){let t=r.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function Df(r){let t=r.split(":");return t[t.length-1]}function Uf(r){return[].concat(...r)}var zs="/peers/";function Br(r){if(!Re(r)||r.type==null)throw new z("Invalid PeerId");let t=r.toCID().toString();return new Un(`${zs}${t}`)}async function hc(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=zt(i.multiaddr)),!fn(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(zt(`/p2p/${r}`))),{isCertified:i,multiaddr:a.bytes}})}async function On(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=Nn(p,{validate:pc})}if(t.tags!=null){let p=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags);c=Nn(p,{validate:mc,map:yc})}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=Nn([...a.entries()],{validate:pc})}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=Nn([...g.entries()],{validate:mc,map:yc})}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 hc(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 Nn(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 pc(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 mc(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 yc(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 gc(r){let t=r.toString().split("/")[2],e=tt.parse(t,Pt);return rn(e)}function Vs(r,t,e){let n=gc(r);return ac(n,t,e)}function Nf(r,t){return{prefix:zs,filters:(r.filters??[]).map(e=>({key:n,value:o})=>e(Vs(n,o,t))),orders:(r.orders??[]).map(e=>(n,o)=>e(Vs(n.key,n.value,t),Vs(o.key,o.value,t)))}}var Mn=class{peerId;datastore;locks;addressFilter;log;maxAddressAge;maxPeerAge;constructor(t,e={}){this.log=t.logger.forComponent("libp2p:peer-store"),this.peerId=t.peerId,this.datastore=t.datastore,this.addressFilter=e.addressFilter,this.locks=Ds({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:Hs({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=te.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,e),new Ye;return $e(t,s,this.peerId.equals(t)?1/0:this.maxAddressAge)}async save(t,e,n){let o=await this.#t(t,n),s=await On(t,e,"patch",{...n,addressFilter:this.addressFilter});return this.#e(t,s,o)}async patch(t,e,n){let o=await this.#t(t,n),s=await On(t,e,"patch",{...n,addressFilter:this.addressFilter,existingPeer:o});return this.#e(t,s,o)}async merge(t,e,n){let o=await this.#t(t,n),s=await On(t,e,"merge",{addressFilter:this.addressFilter,existingPeer:o});return this.#e(t,s,o)}async*all(t){for await(let{key:e,value:n}of this.datastore.query(Nf(t??{},this.maxAddressAge),t)){let o=gc(e);if(o.equals(this.peerId))continue;let s=te.decode(n);if(this.#r(o,s)){await this.datastore.delete(e,t);continue}yield $e(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=te.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,e),new Ye;return{peerPB:s,peer:$e(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=te.encode(e);return await this.datastore.put(Br(t),s,o),{peer:$e(t,e,this.maxAddressAge),previous:n?.peer,updated:n==null||!cc(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 Fs=class{store;events;peerId;log;constructor(t,e={}){this.log=t.logger.forComponent("libp2p:peer-store"),this.events=t.events,this.peerId=t.peerId,this.store=new Mn(t,e)}[Symbol.toStringTag]="@libp2p/peer-store";async forEach(t,e){for await(let n of this.store.all(e))t(n)}async all(t){return Ja(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=rn(i.publicKey.toCID());if(o?.equals(a)===!1)return this.log("envelope peer id was not the expected peer id - expected: %p received: %p",o,a),!1;let c=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 Of(r,t={}){return new Fs(r,t)}return Lc(Mf);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/hashes/esm/utils.js: