SDK

Go SDK

Official Go SDK for the Truthlock platform. Idiomatic Go with full context propagation, typed request/response structs, automatic retries, and comprehensive error handling.

InstallationQuick StartConfigurationAPI MethodsError HandlingExamples

Installation

Public module: The Go SDK is available as a public Go module. No special configuration required.
Terminalbash
go get github.com/truthlocks/sdk-go@latest

Quick Start

main.goGo
package main

import (
    "context"
    "fmt"
    "log"

    truthlock "github.com/truthlocks/sdk-go"
)

func main() {
    // 1. Create client
    client := truthlock.NewClient(truthlock.Config{
        BaseURL:  "https://api.truthlocks.com",
        TenantID: "your-tenant-id",
        APIKey:   "tl_live_...",
    })

    ctx := context.Background()

    // 2. Create and trust an issuer
    issuer, err := client.Issuers.Create(ctx, &truthlock.CreateIssuerRequest{
        Name:        "My Organization",
        LegalName:   "My Organization Inc.",
        DisplayName: "My Org",
    })
    if err != nil {
        log.Fatal(err)
    }

    if _, err := client.Issuers.Trust(ctx, issuer.ID); err != nil {
        log.Fatal(err)
    }

    // 3. Register a signing key
    _, err = client.Keys.Register(ctx, issuer.ID, &truthlock.RegisterKeyRequest{
        KID:          "key-2026",
        Alg:          truthlock.AlgEd25519,
        PublicKeyB64: "your-public-key-base64url",
    })
    if err != nil {
        log.Fatal(err)
    }

    // 4. Mint an attestation (with optional email delivery)
    attestation, err := client.Attestations.Mint(ctx, &truthlock.MintRequest{
        IssuerID: issuer.ID,
        KID:      "key-2026",
        Alg:      truthlock.AlgEd25519,
        Schema:   "degree",
        Claims: map[string]interface{}{
            "student_name":    "Jane Doe",
            "institution":     "State University",
            "degree_type":     "Bachelor of Science",
            "field_of_study":  "Computer Science",
            "graduation_date": "2026-05-15",
        },
        RecipientEmail: "jane.doe@example.com", // optional
    })
    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("Attestation ID: %s\n", attestation.ID)
    fmt.Printf("Log index: %d\n", attestation.LogIndex)

    // 5. Verify
    result, err := client.Verify.VerifyOnline(ctx, &truthlock.VerifyRequest{
        AttestationID: attestation.ID,
    })
    if err != nil {
        log.Fatal(err)
    }

    if result.Verdict == truthlock.VerdictValid {
        fmt.Println("Attestation verified successfully")
    }
}

Configuration

Configuration structGo
client := truthlock.NewClient(truthlock.Config{
    // Required
    BaseURL:  "https://api.truthlocks.com",  // API base URL
    TenantID: "your-tenant-id",              // From Console > Settings
    APIKey:   "tl_live_...",                 // From Console > API Keys

    // Optional
    Timeout:    30 * time.Second,  // Request timeout (default: 30s)
    MaxRetries: 3,                 // Auto-retry with backoff (default: 3)
    HTTPClient: &http.Client{},    // Custom HTTP client
})
FieldTypeDescription
BaseURLstringAPI endpoint. Use sandbox-api.truthlocks.com for testing.
TenantIDstringYour tenant UUID from the Truthlocks Console.
APIKeystringAPI key starting with tl_live_ or tl_test_.
Timeouttime.DurationPer-request timeout. Default: 30s.
MaxRetriesintMax retries for 429/5xx errors. Default: 3.
HTTPClient*http.ClientCustom HTTP client for proxy, TLS, etc.

API Methods

All methods accept a context.Context as the first argument for cancellation and deadline propagation. See the API Reference for full request/response types.

Issuers

MethodHTTPDescription
client.Issuers.Create(ctx, req)POSTCreate a new issuer organization
client.Issuers.Get(ctx, id)GETGet issuer by UUID
client.Issuers.List(ctx)GETList all issuers for the tenant
client.Issuers.Trust(ctx, id)POSTMark issuer as trusted
client.Issuers.Suspend(ctx, id, reason)POSTTemporarily suspend an issuer
client.Issuers.Revoke(ctx, id, reason)POSTPermanently revoke an issuer

Keys

MethodHTTPDescription
client.Keys.Register(ctx, issuerId, req)POSTRegister an Ed25519 signing key
client.Keys.List(ctx, issuerId)GETList all keys for an issuer
client.Keys.Rotate(ctx, kid, req)POSTRotate a signing key
client.Keys.ReportCompromise(ctx, kid)POSTReport a key as compromised

Attestations

MethodHTTPDescription
client.Attestations.Mint(ctx, req)POSTMint a new signed attestation
client.Attestations.Get(ctx, id)GETGet attestation by ID
client.Attestations.List(ctx)GETList attestations with filters
client.Attestations.Revoke(ctx, id, req)POSTRevoke an attestation
client.Attestations.Supersede(ctx, id, req)POSTReplace with a new version
client.Attestations.GetProofBundle(ctx, id)GETGet cryptographic proof bundle

Verification

MethodHTTPDescription
client.Verify.VerifyOnline(ctx, req)POSTVerify attestation against transparency log

API Keys

MethodHTTPDescription
client.APIKeys.List(ctx)GETList all API keys
client.APIKeys.Create(ctx, req)POSTCreate a new API key
client.APIKeys.Revoke(ctx, id)DELETERevoke an API key

Audit

MethodHTTPDescription
client.Audit.Query(ctx, params)GETQuery audit event log
client.Audit.Export(ctx, req)POSTExport audit log as CSV/JSON

Governance

MethodHTTPDescription
client.Governance.ListRequests(ctx)GETList pending governance requests
client.Governance.CreateRequest(ctx, req)POSTSubmit a governance request
client.Governance.ApproveRequest(ctx, id)POSTApprove a governance request
client.Governance.ExecuteRequest(ctx, id)POSTExecute an approved request

Error Handling

API errors are returned as *truthlock.Error, which implements the standard error interface. Use type assertion to access structured error details.

Error handlingGo
attestation, err := client.Attestations.Mint(ctx, req)
if err != nil {
    var tlErr *truthlock.Error
    if errors.As(err, &tlErr) {
        fmt.Printf("Code:    %s\n", tlErr.Code)    // e.g. "ISSUER_NOT_TRUSTED"
        fmt.Printf("Message: %s\n", tlErr.Message) // Human-readable
        fmt.Printf("Status:  %d\n", tlErr.Status)  // HTTP status code

        switch tlErr.Code {
        case truthlock.ErrIssuerNotTrusted:
            // Issuer needs to be trusted before minting
        case truthlock.ErrKeyNotFound:
            // Signing key not registered
        case truthlock.ErrQuotaExceeded:
            // Plan limit reached
        }
    }
    return err
}
ConstantCodeDescription
ErrIssuerNotTrustedISSUER_NOT_TRUSTEDIssuer must be trusted before minting
ErrKeyNotFoundKEY_NOT_FOUNDSigning key not registered
ErrQuotaExceededQUOTA_EXCEEDEDMinting or verification quota exhausted
ErrInvalidSchemaINVALID_SCHEMASchema ID not recognized
ErrDuplicateIdempotencyDUPLICATE_IDEMPOTENCYIdempotency key already used
ErrPayloadTooLargePAYLOAD_TOO_LARGEPayload exceeds 50 MB limit

Examples

Batch Minting with Error Collection

batch.goGo
func mintBatch(ctx context.Context, client *truthlock.Client, employees []Employee) error {
    var errs []error
    for _, emp := range employees {
        _, err := client.Attestations.Mint(ctx, &truthlock.MintRequest{
            IssuerID: issuerId,
            KID:      "key-2026",
            Alg:      truthlock.AlgEd25519,
            Schema:   "employment-verification",
            Claims: map[string]interface{}{
                "employee_name":   emp.Name,
                "employer":        "Acme Corp",
                "position":        emp.Title,
                "department":      emp.Dept,
                "employment_type": "Full-time",
                "start_date":      emp.StartDate,
            },
            RecipientEmail: emp.Email,
        })
        if err != nil {
            errs = append(errs, fmt.Errorf("mint %s: %w", emp.Name, err))
            continue
        }
    }
    return errors.Join(errs...)
}

Context with Timeout

timeout.goGo
// Per-operation timeout (overrides client default)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

result, err := client.Verify.VerifyOnline(ctx, &truthlock.VerifyRequest{
    AttestationID: attestationID,
})
if err != nil {
    if errors.Is(err, context.DeadlineExceeded) {
        log.Println("Verification timed out")
    }
    return err
}

Custom HTTP Client (proxy, mTLS)

custom-http.goGo
// Use a custom HTTP client for corporate proxy or mutual TLS
client := truthlock.NewClient(truthlock.Config{
    BaseURL:  "https://api.truthlocks.com",
    TenantID: "your-tenant-id",
    APIKey:   "tl_live_...",
    HTTPClient: &http.Client{
        Transport: &http.Transport{
            Proxy: http.ProxyFromEnvironment,
            TLSClientConfig: &tls.Config{
                Certificates: []tls.Certificate{clientCert},
            },
        },
    },
})

Requirements

Go>= 1.21
Modulegithub.com/truthlocks/sdk-go
AuthPublic module — no auth required
DependenciesNo external dependencies (stdlib only)