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
feat: add biometric unlocking
ammarahm-ed0b6a0bd9f8d7
diff --git a/apps/mobile/src/components/ActionSheetComponent/index.js b/apps/mobile/src/components/ActionSheetComponent/index.jsindex 887a6efb0..38cfe4928 100644--- a/apps/mobile/src/components/ActionSheetComponent/index.js+++ b/apps/mobile/src/components/ActionSheetComponent/index.js@@ -429,34 +429,35 @@ export const ActionSheetComponent = ({};const onPressVaultButton = async () => {- await PremiumService.verify(- () => {- if (!note.id) return;+ if (!note.id) return;- if (note.locked) {- close('unlock');- } else {- db.vault- .add(note.id)- .then(() => {- sendNoteEditedEvent(note.id, false, true);+ if (note.locked) {+ close('unlock');+ } else {+ db.vault+ .add(note.id)+ .then(() => {+ sendNoteEditedEvent(note.id, false, true);+ close();+ })+ .catch(async (e) => {+ switch (e.message) {+ case db.vault.ERRORS.noVault:+ close('novault');+ break;+ case db.vault.ERRORS.vaultLocked:+ close('locked');+ break;+ case db.vault.ERRORS.wrongPassword:close();- })- .catch(async (e) => {- switch (e.message) {- case db.vault.ERRORS.noVault:- close('novault');- break;- case db.vault.ERRORS.vaultLocked:- close('locked');- break;- case db.vault.ERRORS.wrongPassword:- close();- break;- }- });- }- },+ break;+ }+ });+ }++ return;+ await PremiumService.verify(+ () => {},() => {eSendEvent(eShowGetPremium, {context: 'sheet',@@ -480,7 +481,6 @@ export const ActionSheetComponent = ({backgroundColor: colors.bg,paddingHorizontal: 0,}}>-{!note.id && !note.dateCreated ? (<Paragraph style={{marginVertical: 10}}>Start writing to save your note.diff --git a/apps/mobile/src/components/Button/index.js b/apps/mobile/src/components/Button/index.jsindex d93a460fe..036899964 100644--- a/apps/mobile/src/components/Button/index.js+++ b/apps/mobile/src/components/Button/index.js@@ -26,6 +26,12 @@ const BUTTON_TYPES = {text: 'accent',selected: 'bg',},++ shade: {+ primary: 'shade',+ text: 'accent',+ selected: 'shade',+ },};export const Button = ({diff --git a/apps/mobile/src/components/Dialog/BaseDialog.js b/apps/mobile/src/components/Dialog/BaseDialog.jsindex 8e90f3824..57aff4d17 100644--- a/apps/mobile/src/components/Dialog/BaseDialog.js+++ b/apps/mobile/src/components/Dialog/BaseDialog.js@@ -1,7 +1,10 @@import React from 'react';import {Animated,+ KeyboardAvoidingView,Modal,+ Platform,+ SafeAreaView,StyleSheet,TouchableOpacity,View,@@ -14,7 +17,7 @@ const BaseDialog = ({children,onShow,animation = 'fade',- premium+ premium,}) => {const [state, dispatch] = useTracked();const scaleValue = new Animated.Value(1);@@ -32,23 +35,26 @@ const BaseDialog = ({}}animationType={animation}onRequestClose={onRequestClose}>- <View- style={[- {- backgroundColor: state.colors.night- ? 'rgba(255,255,255,0.15)'- : 'rgba(0,0,0,0.3)',- },- styles.backdrop,- ]}>- <TouchableOpacity- onPress={onRequestClose}- style={styles.overlayButton}- />- {premium}+ <SafeAreaView>+ <KeyboardAvoidingView+ behavior={Platform.OS === 'ios' ? 'padding' : null}+ style={[+ {+ backgroundColor: state.colors.night+ ? 'rgba(255,255,255,0.15)'+ : 'rgba(0,0,0,0.3)',+ },+ styles.backdrop,+ ]}>+ <TouchableOpacity+ onPress={onRequestClose}+ style={styles.overlayButton}+ />+ {premium}- {children}- </View>+ {children}+ </KeyboardAvoidingView>+ </SafeAreaView></Modal>);};diff --git a/apps/mobile/src/components/VaultDialog/index.js b/apps/mobile/src/components/VaultDialog/index.jsindex 309047a98..03d721bf3 100644--- a/apps/mobile/src/components/VaultDialog/index.js+++ b/apps/mobile/src/components/VaultDialog/index.js@@ -1,7 +1,9 @@import React, {Component, createRef} from 'react';-import {KeyboardAvoidingView, View} from 'react-native';+import {TouchableOpacity, View} from 'react-native';import {TextInput} from 'react-native-gesture-handler';+import * as Keychain from 'react-native-keychain';import Share from 'react-native-share';+import Icon from 'react-native-vector-icons/MaterialCommunityIcons';import {Actions} from '../../provider/Actions';import {DDS} from '../../services/DeviceDetection';import {@@ -11,7 +13,6 @@ import {ToastEvent,} from '../../services/EventManager';import {getElevation} from '../../utils';-import {openEditorAnimation} from '../../utils/Animations';import {db} from '../../utils/DB';import {eCloseVaultDialog,@@ -19,14 +20,17 @@ import {eOpenVaultDialog,refreshNotesPage,} from '../../utils/Events';-import { tabBarRef } from '../../utils/Refs';+import {tabBarRef} from '../../utils/Refs';import {ph, pv, SIZE, WEIGHT} from '../../utils/SizeUtils';+import {Button} from '../Button';import BaseDialog from '../Dialog/base-dialog';import DialogButtons from '../Dialog/dialog-buttons';import DialogHeader from '../Dialog/dialog-header';import {updateEvent} from '../DialogManager/recievers';import Seperator from '../Seperator';import {Toast} from '../Toast';+import Paragraph from '../Typography/Paragraph';+const passInputRef = createRef();const confirmPassRef = createRef();@@ -45,6 +49,9 @@ export class VaultDialog extends Component {passwordsDontMatch: false,deleteNote: false,focusIndex: null,+ biometricUnlock: false,+ isBiometryAvailable: false,+ fingerprintAccess: false,};this.password = null;this.confirmPassword = null;@@ -60,25 +67,37 @@ export class VaultDialog extends Component {eUnSubscribeEvent(eCloseVaultDialog, this.close);}- open = ({- item,- novault,- locked,- permanant = false,- goToEditor = false,- share = false,- deleteNote = false,- }) => {+ /**+ *+ * @param {import('../../services/EventManager').vaultType} data+ */+ open = async (data) => {+ let biometry = await Keychain.getSupportedBiometryType();+ let available = false;+ let fingerprint = await Keychain.hasInternetCredentials('nn_vault');+ if (+ biometry === Keychain.BIOMETRY_TYPE.FINGERPRINT ||+ biometry === Keychain.BIOMETRY_TYPE.TOUCH_ID+ ) {+ available = true;+ }this.setState({visible: true,- note: item,- novault: novault,- locked,- permanant,- goToEditor,- share,- deleteNote,+ note: data.item,+ novault: data.novault,+ locked: data.locked,+ permanant: data.permanant,+ goToEditor: data.goToEditor,+ share: data.share,+ deleteNote: data.deleteNote,+ copyNote: data.copyNote,+ isBiometryAvailable: available,+ biometricUnlock: fingerprint,+ fingerprintAccess: data.fingerprintAccess,});+ if (fingerprint && this.state.novault && !this.state.fingerprintAccess) {+ await this._onPressFingerprintAuth();+ }};close = () => {@@ -139,6 +158,8 @@ export class VaultDialog extends Component {this._takeErrorAction(e);});}+ } else if (this.state.fingerprintEnroll) {+ this._enrollFingerprint();}};@@ -172,6 +193,7 @@ export class VaultDialog extends Component {.open(this.state.note.id, this.password).then(async (note) => {if (this.state.goToEditor) {+ console.log(note, 'NOTE');this._openInEditor(note);} else if (this.state.share) {this._shareNote(note);@@ -192,33 +214,59 @@ export class VaultDialog extends Component {ToastEvent.show('Note deleted', 'success', 'local');}+ async _enrollFingerprint() {+ try {+ await Keychain.setInternetCredentials(+ 'nn_vault',+ 'nn_vault',+ this.password,+ {+ accessControl:+ Keychain.ACCESS_CONTROL.BIOMETRY_ANY_OR_DEVICE_PASSCODE,+ authenticationPrompt: {cancel: null},+ accessible:+ Keychain.AUTHENTICATION_TYPE.DEVICE_PASSCODE_OR_BIOMETRICS,+ },+ );+ } catch (e) {+ this._takeErrorAction(e);+ }+ }+async _createVault() {await db.vault.create(this.password);+ if (this.state.biometricUnlock) {+ await this._enrollFingerprint();+ }if (this.state.note && this.state.note.id && !this.state.note.locked) {await db.vault.add(this.state.note.id);this.close();ToastEvent.show('Note added to vault', 'success', 'local');+ } else {+ eSendEvent('vaultUpdated');+ this.close();}}_permanantUnlock() {+ console.log('permanant unlock');db.vault.remove(this.state.note.id, this.password)- .then(() => {+ .then((r) => {+ console.log(r, 'unocking result');this.close();}).catch((e) => {+ console.log(e, 'unlocking error');this._takeErrorAction(e);});}_openInEditor(note) {eSendEvent(eOnLoadNote, note);-if (!DDS.isTab) {tabBarRef.current?.goToPage(1);}- ToastEvent.show('Note unlocked', 'success');this.close();}@@ -243,6 +291,26 @@ export class VaultDialog extends Component {}}+ _onPressFingerprintAuth = async () => {+ try {+ let credentials = await Keychain.getInternetCredentials('nn_vault', {+ accessControl: Keychain.ACCESS_CONTROL.BIOMETRY_ANY_OR_DEVICE_PASSCODE,+ authenticationType:+ Keychain.AUTHENTICATION_TYPE.DEVICE_PASSCODE_OR_BIOMETRICS,+ authenticationPrompt: {+ cancel: null,+ },+ });+ console.log(credentials.password);+ if (credentials?.password) {+ this.password = credentials.password;+ this.onPress();+ }+ } catch (e) {+ ToastEvent.show('Fingerprint Authentication Canceled', 'error', 'local');+ }+ };+render() {const {colors} = this.props;const {@@ -253,8 +321,7 @@ export class VaultDialog extends Component {novault,locked,permanant,- goToEditor,- share,+ biometricUnlock,} = this.state;return (@@ -268,7 +335,6 @@ export class VaultDialog extends Component {style={{...getElevation(5),width: DDS.isTab ? 350 : '80%',- maxHeight: 350,borderRadius: 5,backgroundColor: colors.bg,paddingHorizontal: ph,@@ -278,6 +344,8 @@ export class VaultDialog extends Component {title={!novault? 'Create Vault'+ : this.state.fingerprintAccess+ ? 'Fingerprint Access': note.locked? this.state.deleteNote? 'Delete note'@@ -291,6 +359,8 @@ export class VaultDialog extends Component {paragraph={!novault? 'Set a password to create vault'+ : this.state.fingerprintAccess+ ? 'Enter vault password to enable access to the vault with fingerprint': permanant? 'Enter password to remove note from vault.': note.locked@@ -308,35 +378,53 @@ export class VaultDialog extends Component {<Seperator />- {note.locked || locked || permanant ? (- <TextInput- ref={passInputRef}- style={{- padding: pv - 5,- borderBottomWidth: 1.5,- borderColor: wrongPassword- ? colors.errorText- : this.state.focusIndex === 0- ? colors.accent- : colors.nav,- paddingHorizontal: ph,- borderRadius: 5,- marginTop: 10,- fontSize: SIZE.sm,- fontFamily: WEIGHT.regular,- }}- onChangeText={(value) => {- this.password = value;- }}- onFocus={() => {- this.setState({- focusIndex: 0,- });- }}- secureTextEntry- placeholder="Password"- placeholderTextColor={colors.icon}- />+ {note.locked ||+ locked ||+ permanant ||+ this.state.fingerprintAccess ? (+ <>+ <TextInput+ ref={passInputRef}+ style={{+ padding: pv - 5,+ borderBottomWidth: 1.5,+ borderColor: wrongPassword+ ? colors.errorText+ : this.state.focusIndex === 0+ ? colors.accent+ : colors.nav,+ paddingHorizontal: ph,+ borderRadius: 5,+ marginTop: 10,+ fontSize: SIZE.sm,+ fontFamily: WEIGHT.regular,+ }}+ onChangeText={(value) => {+ this.password = value;+ }}+ onFocus={() => {+ this.setState({+ focusIndex: 0,+ });+ }}+ secureTextEntry+ placeholder="Password"+ placeholderTextColor={colors.icon}+ />+ <Seperator />+ {!this.state.biometricUnlock || !novault ? null : (+ <Button+ onPress={this._onPressFingerprintAuth}+ width="100%"+ title={+ !note.locked+ ? 'Lock with Fingerprint'+ : 'Unlock with Fingerprint'+ }+ type="shade"+ />+ )}+ </>) : null}{!novault ? (@@ -409,11 +497,53 @@ export class VaultDialog extends Component {</View>) : null}+ {!this.state.fingerprintAccess &&+ (!this.state.biometricUnlock || !novault) ? (+ <TouchableOpacity+ onPress={() => {+ this.setState({+ biometricUnlock: !biometricUnlock,+ });+ }}+ activeOpacity={0.7}+ style={{+ flexDirection: 'row',+ width: '100%',+ alignItems: 'center',+ height: 40,+ }}>+ <Icon+ size={SIZE.lg}+ color={biometricUnlock ? colors.accent : colors.icon}+ name={+ biometricUnlock+ ? 'check-circle-outline'+ : 'checkbox-blank-circle-outline'+ }+ />++ <Paragraph+ style={{+ fontSize: SIZE.sm,+ fontFamily: WEIGHT.regular,+ color: colors.pri,+ maxWidth: '90%',+ marginLeft: 10,+ }}>+ {!biometricUnlock+ ? 'Fingerprint Unlock Disabled'+ : 'Fingerprint Unlock Enabled'}+ </Paragraph>+ </TouchableOpacity>+ ) : null}+<DialogButtonsonPressNegative={this.close}onPressPositive={this.onPress}positiveTitle={- note.locked+ this.state.fingerprintAccess+ ? 'Enable'+ : note.locked? this.state.deleteNote? 'Delete': this.state.share@@ -421,6 +551,8 @@ export class VaultDialog extends Component {: this.state.goToEditor? 'Open': 'Unlock'+ : !note.id+ ? 'Create': 'Lock'}/>diff --git a/apps/mobile/src/services/EventManager.js b/apps/mobile/src/services/EventManager.jsindex c93afe92d..06e47e777 100644--- a/apps/mobile/src/services/EventManager.js+++ b/apps/mobile/src/services/EventManager.js@@ -11,26 +11,26 @@ export const eUnSubscribeEvent = (eventName, action) => {export const eSendEvent = (eventName, data) => {DeviceEventEmitter.emit(eventName, data);++};-export const openVault = (- item,- novault = false,- locked = false,- permanant = false,- editor = false,- share = false,- deleteNote = false,-) => {- eSendEvent(eOpenVaultDialog, {- item,- novault,- locked,- permanant,- goToEditor: editor,- share,- deleteNote,- });+/**+ * @typedef {Object} vaultType+ * @property {Object} item+ * @property {boolean} novault+ * @property {Object} locked+ * @property {Object} permanant+ * @property {Object} goToEditor+ * @property {Object} share+ * @property {Object} deleteNote+ * @property {Object} fingerprintAccess+ * @property {Object} copyNote+ * @param {vaultType} data+ */++export const openVault = (data) => {+ eSendEvent(eOpenVaultDialog, data);};export function sendNoteEditedEvent(id="",closed=false,noEdit=false) {diff --git a/apps/mobile/src/utils/Storage.js b/apps/mobile/src/utils/Storage.jsindex 6a4a26b5a..d62b46c6b 100644--- a/apps/mobile/src/utils/Storage.js+++ b/apps/mobile/src/utils/Storage.js@@ -67,7 +67,7 @@ async function deriveCryptoKey(name, data) {authenticationType:Keychain.AUTHENTICATION_TYPE.DEVICE_PASSCODE_OR_BIOMETRICS,accessControl: Keychain.ACCESS_CONTROL.DEVICE_PASSCODE,- rules:Keychain.SECURITY_RULES.AUTOMATIC_UPGRADE+ rules: Keychain.SECURITY_RULES.AUTOMATIC_UPGRADE,});return credentials.key;@@ -83,7 +83,7 @@ async function getCryptoKey(name) {authenticationType:Keychain.AUTHENTICATION_TYPE.DEVICE_PASSCODE_OR_BIOMETRICS,accessControl: Keychain.ACCESS_CONTROL.DEVICE_PASSCODE,- authenticationPrompt:{cancel:null}+ authenticationPrompt: {cancel: null},});return credentials.password;} else {