Skip to content

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

Refactor VaultStoreKit function naming (#771)

Leendert de Borst198b53229997
diff --git a/apps/mobile-app/app/sync.tsx b/apps/mobile-app/app/sync.tsx
index e997527b9..162f4c0ba 100644
--- a/apps/mobile-app/app/sync.tsx
+++ b/apps/mobile-app/app/sync.tsx
@@ -43,8 +43,8 @@ export default function SyncScreen() {
// Try to unlock with FaceID
try {
- const isInitialized = await NativeVaultManager.isVaultInitialized();
- if (isInitialized) {
+ const hasStoredVault = await NativeVaultManager.hasStoredVault();
+ if (hasStoredVault) {
const isFaceIDEnabled = enabledAuthMethods.includes('faceid');
if (!isFaceIDEnabled) {
console.log('FaceID is not enabled, navigating to unlock screen');
diff --git a/apps/mobile-app/context/DbContext.tsx b/apps/mobile-app/context/DbContext.tsx
index 2fc038086..5db29923c 100644
--- a/apps/mobile-app/context/DbContext.tsx
+++ b/apps/mobile-app/context/DbContext.tsx
@@ -64,8 +64,8 @@ export const DbProvider: React.FC<{ children: React.ReactNode }> = ({ children }
const checkStoredVault = useCallback(async () => {
try {
- const isVaultInitialized = await NativeVaultManager.isVaultInitialized();
- if (isVaultInitialized) {
+ const hasStoredVault = await NativeVaultManager.hasStoredVault();
+ if (hasStoredVault) {
// Get metadata from SQLite client
const metadata = await sqliteClient.getVaultMetadata();
if (metadata) {
diff --git a/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift b/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift
index 2fbf62305..0e9c36360 100644
--- a/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift
+++ b/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift
@@ -27,9 +27,26 @@ class CredentialProviderViewController: ASCredentialProviderViewController {
override func viewDidLoad() {
super.viewDidLoad()
- // Check if Face ID/Touch ID is enabled
+ // Check if there is a stored vault. If not, it means the user has not logged in yet and we
+ // should redirect to the main app login screen automatically.
let vaultStore = VaultStore()
+ if !vaultStore.hasStoredVault() {
+ let alert = UIAlertController(
+ title: "Login Required",
+ message: "To use Autofill, please login to your AliasVault account in the AliasVault app.",
+ preferredStyle: .alert
+ )
+ alert.addAction(UIAlertAction(title: "OK", style: .default) { [weak self] _ in
+ self?.extensionContext.cancelRequest(withError: NSError(
+ domain: ASExtensionErrorDomain,
+ code: ASExtensionError.userCanceled.rawValue
+ ))
+ })
+ present(alert, animated: true)
+ return
+ }
+ // Check if Face ID/Touch ID is enabled
let context = LAContext()
var authMethod = "Face ID / Touch ID"
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil) {
@@ -62,7 +79,7 @@ class CredentialProviderViewController: ASCredentialProviderViewController {
// Create the ViewModel with INJECTED behaviors
let viewModel = CredentialProviderViewModel(
loader: {
- try vaultStore.initializeDatabase()
+ try vaultStore.unlockVault()
let credentials = try vaultStore.getAllCredentials()
await self.registerCredentialIdentities(credentials: credentials)
return credentials
diff --git a/apps/mobile-app/ios/NativeVaultManager/RCTNativeVaultManager.mm b/apps/mobile-app/ios/NativeVaultManager/RCTNativeVaultManager.mm
index f9764997f..fb4871565 100644
--- a/apps/mobile-app/ios/NativeVaultManager/RCTNativeVaultManager.mm
+++ b/apps/mobile-app/ios/NativeVaultManager/RCTNativeVaultManager.mm
@@ -80,8 +80,8 @@
[vaultManager getVaultMetadata:resolve rejecter:reject];
}
-- (void)isVaultInitialized:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
- [vaultManager isVaultInitialized:resolve rejecter:reject];
+- (void)hasStoredVault:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
+ [vaultManager hasStoredVault:resolve rejecter:reject];
}
- (void)isVaultUnlocked:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
diff --git a/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift b/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift
index 18563667c..27d4117f2 100644
--- a/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift
+++ b/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift
@@ -183,10 +183,10 @@ public class VaultManager: NSObject {
}
@objc
- func isVaultInitialized(_ resolve: @escaping RCTPromiseResolveBlock,
+ func hasStoredVault(_ resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock) {
do {
- let isInitialized = try vaultStore.isVaultInitialized()
+ let isInitialized = try vaultStore.hasStoredVault()
resolve(isInitialized)
} catch {
reject("VAULT_ERROR", "Failed to check vault initialization: \(error.localizedDescription)", error)
@@ -215,10 +215,7 @@ public class VaultManager: NSObject {
func unlockVault(_ resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock) {
do {
- // TODO: rename this to unlockvault? so meaning is: initialized means it exists, and unlock means
- // we're decrypting the encrypted database (that exists) and try to load it into memory. If unlocking
- // fails, user is redirected to the unlock screen in the react native app.
- try vaultStore.initializeDatabase()
+ try vaultStore.unlockVault()
resolve(true)
} catch {
// Check if the error is related to Face ID or decryption
diff --git a/apps/mobile-app/ios/VaultStoreKit/VaultStoreKit.swift b/apps/mobile-app/ios/VaultStoreKit/VaultStoreKit.swift
index ef5789970..f8efb5e49 100644
--- a/apps/mobile-app/ios/VaultStoreKit/VaultStoreKit.swift
+++ b/apps/mobile-app/ios/VaultStoreKit/VaultStoreKit.swift
@@ -131,7 +131,7 @@ public class VaultStore {
}
// MARK: - Vault Status
- public func isVaultInitialized() -> Bool {
+ public func hasStoredVault() -> Bool {
// Check if encrypted database file exists
let hasDatabase = FileManager.default.fileExists(atPath: getEncryptedDbPath().path)
@@ -238,7 +238,7 @@ public class VaultStore {
// Store the encrypted database (base64 encoded) in the app's documents directory
// and metadata in UserDefaults
- // TODO: refactor metadata save and retrieve calls to separate calls for better clarity throughtout
+ // TODO: refactor metadata save and retrieve calls to separate calls for better clarity throughout
// full call chain?
public func storeEncryptedDatabase(_ base64EncryptedDb: String, metadata: String) throws {
// Store the encrypted database (base64 encoded) in the app's documents directory
@@ -305,14 +305,14 @@ public class VaultStore {
}
/**
- * Initialize the database.
+ * Unlock the vault.
*
* This function will decrypt the encrypted database and import it into an in-memory database.
* Note: as part of decryption, executing this function can prompt the user for biometric authentication.
*
* The in-memory database is used for all queries and updates to the database.
*/
- public func initializeDatabase() throws {
+ public func unlockVault() throws {
// Get the encrypted database
guard let encryptedDbBase64 = getEncryptedDatabase() else {
throw NSError(domain: "VaultStore", code: 1, userInfo: [NSLocalizedDescriptionKey: "No encrypted database found"])
@@ -386,25 +386,9 @@ public class VaultStore {
// MARK: - Encryption/Decryption
private func encrypt(data: Data, key: Data) throws -> Data {
- // TODO: check if this works properly and is compatible with the other clients.
- // If it works, remove the commented out code below.
let key = SymmetricKey(data: key)
let sealedBox = try AES.GCM.seal(data, using: key)
return sealedBox.combined!
- /*
- // Generate 12-byte random nonce (IV)
- let iv = AES.GCM.Nonce()
-
- // Encrypt with AES-GCM and custom IV
- let sealedBox = try AES.GCM.seal(data, using: key, nonce: iv)
-
- // Concatenate: IV (12 bytes) + ciphertext + tag
- var combined = Data()
- combined.append(contentsOf: iv) // 12 bytes
- combined.append(sealedBox.ciphertext)
- combined.append(sealedBox.tag) // 16 bytes
-
- return combined*/
}
private func decrypt(data: Data, key: Data) throws -> Data {
diff --git a/apps/mobile-app/ios/VaultStoreKitTests/VaultStoreKitTests.swift b/apps/mobile-app/ios/VaultStoreKitTests/VaultStoreKitTests.swift
index f62275dc3..48084da2d 100644
--- a/apps/mobile-app/ios/VaultStoreKitTests/VaultStoreKitTests.swift
+++ b/apps/mobile-app/ios/VaultStoreKitTests/VaultStoreKitTests.swift
@@ -32,8 +32,8 @@ final class VaultStoreKitTests: XCTestCase {
// TODO: get metadata via vault generation and pass it here so we have all info we need for all tests.
try vaultStore.storeEncryptedDatabase(encryptedDb, metadata: "")
- // Then try to initialize the database
- try vaultStore.initializeDatabase()
+ // Unlock the vault (which loads, decrypts and opens the database in memory)
+ try vaultStore.unlockVault()
// If we get here without throwing, initialization was successful
XCTAssertTrue(vaultStore.isVaultUnlocked(), "Vault should be unlocked after initialization")
@@ -48,8 +48,8 @@ final class VaultStoreKitTests: XCTestCase {
// TODO: get metadata via vault generation and pass it here so we have all info we need for all tests.
try vaultStore.storeEncryptedDatabase(encryptedDb, metadata: "")
- // Initialize the database
- try vaultStore.initializeDatabase()
+ // Unlock the vault (which loads, decrypts and opens the database in memory)
+ try vaultStore.unlockVault()
// Try to get all credentials
let credentials = try vaultStore.getAllCredentials()
@@ -77,8 +77,8 @@ final class VaultStoreKitTests: XCTestCase {
let encryptedDb = try loadTestDatabase()
try vaultStore.storeEncryptedDatabase(encryptedDb, metadata: "")
- // Initialize the database
- try vaultStore.initializeDatabase()
+ // Unlock the vault (which loads, decrypts and opens the database in memory)
+ try vaultStore.unlockVault()
// Get all credentials
let credentials = try vaultStore.getAllCredentials()
diff --git a/apps/mobile-app/ios/VaultUI/Views/CredentialProviderView.swift b/apps/mobile-app/ios/VaultUI/Views/CredentialProviderView.swift
index fc1d68867..b17dcbc0e 100644
--- a/apps/mobile-app/ios/VaultUI/Views/CredentialProviderView.swift
+++ b/apps/mobile-app/ios/VaultUI/Views/CredentialProviderView.swift
@@ -102,15 +102,18 @@ public struct CredentialProviderView: View {
}
ToolbarItem(placement: .navigationBarTrailing) {
HStack {
- Button("Add") {
+ // Make this button show a + icon instead of text
+ Button(action: {
if let serviceUrl = viewModel.serviceUrl {
let encodedUrl = serviceUrl.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? ""
if let url = URL(string: "net.aliasvault.app://credentials/add-edit?serviceUrl=\(encodedUrl)") {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}
+ }) {
+ Image(systemName: "plus")
+ .foregroundColor(ColorConstants.Light.primary)
}
- .foregroundColor(ColorConstants.Light.primary)
}
}
}
diff --git a/apps/mobile-app/native/NativeVaultManager.ts b/apps/mobile-app/native/NativeVaultManager.ts
index 33879e7c5..3492f8f4a 100644
--- a/apps/mobile-app/native/NativeVaultManager.ts
+++ b/apps/mobile-app/native/NativeVaultManager.ts
@@ -7,7 +7,7 @@ export interface Spec extends TurboModule {
clearVault(): Promise<void>;
// Vault state management
- isVaultInitialized(): Promise<boolean>;
+ hasStoredVault(): Promise<boolean>;
isVaultUnlocked(): Promise<boolean>;
getVaultMetadata(): Promise<any>;
unlockVault(): Promise<boolean>;
diff --git a/apps/mobile-app/specs/NativeVaultManager.ts b/apps/mobile-app/specs/NativeVaultManager.ts
index e375e6227..036405c5e 100644
--- a/apps/mobile-app/specs/NativeVaultManager.ts
+++ b/apps/mobile-app/specs/NativeVaultManager.ts
@@ -7,7 +7,7 @@ export interface Spec extends TurboModule {
clearVault(): Promise<void>;
// Vault state management
- isVaultInitialized(): Promise<boolean>;
+ hasStoredVault(): Promise<boolean>;
isVaultUnlocked(): Promise<boolean>;
getVaultMetadata(): Promise<any>;
unlockVault(): Promise<boolean>;