diff --git a/apps/expo/package.json b/apps/expo/package.json index f624fea4..4b7cd289 100644 --- a/apps/expo/package.json +++ b/apps/expo/package.json @@ -1,6 +1,6 @@ { "name": "expo-app", - "version": "1.3.0", + "version": "1.3.1", "main": "expo-router/entry", "private": true, "scripts": { diff --git a/apps/expo/utils/walletKeyStore.ts b/apps/expo/utils/walletKeyStore.ts index f56fa0f8..71f0b9a2 100644 --- a/apps/expo/utils/walletKeyStore.ts +++ b/apps/expo/utils/walletKeyStore.ts @@ -1,3 +1,4 @@ +import { agentDependencies } from '@credo-ts/react-native' import { ariesAskar } from '@hyperledger/aries-askar-react-native' import * as SecureStore from 'expo-secure-store' @@ -17,6 +18,11 @@ export const getSecureWalletKey = async (): Promise<{ // New method: raw wallet key let walletKey = await SecureStore.getItemAsync(STORE_KEY_RAW) + // Fix for a period when the key was stored as 'raw' so it has to be regenerated + if (walletKey === 'raw') { + await fixInvalidWalletKey() + walletKey = null + } if (walletKey) return { walletKey, keyDerivation: 'raw' } // TODO: rotate the old wallet key to a new raw key @@ -26,7 +32,20 @@ export const getSecureWalletKey = async (): Promise<{ // No wallet key found, generate new method: raw wallet key const newWalletKey = generateNewWalletKey() - await SecureStore.setItemAsync(STORE_KEY_RAW, newWalletKey.keyDerivation) + await SecureStore.setItemAsync(STORE_KEY_RAW, newWalletKey.walletKey) return newWalletKey } + +/** + * Fix for a period when the key was stored as 'raw' so the whole wallet needs to be regenerated because we don't have the original key anymore. + */ +const fixInvalidWalletKey = async () => { + const fileSystem = new agentDependencies.FileSystem() + + const walletPath = `${fileSystem.dataPath}/wallet` + + if (!(await fileSystem.exists(walletPath))) return + + await fileSystem.delete(walletPath) +}