api

package
v0.88.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package api provides a client for Turnkey's Visualsign API.

The client handles: - API authentication with ECDSA P-256 keys - Request/response marshaling and signing - Attestation document retrieval - Cryptographic operations for API key authentication

Usage

Create a client using NewClient with an API key provider:

client, err := api.NewClient(hostURI, httpClient, organizationID, keyProvider)
if err != nil {
	log.Fatal(err)
}

Call CreateSignablePayload to request transaction parsing:

response, err := client.CreateSignablePayload(ctx, &api.CreateSignablePayloadRequest{
	UnsignedPayload: "base64-encoded-payload",
	Chain:           "CHAIN_SOLANA",
})
if err != nil {
	log.Fatal(err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AttestationQueryRequest

type AttestationQueryRequest struct {
	OrganizationID string `json:"organizationId"`
	EnclaveType    string `json:"enclaveType"`
	PublicKey      string `json:"publicKey"`
}

AttestationQueryRequest represents the request to get attestation document

type AttestationQueryResponse

type AttestationQueryResponse struct {
	AttestationDocument string `json:"attestationDocument"`
}

AttestationQueryResponse represents the response from the attestation query

type AttestationType

type AttestationType string

AttestationType represents different types of attestations

const (
	BootAttestationKey AttestationType = "boot_attestation"
	AppAttestationKey  AttestationType = "app_attestation"
)

type Client

type Client struct {
	HostURI              string
	HTTPClient           HTTPClient
	APIKey               *TurnkeyAPIKey
	APIKeyProvider       KeyProvider
	VisualSignAPIVersion string
}

Client implements the Turnkey API client

func NewClient

func NewClient(hostURI string, httpClient HTTPClient, organizationID string, provider KeyProvider) (*Client, error)

NewClient creates a new Turnkey API client with key provider

func (*Client) CreateSignablePayload

func (c *Client) CreateSignablePayload(ctx context.Context, req *CreateSignablePayloadRequest) (*SignablePayloadResponse, error)

CreateSignablePayload calls Turnkey's visualsign API to create a signable payload

func (*Client) GetBootAttestation

func (c *Client) GetBootAttestation(ctx context.Context, publicKey, enclaveType string) (string, error)

GetBootAttestation retrieves boot attestation for a specific public key and enclave type

type CreateSignablePayloadRequest

type CreateSignablePayloadRequest struct {
	UnsignedPayload string
	Chain           string
}

CreateSignablePayloadRequest represents the request to create signable payload

type ECDSASignature

type ECDSASignature struct {
	R, S *big.Int
}

ECDSASignature represents an ECDSA signature for ASN.1 encoding

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient interface for dependency injection

type KeyProvider

type KeyProvider interface {
	GetAPIKey(ctx context.Context) (*TurnkeyAPIKey, error)
}

KeyProvider interface for providing API keys

type SignablePayloadResponse

type SignablePayloadResponse struct {
	SignablePayload                  string                     `json:"signablePayload"`
	ParsedPayload                    string                     `json:"parsedPayload,omitempty"`      // v2
	InputPayloadDigest               string                     `json:"inputPayloadDigest,omitempty"` // v2
	MetadataDigest                   string                     `json:"metadataDigest,omitempty"`     // v2
	TurnkeySerializedSignablePayload string                     `json:"turnkeySerializedSignablePayload"`
	ManifestVersion                  manifest.ManifestVersion   `json:"manifestVersion"`
	Attestations                     map[AttestationType]string `json:"attestations"`
	QosManifestB64                   string                     `json:"qosManifestB64,omitempty"`
	QosManifestEnvelopeB64           string                     `json:"qosManifestEnvelopeB64,omitempty"`
	EphemeralPublicKeyHex            string                     `json:"ephemeralPublicKeyHex,omitempty"`
	EnclaveApp                       string                     `json:"enclaveApp,omitempty"`
	DeploymentLabel                  string                     `json:"deploymentLabel,omitempty"`
}

SignablePayloadResponse represents the response from CreateSignablePayload

type TurnkeyAPIKey

type TurnkeyAPIKey struct {
	PublicKey      string
	PrivateKey     *ecdsa.PrivateKey
	OrganizationID string
}

TurnkeyAPIKey represents the API key configuration

type TurnkeyBootProof

type TurnkeyBootProof struct {
	AwsAttestationDocB64   string `json:"awsAttestationDocB64"`
	QosManifestB64         string `json:"qosManifestB64"`
	QosManifestEnvelopeB64 string `json:"qosManifestEnvelopeB64"`
	EphemeralPublicKeyHex  string `json:"ephemeralPublicKeyHex"`
	EnclaveApp             string `json:"enclaveApp"`
	DeploymentLabel        string `json:"deploymentLabel"`
}

TurnkeyBootProof represents the boot proof object in the response. Fields match the Turnkey visualsign API bootProof response object. See: https://docs.turnkey.com/concepts/enclave-secure-channels

type TurnkeySignature

type TurnkeySignature struct {
	Message   string `json:"message"`
	PublicKey string `json:"publicKey"`
	Scheme    string `json:"scheme"`
	Signature string `json:"signature"`
}

TurnkeySignature represents the signature object in the response

type TurnkeyStamp

type TurnkeyStamp struct {
	PublicKey string `json:"publicKey"`
	Signature string `json:"signature"`
	Scheme    string `json:"scheme"`
}

TurnkeyStamp represents the stamp structure for API key authentication

type TurnkeyVisualSignRequest

type TurnkeyVisualSignRequest struct {
	Request struct {
		UnsignedPayload string `json:"unsigned_payload"`
		Chain           string `json:"chain"`
	} `json:"request"`
	OrganizationID string `json:"organization_id"`
}

TurnkeyVisualSignRequest represents the request to Turnkey's visualsign API

type TurnkeyVisualSignResponse

type TurnkeyVisualSignResponse struct {
	BootProof *TurnkeyBootProof `json:"bootProof,omitempty"`
	Response  struct {
		ParsedTransaction struct {
			Payload struct {
				SignablePayload    string `json:"signablePayload"`
				ParsedPayload      string `json:"parsedPayload,omitempty"`      // v2
				InputPayloadDigest string `json:"inputPayloadDigest,omitempty"` // v2
				MetadataDigest     string `json:"metadataDigest,omitempty"`     // v2
			} `json:"payload"`
			Signature *TurnkeySignature `json:"signature,omitempty"`
		} `json:"parsedTransaction"`
	} `json:"response"`
	Error string `json:"error,omitempty"`
}

TurnkeyVisualSignResponse represents the response from Turnkey's visualsign API

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL