diff --git a/src/abstractions/crypto.service.ts b/src/abstractions/crypto.service.ts index 3a7e406f1a..b3fb5340b7 100644 --- a/src/abstractions/crypto.service.ts +++ b/src/abstractions/crypto.service.ts @@ -3,31 +3,31 @@ import { SymmetricCryptoKey } from '../models/domain/symmetricCryptoKey'; import { ProfileOrganizationResponse } from '../models/response/profileOrganizationResponse'; -export interface CryptoService { - setKey(key: SymmetricCryptoKey): Promise; - setKeyHash(keyHash: string): Promise<{}>; - setEncKey(encKey: string): Promise<{}>; - setEncPrivateKey(encPrivateKey: string): Promise<{}>; - setOrgKeys(orgs: ProfileOrganizationResponse[]): Promise<{}>; - getKey(): Promise; - getKeyHash(): Promise; - getEncKey(): Promise; - getPrivateKey(): Promise; - getOrgKeys(): Promise>; - getOrgKey(orgId: string): Promise; - clearKey(): Promise; - clearKeyHash(): Promise; - clearEncKey(memoryOnly?: boolean): Promise; - clearPrivateKey(memoryOnly?: boolean): Promise; - clearOrgKeys(memoryOnly?: boolean): Promise; - clearKeys(): Promise; - toggleKey(): Promise; - makeKey(password: string, salt: string): SymmetricCryptoKey; - hashPassword(password: string, key: SymmetricCryptoKey): Promise; - makeEncKey(key: SymmetricCryptoKey): Promise; - encrypt(plainValue: string | Uint8Array, key?: SymmetricCryptoKey, plainValueEncoding?: string): Promise; - encryptToBytes(plainValue: ArrayBuffer, key?: SymmetricCryptoKey): Promise; - decrypt(cipherString: CipherString, key?: SymmetricCryptoKey, outputEncoding?: string): Promise; - decryptFromBytes(encBuf: ArrayBuffer, key: SymmetricCryptoKey): Promise; - rsaDecrypt(encValue: string): Promise; +export abstract class CryptoService { + setKey: (key: SymmetricCryptoKey) => Promise; + setKeyHash: (keyHash: string) => Promise<{}>; + setEncKey: (encKey: string) => Promise<{}>; + setEncPrivateKey: (encPrivateKey: string) => Promise<{}>; + setOrgKeys: (orgs: ProfileOrganizationResponse[]) => Promise<{}>; + getKey: () => Promise; + getKeyHash: () => Promise; + getEncKey: () => Promise; + getPrivateKey: () => Promise; + getOrgKeys: () => Promise>; + getOrgKey: (orgId: string) => Promise; + clearKey: () => Promise; + clearKeyHash: () => Promise; + clearEncKey: (memoryOnly?: boolean) => Promise; + clearPrivateKey: (memoryOnly?: boolean) => Promise; + clearOrgKeys: (memoryOnly?: boolean) => Promise; + clearKeys: () => Promise; + toggleKey: () => Promise; + makeKey: (password: string, salt: string) => SymmetricCryptoKey; + hashPassword: (password: string, key: SymmetricCryptoKey) => Promise; + makeEncKey: (key: SymmetricCryptoKey) => Promise; + encrypt: (plainValue: string | Uint8Array, key?: SymmetricCryptoKey, plainValueEncoding?: string) => Promise; + encryptToBytes: (plainValue: ArrayBuffer, key?: SymmetricCryptoKey) => Promise; + decrypt: (cipherString: CipherString, key?: SymmetricCryptoKey, outputEncoding?: string) => Promise; + decryptFromBytes: (encBuf: ArrayBuffer, key: SymmetricCryptoKey) => Promise; + rsaDecrypt: (encValue: string) => Promise; } diff --git a/src/abstractions/i18n.service.ts b/src/abstractions/i18n.service.ts new file mode 100644 index 0000000000..0a89e6eeba --- /dev/null +++ b/src/abstractions/i18n.service.ts @@ -0,0 +1,4 @@ +export abstract class I18nService { + t: (id: string) => string; + translate: (id: string) => string; +} diff --git a/src/abstractions/index.ts b/src/abstractions/index.ts index 69f1295104..154ef9238f 100644 --- a/src/abstractions/index.ts +++ b/src/abstractions/index.ts @@ -6,6 +6,7 @@ export { CollectionService } from './collection.service'; export { CryptoService } from './crypto.service'; export { EnvironmentService } from './environment.service'; export { FolderService } from './folder.service'; +export { I18nService } from './i18n.service'; export { LockService } from './lock.service'; export { MessagingService } from './messaging.service'; export { PasswordGenerationService } from './passwordGeneration.service'; diff --git a/src/abstractions/platformUtils.service.ts b/src/abstractions/platformUtils.service.ts index c1da1e8cc4..afcc30e5a2 100644 --- a/src/abstractions/platformUtils.service.ts +++ b/src/abstractions/platformUtils.service.ts @@ -1,15 +1,18 @@ import { DeviceType } from '../enums/deviceType'; -export interface PlatformUtilsService { - getDevice(): DeviceType; - getDeviceString(): string; - isFirefox(): boolean; - isChrome(): boolean; - isEdge(): boolean; - isOpera(): boolean; - isVivaldi(): boolean; - isSafari(): boolean; - analyticsId(): string; - getDomain(uriString: string): string; - isViewOpen(): boolean; +export abstract class PlatformUtilsService { + getDevice: () => DeviceType; + getDeviceString: () => string; + isFirefox: () => boolean; + isChrome: () => boolean; + isEdge: () => boolean; + isOpera: () => boolean; + isVivaldi: () => boolean; + isSafari: () => boolean; + analyticsId: () => string; + getDomain: (uriString: string) => string; + isViewOpen: () => boolean; + launchUri: (uri: string) => void; + saveFile: (win: Window, blobData: any, blobOptions: any, fileName: string) => void; + alertError: (title: string, message: string) => void; } diff --git a/src/abstractions/utils.service.ts b/src/abstractions/utils.service.ts index a251eedeaa..5ef1cce54d 100644 --- a/src/abstractions/utils.service.ts +++ b/src/abstractions/utils.service.ts @@ -1,4 +1,4 @@ -export interface UtilsService { - copyToClipboard(text: string, doc?: Document): void; - getHostname(uriString: string): string; +export abstract class UtilsService { + copyToClipboard: (text: string, doc?: Document) => void; + getHostname: (uriString: string) => string; } diff --git a/src/models/view/cardView.ts b/src/models/view/cardView.ts index 2e052fff55..b75fdf1fca 100644 --- a/src/models/view/cardView.ts +++ b/src/models/view/cardView.ts @@ -48,4 +48,18 @@ export class CardView implements View { } return this._subTitle; } + + get expiration(): string { + if (!this.expMonth && !this.expYear) { + return null; + } + + let exp = this.expMonth != null ? ('0' + this.expMonth).slice(-2) : '__'; + exp += (' / ' + (this.expYear != null ? this.formatYear(this.expYear) : '____')); + return exp; + } + + private formatYear(year: string): string { + return year.length === 2 ? '20' + year : year; + } } diff --git a/src/models/view/fieldView.ts b/src/models/view/fieldView.ts index f25f86cc6e..e3c544c8f3 100644 --- a/src/models/view/fieldView.ts +++ b/src/models/view/fieldView.ts @@ -6,10 +6,33 @@ import { Field } from '../domain/field'; export class FieldView implements View { name: string; - vault: string; type: FieldType; + // tslint:disable + private _value: string; + private _maskedValue: string; + // tslint:enable + constructor(f: Field) { this.type = f.type; } + + get value(): string { + return this._value; + } + set value(value: string) { + this._value = value; + this._maskedValue = null; + } + + get maskedValue(): string { + if (this._maskedValue == null && this.value != null) { + this._maskedValue = ''; + for (let i = 0; i < this.value.length; i++) { + this._maskedValue += '•'; + } + } + + return this._maskedValue; + } } diff --git a/src/models/view/identityView.ts b/src/models/view/identityView.ts index e1c3a2255f..ed8bf0e453 100644 --- a/src/models/view/identityView.ts +++ b/src/models/view/identityView.ts @@ -62,4 +62,25 @@ export class IdentityView implements View { return this._subTitle; } + + get fullName(): string { + if (this.title != null || this.firstName != null || this.middleName != null || this.lastName != null) { + let name = ''; + if (this.title != null) { + name += (this.title + ' '); + } + if (this.firstName != null) { + name += (this.firstName + ' '); + } + if (this.middleName != null) { + name += (this.middleName + ' '); + } + if (this.lastName != null) { + name += this.lastName; + } + return name.trim(); + } + + return null; + } } diff --git a/src/services/crypto.service.ts b/src/services/crypto.service.ts index 84391897f8..e6ad642574 100644 --- a/src/services/crypto.service.ts +++ b/src/services/crypto.service.ts @@ -7,7 +7,7 @@ import { EncryptedObject } from '../models/domain/encryptedObject'; import { SymmetricCryptoKey } from '../models/domain/symmetricCryptoKey'; import { ProfileOrganizationResponse } from '../models/response/profileOrganizationResponse'; -import { CryptoService as CryptoServiceInterface } from '../abstractions/crypto.service'; +import { CryptoService as CryptoServiceAbstraction } from '../abstractions/crypto.service'; import { StorageService as StorageServiceInterface } from '../abstractions/storage.service'; import { ConstantsService } from './constants.service'; @@ -33,7 +33,7 @@ const AesAlgorithm = { const Crypto = window.crypto; const Subtle = Crypto.subtle; -export class CryptoService implements CryptoServiceInterface { +export class CryptoService implements CryptoServiceAbstraction { private key: SymmetricCryptoKey; private encKey: SymmetricCryptoKey; private legacyEtmKey: SymmetricCryptoKey;