A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
sync: sync vaultKey
thecodrr2c9d7c285d9f
diff --git a/packages/core/api/sync/merger.js b/packages/core/api/sync/merger.jsindex 86f5f6573..4d83b351a 100644--- a/packages/core/api/sync/merger.js+++ b/packages/core/api/sync/merger.js@@ -70,11 +70,16 @@ class Merger {tags,colors,trash,+ vaultKey,} = serverResponse;if (synced || areAllEmpty(serverResponse)) return false;this.key = await this._db.user.key();+ if (vaultKey) {+ await this._db.vault._setKey(await this._deserialize(vaultKey));+ }+await this._mergeArray(notes,(id) => this._db.notes.note(id),diff --git a/packages/core/api/sync/prepare.js b/packages/core/api/sync/prepare.jsindex 3902f23ae..1f511e4a6 100644--- a/packages/core/api/sync/prepare.js+++ b/packages/core/api/sync/prepare.js@@ -24,6 +24,7 @@ class Prepare {tags: await this._prepareForServer(this._db.tags.raw),colors: await this._prepareForServer(this._db.colors.raw),trash: await this._prepareForServer(this._db.trash.raw),+ vaultKey: await this._serialize(await this._db.vault._getKey()),};}diff --git a/packages/core/api/vault.js b/packages/core/api/vault.jsindex a7e3c42b5..c2e85e3eb 100644--- a/packages/core/api/vault.js+++ b/packages/core/api/vault.js@@ -17,25 +17,34 @@ export default class Vault {};}+ async _getKey() {+ if (await this._exists()) return await this._context.read("vaultKey");+ }++ async _setKey(vaultKey) {+ if (!vaultKey) return;+ await this._context.write("vaultKey", vaultKey);+ }+async create(password) {- const lockKey = await this._context.read("lockKey");- if (!lockKey || !lockKey.cipher || !lockKey.iv) {+ const vaultKey = await this._context.read("vaultKey");+ if (!vaultKey || !vaultKey.cipher || !vaultKey.iv) {const encryptedData = await this._context.encrypt({ password },this._key);- await this._context.write("lockKey", encryptedData);+ await this._context.write("vaultKey", encryptedData);this._password = password;}return true;}async unlock(password) {- const lockKey = await this._context.read("lockKey");- if (!(await this._exists(lockKey))) throw new Error("ERR_NO_VAULT");+ const vaultKey = await this._context.read("vaultKey");+ if (!(await this._exists(vaultKey))) throw new Error("ERR_NO_VAULT");var data;try {- data = await this._context.decrypt({ password }, lockKey);+ data = await this._context.decrypt({ password }, vaultKey);} catch (e) {throw new Error(this.ERRORS.wrongPassword);}@@ -46,9 +55,9 @@ export default class Vault {return true;}- async _exists(lockKey) {- if (!lockKey) lockKey = await this._context.read("lockKey");- return lockKey && lockKey.cipher && lockKey.iv;+ async _exists(vaultKey) {+ if (!vaultKey) vaultKey = await this._context.read("vaultKey");+ return vaultKey && vaultKey.cipher && vaultKey.iv;}async _locked() {