fireblocks-sdk 2026.3.28

Rust implementation of the Fireblocks SDK
Documentation
// Fireblocks API
//
// Fireblocks provides a suite of applications to manage digital asset operations and a complete development platform to build your business on the blockchain.  - Visit our website for more information: [Fireblocks Website](https://fireblocks.com) - Visit our developer docs: [Fireblocks DevPortal](https://developers.fireblocks.com)
//
// The version of the OpenAPI document: 1.8.0
// Contact: developers@fireblocks.com
// Generated by: https://openapi-generator.tech

use {
    super::{Error, configuration},
    crate::{
        apis::{ContentType, ResponseContent},
        models,
    },
    async_trait::async_trait,
    reqwest,
    serde::{Deserialize, Serialize, de::Error as _},
    std::sync::Arc,
};

#[async_trait]
pub trait KeysBetaApi: Send + Sync {
    /// GET /keys/mpc/list
    ///
    /// Returns a list of MPC signing keys of the workspace. For each key, the
    /// list of players associated with it is attached. **Note:**  This endpoint
    /// is currently in beta and might be subject to changes.
    async fn get_mpc_keys_list(
        &self,
    ) -> Result<models::GetMpcKeysResponse, Error<GetMpcKeysListError>>;

    /// GET /keys/mpc/list/{userId}
    ///
    /// Returns a list of MPC signing keys of a specific user. For each key, the
    /// list of players associated with it is attached. **Note:** This endpoint
    /// is currently in beta and might be subject to changes.
    async fn get_mpc_keys_list_by_user(
        &self,
        params: GetMpcKeysListByUserParams,
    ) -> Result<models::GetMpcKeysResponse, Error<GetMpcKeysListByUserError>>;
}

pub struct KeysBetaApiClient {
    configuration: Arc<configuration::Configuration>,
}

impl KeysBetaApiClient {
    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
        Self { configuration }
    }
}

/// struct for passing parameters to the method
/// [`KeysBetaApi::get_mpc_keys_list_by_user`]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "bon", derive(::bon::Builder))]
pub struct GetMpcKeysListByUserParams {
    /// The id for the user
    pub user_id: String,
}

#[async_trait]
impl KeysBetaApi for KeysBetaApiClient {
    /// Returns a list of MPC signing keys of the workspace. For each key, the
    /// list of players associated with it is attached. **Note:**  This endpoint
    /// is currently in beta and might be subject to changes.
    async fn get_mpc_keys_list(
        &self,
    ) -> Result<models::GetMpcKeysResponse, Error<GetMpcKeysListError>> {
        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!("{}/keys/mpc/list", local_var_configuration.base_path);
        let mut local_var_req_builder =
            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
            local_var_req_builder = local_var_req_builder
                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
        }

        let local_var_req = local_var_req_builder.build()?;
        let local_var_resp = local_var_client.execute(local_var_req).await?;

        let local_var_status = local_var_resp.status();
        let local_var_content_type = local_var_resp
            .headers()
            .get("content-type")
            .and_then(|v| v.to_str().ok())
            .unwrap_or("application/octet-stream");
        let local_var_content_type = super::ContentType::from(local_var_content_type);
        let local_var_content = local_var_resp.text().await?;

        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
            match local_var_content_type {
                ContentType::Json => {
                    crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
                }
                ContentType::Text => {
                    return Err(Error::from(serde_json::Error::custom(
                        "Received `text/plain` content type response that cannot be converted to \
                         `models::GetMpcKeysResponse`",
                    )));
                }
                ContentType::Unsupported(local_var_unknown_type) => {
                    return Err(Error::from(serde_json::Error::custom(format!(
                        "Received `{local_var_unknown_type}` content type response that cannot be \
                         converted to `models::GetMpcKeysResponse`"
                    ))));
                }
            }
        } else {
            let local_var_entity: Option<GetMpcKeysListError> =
                serde_json::from_str(&local_var_content).ok();
            let local_var_error = ResponseContent {
                status: local_var_status,
                content: local_var_content,
                entity: local_var_entity,
            };
            Err(Error::ResponseError(local_var_error))
        }
    }

    /// Returns a list of MPC signing keys of a specific user. For each key, the
    /// list of players associated with it is attached. **Note:** This endpoint
    /// is currently in beta and might be subject to changes.
    async fn get_mpc_keys_list_by_user(
        &self,
        params: GetMpcKeysListByUserParams,
    ) -> Result<models::GetMpcKeysResponse, Error<GetMpcKeysListByUserError>> {
        let GetMpcKeysListByUserParams { user_id } = params;

        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!(
            "{}/keys/mpc/list/{userId}",
            local_var_configuration.base_path,
            userId = crate::apis::urlencode(user_id)
        );
        let mut local_var_req_builder =
            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
            local_var_req_builder = local_var_req_builder
                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
        }

        let local_var_req = local_var_req_builder.build()?;
        let local_var_resp = local_var_client.execute(local_var_req).await?;

        let local_var_status = local_var_resp.status();
        let local_var_content_type = local_var_resp
            .headers()
            .get("content-type")
            .and_then(|v| v.to_str().ok())
            .unwrap_or("application/octet-stream");
        let local_var_content_type = super::ContentType::from(local_var_content_type);
        let local_var_content = local_var_resp.text().await?;

        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
            match local_var_content_type {
                ContentType::Json => {
                    crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
                }
                ContentType::Text => {
                    return Err(Error::from(serde_json::Error::custom(
                        "Received `text/plain` content type response that cannot be converted to \
                         `models::GetMpcKeysResponse`",
                    )));
                }
                ContentType::Unsupported(local_var_unknown_type) => {
                    return Err(Error::from(serde_json::Error::custom(format!(
                        "Received `{local_var_unknown_type}` content type response that cannot be \
                         converted to `models::GetMpcKeysResponse`"
                    ))));
                }
            }
        } else {
            let local_var_entity: Option<GetMpcKeysListByUserError> =
                serde_json::from_str(&local_var_content).ok();
            let local_var_error = ResponseContent {
                status: local_var_status,
                content: local_var_content,
                entity: local_var_entity,
            };
            Err(Error::ResponseError(local_var_error))
        }
    }
}

/// struct for typed errors of method [`KeysBetaApi::get_mpc_keys_list`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetMpcKeysListError {
    DefaultResponse(models::ErrorSchema),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`KeysBetaApi::get_mpc_keys_list_by_user`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetMpcKeysListByUserError {
    DefaultResponse(models::ErrorSchema),
    UnknownValue(serde_json::Value),
}