Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Go SDK implementation #47

Merged
merged 24 commits into from
Dec 11, 2024
Merged

Add Go SDK implementation #47

merged 24 commits into from
Dec 11, 2024

Conversation

Hyodar
Copy link
Contributor

@Hyodar Hyodar commented Dec 11, 2024

Hi there!

We're now using Dstack in some of our TEE experiments in Nethermind - more recently https://github.com/NethermindEth/teeception!
The codebase is in Go, so we implemented a quick Go Dstack SDK based on the existing TS and Python implementations. If that's interesting to you, happy to contribute here. Feel free to let me know if there's anything else needed.

This PR adds a Go SDK implementation effectively equivalent to the TS and Python ones, as well as a simple README and unit tests.

Using it is mostly similar to the other ones as well - here's an example:

package main

import (
	"context"
	"fmt"
	"log/slog"

	"github.com/Dstack-TEE/dstack/sdk/go/tappd"
)

func main() {
	client := tappd.NewTappdClient(
		// tappd.WithEndpoint("http://localhost"),
		// tappd.WithLogger(slog.Default()),
	)

	deriveKeyResp, err := client.DeriveKey(context.Background(), "/", "test", nil)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(deriveKeyResp) // &{-----BEGIN PRIVATE KEY--- ...

	tdxQuoteResp, err := client.TdxQuote(context.Background(), []byte("test"), tappd.SHA256)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(tdxQuoteResp) // &{0x0000000000000000000 ...

	rtmrs, err := tdxQuoteResp.ReplayRTMRs()
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(rtmrs) // map[0:00000000000000000 ...
}

Copy link
Collaborator

@kvinwang kvinwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the awesome implementation. Looks excellent overall, with one minor note. @Leechael, please review.

sdk/go/tappd/client.go Outdated Show resolved Hide resolved
sdk/go/tappd/client.go Outdated Show resolved Hide resolved
sdk/go/tappd/client.go Outdated Show resolved Hide resolved
@Leechael
Copy link
Collaborator

btw please remember to include // Author: at the top of the source code file.

@kvinwang kvinwang merged commit c6ae368 into Dstack-TEE:master Dec 11, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants