A self hosted chat application with end-to-end encrypted messaging.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
587 B

  1. import { EncryptionService } from "../service/EncryptionService";
  2. import { ChatMessageDTO } from "../dto/ChatMessageDTO";
  3. import * as log from "loglevel";
  4. import { getOneMessage } from "./messages";
  5. export async function isPassphraseValid(
  6. passphrase: string,
  7. userName: string,
  8. es: EncryptionService
  9. ): Promise<boolean> {
  10. const messages: ChatMessageDTO[] = await getOneMessage(userName, 0);
  11. if (messages.length === 0) return true;
  12. try {
  13. es.decrypt(passphrase, messages[0].messageCipher);
  14. } catch (error) {
  15. log.debug("here");
  16. return false;
  17. }
  18. return true;
  19. }