1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 15:53:27 +00:00

[PM-24105] Remove usage of getUserKey on keyService (#16626)

• prefer undefined over null
• obtain required UserId once per method, before branching
• guards moved to beginning of methods
* lift UserId retrieval to occur once during import
* remove redundant userId retrieval
This commit is contained in:
John Harrington
2025-10-15 07:03:29 -07:00
committed by GitHub
parent 8ff4fb1ed4
commit 64105e64e9
22 changed files with 118 additions and 62 deletions

View File

@@ -1,3 +1,5 @@
import { firstValueFrom } from "rxjs";
import { EncryptService } from "@bitwarden/common/key-management/crypto/abstractions/encrypt.service";
import { EncString } from "@bitwarden/common/key-management/crypto/models/enc-string";
import { UserId } from "@bitwarden/common/types/guid";
@@ -15,7 +17,11 @@ export class LegacyPasswordHistoryDecryptor {
/** Decrypts a password history. */
async decrypt(history: GeneratedPasswordHistory[]): Promise<GeneratedPasswordHistory[]> {
const key = await this.keyService.getUserKey(this.userId);
const key = await firstValueFrom(this.keyService.userKey$(this.userId));
if (key == undefined) {
throw new Error("No user key found for decryption");
}
const promises = (history ?? []).map(async (item) => {
const encrypted = new EncString(item.password);