Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Sync iOS CredentialIdentityStore via React Native callback (#520)
Leendert de Borst3658b606c247
diff --git a/apps/mobile-app/hooks/useVaultSync.ts b/apps/mobile-app/hooks/useVaultSync.tsindex e5c442613..cdf602e77 100644--- a/apps/mobile-app/hooks/useVaultSync.ts+++ b/apps/mobile-app/hooks/useVaultSync.ts@@ -132,6 +132,16 @@ export const useVaultSync = () : {}onSuccess?.(true);++ // Register credential identities after successful vault sync+ try {+ await NativeVaultManager.registerCredentialIdentities();+ console.log('Vault sync: Successfully registered credential identities');+ } catch (error) {+ console.warn('Vault sync: Failed to register credential identities:', error);+ // Don't fail the sync if credential registration fails+ }+return true;} catch (err) {if (err instanceof VaultVersionIncompatibleError) {@@ -151,6 +161,16 @@ export const useVaultSync = () : {}await withMinimumDelay(() => Promise.resolve(onSuccess?.(false)), 300, enableDelay);++ // Register credential identities even when vault is up to date+ try {+ await NativeVaultManager.registerCredentialIdentities();+ console.log('Vault sync: Successfully registered credential identities (vault up to date)');+ } catch (error) {+ console.warn('Vault sync: Failed to register credential identities:', error);+ // Don't fail the sync if credential registration fails+ }+return false;} catch (err) {console.error('Vault sync error:', err);diff --git a/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Credential.swift b/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Credential.swiftindex 1224a5475..c0a50de7c 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 behaviorslet viewModel = CredentialProviderViewModel(loader: {- return try await self.loadCredentials(vaultStore: vaultStore)+ return try await vaultStore.getAllCredentials()},selectionHandler: { identifier, password inself.handleCredentialSelection(identifier: identifier, password: password)@@ -61,16 +61,6 @@ extension CredentialProviderViewController: CredentialProviderDelegate {}}- func loadCredentials(vaultStore: VaultStore) async throws -> [Credential] {- // getAllCredentials now includes passkeys for each credential- let credentials = try vaultStore.getAllCredentials()-- // Register all credential identities (passwords and passkeys)- await self.registerCredentialIdentities(credentials: credentials)-- return credentials- }-// MARK: - Credential-specific Methodsoverride public func prepareInterfaceForUserChoosingTextToInsert() {@@ -140,26 +130,4 @@ extension CredentialProviderViewController: CredentialProviderDelegate {)}}-- /// Register credential identities for QuickType suggestions- private func registerCredentialIdentities(credentials: [Credential]) async {- do {- if #available(iOS 26.0, *) {- // iOS 26+: Register both passwords and passkeys for QuickType and manual selection- try await CredentialIdentityStore.shared.saveCredentialIdentities(credentials)- print("Registered credential identities (passwords + passkeys) for QuickType on iOS 26+")- } else {- // iOS 17-25: Only register passkeys (skip passwords for QuickType to avoid biometric issues)- // But passkeys MUST be registered so iOS knows to offer this extension for passkey authentication- let passkeyOnlyCredentials = credentials.filter { credential in- guard let passkeys = credential.passkeys else { return false }- return !passkeys.isEmpty- }- try await CredentialIdentityStore.shared.saveCredentialIdentities(passkeyOnlyCredentials, passkeyOnly: true)- print("Registered \(passkeyOnlyCredentials.count) passkey identities on iOS <26 (password QuickType disabled)")- }- } catch {- print("Failed to save credential identities: \(error)")- }- }}diff --git a/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift b/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swiftindex 81a8ffcab..75dda77a0 100644--- a/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift+++ b/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift@@ -14,7 +14,17 @@ extension CredentialProviderViewController: PasskeyProviderDelegate {func setupPasskeyView(vaultStore: VaultStore, rpId: String, clientDataHash: Data) throws -> UIViewController {let viewModel = PasskeyProviderViewModel(loader: {- return try await self.loadPasskeyCredentials(vaultStore: vaultStore, rpId: rpId)+ // getAllCredentials now includes passkeys for each credential+ // TODO: call a separate method for only retrieving passkeys?+ var credentials = try vaultStore.getAllCredentials()++ // 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 credentials},selectionHandler: { credential in// For passkey authentication, we assume the data is available@@ -378,11 +388,22 @@ extension CredentialProviderViewController: PasskeyProviderDelegate {/*** Show passkey picker view for user selection+ * TODO: check usages*/private func showPasskeyPickerView(rpId: String, clientDataHash: Data, vaultStore: VaultStore) {let viewModel = PasskeyProviderViewModel(loader: {- return try await self.loadPasskeyCredentials(vaultStore: vaultStore, rpId: rpId)+ // getAllCredentials now includes passkeys for each credential+ // TODO: call a separate method for only retrieving passkeys?+ var credentials = try vaultStore.getAllCredentials()++ // 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 credentials},selectionHandler: { [weak self, clientDataHash, rpId] credential inguard let self = self else { return }@@ -435,33 +456,6 @@ extension CredentialProviderViewController: PasskeyProviderDelegate {return !passkeys.isEmpty}- // Filter by RP ID if specified- /*if !rpId.isEmpty {- let lowercasedRpId = rpId.lowercased()- return credentials.filter { credential in- guard let passkeys = credential.passkeys else { return false }- // Match exact RP ID or check if RP ID is a suffix of the credential's service domain- return passkeys.contains { passkey in- let passkeyRpId = passkey.rpId.lowercased()- // Exact match- if passkeyRpId == lowercasedRpId {- return true- }- // Check if they are related domains (e.g., rpId="example.com", passkey.rpId="www.example.com")- if passkeyRpId.hasSuffix(lowercasedRpId) || lowercasedRpId.hasSuffix(passkeyRpId) {- return true- }- // Check against service URL domain as well- if let serviceUrl = credential.service.url?.lowercased(),- let url = URL(string: serviceUrl),- let host = url.host?.lowercased() {- return host == lowercasedRpId || host.hasSuffix(".\(lowercasedRpId)") || lowercasedRpId.hasSuffix(".\(host)")- }- return false- }- }- }*/-return credentials}diff --git a/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift b/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swiftindex cfad24da4..ff1b93b24 100644--- a/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift+++ b/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift@@ -10,13 +10,11 @@ import VaultModelsprotocol CredentialProviderDelegate: AnyObject {func setupCredentialView(vaultStore: VaultStore, serviceUrl: String?) throws -> UIViewControllerfunc handleCredentialSelection(identifier: String, password: String)- func loadCredentials(vaultStore: VaultStore) async throws -> [Credential]}protocol PasskeyProviderDelegate: AnyObject {func setupPasskeyView(vaultStore: VaultStore, rpId: String, clientDataHash: Data) throws -> UIViewControllerfunc handlePasskeySelection(credential: Credential, clientDataHash: Data, rpId: String)- func loadPasskeyCredentials(vaultStore: VaultStore, rpId: String?) async throws -> [Credential]}/**@@ -204,33 +202,6 @@ public class CredentialProviderViewController: ASCredentialProviderViewControlle}- /// This registers all known AliasVault credentials (both passwords and passkeys) into iOS native credential storage,- /// which iOS can then use to suggest autofill credentials when a user focuses an input field on a login form.- /// These suggestions will then be shown above the iOS keyboard, which saves the user one step.- ///- /// Note: Password QuickType bar suggestions are only enabled on iOS 26+ due to biometric authentication limitations- /// in iOS 17 and 18 where background authentication doesn't work reliably. However, PASSKEY identities must be- /// registered on all iOS versions (17+) so iOS knows to call this extension for passkey authentication requests.- private func registerCredentialIdentities(credentials: [Credential]) async {- do {- if #available(iOS 26.0, *) {- // iOS 26+: Register both passwords and passkeys for QuickType and manual selection- try await CredentialIdentityStore.shared.saveCredentialIdentities(credentials)- print("Registered credential identities (passwords + passkeys) for QuickType on iOS 26+")- } else {- // iOS 17-25: Only register passkeys (skip passwords for QuickType to avoid biometric issues)- // But passkeys MUST be registered so iOS knows to offer this extension for passkey authentication- let passkeyOnlyCredentials = credentials.filter { credential in- guard let passkeys = credential.passkeys else { return false }- return !passkeys.isEmpty- }- try await CredentialIdentityStore.shared.saveCredentialIdentities(passkeyOnlyCredentials, passkeyOnly: true)- print("Registered \(passkeyOnlyCredentials.count) passkey identities on iOS <26 (password QuickType disabled)")- }- } catch {- print("Failed to save credential identities: \(error)")- }- }/// Run sanity checks on the vault store before opening the autofill view to check things like if user is logged in,/// vault is available etc.diff --git a/apps/mobile-app/ios/NativeVaultManager/RCTNativeVaultManager.mm b/apps/mobile-app/ios/NativeVaultManager/RCTNativeVaultManager.mmindex 98729eb65..d2efa2b60 100644--- a/apps/mobile-app/ios/NativeVaultManager/RCTNativeVaultManager.mm+++ b/apps/mobile-app/ios/NativeVaultManager/RCTNativeVaultManager.mm@@ -167,4 +167,8 @@resolve(@"Not applicable on iOS");}+- (void)registerCredentialIdentities:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {+ [vaultManager registerCredentialIdentities:resolve rejecter:reject];+}+@enddiff --git a/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift b/apps/mobile-app/ios/NativeVaultManager/VaultManager.swiftindex 0382f51a1..1017ce5cb 100644--- a/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift+++ b/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift@@ -11,7 +11,7 @@ import VaultModels*/@objc(VaultManager)public class VaultManager: NSObject {- private let vaultStore = VaultStore.shared+ private let vaultStore = VaultStore()private var backgroundTaskIdentifier: UIBackgroundTaskIdentifier = .invalidprivate var clipboardClearTimer: DispatchSourceTimer?@@ -405,12 +405,12 @@ public class VaultManager: NSObject {resolver resolve: @escaping RCTPromiseResolveBlock,rejecter reject: @escaping RCTPromiseRejectBlock) {NSLog("VaultManager: Copying to clipboard with expiration of %.0f seconds", expirationSeconds)-+DispatchQueue.main.async {if expirationSeconds > 0 {// Create expiration datelet expirationDate = Date().addingTimeInterval(expirationSeconds)-+// Set clipboard with expiration and local-only optionsUIPasteboard.general.setItems([[UIPasteboard.typeAutomatic: text]],@@ -419,7 +419,7 @@ public class VaultManager: NSObject {.localOnly: true // Prevent sync to Universal Clipboard/iCloud])-+NSLog("VaultManager: Text copied to clipboard with expiration at %@", expirationDate.description)} else {// No expiration, just copy normally@@ -430,6 +430,42 @@ public class VaultManager: NSObject {}}+ @objc+ func registerCredentialIdentities(_ resolve: @escaping RCTPromiseResolveBlock,+ rejecter reject: @escaping RCTPromiseRejectBlock) {+ Task {+ do {+ // Get all credentials from the vault+ let credentials = try vaultStore.getAllCredentials()++ // Register credential identities using the same logic as the autofill extension+ if #available(iOS 26.0, *) {+ // iOS 26+: Register both passwords and passkeys for QuickType and manual selection+ try await CredentialIdentityStore.shared.saveCredentialIdentities(credentials)+ print("VaultManager: Registered credential identities (passwords + passkeys) for QuickType on iOS 26+")+ } else {+ // iOS 17-25: Only register passkeys (skip passwords for QuickType to avoid biometric issues)+ // But passkeys MUST be registered so iOS knows to offer this extension for passkey authentication+ let passkeyOnlyCredentials = credentials.filter { credential in+ guard let passkeys = credential.passkeys else { return false }+ return !passkeys.isEmpty+ }+ try await CredentialIdentityStore.shared.saveCredentialIdentities(passkeyOnlyCredentials, passkeyOnly: true)+ print("VaultManager: Registered \(passkeyOnlyCredentials.count) passkey identities on iOS <26 (password QuickType disabled)")+ }++ await MainActor.run {+ resolve(nil)+ }+ } catch {+ print("VaultManager: Failed to register credential identities: \(error)")+ await MainActor.run {+ reject("CREDENTIAL_REGISTRATION_ERROR", "Failed to register credential identities: \(error.localizedDescription)", error)+ }+ }+ }+ }+@objcfunc requiresMainQueueSetup() -> Bool {return falsediff --git a/apps/mobile-app/ios/Autofill/CredentialIdentityStore.swift b/apps/mobile-app/ios/VaultStoreKit/CredentialIdentityStore.swiftsimilarity index 82%rename from apps/mobile-app/ios/Autofill/CredentialIdentityStore.swiftrename to apps/mobile-app/ios/VaultStoreKit/CredentialIdentityStore.swiftindex 5a42eb769..9aecf0496 100644--- a/apps/mobile-app/ios/Autofill/CredentialIdentityStore.swift+++ b/apps/mobile-app/ios/VaultStoreKit/CredentialIdentityStore.swift@@ -1,7 +1,5 @@import AuthenticationServicesimport VaultModels-import VaultStoreKit-import VaultUI/*** Native iOS implementation of the CredentialIdentityStore protocol.@@ -10,7 +8,8 @@ import VaultUI* It is used to provide credentials to the system when the user is autocompleting a password.*/public class CredentialIdentityStore {- static let shared = CredentialIdentityStore()+ /// Get global credential store instance+ public static let shared = CredentialIdentityStore()private let store = ASCredentialIdentityStore.sharedprivate init() {}@@ -64,7 +63,7 @@ public class CredentialIdentityStore {// 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 emaillet userName = passkey.userName ?? usernameOrEmail(credential: credential)-+// Convert passkey.Id to bytes for credentialIDlet credentialId = try? PasskeyHelper.guidToBytes(passkey.id.uuidString)@@ -95,13 +94,22 @@ public class CredentialIdentityStore {return}- print("CredentialIdentityStore: Store is enabled, saving \(allIdentities.count) total identities")+ print("CredentialIdentityStore: Store is enabled, replacing all identities with \(allIdentities.count) new identities")do {+ // First, remove all existing credential identities to ensure a clean replacement+ print("CredentialIdentityStore: Removing all existing credential identities...")+ try await store.removeAllCredentialIdentities()+ print("CredentialIdentityStore: Successfully removed all existing identities")++ // Then save the new credential identities+ print("CredentialIdentityStore: Saving \(allIdentities.count) new credential identities...")try await store.saveCredentialIdentities(allIdentities)- print("CredentialIdentityStore: Successfully saved all identities")+ print("CredentialIdentityStore: Successfully saved all new identities")} catch {- print("CredentialIdentityStore: Failed to save credential identities: \(error)")+ print("CredentialIdentityStore: Failed to replace credential identities: \(error)")+ // Re-throw the error so the caller knows the operation failed+ throw error}}@@ -148,3 +156,14 @@ public class CredentialIdentityStore {return parts.suffix(2).joined(separator: ".")}}++/// Returns username or email depending on if they are not null+public 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 ""+}diff --git a/apps/mobile-app/specs/NativeVaultManager.ts b/apps/mobile-app/specs/NativeVaultManager.tsindex 00200fe7d..8f6cc7b01 100644--- a/apps/mobile-app/specs/NativeVaultManager.ts+++ b/apps/mobile-app/specs/NativeVaultManager.ts@@ -52,6 +52,9 @@ export interface Spec extends TurboModule {// Battery optimization managementisIgnoringBatteryOptimizations(): Promise<boolean>;requestIgnoreBatteryOptimizations(): Promise<string>;++ // Credential identity management+ registerCredentialIdentities(): Promise<void>;}export default TurboModuleRegistry.getEnforcing<Spec>('NativeVaultManager');