Skip to content

Commit

Permalink
fix: key generation (#98)
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Lanser <[email protected]>
  • Loading branch information
Tommylans authored Apr 11, 2024
1 parent 347d7b0 commit 572538b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apps/expo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "expo-app",
"version": "1.3.0",
"version": "1.3.1",
"main": "expo-router/entry",
"private": true,
"scripts": {
Expand Down
21 changes: 20 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 @@ -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
Expand All @@ -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)
}

0 comments on commit 572538b

Please sign in to comment.