2023-06-06 22:34:53 +02:00
|
|
|
import { CryptoService as AbstractCryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
2022-10-18 19:03:09 +02:00
|
|
|
|
2024-01-10 17:51:45 +01:00
|
|
|
import {
|
|
|
|
AccountServiceInitOptions,
|
|
|
|
accountServiceFactory,
|
|
|
|
} from "../../../auth/background/service-factories/account-service.factory";
|
2023-06-06 22:34:53 +02:00
|
|
|
import {
|
|
|
|
StateServiceInitOptions,
|
|
|
|
stateServiceFactory,
|
|
|
|
} from "../../../platform/background/service-factories/state-service.factory";
|
|
|
|
import {
|
|
|
|
LogServiceInitOptions,
|
|
|
|
logServiceFactory,
|
|
|
|
} from "../../background/service-factories/log-service.factory";
|
|
|
|
import { BrowserCryptoService } from "../../services/browser-crypto.service";
|
2022-08-29 20:46:42 +02:00
|
|
|
|
|
|
|
import {
|
|
|
|
cryptoFunctionServiceFactory,
|
|
|
|
CryptoFunctionServiceInitOptions,
|
|
|
|
} from "./crypto-function-service.factory";
|
|
|
|
import { encryptServiceFactory, EncryptServiceInitOptions } from "./encrypt-service.factory";
|
|
|
|
import { FactoryOptions, CachedServices, factory } from "./factory-options";
|
2024-02-23 14:48:15 +01:00
|
|
|
import {
|
|
|
|
KeyGenerationServiceInitOptions,
|
|
|
|
keyGenerationServiceFactory,
|
|
|
|
} from "./key-generation-service.factory";
|
2022-08-29 20:46:42 +02:00
|
|
|
import {
|
|
|
|
PlatformUtilsServiceInitOptions,
|
2023-06-06 22:34:53 +02:00
|
|
|
platformUtilsServiceFactory,
|
2022-08-29 20:46:42 +02:00
|
|
|
} from "./platform-utils-service.factory";
|
2024-01-10 17:51:45 +01:00
|
|
|
import { StateProviderInitOptions, stateProviderFactory } from "./state-provider.factory";
|
2022-08-29 20:46:42 +02:00
|
|
|
|
|
|
|
type CryptoServiceFactoryOptions = FactoryOptions;
|
|
|
|
|
|
|
|
export type CryptoServiceInitOptions = CryptoServiceFactoryOptions &
|
2024-02-23 14:48:15 +01:00
|
|
|
KeyGenerationServiceInitOptions &
|
2022-08-29 20:46:42 +02:00
|
|
|
CryptoFunctionServiceInitOptions &
|
|
|
|
EncryptServiceInitOptions &
|
|
|
|
PlatformUtilsServiceInitOptions &
|
|
|
|
LogServiceInitOptions &
|
2024-01-10 17:51:45 +01:00
|
|
|
StateServiceInitOptions &
|
|
|
|
AccountServiceInitOptions &
|
|
|
|
StateProviderInitOptions;
|
2022-08-29 20:46:42 +02:00
|
|
|
|
|
|
|
export function cryptoServiceFactory(
|
|
|
|
cache: { cryptoService?: AbstractCryptoService } & CachedServices,
|
|
|
|
opts: CryptoServiceInitOptions,
|
|
|
|
): Promise<AbstractCryptoService> {
|
|
|
|
return factory(
|
|
|
|
cache,
|
|
|
|
"cryptoService",
|
|
|
|
opts,
|
|
|
|
async () =>
|
2022-10-18 19:03:09 +02:00
|
|
|
new BrowserCryptoService(
|
2024-02-23 14:48:15 +01:00
|
|
|
await keyGenerationServiceFactory(cache, opts),
|
2022-08-29 20:46:42 +02:00
|
|
|
await cryptoFunctionServiceFactory(cache, opts),
|
|
|
|
await encryptServiceFactory(cache, opts),
|
|
|
|
await platformUtilsServiceFactory(cache, opts),
|
|
|
|
await logServiceFactory(cache, opts),
|
|
|
|
await stateServiceFactory(cache, opts),
|
2024-01-10 17:51:45 +01:00
|
|
|
await accountServiceFactory(cache, opts),
|
|
|
|
await stateProviderFactory(cache, opts),
|
2022-08-29 20:46:42 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|