Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Refactor sharing structure (#2159)
Leendert de Borst766ed89e5263
diff --git a/core/rust/src/lib.rs b/core/rust/src/lib.rsindex a582ad8e5..6017aad6b 100644--- a/core/rust/src/lib.rs+++ b/core/rust/src/lib.rs@@ -35,7 +35,7 @@ pub use vault_codec::{extract_bucket, generate_user_salt, unpack_payload, materialize_as_sqlite, pack_payload,validate_manifest, validate_data_bucket, BlobEntry,CanonicalizeInput, CanonicalizedManifest, CanonicalizedVault, CodecRecord, CodecTableData, DataBucket, Manifest,- ManifestEntry, MaterializeInput, MaterializedTables, SharedManifestSpec, ValidationResult,+ ManifestEntry, MaterializeInput, MaterializedTables, ManifestSpec, ValidationResult,};pub use vault_pruner::{prune_vault, PruneInput, PruneOutput, PruneStats,diff --git a/core/rust/src/vault_codec/canonicalize.rs b/core/rust/src/vault_codec/canonicalize.rsindex b4ecb11bf..e38a4241e 100644--- a/core/rust/src/vault_codec/canonicalize.rs+++ b/core/rust/src/vault_codec/canonicalize.rs@@ -18,19 +18,31 @@ use serde_json::json;use super::hash::salted_blob_hash;use super::scoped_assets::{normalize_logo_scope, reconcile_logo_references};-use super::manifest::{BlobEntry, CanonicalizeInput, CanonicalizedManifest, CanonicalizedVault, CodecOverflow, DataBucket, Manifest, CodecRecord};+use super::manifest::{BlobEntry, CanonicalizeInput, CanonicalizedManifest, CanonicalizedVault, CodecOverflow, DataBucket, Manifest, ManifestSpec, CodecRecord};use super::materialize::row_key;-use super::sharing::partition_for_sharing;+use super::sharing::partition_by_manifest;use super::types::{blob_spec_for, bucket_categories, bucket_category_for, is_skip_table, primary_key_for, OVERFLOW_TABLE, SCHEMA_VERSION};use crate::error::VaultResult;/// Canonicalize normalized tables into the split resources: the manifest, one data bucket per declared/// category (see [`BUCKET_TABLES`](super::types::BUCKET_TABLES)), and the content-addressed blob map.pub fn canonicalize_from_sqlite(input: CanonicalizeInput) -> VaultResult<CanonicalizedVault> {- // Every row is stamped with its owning manifest's id.- if input.root_manifest_id.is_empty() {- return Err(crate::error::VaultError::General("canonicalize requires rootManifestId".to_string()));+ /*+ * Exactly one manifest is the user's own. In the steady state that changes nothing about routing+ * — every row names its manifest — but a vault predating the `ManifestId` column has none, and+ * those rows are adopted here rather than dropped. See `ManifestSpec::is_root`.+ */+ let root_positions: Vec<usize> = input.manifests.iter().enumerate().filter(|(_, s)| s.is_root).map(|(i, _)| i).collect();+ let root_index = match root_positions.as_slice() {+ [index] => *index,+ [] => return Err(crate::error::VaultError::General("canonicalize input declares no root manifest".to_string())),+ _ => return Err(crate::error::VaultError::General(format!("canonicalize input declares {} root manifests, expected exactly one", root_positions.len()))),+ };+ if input.manifests[root_index].manifest_id.is_empty() {+ return Err(crate::error::VaultError::General("canonicalize requires a manifest id on the root manifest".to_string()));}+ let root_manifest_id = input.manifests[root_index].manifest_id.clone();+ let root_user_salt = input.manifests[root_index].user_salt.clone();// Collect every non-skip table into a name > rows map (row order preserved per table). Blob// extraction and bucket-splitting happen below.@@ -63,11 +75,15 @@ pub fn canonicalize_from_sqlite(input: CanonicalizeInput) -> VaultResult<Canonic*/let all_logos: Vec<CodecRecord> = all_tables.get("Logos").cloned().unwrap_or_default();- // Split each shared manifest's subtree into its own partition; `all_tables` keeps the root's rows.- let shared_partitions = partition_for_sharing(&mut all_tables, &input.shared_manifests, &all_logos, &input.root_manifest_id)?;+ /*+ * Route every row to the manifest that owns it; `all_tables` keeps what falls to the root. The+ * non-root specs are passed in their original order so the emitted list mirrors the input.+ */+ let other_specs: Vec<ManifestSpec> = input.manifests.iter().enumerate().filter(|(i, _)| *i != root_index).map(|(_, s)| s.clone()).collect();+ let partitions = partition_by_manifest(&mut all_tables, &other_specs, &all_logos, &root_manifest_id)?;- reconcile_logo_references(&mut all_tables, &input.root_manifest_id, &all_logos);- normalize_logo_scope(&mut all_tables, &input.root_manifest_id);+ reconcile_logo_references(&mut all_tables, &root_manifest_id, &all_logos);+ normalize_logo_scope(&mut all_tables, &root_manifest_id);let mut blobs: HashMap<String, BlobEntry> = HashMap::new();let mut manifest_tables: HashMap<String, Vec<CodecRecord>> = HashMap::new();@@ -90,7 +106,7 @@ pub fn canonicalize_from_sqlite(input: CanonicalizeInput) -> VaultResult<Canonic}// Manifest table: extract any blob column into the content-addressed map.- let out_rows = extract_table_blobs(&name, records, &input.user_salt, &mut blobs);+ let out_rows = extract_table_blobs(&name, records, &root_user_salt, &mut blobs);manifest_tables.insert(name, out_rows);}@@ -106,31 +122,40 @@ pub fn canonicalize_from_sqlite(input: CanonicalizeInput) -> VaultResult<Canonic}}+ let mut root_buckets: Vec<DataBucket> = bucketed+ .into_iter()+ .map(|(category, tables)| DataBucket::new(&root_manifest_id, category, tables))+ .collect();+ // Deterministic bucket order (HashMap iteration is unordered) so canonicalize is reproducible.+ root_buckets.sort_by(|a, b| a.category.cmp(&b.category));+// Start with the root manifest.- let mut manifests: Vec<CanonicalizedManifest> = Vec::with_capacity(1 + shared_partitions.len());+ let root_spec = &input.manifests[root_index];+ let mut manifests: Vec<CanonicalizedManifest> = Vec::with_capacity(1 + partitions.len());manifests.push(CanonicalizedManifest {manifest: Manifest {schema_version: SCHEMA_VERSION,migration_id: input.migration_id.clone(),- user_salt: input.user_salt,+ user_salt: root_user_salt,canonicalized_at: input.canonicalized_at.clone(),- manifest_id: input.root_manifest_id,- anchor_folder_id: None,+ manifest_id: root_manifest_id,+ name: root_spec.name.clone(),tables: manifest_tables,extra: HashMap::new(),},is_root: true,+ data_buckets: root_buckets,blobs,});- // Each shared partition becomes its own manifest, its blobs hashed with its own per-manifest salt.- for partition in shared_partitions {- let mut shared_blobs: HashMap<String, BlobEntry> = HashMap::new();- let shared_tables: HashMap<String, Vec<CodecRecord>> = partition+ // Each remaining partition becomes its own manifest, its blobs hashed with its own per-manifest salt.+ for partition in partitions {+ let mut partition_blobs: HashMap<String, BlobEntry> = HashMap::new();+ let partition_tables: HashMap<String, Vec<CodecRecord>> = partition.tables.into_iter().map(|(name, records)| {- let out_rows = extract_table_blobs(&name, records, &partition.user_salt, &mut shared_blobs);+ let out_rows = extract_table_blobs(&name, records, &partition.user_salt, &mut partition_blobs);(name, out_rows)}).collect();@@ -141,23 +166,17 @@ pub fn canonicalize_from_sqlite(input: CanonicalizeInput) -> VaultResult<Canonicuser_salt: partition.user_salt,canonicalized_at: input.canonicalized_at.clone(),manifest_id: partition.manifest_id,- anchor_folder_id: Some(partition.anchor_folder_id),- tables: shared_tables,+ name: partition.name,+ tables: partition_tables,extra: HashMap::new(),},is_root: false,- blobs: shared_blobs,+ data_buckets: Vec::new(),+ blobs: partition_blobs,});}- // Deterministic bucket order (HashMap iteration is unordered) so canonicalize is reproducible.- let mut data_buckets: Vec<DataBucket> = bucketed- .into_iter()- .map(|(category, tables)| DataBucket::new(category, tables))- .collect();- data_buckets.sort_by(|a, b| a.category.cmp(&b.category));-- Ok(CanonicalizedVault { manifests, data_buckets })+ Ok(CanonicalizedVault { manifests })}/// Extract `table`'s blob column (if it owns one) into `blobs`, returning the rewritten rows.@@ -235,7 +254,7 @@ fn remerge_overflow_columns(tables: &mut HashMap<String, Vec<CodecRecord>>, over/// unknown columns re-attach to this bucket's rows, and whole unknown tables recorded under this/// bucket's category are re-emitted, so a bucket-only push from an older client never drops a/// newer writer's data either.-pub fn extract_bucket(category: String, mut tables: HashMap<String, Vec<CodecRecord>>) -> DataBucket {+pub fn extract_bucket(manifest_id: String, category: String, mut tables: HashMap<String, Vec<CodecRecord>>) -> DataBucket {let overflow = tables.remove(OVERFLOW_TABLE).map(|records| CodecOverflow::from_table_records(&records)).unwrap_or_default();remerge_overflow_columns(&mut tables, &overflow);if let Some(ov_tables) = overflow.bucket_tables.get(&category) {@@ -243,5 +262,5 @@ pub fn extract_bucket(category: String, mut tables: HashMap<String, Vec<CodecRectables.entry(name.clone()).or_insert_with(|| rows.clone());}}- DataBucket::new(category, tables)+ DataBucket::new(manifest_id, category, tables)}diff --git a/core/rust/src/vault_codec/manifest.rs b/core/rust/src/vault_codec/manifest.rsindex a2f8712a4..75a268ec5 100644--- a/core/rust/src/vault_codec/manifest.rs+++ b/core/rust/src/vault_codec/manifest.rs@@ -24,10 +24,9 @@ pub struct Manifest {pub canonicalized_at: String,/// The server-side id of the manifest this snapshot belongs to.pub manifest_id: String,- /// The folder this shared manifest is anchored at (the root of the subtree it carries), or `None`- /// for the root manifest.+ /// Display name of the manifest, carried inside the encrypted payload so the server never sees it.#[serde(default, skip_serializing_if = "Option::is_none")]- pub anchor_folder_id: Option<String>,+ pub name: Option<String>,/// Tables mapped to arrays of row objects. Blob columns replaced with `{ "__blobRef", "__blobKind" }`.pub tables: HashMap<String, Vec<CodecRecord>>,/// Forward-compat: unknown top-level keys preserved on round-trip.@@ -35,13 +34,16 @@ pub struct Manifest {pub extra: HashMap<String, serde_json::Value>,}-/// One data bucket: a slice of the vault kept OUT of the manifest so it can sync on its own server-/// revision without rewriting the manifest. `category` mirrors the server `VaultDataBucketCategory`-/// (e.g. "Settings"). `tables` holds the bucket's tables (name > rows).+/// One data bucket: a slice of one manifest kept OUT of the manifest blob so it can sync on its own+/// server revision without rewriting the manifest. `category` mirrors the server+/// `VaultDataBucketCategory` (e.g. "Settings"). `tables` holds the bucket's tables (name > rows).#[derive(Debug, Clone, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct DataBucket {pub schema_version: u32,+ /// The manifest this bucket belongs to.+ #[serde(default)]+ pub manifest_id: String,pub category: String,pub tables: HashMap<String, Vec<CodecRecord>>,#[serde(flatten)]@@ -49,10 +51,11 @@ pub struct DataBucket {}impl DataBucket {- /// Build a data bucket for `category` from its already-normalized tables (name > rows).- pub fn new(category: impl Into<String>, tables: HashMap<String, Vec<CodecRecord>>) -> Self {+ /// Build a data bucket for `category`, owned by `manifest_id`, from its already-normalized tables.+ pub fn new(manifest_id: impl Into<String>, category: impl Into<String>, tables: HashMap<String, Vec<CodecRecord>>) -> Self {Self {schema_version: SCHEMA_VERSION,+ manifest_id: manifest_id.into(),category: category.into(),tables,extra: HashMap::new(),@@ -77,38 +80,64 @@ pub struct BlobEntry {pub bytes_base64: String,}-/// Identifies one shared manifest for the canonicalize split: the manifest id, the anchor folder-/// whose subtree is written into it, and the per-manifest salt used for that manifest's blob hashing.+/// One manifest the caller wants canonicalize to emit. Every manifest in the vault gets a spec,+/// root included: they are the same kind of thing and are described the same way.#[derive(Debug, Clone, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]-pub struct SharedManifestSpec {+pub struct ManifestSpec {pub manifest_id: String,- pub anchor_folder_id: String,+ /// Per-manifest salt for this manifest's blob hashing.pub user_salt: String,+ /// Display name written into the manifest. See [`Manifest::name`].+ #[serde(default)]+ pub name: Option<String>,+ /// Marks the user's own manifest. Exactly one spec may set it. It is a property of the *user's*+ /// relationship to the manifest, not a structural role: the codec treats every manifest as the+ /// same kind of namespace, and clients read the flag back from `Manifests.IsRoot` to decide+ /// which manifest new rows go into and whose settings are theirs.+ ///+ /// The codec itself uses it in exactly two places:+ /// - its `Logos` table doubles as the local favicon cache, so unreferenced rows are kept rather+ /// than pruned (a product rule about the user's own vault, permanent);+ /// - it adopts rows carrying no `ManifestId` stamp (TRANSITIONAL, see below).+ ///+ /// There is no residual set in the steady state: every row names its manifest, and materialize+ /// stamps every row it writes, so any vault that has been materialized once is fully stamped.+ /// Unstamped rows appear only on the one-shot legacy conversion, where a vault predating the+ /// `ManifestId` column is canonicalized for the first time. Once that conversion backfills the+ /// stamps itself, an unstamped row becomes a validation error and this clause goes away —+ /// leaving `is_root` as pure client-facing bookkeeping.+ #[serde(default)]+ pub is_root: bool,}-/// One manifest produced by canonicalize.+/// One manifest produced by canonicalize: the manifest blob, the buckets that sync beside it, and+/// the blob map hashed with its own salt. Shaped as a superset of [`ManifestEntry`], so a+/// canonicalize result feeds straight back into [`MaterializeInput`] with no per-manifest mapping.#[derive(Debug, Clone, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct CanonicalizedManifest {pub manifest: Manifest,pub is_root: bool,+ /// The buckets this manifest owns, one per category it carries rows for.+ #[serde(default)]+ pub data_buckets: Vec<DataBucket>,/// hash > blob plaintext (base64), hashed with this manifest's salt.pub blobs: HashMap<String, BlobEntry>,}-/// Result of canonicalizing a vault.+/// Result of canonicalizing a vault: one entry per manifest, in the order the specs were given.#[derive(Debug, Clone, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct CanonicalizedVault {pub manifests: Vec<CanonicalizedManifest>,- pub data_buckets: Vec<DataBucket>,}impl CanonicalizedVault {- /// The vault's root manifest. Canonicalize always emits exactly one, first in `manifests`.+ /// The manifest flagged as root. Canonicalize refuses input that does not declare exactly one,+ /// so a result always has it.pub fn root(&self) -> &CanonicalizedManifest {- self.manifests.iter().find(|m| m.is_root).expect("canonicalize always emits exactly one root manifest")+ self.manifests.iter().find(|m| m.is_root).expect("canonicalize rejects input without exactly one root manifest")}/// The non-root manifests, in the order their specs were passed to canonicalize.@@ -118,7 +147,10 @@ impl CanonicalizedVault {/// Every manifest as a [`ManifestEntry`], ready to hand back to [`crate::vault_codec::materialize_as_sqlite`].pub fn manifest_entries(&self) -> Vec<ManifestEntry> {- self.manifests.iter().map(|m| ManifestEntry { manifest: m.manifest.clone(), is_root: m.is_root }).collect()+ self.manifests+ .iter()+ .map(|m| ManifestEntry { manifest: m.manifest.clone(), is_root: m.is_root, data_buckets: m.data_buckets.clone() })+ .collect()}}@@ -199,33 +231,33 @@ pub struct CanonicalizeInput {/// [`OVERFLOW_TABLE`](super::types::OVERFLOW_TABLE) row written by the last materialize, its overflow/// (a newer writer's tables/columns this schema can't hold) is re-merged automatically.pub tables: Vec<CodecTableData>,- pub user_salt: String,pub migration_id: String,pub canonicalized_at: String,- #[serde(default)]- pub root_manifest_id: String,- #[serde(default)]- pub shared_manifests: Vec<SharedManifestSpec>,+ /// Every manifest to emit, root included. Rows are routed to these by their `ManifestId` stamp;+ /// a row whose stamp matches no spec falls to the `is_root` one.+ pub manifests: Vec<ManifestSpec>,}-/// One manifest of a materialize input: the manifest itself plus whether it is the vault's root.+/// One manifest of a materialize input: the manifest, the buckets that belong to it, and whether it+/// is the vault's root (bookkeeping the clients read back; see [`ManifestSpec::is_root`]).#[derive(Debug, Clone, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct ManifestEntry {pub manifest: Manifest,#[serde(default)]pub is_root: bool,+ #[serde(default)]+ pub data_buckets: Vec<DataBucket>,}/// Input for [`crate::vault_codec::materialize_as_sqlite`].#[derive(Debug, Clone, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct MaterializeInput {- /// Every manifest making up the logical vault, root included. Exactly one entry must carry- /// `is_root`; the others are combined into it in list order.+ /// Every manifest making up the logical vault. They are combined in list order, so the caller+ /// puts its own manifest first: on a primary-key collision between two manifests the earlier one+ /// wins. At most one entry may carry `is_root`.pub manifests: Vec<ManifestEntry>,- #[serde(default)]- pub data_buckets: Vec<DataBucket>,/// The caller's local SQLite schema: table > column names. Rows are filtered down to what this/// schema can hold and the remainder lands in [`MaterializedTables::overflow`].pub schema_columns: HashMap<String, Vec<String>>,@@ -235,8 +267,8 @@ impl MaterializeInput {/// Build an input from a root manifest plus the non-root manifests combined into it.pub fn new(root: Manifest, others: Vec<Manifest>, data_buckets: Vec<DataBucket>, schema_columns: HashMap<String, Vec<String>>) -> Self {let mut manifests = Vec::with_capacity(1 + others.len());- manifests.push(ManifestEntry { manifest: root, is_root: true });- manifests.extend(others.into_iter().map(|manifest| ManifestEntry { manifest, is_root: false }));- Self { manifests, data_buckets, schema_columns }+ manifests.push(ManifestEntry { manifest: root, is_root: true, data_buckets });+ manifests.extend(others.into_iter().map(|manifest| ManifestEntry { manifest, is_root: false, data_buckets: Vec::new() }));+ Self { manifests, schema_columns }}}diff --git a/core/rust/src/vault_codec/materialize.rs b/core/rust/src/vault_codec/materialize.rsindex 38e0c6b9a..e4ce4b8a3 100644--- a/core/rust/src/vault_codec/materialize.rs+++ b/core/rust/src/vault_codec/materialize.rs@@ -19,16 +19,16 @@ use std::collections::{HashMap, HashSet};use serde_json::json;-use super::manifest::{CodecOverflow, CodecRecord, CodecTableData, Manifest, MaterializeInput, MaterializedTables};+use super::manifest::{CodecOverflow, CodecRecord, CodecTableData, DataBucket, Manifest, ManifestEntry, MaterializeInput, MaterializedTables};use super::types::{is_skip_table, primary_key_for, MANIFESTS_TABLE, OVERFLOW_TABLE};use crate::error::{VaultError, VaultResult};-/// Materialize the vault's manifests + data buckets into the table set the platform inserts. Every-/// manifest arrives in one list; the root one is pulled out and the rest are combined into its table-/// set, root-wins primary-key dedup, personal-table stripping, dangling-parent repair, and-/// per-manifest logo scoping.+/// Materialize the vault's manifests into the table set the platform inserts. Every manifest arrives+/// in one list, each carrying its own data buckets; they are combined into a single table set with+/// per-manifest logo scoping, key-scope filtering, and earlier-manifest-wins primary-key dedup.+/// Every manifest's buckets merge into the same local tables.pub fn materialize_as_sqlite(input: MaterializeInput) -> VaultResult<MaterializedTables> {- let MaterializeInput { mut manifests, data_buckets, schema_columns } = input;+ let MaterializeInput { mut manifests, schema_columns } = input;// Check for a non-empty schema.if schema_columns.is_empty() {@@ -43,10 +43,18 @@ pub fn materialize_as_sqlite(input: MaterializeInput) -> VaultResult<Materialize_ => return Err(VaultError::General(format!("materialize input carries {} root manifests, expected exactly one", root_positions.len()))),};+ /*+ * Every manifest's buckets are merged into the same local table set, so a category one manifest+ * owns privately and a category several manifests each contribute to (a shared last-used-at+ * bucket, say) land in one joined table the app queries without caring which namespace a row+ * came from. Collected before the root is split out so the order matches `manifests`.+ */+ let manifest_records = manifest_bookkeeping_records(&manifests);+ let data_buckets: Vec<DataBucket> = manifests.iter_mut().flat_map(|entry| std::mem::take(&mut entry.data_buckets)).collect();+let root = manifests.remove(root_index).manifest;let others: Vec<Manifest> = manifests.into_iter().map(|entry| entry.manifest).collect();- let manifest_records = manifest_bookkeeping_records(&root, &others);let root_manifest_id = root.manifest_id.clone();let migration_id = root.migration_id;let combined = super::sharing::combine_manifest_tables(root.tables, &root_manifest_id, others);@@ -100,23 +108,19 @@ pub fn materialize_as_sqlite(input: MaterializeInput) -> VaultResult<Materialize})}-/// One `Manifests` row per materialized manifest: `{ Id, IsRoot, AnchorFolderId }`.-fn manifest_bookkeeping_records(root: &Manifest, others: &[Manifest]) -> Vec<CodecRecord> {- let mut records: Vec<CodecRecord> = Vec::with_capacity(1 + others.len());- let mut push = |manifest: &Manifest, is_root: bool| {- let id = manifest.manifest_id.as_str();+/// One `Manifests` row per materialized manifest: `{ Id, IsRoot, Name }`.+fn manifest_bookkeeping_records(manifests: &[ManifestEntry]) -> Vec<CodecRecord> {+ let mut records: Vec<CodecRecord> = Vec::with_capacity(manifests.len());+ for entry in manifests {+ let id = entry.manifest.manifest_id.as_str();if id.is_empty() {- return;+ continue;}let mut row: CodecRecord = HashMap::new();row.insert("Id".to_string(), json!(id));- row.insert("IsRoot".to_string(), json!(if is_root { 1 } else { 0 }));- row.insert("AnchorFolderId".to_string(), manifest.anchor_folder_id.as_deref().map(|f| json!(f)).unwrap_or(serde_json::Value::Null));+ row.insert("IsRoot".to_string(), json!(if entry.is_root { 1 } else { 0 }));+ row.insert("Name".to_string(), entry.manifest.name.as_deref().map(|n| json!(n)).unwrap_or(serde_json::Value::Null));records.push(row);- };- push(root, true);- for manifest in others {- push(manifest, false);}records}diff --git a/core/rust/src/vault_codec/mod.rs b/core/rust/src/vault_codec/mod.rsindex 71a172062..aa34e9540 100644--- a/core/rust/src/vault_codec/mod.rs+++ b/core/rust/src/vault_codec/mod.rs@@ -26,7 +26,7 @@ use crate::error::{VaultError, VaultResult};pub use hash::{canonical_json, content_hash};pub use manifest::{BlobEntry, BucketLayoutEntry, CanonicalizeInput, CanonicalizedManifest, CanonicalizedVault, CodecOverflow, DataBucket,- Manifest, ManifestEntry, MaterializeInput, MaterializedTables, CodecRecord, CodecTableData, SharedManifestSpec,+ Manifest, ManifestEntry, MaterializeInput, MaterializedTables, CodecRecord, CodecTableData, ManifestSpec,};pub use scoped_assets::{KIND_BUILTIN as LOGO_KIND_BUILTIN, KIND_CUSTOM as LOGO_KIND_CUSTOM, KIND_FAVICON as LOGO_KIND_FAVICON};pub use sharing::{active_encryption_key, extract_encryption_key_for_public_key};@@ -50,11 +50,11 @@ pub fn materialize_as_sqlite(input: MaterializeInput) -> VaultResult<Materializematerialize::materialize_as_sqlite(input)}-/// Build a single data bucket for `category` from its tables (bucket-only push path). Include the-/// [`OVERFLOW_TABLE`] row in `tables` (read it alongside the bucket's tables) so a newer writer's-/// columns/tables re-merge and survive; it is consumed and never emitted into the bucket.-pub fn extract_bucket(category: String, tables: std::collections::HashMap<String, Vec<CodecRecord>>) -> DataBucket {- canonicalize::extract_bucket(category, tables)+/// Build the `category` data bucket owned by `manifest_id` from its tables (bucket-only push path).+/// Include the [`OVERFLOW_TABLE`] row in `tables` (read it alongside the bucket's tables) so a newer+/// writer's columns/tables re-merge and survive; it is consumed and never emitted into the bucket.+pub fn extract_bucket(manifest_id: String, category: String, tables: std::collections::HashMap<String, Vec<CodecRecord>>) -> DataBucket {+ canonicalize::extract_bucket(manifest_id, category, tables)}/// The bucket layout: every category and the tables it owns, in declaration order.@@ -212,16 +212,20 @@ pub fn materialize_as_sqlite_json(input_json: &str) -> VaultResult<String> {Ok(serde_json::to_string(&materialize_as_sqlite(input)?)?)}-/// JSON-string sibling of [`extract_bucket`]. Input: `{ "category": <str>, "tables": { <name>: [rows] } }`.+/// JSON-string sibling of [`extract_bucket`].+/// Input: `{ "manifestId": <str>, "category": <str>, "tables": { <name>: [rows] } }`.pub fn extract_bucket_json(input_json: &str) -> VaultResult<String> {#[derive(serde::Deserialize)]+ #[serde(rename_all = "camelCase")]struct Input {+ #[serde(default)]+ manifest_id: String,category: String,#[serde(default)]tables: std::collections::HashMap<String, Vec<CodecRecord>>,}let input: Input = serde_json::from_str(input_json)?;- Ok(serde_json::to_string(&extract_bucket(input.category, input.tables))?)+ Ok(serde_json::to_string(&extract_bucket(input.manifest_id, input.category, input.tables))?)}/// JSON-string sibling of [`bucket_layout`]. Output: `[{ "category": <str>, "tables": [<str>] }]`.diff --git a/core/rust/src/vault_codec/tests.rs b/core/rust/src/vault_codec/tests.rsindex 0db15fd84..fce8f2c53 100644--- a/core/rust/src/vault_codec/tests.rs+++ b/core/rust/src/vault_codec/tests.rs@@ -29,11 +29,14 @@ const ROOT_MANIFEST: &str = "00000000-0000-0000-0000-00000000r00t";fn basic_input(tables: Vec<CodecTableData>) -> CanonicalizeInput {CanonicalizeInput {tables,- user_salt: "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff".to_string(),migration_id: "20250101000000_Init".to_string(),canonicalized_at: "2026-01-01T00:00:00.000Z".to_string(),- root_manifest_id: ROOT_MANIFEST.to_string(),- shared_manifests: Vec::new(),+ manifests: vec![ManifestSpec {+ manifest_id: ROOT_MANIFEST.to_string(),+ user_salt: "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff".to_string(),+ name: None,+ is_root: true,+ }],}}@@ -128,6 +131,7 @@ fn inline_b64_columns_survive_roundtrip() {assert_eq!(cell["__b64"], json!(b64(&secret)));let re = materialize_as_sqlite(materialize_input(out.root().manifest.clone(), vec![], out.data_buckets)).unwrap();+ let re = materialize_as_sqlite(materialize_input(out.root().manifest.clone(), vec![], out.root().data_buckets.clone())).unwrap();let items = re.tables.iter().find(|t| t.name == "Items").unwrap();assert_eq!(items.records[0]["Secret"]["__b64"], json!(b64(&secret)));}@@ -141,6 +145,7 @@ fn materialize_as_sqlite_emits_settings_table_and_migration_id() {]);let out = canonicalize_from_sqlite(input).unwrap();let re = materialize_as_sqlite(materialize_input(out.root().manifest.clone(), vec![], out.data_buckets)).unwrap();+ let re = materialize_as_sqlite(materialize_input(out.root().manifest.clone(), vec![], out.root().data_buckets.clone())).unwrap();assert_eq!(re.migration_id, "20250101000000_Init");assert!(re.tables.iter().any(|t| t.name == "Settings" && t.records.len() == 1));assert!(re.tables.iter().any(|t| t.name == "Items"));@@ -175,6 +180,7 @@ fn full_roundtrip_with_blobs_is_semantically_equal() {assert_eq!(out.root().blobs.len(), 2);let re = materialize_as_sqlite(materialize_input(out.root().manifest.clone(), vec![], out.data_buckets.clone())).unwrap();+ let re = materialize_as_sqlite(materialize_input(out.root().manifest.clone(), vec![], out.root().data_buckets.clone())).unwrap();// Items/Logos/Attachments/Settings all present (skip tables aside).for name in ["Items", "Logos", "Attachments", "Settings"] {assert!(re.tables.iter().any(|t| t.name == name), "missing table {name}");@@ -453,6 +459,7 @@ fn materialize_splits_unknown_columns_into_overflow_table_and_canonicalize_remer.unwrap();let re = materialize_as_sqlite(MaterializeInput::new(out.root().manifest.clone(), vec![], out.data_buckets, old_client_schema())).unwrap();+ let re = materialize_as_sqlite(MaterializeInput::new(out.root().manifest.clone(), vec![], out.root().data_buckets.clone(), old_client_schema())).unwrap();let items = re.tables.iter().find(|t| t.name == "Items").unwrap();assert!(!items.records[0].contains_key("AliasEnabled"), "unknown column filtered out of the insert set");assert_eq!(items.records[0]["Name"], json!("GitHub"));diff --git a/core/rust/src/vault_codec/types.rs b/core/rust/src/vault_codec/types.rsindex 7aa1bbd93..d84045fa5 100644--- a/core/rust/src/vault_codec/types.rs+++ b/core/rust/src/vault_codec/types.rs@@ -44,7 +44,7 @@ pub const ENCRYPTION_KEYS_TABLE: &str = "EncryptionKeys";pub const MANIFEST_ID_COL: &str = "ManifestId";/// Local bookkeeping table materialize writes into the vault DB: one row per manifest this-/// vault is materialized from (`Id`, `IsRoot`, `AnchorFolderId`).+/// vault is materialized from (`Id`, `IsRoot`, `Name`).pub const MANIFESTS_TABLE: &str = "Manifests";/// Manifest / metadata schema version. This is the manifest *wire structure* version and is its owndiff --git a/core/rust/src/vault_codec/validate.rs b/core/rust/src/vault_codec/validate.rsindex a462b22b1..ad0634d02 100644--- a/core/rust/src/vault_codec/validate.rs+++ b/core/rust/src/vault_codec/validate.rs@@ -56,15 +56,12 @@ pub fn validate_manifest(manifest: &Manifest) -> ValidationResult {};}- // A shared manifest is readable by other users: it must never carry personal tables- // (key material, bucketed settings). See `types::is_personal_table`.- if manifest.anchor_folder_id.is_some() {- for name in manifest.tables.keys() {- if super::types::is_personal_table(name) && !manifest.tables[name].is_empty() {- failed.push("shared-manifest-carries-personal-table".to_string());- explain.push(format!("Shared manifest carries personal table {}", name));- break;- }+ // Bucketed tables sync as their own resource beside the manifest, so no manifest may carry them.+ for name in manifest.tables.keys() {+ if super::types::is_personal_table(name) && !manifest.tables[name].is_empty() {+ failed.push("manifest-carries-personal-table".to_string());+ explain.push(format!("Manifest carries personal table {}", name));+ break;}}diff --git a/core/rust/src/wasm.rs b/core/rust/src/wasm.rsindex cb9b3bc31..a22390624 100644--- a/core/rust/src/wasm.rs+++ b/core/rust/src/wasm.rs@@ -164,18 +164,21 @@ pub fn vault_codec_materialize_as_sqlite_js(input: JsValue) -> Result<JsValue, Jcodec_to_js(&output)}-/// Build a single data bucket. Input: `{ category, tables: { <name>: [rows] } }`.+/// Build a single data bucket. Input: `{ manifestId, category, tables: { <name>: [rows] } }`.#[wasm_bindgen(js_name = vaultCodecExtractBucket)]pub fn vault_codec_extract_bucket_js(input: JsValue) -> Result<JsValue, JsValue> {#[derive(serde::Deserialize)]+ #[serde(rename_all = "camelCase")]struct Input {+ #[serde(default)]+ manifest_id: String,category: String,#[serde(default)]tables: std::collections::HashMap<String, Vec<CodecRecord>>,}let input: Input = serde_wasm_bindgen::from_value(input).map_err(|e| JsValue::from_str(&format!("Failed to parse extract-bucket input: {}", e)))?;- codec_to_js(&vault_codec::extract_bucket(input.category, input.tables))+ codec_to_js(&vault_codec::extract_bucket(input.manifest_id, input.category, input.tables))}/// The bucket layout: `[{ category, tables: [<name>] }]`. Source of truth for platform bucket-only sync.diff --git a/core/vault/src/sql/SqlConstants.ts b/core/vault/src/sql/SqlConstants.tsindex b02fe0f3f..fe8c482fe 100644--- a/core/vault/src/sql/SqlConstants.ts+++ b/core/vault/src/sql/SqlConstants.ts@@ -1354,7 +1354,7 @@ ALTER TABLE "Folders" ADD "ManifestId" TEXT NULL;CREATE TABLE "Manifests" ("Id" TEXT NOT NULL CONSTRAINT "PK_Manifests" PRIMARY KEY,"IsRoot" INTEGER NOT NULL,- "AnchorFolderId" TEXT NULL+ "Name" TEXT NULL);INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")