1
0
mirror of https://github.com/bitwarden/desktop.git synced 2024-11-28 12:35:40 +01:00
bitwarden-desktop/src/services/desktopSecureStorage.service.ts
2018-01-23 15:08:57 -05:00

30 lines
865 B
TypeScript

import { ipcRenderer } from 'electron';
import { StorageService } from 'jslib/abstractions/storage.service';
export class DesktopSecureStorageService implements StorageService {
async get<T>(key: string): Promise<T> {
const val = ipcRenderer.sendSync('keytar', {
action: 'getPassword',
key: key,
});
return Promise.resolve(val ? JSON.parse(val) as T : null);
}
async save(key: string, obj: any): Promise<any> {
ipcRenderer.sendSync('keytar', {
action: 'setPassword',
key: key,
value: JSON.stringify(obj),
});
return Promise.resolve();
}
async remove(key: string): Promise<any> {
ipcRenderer.sendSync('keytar', {
action: 'deletePassword',
key: key,
});
return Promise.resolve();
}
}