protect

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package protect provides the Taurus-PROTECT SDK client.

Index

Constants

View Source
const (
	// DefaultRulesCacheTTL is the default TTL for the rules container cache.
	DefaultRulesCacheTTL = 5 * time.Minute
	// DefaultHTTPTimeout is the default timeout for HTTP requests.
	DefaultHTTPTimeout = 30 * time.Second
)

Default configuration values.

Variables

View Source
var (
	// ErrValidation indicates a 400 Bad Request error.
	ErrValidation = &APIError{Code: 400, StatusCode: 400, Message: "validation error"}
	// ErrAuthentication indicates a 401 Unauthorized error.
	ErrAuthentication = &APIError{Code: 401, StatusCode: 401, Message: "authentication error"}
	// ErrAuthorization indicates a 403 Forbidden error.
	ErrAuthorization = &APIError{Code: 403, StatusCode: 403, Message: "authorization error"}
	// ErrNotFound indicates a 404 Not Found error.
	ErrNotFound = &APIError{Code: 404, StatusCode: 404, Message: "not found"}
	// ErrRateLimit indicates a 429 Too Many Requests error.
	ErrRateLimit = &APIError{Code: 429, StatusCode: 429, Message: "rate limit exceeded"}
	// ErrServer indicates a 5xx server error.
	ErrServer = &APIError{Code: 500, StatusCode: 500, Message: "server error"}
)

Sentinel errors for type checking with errors.Is().

View Source
var ErrConfiguration = &ConfigurationError{Message: "invalid configuration"}

ErrConfiguration is the sentinel error for configuration failures.

View Source
var ErrIntegrity = &IntegrityError{Message: "integrity verification failed"}

ErrIntegrity is the sentinel error for integrity failures.

View Source
var ErrRequestMetadata = &RequestMetadataError{Message: "invalid request metadata"}

ErrRequestMetadata is the sentinel error for request metadata failures.

View Source
var ErrWhitelist = &WhitelistError{Message: "whitelist verification failed"}

ErrWhitelist is the sentinel error for whitelist failures.

Functions

func IsConfigurationError

func IsConfigurationError(err error) bool

IsConfigurationError checks if the error is a ConfigurationError.

func IsIntegrityError

func IsIntegrityError(err error) bool

IsIntegrityError checks if the error is an IntegrityError.

func IsWhitelistError

func IsWhitelistError(err error) bool

IsWhitelistError checks if the error is a WhitelistError.

Types

type APIError

type APIError = model.APIError

APIError is the base error type for all Taurus-PROTECT API errors.

func AuthenticationError

func AuthenticationError(message string, err error) *APIError

AuthenticationError creates a new authentication error (401).

func AuthorizationError

func AuthorizationError(message string, err error) *APIError

AuthorizationError creates a new authorization error (403).

func IsAPIError

func IsAPIError(err error) (*APIError, bool)

IsAPIError checks if the error is an APIError and returns it.

func NotFoundError

func NotFoundError(message string, err error) *APIError

NotFoundError creates a new not found error (404).

func RateLimitError

func RateLimitError(message string, retryAfter time.Duration, err error) *APIError

RateLimitError creates a new rate limit error (429).

func ServerError

func ServerError(code int, message string, err error) *APIError

ServerError creates a new server error (5xx).

func ValidationError

func ValidationError(message string, err error) *APIError

ValidationError creates a new validation error (400).

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the main entry point for the Taurus-PROTECT SDK. It provides access to all API services and handles authentication.

Use NewClient to create a new instance with the functional options pattern:

client, err := protect.NewClient(
    "https://api.taurus.example.com",
    protect.WithCredentials(apiKey, apiSecret),
    protect.WithSuperAdminKeysPEM(pemKeys),
    protect.WithMinValidSignatures(2),
)
if err != nil {
    log.Fatal(err)
}
defer client.Close()

Client implements io.Closer and should be closed when no longer needed to securely wipe credentials from memory.

func NewClient

func NewClient(host string, opts ...Option) (*Client, error)

NewClient creates a new Taurus-PROTECT API client.

The host parameter should be the base URL of the Taurus-PROTECT API (e.g., "https://api.taurus.example.com").

At minimum, WithCredentials, WithSuperAdminKeysPEM (or WithSuperAdminKeys), and WithMinValidSignatures must be provided:

client, err := protect.NewClient(
    "https://api.taurus.example.com",
    protect.WithCredentials(apiKey, apiSecret),
    protect.WithSuperAdminKeysPEM(pemKeys),
    protect.WithMinValidSignatures(2),
)

func (*Client) Actions

func (c *Client) Actions() *service.ActionService

Actions returns the action service for managing automated actions.

func (*Client) Addresses

func (c *Client) Addresses() *service.AddressService

Addresses returns the address service for managing blockchain addresses. Address signature verification is mandatory on all get and list operations.

func (*Client) AirGap

func (c *Client) AirGap() *service.AirGapService

AirGap returns the air-gap service for cold HSM integration operations.

func (*Client) Assets

func (c *Client) Assets() *service.AssetService

Assets returns the asset service for querying asset balances at address and wallet level.

func (*Client) Audits

func (c *Client) Audits() *service.AuditService

Audits returns the audit service for querying audit trails.

func (*Client) Balances

func (c *Client) Balances() *service.BalanceService

Balances returns the balance service for querying asset balances.

func (*Client) BaseURL

func (c *Client) BaseURL() string

BaseURL returns the base URL of the API.

func (*Client) Blockchains

func (c *Client) Blockchains() *service.BlockchainService

Blockchains returns the blockchain service for querying blockchain metadata.

func (*Client) BusinessRules

func (c *Client) BusinessRules() *service.BusinessRuleService

BusinessRules returns the business rule service for querying business rules.

func (*Client) Changes

func (c *Client) Changes() *service.ChangeService

Changes returns the change service for managing configuration changes.

func (*Client) Close

func (c *Client) Close() error

Close releases resources and securely wipes credentials from memory. It is safe to call Close multiple times.

func (*Client) Config

func (c *Client) Config() *service.ConfigService

Config returns the config service for querying tenant configuration.

func (*Client) Currencies

func (c *Client) Currencies() *service.CurrencyService

Currencies returns the currency service for querying available currencies.

func (*Client) Exchanges

func (c *Client) Exchanges() *service.ExchangeService

Exchanges returns the exchange service for managing exchange accounts.

func (*Client) FeePayers

func (c *Client) FeePayers() *service.FeePayerService

FeePayers returns the fee payer service for managing fee payers.

func (*Client) Fees

func (c *Client) Fees() *service.FeeService

Fees returns the fee service for querying blockchain fee estimates.

func (*Client) Fiat

func (c *Client) Fiat() *service.FiatService

Fiat returns the fiat service for managing fiat provider accounts.

func (*Client) GovernanceRules

func (c *Client) GovernanceRules() *service.GovernanceRuleService

GovernanceRules returns the governance rule service for managing governance rules.

func (*Client) Groups

func (c *Client) Groups() *service.GroupService

Groups returns the group service for managing user groups.

func (*Client) HTTPClient

func (c *Client) HTTPClient() *http.Client

HTTPClient returns the underlying HTTP client. This can be used for advanced use cases, but most users should use the service methods instead.

func (*Client) Health

func (c *Client) Health() *service.HealthService

Health returns the health service for querying system health checks.

func (*Client) Jobs

func (c *Client) Jobs() *service.JobService

Jobs returns the job service for managing background jobs.

func (*Client) MinValidSignatures

func (c *Client) MinValidSignatures() int

MinValidSignatures returns the minimum number of valid signatures required.

func (*Client) MultiFactorSignature

func (c *Client) MultiFactorSignature() *service.MultiFactorSignatureService

MultiFactorSignature returns the multi-factor signature service for MFA approval workflows.

func (*Client) Prices

func (c *Client) Prices() *service.PriceService

Prices returns the price service for querying currency prices and conversions.

func (*Client) Requests

func (c *Client) Requests() *service.RequestService

Requests returns the request service for managing transaction requests.

func (*Client) Reservations

func (c *Client) Reservations() *service.ReservationService

Reservations returns the reservation service for managing UTXO reservations.

func (*Client) RulesCache

func (c *Client) RulesCache() *cache.RulesContainerCache

RulesCache returns the rules container cache used for address signature verification. This is always non-nil as address signature verification is mandatory.

func (*Client) Scores

func (c *Client) Scores() *service.ScoreService

Scores returns the score service for managing address risk scores.

func (*Client) Staking

func (c *Client) Staking() *service.StakingService

Staking returns the staking service for blockchain staking operations.

func (*Client) Statistics

func (c *Client) Statistics() *service.StatisticsService

Statistics returns the statistics service for querying portfolio and tag statistics.

func (*Client) SuperAdminKeys

func (c *Client) SuperAdminKeys() []*ecdsa.PublicKey

SuperAdminKeys returns the configured SuperAdmin public keys.

func (*Client) Tags

func (c *Client) Tags() *service.TagService

Tags returns the tag service for managing tags.

func (*Client) TaurusNetwork

func (c *Client) TaurusNetwork() *TaurusNetworkClient

TaurusNetwork returns the Taurus Network namespace client providing access to all Taurus Network services: Participants, Pledges, Lending, Settlements, and Sharing.

Example usage:

client.TaurusNetwork().Participants().GetMyParticipant(ctx)
client.TaurusNetwork().Pledges().Create(ctx, req)
client.TaurusNetwork().Lending().GetAgreement(ctx, agreementID)
client.TaurusNetwork().Settlements().Get(ctx, settlementID)
client.TaurusNetwork().Sharing().ShareAddress(ctx, req)

func (*Client) TokenMetadata

func (c *Client) TokenMetadata() *service.TokenMetadataService

TokenMetadata returns the token metadata service for querying NFT and token metadata.

func (*Client) Transactions

func (c *Client) Transactions() *service.TransactionService

Transactions returns the transaction service for querying transactions.

func (*Client) UserDevices

func (c *Client) UserDevices() *service.UserDeviceService

UserDevices returns the user device service for managing device pairing.

func (*Client) Users

func (c *Client) Users() *service.UserService

Users returns the user service for managing users.

func (*Client) VisibilityGroups

func (c *Client) VisibilityGroups() *service.VisibilityGroupService

VisibilityGroups returns the visibility group service for managing restricted visibility groups.

func (*Client) Wallets

func (c *Client) Wallets() *service.WalletService

Wallets returns the wallet service for managing cryptocurrency wallets.

func (*Client) WebhookCalls

func (c *Client) WebhookCalls() *service.WebhookCallService

WebhookCalls returns the webhook call service for querying webhook call history.

func (*Client) Webhooks

func (c *Client) Webhooks() *service.WebhookService

Webhooks returns the webhook service for managing webhook configurations.

func (*Client) WhitelistedAddresses

func (c *Client) WhitelistedAddresses() *service.WhitelistedAddressService

WhitelistedAddresses returns the whitelisted address service for managing external addresses. The service always verifies the integrity of all retrieved addresses using the 6-step cryptographic verification flow with the configured SuperAdmin keys.

func (*Client) WhitelistedAssets

func (c *Client) WhitelistedAssets() *service.WhitelistedAssetService

WhitelistedAssets returns the whitelisted asset service for managing whitelisted contracts/tokens. The service always verifies the integrity of all retrieved assets using the cryptographic verification flow with the configured SuperAdmin keys.

func (*Client) WhitelistedContracts

func (c *Client) WhitelistedContracts() *service.WhitelistedContractService

WhitelistedContracts returns the whitelisted contract service for smart contract whitelisting.

type ConfigurationError

type ConfigurationError struct {
	Message string
	Err     error
}

ConfigurationError indicates invalid SDK configuration. This error is raised when the SDK is configured with invalid or incompatible settings, such as missing credentials or invalid key formats.

func (*ConfigurationError) Error

func (e *ConfigurationError) Error() string

func (*ConfigurationError) Is

func (e *ConfigurationError) Is(target error) bool

Is implements errors.Is for ConfigurationError.

func (*ConfigurationError) Unwrap

func (e *ConfigurationError) Unwrap() error

type IntegrityError

type IntegrityError struct {
	Message string
	Err     error
}

IntegrityError indicates a cryptographic verification failure. This is a security-critical error that should never be retried.

func (*IntegrityError) Error

func (e *IntegrityError) Error() string

func (*IntegrityError) Is

func (e *IntegrityError) Is(target error) bool

Is implements errors.Is for IntegrityError.

func (*IntegrityError) Unwrap

func (e *IntegrityError) Unwrap() error

type Option

type Option func(*clientConfig) error

Option configures a ProtectClient.

func WithCredentials

func WithCredentials(apiKey, apiSecret string) Option

WithCredentials sets the API key and secret for authentication. The apiSecret should be hex-encoded.

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

WithHTTPClient sets a custom HTTP client to use for requests. Note: The client's Transport will be wrapped with TPV1 authentication.

func WithHTTPTimeout

func WithHTTPTimeout(timeout time.Duration) Option

WithHTTPTimeout sets the timeout for HTTP requests. The default is 30 seconds.

func WithMinValidSignatures

func WithMinValidSignatures(n int) Option

WithMinValidSignatures sets the minimum number of valid SuperAdmin signatures required to verify governance rules.

func WithRulesCacheTTL

func WithRulesCacheTTL(ttl time.Duration) Option

WithRulesCacheTTL sets the TTL for the rules container cache. The default is 5 minutes.

func WithSuperAdminKeys

func WithSuperAdminKeys(keys []*ecdsa.PublicKey) Option

WithSuperAdminKeys sets the SuperAdmin public keys directly.

func WithSuperAdminKeysPEM

func WithSuperAdminKeysPEM(pemKeys []string) Option

WithSuperAdminKeysPEM sets the SuperAdmin public keys from PEM-encoded strings. These keys are used to verify governance rules signatures.

type RequestMetadataError

type RequestMetadataError struct {
	Message string
	Err     error
}

RequestMetadataError indicates missing or invalid request metadata.

func (*RequestMetadataError) Error

func (e *RequestMetadataError) Error() string

func (*RequestMetadataError) Is

func (e *RequestMetadataError) Is(target error) bool

Is implements errors.Is for RequestMetadataError.

func (*RequestMetadataError) Unwrap

func (e *RequestMetadataError) Unwrap() error

type TPV1Transport

type TPV1Transport struct {
	// Base is the underlying transport. If nil, http.DefaultTransport is used.
	Base http.RoundTripper
	// Auth provides TPV1 credentials for signing.
	Auth *crypto.TPV1Auth
}

TPV1Transport is an http.RoundTripper that signs requests with TPV1-HMAC-SHA256.

Important: This transport reads and clones the request body for signing. If you use middleware that wraps this transport and expects to retry requests, be aware that the original request body is consumed during signing. The transport properly resets the body on the cloned request, but middleware should not rely on re-reading the original request's body.

Middleware ordering: Place retry middleware ABOVE this transport (closer to the http.Client), so retries create fresh requests rather than reusing requests with consumed bodies.

func (*TPV1Transport) RoundTrip

func (t *TPV1Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip executes a single HTTP transaction, signing the request with TPV1.

type TaurusNetworkClient

type TaurusNetworkClient struct {
	// contains filtered or unexported fields
}

TaurusNetworkClient provides namespaced access to Taurus Network services. Use client.TaurusNetwork() to access this client.

Example usage:

client.TaurusNetwork().Participants().GetMyParticipant(ctx)
client.TaurusNetwork().Pledges().Create(ctx, req)
client.TaurusNetwork().Lending().GetAgreement(ctx, agreementID)
client.TaurusNetwork().Settlements().Get(ctx, settlementID)
client.TaurusNetwork().Sharing().ShareAddress(ctx, req)

func (*TaurusNetworkClient) Lending

Lending returns the lending offers and agreements service. Provides operations for managing lending offers and agreements.

func (*TaurusNetworkClient) Participants

Participants returns the participant management service. Provides operations for managing Taurus Network participants and their attributes.

func (*TaurusNetworkClient) Pledges

Pledges returns the pledge management service. Provides operations for creating, managing, and withdrawing pledges.

func (*TaurusNetworkClient) Settlements

Settlements returns the settlement management service. Provides operations for creating and managing settlements between participants.

func (*TaurusNetworkClient) Sharing

Sharing returns the address/asset sharing service. Provides operations for sharing and unsharing addresses and assets with other participants.

type WhitelistError

type WhitelistError struct {
	Message string
	Err     error
}

WhitelistError indicates a whitelist verification failure.

func (*WhitelistError) Error

func (e *WhitelistError) Error() string

func (*WhitelistError) Is

func (e *WhitelistError) Is(target error) bool

Is implements errors.Is for WhitelistError.

func (*WhitelistError) Unwrap

func (e *WhitelistError) Unwrap() error

Directories

Path Synopsis
Package cache provides thread-safe caching for the Taurus-PROTECT SDK.
Package cache provides thread-safe caching for the Taurus-PROTECT SDK.
Package crypto provides cryptographic utilities for the Taurus-PROTECT SDK.
Package crypto provides cryptographic utilities for the Taurus-PROTECT SDK.
Package helper provides signature verification and validation utilities.
Package helper provides signature verification and validation utilities.
Package mapper provides functions to convert between OpenAPI DTOs and domain models.
Package mapper provides functions to convert between OpenAPI DTOs and domain models.
Package service provides high-level service wrappers for the Taurus-PROTECT API.
Package service provides high-level service wrappers for the Taurus-PROTECT API.

Jump to

Keyboard shortcuts

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