connections

package
v0.76.1 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: AGPL-3.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExpirationDurationMustBeGreaterThan0          = errors.New("the expiration duration must be greater than 0")
	ErrHostnamesMismatchForThisToken                 = errors.New("the hostname from the request does not match the one that initiated the connection")
	ErrInvalidTokenFormat                            = errors.New("the token has not a valid format")
	ErrNoConnectionAssociatedThisAuthenticationToken = errors.New("there is no connection associated to this authentication token")
	ErrTokenDoesNotExist                             = errors.New("the token does not exist")
	ErrTokenHasExpired                               = errors.New("the token has expired")
	ErrTokenIsRequired                               = errors.New("the token is required")
	ErrWalletNameIsRequired                          = errors.New("the wallet name is required")
	ErrWalletPassphraseIsRequired                    = errors.New("the wallet passphrase is required")
)

Functions

func DeleteAPIToken

func DeleteAPIToken(tokenStore TokenStore, rawToken string) error

Types

type GenerateAPITokenHandler

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

func NewGenerateAPITokenHandler

func NewGenerateAPITokenHandler(
	walletStore api.WalletStore,
	tokenStore TokenStore,
	timeService TimeService,
) *GenerateAPITokenHandler

func (*GenerateAPITokenHandler) Handle

type GenerateAPITokenParams

type GenerateAPITokenParams struct {
	Description string                       `json:"name"`
	ExpiresIn   *time.Duration               `json:"expireIn"`
	Wallet      GenerateAPITokenWalletParams `json:"wallet"`
}

type GenerateAPITokenWalletParams

type GenerateAPITokenWalletParams struct {
	Name       string `json:"name"`
	Passphrase string `json:"passphrase"`
}

type ListAPITokensResult

type ListAPITokensResult struct {
	Tokens []TokenSummary `json:"tokens"`
}

func ListAPITokens

func ListAPITokens(tokenStore TokenStore) (ListAPITokensResult, error)

type Manager

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

Manager holds the opened connections between the third-party applications and the wallets.

func NewManager

func NewManager(timeService TimeService, walletStore WalletStore, tokenStore TokenStore, sessionStore SessionStore, interactor api.Interactor) (*Manager, error)

func (*Manager) ConnectedWallet

func (m *Manager) ConnectedWallet(ctx context.Context, hostname string, token Token) (api.ConnectedWallet, *jsonrpc.ErrorDetails)

ConnectedWallet retrieves the wallet associated to the specified token.

func (*Manager) EndAllSessionConnections

func (m *Manager) EndAllSessionConnections()

func (*Manager) EndSessionConnection

func (m *Manager) EndSessionConnection(hostname, walletName string)

func (*Manager) EndSessionConnectionWithToken

func (m *Manager) EndSessionConnectionWithToken(token Token)

func (*Manager) ListSessionConnections

func (m *Manager) ListSessionConnections() []api.Connection

ListSessionConnections lists all the session connections as a list of pairs of hostname/wallet name. The list is sorted, first, by hostname, and, then, by wallet name.

func (*Manager) StartSession

func (m *Manager) StartSession(hostname string, w wallet.Wallet) (Token, error)

StartSession initializes a connection between a wallet and a third-party application. If a connection already exists, it's disconnected and a new token is generated.

type Session added in v0.72.0

type Session struct {
	Token    Token  `json:"token"`
	Hostname string `json:"hostname"`
	Wallet   string `json:"wallet"`
}

type SessionStore added in v0.72.0

type SessionStore interface {
	ListSessions(context.Context) ([]Session, error)
	DeleteSession(context.Context, Token) error
	TrackSession(session Session) error
}

type TimeService

type TimeService interface {
	Now() time.Time
}

type Token

type Token string

func AsToken

func AsToken(token string) (Token, error)

func GenerateToken

func GenerateToken() Token

func (Token) Short

func (t Token) Short() string

func (Token) String

func (t Token) String() string

type TokenDescription

type TokenDescription struct {
	Description    string            `json:"description"`
	CreationDate   time.Time         `json:"creationDate"`
	ExpirationDate *time.Time        `json:"expirationDate"`
	Token          Token             `json:"token"`
	Wallet         WalletCredentials `json:"wallet"`
}

func DescribeAPIToken

func DescribeAPIToken(tokenStore TokenStore, rawToken string) (TokenDescription, error)

type TokenStore

type TokenStore interface {
	TokenExists(Token) (bool, error)
	ListTokens() ([]TokenSummary, error)
	DescribeToken(Token) (TokenDescription, error)
	SaveToken(TokenDescription) error
	DeleteToken(Token) error
	OnUpdate(callbackFn func(ctx context.Context, tokens ...TokenDescription))
}

TokenStore is the component used to retrieve and update the API tokens from the computer.

type TokenSummary

type TokenSummary struct {
	Description    string     `json:"description"`
	Token          Token      `json:"token"`
	CreationDate   time.Time  `json:"creationDate"`
	ExpirationDate *time.Time `json:"expirationDate"`
}

type WalletCredentials

type WalletCredentials struct {
	Name       string `json:"name"`
	Passphrase string `json:"passphrase"`
}

type WalletStore

type WalletStore interface {
	WalletExists(ctx context.Context, name string) (bool, error)
	UnlockWallet(ctx context.Context, name, passphrase string) error
	IsWalletAlreadyUnlocked(ctx context.Context, name string) (bool, error)
	GetWallet(ctx context.Context, name string) (wallet.Wallet, error)
	OnUpdate(callbackFn func(context.Context, wallet.Event))
}

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
store

Jump to

Keyboard shortcuts

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