diff --git a/libs/common/src/abstractions/state.service.ts b/libs/common/src/abstractions/state.service.ts index 04cfb609fe..68986f47e6 100644 --- a/libs/common/src/abstractions/state.service.ts +++ b/libs/common/src/abstractions/state.service.ts @@ -14,7 +14,11 @@ import { BiometricKey } from "../auth/types/biometric-key"; import { KdfType, ThemeType, UriMatchType } from "../enums"; import { EventData } from "../models/data/event.data"; import { ServerConfigData } from "../models/data/server-config.data"; -import { Account, AccountSettingsSettings } from "../models/domain/account"; +import { + Account, + AccountDecryptionOptions, + AccountSettingsSettings, +} from "../models/domain/account"; import { EncString } from "../models/domain/enc-string"; import { StorageOptions } from "../models/domain/storage-options"; import { DeviceKey, SymmetricCryptoKey } from "../models/domain/symmetric-crypto-key"; @@ -165,6 +169,11 @@ export abstract class StateService { setDuckDuckGoSharedKey: (value: string, options?: StorageOptions) => Promise; getDeviceKey: (options?: StorageOptions) => Promise; setDeviceKey: (value: DeviceKey, options?: StorageOptions) => Promise; + getUserDecryptionOptions: (options?: StorageOptions) => Promise; + setUserDecryptionOptions: ( + value: AccountDecryptionOptions, + options?: StorageOptions + ) => Promise; getEmail: (options?: StorageOptions) => Promise; setEmail: (value: string, options?: StorageOptions) => Promise; getEmailVerified: (options?: StorageOptions) => Promise; diff --git a/libs/common/src/services/state.service.ts b/libs/common/src/services/state.service.ts index dc32c688e3..900364a80b 100644 --- a/libs/common/src/services/state.service.ts +++ b/libs/common/src/services/state.service.ts @@ -28,6 +28,7 @@ import { ServerConfigData } from "../models/data/server-config.data"; import { Account, AccountData, + AccountDecryptionOptions, AccountSettings, AccountSettingsSettings, } from "../models/domain/account"; @@ -1080,6 +1081,37 @@ export class StateService< await this.saveAccount(account, options); } + async getUserDecryptionOptions( + options?: StorageOptions + ): Promise { + options = this.reconcileOptions(options, await this.defaultInMemoryOptions()); + + if (options?.userId == null) { + return null; + } + + const account = await this.getAccount(options); + + return account?.decryptionOptions as AccountDecryptionOptions; + } + + async setUserDecryptionOptions( + value: AccountDecryptionOptions, + options?: StorageOptions + ): Promise { + options = this.reconcileOptions(options, await this.defaultInMemoryOptions()); + + if (options?.userId == null) { + return; + } + + const account = await this.getAccount(options); + + account.decryptionOptions = value; + + await this.saveAccount(account, options); + } + async getEmail(options?: StorageOptions): Promise { return ( await this.getAccount(this.reconcileOptions(options, await this.defaultInMemoryOptions()))