api

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	Unsuccessful = Reply{Success: false, Version: pkg.Version()}
	NotFound     = Reply{Success: false, Error: "resource not found", Version: pkg.Version()}
	NotAllowed   = Reply{Success: false, Error: "method not allowed", Version: pkg.Version()}
)

Functions

func ContextWithRequestID

func ContextWithRequestID(parent context.Context, requestID string) context.Context

Adds a request ID to the context which is sent with the request in the X-Request-ID header.

func ErrorStatus

func ErrorStatus(err error) int

ErrorStatus returns the HTTP status code from an error or 500 if the error is not a StatusError.

func RequestIDFromContext

func RequestIDFromContext(ctx context.Context) (string, bool)

Extracts a request ID from the context.

func ValidationError

func ValidationError(err error, errs ...*FieldError) error

Types

type APIAuthentication

type APIAuthentication struct {
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
}

func (*APIAuthentication) Validate

func (r *APIAuthentication) Validate() (err error)

type APIv1

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

APIv1 implements the v1 Client interface for making requests to the TRISA SHN.

func (*APIv1) AccountDetail

func (s *APIv1) AccountDetail(ctx context.Context, id ulid.ULID) (out *Account, err error)

func (*APIv1) Authenticate

func (s *APIv1) Authenticate(ctx context.Context, in *APIAuthentication) (out *LoginReply, err error)

func (*APIv1) CounterpartyDetail

func (s *APIv1) CounterpartyDetail(ctx context.Context, id ulid.ULID) (out *Counterparty, err error)

func (*APIv1) Create

func (s *APIv1) Create(ctx context.Context, endpoint string, in, out interface{}) (err error)

func (*APIv1) CreateAccount

func (s *APIv1) CreateAccount(ctx context.Context, in *Account) (out *Account, err error)

func (*APIv1) CreateCounterparty

func (s *APIv1) CreateCounterparty(ctx context.Context, in *Counterparty) (out *Counterparty, err error)

func (*APIv1) CreateCryptoAddress

func (s *APIv1) CreateCryptoAddress(ctx context.Context, accountID ulid.ULID, in *CryptoAddress) (out *CryptoAddress, err error)

func (*APIv1) CreateTransaction

func (s *APIv1) CreateTransaction(ctx context.Context, in *Transaction) (out *Transaction, err error)

func (*APIv1) CryptoAddressDetail

func (s *APIv1) CryptoAddressDetail(ctx context.Context, accountID, cryptoAddressID ulid.ULID) (out *CryptoAddress, err error)

func (*APIv1) DecodeTravelAddress added in v0.12.0

func (s *APIv1) DecodeTravelAddress(ctx context.Context, in *TravelAddress) (out *TravelAddress, err error)

func (*APIv1) DecryptedEnvelopeDetail

func (s *APIv1) DecryptedEnvelopeDetail(ctx context.Context, transactionID uuid.UUID, envID ulid.ULID) (out *DecryptedEnvelope, err error)

func (*APIv1) Delete

func (s *APIv1) Delete(ctx context.Context, endpoint string) (err error)

func (*APIv1) DeleteAccount

func (s *APIv1) DeleteAccount(ctx context.Context, id ulid.ULID) (err error)

func (*APIv1) DeleteCounterparty

func (s *APIv1) DeleteCounterparty(ctx context.Context, id ulid.ULID) (err error)

func (*APIv1) DeleteCryptoAddress

func (s *APIv1) DeleteCryptoAddress(ctx context.Context, accountID, cryptoAddressID ulid.ULID) (err error)

func (*APIv1) DeleteSecureEnvelope

func (s *APIv1) DeleteSecureEnvelope(ctx context.Context, transactionID uuid.UUID, envID ulid.ULID) error

func (*APIv1) DeleteTransaction

func (s *APIv1) DeleteTransaction(ctx context.Context, id uuid.UUID) (err error)

func (*APIv1) Detail

func (s *APIv1) Detail(ctx context.Context, endpoint string, out interface{}) (err error)

func (*APIv1) Do

func (s *APIv1) Do(req *http.Request, data interface{}, checkStatus bool) (rep *http.Response, err error)

Do executes an http request against the server, performs error checking, and deserializes the response data into the specified struct.

func (*APIv1) EncodeTravelAddress added in v0.12.0

func (s *APIv1) EncodeTravelAddress(ctx context.Context, in *TravelAddress) (out *TravelAddress, err error)

func (*APIv1) List

func (s *APIv1) List(ctx context.Context, endpoint string, in *PageQuery, out interface{}) (err error)

func (*APIv1) ListAccounts

func (s *APIv1) ListAccounts(ctx context.Context, in *PageQuery) (out *AccountsList, err error)

func (*APIv1) ListCounterparties

func (s *APIv1) ListCounterparties(ctx context.Context, in *PageQuery) (out *CounterpartyList, err error)

func (*APIv1) ListCryptoAddresses

func (s *APIv1) ListCryptoAddresses(ctx context.Context, accountID ulid.ULID, in *PageQuery) (out *CryptoAddressList, err error)

func (*APIv1) ListSecureEnvelopes

func (s *APIv1) ListSecureEnvelopes(ctx context.Context, transactionID uuid.UUID, in *EnvelopeListQuery) (out *EnvelopesList, err error)

func (*APIv1) ListTransactions

func (s *APIv1) ListTransactions(ctx context.Context, in *PageQuery) (out *TransactionsList, err error)

func (*APIv1) Login

func (s *APIv1) Login(ctx context.Context, in *LoginRequest) (out *LoginReply, err error)

func (*APIv1) NewRequest

func (s *APIv1) NewRequest(ctx context.Context, method, path string, data interface{}, params *url.Values) (req *http.Request, err error)

func (*APIv1) Reauthenticate

func (s *APIv1) Reauthenticate(ctx context.Context, in *ReauthenticateRequest) (out *LoginReply, err error)

func (*APIv1) SecureEnvelopeDetail

func (s *APIv1) SecureEnvelopeDetail(ctx context.Context, transactionID uuid.UUID, envID ulid.ULID) (out *SecureEnvelope, err error)

func (*APIv1) Status

func (s *APIv1) Status(ctx context.Context) (out *StatusReply, err error)

func (*APIv1) TransactionDetail

func (s *APIv1) TransactionDetail(ctx context.Context, id uuid.UUID) (out *Transaction, err error)

func (*APIv1) Update

func (s *APIv1) Update(ctx context.Context, endpoint string, in, out interface{}) (err error)

func (*APIv1) UpdateAccount

func (s *APIv1) UpdateAccount(ctx context.Context, in *Account) (out *Account, err error)

func (*APIv1) UpdateCounterparty

func (s *APIv1) UpdateCounterparty(ctx context.Context, in *Counterparty) (out *Counterparty, err error)

func (*APIv1) UpdateCryptoAddress

func (s *APIv1) UpdateCryptoAddress(ctx context.Context, accountID ulid.ULID, in *CryptoAddress) (out *CryptoAddress, err error)

func (*APIv1) UpdateTransaction

func (s *APIv1) UpdateTransaction(ctx context.Context, in *Transaction) (out *Transaction, err error)

func (*APIv1) WaitForReady

func (s *APIv1) WaitForReady(ctx context.Context) (err error)

Wait for ready polls the node's status endpoint until it responds with an 200 response, retrying with exponential backoff or until the context deadline is expired. If the user does not supply a context with a deadline, then a default deadline of 5 minutes is used so that this method does not block indefinitely. If the node API service is ready (e.g. responds to a status request) then no error is returned, otherwise an error is returned if the node never responds.

NOTE: if the node returns a 503 Service Unavailable because it is in maintenance mode, this method will continue to wait until the deadline for the node to exit from maintenance mode and be ready again.

type Account

type Account struct {
	ID              ulid.ULID        `json:"id,omitempty"`
	CustomerID      string           `json:"customer_id"`
	FirstName       string           `json:"first_name"`
	LastName        string           `json:"last_name"`
	TravelAddress   string           `json:"travel_address,omitempty"`
	IVMSRecord      string           `json:"ivms101,omitempty"`
	CryptoAddresses []*CryptoAddress `json:"crypto_addresses"`
	Created         time.Time        `json:"created,omitempty"`
	Modified        time.Time        `json:"modified,omitempty"`
}

func NewAccount

func NewAccount(model *models.Account) (out *Account, err error)

func (*Account) Model

func (a *Account) Model() (model *models.Account, err error)

type AccountsList

type AccountsList struct {
	Page     *PageQuery `json:"page"`
	Accounts []*Account `json:"accounts"`
}

func NewAccountList

func NewAccountList(page *models.AccountsPage) (out *AccountsList, err error)

type Client

type Client interface {
	Status(context.Context) (*StatusReply, error)
	Login(context.Context, *LoginRequest) (*LoginReply, error)
	Authenticate(context.Context, *APIAuthentication) (*LoginReply, error)
	Reauthenticate(context.Context, *ReauthenticateRequest) (*LoginReply, error)

	// Transactions Resource
	ListTransactions(context.Context, *PageQuery) (*TransactionsList, error)
	CreateTransaction(context.Context, *Transaction) (*Transaction, error)
	TransactionDetail(context.Context, uuid.UUID) (*Transaction, error)
	UpdateTransaction(context.Context, *Transaction) (*Transaction, error)
	DeleteTransaction(context.Context, uuid.UUID) error

	// SecureEnvelopes Resource
	ListSecureEnvelopes(ctx context.Context, transactionID uuid.UUID, in *EnvelopeListQuery) (*EnvelopesList, error)
	SecureEnvelopeDetail(ctx context.Context, transactionID uuid.UUID, envID ulid.ULID) (*SecureEnvelope, error)
	DecryptedEnvelopeDetail(ctx context.Context, transactionID uuid.UUID, envID ulid.ULID) (*DecryptedEnvelope, error)
	DeleteSecureEnvelope(ctx context.Context, transactionID uuid.UUID, envID ulid.ULID) error

	// Accounts Resource
	ListAccounts(context.Context, *PageQuery) (*AccountsList, error)
	CreateAccount(context.Context, *Account) (*Account, error)
	AccountDetail(context.Context, ulid.ULID) (*Account, error)
	UpdateAccount(context.Context, *Account) (*Account, error)
	DeleteAccount(context.Context, ulid.ULID) error

	// CryptoAddress Resource
	ListCryptoAddresses(ctx context.Context, accountID ulid.ULID, in *PageQuery) (*CryptoAddressList, error)
	CreateCryptoAddress(ctx context.Context, accountID ulid.ULID, in *CryptoAddress) (*CryptoAddress, error)
	CryptoAddressDetail(ctx context.Context, accountID, cryptoAddressID ulid.ULID) (*CryptoAddress, error)
	UpdateCryptoAddress(ctx context.Context, accountID ulid.ULID, in *CryptoAddress) (*CryptoAddress, error)
	DeleteCryptoAddress(ctx context.Context, accountID, cryptoAddressID ulid.ULID) error

	// Counterparty Resource
	ListCounterparties(context.Context, *PageQuery) (*CounterpartyList, error)
	CreateCounterparty(context.Context, *Counterparty) (*Counterparty, error)
	CounterpartyDetail(context.Context, ulid.ULID) (*Counterparty, error)
	UpdateCounterparty(context.Context, *Counterparty) (*Counterparty, error)
	DeleteCounterparty(context.Context, ulid.ULID) error

	// Utilities
	EncodeTravelAddress(context.Context, *TravelAddress) (*TravelAddress, error)
	DecodeTravelAddress(context.Context, *TravelAddress) (*TravelAddress, error)
}

Client defines the service interface for interacting with the TRISA self-hosted node internal API (e.g. the API that users can integrate with).

func New

func New(endpoint string, opts ...ClientOption) (_ Client, err error)

New creates a new APIv1 client that implements the Client interface.

type ClientOption

type ClientOption func(c *APIv1) error

ClientOption allows us to configure the APIv1 client when it is created.

func WithClient

func WithClient(client *http.Client) ClientOption

type Counterparty

type Counterparty struct {
	ID                  ulid.ULID `json:"id,omitempty"`
	Source              string    `json:"source,omitempty"`
	DirectoryID         string    `json:"directory_id,omitempty"`
	RegisteredDirectory string    `json:"registered_directory,omitempty"`
	Protocol            string    `json:"protocol"`
	CommonName          string    `json:"common_name"`
	Endpoint            string    `json:"endpoint"`
	Name                string    `json:"name"`
	Website             string    `json:"website"`
	Country             string    `json:"country"`
	BusinessCategory    string    `json:"business_category"`
	VASPCategories      []string  `json:"vasp_categories"`
	VerifiedOn          time.Time `json:"verified_on"`
	IVMSRecord          string    `json:"ivms101,omitempty"`
	Created             time.Time `json:"created,omitempty"`
	Modified            time.Time `json:"modified,omitempty"`
}

func NewCounterparty

func NewCounterparty(model *models.Counterparty) (out *Counterparty, err error)

func (*Counterparty) Model

func (c *Counterparty) Model() (model *models.Counterparty, err error)

func (*Counterparty) Validate

func (c *Counterparty) Validate() (err error)

type CounterpartyList

type CounterpartyList struct {
	Page           *PageQuery      `json:"page"`
	Counterparties []*Counterparty `json:"counterparties"`
}

func NewCounterpartyList

func NewCounterpartyList(page *models.CounterpartyPage) (out *CounterpartyList, err error)

type CryptoAddress

type CryptoAddress struct {
	ID            ulid.ULID `json:"id,omitempty"`
	CryptoAddress string    `json:"crypto_address"`
	Network       string    `json:"network"`
	AssetType     string    `json:"asset_type"`
	Tag           string    `json:"tag"`
	TravelAddress string    `json:"travel_address,omitempty"`
	Created       time.Time `json:"created,omitempty"`
	Modified      time.Time `json:"modified,omitempty"`
}

func NewCryptoAddress

func NewCryptoAddress(model *models.CryptoAddress) (*CryptoAddress, error)

func (*CryptoAddress) Model

func (c *CryptoAddress) Model(acct *models.Account) (*models.CryptoAddress, error)

type CryptoAddressList

type CryptoAddressList struct {
	Page            *PageQuery       `json:"page"`
	CryptoAddresses []*CryptoAddress `json:"crypto_addresses"`
}

func NewCryptoAddressList

func NewCryptoAddressList(page *models.CryptoAddressPage) (out *CryptoAddressList, err error)

type DecryptedEnvelope

type DecryptedEnvelope struct {
	Identity    *ivms101.IdentityPayload `json:"identity,omitempty"`
	Transaction *generic.Transaction     `json:"transaction,omitempty"`
	Pending     *generic.Pending         `json:"pending,omitempty"`
	SentAt      time.Time                `json:"sent_at"`
	ReceivedAt  time.Time                `json:"received_at,omitempty"`
}

type DetailError

type DetailError struct {
	Field string `json:"field"`
	Error string `json:"error"`
}

type EnvelopeListQuery

type EnvelopeListQuery struct {
	PageQuery
	EnvelopeQuery
}

type EnvelopeQuery

type EnvelopeQuery struct {
	Decrypt  bool `json:"decrypt" url:"decrypt,omitempty" form:"decrypt"`
	Archives bool `json:"archives" url:"archives,omitempty" form:"archives"`
}

type EnvelopesList

type EnvelopesList struct {
	Page               *PageQuery           `json:"page"`
	IsDecrypted        bool                 `json:"is_decrypted"`
	SecureEnvelopes    []*SecureEnvelope    `json:"secure_envelopes,omitempty"`
	DecryptedEnvelopes []*DecryptedEnvelope `json:"decrypted_envelopes,omitempty"`
}

func NewSecureEnvelopeList

func NewSecureEnvelopeList(page *models.SecureEnvelopePage) (out *EnvelopesList, err error)

type ErrorDetail

type ErrorDetail []*DetailError

type FieldError

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

func IncorrectField

func IncorrectField(field, issue string) *FieldError

func MissingField

func MissingField(field string) *FieldError

func ReadOnlyField

func ReadOnlyField(field string) *FieldError

func (*FieldError) Error

func (e *FieldError) Error() string

type LoginReply

type LoginReply struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
}

type LoginRequest

type LoginRequest struct {
	Email    string `json:"email"`
	Password string `json:"password"`
	Next     string `json:"next"`
}

func (*LoginRequest) Validate

func (r *LoginRequest) Validate() (err error)

type PageQuery

type PageQuery struct {
	PageSize      int    `json:"page_size,omitempty" url:"page_size,omitempty" form:"page_size"`
	NextPageToken string `json:"next_page_token" url:"next_page_token,omitempty" form:"next_page_token"`
	PrevPageToken string `json:"prev_page_token" url:"prev_page_token,omitempty" form:"prev_page_token"`
}

PageQuery manages paginated list requests.

type Person

type Person struct {
	FirstName     string `json:"first_name"`
	LastName      string `json:"last_name"`
	CustomerID    string `json:"customer_id"`
	AddrLine1     string `json:"addr_line_1"`
	AddrLine2     string `json:"addr_line_2"`
	City          string `json:"city"`
	State         string `json:"state"`
	PostalCode    string `json:"post_code"`
	Country       string `json:"country"`
	CryptoAddress string `json:"crypto_address"`
}

func (*Person) NaturalPerson

func (p *Person) NaturalPerson() *ivms101.Person

type Prepare

type Prepare struct {
	TravelAddress string    `json:"travel_address"`
	Originator    *Person   `json:"originator"`
	Beneficiary   *Person   `json:"beneficiary"`
	Transfer      *Transfer `json:"transfer"`
}

func (*Prepare) Transaction

func (p *Prepare) Transaction() *generic.Transaction

func (*Prepare) Validate

func (p *Prepare) Validate() error

type Prepared

type Prepared struct {
	TravelAddress string                   `json:"travel_address"`
	Identity      *ivms101.IdentityPayload `json:"identity"`
	Transaction   *generic.Transaction     `json:"transaction"`
}

func (*Prepared) Dump

func (p *Prepared) Dump() string

func (*Prepared) Payload

func (p *Prepared) Payload() (payload *trisa.Payload, err error)

func (*Prepared) Validate

func (p *Prepared) Validate() error

type ReauthenticateRequest

type ReauthenticateRequest struct {
	RefreshToken string `json:"refresh_token"`
}

func (*ReauthenticateRequest) Validate

func (r *ReauthenticateRequest) Validate() (err error)

type Reply

type Reply struct {
	Success     bool        `json:"success"`
	Error       string      `json:"error,omitempty"`
	Version     string      `json:"version,omitempty"`
	ErrorDetail ErrorDetail `json:"errors,omitempty"`
}

Reply contains standard fields that are used for generic API responses and errors.

func Error

func Error(err interface{}) Reply

Construct a new response for an error or simply return unsuccessful.

type SecureEnvelope

type SecureEnvelope struct {
	ID                  ulid.ULID    `json:"id"`
	Direction           string       `json:"direction"`
	EnvelopeID          uuid.UUID    `json:"envelope_id"`
	Payload             []byte       `json:"payload,omitempty"`
	EncryptionKey       []byte       `json:"encryption_key,omitempty"`
	EncryptionAlgorithm string       `json:"encryption_algorithm,omitempty"`
	ValidHMAC           bool         `json:"valid_hmac"`
	HMAC                []byte       `json:"hmac,omitempty"`
	HMACSecret          []byte       `json:"hmac_secret,omitempty"`
	HMACAlgorithm       string       `json:"hmac_algorithm,omitempty"`
	IsError             bool         `json:"is_error"`
	Error               *trisa.Error `json:"error,omitempty"`
	Timestamp           time.Time    `json:"timestamp"`
	Sealed              bool         `json:"sealed"`
	PublicKeySignature  string       `json:"public_key_signature,omitempty"`
	Original            []byte       `json:"original,omitempty"`
}

func NewSecureEnvelope

func NewSecureEnvelope(model *models.SecureEnvelope) (out *SecureEnvelope, err error)

type StatusError

type StatusError struct {
	StatusCode int
	Reply      Reply
}

StatusError decodes an error response from the TRISA API.

func (*StatusError) Error

func (e *StatusError) Error() string

type StatusReply

type StatusReply struct {
	Status  string `json:"status"`
	Uptime  string `json:"uptime,omitempty"`
	Version string `json:"version,omitempty"`
}

Returned on status requests.

type Transaction

type Transaction struct {
	ID                 uuid.UUID  `json:"id"`
	Source             string     `json:"source"`
	Status             string     `json:"status"`
	Counterparty       string     `json:"counterparty"`
	CounterpartyID     ulid.ULID  `json:"counterparty_id,omitempty"`
	Originator         string     `json:"originator,omitempty"`
	OriginatorAddress  string     `json:"orginator_address,omitempty"`
	Beneficiary        string     `json:"beneficiary,omitempty"`
	BeneficiaryAddress string     `json:"beneficiary_address,omitempty"`
	VirtualAsset       string     `json:"virtual_asset"`
	Amount             float64    `json:"amount"`
	LastUpdate         *time.Time `json:"last_update,omitempty"`
	EnvelopeCount      int64      `json:"envelope_count,omitempty"`
	Created            time.Time  `json:"created"`
	Modified           time.Time  `json:"modified"`
}

func NewTransaction

func NewTransaction(model *models.Transaction) (*Transaction, error)

func (*Transaction) Model

func (c *Transaction) Model() (model *models.Transaction, err error)

func (*Transaction) Validate

func (c *Transaction) Validate() (err error)

type TransactionsList

type TransactionsList struct {
	Page         *PageQuery     `json:"page"`
	Transactions []*Transaction `json:"transactions"`
}

func NewTransactionList

func NewTransactionList(page *models.TransactionPage) (out *TransactionsList, err error)

type Transfer

type Transfer struct {
	Amount    float64 `json:"amount"`
	Network   string  `json:"network"`
	AssetType string  `json:"asset_type"`
	TxID      string  `json:"transaction_id"`
	Tag       string  `json:"tag"`
}

type TravelAddress added in v0.12.0

type TravelAddress struct {
	Encoded string `json:"encoded,omitempty"`
	Decoded string `json:"decoded,omitempty"`
}

func (*TravelAddress) ValidateDecode added in v0.12.0

func (t *TravelAddress) ValidateDecode() (err error)

func (*TravelAddress) ValidateEncode added in v0.12.0

func (t *TravelAddress) ValidateEncode() (err error)

type ValidationErrors

type ValidationErrors []*FieldError
Example
err := api.ValidationError(
	nil,
	api.MissingField("name"),
	api.IncorrectField("ssn", "ssn should be 8 digits only"),
	nil,
	api.MissingField("date_of_birth"),
	nil,
)

fmt.Println(err)
Output:

	3 validation errors occurred:
  missing name: this field is required
  invalid field ssn: ssn should be 8 digits only
  missing date_of_birth: this field is required

func (ValidationErrors) Error

func (e ValidationErrors) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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