dstack SDK for Rust
Access TEE features from your Rust application running inside dstack. Derive deterministic keys, generate attestation quotes, create TLS certificates, and sign data—all backed by hardware security.
Installation
[]
= { = "https://github.com/Dstack-TEE/dstack.git" }
Quick Start
use DstackClient;
async
The client automatically connects to /var/run/dstack.sock. For local development with the simulator:
let client = new;
Core API
Derive Keys
get_key() derives deterministic keys bound to your application's identity (app_id). The same path always produces the same key for your app, but different apps get different keys even with the same path.
// Derive keys by path
let eth_key = client.get_key.await?;
let btc_key = client.get_key.await?;
// Use path to separate keys
let mainnet_key = client.get_key.await?;
let testnet_key = client.get_key.await?;
Parameters:
path: Key derivation path (determines the key)purpose(optional): Included in signature chain message, does not affect the derived key
Returns: GetKeyResponse
key: Hex-encoded private keysignature_chain: Signatures proving the key was derived in a genuine TEE
Generate Attestation Quotes
get_quote() creates a TDX quote proving your code runs in a genuine TEE.
let quote = client.get_quote.await?;
// Replay RTMRs from the event log
let rtmrs = quote.replay_rtmrs?;
println!;
Parameters:
report_data: Exactly 64 bytes recommended. If shorter, pad with zeros. If longer, hash it first (e.g., SHA-256).
Returns: GetQuoteResponse
quote: Hex-encoded TDX quoteevent_log: JSON string of measured eventsreplay_rtmrs(): Method to compute RTMR values from event log
Get Instance Info
let info = client.info.await?;
println!;
println!;
println!;
Returns: InfoResponse
app_id: Application identifierinstance_id: Instance identifierapp_name: Application nametcb_info: TCB measurements (JSON string)compose_hash: Hash of the app configurationapp_cert: Application certificate (PEM)
attest(report_data: Vec<u8>) -> AttestResponse
Generates a versioned attestation with a custom 64-byte payload.
attestation: Hex-encoded attestation
emit_event(event: String, payload: Vec<u8>)
Sends an event log with associated binary payload to the runtime.
Generate TLS Certificates
get_tls_key() creates fresh TLS certificates. Unlike get_key(), each call generates a new random key.
use TlsKeyConfig;
let tls_config = builder
.subject
.alt_names
.usage_ra_tls // Embed attestation in certificate
.usage_server_auth
.build;
let tls = client.get_tls_key.await?;
println!; // PEM private key
println!; // Certificate chain
TlsKeyConfig Options:
.subject(name): Certificate common name (e.g., domain name).alt_names(names): List of subject alternative names.usage_ra_tls(bool): Embed TDX quote in certificate extension.usage_server_auth(bool): Enable for server authentication.usage_client_auth(bool): Enable for client authentication
Returns: GetTlsKeyResponse
key: PEM-encoded private keycertificate_chain: List of PEM certificates
Sign and Verify
Sign data using TEE-derived keys (not yet released):
let result = client.sign.await?;
println!;
println!;
// Verify the signature
let valid = client.verify.await?;
println!; // true
sign() Parameters:
algorithm:"ed25519","secp256k1", or"secp256k1_prehashed"data: Data to sign
sign() Returns: SignResponse
signature: Signature bytespublic_key: Public key bytessignature_chain: Signatures proving TEE origin
verify() Parameters:
algorithm: Algorithm used for signingdata: Original datasignature: Signature to verifypublic_key: Public key to verify against
verify() Returns: VerifyResponse
valid: Boolean indicating if signature is valid
Emit Events
Extend RTMR3 with custom measurements for your application's boot sequence (requires dstack OS 0.5.0+). These measurements are append-only and become part of the attestation record.
client.emit_event.await?;
client.emit_event.await?;
Parameters:
event: Event name (string identifier)payload: Event value (bytes)
Blockchain Integration
Ethereum with Alloy
use DstackClient;
use to_account;
let key = client.get_key.await?;
let signer = to_account?;
println!;
Development
For local development without TDX hardware, use the simulator:
Then set the endpoint:
Run examples:
Migration from TappdClient
Replace TappdClient with DstackClient:
// Before
use TappdClient;
let client = new;
// After
use DstackClient;
let client = new;
Method changes:
derive_key()→get_tls_key()for TLS certificates- Socket path:
/var/run/tappd.sock→/var/run/dstack.sock
License
Apache License 2.0