> ## Documentation Index
> Fetch the complete documentation index at: https://docs.verity.usher.so/llms.txt
> Use this file to discover all available pages before exploring further.

# Rust

> A Rust client SDK for interacting with Verity Prover

The Verity Client SDK is a Rust-based client library that enables interaction with the Verity Prover service. It's built on top of the `reqwest` HTTP client and provides a convenient interface for making verifiable HTTP requests.

To read the docs.rs documentation on the `verity-client` crate, please visit: [https://usherlabs.github.io/verity-dp/packages/verity-client/doc/verity\_client/index.html](https://usherlabs.github.io/verity-dp/packages/verity-client/doc/verity_client/index.html)

## Installation

Add the following to your `Cargo.toml`:

```toml theme={null}
[dependencies]
verity-client = "0.1.0"
```

## `VerityClient`

The main client struct that handles all interactions with the Verity Prover service. It's built upon reqwest and provides methods for making HTTP requests with built-in verification.

```rust theme={null}
let config = VerityClientConfig {
    prover_url: String::from("http://127.0.0.1:8080"),
};

let client = VerityClient::new(config);
```

## Request Building

The SDK provides a builder pattern for constructing requests. You can:

* Make GET and POST requests
* Add headers
* Set request bodies
* Configure redaction rules

## Making Requests

### GET Request Example

Here's how to make a simple GET request:

```rust theme={null}
let response = VerityClient::new(config)
    .get("https://api.example.com/data")
    .send()
    .await?;
```

### POST Request with JSON

For POST requests with JSON payload:

```rust theme={null}
let response = VerityClient::new(config)
    .post("https://api.example.com/data")
    .json(&serde_json::json!({
        "userId": 1000,
        "firstName": "John"
    }))
    .send()
    .await?;
```

## Data Redaction

The SDK supports redacting sensitive information from both requests and responses in the generated TLS proofs using the `redact()` method:

```rust theme={null}
let client = VerityClient::new(config);
let response = client
    .post("https://api.example.com/users")
    .redact(String::from("req:body:firstName, res:body:firstName"))
    .json(&user_data)
    .send()
    .await?;
```

## Response Handling

The SDK returns a `VerityResponse` struct containing:

* The original response (`subject`)
* A proof of the request/response interaction (`proof`)
* The notary's public key (`notary_pub_key`)

## Advanced Features

### Notary Information

You can retrieve information about the connected notary:

```rust theme={null}
let notary_info = client.get_notary_info().await?;
println!("Notary Version: {}", notary_info.version);
println!("Public Key: {}", notary_info.public_key);
```

### Response to Proof Timeout

The SDK implements a default proof timeout of 1000ms, after which it will cancel the proof awaiting process if no proof is received.
This is the time to wait for a proof received over SSE connection since receiving HTTP response.

### Error Handling

The SDK uses anyhow for error handling, providing detailed error information when requests fail. All async operations return Result types that should be properly handled:

```rust theme={null}
match client.get("https://api.example.com/data").send().await {
    Ok(response) => {
        println!("Response received with proof");
    },
    Err(e) => {
        eprintln!("Request failed: {}", e);
    }
}
```

## Examples

### Basic GET Request

```rust theme={null}
#[tokio::main()]
async fn main() -> anyhow::Result<()> {
    let config = VerityClientConfig {
        prover_url: String::from("http://127.0.0.1:8080"),
    };

    let response = VerityClient::new(config)
        .get("https://jsonplaceholder.typicode.com/posts/98")
        .redact(String::from("res:body:dolor"))
        .send()
        .await?;

    println!("{:#?}", response);
    Ok(())
}
```

### POST Request with Redaction

```rust theme={null}
#[tokio::main()]
async fn main() -> anyhow::Result<()> {
    let config = VerityClientConfig {
        prover_url: String::from("http://127.0.0.1:8080"),
    };

    let response = VerityClient::new(config)
        .post("https://jsonplaceholder.typicode.com/posts")
        .redact(String::from("req:body:firstName, res:body:firstName"))
        .json(&serde_json::json!({
            "userId": 1000,
            "firstName": "John",
            "lastName": "Smith",
            "fullName": "John Smith"
        }))
        .send()
        .await?;

    println!("{:#?}", response);
    Ok(())
}
```

## Technical Details

The SDK is built on several key components:

* `reqwest` for HTTP client functionality
* `tokio` for async runtime
* `serde` for JSON serialization/deserialization
* Event Source implementation for proof streaming
* UUID v4 for request identification

For more detailed information about the implementation, [refer to the source code](https://github.com/usherlabs/verity-dp/tree/main/rs/verity-client), [review the docs.rs](https://usherlabs.github.io/verity-dp/packages/verity-client/doc/verity_client/index.html), or [contact the Usher Labs team](https://go.usher.so/discord).
