Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Update passkey registration flow (#1404)
Leendert de Borstdc6f1a4d08c2
diff --git a/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift b/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swiftindex f1797f996..7516d2659 100644--- a/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift+++ b/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift@@ -347,8 +347,8 @@ extension CredentialProviderViewController: PasskeyProviderDelegate {}// Step 3: Create passkey credentials- // Generate new credential ID (UUID that will be used as the passkey ID)- let passkeyId = UUID()+ let itemId = UUID() // Item ID that will contain the passkey+ let passkeyId = UUID() // Passkey credential IDlet credentialId = try PasskeyHelper.guidToBytes(passkeyId.uuidString)// Create the passkey using PasskeyAuthenticator@@ -364,11 +364,11 @@ extension CredentialProviderViewController: PasskeyProviderDelegate {prfInputs: prfInputs)- // Create a Passkey model object+ // Create a Passkey model object with correct parentItemIdlet now = Date()let passkey = Passkey(id: passkeyId,- parentItemId: UUID(), // Will be set by createItemWithPasskey+ parentItemId: itemId, // Link to the Item that will be createdrpId: rpId,userHandle: userId,userName: userName,@@ -382,9 +382,6 @@ extension CredentialProviderViewController: PasskeyProviderDelegate {)// Step 4: Store credential with passkey in database- // Begin transaction- try vaultStore.beginTransaction()-// Check if we're replacing an existing passkeyif let oldPasskeyId = viewModel.selectedPasskeyToReplace {// Replace existing passkey@@ -406,9 +403,6 @@ extension CredentialProviderViewController: PasskeyProviderDelegate {)}- // Commit transaction to persist the data- try vaultStore.commitTransaction()-// Step 5: Upload vault changes to serverviewModel.setLoading(true, message: NSLocalizedString("creating_passkey", comment: "Uploading vault..."))do {diff --git a/apps/mobile-app/ios/VaultStoreKit/Database/Repositories/PasskeyRepository.swift b/apps/mobile-app/ios/VaultStoreKit/Database/Repositories/PasskeyRepository.swiftindex c1c77fa54..654634d3f 100644--- a/apps/mobile-app/ios/VaultStoreKit/Database/Repositories/PasskeyRepository.swift+++ b/apps/mobile-app/ios/VaultStoreKit/Database/Repositories/PasskeyRepository.swift@@ -121,18 +121,29 @@ public class PasskeyRepository: BaseRepository {}}- /// Replace an existing passkey with a new one.+ /// Replace an existing passkey with a new one, optionally updating the item's logo./// Deletes the old passkey and creates a new one linked to the same item./// - Parameters:/// - oldPasskeyId: The ID of the passkey to replace/// - newPasskey: The new passkey to create/// - displayName: The display name for the new passkey+ /// - logo: Optional logo data to update/// - Returns: The ID of the new passkey@discardableResult- public func replace(oldPasskeyId: String, with newPasskey: Passkey, displayName: String) throws -> String {+ public func replace(oldPasskeyId: String, with newPasskey: Passkey, displayName: String, logo: Data? = nil) throws -> String {return try withTransaction {let now = self.now()+ // Update logo if provided+ if let logo = logo {+ try updateItemLogoInternal(+ itemId: newPasskey.parentItemId.uuidString.uppercased(),+ logo: logo,+ displayName: displayName,+ now: now+ )+ }+// Delete the old passkeytry client.executeUpdate(PasskeyQueries.softDelete, params: [now, oldPasskeyId])@@ -284,49 +295,59 @@ public class PasskeyRepository: BaseRepository {public func updateItemLogo(itemId: String, logo: Data, displayName: String) throws {try withTransaction {let now = self.now()+ try updateItemLogoInternal(itemId: itemId, logo: logo, displayName: displayName, now: now)+ }+ }- // Get current logo ID from item- let itemResults = try client.executeQuery(- "SELECT LogoId FROM Items WHERE Id = ?",- params: [itemId]- )-- let logoDataParam = "av-base64-to-blob:\(logo.base64EncodedString())"-- if let existingLogoId = itemResults.first?["LogoId"] as? String {- // Update existing logo- try client.executeUpdate(LogoQueries.updateFileData, params: [- logoDataParam,- now,- existingLogoId- ])- } else {- // Create new logo and link to item- let newLogoId = generateId()- try client.executeUpdate(LogoQueries.insert, params: [- newLogoId,- "", // Source not needed for update- logoDataParam,- "image/png",- nil,- now,- now,- 0- ])-- // Update item with new logo ID- try client.executeUpdate(- "UPDATE Items SET LogoId = ?, UpdatedAt = ? WHERE Id = ?",- params: [newLogoId, now, itemId]- )- }+ /// Internal helper to update item logo without creating a transaction.+ /// Used within larger transactions to avoid nested transaction issues.+ /// - Parameters:+ /// - itemId: The item ID+ /// - logo: The new logo data+ /// - displayName: The new display name+ /// - now: The current timestamp+ private func updateItemLogoInternal(itemId: String, logo: Data, displayName: String, now: String) throws {+ // Get current logo ID from item+ let itemResults = try client.executeQuery(+ "SELECT LogoId FROM Items WHERE Id = ?",+ params: [itemId]+ )++ let logoDataParam = "av-base64-to-blob:\(logo.base64EncodedString())"++ if let existingLogoId = itemResults.first?["LogoId"] as? String {+ // Update existing logo+ try client.executeUpdate(LogoQueries.updateFileData, params: [+ logoDataParam,+ now,+ existingLogoId+ ])+ } else {+ // Create new logo and link to item+ let newLogoId = generateId()+ try client.executeUpdate(LogoQueries.insert, params: [+ newLogoId,+ "", // Source not needed for update+ logoDataParam,+ "image/png",+ nil,+ now,+ now,+ 0+ ])- // Update item name+ // Update item with new logo IDtry client.executeUpdate(- "UPDATE Items SET Name = ?, UpdatedAt = ? WHERE Id = ?",- params: [displayName, now, itemId]+ "UPDATE Items SET LogoId = ?, UpdatedAt = ? WHERE Id = ?",+ params: [newLogoId, now, itemId])}++ // Update item name+ try client.executeUpdate(+ "UPDATE Items SET Name = ?, UpdatedAt = ? WHERE Id = ?",+ params: [displayName, now, itemId]+ )}}diff --git a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Passkey.swift b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Passkey.swiftindex e6bb72de4..8dbf52577 100644--- a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Passkey.swift+++ b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Passkey.swift@@ -103,15 +103,6 @@ extension VaultStore {let itemId = oldPasskey.parentItemId- // Update logo if provided- if let logo = logo {- try passkeyRepository.updateItemLogo(- itemId: itemId.uuidString.uppercased(),- logo: logo,- displayName: displayName- )- }-// Create the new passkey with the same item IDlet updatedPasskey = Passkey(id: newPasskey.id,@@ -128,10 +119,12 @@ extension VaultStore {isDeleted: false)+ // Replace the passkey (handles logo update in same transaction)try passkeyRepository.replace(oldPasskeyId: oldPasskeyId.uuidString.uppercased(),with: updatedPasskey,- displayName: displayName+ displayName: displayName,+ logo: logo)}}