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
fix: encrypt/decrypt delta with note
thecodrr60aec97335c7
diff --git a/packages/core/__tests__/convert.test.js b/packages/core/__tests__/convert.test.jsdeleted file mode 100644index 4f9c2a5f5..000000000--- a/packages/core/__tests__/convert.test.js+++ /dev/null@@ -1,56 +0,0 @@-import Convert from "../utils/convert";--test("object to string", () => {- let objStr = Convert.toString({ hello: "world" });- expect(objStr).toStrictEqual(`{"hello":"world"}`);-});--test("array to string", () => {- let arrStr = Convert.toString(["hello", "world", "what"]);- expect(arrStr).toStrictEqual(`["hello","world","what"]`);-});--test("number to string", () => {- let numStr = Convert.toString(2010);- expect(numStr).toBe("2010");-});--test("bool to string", () => {- let boolStr = Convert.toString(true);- expect(boolStr).toBe("true");-});--test("null conversion", () => {- expect(Convert.toString(undefined)).toBeUndefined();-});--//fromString-test("string to bool", () => {- expect(Convert.fromString("true")).toBe(true);- expect(Convert.fromString("false")).toBe(false);-});--test("string to int", () => {- expect(Convert.fromString("2010")).toBe(2010);-});--test("string to float", () => {- expect(Convert.fromString("20.2")).toBe(20.2);-});--test("string to object", () => {- let objStr = JSON.stringify({ hello: "world" });- expect(Convert.fromString(objStr)).toStrictEqual({ hello: "world" });-});--test("string to array", () => {- expect(Convert.fromString('["hello","world","what"]')).toStrictEqual([- "hello",- "world",- "what"- ]);-});--test("string to string", () => {- expect(Convert.fromString("hello")).toBe("hello");-});diff --git a/packages/core/models/note.js b/packages/core/models/note.jsindex 6e2df2fd4..a40066c25 100644--- a/packages/core/models/note.js+++ b/packages/core/models/note.js@@ -44,7 +44,8 @@ export default class Note {}delta() {- return this.notes.deltaStorage.read(this.note.id + "_delta");+ if (this.note.locked) return [];+ return this.notes.deltaStorage.read(this.note.content.delta);}color(color) {@@ -84,21 +85,32 @@ export default class Note {password,JSON.stringify(this.note.content));+ let delta = await this.notes.collection.indexer.encrypt(+ password,+ JSON.stringify(await this.delta())+ );+ await this.notes.deltaStorage.write(this.note.content.delta, delta);this.note.locked = true;return await this.notes.collection.addItem(this.note);}async unlock(password, perm = false) {- let decrypted = await this.notes.collection.indexer.decrypt(- password,- this.note.content+ let decrypted = JSON.parse(+ await this.notes.collection.indexer.decrypt(password, this.note.content)+ );+ let delta = JSON.parse(+ await this.notes.collection.indexer.decrypt(password, await this.delta()));if (perm) {this.note.locked = false;- this.note.content = JSON.parse(decrypted);+ this.note.content = decrypted;await this.notes.collection.addItem(this.note);+ await this.notes.deltaStorage.write(this.note.content.delta, delta);}- return { ...this.note, content: JSON.parse(decrypted) };+ return {+ ...this.note,+ content: { ...decrypted, delta: delta }+ };}}diff --git a/packages/core/package.json b/packages/core/package.jsonindex 5d96fdc5e..d904d5814 100644--- a/packages/core/package.json+++ b/packages/core/package.json@@ -20,6 +20,7 @@"fuzzysearch": "^1.0.3","node-fetch": "^2.6.0","qclone": "^1.0.4",+ "teleport-javascript": "^1.0.0","transfun": "^1.0.2"}}diff --git a/packages/core/utils/convert.js b/packages/core/utils/convert.jsdeleted file mode 100644index 74aa8b022..000000000--- a/packages/core/utils/convert.js+++ /dev/null@@ -1,21 +0,0 @@-export default class Convert {- static toString(input) {- if (!input) return;- let type = typeof input;- if (type === "object") return JSON.stringify(input);- return input.toString();- }- static fromString(input) {- if (!input) return;- let firstChar = input[0];- if (firstChar == "[" || firstChar == "{") return JSON.parse(input);- if (!isNaN(parseFloat(input)) && input.includes("."))- return parseFloat(input);- if (!isNaN(parseInt(input))) return parseInt(input);- if (parseBoolean(input) !== undefined) return parseBoolean(input);- return input;- }-}-function parseBoolean(value) {- return value === "true" ? true : value === "false" ? false : undefined;-}diff --git a/packages/core/yarn.lock b/packages/core/yarn.lockindex dd3e5b3bb..602404bb0 100644--- a/packages/core/yarn.lock+++ b/packages/core/yarn.lock@@ -4437,6 +4437,11 @@ tar@^4:safe-buffer "^5.1.2"yallist "^3.0.3"+teleport-javascript@^1.0.0:+ version "1.0.0"+ resolved "https://registry.yarnpkg.com/teleport-javascript/-/teleport-javascript-1.0.0.tgz#c9397fad598d662027e4d3a5fa7e7da1c8361547"+ integrity sha512-j1llvWVFyEn/6XIFDfX5LAU43DXe0GCt3NfXDwJ8XpRRMkS+i50SAkonAONBy+vxwPFBd50MFU8a2uj8R/ccLg==+test-exclude@^5.2.3:version "5.2.3"resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-5.2.3.tgz#c3d3e1e311eb7ee405e092dac10aefd09091eac0"