anchorplatform

package
v0.0.0-...-4a8fab6 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrJWTManagerNotSet    = fmt.Errorf("jwt manager not set")
	ErrAuthNotEnforcedOnAP = fmt.Errorf("anchor platform is not enforcing authentication")
	ErrServiceUnavailable  = fmt.Errorf("anchor platform service is unavailable")
)
View Source
var ErrInvalidToken = fmt.Errorf("invalid token")

Functions

func NewStellarAssetInAIF

func NewStellarAssetInAIF(assetCode, assetIssuer string) string

NewAnchorPlatformStellarAsset creates a stellar asset using the [Asset Identification Format](https://stellar.org/protocol/sep-38#asset-identification-format)

func SEP24HeaderTokenAuthenticateMiddleware

func SEP24HeaderTokenAuthenticateMiddleware(jwtManager *JWTManager, networkPassphrase string, tenantManager tenant.ManagerInterface, singleTenantMode bool) func(http.Handler) http.Handler

SEP24HeaderTokenAuthenticateMiddleware is a middleware that validates if the token passed in the 'Authorization' header is valid for the authenticated endpoints.

func SEP24QueryTokenAuthenticateMiddleware

func SEP24QueryTokenAuthenticateMiddleware(jwtManager *JWTManager, networkPassphrase string, tenantManager tenant.ManagerInterface, singleTenantMode bool) func(http.Handler) http.Handler

SEP24QueryTokenAuthenticateMiddleware is a middleware that validates if the token passed in as a query parameter with ?token={token} is valid for the authenticated endpoints.

Types

type APAmount

type APAmount struct {
	Amount string `json:"amount"`
	Asset  string `json:"asset"`
}

APAmount is the body of the Stellar amount stored in the Anchor Platform.

type APSep24Transaction

type APSep24Transaction struct {
	APSep24TransactionPatch
	// Kind can be "deposit" or "withdrawal". It's a read-only field.
	Kind           string    `json:"kind,omitempty"`
	AmountExpected *APAmount `json:"amount_expected,omitempty"`

	// These fields are patchable but they are already set by the AP, so I'm leaving them out of the patch:
	UpdatedAt *time.Time `json:"updated_at,omitempty"`
	StartedAt *time.Time `json:"started_at,omitempty"`
	Memo      string     `json:"memo,omitempty"`
	MemoType  string     `json:"memo_type,omitempty"`
	AmountIn  *APAmount  `json:"amount_in,omitempty"`
}

APSep24Transaction is the transaction object used in the `{PlatformAPIBaseURL}/transactions` requests.

type APSep24TransactionPatch

type APSep24TransactionPatch struct {
	// Identifiers:
	ID                    string `json:"id"`
	ExternalTransactionID string `json:"external_transaction_id,omitempty"`

	// Status
	SEP                 string                 `json:"sep,omitempty"`
	Status              APTransactionStatus    `json:"status,omitempty"`
	StellarTransactions []APStellarTransaction `json:"stellar_transactions,omitempty"`
	Message             string                 `json:"message,omitempty"`

	// Amounts
	AmountOut *APAmount `json:"amount_out,omitempty"`
	AmountFee *APAmount `json:"amount_fee,omitempty"`

	// Accounts
	SourceAccount      string `json:"source_account,omitempty"`
	DestinationAccount string `json:"destination_account,omitempty"`

	// Dates
	CompletedAt        *time.Time `json:"completed_at,omitempty"`
	TransferReceivedAt *time.Time `json:"transfer_received_at,omitempty"`
}

APSep24TransactionPatch is the transaction object used in the `PATCH {PlatformAPIBaseURL}/transactions` request. It's be used to update the transaction data.

type APSep24TransactionPatchPostError

type APSep24TransactionPatchPostError struct {
	ID      string              `json:"id"`
	SEP     string              `json:"sep,omitempty"`
	Message string              `json:"message,omitempty"` // Error message
	Status  APTransactionStatus `json:"status,omitempty"`  // Error

}

type APSep24TransactionPatchPostRegistration

type APSep24TransactionPatchPostRegistration struct {
	ID                    string              `json:"id"`
	ExternalTransactionID string              `json:"external_transaction_id,omitempty"`
	SEP                   string              `json:"sep,omitempty"`
	Status                APTransactionStatus `json:"status,omitempty"`
	Message               string              `json:"message,omitempty"`
	TransferReceivedAt    *time.Time          `json:"transfer_received_at,omitempty"`
}

APSep24TransactionPatchPostRegistration is a subset of APSep24TransactionPatch that can be used to update the transaction data after the registration.

type APSep24TransactionPatchPostSuccess

type APSep24TransactionPatchPostSuccess struct {
	ID                  string                 `json:"id"`
	SEP                 string                 `json:"sep,omitempty"`
	Status              APTransactionStatus    `json:"status,omitempty"` // Success
	StellarTransactions []APStellarTransaction `json:"stellar_transactions,omitempty"`
	// Message             string                 `json:"message,omitempty"`
	CompletedAt *time.Time `json:"completed_at,omitempty"`
	AmountOut   APAmount   `json:"amount_out,omitempty"`
}

type APSep24TransactionRecords

type APSep24TransactionRecords struct {
	Records []APSep24TransactionWrapper `json:"records"`
}

APSep24TransactionRecords is a struct used for composing the HTTP body of a request or response to `{PlatformAPIBaseURL}/transactions`. It structures the body in the following format:

	{
	  "records": [
       {
         "transaction": {...}
       },
       ...
     ]
	}

The `records` field contains a slice of APSep24TransactionWrapper, each wrapping an APSep24Transaction.

func NewAPSep24TransactionRecordsFromPatches

func NewAPSep24TransactionRecordsFromPatches(patches ...APSep24TransactionPatch) APSep24TransactionRecords

type APSep24TransactionWrapper

type APSep24TransactionWrapper struct {
	APSep24Transaction `json:"transaction"`
}

APSep24TransactionWrapper is a struct that wraps an APSep24Transaction for use in a request or response to `{PlatformAPIBaseURL}/transactions`. It structures the "transaction" field in the following format within a record:

{
  "transaction": {...}
}

The `APSep24Transaction` field contains the transaction data.

type APStellarTransaction

type APStellarTransaction struct {
	ID       string `json:"id"`
	Memo     string `json:"memo,omitempty"`
	MemoType string `json:"memo_type,omitempty"`
}

APTransactionStatus is the body of the Stellar transaction stored in the Anchor Platform.

type APTransactionStatus

type APTransactionStatus string
const (
	APTransactionStatusCompleted     APTransactionStatus = "completed"
	APTransactionStatusError         APTransactionStatus = "error"
	APTransactionStatusPendingAnchor APTransactionStatus = "pending_anchor"
)

type AnchorPlatformAPIService

type AnchorPlatformAPIService struct {
	HttpClient                    httpclient.HttpClientInterface
	AnchorPlatformBasePlatformURL string
	// contains filtered or unexported fields
}

func NewAnchorPlatformAPIService

func NewAnchorPlatformAPIService(httpClient httpclient.HttpClientInterface, anchorPlatformBasePlatformURL, anchorPlatformOutgoingJWTSecret string) (*AnchorPlatformAPIService, error)

func (*AnchorPlatformAPIService) GetJWTToken

func (a *AnchorPlatformAPIService) GetJWTToken(apTx ...APSep24TransactionPatch) (string, error)

GetJWTToken will generate a JWT token if the service is configured with an outgoing JWT secret.

func (*AnchorPlatformAPIService) IsAnchorProtectedByAuth

func (a *AnchorPlatformAPIService) IsAnchorProtectedByAuth(ctx context.Context) (bool, error)

func (*AnchorPlatformAPIService) PatchAnchorTransactionsPostErrorCompletion

func (a *AnchorPlatformAPIService) PatchAnchorTransactionsPostErrorCompletion(ctx context.Context, apTxPostErrorCompletion ...APSep24TransactionPatchPostError) error

func (*AnchorPlatformAPIService) PatchAnchorTransactionsPostRegistration

func (a *AnchorPlatformAPIService) PatchAnchorTransactionsPostRegistration(ctx context.Context, apTxPostRegistrationPatch ...APSep24TransactionPatchPostRegistration) error

func (*AnchorPlatformAPIService) PatchAnchorTransactionsPostSuccessCompletion

func (a *AnchorPlatformAPIService) PatchAnchorTransactionsPostSuccessCompletion(ctx context.Context, apTxPostSuccessCompletion ...APSep24TransactionPatchPostSuccess) error

type AnchorPlatformAPIServiceInterface

type AnchorPlatformAPIServiceInterface interface {
	PatchAnchorTransactionsPostRegistration(ctx context.Context, apTxPatch ...APSep24TransactionPatchPostRegistration) error
	PatchAnchorTransactionsPostSuccessCompletion(ctx context.Context, apTxPatch ...APSep24TransactionPatchPostSuccess) error
	PatchAnchorTransactionsPostErrorCompletion(ctx context.Context, apTxPatch ...APSep24TransactionPatchPostError) error
	IsAnchorProtectedByAuth(ctx context.Context) (bool, error)
}

type AnchorPlatformAPIServiceMock

type AnchorPlatformAPIServiceMock struct {
	mock.Mock
}

func (*AnchorPlatformAPIServiceMock) IsAnchorProtectedByAuth

func (a *AnchorPlatformAPIServiceMock) IsAnchorProtectedByAuth(ctx context.Context) (bool, error)

func (*AnchorPlatformAPIServiceMock) PatchAnchorTransactionsPostErrorCompletion

func (a *AnchorPlatformAPIServiceMock) PatchAnchorTransactionsPostErrorCompletion(ctx context.Context, apTxPatch ...APSep24TransactionPatchPostError) error

func (*AnchorPlatformAPIServiceMock) PatchAnchorTransactionsPostRegistration

func (a *AnchorPlatformAPIServiceMock) PatchAnchorTransactionsPostRegistration(ctx context.Context, apTxPatch ...APSep24TransactionPatchPostRegistration) error

func (*AnchorPlatformAPIServiceMock) PatchAnchorTransactionsPostSuccessCompletion

func (a *AnchorPlatformAPIServiceMock) PatchAnchorTransactionsPostSuccessCompletion(ctx context.Context, apTxPatch ...APSep24TransactionPatchPostSuccess) error

type ContextType

type ContextType string
const SEP24ClaimsContextKey ContextType = "sep24_claims"

type GetTransactionsQueryParams

type GetTransactionsQueryParams struct {
	SEP        string   `schema:"sep,required,omitempty"`
	Order      string   `schema:"order,omitempty"`
	OrderBy    string   `schema:"order_by,omitempty"`
	PageNumber int      `schema:"page_number,omitempty"`
	PageSize   int      `schema:"page_size,omitempty"`
	Statuses   []string `schema:"statuses,omitempty"`
}

GetTransactionsQueryParams are the query parameters that can be used in the `GET {PlatformAPIBaseURL}/transactions` request.

type JWTManager

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

func NewJWTManager

func NewJWTManager(secret string, expirationMiliseconds int64) (*JWTManager, error)

NewJWTManager creates a new JWTManager instance based on the provided secret and expirationMiliseconds.

func (*JWTManager) GenerateDefaultToken

func (manager *JWTManager) GenerateDefaultToken(id string) (string, error)

GenerateDefaultToken will generate a JWT token string using the token manager and only the default claims.

func (*JWTManager) GenerateSEP24Token

func (manager *JWTManager) GenerateSEP24Token(stellarAccount, stellarMemo, clientDomain, homeDomain, transactionID string) (string, error)

GenerateSEP24Token will generate a JWT token string using the token manager and the provided parameters. The parameters are validated before generating the token.

func (*JWTManager) ParseDefaultTokenClaims

func (manager *JWTManager) ParseDefaultTokenClaims(tokenString string) (*jwt.RegisteredClaims, error)

ParseDefaultTokenClaims will parse the default claims from a JWT token string.

func (*JWTManager) ParseSEP24TokenClaims

func (manager *JWTManager) ParseSEP24TokenClaims(tokenString string) (*SEP24JWTClaims, error)

ParseSEP24TokenClaims will parse the provided token string and return the SEP24JWTClaims, if possible. If the token is not a valid SEP-24 token, an error is returned instead.

type SEP24JWTClaims

type SEP24JWTClaims struct {
	// Fields expected according with https://github.com/stellar/java-stellar-anchor-sdk/blob/bfa9b1d735f099bc6a21f0b9c55bd381a50c16b8/platform/src/main/java/org/stellar/anchor/platform/service/SimpleInteractiveUrlConstructor.java#L47-L56
	ClientDomainClaim string `json:"client_domain"`
	HomeDomainClaim   string `json:"home_domain"`
	jwt.RegisteredClaims
}

func GetSEP24Claims

func GetSEP24Claims(ctx context.Context) *SEP24JWTClaims

func (*SEP24JWTClaims) ClientDomain

func (c *SEP24JWTClaims) ClientDomain() string

func (*SEP24JWTClaims) ExpiresAt

func (c *SEP24JWTClaims) ExpiresAt() *time.Time

func (*SEP24JWTClaims) HomeDomain

func (c *SEP24JWTClaims) HomeDomain() string

func (*SEP24JWTClaims) SEP10StellarAccount

func (c *SEP24JWTClaims) SEP10StellarAccount() string

func (*SEP24JWTClaims) SEP10StellarMemo

func (c *SEP24JWTClaims) SEP10StellarMemo() string

func (*SEP24JWTClaims) TransactionID

func (c *SEP24JWTClaims) TransactionID() string

func (SEP24JWTClaims) Valid

func (c SEP24JWTClaims) Valid() error

type SEP24RequestQuery

type SEP24RequestQuery struct {
	Token         string `query:"token"`
	TransactionID string `query:"transaction_id"`
}

Jump to

Keyboard shortcuts

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