Skip to content

Commit 670d852

Browse files
committed
chore: crate renaming + add readme
1 parent 810f835 commit 670d852

File tree

4 files changed

+116
-4
lines changed

4 files changed

+116
-4
lines changed

sdk/rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "dstack-sdk"
2+
name = "dstack-rust"
33
version = "0.1.0"
44
edition = "2024"
55

sdk/rust/README.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Dstack Crate
2+
3+
This crate provides a rust client for communicating with the dstack server, which available inside dstack.
4+
5+
## Installation
6+
7+
```toml
8+
[dependencies]
9+
dstack-rust = { git = "https://github.com/Dstack-TEE/dstack.git", package = "dstack-rust" }
10+
```
11+
12+
## Basic Usage
13+
14+
```rust
15+
use dstack_client::DstackClient;
16+
17+
#[tokio::main]
18+
async fn main() -> Result<(), Box<dyn std::error::Error>> {
19+
let client = DstackClient::new(None); // Uses env var or default to Unix socket
20+
21+
// Get system info
22+
let info = client.info().await?;
23+
println!("Instance ID: {}", info.instance_id);
24+
25+
// Derive a key
26+
let key_resp = client.get_key(Some("my-app".to_string()), None).await?;
27+
println!("Key: {}", key_resp.key);
28+
println!("Signature Chain: {:?}", key_resp.signature_chain);
29+
30+
// Generate TDX quote
31+
let quote_resp = client.get_quote(b"test-data".to_vec()).await?;
32+
println!("Quote: {}", quote_resp.quote);
33+
let rtmrs = quote_resp.replay_rtmrs()?;
34+
println!("Replayed RTMRs: {:?}", rtmrs);
35+
36+
// Emit an event
37+
client.emit_event("BootComplete".to_string(), b"payload-data".to_vec()).await?;
38+
39+
Ok(())
40+
}
41+
```
42+
43+
## Features
44+
### Initialization
45+
46+
```rust
47+
let client = DstackClient::new(Some("http://localhost:8000"));
48+
```
49+
- `endpoint`: Optional HTTP URL or Unix socket path (`/var/run/dstack.sock` by default)
50+
51+
- Will use the `DSTACK_SIMULATOR_ENDPOINT` environment variable if set
52+
53+
## Methods
54+
55+
### `info(): InfoResponse`
56+
57+
Fetches metadata and measurements about the CVM instance.
58+
59+
### `get_key(path: Option<String>, purpose: Option<String>) -> GetKeyResponse`
60+
61+
Derives a key for a specified path and optional purpose.
62+
63+
- `key`: Private key in hex format
64+
65+
- `signature_chain`: Vec of X.509 certificate chain entries
66+
67+
### `get_quote(report_data: Vec<u8>) -> GetQuoteResponse`
68+
69+
Generates a TDX quote with a custom 64-byte payload.
70+
71+
- `quote`: Hex-encoded quote
72+
73+
- `event_log`: Serialized list of events
74+
75+
- `replay_rtmrs()`: Reconstructs RTMR values from the event log
76+
77+
### `emit_event(event: String, payload: Vec<u8>)`
78+
Sends an event log with associated binary payload to the runtime.
79+
80+
### `get_tls_key(...) -> GetTlsKeyResponse`
81+
Requests a key and X.509 certificate chain for RA-TLS or server/client authentication.
82+
83+
### Structures
84+
- `GetKeyResponse`: Holds derived key and signature chain
85+
86+
- `GetQuoteResponse`: Contains the TDX quote and event log, with RTMR replay support
87+
88+
- `InfoResponse`: CVM instance metadata, including image and runtime measurements
89+
90+
## API Reference
91+
92+
### Running the Simulator
93+
94+
For local development without TDX devices, you can use the simulator under `sdk/simulator`.
95+
96+
Run the simulator with:
97+
98+
```bash
99+
git clone https://github.com/Dstack-TEE/dstack.git
100+
cd dstack/sdk/simulator
101+
./build.sh
102+
./dstack-simulator
103+
```
104+
Set the endpoint in your environment:
105+
106+
```
107+
export DSTACK_SIMULATOR_ENDPOINT=http://localhost:8000
108+
```
109+
110+
## License
111+
112+
Apache License

sdk/rust/tests/test_client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use dstack_sdk::dstack_client::DstackClient as AsyncDstackClient;
1+
use dstack_rust::dstack_client::DstackClient as AsyncDstackClient;
22
use evidence_api::tdx::quote::TdxQuote;
33
use tokio;
44

sdk/rust/tests/test_eth.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use dstack_sdk::dstack_client::{ DstackClient, GetKeyResponse };
2-
use dstack_sdk::ethereum::to_account;
1+
use dstack_rust::dstack_client::{ DstackClient, GetKeyResponse };
2+
use dstack_rust::ethereum::to_account;
33
use tokio;
44

55
#[tokio::test]

0 commit comments

Comments
 (0)