From 210a9f12ce004eef9171897040b9c4f423369a56 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 19 Jul 2023 04:50:24 -0400 Subject: [PATCH] refactor: consolidate all bootloader state to a map --- src/main/bootloader/vars.ts | 49 ++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/src/main/bootloader/vars.ts b/src/main/bootloader/vars.ts index 7d425bf..cb7a0ea 100644 --- a/src/main/bootloader/vars.ts +++ b/src/main/bootloader/vars.ts @@ -1,51 +1,54 @@ -import { Client } from "@lumeweb/libportal"; import { x25519 } from "@noble/curves/ed25519"; -let loginComplete = false; -let logoutComplete = false; -let kernelLoaded = "not yet"; -let communicationKey: Uint8Array; -let frontendCommunicationPubKey: Uint8Array; - export const defaultKernelLink = "zduGxnSUFCXuVCkaGfq7761tcASmEK5WBn8kBesgTDizG6bvKuPD5RrDCj"; +const store = new Map( + Object.entries({ + loginComplete: false, + logoutComplete: false, + kernelLoaded: "not yet", + communicationKey: null, + frontendCommunicationPubKey: null, + }), +); + export function setLoginComplete(status: boolean) { - loginComplete = status; + store.set("loginComplete", status); } -export function getLoginComplete() { - return loginComplete; +export function getLoginComplete(): boolean { + return store.get("loginComplete"); } export function setLogoutComplete(status: boolean) { - logoutComplete = status; + store.set("logoutComplete", status); } -export function getLogoutComplete() { - return logoutComplete; +export function getLogoutComplete(): boolean { + return store.get("logoutComplete"); } export function setKernelLoaded(status: string) { - kernelLoaded = status; + store.set("kernelLoaded", status); } -export function getKernelLoaded() { - return kernelLoaded; +export function getKernelLoaded(): string { + return store.get("kernelLoaded"); } -export function getCommunicationKey() { - if (!communicationKey) { - communicationKey = x25519.utils.randomPrivateKey(); +export function getCommunicationKey(): Uint8Array { + if (!store.get("communicationKey")) { + store.set("communicationKey", x25519.utils.randomPrivateKey()); } - return communicationKey; + return store.get("communicationKey"); } export function getCommunicationPubKey() { return x25519.getPublicKey(getCommunicationKey()); } -export function getFrontendCommunicationPubkey() { - return frontendCommunicationPubKey; +export function getFrontendCommunicationPubkey(): Uint8Array { + return store.get("frontendCommunicationPubKey"); } export function setFrontendCommunicationPubkey(key: Uint8Array) { - frontendCommunicationPubKey = key; + store.set("frontendCommunicationPubKey", key); }