Move VaultConstants to VaultUtils shared project (#2006)

This commit is contained in:
Leendert de Borst
2026-05-12 20:15:32 +02:00
parent 065f5095f9
commit 3b052efead
14 changed files with 58 additions and 65 deletions

View File

@@ -12,7 +12,6 @@ import VaultUtils
extension CredentialProviderViewController: CredentialProviderDelegate {
// MARK: - CredentialProviderDelegate Implementation
func setupCredentialView(vaultStore: VaultStore, serviceUrl: String?) throws -> UIViewController {
// Create the ViewModel with injected behaviors
let viewModel = CredentialProviderViewModel(

View File

@@ -396,27 +396,14 @@ public class VaultManager: NSObject {
@objc
func getAutofillCopyTotpOnFill(_ resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock) {
guard let defaults = UserDefaults(suiteName: VaultConstants.userDefaultsSuite) else {
resolve(true)
return
}
// Default to true when key has never been written.
if defaults.object(forKey: VaultConstants.autofillCopyTotpOnFillKey) == nil {
resolve(true)
return
}
resolve(defaults.bool(forKey: VaultConstants.autofillCopyTotpOnFillKey))
resolve(AutofillSettings.shouldCopyTotpOnFill)
}
@objc
func setAutofillCopyTotpOnFill(_ enabled: Bool,
resolver resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock) {
guard let defaults = UserDefaults(suiteName: VaultConstants.userDefaultsSuite) else {
reject("AUTOFILL_SETTING_ERROR", "App Group UserDefaults unavailable", nil)
return
}
defaults.set(enabled, forKey: VaultConstants.autofillCopyTotpOnFillKey)
AutofillSettings.shouldCopyTotpOnFill = enabled
resolve(nil)
}

View File

@@ -1,34 +0,0 @@
import Foundation
import VaultModels
/// Constants used for userDefaults keys and other things.
public struct VaultConstants {
static let keychainService = "net.aliasvault.autofill"
static let keychainAccessGroup = "group.net.aliasvault.autofill"
public static let userDefaultsSuite = "group.net.aliasvault.autofill"
static let vaultMetadataKey = "aliasvault_vault_metadata"
static let encryptionKeyKey = "aliasvault_encryption_key"
static let encryptedDbFileName = "encrypted_db.sqlite"
static let authMethodsKey = "aliasvault_auth_methods"
static let autoLockTimeoutKey = "aliasvault_auto_lock_timeout"
static let encryptionKeyDerivationParamsKey = "aliasvault_encryption_key_derivation_params"
static let usernameKey = "aliasvault_username"
static let offlineModeKey = "aliasvault_offline_mode"
static let pinEnabledKey = "aliasvault_pin_enabled"
static let serverVersionKey = "aliasvault_server_version"
public static let autofillCopyTotpOnFillKey = "aliasvault_autofill_copy_totp_on_fill"
// Sync state keys (for offline sync and race detection)
static let isDirtyKey = "aliasvault_is_dirty"
static let mutationSequenceKey = "aliasvault_mutation_sequence"
static let isSyncingKey = "aliasvault_is_syncing"
static let defaultAutoLockTimeout: Int = 3600 // 1 hour in seconds
// Trash retention. Soft-deleted items stay in the recycle bin for this many
// days before the Rust pruner permanently removes them on the next sync.
// This value is declared in other places as well, make sure to update them
// when updating this value.
static let trashRetentionDays: Int = 30
}

View File

@@ -1,4 +1,5 @@
import Foundation
import VaultUtils
/**
* Native Swift WebAPI service for making HTTP requests to the AliasVault server.

View File

@@ -2,6 +2,7 @@ import Foundation
import LocalAuthentication
import Security
import VaultModels
import VaultUtils
/// Extension for the VaultStore class to handle authentication methods
extension VaultStore {

View File

@@ -1,5 +1,6 @@
import Foundation
import Security
import VaultUtils
/// Extension for the VaultStore class to handle cache management
extension VaultStore {

View File

@@ -3,6 +3,7 @@ import CryptoKit
import LocalAuthentication
import Security
import SignalArgon2
import VaultUtils
/// Extension for the VaultStore class to handle encryption/decryption
extension VaultStore {

View File

@@ -1,5 +1,6 @@
import Foundation
import SQLite
import VaultUtils
/// Extension for the VaultStore class to handle database management
extension VaultStore {

View File

@@ -1,5 +1,6 @@
import Foundation
import VaultModels
import VaultUtils
/// Extension for the VaultStore class to handle metadata management
extension VaultStore {

View File

@@ -1,5 +1,6 @@
import Foundation
import VaultModels
import VaultUtils
/// Vault upload model that matches the API contract
public struct VaultUpload: Codable {

View File

@@ -3,6 +3,7 @@ import CryptoKit
import Security
import SignalArgon2
import VaultModels
import VaultUtils
/// Extension for the VaultStore class to handle PIN unlock functionality
extension VaultStore {

View File

@@ -5,6 +5,7 @@ import CryptoKit
import CommonCrypto
import Security
import VaultModels
import VaultUtils
/// This class is used to store and retrieve the encrypted AliasVault database and encryption key.
/// It also handles executing queries against the SQLite database and biometric authentication.

View File

@@ -1,30 +1,28 @@
import Foundation
/// Read-only access to autofill-related preferences shared between the main app and
/// Read/write access to autofill-related preferences shared between the main app and
/// the iOS Autofill extension via the App Group UserDefaults suite.
///
/// The setter side lives in NativeVaultManager (main app target) and writes to the
/// same suite. Keys and the suite identifier must stay in sync with VaultConstants.
/// All underlying identifiers (suite name + key names) come from `VaultConstants`
/// so they are defined exactly once across the project.
public enum AutofillSettings {
/// App Group identifier must match `VaultConstants.userDefaultsSuite` and
/// the autofill entitlements.
private static let suiteName = "group.net.aliasvault.autofill"
/// Key must match `VaultConstants.autofillCopyTotpOnFillKey`.
private static let copyTotpOnFillKey = "aliasvault_autofill_copy_totp_on_fill"
private static var sharedDefaults: UserDefaults? {
UserDefaults(suiteName: suiteName)
UserDefaults(suiteName: VaultConstants.userDefaultsSuite)
}
/// Whether the autofill extension should copy a credential's current TOTP code to
/// the clipboard when the user selects it for autofill.
/// Defaults to `true` when the key has never been written.
public static var shouldCopyTotpOnFill: Bool {
guard let defaults = sharedDefaults else { return true }
if defaults.object(forKey: copyTotpOnFillKey) == nil {
return true
get {
guard let defaults = sharedDefaults else { return true }
if defaults.object(forKey: VaultConstants.autofillCopyTotpOnFillKey) == nil {
return true
}
return defaults.bool(forKey: VaultConstants.autofillCopyTotpOnFillKey)
}
set {
sharedDefaults?.set(newValue, forKey: VaultConstants.autofillCopyTotpOnFillKey)
}
return defaults.bool(forKey: copyTotpOnFillKey)
}
}

View File

@@ -0,0 +1,34 @@
import Foundation
/// Constants used for userDefaults keys, keychain identifiers, and other shared
/// identifiers across the app, autofill extension, and shared frameworks.
public struct VaultConstants {
public static let keychainService = "net.aliasvault.autofill"
public static let keychainAccessGroup = "group.net.aliasvault.autofill"
public static let userDefaultsSuite = "group.net.aliasvault.autofill"
public static let vaultMetadataKey = "aliasvault_vault_metadata"
public static let encryptionKeyKey = "aliasvault_encryption_key"
public static let encryptedDbFileName = "encrypted_db.sqlite"
public static let authMethodsKey = "aliasvault_auth_methods"
public static let autoLockTimeoutKey = "aliasvault_auto_lock_timeout"
public static let encryptionKeyDerivationParamsKey = "aliasvault_encryption_key_derivation_params"
public static let usernameKey = "aliasvault_username"
public static let offlineModeKey = "aliasvault_offline_mode"
public static let pinEnabledKey = "aliasvault_pin_enabled"
public static let serverVersionKey = "aliasvault_server_version"
public static let autofillCopyTotpOnFillKey = "aliasvault_autofill_copy_totp_on_fill"
// Sync state keys (for offline sync and race detection)
public static let isDirtyKey = "aliasvault_is_dirty"
public static let mutationSequenceKey = "aliasvault_mutation_sequence"
public static let isSyncingKey = "aliasvault_is_syncing"
public static let defaultAutoLockTimeout: Int = 3600 // 1 hour in seconds
// Trash retention. Soft-deleted items stay in the recycle bin for this many
// days before the Rust pruner permanently removes them on the next sync.
// This value is declared in other places as well, make sure to update them
// when updating this value.
public static let trashRetentionDays: Int = 30
}