Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Refactor React Native bridge to Turbo Native Module (#771)

Leendert de Borstc94b5339b9b1
diff --git a/mobile-app/app/sync.tsx b/mobile-app/app/sync.tsx
index acf89dc16..ad2940cde 100644
--- a/mobile-app/app/sync.tsx
+++ b/mobile-app/app/sync.tsx
@@ -4,8 +4,8 @@ import { useAuth } from '@/context/AuthContext';
import { useVaultSync } from '@/hooks/useVaultSync';
import { ThemedView } from '@/components/ThemedView';
import LoadingIndicator from '@/components/LoadingIndicator';
-import { NativeModules } from 'react-native';
import { useDb } from '@/context/DbContext';
+import NativeVaultManager from '../specs/NativeCredentialManager';
export default function SyncScreen() {
const authContext = useAuth();
@@ -43,7 +43,7 @@ export default function SyncScreen() {
// Try to unlock with FaceID
try {
- const isInitialized = await NativeModules.CredentialManager.isVaultInitialized();
+ const isInitialized = await NativeCredentialManager.isVaultInitialized();
if (isInitialized) {
const isFaceIDEnabled = enabledAuthMethods.includes('faceid');
if (!isFaceIDEnabled) {
diff --git a/mobile-app/context/AuthContext.tsx b/mobile-app/context/AuthContext.tsx
index 4686f05ba..91618af15 100644
--- a/mobile-app/context/AuthContext.tsx
+++ b/mobile-app/context/AuthContext.tsx
@@ -1,10 +1,11 @@
import React, { createContext, useContext, useState, useEffect, useMemo, useCallback, useRef } from 'react';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { useDb } from './DbContext';
-import { NativeModules, AppState } from 'react-native';
+import { AppState } from 'react-native';
import { router, usePathname } from 'expo-router';
import { NavigationContainerRef, ParamListBase } from '@react-navigation/native';
import * as LocalAuthentication from 'expo-local-authentication';
+import NativeCredentialManager from '../specs/NativeCredentialManager';
// Create a navigation reference
export const navigationRef = React.createRef<NavigationContainerRef<ParamListBase>>();
@@ -51,7 +52,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
*/
const getEnabledAuthMethods = useCallback(async (): Promise<AuthMethod[]> => {
try {
- let methods = await NativeModules.CredentialManager.getAuthMethods() as AuthMethod[];
+ let methods = await NativeCredentialManager.getAuthMethods() as AuthMethod[];
// Check if Face ID is actually available despite being enabled
if (methods.includes('faceid')) {
const isEnrolled = await LocalAuthentication.isEnrolledAsync();
@@ -149,7 +150,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
// Update iOS credentials manager
try {
- await NativeModules.CredentialManager.setAuthMethods(methodsToSave);
+ await NativeCredentialManager.setAuthMethods(methodsToSave);
} catch (error) {
console.error('Failed to update iOS auth methods:', error);
}
@@ -179,8 +180,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
*/
const getAutoLockTimeout = async (): Promise<number> => {
try {
- const timeout = await NativeModules.CredentialManager.getAutoLockTimeout();
- return timeout;
+ return await NativeCredentialManager.getAutoLockTimeout();
} catch (error) {
console.error('Failed to get auto-lock timeout:', error);
return 0;
@@ -192,7 +192,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
*/
const setAutoLockTimeout = async (timeout: number) => {
try {
- await NativeModules.CredentialManager.setAutoLockTimeout(timeout);
+ await NativeCredentialManager.setAutoLockTimeout(timeout);
} catch (error) {
console.error('Failed to update iOS auto-lock timeout:', error);
}
@@ -200,8 +200,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
const isVaultUnlocked = async (): Promise<boolean> => {
try {
- const isUnlocked = await NativeModules.CredentialManager.isVaultUnlocked();
- return isUnlocked;
+ return await NativeCredentialManager.isVaultUnlocked();
} catch (error) {
console.error('Failed to check vault status:', error);
return false;
diff --git a/mobile-app/context/DbContext.tsx b/mobile-app/context/DbContext.tsx
index 26cd282d9..8f82a9ff4 100644
--- a/mobile-app/context/DbContext.tsx
+++ b/mobile-app/context/DbContext.tsx
@@ -1,8 +1,8 @@
import React, { createContext, useContext, useState, useEffect, useCallback, useMemo } from 'react';
import SqliteClient from '@/utils/SqliteClient';
import { VaultResponse } from '@/utils/types/webapi/VaultResponse';
-import { NativeModules } from 'react-native';
import { VaultMetadata } from '@/utils/types/messaging/VaultMetadata';
+import NativeCredentialManager from '../specs/NativeCredentialManager';
type DbContextType = {
sqliteClient: SqliteClient | null;
@@ -21,8 +21,6 @@ const DbContext = createContext<DbContextType | undefined>(undefined);
* DbProvider to provide the SQLite client to the app that components can use to make database queries.
*/
export const DbProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
- const credentialManager = NativeModules.CredentialManager;
-
/**
* SQLite client is initialized in constructor as it passes SQL queries to the native module.
*/
@@ -66,7 +64,7 @@ export const DbProvider: React.FC<{ children: React.ReactNode }> = ({ children }
const checkStoredVault = useCallback(async () => {
try {
- const isVaultInitialized = await credentialManager.isVaultInitialized();
+ const isVaultInitialized = await NativeCredentialManager.isVaultInitialized();
if (isVaultInitialized) {
// Get metadata from SQLite client
const metadata = await sqliteClient.getVaultMetadata();
@@ -106,7 +104,7 @@ export const DbProvider: React.FC<{ children: React.ReactNode }> = ({ children }
const clearDatabase = useCallback(() : void => {
setDbInitialized(false);
// TODO: implement actual vault clearing.
- credentialManager.clearVault();
+ NativeCredentialManager.clearVault();
}, []);
/**
@@ -114,7 +112,13 @@ export const DbProvider: React.FC<{ children: React.ReactNode }> = ({ children }
* and load it into memory.
*/
const unlockVault = useCallback(async () : Promise<boolean> => {
- return await credentialManager.unlockVault();
+ try {
+ await NativeCredentialManager.unlockVault();
+ return true;
+ } catch (error) {
+ console.error('Failed to unlock vault:', error);
+ return false;
+ }
}, []);
/**
diff --git a/mobile-app/ios/CredentialManager/CredentialManager.m b/mobile-app/ios/CredentialManager/CredentialManager.m
index edf8f8e3c..e69de29bb 100644
--- a/mobile-app/ios/CredentialManager/CredentialManager.m
+++ b/mobile-app/ios/CredentialManager/CredentialManager.m
@@ -1,50 +0,0 @@
-#import <React/RCTBridgeModule.h>
-
-@interface RCT_EXTERN_MODULE(CredentialManager, NSObject)
-RCT_EXTERN_METHOD(requiresMainQueueSetup)
-
-RCT_EXTERN_METHOD(addCredential:(NSString *)username password:(NSString *)password service:(NSString *)service)
-RCT_EXTERN_METHOD(getCredentials)
-RCT_EXTERN_METHOD(clearVault)
-// TODO: isvaultinitialized should be renamed to "isVaultExists" or something similar as we're just checking if the file exists.
-// The initializevault actually initializes the vault by decrypting it and loading the DB into memory.
-RCT_EXTERN_METHOD(isVaultInitialized:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
-RCT_EXTERN_METHOD(isVaultUnlocked:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
-RCT_EXTERN_METHOD(getVaultMetadata:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
-RCT_EXTERN_METHOD(unlockVault:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
-
-// New methods for SQLite database operations
-RCT_EXTERN_METHOD(storeDatabase:(NSString *)base64EncryptedDb
- metadata:(NSString *)metadata
- resolver:(RCTPromiseResolveBlock)resolve
- rejecter:(RCTPromiseRejectBlock)reject)
-
-RCT_EXTERN_METHOD(setAuthMethods:(NSArray *)authMethods
- resolver:(RCTPromiseResolveBlock)resolve
- rejecter:(RCTPromiseRejectBlock)reject)
-
-RCT_EXTERN_METHOD(storeEncryptionKey:(NSString *)base64EncryptionKey
- resolver:(RCTPromiseResolveBlock)resolve
- rejecter:(RCTPromiseRejectBlock)reject)
-
-RCT_EXTERN_METHOD(executeQuery:(NSString *)query
- params:(NSArray *)params
- resolver:(RCTPromiseResolveBlock)resolve
- rejecter:(RCTPromiseRejectBlock)reject)
-
-RCT_EXTERN_METHOD(executeUpdate:(NSString *)query
- params:(NSArray *)params
- resolver:(RCTPromiseResolveBlock)resolve
- rejecter:(RCTPromiseRejectBlock)reject)
-
-RCT_EXTERN_METHOD(setAutoLockTimeout:(NSInteger)timeout
- resolver:(RCTPromiseResolveBlock)resolve
- rejecter:(RCTPromiseRejectBlock)reject)
-
-RCT_EXTERN_METHOD(getAutoLockTimeout:(RCTPromiseResolveBlock)resolve
- rejecter:(RCTPromiseRejectBlock)reject)
-
-RCT_EXTERN_METHOD(getAuthMethods:(RCTPromiseResolveBlock)resolve
- rejecter:(RCTPromiseRejectBlock)reject)
-
-@end
diff --git a/mobile-app/ios/CredentialManager/CredentialManager.swift b/mobile-app/ios/CredentialManager/CredentialManager.swift
index 5004f3843..2813bbdb9 100644
--- a/mobile-app/ios/CredentialManager/CredentialManager.swift
+++ b/mobile-app/ios/CredentialManager/CredentialManager.swift
@@ -3,7 +3,7 @@ import SQLite
import LocalAuthentication
@objc(CredentialManager)
-class CredentialManager: NSObject {
+public class CredentialManager: NSObject {
private let credentialStore = SharedCredentialStore.shared
override init() {
diff --git a/mobile-app/ios/NativeCredentialManager/RCTNativeCredentialManager.h b/mobile-app/ios/NativeCredentialManager/RCTNativeCredentialManager.h
new file mode 100644
index 000000000..641b25dda
--- /dev/null
+++ b/mobile-app/ios/NativeCredentialManager/RCTNativeCredentialManager.h
@@ -0,0 +1,17 @@
+//
+// RCTNativeCredentialManager.h
+// AliasVault
+//
+// Created by Leendert de Borst on 24/04/2025.
+//
+
+#import <Foundation/Foundation.h>
+#import <NativeCredentialManagerSpec/NativeCredentialManagerSpec.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface RCTNativeCredentialManager : NSObject <NativeCredentialManagerSpec>
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/mobile-app/ios/NativeCredentialManager/RCTNativeCredentialManager.mm b/mobile-app/ios/NativeCredentialManager/RCTNativeCredentialManager.mm
new file mode 100644
index 000000000..e05066351
--- /dev/null
+++ b/mobile-app/ios/NativeCredentialManager/RCTNativeCredentialManager.mm
@@ -0,0 +1,98 @@
+//
+// RCTNativeCredentialManager.m
+// AliasVault
+//
+// Created by Leendert de Borst on 24/04/2025.
+//
+
+#import "RCTNativeCredentialManager.h"
+#import <ExpoModulesCore-Swift.h>
+#import "AliasVault-Swift.h"
+
+@interface RCTNativeCredentialManager () <NativeCredentialManagerSpec>
+@end
+
+@implementation RCTNativeCredentialManager {
+ CredentialManager *credentialManager;
+}
+
++ (NSString *)moduleName {
+ return @"NativeCredentialManager";
+}
+
+- (id) init {
+ if (self = [super init]) {
+ credentialManager = [CredentialManager new];
+ }
+ return self;
+}
+
+- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const facebook::react::ObjCTurboModule::InitParams &)params {
+ return std::make_shared<facebook::react::NativeCredentialManagerSpecJSI>(params);
+}
+
+- (void)addCredential:(NSString *)username password:(NSString *)password service:(NSString *)service resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
+ [credentialManager addCredential:username password:password service:service];
+}
+
+- (void)clearVault {
+ [credentialManager clearVault];
+}
+
+- (void)executeQuery:(NSString *)query params:(NSArray *)params resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
+ [credentialManager executeQuery:query params:params resolver:resolve rejecter:reject];
+}
+
+- (void)executeUpdate:(NSString *)query params:(NSArray *)params resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
+ [credentialManager executeUpdate:query params:params resolver:resolve rejecter:reject];
+}
+
+- (void)getAuthMethods:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
+ [credentialManager getAuthMethods:resolve rejecter:reject];
+}
+
+- (void)getAutoLockTimeout:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
+ [credentialManager getAutoLockTimeout:resolve rejecter:reject];
+}
+
+- (void)getCredentials:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
+ [credentialManager getCredentials];
+}
+
+- (void)getVaultMetadata:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
+ [credentialManager getVaultMetadata:resolve rejecter:reject];
+}
+
+- (void)isVaultInitialized:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
+ [credentialManager isVaultInitialized:resolve rejecter:reject];
+}
+
+- (void)isVaultUnlocked:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
+ [credentialManager isVaultUnlocked:resolve rejecter:reject];
+}
+
+- (void)setAuthMethods:(NSArray *)authMethods resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
+ [credentialManager setAuthMethods:authMethods resolver:resolve rejecter:reject];
+}
+
+- (void)setAutoLockTimeout:(double)timeout resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
+ [credentialManager setAutoLockTimeout:timeout resolver:resolve rejecter:reject];
+}
+
+- (void)storeDatabase:(NSString *)base64EncryptedDb metadata:(NSString *)metadata resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
+ [credentialManager storeDatabase:base64EncryptedDb metadata:metadata resolver:resolve rejecter:reject];
+}
+
+- (void)storeEncryptionKey:(NSString *)base64EncryptionKey resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
+ [credentialManager storeEncryptionKey:base64EncryptionKey resolver:resolve rejecter:reject];
+}
+
+- (void)unlockVault:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
+ [credentialManager unlockVault:resolve rejecter:reject];
+}
+
+- (void)clearVault:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
+ [credentialManager clearVault];
+}
+
+@end
diff --git a/mobile-app/ios/Podfile b/mobile-app/ios/Podfile
index 06ba3e0dc..6cc10b19a 100644
--- a/mobile-app/ios/Podfile
+++ b/mobile-app/ios/Podfile
@@ -17,6 +17,7 @@ target 'AliasVault' do
use_expo_modules!
pod 'KeychainAccess', '~> 4.2.2'
pod 'SQLite.swift', '~> 0.14.0'
+ pod 'ExpoModulesCore', :path => '../node_modules/expo-modules-core'
if ENV['EXPO_USE_COMMUNITY_AUTOLINKING'] == '1'
config_command = ['node', '-e', "process.argv=['', '', 'config'];require('@react-native-community/cli').run()"];
@@ -70,4 +71,4 @@ end
target 'Autofill' do
pod 'KeychainAccess', '~> 4.2.2'
pod 'SQLite.swift', '~> 0.14.0'
-end
+end
\ No newline at end of file
diff --git a/mobile-app/ios/Podfile.lock b/mobile-app/ios/Podfile.lock
index c7b901041..b11951ed0 100644
--- a/mobile-app/ios/Podfile.lock
+++ b/mobile-app/ios/Podfile.lock
@@ -2588,7 +2588,7 @@ SPEC CHECKSUMS:
React-runtimescheduler: 8ec34cc885281a34696ea16c4fd86892d631f38d
React-timing: 331cbf9f2668c67faddfd2e46bb7f41cbd9320b9
React-utils: ed818f19ab445000d6b5c4efa9d462449326cc9f
- ReactCodegen: f853a20cc9125c5521c8766b4b49375fec20648b
+ ReactCodegen: de51c29eefd89f0132898abf5b025c5fa467c560
ReactCommon: 300d8d9c5cb1a6cd79a67cf5d8f91e4d477195f9
RNArgon2: 708e188b7a4d4ec8baf62463927c47abef453a94
RNCAsyncStorage: ab0ad9a78ead8b9f143f0238a5aa535777b12e65
@@ -2600,6 +2600,6 @@ SPEC CHECKSUMS:
SQLite.swift: 2992550ebf3c5b268bf4352603e3df87d2a4ed72
Yoga: feb4910aba9742cfedc059e2b2902e22ffe9954a
-PODFILE CHECKSUM: 71411f71c96e4b6a3db40174f3834328e5a380b9
+PODFILE CHECKSUM: 4913b1bd42fe318bcd86889f21584aef9eedc0da
COCOAPODS: 1.16.2
diff --git a/mobile-app/ios/aliasvault.xcodeproj/project.pbxproj b/mobile-app/ios/aliasvault.xcodeproj/project.pbxproj
index 07347af65..5c6572c6d 100644
--- a/mobile-app/ios/aliasvault.xcodeproj/project.pbxproj
+++ b/mobile-app/ios/aliasvault.xcodeproj/project.pbxproj
@@ -21,6 +21,8 @@
CE26D6912DA7FCD2006DC04D /* SharedCredentialStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE26D68D2DA7FCD2006DC04D /* SharedCredentialStore.swift */; };
CE9A55EA2DA8039F00CB0A4C /* Credential.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE9A55E92DA8039F00CB0A4C /* Credential.swift */; };
CE9A55EB2DA8039F00CB0A4C /* Credential.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE9A55E92DA8039F00CB0A4C /* Credential.swift */; };
+ CE9A58FC2DBA982100CB0A4C /* RCTNativeCredentialManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = CE9A58FB2DBA982100CB0A4C /* RCTNativeCredentialManager.mm */; };
+ CE9A5A022DBAAE5000CB0A4C /* RCTNativeCredentialManager.h in Sources */ = {isa = PBXBuildFile; fileRef = CE9A58FA2DBA982100CB0A4C /* RCTNativeCredentialManager.h */; };
CEE909802DA548C7008D568F /* AuthenticationServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CEE9097F2DA548C7008D568F /* AuthenticationServices.framework */; };
CEE9098B2DA548C7008D568F /* Autofill.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = CEE9097E2DA548C7008D568F /* Autofill.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
D6E19ADE0A608FA46984C60D /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = BA88D6CB4FD656C7180FE9F7 /* PrivacyInfo.xcprivacy */; };
@@ -71,6 +73,8 @@
CE26D68C2DA7FCD2006DC04D /* CredentialManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CredentialManager.swift; sourceTree = "<group>"; };
CE26D68D2DA7FCD2006DC04D /* SharedCredentialStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SharedCredentialStore.swift; sourceTree = "<group>"; };
CE9A55E92DA8039F00CB0A4C /* Credential.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Credential.swift; sourceTree = "<group>"; };
+ CE9A58FA2DBA982100CB0A4C /* RCTNativeCredentialManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RCTNativeCredentialManager.h; sourceTree = "<group>"; };
+ CE9A58FB2DBA982100CB0A4C /* RCTNativeCredentialManager.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = RCTNativeCredentialManager.mm; sourceTree = "<group>"; };
CEE9097E2DA548C7008D568F /* Autofill.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = Autofill.appex; sourceTree = BUILT_PRODUCTS_DIR; };
CEE9097F2DA548C7008D568F /* AuthenticationServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AuthenticationServices.framework; path = System/Library/Frameworks/AuthenticationServices.framework; sourceTree = SDKROOT; };
D3105EF00E7F103157A21E09 /* libPods-AliasVault.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-AliasVault.a"; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -163,6 +167,7 @@
83CBB9F61A601CBA00E9B192 = {
isa = PBXGroup;
children = (
+ CE9A58F92DBA97D500CB0A4C /* NativeCredentialManager */,
13B07FAE1A68108700A75B9A /* AliasVault */,
CEE909812DA548C7008D568F /* Autofill */,
CE26D68A2DA7FCB5006DC04D /* CredentialManager */,
@@ -214,6 +219,15 @@
path = CredentialManager;
sourceTree = "<group>";
};
+ CE9A58F92DBA97D500CB0A4C /* NativeCredentialManager */ = {
+ isa = PBXGroup;
+ children = (
+ CE9A58FA2DBA982100CB0A4C /* RCTNativeCredentialManager.h */,
+ CE9A58FB2DBA982100CB0A4C /* RCTNativeCredentialManager.mm */,
+ );
+ path = NativeCredentialManager;
+ sourceTree = "<group>";
+ };
D65327D7A22EEC0BE12398D9 /* Pods */ = {
isa = PBXGroup;
children = (
@@ -489,11 +503,13 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ CE9A5A022DBAAE5000CB0A4C /* RCTNativeCredentialManager.h in Sources */,
13B07FBC1A68108700A75B9A /* AppDelegate.mm in Sources */,
CE26D68E2DA7FCD2006DC04D /* SharedCredentialStore.swift in Sources */,
CE26D68F2DA7FCD2006DC04D /* CredentialManager.swift in Sources */,
CE26D6902DA7FCD2006DC04D /* CredentialManager.m in Sources */,
13B07FC11A68108700A75B9A /* main.m in Sources */,
+ CE9A58FC2DBA982100CB0A4C /* RCTNativeCredentialManager.mm in Sources */,
B18059E884C0ABDD17F3DC3D /* ExpoModulesProvider.swift in Sources */,
CE9A55EA2DA8039F00CB0A4C /* Credential.swift in Sources */,
E8FD7000523F4549908941A2 /* noop-file.swift in Sources */,
diff --git a/mobile-app/package-lock.json b/mobile-app/package-lock.json
index 2c622785a..81b181485 100644
--- a/mobile-app/package-lock.json
+++ b/mobile-app/package-lock.json
@@ -22,6 +22,7 @@
"expo-haptics": "~14.0.1",
"expo-linking": "~7.0.5",
"expo-local-authentication": "~15.0.2",
+ "expo-modules-core": "~2.2.3",
"expo-router": "~4.0.20",
"expo-sharing": "~13.0.1",
"expo-splash-screen": "~0.29.22",
diff --git a/mobile-app/package.json b/mobile-app/package.json
index 8cbfb2d88..f028d1fad 100644
--- a/mobile-app/package.json
+++ b/mobile-app/package.json
@@ -14,6 +14,19 @@
"jest": {
"preset": "jest-expo"
},
+ "codegenConfig": {
+ "name": "NativeCredentialManagerSpec",
+ "type": "modules",
+ "jsSrcsDir": "specs",
+ "android": {
+ "javaPackageName": "com.aliasvault.credentialmanager"
+ },
+ "ios": {
+ "modulesProvider": {
+ "NativeCredentialManager": "RCTCredentialManager"
+ }
+ }
+ },
"dependencies": {
"@expo/vector-icons": "^14.0.2",
"@react-native-async-storage/async-storage": "^2.1.2",
@@ -54,7 +67,8 @@
"react-native-toast-message": "^2.2.1",
"react-native-web": "~0.19.13",
"react-native-webview": "13.12.5",
- "secure-remote-password": "github:LinusU/secure-remote-password#73e5f732b6ca0cdbdc19da1a0c5f48cdbad2cbf0"
+ "secure-remote-password": "github:LinusU/secure-remote-password#73e5f732b6ca0cdbdc19da1a0c5f48cdbad2cbf0",
+ "expo-modules-core": "~2.2.3"
},
"devDependencies": {
"@babel/core": "^7.25.2",
diff --git a/mobile-app/specs/NativeCredentialManager.ts b/mobile-app/specs/NativeCredentialManager.ts
new file mode 100644
index 000000000..f167a040d
--- /dev/null
+++ b/mobile-app/specs/NativeCredentialManager.ts
@@ -0,0 +1,31 @@
+import type {TurboModule} from 'react-native';
+import {TurboModuleRegistry} from 'react-native';
+
+export interface Spec extends TurboModule {
+ // Basic credential operations
+ addCredential(username: string, password: string, service: string): Promise<void>;
+ getCredentials(): Promise<{ credentials: Array<{ username: string; password: string; service: string }> }>;
+ clearVault(): Promise<void>;
+
+ // Vault state management
+ isVaultInitialized(): Promise<boolean>;
+ isVaultUnlocked(): Promise<boolean>;
+ getVaultMetadata(): Promise<any>;
+ unlockVault(): Promise<boolean>;
+
+ // Database operations
+ storeDatabase(base64EncryptedDb: string, metadata: string): Promise<void>;
+ setAuthMethods(authMethods: string[]): Promise<void>;
+ storeEncryptionKey(base64EncryptionKey: string): Promise<void>;
+
+ // SQL operations
+ executeQuery(query: string, params: any[]): Promise<any[]>;
+ executeUpdate(query: string, params: any[]): Promise<number>;
+
+ // Auto-lock settings
+ setAutoLockTimeout(timeout: number): Promise<void>;
+ getAutoLockTimeout(): Promise<number>;
+ getAuthMethods(): Promise<string[]>;
+}
+
+export default TurboModuleRegistry.getEnforcing<Spec>('NativeCredentialManager');
\ No newline at end of file
diff --git a/mobile-app/utils/SqliteClient.tsx b/mobile-app/utils/SqliteClient.tsx
index 96c0c075d..6d0bb7eef 100644
--- a/mobile-app/utils/SqliteClient.tsx
+++ b/mobile-app/utils/SqliteClient.tsx
@@ -4,6 +4,8 @@ import { EncryptionKey } from './types/EncryptionKey';
import { TotpCode } from './types/TotpCode';
import { PasswordSettings } from './types/PasswordSettings';
import { VaultMetadata } from './types/messaging/VaultMetadata';
+import NativeCredentialManager from '../specs/NativeCredentialManager';
+
type SQLiteBindValue = string | number | null | Uint8Array;
@@ -11,15 +13,13 @@ type SQLiteBindValue = string | number | null | Uint8Array;
* Client for interacting with the SQLite database through native code.
*/
class SqliteClient {
- private credentialManager = NativeModules.CredentialManager;
-
/**
* Store the encrypted database via the native code implementation.
*/
async storeEncryptedDatabase(base64EncryptedDb: string, metadata: VaultMetadata): Promise<void> {
try {
const metadataJson = JSON.stringify(metadata);
- await this.credentialManager.storeDatabase(base64EncryptedDb, metadataJson);
+ await NativeCredentialManager.storeDatabase(base64EncryptedDb, metadataJson);
} catch (error) {
console.error('Error initializing SQLite database:', error);
throw error;
@@ -33,7 +33,7 @@ class SqliteClient {
*/
public async getVaultMetadata(): Promise<VaultMetadata> {
try {
- const metadataJson = await this.credentialManager.getVaultMetadata();
+ const metadataJson = await NativeCredentialManager.getVaultMetadata();
if (!metadataJson) {
throw new Error('No vault metadata found in native storage');
}
@@ -54,7 +54,7 @@ class SqliteClient {
*/
public async storeEncryptionKey(base64EncryptionKey: string): Promise<void> {
try {
- await this.credentialManager.storeEncryptionKey(base64EncryptionKey);
+ await NativeCredentialManager.storeEncryptionKey(base64EncryptionKey);
} catch (error) {
console.error('Error storing encryption key:', error);
throw error;
@@ -66,7 +66,7 @@ class SqliteClient {
*/
public async executeQuery<T>(query: string, params: SQLiteBindValue[] = []): Promise<T[]> {
try {
- const results = await this.credentialManager.executeQuery(query, params);
+ const results = await NativeCredentialManager.executeQuery(query, params);
return results as T[];
} catch (error) {
console.error('Error executing query:', error);
@@ -79,7 +79,7 @@ class SqliteClient {
*/
public async executeUpdate(query: string, params: SQLiteBindValue[] = []): Promise<number> {
try {
- const result = await this.credentialManager.executeUpdate(query, params);
+ const result = await NativeCredentialManager.executeUpdate(query, params);
return result as number;
} catch (error) {
console.error('Error executing update:', error);
@@ -288,10 +288,6 @@ class SqliteClient {
* @returns The number of rows modified
*/
public async createCredential(credential: Credential): Promise<number> {
- if (!this.credentialManager) {
- throw new Error('CredentialManager not initialized');
- }
-
try {
await this.executeUpdate('BEGIN TRANSACTION');
@@ -393,10 +389,6 @@ class SqliteClient {
* Returns null if no migrations are found.
*/
public async getDatabaseVersion(): Promise<string | null> {
- if (!this.credentialManager) {
- throw new Error('CredentialManager not initialized');
- }
-
try {
// Query the migrations history table for the latest migration
const results = await this.executeQuery<{ MigrationId: string }>(`
@@ -431,10 +423,6 @@ class SqliteClient {
* @returns Array of TotpCode objects
*/
public async getTotpCodesForCredential(credentialId: string): Promise<TotpCode[]> {
- if (!this.credentialManager) {
- throw new Error('CredentialManager not initialized');
- }
-
try {
/*
* Check if TotpCodes table exists (for backward compatibility).
@@ -468,10 +456,6 @@ class SqliteClient {
* @returns True if the table exists, false otherwise
*/
private async tableExists(tableName: string): Promise<boolean> {
- if (!this.credentialManager) {
- throw new Error('CredentialManager not initialized');
- }
-
try {
const query = `
SELECT name FROM sqlite_master