OpenSecret Rust SDK
Rust SDK for OpenSecret - secure AI API interactions with nitro attestation.
Features
- 🔐 Nitro Attestation: Verify server identity through AWS Nitro Enclaves
- 🔑 End-to-End Encryption: All API calls encrypted with session keys
- 👤 Authentication: Support for both email-based and guest users
- 🔄 Token Management: Automatic token refresh and session management
- 🛡️ Secure by Default: No plaintext data transmission
Installation
Add to your Cargo.toml:
[]
= "0.1.0"
Quick Start
use ;
use Uuid;
async
Authentication
User Registration
Register with email:
let response = client.register.await?;
Register as guest (no email):
let response = client.register_guest.await?;
Login
Login with email:
let response = client.login.await?;
Login with user ID (guests only):
let response = client.login_with_id.await?;
Token Management
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?;
Session Management
Every API call requires an encrypted session:
- Attestation Handshake: Establishes trust and exchanges encryption keys
- Encrypted Communication: All subsequent calls use the session key
- Token Authentication: Protected endpoints require valid access tokens
// Required before any API calls
client.perform_attestation_handshake.await?;
// Check session status
if let Some = client.get_session_id?
Error Handling
The SDK uses a custom Error type with detailed error variants:
use Error;
match client.login.await
Testing
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)
# With output
# Specific test
Examples
See the examples/ directory for complete examples:
# Basic authentication flow
Security Considerations
- Always verify attestation in production environments
- Store tokens securely - the SDK keeps them in memory only
- Use HTTPS for all production API calls
- Rotate tokens regularly using the refresh mechanism
- Clear sessions after use with
logout()
License
MIT