Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add swift pin configure flow (#1340)
Leendert de Borstda36af15ae94
diff --git a/apps/mobile-app/ios/NativeVaultManager/RCTNativeVaultManager.mm b/apps/mobile-app/ios/NativeVaultManager/RCTNativeVaultManager.mmindex e2a35da23..b4711e925 100644--- a/apps/mobile-app/ios/NativeVaultManager/RCTNativeVaultManager.mm+++ b/apps/mobile-app/ios/NativeVaultManager/RCTNativeVaultManager.mm@@ -141,6 +141,14 @@[vaultManager openAutofillSettingsPage:resolve rejecter:reject];}+- (void)getAutofillShowSearchText:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {+ [vaultManager getAutofillShowSearchText:resolve rejecter:reject];+}++- (void)setAutofillShowSearchText:(BOOL)showSearchText resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {+ [vaultManager setAutofillShowSearchText:showSearchText resolver:resolve rejecter:reject];+}+- (void)copyToClipboardWithExpiration:(NSString *)text expirationSeconds:(double)expirationSeconds resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {[vaultManager copyToClipboardWithExpiration:text expirationSeconds:expirationSeconds resolver:resolve rejecter:reject];}@@ -273,4 +281,8 @@[vaultManager showPinUnlockUI:resolve rejecter:reject];}+- (void)showNativePinSetup:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {+ [vaultManager showNativePinSetup:resolve rejecter:reject];+}+@enddiff --git a/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift b/apps/mobile-app/ios/NativeVaultManager/VaultManager.swiftindex 63e046637..c3f7bf689 100644--- a/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift+++ b/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift@@ -884,6 +884,55 @@ public class VaultManager: NSObject {}}+ @objc+ func showNativePinSetup(_ resolve: @escaping RCTPromiseResolveBlock,+ rejecter reject: @escaping RCTPromiseRejectBlock) {+ DispatchQueue.main.async { [weak self] in+ guard let self = self else {+ reject("INTERNAL_ERROR", "VaultManager instance deallocated", nil)+ return+ }++ // Get the root view controller from React Native+ guard let rootVC = RCTPresentedViewController() else {+ reject("NO_VIEW_CONTROLLER", "No view controller available", nil)+ return+ }++ // Create PIN setup view with ViewModel+ let viewModel = PinSetupViewModel(+ setupHandler: { [weak self] pin in+ guard let self = self else {+ throw NSError(domain: "VaultManager", code: -1, userInfo: [NSLocalizedDescriptionKey: "VaultManager instance deallocated"])+ }++ // Setup PIN (vault must be unlocked - encryption key is retrieved from memory)+ try self.vaultStore.setupPin(pin)++ // Success - dismiss and resolve+ await MainActor.run {+ rootVC.dismiss(animated: true) {+ resolve(nil)+ }+ }+ },+ cancelHandler: {+ // Dismiss the view+ rootVC.dismiss(animated: true) {+ reject("USER_CANCELLED", "User cancelled PIN setup", nil)+ }+ }+ )++ let pinSetupView = PinSetupView(viewModel: viewModel)+ let hostingController = UIHostingController(rootView: pinSetupView)++ // Present modally as full screen+ hostingController.modalPresentationStyle = .fullScreen+ rootVC.present(hostingController, animated: true)+ }+ }+@objcfunc requiresMainQueueSetup() -> Bool {return falsediff --git a/apps/mobile-app/ios/VaultUI/Auth/PinNumpadView.swift b/apps/mobile-app/ios/VaultUI/Auth/PinNumpadView.swiftnew file mode 100644index 000000000..23ee6f7f8--- /dev/null+++ b/apps/mobile-app/ios/VaultUI/Auth/PinNumpadView.swift@@ -0,0 +1,68 @@+import SwiftUI++/// Reusable numpad view component for PIN entry+public struct PinNumpadView: View {+ let theme: Theme+ let onDigit: (String) -> Void+ let onBackspace: () -> Void++ public init(+ theme: Theme,+ onDigit: @escaping (String) -> Void,+ onBackspace: @escaping () -> Void+ ) {+ self.theme = theme+ self.onDigit = onDigit+ self.onBackspace = onBackspace+ }++ public var body: some View {+ VStack(spacing: 12) {+ // Row 1: 1-3+ HStack(spacing: 12) {+ ForEach(1...3, id: \.self) { num in+ NumpadButton(value: "\(num)", theme: theme) {+ onDigit("\(num)")+ }+ }+ }++ // Row 2: 4-6+ HStack(spacing: 12) {+ ForEach(4...6, id: \.self) { num in+ NumpadButton(value: "\(num)", theme: theme) {+ onDigit("\(num)")+ }+ }+ }++ // Row 3: 7-9+ HStack(spacing: 12) {+ ForEach(7...9, id: \.self) { num in+ NumpadButton(value: "\(num)", theme: theme) {+ onDigit("\(num)")+ }+ }+ }++ // Row 4: Empty, 0, Backspace+ HStack(spacing: 12) {+ // Empty space+ Color.clear+ .frame(height: 60)++ // 0 button+ NumpadButton(value: "0", theme: theme) {+ onDigit("0")+ }++ // Backspace button+ NumpadButton(icon: "delete.left", theme: theme) {+ onBackspace()+ }+ }+ }+ .padding(.horizontal, 40)+ .padding(.bottom, 40)+ }+}diff --git a/apps/mobile-app/ios/VaultUI/Auth/PinSetupView.swift b/apps/mobile-app/ios/VaultUI/Auth/PinSetupView.swiftnew file mode 100644index 000000000..8793d029c--- /dev/null+++ b/apps/mobile-app/ios/VaultUI/Auth/PinSetupView.swift@@ -0,0 +1,161 @@+import SwiftUI+import UIKit++private let locBundle = Bundle.vaultUI++/// SwiftUI view for PIN setup in native iOS flows+/// Two-step process: enter new PIN, then confirm it+public struct PinSetupView: View {+ @ObservedObject public var viewModel: PinSetupViewModel+ @Environment(\.colorScheme) var colorScheme++ public init(viewModel: PinSetupViewModel) {+ self._viewModel = ObservedObject(wrappedValue: viewModel)+ }++ public var body: some View {+ GeometryReader { geometry in+ ZStack {+ VStack(spacing: 0) {+ // Header with cancel button+ HStack {+ Spacer()+ Button(action: {+ viewModel.cancel()+ }) {+ Text(String(localized: "cancel", bundle: locBundle))+ .foregroundColor(theme.primary)+ }+ .padding(.trailing, 20)+ }+ .padding(.top, 20)+ .frame(height: 50)++ Spacer()++ // AliasVault Logo+ Image("Logo", bundle: .vaultUI)+ .resizable()+ .aspectRatio(contentMode: .fit)+ .frame(width: 80, height: 80)+ .padding(.bottom, 20)++ // Title+ Text(viewModel.configuration.title)+ .font(.system(size: 24, weight: .semibold))+ .foregroundColor(theme.text)+ .padding(.bottom, 8)++ // Subtitle+ Text(viewModel.configuration.subtitle)+ .font(.system(size: 16))+ .foregroundColor(theme.text.opacity(0.7))+ .multilineTextAlignment(.center)+ .padding(.horizontal, 40)+ .padding(.bottom, 32)++ // PIN dots display or text based on step+ if let pinLength = viewModel.configuration.pinLength {+ // Confirm step: show dots for fixed length+ HStack(spacing: 12) {+ ForEach(0..<pinLength, id: \.self) { index in+ Circle()+ .strokeBorder(+ index < viewModel.pin.count ? theme.primary : theme.accentBorder,+ lineWidth: 2+ )+ .background(+ Circle()+ .fill(index < viewModel.pin.count ? theme.primary : Color.clear)+ )+ .frame(width: 16, height: 16)+ }+ }+ .padding(.bottom, 24)+ } else {+ // Enter new step: show bullet points for variable length+ Text(viewModel.pin.isEmpty ? "----" : String(repeating: "•", count: viewModel.pin.count))+ .font(.system(size: 42, weight: .semibold))+ .foregroundColor(theme.text)+ .kerning(8)+ .frame(minHeight: 48)+ .padding(.bottom, 24)+ }++ // Error message+ if let error = viewModel.error {+ Text(error)+ .font(.system(size: 14))+ .foregroundColor(theme.errorBorder)+ .multilineTextAlignment(.center)+ .padding(.horizontal, 40)+ .padding(.bottom, 12)+ .transition(.opacity)+ }++ // Continue/Confirm button (for enter new step with variable length)+ if viewModel.configuration.step == .enterNew && viewModel.configuration.pinLength == nil {+ Button(action: {+ Task {+ await viewModel.submitPin()+ }+ }) {+ Text(String(localized: "pin_next", bundle: locBundle))+ .font(.system(size: 16, weight: .semibold))+ .foregroundColor(theme.primarySurfaceText)+ .frame(maxWidth: .infinity)+ .frame(height: 50)+ .background(+ RoundedRectangle(cornerRadius: 8)+ .fill(viewModel.canSubmit ? theme.primary : theme.primary.opacity(0.5))+ )+ }+ .disabled(!viewModel.canSubmit)+ .padding(.horizontal, 40)+ .padding(.bottom, 24)+ }++ Spacer()++ // Numpad+ PinNumpadView(+ theme: theme,+ onDigit: { digit in+ viewModel.addDigit(digit)+ },+ onBackspace: {+ viewModel.removeDigit()+ }+ )+ }+ .frame(width: geometry.size.width, height: geometry.size.height)+ .background(theme.background)+ .blur(radius: viewModel.isProcessing ? 2 : 0)+ .disabled(viewModel.isProcessing)++ // Loading overlay+ if viewModel.isProcessing {+ ZStack {+ Color.black.opacity(0.3)+ .ignoresSafeArea()++ ProgressView()+ .progressViewStyle(CircularProgressViewStyle(tint: theme.primary))+ .scaleEffect(1.5)+ .padding(24)+ .background(+ RoundedRectangle(cornerRadius: 16)+ .fill(theme.accentBackground)+ )+ .shadow(color: Color.black.opacity(0.2), radius: 10, x: 0, y: 4)+ }+ .transition(.opacity)+ }+ }+ }+ }++ private var theme: Theme {+ colorScheme == .dark ? Theme.dark : Theme.light+ }+}diff --git a/apps/mobile-app/ios/VaultUI/Auth/PinSetupViewModel.swift b/apps/mobile-app/ios/VaultUI/Auth/PinSetupViewModel.swiftnew file mode 100644index 000000000..ceeeef001--- /dev/null+++ b/apps/mobile-app/ios/VaultUI/Auth/PinSetupViewModel.swift@@ -0,0 +1,190 @@+import Foundation+import SwiftUI+import UIKit++private let locBundle = Bundle.vaultUI++/// Configuration for PIN setup flow+public struct PinSetupConfiguration {+ /// Current step in the setup process+ public enum Step {+ case enterNew+ case confirm+ }++ public let step: Step+ public let title: String+ public let subtitle: String+ public let pinLength: Int? // nil = variable length (4-8 digits)+ public let firstStepPin: String? // Pin from first step (used in confirm step)++ public init(step: Step, title: String, subtitle: String, pinLength: Int?, firstStepPin: String? = nil) {+ self.step = step+ self.title = title+ self.subtitle = subtitle+ self.pinLength = pinLength+ self.firstStepPin = firstStepPin+ }+}++/// ViewModel for PIN setup flow+@MainActor+public class PinSetupViewModel: ObservableObject {+ @Published public var pin: String = ""+ @Published public var error: String?+ @Published public var isProcessing: Bool = false+ @Published public var configuration: PinSetupConfiguration++ private let setupHandler: (String) async throws -> Void+ private let cancelHandler: () -> Void++ public init(+ setupHandler: @escaping (String) async throws -> Void,+ cancelHandler: @escaping () -> Void+ ) {+ self.setupHandler = setupHandler+ self.cancelHandler = cancelHandler++ // Start with first step+ self.configuration = PinSetupConfiguration(+ step: .enterNew,+ title: String(localized: "pin_setup_title", bundle: locBundle),+ subtitle: String(localized: "pin_setup_subtitle", bundle: locBundle),+ pinLength: nil // Variable length for first step+ )+ }++ public func addDigit(_ digit: String) {+ // Clear error when user starts typing again+ error = nil++ // Check if we've reached max length+ let maxLength = configuration.pinLength ?? 8 // Max 8 digits in setup mode+ if pin.count >= maxLength {+ return+ }++ pin += digit++ // Auto-submit when PIN reaches expected length (only for confirm step with fixed length)+ if configuration.step == .confirm,+ let expectedLength = configuration.pinLength,+ pin.count == expectedLength {+ // Small delay to show the last dot filled before submitting+ Task {+ try? await Task.sleep(nanoseconds: 100_000_000) // 100ms+ await submitPin()+ }+ }+ }++ public func removeDigit() {+ guard !pin.isEmpty else { return }+ pin.removeLast()+ error = nil+ }++ public func cancel() {+ cancelHandler()+ }++ public func submitPin() async {+ // Validate minimum length for setup mode+ if configuration.step == .enterNew && pin.count < 4 {+ return // Don't submit until at least 4 digits+ }++ isProcessing = true++ // Give UI time to update+ try? await Task.sleep(nanoseconds: 50_000_000) // 50ms++ switch configuration.step {+ case .enterNew:+ // Move to confirm step+ let pinLength = pin.count+ let firstStepPin = pin++ isProcessing = false++ // Update configuration for confirm step+ configuration = PinSetupConfiguration(+ step: .confirm,+ title: String(localized: "pin_confirm_title", bundle: locBundle),+ subtitle: String(localized: "pin_confirm_subtitle", bundle: locBundle),+ pinLength: pinLength, // Fix length for confirmation+ firstStepPin: firstStepPin+ )++ // Clear current PIN for confirmation entry+ pin = ""++ case .confirm:+ // Check if PINs match+ guard let firstPin = configuration.firstStepPin else {+ isProcessing = false+ self.error = String(localized: "pin_setup_error", bundle: locBundle)+ triggerErrorFeedback()+ return+ }++ if pin != firstPin {+ // PINs don't match - restart from beginning+ isProcessing = false+ self.error = String(localized: "pin_mismatch", bundle: locBundle)+ triggerErrorFeedback()++ // Wait to let user see the error message+ try? await Task.sleep(nanoseconds: 1_000_000_000) // 1 second++ // Restart from beginning+ configuration = PinSetupConfiguration(+ step: .enterNew,+ title: String(localized: "pin_setup_title", bundle: locBundle),+ subtitle: String(localized: "pin_setup_subtitle", bundle: locBundle),+ pinLength: nil+ )+ pin = ""+ error = nil+ return+ }++ // PINs match - setup the PIN+ do {+ try await setupHandler(pin)+ // Success - the handler will navigate away or complete the flow+ // Keep loading state active since we're navigating+ } catch {+ // Generic error fallback+ isProcessing = false+ self.error = String(localized: "pin_setup_failed", bundle: locBundle)+ triggerErrorFeedback()+ shakeAndClear()+ }+ }+ }++ /// Check if we can submit based on current state+ public var canSubmit: Bool {+ switch configuration.step {+ case .enterNew:+ return pin.count >= 4 && pin.count <= 8+ case .confirm:+ return pin.count == configuration.pinLength+ }+ }++ private func triggerErrorFeedback() {+ // Trigger haptic feedback for error+ let generator = UINotificationFeedbackGenerator()+ generator.notificationOccurred(.error)+ }++ private func shakeAndClear() {+ // Clear the PIN after a short delay to show error+ Task {+ try? await Task.sleep(nanoseconds: 500_000_000) // 500ms+ pin = ""+ }+ }+}diff --git a/apps/mobile-app/ios/VaultUI/Auth/PinUnlockView.swift b/apps/mobile-app/ios/VaultUI/Auth/PinUnlockView.swiftindex 3a497c992..5ecf39d75 100644--- a/apps/mobile-app/ios/VaultUI/Auth/PinUnlockView.swift+++ b/apps/mobile-app/ios/VaultUI/Auth/PinUnlockView.swift@@ -96,53 +96,15 @@ public struct PinUnlockView: View {Spacer()// Numpad- VStack(spacing: 12) {- // Row 1: 1-3- HStack(spacing: 12) {- ForEach(1...3, id: \.self) { num in- NumpadButton(value: "\(num)", theme: theme) {- viewModel.addDigit("\(num)")- }- }- }-- // Row 2: 4-6- HStack(spacing: 12) {- ForEach(4...6, id: \.self) { num in- NumpadButton(value: "\(num)", theme: theme) {- viewModel.addDigit("\(num)")- }- }- }-- // Row 3: 7-9- HStack(spacing: 12) {- ForEach(7...9, id: \.self) { num in- NumpadButton(value: "\(num)", theme: theme) {- viewModel.addDigit("\(num)")- }- }+ PinNumpadView(+ theme: theme,+ onDigit: { digit in+ viewModel.addDigit(digit)+ },+ onBackspace: {+ viewModel.removeDigit()}-- // Row 4: Empty, 0, Backspace- HStack(spacing: 12) {- // Empty space- Color.clear- .frame(height: 60)-- // 0 button- NumpadButton(value: "0", theme: theme) {- viewModel.addDigit("0")- }-- // Backspace button- NumpadButton(icon: "delete.left", theme: theme) {- viewModel.removeDigit()- }- }- }- .padding(.horizontal, 40)- .padding(.bottom, 40)+ )}.frame(width: geometry.size.width, height: geometry.size.height).background(theme.background)@@ -246,10 +208,11 @@ struct NumpadButtonStyle: ButtonStyle {// MARK: - Theme/// Theme colors matching the React Native app-struct Theme {+public struct Theme {let background: Colorlet text: Colorlet primary: Color+ let primarySurfaceText: Colorlet accentBackground: Colorlet accentBorder: Colorlet errorBorder: Color@@ -258,6 +221,7 @@ struct Theme {background: Color(UIColor.systemBackground),text: Color(UIColor.label),primary: ColorConstants.Light.primary,+ primarySurfaceText: Color.white,accentBackground: Color(UIColor.secondarySystemBackground),accentBorder: Color(UIColor.separator),errorBorder: Color.red@@ -267,6 +231,7 @@ struct Theme {background: Color(UIColor.systemBackground),text: Color(UIColor.label),primary: ColorConstants.Dark.primary,+ primarySurfaceText: Color.white,accentBackground: Color(UIColor.secondarySystemBackground),accentBorder: Color(UIColor.separator),errorBorder: Color.reddiff --git a/apps/mobile-app/ios/VaultUI/en.lproj/Localizable.strings b/apps/mobile-app/ios/VaultUI/en.lproj/Localizable.stringsindex 4c397d485..2ee2f1c71 100644Binary files a/apps/mobile-app/ios/VaultUI/en.lproj/Localizable.strings and b/apps/mobile-app/ios/VaultUI/en.lproj/Localizable.strings differ