Skip to content

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

Add passkey merge flow to passkey create in iOS (#1404)

Leendert de Borst29ff15d6b1d9
diff --git a/apps/mobile-app/ios/AliasVault.xcodeproj/project.pbxproj b/apps/mobile-app/ios/AliasVault.xcodeproj/project.pbxproj
index 5d4eeb343..342538b8c 100644
--- a/apps/mobile-app/ios/AliasVault.xcodeproj/project.pbxproj
+++ b/apps/mobile-app/ios/AliasVault.xcodeproj/project.pbxproj
@@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
- objectVersion = 60;
+ objectVersion = 70;
objects = {
/* Begin PBXBuildFile section */
@@ -272,7 +272,7 @@
/* End PBXFileReference section */
/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */
- CEE9098F2DA548C7008D568F /* Exceptions for "Autofill" folder in "Autofill" target */ = {
+ CEE9098F2DA548C7008D568F /* PBXFileSystemSynchronizedBuildFileExceptionSet */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
membershipExceptions = (
Info.plist,
@@ -282,84 +282,13 @@
/* End PBXFileSystemSynchronizedBuildFileExceptionSet section */
/* Begin PBXFileSystemSynchronizedRootGroup section */
- CE59C7602E4F47FD0024A246 /* AliasVaultUITests */ = {
- isa = PBXFileSystemSynchronizedRootGroup;
- exceptions = (
- );
- explicitFileTypes = {
- };
- explicitFolders = (
- );
- path = AliasVaultUITests;
- sourceTree = "<group>";
- };
- CE77825E2EA1822400A75E6F /* VaultUtils */ = {
- isa = PBXFileSystemSynchronizedRootGroup;
- exceptions = (
- );
- explicitFileTypes = {
- };
- explicitFolders = (
- );
- path = VaultUtils;
- sourceTree = "<group>";
- };
- CEE480882DBE86DC00F4A367 /* VaultStoreKit */ = {
- isa = PBXFileSystemSynchronizedRootGroup;
- exceptions = (
- );
- explicitFileTypes = {
- };
- explicitFolders = (
- );
- path = VaultStoreKit;
- sourceTree = "<group>";
- };
- CEE480972DBE86DD00F4A367 /* VaultStoreKitTests */ = {
- isa = PBXFileSystemSynchronizedRootGroup;
- exceptions = (
- );
- explicitFileTypes = {
- };
- explicitFolders = (
- );
- path = VaultStoreKitTests;
- sourceTree = "<group>";
- };
- CEE4816B2DBE8AC800F4A367 /* VaultUI */ = {
- isa = PBXFileSystemSynchronizedRootGroup;
- exceptions = (
- );
- explicitFileTypes = {
- };
- explicitFolders = (
- );
- path = VaultUI;
- sourceTree = "<group>";
- };
- CEE482AB2DBE8EFE00F4A367 /* VaultModels */ = {
- isa = PBXFileSystemSynchronizedRootGroup;
- exceptions = (
- );
- explicitFileTypes = {
- };
- explicitFolders = (
- );
- path = VaultModels;
- sourceTree = "<group>";
- };
- CEE909812DA548C7008D568F /* Autofill */ = {
- isa = PBXFileSystemSynchronizedRootGroup;
- exceptions = (
- CEE9098F2DA548C7008D568F /* Exceptions for "Autofill" folder in "Autofill" target */,
- );
- explicitFileTypes = {
- };
- explicitFolders = (
- );
- path = Autofill;
- sourceTree = "<group>";
- };
+ CE59C7602E4F47FD0024A246 /* AliasVaultUITests */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = AliasVaultUITests; sourceTree = "<group>"; };
+ CE77825E2EA1822400A75E6F /* VaultUtils */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = VaultUtils; sourceTree = "<group>"; };
+ CEE480882DBE86DC00F4A367 /* VaultStoreKit */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = VaultStoreKit; sourceTree = "<group>"; };
+ CEE480972DBE86DD00F4A367 /* VaultStoreKitTests */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = VaultStoreKitTests; sourceTree = "<group>"; };
+ CEE4816B2DBE8AC800F4A367 /* VaultUI */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = VaultUI; sourceTree = "<group>"; };
+ CEE482AB2DBE8EFE00F4A367 /* VaultModels */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = VaultModels; sourceTree = "<group>"; };
+ CEE909812DA548C7008D568F /* Autofill */ = {isa = PBXFileSystemSynchronizedRootGroup; exceptions = (CEE9098F2DA548C7008D568F /* PBXFileSystemSynchronizedBuildFileExceptionSet */, ); explicitFileTypes = {}; explicitFolders = (); path = Autofill; sourceTree = "<group>"; };
/* End PBXFileSystemSynchronizedRootGroup section */
/* Begin PBXFrameworksBuildPhase section */
@@ -519,7 +448,7 @@
path = Generated;
sourceTree = "<group>";
};
- 6114AD0A31612EA499210371 /* */ = {
+ 6114AD0A31612EA499210371 = {
isa = PBXGroup;
children = (
8F8258CE46969A87661E0302 /* RustCore.swift */,
@@ -555,7 +484,7 @@
832341AE1AAA6A7D00B99B32 /* Libraries */,
D65327D7A22EEC0BE12398D9 /* Pods */,
83CBBA001A601CBA00E9B192 /* Products */,
- 6114AD0A31612EA499210371 /* */,
+ 6114AD0A31612EA499210371,
CE5212B62F0C061800F4C835 /* Recovered References */,
3AD00C41DD88E219A26C2E41 /* RustCoreFramework */,
);
@@ -1709,10 +1638,7 @@
LIBRARY_SEARCH_PATHS = "$(SDKROOT)/usr/lib/swift\"$(inherited)\"";
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
- OTHER_LDFLAGS = (
- "$(inherited)",
- " ",
- );
+ OTHER_LDFLAGS = "$(inherited) ";
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) DEBUG";
@@ -1766,10 +1692,7 @@
);
LIBRARY_SEARCH_PATHS = "$(SDKROOT)/usr/lib/swift\"$(inherited)\"";
MTL_ENABLE_DEBUG_INFO = NO;
- OTHER_LDFLAGS = (
- "$(inherited)",
- " ",
- );
+ OTHER_LDFLAGS = "$(inherited) ";
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
USE_HERMES = true;
diff --git a/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift b/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift
index 7516d2659..505721049 100644
--- a/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift
+++ b/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift
@@ -241,6 +241,26 @@ extension CredentialProviderViewController: PasskeyProviderDelegate {
// Continue with empty list
}
+ // Query for existing Items without passkeys that match this rpId
+ var existingItemsWithoutPasskey: [ItemWithCredentialInfo] = []
+ do {
+ let results = try vaultStore.getItemsWithoutPasskey(forRpId: rpId, userName: userName)
+ existingItemsWithoutPasskey = results.map { item in
+ ItemWithCredentialInfo(
+ itemId: item.itemId,
+ serviceName: item.serviceName,
+ url: item.url,
+ username: item.username,
+ hasPassword: item.hasPassword,
+ createdAt: item.createdAt,
+ updatedAt: item.updatedAt
+ )
+ }
+ } catch {
+ print("PasskeyRegistration: Failed to query existing items: \(error)")
+ // Continue with empty list
+ }
+
// Create view model with handlers
// Use lazy initialization to avoid capturing viewModel before it's assigned
var viewModel: PasskeyRegistrationViewModel!
@@ -251,6 +271,7 @@ extension CredentialProviderViewController: PasskeyProviderDelegate {
userName: userName,
userDisplayName: userDisplayName,
existingPasskeys: existingPasskeys,
+ existingItemsWithoutPasskey: existingItemsWithoutPasskey,
completionHandler: { [weak self] success in
guard let self = self else { return }
@@ -391,6 +412,13 @@ extension CredentialProviderViewController: PasskeyProviderDelegate {
displayName: viewModel.displayName,
logo: logo
)
+ } else if let existingItemId = viewModel.selectedItemToMerge {
+ // Merge passkey into existing item without passkey
+ try vaultStore.addPasskeyToExistingItem(
+ itemId: existingItemId,
+ passkey: passkey,
+ logo: logo
+ )
} else {
// Store item with passkey and logo in database
// Use viewModel.displayName as the title (Item.name)
diff --git a/apps/mobile-app/ios/VaultStoreKit/Database/Queries/PasskeyQueries.swift b/apps/mobile-app/ios/VaultStoreKit/Database/Queries/PasskeyQueries.swift
index 12de6476c..0a9135b03 100644
--- a/apps/mobile-app/ios/VaultStoreKit/Database/Queries/PasskeyQueries.swift
+++ b/apps/mobile-app/ios/VaultStoreKit/Database/Queries/PasskeyQueries.swift
@@ -85,6 +85,34 @@ public struct PasskeyQueries {
UpdatedAt = ?
WHERE Id = ? AND IsDeleted = 0
"""
+
+ /// Get Items that match an rpId but don't have a passkey yet.
+ /// Used for finding existing credentials that could have a passkey added to them.
+ public static let getItemsWithoutPasskeyForRpId = """
+ SELECT i.Id, i.Name, i.CreatedAt, i.UpdatedAt,
+ fv_url.Value as Url,
+ fv_username.Value as Username,
+ fv_password.Value as Password
+ FROM Items i
+ INNER JOIN FieldValues fv_url ON fv_url.ItemId = i.Id
+ AND fv_url.FieldKey = 'login.url'
+ AND fv_url.IsDeleted = 0
+ LEFT JOIN FieldValues fv_username ON fv_username.ItemId = i.Id
+ AND fv_username.FieldKey = 'login.username'
+ AND fv_username.IsDeleted = 0
+ LEFT JOIN FieldValues fv_password ON fv_password.ItemId = i.Id
+ AND fv_password.FieldKey = 'login.password'
+ AND fv_password.IsDeleted = 0
+ WHERE i.IsDeleted = 0
+ AND i.DeletedAt IS NULL
+ AND i.ItemType = 'Login'
+ AND (LOWER(fv_url.Value) LIKE ? OR LOWER(fv_url.Value) LIKE ?)
+ AND NOT EXISTS (
+ SELECT 1 FROM Passkeys p
+ WHERE p.ItemId = i.Id AND p.IsDeleted = 0
+ )
+ ORDER BY i.UpdatedAt DESC
+ """
}
/// SQL query constants for Logo operations used during passkey/item creation.
diff --git a/apps/mobile-app/ios/VaultStoreKit/Database/Repositories/PasskeyRepository.swift b/apps/mobile-app/ios/VaultStoreKit/Database/Repositories/PasskeyRepository.swift
index 654634d3f..354ae7010 100644
--- a/apps/mobile-app/ios/VaultStoreKit/Database/Repositories/PasskeyRepository.swift
+++ b/apps/mobile-app/ios/VaultStoreKit/Database/Repositories/PasskeyRepository.swift
@@ -59,6 +59,55 @@ public class PasskeyRepository: BaseRepository {
return mappedResults
}
+ /// Get Items that match an rpId but don't have a passkey yet.
+ /// Used for finding existing credentials that could have a passkey added to them.
+ /// - Parameters:
+ /// - rpId: The relying party identifier (domain)
+ /// - userName: Optional username to filter by
+ /// - Returns: Array of ItemWithCredentialInfoData objects
+ public func getItemsWithoutPasskey(forRpId rpId: String, userName: String? = nil) throws -> [ItemWithCredentialInfoData] {
+ let rpIdLower = rpId.lowercased()
+ let urlPattern1 = "%\(rpIdLower)%"
+ let urlPattern2 = "%\(rpIdLower.replacingOccurrences(of: "www.", with: ""))%"
+
+ let results = try client.executeQuery(PasskeyQueries.getItemsWithoutPasskeyForRpId, params: [urlPattern1, urlPattern2])
+
+ var items: [ItemWithCredentialInfoData] = []
+
+ for row in results {
+ guard let idString = row["Id"] as? String,
+ let itemId = UUID(uuidString: idString) else {
+ continue
+ }
+
+ let serviceName = row["Name"] as? String
+ let url = row["Url"] as? String
+ let itemUsername = row["Username"] as? String
+ let password = row["Password"] as? String
+ let hasPassword = password != nil && !password!.isEmpty
+
+ // Filter by username if provided
+ if let userName = userName, itemUsername != userName {
+ continue
+ }
+
+ let createdAt = DateHelpers.parseDateString(row["CreatedAt"] as? String ?? "") ?? Date.distantPast
+ let updatedAt = DateHelpers.parseDateString(row["UpdatedAt"] as? String ?? "") ?? Date.distantPast
+
+ items.append(ItemWithCredentialInfoData(
+ itemId: itemId,
+ serviceName: serviceName,
+ url: url,
+ username: itemUsername,
+ hasPassword: hasPassword,
+ createdAt: createdAt,
+ updatedAt: updatedAt
+ ))
+ }
+
+ return items
+ }
+
// MARK: - Write Operations
/// Create a new passkey.
@@ -349,6 +398,84 @@ public class PasskeyRepository: BaseRepository {
params: [displayName, now, itemId]
)
}
+
+ /// Add a passkey to an existing Item (merge passkey into existing credential).
+ /// - Parameters:
+ /// - itemId: The UUID of the existing Item to add the passkey to
+ /// - passkey: The passkey to add
+ /// - logo: Optional logo data to update/add
+ /// - Returns: The ID of the created passkey
+ @discardableResult
+ public func addPasskeyToExistingItem(
+ itemId: UUID,
+ passkey: Passkey,
+ logo: Data? = nil
+ ) throws -> String {
+ return try withTransaction {
+ let itemIdString = itemId.uuidString.uppercased()
+ let now = self.now()
+
+ // Update logo if provided
+ if let logo = logo {
+ try updateItemLogoInternal(
+ itemId: itemIdString,
+ logo: logo,
+ displayName: passkey.displayName,
+ now: now
+ )
+ }
+
+ // Create the passkey linked to the existing item
+ let passkeyId = passkey.id.uuidString.uppercased()
+
+ guard let publicKeyString = String(data: passkey.publicKey, encoding: .utf8),
+ let privateKeyString = String(data: passkey.privateKey, encoding: .utf8) else {
+ throw PasskeyRepositoryError.invalidKeyData
+ }
+
+ let userHandleParam: SqliteBindValue = passkey.userHandle.map { "av-base64-to-blob:\($0.base64EncodedString())" }
+ let prfKeyParam: SqliteBindValue = passkey.prfKey.map { "av-base64-to-blob:\($0.base64EncodedString())" }
+
+ try client.executeUpdate(PasskeyQueries.insert, params: [
+ passkeyId,
+ itemIdString,
+ passkey.rpId,
+ userHandleParam,
+ publicKeyString,
+ privateKeyString,
+ prfKeyParam,
+ passkey.displayName,
+ now,
+ now,
+ 0
+ ])
+
+ return passkeyId
+ }
+ }
+}
+
+/// Data class to hold Item info for Items without passkeys (internal VaultStoreKit type).
+/// Used for showing existing credentials that can have a passkey added.
+/// Note: VaultUI has its own ItemWithCredentialInfo type for UI usage.
+public struct ItemWithCredentialInfoData {
+ public let itemId: UUID
+ public let serviceName: String?
+ public let url: String?
+ public let username: String?
+ public let hasPassword: Bool
+ public let createdAt: Date
+ public let updatedAt: Date
+
+ public init(itemId: UUID, serviceName: String?, url: String?, username: String?, hasPassword: Bool, createdAt: Date, updatedAt: Date) {
+ self.itemId = itemId
+ self.serviceName = serviceName
+ self.url = url
+ self.username = username
+ self.hasPassword = hasPassword
+ self.createdAt = createdAt
+ self.updatedAt = updatedAt
+ }
}
/// Errors that can occur in PasskeyRepository operations.
diff --git a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Passkey.swift b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Passkey.swift
index 8dbf52577..82c9eb4a3 100644
--- a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Passkey.swift
+++ b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Passkey.swift
@@ -54,6 +54,14 @@ extension VaultStore {
return results.map { (passkey: $0.passkey, serviceName: $0.serviceName, username: $0.username) }
}
+ /**
+ * Get Items that match an rpId but don't have a passkey yet.
+ * Used for finding existing credentials that could have a passkey added to them.
+ */
+ public func getItemsWithoutPasskey(forRpId rpId: String, userName: String? = nil) throws -> [ItemWithCredentialInfoData] {
+ return try passkeyRepository.getItemsWithoutPasskey(forRpId: rpId, userName: userName)
+ }
+
// MARK: - Passkey Storage (Public API)
/**
@@ -127,6 +135,40 @@ extension VaultStore {
logo: logo
)
}
+
+ /**
+ * Add a passkey to an existing Item (merge passkey into existing credential).
+ * @param itemId The UUID of the existing Item to add the passkey to.
+ * @param passkey The passkey to add.
+ * @param logo Optional logo to update/add.
+ */
+ public func addPasskeyToExistingItem(
+ itemId: UUID,
+ passkey: Passkey,
+ logo: Data? = nil
+ ) throws {
+ // Create the passkey with the existing item ID
+ let passkeyWithItemId = Passkey(
+ id: passkey.id,
+ parentItemId: itemId, // Link to the existing item
+ rpId: passkey.rpId,
+ userHandle: passkey.userHandle,
+ userName: passkey.userName,
+ publicKey: passkey.publicKey,
+ privateKey: passkey.privateKey,
+ prfKey: passkey.prfKey,
+ displayName: passkey.displayName,
+ createdAt: Date(),
+ updatedAt: Date(),
+ isDeleted: false
+ )
+
+ try passkeyRepository.addPasskeyToExistingItem(
+ itemId: itemId,
+ passkey: passkeyWithItemId,
+ logo: logo
+ )
+ }
}
/**
diff --git a/apps/mobile-app/ios/VaultUI/Registration/Passkeys/Components/ExistingPasskeyRow.swift b/apps/mobile-app/ios/VaultUI/Registration/Passkeys/Components/ExistingPasskeyRow.swift
index 3fe1f7ec1..d7d28774e 100644
--- a/apps/mobile-app/ios/VaultUI/Registration/Passkeys/Components/ExistingPasskeyRow.swift
+++ b/apps/mobile-app/ios/VaultUI/Registration/Passkeys/Components/ExistingPasskeyRow.swift
@@ -46,22 +46,3 @@ struct ExistingPasskeyRow: View {
.cornerRadius(8)
}
}
-
-/// Helper struct to pass passkey data with credential info
-public struct PasskeyWithCredentialInfo: Identifiable {
- public let id: UUID
- public let displayName: String
- public let serviceName: String?
- public let username: String?
- public let rpId: String
- public let userId: Data?
-
- public init(id: UUID, displayName: String, serviceName: String?, username: String?, rpId: String, userId: Data?) {
- self.id = id
- self.displayName = displayName
- self.serviceName = serviceName
- self.username = username
- self.rpId = rpId
- self.userId = userId
- }
-}
diff --git a/apps/mobile-app/ios/VaultUI/Registration/Passkeys/Enums/PasskeyNavigationDestination.swift b/apps/mobile-app/ios/VaultUI/Registration/Passkeys/Enums/PasskeyNavigationDestination.swift
index 02111e4b5..1499cecf5 100644
--- a/apps/mobile-app/ios/VaultUI/Registration/Passkeys/Enums/PasskeyNavigationDestination.swift
+++ b/apps/mobile-app/ios/VaultUI/Registration/Passkeys/Enums/PasskeyNavigationDestination.swift
@@ -4,4 +4,5 @@ import Foundation
public enum PasskeyNavigationDestination: Hashable {
case createNew
case replace(UUID)
+ case mergeWithItem(UUID) // Add passkey to existing item without passkey
}
diff --git a/apps/mobile-app/ios/VaultUI/Registration/Passkeys/Models/ItemWithCredentialInfo.swift b/apps/mobile-app/ios/VaultUI/Registration/Passkeys/Models/ItemWithCredentialInfo.swift
new file mode 100644
index 000000000..e327e06a3
--- /dev/null
+++ b/apps/mobile-app/ios/VaultUI/Registration/Passkeys/Models/ItemWithCredentialInfo.swift
@@ -0,0 +1,24 @@
+import Foundation
+
+/// Helper struct to pass item data with credential info (for items without passkeys)
+public struct ItemWithCredentialInfo: Identifiable {
+ public let id: UUID // Alias for itemId for Identifiable conformance
+ public let itemId: UUID
+ public let serviceName: String?
+ public let url: String?
+ public let username: String?
+ public let hasPassword: Bool
+ public let createdAt: Date
+ public let updatedAt: Date
+
+ public init(itemId: UUID, serviceName: String?, url: String?, username: String?, hasPassword: Bool, createdAt: Date, updatedAt: Date) {
+ self.id = itemId
+ self.itemId = itemId
+ self.serviceName = serviceName
+ self.url = url
+ self.username = username
+ self.hasPassword = hasPassword
+ self.createdAt = createdAt
+ self.updatedAt = updatedAt
+ }
+}
diff --git a/apps/mobile-app/ios/VaultUI/Registration/Passkeys/Models/PasskeyWithCredentialInfo.swift b/apps/mobile-app/ios/VaultUI/Registration/Passkeys/Models/PasskeyWithCredentialInfo.swift
new file mode 100644
index 000000000..23eeb0af6
--- /dev/null
+++ b/apps/mobile-app/ios/VaultUI/Registration/Passkeys/Models/PasskeyWithCredentialInfo.swift
@@ -0,0 +1,20 @@
+import Foundation
+
+/// Helper struct to pass passkey data with credential info
+public struct PasskeyWithCredentialInfo: Identifiable {
+ public let id: UUID
+ public let displayName: String
+ public let serviceName: String?
+ public let username: String?
+ public let rpId: String
+ public let userId: Data?
+
+ public init(id: UUID, displayName: String, serviceName: String?, username: String?, rpId: String, userId: Data?) {
+ self.id = id
+ self.displayName = displayName
+ self.serviceName = serviceName
+ self.username = username
+ self.rpId = rpId
+ self.userId = userId
+ }
+}
diff --git a/apps/mobile-app/ios/VaultUI/Registration/Passkeys/PasskeyFormView.swift b/apps/mobile-app/ios/VaultUI/Registration/Passkeys/PasskeyFormView.swift
index df591af8b..2d33b6ee4 100644
--- a/apps/mobile-app/ios/VaultUI/Registration/Passkeys/PasskeyFormView.swift
+++ b/apps/mobile-app/ios/VaultUI/Registration/Passkeys/PasskeyFormView.swift
@@ -7,6 +7,7 @@ struct PasskeyFormView: View {
@ObservedObject var viewModel: PasskeyRegistrationViewModel
let isReplaceMode: Bool
let replacingPasskeyId: UUID?
+ let mergingItemId: UUID?
@Environment(\.colorScheme) private var colorScheme
@FocusState private var isTitleFocused: Bool
@@ -16,6 +17,15 @@ struct PasskeyFormView: View {
return viewModel.existingPasskeys.first(where: { $0.id == id })
}
+ var mergingItem: ItemWithCredentialInfo? {
+ guard let id = mergingItemId else { return nil }
+ return viewModel.existingItemsWithoutPasskey.first(where: { $0.itemId == id })
+ }
+
+ var isMergeMode: Bool {
+ mergingItemId != nil
+ }
+
var isTitleValid: Bool {
!viewModel.displayName.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
}
@@ -32,7 +42,7 @@ struct PasskeyFormView: View {
// Notice section
if isReplaceMode {
// Warning and explanation for replacing
- if let passkey = replacingPasskey {
+ if replacingPasskey != nil {
VStack(spacing: 12) {
HStack(spacing: 12) {
Image(systemName: "info.circle.fill")
@@ -46,6 +56,23 @@ struct PasskeyFormView: View {
.padding(.horizontal)
.padding(.top, 8)
}
+ } else if isMergeMode {
+ // Explanation for merging with existing item
+ VStack(spacing: 8) {
+ HStack(spacing: 12) {
+ Image(systemName: "info.circle.fill")
+ .foregroundColor(ColorConstants.Light.primary)
+ Text(String(localized: "merge_passkey_explanation", bundle: locBundle))
+ .font(.caption)
+ .foregroundColor(colorScheme == .dark ? ColorConstants.Dark.textMuted : ColorConstants.Light.textMuted)
+ .fixedSize(horizontal: false, vertical: true)
+ }
+ .padding()
+ .background(ColorConstants.Light.primary.opacity(0.1))
+ .cornerRadius(8)
+ }
+ .padding(.horizontal)
+ .padding(.top, 8)
} else {
// Informational notice for creating new
VStack(spacing: 8) {
@@ -95,9 +122,7 @@ struct PasskeyFormView: View {
}, label: {
HStack {
Image(systemName: "key.fill")
- Text(isReplaceMode
- ? String(localized: "confirm_replace", bundle: locBundle)
- : String(localized: "create_passkey_button_confirm", bundle: locBundle))
+ Text(buttonText)
}
.padding()
.frame(maxWidth: .infinity)
@@ -120,12 +145,30 @@ struct PasskeyFormView: View {
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .principal) {
- Text(isReplaceMode
- ? String(localized: "replace_passkey_title", bundle: locBundle)
- : String(localized: "create_passkey_title", bundle: locBundle))
+ Text(titleText)
.font(.headline)
.foregroundStyle(colorScheme == .dark ? ColorConstants.Dark.text : ColorConstants.Light.text)
}
}
}
+
+ private var buttonText: String {
+ if isReplaceMode {
+ return String(localized: "confirm_replace", bundle: locBundle)
+ } else if isMergeMode {
+ return String(localized: "confirm_add_passkey", bundle: locBundle)
+ } else {
+ return String(localized: "create_passkey_button_confirm", bundle: locBundle)
+ }
+ }
+
+ private var titleText: String {
+ if isReplaceMode {
+ return String(localized: "replace_passkey_title", bundle: locBundle)
+ } else if isMergeMode {
+ return String(localized: "add_passkey_title", bundle: locBundle)
+ } else {
+ return String(localized: "create_passkey_title", bundle: locBundle)
+ }
+ }
}
diff --git a/apps/mobile-app/ios/VaultUI/Registration/Passkeys/PasskeyRegistrationView.swift b/apps/mobile-app/ios/VaultUI/Registration/Passkeys/PasskeyRegistrationView.swift
index b836e325c..05903fe01 100644
--- a/apps/mobile-app/ios/VaultUI/Registration/Passkeys/PasskeyRegistrationView.swift
+++ b/apps/mobile-app/ios/VaultUI/Registration/Passkeys/PasskeyRegistrationView.swift
@@ -27,8 +27,8 @@ public struct PasskeyRegistrationView: View {
// Header
PasskeyRegistrationHeader(rpId: viewModel.rpId)
- // Show selection or form based on existing passkeys
- if viewModel.existingPasskeys.isEmpty {
+ // Show selection or form based on existing passkeys/items
+ if viewModel.existingPasskeys.isEmpty && viewModel.existingItemsWithoutPasskey.isEmpty {
// Go directly to create form
createFormContent
} else {
@@ -48,7 +48,7 @@ public struct PasskeyRegistrationView: View {
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .principal) {
- if !viewModel.existingPasskeys.isEmpty {
+ if !viewModel.existingPasskeys.isEmpty || !viewModel.existingItemsWithoutPasskey.isEmpty {
Text(String(localized: "create_passkey_title", bundle: locBundle))
.font(.headline)
.foregroundStyle(colorScheme == .dark ? ColorConstants.Dark.text : ColorConstants.Light.text)
@@ -64,7 +64,7 @@ public struct PasskeyRegistrationView: View {
// MARK: - Selection Content (Inline)
private var selectionContent: some View {
- VStack(spacing: 36) {
+ VStack(spacing: 24) {
// Create new button
Button(action: {
viewModel.handleCreateNew()
@@ -81,28 +81,56 @@ public struct PasskeyRegistrationView: View {
.cornerRadius(8)
})
- // Existing passkeys list
- VStack(alignment: .leading, spacing: 12) {
- Text(String(localized: "select_passkey_to_replace", bundle: locBundle) + ":")
- .font(.subheadline)
- .fontWeight(.medium)
- .foregroundColor(colorScheme == .dark ? ColorConstants.Dark.text : ColorConstants.Light.text)
- .padding(.horizontal)
+ // Existing Items without passkey section (for merging)
+ if !viewModel.existingItemsWithoutPasskey.isEmpty {
+ VStack(alignment: .leading, spacing: 12) {
+ Text(String(localized: "passkey_add_to_existing", bundle: locBundle) + ":")
+ .font(.subheadline)
+ .fontWeight(.medium)
+ .foregroundColor(colorScheme == .dark ? ColorConstants.Dark.text : ColorConstants.Light.text)
+ .padding(.horizontal)
+
+ ScrollView {
+ VStack(spacing: 8) {
+ ForEach(viewModel.existingItemsWithoutPasskey) { itemInfo in
+ Button(action: {
+ viewModel.handleSelectMerge(itemId: itemInfo.itemId)
+ navigationPath.append(PasskeyNavigationDestination.mergeWithItem(itemInfo.itemId))
+ }, label: {
+ ExistingItemRow(item: itemInfo, rpId: viewModel.rpId)
+ })
+ .buttonStyle(PlainButtonStyle())
+ }
+ }
+ }
+ .frame(maxHeight: 200)
+ }
+ }
- ScrollView {
- VStack(spacing: 8) {
- ForEach(viewModel.existingPasskeys) { passkeyInfo in
- Button(action: {
- viewModel.handleSelectReplace(passkeyId: passkeyInfo.id)
- navigationPath.append(PasskeyNavigationDestination.replace(passkeyInfo.id))
- }, label: {
- ExistingPasskeyRow(passkey: passkeyInfo)
- })
- .buttonStyle(PlainButtonStyle())
+ // Existing passkeys list (for replacement)
+ if !viewModel.existingPasskeys.isEmpty {
+ VStack(alignment: .leading, spacing: 12) {
+ Text(String(localized: "select_passkey_to_replace", bundle: locBundle) + ":")
+ .font(.subheadline)
+ .fontWeight(.medium)
+ .foregroundColor(colorScheme == .dark ? ColorConstants.Dark.text : ColorConstants.Light.text)
+ .padding(.horizontal)
+
+ ScrollView {
+ VStack(spacing: 8) {
+ ForEach(viewModel.existingPasskeys) { passkeyInfo in
+ Button(action: {
+ viewModel.handleSelectReplace(passkeyId: passkeyInfo.id)
+ navigationPath.append(PasskeyNavigationDestination.replace(passkeyInfo.id))
+ }, label: {
+ ExistingPasskeyRow(passkey: passkeyInfo)
+ })
+ .buttonStyle(PlainButtonStyle())
+ }
}
}
+ .frame(maxHeight: 200)
}
- .frame(maxHeight: 200)
}
Spacer()
@@ -210,18 +238,70 @@ public struct PasskeyRegistrationView: View {
PasskeyFormView(
viewModel: viewModel,
isReplaceMode: false,
- replacingPasskeyId: nil
+ replacingPasskeyId: nil,
+ mergingItemId: nil
)
case .replace(let passkeyId):
PasskeyFormView(
viewModel: viewModel,
isReplaceMode: true,
- replacingPasskeyId: passkeyId
+ replacingPasskeyId: passkeyId,
+ mergingItemId: nil
+ )
+ case .mergeWithItem(let itemId):
+ PasskeyFormView(
+ viewModel: viewModel,
+ isReplaceMode: false,
+ replacingPasskeyId: nil,
+ mergingItemId: itemId
)
}
}
}
+/// Row displaying an existing item (without passkey) that can have a passkey merged into it
+struct ExistingItemRow: View {
+ let item: ItemWithCredentialInfo
+ let rpId: String
+
+ @Environment(\.colorScheme) private var colorScheme
+
+ var body: some View {
+ HStack(spacing: 12) {
+ // Credential icon
+ Image(systemName: "person.crop.circle.fill")
+ .foregroundColor(ColorConstants.Light.primary)
+ .frame(width: 24)
+
+ VStack(alignment: .leading, spacing: 4) {
+ Text(item.serviceName ?? rpId)
+ .font(.body)
+ .fontWeight(.medium)
+ .foregroundColor(colorScheme == .dark ? ColorConstants.Dark.text : ColorConstants.Light.text)
+
+ HStack(spacing: 4) {
+ if let username = item.username {
+ Text(username)
+ .font(.caption)
+ .foregroundColor(colorScheme == .dark ? ColorConstants.Dark.textMuted : ColorConstants.Light.textMuted)
+ }
+ }
+ }
+
+ Spacer()
+
+ Image(systemName: "chevron.right")
+ .foregroundColor(colorScheme == .dark ? ColorConstants.Dark.textMuted : ColorConstants.Light.textMuted)
+ .font(.caption)
+ }
+ .padding()
+ .background(
+ (colorScheme == .dark ? ColorConstants.Dark.accentBackground : ColorConstants.Light.accentBackground)
+ )
+ .cornerRadius(8)
+ }
+}
+
/// View model for passkey registration
public class PasskeyRegistrationViewModel: ObservableObject {
@Published public var requestId: String
@@ -233,7 +313,10 @@ public class PasskeyRegistrationViewModel: ObservableObject {
@Published public var isLoading: Bool = false
@Published public var loadingMessage: String = ""
@Published public var existingPasskeys: [PasskeyWithCredentialInfo] = []
+ @Published public var existingItemsWithoutPasskey: [ItemWithCredentialInfo] = []
@Published public var selectedPasskeyToReplace: UUID?
+ @Published public var selectedItemToMerge: UUID?
+ @Published public var isMergeMode: Bool = false
private let completionHandler: (Bool) -> Void
private let cancelHandler: () -> Void
@@ -245,6 +328,7 @@ public class PasskeyRegistrationViewModel: ObservableObject {
userName: String? = nil,
userDisplayName: String? = nil,
existingPasskeys: [PasskeyWithCredentialInfo] = [],
+ existingItemsWithoutPasskey: [ItemWithCredentialInfo] = [],
completionHandler: @escaping (Bool) -> Void,
cancelHandler: @escaping () -> Void
) {
@@ -256,6 +340,7 @@ public class PasskeyRegistrationViewModel: ObservableObject {
// Initialize displayName to rpId by default
self.displayName = rpId
self.existingPasskeys = existingPasskeys
+ self.existingItemsWithoutPasskey = existingItemsWithoutPasskey
self.completionHandler = completionHandler
self.cancelHandler = cancelHandler
}
@@ -269,17 +354,31 @@ public class PasskeyRegistrationViewModel: ObservableObject {
public func handleCreateNew() {
selectedPasskeyToReplace = nil
+ selectedItemToMerge = nil
+ isMergeMode = false
displayName = rpId
}
public func handleSelectReplace(passkeyId: UUID) {
selectedPasskeyToReplace = passkeyId
+ selectedItemToMerge = nil
+ isMergeMode = false
// Pre-fill display name with the existing passkey's name
if let passkey = existingPasskeys.first(where: { $0.id == passkeyId }) {
displayName = passkey.displayName
}
}
+ public func handleSelectMerge(itemId: UUID) {
+ selectedPasskeyToReplace = nil
+ selectedItemToMerge = itemId
+ isMergeMode = true
+ // Pre-fill display name with the existing item's service name
+ if let item = existingItemsWithoutPasskey.first(where: { $0.itemId == itemId }) {
+ displayName = item.serviceName ?? rpId
+ }
+ }
+
public func createPasskey() {
// Validate title is not empty
let trimmedTitle = displayName.trimmingCharacters(in: .whitespacesAndNewlines)
diff --git a/apps/mobile-app/ios/VaultUI/en.lproj/Localizable.strings b/apps/mobile-app/ios/VaultUI/en.lproj/Localizable.strings
index 1087271b1..1338f616c 100644
--- a/apps/mobile-app/ios/VaultUI/en.lproj/Localizable.strings
+++ b/apps/mobile-app/ios/VaultUI/en.lproj/Localizable.strings
@@ -57,6 +57,12 @@
"replace_passkey_explanation" = "This will replace the existing passkey with a new one. Please be aware that your old passkey will be overwritten and no longer accessible. If you wish to create a separate passkey instead, go back to the previous screen.";
"create_passkey_explanation" = "This creates a new passkey and stores it in your vault. It will be automatically synced across all your devices that use AliasVault.";
+/* Passkey merge with existing item */
+"passkey_add_to_existing" = "Or, add passkey to an existing item";
+"add_passkey_title" = "Add Passkey";
+"confirm_add_passkey" = "Add Passkey";
+"merge_passkey_explanation" = "This will add a passkey to your existing item. Your password and other data will be preserved.";
+
/* PIN Unlock */
"unlock_vault" = "Unlock Vault";
"enter_pin_to_unlock_vault" = "Enter your PIN to unlock your vault";