add api service

This commit is contained in:
Thomas Avery 2024-10-25 16:55:13 -05:00
parent bacb7cd7a0
commit 6f169534ca
No known key found for this signature in database
GPG Key ID: 44A02A0410B0F429
3 changed files with 43 additions and 0 deletions

View File

@ -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<void>;
}

View File

@ -0,0 +1,6 @@
import { EncString } from "@bitwarden/common/platform/models/domain/enc-string";
export class KeyRegenerationRequest {
userPublicKey: string;
userKeyEncryptedUserPrivateKey: EncString;
}

View File

@ -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<void> {
const request: KeyRegenerationRequest = {
userPublicKey,
userKeyEncryptedUserPrivateKey,
};
await this.apiService.send(
"POST",
"/accounts/key-management/regenerate-keys",
request,
true,
true,
);
}
}