import { type DesktopApi } from '@suite/desktop-app-api'; import { type DecryptParams, type EncryptParams, type EncryptableBranded, type PlatformEncryption, asEncryptedHex, } from '@suite-common/platform-encryption'; import { ok } from '@trezor/type-utils'; export type ElectronPlatformEncryptionDeps = { desktopApi: DesktopApi; }; export const createElectronPlatformEncryption = ( deps: ElectronPlatformEncryptionDeps, ): PlatformEncryption => ({ encrypt: async ({ value }: EncryptParams) => { const result = await deps.desktopApi.safeStoreEncrypt({ value }); return result.success ? ok(asEncryptedHex(result.payload as T)) : result; }, decrypt: async ({ value }: DecryptParams) => { const result = await deps.desktopApi.safeStoreDecrypt({ value }); return result.success ? ok(result.payload as T) : result; }, });