1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-12 14:23:32 +00:00

[PM-14838] upgrade generator account storage to ObjectKey storage (#11975)

This commit is contained in:
✨ Audrey ✨
2024-11-14 10:09:59 -05:00
committed by GitHub
parent a08c9776cb
commit 642b8d2e6b

View File

@@ -24,11 +24,6 @@ import {
} from "../policies"; } from "../policies";
import { CatchallConstraints } from "../policies/catchall-constraints"; import { CatchallConstraints } from "../policies/catchall-constraints";
import { SubaddressConstraints } from "../policies/subaddress-constraints"; import { SubaddressConstraints } from "../policies/subaddress-constraints";
import {
EFF_USERNAME_SETTINGS,
PASSPHRASE_SETTINGS,
PASSWORD_SETTINGS,
} from "../strategies/storage";
import { import {
CatchallGenerationOptions, CatchallGenerationOptions,
CredentialGenerator, CredentialGenerator,
@@ -51,7 +46,10 @@ import { DefaultPasswordBoundaries } from "./default-password-boundaries";
import { DefaultPasswordGenerationOptions } from "./default-password-generation-options"; import { DefaultPasswordGenerationOptions } from "./default-password-generation-options";
import { DefaultSubaddressOptions } from "./default-subaddress-generator-options"; import { DefaultSubaddressOptions } from "./default-subaddress-generator-options";
const PASSPHRASE = Object.freeze({ const PASSPHRASE: CredentialGeneratorConfiguration<
PassphraseGenerationOptions,
PassphraseGeneratorPolicy
> = Object.freeze({
id: "passphrase", id: "passphrase",
category: "password", category: "password",
nameKey: "passphrase", nameKey: "passphrase",
@@ -76,7 +74,23 @@ const PASSPHRASE = Object.freeze({
}, },
wordSeparator: { maxLength: 1 }, wordSeparator: { maxLength: 1 },
}, },
account: PASSPHRASE_SETTINGS, account: {
key: "passphraseGeneratorSettings",
target: "object",
format: "plain",
classifier: new PublicClassifier<PassphraseGenerationOptions>([
"numWords",
"wordSeparator",
"capitalize",
"includeNumber",
]),
state: GENERATOR_DISK,
initial: DefaultPassphraseGenerationOptions,
options: {
deserializer: (value) => value,
clearOn: ["logout"],
},
} satisfies ObjectKey<PassphraseGenerationOptions>,
}, },
policy: { policy: {
type: PolicyType.PasswordGenerator, type: PolicyType.PasswordGenerator,
@@ -89,12 +103,12 @@ const PASSPHRASE = Object.freeze({
createEvaluator: (policy) => new PassphraseGeneratorOptionsEvaluator(policy), createEvaluator: (policy) => new PassphraseGeneratorOptionsEvaluator(policy),
toConstraints: (policy) => new PassphrasePolicyConstraints(policy), toConstraints: (policy) => new PassphrasePolicyConstraints(policy),
}, },
} satisfies CredentialGeneratorConfiguration< });
PassphraseGenerationOptions,
PassphraseGeneratorPolicy
>);
const PASSWORD = Object.freeze({ const PASSWORD: CredentialGeneratorConfiguration<
PasswordGenerationOptions,
PasswordGeneratorPolicy
> = Object.freeze({
id: "password", id: "password",
category: "password", category: "password",
nameKey: "password", nameKey: "password",
@@ -126,7 +140,29 @@ const PASSWORD = Object.freeze({
max: DefaultPasswordBoundaries.minSpecialCharacters.max, max: DefaultPasswordBoundaries.minSpecialCharacters.max,
}, },
}, },
account: PASSWORD_SETTINGS, account: {
key: "passwordGeneratorSettings",
target: "object",
format: "plain",
classifier: new PublicClassifier<PasswordGenerationOptions>([
"length",
"ambiguous",
"uppercase",
"minUppercase",
"lowercase",
"minLowercase",
"number",
"minNumber",
"special",
"minSpecial",
]),
state: GENERATOR_DISK,
initial: DefaultPasswordGenerationOptions,
options: {
deserializer: (value) => value,
clearOn: ["logout"],
},
} satisfies ObjectKey<PasswordGenerationOptions>,
}, },
policy: { policy: {
type: PolicyType.PasswordGenerator, type: PolicyType.PasswordGenerator,
@@ -143,9 +179,10 @@ const PASSWORD = Object.freeze({
createEvaluator: (policy) => new PasswordGeneratorOptionsEvaluator(policy), createEvaluator: (policy) => new PasswordGeneratorOptionsEvaluator(policy),
toConstraints: (policy) => new DynamicPasswordPolicyConstraints(policy), toConstraints: (policy) => new DynamicPasswordPolicyConstraints(policy),
}, },
} satisfies CredentialGeneratorConfiguration<PasswordGenerationOptions, PasswordGeneratorPolicy>); });
const USERNAME = Object.freeze({ const USERNAME: CredentialGeneratorConfiguration<EffUsernameGenerationOptions, NoPolicy> =
Object.freeze({
id: "username", id: "username",
category: "username", category: "username",
nameKey: "randomWord", nameKey: "randomWord",
@@ -164,7 +201,21 @@ const USERNAME = Object.freeze({
settings: { settings: {
initial: DefaultEffUsernameOptions, initial: DefaultEffUsernameOptions,
constraints: {}, constraints: {},
account: EFF_USERNAME_SETTINGS, account: {
key: "effUsernameGeneratorSettings",
target: "object",
format: "plain",
classifier: new PublicClassifier<EffUsernameGenerationOptions>([
"wordCapitalize",
"wordIncludeNumber",
]),
state: GENERATOR_DISK,
initial: DefaultEffUsernameOptions,
options: {
deserializer: (value) => value,
clearOn: ["logout"],
},
} satisfies ObjectKey<EffUsernameGenerationOptions>,
}, },
policy: { policy: {
type: PolicyType.PasswordGenerator, type: PolicyType.PasswordGenerator,
@@ -179,7 +230,7 @@ const USERNAME = Object.freeze({
return new IdentityConstraint<EffUsernameGenerationOptions>(); return new IdentityConstraint<EffUsernameGenerationOptions>();
}, },
}, },
} satisfies CredentialGeneratorConfiguration<EffUsernameGenerationOptions, NoPolicy>); });
const CATCHALL: CredentialGeneratorConfiguration<CatchallGenerationOptions, NoPolicy> = const CATCHALL: CredentialGeneratorConfiguration<CatchallGenerationOptions, NoPolicy> =
Object.freeze({ Object.freeze({