2 releases

new 0.1.1 May 1, 2025
0.1.0 Apr 29, 2025

#4 in #scp

39 downloads per month

MIT license

74KB
1.5K SLoC

Rust Connector for Klave

Overview

This crate provides the necessary tools for connecting/interacting with Klave applications. It enables seamless communication with Klave apps and supports various features for secure and efficient integration.

It covers:

  • Establishing secure WebSocket connections
  • Performing cryptographic handshake operations
  • Sending and receiving messages with callbacks
  • Managing periodic transactions
  • And more...

Getting Started

Bootstrap

You can start from scratch with cargo add klave-connector or
Fork the Rust Connector repository.

Develop

Develop your app in Rust using the Klave Connector. Ensure the Rust packages you are using are compatible with tokio and asynchronous programming.

Build

Build your project with:

cargo build --release

Deploy

Deploy your app on Klave or integrate it into your existing Rust application.

Usage

Example: Connecting to Klave

use klave_connector::SCP;
use klave_connector::Key;

#[tokio::main]
async fn main() {    
    let mut client = SCP::new("wss://klave-dev.secretarium.org/", None, None);

    match client.connect().await {
        Ok(_) => println!("Connected to Klave successfully."),
        Err(e) => {
            eprintln!("Failed to connect to Klave: {}", e);
            return;
        }
    };

    // Send a transaction
    let mut tx = client.new_tx("wasm-manager", "version", None, None).await;
    tx.on_error(|request_id, error_message| {
        eprintln!("Transaction error occurred. RequestId: {:?}, Error: {:?}", request_id, error_message);
    });
    tx.on_result(|request_id, result| {
        eprintln!("Result received. RequestId: {:?}, Result: {:?}", request_id, result);
    });
    let _ = tx.send().await;

    match client.close().await {
        Ok(_) => println!("Connection closed successfully."),
        Err(e) => eprintln!("Failed to close connection: {}", e),
    };
}

Features

  • Secure WebSocket Communication: Establish encrypted WebSocket connections with Klave apps.
  • Transaction Management: Send transactions with support for callbacks and periodic execution.
  • Cluster Negotiation: Handle cluster negotiations and gateway handshakes seamlessly.
  • Cryptographic Operations: Perform encryption and decryption using hardware-accelerated cryptography.
  • Customizable Callbacks: Define custom handlers for transaction results, errors, and states.

Contributing

Contributions to this crate are welcome! If you encounter any bugs or have suggestions for improvements, please open an issue on the GitHub repository.

License

This crate is licensed under the terms detailed in LICENSE.md.

Dependencies

~10–22MB
~341K SLoC