Skip to content

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

Remove unused native add methods (#771)

Leendert de Borste7e7bc5f87b2
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/credentialmanager/CredentialManagerModule.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/credentialmanager/CredentialManagerModule.kt
index 267de80df..591050b01 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/credentialmanager/CredentialManagerModule.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/credentialmanager/CredentialManagerModule.kt
@@ -20,17 +20,17 @@ import org.json.JSONObject;
import java.util.List;
-class CredentialManagerModule(private val reactContext: ReactApplicationContext) :
+class CredentialManagerModule(private val reactContext: ReactApplicationContext) :
ReactContextBaseJavaModule(reactContext) {
-
+
companion object {
private const val TAG = "CredentialManagerModule"
}
-
+
override fun getName(): String {
return "CredentialManager"
}
-
+
private fun getFragmentActivity(): FragmentActivity? {
val activity = currentActivity
return if (activity is FragmentActivity) {
@@ -39,37 +39,7 @@ class CredentialManagerModule(private val reactContext: ReactApplicationContext)
null
}
}
-
- @ReactMethod
- fun addCredential(username: String, password: String, service: String, promise: Promise) {
- UiThreadUtil.runOnUiThread {
- try {
- val activity = getFragmentActivity()
- if (activity == null) {
- promise.reject("ERR_ACTIVITY", "Activity is not available")
- return@runOnUiThread
- }
-
- val store = SharedCredentialStore.getInstance(reactContext)
- val credential = Credential(username, password, service)
-
- store.saveCredential(activity, credential, object : SharedCredentialStore.CryptoOperationCallback {
- override fun onSuccess(result: String) {
- promise.resolve(true)
- }
-
- override fun onError(e: Exception) {
- Log.e(TAG, "Error adding credential", e)
- promise.reject("ERR_ADD_CREDENTIAL", "Failed to add credential: ${e.message}", e)
- }
- })
- } catch (e: Exception) {
- Log.e(TAG, "Error preparing to add credential", e)
- promise.reject("ERR_ADD_CREDENTIAL", "Failed to prepare adding credential: ${e.message}", e)
- }
- }
- }
-
+
@ReactMethod
fun getCredentials(promise: Promise) {
UiThreadUtil.runOnUiThread {
@@ -79,15 +49,15 @@ class CredentialManagerModule(private val reactContext: ReactApplicationContext)
promise.reject("ERR_ACTIVITY", "Activity is not available")
return@runOnUiThread
}
-
+
val store = SharedCredentialStore.getInstance(reactContext)
-
+
store.getAllCredentials(activity, object : SharedCredentialStore.CryptoOperationCallback {
override fun onSuccess(jsonString: String) {
try {
val jsonArray = JSONArray(jsonString)
val credentialsArray = Arguments.createArray()
-
+
for (i in 0 until jsonArray.length()) {
val jsonObject = jsonArray.getJSONObject(i)
val credentialMap = Arguments.createMap()
@@ -96,14 +66,14 @@ class CredentialManagerModule(private val reactContext: ReactApplicationContext)
credentialMap.putString("service", jsonObject.getString("service"))
credentialsArray.pushMap(credentialMap)
}
-
+
promise.resolve(credentialsArray)
} catch (e: Exception) {
Log.e(TAG, "Error parsing credentials", e)
promise.reject("ERR_PARSE_CREDENTIALS", "Failed to parse credentials: ${e.message}", e)
}
}
-
+
override fun onError(e: Exception) {
Log.e(TAG, "Error getting credentials", e)
promise.reject("ERR_GET_CREDENTIALS", "Failed to get credentials: ${e.message}", e)
@@ -115,7 +85,7 @@ class CredentialManagerModule(private val reactContext: ReactApplicationContext)
}
}
}
-
+
@ReactMethod
fun clearCredentials(promise: Promise) {
try {
@@ -127,4 +97,4 @@ class CredentialManagerModule(private val reactContext: ReactApplicationContext)
promise.reject("ERR_CLEAR_CREDENTIALS", "Failed to clear credentials: ${e.message}", e)
}
}
-}
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/apps/mobile-app/context/DbContext.tsx b/apps/mobile-app/context/DbContext.tsx
index f972c7c9b..2fc038086 100644
--- a/apps/mobile-app/context/DbContext.tsx
+++ b/apps/mobile-app/context/DbContext.tsx
@@ -99,11 +99,10 @@ export const DbProvider: React.FC<{ children: React.ReactNode }> = ({ children }
}, [dbInitialized, checkStoredVault]);
/**
- * Clear database and remove from background worker, called when logging out.
+ * Clear database and remove from native module, called when logging out.
*/
const clearDatabase = useCallback(() : void => {
setDbInitialized(false);
- // TODO: implement actual vault clearing.
NativeVaultManager.clearVault();
}, []);
diff --git a/apps/mobile-app/ios/NativeVaultManager/RCTNativeVaultManager.mm b/apps/mobile-app/ios/NativeVaultManager/RCTNativeVaultManager.mm
index 127076cc4..f9764997f 100644
--- a/apps/mobile-app/ios/NativeVaultManager/RCTNativeVaultManager.mm
+++ b/apps/mobile-app/ios/NativeVaultManager/RCTNativeVaultManager.mm
@@ -40,10 +40,6 @@
return std::make_shared<facebook::react::NativeVaultManagerSpecJSI>(params);
}
-- (void)addCredential:(NSString *)username password:(NSString *)password service:(NSString *)service resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
- [vaultManager addCredential:username password:password service:service];
-}
-
- (void)clearVault {
[vaultManager clearVault];
}
diff --git a/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift b/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift
index 5c3cb457a..18563667c 100644
--- a/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift
+++ b/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift
@@ -130,17 +130,6 @@ public class VaultManager: NSObject {
}
}
- @objc
- func addCredential(_ username: String, password: String, service: String) {
- do {
- // TODO: implement this
- //let credential = Credential(username: username, password: password, service: service)
- //try vaultStore.addCredential(credential)
- } catch {
- print("Failed to add credential: \(error)")
- }
- }
-
@objc
func getCredentials() -> [String: Any] {
do {
diff --git a/apps/mobile-app/ios/VaultStoreKit/VaultStoreKit.swift b/apps/mobile-app/ios/VaultStoreKit/VaultStoreKit.swift
index 9a22e4941..ef5789970 100644
--- a/apps/mobile-app/ios/VaultStoreKit/VaultStoreKit.swift
+++ b/apps/mobile-app/ios/VaultStoreKit/VaultStoreKit.swift
@@ -414,33 +414,6 @@ public class VaultStore {
}
// MARK: - Credential Operations
-
- func addCredential(_ credential: Credential) throws {
- // After initialization attempt, check if db is still nil
- guard let db = db else {
- throw NSError(domain: "VaultStore", code: 4, userInfo: [NSLocalizedDescriptionKey: "Database not initialized"])
- }
-
- // TODO: update this to use the actual database schema.
- // TODO: having the add logic here means we have duplicate code with the react native implementation.
- let credentials = Table("credentials")
- let id = Expression<String>("id")
- let username = Expression<String>("username")
- let password = Expression<String>("password")
- let service = Expression<String>("service")
- let createdAt = Expression<Date>("created_at")
- let updatedAt = Expression<Date>("updated_at")
-
- try db.run(credentials.insert(
- id <- UUID().uuidString,
- username <- credential.username ?? "",
- password <- credential.password?.value ?? "",
- service <- credential.service.name ?? "",
- createdAt <- Date(),
- updatedAt <- Date()
- ))
- }
-
public func getAllCredentials() throws -> [Credential] {
guard let db = db else {
throw NSError(domain: "VaultStore", code: 4, userInfo: [NSLocalizedDescriptionKey: "Database not initialized"])
diff --git a/apps/mobile-app/ios/VaultUI/Views/CredentialProviderView.swift b/apps/mobile-app/ios/VaultUI/Views/CredentialProviderView.swift
index d4707357e..fc1d68867 100644
--- a/apps/mobile-app/ios/VaultUI/Views/CredentialProviderView.swift
+++ b/apps/mobile-app/ios/VaultUI/Views/CredentialProviderView.swift
@@ -114,9 +114,6 @@ public struct CredentialProviderView: View {
}
}
}
- .sheet(isPresented: $viewModel.showAddCredential) {
- AddCredentialView(viewModel: viewModel)
- }
.actionSheet(isPresented: $viewModel.showSelectionOptions) {
// Define all text strings
guard let credential = viewModel.selectedCredential else {
@@ -191,7 +188,6 @@ public class CredentialProviderViewModel: ObservableObject {
@Published var isLoading = true
@Published var showError = false
@Published var errorMessage = ""
- @Published var showAddCredential = false
@Published var showSelectionOptions = false
@Published var selectedCredential: Credential?
@Published public var isChoosingTextToInsert = false
@@ -381,48 +377,6 @@ public class CredentialProviderViewModel: ObservableObject {
}
}
-// MARK: - AddCredentialView
-
-struct AddCredentialView: View {
- @ObservedObject var viewModel: CredentialProviderViewModel
- @Environment(\.dismiss) private var dismiss
-
- var body: some View {
- NavigationView {
- Form {
- TextField("Username", text: $viewModel.newUsername)
- .textContentType(.username)
- .autocapitalization(.none)
-
- SecureField("Password", text: $viewModel.newPassword)
- .textContentType(.password)
-
- TextField("Service", text: $viewModel.newService)
- .textContentType(.URL)
- .autocapitalization(.none)
- }
- .navigationTitle("Add Credential")
- .navigationBarTitleDisplayMode(.inline)
- .toolbar {
- ToolbarItem(placement: .navigationBarLeading) {
- Button("Cancel") {
- dismiss()
- }
- }
- ToolbarItem(placement: .navigationBarTrailing) {
- Button("Save") {
- //viewModel.addCredential()
- dismiss()
- }
- .disabled(viewModel.newUsername.isEmpty ||
- viewModel.newPassword.isEmpty ||
- viewModel.newService.isEmpty)
- }
- }
- }
- }
-}
-
// MARK: - SearchBar
struct SearchBar: View {
diff --git a/apps/mobile-app/native/NativeVaultManager.ts b/apps/mobile-app/native/NativeVaultManager.ts
index 0c6f7cae4..33879e7c5 100644
--- a/apps/mobile-app/native/NativeVaultManager.ts
+++ b/apps/mobile-app/native/NativeVaultManager.ts
@@ -3,7 +3,6 @@ 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>;
diff --git a/apps/mobile-app/specs/NativeVaultManager.ts b/apps/mobile-app/specs/NativeVaultManager.ts
index 0e905e25d..e375e6227 100644
--- a/apps/mobile-app/specs/NativeVaultManager.ts
+++ b/apps/mobile-app/specs/NativeVaultManager.ts
@@ -3,7 +3,6 @@ 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>;