diff --git a/apps/expo/utils/walletKeyStore.ts b/apps/expo/utils/walletKeyStore.ts index cb48f769..5dc31197 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' @@ -18,7 +19,10 @@ 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') walletKey = null + if (walletKey === 'raw') { + await fixInvalidWalletKey() + walletKey = null + } if (walletKey) return { walletKey, keyDerivation: 'raw' } // TODO: rotate the old wallet key to a new raw key @@ -32,3 +36,14 @@ export const getSecureWalletKey = async (): Promise<{ 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() + + if (!(await fileSystem.exists(fileSystem.dataPath))) return + + await fileSystem.delete(fileSystem.dataPath) +}