diff --git a/src/components/AccountEncrypted.vue b/src/components/AccountEncrypted.vue deleted file mode 100644 index 7630982..0000000 --- a/src/components/AccountEncrypted.vue +++ /dev/null @@ -1,49 +0,0 @@ - - - diff --git a/src/services/CouchService.ts b/src/services/CouchService.ts index 82e34dd..a96bc96 100644 --- a/src/services/CouchService.ts +++ b/src/services/CouchService.ts @@ -30,8 +30,6 @@ const REMOTE: string = 'https://juliencalixte.ddns.net/database' class CouchService { public db: PouchDB.Database | null = new PouchDb(LOCALE_DB) - public remoteUserDb: PouchDB.Database | null = null - public userDb: PouchDB.Database | null = null private innerRemote: PouchDB.Database | null = null private user: IUser | null = null private sync: PouchDB.Replication.Sync<{}> | null = null @@ -64,21 +62,6 @@ class CouchService { return false } await this.cancelSync() - if (this.userDb && this.remoteUserDb) { - this.userSync = this.userDb - .sync(this.remoteUserDb, { - live: true, - retry: true - }) - .on('change', (result: PouchDB.Replication.SyncResult) => { - if (result.direction === 'pull') { - emit( - SYNC, - result.change.docs.map((doc: any) => doc._id) - ) - } - }) - } this.sync = this.db .sync(this.remote, { @@ -143,10 +126,6 @@ class CouchService { this.db = new PouchDb(`vaquant-${user.userId}`) } } - // this.remoteUserDb = hexUser - // ? new PouchDb(`${REMOTE}/userdb-${hexUser}`, remoteConfig) - // : null - // this.userDb = hexUser ? new PouchDb(`userdb-${hexUser}`) : null this.initLive() } else { this.cancelSync() @@ -220,102 +199,6 @@ class CouchService { return response } - public async retrievePassword(id: string, user: IUser): Promise { - if (!this.userDb || !this.remoteUserDb) { - return false - } - if (this.userDb.get(id)) { - return true - } - const response = await axios.post(GET_KEY_URL, { - accountId: id, - username: user.userId, - salt: user.salt - }) - if (response.data) { - const passwordDoc: IEncryptPassword = { - _id: id, - password: response.data - } - const putResponse = await this.userDb.put(passwordDoc) - if (putResponse.ok) { - await this.userDb.sync(this.remoteUserDb) - } - return putResponse.ok - } - return false - } - - public async encrypt( - id: string, - doc: IEncryptable, - savePassword: boolean = false, - usernames: string[] = [] - ): Promise { - try { - if (!this.userDb) { - return null - } - let passwordDoc: IEncryptPassword | null = null - try { - passwordDoc = (await this.userDb.get(id)) as IEncryptPassword - } catch (error) { - // tslint:disable-next-line:no-console - console.warn('encrypt retrieve password', { error, savePassword }) - } - if (!passwordDoc && savePassword) { - try { - passwordDoc = await cryptoService.createPassword() - passwordDoc._id = id - await this.userDb.put(passwordDoc) - if (this.remoteUserDb) { - this.userDb.sync(this.remoteUserDb).then(() => { - if (!passwordDoc || !usernames.length || !this.user) { - return - } - axios.post(SET_KEY_URL, { - accountId: id, - password: passwordDoc.password, - usernames, - username: this.user.userId, - salt: this.user.salt - }) - }) - } - } catch (error) { - // tslint:disable-next-line:no-console - console.warn('encrypt and save password', { error, savePassword }) - } - } - if (!passwordDoc) { - return doc - } - return await cryptoService.encrypt(doc, passwordDoc.password) - } catch (error) { - // tslint:disable-next-line:no-console - console.warn('encrypt and save', { error }) - return doc - } - } - - public async decrypt( - id: string, - doc: IEncrypted - ): Promise { - try { - if (!this.userDb) { - return doc - } - const passwordDoc = (await this.userDb.get(id)) as IEncryptPassword - if (!passwordDoc) { - return doc - } - return await cryptoService.decrypt(doc, passwordDoc.password) - } catch (error) { - return doc - } - } - public async remove(id: string): Promise { if (!this.db) { return false @@ -326,23 +209,7 @@ class CouchService { ...doc, _deleted: true }) - if (this.userDb) { - const userDb = this.userDb - userDb - .get(id) - .then((password: any) => { - if (password) { - userDb.put({ - ...password, - _deleted: true - }) - } - }) - .catch((error: any) => { - // tslint:disable-next-line:no-console - console.warn('remove password', { error }) - }) - } + return response.ok } return false @@ -358,10 +225,6 @@ class CouchService { await this.db.destroy() this.db = null } - if (this.userDb) { - await this.userDb.destroy() - this.userDb = null - } const hexUser: string = toHex(this.user.userId) this.setUser(this.user, hexUser, false) } diff --git a/src/services/TransactionService.ts b/src/services/TransactionService.ts index 6a3df0d..5028b61 100644 --- a/src/services/TransactionService.ts +++ b/src/services/TransactionService.ts @@ -52,7 +52,7 @@ class TransactionService { public async get(id: string): Promise { const transaction: ITransaction = await couchService.get(id) - return await this.decrypt(transaction) + return transaction } public async add( @@ -89,9 +89,9 @@ class TransactionService { return [] } - const response: PouchDB.Core.AllDocsResponse< + const response: PouchDB.Core.AllDocsResponse = await couchService.getByPrefix< ITransaction - > = await couchService.getByPrefix(`tra-${accountId}`) + >(`tra-${accountId}`) const transactions = response.rows.map((row) => row.doc) as ITransaction[] return transactions.sort((a: ITransaction, b: ITransaction) => a.date < b.date ? -1 : 1 @@ -155,20 +155,6 @@ class TransactionService { tag: transaction.tag } } - - private async decrypt(transaction: ITransaction): Promise { - if (!transaction) { - return transaction - } - const decrypt = await couchService.decrypt( - transaction.accountId || '', - this.toEncrypt(transaction) - ) - return { - ...transaction, - ...decrypt - } - } } export default new TransactionService() diff --git a/src/views/accounts/AccountItem.vue b/src/views/accounts/AccountItem.vue index 8635393..731d4af 100644 --- a/src/views/accounts/AccountItem.vue +++ b/src/views/accounts/AccountItem.vue @@ -192,7 +192,6 @@ import { primary, main, findContrastColor, findDarkValue } from '@/utils' @Component({ components: { 'account-share': () => import('@/components/AccountShare.vue'), - 'account-encrypted': () => import('@/components/AccountEncrypted.vue'), 'account-transaction-list': () => import('@/components/AccountTransactionList.vue'), 'tag-list': () => import('@/components/TagList.vue'),