diff --git a/src/matrix/e2ee/common.js b/src/matrix/e2ee/common.js index 190f2fa2..52995765 100644 --- a/src/matrix/e2ee/common.js +++ b/src/matrix/e2ee/common.js @@ -17,7 +17,7 @@ limitations under the License. import anotherjson from "../../../lib/another-json/index.js"; import {createEnum} from "../../utils/enum.js"; -export const DecryptionSource = createEnum(["Sync", "Timeline", "Retry"]); +export const DecryptionSource = createEnum("Sync", "Timeline", "Retry"); // use common prefix so it's easy to clear properties that are not e2ee related during session clear export const SESSION_KEY_PREFIX = "e2ee:"; diff --git a/src/utils/enum.js b/src/utils/enum.js index 733a548b..4defcfd7 100644 --- a/src/utils/enum.js +++ b/src/utils/enum.js @@ -17,6 +17,9 @@ limitations under the License. export function createEnum(...values) { const obj = {}; for (const value of values) { + if (typeof value !== "string") { + throw new Error("Invalid enum value name" + value?.toString()); + } obj[value] = value; } return Object.freeze(obj);