Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

partially implement vault system

ammarahm-ed09223e002e72
diff --git a/apps/mobile/ios/Podfile.lock b/apps/mobile/ios/Podfile.lock
index ac6efa41f..c4d60113b 100644
--- a/apps/mobile/ios/Podfile.lock
+++ b/apps/mobile/ios/Podfile.lock
@@ -182,6 +182,8 @@ PODS:
- React-cxxreact (= 0.61.4)
- React-jsi (= 0.61.4)
- React-jsinspector (0.61.4)
+ - react-native-aes (1.3.6):
+ - React
- react-native-webview (7.5.1):
- React
- React-RCTActionSheet (0.61.4):
@@ -250,6 +252,7 @@ DEPENDENCIES:
- React-jsi (from `../node_modules/react-native/ReactCommon/jsi`)
- React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`)
- React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`)
+ - react-native-aes (from `../node_modules/react-native-aes-crypto`)
- react-native-webview (from `../node_modules/react-native-webview`)
- React-RCTActionSheet (from `../node_modules/react-native/Libraries/ActionSheetIOS`)
- React-RCTAnimation (from `../node_modules/react-native/Libraries/NativeAnimation`)
@@ -303,6 +306,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/jsiexecutor"
React-jsinspector:
:path: "../node_modules/react-native/ReactCommon/jsinspector"
+ react-native-aes:
+ :path: "../node_modules/react-native-aes-crypto"
react-native-webview:
:path: "../node_modules/react-native-webview"
React-RCTActionSheet:
@@ -356,6 +361,7 @@ SPEC CHECKSUMS:
React-jsi: ca921f4041505f9d5197139b2d09eeb020bb12e8
React-jsiexecutor: 8dfb73b987afa9324e4009bdce62a18ce23d983c
React-jsinspector: d15478d0a8ada19864aa4d1cc1c697b41b3fa92f
+ react-native-aes: 22ea989d641f53ea7722fe6b146349ed66e6455d
react-native-webview: 2aadbfef6b9eaa9e89b306ae3e31e6e870a6306d
React-RCTActionSheet: 7369b7c85f99b6299491333affd9f01f5a130c22
React-RCTAnimation: d07be15b2bd1d06d89417eb0343f98ffd2b099a7
diff --git a/apps/mobile/src/components/EditorMenu/index.js b/apps/mobile/src/components/EditorMenu/index.js
index fe07aac66..b92e1ae3f 100644
--- a/apps/mobile/src/components/EditorMenu/index.js
+++ b/apps/mobile/src/components/EditorMenu/index.js
@@ -1,4 +1,4 @@
-import React from 'react';
+import React, {useState} from 'react';
import {
ScrollView,
View,
@@ -23,6 +23,7 @@ import AsyncStorage from '@react-native-community/async-storage';
import {AnimatedSafeAreaView} from '../../views/Home';
import {TextInput} from 'react-native-gesture-handler';
import {useAppContext} from '../../provider/useAppContext';
+import {VaultDialog} from '../VaultDialog';
let tagsInputRef;
@@ -32,8 +33,12 @@ export const EditorMenu = ({
update = () => {},
updateProps = () => {},
noteProps,
+ note,
+ timestamp,
}) => {
const {colors, changeColorScheme} = useAppContext();
+ const [unlock, setUnlock] = useState(false);
+ const [vaultDialog, setVaultDialog] = useState(false);
let tagToAdd = null;
let backPressCount = 0;
@@ -42,7 +47,6 @@ export const EditorMenu = ({
<TouchableOpacity
activeOpacity={opacity}
onPress={() => {
- item.close === false ? null : close();
item.func();
}}
style={{
@@ -316,12 +320,19 @@ export const EditorMenu = ({
close: true,
},
{
- name: 'Locked',
+ name: noteProps.locked ? 'Remove from Vault' : 'Add to Vault',
icon: 'lock',
- func: () => {},
+ func: () => {
+ if (noteProps.locked) {
+ setUnlock(true);
+ } else {
+ setUnlock(false);
+ }
+ setVaultDialog(true);
+ },
close: true,
check: true,
- on: false,
+ on: noteProps.locked,
},
]}
keyExtractor={(item, index) => item.name}
@@ -470,6 +481,25 @@ export const EditorMenu = ({
<ActivityIndicator color={colors.accent} />
</View>
</ScrollView>
+
+ <VaultDialog
+ close={(item, locked) => {
+ if (item) {
+ update(item);
+ }
+ let props = {...noteProps};
+ props.locked = locked;
+ updateProps(props);
+
+ setVaultDialog(false);
+ setUnlock(false);
+ }}
+ note={note}
+ timestamp={timestamp}
+ perm={true}
+ openedToUnlock={unlock}
+ visible={vaultDialog}
+ />
</KeyboardAvoidingView>
</AnimatedSafeAreaView>
);
diff --git a/apps/mobile/src/components/NoteItem/index.js b/apps/mobile/src/components/NoteItem/index.js
index b2a248e6b..f7a7b6b5b 100644
--- a/apps/mobile/src/components/NoteItem/index.js
+++ b/apps/mobile/src/components/NoteItem/index.js
@@ -24,6 +24,8 @@ const NoteItem = props => {
const {colors} = useAppContext();
const [visible, setVisible] = useState(false);
const [vaultDialog, setVaultDialog] = useState(false);
+ const [unlock, setUnlock] = useState(false);
+ const [isPerm, setIsPerm] = useState(false);
const item = props.item;
let show = null;
@@ -35,7 +37,12 @@ const NoteItem = props => {
if (show === 'delete') {
setVisible(true);
show = null;
- } else if (show == 'vault') {
+ } else if (show == 'lock') {
+ setVaultDialog(true);
+ show = null;
+ } else if (show == 'unlock') {
+ setUnlock(true);
+ setIsPerm(true);
setVaultDialog(true);
show = null;
}
@@ -85,7 +92,18 @@ const NoteItem = props => {
setVisible(false);
}}
/>
- <VaultDialog visible={vaultDialog} />
+ <VaultDialog
+ close={() => {
+ setVaultDialog(false);
+ setUnlock(false);
+ setIsPerm(false);
+ props.refresh();
+ }}
+ note={item}
+ perm={isPerm}
+ openedToUnlock={unlock}
+ visible={vaultDialog}
+ />
{props.pinned ? (
<View
style={{
@@ -114,11 +132,16 @@ const NoteItem = props => {
<TouchableOpacity
activeOpacity={1}
onPress={() => {
- SideMenuEvent.close();
- SideMenuEvent.disable();
- NavigationService.navigate('Editor', {
- note: item,
- });
+ if (item.locked) {
+ setUnlock(true);
+ setVaultDialog(true);
+ } else {
+ SideMenuEvent.close();
+ SideMenuEvent.disable();
+ NavigationService.navigate('Editor', {
+ note: item,
+ });
+ }
}}
style={{
paddingLeft: 0,
@@ -336,7 +359,8 @@ const NoteItem = props => {
</MenuItem>
<MenuItem
onPress={() => {
- show = 'vault';
+ item.locked ? (show = 'unlock') : (show = 'lock');
+
hideMenu(true);
}}
textStyle={{
@@ -345,7 +369,7 @@ const NoteItem = props => {
fontFamily: WEIGHT.regular,
fontSize: SIZE.xs,
}}>
- Lock
+ {item.locked ? 'Remove from vault' : ' Add to Vault'}
</MenuItem>
<MenuItem
diff --git a/apps/mobile/src/components/NotesList/index.js b/apps/mobile/src/components/NotesList/index.js
index 4a5ed5db5..8880d4b30 100644
--- a/apps/mobile/src/components/NotesList/index.js
+++ b/apps/mobile/src/components/NotesList/index.js
@@ -259,7 +259,7 @@ export const NotesList = ({
fontFamily: WEIGHT.regular,
marginTop: 20,
}}>
- Notes you write show up here.
+ Notes you write will appear here.
</Text>
</View>
}
diff --git a/apps/mobile/src/components/VaultDialog/index.js b/apps/mobile/src/components/VaultDialog/index.js
index 4769879e7..964a89b61 100644
--- a/apps/mobile/src/components/VaultDialog/index.js
+++ b/apps/mobile/src/components/VaultDialog/index.js
@@ -6,13 +6,23 @@ import {FlatList, TextInput} from 'react-native-gesture-handler';
import {useForceUpdate} from '../../views/ListsEditor';
import {db} from '../../../App';
import {useAppContext} from '../../provider/useAppContext';
+import {getElevation} from '../../utils/utils';
+import NavigationService from '../../services/NavigationService';
let refs = [];
-export const VaultDialog = ({visible, close}) => {
+export const VaultDialog = ({
+ openedToUnlock = false,
+ visible,
+ hasPassword = false,
+ note,
+ close = () => {},
+ perm = false,
+ timestamp = null,
+}) => {
const {colors} = useAppContext();
- const forceUpdate = useForceUpdate();
const [hidden, setHidden] = useState(false);
+ let password = null;
return (
<Modal
visible={visible}
@@ -28,9 +38,9 @@ export const VaultDialog = ({visible, close}) => {
}}>
<View
style={{
+ ...getElevation(5),
width: '80%',
maxHeight: 350,
- elevation: 5,
borderRadius: 5,
backgroundColor: colors.bg,
paddingHorizontal: ph,
@@ -46,12 +56,11 @@ export const VaultDialog = ({visible, close}) => {
<Text
style={{
color: colors.accent,
- fontFamily: WEIGHT.semibold,
- marginLeft: 10,
- fontSize: SIZE.lg,
- marginTop: -5,
+ fontFamily: WEIGHT.bold,
+ marginLeft: 5,
+ fontSize: SIZE.md,
}}>
- Lock Note
+ {openedToUnlock ? 'Unlock Note' : 'Lock Note'}
</Text>
</View>
@@ -64,12 +73,35 @@ export const VaultDialog = ({visible, close}) => {
marginTop: 10,
marginBottom: hidden ? 20 : 0,
}}>
- {hidden
+ {hasPassword
? 'Set password for all your locked notes.'
+ : openedToUnlock
+ ? 'Enter vault password to unlock note.'
: 'Do you want to lock this note?'}
</Text>
- {!hidden ? null : (
+ {openedToUnlock ? (
+ <TextInput
+ style={{
+ padding: pv - 5,
+ borderWidth: 1.5,
+ borderColor: colors.nav,
+ paddingHorizontal: ph,
+ borderRadius: 5,
+ marginTop: 10,
+ fontSize: SIZE.sm,
+ fontFamily: WEIGHT.regular,
+ }}
+ onChangeText={value => {
+ password = value;
+ }}
+ secureTextEntry
+ placeholder="Password"
+ placeholderTextColor={colors.icon}
+ />
+ ) : null}
+
+ {!hasPassword ? null : (
<View>
<TextInput
style={{
@@ -128,6 +160,31 @@ export const VaultDialog = ({visible, close}) => {
}}>
<TouchableOpacity
activeOpacity={opacity}
+ onPress={async () => {
+ if (openedToUnlock) {
+ console.log(note.dateCreated, password, perm);
+ let n = db.getNote(note.dateCreated);
+ let item;
+ if (n.content.cipher) {
+ console.log(n.content.cipher);
+
+ item = await db.unlockNote(n.dateCreated, password, perm);
+ console.log(item);
+ } else {
+ item = n;
+ }
+ if (!perm) {
+ NavigationService.navigate('Editor', {
+ note: item,
+ });
+ }
+ close(item, false);
+ } else {
+ await db.lockNote(note.dateCreated, 'password');
+
+ close(null, true);
+ }
+ }}
style={{
paddingVertical: pv,
paddingHorizontal: ph,
@@ -145,7 +202,7 @@ export const VaultDialog = ({visible, close}) => {
color: 'white',
fontSize: SIZE.sm,
}}>
- Lock
+ {openedToUnlock ? 'Unlock' : 'Lock'}
</Text>
</TouchableOpacity>
@@ -178,75 +235,3 @@ export const VaultDialog = ({visible, close}) => {
</Modal>
);
};
-
-const TopicItem = ({
- item,
- index,
- onFocus,
- onSubmit,
- onDelete,
- onChange,
- colors,
-}) => {
- const [focus, setFocus] = useState(true);
- const topicRef = ref => (refs[index] = ref);
-
- let text = item;
-
- return (
- <View
- style={{
- flexDirection: 'row',
- justifyContent: 'space-between',
- alignItems: 'center',
- borderRadius: 5,
- borderWidth: 1.5,
- borderColor: colors.nav,
- paddingHorizontal: ph,
- marginTop: 10,
- }}>
- <TextInput
- ref={topicRef}
- onFocus={() => {
- onFocus(index);
-
- setFocus(true);
- }}
- onBlur={() => {
- onSubmit(text, index, false);
- setFocus(false);
- }}
- onChangeText={value => {
- onChange(value, index);
-
- text = value;
- }}
- onSubmit={() => onSubmit(text, index, true)}
- blurOnSubmit
- style={{
- padding: pv - 5,
- paddingHorizontal: 0,
- fontSize: SIZE.sm,
- fontFamily: WEIGHT.regular,
- width: '90%',
- maxWidth: '90%',
- }}
- placeholder="Add a topic"
- placeholderTextColor={colors.icon}
- />
-
- <TouchableOpacity
- onPress={() => (!focus ? onDelete(index) : onSubmit(text, index, true))}
- style={{
- justifyContent: 'center',
- alignItems: 'center',
- }}>
- <Icon
- name={!focus ? 'minus' : 'plus'}
- size={SIZE.lg}
- color={colors.accent}
- />
- </TouchableOpacity>
- </View>
- );
-};
diff --git a/apps/mobile/src/utils/storage.js b/apps/mobile/src/utils/storage.js
index a7145a092..f585f3085 100644
--- a/apps/mobile/src/utils/storage.js
+++ b/apps/mobile/src/utils/storage.js
@@ -1,4 +1,6 @@
import AsyncStorage from '@react-native-community/async-storage';
+import {NativeModules, Platform} from 'react-native';
+var Aes = NativeModules.Aes;
async function read(key) {
return await AsyncStorage.getItem(key);
@@ -16,4 +18,30 @@ function clear() {
AsyncStorage.clear();
}
-export default {read, write, remove, clear};
+function encrypt(password, data) {
+ let key;
+ return Aes.pbkdf2('password', 'salt', 5000, 256).then(aes => {
+ key = aes;
+
+ return Aes.randomKey(32).then(iv => {
+ return Aes.encrypt(data, key, iv).then(cipher => ({
+ cipher,
+ iv,
+ }));
+ });
+ });
+}
+
+function decrypt(password, data) {
+ let key;
+ return Aes.pbkdf2(password, 'salt', 5000, 256).then(aes => {
+ key = aes;
+ console.log(data, key);
+ return Aes.decrypt(data.cipher, key, data.iv).then(e => {
+ console.log(e);
+ return e;
+ });
+ });
+}
+
+export default {read, write, remove, clear, encrypt, decrypt};
diff --git a/apps/mobile/src/views/Editor/index.js b/apps/mobile/src/views/Editor/index.js
index 120840b8b..e40434068 100755
--- a/apps/mobile/src/views/Editor/index.js
+++ b/apps/mobile/src/views/Editor/index.js
@@ -31,7 +31,8 @@ var content = null;
var title = null;
let titleRef;
let EditorWebView;
-
+let timer = null;
+let note = {};
const Editor = ({navigation}) => {
// Global State
const {colors} = useAppContext();
@@ -48,8 +49,10 @@ const Editor = ({navigation}) => {
favorite: false,
colors: [],
});
+
// VARIABLES
let updateInterval = null;
+ let lastTextChange = 0;
// FUNCTIONS
@@ -61,7 +64,7 @@ const Editor = ({navigation}) => {
}
};
- const saveNote = async (noteProps = {}) => {
+ const saveNote = async (noteProps = {}, lockNote = false) => {
if (!content) {
content = {
text: '',
@@ -76,37 +79,49 @@ const Editor = ({navigation}) => {
favorite: noteProps.favorite,
locked: noteProps.locked,
title,
- content,
+ content: {
+ text: content.text,
+ delta: content.delta,
+ },
dateCreated: timestamp,
});
+
+ if (lockNote && noteProps.locked) {
+ console.log(noteProps, timestamp);
+ db.lockNote(timestamp, 'password');
+ }
};
const onWebViewLoad = () => {
post(JSON.stringify(colors));
if (navigation.state.params && navigation.state.params.note) {
- let note = navigation.state.params.note;
- titleRef.setNativeProps({
- text: note.title,
- });
- title = note.title;
+ note = navigation.state.params.note;
- timestamp = note.dateCreated;
- post(JSON.stringify(note.content.delta));
- let props = {
- tags: note.tags,
- colors: note.colors,
- pinned: note.pinned,
- favorite: note.favorite,
- locked: note.locked,
- };
- setNoteProps({...props});
- console.log(note);
+ updateEditor();
}
+ };
- if (content && content.delta) {
- post(JSON.stringify(content.delta));
- }
+ const updateEditor = () => {
+ let props = {
+ tags: note.tags,
+ colors: note.colors,
+ pinned: note.pinned,
+ favorite: note.favorite,
+ locked: note.locked,
+ };
+ setNoteProps({...props});
+ post(JSON.stringify(note.content.delta));
+ setTimeout(() => {
+ title = note.title;
+ titleRef.setNativeProps({
+ text: title,
+ });
+ timestamp = note.dateCreated;
+ content = note.content;
+ }, 200);
+ console.log(note);
};
+
const onTitleTextChange = value => {
title = value;
};
@@ -227,7 +242,11 @@ const Editor = ({navigation}) => {
}}
onMessage={evt => {
if (evt.nativeEvent.data !== '') {
+ timer = null;
onChange(evt.nativeEvent.data);
+ timer = setTimeout(() => {
+ saveNote(noteProps, true);
+ }, 2000);
}
}}
/>
@@ -244,22 +263,26 @@ const Editor = ({navigation}) => {
return true;
});
return () => {
- title = null;
- timestamp = null;
- content = null;
handleBack.remove();
handleBack = null;
};
}, []);
useEffect(() => {
+ console.log('hello');
updateInterval = setInterval(async function() {
await saveNote(noteProps);
}, 2000);
+
return () => {
- saveNote(noteProps);
+ saveNote(noteProps, true);
clearInterval(updateInterval);
updateInterval = null;
+ console.log('yeah');
+ title = null;
+ content = null;
+ timer = null;
+ timestamp = null;
};
}, [noteProps]);
@@ -310,7 +333,20 @@ const Editor = ({navigation}) => {
width: sidebar ? '30%' : '0%',
opacity: sidebar ? 1 : 0,
}}>
- <EditorMenu />
+ <EditorMenu
+ hide={false}
+ noteProps={noteProps}
+ updateProps={props => {
+ setNoteProps(props);
+
+ console.log(props, noteProps);
+ }}
+ close={() => {
+ setTimeout(() => {
+ setOpen(args);
+ }, 500);
+ }}
+ />
</Animatable.View>
</View>
) : (
@@ -331,6 +367,9 @@ const Editor = ({navigation}) => {
openMenuOffset={w / 1.2}
menuPosition="right"
onChange={args => {
+ if (noteProps.locked) {
+ db.lockNote(timestamp, 'password');
+ }
setTimeout(() => {
setOpen(args);
}, 500);
@@ -339,15 +378,18 @@ const Editor = ({navigation}) => {
<EditorMenu
hide={false}
noteProps={noteProps}
+ note={note}
+ timestamp={timestamp}
updateProps={props => {
setNoteProps(props);
-
console.log(props, noteProps);
+ if (props.locked) {
+ saveNote(noteProps, true);
+ }
}}
- close={() => {
- setTimeout(() => {
- setOpen(args);
- }, 500);
+ update={item => {
+ note = item;
+ updateEditor();
}}
/>
}>
@@ -368,6 +410,7 @@ const Editor = ({navigation}) => {
setDialog(false);
}}
/>
+
{_renderEditor()}
</AnimatedSafeAreaView>
</SideMenu>
diff --git a/apps/mobile/src/views/Home/index.js b/apps/mobile/src/views/Home/index.js
index 3120276e0..461cd5dca 100755
--- a/apps/mobile/src/views/Home/index.js
+++ b/apps/mobile/src/views/Home/index.js
@@ -56,6 +56,7 @@ export const Home = ({navigation}) => {
const fetchNotes = () => {
allNotes = db.groupNotes();
setNotes([...allNotes]);
+ console.log(allNotes);
};
useEffect(() => {
diff --git a/apps/mobile/src/views/Trash/index.js b/apps/mobile/src/views/Trash/index.js
index 2ff31d0a6..e53a97610 100644
--- a/apps/mobile/src/views/Trash/index.js
+++ b/apps/mobile/src/views/Trash/index.js
@@ -1,49 +1,26 @@
import React, {useEffect, useState} from 'react';
import {
- ScrollView,
- View,
Text,
TouchableOpacity,
Dimensions,
- Image,
SafeAreaView,
- Platform,
FlatList,
} from 'react-native';
-import NavigationService from '../../services/NavigationService';
-import {
- COLOR_SCHEME,
- SIZE,
- br,
- ph,
- pv,
- opacity,
- FONT,
- WEIGHT,
- clearThemeUpdateListener,
- onThemeUpdate,
-} from '../../common/common';
+import {SIZE, ph, pv, opacity, WEIGHT} from '../../common/common';
import Icon from 'react-native-vector-icons/Feather';
-import {Reminder} from '../../components/Reminder';
-import {ListItem} from '../../components/ListItem';
import {Header} from '../../components/header';
import NoteItem from '../../components/NoteItem';
-import {useForceUpdate} from '../ListsEditor';
import {useAppContext} from '../../provider/useAppContext';
-import {db, DDS} from '../../../App';
+import {db} from '../../../App';
import {NotebookItem} from '../../components/NotebookItem';
-const w = Dimensions.get('window').width;
-const h = Dimensions.get('window').height;
-
export const Trash = ({navigation}) => {
const {colors} = useAppContext();
const [trash, setTrash] = useState([]);
+
useEffect(() => {
let allTrash = db.getTrash();
-
setTrash([...allTrash]);
- console.log(allTrash);
}, []);
return (
@@ -53,6 +30,7 @@ export const Trash = ({navigation}) => {
height: '100%',
}}>
<Header colors={colors} heading="Trash" canGoBack={false} menu={true} />
+
<FlatList
numColumns={1}
style={{