| Crates.io | opensecret |
| lib.rs | opensecret |
| version | 0.2.1 |
| created_at | 2025-08-20 16:50:34.684299+00 |
| updated_at | 2025-09-12 18:26:09.506485+00 |
| description | Rust SDK for OpenSecret - secure AI API interactions with nitro attestation |
| homepage | https://opensecret.cloud |
| repository | https://github.com/OpenSecretCloud/OpenSecret-SDK |
| max_upload_size | |
| id | 1803700 |
| size | 248,519 |
Rust SDK for OpenSecret - secure AI API interactions with nitro attestation.
Add to your Cargo.toml:
[dependencies]
opensecret = "0.1.0"
use opensecret::{OpenSecretClient, Result};
use uuid::Uuid;
#[tokio::main]
async fn main() -> Result<()> {
// Initialize client
let client = OpenSecretClient::new("https://api.opensecret.com")?;
let client_id = Uuid::parse_str("your-client-id")?;
// Establish secure session
client.perform_attestation_handshake().await?;
// Register and login
let response = client.register(
"user@example.com".to_string(),
"password".to_string(),
client_id,
Some("John Doe".to_string())
).await?;
println!("Logged in as: {}", response.id);
Ok(())
}
Register with email:
let response = client.register(
email,
password,
client_id,
Some(name) // Optional
).await?;
Register as guest (no email):
let response = client.register_guest(
password,
client_id
).await?;
Login with email:
let response = client.login(
email,
password,
client_id
).await?;
Login with user ID (guests only):
let response = client.login_with_id(
user_id,
password,
client_id
).await?;
Tokens are automatically stored after login/registration. You can:
// Get current tokens
let access_token = client.get_access_token()?;
let refresh_token = client.get_refresh_token()?;
// Refresh tokens
client.refresh_token().await?;
// Logout (clears session and tokens)
client.logout().await?;
Every API call requires an encrypted session:
// Required before any API calls
client.perform_attestation_handshake().await?;
// Check session status
if let Some(session_id) = client.get_session_id()? {
println!("Active session: {}", session_id);
}
The SDK uses a custom Error type with detailed error variants:
use opensecret::Error;
match client.login(email, password, client_id).await {
Ok(response) => println!("Success!"),
Err(Error::Authentication(msg)) => println!("Auth failed: {}", msg),
Err(Error::Api { status, message }) => println!("API error {}: {}", status, message),
Err(e) => println!("Other error: {}", e),
}
The SDK reads configuration from .env.local in the parent directory (OpenSecret-SDK root), matching the TypeScript SDK setup.
Required environment variables in .env.local:
VITE_OPEN_SECRET_API_URL=http://localhost:3000
VITE_TEST_CLIENT_ID=your-client-id-uuid
Run tests:
# All tests (requires running server on localhost:3000)
cargo test
# With output
cargo test -- --nocapture
# Specific test
cargo test test_login_signup_flow -- --nocapture
See the examples/ directory for complete examples:
# Basic authentication flow
cargo run --example auth_example
logout()MIT