Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Merge branch 'main' into 2159-transform-core-data-storage-model-prerequisite-for-familyvault-sharing

Leendert de Borstdc34fa9d64f7
diff --cc apps/browser-extension/src/entrypoints/popup/pages/items/ItemAddEdit.tsx
index da4b62ea6,72d1772ac..abcd3d48b
--- a/apps/browser-extension/src/entrypoints/popup/pages/items/ItemAddEdit.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/pages/items/ItemAddEdit.tsx
@@@ -30,13 -29,12 +30,13 @@@ import useFormPersistence from '@/entry
import useServiceDetection from '@/entrypoints/popup/hooks/useServiceDetection';
import { useVaultMutate } from '@/entrypoints/popup/hooks/useVaultMutate';
- import { UsernameEmailGenerator, Gender } from '@/utils/dist/core/identity-generator';
-import type { Item, ItemField, ItemType, FieldType, Attachment, TotpCode, PasswordSettings } from '@/utils/dist/core/models/vault';
-import { FieldCategories, FieldTypes, ItemTypes, getSystemFieldsForItemType, getOptionalFieldsForItemType, isFieldShownByDefault, getSystemField, fieldAppliesToType } from '@/utils/dist/core/models/vault';
+import type { Item, ItemField, ItemType, FieldType, Attachment, TotpCode, PasswordSettings, LogoSelection } from '@/utils/dist/core/models/vault';
+import { FieldCategories, FieldTypes, LogoKinds, ItemTypes, getSystemFieldsForItemType, getOptionalFieldsForItemType, isFieldShownByDefault, getSystemField, fieldAppliesToType } from '@/utils/dist/core/models/vault';
import { FaviconService } from '@/utils/FaviconService';
import { LocalPreferencesService } from '@/utils/LocalPreferencesService';
import { sendMessage } from '@/utils/messaging/ExtensionMessaging';
+ import * as RustCore from '@/utils/RustCore';
+import SqliteClient from '@/utils/SqliteClient';
import { browser } from '#imports';
diff --cc core/rust/src/lib.rs
index d4f73efe4,be093b695..c7a0c2d9b
--- a/core/rust/src/lib.rs
+++ b/core/rust/src/lib.rs
@@@ -11,8 -14,9 +14,10 @@@
//! and calls this library for the core logic.
pub mod error;
+ mod hex;
+ mod rng;
pub mod vault_merge;
+pub mod vault_codec;
pub mod vault_pruner;
pub mod credential_matcher;
pub mod password_generator;
diff --cc core/rust/src/uniffi_api.rs
index bb0a6da6c,92b4f2d4f..e601eb71d
--- a/core/rust/src/uniffi_api.rs
+++ b/core/rust/src/uniffi_api.rs
@@@ -144,110 -148,58 +144,162 @@@ pub fn get_diceware_languages() -> Vec<
crate::password_generator::available_languages()
}
+ // ═══════════════════════════════════════════════════════════════════════════════
+ // Identity Generator Functions
+ // ═══════════════════════════════════════════════════════════════════════════════
+
+ /// Generate a random identity from a JSON-serialized request.
+ ///
+ /// The request accepts `language`, `gender` ("male"/"female"/"random"), `ageRange`
+ /// (e.g. "21-25" or "random") and/or explicit `birthdateOptions`.
+ ///
+ /// # Arguments
+ /// * `request_json` - JSON string, e.g. `{"language":"en","gender":"random","ageRange":"21-25"}`
+ ///
+ /// # Returns
+ /// The generated identity as a JSON string with camelCase fields:
+ /// `{"firstName":"...","lastName":"...","gender":"Male","birthDate":"1990-05-15","emailPrefix":"...","nickName":"..."}`
+ #[uniffi::export]
+ pub fn generate_identity(request_json: String) -> Result<String, VaultError> {
+ crate::identity_generator::generate_identity(&request_json)
+ }
+
+ /// Generate a username from a JSON-serialized name input
+ /// (`{"firstName":"...","lastName":"...","birthDate":"1990-05-15"}`).
+ #[uniffi::export]
+ pub fn generate_identity_username(input_json: String) -> Result<String, VaultError> {
+ crate::identity_generator::generate_username(&input_json)
+ }
+
+ /// Generate an email prefix from a JSON-serialized name input
+ /// (`{"firstName":"...","lastName":"...","birthDate":"1990-05-15"}`).
+ #[uniffi::export]
+ pub fn generate_identity_email_prefix(input_json: String) -> Result<String, VaultError> {
+ crate::identity_generator::generate_email_prefix(&input_json)
+ }
+
+ /// Generate a random alphanumeric email prefix that is not based on any identity.
+ #[uniffi::export]
+ pub fn generate_random_email_prefix(length: u32) -> String {
+ crate::identity_generator::generate_random_email_prefix(length)
+ }
+
+ /// Get the list of bundled identity dictionary language codes.
+ #[uniffi::export]
+ pub fn get_identity_languages() -> Vec<String> {
+ crate::identity_generator::available_languages()
+ }
+
+ /// Get the list of age range option values ("random" plus 5-year ranges).
+ #[uniffi::export]
+ pub fn get_identity_age_ranges() -> Vec<String> {
+ crate::identity_generator::available_age_ranges()
+ }
+
+// ═══════════════════════════════════════════════════════════════════════════════
+// Vault Codec Functions (manifest-v1 storage format) — JSON-string in/out.
+// ═══════════════════════════════════════════════════════════════════════════════
+
+/// Canonicalize normalized tables into manifest + metadata + blob map.
+/// Input: `CanonicalizeInput` JSON. Output: `CanonicalizedVault` JSON.
+#[uniffi::export]
+pub fn vault_codec_canonicalize_from_sqlite(input_json: String) -> Result<String, VaultError> {
+ crate::vault_codec::canonicalize_from_sqlite_json(&input_json)
+}
+
+/// Materialize manifest + metadata into the table set the platform inserts.
+/// Input: `MaterializeInput` JSON. Output: `MaterializedTables` JSON.
+#[uniffi::export]
+pub fn vault_codec_materialize_as_sqlite(input_json: String) -> Result<String, VaultError> {
+ crate::vault_codec::materialize_as_sqlite_json(&input_json)
+}
+
+/// Build a single data bucket. Input: `{ category, tables }` JSON. Output: `DataBucket` JSON.
+#[uniffi::export]
+pub fn vault_codec_extract_bucket(input_json: String) -> Result<String, VaultError> {
+ crate::vault_codec::extract_bucket_json(&input_json)
+}
+
+/// The bucket layout: `[{ category, tables: [<name>] }]` JSON. Source of truth for bucket-only sync.
+#[uniffi::export]
+pub fn vault_codec_bucket_layout() -> Result<String, VaultError> {
+ crate::vault_codec::bucket_layout_json()
+}
+
+/// Generate a fresh 32-byte per-user salt (lowercase hex).
+#[uniffi::export]
+pub fn vault_codec_generate_user_salt() -> String {
+ crate::vault_codec::generate_user_salt()
+}
+
+/// The `Logos.Id` to use for `source` inside the manifest scoped to `shared_folder_id` (`None` = the
+/// user's own root manifest). Every platform derives logo ids via this method to prevent duplicates.
+#[uniffi::export]
+pub fn vault_codec_logo_id_for_source(shared_folder_id: Option<String>, source: String) -> String {
+ crate::vault_codec::logo_id_for_source(shared_folder_id.as_deref(), &source)
+}
+
+/// The sha256 (lowercase hex) of an uploaded logo's bytes: the `Source` of a `custom` logo row, and
+/// what [`vault_codec_logo_id_for`] then derives the row id from.
+#[uniffi::export]
+pub fn vault_codec_logo_content_hash(bytes: Vec<u8>) -> String {
+ crate::vault_codec::logo_content_hash(&bytes)
+}
+
+/// The `Logos.Id` to use for the logo `(kind, source)` inside the manifest scoped to
+/// `shared_folder_id` (`None` = the user's own root manifest). `kind` is 'favicon' (source = domain),
+/// 'builtin' (source = catalog key) or 'custom' (source = image content hash).
+#[uniffi::export]
+pub fn vault_codec_logo_id_for(shared_folder_id: Option<String>, kind: String, source: String) -> String {
+ crate::vault_codec::logo_id_for(shared_folder_id.as_deref(), &kind, &source)
+}
+
+/// Pack a payload JSON string into gzip(envelope{contentHash, payload}). The caller encrypts the result.
+#[uniffi::export]
+pub fn vault_codec_pack_payload(payload_json: String) -> Result<Vec<u8>, VaultError> {
+ crate::vault_codec::pack_payload(&payload_json)
+}
+
+/// Unpack a (decrypted) payload: gunzip > verify content hash > return payload JSON string.
+#[uniffi::export]
+pub fn vault_codec_unpack_payload(plain_bytes: Vec<u8>) -> Result<String, VaultError> {
+ crate::vault_codec::unpack_payload(&plain_bytes)
+}
+
+/// Structurally validate a manifest. Input: `Manifest` JSON. Output: `ValidationResult` JSON.
+#[uniffi::export]
+pub fn vault_codec_validate_manifest(manifest_json: String) -> Result<String, VaultError> {
+ crate::vault_codec::validate_manifest_json(&manifest_json)
+}
+
+/// Validate a data bucket. Input: `DataBucket` JSON. Output: `ValidationResult` JSON.
+#[uniffi::export]
+pub fn vault_codec_validate_data_bucket(data_bucket_json: String) -> Result<String, VaultError> {
+ crate::vault_codec::validate_data_bucket_json(&data_bucket_json)
+}
+
+/// SHA-256 (lowercase hex) of a base64 ciphertext string.
+#[uniffi::export]
+pub fn vault_codec_compute_ciphertext_hash(base64_ciphertext: String) -> String {
+ crate::vault_codec::compute_ciphertext_hash(&base64_ciphertext)
+}
+
+/// Content fingerprint of a manifest / data-bucket payload JSON for change detection: SHA-256 (lowercase
+/// hex) of the canonical JSON, excluding the volatile `canonicalizedAt` timestamp.
+#[uniffi::export]
+pub fn vault_codec_compute_content_fingerprint(payload_json: String) -> String {
+ crate::vault_codec::compute_content_fingerprint(&payload_json)
+}
+
+/// Extract the encryption-key row whose `PublicKey` matches `public_key` from the decrypted `EncryptionKeys`
+/// data bucket. Input: `DataBucket` JSON + the target public key. Output: the matching row JSON object, or
+/// `null` when no live row carries that key. Chosen over the primary key so a shared-folder VEK wrapped for
+/// an older key still unwraps after key rotation.
+#[uniffi::export]
+pub fn vault_codec_extract_encryption_key_for_public_key_from_bucket(bucket_json: String, public_key: String) -> Result<String, VaultError> {
+ crate::vault_codec::extract_encryption_key_for_public_key_from_bucket_json(&bucket_json, &public_key)
+}
+
// ═══════════════════════════════════════════════════════════════════════════════
// SRP (Secure Remote Password) Functions
// ═══════════════════════════════════════════════════════════════════════════════