common

package
v0.0.0-...-7608417 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAuthenticationExpired            = NewError("auth_expired", "authentication expired or not found")
	ErrAuthenticationVerificationFailed = NewError("auth_verification_failed", "authentication verification failed")
)
View Source
var (
	ErrAuthenticationFailed      = NewError("auth_failed", "authentication failed")
	ErrAuthenticationNotVerified = NewError("auth_not_verified", "authentication not verified")
)
View Source
var ErrInvalidPublicKey = NewError("invalid_public_key", "failed to generate address for this pair of chain and public key")

Functions

func RegisterProjectionsAsGroup

func RegisterProjectionsAsGroup(repo *eventsourcing.EventRepository, ps ...Projection) *eventsourcing.Group

RegisterProjectionsAsGroup registers a group of projections

func ResetAllProjections

func ResetAllProjections(db *sql.DB) error

ResetAllProjections resets all projections by dropping the projections table

func Validate

func Validate(i interface{}) error

Types

type AuthenticationDB

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

AuthenticationDB is a cache for storing authentication tokens

func NewAuthenticationDB

func NewAuthenticationDB() *AuthenticationDB

NewAuthenticationDB creates a new AuthenticationDB

func (*AuthenticationDB) ExtractTokenFromHttp

func (db *AuthenticationDB) ExtractTokenFromHttp(r *http.Request) (Token, error)

ExtractTokenFromHttp extracts an authentication token from the HTTP request Authorization header as a Bearer token

func (*AuthenticationDB) Get

func (a *AuthenticationDB) Get(id uuid.UUID) (Token, error)

Get retrieves an authentication token

func (*AuthenticationDB) Init

func (a *AuthenticationDB) Init(chain Chain, address string) (Token, error)

Init initializes an authentication token

func (*AuthenticationDB) Verify

func (a *AuthenticationDB) Verify(id uuid.UUID, signature []byte) error

Verify verifies an authentication token

type BaseProjection

type BaseProjection struct {
	*sql.DB
	// contains filtered or unexported fields
}

BaseProjection is a base struct for all projections and queries

func NewBaseProjection

func NewBaseProjection(db *sql.DB, store Store, name string) (*BaseProjection, error)

NewBaseProjection creates a new BaseProjection

func (*BaseProjection) Begin

func (bp *BaseProjection) Begin() (*sql.Tx, error)

Begin starts a new transaction for the projection

func (*BaseProjection) Fetch

func (bp *BaseProjection) Fetch() (core.Iterator, error)

Fetch fetches events from the store

type Chain

type Chain = string

Chain represents a blockchain network

const (
	ChainEthereum  Chain = "ETH"
	ChainThorchain Chain = "THOR"
)

type CommandHandler

type CommandHandler[C any] interface {
	Handle(ctx context.Context, cmd C) (string, error)
}

type Error

type Error struct {
	Code     string                 `json:"code,omitempty"`
	Message  string                 `json:"message,omitempty"`
	Internal error                  `json:"internal,omitempty"`
	Meta     map[string]interface{} `json:"meta,omitempty"`
}

Error is a domain error that includes a code, message, meta

func ErrorFromValidationErrors

func ErrorFromValidationErrors(errs validator.ValidationErrors) *Error

ErrorFromValidationErrors creates a domain error from a list of validation errors

func NewError

func NewError(code, message string) *Error

NewError creates a new domain error

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface

func (*Error) IncludeMeta

func (e *Error) IncludeMeta(meta map[string]interface{}) *Error

IncludeMeta includes meta data in the error

type FailSafeProjection

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

func NewFailSafeProjection

func NewFailSafeProjection(base Projection, logger zerolog.Logger) *FailSafeProjection

func (*FailSafeProjection) Callback

func (fsp *FailSafeProjection) Callback(event eventsourcing.Event) error

Callback implements the Callback method of the Projection interface

func (*FailSafeProjection) Fetch

func (fsp *FailSafeProjection) Fetch() (core.Iterator, error)

Fetch implements the Fetch method of the Projection interface

type Projection

type Projection interface {
	Fetch() (core.Iterator, error)
	Callback(eventsourcing.Event) error
}

type Store

type Store interface {
	All(start core.Version, count uint64) (core.Iterator, error)
}

Store is an interface that limits the methods that can be called on a store to All method only

type Token

type Token struct {
	Id        uuid.UUID `json:"id,omitempty"`
	Chain     Chain     `json:"chain,omitempty"`
	Address   string    `json:"address,omitempty"`
	IssuedAt  int64     `json:"issued_at,omitempty"`
	ExpiresAt int64     `json:"expires_at,omitempty"`
	Challenge string    `json:"challenge,omitempty"`
	Verified  bool      `json:"verified,omitempty"`
}

Token represents an authentication token

func (Token) Bytes

func (t Token) Bytes() []byte

Bytes returns the token as a byte slice

func (Token) VerifyChallenge

func (t Token) VerifyChallenge(signature []byte) error

VerifyChallenge verifies the challenge

Jump to

Keyboard shortcuts

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