2022-08-18 16:23:16 +02:00
|
|
|
import { CryptoFunctionService } from "@bitwarden/common/abstractions/cryptoFunction.service";
|
|
|
|
import { WebCryptoFunctionService } from "@bitwarden/common/services/webCryptoFunction.service";
|
|
|
|
|
|
|
|
import { CachedServices, factory, FactoryOptions } from "./factory-options";
|
|
|
|
|
|
|
|
type CryptoFunctionServiceFactoryOptions = FactoryOptions & {
|
|
|
|
cryptoFunctionServiceOptions: {
|
2022-10-19 15:55:57 +02:00
|
|
|
win: Window | typeof globalThis;
|
2022-08-18 16:23:16 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export type CryptoFunctionServiceInitOptions = CryptoFunctionServiceFactoryOptions;
|
|
|
|
|
|
|
|
export function cryptoFunctionServiceFactory(
|
|
|
|
cache: { cryptoFunctionService?: CryptoFunctionService } & CachedServices,
|
|
|
|
opts: CryptoFunctionServiceFactoryOptions
|
2022-08-29 20:46:42 +02:00
|
|
|
): Promise<CryptoFunctionService> {
|
2022-08-18 16:23:16 +02:00
|
|
|
return factory(
|
|
|
|
cache,
|
|
|
|
"cryptoFunctionService",
|
|
|
|
opts,
|
|
|
|
() => new WebCryptoFunctionService(opts.cryptoFunctionServiceOptions.win)
|
|
|
|
);
|
|
|
|
}
|