volt-client-grpc
A Rust client library for connecting to TDX Volt servers via gRPC.
Overview
This library provides a Rust implementation for:
- Authenticating with Volt servers (direct and relayed connections)
- Managing persistent connections with automatic reconnection
- Making unary and streaming gRPC calls
- Resource management operations
- File operations
- Database operations
- Y.js/yrs document synchronization via SyncProvider
Proto File Compilation
This package includes protobuf definitions in the proto/volt_api/ directory. The build script uses tonic-build to compile these into Rust code.
packages/volt-client-grpc/
├── proto/
│ ├── sync.proto # Sync protocol definitions
│ └── volt_api/
│ └── tdx/volt_api/
│ ├── volt/ # Main Volt API
│ ├── data/ # Database API
│ ├── relay/ # Relay API
│ └── proto_db_sync/ # DB sync protocol
├── src/
└── build.rs
The proto files are automatically compiled during the build process.
Generated Types
The following modules are generated from proto files:
proto::volt- Main Volt API (authentication, resources, connections)proto::data- Database API (SQLite operations)proto::relay- Relay API (for relayed connections through cloud relay)proto::proto_db_sync- Database sync protocol
Installation
Add to your Cargo.toml:
[]
= { = "path/to/volt-client-grpc" }
Usage
Basic Connection
use ;
async
Configuration
Configuration can be provided in several ways:
use ;
// From a file
let source: ConfigSource = "volt.config.json".into;
// From a config struct
let config = VoltClientConfig ;
let source: ConfigSource = config.into;
// From JSON
let source: ConfigSource = json!.into;
Configuration File Format
Authentication Options
use InitialiseOptions;
// Default DID-based authentication
let options = default;
// Session-only authentication (no DID)
let options = new.with_no_did;
// Manage your own DID
let options = new.with_own_did;
// Use an exchange token
let options = new
.with_exchange_token;
// Custom DID registries
let options = new
.with_did_registries;
Resource Operations
// Get a resource
let resource = client.get_resource.await?;
// Save a resource
let result = client.save_resource.await?;
// Delete a resource
let result = client.delete_resource.await?;
// Request access to a resource
use VoltAccessType;
let granted = client.request_access_blocking.await?;
Database Operations
// Create a database
let result = client.create_database.await?;
// Bulk update
let result = client.bulk_update.await?;
API Reference
VoltClient
The main client struct for interacting with a Volt server.
Methods
new()- Create a new clientinitialise(config, options)- Initialize with configurationinitialise_and_connect(config, options, hello)- Initialize and connectconnect(hello)- Connect to the serverdisconnect()- Disconnect from the serveris_connected()- Check connection statusclose()- Close and release resources
Resource Management
can_access_resource(request)- Check resource accessdelete_resource(request)- Delete a resourceget_resource(request)- Get a resourceget_resources(request)- Get multiple resourcessave_resource(request)- Save a resourcerequest_access(request)- Request resource access
File Operations
get_file_content(request)- Get file contentset_file_content(request)- Set file contentget_file_descendants(request)- Get file descendants
Database Operations
create_database(request)- Create a databasebulk_update(request)- Bulk update
VoltCredential
Manages authentication credentials.
VoltConnection
Manages the persistent connection with automatic reconnection.
Examples
See the examples/ directory for complete working examples:
| Example | Description |
|---|---|
grpc-client |
Basic gRPC client connection |
grpc-create-resource |
Create resources via gRPC |
sync-provider |
Y.js document synchronization |
sync-provider-with-subdocs |
Subdocument sync with events |
sync-manager-example |
High-level SyncManager API |
subdoc-writer |
Interactive subdocument editing |
Run an example:
Features
- Async/Await: Built on Tokio for async operations
- TLS Support: Secure connections using rustls
- Auto-Reconnect: Automatic reconnection on disconnect
- DID Support: Decentralized identifier authentication
- Streaming: Support for bidirectional streaming RPCs
Comparison with JavaScript Version
| Feature | JavaScript | Rust |
|---|---|---|
| Runtime | Node.js | Tokio |
| gRPC | @grpc/grpc-js | tonic |
| TLS | Node crypto | rustls |
| Crypto | Node crypto | ring, ed25519-dalek |
| Events | EventEmitter | mpsc channels |
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.