Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: key generation #98

Merged
merged 5 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Loading