index.ts 785 B

12345678910111213141516171819202122
  1. import ComlinkCryptoWorker from "@ente/shared/crypto";
  2. import { B64EncryptionResult } from "@ente/shared/crypto/types";
  3. import { CustomError } from "@ente/shared/error";
  4. import { getKey, SESSION_KEYS } from "@ente/shared/storage/sessionStorage";
  5. export const getActualKey = async () => {
  6. try {
  7. const encryptionKeyAttributes: B64EncryptionResult = getKey(
  8. SESSION_KEYS.ENCRYPTION_KEY,
  9. );
  10. const cryptoWorker = await ComlinkCryptoWorker.getInstance();
  11. const key = await cryptoWorker.decryptB64(
  12. encryptionKeyAttributes.encryptedData,
  13. encryptionKeyAttributes.nonce,
  14. encryptionKeyAttributes.key,
  15. );
  16. return key;
  17. } catch (e) {
  18. throw new Error(CustomError.KEY_MISSING);
  19. }
  20. };