Skip to content

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

Refactor ManifestKeyType and UnlockMethodType to string identifiers (#2159)

Leendert de Borstd6e120a738ec
diff --git a/apps/browser-extension/src/utils/dist/core/models/webapi/index.d.ts b/apps/browser-extension/src/utils/dist/core/models/webapi/index.d.ts
index ee57fe915..b8ffc588e 100644
--- a/apps/browser-extension/src/utils/dist/core/models/webapi/index.d.ts
+++ b/apps/browser-extension/src/utils/dist/core/models/webapi/index.d.ts
@@ -463,4 +463,72 @@ type VaultKeyGetResponse = {
vaultKey: VaultKeyResponse | null;
};
-export { type ApiErrorResponse, AuthEventType, type AuthLogModel, type BadRequestResponse, type DeleteAccountInitiateRequest, type DeleteAccountInitiateResponse, type DeleteAccountRequest, type Email, type EmailAttachment, type FaviconExtractModel, type LoginRequest, type LoginResponse, type MailboxBulkRequest, type MailboxBulkResponse, type MailboxEmail, type ManifestRevision, type MobileLoginInitiateRequest, type MobileLoginInitiateResponse, type MobileLoginPollResponse, type MobileLoginSubmitRequest, type PasswordChangeInitiateResponse, type RefreshToken, type StatusResponse, type StatusResponseV2, type TokenModel, type ValidateLoginRequest, type ValidateLoginRequest2Fa, type ValidateLoginResponse, type Vault, type VaultKeyGetResponse, type VaultKeyResponse, type VaultPasswordChangeRequest, type VaultPostResponse, type VaultResponse };
+/**
+ * <auto-generated />
+ * This file is auto-generated from core/models/scripts/generate-key-vocabulary.cjs.
+ * Do not edit this file directly. Run 'core/models/build.sh' (or 'node core/models/scripts/generate-key-vocabulary.cjs') to regenerate.
+ */
+/**
+ * Unlock methods a user can enroll. Each enrolled method stores one copy of the user's Account Key,
+ * encrypted with a KEK derived from that method's secret.
+ */
+declare const UnlockMethodType: {
+ /**
+ * Master password: the KEK is derived from the password via Argon2.
+ */
+ readonly Password: "password";
+};
+/**
+ * Type representing all valid UnlockMethodType tokens.
+ */
+type UnlockMethodTypeValue = typeof UnlockMethodType[keyof typeof UnlockMethodType];
+
+/**
+ * <auto-generated />
+ * This file is auto-generated from core/models/scripts/generate-key-vocabulary.cjs.
+ * Do not edit this file directly. Run 'core/models/build.sh' (or 'node core/models/scripts/generate-key-vocabulary.cjs') to regenerate.
+ */
+/**
+ * How one user's access to one manifest's VEK is protected. Every (user, manifest) access path is
+ * exactly one of these, and the token decides where the client looks for the key that opens the manifest.
+ */
+declare const ManifestKeyType: {
+ /**
+ * The VEK is encrypted with the user's own Account Key, which their unlock chain produces.
+ */
+ readonly AccountKey: "accountkey";
+ /**
+ * A grant: the VEK is encrypted to a public key of the user, so only its holder's private half can open it.
+ */
+ readonly GrantKey: "grantkey";
+};
+/**
+ * Type representing all valid ManifestKeyType tokens.
+ */
+type ManifestKeyTypeValue = typeof ManifestKeyType[keyof typeof ManifestKeyType];
+
+/**
+ * <auto-generated />
+ * This file is auto-generated from core/models/scripts/generate-key-vocabulary.cjs.
+ * Do not edit this file directly. Run 'core/models/build.sh' (or 'node core/models/scripts/generate-key-vocabulary.cjs') to regenerate.
+ */
+/**
+ * The algorithms a piece of vault key ciphertext can be encrypted with. The token travels next to every
+ * ciphertext, so a reader always knows how to open it without inferring anything from context.
+ */
+declare const VaultKeyAlgorithm: {
+ /**
+ * AES-256-GCM: symmetric, used where the reader already holds the wrapping key.
+ */
+ readonly Aes256Gcm: "aes256-gcm";
+ /**
+ * RSA-OAEP with SHA-256: asymmetric, used to encrypt a VEK to a recipient's public key.
+ */
+ readonly RsaOaepSha256: "rsa-oaep-sha256";
+};
+/**
+ * Type representing all valid VaultKeyAlgorithm tokens.
+ */
+type VaultKeyAlgorithmValue = typeof VaultKeyAlgorithm[keyof typeof VaultKeyAlgorithm];
+
+export { type ApiErrorResponse, AuthEventType, type AuthLogModel, type BadRequestResponse, type DeleteAccountInitiateRequest, type DeleteAccountInitiateResponse, type DeleteAccountRequest, type Email, type EmailAttachment, type FaviconExtractModel, type LoginRequest, type LoginResponse, type MailboxBulkRequest, type MailboxBulkResponse, type MailboxEmail, ManifestKeyType, type ManifestKeyTypeValue, type ManifestRevision, type MobileLoginInitiateRequest, type MobileLoginInitiateResponse, type MobileLoginPollResponse, type MobileLoginSubmitRequest, type PasswordChangeInitiateResponse, type RefreshToken, type StatusResponse, type StatusResponseV2, type TokenModel, UnlockMethodType, type UnlockMethodTypeValue, type ValidateLoginRequest, type ValidateLoginRequest2Fa, type ValidateLoginResponse, type Vault, VaultKeyAlgorithm, type VaultKeyAlgorithmValue, type VaultKeyGetResponse, type VaultKeyResponse, type VaultPasswordChangeRequest, type VaultPostResponse, type VaultResponse };
diff --git a/apps/browser-extension/src/utils/dist/core/models/webapi/index.js b/apps/browser-extension/src/utils/dist/core/models/webapi/index.js
index 332678d2f..5860e5256 100644
--- a/apps/browser-extension/src/utils/dist/core/models/webapi/index.js
+++ b/apps/browser-extension/src/utils/dist/core/models/webapi/index.js
@@ -18,4 +18,36 @@ var AuthEventType = /* @__PURE__ */ ((AuthEventType2) => {
return AuthEventType2;
})(AuthEventType || {});
-export { AuthEventType };
+// src/webapi/UnlockMethodType.ts
+var UnlockMethodType = {
+ /**
+ * Master password: the KEK is derived from the password via Argon2.
+ */
+ Password: "password"
+};
+
+// src/webapi/ManifestKeyType.ts
+var ManifestKeyType = {
+ /**
+ * The VEK is encrypted with the user's own Account Key, which their unlock chain produces.
+ */
+ AccountKey: "accountkey",
+ /**
+ * A grant: the VEK is encrypted to a public key of the user, so only its holder's private half can open it.
+ */
+ GrantKey: "grantkey"
+};
+
+// src/webapi/VaultKeyAlgorithm.ts
+var VaultKeyAlgorithm = {
+ /**
+ * AES-256-GCM: symmetric, used where the reader already holds the wrapping key.
+ */
+ Aes256Gcm: "aes256-gcm",
+ /**
+ * RSA-OAEP with SHA-256: asymmetric, used to encrypt a VEK to a recipient's public key.
+ */
+ RsaOaepSha256: "rsa-oaep-sha256"
+};
+
+export { AuthEventType, ManifestKeyType, UnlockMethodType, VaultKeyAlgorithm };
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/models/ManifestKeyType.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/models/ManifestKeyType.kt
new file mode 100644
index 000000000..4c302834a
--- /dev/null
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/models/ManifestKeyType.kt
@@ -0,0 +1,26 @@
+// <auto-generated />
+// This file is auto-generated from core/models/scripts/generate-key-vocabulary.cjs.
+// Do not edit this file directly. Run 'core/models/build.sh' (or 'node core/models/scripts/generate-key-vocabulary.cjs') to regenerate.
+
+package net.aliasvault.app.vaultstore.models
+
+/**
+ * How one user's access to one manifest's VEK is protected. Every (user, manifest) access path is
+ * exactly one of these, and the token decides where the client looks for the key that opens the manifest.
+ */
+object ManifestKeyType {
+ /**
+ * The VEK is encrypted with the user's own Account Key, which their unlock chain produces.
+ */
+ const val ACCOUNT_KEY = "accountkey"
+
+ /**
+ * A grant: the VEK is encrypted to a public key of the user, so only its holder's private half can open it.
+ */
+ const val GRANT_KEY = "grantkey"
+
+ /**
+ * All known ManifestKeyType tokens.
+ */
+ val all = listOf(ACCOUNT_KEY, GRANT_KEY)
+}
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/models/UnlockMethodType.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/models/UnlockMethodType.kt
new file mode 100644
index 000000000..486dbe47f
--- /dev/null
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/models/UnlockMethodType.kt
@@ -0,0 +1,21 @@
+// <auto-generated />
+// This file is auto-generated from core/models/scripts/generate-key-vocabulary.cjs.
+// Do not edit this file directly. Run 'core/models/build.sh' (or 'node core/models/scripts/generate-key-vocabulary.cjs') to regenerate.
+
+package net.aliasvault.app.vaultstore.models
+
+/**
+ * Unlock methods a user can enroll. Each enrolled method stores one copy of the user's Account Key,
+ * encrypted with a KEK derived from that method's secret.
+ */
+object UnlockMethodType {
+ /**
+ * Master password: the KEK is derived from the password via Argon2.
+ */
+ const val PASSWORD = "password"
+
+ /**
+ * All known UnlockMethodType tokens.
+ */
+ val all = listOf(PASSWORD)
+}
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/models/VaultKeyAlgorithm.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/models/VaultKeyAlgorithm.kt
new file mode 100644
index 000000000..db959e593
--- /dev/null
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/models/VaultKeyAlgorithm.kt
@@ -0,0 +1,26 @@
+// <auto-generated />
+// This file is auto-generated from core/models/scripts/generate-key-vocabulary.cjs.
+// Do not edit this file directly. Run 'core/models/build.sh' (or 'node core/models/scripts/generate-key-vocabulary.cjs') to regenerate.
+
+package net.aliasvault.app.vaultstore.models
+
+/**
+ * The algorithms a piece of vault key ciphertext can be encrypted with. The token travels next to every
+ * ciphertext, so a reader always knows how to open it without inferring anything from context.
+ */
+object VaultKeyAlgorithm {
+ /**
+ * AES-256-GCM: symmetric, used where the reader already holds the wrapping key.
+ */
+ const val AES256_GCM = "aes256-gcm"
+
+ /**
+ * RSA-OAEP with SHA-256: asymmetric, used to encrypt a VEK to a recipient's public key.
+ */
+ const val RSA_OAEP_SHA256 = "rsa-oaep-sha256"
+
+ /**
+ * All known VaultKeyAlgorithm tokens.
+ */
+ val all = listOf(AES256_GCM, RSA_OAEP_SHA256)
+}
diff --git a/apps/mobile-app/ios/VaultModels/ManifestKeyType.swift b/apps/mobile-app/ios/VaultModels/ManifestKeyType.swift
new file mode 100644
index 000000000..34848e4b4
--- /dev/null
+++ b/apps/mobile-app/ios/VaultModels/ManifestKeyType.swift
@@ -0,0 +1,18 @@
+// <auto-generated />
+// This file is auto-generated from core/models/scripts/generate-key-vocabulary.cjs.
+// Do not edit this file directly. Run 'core/models/build.sh' (or 'node core/models/scripts/generate-key-vocabulary.cjs') to regenerate.
+
+import Foundation
+
+/// How one user's access to one manifest's VEK is protected. Every (user, manifest) access path is
+/// exactly one of these, and the token decides where the client looks for the key that opens the manifest.
+public struct ManifestKeyType {
+ /// The VEK is encrypted with the user's own Account Key, which their unlock chain produces.
+ public static let accountKey = "accountkey"
+
+ /// A grant: the VEK is encrypted to a public key of the user, so only its holder's private half can open it.
+ public static let grantKey = "grantkey"
+
+ /// All known ManifestKeyType tokens.
+ public static let all = [accountKey, grantKey]
+}
diff --git a/apps/mobile-app/ios/VaultModels/UnlockMethodType.swift b/apps/mobile-app/ios/VaultModels/UnlockMethodType.swift
new file mode 100644
index 000000000..373f417d4
--- /dev/null
+++ b/apps/mobile-app/ios/VaultModels/UnlockMethodType.swift
@@ -0,0 +1,15 @@
+// <auto-generated />
+// This file is auto-generated from core/models/scripts/generate-key-vocabulary.cjs.
+// Do not edit this file directly. Run 'core/models/build.sh' (or 'node core/models/scripts/generate-key-vocabulary.cjs') to regenerate.
+
+import Foundation
+
+/// Unlock methods a user can enroll. Each enrolled method stores one copy of the user's Account Key,
+/// encrypted with a KEK derived from that method's secret.
+public struct UnlockMethodType {
+ /// Master password: the KEK is derived from the password via Argon2.
+ public static let password = "password"
+
+ /// All known UnlockMethodType tokens.
+ public static let all = [password]
+}
diff --git a/apps/mobile-app/ios/VaultModels/VaultKeyAlgorithm.swift b/apps/mobile-app/ios/VaultModels/VaultKeyAlgorithm.swift
new file mode 100644
index 000000000..95f499f83
--- /dev/null
+++ b/apps/mobile-app/ios/VaultModels/VaultKeyAlgorithm.swift
@@ -0,0 +1,18 @@
+// <auto-generated />
+// This file is auto-generated from core/models/scripts/generate-key-vocabulary.cjs.
+// Do not edit this file directly. Run 'core/models/build.sh' (or 'node core/models/scripts/generate-key-vocabulary.cjs') to regenerate.
+
+import Foundation
+
+/// The algorithms a piece of vault key ciphertext can be encrypted with. The token travels next to every
+/// ciphertext, so a reader always knows how to open it without inferring anything from context.
+public struct VaultKeyAlgorithm {
+ /// AES-256-GCM: symmetric, used where the reader already holds the wrapping key.
+ public static let aes256Gcm = "aes256-gcm"
+
+ /// RSA-OAEP with SHA-256: asymmetric, used to encrypt a VEK to a recipient's public key.
+ public static let rsaOaepSha256 = "rsa-oaep-sha256"
+
+ /// All known VaultKeyAlgorithm tokens.
+ public static let all = [aes256Gcm, rsaOaepSha256]
+}
diff --git a/apps/mobile-app/utils/dist/core/models/webapi/index.d.ts b/apps/mobile-app/utils/dist/core/models/webapi/index.d.ts
index ee57fe915..b8ffc588e 100644
--- a/apps/mobile-app/utils/dist/core/models/webapi/index.d.ts
+++ b/apps/mobile-app/utils/dist/core/models/webapi/index.d.ts
@@ -463,4 +463,72 @@ type VaultKeyGetResponse = {
vaultKey: VaultKeyResponse | null;
};
-export { type ApiErrorResponse, AuthEventType, type AuthLogModel, type BadRequestResponse, type DeleteAccountInitiateRequest, type DeleteAccountInitiateResponse, type DeleteAccountRequest, type Email, type EmailAttachment, type FaviconExtractModel, type LoginRequest, type LoginResponse, type MailboxBulkRequest, type MailboxBulkResponse, type MailboxEmail, type ManifestRevision, type MobileLoginInitiateRequest, type MobileLoginInitiateResponse, type MobileLoginPollResponse, type MobileLoginSubmitRequest, type PasswordChangeInitiateResponse, type RefreshToken, type StatusResponse, type StatusResponseV2, type TokenModel, type ValidateLoginRequest, type ValidateLoginRequest2Fa, type ValidateLoginResponse, type Vault, type VaultKeyGetResponse, type VaultKeyResponse, type VaultPasswordChangeRequest, type VaultPostResponse, type VaultResponse };
+/**
+ * <auto-generated />
+ * This file is auto-generated from core/models/scripts/generate-key-vocabulary.cjs.
+ * Do not edit this file directly. Run 'core/models/build.sh' (or 'node core/models/scripts/generate-key-vocabulary.cjs') to regenerate.
+ */
+/**
+ * Unlock methods a user can enroll. Each enrolled method stores one copy of the user's Account Key,
+ * encrypted with a KEK derived from that method's secret.
+ */
+declare const UnlockMethodType: {
+ /**
+ * Master password: the KEK is derived from the password via Argon2.
+ */
+ readonly Password: "password";
+};
+/**
+ * Type representing all valid UnlockMethodType tokens.
+ */
+type UnlockMethodTypeValue = typeof UnlockMethodType[keyof typeof UnlockMethodType];
+
+/**
+ * <auto-generated />
+ * This file is auto-generated from core/models/scripts/generate-key-vocabulary.cjs.
+ * Do not edit this file directly. Run 'core/models/build.sh' (or 'node core/models/scripts/generate-key-vocabulary.cjs') to regenerate.
+ */
+/**
+ * How one user's access to one manifest's VEK is protected. Every (user, manifest) access path is
+ * exactly one of these, and the token decides where the client looks for the key that opens the manifest.
+ */
+declare const ManifestKeyType: {
+ /**
+ * The VEK is encrypted with the user's own Account Key, which their unlock chain produces.
+ */
+ readonly AccountKey: "accountkey";
+ /**
+ * A grant: the VEK is encrypted to a public key of the user, so only its holder's private half can open it.
+ */
+ readonly GrantKey: "grantkey";
+};
+/**
+ * Type representing all valid ManifestKeyType tokens.
+ */
+type ManifestKeyTypeValue = typeof ManifestKeyType[keyof typeof ManifestKeyType];
+
+/**
+ * <auto-generated />
+ * This file is auto-generated from core/models/scripts/generate-key-vocabulary.cjs.
+ * Do not edit this file directly. Run 'core/models/build.sh' (or 'node core/models/scripts/generate-key-vocabulary.cjs') to regenerate.
+ */
+/**
+ * The algorithms a piece of vault key ciphertext can be encrypted with. The token travels next to every
+ * ciphertext, so a reader always knows how to open it without inferring anything from context.
+ */
+declare const VaultKeyAlgorithm: {
+ /**
+ * AES-256-GCM: symmetric, used where the reader already holds the wrapping key.
+ */
+ readonly Aes256Gcm: "aes256-gcm";
+ /**
+ * RSA-OAEP with SHA-256: asymmetric, used to encrypt a VEK to a recipient's public key.
+ */
+ readonly RsaOaepSha256: "rsa-oaep-sha256";
+};
+/**
+ * Type representing all valid VaultKeyAlgorithm tokens.
+ */
+type VaultKeyAlgorithmValue = typeof VaultKeyAlgorithm[keyof typeof VaultKeyAlgorithm];
+
+export { type ApiErrorResponse, AuthEventType, type AuthLogModel, type BadRequestResponse, type DeleteAccountInitiateRequest, type DeleteAccountInitiateResponse, type DeleteAccountRequest, type Email, type EmailAttachment, type FaviconExtractModel, type LoginRequest, type LoginResponse, type MailboxBulkRequest, type MailboxBulkResponse, type MailboxEmail, ManifestKeyType, type ManifestKeyTypeValue, type ManifestRevision, type MobileLoginInitiateRequest, type MobileLoginInitiateResponse, type MobileLoginPollResponse, type MobileLoginSubmitRequest, type PasswordChangeInitiateResponse, type RefreshToken, type StatusResponse, type StatusResponseV2, type TokenModel, UnlockMethodType, type UnlockMethodTypeValue, type ValidateLoginRequest, type ValidateLoginRequest2Fa, type ValidateLoginResponse, type Vault, VaultKeyAlgorithm, type VaultKeyAlgorithmValue, type VaultKeyGetResponse, type VaultKeyResponse, type VaultPasswordChangeRequest, type VaultPostResponse, type VaultResponse };
diff --git a/apps/mobile-app/utils/dist/core/models/webapi/index.js b/apps/mobile-app/utils/dist/core/models/webapi/index.js
index 332678d2f..5860e5256 100644
--- a/apps/mobile-app/utils/dist/core/models/webapi/index.js
+++ b/apps/mobile-app/utils/dist/core/models/webapi/index.js
@@ -18,4 +18,36 @@ var AuthEventType = /* @__PURE__ */ ((AuthEventType2) => {
return AuthEventType2;
})(AuthEventType || {});
-export { AuthEventType };
+// src/webapi/UnlockMethodType.ts
+var UnlockMethodType = {
+ /**
+ * Master password: the KEK is derived from the password via Argon2.
+ */
+ Password: "password"
+};
+
+// src/webapi/ManifestKeyType.ts
+var ManifestKeyType = {
+ /**
+ * The VEK is encrypted with the user's own Account Key, which their unlock chain produces.
+ */
+ AccountKey: "accountkey",
+ /**
+ * A grant: the VEK is encrypted to a public key of the user, so only its holder's private half can open it.
+ */
+ GrantKey: "grantkey"
+};
+
+// src/webapi/VaultKeyAlgorithm.ts
+var VaultKeyAlgorithm = {
+ /**
+ * AES-256-GCM: symmetric, used where the reader already holds the wrapping key.
+ */
+ Aes256Gcm: "aes256-gcm",
+ /**
+ * RSA-OAEP with SHA-256: asymmetric, used to encrypt a VEK to a recipient's public key.
+ */
+ RsaOaepSha256: "rsa-oaep-sha256"
+};
+
+export { AuthEventType, ManifestKeyType, UnlockMethodType, VaultKeyAlgorithm };
diff --git a/apps/server/AliasVault.Api/Controllers/V2/VaultController.cs b/apps/server/AliasVault.Api/Controllers/V2/VaultController.cs
index 98e6e2bc8..51ae06704 100644
--- a/apps/server/AliasVault.Api/Controllers/V2/VaultController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V2/VaultController.cs
@@ -147,7 +147,7 @@ public class VaultController(
accessKeysByManifest.TryGetValue(m.ManifestId, out var accessKey);
// An account-key row's ciphertext is not sent: the caller decrypted that VEK from their password chain before this call.
- var grant = accessKey != null && ManifestKeyTypes.CarriesEncryptedVek(accessKey.Type) ? accessKey : null;
+ var grant = accessKey != null && ManifestKeyTypes.VekTravelsWithManifest(accessKey.Type) ? accessKey : null;
return new Manifest
{
ManifestId = m.ManifestId,
@@ -220,7 +220,7 @@ public class VaultController(
// How this manifest's VEK reaches the caller.
var accessKey = (await GetAccessKeysAsync(context, user.Id, [latest.ManifestId])).GetValueOrDefault(latest.ManifestId);
manifest.KeyType = accessKey != null ? ManifestKeyTypes.ToToken(accessKey.Type) : null;
- if (accessKey != null && ManifestKeyTypes.CarriesEncryptedVek(accessKey.Type))
+ if (accessKey != null && ManifestKeyTypes.VekTravelsWithManifest(accessKey.Type))
{
manifest.EncryptedVek = accessKey.EncryptedVek;
manifest.Algorithm = VaultKeyAlgorithms.ToToken(accessKey.Algorithm);
diff --git a/apps/server/AliasVault.Api/Controllers/V2/VaultKeyController.cs b/apps/server/AliasVault.Api/Controllers/V2/VaultKeyController.cs
index 54462a274..eb81c14b6 100644
--- a/apps/server/AliasVault.Api/Controllers/V2/VaultKeyController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V2/VaultKeyController.cs
@@ -10,6 +10,7 @@ namespace AliasVault.Api.Controllers.V2;
using AliasServerDb;
using AliasVault.Api.Controllers.Abstracts;
using AliasVault.Api.Helpers;
+using AliasVault.Shared.Models.Enums;
using AliasVault.Shared.Models.WebApi.V2.Auth;
using Asp.Versioning;
using Microsoft.AspNetCore.Identity;
@@ -40,7 +41,7 @@ public class VaultKeyController(IAliasServerDbContextFactory dbContextFactory, U
}
// Check if the unlock method type is valid.
- if (!Enum.TryParse<UnlockMethodType>(type, true, out var parsedType) || !Enum.IsDefined(parsedType))
+ if (!UnlockMethodTypes.TryParse(type?.ToLowerInvariant(), out var parsedType))
{
return Ok(new VaultKeyGetResponse { VaultKey = null });
}
@@ -69,7 +70,7 @@ public class VaultKeyController(IAliasServerDbContextFactory dbContextFactory, U
{
VaultKey = new VaultKeyResponse
{
- Type = unlockKey.Type.ToString().ToLowerInvariant(),
+ Type = UnlockMethodTypes.ToToken(unlockKey.Type),
EncryptedAccountKey = unlockKey.EncryptedAccountKey,
EncryptedVek = encryptedVek,
AccountPublicKey = accountKeypair?.PublicKey,
diff --git a/apps/server/AliasVault.Api/Helpers/AuthHelper.cs b/apps/server/AliasVault.Api/Helpers/AuthHelper.cs
index fdf0b0597..d28fa353a 100644
--- a/apps/server/AliasVault.Api/Helpers/AuthHelper.cs
+++ b/apps/server/AliasVault.Api/Helpers/AuthHelper.cs
@@ -10,6 +10,7 @@ namespace AliasVault.Api.Helpers;
using AliasServerDb;
using AliasVault.Api.Headers;
using AliasVault.Cryptography.Client;
+using AliasVault.Shared.Models.Enums;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Memory;
using SecureRemotePassword;
diff --git a/apps/server/AliasVault.Api/Helpers/EmailAccessHelper.cs b/apps/server/AliasVault.Api/Helpers/EmailAccessHelper.cs
index 36d913fb5..6a8d9c515 100644
--- a/apps/server/AliasVault.Api/Helpers/EmailAccessHelper.cs
+++ b/apps/server/AliasVault.Api/Helpers/EmailAccessHelper.cs
@@ -8,6 +8,7 @@
namespace AliasVault.Api.Helpers;
using AliasServerDb;
+using AliasVault.Shared.Models.Enums;
using Microsoft.EntityFrameworkCore;
/// <summary>
diff --git a/apps/server/AliasVault.Api/Helpers/ManifestAccessHelper.cs b/apps/server/AliasVault.Api/Helpers/ManifestAccessHelper.cs
index 7c5038798..27bb0ddc0 100644
--- a/apps/server/AliasVault.Api/Helpers/ManifestAccessHelper.cs
+++ b/apps/server/AliasVault.Api/Helpers/ManifestAccessHelper.cs
@@ -8,6 +8,7 @@
namespace AliasVault.Api.Helpers;
using AliasServerDb;
+using AliasVault.Shared.Models.Enums;
/// <summary>
/// Helper for resolving which vault manifests a user can access.
diff --git a/apps/server/Databases/AliasServerDb/AliasServerDbContext.cs b/apps/server/Databases/AliasServerDb/AliasServerDbContext.cs
index da18802fa..4cf53d7cc 100644
--- a/apps/server/Databases/AliasServerDb/AliasServerDbContext.cs
+++ b/apps/server/Databases/AliasServerDb/AliasServerDbContext.cs
@@ -7,6 +7,7 @@
namespace AliasServerDb;
+using AliasVault.Shared.Models.Enums;
using AliasVault.WorkerStatus.Database;
using Microsoft.AspNetCore.DataProtection.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity;
@@ -372,6 +373,7 @@ public class AliasServerDbContext : WorkerStatusDbContext, IDataProtectionKeyCon
builder.HasIndex(e => new { e.UserId, e.Type, e.VaultManifestId }).IsUnique().HasDatabaseName("UX_VaultManifestAccessKeys_UserId_Type_Manifest");
builder.HasIndex(e => e.VaultManifestId).HasDatabaseName("IX_VaultManifestAccessKeys_VaultManifestId");
builder.Property(e => e.Metadata).HasColumnType("jsonb");
+ builder.Property(e => e.Type).HasConversion(v => ManifestKeyTypes.ToToken(v), v => ManifestKeyTypes.Parse(v));
builder.Property(e => e.Algorithm).HasConversion(v => VaultKeyAlgorithms.ToToken(v), v => VaultKeyAlgorithms.Parse(v));
builder.HasOne(e => e.UserGrantKey)
.WithMany()
@@ -389,6 +391,7 @@ public class AliasServerDbContext : WorkerStatusDbContext, IDataProtectionKeyCon
builder.HasIndex(e => new { e.UserId, e.Type }).IsUnique().HasDatabaseName("UX_UserUnlockKeys_UserId_Type");
builder.Property(e => e.Metadata).HasColumnType("jsonb");
+ builder.Property(e => e.Type).HasConversion(v => UnlockMethodTypes.ToToken(v), v => UnlockMethodTypes.Parse(v));
builder.Property(e => e.Algorithm).HasConversion(v => VaultKeyAlgorithms.ToToken(v), v => VaultKeyAlgorithms.Parse(v));
});
diff --git a/apps/server/Databases/AliasServerDb/ManifestKeyType.cs b/apps/server/Databases/AliasServerDb/ManifestKeyType.cs
deleted file mode 100644
index df7efc1d8..000000000
--- a/apps/server/Databases/AliasServerDb/ManifestKeyType.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="ManifestKeyType.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 AliasServerDb;
-
-/// <summary>
-/// What encrypts a <see cref="VaultManifestAccessKey"/> row's VEK.
-/// </summary>
-public enum ManifestKeyType
-{
- /// <summary>
- /// The user's own personal-manifest VEK, encrypted by their Account Key (see <see cref="UserUnlockKey"/>).
- /// </summary>
- AccountKey = 1,
-
- /// <summary>
- /// A grant: the VEK is encrypted to the user's grant key (see <see cref="UserGrantKey"/>), so only
- /// its holder's private half can decrypt it.
- /// </summary>
- GrantKey = 2,
-}
diff --git a/apps/server/Databases/AliasServerDb/ManifestKeyTypeDefinition.cs b/apps/server/Databases/AliasServerDb/ManifestKeyTypeDefinition.cs
deleted file mode 100644
index 3ecee427b..000000000
--- a/apps/server/Databases/AliasServerDb/ManifestKeyTypeDefinition.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="ManifestKeyTypeDefinition.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 AliasServerDb;
-
-/// <summary>
-/// The properties of a single <see cref="ManifestKeyType"/>.
-/// </summary>
-public sealed class ManifestKeyTypeDefinition
-{
- /// <summary>
- /// Gets the key type this definition describes.
- /// </summary>
- public required ManifestKeyType Type { get; init; }
-
- /// <summary>
- /// Gets the token that names the key type on the wire.
- /// </summary>
- public required string Token { get; init; }
-
- /// <summary>
- /// Gets a value indicating whether the encrypted VEK travels to the client along with the manifest.
- /// </summary>
- public required bool CarriesEncryptedVek { get; init; }
-}
diff --git a/apps/server/Databases/AliasServerDb/ManifestKeyTypes.cs b/apps/server/Databases/AliasServerDb/ManifestKeyTypes.cs
deleted file mode 100644
index fc528e51e..000000000
--- a/apps/server/Databases/AliasServerDb/ManifestKeyTypes.cs
+++ /dev/null
@@ -1,110 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="ManifestKeyTypes.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 AliasServerDb;
-
-/// <summary>
-/// The manifest key types this build supports, each with everything that varies per type.
-/// </summary>
-public static class ManifestKeyTypes
-{
- /// <summary>
- /// Every key type this build supports.
- /// </summary>
- private static readonly ManifestKeyTypeDefinition[] Definitions =
- [
- new ManifestKeyTypeDefinition
- {
- Type = ManifestKeyType.AccountKey,
- Token = "accountkey",
- CarriesEncryptedVek = false,
- },
- new ManifestKeyTypeDefinition
- {
- Type = ManifestKeyType.GrantKey,
- Token = "grantkey",
- CarriesEncryptedVek = true,
- },
- ];
-
- private static readonly Dictionary<ManifestKeyType, ManifestKeyTypeDefinition> ByType = Definitions.ToDictionary(x => x.Type);
- private static readonly Dictionary<string, ManifestKeyTypeDefinition> ByToken = Definitions.ToDictionary(x => x.Token, StringComparer.Ordinal);
-
- /// <summary>
- /// Initializes static members of the <see cref="ManifestKeyTypes"/> class.
- /// </summary>
- static ManifestKeyTypes()
- {
- var undefined = Enum.GetValues<ManifestKeyType>().Where(x => !ByType.ContainsKey(x)).ToList();
- if (undefined.Count > 0)
- {
- throw new InvalidOperationException($"Manifest key type(s) without a definition: {string.Join(", ", undefined)}.");
- }
- }
-
- /// <summary>
- /// Returns the definition of a key type.
- /// </summary>
- /// <param name="type">The key type to look up.</param>
- /// <returns>The definition.</returns>
- public static ManifestKeyTypeDefinition GetDefinition(ManifestKeyType type)
- {
- if (!ByType.TryGetValue(type, out var definition))
- {
- throw new ArgumentOutOfRangeException(nameof(type), type, "Unknown manifest key type.");
- }
-
- return definition;
- }
-
- /// <summary>
- /// Returns the token for a key type.
- /// </summary>
- /// <param name="type">The key type to convert.</param>
- /// <returns>The token.</returns>
- public static string ToToken(ManifestKeyType type) => GetDefinition(type).Token;
-
- /// <summary>
- /// Whether a key type's encrypted VEK is carried to the client alongside the manifest.
- /// </summary>
- /// <param name="type">The key type to check.</param>
- /// <returns>True when the manifest carries the encrypted VEK.</returns>
- public static bool CarriesEncryptedVek(ManifestKeyType type) => GetDefinition(type).CarriesEncryptedVek;
-
- /// <summary>
- /// Parses a token.
- /// </summary>
- /// <param name="token">The token to parse.</param>
- /// <param name="type">The parsed key type.</param>
- /// <returns>True when the token names a key type this build supports.</returns>
- public static bool TryParse(string? token, out ManifestKeyType type)
- {
- if (token is null || !ByToken.TryGetValue(token, out var definition))
- {
- type = default;
- return false;
- }
-
- type = definition.Type;
- return true;
- }
-
- /// <summary>
- /// Parses a token and returns the key type.
- /// </summary>
- /// <param name="token">The token to parse.</param>
- /// <returns>The parsed key type.</returns>
- public static ManifestKeyType Parse(string? token)
- {
- if (!TryParse(token, out var type))
- {
- throw new ArgumentOutOfRangeException(nameof(token), token, "Unknown manifest key type token.");
- }
-
- return type;
- }
-}
diff --git a/apps/server/Databases/AliasServerDb/Migrations/20260809190147_StoreKeyVocabularyAsTokens.Designer.cs b/apps/server/Databases/AliasServerDb/Migrations/20260809190147_StoreKeyVocabularyAsTokens.Designer.cs
new file mode 100644
index 000000000..87b7087c5
--- /dev/null
+++ b/apps/server/Databases/AliasServerDb/Migrations/20260809190147_StoreKeyVocabularyAsTokens.Designer.cs
@@ -0,0 +1,1640 @@
+// <auto-generated />
+using System;
+using AliasServerDb;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
+
+#nullable disable
+
+namespace AliasServerDb.Migrations
+{
+ [DbContext(typeof(AliasServerDbContext))]
+ [Migration("20260809190147_StoreKeyVocabularyAsTokens")]
+ partial class StoreKeyVocabularyAsTokens
+ {
+ /// <inheritdoc />
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "10.0.10")
+ .HasAnnotation("Proxies:ChangeTracking", false)
+ .HasAnnotation("Proxies:CheckEquality", false)
+ .HasAnnotation("Proxies:LazyLoading", true)
+ .HasAnnotation("Relational:MaxIdentifierLength", 63);
+
+ NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
+
+ modelBuilder.Entity("AliasServerDb.AdminRole", b =>
+ {
+ b.Property<string>("Id")
+ .HasColumnType("text");
+
+ b.Property<string>("ConcurrencyStamp")
+ .HasColumnType("text");
+
+ b.Property<string>("Name")
+ .HasColumnType("text");
+
+ b.Property<string>("NormalizedName")
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.ToTable("AdminRoles");
+ });
+
+ modelBuilder.Entity("AliasServerDb.AdminUser", b =>
+ {
+ b.Property<string>("Id")
+ .HasColumnType("text");
+
+ b.Property<int>("AccessFailedCount")
+ .HasColumnType("integer");
+
+ b.Property<string>("ConcurrencyStamp")
+ .HasColumnType("text");
+
+ b.Property<string>("Email")
+ .HasColumnType("text");
+
+ b.Property<bool>("EmailConfirmed")
+ .HasColumnType("boolean");
+
+ b.Property<DateTime?>("LastPasswordChanged")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<bool>("LockoutEnabled")
+ .HasColumnType("boolean");
+
+ b.Property<DateTimeOffset?>("LockoutEnd")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("NormalizedEmail")
+ .HasColumnType("text");
+
+ b.Property<string>("NormalizedUserName")
+ .HasColumnType("text");
+
+ b.Property<string>("PasswordHash")
+ .HasColumnType("text");
+
+ b.Property<string>("PhoneNumber")
+ .HasColumnType("text");
+
+ b.Property<bool>("PhoneNumberConfirmed")
+ .HasColumnType("boolean");
+
+ b.Property<string>("SecurityStamp")
+ .HasColumnType("text");
+
+ b.Property<bool>("TwoFactorEnabled")
+ .HasColumnType("boolean");
+
+ b.Property<string>("UserName")
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.ToTable("AdminUsers");
+ });
+
+ modelBuilder.Entity("AliasServerDb.AliasVaultRole", b =>
+ {
+ b.Property<string>("Id")
+ .HasColumnType("text");
+
+ b.Property<string>("ConcurrencyStamp")
+ .HasColumnType("text");
+
+ b.Property<string>("Name")
+ .HasColumnType("text");
+
+ b.Property<string>("NormalizedName")
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.ToTable("AliasVaultRoles");
+ });
+
+ modelBuilder.Entity("AliasServerDb.AliasVaultUser", b =>
+ {
+ b.Property<string>("Id")
+ .HasColumnType("text");
+
+ b.Property<int>("AccessFailedCount")
+ .HasColumnType("integer");
+
+ b.Property<bool>("Blocked")
+ .HasColumnType("boolean");
+
+ b.Property<DateTime?>("BlockedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("ConcurrencyStamp")
+ .HasColumnType("text");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("Email")
+ .HasColumnType("text");
+
+ b.Property<bool>("EmailConfirmed")
+ .HasColumnType("boolean");
+
+ b.Property<DateTime?>("LastActivityDate")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<bool>("LockoutEnabled")
+ .HasColumnType("boolean");
+
+ b.Property<DateTimeOffset?>("LockoutEnd")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("NormalizedEmail")
+ .HasColumnType("text");
+
+ b.Property<string>("NormalizedUserName")
+ .HasColumnType("text");
+
+ b.Property<DateTime>("PasswordChangedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("PasswordHash")
+ .HasColumnType("text");
+
+ b.Property<Guid>("PersonalGroupId")
+ .HasColumnType("uuid");
+
+ b.Property<string>("PhoneNumber")
+ .HasColumnType("text");
+
+ b.Property<bool>("PhoneNumberConfirmed")
+ .HasColumnType("boolean");
+
+ b.Property<string>("SecurityStamp")
+ .HasColumnType("text");
+
+ b.Property<string>("SrpIdentity")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<bool>("TwoFactorEnabled")
+ .HasColumnType("boolean");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("UserName")
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.HasIndex("PersonalGroupId")
+ .IsUnique()
+ .HasDatabaseName("UX_AliasVaultUsers_PersonalGroupId");
+
+ b.ToTable("AliasVaultUsers");
+ });
+
+ modelBuilder.Entity("AliasServerDb.AliasVaultUserRefreshToken", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("DeviceIdentifier")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<DateTime>("ExpireDate")
+ .HasMaxLength(255)
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("IpAddress")
+ .HasMaxLength(45)
+ .HasColumnType("character varying(45)");
+
+ b.Property<string>("PreviousTokenValue")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("UserId")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("Value")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId");
+
+ b.ToTable("AliasVaultUserRefreshTokens");
+ });
+
+ modelBuilder.Entity("AliasServerDb.AuthLog", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<string>("AdditionalInfo")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("Browser")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<string>("Client")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<string>("Country")
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<string>("DeviceType")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<int>("EventType")
+ .HasColumnType("integer");
+
+ b.Property<int?>("FailureReason")
+ .HasColumnType("integer");
+
+ b.Property<string>("IpAddress")
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<bool>("IsSuccess")
+ .HasColumnType("boolean");
+
+ b.Property<bool>("IsSuspiciousActivity")
+ .HasColumnType("boolean");
+
+ b.Property<string>("OperatingSystem")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<string>("RequestPath")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<DateTime>("Timestamp")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("Username")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("Id");
+
+ b.HasIndex(new[] { "EventType" }, "IX_EventType");
+
+ b.HasIndex(new[] { "IpAddress" }, "IX_IpAddress");
+
+ b.HasIndex(new[] { "Timestamp" }, "IX_Timestamp");
+
+ b.HasIndex(new[] { "Username", "IsSuccess", "Timestamp" }, "IX_Username_IsSuccess_Timestamp")
+ .IsDescending(false, false, true);
+
+ b.HasIndex(new[] { "Username", "Timestamp" }, "IX_Username_Timestamp")
+ .IsDescending(false, true);
+
+ b.ToTable("AuthLogs");
+ });
+
+ modelBuilder.Entity("AliasServerDb.BlockedIpRange", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<bool>("BlockLogin")
+ .HasColumnType("boolean");
+
+ b.Property<bool>("BlockRegistration")
+ .HasColumnType("boolean");
+
+ b.Property<bool>("BlockShadow")
+ .HasColumnType("boolean");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("CreatedBy")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<bool>("Enabled")
+ .HasColumnType("boolean");
+
+ b.Property<string>("IpRange")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<string>("Reason")
+ .HasMaxLength(500)
+ .HasColumnType("character varying(500)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.HasKey("Id");
+
+ b.HasIndex(new[] { "Enabled" }, "IX_BlockedIpRange_Enabled");
+
+ b.HasIndex(new[] { "IpRange" }, "IX_BlockedIpRange_IpRange")
+ .IsUnique();
+
+ b.ToTable("BlockedIpRanges");
+ });
+
+ modelBuilder.Entity("AliasServerDb.Email", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<DateTime>("Date")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<DateTime>("DateSystem")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("EncryptedSymmetricKey")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<Guid>("EncryptionKeyId")
+ .HasMaxLength(255)
+ .HasColumnType("uuid");
+
+ b.Property<string>("From")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("FromDomain")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("FromLocal")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("MessageHtml")
+ .HasColumnType("text");
+
+ b.Property<string>("MessagePlain")
+ .HasColumnType("text");
+
+ b.Property<string>("MessagePreview")
+ .HasColumnType("text");
+
+ b.Property<string>("MessageSource")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<bool>("PushNotificationSent")
+ .HasColumnType("boolean");
+
+ b.Property<string>("Subject")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("To")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("ToDomain")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("ToLocal")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<bool>("Visible")
+ .HasColumnType("boolean");
+
+ b.HasKey("Id");
+
+ b.HasIndex("Date");
+
+ b.HasIndex("DateSystem");
+
+ b.HasIndex("EncryptionKeyId");
+
+ b.HasIndex("PushNotificationSent");
+
+ b.HasIndex("Visible");
+
+ b.HasIndex("To", "DateSystem");
+
+ b.ToTable("Emails");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EmailAttachment", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<byte[]>("Bytes")
+ .IsRequired()
+ .HasColumnType("bytea");
+
+ b.Property<DateTime>("Date")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<int>("EmailId")
+ .HasColumnType("integer");
+
+ b.Property<string>("Filename")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<int>("Filesize")
+ .HasColumnType("integer");
+
+ b.Property<string>("MimeType")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.HasIndex("EmailId");
+
+ b.ToTable("EmailAttachments");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EmailClaim", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<string>("Address")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("AddressDomain")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("AddressLocal")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<bool>("Disabled")
+ .HasColumnType("boolean");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<Guid?>("VaultManifestId")
+ .HasColumnType("uuid");
+
+ b.HasKey("Id");
+
+ b.HasIndex("Address")
+ .IsUnique();
+
+ b.HasIndex("VaultManifestId", "CreatedAt");
+
+ b.HasIndex("VaultManifestId", "Disabled");
+
+ b.ToTable("EmailClaims");
+ });
+
+ modelBuilder.Entity("AliasServerDb.Group", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<int>("EmailsReceived")
+ .HasColumnType("integer");
+
+ b.Property<int>("MaxEmailAgeDays")
+ .HasColumnType("integer");
+
+ b.Property<int>("MaxEmails")
+ .HasColumnType("integer");
+
+ b.Property<string>("Name")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<bool>("ShadowBlocked")
+ .HasColumnType("boolean");
+
+ b.Property<DateTime?>("ShadowBlockedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<int>("Type")
+ .HasColumnType("integer");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.HasKey("Id");
+
+ b.ToTable("Groups");
+ });
+
+ modelBuilder.Entity("AliasServerDb.GroupMember", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<Guid>("GroupId")
+ .HasColumnType("uuid");
+
+ b.Property<int>("Role")
+ .HasColumnType("integer");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("UserId")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId");
+
+ b.HasIndex("GroupId", "UserId")
+ .IsUnique();
+
+ b.ToTable("GroupMembers");
+ });
+
+ modelBuilder.Entity("AliasServerDb.Log", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<string>("Application")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<string>("Exception")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("Level")
+ .IsRequired()
+ .HasMaxLength(128)
+ .HasColumnType("character varying(128)");
+
+ b.Property<string>("LogEvent")
+ .IsRequired()
+ .HasColumnType("text")
+ .HasColumnName("LogEvent");
+
+ b.Property<string>("Message")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("MessageTemplate")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("Properties")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("SourceContext")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<DateTime>("TimeStamp")
+ .HasColumnType("timestamp with time zone");
+
+ b.HasKey("Id");
+
+ b.HasIndex("Application");
+
+ b.HasIndex("TimeStamp");
+
+ b.ToTable("Logs", (string)null);
+ });
+
+ modelBuilder.Entity("AliasServerDb.MobileLoginRequest", b =>
+ {
+ b.Property<string>("Id")
+ .HasColumnType("text");
+
+ b.Property<DateTime?>("ClearedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("ClientIpAddress")
+ .HasColumnType("text");
+
+ b.Property<string>("ClientPublicKey")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("EncryptedDecryptionKey")
+ .HasColumnType("text");
+
+ b.Property<DateTime?>("FulfilledAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("MobileIpAddress")
+ .HasColumnType("text");
+
+ b.Property<DateTime?>("RetrievedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("UserId")
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.HasIndex(new[] { "ClientIpAddress" }, "IX_ClientIpAddress");
+
+ b.HasIndex(new[] { "CreatedAt" }, "IX_CreatedAt");
+
+ b.HasIndex(new[] { "MobileIpAddress" }, "IX_MobileIpAddress");
+
+ b.HasIndex(new[] { "RetrievedAt", "ClearedAt", "FulfilledAt" }, "IX_RetrievedAt_ClearedAt_FulfilledAt");
+
+ b.HasIndex(new[] { "UserId" }, "IX_UserId");
+
+ b.ToTable("MobileLoginRequests");
+ });
+
+ modelBuilder.Entity("AliasServerDb.RateLimit", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<int?>("AppliesToAccountAgeMaxDays")
+ .HasColumnType("integer");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("CreatedBy")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<DateTime?>("EffectiveFrom")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<DateTime?>("EffectiveUntil")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<bool>("Enabled")
+ .HasColumnType("boolean");
+
+ b.Property<Guid?>("GroupId")
+ .HasColumnType("uuid");
+
+ b.Property<int>("LimitType")
+ .HasColumnType("integer");
+
+ b.Property<int>("MaxCount")
+ .HasColumnType("integer");
+
+ b.Property<string>("Notes")
+ .HasMaxLength(1000)
+ .HasColumnType("character varying(1000)");
+
+ b.Property<int?>("Tier")
+ .HasColumnType("integer");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<int>("WindowSeconds")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.HasIndex("GroupId");
+
+ b.HasIndex("Tier");
+
+ b.HasIndex("LimitType", "Enabled");
+
+ b.ToTable("RateLimits");
+ });
+
+ modelBuilder.Entity("AliasServerDb.ServerSetting", b =>
+ {
+ b.Property<string>("Key")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("Value")
+ .HasColumnType("text");
+
+ b.HasKey("Key");
+
+ b.ToTable("ServerSettings");
+ });
+
+ modelBuilder.Entity("AliasServerDb.TaskRunnerJob", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<TimeOnly?>("EndTime")
+ .HasColumnType("time without time zone");
+
+ b.Property<string>("ErrorMessage")
+ .HasColumnType("text");
+
+ b.Property<bool>("IsOnDemand")
+ .HasColumnType("boolean");
+
+ b.Property<string>("Name")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<DateTime>("RunDate")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<TimeOnly>("StartTime")
+ .HasColumnType("time without time zone");
+
+ b.Property<int>("Status")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.ToTable("TaskRunnerJobs");
+ });
+
+ modelBuilder.Entity("AliasServerDb.UserGrantKey", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("EncryptedPrivateKey")
+ .IsRequired()
+ .HasMaxLength(4000)
+ .HasColumnType("character varying(4000)");
+
+ b.Property<bool>("IsPrimary")
+ .HasColumnType("boolean");
+
+ b.Property<string>("PublicKey")
+ .IsRequired()
+ .HasMaxLength(2000)
+ .HasColumnType("character varying(2000)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("UserId")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId")
+ .IsUnique()
+ .HasDatabaseName("UX_UserGrantKeys_User_Primary")
+ .HasFilter("\"IsPrimary\"");
+
+ b.ToTable("UserGrantKeys");
+ });
+
+ modelBuilder.Entity("AliasServerDb.UserUnlockKey", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<string>("Algorithm")
+ .IsRequired()
+ .HasMaxLength(30)
+ .HasColumnType("character varying(30)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("EncryptedAccountKey")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<DateTime?>("LastUsedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("Metadata")
+ .HasColumnType("jsonb");
+
+ b.Property<string>("Type")
+ .IsRequired()
+ .HasMaxLength(30)
+ .HasColumnType("character varying(30)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("UserId")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId", "Type")
+ .IsUnique()
+ .HasDatabaseName("UX_UserUnlockKeys_UserId_Type");
+
+ b.ToTable("UserUnlockKeys");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultBlobObject", b =>
+ {
+ b.Property<string>("Hash")
+ .HasMaxLength(64)
+ .HasColumnType("character varying(64)");
+
+ b.Property<string>("OwnerUserId")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("Category")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("character varying(20)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<byte[]>("EncryptedData")
+ .IsRequired()
+ .HasColumnType("bytea");
+
+ b.Property<DateTime>("LastReferencedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<int>("SizeBytes")
+ .HasColumnType("integer");
+
+ b.HasKey("Hash", "OwnerUserId");
+
+ b.HasIndex("OwnerUserId", "Category");
+
+ b.ToTable("VaultBlobObjects");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultBlobReference", b =>
+ {
+ b.Property<Guid>("ManifestId")
+ .HasColumnType("uuid");
+
+ b.Property<long>("RevisionNumber")
+ .HasColumnType("bigint");
+
+ b.Property<string>("BlobHash")
+ .HasMaxLength(64)
+ .HasColumnType("character varying(64)");
+
+ b.HasKey("ManifestId", "RevisionNumber", "BlobHash");
+
+ b.ToTable("VaultBlobReferences");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultDataBucket", b =>
+ {
+ b.Property<Guid>("ManifestId")
+ .HasColumnType("uuid");
+
+ b.Property<string>("Category")
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<string>("CiphertextHash")
+ .HasMaxLength(64)
+ .HasColumnType("character varying(64)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("EncryptedData")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<long>("RevisionNumber")
+ .HasColumnType("bigint");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.HasKey("ManifestId", "Category");
+
+ b.ToTable("VaultDataBuckets");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultDataBucketsHistory", b =>
+ {
+ b.Property<Guid>("ManifestId")
+ .HasColumnType("uuid");
+
+ b.Property<string>("Category")
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<long>("RevisionNumber")
+ .HasColumnType("bigint");
+
+ b.Property<string>("CiphertextHash")
+ .HasMaxLength(64)
+ .HasColumnType("character varying(64)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("EncryptedData")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.HasKey("ManifestId", "Category", "RevisionNumber");
+
+ b.ToTable("VaultDataBucketsHistory");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultManifest", b =>
+ {
+ b.Property<Guid>("ManifestId")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<string>("Client")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<int>("CredentialsCount")
+ .HasColumnType("integer");
+
+ b.Property<int>("EmailClaimsCount")
+ .HasColumnType("integer");
+
+ b.Property<string>("EncryptionSettings")
+ .HasColumnType("text");
+
+ b.Property<string>("EncryptionType")
+ .HasColumnType("text");
+
+ b.Property<int>("FileSize")
+ .HasColumnType("integer");
+
+ b.Property<string>("ManifestBlob")
+ .HasColumnType("text");
+
+ b.Property<string>("ManifestCiphertextHash")
+ .HasMaxLength(64)
+ .HasColumnType("character varying(64)");
+
+ b.Property<string>("Name")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<Guid>("OwnerGroupId")
+ .HasColumnType("uuid");
+
+ b.Property<long>("RevisionNumber")
+ .HasColumnType("bigint");
+
+ b.Property<string>("Salt")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<string>("StorageFormat")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("character varying(20)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("VaultBlob")
+ .HasColumnType("text");
+
+ b.Property<string>("Verifier")
+ .HasMaxLength(1000)
+ .HasColumnType("character varying(1000)");
+
+ b.Property<string>("Version")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("ManifestId");
+
+ b.HasIndex("OwnerGroupId");
+
+ b.ToTable("VaultManifests");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultManifestAccessKey", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<string>("Algorithm")
+ .IsRequired()
+ .HasMaxLength(30)
+ .HasColumnType("character varying(30)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("EncryptedVek")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<DateTime?>("LastUsedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("Metadata")
+ .HasColumnType("jsonb");
+
+ b.Property<string>("Type")
+ .IsRequired()
+ .HasMaxLength(30)
+ .HasColumnType("character varying(30)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<Guid?>("UserGrantKeyId")
+ .HasColumnType("uuid");
+
+ b.Property<string>("UserId")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<Guid>("VaultManifestId")
+ .HasColumnType("uuid");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserGrantKeyId");
+
+ b.HasIndex("VaultManifestId")
+ .HasDatabaseName("IX_VaultManifestAccessKeys_VaultManifestId");
+
+ b.HasIndex("UserId", "Type", "VaultManifestId")
+ .IsUnique()
+ .HasDatabaseName("UX_VaultManifestAccessKeys_UserId_Type_Manifest");
+
+ b.ToTable("VaultManifestAccessKeys");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultManifestDeliveryKey", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<bool>("IsPrimary")
+ .HasColumnType("boolean");
+
+ b.Property<string>("PublicKey")
+ .IsRequired()
+ .HasMaxLength(2000)
+ .HasColumnType("character varying(2000)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<Guid>("VaultManifestId")
+ .HasColumnType("uuid");
+
+ b.HasKey("Id");
+
+ b.HasIndex("VaultManifestId")
+ .IsUnique()
+ .HasDatabaseName("UX_VaultManifestDeliveryKeys_Manifest_Primary")
+ .HasFilter("\"IsPrimary\"");
+
+ b.HasIndex("VaultManifestId", "IsPrimary");
+
+ b.ToTable("VaultManifestDeliveryKeys");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultManifestsHistory", b =>
+ {
+ b.Property<Guid>("ManifestId")
+ .HasColumnType("uuid");
+
+ b.Property<long>("RevisionNumber")
+ .HasColumnType("bigint");
+
+ b.Property<string>("Client")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<int>("CredentialsCount")
+ .HasColumnType("integer");
+
+ b.Property<int>("EmailClaimsCount")
+ .HasColumnType("integer");
+
+ b.Property<string>("EncryptionSettings")
+ .HasColumnType("text");
+
+ b.Property<string>("EncryptionType")
+ .HasColumnType("text");
+
+ b.Property<int>("FileSize")
+ .HasColumnType("integer");
+
+ b.Property<string>("ManifestBlob")
+ .HasColumnType("text");
+
+ b.Property<string>("ManifestCiphertextHash")
+ .HasMaxLength(64)
+ .HasColumnType("character varying(64)");
+
+ b.Property<string>("Salt")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<string>("StorageFormat")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("character varying(20)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("VaultBlob")
+ .HasColumnType("text");
+
+ b.Property<string>("Verifier")
+ .HasMaxLength(1000)
+ .HasColumnType("character varying(1000)");
+
+ b.Property<string>("Version")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("ManifestId", "RevisionNumber");
+
+ b.ToTable("VaultManifestsHistory", (string)null);
+ });
+
+ modelBuilder.Entity("AliasVault.WorkerStatus.Database.WorkerServiceStatus", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<string>("CurrentStatus")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<string>("DesiredStatus")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<DateTime>("Heartbeat")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("ServiceName")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("Id");
+
+ b.ToTable("WorkerServiceStatuses");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.DataProtection.EntityFrameworkCore.DataProtectionKey", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<string>("FriendlyName")
+ .HasColumnType("text");
+
+ b.Property<string>("Xml")
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.ToTable("DataProtectionKeys");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<string>("ClaimType")
+ .HasColumnType("text");
+
+ b.Property<string>("ClaimValue")
+ .HasColumnType("text");
+
+ b.Property<string>("RoleId")
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.ToTable("RoleClaims", (string)null);
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<string>("ClaimType")
+ .HasColumnType("text");
+
+ b.Property<string>("ClaimValue")
+ .HasColumnType("text");
+
+ b.Property<string>("UserId")
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.ToTable("UserClaims", (string)null);
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
+ {
+ b.Property<string>("LoginProvider")
+ .HasColumnType("text");
+
+ b.Property<string>("ProviderKey")
+ .HasColumnType("text");
+
+ b.Property<string>("ProviderDisplayName")
+ .HasColumnType("text");
+
+ b.Property<string>("UserId")
+ .HasColumnType("text");
+
+ b.HasKey("LoginProvider", "ProviderKey");
+
+ b.ToTable("UserLogins", (string)null);
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
+ {
+ b.Property<string>("UserId")
+ .HasColumnType("text");
+
+ b.Property<string>("RoleId")
+ .HasColumnType("text");
+
+ b.HasKey("UserId", "RoleId");
+
+ b.ToTable("UserRoles", (string)null);
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
+ {
+ b.Property<string>("UserId")
+ .HasColumnType("text");
+
+ b.Property<string>("LoginProvider")
+ .HasColumnType("text");
+
+ b.Property<string>("Name")
+ .HasColumnType("text");
+
+ b.Property<string>("Value")
+ .HasColumnType("text");
+
+ b.HasKey("UserId", "LoginProvider", "Name");
+
+ b.ToTable("UserTokens", (string)null);
+ });
+
+ modelBuilder.Entity("AliasServerDb.AliasVaultUser", b =>
+ {
+ b.HasOne("AliasServerDb.Group", "PersonalGroup")
+ .WithOne()
+ .HasForeignKey("AliasServerDb.AliasVaultUser", "PersonalGroupId")
+ .OnDelete(DeleteBehavior.Restrict)
+ .IsRequired();
+
+ b.Navigation("PersonalGroup");
+ });
+
+ modelBuilder.Entity("AliasServerDb.AliasVaultUserRefreshToken", b =>
+ {
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("AliasServerDb.Email", b =>
+ {
+ b.HasOne("AliasServerDb.VaultManifestDeliveryKey", "EncryptionKey")
+ .WithMany("Emails")
+ .HasForeignKey("EncryptionKeyId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("EncryptionKey");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EmailAttachment", b =>
+ {
+ b.HasOne("AliasServerDb.Email", "Email")
+ .WithMany("Attachments")
+ .HasForeignKey("EmailId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Email");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EmailClaim", b =>
+ {
+ b.HasOne("AliasServerDb.VaultManifest", "VaultManifest")
+ .WithMany()
+ .HasForeignKey("VaultManifestId")
+ .OnDelete(DeleteBehavior.SetNull);
+
+ b.Navigation("VaultManifest");
+ });
+
+ modelBuilder.Entity("AliasServerDb.GroupMember", b =>
+ {
+ b.HasOne("AliasServerDb.Group", "Group")
+ .WithMany("Members")
+ .HasForeignKey("GroupId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Group");
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("AliasServerDb.MobileLoginRequest", b =>
+ {
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade);
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("AliasServerDb.RateLimit", b =>
+ {
+ b.HasOne("AliasServerDb.Group", "Group")
+ .WithMany()
+ .HasForeignKey("GroupId")
+ .OnDelete(DeleteBehavior.Cascade);
+
+ b.Navigation("Group");
+ });
+
+ modelBuilder.Entity("AliasServerDb.UserGrantKey", b =>
+ {
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("AliasServerDb.UserUnlockKey", b =>
+ {
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultBlobObject", b =>
+ {
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany()
+ .HasForeignKey("OwnerUserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultBlobReference", b =>
+ {
+ b.HasOne("AliasServerDb.VaultManifest", "Manifest")
+ .WithMany()
+ .HasForeignKey("ManifestId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Manifest");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultDataBucket", b =>
+ {
+ b.HasOne("AliasServerDb.VaultManifest", "Manifest")
+ .WithMany()
+ .HasForeignKey("ManifestId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Manifest");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultDataBucketsHistory", b =>
+ {
+ b.HasOne("AliasServerDb.VaultDataBucket", "Bucket")
+ .WithMany()
+ .HasForeignKey("ManifestId", "Category")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Bucket");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultManifest", b =>
+ {
+ b.HasOne("AliasServerDb.Group", "OwnerGroup")
+ .WithMany()
+ .HasForeignKey("OwnerGroupId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("OwnerGroup");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultManifestAccessKey", b =>
+ {
+ b.HasOne("AliasServerDb.UserGrantKey", "UserGrantKey")
+ .WithMany()
+ .HasForeignKey("UserGrantKeyId")
+ .OnDelete(DeleteBehavior.SetNull);
+
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany("VaultManifestAccessKeys")
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("User");
+
+ b.Navigation("UserGrantKey");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultManifestDeliveryKey", b =>
+ {
+ b.HasOne("AliasServerDb.VaultManifest", "VaultManifest")
+ .WithMany()
+ .HasForeignKey("VaultManifestId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("VaultManifest");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultManifestsHistory", b =>
+ {
+ b.HasOne("AliasServerDb.VaultManifest", "Manifest")
+ .WithMany()
+ .HasForeignKey("ManifestId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Manifest");
+ });
+
+ modelBuilder.Entity("AliasServerDb.AliasVaultUser", b =>
+ {
+ b.Navigation("VaultManifestAccessKeys");
+ });
+
+ modelBuilder.Entity("AliasServerDb.Email", b =>
+ {
+ b.Navigation("Attachments");
+ });
+
+ modelBuilder.Entity("AliasServerDb.Group", b =>
+ {
+ b.Navigation("Members");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultManifestDeliveryKey", b =>
+ {
+ b.Navigation("Emails");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/apps/server/Databases/AliasServerDb/Migrations/20260809190147_StoreKeyVocabularyAsTokens.cs b/apps/server/Databases/AliasServerDb/Migrations/20260809190147_StoreKeyVocabularyAsTokens.cs
new file mode 100644
index 000000000..40c857f32
--- /dev/null
+++ b/apps/server/Databases/AliasServerDb/Migrations/20260809190147_StoreKeyVocabularyAsTokens.cs
@@ -0,0 +1,45 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace AliasServerDb.Migrations
+{
+ /// <summary>
+ /// Stores the key vocabulary Type columns as the constant string values instead of enum ints, so each key type
+ /// has exactly one identifier across the database, the API and every client.
+ /// </summary>
+ public partial class StoreKeyVocabularyAsTokens : Migration
+ {
+ /// <inheritdoc />
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.Sql("""
+ ALTER TABLE "VaultManifestAccessKeys"
+ ALTER COLUMN "Type" TYPE character varying(30)
+ USING CASE "Type" WHEN 1 THEN 'accountkey' WHEN 2 THEN 'grantkey' END;
+ """);
+
+ migrationBuilder.Sql("""
+ ALTER TABLE "UserUnlockKeys"
+ ALTER COLUMN "Type" TYPE character varying(30)
+ USING CASE "Type" WHEN 0 THEN 'password' END;
+ """);
+ }
+
+ /// <inheritdoc />
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.Sql("""
+ ALTER TABLE "VaultManifestAccessKeys"
+ ALTER COLUMN "Type" TYPE integer
+ USING CASE "Type" WHEN 'accountkey' THEN 1 WHEN 'grantkey' THEN 2 END;
+ """);
+
+ migrationBuilder.Sql("""
+ ALTER TABLE "UserUnlockKeys"
+ ALTER COLUMN "Type" TYPE integer
+ USING CASE "Type" WHEN 'password' THEN 0 END;
+ """);
+ }
+ }
+}
diff --git a/apps/server/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs b/apps/server/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs
index 6fa1438d7..f4d51c285 100644
--- a/apps/server/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs
+++ b/apps/server/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs
@@ -889,8 +889,10 @@ namespace AliasServerDb.Migrations
b.Property<string>("Metadata")
.HasColumnType("jsonb");
- b.Property<int>("Type")
- .HasColumnType("integer");
+ b.Property<string>("Type")
+ .IsRequired()
+ .HasMaxLength(30)
+ .HasColumnType("character varying(30)");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("timestamp with time zone");
@@ -1122,8 +1124,10 @@ namespace AliasServerDb.Migrations
b.Property<string>("Metadata")
.HasColumnType("jsonb");
- b.Property<int>("Type")
- .HasColumnType("integer");
+ b.Property<string>("Type")
+ .IsRequired()
+ .HasMaxLength(30)
+ .HasColumnType("character varying(30)");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("timestamp with time zone");
diff --git a/apps/server/Databases/AliasServerDb/UnlockMethodType.cs b/apps/server/Databases/AliasServerDb/UnlockMethodType.cs
deleted file mode 100644
index 148ac73b9..000000000
--- a/apps/server/Databases/AliasServerDb/UnlockMethodType.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="UnlockMethodType.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 AliasServerDb;
-
-/// <summary>
-/// Unlock methods a user can enroll (see <see cref="UserUnlockKey"/>).
-/// </summary>
-public enum UnlockMethodType
-{
- /// <summary>
- /// Master password (KEK derived via Argon2 from the password).
- /// </summary>
- Password = 0,
-}
diff --git a/apps/server/Databases/AliasServerDb/UserUnlockKey.cs b/apps/server/Databases/AliasServerDb/UserUnlockKey.cs
index 3c60037db..bc6377b84 100644
--- a/apps/server/Databases/AliasServerDb/UserUnlockKey.cs
+++ b/apps/server/Databases/AliasServerDb/UserUnlockKey.cs
@@ -8,6 +8,7 @@ namespace AliasServerDb;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
+using AliasVault.Shared.Models.Enums;
/// <summary>
/// User tied unlock method that a user uses to login to their own account. Every unlock method encrypts the same Account Key,
@@ -36,6 +37,7 @@ public class UserUnlockKey
/// <summary>
/// Gets or sets the unlock method this row represents.
/// </summary>
+ [StringLength(30)]
public required UnlockMethodType Type { get; set; }
/// <summary>
diff --git a/apps/server/Databases/AliasServerDb/VaultKeyAlgorithm.cs b/apps/server/Databases/AliasServerDb/VaultKeyAlgorithm.cs
deleted file mode 100644
index 463c787ab..000000000
--- a/apps/server/Databases/AliasServerDb/VaultKeyAlgorithm.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="VaultKeyAlgorithm.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 AliasServerDb;
-
-/// <summary>
-/// Algorithms a VEK can be encrypted with.
-/// </summary>
-public enum VaultKeyAlgorithm
-{
- /// <summary>
- /// AES-256-GCM with a 96-bit IV and 128-bit tag.
- /// </summary>
- Aes256Gcm = 0,
-
- /// <summary>
- /// RSA-OAEP with a 2048-bit modulus, SHA-256 and MGF1-SHA-256.
- /// </summary>
- RsaOaepSha256 = 1,
-}
diff --git a/apps/server/Databases/AliasServerDb/VaultKeyAlgorithmDefinition.cs b/apps/server/Databases/AliasServerDb/VaultKeyAlgorithmDefinition.cs
deleted file mode 100644
index f619c0574..000000000
--- a/apps/server/Databases/AliasServerDb/VaultKeyAlgorithmDefinition.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="VaultKeyAlgorithmDefinition.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 AliasServerDb;
-
-/// <summary>
-/// The properties of a single <see cref="VaultKeyAlgorithm"/>.
-/// </summary>
-public sealed class VaultKeyAlgorithmDefinition
-{
- /// <summary>
- /// Gets the algorithm this definition describes.
- /// </summary>
- public required VaultKeyAlgorithm Algorithm { get; init; }
-
- /// <summary>
- /// Gets the token that names the algorithm on the wire and in the database.
- /// </summary>
- public required string Token { get; init; }
-
- /// <summary>
- /// Gets a value indicating whether the algorithm encrypts to a public key.
- /// </summary>
- public required bool IsAsymmetric { get; init; }
-}
diff --git a/apps/server/Databases/AliasServerDb/VaultKeyAlgorithms.cs b/apps/server/Databases/AliasServerDb/VaultKeyAlgorithms.cs
deleted file mode 100644
index 253277726..000000000
--- a/apps/server/Databases/AliasServerDb/VaultKeyAlgorithms.cs
+++ /dev/null
@@ -1,110 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="VaultKeyAlgorithms.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 AliasServerDb;
-
-/// <summary>
-/// Vault key encryption algorithms.
-/// </summary>
-public static class VaultKeyAlgorithms
-{
- /// <summary>
- /// Every algorithm this build supports.
- /// </summary>
- private static readonly VaultKeyAlgorithmDefinition[] Definitions =
- [
- new VaultKeyAlgorithmDefinition
- {
- Algorithm = VaultKeyAlgorithm.Aes256Gcm,
- Token = "aes256-gcm",
- IsAsymmetric = false,
- },
- new VaultKeyAlgorithmDefinition
- {
- Algorithm = VaultKeyAlgorithm.RsaOaepSha256,
- Token = "rsa-oaep-sha256",
- IsAsymmetric = true,
- },
- ];
-
- private static readonly Dictionary<VaultKeyAlgorithm, VaultKeyAlgorithmDefinition> ByAlgorithm = Definitions.ToDictionary(x => x.Algorithm);
- private static readonly Dictionary<string, VaultKeyAlgorithmDefinition> ByToken = Definitions.ToDictionary(x => x.Token, StringComparer.Ordinal);
-
- /// <summary>
- /// Initializes static members of the <see cref="VaultKeyAlgorithms"/> class.
- /// </summary>
- static VaultKeyAlgorithms()
- {
- var undefined = Enum.GetValues<VaultKeyAlgorithm>().Where(x => !ByAlgorithm.ContainsKey(x)).ToList();
- if (undefined.Count > 0)
- {
- throw new InvalidOperationException($"Vault key algorithm(s) without a definition: {string.Join(", ", undefined)}.");
- }
- }
-
- /// <summary>
- /// Returns the definition of an algorithm.
- /// </summary>
- /// <param name="algorithm">The algorithm to look up.</param>
- /// <returns>The definition.</returns>
- public static VaultKeyAlgorithmDefinition GetDefinition(VaultKeyAlgorithm algorithm)
- {
- if (!ByAlgorithm.TryGetValue(algorithm, out var definition))
- {
- throw new ArgumentOutOfRangeException(nameof(algorithm), algorithm, "Unknown vault key algorithm.");
- }
-
- return definition;
- }
-
- /// <summary>
- /// Returns the token for an algorithm.
- /// </summary>
- /// <param name="algorithm">The algorithm to convert.</param>
- /// <returns>The token.</returns>
- public static string ToToken(VaultKeyAlgorithm algorithm) => GetDefinition(algorithm).Token;
-
- /// <summary>
- /// Parses a token.
- /// </summary>
- /// <param name="token">The token to parse.</param>
- /// <param name="algorithm">The parsed algorithm.</param>
- /// <returns>True when the token names an algorithm this build supports.</returns>
- public static bool TryParse(string? token, out VaultKeyAlgorithm algorithm)
- {
- if (token is null || !ByToken.TryGetValue(token, out var definition))
- {
- algorithm = default;
- return false;
- }
-
- algorithm = definition.Algorithm;
- return true;
- }
-
- /// <summary>
- /// Parses a token and returns the algorithm.
- /// </summary>
- /// <param name="token">The token to parse.</param>
- /// <returns>The parsed algorithm.</returns>
- public static VaultKeyAlgorithm Parse(string? token)
- {
- if (!TryParse(token, out var algorithm))
- {
- throw new ArgumentOutOfRangeException(nameof(token), token, "Unknown vault key algorithm token.");
- }
-
- return algorithm;
- }
-
- /// <summary>
- /// Whether an algorithm encrypts to a public key, i.e. is valid on a <see cref="ManifestKeyType.GrantKey"/> grant.
- /// </summary>
- /// <param name="algorithm">The algorithm to check.</param>
- /// <returns>True for asymmetric algorithms.</returns>
- public static bool IsAsymmetric(VaultKeyAlgorithm algorithm) => GetDefinition(algorithm).IsAsymmetric;
-}
diff --git a/apps/server/Databases/AliasServerDb/VaultManifestAccessKey.cs b/apps/server/Databases/AliasServerDb/VaultManifestAccessKey.cs
index 5d8a94684..fdbe82668 100644
--- a/apps/server/Databases/AliasServerDb/VaultManifestAccessKey.cs
+++ b/apps/server/Databases/AliasServerDb/VaultManifestAccessKey.cs
@@ -8,6 +8,7 @@ namespace AliasServerDb;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
+using AliasVault.Shared.Models.Enums;
/// <summary>
/// A per-(user, manifest) VEK access path.
@@ -40,6 +41,7 @@ public class VaultManifestAccessKey
/// <summary>
/// Gets or sets what encrypts this row's VEK.
/// </summary>
+ [StringLength(30)]
public required ManifestKeyType Type { get; set; }
/// <summary>
diff --git a/apps/server/Shared/AliasVault.Shared/Models/Enums/ManifestKeyType.cs b/apps/server/Shared/AliasVault.Shared/Models/Enums/ManifestKeyType.cs
new file mode 100644
index 000000000..d87147562
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/Enums/ManifestKeyType.cs
@@ -0,0 +1,95 @@
+// <auto-generated />
+// This file is auto-generated from core/models/scripts/generate-key-vocabulary.cjs.
+// Do not edit this file directly. Run 'core/models/build.sh' (or 'node core/models/scripts/generate-key-vocabulary.cjs') to regenerate.
+
+#nullable enable
+
+namespace AliasVault.Shared.Models.Enums;
+
+/// <summary>
+/// How one user's access to one manifest's VEK is protected. Every (user, manifest) access path is
+/// exactly one of these, and the token decides where the client looks for the key that opens the manifest.
+/// The token is the only persisted and transmitted identifier; the ordinals below are cosmetic.
+/// </summary>
+public enum ManifestKeyType
+{
+ /// <summary>
+ /// The VEK is encrypted with the user's own Account Key, which their unlock chain produces.
+ /// </summary>
+ AccountKey = 0,
+
+ /// <summary>
+ /// A grant: the VEK is encrypted to a public key of the user, so only its holder's private half can open it.
+ /// </summary>
+ GrantKey = 1,
+}
+
+/// <summary>
+/// Token conversions for <see cref="ManifestKeyType"/>.
+/// </summary>
+public static class ManifestKeyTypes
+{
+ /// <summary>
+ /// Returns the wire/storage token for a ManifestKeyType.
+ /// </summary>
+ /// <param name="type">The ManifestKeyType to convert.</param>
+ /// <returns>The token.</returns>
+ public static string ToToken(ManifestKeyType type) => type switch
+ {
+ ManifestKeyType.AccountKey => "accountkey",
+ ManifestKeyType.GrantKey => "grantkey",
+ _ => throw new ArgumentOutOfRangeException(nameof(type), type, "Unknown ManifestKeyType."),
+ };
+
+ /// <summary>
+ /// Parses a token.
+ /// </summary>
+ /// <param name="token">The token to parse.</param>
+ /// <param name="type">The parsed ManifestKeyType.</param>
+ /// <returns>True when the token names a ManifestKeyType this build supports.</returns>
+ public static bool TryParse(string? token, out ManifestKeyType type)
+ {
+ switch (token)
+ {
+ case "accountkey":
+ type = ManifestKeyType.AccountKey;
+ return true;
+ case "grantkey":
+ type = ManifestKeyType.GrantKey;
+ return true;
+ default:
+ type = default;
+ return false;
+ }
+ }
+
+ /// <summary>
+ /// Parses a token and returns the ManifestKeyType.
+ /// </summary>
+ /// <param name="token">The token to parse.</param>
+ /// <returns>The parsed ManifestKeyType.</returns>
+ public static ManifestKeyType Parse(string? token)
+ {
+ if (!TryParse(token, out var type))
+ {
+ throw new ArgumentOutOfRangeException(nameof(token), token, "Unknown ManifestKeyType token.");
+ }
+
+ return type;
+ }
+
+ /// <summary>
+ /// Whether this access path's encrypted VEK is delivered on the manifest itself.
+ /// False does not mean the ciphertext is withheld, only that it reaches the client by another route:
+ /// an account-key VEK travels in the unlock envelope served by GET /v2/VaultKey/{type}, because the
+ /// client must already have derived its KEK before any manifest is worth fetching.
+ /// </summary>
+ /// <param name="type">The ManifestKeyType to check.</param>
+ /// <returns>The flag value for that ManifestKeyType.</returns>
+ public static bool VekTravelsWithManifest(ManifestKeyType type) => type switch
+ {
+ ManifestKeyType.AccountKey => false,
+ ManifestKeyType.GrantKey => true,
+ _ => throw new ArgumentOutOfRangeException(nameof(type), type, "Unknown ManifestKeyType."),
+ };
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/Enums/UnlockMethodType.cs b/apps/server/Shared/AliasVault.Shared/Models/Enums/UnlockMethodType.cs
new file mode 100644
index 000000000..de57416e8
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/Enums/UnlockMethodType.cs
@@ -0,0 +1,71 @@
+// <auto-generated />
+// This file is auto-generated from core/models/scripts/generate-key-vocabulary.cjs.
+// Do not edit this file directly. Run 'core/models/build.sh' (or 'node core/models/scripts/generate-key-vocabulary.cjs') to regenerate.
+
+#nullable enable
+
+namespace AliasVault.Shared.Models.Enums;
+
+/// <summary>
+/// Unlock methods a user can enroll. Each enrolled method stores one copy of the user's Account Key,
+/// encrypted with a KEK derived from that method's secret.
+/// The token is the only persisted and transmitted identifier; the ordinals below are cosmetic.
+/// </summary>
+public enum UnlockMethodType
+{
+ /// <summary>
+ /// Master password: the KEK is derived from the password via Argon2.
+ /// </summary>
+ Password = 0,
+}
+
+/// <summary>
+/// Token conversions for <see cref="UnlockMethodType"/>.
+/// </summary>
+public static class UnlockMethodTypes
+{
+ /// <summary>
+ /// Returns the wire/storage token for a UnlockMethodType.
+ /// </summary>
+ /// <param name="type">The UnlockMethodType to convert.</param>
+ /// <returns>The token.</returns>
+ public static string ToToken(UnlockMethodType type) => type switch
+ {
+ UnlockMethodType.Password => "password",
+ _ => throw new ArgumentOutOfRangeException(nameof(type), type, "Unknown UnlockMethodType."),
+ };
+
+ /// <summary>
+ /// Parses a token.
+ /// </summary>
+ /// <param name="token">The token to parse.</param>
+ /// <param name="type">The parsed UnlockMethodType.</param>
+ /// <returns>True when the token names a UnlockMethodType this build supports.</returns>
+ public static bool TryParse(string? token, out UnlockMethodType type)
+ {
+ switch (token)
+ {
+ case "password":
+ type = UnlockMethodType.Password;
+ return true;
+ default:
+ type = default;
+ return false;
+ }
+ }
+
+ /// <summary>
+ /// Parses a token and returns the UnlockMethodType.
+ /// </summary>
+ /// <param name="token">The token to parse.</param>
+ /// <returns>The parsed UnlockMethodType.</returns>
+ public static UnlockMethodType Parse(string? token)
+ {
+ if (!TryParse(token, out var type))
+ {
+ throw new ArgumentOutOfRangeException(nameof(token), token, "Unknown UnlockMethodType token.");
+ }
+
+ return type;
+ }
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/Enums/VaultKeyAlgorithm.cs b/apps/server/Shared/AliasVault.Shared/Models/Enums/VaultKeyAlgorithm.cs
new file mode 100644
index 000000000..447bf6a8e
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/Enums/VaultKeyAlgorithm.cs
@@ -0,0 +1,92 @@
+// <auto-generated />
+// This file is auto-generated from core/models/scripts/generate-key-vocabulary.cjs.
+// Do not edit this file directly. Run 'core/models/build.sh' (or 'node core/models/scripts/generate-key-vocabulary.cjs') to regenerate.
+
+#nullable enable
+
+namespace AliasVault.Shared.Models.Enums;
+
+/// <summary>
+/// The algorithms a piece of vault key ciphertext can be encrypted with. The token travels next to every
+/// ciphertext, so a reader always knows how to open it without inferring anything from context.
+/// The token is the only persisted and transmitted identifier; the ordinals below are cosmetic.
+/// </summary>
+public enum VaultKeyAlgorithm
+{
+ /// <summary>
+ /// AES-256-GCM: symmetric, used where the reader already holds the wrapping key.
+ /// </summary>
+ Aes256Gcm = 0,
+
+ /// <summary>
+ /// RSA-OAEP with SHA-256: asymmetric, used to encrypt a VEK to a recipient's public key.
+ /// </summary>
+ RsaOaepSha256 = 1,
+}
+
+/// <summary>
+/// Token conversions for <see cref="VaultKeyAlgorithm"/>.
+/// </summary>
+public static class VaultKeyAlgorithms
+{
+ /// <summary>
+ /// Returns the wire/storage token for a VaultKeyAlgorithm.
+ /// </summary>
+ /// <param name="type">The VaultKeyAlgorithm to convert.</param>
+ /// <returns>The token.</returns>
+ public static string ToToken(VaultKeyAlgorithm type) => type switch
+ {
+ VaultKeyAlgorithm.Aes256Gcm => "aes256-gcm",
+ VaultKeyAlgorithm.RsaOaepSha256 => "rsa-oaep-sha256",
+ _ => throw new ArgumentOutOfRangeException(nameof(type), type, "Unknown VaultKeyAlgorithm."),
+ };
+
+ /// <summary>
+ /// Parses a token.
+ /// </summary>
+ /// <param name="token">The token to parse.</param>
+ /// <param name="type">The parsed VaultKeyAlgorithm.</param>
+ /// <returns>True when the token names a VaultKeyAlgorithm this build supports.</returns>
+ public static bool TryParse(string? token, out VaultKeyAlgorithm type)
+ {
+ switch (token)
+ {
+ case "aes256-gcm":
+ type = VaultKeyAlgorithm.Aes256Gcm;
+ return true;
+ case "rsa-oaep-sha256":
+ type = VaultKeyAlgorithm.RsaOaepSha256;
+ return true;
+ default:
+ type = default;
+ return false;
+ }
+ }
+
+ /// <summary>
+ /// Parses a token and returns the VaultKeyAlgorithm.
+ /// </summary>
+ /// <param name="token">The token to parse.</param>
+ /// <returns>The parsed VaultKeyAlgorithm.</returns>
+ public static VaultKeyAlgorithm Parse(string? token)
+ {
+ if (!TryParse(token, out var type))
+ {
+ throw new ArgumentOutOfRangeException(nameof(token), token, "Unknown VaultKeyAlgorithm token.");
+ }
+
+ return type;
+ }
+
+ /// <summary>
+ /// Whether the algorithm encrypts to a public key, which is what a grant requires.
+ /// </summary>
+ /// <param name="type">The VaultKeyAlgorithm to check.</param>
+ /// <returns>The flag value for that VaultKeyAlgorithm.</returns>
+ public static bool IsAsymmetric(VaultKeyAlgorithm type) => type switch
+ {
+ VaultKeyAlgorithm.Aes256Gcm => false,
+ VaultKeyAlgorithm.RsaOaepSha256 => true,
+ _ => throw new ArgumentOutOfRangeException(nameof(type), type, "Unknown VaultKeyAlgorithm."),
+ };
+}
diff --git a/core/models/build.sh b/core/models/build.sh
index 9cfd54bac..90e9ff9cf 100755
--- a/core/models/build.sh
+++ b/core/models/build.sh
@@ -21,6 +21,10 @@ echo "🔄 Generating vault data bucket categories (C#, TS, Swift, Kotlin) from
# Run before the build so the generated TS lands in src/ and is compiled into dist/ (and linted).
node scripts/generate-bucket-categories.cjs
+echo ""
+echo "🔄 Generating vault key vocabulary (C#, TS, Swift, Kotlin)..."
+node scripts/generate-key-vocabulary.cjs
+
npm run lint && npm run test && npm run build
echo ""
diff --git a/core/models/scripts/generate-key-vocabulary.cjs b/core/models/scripts/generate-key-vocabulary.cjs
new file mode 100644
index 000000000..78ffbd1c8
--- /dev/null
+++ b/core/models/scripts/generate-key-vocabulary.cjs
@@ -0,0 +1,423 @@
+#!/usr/bin/env node
+/**
+ * Generates the vault key vocabulary for C#, TypeScript, Swift, and Kotlin.
+ */
+
+const fs = require('fs');
+const path = require('path');
+
+// Paths
+const REPO_ROOT = path.join(__dirname, '../../..');
+const CS_OUTPUT_DIR = path.join(REPO_ROOT, 'apps/server/Shared/AliasVault.Shared/Models/Enums');
+const TS_OUTPUT_DIR = path.join(REPO_ROOT, 'core/models/src/webapi');
+const SWIFT_OUTPUT_DIR = path.join(REPO_ROOT, 'apps/mobile-app/ios/VaultModels');
+const KOTLIN_OUTPUT_DIR = path.join(REPO_ROOT, 'apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/models');
+
+const CS_NAMESPACE = 'AliasVault.Shared.Models.Enums';
+const KOTLIN_PACKAGE = 'net.aliasvault.app.vaultstore.models';
+
+const AUTOGEN_NOTE = 'core/models/scripts/generate-key-vocabulary.cjs';
+const REGEN_HINT = "Run 'core/models/build.sh' (or 'node core/models/scripts/generate-key-vocabulary.cjs') to regenerate.";
+
+/**
+ * The single source of truth for every key vocabulary.
+ *
+ * Per vocabulary:
+ * name - the type name shared by all platforms.
+ * helperName - the C# static class holding the string-constant conversions and the per-member predicates.
+ * summary - doc comment lines for the generated type.
+ * flags - boolean properties that vary per member; each becomes a C# predicate on the helper class.
+ * members - the closed set of members.
+ */
+const VOCABULARIES = [
+ {
+ name: 'UnlockMethodType',
+ helperName: 'UnlockMethodTypes',
+ summary: [
+ 'Unlock methods a user can enroll. Each enrolled method stores one copy of the user\'s Account Key,',
+ 'encrypted with a KEK derived from that method\'s secret.',
+ ],
+ flags: [],
+ members: [
+ {
+ name: 'Password',
+ token: 'password',
+ summary: 'Master password: the KEK is derived from the password via Argon2.',
+ },
+ ],
+ },
+ {
+ name: 'ManifestKeyType',
+ helperName: 'ManifestKeyTypes',
+ summary: [
+ 'How one user\'s access to one manifest\'s VEK is protected. Every (user, manifest) access path is',
+ 'exactly one of these, and the token decides where the client looks for the key that opens the manifest.',
+ ],
+ flags: [
+ {
+ name: 'VekTravelsWithManifest',
+ summary: [
+ 'Whether this access path\'s encrypted VEK is delivered on the manifest itself.',
+ 'False does not mean the ciphertext is withheld, only that it reaches the client by another route:',
+ 'an account-key VEK travels in the unlock envelope served by GET /v2/VaultKey/{type}, because the',
+ 'client must already have derived its KEK before any manifest is worth fetching.',
+ ],
+ },
+ ],
+ members: [
+ {
+ name: 'AccountKey',
+ token: 'accountkey',
+ summary: 'The VEK is encrypted with the user\'s own Account Key, which their unlock chain produces.',
+ flags: { VekTravelsWithManifest: false },
+ },
+ {
+ name: 'GrantKey',
+ token: 'grantkey',
+ summary: 'A grant: the VEK is encrypted to a public key of the user, so only its holder\'s private half can open it.',
+ flags: { VekTravelsWithManifest: true },
+ },
+ ],
+ },
+ {
+ name: 'VaultKeyAlgorithm',
+ helperName: 'VaultKeyAlgorithms',
+ summary: [
+ 'The algorithms a piece of vault key ciphertext can be encrypted with. The token travels next to every',
+ 'ciphertext, so a reader always knows how to open it without inferring anything from context.',
+ ],
+ flags: [
+ {
+ name: 'IsAsymmetric',
+ summary: [
+ 'Whether the algorithm encrypts to a public key, which is what a grant requires.',
+ ],
+ },
+ ],
+ members: [
+ {
+ name: 'Aes256Gcm',
+ token: 'aes256-gcm',
+ summary: 'AES-256-GCM: symmetric, used where the reader already holds the wrapping key.',
+ flags: { IsAsymmetric: false },
+ },
+ {
+ name: 'RsaOaepSha256',
+ token: 'rsa-oaep-sha256',
+ summary: 'RSA-OAEP with SHA-256: asymmetric, used to encrypt a VEK to a recipient\'s public key.',
+ flags: { IsAsymmetric: true },
+ },
+ ],
+ },
+];
+
+/** Convert a PascalCase name to camelCase (Swift). */
+function toCamelCase(name) {
+ return name.charAt(0).toLowerCase() + name.slice(1);
+}
+
+/** Convert a PascalCase name to SCREAMING_SNAKE_CASE (Kotlin). */
+function toScreamingSnakeCase(name) {
+ return name.replace(/([A-Z])/g, '_$1').toUpperCase().replace(/^_/, '');
+}
+
+/** Render doc text as an array of lines, accepting either a string or an array. */
+function toLines(summary) {
+ return Array.isArray(summary) ? summary : [summary];
+}
+
+/**
+ * Render doc text as lines with a terminating period on the last one (Kotlin detekt requires it).
+ * Only the final line is touched, so a sentence wrapped across lines is not punctuated mid-way.
+ */
+function toTerminatedLines(summary) {
+ const lines = toLines(summary);
+ const last = lines[lines.length - 1];
+ return [...lines.slice(0, -1), last.endsWith('.') ? last : `${last}.`];
+}
+
+/**
+ * Generate the C# enum plus its token/predicate helper class.
+ *
+ * The helper is a set of switch expressions rather than a lookup table: because the enum and the
+ * switches are emitted from the same list, every member is covered by construction, so there is no
+ * need for the start-up "is any member undefined?" check a hand-written table would require.
+ */
+function generateCSharp(vocab) {
+ const summaryBody = toLines(vocab.summary)
+ .concat(['The token is the only persisted and transmitted identifier; the ordinals below are cosmetic.'])
+ .map(line => `/// ${line}`)
+ .join('\n');
+ const summary = `/// <summary>\n${summaryBody}\n/// </summary>`;
+
+ const members = vocab.members
+ .map((member, index) => ` /// <summary>
+ /// ${member.summary}
+ /// </summary>
+ ${member.name} = ${index},`)
+ .join('\n\n');
+
+ const toTokenArms = vocab.members.map(m => ` ${vocab.name}.${m.name} => "${m.token}",`).join('\n');
+ const parseArms = vocab.members.map(m => ` case "${m.token}":\n type = ${vocab.name}.${m.name};\n return true;`).join('\n');
+
+ const predicates = vocab.flags
+ .map(flag => {
+ const flagSummary = toLines(flag.summary).map(line => ` /// ${line}`).join('\n');
+ const arms = vocab.members.map(m => ` ${vocab.name}.${m.name} => ${m.flags[flag.name] ? 'true' : 'false'},`).join('\n');
+ return `
+ /// <summary>
+${flagSummary}
+ /// </summary>
+ /// <param name="type">The ${vocab.name} to check.</param>
+ /// <returns>The flag value for that ${vocab.name}.</returns>
+ public static bool ${flag.name}(${vocab.name} type) => type switch
+ {
+${arms}
+ _ => throw new ArgumentOutOfRangeException(nameof(type), type, "Unknown ${vocab.name}."),
+ };
+`;
+ })
+ .join('');
+
+ return `// <auto-generated />
+// This file is auto-generated from ${AUTOGEN_NOTE}.
+// Do not edit this file directly. ${REGEN_HINT}
+
+#nullable enable
+
+namespace ${CS_NAMESPACE};
+
+${summary}
+public enum ${vocab.name}
+{
+${members}
+}
+
+/// <summary>
+/// Token conversions for <see cref="${vocab.name}"/>.
+/// </summary>
+public static class ${vocab.helperName}
+{
+ /// <summary>
+ /// Returns the wire/storage token for a ${vocab.name}.
+ /// </summary>
+ /// <param name="type">The ${vocab.name} to convert.</param>
+ /// <returns>The token.</returns>
+ public static string ToToken(${vocab.name} type) => type switch
+ {
+${toTokenArms}
+ _ => throw new ArgumentOutOfRangeException(nameof(type), type, "Unknown ${vocab.name}."),
+ };
+
+ /// <summary>
+ /// Parses a token.
+ /// </summary>
+ /// <param name="token">The token to parse.</param>
+ /// <param name="type">The parsed ${vocab.name}.</param>
+ /// <returns>True when the token names a ${vocab.name} this build supports.</returns>
+ public static bool TryParse(string? token, out ${vocab.name} type)
+ {
+ switch (token)
+ {
+${parseArms}
+ default:
+ type = default;
+ return false;
+ }
+ }
+
+ /// <summary>
+ /// Parses a token and returns the ${vocab.name}.
+ /// </summary>
+ /// <param name="token">The token to parse.</param>
+ /// <returns>The parsed ${vocab.name}.</returns>
+ public static ${vocab.name} Parse(string? token)
+ {
+ if (!TryParse(token, out var type))
+ {
+ throw new ArgumentOutOfRangeException(nameof(token), token, "Unknown ${vocab.name} token.");
+ }
+
+ return type;
+ }
+${predicates}}
+`;
+}
+
+/**
+ * Generate the TypeScript const object (consumed as-is by the browser extension and mobile app).
+ *
+ * Tokens only: anything a client branches on it branches on by token, so the server-side flag table
+ * has no client counterpart to drift from.
+ */
+function generateTypeScript(vocab) {
+ const summary = toLines(vocab.summary).map(line => ` * ${line}`).join('\n');
+
+ const members = vocab.members
+ .map(member => ` /**
+ * ${member.summary}
+ */
+ ${member.name}: '${member.token}',`)
+ .join('\n\n');
+
+ return `/**
+ * <auto-generated />
+ * This file is auto-generated from ${AUTOGEN_NOTE}.
+ * Do not edit this file directly. ${REGEN_HINT}
+ */
+
+/**
+${summary}
+ */
+export const ${vocab.name} = {
+${members}
+} as const;
+
+/**
+ * Type representing all valid ${vocab.name} tokens.
+ */
+export type ${vocab.name}Value = typeof ${vocab.name}[keyof typeof ${vocab.name}];
+`;
+}
+
+/**
+ * Generate the Swift string-constant struct (mirrors the VaultDataBucketCategory.swift convention).
+ */
+function generateSwift(vocab) {
+ const summary = toLines(vocab.summary).map(line => `/// ${line}`).join('\n');
+
+ const members = vocab.members
+ .map(member => ` /// ${member.summary}
+ public static let ${toCamelCase(member.name)} = "${member.token}"`)
+ .join('\n\n');
+
+ const all = vocab.members.map(m => toCamelCase(m.name)).join(', ');
+
+ return `// <auto-generated />
+// This file is auto-generated from ${AUTOGEN_NOTE}.
+// Do not edit this file directly. ${REGEN_HINT}
+
+import Foundation
+
+${summary}
+public struct ${vocab.name} {
+${members}
+
+ /// All known ${vocab.name} tokens.
+ public static let all = [${all}]
+}
+`;
+}
+
+/**
+ * Generate the Kotlin string-constant object (mirrors the VaultDataBucketCategory.kt convention).
+ */
+function generateKotlin(vocab) {
+ const summary = toTerminatedLines(vocab.summary).map(line => ` * ${line}`).join('\n');
+
+ const members = vocab.members
+ .map(member => ` /**
+ * ${toTerminatedLines(member.summary).join('\n * ')}
+ */
+ const val ${toScreamingSnakeCase(member.name)} = "${member.token}"`)
+ .join('\n\n');
+
+ const all = vocab.members.map(m => toScreamingSnakeCase(m.name)).join(', ');
+
+ return `// <auto-generated />
+// This file is auto-generated from ${AUTOGEN_NOTE}.
+// Do not edit this file directly. ${REGEN_HINT}
+
+package ${KOTLIN_PACKAGE}
+
+/**
+${summary}
+ */
+object ${vocab.name} {
+${members}
+
+ /**
+ * All known ${vocab.name} tokens.
+ */
+ val all = listOf(${all})
+}
+`;
+}
+
+/**
+ * Ensure the directory for a file path exists.
+ */
+function ensureDir(filePath) {
+ const dir = path.dirname(filePath);
+ if (!fs.existsSync(dir)) {
+ fs.mkdirSync(dir, { recursive: true });
+ }
+}
+
+/**
+ * Fail loudly on a definition that would emit ambiguous or colliding output.
+ */
+function validate() {
+ const seenTokens = new Map();
+ for (const vocab of VOCABULARIES) {
+ if (vocab.members.length === 0) {
+ throw new Error(`${vocab.name} declares no members.`);
+ }
+
+ const tokens = new Set();
+ for (const member of vocab.members) {
+ if (!/^[a-z0-9-]+$/.test(member.token)) {
+ throw new Error(`${vocab.name}.${member.name} has token "${member.token}"; tokens must be lowercase, digits and dashes only.`);
+ }
+
+ if (tokens.has(member.token)) {
+ throw new Error(`${vocab.name} declares token "${member.token}" twice.`);
+ }
+
+ tokens.add(member.token);
+
+ for (const flag of vocab.flags) {
+ if (typeof member.flags?.[flag.name] !== 'boolean') {
+ throw new Error(`${vocab.name}.${member.name} is missing a boolean value for flag "${flag.name}".`);
+ }
+ }
+ }
+
+ // Distinct vocabularies may reuse a token, but sharing one across types makes wire traces ambiguous.
+ for (const member of vocab.members) {
+ const owner = seenTokens.get(member.token);
+ if (owner && owner !== vocab.name) {
+ throw new Error(`Token "${member.token}" is declared by both ${owner} and ${vocab.name}.`);
+ }
+
+ seenTokens.set(member.token, vocab.name);
+ }
+ }
+}
+
+/**
+ * Main execution.
+ */
+function main() {
+ validate();
+
+ for (const vocab of VOCABULARIES) {
+ const outputs = [
+ [path.join(CS_OUTPUT_DIR, `${vocab.name}.cs`), generateCSharp(vocab)],
+ [path.join(TS_OUTPUT_DIR, `${vocab.name}.ts`), generateTypeScript(vocab)],
+ [path.join(SWIFT_OUTPUT_DIR, `${vocab.name}.swift`), generateSwift(vocab)],
+ [path.join(KOTLIN_OUTPUT_DIR, `${vocab.name}.kt`), generateKotlin(vocab)],
+ ];
+
+ for (const [outputPath, content] of outputs) {
+ ensureDir(outputPath);
+ fs.writeFileSync(outputPath, content, 'utf8');
+ console.log(`Generated: ${outputPath}`);
+ }
+ }
+
+ const total = VOCABULARIES.reduce((sum, v) => sum + v.members.length, 0);
+ console.log(`\nKey vocabulary generation complete (${VOCABULARIES.length} vocabularies, ${total} members).`);
+}
+
+main();
diff --git a/core/models/src/webapi/ManifestKeyType.ts b/core/models/src/webapi/ManifestKeyType.ts
new file mode 100644
index 000000000..b777d6446
--- /dev/null
+++ b/core/models/src/webapi/ManifestKeyType.ts
@@ -0,0 +1,26 @@
+/**
+ * <auto-generated />
+ * This file is auto-generated from core/models/scripts/generate-key-vocabulary.cjs.
+ * Do not edit this file directly. Run 'core/models/build.sh' (or 'node core/models/scripts/generate-key-vocabulary.cjs') to regenerate.
+ */
+
+/**
+ * How one user's access to one manifest's VEK is protected. Every (user, manifest) access path is
+ * exactly one of these, and the token decides where the client looks for the key that opens the manifest.
+ */
+export const ManifestKeyType = {
+ /**
+ * The VEK is encrypted with the user's own Account Key, which their unlock chain produces.
+ */
+ AccountKey: 'accountkey',
+
+ /**
+ * A grant: the VEK is encrypted to a public key of the user, so only its holder's private half can open it.
+ */
+ GrantKey: 'grantkey',
+} as const;
+
+/**
+ * Type representing all valid ManifestKeyType tokens.
+ */
+export type ManifestKeyTypeValue = typeof ManifestKeyType[keyof typeof ManifestKeyType];
diff --git a/core/models/src/webapi/UnlockMethodType.ts b/core/models/src/webapi/UnlockMethodType.ts
new file mode 100644
index 000000000..a6b9722cf
--- /dev/null
+++ b/core/models/src/webapi/UnlockMethodType.ts
@@ -0,0 +1,21 @@
+/**
+ * <auto-generated />
+ * This file is auto-generated from core/models/scripts/generate-key-vocabulary.cjs.
+ * Do not edit this file directly. Run 'core/models/build.sh' (or 'node core/models/scripts/generate-key-vocabulary.cjs') to regenerate.
+ */
+
+/**
+ * Unlock methods a user can enroll. Each enrolled method stores one copy of the user's Account Key,
+ * encrypted with a KEK derived from that method's secret.
+ */
+export const UnlockMethodType = {
+ /**
+ * Master password: the KEK is derived from the password via Argon2.
+ */
+ Password: 'password',
+} as const;
+
+/**
+ * Type representing all valid UnlockMethodType tokens.
+ */
+export type UnlockMethodTypeValue = typeof UnlockMethodType[keyof typeof UnlockMethodType];
diff --git a/core/models/src/webapi/VaultKeyAlgorithm.ts b/core/models/src/webapi/VaultKeyAlgorithm.ts
new file mode 100644
index 000000000..28bc8e0e4
--- /dev/null
+++ b/core/models/src/webapi/VaultKeyAlgorithm.ts
@@ -0,0 +1,26 @@
+/**
+ * <auto-generated />
+ * This file is auto-generated from core/models/scripts/generate-key-vocabulary.cjs.
+ * Do not edit this file directly. Run 'core/models/build.sh' (or 'node core/models/scripts/generate-key-vocabulary.cjs') to regenerate.
+ */
+
+/**
+ * The algorithms a piece of vault key ciphertext can be encrypted with. The token travels next to every
+ * ciphertext, so a reader always knows how to open it without inferring anything from context.
+ */
+export const VaultKeyAlgorithm = {
+ /**
+ * AES-256-GCM: symmetric, used where the reader already holds the wrapping key.
+ */
+ Aes256Gcm: 'aes256-gcm',
+
+ /**
+ * RSA-OAEP with SHA-256: asymmetric, used to encrypt a VEK to a recipient's public key.
+ */
+ RsaOaepSha256: 'rsa-oaep-sha256',
+} as const;
+
+/**
+ * Type representing all valid VaultKeyAlgorithm tokens.
+ */
+export type VaultKeyAlgorithmValue = typeof VaultKeyAlgorithm[keyof typeof VaultKeyAlgorithm];
diff --git a/core/models/src/webapi/index.ts b/core/models/src/webapi/index.ts
index 456b56e8c..5d3555b94 100644
--- a/core/models/src/webapi/index.ts
+++ b/core/models/src/webapi/index.ts
@@ -24,3 +24,6 @@ export * from './BadRequestResponse';
export * from './AuthEventType';
export * from './MobileLogin';
export * from './VaultKey';
+export * from './UnlockMethodType';
+export * from './ManifestKeyType';
+export * from './VaultKeyAlgorithm';