zero-trust-sdk

Crates.iozero-trust-sdk
lib.rszero-trust-sdk
version0.1.0
created_at2025-09-27 09:13:19.042673+00
updated_at2025-09-27 09:13:19.042673+00
descriptionRust SDK for Zero Trust Blockchain Database - Secure, programmable access to zero-trust data storage
homepagehttps://zerotrust.com
repositoryhttps://github.com/your-org/zero-trust-sdk
max_upload_size
id1857116
size221,858
Erick Mwombek Lubere (mwombeki6)

documentation

https://docs.rs/zero-trust-sdk

README

Zero Trust Rust SDK

Rust SDK for Zero Trust Blockchain Database - Secure, programmable access to zero-trust data storage.

A Rust client library for the Zero Trust Blockchain Database System, where user authentication/management is handled by traditional PostgreSQL, while application data lives entirely on-chain. Provides immutable, auditable, and verifiable data storage with familiar SQL interfaces.

Installation

Add this to your Cargo.toml:

[dependencies]
zero-trust-sdk = "0.1.0"

Quick Start

use zero_trust_sdk::{ZeroTrustClient, Config};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let config = Config::new("http://localhost:3000", "your-api-key");
    let client = ZeroTrustClient::new(config).await?;

    // Authenticate
    client.auth().login("username", "password").await?;

    // Query data
    let result = client.database().query("SELECT * FROM users").await?;
    println!("Query result: {:?}", result);

    Ok(())
}

Features

  • Async/await support - Built on Tokio for non-blocking operations
  • Type-safe API - Leverages Rust's type system for safer database operations
  • Flexible authentication - Support for traditional login and Web3 wallet authentication
  • SQL interface - Familiar SQL syntax for blockchain data operations
  • Migration support - Database schema migration capabilities
  • Configuration management - File-based and programmatic configuration
  • Error handling - Comprehensive error types with detailed context

Authentication

Traditional Login

client.auth().login("username", "password").await?;

Web3 Wallet Authentication

client.auth().wallet_auth("0x...", "signature").await?;

Database Operations

Querying Data

let users = client.database().query("SELECT * FROM users WHERE active = true").await?;

Creating Tables

client.database().create_table("users", vec![
    ("id", "SERIAL PRIMARY KEY"),
    ("name", "VARCHAR(100)"),
    ("email", "VARCHAR(255) UNIQUE"),
    ("created_at", "TIMESTAMP DEFAULT CURRENT_TIMESTAMP"),
]).await?;

Inserting Data

client.database().execute(
    "INSERT INTO users (name, email) VALUES ($1, $2)",
    vec!["John Doe", "john@example.com"]
).await?;

Configuration

Environment Variables

ZERO_TRUST_API_URL=http://localhost:3000
ZERO_TRUST_API_KEY=your-api-key

Configuration File

Create a zero_trust.toml file:

api_url = "http://localhost:3000"
api_key = "your-api-key"
timeout = 30
retry_attempts = 3

Programmatic Configuration

let config = Config::builder()
    .api_url("http://localhost:3000")
    .api_key("your-api-key")
    .timeout(Duration::from_secs(30))
    .retry_attempts(3)
    .build();

Examples

See the examples/ directory for complete usage examples:

  • examples/test_sdk.rs - Basic SDK usage and operations

Development

Running Examples

cargo run --example test_sdk

Running Tests

cargo test

With Features

# Enable all features
cargo build --features full

# Enable specific features
cargo build --features "migration sync logging"

Features

  • default: Enables migration and sync features
  • migration: Database migration support with progress indicators
  • sync: Synchronous database operations
  • logging: Structured logging with tracing
  • full: All features enabled

Error Handling

The SDK provides comprehensive error types:

use zero_trust_sdk::error::{ZeroTrustError, AuthError, DatabaseError};

match client.auth().login("user", "pass").await {
    Ok(_) => println!("Login successful"),
    Err(ZeroTrustError::Auth(AuthError::InvalidCredentials)) => {
        println!("Invalid username or password");
    },
    Err(ZeroTrustError::Network(e)) => {
        println!("Network error: {}", e);
    },
    Err(e) => println!("Other error: {}", e),
}

License

MIT License - see LICENSE file for details.

Contributing

Please refer to the main Zero Trust project repository for contribution guidelines.

Commit count: 0

cargo fmt