Skip to content

Commit

Permalink
fix: Remove the whole wallet
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Lanser <[email protected]>
  • Loading branch information
Tommylans committed Apr 11, 2024
1 parent be00cc6 commit 881add7
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion apps/expo/utils/walletKeyStore.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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
Expand All @@ -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)
}

0 comments on commit 881add7

Please sign in to comment.