Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Simplify multi-manifest vault upload to all go through the same endpoint (#2159)
Leendert de Borst79036fa0ffd7
diff --git a/apps/server/AliasVault.Api/Controllers/V2/SharingController.cs b/apps/server/AliasVault.Api/Controllers/V2/SharingController.csindex 70ec3f959..5c8fe3f8b 100644--- a/apps/server/AliasVault.Api/Controllers/V2/SharingController.cs+++ b/apps/server/AliasVault.Api/Controllers/V2/SharingController.cs@@ -277,79 +277,4 @@ public class SharingController(return Ok(response);}-- /// <summary>- /// Upload a new revision of a shared-folder manifest. Allowed for the owner and for every user holding a- /// <c>shared</c> grant on it. All members write the same manifest, guarded by the optimistic revision check- /// (a stale writer gets <see cref="VaultStatus.Outdated"/> and must re-pull + merge, like the root manifest).- /// Blob bytes are uploaded beforehand via <c>POST /v2/Vault/blobs</c> into the pusher's own store; the manifest- /// snapshot endpoints resolve referenced blobs across member stores.- /// </summary>- /// <param name="manifestId">The shared folder manifest id.</param>- /// <param name="model">The update request.</param>- /// <param name="clientHeader">The client identifier header.</param>- /// <returns>The update response.</returns>- [HttpPost("folders/{manifestId:guid}")]- public async Task<IActionResult> UpdateFolder(Guid manifestId, [FromBody] UpdateSharedFolderRequest model, [FromHeader(Name = "X-AliasVault-Client")] string? clientHeader)- {- await using var context = await dbContextFactory.CreateDbContextAsync();- var me = await GetCurrentUserAsync();- if (me == null)- {- return Unauthorized();- }-- var manifest = await context.VaultManifests.FirstOrDefaultAsync(x => x.ManifestId == manifestId && !x.IsRoot);- var canWrite = manifest != null && (manifest.OwnerUserId == me.Id || await context.VaultKeys.AnyAsync(k => k.UserId == me.Id && k.KeyType == AuthHelper.VaultKeyTypeShared && k.VaultManifestId == manifestId));- if (manifest == null || !canWrite)- {- return NotFound(ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.SHARED_MANIFEST_NOT_FOUND, 404));- }-- var newRevision = model.CurrentRevision + 1;- if (manifest.RevisionNumber >= newRevision)- {- return Ok(new UpdateSharedFolderResponse { Status = VaultStatus.Outdated, NewRevisionNumber = manifest.RevisionNumber });- }-- var strategy = context.Database.CreateExecutionStrategy();- return await strategy.ExecuteAsync<IActionResult>(async () =>- {- await using var tx = await context.Database.BeginTransactionAsync();-- // Referenced blob bytes must already exist in some member's store (uploaded via POST /v2/Vault/blobs).- if (model.BlobReferences.Count > 0)- {- var refHashes = model.BlobReferences.Select(r => r.Hash).Distinct().ToList();- var presentHashes = await context.VaultBlobObjects.Where(b => refHashes.Contains(b.Hash)).Select(b => b.Hash).Distinct().ToListAsync();- if (refHashes.Except(presentHashes).Any())- {- await tx.RollbackAsync();- return BadRequest(ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.VAULT_NOT_UP_TO_DATE, 400));- }- }-- // Archive the current revision, then update the row in place. TODO: apply a retention policy to- // shared-manifest history (currently only the root manifest history is pruned).- context.VaultManifestsHistory.Add(VaultManifestsHistory.CreateFrom(manifest));-- manifest.ManifestBlob = model.ManifestBlob;- manifest.ManifestCiphertextHash = model.ManifestCiphertextHash;- manifest.Version = model.Version;- manifest.RevisionNumber = newRevision;- manifest.FileSize = FileHelper.Base64StringToKilobytes(model.ManifestBlob);- manifest.Client = clientHeader;- manifest.UpdatedAt = timeProvider.UtcNow;-- foreach (var dto in model.BlobReferences)- {- context.VaultBlobReferences.Add(new VaultBlobReference { ManifestId = manifest.ManifestId, RevisionNumber = newRevision, BlobHash = dto.Hash });- }-- await context.SaveChangesAsync();- await tx.CommitAsync();-- return Ok(new UpdateSharedFolderResponse { Status = VaultStatus.Ok, NewRevisionNumber = newRevision });- });- }}diff --git a/apps/server/AliasVault.Api/Controllers/V2/VaultController.cs b/apps/server/AliasVault.Api/Controllers/V2/VaultController.csindex 7a46f2985..a78584400 100644--- a/apps/server/AliasVault.Api/Controllers/V2/VaultController.cs+++ b/apps/server/AliasVault.Api/Controllers/V2/VaultController.cs@@ -284,16 +284,15 @@ public class VaultController(}/// <summary>- /// Atomic upload. Inserts any new blobs, validates every referenced hash exists, archives the current manifest- /// revision into history, updates the current manifest row in place, adds blob references, optionally upserts- /// metadata, optionally syncs email routing, all in a single DB transaction on purpose.+ /// Unified atomic write. Applies any number of changed manifests (root and/or shared folders), changed data+ /// buckets, and new blobs in a single all-or-nothing DB transaction./// </summary>- /// <param name="model">Upload request DTO.</param>+ /// <param name="model">Vault write request DTO.</param>/// <param name="clientHeader">Client header.</param>- /// <returns>Upload response DTO.</returns>+ /// <returns>Vault write response DTO.</returns>[HttpPost("")]- public async Task<IActionResult> Upload(- [FromBody] UploadRequest model,+ public async Task<IActionResult> Write(+ [FromBody] VaultWriteRequest model,[FromHeader(Name = "X-AliasVault-Client")] string? clientHeader){await using var context = await dbContextFactory.CreateDbContextAsync();@@ -308,43 +307,84 @@ public class VaultController(return BadRequest(ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.USERNAME_MISMATCH, 400));}- // The v2 upload targets the user's root manifest. Registration guarantees a root manifest row exists.- var currentManifest = await context.VaultManifests.FirstOrDefaultAsync(x => x.OwnerUserId == user.Id && x.IsRoot);- if (currentManifest == null)+ // Each manifest and bucket may appear at most once.+ if (model.Manifests.Select(m => m.ManifestId).Distinct().Count() != model.Manifests.Count+ || model.Buckets.Select(b => b.Category).Distinct().Count() != model.Buckets.Count){- // No root manifest exists yet. TODO: test v2 registration flow to ensure this ensures a vault record always is created during registration.return BadRequest(ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.VAULT_NOT_UP_TO_DATE, 400));}- // Optimistic concurrency against the single monotonic RevisionNumber counter, which is shared across- // legacy ("sqlite-blob") and "manifest-v1" revisions. A migrating client sends the legacy revision it last- // synced as CurrentManifestRevision, so the first manifest-v1 revision continues the sequence (e.g. legacy- // 50 --> manifest-v1 51) rather than resetting to 1 and sorting below the legacy revisions.- var serverRevision = currentManifest.RevisionNumber;- var newManifestRevision = model.CurrentManifestRevision + 1;- if (serverRevision >= newManifestRevision)+ var rootWrite = model.Manifests.FirstOrDefault(m => m.ManifestId == null);++ // KEK/VEK migration (CreateVaultKey) is a full root push and only valid alongside a root manifest.+ var hasExistingVaultKey = await context.VaultKeys.AnyAsync(x => x.UserId == user.Id && x.KeyType == AuthHelper.VaultKeyTypePassword);+ if (model.CreateVaultKey != null && (rootWrite == null || model.CreateVaultKey.KeyType != AuthHelper.VaultKeyTypePassword)){- return Ok(new UploadResponse- {- Status = VaultStatus.Outdated,- NewManifestRevision = serverRevision,- });+ return BadRequest(ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.VAULT_KEY_NOT_FOUND, 400));}- // Sanity check if user already has a vault key (when providing vault key creation request).- var hasExistingVaultKey = await context.VaultKeys.AnyAsync(x => x.UserId == user.Id && x.KeyType == AuthHelper.VaultKeyTypePassword);if (model.CreateVaultKey != null && hasExistingVaultKey){return BadRequest(ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.VAULT_KEY_ALREADY_EXISTS, 400));}- // Sanity check that the user has a vault key (when not providing vault key creation request).+ // A root push from a not-yet-migrated user must carry CreateVaultKey.// TODO: remove this guard once every user has migrated to the KEK/VEK model (no keyless users remain).- if (model.CreateVaultKey == null && !hasExistingVaultKey)+ if (rootWrite != null && model.CreateVaultKey == null && !hasExistingVaultKey){return BadRequest(ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.VAULT_KEY_NOT_FOUND, 400));}+ // Resolve + authorize each manifest write to its stored row: a null ManifestId targets the caller's root+ // manifest (created at registration); a keyed write targets a non-root manifest the caller owns or holds a+ // shared grant on.+ var resolved = new List<(ManifestWrite Write, VaultManifest Row)>();+ foreach (var mw in model.Manifests)+ {+ if (mw.ManifestId == null)+ {+ var rootRow = await context.VaultManifests.FirstOrDefaultAsync(x => x.OwnerUserId == user.Id && x.IsRoot);+ if (rootRow == null)+ {+ return BadRequest(ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.VAULT_NOT_UP_TO_DATE, 400));+ }++ resolved.Add((mw, rootRow));+ continue;+ }++ var row = await context.VaultManifests.FirstOrDefaultAsync(x => x.ManifestId == mw.ManifestId && !x.IsRoot);+ var canWrite = row != null && (row.OwnerUserId == user.Id || await context.VaultKeys.AnyAsync(k => k.UserId == user.Id && k.KeyType == AuthHelper.VaultKeyTypeShared && k.VaultManifestId == mw.ManifestId));+ if (row == null || !canWrite)+ {+ return NotFound(ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.SHARED_MANIFEST_NOT_FOUND, 404));+ }++ resolved.Add((mw, row));+ }++ // All-or-nothing revision gate: every manifest and bucket must be exactly one ahead of the server's current.+ // On any staleness, reject the whole write with Outdated and hand back the current revisions to pull/merge.+ var bucketCurrentRevisions = new Dictionary<VaultDataBucketCategory, long>();+ foreach (var bw in model.Buckets)+ {+ bucketCurrentRevisions[bw.Category] = await context.VaultDataBuckets+ .Where(x => x.OwnerUserId == user.Id && x.Category == bw.Category)+ .MaxAsync(x => (long?)x.RevisionNumber) ?? 0;+ }++ var manifestStale = resolved.Any(r => r.Row.RevisionNumber >= r.Write.CurrentRevision + 1);+ var bucketStale = model.Buckets.Any(b => bucketCurrentRevisions[b.Category] >= b.CurrentRevision + 1);+ if (manifestStale || bucketStale)+ {+ return Ok(new VaultWriteResponse+ {+ Status = VaultStatus.Outdated,+ ManifestRevisions = resolved.Select(r => new ManifestWriteResult { ManifestId = r.Write.ManifestId, Revision = r.Row.RevisionNumber }).ToList(),+ BucketRevisions = model.Buckets.Select(b => new BucketRevision { Category = b.Category, Revision = bucketCurrentRevisions[b.Category] }).ToList(),+ });+ }+// The DbContext uses a retrying execution strategy (EnableRetryOnFailure), which forbids user-initiated// transactions unless the whole unit runs inside the strategy so it can be retried atomically.var strategy = context.Database.CreateExecutionStrategy();@@ -357,96 +397,116 @@ public class VaultController({if (!await TryUpsertBlobObjectsAsync(context, user.Id, model.NewBlobs, overwrite: model.CreateVaultKey != null)){+ await tx.RollbackAsync();return BadRequest(ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.VAULT_NOT_UP_TO_DATE, 400));}await context.SaveChangesAsync();}- // 2) Validate every referenced hash exists for this user. If any missing, abort and tell the client which.- if (model.BlobReferences.Count > 0)+ // 2) Validate every referenced hash exists.+ var ownScopeHashes = resolved.Where(r => r.Write.ManifestId == null).SelectMany(r => r.Write.BlobReferences).Select(br => br.Hash).Distinct().ToList();+ var anyScopeHashes = resolved.Where(r => r.Write.ManifestId != null).SelectMany(r => r.Write.BlobReferences).Select(br => br.Hash).Distinct().ToList();+ var missing = new List<string>();+ if (ownScopeHashes.Count > 0){- var refHashes = model.BlobReferences.Select(r => r.Hash).Distinct().ToList();- var presentHashes = await context.VaultBlobObjects- .Where(b => b.OwnerUserId == user.Id && refHashes.Contains(b.Hash))- .Select(b => b.Hash)- .ToListAsync();- var missing = refHashes.Except(presentHashes).ToList();- if (missing.Count > 0)- {- await tx.RollbackAsync();- return Ok(new UploadResponse- {- Status = VaultStatus.Ok,- NewManifestRevision = serverRevision,- MissingBlobHashes = missing,- });- }+ var present = await context.VaultBlobObjects.Where(b => b.OwnerUserId == user.Id && ownScopeHashes.Contains(b.Hash)).Select(b => b.Hash).ToListAsync();+ missing.AddRange(ownScopeHashes.Except(present));}- // 3) Archive the current revision into history first, then update the current row in place with the new manifest-v1 revision.- var archivedRevision = VaultManifestsHistory.CreateFrom(currentManifest);- context.VaultManifestsHistory.Add(archivedRevision);-- currentManifest.VaultBlob = string.Empty;- currentManifest.StorageFormat = ManifestFormat;- currentManifest.ManifestBlob = model.ManifestBlob;- currentManifest.ManifestCiphertextHash = model.ManifestCiphertextHash;- currentManifest.Version = model.Version;- currentManifest.RevisionNumber = newManifestRevision;- currentManifest.FileSize = FileHelper.Base64StringToKilobytes(model.ManifestBlob);- currentManifest.CredentialsCount = model.CredentialsCount;- currentManifest.EmailClaimsCount = model.EmailRouting.EmailAddressList.Count;- currentManifest.Client = clientHeader;- currentManifest.CreatedAt = timeProvider.UtcNow;- currentManifest.UpdatedAt = timeProvider.UtcNow;-- // Create VaultKey row atomically with this upload if provided (migration flow from old v1 encryption flow).- if (model.CreateVaultKey != null)+ if (anyScopeHashes.Count > 0){- if (model.CreateVaultKey.KeyType != AuthHelper.VaultKeyTypePassword)- {- await tx.RollbackAsync();- return BadRequest(ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.VAULT_KEY_NOT_FOUND, 400));- }+ var present = await context.VaultBlobObjects.Where(b => anyScopeHashes.Contains(b.Hash)).Select(b => b.Hash).Distinct().ToListAsync();+ missing.AddRange(anyScopeHashes.Except(present));+ }- context.VaultKeys.Add(new VaultKey+ missing = missing.Distinct().ToList();+ if (missing.Count > 0)+ {+ await tx.RollbackAsync();+ return Ok(new VaultWriteResponse{- Id = Guid.NewGuid(),- UserId = user.Id,- VaultManifestId = currentManifest.ManifestId,- KeyType = AuthHelper.VaultKeyTypePassword,- WrapScheme = AuthHelper.WrapSchemeAesGcmKek,- WrappedVek = model.CreateVaultKey.WrappedVek,- Salt = currentManifest.Salt,- Verifier = currentManifest.Verifier,- EncryptionType = currentManifest.EncryptionType,- EncryptionSettings = currentManifest.EncryptionSettings,- CreatedAt = timeProvider.UtcNow,- UpdatedAt = timeProvider.UtcNow,+ Status = VaultStatus.Ok,+ MissingBlobHashes = missing,+ ManifestRevisions = resolved.Select(r => new ManifestWriteResult { ManifestId = r.Write.ManifestId, Revision = r.Row.RevisionNumber }).ToList(),});+ }++ // 3) Apply each manifest: archive the current revision into history, update the row in place, run the+ // root-only side effects (email claims count + KEK/VEK key creation), and prune history per retention.+ var manifestResults = new List<ManifestWriteResult>();+ foreach (var (mw, row) in resolved)+ {+ var archivedRevision = VaultManifestsHistory.CreateFrom(row);+ context.VaultManifestsHistory.Add(archivedRevision);++ row.VaultBlob = string.Empty;+ row.StorageFormat = ManifestFormat;+ row.ManifestBlob = mw.ManifestBlob;+ row.ManifestCiphertextHash = mw.ManifestCiphertextHash;+ row.Version = mw.Version;+ row.RevisionNumber = mw.CurrentRevision + 1;+ row.FileSize = FileHelper.Base64StringToKilobytes(mw.ManifestBlob);+ row.CredentialsCount = mw.CredentialsCount;+ row.Client = clientHeader;+ row.UpdatedAt = timeProvider.UtcNow;++ if (row.IsRoot)+ {+ row.CreatedAt = timeProvider.UtcNow;+ if (model.EmailRouting != null)+ {+ row.EmailClaimsCount = model.EmailRouting.EmailAddressList.Count;+ }++ // Create the VaultKey row atomically with this write on the KEK/VEK migration (first push after the+ // client re-encrypted the vault under a fresh VEK). Move the SRP credentials off the manifest row.+ if (model.CreateVaultKey != null)+ {+ context.VaultKeys.Add(new VaultKey+ {+ Id = Guid.NewGuid(),+ UserId = user.Id,+ VaultManifestId = row.ManifestId,+ KeyType = AuthHelper.VaultKeyTypePassword,+ WrapScheme = AuthHelper.WrapSchemeAesGcmKek,+ WrappedVek = model.CreateVaultKey.WrappedVek,+ Salt = row.Salt,+ Verifier = row.Verifier,+ EncryptionType = row.EncryptionType,+ EncryptionSettings = row.EncryptionSettings,+ CreatedAt = timeProvider.UtcNow,+ UpdatedAt = timeProvider.UtcNow,+ });++ row.Salt = string.Empty;+ row.Verifier = string.Empty;+ row.EncryptionType = string.Empty;+ row.EncryptionSettings = string.Empty;+ }+ }- currentManifest.Salt = string.Empty;- currentManifest.Verifier = string.Empty;- currentManifest.EncryptionType = string.Empty;- currentManifest.EncryptionSettings = string.Empty;+ await ApplyVaultRetention(context, row, archivedRevision);+ manifestResults.Add(new ManifestWriteResult { ManifestId = mw.ManifestId, Revision = row.RevisionNumber });}- await ApplyVaultRetention(context, currentManifest, archivedRevision);await context.SaveChangesAsync();- // 4) Add blob references for the new revision.- foreach (var dto in model.BlobReferences)+ // 4) Add blob references for each manifest's new revision.+ foreach (var (mw, row) in resolved){- context.VaultBlobReferences.Add(new VaultBlobReference+ foreach (var dto in mw.BlobReferences){- ManifestId = currentManifest.ManifestId,- RevisionNumber = newManifestRevision,- BlobHash = dto.Hash,- });+ context.VaultBlobReferences.Add(new VaultBlobReference+ {+ ManifestId = row.ManifestId,+ RevisionNumber = row.RevisionNumber,+ BlobHash = dto.Hash,+ });+ }}- // 5) Optional data bucket upserts (settings, etc.). Each insert adds a new revision row (history).+ // 5) Data bucket upserts (settings, etc.). Each insert adds a new revision row (history).var newBucketRevisions = new List<BucketRevision>();foreach (var bucket in model.Buckets){@@ -455,12 +515,12 @@ public class VaultController(continue;}- var rev = await UpsertBucketAsync(context, user.Id, bucket.Category, bucket.Blob, bucket.CiphertextHash, currentRevision: null);+ var rev = await UpsertBucketAsync(context, user.Id, bucket.Category, bucket.Blob, bucket.CiphertextHash, bucket.CurrentRevision);newBucketRevisions.Add(new BucketRevision { Category = bucket.Category, Revision = rev });}- // 6) Email routing.- if (model.EmailRouting.EmailAddressList.Count > 0)+ // 6) Root-scoped email routing + public key.+ if (model.EmailRouting != null && model.EmailRouting.EmailAddressList.Count > 0){await UpdateUserEmailClaimsAsync(context, user, model.EmailRouting.EmailAddressList);}@@ -473,45 +533,15 @@ public class VaultController(await context.SaveChangesAsync();await tx.CommitAsync();- return Ok(new UploadResponse+ return Ok(new VaultWriteResponse{Status = VaultStatus.Ok,- NewManifestRevision = newManifestRevision,- NewBucketRevisions = newBucketRevisions,+ ManifestRevisions = manifestResults,+ BucketRevisions = newBucketRevisions,});});}- /// <summary>- /// Single data-bucket upload. For changes to one bucket kind (e.g. settings) that don't touch vault content.- /// </summary>- /// <param name="model">Bucket upload request.</param>- /// <returns>Bucket upload response.</returns>- [HttpPost("buckets")]- public async Task<IActionResult> UpdateBucket([FromBody] BucketUploadRequest model)- {- await using var context = await dbContextFactory.CreateDbContextAsync();- var user = await GetCurrentUserAsync();- if (user == null)- {- return Unauthorized();- }-- var currentRev = await context.VaultDataBuckets- .Where(x => x.OwnerUserId == user.Id && x.Category == model.Category)- .MaxAsync(x => (long?)x.RevisionNumber) ?? 0;- var newRev = model.CurrentRevision + 1;- if (currentRev >= newRev)- {- return Ok(new BucketUploadResponse { Status = VaultStatus.Outdated, Category = model.Category, NewRevision = currentRev });- }-- var stored = await UpsertBucketAsync(context, user.Id, model.Category, model.BucketBlob, model.BucketCiphertextHash, model.CurrentRevision);- await context.SaveChangesAsync();-- return Ok(new BucketUploadResponse { Status = VaultStatus.Ok, Category = model.Category, NewRevision = stored });- }-/// <summary>/// Batch-upload encrypted blobs ahead of a manifest upload. Idempotent per blob on (hash, user): re-uploading/// an existing blob only bumps its LastReferencedAt so the GC grace period restarts. Clients chunk large blobdiff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Sharing/UpdateSharedFolderRequest.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Sharing/UpdateSharedFolderRequest.csdeleted file mode 100644index 1b7d53837..000000000--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Sharing/UpdateSharedFolderRequest.cs+++ /dev/null@@ -1,33 +0,0 @@-//------------------------------------------------------------------------// <copyright file="UpdateSharedFolderRequest.cs" company="aliasvault">-// Copyright (c) aliasvault. All rights reserved.-// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.-// </copyright>-//-------------------------------------------------------------------------namespace AliasVault.Shared.Models.WebApi.V2.Sharing;--using AliasVault.Shared.Models.WebApi.V2.Vault;--/// <summary>-/// Request for POST /v2/Sharing/folders/{manifestId}. Uploads a new revision of a shared-folder manifest. Allowed-/// for the manifest owner and for every user holding a <c>shared</c> grant on it; concurrency is guarded by the-/// same optimistic revision check the root manifest upload uses.-/// </summary>-public class UpdateSharedFolderRequest-{- /// <summary>Gets or sets the encrypted folder manifest blob (AES-GCM ciphertext under the folder VEK, base64).</summary>- public required string ManifestBlob { get; set; }-- /// <summary>Gets or sets the SHA-256 (hex) of the manifest ciphertext, for storage-layer integrity verification.</summary>- public string? ManifestCiphertextHash { get; set; }-- /// <summary>Gets or sets the vault data model version string.</summary>- public required string Version { get; set; }-- /// <summary>Gets or sets the manifest revision the client last synced; the new revision must be exactly one above it.</summary>- public required long CurrentRevision { get; set; }-- /// <summary>Gets or sets the blob references of this manifest revision. Blob bytes are uploaded beforehand via POST /v2/Vault/blobs.</summary>- public List<BlobReference> BlobReferences { get; set; } = [];-}diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Sharing/UpdateSharedFolderResponse.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Sharing/UpdateSharedFolderResponse.csdeleted file mode 100644index afd2ff31c..000000000--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Sharing/UpdateSharedFolderResponse.cs+++ /dev/null@@ -1,22 +0,0 @@-//------------------------------------------------------------------------// <copyright file="UpdateSharedFolderResponse.cs" company="aliasvault">-// Copyright (c) aliasvault. All rights reserved.-// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.-// </copyright>-//-------------------------------------------------------------------------namespace AliasVault.Shared.Models.WebApi.V2.Sharing;--using AliasVault.Shared.Models.Enums;--/// <summary>-/// Response for POST /v2/Sharing/folders/{manifestId}.-/// </summary>-public class UpdateSharedFolderResponse-{- /// <summary>Gets or sets the outcome: Ok when stored, Outdated when the client's revision is stale (re-pull and merge).</summary>- public required VaultStatus Status { get; set; }-- /// <summary>Gets or sets the manifest's current server revision after this call.</summary>- public required long NewRevisionNumber { get; set; }-}diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/BucketUploadResponse.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/BucketUploadResponse.csdeleted file mode 100644index 117a5974e..000000000--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/BucketUploadResponse.cs+++ /dev/null@@ -1,25 +0,0 @@-//------------------------------------------------------------------------// <copyright file="BucketUploadResponse.cs" company="aliasvault">-// Copyright (c) aliasvault. All rights reserved.-// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.-// </copyright>-//-------------------------------------------------------------------------namespace AliasVault.Shared.Models.WebApi.V2.Vault;--using AliasVault.Shared.Models.Enums;--/// <summary>-/// Response for POST /v2/Vault/buckets.-/// </summary>-public class BucketUploadResponse-{- /// <summary>Gets or sets the status.</summary>- public required VaultStatus Status { get; set; }-- /// <summary>Gets or sets the bucket kind this response is for.</summary>- public required VaultDataBucketCategory Category { get; set; }-- /// <summary>Gets or sets the new revision for this bucket kind (or latest if Outdated).</summary>- public required long NewRevision { get; set; }-}diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/BucketUploadRequest.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/BucketWrite.cssimilarity index 63%rename from apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/BucketUploadRequest.csrename to apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/BucketWrite.csindex 1c6697305..1d082ab69 100644--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/BucketUploadRequest.cs+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/BucketWrite.cs@@ -1,5 +1,5 @@//------------------------------------------------------------------------// <copyright file="BucketUploadRequest.cs" company="aliasvault">+// <copyright file="BucketWrite.cs" company="aliasvault">// Copyright (c) aliasvault. All rights reserved.// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.// </copyright>@@ -8,19 +8,20 @@namespace AliasVault.Shared.Models.WebApi.V2.Vault;/// <summary>-/// POST /v2/Vault/buckets. Upload a single data bucket.+/// A single data bucket to write within a <see cref="VaultWriteRequest"/> batch. Carries the client's believed-current+/// revision so the bucket participates in the same optimistic all-or-nothing gate as the manifests./// </summary>-public class BucketUploadRequest+public class BucketWrite{/// <summary>Gets or sets the bucket kind discriminator.</summary>public required VaultDataBucketCategory Category { get; set; }/// <summary>Gets or sets the encrypted bucket blob (base64 of AES-GCM ciphertext).</summary>- public required string BucketBlob { get; set; }+ public required string Blob { get; set; }/// <summary>Gets or sets the SHA-256 (hex) of the bucket ciphertext.</summary>- public required string BucketCiphertextHash { get; set; }+ public required string CiphertextHash { get; set; }- /// <summary>Gets or sets the revision the client believes is current for this bucket kind.</summary>+ /// <summary>Gets or sets the revision the client believes is current for this bucket kind; the new revision must be exactly one above it.</summary>public required long CurrentRevision { get; set; }}diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/CreateVaultKeyRequest.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/CreateVaultKeyRequest.csindex ed1943e6d..cfcd03ec6 100644--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/CreateVaultKeyRequest.cs+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/CreateVaultKeyRequest.cs@@ -8,7 +8,7 @@namespace AliasVault.Shared.Models.WebApi.V2.Vault;/// <summary>-/// Vault key creation payload carried inside <see cref="UploadRequest"/> for the KEK/VEK migration.+/// Vault key creation payload carried inside <see cref="VaultWriteRequest"/> for the KEK/VEK migration./// TODO: remove this class once the legacy model is fully deprecated and upgrade path is no longer needed./// </summary>public class CreateVaultKeyRequestdiff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/ManifestWrite.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/ManifestWrite.csnew file mode 100644index 000000000..5760ebfae--- /dev/null+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/ManifestWrite.cs@@ -0,0 +1,36 @@+//-----------------------------------------------------------------------+// <copyright file="ManifestWrite.cs" company="aliasvault">+// Copyright (c) aliasvault. All rights reserved.+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.+// </copyright>+//-----------------------------------------------------------------------++namespace AliasVault.Shared.Models.WebApi.V2.Vault;++/// <summary>+/// A single manifest to write within a <see cref="VaultWriteRequest"/> batch.+/// </summary>+public class ManifestWrite+{+ /// <summary>Gets or sets the target manifest id.</summary>+ public Guid? ManifestId { get; set; }++ /// <summary>Gets or sets the encrypted manifest blob.</summary>+ public required string ManifestBlob { get; set; }++ /// <summary>Gets or sets the SHA-256 (hex) of the manifest ciphertext.</summary>+ public required string ManifestCiphertextHash { get; set; }++ /// <summary>Gets or sets the data-model version string (e.g. "2.0.0").</summary>+ public required string Version { get; set; }++ /// <summary>Gets or sets the revision the client last synced for this manifest; the new revision must be exactly one above it.</summary>+ public required long CurrentRevision { get; set; }++ /// <summary>Gets or sets the credentials count (anonymous size metric, copied to VaultManifest.CredentialsCount).</summary>+ public int CredentialsCount { get; set; }++ /// <summary>Gets or sets the complete list of blob hashes this manifest revision references. The server validates+ /// each exists (in the caller's store for the root manifest; in any member's store for a shared manifest) before committing.</summary>+ public List<BlobReference> BlobReferences { get; set; } = [];+}diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/ManifestWriteResult.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/ManifestWriteResult.csnew file mode 100644index 000000000..2b9345e35--- /dev/null+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/ManifestWriteResult.cs@@ -0,0 +1,20 @@+//-----------------------------------------------------------------------+// <copyright file="ManifestWriteResult.cs" company="aliasvault">+// Copyright (c) aliasvault. All rights reserved.+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.+// </copyright>+//-----------------------------------------------------------------------++namespace AliasVault.Shared.Models.WebApi.V2.Vault;++/// <summary>+/// Per-manifest result of a <see cref="VaultWriteRequest"/>.+/// </summary>+public class ManifestWriteResult+{+ /// <summary>Gets or sets the manifest id.</summary>+ public Guid? ManifestId { get; set; }++ /// <summary>Gets or sets the revision.</summary>+ public required long Revision { get; set; }+}diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/UploadRequest.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/UploadRequest.csdeleted file mode 100644index 59d77eee3..000000000--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/UploadRequest.cs+++ /dev/null@@ -1,55 +0,0 @@-//------------------------------------------------------------------------// <copyright file="UploadRequest.cs" company="aliasvault">-// Copyright (c) aliasvault. All rights reserved.-// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.-// </copyright>-//-------------------------------------------------------------------------namespace AliasVault.Shared.Models.WebApi.V2.Vault;--/// <summary>-/// Atomic upload payload for POST /v2/Vault. Single DB transaction: insert new blobs, validate references,-/// insert new Vaults row, replace blob references, apply retention.-/// </summary>-public class UploadRequest-{- /// <summary>Gets or sets the username (server cross-checks vs. auth session).</summary>- public required string Username { get; set; }-- /// <summary>Gets or sets the data-model version string (e.g. "2.0.0"). Reused from legacy v1 for now.</summary>- public required string Version { get; set; }-- /// <summary>Gets or sets the encrypted manifest blob (base64 of AES-GCM ciphertext).</summary>- public required string ManifestBlob { get; set; }-- /// <summary>Gets or sets the SHA-256 (hex) of the manifest ciphertext, computed by the client pre-upload.</summary>- public required string ManifestCiphertextHash { get; set; }-- /// <summary>Gets or sets the manifest revision the client believes is current (server rejects if not strictly +1 of latest).</summary>- public required long CurrentManifestRevision { get; set; }-- /// <summary>Gets or sets the credentials count (anonymous size metric, copied to Vaults.CredentialsCount).</summary>- public int CredentialsCount { get; set; }-- /// <summary>Gets or sets the data buckets (e.g. settings) to upsert alongside the manifest (optional). Each- /// bucket's revision is server-assigned; the client need not set <see cref="Bucket.Revision"/>.</summary>- public List<Bucket> Buckets { get; set; } = [];-- /// <summary>Gets or sets the new blob objects the client is uploading for this manifest.</summary>- public List<Blob> NewBlobs { get; set; } = [];-- /// <summary>Gets or sets the complete list of blob hashes the new manifest references. Server validates each- /// exists in VaultBlobObjects for this user before committing.</summary>- public List<BlobReference> BlobReferences { get; set; } = [];-- /// <summary>Gets or sets the email routing data to update server-side.</summary>- public EmailRouting EmailRouting { get; set; } = new();-- /// <summary>Gets or sets the public encryption key (server-side email encryption). Optional, preserved for legacy parity.</summary>- public string? EncryptionPublicKey { get; set; }-- /// <summary>Gets or sets the vault key creation request (KEK/VEK migration). Set on the first upload after the- /// client re-encrypted the vault with a freshly generated VEK; the server creates the VaultKey row atomically- /// with the upload and moves the SRP credentials from the root manifest onto it. Rejected when a key already exists.</summary>- public CreateVaultKeyRequest? CreateVaultKey { get; set; }-}diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/UploadResponse.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/UploadResponse.csdeleted file mode 100644index a331e6a2f..000000000--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/UploadResponse.cs+++ /dev/null@@ -1,29 +0,0 @@-//------------------------------------------------------------------------// <copyright file="UploadResponse.cs" company="aliasvault">-// Copyright (c) aliasvault. All rights reserved.-// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.-// </copyright>-//-------------------------------------------------------------------------namespace AliasVault.Shared.Models.WebApi.V2.Vault;--using AliasVault.Shared.Models.Enums;--/// <summary>-/// Response for POST /v2/Vault.-/// </summary>-public class UploadResponse-{- /// <summary>Gets or sets the status.</summary>- public required VaultStatus Status { get; set; }-- /// <summary>Gets or sets the new manifest revision number assigned by the server (or the latest if Outdated).</summary>- public required long NewManifestRevision { get; set; }-- /// <summary>Gets or sets the new revision for each uploaded data-bucket kind. Empty if none included.</summary>- public List<BucketRevision> NewBucketRevisions { get; set; } = [];-- /// <summary>Gets or sets blob hashes the client claimed in BlobReferences but the server didn't find. Client should- /// re-upload these in NewBlobs and retry.</summary>- public List<string> MissingBlobHashes { get; set; } = [];-}diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/VaultWriteRequest.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/VaultWriteRequest.csnew file mode 100644index 000000000..79e03bfb4--- /dev/null+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/VaultWriteRequest.cs@@ -0,0 +1,35 @@+//-----------------------------------------------------------------------+// <copyright file="VaultWriteRequest.cs" company="aliasvault">+// Copyright (c) aliasvault. All rights reserved.+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.+// </copyright>+//-----------------------------------------------------------------------++namespace AliasVault.Shared.Models.WebApi.V2.Vault;++/// <summary>+/// Unified atomic write for POST /v2/Vault.+/// </summary>+public class VaultWriteRequest+{+ /// <summary>Gets or sets the username.</summary>+ public required string Username { get; set; }++ /// <summary>Gets or sets the manifests to write.</summary>+ public List<ManifestWrite> Manifests { get; set; } = [];++ /// <summary>Gets or sets the data buckets to upsert.</summary>+ public List<BucketWrite> Buckets { get; set; } = [];++ /// <summary>Gets or sets the new blob objects the client is uploading for this write.</summary>+ public List<Blob> NewBlobs { get; set; } = [];++ /// <summary>Gets or sets the email routing data to update server-side.</summary>+ public EmailRouting? EmailRouting { get; set; }++ /// <summary>Gets or sets the public encryption key.</summary>+ public string? EncryptionPublicKey { get; set; }++ /// <summary>Gets or sets the vault key creation request.</summary>+ public CreateVaultKeyRequest? CreateVaultKey { get; set; }+}diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/VaultWriteResponse.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/VaultWriteResponse.csnew file mode 100644index 000000000..3f900dc41--- /dev/null+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/VaultWriteResponse.cs@@ -0,0 +1,28 @@+//-----------------------------------------------------------------------+// <copyright file="VaultWriteResponse.cs" company="aliasvault">+// Copyright (c) aliasvault. All rights reserved.+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.+// </copyright>+//-----------------------------------------------------------------------++namespace AliasVault.Shared.Models.WebApi.V2.Vault;++using AliasVault.Shared.Models.Enums;++/// <summary>+/// Response for POST /v2/Vault.+/// </summary>+public class VaultWriteResponse+{+ /// <summary>Gets or sets the overall status.</summary>+ public required VaultStatus Status { get; set; }++ /// <summary>Gets or sets the per-manifest revisions.</summary>+ public List<ManifestWriteResult> ManifestRevisions { get; set; } = [];++ /// <summary>Gets or sets the per-bucket revisions.</summary>+ public List<BucketRevision> BucketRevisions { get; set; } = [];++ /// <summary>Gets or sets blob hashes referenced but not found server-side.</summary>+ public List<string> MissingBlobHashes { get; set; } = [];+}