Server Management

This commit is contained in:
2026-08-18 16:20:43 +02:00
parent 06ca3a4bae
commit c0470e940b
3 changed files with 29 additions and 4 deletions
+23 -1
View File
@@ -1,7 +1,8 @@
import { getServerList, KnownServer } from "@/lib/serverList";
import { getServerList, getWSUrl, KnownServer } from "@/lib/serverList";
import EnclaveServer from "./server";
import * as ed from "@noble/ed25519";
import { sha512 } from "@noble/hashes/sha2.js";
import { base58 } from "@scure/base";
ed.hashes.sha512 = sha512;
@@ -33,4 +34,25 @@ export default class Enclave {
public async init() {
this.serverList = await getServerList();
}
public async addServer(hostname: string, isSecure: boolean) {
if (this.server) {
this.server.disconnect();
}
this.server = new EnclaveServer(getWSUrl({ hostname, isSecure }));
if (!this.server.serverPublicKey) {
console.error("Failed to get public key");
return;
}
this.serverList.push({
name: "",
description: "",
hostname,
isSecure,
publicKey: base58.encode(this.server.serverPublicKey),
});
}
}
+1 -1
View File
@@ -30,7 +30,7 @@ export default class EnclaveServer {
this.hostname = hostname;
}
public async disconnect() {
public disconnect() {
this.websocket?.websocket.close();
this.websocket = undefined;
}