import { type Branded, type BrandedArity2, type Result } from '@trezor/type-utils'; export type EncryptableBranded = string & Branded; export type EncryptedHex = string & BrandedArity2<'EncryptedHex', T>; export const asEncryptedHex = (value: string) => value as EncryptedHex; export type EncryptionUnavailable = { type: 'EncryptionUnavailable'; message: string; }; export const EncryptionUnavailable = (message: string): EncryptionUnavailable => ({ type: 'EncryptionUnavailable' as const, message, }); export type DecryptionFailed = { type: 'DecryptionFailed'; }; export const DecryptionFailed = (): DecryptionFailed => ({ type: 'DecryptionFailed' as const, }); export type EncryptionError = EncryptionUnavailable; export type DecryptionError = EncryptionUnavailable | DecryptionFailed; export type PlatformEncryptionDep = { platformEncryption: PlatformEncryption }; export const injectPlatformEncryption = (services: any): PlatformEncryptionDep => ({ platformEncryption: services.platformEncryption, }); export type EncryptParams = { value: T }; export type DecryptParams = { value: EncryptedHex }; /** @serviceContract */ export interface PlatformEncryption { encrypt: ( params: EncryptParams, ) => Promise, EncryptionError>>; decrypt: ( params: DecryptParams, ) => Promise>; }