refactor: consolidate all bootloader state to a map

This commit is contained in:
Derrick Hammer 2023-07-19 04:50:24 -04:00
parent 3e2d2bd261
commit 210a9f12ce
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 26 additions and 23 deletions

View File

@ -1,51 +1,54 @@
import { Client } from "@lumeweb/libportal";
import { x25519 } from "@noble/curves/ed25519"; 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 = export const defaultKernelLink =
"zduGxnSUFCXuVCkaGfq7761tcASmEK5WBn8kBesgTDizG6bvKuPD5RrDCj"; "zduGxnSUFCXuVCkaGfq7761tcASmEK5WBn8kBesgTDizG6bvKuPD5RrDCj";
const store = new Map<string, any>(
Object.entries({
loginComplete: false,
logoutComplete: false,
kernelLoaded: "not yet",
communicationKey: null,
frontendCommunicationPubKey: null,
}),
);
export function setLoginComplete(status: boolean) { export function setLoginComplete(status: boolean) {
loginComplete = status; store.set("loginComplete", status);
} }
export function getLoginComplete() { export function getLoginComplete(): boolean {
return loginComplete; return store.get("loginComplete");
} }
export function setLogoutComplete(status: boolean) { export function setLogoutComplete(status: boolean) {
logoutComplete = status; store.set("logoutComplete", status);
} }
export function getLogoutComplete() { export function getLogoutComplete(): boolean {
return logoutComplete; return store.get("logoutComplete");
} }
export function setKernelLoaded(status: string) { export function setKernelLoaded(status: string) {
kernelLoaded = status; store.set("kernelLoaded", status);
} }
export function getKernelLoaded() { export function getKernelLoaded(): string {
return kernelLoaded; return store.get("kernelLoaded");
} }
export function getCommunicationKey() { export function getCommunicationKey(): Uint8Array {
if (!communicationKey) { if (!store.get("communicationKey")) {
communicationKey = x25519.utils.randomPrivateKey(); store.set("communicationKey", x25519.utils.randomPrivateKey());
} }
return communicationKey; return store.get("communicationKey");
} }
export function getCommunicationPubKey() { export function getCommunicationPubKey() {
return x25519.getPublicKey(getCommunicationKey()); return x25519.getPublicKey(getCommunicationKey());
} }
export function getFrontendCommunicationPubkey() { export function getFrontendCommunicationPubkey(): Uint8Array {
return frontendCommunicationPubKey; return store.get("frontendCommunicationPubKey");
} }
export function setFrontendCommunicationPubkey(key: Uint8Array) { export function setFrontendCommunicationPubkey(key: Uint8Array) {
frontendCommunicationPubKey = key; store.set("frontendCommunicationPubKey", key);
} }