client

package
v0.0.0-...-1b5cee2 Latest Latest
Warning

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

Go to latest
Published: May 15, 2023 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrApiVersionMismatch            = fmt.Errorf("api version mismatch")
	ErrApiHeaderMismatch             = fmt.Errorf("api header mismatch")
	ErrStatusCodeMismatch            = fmt.Errorf("status code mismatch")
	ErrContentTypeMismatch           = fmt.Errorf("content type mismatch")
	ErrWalletChecksumMismatch        = fmt.Errorf("wallet checksum mismatch")
	ErrWalletVersionMismatch         = fmt.Errorf("wallet version mismatch")
	ErrServerReturnsInconsistentData = fmt.Errorf("server returns inconsistent data")
	ErrRejectedByServer              = fmt.Errorf("rejected by server")
	ErrWalletNotReady                = fmt.Errorf("wallet not ready, read wallet first")
	ErrSigningFailed                 = fmt.Errorf("signing failed")
)

Functions

This section is empty.

Types

type Client

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

Client is a rest client for the API. It provides methods to communicate with the API server and is designed to serve as a easy way of building client applications that uses the REST API of the central node.

func NewClient

func NewClient(
	apiRoot string, timeout time.Duration, fw transaction.Verifier,
	wrs WalletReadSaver, walletCreator NewSignValidatorCreator,
) *Client

NewClient creates a new rest client.

func (*Client) Address

func (c *Client) Address() (string, error)

Address reads the wallet address. Address is a string representation of wallet public key.

func (*Client) ConfirmTransaction

func (c *Client) ConfirmTransaction(trx *transaction.Transaction) error

ConfirmTransaction confirms transaction by signing it with the wallet and then sending it to the API server.

func (*Client) DataToSign

func (c *Client) DataToSign(address string) (server.DataToSignResponse, error)

DataToSign returns data to sign for the given address. Data to sign are randomly generated bytes by the server and stored in pair with the address. Signing this data is a proof that the signing public address is the owner of the wallet a making request.

func (*Client) FlushWalletFromMemory

func (c *Client) FlushWalletFromMemory()

FlushWalletFromMemory flushes the wallet from the memory. Do it after you have saved the wallet to the file. It is recommended to use this just before logging out from the UI or closing the front end app that.

func (*Client) GenerateToken

func (c *Client) GenerateToken(t time.Time) (token.Token, error)

GenerateToken generates a token for the given time in the central node repository. It is only permitted to generate a token if wallet has admin permissions in the central node.

func (*Client) NewWallet

func (c *Client) NewWallet(token string) error

NewWallet creates a new wallet and sends a request to the API server to validate the wallet.

func (*Client) PostWebhookBlock

func (c *Client) PostWebhookBlock(url string, token string, block *block.Block) error

PostWebhookBlock posts validator.WebHookNewBlockMessage to given url.

func (*Client) ProposeTransaction

func (c *Client) ProposeTransaction(receiverAddr string, subject string, data []byte) error

ProposeTransaction sends a Transaction proposal to the API server for provided receiver address. Subject describes how to read the data from the transaction. For example, if the subject is "json", then the data can by decoded to map[sting]any, when subject "pdf" than it should be decoded by proper pdf decoder, when "csv" then it should be decoded by proper csv decoder. Client is not responsible for decoding the data, it is only responsible for sending the data to the API server.

func (*Client) ReadIssuedTransactions

func (c *Client) ReadIssuedTransactions() ([]transaction.Transaction, error)

ReadIssuedTransactions reads all issued transactions belonging to current wallet from the API server.

func (*Client) ReadWaitingTransactions

func (c *Client) ReadWaitingTransactions() ([]transaction.Transaction, error)

ReadWaitingTransactions reads all waiting transactions belonging to current wallet from the API server.

func (*Client) ReadWalletFromFile

func (c *Client) ReadWalletFromFile() error

ReadWalletFromFile reads the wallet from the file in the path.

func (*Client) SaveWalletToFile

func (c *Client) SaveWalletToFile() error

SaveWalletToFile saves the wallet to the file in the path.

func (*Client) Sign

func (c *Client) Sign(d []byte) (digest [32]byte, signature []byte, err error)

Sign signs the given data with the wallet and returns digest and signature or error otherwise. This process creates a proof for the API server that requesting client is the owner of the wallet.

func (*Client) ValidateApiVersion

func (c *Client) ValidateApiVersion() error

ValidateApiVersion makes a call to the API server and validates client and server API versions and header correctness. If API version not much it is returning an error as accessing the API server with different API version may lead to unexpected results.

type NewSignValidatorCreator

type NewSignValidatorCreator func() (wallet.Wallet, error)

NewWalletCreator is a function that creates a new SignValidator.

type WalletReadSaver

type WalletReadSaver interface {
	ReadWallet() (wallet.Wallet, error)
	SaveWallet(w wallet.Wallet) error
}

WalletReadSaver allows to read and save the wallet.

Jump to

Keyboard shortcuts

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