Crates.io | sindri |
lib.rs | sindri |
version | 0.1.0 |
source | src |
created_at | 2024-05-13 07:30:36.412311 |
updated_at | 2024-07-19 05:27:04.041675 |
description | Rust SDK for the Sindri API |
homepage | |
repository | https://github.com/Sindri-Labs/sindri-rs |
max_upload_size | |
id | 1238132 |
size | 15,021 |
The Sindri Rust SDK is under active development.
Create a new Rust project.
cargo new sindri-sdk-test
In your root directory, add a .env
file to store your Sindri API key.
API_KEY="YOUR_SINDRI_API_KEY"
Add the following dependencies to your Cargo.toml
:
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:
.
├── Cargo.lock
├── Cargo.toml
├── example-input.json
├── noir-circuit
│ ├── Nargo.toml
│ ├── Prover.toml
│ ├── sindri.json
│ └── src
│ └── main.nr
└── src
└── main.rs
The Sindri CLI will generate a samle Noir circuit.
The Noir circuit code is contained in the src/main.nr file. The Sindri CLI will generate a simple equiavlence circuit.
// 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);
}
[package]
name = "sample_circuit"
type = "bin"
authors = [""]
compiler_version = "0.23.0"
[dependencies]
X = 5
Y = 5
Your sindri.json file for vary depending on your circuit type. For Noir, it will resemble the following schema:
{
"$schema": "https://sindri.app/api/v1/sindri-manifest-schema.json",
"name": "sample_circuit",
"circuitType": "noir",
"provingScheme": "barretenberg",
"noirVersion": "0.23.0"
}
A client is created as follows:
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/
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.
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");
}