Add createAccountKeys API (#1240)

This commit is contained in:
David Perez
2024-04-08 14:39:22 -05:00
committed by Álison Fernandes
parent 79f8703d9b
commit 8be7d0f8df
5 changed files with 53 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
package com.x8bit.bitwarden.data.auth.datasource.network.api
import com.x8bit.bitwarden.data.auth.datasource.network.model.CreateAccountKeysRequest
import com.x8bit.bitwarden.data.auth.datasource.network.model.DeleteAccountRequestJson
import com.x8bit.bitwarden.data.auth.datasource.network.model.ResetPasswordRequestJson
import com.x8bit.bitwarden.data.auth.datasource.network.model.SetPasswordRequestJson
@@ -11,6 +12,12 @@ import retrofit2.http.POST
* Defines raw calls under the /accounts API with authentication applied.
*/
interface AuthenticatedAccountsApi {
/**
* Creates the keys for the current account.
*/
@POST("/accounts/keys")
suspend fun createAccountKeys(@Body body: CreateAccountKeysRequest): Result<Unit>
/**
* Deletes the current account.
*/

View File

@@ -0,0 +1,13 @@
package com.x8bit.bitwarden.data.auth.datasource.network.model
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
/**
* Represents the request body used to create the keys for an account.
*/
@Serializable
data class CreateAccountKeysRequest(
@SerialName("PublicKey") val publicKey: String,
@SerialName("EncryptedPrivateKey") val encryptedPrivateKey: String,
)

View File

@@ -13,6 +13,11 @@ import com.x8bit.bitwarden.data.auth.datasource.network.model.SetPasswordRequest
*/
interface AccountsService {
/**
* Creates a new account's keys.
*/
suspend fun createAccountKeys(publicKey: String, encryptedPrivateKey: String): Result<Unit>
/**
* Make delete account request.
*/

View File

@@ -2,6 +2,7 @@ package com.x8bit.bitwarden.data.auth.datasource.network.service
import com.x8bit.bitwarden.data.auth.datasource.network.api.AccountsApi
import com.x8bit.bitwarden.data.auth.datasource.network.api.AuthenticatedAccountsApi
import com.x8bit.bitwarden.data.auth.datasource.network.model.CreateAccountKeysRequest
import com.x8bit.bitwarden.data.auth.datasource.network.model.DeleteAccountRequestJson
import com.x8bit.bitwarden.data.auth.datasource.network.model.PasswordHintRequestJson
import com.x8bit.bitwarden.data.auth.datasource.network.model.PasswordHintResponseJson
@@ -22,6 +23,17 @@ class AccountsServiceImpl(
private val json: Json,
) : AccountsService {
override suspend fun createAccountKeys(
publicKey: String,
encryptedPrivateKey: String,
): Result<Unit> =
authenticatedAccountsApi.createAccountKeys(
body = CreateAccountKeysRequest(
publicKey = publicKey,
encryptedPrivateKey = encryptedPrivateKey,
),
)
override suspend fun deleteAccount(masterPasswordHash: String): Result<Unit> =
authenticatedAccountsApi.deleteAccount(DeleteAccountRequestJson(masterPasswordHash))