sindri_openapi/apis/
circuits_api.rs

1/*
2 * Sindri Labs API
3 *
4 *  ## About [Sindri Labs](https://www.sindri.app/)' API simplifies the developer experience to enable fast and scalable zero-knowledge proof generation. Front-End Dashboard: [https://sindri.app/login](https://sindri.app/login) ## Documentation The [Sindri Documentation](https://sindri.app/docs) contains everything you need to get started! ## Sindri Resources The [sindri-resources GitHub repo](https://github.com/Sindri-Labs/sindri-resources) contains contains resources and sample data for the Sindri API. ## Using this Page This is a standard [OpenAPI (Swagger)](https://swagger.io/specification/) API documentation page. It provides detailed documentation for each endpoint. This page enables easy prototyping via the \"Try it out\" feature! Since all Sindri endpoints require a valid API Key, in order to use the \"Try it out\" feature for any endpoint in this documentation you must first obtain an API key. Do this in one of two ways: 1. Enter your username and password in the `/api/apikey/generate` endpoint of the **Authorization** section below. Use the API key returned in the `access` field of the response. 2. Obtain an API key from the Sindri Dashboard team \"Account Settings\". After obtaining your API key, authorize your page session by entering your API Key in the `SindriAPIKeyBearerAuth` section, reached by clicking \"Authorize\" below. Proving Backend Version: v1.2.17
5 *
6 * The version of the OpenAPI document: v1.17.28
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{Deserialize, Serialize};
15
16/// struct for typed errors of method [`circuit_create`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum CircuitCreateError {
20    Status422(models::ValidationErrorResponse),
21    Status501(models::ComingSoonResponse),
22    Status500(models::SindriInternalErrorResponse),
23    Status400(models::SindriInvalidUploadResponse),
24    UnknownValue(serde_json::Value),
25}
26
27/// struct for typed errors of method [`circuit_delete`]
28#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum CircuitDeleteError {
31    Status404(models::CircuitDoesNotExistResponse),
32    Status500(models::SindriInternalErrorResponse),
33    UnknownValue(serde_json::Value),
34}
35
36/// struct for typed errors of method [`circuit_detail`]
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum CircuitDetailError {
40    Status404(models::CircuitDoesNotExistResponse),
41    Status500(models::SindriInternalErrorResponse),
42    UnknownValue(serde_json::Value),
43}
44
45/// struct for typed errors of method [`circuit_list`]
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum CircuitListError {
49    Status500(models::SindriInternalErrorResponse),
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`circuit_proofs`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum CircuitProofsError {
57    Status404(models::CircuitDoesNotExistResponse),
58    Status500(models::SindriInternalErrorResponse),
59    UnknownValue(serde_json::Value),
60}
61
62/// struct for typed errors of method [`proof_create`]
63#[derive(Debug, Clone, Serialize, Deserialize)]
64#[serde(untagged)]
65pub enum ProofCreateError {
66    Status404(models::CircuitDoesNotExistResponse),
67    Status409(models::CircuitIsNotReadyResponse),
68    Status400(models::ProofCannotBeCreatedResponse),
69    Status501(models::ComingSoonResponse),
70    UnknownValue(serde_json::Value),
71}
72
73/// Create a circuit.
74pub async fn circuit_create(
75    configuration: &configuration::Configuration,
76    files: Vec<u8>,
77    meta: Option<std::collections::HashMap<String, String>>,
78    tags: Option<Vec<String>>,
79) -> Result<models::CircuitInfoResponse, Error<CircuitCreateError>> {
80    // add a prefix to parameters to efficiently prevent name collisions
81    let p_files = files;
82    let p_meta = meta;
83    let p_tags = tags;
84
85    let uri_str = format!("{}/api/v1/circuit/create", configuration.base_path);
86    let mut req_builder = configuration
87        .client
88        .request(reqwest::Method::POST, &uri_str);
89
90    if let Some(ref user_agent) = configuration.user_agent {
91        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
92    }
93    if let Some(ref token) = configuration.bearer_access_token {
94        req_builder = req_builder.bearer_auth(token.to_owned());
95    };
96    if let Some(ref token) = configuration.bearer_access_token {
97        req_builder = req_builder.bearer_auth(token.to_owned());
98    };
99    // Build the request body directly in order to avoid a streaming request
100    // that is incompatible with the retry middleware
101    let boundary = "----------------------------4ebf00fbcf09";
102    req_builder = req_builder.header(
103        "Content-Type",
104        format!("multipart/form-data; boundary={boundary}"),
105    );
106
107    let filename = "rust_sdk_upload.tar.gz";
108    let mut byte_string = Vec::new();
109    byte_string.extend_from_slice(
110        format!(
111            "--{boundary}\r\n\
112            Content-Disposition: form-data; name=\"files\"; filename=\"{filename}\"\r\n\
113            \r\n",
114        )
115        .as_bytes(),
116    );
117    byte_string.extend(p_files);
118    byte_string.extend_from_slice(format!("--{boundary}--\r\n").as_bytes()); // End of files
119    if let Some(p_tags) = p_tags {
120        for tag in p_tags {
121            byte_string.extend_from_slice(
122                format!(
123                    "--{boundary}\r\n\
124                    Content-Disposition: form-data; name=\"tags\"\r\n\
125                    \r\n\
126                    {tag}\r\n"
127                )
128                .as_bytes(),
129            );
130            byte_string.extend_from_slice(format!("--{boundary}--\r\n").as_bytes());
131            // End of tag
132        }
133    }
134    if let Some(p_meta) = p_meta {
135        let meta_json = serde_json::to_string(&p_meta)?;
136        byte_string.extend_from_slice(
137            format!(
138                "--{boundary}\r\n\
139           Content-Disposition: form-data; name=\"meta\"\r\n\
140           Content-Type: application/json\r\n\
141            \r\n\
142            {meta_json}\r\n"
143            )
144            .as_bytes(),
145        );
146        byte_string.extend_from_slice(format!("--{boundary}--\r\n").as_bytes());
147        // End of meta
148    }
149    let local_var_body = reqwest::Body::from(byte_string);
150    req_builder = req_builder.body(local_var_body);
151
152    let req = req_builder.build()?;
153    let resp = configuration.client.execute(req).await?;
154
155    let status = resp.status();
156
157    if !status.is_client_error() && !status.is_server_error() {
158        let content = resp.text().await?;
159        serde_json::from_str(&content).map_err(Error::from)
160    } else {
161        let content = resp.text().await?;
162        let entity: Option<CircuitCreateError> = serde_json::from_str(&content).ok();
163        Err(Error::ResponseError(ResponseContent {
164            status,
165            content,
166            entity,
167        }))
168    }
169}
170
171/// Delete a circuit.
172pub async fn circuit_delete(
173    configuration: &configuration::Configuration,
174    circuit_id: &str,
175) -> Result<models::ActionResponse, Error<CircuitDeleteError>> {
176    // add a prefix to parameters to efficiently prevent name collisions
177    let p_circuit_id = circuit_id;
178
179    let uri_str = format!(
180        "{}/api/v1/circuit/{circuit_id}/delete",
181        configuration.base_path,
182        circuit_id = crate::apis::urlencode(p_circuit_id)
183    );
184    let mut req_builder = configuration
185        .client
186        .request(reqwest::Method::DELETE, &uri_str);
187
188    if let Some(ref user_agent) = configuration.user_agent {
189        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
190    }
191    if let Some(ref token) = configuration.bearer_access_token {
192        req_builder = req_builder.bearer_auth(token.to_owned());
193    };
194    if let Some(ref token) = configuration.bearer_access_token {
195        req_builder = req_builder.bearer_auth(token.to_owned());
196    };
197
198    let req = req_builder.build()?;
199    let resp = configuration.client.execute(req).await?;
200
201    let status = resp.status();
202
203    if !status.is_client_error() && !status.is_server_error() {
204        let content = resp.text().await?;
205        serde_json::from_str(&content).map_err(Error::from)
206    } else {
207        let content = resp.text().await?;
208        let entity: Option<CircuitDeleteError> = serde_json::from_str(&content).ok();
209        Err(Error::ResponseError(ResponseContent {
210            status,
211            content,
212            entity,
213        }))
214    }
215}
216
217/// Get info for an existing circuit.
218pub async fn circuit_detail(
219    configuration: &configuration::Configuration,
220    circuit_id: &str,
221    include_verification_key: Option<bool>,
222) -> Result<models::CircuitInfoResponse, Error<CircuitDetailError>> {
223    // add a prefix to parameters to efficiently prevent name collisions
224    let p_circuit_id = circuit_id;
225    let p_include_verification_key = include_verification_key;
226
227    let uri_str = format!(
228        "{}/api/v1/circuit/{circuit_id}/detail",
229        configuration.base_path,
230        circuit_id = crate::apis::urlencode(p_circuit_id)
231    );
232    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
233
234    if let Some(ref param_value) = p_include_verification_key {
235        req_builder = req_builder.query(&[("include_verification_key", &param_value.to_string())]);
236    }
237    if let Some(ref user_agent) = configuration.user_agent {
238        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
239    }
240    if let Some(ref token) = configuration.bearer_access_token {
241        req_builder = req_builder.bearer_auth(token.to_owned());
242    };
243    if let Some(ref token) = configuration.bearer_access_token {
244        req_builder = req_builder.bearer_auth(token.to_owned());
245    };
246
247    let req = req_builder.build()?;
248    let resp = configuration.client.execute(req).await?;
249
250    let status = resp.status();
251
252    if !status.is_client_error() && !status.is_server_error() {
253        let content = resp.text().await?;
254        serde_json::from_str(&content).map_err(Error::from)
255    } else {
256        let content = resp.text().await?;
257        let entity: Option<CircuitDetailError> = serde_json::from_str(&content).ok();
258        Err(Error::ResponseError(ResponseContent {
259            status,
260            content,
261            entity,
262        }))
263    }
264}
265
266/// List all circuits owned by team.
267pub async fn circuit_list(
268    configuration: &configuration::Configuration,
269) -> Result<Vec<models::CircuitInfoResponse>, Error<CircuitListError>> {
270    let uri_str = format!("{}/api/v1/circuit/list", configuration.base_path);
271    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
272
273    if let Some(ref user_agent) = configuration.user_agent {
274        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
275    }
276    if let Some(ref token) = configuration.bearer_access_token {
277        req_builder = req_builder.bearer_auth(token.to_owned());
278    };
279    if let Some(ref token) = configuration.bearer_access_token {
280        req_builder = req_builder.bearer_auth(token.to_owned());
281    };
282
283    let req = req_builder.build()?;
284    let resp = configuration.client.execute(req).await?;
285
286    let status = resp.status();
287
288    if !status.is_client_error() && !status.is_server_error() {
289        let content = resp.text().await?;
290        serde_json::from_str(&content).map_err(Error::from)
291    } else {
292        let content = resp.text().await?;
293        let entity: Option<CircuitListError> = serde_json::from_str(&content).ok();
294        Err(Error::ResponseError(ResponseContent {
295            status,
296            content,
297            entity,
298        }))
299    }
300}
301
302/// List all proofs for a circuit.
303pub async fn circuit_proofs(
304    configuration: &configuration::Configuration,
305    circuit_id: &str,
306) -> Result<Vec<models::ProofInfoResponse>, Error<CircuitProofsError>> {
307    // add a prefix to parameters to efficiently prevent name collisions
308    let p_circuit_id = circuit_id;
309
310    let uri_str = format!(
311        "{}/api/v1/circuit/{circuit_id}/proofs",
312        configuration.base_path,
313        circuit_id = crate::apis::urlencode(p_circuit_id)
314    );
315    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
316
317    if let Some(ref user_agent) = configuration.user_agent {
318        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
319    }
320    if let Some(ref token) = configuration.bearer_access_token {
321        req_builder = req_builder.bearer_auth(token.to_owned());
322    };
323    if let Some(ref token) = configuration.bearer_access_token {
324        req_builder = req_builder.bearer_auth(token.to_owned());
325    };
326
327    let req = req_builder.build()?;
328    let resp = configuration.client.execute(req).await?;
329
330    let status = resp.status();
331
332    if !status.is_client_error() && !status.is_server_error() {
333        let content = resp.text().await?;
334        serde_json::from_str(&content).map_err(Error::from)
335    } else {
336        let content = resp.text().await?;
337        let entity: Option<CircuitProofsError> = serde_json::from_str(&content).ok();
338        Err(Error::ResponseError(ResponseContent {
339            status,
340            content,
341            entity,
342        }))
343    }
344}
345
346/// Prove a circuit with specific inputs.
347pub async fn proof_create(
348    configuration: &configuration::Configuration,
349    circuit_id: &str,
350    circuit_prove_input: models::CircuitProveInput,
351) -> Result<models::ProofInfoResponse, Error<ProofCreateError>> {
352    // add a prefix to parameters to efficiently prevent name collisions
353    let p_circuit_id = circuit_id;
354    let p_circuit_prove_input = circuit_prove_input;
355
356    let uri_str = format!(
357        "{}/api/v1/circuit/{circuit_id}/prove",
358        configuration.base_path,
359        circuit_id = crate::apis::urlencode(p_circuit_id)
360    );
361    let mut req_builder = configuration
362        .client
363        .request(reqwest::Method::POST, &uri_str);
364
365    if let Some(ref user_agent) = configuration.user_agent {
366        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
367    }
368    if let Some(ref token) = configuration.bearer_access_token {
369        req_builder = req_builder.bearer_auth(token.to_owned());
370    };
371    if let Some(ref token) = configuration.bearer_access_token {
372        req_builder = req_builder.bearer_auth(token.to_owned());
373    };
374    req_builder = req_builder.json(&p_circuit_prove_input);
375
376    let req = req_builder.build()?;
377    let resp = configuration.client.execute(req).await?;
378
379    let status = resp.status();
380
381    if !status.is_client_error() && !status.is_server_error() {
382        let content = resp.text().await?;
383        serde_json::from_str(&content).map_err(Error::from)
384    } else {
385        let content = resp.text().await?;
386        let entity: Option<ProofCreateError> = serde_json::from_str(&content).ok();
387        Err(Error::ResponseError(ResponseContent {
388            status,
389            content,
390            entity,
391        }))
392    }
393}