mirror of
https://github.com/bitwarden/browser
synced 2025-12-20 18:23:31 +00:00
* Rename cryptoservice to keyservice * Rename cryptoservice to keyservice * Move key service to key management ownership * Remove accidentally added file * Fix cli build * Fix browser build * Run prettier * Fix builds * Fix cli build * Fix tests * Fix incorrect renames * Rename webauthn-login-crypto-service * Fix build errors due to merge conflicts * Fix linting
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import { Jsonify } from "type-fest";
|
|
|
|
import { KeyService } from "../../../../../key-management/src/abstractions/key.service";
|
|
import { DeriveDefinition, FOLDER_DISK, UserKeyDefinition } from "../../../platform/state";
|
|
import { FolderService } from "../../abstractions/folder/folder.service.abstraction";
|
|
import { FolderData } from "../../models/data/folder.data";
|
|
import { Folder } from "../../models/domain/folder";
|
|
import { FolderView } from "../../models/view/folder.view";
|
|
|
|
export const FOLDER_ENCRYPTED_FOLDERS = UserKeyDefinition.record<FolderData>(
|
|
FOLDER_DISK,
|
|
"folders",
|
|
{
|
|
deserializer: (obj: Jsonify<FolderData>) => FolderData.fromJSON(obj),
|
|
clearOn: ["logout"],
|
|
},
|
|
);
|
|
|
|
export const FOLDER_DECRYPTED_FOLDERS = DeriveDefinition.from<
|
|
Record<string, FolderData>,
|
|
FolderView[],
|
|
{ folderService: FolderService; keyService: KeyService }
|
|
>(FOLDER_ENCRYPTED_FOLDERS, {
|
|
deserializer: (obj) => obj.map((f) => FolderView.fromJSON(f)),
|
|
derive: async (from, { folderService, keyService }) => {
|
|
const folders = Object.values(from || {}).map((f) => new Folder(f));
|
|
|
|
if (await keyService.hasUserKey()) {
|
|
return await folderService.decryptFolders(folders);
|
|
} else {
|
|
return [];
|
|
}
|
|
},
|
|
});
|