From 693dbab54e48f061ac715aa0932dea651780e5f6 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Tue, 22 Sep 2020 15:22:39 +0100 Subject: [PATCH] Add more types and enums --- src/utils/WellKnownUtils.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/utils/WellKnownUtils.ts b/src/utils/WellKnownUtils.ts index 6437d22cb3..69ed39e0ee 100644 --- a/src/utils/WellKnownUtils.ts +++ b/src/utils/WellKnownUtils.ts @@ -19,9 +19,13 @@ import {MatrixClientPeg} from '../MatrixClientPeg'; const E2EE_WK_KEY = "io.element.e2ee"; const E2EE_WK_KEY_DEPRECATED = "im.vector.riot.e2ee"; +/* eslint-disable camelcase */ export interface IE2EEWellKnown { default?: boolean; + secure_backup_required?: boolean; + secure_backup_setup_methods?: SecureBackupSetupMethod[]; } +/* eslint-enable camelcase */ export function getE2EEWellKnown(): IE2EEWellKnown { const clientWellKnown = MatrixClientPeg.get().getClientWellKnown(); @@ -39,18 +43,26 @@ export function isSecureBackupRequired(): boolean { return wellKnown && wellKnown["secure_backup_required"] === true; } -export function getSecureBackupSetupMethods(): string[] { +export enum SecureBackupSetupMethod { + Key = "key", + Passphrase = "passphrase", +} + +export function getSecureBackupSetupMethods(): SecureBackupSetupMethod[] { const wellKnown = getE2EEWellKnown(); if ( !wellKnown || !wellKnown["secure_backup_setup_methods"] || !wellKnown["secure_backup_setup_methods"].length || !( - wellKnown["secure_backup_setup_methods"].includes("key") || - wellKnown["secure_backup_setup_methods"].includes("passphrase") + wellKnown["secure_backup_setup_methods"].includes(SecureBackupSetupMethod.Key) || + wellKnown["secure_backup_setup_methods"].includes(SecureBackupSetupMethod.Passphrase) ) ) { - return ["key", "passphrase"]; + return [ + SecureBackupSetupMethod.Key, + SecureBackupSetupMethod.Passphrase, + ]; } return wellKnown["secure_backup_setup_methods"]; }