diff --git a/src/App.tsx b/src/App.tsx index 6ffddb8..d280e41 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -5,6 +5,12 @@ export default function App() { const appRef = useRef(null); if (!appRef.current) { appRef.current = new Enclave(); + appRef.current + .init() + .then(() => { + console.log("Encalve initialized"); + }) + .catch(console.error); } return ( diff --git a/src/app/app.ts b/src/app/app.ts index 26ccd24..c1f1e37 100644 --- a/src/app/app.ts +++ b/src/app/app.ts @@ -1,5 +1,9 @@ +import { getServerList, KnownServer } from "@/lib/serverList"; import EnclaveServer from "./server"; import * as ed from "@noble/ed25519"; +import { sha512 } from "@noble/hashes/sha2.js"; + +ed.hashes.sha512 = sha512; /** * Top-level application state and client-side logic. @@ -17,14 +21,16 @@ import * as ed from "@noble/ed25519"; export default class Enclave { private clientSecretKey: Uint8Array; private clientPublicKey: Uint8Array; - public server: EnclaveServer; + public server?: EnclaveServer; + public serverList: KnownServer[]; public constructor() { this.clientSecretKey = ed.utils.randomSecretKey(); this.clientPublicKey = ed.getPublicKey(this.clientSecretKey); + this.serverList = []; + } - this.server = new EnclaveServer("localhost:3415"); - - this.server.connect(this.clientPublicKey, this.clientSecretKey); + public async init() { + this.serverList = await getServerList(); } } diff --git a/src/lib/serverList.ts b/src/lib/serverList.ts index 63fc40b..2452dd1 100644 --- a/src/lib/serverList.ts +++ b/src/lib/serverList.ts @@ -1,12 +1,12 @@ import { invoke } from "@tauri-apps/api/core"; -type KnownServer = { +export interface KnownServer { name: string; description: string; publicKey: string; hostname: string; isWss: boolean; -}; +} export async function saveServerList(servers: KnownServer[]): Promise { await invoke("save_server_list", { servers });