Skip to content

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

Refactor native swift autofill to use custom autofill model instead of legacy credential object (#1404)

Leendert de Borst63a897cae743
diff --git a/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Credential.swift b/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Credential.swift
index 815e69e82..d150629fe 100644
--- a/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Credential.swift
+++ b/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Credential.swift
@@ -16,7 +16,7 @@ extension CredentialProviderViewController: CredentialProviderDelegate {
// Create the ViewModel with injected behaviors
let viewModel = CredentialProviderViewModel(
loader: {
- return try await vaultStore.getAllCredentials()
+ return try await vaultStore.getAllAutofillCredentials()
},
selectionHandler: { identifier, password in
self.handleCredentialSelection(identifier: identifier, password: password)
@@ -79,7 +79,7 @@ extension CredentialProviderViewController: CredentialProviderDelegate {
let minimumDuration: TimeInterval = 0.7 // 700ms
do {
- let credentials = try vaultStore.getAllCredentials()
+ let credentials = try vaultStore.getAllAutofillCredentials()
if let matchingCredential = credentials.first(where: { credential in
return credential.id.uuidString == request.credentialIdentity.recordIdentifier
@@ -94,7 +94,7 @@ extension CredentialProviderViewController: CredentialProviderDelegate {
let identifier = request.credentialIdentity.user
let passwordCredential = ASPasswordCredential(
user: identifier,
- password: matchingCredential.password?.value ?? ""
+ password: matchingCredential.password ?? ""
)
self.extensionContext.completeRequest(withSelectedCredential: passwordCredential, completionHandler: nil)
} else {
diff --git a/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift b/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift
index ed1f2840d..c0f7a390f 100644
--- a/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift
+++ b/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift
@@ -15,7 +15,7 @@ extension CredentialProviderViewController: PasskeyProviderDelegate {
func setupPasskeyView(vaultStore: VaultStore, rpId: String, clientDataHash: Data) throws -> UIViewController {
let viewModel = PasskeyProviderViewModel(
loader: {
- return try vaultStore.getAllCredentialsWithPasskeys()
+ return try vaultStore.getAllAutofillCredentialsWithPasskeys()
},
selectionHandler: { credential in
// For passkey authentication, we assume the data is available
@@ -419,7 +419,7 @@ extension CredentialProviderViewController: PasskeyProviderDelegate {
}
// Step 6: Update the IdentityStore with the new credential (async call)
- let credentials = try vaultStore.getAllCredentials()
+ let credentials = try vaultStore.getAllAutofillCredentials()
try await CredentialIdentityStore.shared.saveCredentialIdentities(credentials)
// Step 7: Create the ASPasskeyRegistrationCredential to return to the system
@@ -543,7 +543,7 @@ extension CredentialProviderViewController: PasskeyProviderDelegate {
/**
* Handle passkey credential selection from picker
*/
- internal func handlePasskeySelection(credential: Credential, clientDataHash: Data, rpId: String) {
+ internal func handlePasskeySelection(credential: AutofillCredential, clientDataHash: Data, rpId: String) {
do {
// Get the first matching passkey for the RP ID
guard let passkeys = credential.passkeys,
diff --git a/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift b/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift
index c0414a3e7..bb5f9a613 100644
--- a/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift
+++ b/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift
@@ -14,7 +14,7 @@ protocol CredentialProviderDelegate: AnyObject {
protocol PasskeyProviderDelegate: AnyObject {
func setupPasskeyView(vaultStore: VaultStore, rpId: String, clientDataHash: Data) throws -> UIViewController
- func handlePasskeySelection(credential: Credential, clientDataHash: Data, rpId: String)
+ func handlePasskeySelection(credential: AutofillCredential, clientDataHash: Data, rpId: String)
}
/**
@@ -450,7 +450,7 @@ public class CredentialProviderViewController: ASCredentialProviderViewControlle
print("Credential identity store is empty, performing initial sync")
// Get all credentials from the vault (already unlocked)
- let credentials = try vaultStore.getAllCredentials()
+ let credentials = try vaultStore.getAllAutofillCredentials()
// Save credentials to the iOS credential identity store
try await CredentialIdentityStore.shared.saveCredentialIdentities(credentials)
diff --git a/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift b/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift
index 717d35c59..485211520 100644
--- a/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift
+++ b/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift
@@ -468,7 +468,7 @@ public class VaultManager: NSObject {
Task {
do {
// Get all credentials from the vault
- let credentials = try vaultStore.getAllCredentials()
+ let credentials = try vaultStore.getAllAutofillCredentials()
// Register both passwords and passkeys for QuickType and manual selection
try await CredentialIdentityStore.shared.saveCredentialIdentities(credentials)
diff --git a/apps/mobile-app/ios/VaultModels/AutofillCredential.swift b/apps/mobile-app/ios/VaultModels/AutofillCredential.swift
new file mode 100644
index 000000000..51860289b
--- /dev/null
+++ b/apps/mobile-app/ios/VaultModels/AutofillCredential.swift
@@ -0,0 +1,96 @@
+import Foundation
+
+/// AutofillCredential is a purpose-specific model for iOS Autofill functionality.
+/// It provides a simplified view of Item data optimized for password/passkey autofill.
+/// This replaces the legacy Credential model which was based on the old data structure.
+public struct AutofillCredential: Codable, Hashable, Equatable {
+ public let id: UUID
+ public let serviceName: String?
+ public let serviceUrl: String?
+ public let logo: Data?
+ public let username: String?
+ public let email: String?
+ public let password: String?
+ public let notes: String?
+ public let passkeys: [Passkey]?
+ public let createdAt: Date
+ public let updatedAt: Date
+
+ public init(
+ id: UUID,
+ serviceName: String?,
+ serviceUrl: String?,
+ logo: Data?,
+ username: String?,
+ email: String?,
+ password: String?,
+ notes: String?,
+ passkeys: [Passkey]?,
+ createdAt: Date,
+ updatedAt: Date
+ ) {
+ self.id = id
+ self.serviceName = serviceName
+ self.serviceUrl = serviceUrl
+ self.logo = logo
+ self.username = username
+ self.email = email
+ self.password = password
+ self.notes = notes
+ self.passkeys = passkeys
+ self.createdAt = createdAt
+ self.updatedAt = updatedAt
+ }
+
+ /// Initialize from an Item model.
+ /// - Parameters:
+ /// - item: The Item to convert from
+ /// - passkeys: Optional passkeys associated with this item
+ public init(from item: Item, passkeys: [Passkey]? = nil) {
+ self.id = item.id
+ self.serviceName = item.name
+ self.serviceUrl = item.url
+ self.logo = item.logo
+ self.username = item.username
+ self.email = item.email
+ self.password = item.password
+ self.notes = item.getFieldValue(FieldKey.notesContent)
+ self.passkeys = passkeys
+ self.createdAt = item.createdAt
+ self.updatedAt = item.updatedAt
+ }
+
+ public static func == (lhs: AutofillCredential, rhs: AutofillCredential) -> Bool {
+ return lhs.id == rhs.id
+ }
+
+ public func hash(into hasher: inout Hasher) {
+ hasher.combine(id)
+ }
+
+ // MARK: - Autofill Helpers
+
+ /// Returns username or email, prioritizing username.
+ /// Used for autofill identifier display and form filling.
+ public var identifier: String {
+ if let username = username, !username.isEmpty {
+ return username
+ }
+ if let email = email, !email.isEmpty {
+ return email
+ }
+ return ""
+ }
+
+ /// Returns true if this credential has a password value.
+ public var hasPassword: Bool {
+ guard let password = password else { return false }
+ return !password.isEmpty
+ }
+
+ /// Returns true if this credential has passkeys.
+ public var hasPasskeys: Bool {
+ guard let passkeys = passkeys else { return false }
+ return !passkeys.isEmpty
+ }
+}
diff --git a/apps/mobile-app/ios/VaultModels/Credential.swift b/apps/mobile-app/ios/VaultModels/Credential.swift
deleted file mode 100644
index 70609fa22..000000000
--- a/apps/mobile-app/ios/VaultModels/Credential.swift
+++ /dev/null
@@ -1,136 +0,0 @@
-import Foundation
-
-public struct Credential: Codable, Hashable, Equatable {
- public let id: UUID
- public let alias: Alias?
- public let service: Service
- public let username: String?
- public let notes: String?
- public let password: Password?
- public let passkeys: [Passkey]? // Array of passkeys linked to this credential
- public let createdAt: Date
- public let updatedAt: Date
- public let isDeleted: Bool
-
- public init(
- id: UUID,
- alias: Alias?,
- service: Service,
- username: String?,
- notes: String?,
- password: Password?,
- passkeys: [Passkey]? = nil,
- createdAt: Date,
- updatedAt: Date,
- isDeleted: Bool
- ) {
- self.id = id
- self.alias = alias
- self.service = service
- self.username = username
- self.notes = notes
- self.password = password
- self.passkeys = passkeys
- self.createdAt = createdAt
- self.updatedAt = updatedAt
- self.isDeleted = isDeleted
- }
-
- public static func == (lhs: Credential, rhs: Credential) -> Bool {
- return lhs.id == rhs.id
- }
-
- public func hash(into hasher: inout Hasher) {
- hasher.combine(id)
- }
-}
-
-public struct Service: Codable, Hashable {
- public let id: UUID
- public let name: String?
- public let url: String?
- public let logo: Data?
- public let createdAt: Date
- public let updatedAt: Date
- public let isDeleted: Bool
-
- public init(
- id: UUID,
- name: String?,
- url: String?,
- logo: Data?,
- createdAt: Date,
- updatedAt: Date,
- isDeleted: Bool
- ) {
- self.id = id
- self.name = name
- self.url = url
- self.logo = logo
- self.createdAt = createdAt
- self.updatedAt = updatedAt
- self.isDeleted = isDeleted
- }
-}
-
-public struct Password: Codable {
- public let id: UUID
- public let credentialId: UUID
- public let value: String
- public let createdAt: Date
- public let updatedAt: Date
- public let isDeleted: Bool
-
- public init(
- id: UUID,
- credentialId: UUID,
- value: String,
- createdAt: Date,
- updatedAt: Date,
- isDeleted: Bool
- ) {
- self.id = id
- self.credentialId = credentialId
- self.value = value
- self.createdAt = createdAt
- self.updatedAt = updatedAt
- self.isDeleted = isDeleted
- }
-}
-
-public struct Alias: Codable, Hashable {
- public let id: UUID
- public let gender: String?
- public let firstName: String?
- public let lastName: String?
- public let nickName: String?
- public let birthDate: Date
- public let email: String?
- public let createdAt: Date
- public let updatedAt: Date
- public let isDeleted: Bool
-
- public init(
- id: UUID,
- gender: String?,
- firstName: String?,
- lastName: String?,
- nickName: String?,
- birthDate: Date,
- email: String?,
- createdAt: Date,
- updatedAt: Date,
- isDeleted: Bool
- ) {
- self.id = id
- self.gender = gender
- self.firstName = firstName
- self.lastName = lastName
- self.nickName = nickName
- self.birthDate = birthDate
- self.email = email
- self.createdAt = createdAt
- self.updatedAt = updatedAt
- self.isDeleted = isDeleted
- }
-}
diff --git a/apps/mobile-app/ios/VaultStoreKit/CredentialIdentityStore.swift b/apps/mobile-app/ios/VaultStoreKit/CredentialIdentityStore.swift
index f893b361d..45d14a2af 100644
--- a/apps/mobile-app/ios/VaultStoreKit/CredentialIdentityStore.swift
+++ b/apps/mobile-app/ios/VaultStoreKit/CredentialIdentityStore.swift
@@ -18,7 +18,7 @@ public class CredentialIdentityStore {
/// Save credentials into the native iOS credential store.
/// - Parameters:
/// - credentials: The credentials to register
- public func saveCredentialIdentities(_ credentials: [Credential]) async throws {
+ public func saveCredentialIdentities(_ credentials: [AutofillCredential]) async throws {
var allIdentities: [ASCredentialIdentity] = []
let state = await storeState()
@@ -77,25 +77,25 @@ public class CredentialIdentityStore {
}
/// Create password credential identities from credentials
- private func createPasswordIdentities(from credentials: [Credential]) -> [ASPasswordCredentialIdentity] {
+ private func createPasswordIdentities(from credentials: [AutofillCredential]) -> [ASPasswordCredentialIdentity] {
return credentials.compactMap { credential in
- guard credential.passkeys?.isEmpty == true else {
- // Skip if this record is a passkey as it will be saved in the createPasskeyIdentities method
+ guard !credential.hasPasskeys else {
+ // Skip if this record has passkeys as they will be saved in createPasskeyIdentities
return nil
}
- guard let password = credential.password, !password.value.isEmpty else {
- // Skip credentials with no password (e.g. applies when this record is a passkey)
+ guard credential.hasPassword else {
+ // Skip credentials with no password
return nil
}
- guard let urlString = credential.service.url,
+ guard let urlString = credential.serviceUrl,
let url = URL(string: urlString),
let host = url.host else {
return nil
}
- let identifier = CredentialHelpers.usernameOrEmail(credential: credential)
+ let identifier = credential.identifier
guard !identifier.isEmpty else {
return nil // Skip credentials with no identifier
}
@@ -111,7 +111,7 @@ public class CredentialIdentityStore {
}
/// Create passkey credential identities from credentials
- private func createPasskeyIdentities(from credentials: [Credential]) -> [ASPasskeyCredentialIdentity] {
+ private func createPasskeyIdentities(from credentials: [AutofillCredential]) -> [ASPasskeyCredentialIdentity] {
return credentials.flatMap { credential -> [ASPasskeyCredentialIdentity] in
guard let passkeys = credential.passkeys else {
return []
@@ -120,8 +120,8 @@ public class CredentialIdentityStore {
return passkeys.filter { !($0.isDeleted) }
.compactMap { passkey in
// Get the userName for display in iOS AutoFill UI
- // Passkeys don't store userName in the database, so we use the credential's username or email
- let userName = passkey.userName ?? CredentialHelpers.usernameOrEmail(credential: credential)
+ // Passkeys may store userName, otherwise use the credential's identifier
+ let userName = passkey.userName ?? credential.identifier
// Convert passkey.Id to bytes for credentialID
let credentialId = try? PasskeyHelper.guidToBytes(passkey.id.uuidString)
diff --git a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Passkey.swift b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Passkey.swift
index cbb2b3536..8cd0e53c5 100644
--- a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Passkey.swift
+++ b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Passkey.swift
@@ -60,14 +60,15 @@ extension VaultStore {
* Create an item with a passkey (for passkey registration)
* This creates an Item record with field values and links the passkey to it
*/
+ @discardableResult
public func createCredentialWithPasskey(
rpId: String,
userName: String?,
displayName: String,
passkey: Passkey,
logo: Data? = nil
- ) throws -> Credential {
- _ = try passkeyRepository.createItemWithPasskey(
+ ) throws -> UUID {
+ let itemIdString = try passkeyRepository.createItemWithPasskey(
rpId: rpId,
userName: userName,
displayName: displayName,
@@ -75,32 +76,12 @@ extension VaultStore {
logo: logo
)
- // Return the credential (legacy format for backwards compatibility)
- let itemId = passkey.parentCredentialId
- let now = Date()
-
- let service = Service(
- id: itemId,
- name: displayName,
- url: "https://\(rpId)",
- logo: logo,
- createdAt: now,
- updatedAt: now,
- isDeleted: false
- )
+ // Return the created item ID
+ guard let itemId = UUID(uuidString: itemIdString) else {
+ throw VaultStoreError.databaseError("Invalid item ID returned")
+ }
- return Credential(
- id: itemId,
- alias: nil,
- service: service,
- username: userName,
- notes: nil,
- password: nil,
- passkeys: [passkey],
- createdAt: now,
- updatedAt: now,
- isDeleted: false
- )
+ return itemId
}
/**
diff --git a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Query.swift b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Query.swift
index b5a2dd84d..b2c2c3cc4 100644
--- a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Query.swift
+++ b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Query.swift
@@ -270,92 +270,30 @@ extension VaultStore {
return try itemRepository.update(item)
}
- // MARK: - Legacy Credentials (Compatibility Layer)
+ // MARK: - Autofill Credentials
- /// Get all credentials from the database.
- /// This method converts the new Items model back to the legacy Credential model for compatibility.
- /// Used by iOS Autofill extension which expects the old Credential structure.
- public func getAllCredentials() throws -> [Credential] {
+ /// Get all items for autofill from the database.
+ /// This method converts Items to AutofillCredential for iOS Autofill extension.
+ public func getAllAutofillCredentials() throws -> [AutofillCredential] {
let items = try getAllItems()
- return items.compactMap { convertItemToCredential($0) }
+ return items.compactMap { convertItemToAutofillCredential($0) }
}
- /// Convert an Item to the legacy Credential format.
- /// Used to maintain backwards compatibility with iOS Autofill extension.
- private func convertItemToCredential(_ item: Item) -> Credential? {
- // Create a Service from the item
- let service = Service(
- id: item.id, // Use item ID as service ID (they're now the same entity)
- name: item.name,
- url: item.url,
- logo: item.logo,
- createdAt: item.createdAt,
- updatedAt: item.updatedAt,
- isDeleted: false
- )
-
- // Create an Alias if the item has alias fields
- var alias: Alias?
- if item.firstName != nil || item.lastName != nil || item.email != nil {
- // Default birth date for backwards compatibility
- var dateComponents = DateComponents()
- dateComponents.year = 1
- dateComponents.month = 1
- dateComponents.day = 1
- let defaultBirthDate = Calendar(identifier: .gregorian).date(from: dateComponents)!
-
- alias = Alias(
- id: item.id, // Use item ID as alias ID
- gender: item.getFieldValue(FieldKey.aliasGender),
- firstName: item.firstName,
- lastName: item.lastName,
- nickName: nil,
- birthDate: defaultBirthDate, // TODO: Parse birthdate from field value
- email: item.email,
- createdAt: item.createdAt,
- updatedAt: item.updatedAt,
- isDeleted: false
- )
- }
-
- // Create a Password if the item has a password field
- var password: Password?
- if let passwordValue = item.password {
- password = Password(
- id: UUID(), // Generate a new ID for the password
- credentialId: item.id,
- value: passwordValue,
- createdAt: item.createdAt,
- updatedAt: item.updatedAt,
- isDeleted: false
- )
- }
-
+ /// Convert an Item to an AutofillCredential for iOS Autofill.
+ private func convertItemToAutofillCredential(_ item: Item) -> AutofillCredential? {
// Load passkeys for this item
let passkeys = try? getPasskeys(forItemId: item.id)
- return Credential(
- id: item.id,
- alias: alias,
- service: service,
- username: item.username,
- notes: item.getFieldValue("login.notes"),
- password: password,
- passkeys: passkeys,
- createdAt: item.createdAt,
- updatedAt: item.updatedAt,
- isDeleted: false
- )
+ return AutofillCredential(from: item, passkeys: passkeys)
}
- /// Get all credentials that have passkeys by filtering the result of getAllCredentials.
- public func getAllCredentialsWithPasskeys() throws -> [Credential] {
- var credentials = try getAllCredentials()
+ /// Get all items that have passkeys for passkey autofill.
+ public func getAllAutofillCredentialsWithPasskeys() throws -> [AutofillCredential] {
+ var credentials = try getAllAutofillCredentials()
// Filter to only include credentials that actually have passkeys
credentials = credentials.filter { credential in
- guard let passkeys = credential.passkeys else { return false }
- return !passkeys.isEmpty
+ return credential.hasPasskeys
}
return credentials
diff --git a/apps/mobile-app/ios/VaultUI/Selection/Components/CredentialCardView.swift b/apps/mobile-app/ios/VaultUI/Selection/Components/CredentialCardView.swift
index 9bc7460fe..cc1568406 100644
--- a/apps/mobile-app/ios/VaultUI/Selection/Components/CredentialCardView.swift
+++ b/apps/mobile-app/ios/VaultUI/Selection/Components/CredentialCardView.swift
@@ -2,16 +2,16 @@ import SwiftUI
import VaultModels
import VaultUtils
-/// Credential card view
-public struct CredentialCard: View {
- let credential: Credential
+/// Autofill credential card view
+public struct AutofillCredentialCard: View {
+ let credential: AutofillCredential
let action: () -> Void
let onCopy: () -> Void
@Environment(\.colorScheme) private var colorScheme
@State private var showCopyToast = false
@State private var copyToastMessage = ""
- public init(credential: Credential, action: @escaping () -> Void, onCopy: @escaping () -> Void) {
+ public init(credential: AutofillCredential, action: @escaping () -> Void, onCopy: @escaping () -> Void) {
self.credential = credential
self.action = action
self.onCopy = onCopy
@@ -25,15 +25,15 @@ public struct CredentialCard: View {
Button(action: action) {
HStack(spacing: 16) {
// Service logo
- ServiceLogoView(logoData: credential.service.logo)
+ ServiceLogoView(logoData: credential.logo)
.frame(width: 32, height: 32)
VStack(alignment: .leading, spacing: 4) {
- Text(truncateText(credential.service.name ?? "Unknown", limit: 26))
+ Text(truncateText(credential.serviceName ?? "Unknown", limit: 26))
.font(.headline)
.foregroundColor(colors.text)
- Text(truncateText(CredentialHelpers.usernameOrEmail(credential: credential), limit: 26))
+ Text(truncateText(credential.identifier, limit: 26))
.font(.subheadline)
.foregroundColor(colors.textMuted)
}
@@ -68,7 +68,7 @@ public struct CredentialCard: View {
})
}
- if let password = credential.password?.value, !password.isEmpty {
+ if let password = credential.password, !password.isEmpty {
Button(action: {
UIPasteboard.general.string = password
copyToastMessage = NSLocalizedString("password_copied", comment: "Password copied message")
@@ -82,7 +82,7 @@ public struct CredentialCard: View {
})
}
- if let email = credential.alias?.email, !email.isEmpty {
+ if let email = credential.email, !email.isEmpty {
Button(action: {
UIPasteboard.general.string = email
copyToastMessage = NSLocalizedString("email_copied", comment: "Email copied message")
@@ -97,8 +97,8 @@ public struct CredentialCard: View {
}
if (credential.username != nil && !credential.username!.isEmpty) ||
- (credential.password?.value != nil && !credential.password!.value.isEmpty) ||
- (credential.alias?.email != nil && !credential.alias!.email!.isEmpty) {
+ (credential.password != nil && !credential.password!.isEmpty) ||
+ (credential.email != nil && !credential.email!.isEmpty) {
Divider()
}
@@ -156,43 +156,19 @@ public func truncateText(_ text: String?, limit: Int) -> String {
}
#Preview {
- CredentialCard(
- credential: Credential(
+ AutofillCredentialCard(
+ credential: AutofillCredential(
id: UUID(),
- alias: Alias(
- id: UUID(),
- gender: "Male",
- firstName: "John",
- lastName: "Doe",
- nickName: "Johnny",
- birthDate: Date(),
- email: "[email protected]",
- createdAt: Date(),
- updatedAt: Date(),
- isDeleted: false
- ),
- service: Service(
- id: UUID(),
- name: "Example Service with a very long name bla bla bla",
- url: "https://example.com",
- logo: nil,
- createdAt: Date(),
- updatedAt: Date(),
- isDeleted: false
- ),
+ serviceName: "Example Service with a very long name bla bla bla",
+ serviceUrl: "https://example.com",
+ logo: nil,
username: "usernameverylongverylongtextindeed",
+ email: "[email protected]",
+ password: "securepassword123",
notes: "Sample notes",
- password: Password(
- id: UUID(),
- credentialId: UUID(),
- value: "securepassword123",
- createdAt: Date(),
- updatedAt: Date(),
- isDeleted: false
- ),
+ passkeys: nil,
createdAt: Date(),
- updatedAt: Date(),
- isDeleted: false
+ updatedAt: Date()
),
action: {},
onCopy: {}
diff --git a/apps/mobile-app/ios/VaultUI/Selection/CredentialProviderView.swift b/apps/mobile-app/ios/VaultUI/Selection/CredentialProviderView.swift
index 99e52cc0f..9c66eaf57 100644
--- a/apps/mobile-app/ios/VaultUI/Selection/CredentialProviderView.swift
+++ b/apps/mobile-app/ios/VaultUI/Selection/CredentialProviderView.swift
@@ -86,8 +86,8 @@ public struct CredentialProviderView: View {
.padding(.top, 60)
} else {
LazyVStack(spacing: 8) {
- ForEach(viewModel.filteredCredentials, id: \.service) { credential in
- CredentialCardWithSelection(
+ ForEach(viewModel.filteredCredentials, id: \.id) { credential in
+ AutofillCredentialCardWithSelection(
credential: credential,
isChoosingTextToInsert: viewModel.isChoosingTextToInsert,
onSelect: { username, password in
@@ -154,10 +154,10 @@ public struct CredentialProviderView: View {
}
}
-// MARK: - CredentialCardWithSelection
+// MARK: - AutofillCredentialCardWithSelection
-private struct CredentialCardWithSelection: View {
- let credential: Credential
+private struct AutofillCredentialCardWithSelection: View {
+ let credential: AutofillCredential
let isChoosingTextToInsert: Bool
let onSelect: (String, String) -> Void
let onCopy: () -> Void
@@ -166,28 +166,15 @@ private struct CredentialCardWithSelection: View {
@Environment(\.colorScheme) private var colorScheme
var body: some View {
- CredentialCard(credential: credential, action: {
+ AutofillCredentialCard(credential: credential, action: {
if isChoosingTextToInsert {
showSelectionSheet = true
} else {
- // For normal autofill, determine the best identifier and fill immediately
- let username = credential.username?.trimmingCharacters(in: .whitespacesAndNewlines)
- let email = credential.alias?.email?.trimmingCharacters(in: .whitespacesAndNewlines)
- let hasUsername = !(username?.isEmpty ?? true)
- let hasEmail = !(email?.isEmpty ?? true)
-
- // Prefer username over email if both exist, or use whichever is available
- let identifier: String
- if hasUsername {
- identifier = username!
- } else if hasEmail {
- identifier = email!
- } else {
- identifier = ""
- }
+ // For normal autofill, use the credential's identifier property
+ let identifier = credential.identifier
// Fill both username and password immediately for normal autofill
- onSelect(identifier, credential.password?.value ?? "")
+ onSelect(identifier, credential.password ?? "")
}
}, onCopy: onCopy)
.confirmationDialog(
@@ -201,14 +188,14 @@ private struct CredentialCardWithSelection: View {
}
}
- if let email = credential.alias?.email, !email.isEmpty {
+ if let email = credential.email, !email.isEmpty {
Button(String(localized: "email_prefix", bundle: locBundle) + email) {
onSelect(email, "")
}
}
Button(String(localized: "password", bundle: locBundle)) {
- onSelect(credential.password?.value ?? "", "")
+ onSelect(credential.password ?? "", "")
}
Button(String(localized: "cancel", bundle: locBundle), role: .cancel) {}
@@ -221,8 +208,8 @@ private struct CredentialCardWithSelection: View {
// MARK: - ViewModel
public class CredentialProviderViewModel: ObservableObject {
- @Published var credentials: [Credential] = []
- @Published var filteredCredentials: [Credential] = []
+ @Published var credentials: [AutofillCredential] = []
+ @Published var filteredCredentials: [AutofillCredential] = []
@Published var searchText = ""
@Published var isLoading = true
@Published var showError = false
@@ -230,12 +217,12 @@ public class CredentialProviderViewModel: ObservableObject {
@Published public var isChoosingTextToInsert = false
@Published public var serviceUrl: String?
- private let loader: () async throws -> [Credential]
+ private let loader: () async throws -> [AutofillCredential]
private let selectionHandler: (String, String) -> Void
private let cancelHandler: () -> Void
public init(
- loader: @escaping () async throws -> [Credential],
+ loader: @escaping () async throws -> [AutofillCredential],
selectionHandler: @escaping (String, String) -> Void,
cancelHandler: @escaping () -> Void,
serviceUrl: String? = nil
@@ -287,62 +274,20 @@ public class CredentialProviderViewModel: ObservableObject {
}
// MARK: - Preview Helpers
-extension Service {
- static var preview: Service {
- Service(
+extension AutofillCredential {
+ static var preview: AutofillCredential {
+ AutofillCredential(
id: UUID(),
- name: "Example Service",
- url: "https://example.com",
+ serviceName: "Example Service",
+ serviceUrl: "https://example.com",
logo: nil,
- createdAt: Date(),
- updatedAt: Date(),
- isDeleted: false
- )
- }
-}
-
-extension Password {
- static var preview: Password {
- Password(
- id: UUID(),
- credentialId: UUID(),
- value: "password123",
- createdAt: Date(),
- updatedAt: Date(),
- isDeleted: false
- )
- }
-}
-
-extension Alias {
- static var preview: Alias {
- Alias(
- id: UUID(),
- gender: "Not specified",
- firstName: "John",
- lastName: "Doe",
- nickName: "JD",
- birthDate: Date(),
- email: "[email protected]",
- createdAt: Date(),
- updatedAt: Date(),
- isDeleted: false
- )
- }
-}
-
-extension Credential {
- static var preview: Credential {
- Credential(
- id: UUID(),
- alias: .preview,
- service: .preview,
username: "johndoe",
+ email: "[email protected]",
+ password: "password123",
notes: "Sample credential",
- password: .preview,
+ passkeys: nil,
createdAt: Date(),
- updatedAt: Date(),
- isDeleted: false
+ updatedAt: Date()
)
}
}
@@ -350,26 +295,20 @@ extension Credential {
// Preview setup
public class PreviewCredentialProviderViewModel: CredentialProviderViewModel {
init() {
- let previewCredentials = [
+ let previewCredentials: [AutofillCredential] = [
.preview,
- Credential(
+ AutofillCredential(
id: UUID(),
- alias: .preview,
- service: Service(
- id: UUID(),
- name: "Another Service",
- url: "https://another.com",
- logo: nil,
- createdAt: Date(),
- updatedAt: Date(),
- isDeleted: false
- ),
+ serviceName: "Another Service",
+ serviceUrl: "https://another.com",
+ logo: nil,
username: "anotheruser",
+ email: "[email protected]",
+ password: "password456",
notes: "Another sample credential",
- password: .preview,
+ passkeys: nil,
createdAt: Date(),
- updatedAt: Date(),
- isDeleted: false
+ updatedAt: Date()
)
]
diff --git a/apps/mobile-app/ios/VaultUI/Selection/PasskeyProviderView.swift b/apps/mobile-app/ios/VaultUI/Selection/PasskeyProviderView.swift
index 70dfcf43e..d990616a3 100644
--- a/apps/mobile-app/ios/VaultUI/Selection/PasskeyProviderView.swift
+++ b/apps/mobile-app/ios/VaultUI/Selection/PasskeyProviderView.swift
@@ -111,7 +111,7 @@ public struct PasskeyProviderView: View {
// MARK: - Passkey Credential Card
private struct PasskeyCredentialCard: View {
- let credential: Credential
+ let credential: AutofillCredential
let rpId: String?
let action: () -> Void
@@ -126,7 +126,7 @@ private struct PasskeyCredentialCard: View {
VStack(alignment: .leading, spacing: 12) {
HStack {
// Service logo (favicon) or fallback to passkey icon
- if let logo = credential.service.logo, !logo.isEmpty,
+ if let logo = credential.logo, !logo.isEmpty,
let uiImage = UIImage(data: logo) {
Image(uiImage: uiImage)
.resizable()
@@ -148,22 +148,19 @@ private struct PasskeyCredentialCard: View {
}
VStack(alignment: .leading, spacing: 4) {
- Text(credential.service.name ?? credential.service.url ?? "-")
+ Text(credential.serviceName ?? credential.serviceUrl ?? "-")
.font(.headline)
.foregroundColor(colors.text)
- if let username = credential.username, !username.isEmpty {
- Text(username)
- .font(.subheadline)
- .foregroundColor(colors.textMuted)
- } else if let email = credential.alias?.email {
- Text(email)
+ let identifier = credential.identifier
+ if !identifier.isEmpty {
+ Text(identifier)
.font(.subheadline)
.foregroundColor(colors.textMuted)
}
// Show passkey count
- if let passkeys = credential.passkeys, !passkeys.isEmpty {
+ if credential.hasPasskeys {
Text(String(localized: "passkey", bundle: locBundle))
.font(.caption)
.foregroundColor(colors.primary)
@@ -187,21 +184,21 @@ private struct PasskeyCredentialCard: View {
// MARK: - ViewModel
public class PasskeyProviderViewModel: ObservableObject {
- @Published var credentials: [Credential] = []
- @Published var filteredCredentials: [Credential] = []
+ @Published var credentials: [AutofillCredential] = []
+ @Published var filteredCredentials: [AutofillCredential] = []
@Published var searchText = ""
@Published var isLoading = true
@Published var showError = false
@Published var errorMessage = ""
@Published public var rpId: String?
- private let loader: () async throws -> [Credential]
- private let selectionHandler: (Credential) -> Void
+ private let loader: () async throws -> [AutofillCredential]
+ private let selectionHandler: (AutofillCredential) -> Void
private let cancelHandler: () -> Void
public init(
- loader: @escaping () async throws -> [Credential],
- selectionHandler: @escaping (Credential) -> Void,
+ loader: @escaping () async throws -> [AutofillCredential],
+ selectionHandler: @escaping (AutofillCredential) -> Void,
cancelHandler: @escaping () -> Void,
rpId: String? = nil
) {
@@ -256,10 +253,10 @@ public class PasskeyProviderViewModel: ObservableObject {
filteredCredentials = credentials.filter { credential in
// Prepare searchable fields including passkey rpIds
var searchableFields = [
- credential.service.name?.lowercased() ?? "",
- credential.service.url?.lowercased() ?? "",
+ credential.serviceName?.lowercased() ?? "",
+ credential.serviceUrl?.lowercased() ?? "",
credential.username?.lowercased() ?? "",
- credential.alias?.email?.lowercased() ?? "",
+ credential.email?.lowercased() ?? "",
credential.notes?.lowercased() ?? ""
]
@@ -277,7 +274,7 @@ public class PasskeyProviderViewModel: ObservableObject {
}
}
- func selectCredential(_ credential: Credential) {
+ func selectCredential(_ credential: AutofillCredential) {
selectionHandler(credential)
}
@@ -337,82 +334,32 @@ public class PasskeyProviderViewModel: ObservableObject {
isDeleted: false
)
- let mockCredentials = [
- Credential(
+ let mockCredentials: [AutofillCredential] = [
+ AutofillCredential(
id: UUID(),
- alias: Alias(
- id: UUID(),
- gender: "Not specified",
- firstName: "John",
- lastName: "Doe",
- nickName: "JD",
- birthDate: Date(),
- email: "[email protected]",
- createdAt: Date(),
- updatedAt: Date(),
- isDeleted: false
- ),
- service: Service(
- id: UUID(),
- name: "GitHub",
- url: "https://github.com",
- logo: nil,
- createdAt: Date(),
- updatedAt: Date(),
- isDeleted: false
- ),
+ serviceName: "GitHub",
+ serviceUrl: "https://github.com",
+ logo: nil,
username: "johndoe",
+ email: "[email protected]",
+ password: "password123",
notes: nil,
- password: Password(
- id: UUID(),
- credentialId: UUID(),
- value: "password123",
- createdAt: Date(),
- updatedAt: Date(),
- isDeleted: false
- ),
passkeys: [mockPasskey1],
createdAt: Date(),
- updatedAt: Date(),
- isDeleted: false
+ updatedAt: Date()
),
- Credential(
+ AutofillCredential(
id: UUID(),
- alias: Alias(
- id: UUID(),
- gender: "Not specified",
- firstName: "John",
- lastName: "Doe",
- nickName: "JD",
- birthDate: Date(),
- email: "[email protected]",
- createdAt: Date(),
- updatedAt: Date(),
- isDeleted: false
- ),
- service: Service(
- id: UUID(),
- name: "Google",
- url: "https://google.com",
- logo: nil,
- createdAt: Date(),
- updatedAt: Date(),
- isDeleted: false
- ),
+ serviceName: "Google",
+ serviceUrl: "https://google.com",
+ logo: nil,
username: nil,
+ email: "[email protected]",
+ password: "password456",
notes: nil,
- password: Password(
- id: UUID(),
- credentialId: UUID(),
- value: "password456",
- createdAt: Date(),
- updatedAt: Date(),
- isDeleted: false
- ),
passkeys: [mockPasskey2],
createdAt: Date(),
- updatedAt: Date(),
- isDeleted: false
+ updatedAt: Date()
)
]
@@ -446,37 +393,19 @@ public class PasskeyProviderViewModel: ObservableObject {
isDeleted: false
)
- let mockCredentials = [
- Credential(
+ let mockCredentials: [AutofillCredential] = [
+ AutofillCredential(
id: UUID(),
- alias: Alias(
- id: UUID(),
- gender: "Not specified",
- firstName: "John",
- lastName: "Doe",
- nickName: "JD",
- birthDate: Date(),
- email: "[email protected]",
- createdAt: Date(),
- updatedAt: Date(),
- isDeleted: false
- ),
- service: Service(
- id: UUID(),
- name: "GitHub",
- url: "https://github.com",
- logo: nil,
- createdAt: Date(),
- updatedAt: Date(),
- isDeleted: false
- ),
+ serviceName: "GitHub",
+ serviceUrl: "https://github.com",
+ logo: nil,
username: "johndoe",
- notes: nil,
+ email: "[email protected]",
password: nil,
+ notes: nil,
passkeys: [mockPasskey],
createdAt: Date(),
- updatedAt: Date(),
- isDeleted: false
+ updatedAt: Date()
)
]
diff --git a/apps/mobile-app/ios/VaultUI/Selection/Utils/CredentialMatcher.swift b/apps/mobile-app/ios/VaultUI/Selection/Utils/CredentialMatcher.swift
index 2f81b0889..30f94110f 100644
--- a/apps/mobile-app/ios/VaultUI/Selection/Utils/CredentialMatcher.swift
+++ b/apps/mobile-app/ios/VaultUI/Selection/Utils/CredentialMatcher.swift
@@ -11,6 +11,7 @@ import VaultModels
/// 3. PRIORITY 3: Service Name Fallback (only for credentials without URLs - anti-phishing)
/// 4. PRIORITY 4: Text/Word Matching (non-URL search)
public class CredentialMatcher {
+ // swiftlint:disable function_body_length
/// Common top-level domains (TLDs) used for app package name detection.
/// When a search string starts with one of these TLDs followed by a dot (e.g., "com.coolblue.app"),
@@ -251,7 +252,7 @@ public class CredentialMatcher {
/// **Security Note**: Priority 3 only searches credentials with no service URL defined.
/// This prevents phishing attacks where a malicious site might match credentials
/// intended for a legitimate site.
- public static func filterCredentials(_ credentials: [Credential], searchText: String) -> [Credential] {
+ public static func filterCredentials(_ credentials: [AutofillCredential], searchText: String) -> [AutofillCredential] {
// Early return for empty search
if searchText.isEmpty {
return credentials
@@ -264,7 +265,7 @@ public class CredentialMatcher {
if isAppPackageName(searchText) {
// Perform exact string match on service URL field
let packageMatches = credentials.filter { credential in
- guard let serviceUrl = credential.service.url, !serviceUrl.isEmpty else { return false }
+ guard let serviceUrl = credential.serviceUrl, !serviceUrl.isEmpty else { return false }
return searchText == serviceUrl
}
@@ -284,7 +285,7 @@ public class CredentialMatcher {
if !searchDomain.isEmpty {
// Valid domain extracted - perform domain matching
let domainMatches = credentials.filter { credential in
- guard let serviceUrl = credential.service.url, !serviceUrl.isEmpty else { return false }
+ guard let serviceUrl = credential.serviceUrl, !serviceUrl.isEmpty else { return false }
return domainsMatch(searchText, serviceUrl)
}
@@ -303,10 +304,10 @@ public class CredentialMatcher {
let nameMatches = credentials.filter { credential in
// SECURITY: Skip credentials that have a URL defined
- guard credential.service.url?.isEmpty != false else { return false }
+ guard credential.serviceUrl?.isEmpty != false else { return false }
// Search in ServiceName and Notes using substring contains
- let serviceNameMatch = credential.service.name?.lowercased().contains(domainWithoutExtension) ?? false
+ let serviceNameMatch = credential.serviceName?.lowercased().contains(domainWithoutExtension) ?? false
let notesMatch = credential.notes?.lowercased().contains(domainWithoutExtension) ?? false
return serviceNameMatch || notesMatch
}
@@ -325,7 +326,7 @@ public class CredentialMatcher {
// If no meaningful words after extraction, fall back to simple substring contains
let lowercasedSearch = searchText.lowercased()
return credentials.filter { credential in
- (credential.service.name?.lowercased().contains(lowercasedSearch) ?? false) ||
+ (credential.serviceName?.lowercased().contains(lowercasedSearch) ?? false) ||
(credential.username?.lowercased().contains(lowercasedSearch) ?? false) ||
(credential.notes?.lowercased().contains(lowercasedSearch) ?? false)
}
@@ -333,7 +334,7 @@ public class CredentialMatcher {
// Match using extracted words - exact word matching only
return credentials.filter { credential in
- let serviceNameWords = credential.service.name.map { extractWords(from: $0) } ?? []
+ let serviceNameWords = credential.serviceName.map { extractWords(from: $0) } ?? []
let usernameWords = credential.username.map { extractWords(from: $0) } ?? []
let notesWords = credential.notes.map { extractWords(from: $0) } ?? []
@@ -345,4 +346,5 @@ public class CredentialMatcher {
}
}
}
+ // swiftlint:enable function_body_length
}
diff --git a/apps/mobile-app/ios/VaultUITests/CredentialMatcherTests.swift b/apps/mobile-app/ios/VaultUITests/CredentialMatcherTests.swift
index a0da12533..4fba17629 100644
--- a/apps/mobile-app/ios/VaultUITests/CredentialMatcherTests.swift
+++ b/apps/mobile-app/ios/VaultUITests/CredentialMatcherTests.swift
@@ -3,7 +3,7 @@ import XCTest
@testable import VaultModels
final class CredentialMatcherTests: XCTestCase {
- private var testCredentials: [Credential] = []
+ private var testCredentials: [AutofillCredential] = []
override func setUp() {
super.setUp()
@@ -22,7 +22,7 @@ final class CredentialMatcherTests: XCTestCase {
let matches = CredentialMatcher.filterCredentials(testCredentials, searchText: "www.coolblue.nl")
XCTAssertEqual(matches.count, 1)
- XCTAssertEqual(matches.first?.service.name, "Coolblue")
+ XCTAssertEqual(matches.first?.serviceName, "Coolblue")
}
// [#2] - Base URL with path match
@@ -30,7 +30,7 @@ final class CredentialMatcherTests: XCTestCase {
let matches = CredentialMatcher.filterCredentials(testCredentials, searchText: "https://gmail.com/signin")
XCTAssertEqual(matches.count, 1)
- XCTAssertEqual(matches.first?.service.name, "Gmail")
+ XCTAssertEqual(matches.first?.serviceName, "Gmail")
}
// [#3] - Root domain with subdomain match
@@ -38,7 +38,7 @@ final class CredentialMatcherTests: XCTestCase {
let matches = CredentialMatcher.filterCredentials(testCredentials, searchText: "https://mail.google.com")
XCTAssertEqual(matches.count, 1)
- XCTAssertEqual(matches.first?.service.name, "Google")
+ XCTAssertEqual(matches.first?.serviceName, "Google")
}
// [#4] - No matches for non-existent domain
@@ -53,7 +53,7 @@ final class CredentialMatcherTests: XCTestCase {
let matches = CredentialMatcher.filterCredentials(testCredentials, searchText: "https://www.dumpert.nl")
XCTAssertEqual(matches.count, 1)
- XCTAssertEqual(matches.first?.service.name, "Dumpert")
+ XCTAssertEqual(matches.first?.serviceName, "Dumpert")
}
// [#6] - Full URL stored matches partial URL search
@@ -61,7 +61,7 @@ final class CredentialMatcherTests: XCTestCase {
let matches = CredentialMatcher.filterCredentials(testCredentials, searchText: "coolblue.nl")
XCTAssertEqual(matches.count, 1)
- XCTAssertTrue(matches.contains { $0.service.name == "Coolblue" })
+ XCTAssertTrue(matches.contains { $0.serviceName == "Coolblue" })
}
// [#7] - Protocol variations (http/https/none) match
@@ -74,9 +74,9 @@ final class CredentialMatcherTests: XCTestCase {
XCTAssertEqual(httpsMatches.count, 1)
XCTAssertEqual(httpMatches.count, 1)
XCTAssertEqual(noProtocolMatches.count, 1)
- XCTAssertEqual(httpsMatches.first?.service.name, "GitHub")
- XCTAssertEqual(httpMatches.first?.service.name, "GitHub")
- XCTAssertEqual(noProtocolMatches.first?.service.name, "GitHub")
+ XCTAssertEqual(httpsMatches.first?.serviceName, "GitHub")
+ XCTAssertEqual(httpMatches.first?.serviceName, "GitHub")
+ XCTAssertEqual(noProtocolMatches.first?.serviceName, "GitHub")
}
// [#8] - WWW prefix variations match
@@ -87,8 +87,8 @@ final class CredentialMatcherTests: XCTestCase {
XCTAssertEqual(withWww.count, 1)
XCTAssertEqual(withoutWww.count, 1)
- XCTAssertEqual(withWww.first?.service.name, "Dumpert")
- XCTAssertEqual(withoutWww.first?.service.name, "Dumpert")
+ XCTAssertEqual(withWww.first?.serviceName, "Dumpert")
+ XCTAssertEqual(withoutWww.first?.serviceName, "Dumpert")
}
// [#9] - Subdomain matching
@@ -99,11 +99,11 @@ final class CredentialMatcherTests: XCTestCase {
let noSubdomain = CredentialMatcher.filterCredentials(testCredentials, searchText: "https://example.com")
XCTAssertEqual(appSubdomain.count, 1)
- XCTAssertEqual(appSubdomain.first?.service.name, "Subdomain Example")
+ XCTAssertEqual(appSubdomain.first?.serviceName, "Subdomain Example")
XCTAssertEqual(wwwSubdomain.count, 1)
- XCTAssertEqual(wwwSubdomain.first?.service.name, "Subdomain Example")
+ XCTAssertEqual(wwwSubdomain.first?.serviceName, "Subdomain Example")
XCTAssertEqual(noSubdomain.count, 1)
- XCTAssertEqual(noSubdomain.first?.service.name, "Subdomain Example")
+ XCTAssertEqual(noSubdomain.first?.serviceName, "Subdomain Example")
}
// [#10] - Paths and query strings ignored
@@ -114,11 +114,11 @@ final class CredentialMatcherTests: XCTestCase {
let withFragment = CredentialMatcher.filterCredentials(testCredentials, searchText: "https://gmail.com#inbox")
XCTAssertEqual(withPath.count, 1)
- XCTAssertEqual(withPath.first?.service.name, "GitHub")
+ XCTAssertEqual(withPath.first?.serviceName, "GitHub")
XCTAssertEqual(withQuery.count, 1)
- XCTAssertEqual(withQuery.first?.service.name, "Stack Overflow")
+ XCTAssertEqual(withQuery.first?.serviceName, "Stack Overflow")
XCTAssertEqual(withFragment.count, 1)
- XCTAssertEqual(withFragment.first?.service.name, "Gmail")
+ XCTAssertEqual(withFragment.first?.serviceName, "Gmail")
}
// [#11] - Complex URL variations
@@ -127,7 +127,7 @@ final class CredentialMatcherTests: XCTestCase {
let matches = CredentialMatcher.filterCredentials(testCredentials, searchText: "https://www.coolblue.nl/product/12345?ref=google")
XCTAssertEqual(matches.count, 1)
- XCTAssertTrue(matches.contains { $0.service.name == "Coolblue" })
+ XCTAssertTrue(matches.contains { $0.serviceName == "Coolblue" })
}
// [#12] - Priority ordering
@@ -135,7 +135,7 @@ final class CredentialMatcherTests: XCTestCase {
let matches = CredentialMatcher.filterCredentials(testCredentials, searchText: "coolblue.nl")
XCTAssertEqual(matches.count, 1)
- XCTAssertEqual(matches.first?.service.name, "Coolblue")
+ XCTAssertEqual(matches.first?.serviceName, "Coolblue")
}
// [#13] - Title-only matching
@@ -143,7 +143,7 @@ final class CredentialMatcherTests: XCTestCase {
let matches = CredentialMatcher.filterCredentials(testCredentials, searchText: "newyorktimes")
XCTAssertEqual(matches.count, 1)
- XCTAssertEqual(matches.first?.service.name, "Title Only newyorktimes")
+ XCTAssertEqual(matches.first?.serviceName, "Title Only newyorktimes")
}
// [#14] - Domain name part matching
@@ -158,7 +158,7 @@ final class CredentialMatcherTests: XCTestCase {
let matches = CredentialMatcher.filterCredentials(testCredentials, searchText: "com.coolblue.app")
XCTAssertEqual(matches.count, 1)
- XCTAssertEqual(matches.first?.service.name, "Coolblue App")
+ XCTAssertEqual(matches.first?.serviceName, "Coolblue App")
}
// [#16] - Invalid URL handling
@@ -186,7 +186,7 @@ final class CredentialMatcherTests: XCTestCase {
// Should match "Coolblue" even though it's followed by a comma and description
XCTAssertEqual(matches.count, 1)
- XCTAssertEqual(matches.first?.service.name, "Reddit")
+ XCTAssertEqual(matches.first?.serviceName, "Reddit")
}
// [#20] - Test multi-part TLDs like .com.au don't match incorrectly
@@ -202,17 +202,17 @@ final class CredentialMatcherTests: XCTestCase {
// Test that blabla.blabla.com.au doesn't match other .com.au sites
let blablaMatches = CredentialMatcher.filterCredentials(australianCredentials, searchText: "https://blabla.blabla.com.au")
XCTAssertEqual(blablaMatches.count, 1, "Should only match the exact domain, not all .com.au sites")
- XCTAssertEqual(blablaMatches.first?.service.name, "BlaBla AU")
+ XCTAssertEqual(blablaMatches.first?.serviceName, "BlaBla AU")
// Test that example.com.au doesn't match blabla.blabla.com.au
let exampleMatches = CredentialMatcher.filterCredentials(australianCredentials, searchText: "https://example.com.au")
XCTAssertEqual(exampleMatches.count, 1, "Should only match example.com.au")
- XCTAssertEqual(exampleMatches.first?.service.name, "Example Site AU")
+ XCTAssertEqual(exampleMatches.first?.serviceName, "Example Site AU")
// Test that .co.uk domains work correctly too
let ukMatches = CredentialMatcher.filterCredentials(australianCredentials, searchText: "https://example.co.uk")
XCTAssertEqual(ukMatches.count, 1, "Should only match the .co.uk domain")
- XCTAssertEqual(ukMatches.first?.service.name, "UK Site")
+ XCTAssertEqual(ukMatches.first?.serviceName, "UK Site")
}
// [#20] - Test reversed domain (app package name) doesn't match on TLD
@@ -228,7 +228,7 @@ final class CredentialMatcherTests: XCTestCase {
// Should only match Marktplaats, not Dumpert (even though both have "nl")
XCTAssertEqual(matches.count, 1, "Should only match Marktplaats, not Dumpert")
- XCTAssertEqual(matches.first?.service.name, "Marktplaats.nl")
+ XCTAssertEqual(matches.first?.serviceName, "Marktplaats.nl")
}
// [#21] - Test app package names are properly detected and handled
@@ -243,17 +243,17 @@ final class CredentialMatcherTests: XCTestCase {
// Test com.google.android package matches
let googleMatches = CredentialMatcher.filterCredentials(packageCredentials, searchText: "com.google.android.googlequicksearchbox")
XCTAssertEqual(googleMatches.count, 1)
- XCTAssertEqual(googleMatches.first?.service.name, "Google App")
+ XCTAssertEqual(googleMatches.first?.serviceName, "Google App")
// Test com.facebook package matches
let facebookMatches = CredentialMatcher.filterCredentials(packageCredentials, searchText: "com.facebook.katana")
XCTAssertEqual(facebookMatches.count, 1)
- XCTAssertEqual(facebookMatches.first?.service.name, "Facebook")
+ XCTAssertEqual(facebookMatches.first?.serviceName, "Facebook")
// Test that web domain doesn't match package name
let webMatches = CredentialMatcher.filterCredentials(packageCredentials, searchText: "https://example.com")
XCTAssertEqual(webMatches.count, 1)
- XCTAssertEqual(webMatches.first?.service.name, "Generic Site")
+ XCTAssertEqual(webMatches.first?.serviceName, "Generic Site")
}
// MARK: - Shared Test Data
@@ -262,7 +262,7 @@ final class CredentialMatcherTests: XCTestCase {
* Creates the shared test credential dataset used across all platforms.
* This ensures consistent testing across Browser Extension, iOS, and Android.
*/
- private func createSharedTestCredentials() -> [Credential] {
+ private func createSharedTestCredentials() -> [AutofillCredential] {
return [
createTestCredential(serviceName: "Gmail", serviceUrl: "https://gmail.com", username: "[email protected]"),
createTestCredential(serviceName: "Google", serviceUrl: "https://google.com", username: "[email protected]"),
@@ -286,35 +286,25 @@ final class CredentialMatcherTests: XCTestCase {
* @param serviceName The name of the service
* @param serviceUrl The URL of the service
* @param username The username for the service
- * @returns A test credential matching the iOS Credential type
+ * @returns A test credential matching the iOS AutofillCredential type
*/
private func createTestCredential(
serviceName: String,
serviceUrl: String,
username: String
- ) -> Credential {
- return Credential(
+ ) -> AutofillCredential {
+ return AutofillCredential(
id: UUID(),
- alias: nil, service: Service(
- id: UUID(),
- name: serviceName,
- url: serviceUrl,
- logo: nil,
- createdAt: Date(),
- updatedAt: Date(),
- isDeleted: false
- ),
+ serviceName: serviceName,
+ serviceUrl: serviceUrl,
+ logo: nil,
username: username,
- notes: nil, password: Password(
- id: UUID(), credentialId: UUID(),
- value: "password123",
- createdAt: Date(),
- updatedAt: Date(),
- isDeleted: false
- ),
+ email: nil,
+ password: "password123",
+ notes: nil,
+ passkeys: nil,
createdAt: Date(),
- updatedAt: Date(),
- isDeleted: false
+ updatedAt: Date()
)
}
}
diff --git a/apps/mobile-app/ios/VaultUtils/CredentialHelpers.swift b/apps/mobile-app/ios/VaultUtils/CredentialHelpers.swift
index 0559bb061..a29b350c9 100644
--- a/apps/mobile-app/ios/VaultUtils/CredentialHelpers.swift
+++ b/apps/mobile-app/ios/VaultUtils/CredentialHelpers.swift
@@ -4,20 +4,14 @@ import VaultModels
/**
* CredentialHelpers
* -------------------------
- * Utility functions for working with Credential objects.
+ * Utility functions for working with AutofillCredential objects.
*/
public class CredentialHelpers {
/// Returns username or email from a credential, depending on which is available.
/// Prioritizes username over email.
/// - Parameter credential: The credential to extract the identifier from
/// - Returns: Username if available, otherwise email, or empty string if neither exists
- public static func usernameOrEmail(credential: Credential) -> String {
- if let username = credential.username, !username.isEmpty {
- return username
- }
- if let email = credential.alias?.email, !email.isEmpty {
- return email
- }
- return ""
+ public static func usernameOrEmail(credential: AutofillCredential) -> String {
+ return credential.identifier
}
}