Skip to content

Commit

Permalink
feat: Added secure store for the wallet key
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Lanser <tom@devv.nl>
  • Loading branch information
Tommylans committed Jun 14, 2023
1 parent eddd16d commit a3a6623
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
12 changes: 11 additions & 1 deletion apps/expo/app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { Stack } from 'expo-router'
import * as SplashScreen from 'expo-splash-screen'
import { useEffect, useState } from 'react'

import { getSecureWalletKey } from '../utils/walletKeyStore'

void SplashScreen.preventAutoHideAsync()

export default function HomeLayout() {
Expand All @@ -27,7 +29,15 @@ export default function HomeLayout() {
useEffect(() => {
if (agent) return

void initializeAgent().then((agent) => setAgent(agent))
const startAgent = async () => {
const walletKey = await getSecureWalletKey()

const agent = await initializeAgent(walletKey)

setAgent(agent)
}

void startAgent()
}, [])

// Hide splash screen when agent and fonts are loaded
Expand Down
1 change: 1 addition & 0 deletions apps/expo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"expo-linear-gradient": "^12.1.2",
"expo-linking": "^4.0.1",
"expo-router": "^1.4.3",
"expo-secure-store": "^12.1.1",
"expo-splash-screen": "~0.18.2",
"expo-status-bar": "^1.4.4",
"expo-system-ui": "~2.2.1",
Expand Down
18 changes: 18 additions & 0 deletions apps/expo/utils/walletKeyStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { uuid } from '@aries-framework/core/build/utils/uuid'
import * as SecureStore from 'expo-secure-store'

const STORE_KEY = 'wallet-key' as const

const generateNewWalletKey = (): string => {
return uuid()
}

export const getSecureWalletKey = async (): Promise<string> => {
const walletKey = await SecureStore.getItemAsync(STORE_KEY)
if (walletKey) return walletKey

const newWalletKey = generateNewWalletKey()
await SecureStore.setItemAsync(STORE_KEY, newWalletKey)

return newWalletKey
}
7 changes: 3 additions & 4 deletions packages/agent/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ import { useAgent as useAgentLib } from '@aries-framework/react-hooks'
import { agentDependencies } from '@aries-framework/react-native'
import { ariesAskar } from '@hyperledger/aries-askar-react-native'

export const initializeAgent = async () => {
export const initializeAgent = async (walletKey: string) => {
const agent = new Agent({
dependencies: agentDependencies,
config: {
label: 'Paradym Wallet',
// FIXME: AW-58: Store wallet key in secure enclave
walletConfig: {
id: 'paradym-wallet',
key: 'a5fc4d22-5e0c-434b-abb5-c091815cf279',
id: 'paradym-wallet-secure',
key: walletKey,
},
autoUpdateStorageOnStartup: true,
logger: new ConsoleLogger(LogLevel.debug),
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8044,6 +8044,7 @@ __metadata:
expo-linear-gradient: ^12.1.2
expo-linking: ^4.0.1
expo-router: ^1.4.3
expo-secure-store: ^12.1.1
expo-splash-screen: ~0.18.2
expo-status-bar: ^1.4.4
expo-system-ui: ~2.2.1
Expand Down Expand Up @@ -8349,6 +8350,15 @@ __metadata:
languageName: node
linkType: hard

"expo-secure-store@npm:^12.1.1":
version: 12.3.0
resolution: "expo-secure-store@npm:12.3.0"
peerDependencies:
expo: "*"
checksum: 37b0b95c80731bbd17ea62e9b3c15e7ad059f23238d69cac145d2094c054efc8ae08f5d8cc48ca4107ca9e23d7c61231eb43493dff984b1a447acd34cb3ea090
languageName: node
linkType: hard

"expo-splash-screen@npm:*, expo-splash-screen@npm:~0.18.2":
version: 0.18.2
resolution: "expo-splash-screen@npm:0.18.2"
Expand Down

0 comments on commit a3a6623

Please sign in to comment.