diff --git a/libs/key-management/src/user-asymmetric-key-regeneration/abstractions/user-asymmetric-key-regeneration-api.service.ts b/libs/key-management/src/user-asymmetric-key-regeneration/abstractions/user-asymmetric-key-regeneration-api.service.ts new file mode 100644 index 0000000000..aac47be71b --- /dev/null +++ b/libs/key-management/src/user-asymmetric-key-regeneration/abstractions/user-asymmetric-key-regeneration-api.service.ts @@ -0,0 +1,8 @@ +import { EncString } from "@bitwarden/common/platform/models/domain/enc-string"; + +export abstract class UserAsymmetricKeysRegenerationApiService { + abstract regenerateUserAsymmetricKeys: ( + userPublicKey: string, + userKeyEncryptedUserPrivateKey: EncString, + ) => Promise; +} diff --git a/libs/key-management/src/user-asymmetric-key-regeneration/models/requests/key-regeneration.request.ts b/libs/key-management/src/user-asymmetric-key-regeneration/models/requests/key-regeneration.request.ts new file mode 100644 index 0000000000..044f58bb51 --- /dev/null +++ b/libs/key-management/src/user-asymmetric-key-regeneration/models/requests/key-regeneration.request.ts @@ -0,0 +1,6 @@ +import { EncString } from "@bitwarden/common/platform/models/domain/enc-string"; + +export class KeyRegenerationRequest { + userPublicKey: string; + userKeyEncryptedUserPrivateKey: EncString; +} diff --git a/libs/key-management/src/user-asymmetric-key-regeneration/services/default-user-asymmetric-key-regeneration-api.service.ts b/libs/key-management/src/user-asymmetric-key-regeneration/services/default-user-asymmetric-key-regeneration-api.service.ts new file mode 100644 index 0000000000..d1fe89a74e --- /dev/null +++ b/libs/key-management/src/user-asymmetric-key-regeneration/services/default-user-asymmetric-key-regeneration-api.service.ts @@ -0,0 +1,29 @@ +import { ApiService } from "@bitwarden/common/abstractions/api.service"; +import { EncString } from "@bitwarden/common/platform/models/domain/enc-string"; + +import { UserAsymmetricKeysRegenerationApiService } from "../abstractions/user-asymmetric-key-regeneration-api.service"; +import { KeyRegenerationRequest } from "../models/requests/key-regeneration.request"; + +export class DefaultUserAsymmetricKeysRegenerationApiService + implements UserAsymmetricKeysRegenerationApiService +{ + constructor(private apiService: ApiService) {} + + async regenerateUserAsymmetricKeys( + userPublicKey: string, + userKeyEncryptedUserPrivateKey: EncString, + ): Promise { + const request: KeyRegenerationRequest = { + userPublicKey, + userKeyEncryptedUserPrivateKey, + }; + + await this.apiService.send( + "POST", + "/accounts/key-management/regenerate-keys", + request, + true, + true, + ); + } +}