@libp2p/peer-store 11.2.6-cb1c14e62 → 11.2.6-cf9aab5c8
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 +1 -1
- package/dist/index.min.js.map +3 -3
- package/package.json +7 -7
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 io=Object.defineProperty;var Yc=Object.getOwnPropertyDescriptor;var jc=Object.getOwnPropertyNames;var Xc=Object.prototype.hasOwnProperty;var mt=(r,t)=>{for(var e in t)io(r,e,{get:t[e],enumerable:!0})},Qc=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of jc(t))!Xc.call(r,o)&&o!==e&&io(r,o,{get:()=>t[o],enumerable:!(n=Yc(t,o))||n.enumerable});return r};var Jc=r=>Qc(io({},"__esModule",{value:!0}),r);var jd={};mt(jd,{persistentPeerStore:()=>Yd});var Fr=Symbol.for("@libp2p/peer-id");function Le(r){return!!r?.[Fr]}var q=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Re=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var sr=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var Wr=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},Gr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var ye=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Pe=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 fo={};mt(fo,{base58btc:()=>Z,base58flickr:()=>iu});var eh=new Uint8Array(0);function yi(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 Mt(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 bi(r){return new TextEncoder().encode(r)}function gi(r){return new TextDecoder().decode(r)}function tu(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),f=Math.log(256)/Math.log(a);function d(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var x=0,p=0,v=0,_=m.length;v!==_&&m[v]===0;)v++,x++;for(var S=(_-v)*f+1>>>0,C=new Uint8Array(S);v!==_;){for(var P=m[v],T=0,K=S-1;(P!==0||T<p)&&K!==-1;K--,T++)P+=256*C[K]>>>0,C[K]=P%a>>>0,P=P/a>>>0;if(P!==0)throw new Error("Non-zero carry");p=T,v++}for(var N=S-p;N!==S&&C[N]===0;)N++;for(var D=c.repeat(x);N<S;++N)D+=r.charAt(C[N]);return D}function u(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var x=0;if(m[x]!==" "){for(var p=0,v=0;m[x]===c;)p++,x++;for(var _=(m.length-x)*l+1>>>0,S=new Uint8Array(_);m[x];){var C=e[m.charCodeAt(x)];if(C===255)return;for(var P=0,T=_-1;(C!==0||P<v)&&T!==-1;T--,P++)C+=a*S[T]>>>0,S[T]=C%256>>>0,C=C/256>>>0;if(C!==0)throw new Error("Non-zero carry");v=P,x++}if(m[x]!==" "){for(var K=_-v;K!==_&&S[K]===0;)K++;for(var N=new Uint8Array(p+(_-K)),D=p;K!==_;)N[D++]=S[K++];return N}}}function h(m){var x=u(m);if(x)return x;throw new Error(`Non-${t} character`)}return{encode:d,decodeUnsafe:u,decode:h}}var eu=tu,ru=eu,wi=ru;var ao=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")}},co=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Ei(this,t)}},uo=class{decoders;constructor(t){this.decoders=t}or(t){return Ei(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ei(r,t){return new uo({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var lo=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 ao(t,e,n),this.decoder=new co(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Oe({name:r,prefix:t,encode:e,decode:n}){return new lo(r,t,e,n)}function oe({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=wi(e,r);return Oe({prefix:t,name:r,encode:n,decode:s=>Mt(o(s))})}function nu(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 f=t[r[l]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|f,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 ou(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 su(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=su(n);return Oe({prefix:t,name:r,encode(s){return ou(s,n,e)},decode(s){return nu(s,o,e,r)}})}var Z=oe({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),iu=oe({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ho={};mt(ho,{base32:()=>Ot,base32hex:()=>lu,base32hexpad:()=>du,base32hexpadupper:()=>hu,base32hexupper:()=>fu,base32pad:()=>cu,base32padupper:()=>uu,base32upper:()=>au,base32z:()=>pu});var Ot=j({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),au=j({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),cu=j({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),uu=j({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),lu=j({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),fu=j({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),du=j({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),hu=j({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),pu=j({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var po={};mt(po,{base36:()=>ir,base36upper:()=>mu});var ir=oe({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),mu=oe({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var yu=Ai,vi=128,bu=127,gu=~bu,xu=Math.pow(2,31);function Ai(r,t,e){t=t||[],e=e||0;for(var n=e;r>=xu;)t[e++]=r&255|vi,r/=128;for(;r&gu;)t[e++]=r&255|vi,r>>>=7;return t[e]=r|0,Ai.bytes=e-n+1,t}var wu=mo,Eu=128,Si=127;function mo(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw mo.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Si)<<o:(i&Si)*Math.pow(2,o),o+=7}while(i>=Eu);return mo.bytes=s-n,e}var vu=Math.pow(2,7),Su=Math.pow(2,14),Au=Math.pow(2,21),Iu=Math.pow(2,28),_u=Math.pow(2,35),Tu=Math.pow(2,42),Bu=Math.pow(2,49),Cu=Math.pow(2,56),Du=Math.pow(2,63),Lu=function(r){return r<vu?1:r<Su?2:r<Au?3:r<Iu?4:r<_u?5:r<Tu?6:r<Bu?7:r<Cu?8:r<Du?9:10},Ru={encode:yu,decode:wu,encodingLength:Lu},Pu=Ru,ar=Pu;function cr(r,t=0){return[ar.decode(r,t),ar.decode.bytes]}function ke(r,t,e=0){return ar.encode(r,t,e),t}function Ke(r){return ar.encodingLength(r)}function Dt(r,t){let e=t.byteLength,n=Ke(r),o=n+Ke(e),s=new Uint8Array(o+e);return ke(r,s,0),ke(e,s,n),s.set(t,o),new Ne(r,e,t,s)}function Ue(r){let t=Mt(r),[e,n]=cr(t),[o,s]=cr(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ne(e,o,i,t)}function Ii(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&yi(r.bytes,e.bytes)}}var Ne=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function _i(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return ku(e,yo(r),t??Z.encoder);default:return Ku(e,yo(r),t??Ot.encoder)}}var Ti=new WeakMap;function yo(r){let t=Ti.get(r);if(t==null){let e=new Map;return Ti.set(r,e),e}return t}var X=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!==ur)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Nu)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=Dt(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&Ii(t.multihash,n.multihash)}toString(t){return _i(this,t)}toJSON(){return{"/":_i(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??Bi(n,o,s.bytes))}else if(e[Uu]===!0){let{version:n,multihash:o,code:s}=e,i=Ue(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!==ur)throw new Error(`Version 0 CID must use dag-pb (code: ${ur}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Bi(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,ur,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=Mt(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 Ne(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[d,u]=cr(t.subarray(e));return e+=u,d},o=n(),s=ur;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,f=l-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:l}}static parse(t,e){let[n,o]=Ou(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return yo(s).set(n,t),s}};function Ou(r,t){switch(r[0]){case"Q":{let e=t??Z;return[Z.prefix,e.decode(`${Z.prefix}${r}`)]}case Z.prefix:{let e=t??Z;return[Z.prefix,e.decode(r)]}case Ot.prefix:{let e=t??Ot;return[Ot.prefix,e.decode(r)]}case ir.prefix:{let e=t??ir;return[ir.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 ku(r,t,e){let{prefix:n}=e;if(n!==Z.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function Ku(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 ur=112,Nu=18;function Bi(r,t,e){let n=Ke(r),o=n+Ke(t),s=new Uint8Array(o+e.byteLength);return ke(r,s,0),ke(t,s,n),s.set(e,o),s}var Uu=Symbol.for("@ipld/js-cid/CID");var bo={};mt(bo,{identity:()=>Lt});var Ci=0,Mu="identity",Di=Mt;function qu(r){return Dt(Ci,Di(r))}var Lt={code:Ci,name:Mu,encode:Di,digest:qu};function $(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 et(r=0){return new Uint8Array(r)}function yt(r=0){return new Uint8Array(r)}function qt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=yt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var Ri=Symbol.for("@achingbrain/uint8arraylist");function Li(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function $r(r){return!!r?.[Ri]}var lt=class r{bufs;length;[Ri]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if($r(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if($r(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=Li(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Li(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if($r(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return qt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:qt(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,f=e>a&&e<=c;if(l&&f){if(t===a&&e===c){n.push(i);break}let d=t-a;n.push(i.subarray(d,d+(e-t)));break}if(l){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!$r(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let d=0;d<s;d++)i[d]=-1;for(let d=0;d<o;d++)i[n[d]]=d;let a=i,c=this.byteLength-n.byteLength,l=n.byteLength-1,f;for(let d=e;d<=c;d+=f){f=0;for(let u=l;u>=0;u--){let h=this.get(d+u);if(n[u]!==h){f=Math.max(1,u-a[h]);break}}if(f===0)return d}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=yt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=et(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=et(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=et(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=yt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=et(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=et(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=et(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=et(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=et(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(!$(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 go={};mt(go,{base10:()=>Hu});var Hu=oe({prefix:"9",name:"base10",alphabet:"0123456789"});var xo={};mt(xo,{base16:()=>Vu,base16upper:()=>zu});var Vu=j({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),zu=j({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var wo={};mt(wo,{base2:()=>Fu});var Fu=j({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Eo={};mt(Eo,{base256emoji:()=>Yu});var Pi=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Wu=Pi.reduce((r,t,e)=>(r[e]=t,r),[]),Gu=Pi.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Zu(r){return r.reduce((t,e)=>(t+=Wu[e],t),"")}function $u(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Gu[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Yu=Oe({prefix:"\u{1F680}",name:"base256emoji",encode:Zu,decode:$u});var So={};mt(So,{base64:()=>ju,base64pad:()=>Xu,base64url:()=>vo,base64urlpad:()=>Qu});var ju=j({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Xu=j({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),vo=j({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Qu=j({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ao={};mt(Ao,{base8:()=>Ju});var Ju=j({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Io={};mt(Io,{identity:()=>tl});var tl=Oe({prefix:"\0",name:"identity",encode:r=>gi(r),decode:r=>bi(r)});var Uh=new TextEncoder,Mh=new TextDecoder;var Bo={};mt(Bo,{sha256:()=>lr,sha512:()=>nl});function To({name:r,code:t,encode:e}){return new _o(r,t,e)}var _o=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?Dt(this.code,e):e.then(n=>Dt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function ki(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var lr=To({name:"sha2-256",code:18,encode:ki("SHA-256")}),nl=To({name:"sha2-512",code:19,encode:ki("SHA-512")});var fr={...Io,...wo,...Ao,...go,...xo,...ho,...po,...fo,...So,...Eo},Xh={...Bo,...bo};function Ni(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Ki=Ni("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Co=Ni("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=yt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),ol={utf8:Ki,"utf-8":Ki,hex:fr.base16,latin1:Co,ascii:Co,binary:Co,...fr},Yr=ol;function H(r,t="utf8"){let e=Yr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function M(r,t="utf8"){let e=Yr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var sl=parseInt("11111",2),Do=parseInt("10000000",2),il=parseInt("01111111",2),Ui={0:dr,1:dr,2:al,3:ll,4:fl,5:ul,6:cl,16:dr,22:dr,48:dr};function Ht(r,t={offset:0}){let e=r[t.offset]&sl;if(t.offset++,Ui[e]!=null)return Ui[e](r,t);throw new Error("No decoder for tag "+e)}function hr(r,t){let e=0;if((r[t.offset]&Do)===Do){let n=r[t.offset]&il,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 dr(r,t){hr(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Ht(r,t);if(n===null)break;e.push(n)}return e}function al(r,t){let e=hr(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 cl(r,t){let e=hr(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 f=0;for(let d=0;d<c.length;d++)f+=c[d]<<d*7;a+=`.${f}`,c=[]}}return a}function ul(r,t){return t.offset++,null}function ll(r,t){let e=hr(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 fl(r,t){let e=hr(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function dl(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new lt;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Lo(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=dl(r.byteLength);return new lt(Uint8Array.from([t.byteLength|Do]),t)}function bt(r){let t=new lt,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new lt(Uint8Array.from([2]),Lo(t),t)}function jr(r){let t=Uint8Array.from([0]),e=new lt(t,r);return new lt(Uint8Array.from([3]),Lo(e),e)}function ie(r,t=48){let e=new lt;for(let n of r)e.append(n);return new lt(Uint8Array.from([t]),Lo(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 hl=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),pl=Uint8Array.from([6,5,43,129,4,0,34]),ml=Uint8Array.from([6,5,43,129,4,0,35]),yl={ext:!0,kty:"EC",crv:"P-256"},bl={ext:!0,kty:"EC",crv:"P-384"},gl={ext:!0,kty:"EC",crv:"P-521"},Ro=32,Po=48,Oo=66;function ko(r){let t=Ht(r);return qi(t)}function qi(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===Ro*2+1)return n=M(t.subarray(e,e+Ro),"base64url"),o=M(t.subarray(e+Ro),"base64url"),new Me({...yl,key_ops:["verify"],x:n,y:o});if(t.byteLength===Po*2+1)return n=M(t.subarray(e,e+Po),"base64url"),o=M(t.subarray(e+Po),"base64url"),new Me({...bl,key_ops:["verify"],x:n,y:o});if(t.byteLength===Oo*2+1)return n=M(t.subarray(e,e+Oo),"base64url"),o=M(t.subarray(e+Oo),"base64url"),new Me({...gl,key_ops:["verify"],x:n,y:o});throw new q(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Hi(r){return ie([bt(Uint8Array.from([1])),ie([xl(r.crv)],160),ie([jr(new lt(Uint8Array.from([4]),H(r.x??"","base64url"),H(r.y??"","base64url")))],161)]).subarray()}function xl(r){if(r==="P-256")return hl;if(r==="P-384")return pl;if(r==="P-521")return ml;throw new q(`Invalid curve ${r}`)}var Me=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Hi(this.jwk)),this._raw}toMultihash(){return Lt.digest(_t(this))}toCID(){return X.createV1(114,this.toMultihash())}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:$(this.raw,t.raw)}async verify(t,e,n){return Mi(this.jwk,e,t,n)}};var be=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function ge(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function pr(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function Q(r,...t){if(!ge(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 Xr(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");pr(r.outputLen),pr(r.blockLen)}function He(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 zi(r,t){Q(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}function zt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Qr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Rt(r,t){return r<<32-t|r>>>t}var Fi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",wl=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Tt(r){if(Q(r),Fi)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=wl[r[e]];return t}var Vt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Vi(r){if(r>=Vt._0&&r<=Vt._9)return r-Vt._0;if(r>=Vt.A&&r<=Vt.F)return r-(Vt.A-10);if(r>=Vt.a&&r<=Vt.f)return r-(Vt.a-10)}function xe(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(Fi)return Uint8Array.fromHex(r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=Vi(r.charCodeAt(s)),a=Vi(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Ko(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function mr(r){return typeof r=="string"&&(r=Ko(r)),Q(r),r}function gt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Q(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 qe=class{};function No(r){let t=n=>r().update(mr(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function yr(r=32){if(be&&typeof be.getRandomValues=="function")return be.getRandomValues(new Uint8Array(r));if(be&&typeof be.randomBytes=="function")return Uint8Array.from(be.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function El(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 Wi(r,t,e){return r&t^~r&e}function Gi(r,t,e){return r&t^r&e^t&e}var br=class extends qe{constructor(t,e,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Qr(this.buffer)}update(t){He(this),t=mr(t),Q(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Qr(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){He(this),zi(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,zt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let d=i;d<o;d++)e[d]=0;El(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=Qr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=c/4,f=this.get();if(l>f.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<l;d++)a.setUint32(4*d,f[d],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()}},Ft=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var it=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Jr=BigInt(4294967295),Zi=BigInt(32);function vl(r,t=!1){return t?{h:Number(r&Jr),l:Number(r>>Zi&Jr)}:{h:Number(r>>Zi&Jr)|0,l:Number(r&Jr)|0}}function $i(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}=vl(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Uo=(r,t,e)=>r>>>e,Mo=(r,t,e)=>r<<32-e|t>>>e,we=(r,t,e)=>r>>>e|t<<32-e,Ee=(r,t,e)=>r<<32-e|t>>>e,gr=(r,t,e)=>r<<64-e|t>>>e-32,xr=(r,t,e)=>r>>>e-32|t<<64-e;function kt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Yi=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),ji=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Xi=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Qi=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Ji=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),ta=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Al=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),ae=new Uint32Array(64),tn=class extends br{constructor(t=32){super(64,t,8,!1),this.A=Ft[0]|0,this.B=Ft[1]|0,this.C=Ft[2]|0,this.D=Ft[3]|0,this.E=Ft[4]|0,this.F=Ft[5]|0,this.G=Ft[6]|0,this.H=Ft[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 d=0;d<16;d++,e+=4)ae[d]=t.getUint32(e,!1);for(let d=16;d<64;d++){let u=ae[d-15],h=ae[d-2],m=Rt(u,7)^Rt(u,18)^u>>>3,x=Rt(h,17)^Rt(h,19)^h>>>10;ae[d]=x+ae[d-7]+m+ae[d-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:l,H:f}=this;for(let d=0;d<64;d++){let u=Rt(a,6)^Rt(a,11)^Rt(a,25),h=f+u+Wi(a,c,l)+Al[d]+ae[d]|0,x=(Rt(n,2)^Rt(n,13)^Rt(n,22))+Gi(n,o,s)|0;f=l,l=c,c=a,a=i+h|0,i=s,s=o,o=n,n=h+x|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,f=f+this.H|0,this.set(n,o,s,i,a,c,l,f)}roundClean(){zt(ae)}destroy(){this.set(0,0,0,0,0,0,0,0),zt(this.buffer)}};var ea=$i(["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))),Il=ea[0],_l=ea[1],ce=new Uint32Array(80),ue=new Uint32Array(80),qo=class extends br{constructor(t=64){super(128,t,16,!1),this.Ah=it[0]|0,this.Al=it[1]|0,this.Bh=it[2]|0,this.Bl=it[3]|0,this.Ch=it[4]|0,this.Cl=it[5]|0,this.Dh=it[6]|0,this.Dl=it[7]|0,this.Eh=it[8]|0,this.El=it[9]|0,this.Fh=it[10]|0,this.Fl=it[11]|0,this.Gh=it[12]|0,this.Gl=it[13]|0,this.Hh=it[14]|0,this.Hl=it[15]|0}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:l,El:f,Fh:d,Fl:u,Gh:h,Gl:m,Hh:x,Hl:p}=this;return[t,e,n,o,s,i,a,c,l,f,d,u,h,m,x,p]}set(t,e,n,o,s,i,a,c,l,f,d,u,h,m,x,p){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=l|0,this.El=f|0,this.Fh=d|0,this.Fl=u|0,this.Gh=h|0,this.Gl=m|0,this.Hh=x|0,this.Hl=p|0}process(t,e){for(let S=0;S<16;S++,e+=4)ce[S]=t.getUint32(e),ue[S]=t.getUint32(e+=4);for(let S=16;S<80;S++){let C=ce[S-15]|0,P=ue[S-15]|0,T=we(C,P,1)^we(C,P,8)^Uo(C,P,7),K=Ee(C,P,1)^Ee(C,P,8)^Mo(C,P,7),N=ce[S-2]|0,D=ue[S-2]|0,b=we(N,D,19)^gr(N,D,61)^Uo(N,D,6),y=Ee(N,D,19)^xr(N,D,61)^Mo(N,D,6),E=Xi(K,y,ue[S-7],ue[S-16]),A=Qi(E,T,b,ce[S-7],ce[S-16]);ce[S]=A|0,ue[S]=E|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:l,Dl:f,Eh:d,El:u,Fh:h,Fl:m,Gh:x,Gl:p,Hh:v,Hl:_}=this;for(let S=0;S<80;S++){let C=we(d,u,14)^we(d,u,18)^gr(d,u,41),P=Ee(d,u,14)^Ee(d,u,18)^xr(d,u,41),T=d&h^~d&x,K=u&m^~u&p,N=Ji(_,P,K,_l[S],ue[S]),D=ta(N,v,C,T,Il[S],ce[S]),b=N|0,y=we(n,o,28)^gr(n,o,34)^gr(n,o,39),E=Ee(n,o,28)^xr(n,o,34)^xr(n,o,39),A=n&s^n&a^s&a,L=o&i^o&c^i&c;v=x|0,_=p|0,x=h|0,p=m|0,h=d|0,m=u|0,{h:d,l:u}=kt(l|0,f|0,D|0,b|0),l=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let R=Yi(b,E,L);n=ji(R,D,y,A),o=R|0}({h:n,l:o}=kt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=kt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=kt(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:f}=kt(this.Dh|0,this.Dl|0,l|0,f|0),{h:d,l:u}=kt(this.Eh|0,this.El|0,d|0,u|0),{h,l:m}=kt(this.Fh|0,this.Fl|0,h|0,m|0),{h:x,l:p}=kt(this.Gh|0,this.Gl|0,x|0,p|0),{h:v,l:_}=kt(this.Hh|0,this.Hl|0,v|0,_|0),this.set(n,o,s,i,a,c,l,f,d,u,h,m,x,p,v,_)}roundClean(){zt(ce,ue)}destroy(){zt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var en=No(()=>new tn);var ra=No(()=>new qo);var zo=BigInt(0),Vo=BigInt(1);function Wt(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function wr(r){let t=r.toString(16);return t.length&1?"0"+t:t}function na(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?zo:BigInt("0x"+r)}function Ve(r){return na(Tt(r))}function Gt(r){return Q(r),na(Tt(Uint8Array.from(r).reverse()))}function rn(r,t){return xe(r.toString(16).padStart(t*2,"0"))}function Zt(r,t){return rn(r,t).reverse()}function F(r,t,e){let n;if(typeof t=="string")try{n=xe(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(ge(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 oa(r,t){if(r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}var Ho=r=>typeof r=="bigint"&&zo<=r;function sa(r,t,e){return Ho(r)&&Ho(t)&&Ho(e)&&t<=r&&r<e}function le(r,t,e,n){if(!sa(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function nn(r){let t;for(t=0;r>zo;r>>=Vo,t+=1);return t}var fe=r=>(Vo<<BigInt(r))-Vo;function ia(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=h=>new Uint8Array(h),o=h=>Uint8Array.of(h),s=n(r),i=n(r),a=0,c=()=>{s.fill(1),i.fill(0),a=0},l=(...h)=>e(i,s,...h),f=(h=n(0))=>{i=l(o(0),h),s=l(),h.length!==0&&(i=l(o(1),h),s=l())},d=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let h=0,m=[];for(;h<t;){s=l();let x=s.slice();m.push(x),h+=s.length}return gt(...m)};return(h,m)=>{c(),f(h);let x;for(;!(x=m(d()));)f();return c(),x}}function de(r,t,e={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(o,s,i){let a=r[o];if(i&&a===void 0)return;let c=typeof a;if(c!==s||a===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${c}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(e).forEach(([o,s])=>n(o,s,!0))}function ze(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 ft=BigInt(0),ot=BigInt(1),ve=BigInt(2),ua=BigInt(3),la=BigInt(4),fa=BigInt(5),Tl=BigInt(7),da=BigInt(8),Bl=BigInt(9),ha=BigInt(16);function J(r,t){let e=r%t;return e>=ft?e:t+e}function Y(r,t,e){let n=r;for(;t-- >ft;)n*=n,n%=e;return n}function aa(r,t){if(r===ft)throw new Error("invert: expected non-zero number");if(t<=ft)throw new Error("invert: expected positive modulus, got "+t);let e=J(r,t),n=t,o=ft,s=ot,i=ot,a=ft;for(;e!==ft;){let l=n/e,f=n%e,d=o-i*l,u=s-a*l;n=e,e=f,o=i,s=a,i=d,a=u}if(n!==ot)throw new Error("invert: does not exist");return J(o,t)}function Fo(r,t,e){if(!r.eql(r.sqr(t),e))throw new Error("Cannot find square root")}function pa(r,t){let e=(r.ORDER+ot)/la,n=r.pow(t,e);return Fo(r,n,t),n}function Cl(r,t){let e=(r.ORDER-fa)/da,n=r.mul(t,ve),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,ve),o),a=r.mul(s,r.sub(i,r.ONE));return Fo(r,a,t),a}function Dl(r){let t=Et(r),e=ma(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+Tl)/ha;return(a,c)=>{let l=a.pow(c,i),f=a.mul(l,n),d=a.mul(l,o),u=a.mul(l,s),h=a.eql(a.sqr(f),c),m=a.eql(a.sqr(d),c);l=a.cmov(l,f,h),f=a.cmov(u,d,m);let x=a.eql(a.sqr(f),c),p=a.cmov(l,f,x);return Fo(a,p,c),p}}function ma(r){if(r<ua)throw new Error("sqrt is not defined for small field");let t=r-ot,e=0;for(;t%ve===ft;)t/=ve,e++;let n=ve,o=Et(r);for(;ca(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return pa;let s=o.pow(n,t),i=(t+ot)/ve;return function(c,l){if(c.is0(l))return l;if(ca(c,l)!==1)throw new Error("Cannot find square root");let f=e,d=c.mul(c.ONE,s),u=c.pow(l,t),h=c.pow(l,i);for(;!c.eql(u,c.ONE);){if(c.is0(u))return c.ZERO;let m=1,x=c.sqr(u);for(;!c.eql(x,c.ONE);)if(m++,x=c.sqr(x),m===f)throw new Error("Cannot find square root");let p=ot<<BigInt(f-m-1),v=c.pow(d,p);f=m,d=c.sqr(v),u=c.mul(u,d),h=c.mul(h,v)}return h}}function Ll(r){return r%la===ua?pa:r%da===fa?Cl:r%ha===Bl?Dl(r):ma(r)}var $t=(r,t)=>(J(r,t)&ot)===ot,Rl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Wo(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},e=Rl.reduce((n,o)=>(n[o]="function",n),t);return de(r,e),r}function Pl(r,t,e){if(e<ft)throw new Error("invalid exponent, negatives unsupported");if(e===ft)return r.ONE;if(e===ot)return t;let n=r.ONE,o=t;for(;e>ft;)e&ot&&(n=r.mul(n,o)),o=r.sqr(o),e>>=ot;return n}function Er(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 ca(r,t){let e=(r.ORDER-ot)/ve,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 ya(r,t){t!==void 0&&pr(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Et(r,t,e=!1,n={}){if(r<=ft)throw new Error("invalid field: expected ORDER > 0, got "+r);let o,s,i=!1,a;if(typeof t=="object"&&t!=null){if(n.sqrt||e)throw new Error("cannot specify opts in two arguments");let u=t;u.BITS&&(o=u.BITS),u.sqrt&&(s=u.sqrt),typeof u.isLE=="boolean"&&(e=u.isLE),typeof u.modOnDecode=="boolean"&&(i=u.modOnDecode),a=u.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:c,nByteLength:l}=ya(r,o);if(l>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let f,d=Object.freeze({ORDER:r,isLE:e,BITS:c,BYTES:l,MASK:fe(c),ZERO:ft,ONE:ot,allowedLengths:a,create:u=>J(u,r),isValid:u=>{if(typeof u!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof u);return ft<=u&&u<r},is0:u=>u===ft,isValidNot0:u=>!d.is0(u)&&d.isValid(u),isOdd:u=>(u&ot)===ot,neg:u=>J(-u,r),eql:(u,h)=>u===h,sqr:u=>J(u*u,r),add:(u,h)=>J(u+h,r),sub:(u,h)=>J(u-h,r),mul:(u,h)=>J(u*h,r),pow:(u,h)=>Pl(d,u,h),div:(u,h)=>J(u*aa(h,r),r),sqrN:u=>u*u,addN:(u,h)=>u+h,subN:(u,h)=>u-h,mulN:(u,h)=>u*h,inv:u=>aa(u,r),sqrt:s||(u=>(f||(f=Ll(r)),f(d,u))),toBytes:u=>e?Zt(u,l):rn(u,l),fromBytes:(u,h=!0)=>{if(a){if(!a.includes(u.length)||u.length>l)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+u.length);let x=new Uint8Array(l);x.set(u,e?0:x.length-u.length),u=x}if(u.length!==l)throw new Error("Field.fromBytes: expected "+l+" bytes, got "+u.length);let m=e?Gt(u):Ve(u);if(i&&(m=J(m,r)),!h&&!d.isValid(m))throw new Error("invalid field element: outside of range 0..ORDER");return m},invertBatch:u=>Er(d,u),cmov:(u,h,m)=>m?h:u});return Object.freeze(d)}function ba(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 Go(r){let t=ba(r);return t+Math.ceil(t/2)}function Zo(r,t,e=!1){let n=r.length,o=ba(t),s=Go(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?Gt(r):Ve(r),a=J(i,t-ot)+ot;return e?Zt(a,o):rn(a,o)}var Fe=BigInt(0),Se=BigInt(1);function vr(r,t){let e=t.negate();return r?e:t}function Yt(r,t){let e=Er(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function Ea(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function $o(r,t){Ea(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=fe(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function ga(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+=Se);let l=t*n,f=l+Math.abs(a)-1,d=a===0,u=a<0,h=t%2!==0;return{nextN:c,offset:f,isZero:d,isNeg:u,isNegF:h,offsetF:l}}function Ol(r,t){if(!Array.isArray(r))throw new Error("array expected");r.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})}function kl(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 Yo=new WeakMap,va=new WeakMap;function jo(r){return va.get(r)||1}function xa(r){if(r!==Fe)throw new Error("invalid wNAF")}var We=class{constructor(t,e){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=e}_unsafeLadder(t,e,n=this.ZERO){let o=t;for(;e>Fe;)e&Se&&(n=n.add(o)),o=o.double(),e>>=Se;return n}precomputeWindow(t,e){let{windows:n,windowSize:o}=$o(e,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let l=1;l<o;l++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(t,e,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=$o(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:l,isZero:f,isNeg:d,isNegF:u,offsetF:h}=ga(n,a,i);n=c,f?s=s.add(vr(u,e[h])):o=o.add(vr(d,e[l]))}return xa(n),{p:o,f:s}}wNAFUnsafe(t,e,n,o=this.ZERO){let s=$o(t,this.bits);for(let i=0;i<s.windows&&n!==Fe;i++){let{nextN:a,offset:c,isZero:l,isNeg:f}=ga(n,i,s);if(n=a,!l){let d=e[c];o=o.add(f?d.negate():d)}}return xa(n),o}getPrecomputes(t,e,n){let o=Yo.get(e);return o||(o=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(o=n(o)),Yo.set(e,o))),o}cached(t,e,n){let o=jo(t);return this.wNAF(o,this.getPrecomputes(o,t,n),e)}unsafe(t,e,n,o){let s=jo(t);return s===1?this._unsafeLadder(t,e,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),e,o)}createCache(t,e){Ea(e,this.bits),va.set(t,e),Yo.delete(t)}hasCache(t){return jo(t)!==1}};function Sa(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>Fe||n>Fe;)e&Se&&(s=s.add(o)),n&Se&&(i=i.add(o)),o=o.double(),e>>=Se,n>>=Se;return{p1:s,p2:i}}function Ge(r,t,e,n){Ol(e,r),kl(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=nn(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let l=fe(c),f=new Array(Number(l)+1).fill(i),d=Math.floor((t.BITS-1)/c)*c,u=i;for(let h=d;h>=0;h-=c){f.fill(i);for(let x=0;x<s;x++){let p=n[x],v=Number(p>>BigInt(h)&l);f[v]=f[v].add(e[x])}let m=i;for(let x=f.length-1,p=i;x>0;x--)p=p.add(f[x]),m=m.add(p);if(u=u.add(m),h!==0)for(let x=0;x<c;x++)u=u.double()}return u}function wa(r,t){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Wo(t),t}else return Et(r)}function on(r,t,e={}){if(!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let a of["p","n","h"]){let c=t[a];if(!(typeof c=="bigint"&&c>Fe))throw new Error(`CURVE.${a} must be positive bigint`)}let n=wa(t.p,e.Fp),o=wa(t.n,e.Fn),i=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let a of i)if(!n.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return{Fp:n,Fn:o}}var Kt=BigInt(0),nt=BigInt(1),Xo=BigInt(2),Kl=BigInt(8);function Nl(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),a=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,a)}function Ul(r,t={}){let{Fp:e,Fn:n}=on("edwards",r,t),{h:o,n:s}=r;de(t,{},{uvRatio:"function"});let i=Xo<<BigInt(n.BYTES*8)-nt,a=x=>e.create(x),c=t.uvRatio||((x,p)=>{try{return{isValid:!0,value:e.sqrt(e.div(x,p))}}catch{return{isValid:!1,value:Kt}}});if(!Nl(e,r,r.Gx,r.Gy))throw new Error("bad curve params: generator point");function l(x,p,v=!1){let _=v?nt:Kt;return le("coordinate "+x,p,_,i),p}function f(x){if(!(x instanceof h))throw new Error("ExtendedPoint expected")}let d=ze((x,p)=>{let{X:v,Y:_,Z:S}=x,C=x.is0();p==null&&(p=C?Kl:e.inv(S));let P=a(v*p),T=a(_*p),K=e.mul(S,p);if(C)return{x:Kt,y:nt};if(K!==nt)throw new Error("invZ was invalid");return{x:P,y:T}}),u=ze(x=>{let{a:p,d:v}=r;if(x.is0())throw new Error("bad point: ZERO");let{X:_,Y:S,Z:C,T:P}=x,T=a(_*_),K=a(S*S),N=a(C*C),D=a(N*N),b=a(T*p),y=a(N*a(b+K)),E=a(D+a(v*a(T*K)));if(y!==E)throw new Error("bad point: equation left != right (1)");let A=a(_*S),L=a(C*P);if(A!==L)throw new Error("bad point: equation left != right (2)");return!0});class h{constructor(p,v,_,S){this.X=l("x",p),this.Y=l("y",v),this.Z=l("z",_,!0),this.T=l("t",S),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(p){return Yt(h,p)}static msm(p,v){return Ge(h,n,p,v)}_setWindowSize(p){this.precompute(p)}static fromAffine(p){if(p instanceof h)throw new Error("extended point not allowed");let{x:v,y:_}=p||{};return l("x",v),l("y",_),new h(v,_,nt,a(v*_))}precompute(p=8,v=!0){return m.createCache(this,p),v||this.multiply(Xo),this}assertValidity(){u(this)}equals(p){f(p);let{X:v,Y:_,Z:S}=this,{X:C,Y:P,Z:T}=p,K=a(v*T),N=a(C*S),D=a(_*T),b=a(P*S);return K===N&&D===b}is0(){return this.equals(h.ZERO)}negate(){return new h(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:p}=r,{X:v,Y:_,Z:S}=this,C=a(v*v),P=a(_*_),T=a(Xo*a(S*S)),K=a(p*C),N=v+_,D=a(a(N*N)-C-P),b=K+P,y=b-T,E=K-P,A=a(D*y),L=a(b*E),R=a(D*E),w=a(y*b);return new h(A,L,w,R)}add(p){f(p);let{a:v,d:_}=r,{X:S,Y:C,Z:P,T}=this,{X:K,Y:N,Z:D,T:b}=p,y=a(S*K),E=a(C*N),A=a(T*_*b),L=a(P*D),R=a((S+C)*(K+N)-y-E),w=L-A,g=L+A,I=a(E-v*y),B=a(R*w),O=a(g*I),k=a(R*I),U=a(w*g);return new h(B,O,U,k)}subtract(p){return this.add(p.negate())}multiply(p){let v=p;le("scalar",v,nt,s);let{p:_,f:S}=m.cached(this,v,C=>Yt(h,C));return Yt(h,[_,S])[0]}multiplyUnsafe(p,v=h.ZERO){let _=p;return le("scalar",_,Kt,s),_===Kt?h.ZERO:this.is0()||_===nt?this:m.unsafe(this,_,S=>Yt(h,S),v)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return m.unsafe(this,s).is0()}toAffine(p){return d(this,p)}clearCofactor(){return o===nt?this:this.multiplyUnsafe(o)}static fromBytes(p,v=!1){return Q(p),h.fromHex(p,v)}static fromHex(p,v=!1){let{d:_,a:S}=r,C=e.BYTES;p=F("pointHex",p,C),Wt("zip215",v);let P=p.slice(),T=p[C-1];P[C-1]=T&-129;let K=Gt(P),N=v?i:e.ORDER;le("pointHex.y",K,Kt,N);let D=a(K*K),b=a(D-nt),y=a(_*D-S),{isValid:E,value:A}=c(b,y);if(!E)throw new Error("Point.fromHex: invalid y coordinate");let L=(A&nt)===nt,R=(T&128)!==0;if(!v&&A===Kt&&R)throw new Error("Point.fromHex: x=0 and x_0=1");return R!==L&&(A=a(-A)),h.fromAffine({x:A,y:K})}toBytes(){let{x:p,y:v}=this.toAffine(),_=Zt(v,e.BYTES);return _[_.length-1]|=p&nt?128:0,_}toRawBytes(){return this.toBytes()}toHex(){return Tt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}h.BASE=new h(r.Gx,r.Gy,nt,a(r.Gx*r.Gy)),h.ZERO=new h(Kt,nt,nt,Kt),h.Fp=e,h.Fn=n;let m=new We(h,n.BYTES*8);return h}var sn=class{constructor(t){this.ep=t}static fromBytes(t){throw new Error("fromBytes must be implemented by subclass")}static fromHex(t){throw new Error("fromHex must be implemented by subclass")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toRawBytes(){return this.toBytes()}toHex(){return Tt(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,e){return this.init(this.ep.precompute(t,e))}};function Ml(r,t,e){if(typeof t!="function")throw new Error('"hash" function param is required');de(e,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=e,{BASE:o,Fp:s,Fn:i}=r,a=i.ORDER,c=e.randomBytes||yr,l=e.adjustScalarBytes||(y=>y),f=e.domain||((y,E,A)=>{if(Wt("phflag",A),E.length||A)throw new Error("Contexts/pre-hash are not supported");return y});function d(y){return i.create(y)}function u(y){return d(Gt(y))}function h(y){let E=s.BYTES;y=F("private key",y,E);let A=F("hashed private key",t(y),2*E),L=l(A.slice(0,E)),R=A.slice(E,2*E),w=u(L);return{head:L,prefix:R,scalar:w}}function m(y){let{head:E,prefix:A,scalar:L}=h(y),R=o.multiply(L),w=R.toBytes();return{head:E,prefix:A,scalar:L,point:R,pointBytes:w}}function x(y){return m(y).pointBytes}function p(y=Uint8Array.of(),...E){let A=gt(...E);return u(t(f(A,F("context",y),!!n)))}function v(y,E,A={}){y=F("message",y),n&&(y=n(y));let{prefix:L,scalar:R,pointBytes:w}=m(E),g=p(A.context,L,y),I=o.multiply(g).toBytes(),B=p(A.context,I,w,y),O=d(g+B*R);le("signature.s",O,Kt,a);let k=s.BYTES,U=gt(I,Zt(O,k));return F("result",U,k*2)}let _={zip215:!0};function S(y,E,A,L=_){let{context:R,zip215:w}=L,g=s.BYTES;y=F("signature",y,2*g),E=F("message",E),A=F("publicKey",A,g),w!==void 0&&Wt("zip215",w),n&&(E=n(E));let I=Gt(y.slice(g,2*g)),B,O,k;try{B=r.fromHex(A,w),O=r.fromHex(y.slice(0,g),w),k=o.multiplyUnsafe(I)}catch{return!1}if(!w&&B.isSmallOrder())return!1;let U=p(R,O.toBytes(),B.toBytes(),E);return O.add(B.multiplyUnsafe(U)).subtract(k).clearCofactor().is0()}o.precompute(8);let C=s.BYTES,P={secret:C,public:C,signature:2*C,seed:C};function T(y=c(P.seed)){return y}let K={getExtendedPublicKey:m,randomSecretKey:T,isValidSecretKey:D,isValidPublicKey:b,randomPrivateKey:T,toMontgomery(y){let{y:E}=r.fromBytes(y),A=C===32;if(!A&&C!==57)throw new Error("only defined for 25519 and 448");let L=A?s.div(nt+E,nt-E):s.div(E-nt,E+nt);return s.toBytes(L)},toMontgomeryPriv(y){Q(y,C);let E=t(y.subarray(0,C));return l(E).subarray(0,C)},precompute(y=8,E=r.BASE){return E.precompute(y,!1)}};function N(y){let E=K.randomSecretKey(y);return{secretKey:E,publicKey:x(E)}}function D(y){try{return!!i.fromBytes(y,!1)}catch{return!1}}function b(y,E){try{return!!r.fromBytes(y,E)}catch{return!1}}return Object.freeze({keygen:N,getPublicKey:x,sign:v,verify:S,utils:K,Point:r,info:{type:"edwards",lengths:P}})}function ql(r){let t={a:r.a,d:r.d,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},e=r.Fp,n=Et(t.n,r.nBitLength,!0),o={Fp:e,Fn:n,uvRatio:r.uvRatio},s={randomBytes:r.randomBytes,adjustScalarBytes:r.adjustScalarBytes,domain:r.domain,prehash:r.prehash,mapToCurve:r.mapToCurve};return{CURVE:t,curveOpts:o,hash:r.hash,eddsaOpts:s}}function Hl(r,t){return Object.assign({},t,{ExtendedPoint:t.Point,CURVE:r})}function Aa(r){let{CURVE:t,curveOpts:e,hash:n,eddsaOpts:o}=ql(r),s=Ul(t,e),i=Ml(s,n,o);return Hl(r,i)}var Vl=BigInt(0),jt=BigInt(1),Ia=BigInt(2),sm=BigInt(3),zl=BigInt(5),Fl=BigInt(8),Sr={p:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Fl,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Wl(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=Sr.p,a=r*r%s*r%s,c=Y(a,Ia,s)*a%s,l=Y(c,jt,s)*r%s,f=Y(l,zl,s)*l%s,d=Y(f,t,s)*f%s,u=Y(d,e,s)*d%s,h=Y(u,n,s)*u%s,m=Y(h,o,s)*h%s,x=Y(m,o,s)*h%s,p=Y(x,t,s)*f%s;return{pow_p_5_8:Y(p,Ia,s)*r%s,b2:a}}function Gl(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var Qo=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function es(r,t){let e=Sr.p,n=J(t*t*t,e),o=J(n*n*t,e),s=Wl(r*o).pow_p_5_8,i=J(r*n*s,e),a=J(t*i*i,e),c=i,l=J(i*Qo,e),f=a===r,d=a===J(-r,e),u=a===J(-r*Qo,e);return f&&(i=c),(d||u)&&(i=l),$t(i,e)&&(i=J(-i,e)),{isValid:f||d,value:i}}var Ae=Et(Sr.p,{isLE:!0}),Zl=Et(Sr.n,{isLE:!0}),$l={...Sr,Fp:Ae,hash:ra,adjustScalarBytes:Gl,uvRatio:es},vt=Aa($l);var Jo=Qo,Yl=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),jl=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Xl=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Ql=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),_a=r=>es(jt,r),Jl=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),ts=r=>vt.CURVE.Fp.create(Gt(r)&Jl);function Ta(r){let{d:t}=vt.CURVE,e=vt.CURVE.Fp.ORDER,n=vt.CURVE.Fp.create,o=n(Jo*r*r),s=n((o+jt)*Xl),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:c,value:l}=es(s,a),f=n(l*r);$t(f,e)||(f=n(-f)),c||(l=f),c||(i=o);let d=n(i*(o-jt)*Ql-a),u=l*l,h=n((l+l)*a),m=n(d*Yl),x=n(jt-u),p=n(jt+u);return new vt.Point(n(h*p),n(x*m),n(m*p),n(h*x))}function tf(r){Q(r,64);let t=ts(r.subarray(0,32)),e=Ta(t),n=ts(r.subarray(32,64)),o=Ta(n);return new Xt(e.add(o))}var Xt=class r extends sn{constructor(t){super(t)}static fromAffine(t){return new r(vt.Point.fromAffine(t))}assertSame(t){if(!(t instanceof r))throw new Error("RistrettoPoint expected")}init(t){return new r(t)}static hashToCurve(t){return tf(F("ristrettoHash",t,64))}static fromBytes(t){Q(t,32);let{a:e,d:n}=vt.CURVE,o=Ae.ORDER,s=Ae.create,i=ts(t);if(!oa(Zt(i,32),t)||$t(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(jt+e*a),l=s(jt-e*a),f=s(c*c),d=s(l*l),u=s(e*n*f-d),{isValid:h,value:m}=_a(s(u*d)),x=s(m*l),p=s(m*x*u),v=s((i+i)*x);$t(v,o)&&(v=s(-v));let _=s(c*p),S=s(v*_);if(!h||$t(S,o)||_===Vl)throw new Error("invalid ristretto255 encoding 2");return new r(new vt.Point(v,_,jt,S))}static fromHex(t){return r.fromBytes(F("ristrettoHex",t,32))}static msm(t,e){return Ge(r,vt.Point.Fn,t,e)}toBytes(){let{X:t,Y:e,Z:n,T:o}=this.ep,s=Ae.ORDER,i=Ae.create,a=i(i(n+e)*i(n-e)),c=i(t*e),l=i(c*c),{value:f}=_a(i(a*l)),d=i(f*a),u=i(f*c),h=i(d*u*o),m;if($t(o*h,s)){let p=i(e*Jo),v=i(t*Jo);t=p,e=v,m=i(d*jl)}else m=u;$t(t*h,s)&&(e=i(-e));let x=i((n-e)*m);return $t(x,s)&&(x=i(-x)),Zt(x,32)}equals(t){this.assertSame(t);let{X:e,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=Ae.create,a=i(e*s)===i(n*o),c=i(n*s)===i(e*o);return a||c}is0(){return this.equals(r.ZERO)}};Xt.BASE=new Xt(vt.Point.BASE);Xt.ZERO=new Xt(vt.Point.ZERO);Xt.Fp=Ae;Xt.Fn=Zl;var Ar=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},an=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Ba={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new an("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 Bt=Ba;var cn=32;var rs,ef=(async()=>{try{return await Bt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function rf(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await Bt.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await Bt.get().subtle.verify({name:"Ed25519"},n,t,e instanceof Uint8Array?e:e.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function nf(r,t,e){return vt.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function Ca(r,t,e){return rs==null&&(rs=await ef),rs?rf(r,t,e):nf(r,t,e)}function un(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var ln=class{type="Ed25519";raw;constructor(t){this.raw=ns(t,cn)}toMultihash(){return Lt.digest(_t(this))}toCID(){return X.createV1(114,this.toMultihash())}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:$(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=Ca(this.raw,e,t);return un(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function os(r){return r=ns(r,cn),new ln(r)}function ns(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new q(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var sf=Math.pow(2,7),af=Math.pow(2,14),cf=Math.pow(2,21),ss=Math.pow(2,28),is=Math.pow(2,35),as=Math.pow(2,42),cs=Math.pow(2,49),V=128,ct=127;function Ct(r){if(r<sf)return 1;if(r<af)return 2;if(r<cf)return 3;if(r<ss)return 4;if(r<is)return 5;if(r<as)return 6;if(r<cs)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ze(r,t,e=0){switch(Ct(r)){case 8:t[e++]=r&255|V,r/=128;case 7:t[e++]=r&255|V,r/=128;case 6:t[e++]=r&255|V,r/=128;case 5:t[e++]=r&255|V,r/=128;case 4:t[e++]=r&255|V,r>>>=7;case 3:t[e++]=r&255|V,r>>>=7;case 2:t[e++]=r&255|V,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function uf(r,t,e=0){switch(Ct(r)){case 8:t.set(e++,r&255|V),r/=128;case 7:t.set(e++,r&255|V),r/=128;case 6:t.set(e++,r&255|V),r/=128;case 5:t.set(e++,r&255|V),r/=128;case 4:t.set(e++,r&255|V),r>>>=7;case 3:t.set(e++,r&255|V),r>>>=7;case 2:t.set(e++,r&255|V),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function us(r,t){let e=r[t],n=0;if(n+=e&ct,e<V||(e=r[t+1],n+=(e&ct)<<7,e<V)||(e=r[t+2],n+=(e&ct)<<14,e<V)||(e=r[t+3],n+=(e&ct)<<21,e<V)||(e=r[t+4],n+=(e&ct)*ss,e<V)||(e=r[t+5],n+=(e&ct)*is,e<V)||(e=r[t+6],n+=(e&ct)*as,e<V)||(e=r[t+7],n+=(e&ct)*cs,e<V))return n;throw new RangeError("Could not decode varint")}function lf(r,t){let e=r.get(t),n=0;if(n+=e&ct,e<V||(e=r.get(t+1),n+=(e&ct)<<7,e<V)||(e=r.get(t+2),n+=(e&ct)<<14,e<V)||(e=r.get(t+3),n+=(e&ct)<<21,e<V)||(e=r.get(t+4),n+=(e&ct)*ss,e<V)||(e=r.get(t+5),n+=(e&ct)*is,e<V)||(e=r.get(t+6),n+=(e&ct)*as,e<V)||(e=r.get(t+7),n+=(e&ct)*cs,e<V))return n;throw new RangeError("Could not decode varint")}function fn(r,t,e=0){return t==null&&(t=yt(Ct(r))),t instanceof Uint8Array?Ze(r,t,e):uf(r,t,e)}function ls(r,t=0){return r instanceof Uint8Array?us(r,t):lf(r,t)}var fs=new Float32Array([-0]),he=new Uint8Array(fs.buffer);function Ra(r,t,e){fs[0]=r,t[e]=he[0],t[e+1]=he[1],t[e+2]=he[2],t[e+3]=he[3]}function Pa(r,t){return he[0]=r[t],he[1]=r[t+1],he[2]=r[t+2],he[3]=r[t+3],fs[0]}var ds=new Float64Array([-0]),ut=new Uint8Array(ds.buffer);function Oa(r,t,e){ds[0]=r,t[e]=ut[0],t[e+1]=ut[1],t[e+2]=ut[2],t[e+3]=ut[3],t[e+4]=ut[4],t[e+5]=ut[5],t[e+6]=ut[6],t[e+7]=ut[7]}function ka(r,t){return ut[0]=r[t],ut[1]=r[t+1],ut[2]=r[t+2],ut[3]=r[t+3],ut[4]=r[t+4],ut[5]=r[t+5],ut[6]=r[t+6],ut[7]=r[t+7],ds[0]}var ff=BigInt(Number.MAX_SAFE_INTEGER),df=BigInt(Number.MIN_SAFE_INTEGER),St=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return Ie;if(t<ff&&t>df)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>Ka&&(o=0n,++n>Ka&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return Ie;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):Ie}},Ie=new St(0,0);Ie.toBigInt=function(){return 0n};Ie.zzEncode=Ie.zzDecode=function(){return this};Ie.length=function(){return 1};var Ka=4294967296n;function Na(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 Ua(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 hs(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 Pt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function dn(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var ps=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,Pt(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 Pt(this,4);return dn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Pt(this,4);return dn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Pt(this,4);let t=Pa(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Pt(this,4);let t=ka(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 Pt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Ua(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Pt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Pt(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 St(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 Pt(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 Pt(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 Pt(this,8);let t=dn(this.buf,this.pos+=4),e=dn(this.buf,this.pos+=4);return new St(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=us(this.buf,this.pos);return this.pos+=Ct(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 ms(r){return new ps(r instanceof Uint8Array?r:r.subarray())}function dt(r,t,e){let n=ms(r);return t.decode(n,void 0,e)}function ys(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return yt(i);o+i>t&&(n=yt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var _e=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function bs(){}var xs=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},hf=ys();function pf(r){return globalThis.Buffer!=null?yt(r):hf(r)}var _r=class{len;head;tail;states;constructor(){this.len=0,this.head=new _e(bs,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new _e(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new ws((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(hn,10,St.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=St.fromBigInt(t);return this._push(hn,e.length(),e)}uint64Number(t){return this._push(Ze,Ct(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=St.fromBigInt(t).zzEncode();return this._push(hn,e.length(),e)}sint64Number(t){let e=St.fromNumber(t).zzEncode();return this._push(hn,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(gs,1,t?1:0)}fixed32(t){return this._push(Ir,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=St.fromBigInt(t);return this._push(Ir,4,e.lo)._push(Ir,4,e.hi)}fixed64Number(t){let e=St.fromNumber(t);return this._push(Ir,4,e.lo)._push(Ir,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(Ra,4,t)}double(t){return this._push(Oa,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(gs,1,0):this.uint32(e)._push(yf,e,t)}string(t){let e=Na(t);return e!==0?this.uint32(e)._push(hs,e,t):this._push(gs,1,0)}fork(){return this.states=new xs(this),this.head=this.tail=new _e(bs,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 _e(bs,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=pf(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function gs(r,t,e){t[e]=r&255}function mf(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var ws=class extends _e{next;constructor(t,e){super(mf,t,e),this.next=void 0}};function hn(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 Ir(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 yf(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(_r.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(bf,t,r),this},_r.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(gf,t,r),this});function bf(r,t,e){t.set(r,e)}function gf(r,t,e){r.length<40?hs(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(H(r),e)}function Es(){return new _r}function ht(r,t){let e=Es();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var $e;(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"})($e||($e={}));function pn(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function vs(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 pn("enum",$e.VARINT,e,n)}function pt(r,t){return pn("message",$e.LENGTH_DELIMITED,r,t)}var Te=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"},Tr=class extends Error{code="ERR_MAX_SIZE";name="MaxSizeError"};var tt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(tt||(tt={}));var Ss;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Ss||(Ss={}));(function(r){r.codec=()=>vs(Ss)})(tt||(tt={}));var Nt;(function(r){let t;r.codec=()=>(t==null&&(t=pt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),tt.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=tt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>ht(e,r.codec()),r.decode=(e,n)=>dt(e,r.codec(),n)})(Nt||(Nt={}));var As;(function(r){let t;r.codec=()=>(t==null&&(t=pt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),tt.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=tt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>ht(e,r.codec()),r.decode=(e,n)=>dt(e,r.codec(),n)})(As||(As={}));var Cr={};mt(Cr,{MAX_RSA_KEY_SIZE:()=>Is,generateRSAKeyPair:()=>Fa,jwkToJWKKeyPair:()=>Wa,jwkToPkcs1:()=>vf,jwkToPkix:()=>Cs,jwkToRSAPrivateKey:()=>Ps,pkcs1MessageToJwk:()=>Ts,pkcs1MessageToRSAPrivateKey:()=>Ds,pkcs1ToJwk:()=>Ef,pkcs1ToRSAPrivateKey:()=>za,pkixMessageToJwk:()=>Bs,pkixMessageToRSAPublicKey:()=>Rs,pkixToJwk:()=>Sf,pkixToRSAPublicKey:()=>Ls});var mn=en;var Ye=class{type="RSA";jwk;_raw;_multihash;constructor(t,e){this.jwk=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=Cr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return X.createV1(114,this._multihash)}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:$(this.raw,t.raw)}verify(t,e,n){return Va(this.jwk,e,t,n)}},Br=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=Cr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:$(this.raw,t.raw)}sign(t,e){return Ha(this.jwk,t,e)}};var Is=8192,_s=18,xf=1062,wf=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Ef(r){let t=Ht(r);return Ts(t)}function Ts(r){return{n:M(r[1],"base64url"),e:M(r[2],"base64url"),d:M(r[3],"base64url"),p:M(r[4],"base64url"),q:M(r[5],"base64url"),dp:M(r[6],"base64url"),dq:M(r[7],"base64url"),qi:M(r[8],"base64url"),kty:"RSA"}}function vf(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new q("JWK was missing components");return ie([bt(Uint8Array.from([0])),bt(H(r.n,"base64url")),bt(H(r.e,"base64url")),bt(H(r.d,"base64url")),bt(H(r.p,"base64url")),bt(H(r.q,"base64url")),bt(H(r.dp,"base64url")),bt(H(r.dq,"base64url")),bt(H(r.qi,"base64url"))]).subarray()}function Sf(r){let t=Ht(r,{offset:0});return Bs(t)}function Bs(r){let t=Ht(r[1],{offset:0});return{kty:"RSA",n:M(t[0],"base64url"),e:M(t[1],"base64url")}}function Cs(r){if(r.n==null||r.e==null)throw new q("JWK was missing components");return ie([wf,jr(ie([bt(H(r.n,"base64url")),bt(H(r.e,"base64url"))]))]).subarray()}function za(r){let t=Ht(r);return Ds(t)}function Ds(r){let t=Ts(r);return Ps(t)}function Ls(r,t){if(r.byteLength>=xf)throw new Re("Key size is too large");let e=Ht(r,{offset:0});return Rs(e,r,t)}function Rs(r,t,e){let n=Bs(r);if(e==null){let o=mn(Nt.encode({Type:tt.RSA,Data:t}));e=Dt(_s,o)}return new Ye(n,e)}function Ps(r){if(Za(r)>Is)throw new q("Key size is too large");let t=Wa(r),e=mn(Nt.encode({Type:tt.RSA,Data:Cs(t.publicKey)})),n=Dt(_s,e);return new Br(t.privateKey,new Ye(t.publicKey,n))}async function Fa(r){if(r>Is)throw new q("Key size is too large");let t=await Ga(r),e=mn(Nt.encode({Type:tt.RSA,Data:Cs(t.publicKey)})),n=Dt(_s,e);return new Br(t.privateKey,new Ye(t.publicKey,n))}function Wa(r){if(r==null)throw new q("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function Ga(r,t){let e=await Bt.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 Af(e,t);return{privateKey:n[0],publicKey:n[1]}}async function Ha(r,t,e){let n=await Bt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);e?.signal?.throwIfAborted();let o=await Bt.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 Va(r,t,e,n){let o=await Bt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Bt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,e instanceof Uint8Array?e:e.subarray());return n?.signal?.throwIfAborted(),s}async function Af(r,t){if(r.privateKey==null||r.publicKey==null)throw new q("Private and public key are required");let e=await Promise.all([Bt.get().subtle.exportKey("jwk",r.privateKey),Bt.get().subtle.exportKey("jwk",r.publicKey)]);return t?.signal?.throwIfAborted(),e}function Za(r){if(r.kty!=="RSA")throw new q("invalid key type");if(r.n==null)throw new q("invalid key modulus");return H(r.n,"base64url").length*8}var yn=class extends qe{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Xr(t);let n=mr(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),zt(s)}update(t){return He(this),this.iHash.update(t),this}digestInto(t){He(this),Q(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()}},Os=(r,t,e)=>new yn(r,t).update(e).digest();Os.create=(r,t)=>new yn(r,t);var $a=(r,t)=>(r+(r>=0?t:-t)/ja)/t;function If(r,t,e){let[[n,o],[s,i]]=t,a=$a(i*r,e),c=$a(-o*r,e),l=r-a*n-c*s,f=-a*o-c*i,d=l<Jt,u=f<Jt;d&&(l=-l),u&&(f=-f);let h=fe(Math.ceil(nn(e)/2))+Xe;if(l<Jt||l>=h||f<Jt||f>=h)throw new Error("splitScalar (endomorphism): failed, k="+r);return{k1neg:d,k1:l,k2neg:u,k2:f}}function Ya(r){r.lowS!==void 0&&Wt("lowS",r.lowS),r.prehash!==void 0&&Wt("prehash",r.prehash)}var ks=class extends Error{constructor(t=""){super(t)}},Qt={Err:ks,_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=wr(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?wr(o.length/2|128):"";return wr(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 f of l)i=i<<8|f;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=wr(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 Ve(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Qt,o=F("signature",r),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:l,l:f}=n.decode(2,c);if(f.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)}},Jt=BigInt(0),Xe=BigInt(1),ja=BigInt(2),bn=BigInt(3),_f=BigInt(4);function Tf(r,t,e){function n(o){let s=r.sqr(o),i=r.mul(s,o);return r.add(r.add(i,r.mul(o,t)),e)}return n}function je(r,t){let{BYTES:e}=r,n;if(typeof t=="bigint")n=t;else{let o=F("private key",t);try{n=r.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${e}, got ${typeof t}`)}}if(!r.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function Bf(r,t={}){let{Fp:e,Fn:n}=on("weierstrass",r,t),{h:o,n:s}=r;de(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:i}=t;if(i&&(!e.is0(r.a)||typeof i.beta!="bigint"||!Array.isArray(i.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');function a(){if(!e.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function c(D,b,y){let{x:E,y:A}=b.toAffine(),L=e.toBytes(E);if(Wt("isCompressed",y),y){a();let R=!e.isOdd(A);return gt(Xa(R),L)}else return gt(Uint8Array.of(4),L,e.toBytes(A))}function l(D){Q(D);let b=e.BYTES,y=b+1,E=2*b+1,A=D.length,L=D[0],R=D.subarray(1);if(A===y&&(L===2||L===3)){let w=e.fromBytes(R);if(!e.isValid(w))throw new Error("bad point: is not on curve, wrong x");let g=u(w),I;try{I=e.sqrt(g)}catch(k){let U=k instanceof Error?": "+k.message:"";throw new Error("bad point: is not on curve, sqrt error"+U)}a();let B=e.isOdd(I);return(L&1)===1!==B&&(I=e.neg(I)),{x:w,y:I}}else if(A===E&&L===4){let w=e.fromBytes(R.subarray(b*0,b*1)),g=e.fromBytes(R.subarray(b*1,b*2));if(!h(w,g))throw new Error("bad point: is not on curve");return{x:w,y:g}}else throw new Error(`bad point: got length ${A}, expected compressed=${y} or uncompressed=${E}`)}let f=t.toBytes||c,d=t.fromBytes||l,u=Tf(e,r.a,r.b);function h(D,b){let y=e.sqr(b),E=u(D);return e.eql(y,E)}if(!h(r.Gx,r.Gy))throw new Error("bad curve params: generator point");let m=e.mul(e.pow(r.a,bn),_f),x=e.mul(e.sqr(r.b),BigInt(27));if(e.is0(e.add(m,x)))throw new Error("bad curve params: a or b");function p(D,b,y=!1){if(!e.isValid(b)||y&&e.is0(b))throw new Error(`bad point coordinate ${D}`);return b}function v(D){if(!(D instanceof T))throw new Error("ProjectivePoint expected")}function _(D){if(!i||!i.basises)throw new Error("no endo");return If(D,i.basises,n.ORDER)}let S=ze((D,b)=>{let{X:y,Y:E,Z:A}=D;if(e.eql(A,e.ONE))return{x:y,y:E};let L=D.is0();b==null&&(b=L?e.ONE:e.inv(A));let R=e.mul(y,b),w=e.mul(E,b),g=e.mul(A,b);if(L)return{x:e.ZERO,y:e.ZERO};if(!e.eql(g,e.ONE))throw new Error("invZ was invalid");return{x:R,y:w}}),C=ze(D=>{if(D.is0()){if(t.allowInfinityPoint&&!e.is0(D.Y))return;throw new Error("bad point: ZERO")}let{x:b,y}=D.toAffine();if(!e.isValid(b)||!e.isValid(y))throw new Error("bad point: x or y not field elements");if(!h(b,y))throw new Error("bad point: equation left != right");if(!D.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function P(D,b,y,E,A){return y=new T(e.mul(y.X,D),y.Y,y.Z),b=vr(E,b),y=vr(A,y),b.add(y)}class T{constructor(b,y,E){this.X=p("x",b),this.Y=p("y",y,!0),this.Z=p("z",E),Object.freeze(this)}static fromAffine(b){let{x:y,y:E}=b||{};if(!b||!e.isValid(y)||!e.isValid(E))throw new Error("invalid affine point");if(b instanceof T)throw new Error("projective point not allowed");return e.is0(y)&&e.is0(E)?T.ZERO:new T(y,E,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}static normalizeZ(b){return Yt(T,b)}static fromBytes(b){return Q(b),T.fromHex(b)}static fromHex(b){let y=T.fromAffine(d(F("pointHex",b)));return y.assertValidity(),y}static fromPrivateKey(b){return T.BASE.multiply(je(n,b))}static msm(b,y){return Ge(T,n,b,y)}_setWindowSize(b){this.precompute(b)}precompute(b=8,y=!0){return N.createCache(this,b),y||this.multiply(bn),this}assertValidity(){C(this)}hasEvenY(){let{y:b}=this.toAffine();if(!e.isOdd)throw new Error("Field doesn't support isOdd");return!e.isOdd(b)}equals(b){v(b);let{X:y,Y:E,Z:A}=this,{X:L,Y:R,Z:w}=b,g=e.eql(e.mul(y,w),e.mul(L,A)),I=e.eql(e.mul(E,w),e.mul(R,A));return g&&I}negate(){return new T(this.X,e.neg(this.Y),this.Z)}double(){let{a:b,b:y}=r,E=e.mul(y,bn),{X:A,Y:L,Z:R}=this,w=e.ZERO,g=e.ZERO,I=e.ZERO,B=e.mul(A,A),O=e.mul(L,L),k=e.mul(R,R),U=e.mul(A,L);return U=e.add(U,U),I=e.mul(A,R),I=e.add(I,I),w=e.mul(b,I),g=e.mul(E,k),g=e.add(w,g),w=e.sub(O,g),g=e.add(O,g),g=e.mul(w,g),w=e.mul(U,w),I=e.mul(E,I),k=e.mul(b,k),U=e.sub(B,k),U=e.mul(b,U),U=e.add(U,I),I=e.add(B,B),B=e.add(I,B),B=e.add(B,k),B=e.mul(B,U),g=e.add(g,B),k=e.mul(L,R),k=e.add(k,k),B=e.mul(k,U),w=e.sub(w,B),I=e.mul(k,O),I=e.add(I,I),I=e.add(I,I),new T(w,g,I)}add(b){v(b);let{X:y,Y:E,Z:A}=this,{X:L,Y:R,Z:w}=b,g=e.ZERO,I=e.ZERO,B=e.ZERO,O=r.a,k=e.mul(r.b,bn),U=e.mul(y,L),G=e.mul(E,R),W=e.mul(A,w),xt=e.add(y,E),z=e.add(L,R);xt=e.mul(xt,z),z=e.add(U,G),xt=e.sub(xt,z),z=e.add(y,A);let rt=e.add(L,w);return z=e.mul(z,rt),rt=e.add(U,W),z=e.sub(z,rt),rt=e.add(E,A),g=e.add(R,w),rt=e.mul(rt,g),g=e.add(G,W),rt=e.sub(rt,g),B=e.mul(O,z),g=e.mul(k,W),B=e.add(g,B),g=e.sub(G,B),B=e.add(G,B),I=e.mul(g,B),G=e.add(U,U),G=e.add(G,U),W=e.mul(O,W),z=e.mul(k,z),G=e.add(G,W),W=e.sub(U,W),W=e.mul(O,W),z=e.add(z,W),U=e.mul(G,z),I=e.add(I,U),U=e.mul(rt,z),g=e.mul(xt,g),g=e.sub(g,U),U=e.mul(xt,G),B=e.mul(rt,B),B=e.add(B,U),new T(g,I,B)}subtract(b){return this.add(b.negate())}is0(){return this.equals(T.ZERO)}multiply(b){let{endo:y}=t;if(!n.isValidNot0(b))throw new Error("invalid scalar: out of range");let E,A,L=R=>N.cached(this,R,w=>Yt(T,w));if(y){let{k1neg:R,k1:w,k2neg:g,k2:I}=_(b),{p:B,f:O}=L(w),{p:k,f:U}=L(I);A=O.add(U),E=P(y.beta,B,k,R,g)}else{let{p:R,f:w}=L(b);E=R,A=w}return Yt(T,[E,A])[0]}multiplyUnsafe(b){let{endo:y}=t,E=this;if(!n.isValid(b))throw new Error("invalid scalar: out of range");if(b===Jt||E.is0())return T.ZERO;if(b===Xe)return E;if(N.hasCache(this))return this.multiply(b);if(y){let{k1neg:A,k1:L,k2neg:R,k2:w}=_(b),{p1:g,p2:I}=Sa(T,E,L,w);return P(y.beta,g,I,A,R)}else return N.unsafe(E,b)}multiplyAndAddUnsafe(b,y,E){let A=this.multiplyUnsafe(y).add(b.multiplyUnsafe(E));return A.is0()?void 0:A}toAffine(b){return S(this,b)}isTorsionFree(){let{isTorsionFree:b}=t;return o===Xe?!0:b?b(T,this):N.unsafe(this,s).is0()}clearCofactor(){let{clearCofactor:b}=t;return o===Xe?this:b?b(T,this):this.multiplyUnsafe(o)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}toBytes(b=!0){return Wt("isCompressed",b),this.assertValidity(),f(T,this,b)}toRawBytes(b=!0){return this.toBytes(b)}toHex(b=!0){return Tt(this.toBytes(b))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}T.BASE=new T(r.Gx,r.Gy,e.ONE),T.ZERO=new T(e.ZERO,e.ONE,e.ZERO),T.Fp=e,T.Fn=n;let K=n.BITS,N=new We(T,t.endo?Math.ceil(K/2):K);return T}function Xa(r){return Uint8Array.of(r?2:3)}function Cf(r,t,e={}){Xr(t),de(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=e.randomBytes||yr,o=e.hmac||((w,...g)=>Os(t,w,gt(...g))),{Fp:s,Fn:i}=r,{ORDER:a,BITS:c}=i,l=Go(a),f={secret:i.BYTES,public:1+s.BYTES,publicUncompressed:1+2*s.BYTES,signature:2*i.BYTES,seed:l};function d(w){let g=a>>Xe;return w>g}function u(w){return d(w)?i.neg(w):w}function h(w,g){if(!i.isValidNot0(g))throw new Error(`invalid signature ${w}: out of range 1..CURVE.n`)}class m{constructor(g,I,B){h("r",g),h("s",I),this.r=g,this.s=I,B!=null&&(this.recovery=B),Object.freeze(this)}static fromBytes(g,I="compact"){if(I==="compact"){let B=i.BYTES;Q(g,B*2);let O=g.subarray(0,B),k=g.subarray(B,B*2);return new m(i.fromBytes(O),i.fromBytes(k))}if(I==="der"){Q(g);let{r:B,s:O}=Qt.toSig(g);return new m(B,O)}throw new Error("invalid format")}static fromHex(g,I){return this.fromBytes(xe(g),I)}addRecoveryBit(g){return new m(this.r,this.s,g)}recoverPublicKey(g){let I=s.ORDER,{r:B,s:O,recovery:k}=this;if(k==null||![0,1,2,3].includes(k))throw new Error("recovery id invalid");if(a*ja<I&&k>1)throw new Error("recovery id is ambiguous for h>1 curve");let G=k===2||k===3?B+a:B;if(!s.isValid(G))throw new Error("recovery id 2 or 3 invalid");let W=s.toBytes(G),xt=r.fromHex(gt(Xa((k&1)===0),W)),z=i.inv(G),rt=K(F("msgHash",g)),wt=i.create(-rt*z),ne=i.create(O*z),pe=r.BASE.multiplyUnsafe(wt).add(xt.multiplyUnsafe(ne));if(pe.is0())throw new Error("point at infinify");return pe.assertValidity(),pe}hasHighS(){return d(this.s)}normalizeS(){return this.hasHighS()?new m(this.r,i.neg(this.s),this.recovery):this}toBytes(g="compact"){if(g==="compact")return gt(i.toBytes(this.r),i.toBytes(this.s));if(g==="der")return xe(Qt.hexFromSig(this));throw new Error("invalid format")}toHex(g){return Tt(this.toBytes(g))}assertValidity(){}static fromCompact(g){return m.fromBytes(F("sig",g),"compact")}static fromDER(g){return m.fromBytes(F("sig",g),"der")}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Tt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Tt(this.toBytes("compact"))}}function x(w){try{return!!je(i,w)}catch{return!1}}function p(w,g){try{let I=w.length;return g===!0&&I!==f.public||g===!1&&I!==f.publicUncompressed?!1:!!r.fromBytes(w)}catch{return!1}}function v(w=n(l)){return Zo(w,a)}let _={isValidSecretKey:x,isValidPublicKey:p,randomSecretKey:v,isValidPrivateKey:x,randomPrivateKey:v,normPrivateKeyToScalar:w=>je(i,w),precompute(w=8,g=r.BASE){return g.precompute(w,!1)}};function S(w,g=!0){return r.BASE.multiply(je(i,w)).toBytes(g)}function C(w){if(typeof w=="bigint")return!1;if(w instanceof r)return!0;if(i.allowedLengths||f.secret===f.public)return;let g=F("key",w).length;return g===f.public||g===f.publicUncompressed}function P(w,g,I=!0){if(C(w)===!0)throw new Error("first arg must be private key");if(C(g)===!1)throw new Error("second arg must be public key");let B=je(i,w);return r.fromHex(g).multiply(B).toBytes(I)}let T=e.bits2int||function(w){if(w.length>8192)throw new Error("input is too large");let g=Ve(w),I=w.length*8-c;return I>0?g>>BigInt(I):g},K=e.bits2int_modN||function(w){return i.create(T(w))},N=fe(c);function D(w){return le("num < 2^"+c,w,Jt,N),i.toBytes(w)}function b(w,g,I=y){if(["recovered","canonical"].some(wt=>wt in I))throw new Error("sign() legacy options not supported");let{lowS:B,prehash:O,extraEntropy:k}=I;B==null&&(B=!0),w=F("msgHash",w),Ya(I),O&&(w=F("prehashed msgHash",t(w)));let U=K(w),G=je(i,g),W=[D(G),D(U)];if(k!=null&&k!==!1){let wt=k===!0?n(f.secret):k;W.push(F("extraEntropy",wt))}let xt=gt(...W),z=U;function rt(wt){let ne=T(wt);if(!i.isValidNot0(ne))return;let pe=i.inv(ne),nr=r.BASE.multiply(ne).toAffine(),me=i.create(nr.x);if(me===Jt)return;let or=i.create(pe*i.create(z+me*G));if(or===Jt)return;let pi=(nr.x===me?0:2)|Number(nr.y&Xe),mi=or;return B&&d(or)&&(mi=u(or),pi^=1),new m(me,mi,pi)}return{seed:xt,k2sig:rt}}let y={lowS:e.lowS,prehash:!1},E={lowS:e.lowS,prehash:!1};function A(w,g,I=y){let{seed:B,k2sig:O}=b(w,g,I);return ia(t.outputLen,i.BYTES,o)(B,O)}r.BASE.precompute(8);function L(w,g,I,B=E){let O=w;g=F("msgHash",g),I=F("publicKey",I),Ya(B);let{lowS:k,prehash:U,format:G}=B;if("strict"in B)throw new Error("options.strict was renamed to lowS");let W,xt;if(G===void 0){let z=typeof O=="string"||ge(O),rt=!z&&O!==null&&typeof O=="object"&&typeof O.r=="bigint"&&typeof O.s=="bigint";if(!z&&!rt)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(rt)W=new m(O.r,O.s);else if(z){try{W=m.fromDER(O)}catch(wt){if(!(wt instanceof Qt.Err))throw wt}if(!W)try{W=m.fromCompact(O)}catch{return!1}}}else if(G==="compact"||G==="der"){if(typeof O!="string"&&!ge(O))throw new Error('"der" / "compact" format expects Uint8Array signature');W=m.fromBytes(F("sig",O),G)}else if(G==="js"){if(!(O instanceof m))throw new Error('"js" format expects Signature instance');W=O}else throw new Error('format must be "compact", "der" or "js"');if(!W)return!1;try{if(xt=r.fromHex(I),k&&W.hasHighS())return!1;U&&(g=t(g));let{r:z,s:rt}=W,wt=K(g),ne=i.inv(rt),pe=i.create(wt*ne),nr=i.create(z*ne),me=r.BASE.multiplyUnsafe(pe).add(xt.multiplyUnsafe(nr));return me.is0()?!1:i.create(me.x)===z}catch{return!1}}function R(w){let g=_.randomSecretKey(w);return{secretKey:g,publicKey:S(g)}}return Object.freeze({keygen:R,getPublicKey:S,sign:A,verify:L,getSharedSecret:P,utils:_,Point:r,Signature:m,info:{type:"weierstrass",lengths:f,publicKeyHasPrefix:!0}})}function Df(r){let t={a:r.a,b:r.b,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},e=r.Fp,n=r.allowedPrivateKeyLengths?Array.from(new Set(r.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,o=Et(t.n,{BITS:r.nBitLength,allowedLengths:n,modOnDecode:r.wrapPrivateKey}),s={Fp:e,Fn:o,allowInfinityPoint:r.allowInfinityPoint,endo:r.endo,isTorsionFree:r.isTorsionFree,clearCofactor:r.clearCofactor,fromBytes:r.fromBytes,toBytes:r.toBytes};return{CURVE:t,curveOpts:s}}function Lf(r){let{CURVE:t,curveOpts:e}=Df(r),n={hmac:r.hmac,randomBytes:r.randomBytes,lowS:r.lowS,bits2int:r.bits2int,bits2int_modN:r.bits2int_modN};return{CURVE:t,curveOpts:e,hash:r.hash,ecdsaOpts:n}}function Rf(r,t){return Object.assign({},t,{ProjectivePoint:t.Point,CURVE:r})}function Qa(r){let{CURVE:t,curveOpts:e,hash:n,ecdsaOpts:o}=Lf(r),s=Bf(t,e),i=Cf(s,n,o);return Rf(r,i)}function Ja(r,t){let e=n=>Qa({...r,hash:n});return{...e(t),create:e}}var Ns={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Pf={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var tc=BigInt(2);function Of(r){let t=Ns.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),l=r*r*r%t,f=l*l*r%t,d=Y(f,e,t)*f%t,u=Y(d,e,t)*f%t,h=Y(u,tc,t)*l%t,m=Y(h,o,t)*h%t,x=Y(m,s,t)*m%t,p=Y(x,a,t)*x%t,v=Y(p,c,t)*p%t,_=Y(v,a,t)*x%t,S=Y(_,e,t)*f%t,C=Y(S,i,t)*m%t,P=Y(C,n,t)*l%t,T=Y(P,tc,t);if(!Ks.eql(Ks.sqr(T),r))throw new Error("Cannot find square root");return T}var Ks=Et(Ns.p,void 0,void 0,{sqrt:Of}),Qe=Ja({...Ns,Fp:Ks,lowS:!0,endo:Pf},en);function ec(r,t,e,n){let o=lr.digest(e instanceof Uint8Array?e:e.subarray());if(un(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Qe.verify(t,s,r))).catch(s=>{throw s.name==="AbortError"?s:new Ar(String(s))});try{return n?.signal?.throwIfAborted(),Qe.verify(t,o.digest,r)}catch(s){throw new Ar(String(s))}}var gn=class{type="secp256k1";raw;_key;constructor(t){this._key=nc(t),this.raw=rc(this._key)}toMultihash(){return Lt.digest(_t(this))}toCID(){return X.createV1(114,this.toMultihash())}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:$(this.raw,t.raw)}verify(t,e,n){return ec(this._key,e,t,n)}};function Us(r){return new gn(r)}function rc(r){return Qe.ProjectivePoint.fromHex(r).toRawBytes(!0)}function nc(r){try{return Qe.ProjectivePoint.fromHex(r),r}catch(t){throw new Re(String(t))}}function xn(r,t){let{Type:e,Data:n}=Nt.decode(r),o=n??new Uint8Array;switch(e){case tt.RSA:return Ls(o,t);case tt.Ed25519:return os(o);case tt.secp256k1:return Us(o);case tt.ECDSA:return ko(o);default:throw new ye}}function oc(r){let{Type:t,Data:e}=Nt.decode(r.digest),n=e??new Uint8Array;switch(t){case tt.Ed25519:return os(n);case tt.secp256k1:return Us(n);case tt.ECDSA:return ko(n);default:throw new ye}}function _t(r){return Nt.encode({Type:tt[r.type],Data:r.raw})}var sc=Symbol.for("nodejs.util.inspect.custom"),kf=114,Dr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Fr]=!0;toString(){return this.string==null&&(this.string=Z.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return X.createV1(kf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return $(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return $(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[sc](){return`PeerId(${this.toString()})`}},Lr=class extends Dr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Rr=class extends Dr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Pr=class extends Dr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Kf=2336,Or=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Lt.digest(H(this.url))}[sc](){return`PeerId(${this.url})`}[Fr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return X.createV1(Kf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=M(t)),t.toString()===this.toString())}};var Nf=114,ic=2336;function ac(r){if(r.type==="Ed25519")return new Rr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new Pr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new Lr({multihash:r.toCID().multihash,publicKey:r});throw new ye}function Ms(r){if(Mf(r))return new Lr({multihash:r});if(Uf(r))try{let t=oc(r);if(t.type==="Ed25519")return new Rr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new Pr({multihash:r,publicKey:t})}catch{let e=M(r.digest);return new Or(new URL(e))}throw new Gr("Supplied PeerID Multihash is invalid")}function wn(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==Nf&&r.code!==ic)throw new Wr("Supplied PeerID CID is invalid");if(r.code===ic){let t=M(r.multihash.digest);return new Or(new URL(t))}return Ms(r.multihash)}function Uf(r){return r.code===Lt.code}function Mf(r){return r.code===lr.code}var kr;(function(r){let t;r.codec=()=>(t==null&&(t=pt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.publicKey!=null&&e.publicKey.byteLength>0&&(n.uint32(10),n.bytes(e.publicKey)),e.payloadType!=null&&e.payloadType.byteLength>0&&(n.uint32(18),n.bytes(e.payloadType)),e.payload!=null&&e.payload.byteLength>0&&(n.uint32(26),n.bytes(e.payload)),e.signature!=null&&e.signature.byteLength>0&&(n.uint32(42),n.bytes(e.signature)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={publicKey:et(0),payloadType:et(0),payload:et(0),signature:et(0)},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.publicKey=e.bytes();break}case 2:{s.payloadType=e.bytes();break}case 3:{s.payload=e.bytes();break}case 5:{s.signature=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>ht(e,r.codec()),r.decode=(e,n)=>dt(e,r.codec(),n)})(kr||(kr={}));var En=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var Je=class r{static createFromProtobuf=t=>{let e=kr.decode(t),n=xn(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=cc(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 En("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=kr.encode({publicKey:_t(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return t==null?!1:$(this.marshal(),t.marshal())}async validate(t,e){let n=cc(t,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,e)}},cc=(r,t,e)=>{let n=H(r),o=fn(n.byteLength),s=fn(t.length),i=fn(e.length);return new lt(o,n,s,t,i,e)};function uc(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 at=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},te=class extends Error{static name="ValidationError";name="ValidationError"},Kr=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},vn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var Sn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",l=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let d=this.readChar();if(d===void 0)return;let u=Number.parseInt(d,t);if(!Number.isNaN(u))return u});if(f===void 0)break;if(s*=t,s+=f,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 qf=45,Hf=15,An=new Sn;function qs(r){if(!(r.length>Hf))return An.new(r).parseWith(()=>An.readIPv4Addr())}function Hs(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>qf))return An.new(r).parseWith(()=>An.readIPv6Addr())}function In(r){return!!qs(r)}function fc(r){return!!Hs(r)}function zs(r){return t=>M(t,r)}function Fs(r){return t=>H(t,r)}function tr(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function Be(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(t)}function dc(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=H(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Be(n);return qt([e,o],e.length+o.length)}function hc(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=Ot.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=Be(n);return qt([e,o],e.length+o.length)}function Ws(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=M(t,"base32"),o=tr(e);return`${n}:${o}`}var Gs=function(r){r=r.toString().trim();let t=new Uint8Array(4);return r.split(/\./g).forEach((e,n)=>{let o=parseInt(e,10);if(isNaN(o)||o<0||o>255)throw new at("Invalid byte value in IP address");t[n]=o}),t},pc=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=In(e[n]),i;s&&(i=Gs(e[n]),e[n]=M(i.subarray(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,M(i.subarray(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let s=[n,1];for(n=9-e.length;n>0;n--)s.push("0");e.splice.apply(e,s)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){e[n]===""&&(e[n]="0");let s=parseInt(e[n],16);if(isNaN(s)||s<0||s>65535)throw new at("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},mc=function(r){if(r.byteLength!==4)throw new at("IPv4 address was incorrect length");let t=[];for(let e=0;e<r.byteLength;e++)t.push(r[e]);return t.join(".")},yc=function(r){if(r.byteLength!==16)throw new at("IPv6 address was incorrect length");let t=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],s=r[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let e=t.join(":");try{let n=new URL(`http://[${e}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new at(`Invalid IPv6 address "${e}"`)}};function bc(r){try{let t=new URL(`http://[${r}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new at(`Invalid IPv6 address "${r}"`)}}var Vs=Object.values(fr).map(r=>r.decoder),Vf=function(){let r=Vs[0].or(Vs[1]);return Vs.slice(2).forEach(t=>r=r.or(t)),r}();function gc(r){return Vf.decode(r)}function xc(r){return t=>r.encoder.encode(t)}function zf(r){if(parseInt(r).toString()!==r)throw new te("Value must be an integer")}function Ff(r){if(r<0)throw new te("Value must be a positive integer, or zero")}function Wf(r){return t=>{if(t>r)throw new te(`Value must be smaller than or equal to ${r}`)}}function Gf(...r){return t=>{for(let e of r)e(t)}}var Nr=Gf(zf,Ff,Wf(65535));var st=-1,Zs=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let e;if(typeof t=="string"?e=this.protocolsByName.get(t):e=this.protocolsByCode.get(t),e==null)throw new vn(`Protocol ${t} was unknown`);return e}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(e=>{this.protocolsByName.set(e,t)})}removeProtocol(t){let e=this.protocolsByCode.get(t);e!=null&&(this.protocolsByCode.delete(e.code),this.protocolsByName.delete(e.name),e.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},At=new Zs,vd=[{code:4,name:"ip4",size:32,valueToBytes:Gs,bytesToValue:mc,validate:r=>{if(!In(r))throw new te(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Be,bytesToValue:tr,validate:Nr},{code:273,name:"udp",size:16,valueToBytes:Be,bytesToValue:tr,validate:Nr},{code:33,name:"dccp",size:16,valueToBytes:Be,bytesToValue:tr,validate:Nr},{code:41,name:"ip6",size:128,valueToBytes:pc,bytesToValue:yc,stringToValue:bc,validate:r=>{if(!fc(r))throw new te(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:st},{code:43,name:"ipcidr",size:8,bytesToValue:zs("base10"),valueToBytes:Fs("base10")},{code:53,name:"dns",size:st,resolvable:!0},{code:54,name:"dns4",size:st,resolvable:!0},{code:55,name:"dns6",size:st,resolvable:!0},{code:56,name:"dnsaddr",size:st,resolvable:!0},{code:132,name:"sctp",size:16,valueToBytes:Be,bytesToValue:tr,validate:Nr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:st,path:!0,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:st,bytesToValue:zs("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?Fs("base58btc")(r):X.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Ws,valueToBytes:dc},{code:445,name:"onion3",size:296,bytesToValue:Ws,valueToBytes:hc},{code:446,name:"garlic64",size:st},{code:447,name:"garlic32",size:st},{code:448,name:"tls"},{code:449,name:"sni",size:st},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:st,bytesToValue:xc(vo),valueToBytes:gc},{code:480,name:"http"},{code:481,name:"http-path",size:st,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:st}];vd.forEach(r=>{At.addProtocol(r)});function wc(r){let t=[],e=0;for(;e<r.length;){let n=ls(r,e),o=At.getProtocol(n),s=Ct(n),i=Sd(o,r,e+s),a=0;i>0&&o.size===st&&(a=Ct(i));let c=s+a+i,l={code:n,name:o.name,bytes:r.subarray(e,e+c)};if(i>0){let f=e+s+a,d=r.subarray(f,f+i);l.value=o.bytesToValue?.(d)??M(d)}t.push(l),e+=c}return t}function Ec(r){let t=0,e=[];for(let n of r){if(n.bytes==null){let o=At.getProtocol(n.code),s=Ct(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??H(n.value),a=i.byteLength,o.size===st&&(c=Ct(a)));let l=new Uint8Array(s+c+a),f=0;Ze(n.code,l,f),f+=s,i!=null&&(o.size===st&&(Ze(a,l,f),f+=c),l.set(i,f)),n.bytes=l}e.push(n.bytes),t+=n.bytes.byteLength}return qt(e,t)}function vc(r){if(r.charAt(0)!=="/")throw new at('String multiaddr must start with "/"');let t=[],e="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(e==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let a=s===r.length-1;if(i==="/"||a){let c=At.getProtocol(o);if(e==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",e="protocol";continue}else if(a)throw new at(`Component ${o} was missing value`);e="value"}else if(e==="value"){let l={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new at(`Component ${o} was missing value`);l.value=c.stringToValue?.(n)??n}t.push(l),n="",o="",e="protocol"}}}if(o!==""&&n!=="")throw new at("Incomplete multiaddr");return t}function Sc(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=At.getProtocol(t.code);if(e==null)throw new at(`Unknown protocol code ${t.code}`);return[t.name,e.valueToString?.(t.value)??t.value]}).join("/")}`}function Sd(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:ls(t,e)}var Ad=Symbol.for("nodejs.util.inspect.custom"),ei=Symbol.for("@multiformats/multiaddr"),Id=[53,54,55,56],ti=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}};function _d(r){if(r==null&&(r="/"),Ln(r))return r.getComponents();if(r instanceof Uint8Array)return wc(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),vc(r);if(Array.isArray(r))return r;throw new at("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Dn=class r{[ei]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=_d(t),e.validate!==!1&&Td(this)}get bytes(){return this.#r==null&&(this.#r=Ec(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Sc(this.#t)),this.#e}toJSON(){return this.toString()}toOptions(){let t,e,n,o,s="";for(let{code:a,name:c,value:l}of this.#t)a===42&&(s=`%${l??""}`),Id.includes(a)&&(e="tcp",o=443,n=`${l??""}${s}`,t=a===55?6:4),(a===6||a===273)&&(e=c==="tcp"?"tcp":"udp",o=parseInt(l??"")),(a===4||a===41)&&(e="tcp",n=`${l??""}${s}`,t=a===41?6:4);if(t==null||e==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:t,host:n,transport:e,port:o}}getComponents(){return[...this.#t]}protos(){return this.#t.map(({code:t,value:e})=>{let n=At.getProtocol(t);return{code:t,size:n.size??0,name:n.name,resolvable:!!n.resolvable,path:!!n.path}})}protoCodes(){return this.#t.map(({code:t})=>t)}protoNames(){return this.#t.map(({name:t})=>t)}tuples(){return this.#t.map(({code:t,value:e})=>{if(e==null)return[t];let n=At.getProtocol(t),o=[t];return e!=null&&o.push(n.valueToBytes?.(e)??H(e)),o})}stringTuples(){return this.#t.map(({code:t,value:e})=>e==null?[t]:[t,e])}encapsulate(t){let e=new r(t);return new r([...this.#t,...e.getComponents()],{validate:!1})}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new Kr(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(t){let e;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){e=n;break}return new r(this.#t.slice(0,e),{validate:!1})}getPeerId(){try{let t=[];this.#t.forEach(({code:n,value:o})=>{n===421&&t.push([n,o]),n===290&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?M(Z.decode(`z${n}`),"base58btc"):M(X.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){for(let t of this.#t)if(At.getProtocol(t.code).path)return t.value??null;return null}equals(t){return $(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(s=>s.resolvable);if(e==null)return[this];let n=Ac.get(e.name);if(n==null)throw new ti(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>Ut(s))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(){return!(this.#t.length!==2||this.#t[0].code!==4&&this.#t[0].code!==41||this.#t[1].code!==6&&this.#t[1].code!==273)}[Ad](){return`Multiaddr(${this.toString()})`}};function Td(r){r.getComponents().forEach(t=>{let e=At.getProtocol(t.code);t.value!=null&&e.validate?.(t.value)})}var Jb=parseInt("0xFFFF",16),tg=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var Ac=new Map;function Ln(r){return!!r?.[ei]}function Ut(r){return new Dn(r)}var Tc="libp2p-peer-record",Bc=Uint8Array.from([3,1]);var Mr;(function(r){let t;(function(n){let o;n.codec=()=>(o==null&&(o=pt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.multiaddr!=null&&s.multiaddr.byteLength>0&&(i.uint32(10),i.bytes(s.multiaddr)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={multiaddr:et(0)},l=i==null?s.len:s.pos+i;for(;s.pos<l;){let f=s.uint32();switch(f>>>3){case 1:{c.multiaddr=s.bytes();break}default:{s.skipType(f&7);break}}}return c})),o),n.encode=s=>ht(s,n.codec()),n.decode=(s,i)=>dt(s,n.codec(),i)})(t=r.AddressInfo||(r.AddressInfo={}));let e;r.codec=()=>(e==null&&(e=pt((n,o,s={})=>{if(s.lengthDelimited!==!1&&o.fork(),n.peerId!=null&&n.peerId.byteLength>0&&(o.uint32(10),o.bytes(n.peerId)),n.seq!=null&&n.seq!==0n&&(o.uint32(16),o.uint64(n.seq)),n.addresses!=null)for(let i of n.addresses)o.uint32(26),r.AddressInfo.codec().encode(i,o);s.lengthDelimited!==!1&&o.ldelim()},(n,o,s={})=>{let i={peerId:et(0),seq:0n,addresses:[]},a=o==null?n.len:n.pos+o;for(;n.pos<a;){let c=n.uint32();switch(c>>>3){case 1:{i.peerId=n.bytes();break}case 2:{i.seq=n.uint64();break}case 3:{if(s.limits?.addresses!=null&&i.addresses.length===s.limits.addresses)throw new Te('Decode error - map field "addresses" had too many elements');i.addresses.push(r.AddressInfo.codec().decode(n,n.uint32(),{limits:s.limits?.addresses$}));break}default:{n.skipType(c&7);break}}}return i})),e),r.encode=n=>ht(n,r.codec()),r.decode=(n,o)=>dt(n,r.codec(),o)})(Mr||(Mr={}));var Ce=class r{static createFromProtobuf=t=>{let e=Mr.decode(t),n=Ms(Ue(e.peerId)),o=(e.addresses??[]).map(i=>Ut(i.multiaddr)),s=e.seq;return new r({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Tc;static CODEC=Bc;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=Mr.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||!uc(this.multiaddrs,t.multiaddrs))}};function Rd(r){return r[Symbol.asyncIterator]!=null}function Pd(r){if(Rd(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 Cc=Pd;function Rn(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 qr=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 Rn(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 Rn(this.map.values(),t=>t.key)}values(){return Rn(this.map.values(),t=>t.value)}get size(){return this.map.size}};var ri=class extends qr{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 ni(r){let{name:t,metrics:e}=r,n;return e!=null?n=new ri({name:t,metrics:e}):n=new qr,n}var It=class extends Error{static name="AbortError";name="AbortError";constructor(t="The operation was aborted",...e){super(t,...e)}};function Pn(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var On=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}},er=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new On(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 On(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 oi=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function Dc(r={}){return Od(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 Od(r,t){t=t??{};let e=t.onEnd,n=new er,o,s,i,a=Pn(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((p,v)=>{s=_=>{s=null,n.push(_);try{p(r(n))}catch(S){v(S)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Pn()})}},l=p=>s!=null?s(p):(n.push(p),o),f=p=>(n=new er,s!=null?s({error:p}):(n.push({error:p}),o)),d=p=>{if(i)return o;if(t?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:p})},u=p=>i?o:(i=!0,p!=null?f(p):l({done:!0})),h=()=>(n=new er,u(),{done:!0}),m=p=>(u(p),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:h,throw:m,push:d,end:u,get readableLength(){return n.size},onEmpty:async p=>{let v=p?.signal;if(v?.throwIfAborted(),n.isEmpty())return;let _,S;v!=null&&(_=new Promise((C,P)=>{S=()=>{P(new oi)},v.addEventListener("abort",S)}));try{await Promise.race([a.promise,_])}finally{S!=null&&v!=null&&v?.removeEventListener("abort",S)}}},e==null)return o;let x=o;return o={[Symbol.asyncIterator](){return this},next(){return x.next()},throw(p){return x.throw(p),e!=null&&(e(p),e=void 0),{done:!0}},return(){return x.return(),e!=null&&(e(),e=void 0),{done:!0}},push:d,end(p){return x.end(p),e!=null&&(e(p),e=void 0),o},get readableLength(){return x.readableLength},onEmpty:p=>x.onEmpty(p)},o}async function kn(r,t,e,n){let o=new It(n?.errorMessage);n?.errorCode!=null&&(o.code=n.errorCode);let s=n?.errorEvent??"error";return e?.aborted===!0?Promise.reject(o):new Promise((i,a)=>{function c(){ii(e,"abort",d),ii(r,t,l),ii(r,s,f)}let l=u=>{try{if(n?.filter?.(u)===!1)return}catch(h){c(),a(h);return}c(),i(u)},f=u=>{if(c(),u instanceof Error){a(u);return}a(u.detail??n?.error??new Error(`The "${n?.errorEvent}" event was emitted but the event had no '.detail' field. Pass an 'error' option to race-event to change this message.`))},d=()=>{c(),a(o)};si(e,"abort",d),si(r,t,l),si(r,s,f)})}function si(r,t,e){r!=null&&(Lc(r)?r.addEventListener(t,e):r.addListener(t,e))}function ii(r,t,e){r!=null&&(Lc(r)?r.removeEventListener(t,e):r.removeListener(t,e))}function Lc(r){return typeof r.addEventListener=="function"&&typeof r.removeEventListener=="function"}var Kn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};var Nn=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function Rc(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new Nn(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new Nn(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 Un=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 It)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function kd(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Mn=class{id;fn;options;recipients;status;timeline;controller;constructor(t,e){this.id=kd(),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 It),this.cleanup())}async join(t={}){let e=new Un(t.signal);return this.recipients.push(e),t.signal?.addEventListener("abort",this.onAbort),e.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let t=await Rc(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(e=>{e.deferred.resolve(t)}),this.status="complete"}catch(t){this.recipients.forEach(e=>{e.deferred.reject(t)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(t=>{t.cleanup(),t.signal?.removeEventListener("abort",this.onAbort)})}};function ai(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 Hr=class extends Pe{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=ai(this.emitEmpty.bind(this),1),this.emitIdle=ai(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 Kn;let n=new Mn(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 It)}),this.clear()}async onEmpty(t){this.size!==0&&await kn(this,"empty",t?.signal)}async onSizeLessThan(t,e){this.size<t||await kn(this,"next",e?.signal,{filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await kn(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=Dc({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 It("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 qn="lock:worker:request-read",Hn="lock:worker:abort-read-request",Vn="lock:worker:release-read",zn="lock:master:grant-read",Fn="lock:master:error-read",Wn="lock:worker:request-write",Gn="lock:worker:abort-write-request",Zn="lock:worker:release-write",$n="lock:master:grant-write",Yn="lock:master:error-write",jn="lock:worker:finalize",Xn="mortice",Pc={singleProcess:!1};var ci=(r,t,e,n,o,s,i,a,c)=>l=>{if(l.data==null)return;let f={type:l.data.type,name:l.data.name,identifier:l.data.identifier};f.type===o&&r.safeDispatchEvent(e,{detail:{name:f.name,identifier:f.identifier,handler:async()=>{t.postMessage({type:c,name:f.name,identifier:f.identifier}),await new Promise(d=>{let u=h=>{if(h?.data==null)return;let m={type:h.data.type,name:h.data.name,identifier:h.data.identifier};m.type===a&&m.identifier===f.identifier&&(t.removeEventListener("message",u),d())};t.addEventListener("message",u)})},onError:d=>{t.postMessage({type:i,name:f.name,identifier:f.identifier,error:{message:d.message,name:d.name,stack:d.stack}})}}}),f.type===s&&r.safeDispatchEvent(n,{detail:{name:f.name,identifier:f.identifier}}),f.type===jn&&r.safeDispatchEvent("finalizeRequest",{detail:{name:f.name}})};var Oc=(r=10)=>Math.random().toString().substring(2,r+2);var Qn=class{name;channel;constructor(t){this.name=t,this.channel=new BroadcastChannel(Xn)}readLock(t){return this.sendRequest(qn,Hn,zn,Fn,Vn,t)}writeLock(t){return this.sendRequest(Wn,Gn,$n,Yn,Zn,t)}finalize(){this.channel.postMessage({type:jn,name:this.name}),this.channel.close()}async sendRequest(t,e,n,o,s,i){i?.signal?.throwIfAborted();let a=Oc();return this.channel.postMessage({type:t,identifier:a,name:this.name}),new Promise((c,l)=>{let f=()=>{this.channel.postMessage({type:e,identifier:a,name:this.name})};i?.signal?.addEventListener("abort",f,{once:!0});let d=u=>{if(u.data?.identifier===a&&(u.data?.type===n&&(this.channel.removeEventListener("message",d),i?.signal?.removeEventListener("abort",f),c(()=>{this.channel.postMessage({type:s,identifier:a,name:this.name})})),u.data.type===o)){this.channel.removeEventListener("message",d),i?.signal?.removeEventListener("abort",f);let h=new Error;u.data.error!=null&&(h.message=u.data.error.message,h.name=u.data.error.name,h.stack=u.data.error.stack),l(h)}};this.channel.addEventListener("message",d)})}};var kc=r=>{if(r=Object.assign({},Pc,r),!!globalThis.document||r.singleProcess){let e=new BroadcastChannel(Xn),n=new Pe;return e.addEventListener("message",ci(n,e,"requestReadLock","abortReadLockRequest",qn,Hn,Fn,Vn,zn)),e.addEventListener("message",ci(n,e,"requestWriteLock","abortWriteLockRequest",Wn,Gn,Yn,Zn,$n)),n}return new Qn(r.name)};var De=new Map,Vr;function Kc(r){return typeof r?.readLock=="function"&&typeof r?.writeLock=="function"}function Kd(r){if(Vr==null&&(Vr=kc(r),!Kc(Vr))){let t=Vr;t.addEventListener("requestReadLock",e=>{let n=e.detail.name,o=e.detail.identifier,s=De.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=De.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=De.get(n);o?.finalize()})}return Vr}async function ui(r,t){let e,n,o=new Promise((i,a)=>{e=i,n=a}),s=()=>{n(new It)};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 Nc=(r,t)=>{let e=De.get(r);if(e!=null)return e;let n=Kd(t);if(Kc(n))return e=n,De.set(r,e),e;let o=new Hr({concurrency:1}),s;return e={async readLock(i){if(s!=null)return ui(s,i);s=new Hr({concurrency:t.concurrency,autoStart:!1});let a=s,c=ui(s,i);return o.add(async()=>{a.start(),await a.onIdle().then(()=>{s===a&&(s=null)})}),c},async writeLock(i){return s=null,ui(o,i)},finalize:()=>{De.delete(r)},queue:o},De.set(r,e),t.autoFinalize===!0&&o.addEventListener("idle",()=>{e.finalize()},{once:!0}),e};var Nd={name:"lock",concurrency:1/0,singleProcess:!1,autoFinalize:!1};function li(r){let t=Object.assign({},Nd,r);return Nc(t.name,t)}var ee;(function(r){let t;(function(o){let s;o.codec=()=>(s==null&&(s=pt((i,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),i.key!=null&&i.key!==""&&(a.uint32(10),a.string(i.key)),i.value!=null&&i.value.byteLength>0&&(a.uint32(18),a.bytes(i.value)),c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let l={key:"",value:et(0)},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let d=i.uint32();switch(d>>>3){case 1:{l.key=i.string();break}case 2:{l.value=i.bytes();break}default:{i.skipType(d&7);break}}}return l})),s),o.encode=i=>ht(i,o.codec()),o.decode=(i,a)=>dt(i,o.codec(),a)})(t=r.Peer$metadataEntry||(r.Peer$metadataEntry={}));let e;(function(o){let s;o.codec=()=>(s==null&&(s=pt((i,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),i.key!=null&&i.key!==""&&(a.uint32(10),a.string(i.key)),i.value!=null&&(a.uint32(18),to.codec().encode(i.value,a)),c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let l={key:""},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let d=i.uint32();switch(d>>>3){case 1:{l.key=i.string();break}case 2:{l.value=to.codec().decode(i,i.uint32(),{limits:c.limits?.value});break}default:{i.skipType(d&7);break}}}return l})),s),o.encode=i=>ht(i,o.codec()),o.decode=(i,a)=>dt(i,o.codec(),a)})(e=r.Peer$tagsEntry||(r.Peer$tagsEntry={}));let n;r.codec=()=>(n==null&&(n=pt((o,s,i={})=>{if(i.lengthDelimited!==!1&&s.fork(),o.addresses!=null)for(let a of o.addresses)s.uint32(10),Jn.codec().encode(a,s);if(o.protocols!=null)for(let a of o.protocols)s.uint32(18),s.string(a);if(o.publicKey!=null&&(s.uint32(34),s.bytes(o.publicKey)),o.peerRecordEnvelope!=null&&(s.uint32(42),s.bytes(o.peerRecordEnvelope)),o.metadata!=null&&o.metadata.size!==0)for(let[a,c]of o.metadata.entries())s.uint32(50),r.Peer$metadataEntry.codec().encode({key:a,value:c},s);if(o.tags!=null&&o.tags.size!==0)for(let[a,c]of o.tags.entries())s.uint32(58),r.Peer$tagsEntry.codec().encode({key:a,value:c},s);o.updated!=null&&(s.uint32(64),s.uint64Number(o.updated)),i.lengthDelimited!==!1&&s.ldelim()},(o,s,i={})=>{let a={addresses:[],protocols:[],metadata:new Map,tags:new Map},c=s==null?o.len:o.pos+s;for(;o.pos<c;){let l=o.uint32();switch(l>>>3){case 1:{if(i.limits?.addresses!=null&&a.addresses.length===i.limits.addresses)throw new Te('Decode error - map field "addresses" had too many elements');a.addresses.push(Jn.codec().decode(o,o.uint32(),{limits:i.limits?.addresses$}));break}case 2:{if(i.limits?.protocols!=null&&a.protocols.length===i.limits.protocols)throw new Te('Decode error - map field "protocols" had too many elements');a.protocols.push(o.string());break}case 4:{a.publicKey=o.bytes();break}case 5:{a.peerRecordEnvelope=o.bytes();break}case 6:{if(i.limits?.metadata!=null&&a.metadata.size===i.limits.metadata)throw new Tr('Decode error - map field "metadata" had too many elements');let f=r.Peer$metadataEntry.codec().decode(o,o.uint32());a.metadata.set(f.key,f.value);break}case 7:{if(i.limits?.tags!=null&&a.tags.size===i.limits.tags)throw new Tr('Decode error - map field "tags" had too many elements');let f=r.Peer$tagsEntry.codec().decode(o,o.uint32(),{limits:{value:i.limits?.tags$value}});a.tags.set(f.key,f.value);break}case 8:{a.updated=o.uint64Number();break}default:{o.skipType(l&7);break}}}return a})),n),r.encode=o=>ht(o,r.codec()),r.decode=(o,s)=>dt(o,r.codec(),s)})(ee||(ee={}));var Jn;(function(r){let t;r.codec=()=>(t==null&&(t=pt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.multiaddr!=null&&e.multiaddr.byteLength>0&&(n.uint32(10),n.bytes(e.multiaddr)),e.isCertified!=null&&(n.uint32(16),n.bool(e.isCertified)),e.observed!=null&&(n.uint32(24),n.uint64Number(e.observed)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={multiaddr:et(0)},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.multiaddr=e.bytes();break}case 2:{s.isCertified=e.bool();break}case 3:{s.observed=e.uint64Number();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>ht(e,r.codec()),r.decode=(e,n)=>dt(e,r.codec(),n)})(Jn||(Jn={}));var to;(function(r){let t;r.codec=()=>(t==null&&(t=pt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.value!=null&&e.value!==0&&(n.uint32(8),n.uint32(e.value)),e.expiry!=null&&(n.uint32(16),n.uint64(e.expiry)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={value:0},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.value=e.uint32();break}case 2:{s.expiry=e.uint64();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>ht(e,r.codec()),r.decode=(e,n)=>dt(e,r.codec(),n)})(to||(to={}));function Ud(r,t){if(r.publicKey!=null||t.publicKey==null)return r;let e;r.type==="RSA"&&(e=r.toMultihash());let n=xn(t.publicKey,e);return ac(n)}function Uc(r,t,e){let n=ee.decode(t);return rr(r,n,e)}function rr(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:Ud(r,t),addresses:t.addresses.filter(({observed:s})=>s!=null&&s>Date.now()-e).map(({multiaddr:s,isCertified:i})=>({multiaddr:Ut(s),isCertified:i??!1})),metadata:t.metadata,peerRecordEnvelope:t.peerRecordEnvelope??void 0,tags:n}}function Mc(r,t){return Md(r.addresses,t.addresses)&&qd(r.protocols,t.protocols)&&Hd(r.publicKey,t.publicKey)&&Vd(r.peerRecordEnvelope,t.peerRecordEnvelope)&&zd(r.metadata,t.metadata)&&Fd(r.tags,t.tags)}function Md(r,t){return Hc(r,t,(e,n)=>!(e.isCertified!==n.isCertified||!$(e.multiaddr,n.multiaddr)))}function qd(r,t){return Hc(r,t,(e,n)=>e===n)}function Hd(r,t){return qc(r,t)}function Vd(r,t){return qc(r,t)}function zd(r,t){return Vc(r,t,(e,n)=>$(e,n))}function Fd(r,t){return Vc(r,t,(e,n)=>e.value===n.value&&e.expiry===n.expiry)}function qc(r,t){return r==null&&t==null?!0:r!=null&&t!=null?$(r,t):!1}function Hc(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 Vc(r,t,e){if(r.size!==t.size)return!1;for(let[n,o]of r.entries()){let s=t.get(n);if(s==null||!e(o,s))return!1}return!0}var re="/",zc=new TextEncoder().encode(re),eo=zc[0],ro=class r{_buf;constructor(t,e){if(typeof t=="string")this._buf=H(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]!==eo)throw new Error("Invalid key")}toString(t="utf8"){return M(this._buf,t)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(t){return new r(t.join(re))}static random(){return new r(Math.random().toString().substring(2))}static asKey(t){return t instanceof Uint8Array||typeof t=="string"?new r(t):typeof t.uint8Array=="function"?new r(t.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=zc),this._buf[0]!==eo){let t=new Uint8Array(this._buf.byteLength+1);t.fill(eo,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===eo;)this._buf=this._buf.subarray(0,-1)}less(t){let e=this.list(),n=t.list();for(let o=0;o<e.length;o++){if(n.length<o+1)return!1;let s=e[o],i=n[o];if(s<i)return!0;if(s>i)return!1}return e.length<n.length}reverse(){return r.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let t=this.namespaces();return t[t.length-1]}list(){return this.toString().split(re).slice(1)}type(){return Wd(this.baseNamespace())}name(){return Gd(this.baseNamespace())}instance(t){return new r(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(re)||(t+=re),t+=this.type(),new r(t)}parent(){let t=this.list();return t.length===1?new r(re):new r(t.slice(0,-1).join(re))}child(t){return this.toString()===re?t:t.toString()===re?this:new r(this.toString()+t.toString(),!1)}isAncestorOf(t){return t.toString()===this.toString()?!1:t.toString().startsWith(this.toString())}isDecendantOf(t){return t.toString()===this.toString()?!1:this.toString().startsWith(t.toString())}isTopLevel(){return this.list().length===1}concat(...t){return r.withNamespaces([...this.namespaces(),...Zd(t.map(e=>e.namespaces()))])}};function Wd(r){let t=r.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function Gd(r){let t=r.split(":");return t[t.length-1]}function Zd(r){return[].concat(...r)}var fi="/peers/";function zr(r){if(!Le(r)||r.type==null)throw new q("Invalid PeerId");let t=r.toCID().toString();return new ro(`${fi}${t}`)}async function Fc(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=Ut(i.multiaddr)),!Ln(i.multiaddr))throw new q("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(Ut(`/p2p/${r}`))),{isCertified:i,multiaddr:a.bytes}})}async function oo(r,t,e,n){if(t==null)throw new q("Invalid PeerData");if(t.publicKey!=null&&r.publicKey!=null&&!t.publicKey.equals(r.publicKey))throw new q("publicKey bytes do not match peer id publicKey bytes");let o=n.existingPeer?.peer;if(o!=null&&!r.equals(o.id))throw new q("peer id did not match existing peer id");let s=o?.addresses??[],i=new Set(o?.protocols??[]),a=o?.metadata??new Map,c=o?.tags??new Map,l=o?.peerRecordEnvelope;if(e==="patch"){if((t.multiaddrs!=null||t.addresses!=null)&&(s=[],t.multiaddrs!=null&&s.push(...t.multiaddrs.map(u=>({isCertified:!1,multiaddr:u}))),t.addresses!=null&&s.push(...t.addresses)),t.protocols!=null&&(i=new Set(t.protocols)),t.metadata!=null){let u=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);a=no(u,{validate:Wc})}if(t.tags!=null){let u=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags);c=no(u,{validate:Gc,map:Zc})}t.peerRecordEnvelope!=null&&(l=t.peerRecordEnvelope)}if(e==="merge"){if(t.multiaddrs!=null&&s.push(...t.multiaddrs.map(u=>({isCertified:!1,multiaddr:u}))),t.addresses!=null&&s.push(...t.addresses),t.protocols!=null&&(i=new Set([...i,...t.protocols])),t.metadata!=null){let u=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);for(let[h,m]of u)m==null?a.delete(h):a.set(h,m);a=no([...a.entries()],{validate:Wc})}if(t.tags!=null){let u=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags),h=new Map(c);for(let[m,x]of u)x==null?h.delete(m):h.set(m,x);c=no([...h.entries()],{validate:Gc,map:Zc})}t.peerRecordEnvelope!=null&&(l=t.peerRecordEnvelope)}let f;o?.id.publicKey!=null?f=_t(o.id.publicKey):t.publicKey!=null?f=_t(t.publicKey):r.publicKey!=null&&(f=_t(r.publicKey));let d={addresses:await Fc(r,n.addressFilter??(async()=>!0),s,n.existingPeer?.peerPB.addresses,n),protocols:[...i.values()].sort((u,h)=>u.localeCompare(h)),metadata:a,tags:c,publicKey:f,peerRecordEnvelope:l};return d.addresses.forEach(u=>{u.observed=n.existingPeer?.peerPB.addresses?.find(h=>$(h.multiaddr,h.multiaddr))?.observed??Date.now()}),r.type!=="RSA"&&delete d.publicKey,d}function no(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 Wc(r,t){if(typeof r!="string")throw new q("Metadata key must be a string");if(!(t instanceof Uint8Array))throw new q("Metadata value must be a Uint8Array")}function Gc(r,t){if(typeof r!="string")throw new q("Tag name must be a string");if(t.value!=null){if(parseInt(`${t.value}`,10)!==t.value)throw new q("Tag value must be an integer");if(t.value<0||t.value>100)throw new q("Tag value must be between 0-100")}if(t.ttl!=null){if(parseInt(`${t.ttl}`,10)!==t.ttl)throw new q("Tag ttl must be an integer");if(t.ttl<0)throw new q("Tag ttl must be between greater than 0")}}function Zc(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 $c(r){let t=r.toString().split("/")[2],e=X.parse(t,Ot);return wn(e)}function di(r,t,e){let n=$c(r);return Uc(n,t,e)}function $d(r,t){return{prefix:fi,filters:(r.filters??[]).map(e=>({key:n,value:o})=>e(di(n,o,t))),orders:(r.orders??[]).map(e=>(n,o)=>e(di(n.key,n.value,t),di(o.key,o.value,t)))}}var so=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=ni({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:li({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(zr(t),e)}async load(t,e){let n=zr(t),o=await this.datastore.get(n,e),s=ee.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,e),new sr;return rr(t,s,this.peerId.equals(t)?1/0:this.maxAddressAge)}async save(t,e,n){let o=await this.#t(t,n),s=await oo(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 oo(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 oo(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($d(t??{},this.maxAddressAge),t)){let o=$c(e);if(o.equals(this.peerId))continue;let s=ee.decode(n);if(this.#r(o,s)){await this.datastore.delete(e,t);continue}yield rr(o,s,this.peerId.equals(o)?1/0:this.maxAddressAge)}}async#t(t,e){try{let n=zr(t),o=await this.datastore.get(n,e),s=ee.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,e),new sr;return{peerPB:s,peer:rr(t,s,this.maxAddressAge)}}catch(n){n.name!=="NotFoundError"&&this.log.error("invalid peer data found in peer store - %e",n)}}async#e(t,e,n,o){e.updated=Date.now();let s=ee.encode(e);return await this.datastore.put(zr(t),s,o),{peer:rr(t,e,this.maxAddressAge),previous:n?.peer,updated:n==null||!Mc(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 hi=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 so(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 Cc(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=Le(e)?e:Le(e?.expectedPeer)?e.expectedPeer:void 0,s=Le(e)||e===void 0?n:e,i=await Je.openAndCertify(t,Ce.DOMAIN,s),a=wn(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=Ce.createFromProtobuf(i.payload),l;try{l=await this.get(a,s)}catch(f){if(f.name!=="NotFoundError")throw f}if(l?.peerRecordEnvelope!=null){let f=Je.createFromProtobuf(l.peerRecordEnvelope),d=Ce.createFromProtobuf(f.payload);if(d.seqNumber>=c.seqNumber)return this.log("sequence number was lower or equal to existing sequence number - stored: %d received: %d",d.seqNumber,c.seqNumber),!1}return await this.patch(c.peerId,{peerRecordEnvelope:t,addresses:c.multiaddrs.map(f=>({isCertified:!0,multiaddr:f}))},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 Yd(r,t={}){return new hi(r,t)}return Jc(jd);})();
|
|
2
|
+
"use strict";var Libp2PPeerStore=(()=>{var io=Object.defineProperty;var Jc=Object.getOwnPropertyDescriptor;var tu=Object.getOwnPropertyNames;var eu=Object.prototype.hasOwnProperty;var xt=(e,t)=>{for(var r in t)io(e,r,{get:t[r],enumerable:!0})},ru=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of tu(t))!eu.call(e,o)&&o!==r&&io(e,o,{get:()=>t[o],enumerable:!(n=Jc(t,o))||n.enumerable});return e};var nu=e=>ru(io({},"__esModule",{value:!0}),e);var th={};xt(th,{persistentPeerStore:()=>Jd});var zr=Symbol.for("@libp2p/peer-id");function Te(e){return!!e?.[zr]}var q=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Re=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var nr=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var Fr=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},Wr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var ye=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var De=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let r=this.#t.get(t);return r==null?0:r.length}addEventListener(t,r,n){super.addEventListener(t,r,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,r,n){super.removeEventListener(t.toString(),r??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==r),this.#t.set(t,o))}dispatchEvent(t){let r=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),r}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var fo={};xt(fo,{base58btc:()=>G,base58flickr:()=>lu});var sh=new Uint8Array(0);function Ei(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function qt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function vi(e){return new TextEncoder().encode(e)}function Si(e){return new TextDecoder().decode(e)}function ou(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=e.length,c=e.charAt(0),l=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function d(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var E=0,v=0,b=0,A=p.length;b!==A&&p[b]===0;)b++,E++;for(var x=(A-b)*f+1>>>0,C=new Uint8Array(x);b!==A;){for(var L=p[b],M=0,N=x-1;(L!==0||M<v)&&N!==-1;N--,M++)L+=256*C[N]>>>0,C[N]=L%a>>>0,L=L/a>>>0;if(L!==0)throw new Error("Non-zero carry");v=M,b++}for(var O=x-v;O!==x&&C[O]===0;)O++;for(var w=c.repeat(E);O<x;++O)w+=e.charAt(C[O]);return w}function u(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var E=0;if(p[E]!==" "){for(var v=0,b=0;p[E]===c;)v++,E++;for(var A=(p.length-E)*l+1>>>0,x=new Uint8Array(A);p[E];){var C=r[p.charCodeAt(E)];if(C===255)return;for(var L=0,M=A-1;(C!==0||L<b)&&M!==-1;M--,L++)C+=a*x[M]>>>0,x[M]=C%256>>>0,C=C/256>>>0;if(C!==0)throw new Error("Non-zero carry");b=L,E++}if(p[E]!==" "){for(var N=A-b;N!==A&&x[N]===0;)N++;for(var O=new Uint8Array(v+(A-N)),w=v;N!==A;)O[w++]=x[N++];return O}}}function h(p){var E=u(p);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:d,decodeUnsafe:u,decode:h}}var su=ou,iu=su,Ii=iu;var ao=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},co=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.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 _i(this,t)}},uo=class{decoders;constructor(t){this.decoders=t}or(t){return _i(this,t)}decode(t){let r=t[0],n=this.decoders[r];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 _i(e,t){return new uo({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var lo=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new ao(t,r,n),this.decoder=new co(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Le({name:e,prefix:t,encode:r,decode:n}){return new lo(e,t,r,n)}function se({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Ii(r,e);return Le({prefix:t,name:e,encode:n,decode:s=>qt(o(s))})}function au(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let l=0;l<o;++l){let f=t[e[l]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function cu(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],i+=8;i>r;)i-=r,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function uu(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function Q({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=uu(n);return Le({prefix:t,name:e,encode(s){return cu(s,n,r)},decode(s){return au(s,o,r,e)}})}var G=se({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),lu=se({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ho={};xt(ho,{base32:()=>Kt,base32hex:()=>pu,base32hexpad:()=>yu,base32hexpadupper:()=>bu,base32hexupper:()=>mu,base32pad:()=>du,base32padupper:()=>hu,base32upper:()=>fu,base32z:()=>gu});var Kt=Q({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),fu=Q({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),du=Q({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),hu=Q({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),pu=Q({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),mu=Q({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),yu=Q({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),bu=Q({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),gu=Q({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var po={};xt(po,{base36:()=>or,base36upper:()=>xu});var or=se({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),xu=se({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var wu=Ti,Bi=128,Eu=127,vu=~Eu,Su=Math.pow(2,31);function Ti(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Su;)t[r++]=e&255|Bi,e/=128;for(;e&vu;)t[r++]=e&255|Bi,e>>>=7;return t[r]=e|0,Ti.bytes=r-n+1,t}var Au=mo,Iu=128,Ci=127;function mo(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw mo.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Ci)<<o:(i&Ci)*Math.pow(2,o),o+=7}while(i>=Iu);return mo.bytes=s-n,r}var _u=Math.pow(2,7),Bu=Math.pow(2,14),Cu=Math.pow(2,21),Tu=Math.pow(2,28),Ru=Math.pow(2,35),Du=Math.pow(2,42),Lu=Math.pow(2,49),Pu=Math.pow(2,56),Ou=Math.pow(2,63),ku=function(e){return e<_u?1:e<Bu?2:e<Cu?3:e<Tu?4:e<Ru?5:e<Du?6:e<Lu?7:e<Pu?8:e<Ou?9:10},Ku={encode:wu,decode:Au,encodingLength:ku},Uu=Ku,sr=Uu;function ir(e,t=0){return[sr.decode(e,t),sr.decode.bytes]}function Pe(e,t,r=0){return sr.encode(e,t,r),t}function Oe(e){return sr.encodingLength(e)}function Lt(e,t){let r=t.byteLength,n=Oe(e),o=n+Oe(r),s=new Uint8Array(o+r);return Pe(e,s,0),Pe(r,s,n),s.set(t,o),new ke(e,r,t,s)}function Ke(e){let t=qt(e),[r,n]=ir(t),[o,s]=ir(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ke(r,o,i,t)}function Ri(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Ei(e.bytes,r.bytes)}}var ke=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function Di(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return Mu(r,yo(e),t??G.encoder);default:return qu(r,yo(e),t??Kt.encoder)}}var Li=new WeakMap;function yo(e){let t=Li.get(e);if(t==null){let r=new Map;return Li.set(e,r),r}return t}var J=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,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:r}=this;if(t!==ar)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Vu)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}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:r}=this.multihash,n=Lt(t,r);return e.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 e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&Ri(t.multihash,n.multihash)}toString(t){return Di(this,t)}toJSON(){return{"/":Di(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 r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new e(n,o,s,i??Pi(n,o,s.bytes))}else if(r[Hu]===!0){let{version:n,multihash:o,code:s}=r,i=Ke(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="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(r!==ar)throw new Error(`Version 0 CID must use dag-pb (code: ${ar}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Pi(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,ar,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=qt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new ke(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[d,u]=ir(t.subarray(r));return r+=u,d},o=n(),s=ar;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),l=r+c,f=l-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:l}}static parse(t,r){let[n,o]=Nu(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return yo(s).set(n,t),s}};function Nu(e,t){switch(e[0]){case"Q":{let r=t??G;return[G.prefix,r.decode(`${G.prefix}${e}`)]}case G.prefix:{let r=t??G;return[G.prefix,r.decode(e)]}case Kt.prefix:{let r=t??Kt;return[Kt.prefix,r.decode(e)]}case or.prefix:{let r=t??or;return[or.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function Mu(e,t,r){let{prefix:n}=r;if(n!==G.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function qu(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var ar=112,Vu=18;function Pi(e,t,r){let n=Oe(e),o=n+Oe(t),s=new Uint8Array(o+r.byteLength);return Pe(e,s,0),Pe(t,s,n),s.set(r,o),s}var Hu=Symbol.for("@ipld/js-cid/CID");var bo={};xt(bo,{identity:()=>Pt});var Oi=0,zu="identity",ki=qt;function Fu(e){return Lt(Oi,ki(e))}var Pt={code:Oi,name:zu,encode:ki,digest:Fu};function $(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function rt(e=0){return new Uint8Array(e)}function wt(e=0){return new Uint8Array(e)}function Vt(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=wt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Ui=Symbol.for("@achingbrain/uint8arraylist");function Ki(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function $r(e){return!!e?.[Ui]}var dt=class e{bufs;length;[Ui]=!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 r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if($r(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if($r(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=Ki(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Ki(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if($r(t))for(let n=0;n<t.length;n++)this.set(r+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,r){let{bufs:n,length:o}=this._subList(t,r);return Vt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Vt(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=[...n],s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===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,f=r>a&&r<=c;if(l&&f){if(t===a&&r===c){n.push(i);break}let d=t-a;n.push(i.subarray(d,d+(r-t)));break}if(l){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!$r(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;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 d=0;d<s;d++)i[d]=-1;for(let d=0;d<o;d++)i[n[d]]=d;let a=i,c=this.byteLength-n.byteLength,l=n.byteLength-1,f;for(let d=r;d<=c;d+=f){f=0;for(let u=l;u>=0;u--){let h=this.get(d+u);if(n[u]!==h){f=Math.max(1,u-a[h]);break}}if(f===0)return d}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=wt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=rt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=wt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=rt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!$(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var go={};xt(go,{base10:()=>Wu});var Wu=se({prefix:"9",name:"base10",alphabet:"0123456789"});var xo={};xt(xo,{base16:()=>Gu,base16upper:()=>$u});var Gu=Q({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),$u=Q({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var wo={};xt(wo,{base2:()=>Zu});var Zu=Q({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Eo={};xt(Eo,{base256emoji:()=>Ju});var Ni=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),ju=Ni.reduce((e,t,r)=>(e[r]=t,e),[]),Yu=Ni.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Xu(e){return e.reduce((t,r)=>(t+=ju[r],t),"")}function Qu(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Yu[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Ju=Le({prefix:"\u{1F680}",name:"base256emoji",encode:Xu,decode:Qu});var So={};xt(So,{base64:()=>tl,base64pad:()=>el,base64url:()=>vo,base64urlpad:()=>rl});var tl=Q({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),el=Q({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),vo=Q({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),rl=Q({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ao={};xt(Ao,{base8:()=>nl});var nl=Q({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Io={};xt(Io,{identity:()=>ol});var ol=Le({prefix:"\0",name:"identity",encode:e=>Si(e),decode:e=>vi(e)});var Hh=new TextEncoder,zh=new TextDecoder;var Co={};xt(Co,{sha256:()=>cr,sha512:()=>al});function Bo({name:e,code:t,encode:r}){return new _o(e,t,r)}var _o=class{name;code;encode;constructor(t,r,n){this.name=t,this.code=r,this.encode=n}digest(t){if(t instanceof Uint8Array){let r=this.encode(t);return r instanceof Uint8Array?Lt(this.code,r):r.then(n=>Lt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function qi(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var cr=Bo({name:"sha2-256",code:18,encode:qi("SHA-256")}),al=Bo({name:"sha2-512",code:19,encode:qi("SHA-512")});var ur={...Io,...wo,...Ao,...go,...xo,...ho,...po,...fo,...So,...Eo},ep={...Co,...bo};function Hi(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Vi=Hi("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),To=Hi("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=wt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),cl={utf8:Vi,"utf-8":Vi,hex:ur.base16,latin1:To,ascii:To,binary:To,...ur},Zr=cl;function V(e,t="utf8"){let r=Zr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function U(e,t="utf8"){let r=Zr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var ul=parseInt("11111",2),Ro=parseInt("10000000",2),ll=parseInt("01111111",2),zi={0:lr,1:lr,2:fl,3:pl,4:ml,5:hl,6:dl,16:lr,22:lr,48:lr};function Ht(e,t={offset:0}){let r=e[t.offset]&ul;if(t.offset++,zi[r]!=null)return zi[r](e,t);throw new Error("No decoder for tag "+r)}function fr(e,t){let r=0;if((e[t.offset]&Ro)===Ro){let n=e[t.offset]&ll,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function lr(e,t){fr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Ht(e,t);if(n===null)break;r.push(n)}return r}function fl(e,t){let r=fr(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function dl(e,t){let r=fr(e,t),n=t.offset+r,o=e[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=e[t.offset];if(t.offset++,c.push(l&127),l<128){c.reverse();let f=0;for(let d=0;d<c.length;d++)f+=c[d]<<d*7;a+=`.${f}`,c=[]}}return a}function hl(e,t){return t.offset++,null}function pl(e,t){let r=fr(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function ml(e,t){let r=fr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function yl(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new dt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Do(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=yl(e.byteLength);return new dt(Uint8Array.from([t.byteLength|Ro]),t)}function Et(e){let t=new dt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new dt(Uint8Array.from([2]),Do(t),t)}function jr(e){let t=Uint8Array.from([0]),r=new dt(t,e);return new dt(Uint8Array.from([3]),Do(r),r)}function ae(e,t=48){let r=new dt;for(let n of e)r.append(n);return new dt(Uint8Array.from([t]),Do(r),r)}async function Fi(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),s}var bl=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),gl=Uint8Array.from([6,5,43,129,4,0,34]),xl=Uint8Array.from([6,5,43,129,4,0,35]),wl={ext:!0,kty:"EC",crv:"P-256"},El={ext:!0,kty:"EC",crv:"P-384"},vl={ext:!0,kty:"EC",crv:"P-521"},Lo=32,Po=48,Oo=66;function ko(e){let t=Ht(e);return Wi(t)}function Wi(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Lo*2+1)return n=U(t.subarray(r,r+Lo),"base64url"),o=U(t.subarray(r+Lo),"base64url"),new Ue({...wl,key_ops:["verify"],x:n,y:o});if(t.byteLength===Po*2+1)return n=U(t.subarray(r,r+Po),"base64url"),o=U(t.subarray(r+Po),"base64url"),new Ue({...El,key_ops:["verify"],x:n,y:o});if(t.byteLength===Oo*2+1)return n=U(t.subarray(r,r+Oo),"base64url"),o=U(t.subarray(r+Oo),"base64url"),new Ue({...vl,key_ops:["verify"],x:n,y:o});throw new q(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Gi(e){return ae([Et(Uint8Array.from([1])),ae([Sl(e.crv)],160),ae([jr(new dt(Uint8Array.from([4]),V(e.x??"","base64url"),V(e.y??"","base64url")))],161)]).subarray()}function Sl(e){if(e==="P-256")return bl;if(e==="P-384")return gl;if(e==="P-521")return xl;throw new q(`Invalid curve ${e}`)}var Ue=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 Pt.digest(Ct(this))}toCID(){return J.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:$(this.raw,t.raw)}async verify(t,r,n){return Fi(this.jwk,r,t,n)}};var be=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Ft(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function dr(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function vt(e,...t){if(!Ft(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Yr(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");dr(e.outputLen),dr(e.blockLen)}function Me(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Zi(e,t){vt(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Wt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Xr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Ot(e,t){return e<<32-t|e>>>t}var ji=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Al=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Tt(e){if(vt(e),ji)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Al[e[r]];return t}var zt={_0:48,_9:57,A:65,F:70,a:97,f:102};function $i(e){if(e>=zt._0&&e<=zt._9)return e-zt._0;if(e>=zt.A&&e<=zt.F)return e-(zt.A-10);if(e>=zt.a&&e<=zt.f)return e-(zt.a-10)}function ge(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(ji)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=$i(e.charCodeAt(s)),a=$i(e.charCodeAt(s+1));if(i===void 0||a===void 0){let c=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Ko(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function hr(e){return typeof e=="string"&&(e=Ko(e)),vt(e),e}function ht(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];vt(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}var Ne=class{};function Uo(e){let t=n=>e().update(hr(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function qe(e=32){if(be&&typeof be.getRandomValues=="function")return be.getRandomValues(new Uint8Array(e));if(be&&typeof be.randomBytes=="function")return Uint8Array.from(be.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function Il(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),a=Number(r&s),c=n?4:0,l=n?0:4;e.setUint32(t+c,i,n),e.setUint32(t+l,a,n)}function Yi(e,t,r){return e&t^~e&r}function Xi(e,t,r){return e&t^e&r^t&r}var pr=class extends Ne{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Xr(this.buffer)}update(t){Me(this),t=hr(t),vt(t);let{view:r,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=Xr(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(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Me(this),Zi(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Wt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let d=i;d<o;d++)r[d]=0;Il(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=Xr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=c/4,f=this.get();if(l>f.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<l;d++)a.setUint32(4*d,f[d],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,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%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Gt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var at=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Qr=BigInt(4294967295),Qi=BigInt(32);function _l(e,t=!1){return t?{h:Number(e&Qr),l:Number(e>>Qi&Qr)}:{h:Number(e>>Qi&Qr)|0,l:Number(e&Qr)|0}}function Ji(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=_l(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var No=(e,t,r)=>e>>>r,Mo=(e,t,r)=>e<<32-r|t>>>r,xe=(e,t,r)=>e>>>r|t<<32-r,we=(e,t,r)=>e<<32-r|t>>>r,mr=(e,t,r)=>e<<64-r|t>>>r-32,yr=(e,t,r)=>e>>>r-32|t<<64-r;function Ut(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var ta=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),ea=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,ra=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),na=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,oa=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),sa=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var Cl=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]),ce=new Uint32Array(64),Jr=class extends pr{constructor(t=32){super(64,t,8,!1),this.A=Gt[0]|0,this.B=Gt[1]|0,this.C=Gt[2]|0,this.D=Gt[3]|0,this.E=Gt[4]|0,this.F=Gt[5]|0,this.G=Gt[6]|0,this.H=Gt[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,r,n,o,s,i,a,c]}set(t,r,n,o,s,i,a,c){this.A=t|0,this.B=r|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,r){for(let d=0;d<16;d++,r+=4)ce[d]=t.getUint32(r,!1);for(let d=16;d<64;d++){let u=ce[d-15],h=ce[d-2],p=Ot(u,7)^Ot(u,18)^u>>>3,E=Ot(h,17)^Ot(h,19)^h>>>10;ce[d]=E+ce[d-7]+p+ce[d-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:l,H:f}=this;for(let d=0;d<64;d++){let u=Ot(a,6)^Ot(a,11)^Ot(a,25),h=f+u+Yi(a,c,l)+Cl[d]+ce[d]|0,E=(Ot(n,2)^Ot(n,13)^Ot(n,22))+Xi(n,o,s)|0;f=l,l=c,c=a,a=i+h|0,i=s,s=o,o=n,n=h+E|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,f=f+this.H|0,this.set(n,o,s,i,a,c,l,f)}roundClean(){Wt(ce)}destroy(){this.set(0,0,0,0,0,0,0,0),Wt(this.buffer)}};var ia=Ji(["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(e=>BigInt(e))),Tl=ia[0],Rl=ia[1],ue=new Uint32Array(80),le=new Uint32Array(80),qo=class extends pr{constructor(t=64){super(128,t,16,!1),this.Ah=at[0]|0,this.Al=at[1]|0,this.Bh=at[2]|0,this.Bl=at[3]|0,this.Ch=at[4]|0,this.Cl=at[5]|0,this.Dh=at[6]|0,this.Dl=at[7]|0,this.Eh=at[8]|0,this.El=at[9]|0,this.Fh=at[10]|0,this.Fl=at[11]|0,this.Gh=at[12]|0,this.Gl=at[13]|0,this.Hh=at[14]|0,this.Hl=at[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:l,El:f,Fh:d,Fl:u,Gh:h,Gl:p,Hh:E,Hl:v}=this;return[t,r,n,o,s,i,a,c,l,f,d,u,h,p,E,v]}set(t,r,n,o,s,i,a,c,l,f,d,u,h,p,E,v){this.Ah=t|0,this.Al=r|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=f|0,this.Fh=d|0,this.Fl=u|0,this.Gh=h|0,this.Gl=p|0,this.Hh=E|0,this.Hl=v|0}process(t,r){for(let x=0;x<16;x++,r+=4)ue[x]=t.getUint32(r),le[x]=t.getUint32(r+=4);for(let x=16;x<80;x++){let C=ue[x-15]|0,L=le[x-15]|0,M=xe(C,L,1)^xe(C,L,8)^No(C,L,7),N=we(C,L,1)^we(C,L,8)^Mo(C,L,7),O=ue[x-2]|0,w=le[x-2]|0,T=xe(O,w,19)^mr(O,w,61)^No(O,w,6),k=we(O,w,19)^yr(O,w,61)^Mo(O,w,6),R=ra(N,k,le[x-7],le[x-16]),g=na(R,M,T,ue[x-7],ue[x-16]);ue[x]=g|0,le[x]=R|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:l,Dl:f,Eh:d,El:u,Fh:h,Fl:p,Gh:E,Gl:v,Hh:b,Hl:A}=this;for(let x=0;x<80;x++){let C=xe(d,u,14)^xe(d,u,18)^mr(d,u,41),L=we(d,u,14)^we(d,u,18)^yr(d,u,41),M=d&h^~d&E,N=u&p^~u&v,O=oa(A,L,N,Rl[x],le[x]),w=sa(O,b,C,M,Tl[x],ue[x]),T=O|0,k=xe(n,o,28)^mr(n,o,34)^mr(n,o,39),R=we(n,o,28)^yr(n,o,34)^yr(n,o,39),g=n&s^n&a^s&a,m=o&i^o&c^i&c;b=E|0,A=v|0,E=h|0,v=p|0,h=d|0,p=u|0,{h:d,l:u}=Ut(l|0,f|0,w|0,T|0),l=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let y=ta(T,R,m);n=ea(y,w,k,g),o=y|0}({h:n,l:o}=Ut(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Ut(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Ut(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:f}=Ut(this.Dh|0,this.Dl|0,l|0,f|0),{h:d,l:u}=Ut(this.Eh|0,this.El|0,d|0,u|0),{h,l:p}=Ut(this.Fh|0,this.Fl|0,h|0,p|0),{h:E,l:v}=Ut(this.Gh|0,this.Gl|0,E|0,v|0),{h:b,l:A}=Ut(this.Hh|0,this.Hl|0,b|0,A|0),this.set(n,o,s,i,a,c,l,f,d,u,h,p,E,v,b,A)}roundClean(){Wt(ue,le)}destroy(){Wt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var tn=Uo(()=>new Jr);var aa=Uo(()=>new qo);var zo=BigInt(0),Ho=BigInt(1);function $t(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}"`;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function St(e,t,r=""){let n=Ft(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,a=s?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return e}function br(e){let t=e.toString(16);return t.length&1?"0"+t:t}function ca(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?zo:BigInt("0x"+e)}function Ve(e){return ca(Tt(e))}function Zt(e){return vt(e),ca(Tt(Uint8Array.from(e).reverse()))}function en(e,t){return ge(e.toString(16).padStart(t*2,"0"))}function Fo(e,t){return en(e,t).reverse()}function F(e,t,r){let n;if(typeof t=="string")try{n=ge(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(Ft(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}function ua(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function Wo(e){return Uint8Array.from(e)}var Vo=e=>typeof e=="bigint"&&zo<=e;function la(e,t,r){return Vo(e)&&Vo(t)&&Vo(r)&&t<=e&&e<r}function gr(e,t,r,n){if(!la(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function rn(e){let t;for(t=0;e>zo;e>>=Ho,t+=1);return t}var fe=e=>(Ho<<BigInt(e))-Ho;function fa(e,t,r){if(typeof e!="number"||e<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 r!="function")throw new Error("hmacFn must be a function");let n=h=>new Uint8Array(h),o=h=>Uint8Array.of(h),s=n(e),i=n(e),a=0,c=()=>{s.fill(1),i.fill(0),a=0},l=(...h)=>r(i,s,...h),f=(h=n(0))=>{i=l(o(0),h),s=l(),h.length!==0&&(i=l(o(1),h),s=l())},d=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let h=0,p=[];for(;h<t;){s=l();let E=s.slice();p.push(E),h+=s.length}return ht(...p)};return(h,p)=>{c(),f(h);let E;for(;!(E=p(d()));)f();return c(),E}}function de(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,s,i){let a=e[o];if(i&&a===void 0)return;let c=typeof a;if(c!==s||a===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${c}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(r).forEach(([o,s])=>n(o,s,!0))}var Go=()=>{throw new Error("not implemented")};function He(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var pt=BigInt(0),ot=BigInt(1),Ee=BigInt(2),pa=BigInt(3),ma=BigInt(4),ya=BigInt(5),Dl=BigInt(7),ba=BigInt(8),Ll=BigInt(9),ga=BigInt(16);function tt(e,t){let r=e%t;return r>=pt?r:t+r}function Z(e,t,r){let n=e;for(;t-- >pt;)n*=n,n%=r;return n}function da(e,t){if(e===pt)throw new Error("invert: expected non-zero number");if(t<=pt)throw new Error("invert: expected positive modulus, got "+t);let r=tt(e,t),n=t,o=pt,s=ot,i=ot,a=pt;for(;r!==pt;){let l=n/r,f=n%r,d=o-i*l,u=s-a*l;n=r,r=f,o=i,s=a,i=d,a=u}if(n!==ot)throw new Error("invert: does not exist");return tt(o,t)}function $o(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function xa(e,t){let r=(e.ORDER+ot)/ma,n=e.pow(t,r);return $o(e,n,t),n}function Pl(e,t){let r=(e.ORDER-ya)/ba,n=e.mul(t,Ee),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,Ee),o),a=e.mul(s,e.sub(i,e.ONE));return $o(e,a,t),a}function Ol(e){let t=At(e),r=wa(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+Dl)/ga;return(a,c)=>{let l=a.pow(c,i),f=a.mul(l,n),d=a.mul(l,o),u=a.mul(l,s),h=a.eql(a.sqr(f),c),p=a.eql(a.sqr(d),c);l=a.cmov(l,f,h),f=a.cmov(u,d,p);let E=a.eql(a.sqr(f),c),v=a.cmov(l,f,E);return $o(a,v,c),v}}function wa(e){if(e<pa)throw new Error("sqrt is not defined for small field");let t=e-ot,r=0;for(;t%Ee===pt;)t/=Ee,r++;let n=Ee,o=At(e);for(;ha(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return xa;let s=o.pow(n,t),i=(t+ot)/Ee;return function(c,l){if(c.is0(l))return l;if(ha(c,l)!==1)throw new Error("Cannot find square root");let f=r,d=c.mul(c.ONE,s),u=c.pow(l,t),h=c.pow(l,i);for(;!c.eql(u,c.ONE);){if(c.is0(u))return c.ZERO;let p=1,E=c.sqr(u);for(;!c.eql(E,c.ONE);)if(p++,E=c.sqr(E),p===f)throw new Error("Cannot find square root");let v=ot<<BigInt(f-p-1),b=c.pow(d,v);f=p,d=c.sqr(b),u=c.mul(u,d),h=c.mul(h,b)}return h}}function kl(e){return e%ma===pa?xa:e%ba===ya?Pl:e%ga===Ll?Ol(e):wa(e)}var jt=(e,t)=>(tt(e,t)&ot)===ot,Kl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Zo(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=Kl.reduce((n,o)=>(n[o]="function",n),t);return de(e,r),e}function Ul(e,t,r){if(r<pt)throw new Error("invalid exponent, negatives unsupported");if(r===pt)return e.ONE;if(r===ot)return t;let n=e.ONE,o=t;for(;r>pt;)r&ot&&(n=e.mul(n,o)),o=e.sqr(o),r>>=ot;return n}function xr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,a,c)=>e.is0(a)?i:(n[c]=i,e.mul(i,a)),e.ONE),s=e.inv(o);return t.reduceRight((i,a,c)=>e.is0(a)?i:(n[c]=e.mul(i,n[c]),e.mul(i,a)),s),n}function ha(e,t){let r=(e.ORDER-ot)/Ee,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function nn(e,t){t!==void 0&&dr(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function At(e,t,r=!1,n={}){if(e<=pt)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,s,i=!1,a;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let u=t;u.BITS&&(o=u.BITS),u.sqrt&&(s=u.sqrt),typeof u.isLE=="boolean"&&(r=u.isLE),typeof u.modFromBytes=="boolean"&&(i=u.modFromBytes),a=u.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:c,nByteLength:l}=nn(e,o);if(l>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let f,d=Object.freeze({ORDER:e,isLE:r,BITS:c,BYTES:l,MASK:fe(c),ZERO:pt,ONE:ot,allowedLengths:a,create:u=>tt(u,e),isValid:u=>{if(typeof u!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof u);return pt<=u&&u<e},is0:u=>u===pt,isValidNot0:u=>!d.is0(u)&&d.isValid(u),isOdd:u=>(u&ot)===ot,neg:u=>tt(-u,e),eql:(u,h)=>u===h,sqr:u=>tt(u*u,e),add:(u,h)=>tt(u+h,e),sub:(u,h)=>tt(u-h,e),mul:(u,h)=>tt(u*h,e),pow:(u,h)=>Ul(d,u,h),div:(u,h)=>tt(u*da(h,e),e),sqrN:u=>u*u,addN:(u,h)=>u+h,subN:(u,h)=>u-h,mulN:(u,h)=>u*h,inv:u=>da(u,e),sqrt:s||(u=>(f||(f=kl(e)),f(d,u))),toBytes:u=>r?Fo(u,l):en(u,l),fromBytes:(u,h=!0)=>{if(a){if(!a.includes(u.length)||u.length>l)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+u.length);let E=new Uint8Array(l);E.set(u,r?0:E.length-u.length),u=E}if(u.length!==l)throw new Error("Field.fromBytes: expected "+l+" bytes, got "+u.length);let p=r?Zt(u):Ve(u);if(i&&(p=tt(p,e)),!h&&!d.isValid(p))throw new Error("invalid field element: outside of range 0..ORDER");return p},invertBatch:u=>xr(d,u),cmov:(u,h,p)=>p?h:u});return Object.freeze(d)}function Ea(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function jo(e){let t=Ea(e);return t+Math.ceil(t/2)}function Yo(e,t,r=!1){let n=e.length,o=Ea(t),s=jo(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Zt(e):Ve(e),a=tt(i,t-ot)+ot;return r?Fo(a,o):en(a,o)}var ze=BigInt(0),ve=BigInt(1);function wr(e,t){let r=t.negate();return e?r:t}function Yt(e,t){let r=xr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Ia(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Xo(e,t){Ia(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=fe(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function va(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(e&o),c=e>>i;a>n&&(a-=s,c+=ve);let l=t*n,f=l+Math.abs(a)-1,d=a===0,u=a<0,h=t%2!==0;return{nextN:c,offset:f,isZero:d,isNeg:u,isNegF:h,offsetF:l}}function Nl(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function Ml(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var Qo=new WeakMap,_a=new WeakMap;function Jo(e){return _a.get(e)||1}function Sa(e){if(e!==ze)throw new Error("invalid wNAF")}var Fe=class{constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>ze;)r&ve&&(n=n.add(o)),o=o.double(),r>>=ve;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=Xo(r,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let l=1;l<o;l++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=Xo(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:l,isZero:f,isNeg:d,isNegF:u,offsetF:h}=va(n,a,i);n=c,f?s=s.add(wr(u,r[h])):o=o.add(wr(d,r[l]))}return Sa(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=Xo(t,this.bits);for(let i=0;i<s.windows&&n!==ze;i++){let{nextN:a,offset:c,isZero:l,isNeg:f}=va(n,i,s);if(n=a,!l){let d=r[c];o=o.add(f?d.negate():d)}}return Sa(n),o}getPrecomputes(t,r,n){let o=Qo.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),Qo.set(r,o))),o}cached(t,r,n){let o=Jo(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=Jo(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){Ia(r,this.bits),_a.set(t,r),Qo.delete(t)}hasCache(t){return Jo(t)!==1}};function Ba(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>ze||n>ze;)r&ve&&(s=s.add(o)),n&ve&&(i=i.add(o)),o=o.double(),r>>=ve,n>>=ve;return{p1:s,p2:i}}function We(e,t,r,n){Nl(r,e),Ml(n,t);let o=r.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=e.ZERO,a=rn(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let l=fe(c),f=new Array(Number(l)+1).fill(i),d=Math.floor((t.BITS-1)/c)*c,u=i;for(let h=d;h>=0;h-=c){f.fill(i);for(let E=0;E<s;E++){let v=n[E],b=Number(v>>BigInt(h)&l);f[b]=f[b].add(r[E])}let p=i;for(let E=f.length-1,v=i;E>0;E--)v=v.add(f[E]),p=p.add(v);if(u=u.add(p),h!==0)for(let E=0;E<c;E++)u=u.double()}return u}function Aa(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Zo(t),t}else return At(e,{isLE:r})}function on(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let c of["p","n","h"]){let l=t[c];if(!(typeof l=="bigint"&&l>ze))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Aa(t.p,r.Fp,n),s=Aa(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}var he=BigInt(0),st=BigInt(1),ts=BigInt(2),ql=BigInt(8);function Vl(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),a=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,a)}function Hl(e,t={}){let r=on("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i}=s;de(t,{},{uvRatio:"function"});let a=ts<<BigInt(o.BYTES*8)-st,c=v=>n.create(v),l=t.uvRatio||((v,b)=>{try{return{isValid:!0,value:n.sqrt(n.div(v,b))}}catch{return{isValid:!1,value:he}}});if(!Vl(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function f(v,b,A=!1){let x=A?st:he;return gr("coordinate "+v,b,x,a),b}function d(v){if(!(v instanceof p))throw new Error("ExtendedPoint expected")}let u=He((v,b)=>{let{X:A,Y:x,Z:C}=v,L=v.is0();b==null&&(b=L?ql:n.inv(C));let M=c(A*b),N=c(x*b),O=n.mul(C,b);if(L)return{x:he,y:st};if(O!==st)throw new Error("invZ was invalid");return{x:M,y:N}}),h=He(v=>{let{a:b,d:A}=s;if(v.is0())throw new Error("bad point: ZERO");let{X:x,Y:C,Z:L,T:M}=v,N=c(x*x),O=c(C*C),w=c(L*L),T=c(w*w),k=c(N*b),R=c(w*c(k+O)),g=c(T+c(A*c(N*O)));if(R!==g)throw new Error("bad point: equation left != right (1)");let m=c(x*C),y=c(L*M);if(m!==y)throw new Error("bad point: equation left != right (2)");return!0});class p{constructor(b,A,x,C){this.X=f("x",b),this.Y=f("y",A),this.Z=f("z",x,!0),this.T=f("t",C),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){if(b instanceof p)throw new Error("extended point not allowed");let{x:A,y:x}=b||{};return f("x",A),f("y",x),new p(A,x,st,c(A*x))}static fromBytes(b,A=!1){let x=n.BYTES,{a:C,d:L}=s;b=Wo(St(b,x,"point")),$t(A,"zip215");let M=Wo(b),N=b[x-1];M[x-1]=N&-129;let O=Zt(M),w=A?a:n.ORDER;gr("point.y",O,he,w);let T=c(O*O),k=c(T-st),R=c(L*T-C),{isValid:g,value:m}=l(k,R);if(!g)throw new Error("bad point: invalid y coordinate");let y=(m&st)===st,S=(N&128)!==0;if(!A&&m===he&&S)throw new Error("bad point: x=0 and x_0=1");return S!==y&&(m=c(-m)),p.fromAffine({x:m,y:O})}static fromHex(b,A=!1){return p.fromBytes(F("point",b),A)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,A=!0){return E.createCache(this,b),A||this.multiply(ts),this}assertValidity(){h(this)}equals(b){d(b);let{X:A,Y:x,Z:C}=this,{X:L,Y:M,Z:N}=b,O=c(A*N),w=c(L*C),T=c(x*N),k=c(M*C);return O===w&&T===k}is0(){return this.equals(p.ZERO)}negate(){return new p(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:b}=s,{X:A,Y:x,Z:C}=this,L=c(A*A),M=c(x*x),N=c(ts*c(C*C)),O=c(b*L),w=A+x,T=c(c(w*w)-L-M),k=O+M,R=k-N,g=O-M,m=c(T*R),y=c(k*g),S=c(T*g),I=c(R*k);return new p(m,y,I,S)}add(b){d(b);let{a:A,d:x}=s,{X:C,Y:L,Z:M,T:N}=this,{X:O,Y:w,Z:T,T:k}=b,R=c(C*O),g=c(L*w),m=c(N*x*k),y=c(M*T),S=c((C+L)*(O+w)-R-g),I=y-m,D=y+m,_=c(g-A*R),B=c(S*I),P=c(D*_),K=c(S*_),j=c(I*D);return new p(B,P,j,K)}subtract(b){return this.add(b.negate())}multiply(b){if(!o.isValidNot0(b))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:A,f:x}=E.cached(this,b,C=>Yt(p,C));return Yt(p,[A,x])[0]}multiplyUnsafe(b,A=p.ZERO){if(!o.isValid(b))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return b===he?p.ZERO:this.is0()||b===st?this:E.unsafe(this,b,x=>Yt(p,x),A)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return E.unsafe(this,s.n).is0()}toAffine(b){return u(this,b)}clearCofactor(){return i===st?this:this.multiplyUnsafe(i)}toBytes(){let{x:b,y:A}=this.toAffine(),x=n.toBytes(A);return x[x.length-1]|=b&st?128:0,x}toHex(){return Tt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(b){return Yt(p,b)}static msm(b,A){return We(p,o,b,A)}_setWindowSize(b){this.precompute(b)}toRawBytes(){return this.toBytes()}}p.BASE=new p(s.Gx,s.Gy,st,c(s.Gx*s.Gy)),p.ZERO=new p(he,st,st,he),p.Fp=n,p.Fn=o;let E=new Fe(p,o.BITS);return p.BASE.precompute(8),p}var sn=class{constructor(t){this.ep=t}static fromBytes(t){Go()}static fromHex(t){Go()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return Tt(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,r){return this.init(this.ep.precompute(t,r))}toRawBytes(){return this.toBytes()}};function zl(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');de(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:s,Fn:i}=e,a=r.randomBytes||qe,c=r.adjustScalarBytes||(w=>w),l=r.domain||((w,T,k)=>{if($t(k,"phflag"),T.length||k)throw new Error("Contexts/pre-hash are not supported");return w});function f(w){return i.create(Zt(w))}function d(w){let T=x.secretKey;w=F("private key",w,T);let k=F("hashed private key",t(w),2*T),R=c(k.slice(0,T)),g=k.slice(T,2*T),m=f(R);return{head:R,prefix:g,scalar:m}}function u(w){let{head:T,prefix:k,scalar:R}=d(w),g=o.multiply(R),m=g.toBytes();return{head:T,prefix:k,scalar:R,point:g,pointBytes:m}}function h(w){return u(w).pointBytes}function p(w=Uint8Array.of(),...T){let k=ht(...T);return f(t(l(k,F("context",w),!!n)))}function E(w,T,k={}){w=F("message",w),n&&(w=n(w));let{prefix:R,scalar:g,pointBytes:m}=u(T),y=p(k.context,R,w),S=o.multiply(y).toBytes(),I=p(k.context,S,m,w),D=i.create(y+I*g);if(!i.isValid(D))throw new Error("sign failed: invalid s");let _=ht(S,i.toBytes(D));return St(_,x.signature,"result")}let v={zip215:!0};function b(w,T,k,R=v){let{context:g,zip215:m}=R,y=x.signature;w=F("signature",w,y),T=F("message",T),k=F("publicKey",k,x.publicKey),m!==void 0&&$t(m,"zip215"),n&&(T=n(T));let S=y/2,I=w.subarray(0,S),D=Zt(w.subarray(S,y)),_,B,P;try{_=e.fromBytes(k,m),B=e.fromBytes(I,m),P=o.multiplyUnsafe(D)}catch{return!1}if(!m&&_.isSmallOrder())return!1;let K=p(g,B.toBytes(),_.toBytes(),T);return B.add(_.multiplyUnsafe(K)).subtract(P).clearCofactor().is0()}let A=s.BYTES,x={secretKey:A,publicKey:A,signature:2*A,seed:A};function C(w=a(x.seed)){return St(w,x.seed,"seed")}function L(w){let T=O.randomSecretKey(w);return{secretKey:T,publicKey:h(T)}}function M(w){return Ft(w)&&w.length===i.BYTES}function N(w,T){try{return!!e.fromBytes(w,T)}catch{return!1}}let O={getExtendedPublicKey:u,randomSecretKey:C,isValidSecretKey:M,isValidPublicKey:N,toMontgomery(w){let{y:T}=e.fromBytes(w),k=x.publicKey,R=k===32;if(!R&&k!==57)throw new Error("only defined for 25519 and 448");let g=R?s.div(st+T,st-T):s.div(T-st,T+st);return s.toBytes(g)},toMontgomeryPriv(w){let T=x.secretKey;St(w,T);let k=t(w.subarray(0,T));return c(k).subarray(0,T)},randomPrivateKey:C,precompute(w=8,T=e.BASE){return T.precompute(w,!1)}};return Object.freeze({keygen:L,getPublicKey:h,sign:E,verify:b,utils:O,Point:e,lengths:x})}function Fl(e){let t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=At(t.n,e.nBitLength,!0),o={Fp:r,Fn:n,uvRatio:e.uvRatio},s={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:o,hash:e.hash,eddsaOpts:s}}function Wl(e,t){let r=t.Point;return Object.assign({},t,{ExtendedPoint:r,CURVE:e,nBitLength:r.Fn.BITS,nByteLength:r.Fn.BYTES})}function Ca(e){let{CURVE:t,curveOpts:r,hash:n,eddsaOpts:o}=Fl(e),s=Hl(t,r),i=zl(s,n,o);return Wl(e,i)}var Gl=BigInt(0),Xt=BigInt(1),Ta=BigInt(2),um=BigInt(3),$l=BigInt(5),Zl=BigInt(8),Ge=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Er={p:Ge,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Zl,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function jl(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Ge,a=e*e%s*e%s,c=Z(a,Ta,s)*a%s,l=Z(c,Xt,s)*e%s,f=Z(l,$l,s)*l%s,d=Z(f,t,s)*f%s,u=Z(d,r,s)*d%s,h=Z(u,n,s)*u%s,p=Z(h,o,s)*h%s,E=Z(p,o,s)*h%s,v=Z(E,t,s)*f%s;return{pow_p_5_8:Z(v,Ta,s)*e%s,b2:a}}function Yl(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var es=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function os(e,t){let r=Ge,n=tt(t*t*t,r),o=tt(n*n*t,r),s=jl(e*o).pow_p_5_8,i=tt(e*n*s,r),a=tt(t*i*i,r),c=i,l=tt(i*es,r),f=a===e,d=a===tt(-e,r),u=a===tt(-e*es,r);return f&&(i=c),(d||u)&&(i=l),jt(i,r)&&(i=tt(-i,r)),{isValid:f||d,value:i}}var pe=At(Er.p,{isLE:!0}),Xl=At(Er.n,{isLE:!0}),Ql={...Er,Fp:pe,hash:aa,adjustScalarBytes:Yl,uvRatio:os},Qt=Ca(Ql);var rs=es,Jl=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),tf=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),ef=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),rf=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Ra=e=>os(Xt,e),nf=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),ns=e=>Qt.Point.Fp.create(Zt(e)&nf);function Da(e){let{d:t}=Er,r=Ge,n=b=>pe.create(b),o=n(rs*e*e),s=n((o+Xt)*ef),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:c,value:l}=os(s,a),f=n(l*e);jt(f,r)||(f=n(-f)),c||(l=f),c||(i=o);let d=n(i*(o-Xt)*rf-a),u=l*l,h=n((l+l)*a),p=n(d*Jl),E=n(Xt-u),v=n(Xt+u);return new Qt.Point(n(h*v),n(E*p),n(p*v),n(h*E))}function of(e){vt(e,64);let t=ns(e.subarray(0,32)),r=Da(t),n=ns(e.subarray(32,64)),o=Da(n);return new Jt(r.add(o))}var Jt=class e extends sn{constructor(t){super(t)}static fromAffine(t){return new e(Qt.Point.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static hashToCurve(t){return of(F("ristrettoHash",t,64))}static fromBytes(t){vt(t,32);let{a:r,d:n}=Er,o=Ge,s=C=>pe.create(C),i=ns(t);if(!ua(pe.toBytes(i),t)||jt(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(Xt+r*a),l=s(Xt-r*a),f=s(c*c),d=s(l*l),u=s(r*n*f-d),{isValid:h,value:p}=Ra(s(u*d)),E=s(p*l),v=s(p*E*u),b=s((i+i)*E);jt(b,o)&&(b=s(-b));let A=s(c*v),x=s(b*A);if(!h||jt(x,o)||A===Gl)throw new Error("invalid ristretto255 encoding 2");return new e(new Qt.Point(b,A,Xt,x))}static fromHex(t){return e.fromBytes(F("ristrettoHex",t,32))}static msm(t,r){return We(e,Qt.Point.Fn,t,r)}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=Ge,i=v=>pe.create(v),a=i(i(n+r)*i(n-r)),c=i(t*r),l=i(c*c),{value:f}=Ra(i(a*l)),d=i(f*a),u=i(f*c),h=i(d*u*o),p;if(jt(o*h,s)){let v=i(r*rs),b=i(t*rs);t=v,r=b,p=i(d*tf)}else p=u;jt(t*h,s)&&(r=i(-r));let E=i((n-r)*p);return jt(E,s)&&(E=i(-E)),pe.toBytes(E)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=l=>pe.create(l),a=i(r*s)===i(n*o),c=i(n*s)===i(r*o);return a||c}is0(){return this.equals(e.ZERO)}};Jt.BASE=new Jt(Qt.Point.BASE);Jt.ZERO=new Jt(Qt.Point.ZERO);Jt.Fp=pe;Jt.Fn=Xl;var vr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},an=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var La={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new an("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 Rt=La;var cn=32;var ss,sf=(async()=>{try{return await Rt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function af(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Rt.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Rt.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function cf(e,t,r){return Qt.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Pa(e,t,r){return ss==null&&(ss=await sf),ss?af(e,t,r):cf(e,t,r)}function un(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var ln=class{type="Ed25519";raw;constructor(t){this.raw=is(t,cn)}toMultihash(){return Pt.digest(Ct(this))}toCID(){return J.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:$(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Pa(this.raw,r,t);return un(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function as(e){return e=is(e,cn),new ln(e)}function is(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new q(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var lf=Math.pow(2,7),ff=Math.pow(2,14),df=Math.pow(2,21),cs=Math.pow(2,28),us=Math.pow(2,35),ls=Math.pow(2,42),fs=Math.pow(2,49),z=128,lt=127;function Dt(e){if(e<lf)return 1;if(e<ff)return 2;if(e<df)return 3;if(e<cs)return 4;if(e<us)return 5;if(e<ls)return 6;if(e<fs)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function $e(e,t,r=0){switch(Dt(e)){case 8:t[r++]=e&255|z,e/=128;case 7:t[r++]=e&255|z,e/=128;case 6:t[r++]=e&255|z,e/=128;case 5:t[r++]=e&255|z,e/=128;case 4:t[r++]=e&255|z,e>>>=7;case 3:t[r++]=e&255|z,e>>>=7;case 2:t[r++]=e&255|z,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function hf(e,t,r=0){switch(Dt(e)){case 8:t.set(r++,e&255|z),e/=128;case 7:t.set(r++,e&255|z),e/=128;case 6:t.set(r++,e&255|z),e/=128;case 5:t.set(r++,e&255|z),e/=128;case 4:t.set(r++,e&255|z),e>>>=7;case 3:t.set(r++,e&255|z),e>>>=7;case 2:t.set(r++,e&255|z),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function ds(e,t){let r=e[t],n=0;if(n+=r<,r<z||(r=e[t+1],n+=(r<)<<7,r<z)||(r=e[t+2],n+=(r<)<<14,r<z)||(r=e[t+3],n+=(r<)<<21,r<z)||(r=e[t+4],n+=(r<)*cs,r<z)||(r=e[t+5],n+=(r<)*us,r<z)||(r=e[t+6],n+=(r<)*ls,r<z)||(r=e[t+7],n+=(r<)*fs,r<z))return n;throw new RangeError("Could not decode varint")}function pf(e,t){let r=e.get(t),n=0;if(n+=r<,r<z||(r=e.get(t+1),n+=(r<)<<7,r<z)||(r=e.get(t+2),n+=(r<)<<14,r<z)||(r=e.get(t+3),n+=(r<)<<21,r<z)||(r=e.get(t+4),n+=(r<)*cs,r<z)||(r=e.get(t+5),n+=(r<)*us,r<z)||(r=e.get(t+6),n+=(r<)*ls,r<z)||(r=e.get(t+7),n+=(r<)*fs,r<z))return n;throw new RangeError("Could not decode varint")}function fn(e,t,r=0){return t==null&&(t=wt(Dt(e))),t instanceof Uint8Array?$e(e,t,r):hf(e,t,r)}function hs(e,t=0){return e instanceof Uint8Array?ds(e,t):pf(e,t)}var ps=new Float32Array([-0]),me=new Uint8Array(ps.buffer);function Ka(e,t,r){ps[0]=e,t[r]=me[0],t[r+1]=me[1],t[r+2]=me[2],t[r+3]=me[3]}function Ua(e,t){return me[0]=e[t],me[1]=e[t+1],me[2]=e[t+2],me[3]=e[t+3],ps[0]}var ms=new Float64Array([-0]),ft=new Uint8Array(ms.buffer);function Na(e,t,r){ms[0]=e,t[r]=ft[0],t[r+1]=ft[1],t[r+2]=ft[2],t[r+3]=ft[3],t[r+4]=ft[4],t[r+5]=ft[5],t[r+6]=ft[6],t[r+7]=ft[7]}function Ma(e,t){return ft[0]=e[t],ft[1]=e[t+1],ft[2]=e[t+2],ft[3]=e[t+3],ft[4]=e[t+4],ft[5]=e[t+5],ft[6]=e[t+6],ft[7]=e[t+7],ms[0]}var mf=BigInt(Number.MAX_SAFE_INTEGER),yf=BigInt(Number.MIN_SAFE_INTEGER),It=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+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 r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(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,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return Se;if(t<mf&&t>yf)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>qa&&(o=0n,++n>qa&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return Se;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):Se}},Se=new It(0,0);Se.toBigInt=function(){return 0n};Se.zzEncode=Se.zzDecode=function(){return this};Se.length=function(){return 1};var qa=4294967296n;function Va(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Ha(e,t,r){if(r-t<1)return"";let o,s=[],i=0,a;for(;t<r;)a=e[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(e[t++]&63)<<6|e[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 ys(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function kt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function dn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var bs=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,kt(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 kt(this,4);return dn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw kt(this,4);return dn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw kt(this,4);let t=Ua(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw kt(this,4);let t=Ma(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw kt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Ha(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw kt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw kt(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 It(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*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;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw kt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw kt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw kt(this,8);let t=dn(this.buf,this.pos+=4),r=dn(this.buf,this.pos+=4);return new It(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=ds(this.buf,this.pos);return this.pos+=Dt(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 gs(e){return new bs(e instanceof Uint8Array?e:e.subarray())}function mt(e,t,r){let n=gs(e);return t.decode(n,void 0,r)}function xs(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return wt(i);o+i>t&&(n=wt(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,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function ws(){}var vs=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},bf=xs();function gf(e){return globalThis.Buffer!=null?wt(e):bf(e)}var Ar=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ae(ws,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new Ae(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Ss((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(hn,10,It.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=It.fromBigInt(t);return this._push(hn,r.length(),r)}uint64Number(t){return this._push($e,Dt(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 r=It.fromBigInt(t).zzEncode();return this._push(hn,r.length(),r)}sint64Number(t){let r=It.fromNumber(t).zzEncode();return this._push(hn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Es,1,t?1:0)}fixed32(t){return this._push(Sr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=It.fromBigInt(t);return this._push(Sr,4,r.lo)._push(Sr,4,r.hi)}fixed64Number(t){let r=It.fromNumber(t);return this._push(Sr,4,r.lo)._push(Sr,4,r.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(Ka,4,t)}double(t){return this._push(Na,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Es,1,0):this.uint32(r)._push(wf,r,t)}string(t){let r=Va(t);return r!==0?this.uint32(r)._push(ys,r,t):this._push(Es,1,0)}fork(){return this.states=new vs(this),this.head=this.tail=new Ae(ws,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(ws,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=gf(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Es(e,t,r){t[r]=e&255}function xf(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Ss=class extends Ae{next;constructor(t,r){super(xf,t,r),this.next=void 0}};function hn(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function Sr(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function wf(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Ar.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Ef,t,e),this},Ar.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(vf,t,e),this});function Ef(e,t,r){t.set(e,r)}function vf(e,t,r){e.length<40?ys(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(V(e),r)}function As(){return new Ar}function yt(e,t){let r=As();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var Ze;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(Ze||(Ze={}));function pn(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function Is(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return pn("enum",Ze.VARINT,r,n)}function bt(e,t){return pn("message",Ze.LENGTH_DELIMITED,e,t)}var Ie=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"},Ir=class extends Error{code="ERR_MAX_SIZE";name="MaxSizeError"};var et;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(et||(et={}));var _s;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(_s||(_s={}));(function(e){e.codec=()=>Is(_s)})(et||(et={}));var Nt;(function(e){let t;e.codec=()=>(t==null&&(t=bt((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),et.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.Type=et.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>yt(r,e.codec()),e.decode=(r,n)=>mt(r,e.codec(),n)})(Nt||(Nt={}));var Bs;(function(e){let t;e.codec=()=>(t==null&&(t=bt((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),et.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.Type=et.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>yt(r,e.codec()),e.decode=(r,n)=>mt(r,e.codec(),n)})(Bs||(Bs={}));var Br={};xt(Br,{MAX_RSA_KEY_SIZE:()=>Cs,generateRSAKeyPair:()=>Za,jwkToJWKKeyPair:()=>ja,jwkToPkcs1:()=>_f,jwkToPkix:()=>Ls,jwkToRSAPrivateKey:()=>Ks,pkcs1MessageToJwk:()=>Rs,pkcs1MessageToRSAPrivateKey:()=>Ps,pkcs1ToJwk:()=>If,pkcs1ToRSAPrivateKey:()=>$a,pkixMessageToJwk:()=>Ds,pkixMessageToRSAPublicKey:()=>ks,pkixToJwk:()=>Bf,pkixToRSAPublicKey:()=>Os});var mn=tn;var je=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Br.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return J.createV1(114,this._multihash)}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:$(this.raw,t.raw)}verify(t,r,n){return Ga(this.jwk,r,t,n)}},_r=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Br.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:$(this.raw,t.raw)}sign(t,r){return Wa(this.jwk,t,r)}};var Cs=8192,Ts=18,Sf=1062,Af=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function If(e){let t=Ht(e);return Rs(t)}function Rs(e){return{n:U(e[1],"base64url"),e:U(e[2],"base64url"),d:U(e[3],"base64url"),p:U(e[4],"base64url"),q:U(e[5],"base64url"),dp:U(e[6],"base64url"),dq:U(e[7],"base64url"),qi:U(e[8],"base64url"),kty:"RSA"}}function _f(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new q("JWK was missing components");return ae([Et(Uint8Array.from([0])),Et(V(e.n,"base64url")),Et(V(e.e,"base64url")),Et(V(e.d,"base64url")),Et(V(e.p,"base64url")),Et(V(e.q,"base64url")),Et(V(e.dp,"base64url")),Et(V(e.dq,"base64url")),Et(V(e.qi,"base64url"))]).subarray()}function Bf(e){let t=Ht(e,{offset:0});return Ds(t)}function Ds(e){let t=Ht(e[1],{offset:0});return{kty:"RSA",n:U(t[0],"base64url"),e:U(t[1],"base64url")}}function Ls(e){if(e.n==null||e.e==null)throw new q("JWK was missing components");return ae([Af,jr(ae([Et(V(e.n,"base64url")),Et(V(e.e,"base64url"))]))]).subarray()}function $a(e){let t=Ht(e);return Ps(t)}function Ps(e){let t=Rs(e);return Ks(t)}function Os(e,t){if(e.byteLength>=Sf)throw new Re("Key size is too large");let r=Ht(e,{offset:0});return ks(r,e,t)}function ks(e,t,r){let n=Ds(e);if(r==null){let o=mn(Nt.encode({Type:et.RSA,Data:t}));r=Lt(Ts,o)}return new je(n,r)}function Ks(e){if(Xa(e)>Cs)throw new q("Key size is too large");let t=ja(e),r=mn(Nt.encode({Type:et.RSA,Data:Ls(t.publicKey)})),n=Lt(Ts,r);return new _r(t.privateKey,new je(t.publicKey,n))}async function Za(e){if(e>Cs)throw new q("Key size is too large");let t=await Ya(e),r=mn(Nt.encode({Type:et.RSA,Data:Ls(t.publicKey)})),n=Lt(Ts,r);return new _r(t.privateKey,new je(t.publicKey,n))}function ja(e){if(e==null)throw new q("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function Ya(e,t){let r=await Rt.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await Cf(r,t);return{privateKey:n[0],publicKey:n[1]}}async function Wa(e,t,r){let n=await Rt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Rt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Ga(e,t,r,n){let o=await Rt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Rt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function Cf(e,t){if(e.privateKey==null||e.publicKey==null)throw new q("Private and public key are required");let r=await Promise.all([Rt.get().subtle.exportKey("jwk",e.privateKey),Rt.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function Xa(e){if(e.kty!=="RSA")throw new q("invalid key type");if(e.n==null)throw new q("invalid key modulus");return V(e.n,"base64url").length*8}var yn=class extends Ne{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,Yr(t);let n=hr(r);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),Wt(s)}update(t){return Me(this),this.iHash.update(t),this}digestInto(t){Me(this),vt(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:r,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=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Us=(e,t,r)=>new yn(e,t).update(r).digest();Us.create=(e,t)=>new yn(e,t);var Qa=(e,t)=>(e+(e>=0?t:-t)/Ja)/t;function Tf(e,t,r){let[[n,o],[s,i]]=t,a=Qa(i*e,r),c=Qa(-o*e,r),l=e-a*n-c*s,f=-a*o-c*i,d=l<ee,u=f<ee;d&&(l=-l),u&&(f=-f);let h=fe(Math.ceil(rn(r)/2))+Xe;if(l<ee||l>=h||f<ee||f>=h)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:d,k1:l,k2neg:u,k2:f}}function Ms(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Ns(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return $t(r.lowS,"lowS"),$t(r.prehash,"prehash"),r.format!==void 0&&Ms(r.format),r}var qs=class extends Error{constructor(t=""){super(t)}},te={Err:qs,_tlv:{encode:(e,t)=>{let{Err:r}=te;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=br(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?br(o.length/2|128):"";return br(e)+s+o+t},decode(e,t){let{Err:r}=te,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("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 r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let l=t.subarray(n,n+c);if(l.length!==c)throw new r("tlv.decode: length bytes not complete");if(l[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of l)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=te;if(e<ee)throw new t("integer: negative integers are not allowed");let r=br(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=te;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Ve(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=te,o=F("signature",e),{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:f}=n.decode(2,c);if(f.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(l)}},hexFromSig(e){let{_tlv:t,_int:r}=te,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},ee=BigInt(0),Xe=BigInt(1),Ja=BigInt(2),bn=BigInt(3),Rf=BigInt(4);function Ye(e,t){let{BYTES:r}=e,n;if(typeof t=="bigint")n=t;else{let o=F("private key",t);try{n=e.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof t}`)}}if(!e.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function Df(e,t={}){let r=on("weierstrass",e,t),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:a}=s;de(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:c}=t;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let l=ec(n,o);function f(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function d(R,g,m){let{x:y,y:S}=g.toAffine(),I=n.toBytes(y);if($t(m,"isCompressed"),m){f();let D=!n.isOdd(S);return ht(tc(D),I)}else return ht(Uint8Array.of(4),I,n.toBytes(S))}function u(R){St(R,void 0,"Point");let{publicKey:g,publicKeyUncompressed:m}=l,y=R.length,S=R[0],I=R.subarray(1);if(y===g&&(S===2||S===3)){let D=n.fromBytes(I);if(!n.isValid(D))throw new Error("bad point: is not on curve, wrong x");let _=E(D),B;try{B=n.sqrt(_)}catch(j){let W=j instanceof Error?": "+j.message:"";throw new Error("bad point: is not on curve, sqrt error"+W)}f();let P=n.isOdd(B);return(S&1)===1!==P&&(B=n.neg(B)),{x:D,y:B}}else if(y===m&&S===4){let D=n.BYTES,_=n.fromBytes(I.subarray(0,D)),B=n.fromBytes(I.subarray(D,D*2));if(!v(_,B))throw new Error("bad point: is not on curve");return{x:_,y:B}}else throw new Error(`bad point: got length ${y}, expected compressed=${g} or uncompressed=${m}`)}let h=t.toBytes||d,p=t.fromBytes||u;function E(R){let g=n.sqr(R),m=n.mul(g,R);return n.add(n.add(m,n.mul(R,s.a)),s.b)}function v(R,g){let m=n.sqr(g),y=E(R);return n.eql(m,y)}if(!v(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let b=n.mul(n.pow(s.a,bn),Rf),A=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(b,A)))throw new Error("bad curve params: a or b");function x(R,g,m=!1){if(!n.isValid(g)||m&&n.is0(g))throw new Error(`bad point coordinate ${R}`);return g}function C(R){if(!(R instanceof w))throw new Error("ProjectivePoint expected")}function L(R){if(!c||!c.basises)throw new Error("no endo");return Tf(R,c.basises,o.ORDER)}let M=He((R,g)=>{let{X:m,Y:y,Z:S}=R;if(n.eql(S,n.ONE))return{x:m,y};let I=R.is0();g==null&&(g=I?n.ONE:n.inv(S));let D=n.mul(m,g),_=n.mul(y,g),B=n.mul(S,g);if(I)return{x:n.ZERO,y:n.ZERO};if(!n.eql(B,n.ONE))throw new Error("invZ was invalid");return{x:D,y:_}}),N=He(R=>{if(R.is0()){if(t.allowInfinityPoint&&!n.is0(R.Y))return;throw new Error("bad point: ZERO")}let{x:g,y:m}=R.toAffine();if(!n.isValid(g)||!n.isValid(m))throw new Error("bad point: x or y not field elements");if(!v(g,m))throw new Error("bad point: equation left != right");if(!R.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function O(R,g,m,y,S){return m=new w(n.mul(m.X,R),m.Y,m.Z),g=wr(y,g),m=wr(S,m),g.add(m)}class w{constructor(g,m,y){this.X=x("x",g),this.Y=x("y",m,!0),this.Z=x("z",y),Object.freeze(this)}static CURVE(){return s}static fromAffine(g){let{x:m,y}=g||{};if(!g||!n.isValid(m)||!n.isValid(y))throw new Error("invalid affine point");if(g instanceof w)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(y)?w.ZERO:new w(m,y,n.ONE)}static fromBytes(g){let m=w.fromAffine(p(St(g,void 0,"point")));return m.assertValidity(),m}static fromHex(g){return w.fromBytes(F("pointHex",g))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,m=!0){return k.createCache(this,g),m||this.multiply(bn),this}assertValidity(){N(this)}hasEvenY(){let{y:g}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(g)}equals(g){C(g);let{X:m,Y:y,Z:S}=this,{X:I,Y:D,Z:_}=g,B=n.eql(n.mul(m,_),n.mul(I,S)),P=n.eql(n.mul(y,_),n.mul(D,S));return B&&P}negate(){return new w(this.X,n.neg(this.Y),this.Z)}double(){let{a:g,b:m}=s,y=n.mul(m,bn),{X:S,Y:I,Z:D}=this,_=n.ZERO,B=n.ZERO,P=n.ZERO,K=n.mul(S,S),j=n.mul(I,I),W=n.mul(D,D),H=n.mul(S,I);return H=n.add(H,H),P=n.mul(S,D),P=n.add(P,P),_=n.mul(g,P),B=n.mul(y,W),B=n.add(_,B),_=n.sub(j,B),B=n.add(j,B),B=n.mul(_,B),_=n.mul(H,_),P=n.mul(y,P),W=n.mul(g,W),H=n.sub(K,W),H=n.mul(g,H),H=n.add(H,P),P=n.add(K,K),K=n.add(P,K),K=n.add(K,W),K=n.mul(K,H),B=n.add(B,K),W=n.mul(I,D),W=n.add(W,W),K=n.mul(W,H),_=n.sub(_,K),P=n.mul(W,j),P=n.add(P,P),P=n.add(P,P),new w(_,B,P)}add(g){C(g);let{X:m,Y:y,Z:S}=this,{X:I,Y:D,Z:_}=g,B=n.ZERO,P=n.ZERO,K=n.ZERO,j=s.a,W=n.mul(s.b,bn),H=n.mul(m,I),Y=n.mul(y,D),nt=n.mul(S,_),gt=n.add(m,y),X=n.add(I,D);gt=n.mul(gt,X),X=n.add(H,Y),gt=n.sub(gt,X),X=n.add(m,S);let ut=n.add(I,_);return X=n.mul(X,ut),ut=n.add(H,nt),X=n.sub(X,ut),ut=n.add(y,S),B=n.add(D,_),ut=n.mul(ut,B),B=n.add(Y,nt),ut=n.sub(ut,B),K=n.mul(j,X),B=n.mul(W,nt),K=n.add(B,K),B=n.sub(Y,K),K=n.add(Y,K),P=n.mul(B,K),Y=n.add(H,H),Y=n.add(Y,H),nt=n.mul(j,nt),X=n.mul(W,X),Y=n.add(Y,nt),nt=n.sub(H,nt),nt=n.mul(j,nt),X=n.add(X,nt),H=n.mul(Y,X),P=n.add(P,H),H=n.mul(ut,X),B=n.mul(gt,B),B=n.sub(B,H),H=n.mul(gt,Y),K=n.mul(ut,K),K=n.add(K,H),new w(B,P,K)}subtract(g){return this.add(g.negate())}is0(){return this.equals(w.ZERO)}multiply(g){let{endo:m}=t;if(!o.isValidNot0(g))throw new Error("invalid scalar: out of range");let y,S,I=D=>k.cached(this,D,_=>Yt(w,_));if(m){let{k1neg:D,k1:_,k2neg:B,k2:P}=L(g),{p:K,f:j}=I(_),{p:W,f:H}=I(P);S=j.add(H),y=O(m.beta,K,W,D,B)}else{let{p:D,f:_}=I(g);y=D,S=_}return Yt(w,[y,S])[0]}multiplyUnsafe(g){let{endo:m}=t,y=this;if(!o.isValid(g))throw new Error("invalid scalar: out of range");if(g===ee||y.is0())return w.ZERO;if(g===Xe)return y;if(k.hasCache(this))return this.multiply(g);if(m){let{k1neg:S,k1:I,k2neg:D,k2:_}=L(g),{p1:B,p2:P}=Ba(w,y,I,_);return O(m.beta,B,P,S,D)}else return k.unsafe(y,g)}multiplyAndAddUnsafe(g,m,y){let S=this.multiplyUnsafe(m).add(g.multiplyUnsafe(y));return S.is0()?void 0:S}toAffine(g){return M(this,g)}isTorsionFree(){let{isTorsionFree:g}=t;return i===Xe?!0:g?g(w,this):k.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:g}=t;return i===Xe?this:g?g(w,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(g=!0){return $t(g,"isCompressed"),this.assertValidity(),h(w,this,g)}toHex(g=!0){return Tt(this.toBytes(g))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(g=!0){return this.toBytes(g)}_setWindowSize(g){this.precompute(g)}static normalizeZ(g){return Yt(w,g)}static msm(g,m){return We(w,o,g,m)}static fromPrivateKey(g){return w.BASE.multiply(Ye(o,g))}}w.BASE=new w(s.Gx,s.Gy,n.ONE),w.ZERO=new w(n.ZERO,n.ONE,n.ZERO),w.Fp=n,w.Fn=o;let T=o.BITS,k=new Fe(w,t.endo?Math.ceil(T/2):T);return w.BASE.precompute(8),w}function tc(e){return Uint8Array.of(e?2:3)}function ec(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Lf(e,t={}){let{Fn:r}=e,n=t.randomBytes||qe,o=Object.assign(ec(e.Fp,r),{seed:jo(r.ORDER)});function s(h){try{return!!Ye(r,h)}catch{return!1}}function i(h,p){let{publicKey:E,publicKeyUncompressed:v}=o;try{let b=h.length;return p===!0&&b!==E||p===!1&&b!==v?!1:!!e.fromBytes(h)}catch{return!1}}function a(h=n(o.seed)){return Yo(St(h,o.seed,"seed"),r.ORDER)}function c(h,p=!0){return e.BASE.multiply(Ye(r,h)).toBytes(p)}function l(h){let p=a(h);return{secretKey:p,publicKey:c(p)}}function f(h){if(typeof h=="bigint")return!1;if(h instanceof e)return!0;let{secretKey:p,publicKey:E,publicKeyUncompressed:v}=o;if(r.allowedLengths||p===E)return;let b=F("key",h).length;return b===E||b===v}function d(h,p,E=!0){if(f(h)===!0)throw new Error("first arg must be private key");if(f(p)===!1)throw new Error("second arg must be public key");let v=Ye(r,h);return e.fromHex(p).multiply(v).toBytes(E)}return Object.freeze({getPublicKey:c,getSharedSecret:d,keygen:l,Point:e,utils:{isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a,isValidPrivateKey:s,randomPrivateKey:a,normPrivateKeyToScalar:h=>Ye(r,h),precompute(h=8,p=e.BASE){return p.precompute(h,!1)}},lengths:o})}function Pf(e,t,r={}){Yr(t),de(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||qe,o=r.hmac||((m,...y)=>Us(t,m,ht(...y))),{Fp:s,Fn:i}=e,{ORDER:a,BITS:c}=i,{keygen:l,getPublicKey:f,getSharedSecret:d,utils:u,lengths:h}=Lf(e,r),p={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},E="compact";function v(m){let y=a>>Xe;return m>y}function b(m,y){if(!i.isValidNot0(y))throw new Error(`invalid signature ${m}: out of range 1..Point.Fn.ORDER`);return y}function A(m,y){Ms(y);let S=h.signature,I=y==="compact"?S:y==="recovered"?S+1:void 0;return St(m,I,`${y} signature`)}class x{constructor(y,S,I){this.r=b("r",y),this.s=b("s",S),I!=null&&(this.recovery=I),Object.freeze(this)}static fromBytes(y,S=E){A(y,S);let I;if(S==="der"){let{r:P,s:K}=te.toSig(St(y));return new x(P,K)}S==="recovered"&&(I=y[0],S="compact",y=y.subarray(1));let D=i.BYTES,_=y.subarray(0,D),B=y.subarray(D,D*2);return new x(i.fromBytes(_),i.fromBytes(B),I)}static fromHex(y,S){return this.fromBytes(ge(y),S)}addRecoveryBit(y){return new x(this.r,this.s,y)}recoverPublicKey(y){let S=s.ORDER,{r:I,s:D,recovery:_}=this;if(_==null||![0,1,2,3].includes(_))throw new Error("recovery id invalid");if(a*Ja<S&&_>1)throw new Error("recovery id is ambiguous for h>1 curve");let P=_===2||_===3?I+a:I;if(!s.isValid(P))throw new Error("recovery id 2 or 3 invalid");let K=s.toBytes(P),j=e.fromBytes(ht(tc((_&1)===0),K)),W=i.inv(P),H=L(F("msgHash",y)),Y=i.create(-H*W),nt=i.create(D*W),gt=e.BASE.multiplyUnsafe(Y).add(j.multiplyUnsafe(nt));if(gt.is0())throw new Error("point at infinify");return gt.assertValidity(),gt}hasHighS(){return v(this.s)}toBytes(y=E){if(Ms(y),y==="der")return ge(te.hexFromSig(this));let S=i.toBytes(this.r),I=i.toBytes(this.s);if(y==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return ht(Uint8Array.of(this.recovery),S,I)}return ht(S,I)}toHex(y){return Tt(this.toBytes(y))}assertValidity(){}static fromCompact(y){return x.fromBytes(F("sig",y),"compact")}static fromDER(y){return x.fromBytes(F("sig",y),"der")}normalizeS(){return this.hasHighS()?new x(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Tt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Tt(this.toBytes("compact"))}}let C=r.bits2int||function(y){if(y.length>8192)throw new Error("input is too large");let S=Ve(y),I=y.length*8-c;return I>0?S>>BigInt(I):S},L=r.bits2int_modN||function(y){return i.create(C(y))},M=fe(c);function N(m){return gr("num < 2^"+c,m,ee,M),i.toBytes(m)}function O(m,y){return St(m,void 0,"message"),y?St(t(m),void 0,"prehashed message"):m}function w(m,y,S){if(["recovered","canonical"].some(Y=>Y in S))throw new Error("sign() legacy options not supported");let{lowS:I,prehash:D,extraEntropy:_}=Ns(S,p);m=O(m,D);let B=L(m),P=Ye(i,y),K=[N(P),N(B)];if(_!=null&&_!==!1){let Y=_===!0?n(h.secretKey):_;K.push(F("extraEntropy",Y))}let j=ht(...K),W=B;function H(Y){let nt=C(Y);if(!i.isValidNot0(nt))return;let gt=i.inv(nt),X=e.BASE.multiply(nt).toAffine(),ut=i.create(X.x);if(ut===ee)return;let Hr=i.create(gt*i.create(W+ut*P));if(Hr===ee)return;let xi=(X.x===ut?0:2)|Number(X.y&Xe),wi=Hr;return I&&v(Hr)&&(wi=i.neg(Hr),xi^=1),new x(ut,wi,xi)}return{seed:j,k2sig:H}}function T(m,y,S={}){m=F("message",m);let{seed:I,k2sig:D}=w(m,y,S);return fa(t.outputLen,i.BYTES,o)(I,D)}function k(m){let y,S=typeof m=="string"||Ft(m),I=!S&&m!==null&&typeof m=="object"&&typeof m.r=="bigint"&&typeof m.s=="bigint";if(!S&&!I)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(I)y=new x(m.r,m.s);else if(S){try{y=x.fromBytes(F("sig",m),"der")}catch(D){if(!(D instanceof te.Err))throw D}if(!y)try{y=x.fromBytes(F("sig",m),"compact")}catch{return!1}}return y||!1}function R(m,y,S,I={}){let{lowS:D,prehash:_,format:B}=Ns(I,p);if(S=F("publicKey",S),y=O(F("message",y),_),"strict"in I)throw new Error("options.strict was renamed to lowS");let P=B===void 0?k(m):x.fromBytes(F("sig",m),B);if(P===!1)return!1;try{let K=e.fromBytes(S);if(D&&P.hasHighS())return!1;let{r:j,s:W}=P,H=L(y),Y=i.inv(W),nt=i.create(H*Y),gt=i.create(j*Y),X=e.BASE.multiplyUnsafe(nt).add(K.multiplyUnsafe(gt));return X.is0()?!1:i.create(X.x)===j}catch{return!1}}function g(m,y,S={}){let{prehash:I}=Ns(S,p);return y=O(y,I),x.fromBytes(m,"recovered").recoverPublicKey(y).toBytes()}return Object.freeze({keygen:l,getPublicKey:f,getSharedSecret:d,utils:u,lengths:h,Point:e,sign:T,verify:R,recoverPublicKey:g,Signature:x,hash:t})}function Of(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,o=At(t.n,{BITS:e.nBitLength,allowedLengths:n,modFromBytes:e.wrapPrivateKey}),s={Fp:r,Fn:o,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:s}}function kf(e){let{CURVE:t,curveOpts:r}=Of(e),n={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,hash:e.hash,ecdsaOpts:n}}function Kf(e,t){let r=t.Point;return Object.assign({},t,{ProjectivePoint:r,CURVE:Object.assign({},e,nn(r.Fn.ORDER,r.Fn.BITS))})}function rc(e){let{CURVE:t,curveOpts:r,hash:n,ecdsaOpts:o}=kf(e),s=Df(t,r),i=Pf(s,n,o);return Kf(e,i)}function nc(e,t){let r=n=>rc({...e,hash:n});return{...r(t),create:r}}var Hs={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Uf={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var oc=BigInt(2);function Nf(e){let t=Hs.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),l=e*e*e%t,f=l*l*e%t,d=Z(f,r,t)*f%t,u=Z(d,r,t)*f%t,h=Z(u,oc,t)*l%t,p=Z(h,o,t)*h%t,E=Z(p,s,t)*p%t,v=Z(E,a,t)*E%t,b=Z(v,c,t)*v%t,A=Z(b,a,t)*E%t,x=Z(A,r,t)*f%t,C=Z(x,i,t)*p%t,L=Z(C,n,t)*l%t,M=Z(L,oc,t);if(!Vs.eql(Vs.sqr(M),e))throw new Error("Cannot find square root");return M}var Vs=At(Hs.p,{sqrt:Nf}),Qe=nc({...Hs,Fp:Vs,lowS:!0,endo:Uf},tn);function sc(e,t,r,n){let o=cr.digest(r instanceof Uint8Array?r:r.subarray());if(un(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Qe.verify(t,s,e))).catch(s=>{throw s.name==="AbortError"?s:new vr(String(s))});try{return n?.signal?.throwIfAborted(),Qe.verify(t,o.digest,e)}catch(s){throw new vr(String(s))}}var gn=class{type="secp256k1";raw;_key;constructor(t){this._key=ac(t),this.raw=ic(this._key)}toMultihash(){return Pt.digest(Ct(this))}toCID(){return J.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:$(this.raw,t.raw)}verify(t,r,n){return sc(this._key,r,t,n)}};function zs(e){return new gn(e)}function ic(e){return Qe.ProjectivePoint.fromHex(e).toRawBytes(!0)}function ac(e){try{return Qe.ProjectivePoint.fromHex(e),e}catch(t){throw new Re(String(t))}}function xn(e,t){let{Type:r,Data:n}=Nt.decode(e),o=n??new Uint8Array;switch(r){case et.RSA:return Os(o,t);case et.Ed25519:return as(o);case et.secp256k1:return zs(o);case et.ECDSA:return ko(o);default:throw new ye}}function cc(e){let{Type:t,Data:r}=Nt.decode(e.digest),n=r??new Uint8Array;switch(t){case et.Ed25519:return as(n);case et.secp256k1:return zs(n);case et.ECDSA:return ko(n);default:throw new ye}}function Ct(e){return Nt.encode({Type:et[e.type],Data:e.raw})}var uc=Symbol.for("nodejs.util.inspect.custom"),Mf=114,Cr=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()})`}[zr]=!0;toString(){return this.string==null&&(this.string=G.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return J.createV1(Mf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return $(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return $(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[uc](){return`PeerId(${this.toString()})`}},Tr=class extends Cr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Rr=class extends Cr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Dr=class extends Cr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},qf=2336,Lr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Pt.digest(V(this.url))}[uc](){return`PeerId(${this.url})`}[zr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return J.createV1(qf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=U(t)),t.toString()===this.toString())}};var Vf=114,lc=2336;function fc(e){if(e.type==="Ed25519")return new Rr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new Dr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new Tr({multihash:e.toCID().multihash,publicKey:e});throw new ye}function Fs(e){if(zf(e))return new Tr({multihash:e});if(Hf(e))try{let t=cc(e);if(t.type==="Ed25519")return new Rr({multihash:e,publicKey:t});if(t.type==="secp256k1")return new Dr({multihash:e,publicKey:t})}catch{let r=U(e.digest);return new Lr(new URL(r))}throw new Wr("Supplied PeerID Multihash is invalid")}function wn(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==Vf&&e.code!==lc)throw new Fr("Supplied PeerID CID is invalid");if(e.code===lc){let t=U(e.multihash.digest);return new Lr(new URL(t))}return Fs(e.multihash)}function Hf(e){return e.code===Pt.code}function zf(e){return e.code===cr.code}var Pr;(function(e){let t;e.codec=()=>(t==null&&(t=bt((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.publicKey!=null&&r.publicKey.byteLength>0&&(n.uint32(10),n.bytes(r.publicKey)),r.payloadType!=null&&r.payloadType.byteLength>0&&(n.uint32(18),n.bytes(r.payloadType)),r.payload!=null&&r.payload.byteLength>0&&(n.uint32(26),n.bytes(r.payload)),r.signature!=null&&r.signature.byteLength>0&&(n.uint32(42),n.bytes(r.signature)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={publicKey:rt(0),payloadType:rt(0),payload:rt(0),signature:rt(0)},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.publicKey=r.bytes();break}case 2:{s.payloadType=r.bytes();break}case 3:{s.payload=r.bytes();break}case 5:{s.signature=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>yt(r,e.codec()),e.decode=(r,n)=>mt(r,e.codec(),n)})(Pr||(Pr={}));var En=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var Je=class e{static createFromProtobuf=t=>{let r=Pr.decode(t),n=xn(r.publicKey);return new e({publicKey:n,payloadType:r.payloadType,payload:r.payload,signature:r.signature})};static seal=async(t,r,n)=>{if(r==null)throw new Error("Missing private key");let o=t.domain,s=t.codec,i=t.marshal(),a=dc(o,s,i),c=await r.sign(a.subarray(),n);return new e({publicKey:r.publicKey,payloadType:s,payload:i,signature:c})};static openAndCertify=async(t,r,n)=>{let o=e.createFromProtobuf(t);if(!await o.validate(r,n))throw new En("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(t){let{publicKey:r,payloadType:n,payload:o,signature:s}=t;this.publicKey=r,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=Pr.encode({publicKey:Ct(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return t==null?!1:$(this.marshal(),t.marshal())}async validate(t,r){let n=dc(t,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},dc=(e,t,r)=>{let n=V(e),o=fn(n.byteLength),s=fn(t.length),i=fn(r.length);return new dt(o,n,s,t,i,r)};function hc(e,t){let r=(n,o)=>n.toString().localeCompare(o.toString());return e.length!==t.length?!1:(t.sort(r),e.sort(r).every((n,o)=>t[o].equals(n)))}var ct=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},re=class extends Error{static name="ValidationError";name="ValidationError"},Or=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},vn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var Sn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let r=this.index,n=t();return n===void 0&&(this.index=r),n}parseWith(t){let r=t();if(this.index===this.input.length)return r}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 r=this.readChar();if(r===t)return r})}readSeparator(t,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,r,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 f=this.readAtomically(()=>{let d=this.readChar();if(d===void 0)return;let u=Number.parseInt(d,t);if(!Number.isNaN(u))return u});if(f===void 0)break;if(s*=t,s+=f,s>l||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let r=0;r<t.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[r]=n}return t})}readIPv6Addr(){let t=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[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];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=t(r);if(n===16)return r;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 r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Ff=45,Wf=15,An=new Sn;function Ws(e){if(!(e.length>Wf))return An.new(e).parseWith(()=>An.readIPv4Addr())}function Gs(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>Ff))return An.new(e).parseWith(()=>An.readIPv6Addr())}function In(e){return!!Ws(e)}function mc(e){return!!Gs(e)}function Zs(e){return t=>U(t,e)}function js(e){return t=>V(t,e)}function tr(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function _e(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function yc(e){let t=e.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 r=V(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=_e(n);return Vt([r,o],r.length+o.length)}function bc(e){let t=e.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 r=Kt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=_e(n);return Vt([r,o],r.length+o.length)}function Ys(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=U(t,"base32"),o=tr(r);return`${n}:${o}`}var Xs=function(e){e=e.toString().trim();let t=new Uint8Array(4);return e.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new ct("Invalid byte value in IP address");t[n]=o}),t},gc=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let s=In(r[n]),i;s&&(i=Xs(r[n]),r[n]=U(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,U(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(t+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new ct("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},xc=function(e){if(e.byteLength!==4)throw new ct("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},wc=function(e){if(e.byteLength!==16)throw new ct("IPv6 address was incorrect length");let t=[];for(let n=0;n<e.byteLength;n+=2){let o=e[n],s=e[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let r=t.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new ct(`Invalid IPv6 address "${r}"`)}};function Ec(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new ct(`Invalid IPv6 address "${e}"`)}}var $s=Object.values(ur).map(e=>e.decoder),Gf=function(){let e=$s[0].or($s[1]);return $s.slice(2).forEach(t=>e=e.or(t)),e}();function vc(e){return Gf.decode(e)}function Sc(e){return t=>e.encoder.encode(t)}function $f(e){if(parseInt(e).toString()!==e)throw new re("Value must be an integer")}function Zf(e){if(e<0)throw new re("Value must be a positive integer, or zero")}function jf(e){return t=>{if(t>e)throw new re(`Value must be smaller than or equal to ${e}`)}}function Yf(...e){return t=>{for(let r of e)r(t)}}var kr=Yf($f,Zf,jf(65535));var it=-1,Qs=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let r;if(typeof t=="string"?r=this.protocolsByName.get(t):r=this.protocolsByCode.get(t),r==null)throw new vn(`Protocol ${t} was unknown`);return r}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(r=>{this.protocolsByName.set(r,t)})}removeProtocol(t){let r=this.protocolsByCode.get(t);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},_t=new Qs,_d=[{code:4,name:"ip4",size:32,valueToBytes:Xs,bytesToValue:xc,validate:e=>{if(!In(e))throw new re(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:_e,bytesToValue:tr,validate:kr},{code:273,name:"udp",size:16,valueToBytes:_e,bytesToValue:tr,validate:kr},{code:33,name:"dccp",size:16,valueToBytes:_e,bytesToValue:tr,validate:kr},{code:41,name:"ip6",size:128,valueToBytes:gc,bytesToValue:wc,stringToValue:Ec,validate:e=>{if(!mc(e))throw new re(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:it},{code:43,name:"ipcidr",size:8,bytesToValue:Zs("base10"),valueToBytes:js("base10")},{code:53,name:"dns",size:it,resolvable:!0},{code:54,name:"dns4",size:it,resolvable:!0},{code:55,name:"dns6",size:it,resolvable:!0},{code:56,name:"dnsaddr",size:it,resolvable:!0},{code:132,name:"sctp",size:16,valueToBytes:_e,bytesToValue:tr,validate:kr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:it,path:!0,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:it,bytesToValue:Zs("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?js("base58btc")(e):J.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Ys,valueToBytes:yc},{code:445,name:"onion3",size:296,bytesToValue:Ys,valueToBytes:bc},{code:446,name:"garlic64",size:it},{code:447,name:"garlic32",size:it},{code:448,name:"tls"},{code:449,name:"sni",size:it},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:it,bytesToValue:Sc(vo),valueToBytes:vc},{code:480,name:"http"},{code:481,name:"http-path",size:it,stringToValue:e=>`/${decodeURIComponent(e)}`,valueToString:e=>encodeURIComponent(e.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:it}];_d.forEach(e=>{_t.addProtocol(e)});function Ac(e){let t=[],r=0;for(;r<e.length;){let n=hs(e,r),o=_t.getProtocol(n),s=Dt(n),i=Bd(o,e,r+s),a=0;i>0&&o.size===it&&(a=Dt(i));let c=s+a+i,l={code:n,name:o.name,bytes:e.subarray(r,r+c)};if(i>0){let f=r+s+a,d=e.subarray(f,f+i);l.value=o.bytesToValue?.(d)??U(d)}t.push(l),r+=c}return t}function Ic(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=_t.getProtocol(n.code),s=Dt(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??V(n.value),a=i.byteLength,o.size===it&&(c=Dt(a)));let l=new Uint8Array(s+c+a),f=0;$e(n.code,l,f),f+=s,i!=null&&(o.size===it&&($e(a,l,f),f+=c),l.set(i,f)),n.bytes=l}r.push(n.bytes),t+=n.bytes.byteLength}return Vt(r,t)}function _c(e){if(e.charAt(0)!=="/")throw new ct('String multiaddr must start with "/"');let t=[],r="protocol",n="",o="";for(let s=1;s<e.length;s++){let i=e.charAt(s);i!=="/"&&(r==="protocol"?o+=e.charAt(s):n+=e.charAt(s));let a=s===e.length-1;if(i==="/"||a){let c=_t.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new ct(`Component ${o} was missing value`);r="value"}else if(r==="value"){let l={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new ct(`Component ${o} was missing value`);l.value=c.stringToValue?.(n)??n}t.push(l),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new ct("Incomplete multiaddr");return t}function Bc(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=_t.getProtocol(t.code);if(r==null)throw new ct(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function Bd(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:hs(t,r)}var Cd=Symbol.for("nodejs.util.inspect.custom"),ii=Symbol.for("@multiformats/multiaddr"),Td=[53,54,55,56],si=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}};function Rd(e){if(e==null&&(e="/"),Dn(e))return e.getComponents();if(e instanceof Uint8Array)return Ac(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),_c(e);if(Array.isArray(e))return e;throw new ct("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Rn=class e{[ii]=!0;#t;#e;#r;constructor(t="/",r={}){this.#t=Rd(t),r.validate!==!1&&Dd(this)}get bytes(){return this.#r==null&&(this.#r=Ic(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Bc(this.#t)),this.#e}toJSON(){return this.toString()}toOptions(){let t,r,n,o,s="";for(let{code:a,name:c,value:l}of this.#t)a===42&&(s=`%${l??""}`),Td.includes(a)&&(r="tcp",o=443,n=`${l??""}${s}`,t=a===55?6:4),(a===6||a===273)&&(r=c==="tcp"?"tcp":"udp",o=parseInt(l??"")),(a===4||a===41)&&(r="tcp",n=`${l??""}${s}`,t=a===41?6:4);if(t==null||r==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:r,port:o}}getComponents(){return[...this.#t]}protos(){return this.#t.map(({code:t,value:r})=>{let n=_t.getProtocol(t);return{code:t,size:n.size??0,name:n.name,resolvable:!!n.resolvable,path:!!n.path}})}protoCodes(){return this.#t.map(({code:t})=>t)}protoNames(){return this.#t.map(({name:t})=>t)}tuples(){return this.#t.map(({code:t,value:r})=>{if(r==null)return[t];let n=_t.getProtocol(t),o=[t];return r!=null&&o.push(n.valueToBytes?.(r)??V(r)),o})}stringTuples(){return this.#t.map(({code:t,value:r})=>r==null?[t]:[t,r])}encapsulate(t){let r=new e(t);return new e([...this.#t,...r.getComponents()],{validate:!1})}decapsulate(t){let r=t.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new Or(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new e(n.slice(0,o),{validate:!1})}decapsulateCode(t){let r;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){r=n;break}return new e(this.#t.slice(0,r),{validate:!1})}getPeerId(){try{let t=[];this.#t.forEach(({code:n,value:o})=>{n===421&&t.push([n,o]),n===290&&(t=[])});let r=t.pop();if(r?.[1]!=null){let n=r[1];return n[0]==="Q"||n[0]==="1"?U(G.decode(`z${n}`),"base58btc"):U(J.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){for(let t of this.#t)if(_t.getProtocol(t.code).path)return t.value??null;return null}equals(t){return $(this.bytes,t.bytes)}async resolve(t){let r=this.protos().find(s=>s.resolvable);if(r==null)return[this];let n=Cc.get(r.name);if(n==null)throw new si(`no available resolver for ${r.name}`);return(await n(this,t)).map(s=>Mt(s))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(){return!(this.#t.length!==2||this.#t[0].code!==4&&this.#t[0].code!==41||this.#t[1].code!==6&&this.#t[1].code!==273)}[Cd](){return`Multiaddr(${this.toString()})`}};function Dd(e){e.getComponents().forEach(t=>{let r=_t.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}var ng=parseInt("0xFFFF",16),og=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var Cc=new Map;function Dn(e){return!!e?.[ii]}function Mt(e){return new Rn(e)}var Dc="libp2p-peer-record",Lc=Uint8Array.from([3,1]);var Ur;(function(e){let t;(function(n){let o;n.codec=()=>(o==null&&(o=bt((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:rt(0)},l=i==null?s.len:s.pos+i;for(;s.pos<l;){let f=s.uint32();switch(f>>>3){case 1:{c.multiaddr=s.bytes();break}default:{s.skipType(f&7);break}}}return c})),o),n.encode=s=>yt(s,n.codec()),n.decode=(s,i)=>mt(s,n.codec(),i)})(t=e.AddressInfo||(e.AddressInfo={}));let r;e.codec=()=>(r==null&&(r=bt((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),e.AddressInfo.codec().encode(i,o);s.lengthDelimited!==!1&&o.ldelim()},(n,o,s={})=>{let i={peerId:rt(0),seq:0n,addresses:[]},a=o==null?n.len:n.pos+o;for(;n.pos<a;){let c=n.uint32();switch(c>>>3){case 1:{i.peerId=n.bytes();break}case 2:{i.seq=n.uint64();break}case 3:{if(s.limits?.addresses!=null&&i.addresses.length===s.limits.addresses)throw new Ie('Decode error - map field "addresses" had too many elements');i.addresses.push(e.AddressInfo.codec().decode(n,n.uint32(),{limits:s.limits?.addresses$}));break}default:{n.skipType(c&7);break}}}return i})),r),e.encode=n=>yt(n,e.codec()),e.decode=(n,o)=>mt(n,e.codec(),o)})(Ur||(Ur={}));var Be=class e{static createFromProtobuf=t=>{let r=Ur.decode(t),n=Fs(Ke(r.peerId)),o=(r.addresses??[]).map(i=>Mt(i.multiaddr)),s=r.seq;return new e({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Dc;static CODEC=Lc;peerId;multiaddrs;seqNumber;domain=e.DOMAIN;codec=e.CODEC;marshaled;constructor(t){let{peerId:r,multiaddrs:n,seqNumber:o}=t;this.peerId=r,this.multiaddrs=n??[],this.seqNumber=o??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=Ur.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 e)||!this.peerId.equals(t.peerId)||this.seqNumber!==t.seqNumber||!hc(this.multiaddrs,t.multiaddrs))}};function Kd(e){return e[Symbol.asyncIterator]!=null}function Ud(e){if(Kd(e))return(async()=>{let r=[];for await(let n of e)r.push(n);return r})();let t=[];for(let r of e)t.push(r);return t}var Pc=Ud;function Ln(e,t){let r={[Symbol.iterator]:()=>r,next:()=>{let n=e.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return r}var Nr=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[r,n]of t.entries())this.map.set(r.toString(),{key:r,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return Ln(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((r,n)=>{t(r.value,r.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,r){this.map.set(t.toString(),{key:t,value:r})}keys(){return Ln(this.map.values(),t=>t.key)}values(){return Ln(this.map.values(),t=>t.value)}get size(){return this.map.size}};var ai=class extends Nr{metric;constructor(t){super();let{name:r,metrics:n}=t;this.metric=n.registerMetric(r),this.updateComponentMetric()}set(t,r){return super.set(t,r),this.updateComponentMetric(),this}delete(t){let r=super.delete(t);return this.updateComponentMetric(),r}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function ci(e){let{name:t,metrics:r}=e,n;return r!=null?n=new ai({name:t,metrics:r}):n=new Nr,n}var Bt=class extends Error{static name="AbortError";name="AbortError";constructor(t="The operation was aborted",...r){super(t,...r)}};function Pn(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var On=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}},er=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new On(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 r=this.head;this.head=r.next=new On(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var ui=class extends Error{type;code;constructor(t,r){super(t??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Oc(e={}){return Nd(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},e)}function Nd(e,t){t=t??{};let r=t.onEnd,n=new er,o,s,i,a=Pn(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((v,b)=>{s=A=>{s=null,n.push(A);try{v(e(n))}catch(x){b(x)}return o}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Pn()})}},l=v=>s!=null?s(v):(n.push(v),o),f=v=>(n=new er,s!=null?s({error:v}):(n.push({error:v}),o)),d=v=>{if(i)return o;if(t?.objectMode!==!0&&v?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:v})},u=v=>i?o:(i=!0,v!=null?f(v):l({done:!0})),h=()=>(n=new er,u(),{done:!0}),p=v=>(u(v),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:h,throw:p,push:d,end:u,get readableLength(){return n.size},onEmpty:async v=>{let b=v?.signal;if(b?.throwIfAborted(),n.isEmpty())return;let A,x;b!=null&&(A=new Promise((C,L)=>{x=()=>{L(new ui)},b.addEventListener("abort",x)}));try{await Promise.race([a.promise,A])}finally{x!=null&&b!=null&&b?.removeEventListener("abort",x)}}},r==null)return o;let E=o;return o={[Symbol.asyncIterator](){return this},next(){return E.next()},throw(v){return E.throw(v),r!=null&&(r(v),r=void 0),{done:!0}},return(){return E.return(),r!=null&&(r(),r=void 0),{done:!0}},push:d,end(v){return E.end(v),r!=null&&(r(v),r=void 0),o},get readableLength(){return E.readableLength},onEmpty:v=>E.onEmpty(v)},o}async function kn(e,t,r,n){let o=new Bt(n?.errorMessage);n?.errorCode!=null&&(o.code=n.errorCode);let s=n?.errorEvent??"error";return r?.aborted===!0?Promise.reject(o):new Promise((i,a)=>{function c(){fi(r,"abort",d),fi(e,t,l),fi(e,s,f)}let l=u=>{try{if(n?.filter?.(u)===!1)return}catch(h){c(),a(h);return}c(),i(u)},f=u=>{if(c(),u instanceof Error){a(u);return}a(u.detail??n?.error??new Error(`The "${n?.errorEvent}" event was emitted but the event had no '.detail' field. Pass an 'error' option to race-event to change this message.`))},d=()=>{c(),a(o)};li(r,"abort",d),li(e,t,l),li(e,s,f)})}function li(e,t,r){e!=null&&(kc(e)?e.addEventListener(t,r):e.addListener(t,r))}function fi(e,t,r){e!=null&&(kc(e)?e.removeEventListener(t,r):e.removeListener(t,r))}function kc(e){return typeof e.addEventListener=="function"&&typeof e.removeEventListener=="function"}var Kn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};var Un=class extends Error{type;code;constructor(t,r,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=r??"ABORT_ERR"}};async function Kc(e,t,r){if(t==null)return e;if(t.aborted)return e.catch(()=>{}),Promise.reject(new Un(r?.errorMessage,r?.errorCode,r?.errorName));let n,o=new Un(r?.errorMessage,r?.errorCode,r?.errorName);try{return await Promise.race([e,new Promise((s,i)=>{n=()=>{i(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var Nn=class{deferred;signal;constructor(t){this.signal=t,this.deferred=Promise.withResolvers(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Bt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Md(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Mn=class{id;fn;options;recipients;status;timeline;controller;constructor(t,r){this.id=Md(),this.status="queued",this.fn=t,this.options=r,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((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new Bt),this.cleanup())}async join(t={}){let r=new Nn(t.signal);return this.recipients.push(r),t.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let t=await Kc(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(t)}),this.status="complete"}catch(t){this.recipients.forEach(r=>{r.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 di(e,t){let r,n=function(){let o=function(){r=void 0,e()};clearTimeout(r),r=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var Mr=class extends De{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=di(this.emitEmpty.bind(this),1),this.emitIdle=di(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 r of this.queue)if(r.status==="queued"){t=r;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===t){this.queue.splice(r,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,r){if(r?.signal?.throwIfAborted(),this.size===this.maxSize)throw new Kn;let n=new Mn(t,r);return this.enqueue(n),this.safeDispatchEvent("add"),this.autoStart&&this.tryToStartAnother(),n.join(r).then(o=>(this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(t=>{t.abort(new Bt)}),this.clear()}async onEmpty(t){this.size!==0&&await kn(this,"empty",t?.signal)}async onSizeLessThan(t,r){this.size<t||await kn(this,"next",r?.signal,{filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await kn(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 r=Oc({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),r.end(c)},o=c=>{c.detail!=null&&r.push(c.detail.result)},s=c=>{n(c.detail.error)},i=()=>{n()},a=()=>{n(new Bt("Queue aborted"))};this.addEventListener("success",o),this.addEventListener("failure",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("success",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};var qn="lock:worker:request-read",Vn="lock:worker:abort-read-request",Hn="lock:worker:release-read",zn="lock:master:grant-read",Fn="lock:master:error-read",Wn="lock:worker:request-write",Gn="lock:worker:abort-write-request",$n="lock:worker:release-write",Zn="lock:master:grant-write",jn="lock:master:error-write",Yn="lock:worker:finalize",Xn="mortice",Uc={singleProcess:!1};var hi=(e,t,r,n,o,s,i,a,c)=>l=>{if(l.data==null)return;let f={type:l.data.type,name:l.data.name,identifier:l.data.identifier};f.type===o&&e.safeDispatchEvent(r,{detail:{name:f.name,identifier:f.identifier,handler:async()=>{t.postMessage({type:c,name:f.name,identifier:f.identifier}),await new Promise(d=>{let u=h=>{if(h?.data==null)return;let p={type:h.data.type,name:h.data.name,identifier:h.data.identifier};p.type===a&&p.identifier===f.identifier&&(t.removeEventListener("message",u),d())};t.addEventListener("message",u)})},onError:d=>{t.postMessage({type:i,name:f.name,identifier:f.identifier,error:{message:d.message,name:d.name,stack:d.stack}})}}}),f.type===s&&e.safeDispatchEvent(n,{detail:{name:f.name,identifier:f.identifier}}),f.type===Yn&&e.safeDispatchEvent("finalizeRequest",{detail:{name:f.name}})};var Nc=(e=10)=>Math.random().toString().substring(2,e+2);var Qn=class{name;channel;constructor(t){this.name=t,this.channel=new BroadcastChannel(Xn)}readLock(t){return this.sendRequest(qn,Vn,zn,Fn,Hn,t)}writeLock(t){return this.sendRequest(Wn,Gn,Zn,jn,$n,t)}finalize(){this.channel.postMessage({type:Yn,name:this.name}),this.channel.close()}async sendRequest(t,r,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 f=()=>{this.channel.postMessage({type:r,identifier:a,name:this.name})};i?.signal?.addEventListener("abort",f,{once:!0});let d=u=>{if(u.data?.identifier===a&&(u.data?.type===n&&(this.channel.removeEventListener("message",d),i?.signal?.removeEventListener("abort",f),c(()=>{this.channel.postMessage({type:s,identifier:a,name:this.name})})),u.data.type===o)){this.channel.removeEventListener("message",d),i?.signal?.removeEventListener("abort",f);let h=new Error;u.data.error!=null&&(h.message=u.data.error.message,h.name=u.data.error.name,h.stack=u.data.error.stack),l(h)}};this.channel.addEventListener("message",d)})}};var Mc=e=>{if(e=Object.assign({},Uc,e),!!globalThis.document||e.singleProcess){let r=new BroadcastChannel(Xn),n=new De;return r.addEventListener("message",hi(n,r,"requestReadLock","abortReadLockRequest",qn,Vn,Fn,Hn,zn)),r.addEventListener("message",hi(n,r,"requestWriteLock","abortWriteLockRequest",Wn,Gn,jn,$n,Zn)),n}return new Qn(e.name)};var Ce=new Map,qr;function qc(e){return typeof e?.readLock=="function"&&typeof e?.writeLock=="function"}function qd(e){if(qr==null&&(qr=Mc(e),!qc(qr))){let t=qr;t.addEventListener("requestReadLock",r=>{let n=r.detail.name,o=r.detail.identifier,s=Ce.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 r.detail.handler().finally(()=>{c()})}).catch(c=>{r.detail.onError(c)}).finally(()=>{t.removeEventListener("abortReadLockRequest",a)})}),t.addEventListener("requestWriteLock",r=>{let n=r.detail.name,o=r.detail.identifier,s=Ce.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 r.detail.handler().finally(()=>{c()})}).catch(c=>{r.detail.onError(c)}).finally(()=>{t.removeEventListener("abortWriteLockRequest",a)})}),t.addEventListener("finalizeRequest",r=>{let n=r.detail.name,o=Ce.get(n);o?.finalize()})}return qr}async function pi(e,t){let r,n,o=new Promise((i,a)=>{r=i,n=a}),s=()=>{n(new Bt)};return t?.signal?.addEventListener("abort",s,{once:!0}),e.add(async()=>{await new Promise(i=>{r(()=>{t?.signal?.removeEventListener("abort",s),i()})})},{signal:t?.signal}).catch(i=>{n(i)}),o}var Vc=(e,t)=>{let r=Ce.get(e);if(r!=null)return r;let n=qd(t);if(qc(n))return r=n,Ce.set(e,r),r;let o=new Mr({concurrency:1}),s;return r={async readLock(i){if(s!=null)return pi(s,i);s=new Mr({concurrency:t.concurrency,autoStart:!1});let a=s,c=pi(s,i);return o.add(async()=>{a.start(),await a.onIdle().then(()=>{s===a&&(s=null)})}),c},async writeLock(i){return s=null,pi(o,i)},finalize:()=>{Ce.delete(e)},queue:o},Ce.set(e,r),t.autoFinalize===!0&&o.addEventListener("idle",()=>{r.finalize()},{once:!0}),r};var Vd={name:"lock",concurrency:1/0,singleProcess:!1,autoFinalize:!1};function mi(e){let t=Object.assign({},Vd,e);return Vc(t.name,t)}var ne;(function(e){let t;(function(o){let s;o.codec=()=>(s==null&&(s=bt((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:rt(0)},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let d=i.uint32();switch(d>>>3){case 1:{l.key=i.string();break}case 2:{l.value=i.bytes();break}default:{i.skipType(d&7);break}}}return l})),s),o.encode=i=>yt(i,o.codec()),o.decode=(i,a)=>mt(i,o.codec(),a)})(t=e.Peer$metadataEntry||(e.Peer$metadataEntry={}));let r;(function(o){let s;o.codec=()=>(s==null&&(s=bt((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),to.codec().encode(i.value,a)),c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let l={key:""},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let d=i.uint32();switch(d>>>3){case 1:{l.key=i.string();break}case 2:{l.value=to.codec().decode(i,i.uint32(),{limits:c.limits?.value});break}default:{i.skipType(d&7);break}}}return l})),s),o.encode=i=>yt(i,o.codec()),o.decode=(i,a)=>mt(i,o.codec(),a)})(r=e.Peer$tagsEntry||(e.Peer$tagsEntry={}));let n;e.codec=()=>(n==null&&(n=bt((o,s,i={})=>{if(i.lengthDelimited!==!1&&s.fork(),o.addresses!=null)for(let a of o.addresses)s.uint32(10),Jn.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),e.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),e.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 Ie('Decode error - map field "addresses" had too many elements');a.addresses.push(Jn.codec().decode(o,o.uint32(),{limits:i.limits?.addresses$}));break}case 2:{if(i.limits?.protocols!=null&&a.protocols.length===i.limits.protocols)throw new Ie('Decode error - map field "protocols" had too many elements');a.protocols.push(o.string());break}case 4:{a.publicKey=o.bytes();break}case 5:{a.peerRecordEnvelope=o.bytes();break}case 6:{if(i.limits?.metadata!=null&&a.metadata.size===i.limits.metadata)throw new Ir('Decode error - map field "metadata" had too many elements');let f=e.Peer$metadataEntry.codec().decode(o,o.uint32());a.metadata.set(f.key,f.value);break}case 7:{if(i.limits?.tags!=null&&a.tags.size===i.limits.tags)throw new Ir('Decode error - map field "tags" had too many elements');let f=e.Peer$tagsEntry.codec().decode(o,o.uint32(),{limits:{value:i.limits?.tags$value}});a.tags.set(f.key,f.value);break}case 8:{a.updated=o.uint64Number();break}default:{o.skipType(l&7);break}}}return a})),n),e.encode=o=>yt(o,e.codec()),e.decode=(o,s)=>mt(o,e.codec(),s)})(ne||(ne={}));var Jn;(function(e){let t;e.codec=()=>(t==null&&(t=bt((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.multiaddr!=null&&r.multiaddr.byteLength>0&&(n.uint32(10),n.bytes(r.multiaddr)),r.isCertified!=null&&(n.uint32(16),n.bool(r.isCertified)),r.observed!=null&&(n.uint32(24),n.uint64Number(r.observed)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={multiaddr:rt(0)},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.multiaddr=r.bytes();break}case 2:{s.isCertified=r.bool();break}case 3:{s.observed=r.uint64Number();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>yt(r,e.codec()),e.decode=(r,n)=>mt(r,e.codec(),n)})(Jn||(Jn={}));var to;(function(e){let t;e.codec=()=>(t==null&&(t=bt((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.value!=null&&r.value!==0&&(n.uint32(8),n.uint32(r.value)),r.expiry!=null&&(n.uint32(16),n.uint64(r.expiry)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={value:0},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.value=r.uint32();break}case 2:{s.expiry=r.uint64();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>yt(r,e.codec()),e.decode=(r,n)=>mt(r,e.codec(),n)})(to||(to={}));function Hd(e,t){if(e.publicKey!=null||t.publicKey==null)return e;let r;e.type==="RSA"&&(r=e.toMultihash());let n=xn(t.publicKey,r);return fc(n)}function Hc(e,t,r){let n=ne.decode(t);return rr(e,n,r)}function rr(e,t,r){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:Hd(e,t),addresses:t.addresses.filter(({observed:s})=>s!=null&&s>Date.now()-r).map(({multiaddr:s,isCertified:i})=>({multiaddr:Mt(s),isCertified:i??!1})),metadata:t.metadata,peerRecordEnvelope:t.peerRecordEnvelope??void 0,tags:n}}function zc(e,t){return zd(e.addresses,t.addresses)&&Fd(e.protocols,t.protocols)&&Wd(e.publicKey,t.publicKey)&&Gd(e.peerRecordEnvelope,t.peerRecordEnvelope)&&$d(e.metadata,t.metadata)&&Zd(e.tags,t.tags)}function zd(e,t){return Wc(e,t,(r,n)=>!(r.isCertified!==n.isCertified||!$(r.multiaddr,n.multiaddr)))}function Fd(e,t){return Wc(e,t,(r,n)=>r===n)}function Wd(e,t){return Fc(e,t)}function Gd(e,t){return Fc(e,t)}function $d(e,t){return Gc(e,t,(r,n)=>$(r,n))}function Zd(e,t){return Gc(e,t,(r,n)=>r.value===n.value&&r.expiry===n.expiry)}function Fc(e,t){return e==null&&t==null?!0:e!=null&&t!=null?$(e,t):!1}function Wc(e,t,r){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!r(e[n],t[n]))return!1;return!0}function Gc(e,t,r){if(e.size!==t.size)return!1;for(let[n,o]of e.entries()){let s=t.get(n);if(s==null||!r(o,s))return!1}return!0}var oe="/",$c=new TextEncoder().encode(oe),eo=$c[0],ro=class e{_buf;constructor(t,r){if(typeof t=="string")this._buf=V(t);else if(t instanceof Uint8Array)this._buf=t;else throw new Error("Invalid key, should be String of Uint8Array");if(r==null&&(r=!0),r&&this.clean(),this._buf.byteLength===0||this._buf[0]!==eo)throw new Error("Invalid key")}toString(t="utf8"){return U(this._buf,t)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(t){return new e(t.join(oe))}static random(){return new e(Math.random().toString().substring(2))}static asKey(t){return t instanceof Uint8Array||typeof t=="string"?new e(t):typeof t.uint8Array=="function"?new e(t.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=$c),this._buf[0]!==eo){let t=new Uint8Array(this._buf.byteLength+1);t.fill(eo,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===eo;)this._buf=this._buf.subarray(0,-1)}less(t){let r=this.list(),n=t.list();for(let o=0;o<r.length;o++){if(n.length<o+1)return!1;let s=r[o],i=n[o];if(s<i)return!0;if(s>i)return!1}return r.length<n.length}reverse(){return e.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let t=this.namespaces();return t[t.length-1]}list(){return this.toString().split(oe).slice(1)}type(){return jd(this.baseNamespace())}name(){return Yd(this.baseNamespace())}instance(t){return new e(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(oe)||(t+=oe),t+=this.type(),new e(t)}parent(){let t=this.list();return t.length===1?new e(oe):new e(t.slice(0,-1).join(oe))}child(t){return this.toString()===oe?t:t.toString()===oe?this:new e(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 e.withNamespaces([...this.namespaces(),...Xd(t.map(r=>r.namespaces()))])}};function jd(e){let t=e.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function Yd(e){let t=e.split(":");return t[t.length-1]}function Xd(e){return[].concat(...e)}var yi="/peers/";function Vr(e){if(!Te(e)||e.type==null)throw new q("Invalid PeerId");let t=e.toCID().toString();return new ro(`${yi}${t}`)}async function Zc(e,t,r,n,o){let s=new Map;for(let i of r){if(i==null)continue;if(i.multiaddr instanceof Uint8Array&&(i.multiaddr=Mt(i.multiaddr)),!Dn(i.multiaddr))throw new q("Multiaddr was invalid");if(!await t(e,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 e.equals(c)&&(a=a.decapsulate(Mt(`/p2p/${e}`))),{isCertified:i,multiaddr:a.bytes}})}async function oo(e,t,r,n){if(t==null)throw new q("Invalid PeerData");if(t.publicKey!=null&&e.publicKey!=null&&!t.publicKey.equals(e.publicKey))throw new q("publicKey bytes do not match peer id publicKey bytes");let o=n.existingPeer?.peer;if(o!=null&&!e.equals(o.id))throw new q("peer id did not match existing peer id");let s=o?.addresses??[],i=new Set(o?.protocols??[]),a=o?.metadata??new Map,c=o?.tags??new Map,l=o?.peerRecordEnvelope;if(r==="patch"){if((t.multiaddrs!=null||t.addresses!=null)&&(s=[],t.multiaddrs!=null&&s.push(...t.multiaddrs.map(u=>({isCertified:!1,multiaddr:u}))),t.addresses!=null&&s.push(...t.addresses)),t.protocols!=null&&(i=new Set(t.protocols)),t.metadata!=null){let u=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);a=no(u,{validate:jc})}if(t.tags!=null){let u=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags);c=no(u,{validate:Yc,map:Xc})}t.peerRecordEnvelope!=null&&(l=t.peerRecordEnvelope)}if(r==="merge"){if(t.multiaddrs!=null&&s.push(...t.multiaddrs.map(u=>({isCertified:!1,multiaddr:u}))),t.addresses!=null&&s.push(...t.addresses),t.protocols!=null&&(i=new Set([...i,...t.protocols])),t.metadata!=null){let u=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);for(let[h,p]of u)p==null?a.delete(h):a.set(h,p);a=no([...a.entries()],{validate:jc})}if(t.tags!=null){let u=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags),h=new Map(c);for(let[p,E]of u)E==null?h.delete(p):h.set(p,E);c=no([...h.entries()],{validate:Yc,map:Xc})}t.peerRecordEnvelope!=null&&(l=t.peerRecordEnvelope)}let f;o?.id.publicKey!=null?f=Ct(o.id.publicKey):t.publicKey!=null?f=Ct(t.publicKey):e.publicKey!=null&&(f=Ct(e.publicKey));let d={addresses:await Zc(e,n.addressFilter??(async()=>!0),s,n.existingPeer?.peerPB.addresses,n),protocols:[...i.values()].sort((u,h)=>u.localeCompare(h)),metadata:a,tags:c,publicKey:f,peerRecordEnvelope:l};return d.addresses.forEach(u=>{u.observed=n.existingPeer?.peerPB.addresses?.find(h=>$(h.multiaddr,h.multiaddr))?.observed??Date.now()}),e.type!=="RSA"&&delete d.publicKey,d}function no(e,t){let r=new Map;for(let[n,o]of e)o!=null&&t.validate(n,o);for(let[n,o]of e.sort(([s],[i])=>s.localeCompare(i)))o!=null&&r.set(n,t.map?.(n,o)??o);return r}function jc(e,t){if(typeof e!="string")throw new q("Metadata key must be a string");if(!(t instanceof Uint8Array))throw new q("Metadata value must be a Uint8Array")}function Yc(e,t){if(typeof e!="string")throw new q("Tag name must be a string");if(t.value!=null){if(parseInt(`${t.value}`,10)!==t.value)throw new q("Tag value must be an integer");if(t.value<0||t.value>100)throw new q("Tag value must be between 0-100")}if(t.ttl!=null){if(parseInt(`${t.ttl}`,10)!==t.ttl)throw new q("Tag ttl must be an integer");if(t.ttl<0)throw new q("Tag ttl must be between greater than 0")}}function Xc(e,t){let r;t.expiry!=null&&(r=t.expiry),t.ttl!=null&&(r=BigInt(Date.now()+Number(t.ttl)));let n={value:t.value??0};return r!=null&&(n.expiry=r),n}function Qc(e){let t=e.toString().split("/")[2],r=J.parse(t,Kt);return wn(r)}function bi(e,t,r){let n=Qc(e);return Hc(n,t,r)}function Qd(e,t){return{prefix:yi,filters:(e.filters??[]).map(r=>({key:n,value:o})=>r(bi(n,o,t))),orders:(e.orders??[]).map(r=>(n,o)=>r(bi(n.key,n.value,t),bi(o.key,o.value,t)))}}var so=class{peerId;datastore;locks;addressFilter;log;maxAddressAge;maxPeerAge;constructor(t,r={}){this.log=t.logger.forComponent("libp2p:peer-store"),this.peerId=t.peerId,this.datastore=t.datastore,this.addressFilter=r.addressFilter,this.locks=ci({name:"libp2p_peer_store_locks",metrics:t.metrics}),this.maxAddressAge=r.maxAddressAge??36e5,this.maxPeerAge=r.maxPeerAge??216e5}getLock(t){let r=this.locks.get(t);return r==null&&(r={refs:0,lock:mi({name:t.toString(),singleProcess:!0})},this.locks.set(t,r)),r.refs++,r}maybeRemoveLock(t,r){r.refs--,r.refs===0&&(r.lock.finalize(),this.locks.delete(t))}async getReadLock(t,r){let n=this.getLock(t);try{let o=await n.lock.readLock(r);return()=>{o(),this.maybeRemoveLock(t,n)}}catch(o){throw this.maybeRemoveLock(t,n),o}}async getWriteLock(t,r){let n=this.getLock(t);try{let o=await n.lock.writeLock(r);return()=>{o(),this.maybeRemoveLock(t,n)}}catch(o){throw this.maybeRemoveLock(t,n),o}}async has(t,r){try{return await this.load(t,r),!0}catch(n){if(n.name!=="NotFoundError")throw n}return!1}async delete(t,r){this.peerId.equals(t)||await this.datastore.delete(Vr(t),r)}async load(t,r){let n=Vr(t),o=await this.datastore.get(n,r),s=ne.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,r),new nr;return rr(t,s,this.peerId.equals(t)?1/0:this.maxAddressAge)}async save(t,r,n){let o=await this.#t(t,n),s=await oo(t,r,"patch",{...n,addressFilter:this.addressFilter});return this.#e(t,s,o)}async patch(t,r,n){let o=await this.#t(t,n),s=await oo(t,r,"patch",{...n,addressFilter:this.addressFilter,existingPeer:o});return this.#e(t,s,o)}async merge(t,r,n){let o=await this.#t(t,n),s=await oo(t,r,"merge",{addressFilter:this.addressFilter,existingPeer:o});return this.#e(t,s,o)}async*all(t){for await(let{key:r,value:n}of this.datastore.query(Qd(t??{},this.maxAddressAge),t)){let o=Qc(r);if(o.equals(this.peerId))continue;let s=ne.decode(n);if(this.#r(o,s)){await this.datastore.delete(r,t);continue}yield rr(o,s,this.peerId.equals(o)?1/0:this.maxAddressAge)}}async#t(t,r){try{let n=Vr(t),o=await this.datastore.get(n,r),s=ne.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,r),new nr;return{peerPB:s,peer:rr(t,s,this.maxAddressAge)}}catch(n){n.name!=="NotFoundError"&&this.log.error("invalid peer data found in peer store - %e",n)}}async#e(t,r,n,o){r.updated=Date.now();let s=ne.encode(r);return await this.datastore.put(Vr(t),s,o),{peer:rr(t,r,this.maxAddressAge),previous:n?.peer,updated:n==null||!zc(r,n.peerPB)}}#r(t,r){if(r.updated==null)return!0;if(this.peerId.equals(t))return!1;let n=r.updated<Date.now()-this.maxPeerAge,o=Date.now()-this.maxAddressAge,s=r.addresses.filter(i=>i.observed!=null&&i.observed>o);return n&&s.length===0}};var gi=class{store;events;peerId;log;constructor(t,r={}){this.log=t.logger.forComponent("libp2p:peer-store"),this.events=t.events,this.peerId=t.peerId,this.store=new so(t,r)}[Symbol.toStringTag]="@libp2p/peer-store";async forEach(t,r){for await(let n of this.store.all(r))t(n)}async all(t){return Pc(this.store.all(t))}async delete(t,r){let n=await this.store.getReadLock(t,r);try{await this.store.delete(t,r)}finally{n()}}async has(t,r){let n=await this.store.getReadLock(t,r);try{return await this.store.has(t,r)}finally{this.log.trace("has release read lock"),n?.()}}async get(t,r){let n=await this.store.getReadLock(t,r);try{return await this.store.load(t,r)}finally{n?.()}}async getInfo(t,r){let n=await this.get(t,r);return{id:n.id,multiaddrs:n.addresses.map(({multiaddr:o})=>o)}}async save(t,r,n){let o=await this.store.getWriteLock(t,n);try{let s=await this.store.save(t,r,n);return this.#t(t,s),s.peer}finally{o?.()}}async patch(t,r,n){let o=await this.store.getWriteLock(t,n);try{let s=await this.store.patch(t,r,n);return this.#t(t,s),s.peer}finally{o?.()}}async merge(t,r,n){let o=await this.store.getWriteLock(t,n);try{let s=await this.store.merge(t,r,n);return this.#t(t,s),s.peer}finally{o?.()}}async consumePeerRecord(t,r,n){let o=Te(r)?r:Te(r?.expectedPeer)?r.expectedPeer:void 0,s=Te(r)||r===void 0?n:r,i=await Je.openAndCertify(t,Be.DOMAIN,s),a=wn(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=Be.createFromProtobuf(i.payload),l;try{l=await this.get(a,s)}catch(f){if(f.name!=="NotFoundError")throw f}if(l?.peerRecordEnvelope!=null){let f=Je.createFromProtobuf(l.peerRecordEnvelope),d=Be.createFromProtobuf(f.payload);if(d.seqNumber>=c.seqNumber)return this.log("sequence number was lower or equal to existing sequence number - stored: %d received: %d",d.seqNumber,c.seqNumber),!1}return await this.patch(c.peerId,{peerRecordEnvelope:t,addresses:c.multiaddrs.map(f=>({isCertified:!0,multiaddr:f}))},s),!0}#t(t,r){r.updated&&(this.peerId.equals(t)?this.events.safeDispatchEvent("self:peer:update",{detail:r}):this.events.safeDispatchEvent("peer:update",{detail:r}))}};function Jd(e,t={}){return new gi(e,t)}return nu(th);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/hashes/esm/utils.js:
|