diff --git a/src/models/helpers/setupRootStore.ts b/src/models/helpers/setupRootStore.ts index aad423e..d6ed19e 100644 --- a/src/models/helpers/setupRootStore.ts +++ b/src/models/helpers/setupRootStore.ts @@ -54,20 +54,21 @@ export async function setupRootStore(rootStore: RootStore) { try { await MMKVStorage.initEncryption() } catch (e: any) { + log.error('[setupRootStore]', 'Encryption init failed', {error: e}) + if (e && typeof e === 'object') { - const errString = JSON.stringify(e) + const errString = JSON.stringify(e) - const isCancellPressed = errString.includes('code: 10') - const isBackPressed = errString.includes('code: 13') - const isIOSCancel = 'code' in e && String(e.code) === '-128' + const isBackPressed = errString.includes('code: 10') + const isCancellPressed = errString.includes('code: 13') + const isIOSCancel = 'code' in e && String(e.code) === '-128' // In case user cancels / fails the fingerprint auth, empty app state is loaded. // If a user updates the empty app state, it is stored unencrypted and returned after restart as primary one, // making encrypted data inaccessible or later overwritten. // Therefore this ugly app exit on unsuccessful auth. - if(isCancellPressed || isBackPressed || isIOSCancel) { - log.error('[setupRootStore]', 'Exiting app on failed auth', {error: e}) + if(isCancellPressed || isBackPressed || isIOSCancel) { RNExitApp.exitApp() } } diff --git a/src/screens/ContactsScreen.tsx b/src/screens/ContactsScreen.tsx index 7a79e4c..e0a57b6 100644 --- a/src/screens/ContactsScreen.tsx +++ b/src/screens/ContactsScreen.tsx @@ -34,7 +34,7 @@ export const ContactsScreen: FC = observer(function Contact try { log.trace(walletProfileStore) - if(!walletProfileStore.pubkey || !walletProfileStore.picture) { // pic needed + if(!walletProfileStore.pubkey || !walletProfileStore.picture) { // pic check needed to be sure profile does not exists on the server // create random name, NIP05 identifier, random picture and sharable profile // announce new profile to the added default public and minibits relays const walletId = userSettingsStore.walletId @@ -44,11 +44,11 @@ export const ContactsScreen: FC = observer(function Contact } catch(e: any) { log.error(e.name, e.message) - // in case we somehow hit the existing name we silently retry - if(e.name && e.name === Err.ALREADY_EXISTS_ERROR) { + // in case we somehow hit the existing name we silently retry TBD + /* if(e.name && e.name === Err.ALREADY_EXISTS_ERROR) { const randomName = getRandomUsername() await walletProfileStore.create(randomName as string) - } + } */ return false // silent } diff --git a/src/services/keyChain.ts b/src/services/keyChain.ts index e3c189e..620fea7 100644 --- a/src/services/keyChain.ts +++ b/src/services/keyChain.ts @@ -359,7 +359,7 @@ const loadMmkvEncryptionKey = async function (): Promise { log.trace('[loadMmkvEncryptionKey]', 'Did not find existing encryptionKey in the KeyChain.') return undefined } catch (e: any) { - throw new AppError(Err.KEYCHAIN_ERROR, e.message) + throw new AppError(Err.KEYCHAIN_ERROR, e.message, {caller: 'loadMmkvEncryptionKey', message: e.message}) } } diff --git a/src/services/mmkvStorage.ts b/src/services/mmkvStorage.ts index 2876326..1adc4ca 100644 --- a/src/services/mmkvStorage.ts +++ b/src/services/mmkvStorage.ts @@ -8,8 +8,12 @@ let _encryptionKey: string | undefined const initEncryption = async function (): Promise { if (!_encryptionKey) { - _encryptionKey = await getOrCreateEncryptionKey() - getInstance() // Instantiate the MMKV instance with the encryption key + try { + _encryptionKey = await getOrCreateEncryptionKey() + getInstance() // Instantiate the MMKV instance with the encryption key + } catch(e: any) { + throw e + } } } @@ -38,7 +42,11 @@ const getOrCreateEncryptionKey = async function (): Promise { let key: string | null = null - key = (await KeyChain.loadMmkvEncryptionKey()) as string + try { + key = (await KeyChain.loadMmkvEncryptionKey()) as string + } catch (e: any) { + throw e + } if (!key) { key = KeyChain.generateMmkvEncryptionKey() as string