# Sindri Rust SDK The Sindri Rust SDK is under active development. # Setup Create a new Rust project. ```bash cargo new sindri-sdk-test ``` In your root directory, add a `.env` file to store your Sindri API key. ``` bash API_KEY="YOUR_SINDRI_API_KEY" ``` Add the following dependencies to your `Cargo.toml`: ```bash cargo add sindri dotenvy tokio --features tokio/full ``` In this example, we will use a Noir circuit that was generated from the Sindri CLI. Information on how to use the Sindri CLI can be found here: https://sindri.app/docs/getting-started/cli/ For simplicity, circuit files are added to the root directory. Your directory tree should look like this: ```bash . ├── Cargo.lock ├── Cargo.toml ├── example-input.json ├── noir-circuit │ ├── Nargo.toml │ ├── Prover.toml │ ├── sindri.json │ └── src │ └── main.nr └── src └── main.rs ``` # Noir circuit files The Sindri CLI will generate a samle Noir circuit. ## noir-circuit/src/main.nr The Noir circuit code is contained in the src/main.nr file. The Sindri CLI will generate a simple equiavlence circuit. ```RUST // Define the main function for the circuit. fn main(X: Field, Y: pub Field) { // Put your code here... // Enforce the constraint that X must equal Y. assert(X == Y); } ``` ## nargo.toml ```RUST [package] name = "sample_circuit" type = "bin" authors = [""] compiler_version = "0.23.0" [dependencies] ``` ## Prover.toml ```Rust X = 5 Y = 5 ``` ## sindri.json Your sindri.json file for vary depending on your circuit type. For Noir, it will resemble the following schema: ```JSON { "$schema": "https://sindri.app/api/v1/sindri-manifest-schema.json", "name": "sample_circuit", "circuitType": "noir", "provingScheme": "barretenberg", "noirVersion": "0.23.0" } ``` # Creating a client A client is created as follows: ```Rust let client = SindriBuilder::new(&api_key).build(); ``` The client allows you to compile and prove circuits, obtain circuit and proof metadata, and delete specific circuits and proofs. Information regarding the various Sindri API endpoints can be found here: https://sindri.app/docs/reference/api/ # Sample main.rs An example of a Rust program that uses the SDK to access all of the available API endpoints is shown below. The code compiles and proves a Noir circuit, fetches the circuit and proof metadata, obtains a list of all user circuits, obtains a list of proofs generated from a specific circuit, and finally deletes the circuit and the proof from the Sindri database. ```Rust use dotenvy::dotenv; use sindri::SindriBuilder; #[tokio::main] async fn main() { dotenv().expect("Failed to read .env file"); let api_key: String = std::env::var("API_KEY").unwrap(); let client = SindriBuilder::new(&api_key).build(); let circuit_id = client.upload_circuit("noir-sdk-test", "./noir-circuit").await.unwrap(); let proof_id = client.prove_circuit(&circuit_id, "example-input.json").await.unwrap(); let circuit_details = client.get_circuit_details(&circuit_id).await.unwrap(); let proof_details = client.get_proof_details(&proof_id).await.unwrap(); let circuits_list = client.get_all_circuits().await.unwrap(); let proofs_list = client.get_all_circuit_proofs(&circuit_id).await.unwrap(); println!("circuit details {:?}", circuit_details); println!("proof details {:?}", proof_details); println!("circuits list {:?}", circuits_list); println!("proofs list {:?}", proofs_list); std::thread::sleep(std::time::Duration::from_secs(1)); let _ = client.delete_proof(&proof_id).await.unwrap(); println!("proof succesfully deleted"); std::thread::sleep(std::time::Duration::from_secs(1)); let _ = client.delete_circuit(&circuit_id).await.unwrap(); println!("circuit successfully deleted"); } ```