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.

21 lines
625 B

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