Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Make manifestId required in all native mobile app queries (#2159)
Leendert de Borste28e1c23cca7
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultPasskey.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultPasskey.ktindex 347e63d09..4799f34ef 100644--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultPasskey.kt+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultPasskey.kt@@ -30,9 +30,9 @@ class VaultPasskey(}/**- * Get all passkeys for an item. Resolves the item's manifest when the caller does not hold it.+ * Get all passkeys for an item.*/- fun getPasskeysForItem(itemId: UUID, manifestId: String? = null): List<Passkey> {+ fun getPasskeysForItem(itemId: UUID, manifestId: String): List<Passkey> {return passkeyRepository.getForItem(itemId, manifestId)}diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultStore.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultStore.ktindex dcc15236c..088279e55 100644--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultStore.kt+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultStore.kt@@ -762,9 +762,9 @@ class VaultStore(}/**- * Get all passkeys for an item. Resolves the item's manifest when the caller does not hold it.+ * Get all passkeys for an item.*/- fun getPasskeysForItem(itemId: java.util.UUID, manifestId: String? = null): List<net.aliasvault.app.vaultstore.models.Passkey> {+ fun getPasskeysForItem(itemId: java.util.UUID, manifestId: String): List<net.aliasvault.app.vaultstore.models.Passkey> {return passkey.getPasskeysForItem(itemId, manifestId)}diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/queries/PasskeyQueries.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/queries/PasskeyQueries.ktindex 972b2121a..0210cea4a 100644--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/queries/PasskeyQueries.kt+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/queries/PasskeyQueries.kt@@ -71,13 +71,12 @@ object PasskeyQueries {"""/**- * Insert a new passkey, stamped with the manifest of the item it hangs off. Binds the item id twice:- * once for the column, once for the manifest lookup, followed by the fallback manifest.+ * Insert a new passkey, stamped with the manifest of the item it hangs off (bound third, after the item id).*/const val INSERT = """INSERT INTO Passkeys (Id, ItemId, ManifestId, RpId, UserHandle, PublicKey, PrivateKey,PrfKey, DisplayName, AdditionalData, CreatedAt, UpdatedAt, IsDeleted)- VALUES (?, ?, COALESCE((SELECT ManifestId FROM Items WHERE Id = ?), ?), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"""/**@@ -123,20 +122,19 @@ object PasskeyQueries {""".trimIndent()/**- * Create an Item record for passkey registration, stamped with the manifest of its folder (or the- * fallback manifest when it has none).+ * Create an Item record for passkey registration. Binds (id, name, itemType, logoId, folderId, now, now, 0, null, manifestId).*/const val CREATE_ITEM = """INSERT INTO Items (Id, Name, ItemType, LogoId, FolderId, CreatedAt, UpdatedAt, IsDeleted, DeletedAt, ManifestId)- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, COALESCE((SELECT ManifestId FROM Folders WHERE Id = ?), ?))+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"""/**- * Insert a field value, stamped with the manifest of its item.+ * Insert a field value. Binds (id, itemId, fieldDefinitionId, fieldKey, value, weight, now, now, 0, manifestId).*/const val INSERT_FIELD_VALUE = """INSERT INTO FieldValues (Id, ItemId, FieldDefinitionId, FieldKey, Value, Weight, CreatedAt, UpdatedAt, IsDeleted, ManifestId)- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, COALESCE((SELECT ManifestId FROM Items WHERE Id = ?), ?))+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"""/**diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/repositories/BaseRepository.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/repositories/BaseRepository.ktindex 9a2500877..ecad7b4c3 100644--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/repositories/BaseRepository.kt+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/repositories/BaseRepository.kt@@ -21,18 +21,6 @@ open class BaseRepository(return database.getPersonalManifestId() ?: throw AppError.ManifestNotRecorded()}- /**- * The manifest a manifest-scoped row belongs to, looked up from the row itself: the personal manifest when- * the row exists there, else the lowest manifest id holding it. Null when no such row exists.- */- protected fun resolveRowManifestId(table: String, id: String, column: String = "Id"): String? {- val rows = executeQuery("SELECT ManifestId FROM $table WHERE $column = ? ORDER BY ManifestId", arrayOf(id))- val manifestIds = rows.mapNotNull { it["ManifestId"] as? String }- if (manifestIds.isEmpty()) return null- val personal = database.getPersonalManifestId()- return manifestIds.firstOrNull { it == personal } ?: manifestIds.first()- }-/*** The grouping key of a manifest-scoped row, for joining rows of one query to rows of another in memory.*/diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/repositories/PasskeyRepository.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/repositories/PasskeyRepository.ktindex 983427b49..8de811a4f 100644--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/repositories/PasskeyRepository.kt+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/repositories/PasskeyRepository.kt@@ -69,15 +69,13 @@ class PasskeyRepository(database: VaultDatabase) : BaseRepository(database) {}/**- * Get all passkeys for an item. Resolves the item's manifest when the caller does not hold it.+ * Get all passkeys for an item.* @param itemId The UUID of the parent item- * @param manifestId The manifest the item belongs to, when known+ * @param manifestId The manifest the item belongs to* @return List of Passkey objects*/- fun getForItem(itemId: UUID, manifestId: String? = null): List<Passkey> {- val id = itemId.toString().lowercase()- val scope = manifestId ?: resolveRowManifestId("Items", id) ?: return emptyList()- val results = executeQuery(PasskeyQueries.GET_BY_ITEM_ID, arrayOf(id, scope))+ fun getForItem(itemId: UUID, manifestId: String): List<Passkey> {+ val results = executeQuery(PasskeyQueries.GET_BY_ITEM_ID, arrayOf(itemId.toString().lowercase(), manifestId))return results.mapNotNull { parsePasskeyRow(it) }}@@ -104,18 +102,17 @@ class PasskeyRepository(database: VaultDatabase) : BaseRepository(database) {// MARK: - Write Operations/**- * Insert a new passkey, stamped with the manifest of its item.+ * Insert a new passkey, stamped with the manifest of its item, which the caller has already put on it.* @param passkey The passkey to insert*/private fun insert(passkey: Passkey) {- val itemId = passkey.parentItemId.toString().lowercase()+ val manifestId = passkey.manifestId ?: error("Passkey has no manifest: ${passkey.id}")executeUpdate(PasskeyQueries.INSERT,arrayOf(passkey.id.toString().lowercase(),- itemId,- itemId,- activeManifestId(),+ passkey.parentItemId.toString().lowercase(),+ manifestId,passkey.rpId,passkey.userHandle,String(passkey.publicKey, Charsets.UTF_8),@@ -157,7 +154,7 @@ class PasskeyRepository(database: VaultDatabase) : BaseRepository(database) {// Create the ItemexecuteUpdate(PasskeyQueries.CREATE_ITEM,- arrayOf(itemId, displayName, "Login", logoId, null, timestamp, timestamp, 0, null, null, manifestId),+ arrayOf(itemId, displayName, "Login", logoId, null, timestamp, timestamp, 0, null, manifestId),)// Insert URL and username field values@@ -433,7 +430,7 @@ class PasskeyRepository(database: VaultDatabase) : BaseRepository(database) {private fun insertFieldValue(itemId: String, manifestId: String, fieldKey: String, value: String, weight: Int, timestamp: String) {executeUpdate(PasskeyQueries.INSERT_FIELD_VALUE,- arrayOf(generateId(), itemId, null, fieldKey, value, weight, timestamp, timestamp, 0, itemId, manifestId),+ arrayOf(generateId(), itemId, null, fieldKey, value, weight, timestamp, timestamp, 0, manifestId),)}diff --git a/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Credential.swift b/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Credential.swiftindex 60a39f598..c827845c7 100644--- a/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Credential.swift+++ b/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Credential.swift@@ -25,20 +25,20 @@ extension CredentialProviderViewController: CredentialProviderDelegate {self.handleCancel()},serviceUrl: serviceUrl,- urlLinker: { itemId, url in+ urlLinker: { credential, url in/*- * Step 1 — Append the URL/app identifier to the chosen credential's+ * Step 1: append the URL/app identifier to the chosen credential's* `login.url` multi-value field.*/do {- try vaultStore.appendUrl(toItemId: itemId, url: url)+ try vaultStore.appendUrl(toItemId: credential.id, manifestId: credential.manifestId, url: url)} catch {print("[Autofill] Failed to append URL to credential: \(error)")return}/*- * Step 2 — Push the change to the server (skipped if offline, client will retry later).+ * Step 2: push the change to the server (skipped if offline, client will retry later).*/let webApiService = WebApiService()do {@@ -48,7 +48,7 @@ extension CredentialProviderViewController: CredentialProviderDelegate {}/*- * Step 3 — Refresh the iOS credential identity store with the+ * Step 3: refresh the iOS credential identity store with the* new URL.*/do {@@ -59,9 +59,9 @@ extension CredentialProviderViewController: CredentialProviderDelegate {print("[Autofill] Failed to refresh iOS credential identity cache: \(error)")}},- usageRecorder: { itemId in+ usageRecorder: { credential indo {- try vaultStore.recordItemUsage(itemId: itemId, action: .autofill)+ try vaultStore.recordItemUsage(itemId: credential.id, manifestId: credential.manifestId, action: .autofill)} catch {print("[Autofill] Failed to record credential usage: \(error)")}diff --git a/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift b/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swiftindex f0fc6f22e..50516948e 100644--- a/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift+++ b/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift@@ -87,8 +87,10 @@ extension CredentialProviderViewController: PasskeyProviderDelegate {// If the item behind this passkey also has a TOTP code and the user has the// copy-on-fill setting enabled (default), put the current code on the clipboard.- let totp = (try? vaultStore.getFirstTotpCode(forItemId: passkey.parentItemId, manifestId: passkey.manifestId)) ?? nil- TotpClipboard.copyCodeIfEnabled(totp: totp)+ if let manifestId = passkey.manifestId {+ let totp = (try? vaultStore.getFirstTotpCode(forItemId: passkey.parentItemId, manifestId: manifestId)) ?? nil+ TotpClipboard.copyCodeIfEnabled(totp: totp)+ }recordPasskeyUsage(vaultStore: vaultStore, passkey: passkey)@@ -265,9 +267,13 @@ extension CredentialProviderViewController: PasskeyProviderDelegate {var existingPasskeys: [PasskeyWithCredentialInfo] = []do {let results = try vaultStore.getPasskeysWithCredentialInfo(forRpId: rpId, userId: userId)- existingPasskeys = results.map { result in- PasskeyWithCredentialInfo(+ existingPasskeys = results.compactMap { result in+ guard let manifestId = result.passkey.manifestId else {+ return nil+ }+ return PasskeyWithCredentialInfo(id: result.passkey.id,+ manifestId: manifestId,displayName: result.passkey.displayName,serviceName: result.serviceName,username: result.username,@@ -290,6 +296,7 @@ extension CredentialProviderViewController: PasskeyProviderDelegate {existingItemsWithoutPasskey = results.map { item inItemWithCredentialInfo(itemId: item.itemId,+ manifestId: item.manifestId,serviceName: item.serviceName,urls: item.urls,username: item.username,@@ -485,18 +492,20 @@ extension CredentialProviderViewController: PasskeyProviderDelegate {// Step 4: Store credential with passkey in database// Check if we're replacing an existing passkey- if let oldPasskeyId = viewModel.selectedPasskeyToReplace {+ if let oldPasskey = viewModel.selectedPasskeyToReplace {// Replace existing passkeytry vaultStore.replacePasskey(- oldPasskeyId: oldPasskeyId,+ oldPasskeyId: oldPasskey.id,+ manifestId: oldPasskey.manifestId,newPasskey: passkey,displayName: viewModel.displayName,logo: logo)- } else if let existingItemId = viewModel.selectedItemToMerge {+ } else if let existingItem = viewModel.selectedItemToMerge {// Merge passkey into existing item without passkeytry vaultStore.addPasskeyToExistingItem(- itemId: existingItemId,+ itemId: existingItem.itemId,+ manifestId: existingItem.manifestId,passkey: passkey,logo: logo)@@ -653,8 +662,12 @@ extension CredentialProviderViewController: PasskeyProviderDelegate {* Recorded before the request completes: the host may tear the extension down right after.*/private func recordPasskeyUsage(vaultStore: VaultStore, passkey: Passkey) {+ guard let manifestId = passkey.manifestId else {+ print("[Autofill] Passkey \(passkey.id) carries no manifest, usage not recorded")+ return+ }do {- try vaultStore.recordItemUsage(itemId: passkey.parentItemId, manifestId: passkey.manifestId, action: .passkey)+ try vaultStore.recordItemUsage(itemId: passkey.parentItemId, manifestId: manifestId, action: .passkey)} catch {print("[Autofill] Failed to record passkey usage: \(error)")}diff --git a/apps/mobile-app/ios/VaultModels/AutofillCredential.swift b/apps/mobile-app/ios/VaultModels/AutofillCredential.swiftindex 9f78f585b..8a60ed70c 100644--- a/apps/mobile-app/ios/VaultModels/AutofillCredential.swift+++ b/apps/mobile-app/ios/VaultModels/AutofillCredential.swift@@ -5,7 +5,7 @@ import Foundation/// 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 manifestId: String?+ public let manifestId: Stringpublic let serviceName: String?public let serviceUrls: [String]public let logo: Data?@@ -25,7 +25,7 @@ public struct AutofillCredential: Codable, Hashable, Equatable {public init(id: UUID,- manifestId: String? = nil,+ manifestId: String,serviceName: String?,serviceUrls: [String],logo: Data?,diff --git a/apps/mobile-app/ios/VaultStoreKit/Database/BaseRepository.swift b/apps/mobile-app/ios/VaultStoreKit/Database/BaseRepository.swiftindex 4be863300..30a40844c 100644--- a/apps/mobile-app/ios/VaultStoreKit/Database/BaseRepository.swift+++ b/apps/mobile-app/ios/VaultStoreKit/Database/BaseRepository.swift@@ -1,8 +1,12 @@import Foundationimport VaultUtils+/// The grouping key of a manifest-scoped row (same id can exist in several manifests by design).+internal func scopedKey(manifestId: String, id: String) -> String {+ return manifestId + id+}+/// Base repository class with common database operations.-/// Provides transaction handling, soft delete, and other shared functionality.public class BaseRepository {/// The database client used for executing queries.internal let client: DatabaseClient@@ -14,9 +18,13 @@ public class BaseRepository {}/// The manifest new rows outside any folder or item are stamped with: the personal manifest. Rows inside a- /// folder or item take that parent's manifest through the SQL instead.- public func activeManifestId() -> String {- return client.personalManifestId() ?? ""+ /// folder or item take that parent's manifest through the SQL instead. An unrecorded manifest is an error,+ /// never the empty (unstamped) scope, which every later push would reject.+ public func writeManifestId() throws -> String {+ guard let manifestId = client.personalManifestId(), !manifestId.isEmpty else {+ throw AppError.manifestNotRecorded+ }+ return manifestId}// MARK: - Transaction Helpers@@ -37,79 +45,8 @@ public class BaseRepository {}}- // MARK: - Soft Delete Helpers-- /// Soft delete a record by setting IsDeleted = 1.- /// - Parameters:- /// - table: The table name- /// - id: The record ID- /// - Returns: Number of rows affected- @discardableResult- public func softDelete(table: String, id: String) throws -> Int {- let timestamp = DateHelpers.now()- return try client.executeUpdate(- "UPDATE \(table) SET IsDeleted = 1, UpdatedAt = ? WHERE Id = ?",- params: [timestamp, id]- )- }-- /// Soft delete records by a foreign key.- /// - Parameters:- /// - table: The table name- /// - foreignKey: The foreign key column name- /// - foreignKeyValue: The foreign key value- /// - Returns: Number of rows affected- @discardableResult- public func softDeleteByForeignKey(table: String, foreignKey: String, foreignKeyValue: String) throws -> Int {- let timestamp = DateHelpers.now()- return try client.executeUpdate(- "UPDATE \(table) SET IsDeleted = 1, UpdatedAt = ? WHERE \(foreignKey) = ?",- params: [timestamp, foreignKeyValue]- )- }-- // MARK: - Hard Delete Helpers-- /// Hard delete a record permanently.- /// - Parameters:- /// - table: The table name- /// - id: The record ID- /// - Returns: Number of rows affected- @discardableResult- public func hardDelete(table: String, id: String) throws -> Int {- return try client.executeUpdate(- "DELETE FROM \(table) WHERE Id = ?",- params: [id]- )- }-- /// Hard delete records by a foreign key.- /// - Parameters:- /// - table: The table name- /// - foreignKey: The foreign key column name- /// - foreignKeyValue: The foreign key value- /// - Returns: Number of rows affected- @discardableResult- public func hardDeleteByForeignKey(table: String, foreignKey: String, foreignKeyValue: String) throws -> Int {- return try client.executeUpdate(- "DELETE FROM \(table) WHERE \(foreignKey) = ?",- params: [foreignKeyValue]- )- }-// MARK: - Utility Methods- /// Check if a table exists in the database.- /// - Parameter tableName: The name of the table to check- /// - Returns: True if the table exists- public func tableExists(_ tableName: String) throws -> Bool {- let results = try client.executeQuery(- "SELECT name FROM sqlite_master WHERE type='table' AND name=?",- params: [tableName]- )- return !results.isEmpty- }-/// Generate a new id./// - Returns: A new UUID stringpublic func generateId() -> String {@@ -121,12 +58,4 @@ public class BaseRepository {public func now() -> String {return DateHelpers.now()}-- /// Build a parameterized IN clause for SQL queries.- /// - Parameter values: Array of values for the IN clause- /// - Returns: Tuple with placeholders string and values array- public func buildInClause(_ values: [String]) -> (placeholders: String, values: [String]) {- let placeholders = values.map { _ in "?" }.joined(separator: ",")- return (placeholders, values)- }}diff --git a/apps/mobile-app/ios/VaultStoreKit/Database/Queries/ItemQueries.swift b/apps/mobile-app/ios/VaultStoreKit/Database/Queries/ItemQueries.swiftindex d587ab83d..c1962e3ba 100644--- a/apps/mobile-app/ios/VaultStoreKit/Database/Queries/ItemQueries.swift+++ b/apps/mobile-app/ios/VaultStoreKit/Database/Queries/ItemQueries.swift@@ -59,10 +59,10 @@ public struct ItemQueries {SELECT Id, ManifestId, Name, ParentFolderId FROM Folders WHERE IsDeleted = 0"""- /// Insert a new item, stamped with the manifest of the folder it is placed in.+ /// Insert a new item, bound as [id, name, itemType, logoId, folderId, now, now, 0, manifestId].public static let insertItem = """INSERT INTO Items (Id, Name, ItemType, LogoId, FolderId, CreatedAt, UpdatedAt, IsDeleted, ManifestId)- VALUES (?, ?, ?, ?, ?, ?, ?, ?, COALESCE((SELECT ManifestId FROM Folders WHERE Id = ?), ?))+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"""/// Bump an item's UpdatedAt so a child-row change is picked up by sync.@@ -73,10 +73,10 @@ public struct ItemQueries {/// SQL query constants for FieldValue operations.public struct FieldValueQueries {- /// Insert a new field value, stamped with the manifest of the item it hangs off.+ /// Insert a new field value, bound as [id, itemId, fieldDefinitionId, fieldKey, value, weight, now, now, 0, manifestId].public static let insert = """INSERT INTO FieldValues (Id, ItemId, FieldDefinitionId, FieldKey, Value, Weight, CreatedAt, UpdatedAt, IsDeleted, ManifestId)- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, COALESCE((SELECT ManifestId FROM Items WHERE Id = ?), ?))+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"""/// The Weight a system field's values are written with: the field's DefaultDisplayOrder fromdiff --git a/apps/mobile-app/ios/VaultStoreKit/Database/Queries/PasskeyQueries.swift b/apps/mobile-app/ios/VaultStoreKit/Database/Queries/PasskeyQueries.swiftindex a554f4821..996eb7b3b 100644--- a/apps/mobile-app/ios/VaultStoreKit/Database/Queries/PasskeyQueries.swift+++ b/apps/mobile-app/ios/VaultStoreKit/Database/Queries/PasskeyQueries.swift@@ -40,6 +40,12 @@ public struct PasskeyQueries {WHERE p.Id = ? AND p.IsDeleted = 0"""+ /// Get one passkey inside one manifest, bound as [passkeyId, manifestId].+ public static let getByIdInManifest = """+ \(baseSelectWithItemCheck)+ WHERE p.Id = ? AND p.ManifestId = ? AND p.IsDeleted = 0+ """+/// Get all passkeys for one item, bound as [itemId, manifestId].public static let getByItemId = """\(baseSelect)@@ -67,11 +73,10 @@ public struct PasskeyQueries {ORDER BY p.CreatedAt DESC"""- /// Insert a new passkey, stamped with the manifest of the item it hangs off. Binds the item id twice:- /// once for the column, once for the manifest lookup, followed by the fallback manifest.+ /// Insert a new passkey, stamped with the manifest of the item it hangs off (bound third, after the item id).public static let insert = """INSERT INTO Passkeys (Id, ItemId, ManifestId, RpId, UserHandle, PublicKey, PrivateKey, PrfKey, DisplayName, AdditionalData, CreatedAt, UpdatedAt, IsDeleted)- VALUES (?, ?, COALESCE((SELECT ManifestId FROM Items WHERE Id = ?), ?), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"""/// Soft delete a passkey, bound as [now, passkeyId, manifestId].diff --git a/apps/mobile-app/ios/VaultStoreKit/Database/Repositories/ItemRepository.swift b/apps/mobile-app/ios/VaultStoreKit/Database/Repositories/ItemRepository.swiftindex ab85a55b5..c50c28b6f 100644--- a/apps/mobile-app/ios/VaultStoreKit/Database/Repositories/ItemRepository.swift+++ b/apps/mobile-app/ios/VaultStoreKit/Database/Repositories/ItemRepository.swift@@ -65,21 +65,17 @@ public class ItemRepository: BaseRepository {/// - itemId: The id of the item to append the value to (lowercase string)/// - fieldKey: The system FieldKey to append under (e.g. `FieldKey.loginUrl`)/// - value: The value to append- /// - manifestId: The manifest the item belongs to, when the caller knows it+ /// - manifestId: The manifest the item belongs to/// - Returns: The number of rows affected by the parent Item's UpdatedAt bump, 0 when no such item exists@discardableResult- public func appendFieldValue(itemId: String, fieldKey: String, value: String, manifestId: String? = nil) throws -> Int {+ public func appendFieldValue(itemId: String, manifestId: String, fieldKey: String, value: String) throws -> Int {return try withTransaction {- guard let scope = try manifestId ?? resolveRowManifestId(table: "Items", id: itemId) else {- return 0- }-let now = self.now()let weight = FieldValueQueries.defaultWeight(forFieldKey: fieldKey)- try client.executeUpdate(FieldValueQueries.insert, params: [generateId(), itemId, nil, fieldKey, value, weight, now, now, 0, itemId, scope])+ try client.executeUpdate(FieldValueQueries.insert, params: [generateId(), itemId, nil, fieldKey, value, weight, now, now, 0, manifestId])// Bump the parent Item's UpdatedAt so the change is picked up by the sync layer.- return try client.executeUpdate(ItemQueries.touchItem, params: [now, itemId, scope])+ return try client.executeUpdate(ItemQueries.touchItem, params: [now, itemId, manifestId])}}}diff --git a/apps/mobile-app/ios/VaultStoreKit/Database/Repositories/ItemStatsRepository.swift b/apps/mobile-app/ios/VaultStoreKit/Database/Repositories/ItemStatsRepository.swiftindex 6aace52f1..722b0f3f6 100644--- a/apps/mobile-app/ios/VaultStoreKit/Database/Repositories/ItemStatsRepository.swift+++ b/apps/mobile-app/ios/VaultStoreKit/Database/Repositories/ItemStatsRepository.swift@@ -28,21 +28,14 @@ public class ItemStatsRepository: BaseRepository {/// Record one use of an item. Runs in its own transaction so the vault is persisted and marked dirty./// - Parameters:/// - itemId: The item that was used- /// - manifestId: The manifest the item belongs to, when the caller knows it+ /// - manifestId: The manifest the item belongs to/// - action: What the user did with it- /// - Returns: True when a use was recorded, false when no such item exists- @discardableResult- public func recordUsage(itemId: String, manifestId: String? = nil, action: ItemUsageAction) throws -> Bool {- return try withTransaction {- guard let scope = try manifestId ?? resolveRowManifestId(table: "Items", id: itemId) else {- return false- }-+ public func recordUsage(itemId: String, manifestId: String, action: ItemUsageAction) throws {+ try withTransaction {let now = self.now()let columns = action.columns- try client.executeUpdate(ItemStatsQueries.insertRow, params: [scope, itemId, now, now])- try client.executeUpdate(ItemStatsQueries.forAction(lastColumn: columns.last, countColumn: columns.count), params: [now, now, now, scope, itemId])- return true+ try client.executeUpdate(ItemStatsQueries.insertRow, params: [manifestId, itemId, now, now])+ try client.executeUpdate(ItemStatsQueries.forAction(lastColumn: columns.last, countColumn: columns.count), params: [now, now, now, manifestId, itemId])}}}diff --git a/apps/mobile-app/ios/VaultStoreKit/Database/Repositories/PasskeyRepository.swift b/apps/mobile-app/ios/VaultStoreKit/Database/Repositories/PasskeyRepository.swiftindex 976920681..99968cd7c 100644--- a/apps/mobile-app/ios/VaultStoreKit/Database/Repositories/PasskeyRepository.swift+++ b/apps/mobile-app/ios/VaultStoreKit/Database/Repositories/PasskeyRepository.swift@@ -20,16 +20,26 @@ public class PasskeyRepository: BaseRepository {return PasskeyMapper.mapRow(row)}+ /// Get a passkey by its ID inside one manifest.+ /// - Parameters:+ /// - passkeyId: The passkey ID (UUID string)+ /// - manifestId: The manifest the passkey belongs to+ /// - Returns: Passkey object or nil if not found+ public func getById(_ passkeyId: String, manifestId: String) throws -> Passkey? {+ let results = try client.executeQuery(PasskeyQueries.getByIdInManifest, params: [passkeyId, manifestId])+ guard let row = results.first.flatMap({ PasskeyRow(from: $0) }) else {+ return nil+ }+ return PasskeyMapper.mapRow(row)+ }+/// Get all passkeys for an item./// - Parameters:/// - itemId: The item ID (UUID string)- /// - manifestId: The manifest the item belongs to, when the caller knows it+ /// - manifestId: The manifest the item belongs to/// - Returns: Array of Passkey objects- public func getByItemId(_ itemId: String, manifestId: String? = nil) throws -> [Passkey] {- guard let scope = try manifestId ?? resolveRowManifestId(table: "Items", id: itemId) else {- return []- }- let results = try client.executeQuery(PasskeyQueries.getByItemId, params: [itemId, scope])+ public func getByItemId(_ itemId: String, manifestId: String) throws -> [Passkey] {+ let results = try client.executeQuery(PasskeyQueries.getByItemId, params: [itemId, manifestId])return PasskeyMapper.mapRows(results.compactMap { PasskeyRow(from: $0) })}@@ -100,7 +110,7 @@ public class PasskeyRepository: BaseRepository {/// Map one row of the without-passkey queries.private func mapItemWithCredentialInfo(_ row: [String: Any], urls: [String]) -> ItemWithCredentialInfoData? {- guard let idString = row["Id"] as? String, let itemId = UUID(uuidString: idString) else {+ guard let idString = row["Id"] as? String, let itemId = UUID(uuidString: idString), let manifestId = row["ManifestId"] as? String else {return nil}@@ -114,76 +124,58 @@ public class PasskeyRepository: BaseRepository {hasPassword: !(password ?? "").isEmpty,createdAt: DateHelpers.parseDateString(row["CreatedAt"] as? String ?? "") ?? Date.distantPast,updatedAt: DateHelpers.parseDateString(row["UpdatedAt"] as? String ?? "") ?? Date.distantPast,- manifestId: row["ManifestId"] as? String+ manifestId: manifestId)}// MARK: - Write Operations- /// Create a new passkey. The manifest is read from the item the passkey hangs off.- /// - Parameter passkey: The passkey to create- @discardableResult- public func create(_ passkey: Passkey) throws -> String {- return try withTransaction {- try insertPasskey(passkey, itemId: passkey.parentItemId.uuidString.lowercased(), displayName: passkey.displayName, now: self.now())- }- }-/// Soft delete a passkey./// - Parameters:/// - passkeyId: The ID of the passkey to delete- /// - manifestId: The manifest the passkey belongs to, when the caller knows it+ /// - manifestId: The manifest the passkey belongs to/// - Returns: Number of rows affected@discardableResult- public func delete(_ passkeyId: String, manifestId: String? = nil) throws -> Int {+ public func delete(_ passkeyId: String, manifestId: String) throws -> Int {return try withTransaction {- guard let scope = try manifestId ?? resolveRowManifestId(table: "Passkeys", id: passkeyId) else {- return 0- }- return try client.executeUpdate(PasskeyQueries.softDelete, params: [self.now(), passkeyId, scope])+ try client.executeUpdate(PasskeyQueries.softDelete, params: [self.now(), passkeyId, manifestId])}}/// Update a passkey's display name./// - Parameters:/// - passkeyId: The ID of the passkey to update+ /// - manifestId: The manifest the passkey belongs to/// - displayName: The new display name- /// - manifestId: The manifest the passkey belongs to, when the caller knows it/// - Returns: Number of rows affected@discardableResult- public func updateDisplayName(_ passkeyId: String, displayName: String, manifestId: String? = nil) throws -> Int {+ public func updateDisplayName(_ passkeyId: String, manifestId: String, displayName: String) throws -> Int {return try withTransaction {- guard let scope = try manifestId ?? resolveRowManifestId(table: "Passkeys", id: passkeyId) else {- return 0- }- return try client.executeUpdate(PasskeyQueries.updateDisplayName, params: [displayName, self.now(), passkeyId, scope])+ try client.executeUpdate(PasskeyQueries.updateDisplayName, params: [displayName, self.now(), passkeyId, manifestId])}}/// Replace an existing passkey with a new one, optionally refreshing the item's logo.- /// Soft deletes the old passkey and creates a new one linked to the same item, in that item's manifest.+ /// Soft deletes the old passkey and creates a new one linked to the same item, in the same manifest./// - Parameters:/// - oldPasskeyId: The ID of the passkey to replace+ /// - manifestId: The manifest the old passkey and its item belong to/// - newPasskey: The new passkey to create/// - displayName: The display name for the new passkey/// - logo: Optional favicon bytes fetched for the passkey's rpId/// - Returns: The ID of the new passkey@discardableResult- public func replace(oldPasskeyId: String, with newPasskey: Passkey, displayName: String, logo: Data? = nil) throws -> String {+ public func replace(oldPasskeyId: String, manifestId: String, with newPasskey: Passkey, displayName: String, logo: Data? = nil) throws -> String {return try withTransaction {- guard let scope = try newPasskey.manifestId ?? resolveRowManifestId(table: "Passkeys", id: oldPasskeyId) else {- throw PasskeyRepositoryError.passkeyNotFound- }-let now = self.now()let itemId = newPasskey.parentItemId.uuidString.lowercased()if let logo = logo {- try refreshItemLogo(itemId: itemId, manifestId: scope, rpId: newPasskey.rpId, logo: logo, now: now)+ try refreshItemLogo(itemId: itemId, manifestId: manifestId, rpId: newPasskey.rpId, logo: logo, now: now)}- try client.executeUpdate(PasskeyQueries.softDelete, params: [now, oldPasskeyId, scope])- return try insertPasskey(newPasskey, itemId: itemId, displayName: displayName, now: now)+ try client.executeUpdate(PasskeyQueries.softDelete, params: [now, oldPasskeyId, manifestId])+ return try insertPasskey(newPasskey, itemId: itemId, manifestId: manifestId, displayName: displayName, now: now)}}@@ -208,52 +200,35 @@ public class PasskeyRepository: BaseRepository {let scope = try writeManifestId()let logoId = try resolveLogoId(existingLogoId: nil, manifestId: scope, rpId: rpId, logo: logo, now: now)- try client.executeUpdate(ItemQueries.insertItem, params: [itemId, displayName as SqliteBindValue, ItemType.login, logoId as SqliteBindValue, nil, now, now, 0, nil, scope])+ try client.executeUpdate(ItemQueries.insertItem, params: [itemId, displayName as SqliteBindValue, ItemType.login, logoId as SqliteBindValue, nil, now, now, 0, scope])try insertSystemField(itemId: itemId, fieldKey: FieldKey.loginUrl, value: "https://\(rpId)", manifestId: scope, now: now)if let userName = userName, !userName.isEmpty {try insertSystemField(itemId: itemId, fieldKey: FieldKey.loginUsername, value: userName, manifestId: scope, now: now)}- _ = try insertPasskey(passkey, itemId: itemId, displayName: passkey.displayName, now: now)+ _ = try insertPasskey(passkey, itemId: itemId, manifestId: scope, displayName: passkey.displayName, now: now)return itemId}}- /// Refresh an item's logo from a freshly fetched favicon. Only the logo is touched, never the item name.- /// - Parameters:- /// - itemId: The item ID- /// - logo: The favicon bytes- /// - rpId: The relying party ID the favicon was fetched for- public func updateItemLogo(itemId: String, logo: Data, rpId: String) throws {- try withTransaction {- guard let scope = try resolveRowManifestId(table: "Items", id: itemId) else {- throw PasskeyRepositoryError.itemNotFound- }- try refreshItemLogo(itemId: itemId, manifestId: scope, rpId: rpId, logo: logo, now: self.now())- }- }-/// 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+ /// - manifestId: The manifest the item belongs to/// - passkey: The passkey to add/// - logo: Optional favicon bytes fetched for the passkey's rpId/// - Returns: The ID of the created passkey@discardableResult- public func addPasskeyToExistingItem(itemId: UUID, passkey: Passkey, logo: Data? = nil) throws -> String {+ public func addPasskeyToExistingItem(itemId: UUID, manifestId: String, passkey: Passkey, logo: Data? = nil) throws -> String {return try withTransaction {let itemIdString = itemId.uuidString.lowercased()- guard let scope = try resolveRowManifestId(table: "Items", id: itemIdString) else {- throw PasskeyRepositoryError.itemNotFound- }-let now = self.now()if let logo = logo {- try refreshItemLogo(itemId: itemIdString, manifestId: scope, rpId: passkey.rpId, logo: logo, now: now)+ try refreshItemLogo(itemId: itemIdString, manifestId: manifestId, rpId: passkey.rpId, logo: logo, now: now)}- return try insertPasskey(passkey, itemId: itemIdString, displayName: passkey.displayName, now: now)+ return try insertPasskey(passkey, itemId: itemIdString, manifestId: manifestId, displayName: passkey.displayName, now: now)}}@@ -267,23 +242,21 @@ public class PasskeyRepository: BaseRepository {/// Insert one system field value for an item.private func insertSystemField(itemId: String, fieldKey: String, value: String, manifestId: String, now: String) throws {let weight = FieldValueQueries.defaultWeight(forFieldKey: fieldKey)- try client.executeUpdate(FieldValueQueries.insert, params: [generateId(), itemId, nil, fieldKey, value, weight, now, now, 0, itemId, manifestId])+ try client.executeUpdate(FieldValueQueries.insert, params: [generateId(), itemId, nil, fieldKey, value, weight, now, now, 0, manifestId])}/// Insert a passkey row linked to an item, stamped with the item's manifest./// - Returns: The passkey ID- private func insertPasskey(_ passkey: Passkey, itemId: String, displayName: String, now: String) throws -> String {+ private func insertPasskey(_ passkey: Passkey, itemId: String, manifestId: String, displayName: String, now: String) throws -> String {let passkeyId = passkey.id.uuidString.lowercased()guard let publicKeyString = String(data: passkey.publicKey, encoding: .utf8), let privateKeyString = String(data: passkey.privateKey, encoding: .utf8) else {throw PasskeyRepositoryError.invalidKeyData}- let fallbackManifestId = try writeManifestId()try client.executeUpdate(PasskeyQueries.insert, params: [passkeyId,itemId,- itemId,- fallbackManifestId,+ manifestId,passkey.rpId,blobParam(passkey.userHandle),publicKeyString,diff --git a/apps/mobile-app/ios/VaultStoreKit/Database/Repositories/PasskeyRepositoryTypes.swift b/apps/mobile-app/ios/VaultStoreKit/Database/Repositories/PasskeyRepositoryTypes.swiftindex 1cbd72ac7..0b88e2e54 100644--- a/apps/mobile-app/ios/VaultStoreKit/Database/Repositories/PasskeyRepositoryTypes.swift+++ b/apps/mobile-app/ios/VaultStoreKit/Database/Repositories/PasskeyRepositoryTypes.swift@@ -20,11 +20,11 @@ public struct ItemWithCredentialInfoData {public let createdAt: Date/// When the item was last updated.public let updatedAt: Date- /// The manifest the item lives in, when known.- public let manifestId: String?+ /// The manifest the item lives in.+ public let manifestId: String/// Create an entry from the mapped row values.- public init(itemId: UUID, serviceName: String?, urls: [String], username: String?, email: String? = nil, hasPassword: Bool, createdAt: Date, updatedAt: Date, manifestId: String? = nil) {+ public init(itemId: UUID, serviceName: String?, urls: [String], username: String?, email: String? = nil, hasPassword: Bool, createdAt: Date, updatedAt: Date, manifestId: String) {self.itemId = itemIdself.serviceName = serviceNameself.urls = urls@@ -43,6 +43,4 @@ public enum PasskeyRepositoryError: Error {case invalidKeyData/// No live passkey with the given id exists.case passkeyNotFound- /// No item with the given id exists.- case itemNotFound}diff --git a/apps/mobile-app/ios/VaultStoreKit/Database/Repositories/TotpRepository.swift b/apps/mobile-app/ios/VaultStoreKit/Database/Repositories/TotpRepository.swiftindex 7e6538d68..683fce450 100644--- a/apps/mobile-app/ios/VaultStoreKit/Database/Repositories/TotpRepository.swift+++ b/apps/mobile-app/ios/VaultStoreKit/Database/Repositories/TotpRepository.swift@@ -13,15 +13,10 @@ public class TotpRepository: BaseRepository {/// Get all TOTP codes for a specific item./// - Parameters:/// - itemId: The UUID of the item- /// - manifestId: The manifest the item belongs to, when the caller knows it+ /// - manifestId: The manifest the item belongs to/// - Returns: Array of TotpCode objects for the item- public func getTotpCodesForItem(_ itemId: UUID, manifestId: String? = nil) throws -> [TotpCode] {- let itemIdString = itemId.uuidString.lowercased()- guard let scope = try manifestId ?? resolveRowManifestId(table: "Items", id: itemIdString) else {- return []- }-- let results = try client.executeQuery(Self.getByItemId, params: [itemIdString, scope])+ public func getTotpCodesForItem(_ itemId: UUID, manifestId: String) throws -> [TotpCode] {+ let results = try client.executeQuery(Self.getByItemId, params: [itemId.uuidString.lowercased(), manifestId])return results.compactMap { row -> TotpCode? inguard let idString = row["Id"] as? String, let id = UUID(uuidString: idString), let name = row["Name"] as? String, let secretKey = row["SecretKey"] as? String else {return nil@@ -46,9 +41,9 @@ public class TotpRepository: BaseRepository {/// Get the first TOTP code for a specific item (convenience method)./// - Parameters:/// - itemId: The UUID of the item- /// - manifestId: The manifest the item belongs to, when the caller knows it+ /// - manifestId: The manifest the item belongs to/// - Returns: Optional TotpCode if one exists- public func getFirstTotpCodeForItem(_ itemId: UUID, manifestId: String? = nil) throws -> TotpCode? {+ public func getFirstTotpCodeForItem(_ itemId: UUID, manifestId: String) throws -> TotpCode? {return try getTotpCodesForItem(itemId, manifestId: manifestId).first}}diff --git a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Passkey.swift b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Passkey.swiftindex 0e1973410..a7d1340a3 100644--- a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Passkey.swift+++ b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Passkey.swift@@ -26,17 +26,10 @@ extension VaultStore {/*** Get all passkeys for an item.*/- public func getPasskeys(forItemId itemId: UUID, manifestId: String? = nil) throws -> [Passkey] {+ public func getPasskeys(forItemId itemId: UUID, manifestId: String) throws -> [Passkey] {return try passkeyRepository.getByItemId(itemId.uuidString.lowercased(), manifestId: manifestId)}- /**- * Get all passkeys for a credential (legacy alias for backwards compatibility)- */- public func getPasskeys(forCredentialId credentialId: UUID) throws -> [Passkey] {- return try getPasskeys(forItemId: credentialId)- }-/*** Get all passkeys for a specific relying party identifier (RP ID)*/@@ -102,29 +95,20 @@ extension VaultStore {return itemId}- /**- * Insert a new passkey into the database- */- public func insertPasskey(_ passkey: Passkey) throws {- try passkeyRepository.create(passkey)- }-/*** Replace an existing passkey with a new one- * This deletes the old passkey and creates a new one with the same item+ * This deletes the old passkey and creates a new one with the same item, in the same manifest*/- public func replacePasskey(oldPasskeyId: UUID, newPasskey: Passkey, displayName: String, logo: Data? = nil) throws {+ public func replacePasskey(oldPasskeyId: UUID, manifestId: String, newPasskey: Passkey, displayName: String, logo: Data? = nil) throws {// Get the old passkey to find its item- guard let oldPasskey = try passkeyRepository.getById(oldPasskeyId.uuidString.lowercased()) else {+ guard let oldPasskey = try passkeyRepository.getById(oldPasskeyId.uuidString.lowercased(), manifestId: manifestId) else {throw VaultStoreError.passkeyNotFound}- let itemId = oldPasskey.parentItemId-// Create the new passkey with the same item ID, in the same manifestlet updatedPasskey = Passkey(id: newPasskey.id,- parentItemId: itemId, // Use the old item ID+ parentItemId: oldPasskey.parentItemId,rpId: newPasskey.rpId,userHandle: newPasskey.userHandle,userName: newPasskey.userName,@@ -135,12 +119,13 @@ extension VaultStore {createdAt: Date(),updatedAt: Date(),isDeleted: false,- manifestId: oldPasskey.manifestId+ manifestId: manifestId)// Replace the passkey (handles logo update in same transaction)try passkeyRepository.replace(oldPasskeyId: oldPasskeyId.uuidString.lowercased(),+ manifestId: manifestId,with: updatedPasskey,displayName: displayName,logo: logo@@ -150,18 +135,20 @@ extension VaultStore {/*** 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 manifestId The manifest the item belongs to.* @param passkey The passkey to add.* @param logo Optional logo to update/add.*/public func addPasskeyToExistingItem(itemId: UUID,+ manifestId: String,passkey: Passkey,logo: Data? = nil) throws {- // Create the passkey with the existing item ID+ // Create the passkey with the existing item ID, in that item's manifestlet passkeyWithItemId = Passkey(id: passkey.id,- parentItemId: itemId, // Link to the existing item+ parentItemId: itemId,rpId: passkey.rpId,userHandle: passkey.userHandle,userName: passkey.userName,@@ -171,11 +158,13 @@ extension VaultStore {displayName: passkey.displayName,createdAt: Date(),updatedAt: Date(),- isDeleted: false+ isDeleted: false,+ manifestId: manifestId)try passkeyRepository.addPasskeyToExistingItem(itemId: itemId,+ manifestId: manifestId,passkey: passkeyWithItemId,logo: logo)@@ -188,6 +177,5 @@ extension VaultStore {public enum VaultStoreError: Error {case vaultNotUnlockedcase passkeyNotFound- case itemNotFoundcase databaseError(String)}diff --git a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Query.swift b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Query.swiftindex 2a00d8492..44af29915 100644--- a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Query.swift+++ b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Query.swift@@ -148,17 +148,18 @@ extension VaultStore {/// for kicking off `mutateVault(using:)` afterwards to push the change./// - Parameters:/// - itemId: The UUID of the credential to append to+ /// - manifestId: The manifest the credential belongs to/// - url: The URL or app package identifier to add- public func appendUrl(toItemId itemId: UUID, url: String) throws {- try itemRepository.appendFieldValue(itemId: itemId.uuidString.lowercased(), fieldKey: FieldKey.loginUrl, value: url)+ public func appendUrl(toItemId itemId: UUID, manifestId: String, url: String) throws {+ try itemRepository.appendFieldValue(itemId: itemId.uuidString.lowercased(), manifestId: manifestId, fieldKey: FieldKey.loginUrl, value: url)}/// Record one use of an item in its ItemStats row. Runs in a transaction, so the vault is persisted and marked dirty./// - Parameters:/// - itemId: The item that was used- /// - manifestId: The manifest the item belongs to, when the caller knows it+ /// - manifestId: The manifest the item belongs to/// - action: What the user did with it- public func recordItemUsage(itemId: UUID, manifestId: String? = nil, action: ItemUsageAction) throws {+ public func recordItemUsage(itemId: UUID, manifestId: String, action: ItemUsageAction) throws {try itemStatsRepository.recordUsage(itemId: itemId.uuidString.lowercased(), manifestId: manifestId, action: action)}@@ -192,10 +193,10 @@ extension VaultStore {/// Get the first TOTP code for a specific item./// - Parameters:/// - itemId: The UUID of the item- /// - manifestId: The manifest the item belongs to, when the caller knows it+ /// - manifestId: The manifest the item belongs to/// - Returns: Optional TotpCode if one exists/// - Throws: Database errors- public func getFirstTotpCode(forItemId itemId: UUID, manifestId: String? = nil) throws -> TotpCode? {+ public func getFirstTotpCode(forItemId itemId: UUID, manifestId: String) throws -> TotpCode? {return try totpRepository.getFirstTotpCodeForItem(itemId, manifestId: manifestId)}}diff --git a/apps/mobile-app/ios/VaultUI/Registration/Passkeys/Models/ItemWithCredentialInfo.swift b/apps/mobile-app/ios/VaultUI/Registration/Passkeys/Models/ItemWithCredentialInfo.swiftindex 387e01771..2544b65b8 100644--- a/apps/mobile-app/ios/VaultUI/Registration/Passkeys/Models/ItemWithCredentialInfo.swift+++ b/apps/mobile-app/ios/VaultUI/Registration/Passkeys/Models/ItemWithCredentialInfo.swift@@ -4,8 +4,8 @@ import Foundationpublic struct ItemWithCredentialInfo: Identifiable {public let id: UUID // Alias for itemId for Identifiable conformancepublic let itemId: UUID+ public let manifestId: Stringpublic let serviceName: String?- /// All URLs associated with this item (supports multi-value URL fields)public let urls: [String]public let username: String?public let email: String?@@ -23,9 +23,10 @@ public struct ItemWithCredentialInfo: Identifiable {return (mail?.isEmpty == false) ? mail : nil}- public init(itemId: UUID, serviceName: String?, urls: [String], username: String?, email: String? = nil, hasPassword: Bool, createdAt: Date, updatedAt: Date) {+ public init(itemId: UUID, manifestId: String, serviceName: String?, urls: [String], username: String?, email: String? = nil, hasPassword: Bool, createdAt: Date, updatedAt: Date) {self.id = itemIdself.itemId = itemId+ self.manifestId = manifestIdself.serviceName = serviceNameself.urls = urlsself.username = usernamediff --git a/apps/mobile-app/ios/VaultUI/Registration/Passkeys/Models/PasskeyWithCredentialInfo.swift b/apps/mobile-app/ios/VaultUI/Registration/Passkeys/Models/PasskeyWithCredentialInfo.swiftindex aa7258808..068e4a9ed 100644--- a/apps/mobile-app/ios/VaultUI/Registration/Passkeys/Models/PasskeyWithCredentialInfo.swift+++ b/apps/mobile-app/ios/VaultUI/Registration/Passkeys/Models/PasskeyWithCredentialInfo.swift@@ -3,6 +3,7 @@ import Foundation/// Helper struct to pass passkey data with credential infopublic struct PasskeyWithCredentialInfo: Identifiable {public let id: UUID+ public let manifestId: Stringpublic let displayName: Stringpublic let serviceName: String?public let username: String?@@ -20,8 +21,9 @@ public struct PasskeyWithCredentialInfo: Identifiable {return (mail?.isEmpty == false) ? mail : nil}- public init(id: UUID, displayName: String, serviceName: String?, username: String?, email: String? = nil, rpId: String, userId: Data?) {+ public init(id: UUID, manifestId: String, displayName: String, serviceName: String?, username: String?, email: String? = nil, rpId: String, userId: Data?) {self.id = id+ self.manifestId = manifestIdself.displayName = displayNameself.serviceName = serviceNameself.username = usernamediff --git a/apps/mobile-app/ios/VaultUI/Registration/Passkeys/PasskeyRegistrationView.swift b/apps/mobile-app/ios/VaultUI/Registration/Passkeys/PasskeyRegistrationView.swiftindex d8162e087..5d5fe6bd1 100644--- a/apps/mobile-app/ios/VaultUI/Registration/Passkeys/PasskeyRegistrationView.swift+++ b/apps/mobile-app/ios/VaultUI/Registration/Passkeys/PasskeyRegistrationView.swift@@ -94,7 +94,7 @@ public struct PasskeyRegistrationView: View {VStack(spacing: 8) {ForEach(viewModel.existingItemsWithoutPasskey) { itemInfo inButton(action: {- viewModel.handleSelectMerge(itemId: itemInfo.itemId)+ viewModel.handleSelectMerge(itemInfo)navigationPath.append(PasskeyNavigationDestination.mergeWithItem(itemInfo.itemId))}, label: {ExistingItemRow(item: itemInfo, rpId: viewModel.rpId)@@ -120,7 +120,7 @@ public struct PasskeyRegistrationView: View {VStack(spacing: 8) {ForEach(viewModel.existingPasskeys) { passkeyInfo inButton(action: {- viewModel.handleSelectReplace(passkeyId: passkeyInfo.id)+ viewModel.handleSelectReplace(passkeyInfo)navigationPath.append(PasskeyNavigationDestination.replace(passkeyInfo.id))}, label: {ExistingPasskeyRow(passkey: passkeyInfo)@@ -314,8 +314,8 @@ public class PasskeyRegistrationViewModel: ObservableObject {@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 selectedPasskeyToReplace: PasskeyWithCredentialInfo?+ @Published public var selectedItemToMerge: ItemWithCredentialInfo?@Published public var isMergeMode: Bool = falseprivate let completionHandler: (Bool) -> Void@@ -359,24 +359,20 @@ public class PasskeyRegistrationViewModel: ObservableObject {displayName = rpId}- public func handleSelectReplace(passkeyId: UUID) {- selectedPasskeyToReplace = passkeyId+ public func handleSelectReplace(_ passkey: PasskeyWithCredentialInfo) {+ selectedPasskeyToReplace = passkeyselectedItemToMerge = nilisMergeMode = false// Pre-fill display name with the existing passkey's name- if let passkey = existingPasskeys.first(where: { $0.id == passkeyId }) {- displayName = passkey.displayName- }+ displayName = passkey.displayName}- public func handleSelectMerge(itemId: UUID) {+ public func handleSelectMerge(_ item: ItemWithCredentialInfo) {selectedPasskeyToReplace = nil- selectedItemToMerge = itemId+ selectedItemToMerge = itemisMergeMode = 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- }+ displayName = item.serviceName ?? rpId}public func createPasskey() {@@ -430,6 +426,7 @@ public class PasskeyRegistrationViewModel: ObservableObject {existingPasskeys: [PasskeyWithCredentialInfo(id: UUID(),+ manifestId: "preview",displayName: "My Example Passkey",serviceName: "Example Service",username: "[email protected]",@@ -438,6 +435,7 @@ public class PasskeyRegistrationViewModel: ObservableObject {),PasskeyWithCredentialInfo(id: UUID(),+ manifestId: "preview",displayName: "Work Account",serviceName: "Example Service",username: "[email protected]",diff --git a/apps/mobile-app/ios/VaultUI/Selection/Components/CredentialCardView.swift b/apps/mobile-app/ios/VaultUI/Selection/Components/CredentialCardView.swiftindex ffd65b031..9ce541e52 100644--- a/apps/mobile-app/ios/VaultUI/Selection/Components/CredentialCardView.swift+++ b/apps/mobile-app/ios/VaultUI/Selection/Components/CredentialCardView.swift@@ -192,6 +192,7 @@ public func truncateText(_ text: String?, limit: Int) -> String {AutofillCredentialCard(credential: AutofillCredential(id: UUID(),+ manifestId: "preview",serviceName: "Example Service with a very long name bla bla bla",serviceUrls: ["https://example.com"],logo: nil,diff --git a/apps/mobile-app/ios/VaultUI/Selection/CredentialProviderView.swift b/apps/mobile-app/ios/VaultUI/Selection/CredentialProviderView.swiftindex 034aba9e9..1b6b14200 100644--- a/apps/mobile-app/ios/VaultUI/Selection/CredentialProviderView.swift+++ b/apps/mobile-app/ios/VaultUI/Selection/CredentialProviderView.swift@@ -309,7 +309,7 @@ private struct AutofillCredentialCardWithSelection: View {/// State for the "do you want to link this URL/app to the credential?" alert./// Held on the view-model while the alert is visible.public struct PendingLinkSelection {- public let credentialId: UUID+ public let credential: AutofillCredentialpublic let credentialName: Stringpublic let username: Stringpublic let password: String@@ -331,23 +331,23 @@ public class CredentialProviderViewModel: ObservableObject {private let selectionHandler: (String, String) -> Voidprivate let cancelHandler: () -> Void- /// Optional async handler that, given an item ID and the requesting service URL,- /// appends the URL to that item's `login.url` field and syncs the vault.+ /// Optional async handler that, given a credential and the requesting service URL,+ /// appends the URL to that credential's `login.url` field and syncs the vault./// When nil, the link-prompt flow is disabled and selection always falls through/// directly to `selectionHandler`.- private let urlLinker: ((UUID, String) async -> Void)?+ private let urlLinker: ((AutofillCredential, String) async -> Void)?- /// Optional handler called with the item id right before a fill is handed to the host, so the+ /// Optional handler called with the credential right before a fill is handed to the host, so the/// vault can record the use.- private let usageRecorder: ((UUID) -> Void)?+ private let usageRecorder: ((AutofillCredential) -> Void)?public init(loader: @escaping () async throws -> [AutofillCredential],selectionHandler: @escaping (String, String) -> Void,cancelHandler: @escaping () -> Void,serviceUrl: String? = nil,- urlLinker: ((UUID, String) async -> Void)? = nil,- usageRecorder: ((UUID) -> Void)? = nil+ urlLinker: ((AutofillCredential, String) async -> Void)? = nil,+ usageRecorder: ((AutofillCredential) -> Void)? = nil) {self.loader = loaderself.selectionHandler = selectionHandler@@ -409,7 +409,7 @@ public class CredentialProviderViewModel: ObservableObject {let serviceUrl = serviceUrl,!serviceUrl.isEmpty,urlLinker != nil else {- complete(credentialId: credential.id, username: username, password: password)+ complete(credential: credential, username: username, password: password)return}@@ -422,12 +422,12 @@ public class CredentialProviderViewModel: ObservableObject {AutofillUrlNormalizer.comparisonKey(existing) == serviceKey}if alreadyLinked {- complete(credentialId: credential.id, username: username, password: password)+ complete(credential: credential, username: username, password: password)return}pendingLinkSelection = PendingLinkSelection(- credentialId: credential.id,+ credential: credential,credentialName: credential.serviceName ?? "",username: username,password: password@@ -447,9 +447,9 @@ public class CredentialProviderViewModel: ObservableObject {isLinkingUrl = trueTask { @MainActor in- await urlLinker(pending.credentialId, serviceUrl)+ await urlLinker(pending.credential, serviceUrl)isLinkingUrl = false- complete(credentialId: pending.credentialId, username: pending.username, password: pending.password)+ complete(credential: pending.credential, username: pending.username, password: pending.password)}}@@ -460,12 +460,12 @@ public class CredentialProviderViewModel: ObservableObject {return}pendingLinkSelection = nil- complete(credentialId: pending.credentialId, username: pending.username, password: pending.password)+ complete(credential: pending.credential, username: pending.username, password: pending.password)}/// Complete a fill: record the use of the credential, then hand the values to the host.- private func complete(credentialId: UUID, username: String, password: String) {- usageRecorder?(credentialId)+ private func complete(credential: AutofillCredential, username: String, password: String) {+ usageRecorder?(credential)selectionHandler(username, password)}@@ -487,6 +487,7 @@ extension AutofillCredential {static var preview: AutofillCredential {AutofillCredential(id: UUID(),+ manifestId: "preview",serviceName: "Example Service",serviceUrls: ["https://example.com"],logo: nil,@@ -508,6 +509,7 @@ public class PreviewCredentialProviderViewModel: CredentialProviderViewModel {.preview,AutofillCredential(id: UUID(),+ manifestId: "preview",serviceName: "Another Service",serviceUrls: ["https://another.com"],logo: nil,diff --git a/apps/mobile-app/ios/VaultUI/Selection/PasskeyProviderView.swift b/apps/mobile-app/ios/VaultUI/Selection/PasskeyProviderView.swiftindex 972f5cf3b..70c4dd49c 100644--- a/apps/mobile-app/ios/VaultUI/Selection/PasskeyProviderView.swift+++ b/apps/mobile-app/ios/VaultUI/Selection/PasskeyProviderView.swift@@ -337,6 +337,7 @@ public class PasskeyProviderViewModel: ObservableObject {let mockCredentials: [AutofillCredential] = [AutofillCredential(id: UUID(),+ manifestId: "preview",serviceName: "GitHub",serviceUrls: ["https://github.com"],logo: nil,@@ -350,6 +351,7 @@ public class PasskeyProviderViewModel: ObservableObject {),AutofillCredential(id: UUID(),+ manifestId: "preview",serviceName: "Google",serviceUrls: ["https://google.com"],logo: nil,@@ -396,6 +398,7 @@ public class PasskeyProviderViewModel: ObservableObject {let mockCredentials: [AutofillCredential] = [AutofillCredential(id: UUID(),+ manifestId: "preview",serviceName: "GitHub",serviceUrls: ["https://github.com"],logo: nil,