session

package
v0.63.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoWalletConnected                       = errors.New("no wallet connected")
	ErrCannotEndLongLivingSessions             = errors.New("sessions attached to long-living tokens cannot be ended")
	ErrGeneratedTokenCollidesWithExistingToken = errors.New("the generated token collides with an existing token")
	ErrAPITokenExpired                         = errors.New("the token has expired")
)

Functions

func GenerateToken

func GenerateToken() string

Types

type ConnectedWallet

type ConnectedWallet struct {
	// Hostname is the hostname for which the connection is set.
	Hostname string
	// Wallet is the wallet selected by the client for this connection.
	Wallet wallet.Wallet
	// RestrictedKeys holds the keys that have been selected by the client
	// during the permissions request.
	RestrictedKeys map[string]wallet.KeyPair

	// An optional expiry date for this token
	Expiry *time.Time
	// contains filtered or unexported fields
}

ConnectedWallet contains the resources and the information of the current connection, required by the wallet handlers to work, and based on the permissions the client has set.

func NewConnectedWallet

func NewConnectedWallet(hostname string, w wallet.Wallet) (*ConnectedWallet, error)

func NewLongLivingConnectedWallet

func NewLongLivingConnectedWallet(w wallet.Wallet, now time.Time, expiry *time.Time) (*ConnectedWallet, error)

func (*ConnectedWallet) CanUseKey

func (s *ConnectedWallet) CanUseKey(pubKey string) bool

CanUseKey determines is the permissions allow the specified key to be used, and ensure the key exist and is not tainted.

func (*ConnectedWallet) Expired

func (s *ConnectedWallet) Expired(now time.Time) error

func (*ConnectedWallet) Permissions

func (s *ConnectedWallet) Permissions() wallet.Permissions

func (*ConnectedWallet) ReloadWithWallet

func (s *ConnectedWallet) ReloadWithWallet(updatedWallet wallet.Wallet) error

func (*ConnectedWallet) RequireInteraction

func (s *ConnectedWallet) RequireInteraction() bool

RequireInteraction tells if an interaction with the user is needed for supervision is required or not. It is related to the type of API token that is used for this connection. If it's a long-living token, then no interaction is required.

func (*ConnectedWallet) UpdatePermissions

func (s *ConnectedWallet) UpdatePermissions(perms wallet.Permissions) error

type Connection

type Connection struct {
	// Hostname is the hostname for which the connection is set.
	Hostname string `json:"hostname"`
	// Wallet is the wallet selected by the client for this connection.
	Wallet string `json:"wallet"`
}

type Sessions

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

Sessions holds the live sessions.

func NewSessions

func NewSessions() *Sessions

func (*Sessions) ConnectWallet

func (s *Sessions) ConnectWallet(hostname string, w wallet.Wallet) (string, error)

ConnectWallet initiates a wallet connection and load associated resources in it. If a connection already exists, it's disconnected and a new token is generated.

func (*Sessions) ConnectWalletForLongLivingConnection

func (s *Sessions) ConnectWalletForLongLivingConnection(
	token string, w wallet.Wallet, now time.Time, expiry *time.Time,
) error

func (*Sessions) DisconnectAllWallets

func (s *Sessions) DisconnectAllWallets()

func (*Sessions) DisconnectWallet

func (s *Sessions) DisconnectWallet(hostname, wallet string)

DisconnectWallet unloads the connected wallet resources and revokes the token. It does not fail. Non-existing token does nothing. This doesn't work for long-living connections.

func (*Sessions) DisconnectWalletWithToken

func (s *Sessions) DisconnectWalletWithToken(token string) error

DisconnectWalletWithToken looks for the connected wallet associated to the token, unloads its resources, and revokes the token. It does not fail. Non-existing token does nothing.

func (*Sessions) GetConnectedWallet

func (s *Sessions) GetConnectedWallet(token string, now time.Time) (*ConnectedWallet, error)

GetConnectedWallet retrieves the resources and information of the connected wallet, associated to the specified token.

func (*Sessions) ListConnections

func (s *Sessions) ListConnections() []Connection

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

type Token

type Token struct {
	Description string            `json:"description"`
	Expiry      *int64            `json:"expiry"`
	Token       string            `json:"token"`
	Wallet      WalletCredentials `json:"wallet"`
}

type TokenSummary

type TokenSummary struct {
	Description string    `json:"description"`
	Token       string    `json:"token"`
	CreateAt    time.Time `json:"createAt"`
	Expiry      *int64    `json:"expiry"`
}

type WalletCredentials

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

Directories

Path Synopsis
store
v1

Jump to

Keyboard shortcuts

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