mirror of
https://github.com/bitwarden/browser
synced 2025-12-29 06:33:40 +00:00
* Move cryptofunction service to km * Fix formatting * Fix import * Fix build on desktop * Fix build on browser and tests
32 lines
1.2 KiB
TypeScript
32 lines
1.2 KiB
TypeScript
import { CryptoFunctionService } from "@bitwarden/common/key-management/crypto/abstractions/crypto-function.service";
|
|
import { WebCryptoFunctionService } from "@bitwarden/common/key-management/crypto/services/web-crypto-function.service";
|
|
|
|
export class RendererCryptoFunctionService
|
|
extends WebCryptoFunctionService
|
|
implements CryptoFunctionService
|
|
{
|
|
constructor(win: Window | typeof global) {
|
|
super(win);
|
|
}
|
|
|
|
// We can't use the `argon2-browser` implementation because it loads WASM and the Content Security Policy doesn't allow it.
|
|
// Rather than trying to weaken the policy, we'll just use the Node.js implementation though the IPC channel.
|
|
// Note that the rest of the functions on this service will be inherited from the WebCryptoFunctionService, as those work just fine.
|
|
async argon2(
|
|
password: string | Uint8Array,
|
|
salt: string | Uint8Array,
|
|
iterations: number,
|
|
memory: number,
|
|
parallelism: number,
|
|
): Promise<Uint8Array> {
|
|
if (typeof password === "string") {
|
|
password = new TextEncoder().encode(password);
|
|
}
|
|
if (typeof salt === "string") {
|
|
salt = new TextEncoder().encode(salt);
|
|
}
|
|
|
|
return await ipc.platform.crypto.argon2(password, salt, iterations, memory, parallelism);
|
|
}
|
|
}
|