1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-06 00:13:28 +00:00
Files
browser/libs/tools/generator/extensions/legacy/src/create-legacy-password-generation-service.ts
Bernd Schoolmann 2f8a7a95bd [PM-15994] Move encrypt service to km ownership (#13220)
* Move encrypt service to km ownership

* Update imports for encrypt service abstraction and move bulk encrypt service abstraction

* Fix imports

* Fix further imports

* Fix imports

* Fix worker import
2025-02-05 17:39:11 +01:00

52 lines
2.1 KiB
TypeScript

// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { EncryptService } from "@bitwarden/common/key-management/crypto/abstractions/encrypt.service";
import { StateProvider } from "@bitwarden/common/platform/state";
import { engine, services, strategies } from "@bitwarden/generator-core";
import { LocalGeneratorHistoryService } from "@bitwarden/generator-history";
import { DefaultGeneratorNavigationService } from "@bitwarden/generator-navigation";
import { KeyService } from "@bitwarden/key-management";
import { LegacyPasswordGenerationService } from "./legacy-password-generation.service";
import { PasswordGenerationServiceAbstraction } from "./password-generation.service.abstraction";
const { PassphraseGeneratorStrategy, PasswordGeneratorStrategy } = strategies;
const { KeyServiceRandomizer, PasswordRandomizer } = engine;
const DefaultGeneratorService = services.DefaultGeneratorService;
export function legacyPasswordGenerationServiceFactory(
encryptService: EncryptService,
keyService: KeyService,
policyService: PolicyService,
accountService: AccountService,
stateProvider: StateProvider,
): PasswordGenerationServiceAbstraction {
const randomizer = new KeyServiceRandomizer(keyService);
const passwordRandomizer = new PasswordRandomizer(randomizer);
const passwords = new DefaultGeneratorService(
new PasswordGeneratorStrategy(passwordRandomizer, stateProvider),
policyService,
);
const passphrases = new DefaultGeneratorService(
new PassphraseGeneratorStrategy(passwordRandomizer, stateProvider),
policyService,
);
const navigation = new DefaultGeneratorNavigationService(stateProvider, policyService);
const history = new LocalGeneratorHistoryService(encryptService, keyService, stateProvider);
return new LegacyPasswordGenerationService(
accountService,
navigation,
passwords,
passphrases,
history,
);
}