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
crypto: migrate to the new crypto api interface
thecodrr8a1d4b179a4a
diff --git a/packages/core/__mocks__/storage.mock.js b/packages/core/__mocks__/storage.mock.jsindex d0e5b9faa..b398b0926 100644--- a/packages/core/__mocks__/storage.mock.js+++ b/packages/core/__mocks__/storage.mock.js@@ -7,7 +7,7 @@ async function read(key) {async function readMulti(keys) {return new Promise((resolve, reject) => {const result = [];- keys.forEach(key => {+ keys.forEach((key) => {result.push([key, storage[key]]);});resolve(result);@@ -29,9 +29,17 @@ function encrypt(password, data) {resolve({ iv: "some iv", cipher: data }));}+function decrypt(password, data) {return new Promise((resolve, reject) => resolve(data.cipher));}++function deriveKey(password, salt) {+ return new Promise((resolve, reject) =>+ resolve({ key: password, salt: "salt" })+ );+}+module.exports = {read,readMulti,@@ -39,5 +47,6 @@ module.exports = {remove,clear,encrypt,- decrypt+ decrypt,+ deriveKey,};diff --git a/packages/core/api/vault.js b/packages/core/api/vault.jsindex e6aa12c02..f7297f2d2 100644--- a/packages/core/api/vault.js+++ b/packages/core/api/vault.js@@ -13,14 +13,17 @@ export default class Vault {this.ERRORS = {noVault: "ERR_NO_VAULT",vaultLocked: "ERR_VAULT_LOCKED",- wrongPassword: "ERR_WRONG_PASSWORD"+ wrongPassword: "ERR_WRONG_PASSWORD",};}async create(password) {const lockKey = await this._context.read("lockKey");if (!lockKey || !lockKey.cipher || !lockKey.iv) {- const encryptedData = await this._context.encrypt(password, this._key);+ const encryptedData = await this._context.encrypt(+ { password },+ this._key+ );await this._context.write("lockKey", encryptedData);this._password = password;}@@ -32,7 +35,7 @@ export default class Vault {if (!(await this._exists(lockKey))) throw new Error("ERR_NO_VAULT");var data;try {- data = await this._context.decrypt(password, lockKey);+ data = await this._context.decrypt({ password }, lockKey);} catch (e) {throw new Error(this.ERRORS.wrongPassword);}@@ -96,8 +99,8 @@ export default class Vault {if (!delta.ops) delta = await this._db.delta.get(deltaId);if (text === textId) text = await this._db.text.get(textId);- text = await this._context.encrypt(this._password, text);- delta = await this._context.encrypt(this._password, delta);+ text = await this._context.encrypt({ password: this._password }, text);+ delta = await this._context.encrypt({ password: this._password }, delta);await this._db.text.add({ id: textId, data: text });await this._db.delta.add({ id: deltaId, data: delta });@@ -107,14 +110,14 @@ export default class Vault {let { text, delta } = { ...content };text = await this._db.text.get(text);- text = await this._context.decrypt(this._password, text);+ text = await this._context.decrypt({ password: this._password }, text);delta = await this._db.text.get(delta);- delta = await this._context.decrypt(this._password, delta);+ delta = await this._context.decrypt({ password: this._password }, delta);return {delta,- text+ text,};}@@ -135,7 +138,7 @@ export default class Vault {return await this._db.notes.add({id,- locked: true+ locked: true,});}@@ -147,7 +150,7 @@ export default class Vault {if (perm) {await this._db.notes.add({id: note.id,- locked: false+ locked: false,});await this._db.delta.add({ id: note.content.delta, data: delta });await this._db.text.add({ id: note.content.text, data: text });@@ -156,7 +159,7 @@ export default class Vault {return {...note,- content: { delta }+ content: { delta },};}}