Skip to content

Commit 0b15643

Browse files
authored
Merge pull request #144 from Dstack-TEE/rename-sdk
API renaming for Client SDK
2 parents 45fe4b4 + f72f52a commit 0b15643

24 files changed

+1726
-711
lines changed

sdk/go/README.md

Lines changed: 30 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ import (
1818
"fmt"
1919
"log/slog"
2020

21-
"github.com/Dstack-TEE/dstack/sdk/go/tappd"
21+
"github.com/Dstack-TEE/dstack/sdk/go/dstack"
2222
)
2323

2424
func main() {
25-
client := tappd.NewTappdClient(
26-
// tappd.WithEndpoint("http://localhost"),
27-
// tappd.WithLogger(slog.Default()),
25+
client := dstack.NewDstackClient(
26+
// dstack.WithEndpoint("http://localhost"),
27+
// dstack.WithLogger(slog.Default()),
2828
)
2929

30-
// Get information about the Tappd instance
30+
// Get information about the dstack client instance
3131
info, err := client.Info(context.Background())
3232
if err != nil {
3333
fmt.Println(err)
@@ -37,17 +37,19 @@ func main() {
3737
fmt.Println(info.TcbInfo.Mrtd) // Access TCB info directly
3838
fmt.Println(info.TcbInfo.EventLog[0].Event) // Access event log entries
3939

40-
// Derive a key with optional path and subject
41-
deriveKeyResp, err := client.DeriveKey(context.Background(), "/")
40+
path := "/test"
41+
purpose := "test" // or leave empty
42+
43+
// Derive a key with optional path and purpose
44+
deriveKeyResp, err := client.GetKey(context.Background(), path, purpose)
4245
if err != nil {
4346
fmt.Println(err)
4447
return
4548
}
46-
fmt.Println(deriveKeyResp.Key) // -----BEGIN PRIVATE KEY--- ...
47-
keyBytes, _ := deriveKeyResp.ToBytes(-1) // Get key as bytes
49+
fmt.Println(deriveKeyResp.Key)
4850

4951
// Generate TDX quote
50-
tdxQuoteResp, err := client.TdxQuote(context.Background(), []byte("test"))
52+
tdxQuoteResp, err := client.GetQuote(context.Background(), []byte("test"))
5153
if err != nil {
5254
fmt.Println(err)
5355
return
@@ -65,16 +67,16 @@ func main() {
6567

6668
## API Reference
6769

68-
### TappdClient
70+
### DstackClient
6971

7072
#### Constructor
7173

7274
```go
73-
func NewTappdClient(opts ...TappdClientOption) *TappdClient
75+
func NewDstackClient(opts ...DstackClientOption) *DstackClient
7476
```
7577

7678
Options:
77-
- `WithEndpoint(endpoint string)`: Sets the endpoint (Unix socket path or HTTP(S) URL). Defaults to '/var/run/tappd.sock'.
79+
- `WithEndpoint(endpoint string)`: Sets the endpoint (Unix socket path or HTTP(S) URL). Defaults to '/var/run/dstack.sock'.
7880
- `WithLogger(logger *slog.Logger)`: Sets the logger. Defaults to `slog.Default()`.
7981

8082
The client uses `DSTACK_SIMULATOR_ENDPOINT` environment variable if set.
@@ -83,142 +85,40 @@ NOTE: Leave endpoint empty in production. You only need to add `volumes` in your
8385

8486
```yaml
8587
volumes:
86-
- /var/run/tappd.sock:/var/run/tappd.sock
88+
- /var/run/dstack.sock:/var/run/dstack.sock
8789
```
8890

89-
For local development without TDX devices, you can use the simulator available for download here:
90-
91-
https://github.com/Leechael/tappd-simulator/releases
92-
9391
#### Methods
9492

95-
##### `DeriveKey(ctx context.Context, path string) (*DeriveKeyResponse, error)`
96-
97-
Derives a key for the given path. This is a convenience method that uses the path as the subject.
98-
99-
##### `DeriveKeyWithSubject(ctx context.Context, path string, subject string) (*DeriveKeyResponse, error)`
100-
101-
Derives a key for the given path and subject.
102-
103-
##### `DeriveKeyWithSubjectAndAltNames(ctx context.Context, path string, subject string, altNames []string) (*DeriveKeyResponse, error)`
104-
105-
Derives a key for the given path, subject, and alternative names.
106-
107-
**NOTE: Only the `path` affects the derived result. `subject` & `altNames` are for the generated certificate and do not affect the derived result.**
108-
109-
##### `TdxQuote(ctx context.Context, reportData []byte) (*TdxQuoteResponse, error)`
110-
111-
Generates a TDX quote using SHA512 as the hash algorithm.
112-
113-
##### `TdxQuoteWithHashAlgorithm(ctx context.Context, reportData []byte, hashAlgorithm QuoteHashAlgorithm) (*TdxQuoteResponse, error)`
114-
115-
Generates a TDX quote with a specific hash algorithm. The quote is returned in hex format, and you can paste your quote into https://proof.t16z.com/ to get the attestation report.
116-
117-
##### `Info(ctx context.Context) (*TappdInfoResponse, error)`
118-
119-
Retrieves information about the Tappd instance, including TCB info and event logs.
120-
121-
### Types
122-
123-
```go
124-
type QuoteHashAlgorithm string
125-
126-
const (
127-
SHA256 QuoteHashAlgorithm = "sha256"
128-
SHA384 QuoteHashAlgorithm = "sha384"
129-
SHA512 QuoteHashAlgorithm = "sha512"
130-
SHA3_256 QuoteHashAlgorithm = "sha3-256"
131-
SHA3_384 QuoteHashAlgorithm = "sha3-384"
132-
SHA3_512 QuoteHashAlgorithm = "sha3-512"
133-
KECCAK256 QuoteHashAlgorithm = "keccak256"
134-
KECCAK384 QuoteHashAlgorithm = "keccak384"
135-
KECCAK512 QuoteHashAlgorithm = "keccak512"
136-
RAW QuoteHashAlgorithm = "raw"
137-
)
138-
139-
type DeriveKeyResponse struct {
140-
Key string
141-
CertificateChain []string
142-
}
143-
144-
func (d *DeriveKeyResponse) ToBytes(maxLength int) ([]byte, error)
145-
146-
type TdxQuoteResponse struct {
147-
Quote string
148-
EventLog string
149-
}
150-
151-
func (r *TdxQuoteResponse) ReplayRTMRs() (map[int]string, error)
152-
153-
type EventLog struct {
154-
IMR int
155-
EventType int
156-
Digest string
157-
Event string
158-
EventPayload string
159-
}
160-
161-
type TcbInfo struct {
162-
Mrtd string
163-
RootfsHash string
164-
Rtmr0 string
165-
Rtmr1 string
166-
Rtmr2 string
167-
Rtmr3 string
168-
EventLog []EventLog
169-
}
170-
171-
type TappdInfoResponse struct {
172-
AppID string
173-
InstanceID string
174-
AppCert string
175-
TcbInfo TcbInfo
176-
AppName string
177-
PublicLogs bool
178-
PublicSysinfo bool
179-
}
180-
```
93+
- `Info(ctx context.Context) (*InfoResponse, error)`: Retrieves information about the CVM instance.
94+
- `GetKey(ctx context.Context, path string, purpose string) (*GetKeyResponse, error)`: Derives a key for the given path and purpose.
95+
- `GetQuote(ctx context.Context, reportData []byte) (*GetQuoteResponse, error)`: Generates a TDX quote using SHA512 as the hash algorithm.
96+
- `GetTlsKey(ctx context.Context, path string, subject string, altNames []string, usageRaTls bool, usageServerAuth bool, usageClientAuth bool, randomSeed bool) (*GetTlsKeyResponse, error)`: Derives a key for the given path and purpose.
18197

18298
## Development
18399

184100
Set up [Go](https://go.dev/doc/install).
185101

186-
### Running Tests
102+
### Running the Simulator
187103

188-
There are several ways to run the tests:
104+
For local development without TDX devices, you can use the simulator under `sdk/simulator`.
189105

190-
1. Run all tests with local simulator:
191-
```bash
192-
DSTACK_SIMULATOR_ENDPOINT=/tmp/tappd.sock go test ./...
193-
```
194-
195-
2. Run specific test package:
196-
```bash
197-
DSTACK_SIMULATOR_ENDPOINT=/tmp/tappd.sock go test ./tappd
198-
```
106+
Run the simulator with:
199107

200-
3. Run tests with verbose output:
201108
```bash
202-
DSTACK_SIMULATOR_ENDPOINT=/tmp/tappd.sock go test -v ./...
109+
cd sdk/simulator
110+
./build.sh
111+
./dstack-simulator
203112
```
204113

205-
4. Run specific test function:
114+
### Running Tests
206115
```bash
207-
DSTACK_SIMULATOR_ENDPOINT=/tmp/tappd.sock go test -v ./tappd -run TestDeriveKey
208-
```
116+
DSTACK_SIMULATOR_ENDPOINT=$(realpath ../simulator/dstack.sock) go test -v ./dstack
209117

210-
5. Run tests with coverage report:
211-
```bash
212-
DSTACK_SIMULATOR_ENDPOINT=/tmp/tappd.sock go test -coverprofile=coverage.out ./...
213-
# View coverage in browser
214-
go tool cover -html=coverage.out
118+
# or for the old Tappd client
119+
DSTACK_SIMULATOR_ENDPOINT=$(realpath ../simulator/tappd.sock) go test -v ./tappd
215120
```
216121

217-
Note: The tests require a running Tappd simulator. You can download it from:
218-
https://github.com/Leechael/tappd-simulator/releases
219-
220-
Make sure the simulator is running and accessible at the path specified in `DSTACK_SIMULATOR_ENDPOINT` before running the tests.
221-
222122
## License
223123

224124
Apache License

0 commit comments

Comments
 (0)