ente/web/packages/shared/user/index.ts

23 lines
785 B
TypeScript
Raw Normal View History

import ComlinkCryptoWorker from "@ente/shared/crypto";
import { B64EncryptionResult } from "@ente/shared/crypto/types";
import { CustomError } from "@ente/shared/error";
import { getKey, SESSION_KEYS } from "@ente/shared/storage/sessionStorage";
2023-11-02 12:06:34 +00:00
export const getActualKey = async () => {
try {
const encryptionKeyAttributes: B64EncryptionResult = getKey(
SESSION_KEYS.ENCRYPTION_KEY,
2023-11-02 12:06:34 +00:00
);
const cryptoWorker = await ComlinkCryptoWorker.getInstance();
const key = await cryptoWorker.decryptB64(
encryptionKeyAttributes.encryptedData,
encryptionKeyAttributes.nonce,
encryptionKeyAttributes.key,
2023-11-02 12:06:34 +00:00
);
return key;
} catch (e) {
throw new Error(CustomError.KEY_MISSING);
}
};