fireblocks_sdk/apis/
keys_beta_api.rs

1// Fireblocks API
2//
3// 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)
4//
5// The version of the OpenAPI document: 1.8.0
6// Contact: developers@fireblocks.com
7// Generated by: https://openapi-generator.tech
8
9use {
10    super::{Error, configuration},
11    crate::{
12        apis::{ContentType, ResponseContent},
13        models,
14    },
15    async_trait::async_trait,
16    reqwest,
17    serde::{Deserialize, Serialize, de::Error as _},
18    std::sync::Arc,
19};
20
21#[async_trait]
22pub trait KeysBetaApi: Send + Sync {
23    /// GET /keys/mpc/list
24    ///
25    /// Returns a list of MPC signing keys of the workspace. For each key, the
26    /// list of players associated with it is attached. **Note:**  This endpoint
27    /// is currently in beta and might be subject to changes.
28    async fn get_mpc_keys_list(
29        &self,
30    ) -> Result<models::GetMpcKeysResponse, Error<GetMpcKeysListError>>;
31
32    /// GET /keys/mpc/list/{userId}
33    ///
34    /// Returns a list of MPC signing keys of a specific user. For each key, the
35    /// list of players associated with it is attached. **Note:** This endpoint
36    /// is currently in beta and might be subject to changes.
37    async fn get_mpc_keys_list_by_user(
38        &self,
39        params: GetMpcKeysListByUserParams,
40    ) -> Result<models::GetMpcKeysResponse, Error<GetMpcKeysListByUserError>>;
41}
42
43pub struct KeysBetaApiClient {
44    configuration: Arc<configuration::Configuration>,
45}
46
47impl KeysBetaApiClient {
48    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
49        Self { configuration }
50    }
51}
52
53/// struct for passing parameters to the method [`get_mpc_keys_list_by_user`]
54#[derive(Clone, Debug)]
55#[cfg_attr(feature = "bon", derive(::bon::Builder))]
56pub struct GetMpcKeysListByUserParams {
57    /// The id for the user
58    pub user_id: String,
59}
60
61#[async_trait]
62impl KeysBetaApi for KeysBetaApiClient {
63    /// Returns a list of MPC signing keys of the workspace. For each key, the
64    /// list of players associated with it is attached. **Note:**  This endpoint
65    /// is currently in beta and might be subject to changes.
66    async fn get_mpc_keys_list(
67        &self,
68    ) -> Result<models::GetMpcKeysResponse, Error<GetMpcKeysListError>> {
69        let local_var_configuration = &self.configuration;
70
71        let local_var_client = &local_var_configuration.client;
72
73        let local_var_uri_str = format!("{}/keys/mpc/list", local_var_configuration.base_path);
74        let mut local_var_req_builder =
75            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
76
77        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
78            local_var_req_builder = local_var_req_builder
79                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
80        }
81
82        let local_var_req = local_var_req_builder.build()?;
83        let local_var_resp = local_var_client.execute(local_var_req).await?;
84
85        let local_var_status = local_var_resp.status();
86        let local_var_content_type = local_var_resp
87            .headers()
88            .get("content-type")
89            .and_then(|v| v.to_str().ok())
90            .unwrap_or("application/octet-stream");
91        let local_var_content_type = super::ContentType::from(local_var_content_type);
92        let local_var_content = local_var_resp.text().await?;
93
94        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
95            match local_var_content_type {
96                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
97                ContentType::Text => {
98                    return Err(Error::from(serde_json::Error::custom(
99                        "Received `text/plain` content type response that cannot be converted to \
100                         `models::GetMpcKeysResponse`",
101                    )));
102                }
103                ContentType::Unsupported(local_var_unknown_type) => {
104                    return Err(Error::from(serde_json::Error::custom(format!(
105                        "Received `{local_var_unknown_type}` content type response that cannot be \
106                         converted to `models::GetMpcKeysResponse`"
107                    ))));
108                }
109            }
110        } else {
111            let local_var_entity: Option<GetMpcKeysListError> =
112                serde_json::from_str(&local_var_content).ok();
113            let local_var_error = ResponseContent {
114                status: local_var_status,
115                content: local_var_content,
116                entity: local_var_entity,
117            };
118            Err(Error::ResponseError(local_var_error))
119        }
120    }
121
122    /// Returns a list of MPC signing keys of a specific user. For each key, the
123    /// list of players associated with it is attached. **Note:** This endpoint
124    /// is currently in beta and might be subject to changes.
125    async fn get_mpc_keys_list_by_user(
126        &self,
127        params: GetMpcKeysListByUserParams,
128    ) -> Result<models::GetMpcKeysResponse, Error<GetMpcKeysListByUserError>> {
129        let GetMpcKeysListByUserParams { user_id } = params;
130
131        let local_var_configuration = &self.configuration;
132
133        let local_var_client = &local_var_configuration.client;
134
135        let local_var_uri_str = format!(
136            "{}/keys/mpc/list/{userId}",
137            local_var_configuration.base_path,
138            userId = crate::apis::urlencode(user_id)
139        );
140        let mut local_var_req_builder =
141            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
142
143        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
144            local_var_req_builder = local_var_req_builder
145                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
146        }
147
148        let local_var_req = local_var_req_builder.build()?;
149        let local_var_resp = local_var_client.execute(local_var_req).await?;
150
151        let local_var_status = local_var_resp.status();
152        let local_var_content_type = local_var_resp
153            .headers()
154            .get("content-type")
155            .and_then(|v| v.to_str().ok())
156            .unwrap_or("application/octet-stream");
157        let local_var_content_type = super::ContentType::from(local_var_content_type);
158        let local_var_content = local_var_resp.text().await?;
159
160        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
161            match local_var_content_type {
162                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
163                ContentType::Text => {
164                    return Err(Error::from(serde_json::Error::custom(
165                        "Received `text/plain` content type response that cannot be converted to \
166                         `models::GetMpcKeysResponse`",
167                    )));
168                }
169                ContentType::Unsupported(local_var_unknown_type) => {
170                    return Err(Error::from(serde_json::Error::custom(format!(
171                        "Received `{local_var_unknown_type}` content type response that cannot be \
172                         converted to `models::GetMpcKeysResponse`"
173                    ))));
174                }
175            }
176        } else {
177            let local_var_entity: Option<GetMpcKeysListByUserError> =
178                serde_json::from_str(&local_var_content).ok();
179            let local_var_error = ResponseContent {
180                status: local_var_status,
181                content: local_var_content,
182                entity: local_var_entity,
183            };
184            Err(Error::ResponseError(local_var_error))
185        }
186    }
187}
188
189/// struct for typed errors of method [`get_mpc_keys_list`]
190#[derive(Debug, Clone, Serialize, Deserialize)]
191#[serde(untagged)]
192pub enum GetMpcKeysListError {
193    DefaultResponse(models::ErrorSchema),
194    UnknownValue(serde_json::Value),
195}
196
197/// struct for typed errors of method [`get_mpc_keys_list_by_user`]
198#[derive(Debug, Clone, Serialize, Deserialize)]
199#[serde(untagged)]
200pub enum GetMpcKeysListByUserError {
201    DefaultResponse(models::ErrorSchema),
202    UnknownValue(serde_json::Value),
203}