wallet

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidParameter = errors.New("invalid parameter")
	ErrNotFound         = errors.New("not found")
	ErrInvalidPIN       = errors.New("invalid pin code")
	ErrForbidden        = errors.New("forbidden")
	ErrUnauthorized     = errors.New("unauthorized")
)

Predefined package errors

Functions

func MakeChangeWalletPinEndpoint

func MakeChangeWalletPinEndpoint(s Service) endpoint.Endpoint

MakeChangeWalletPinEndpoint returns an endpoint function for the ChangeWalletPin method.

func MakeDeleteWalletEndpoint

func MakeDeleteWalletEndpoint(s Service) endpoint.Endpoint

MakeDeleteWalletEndpoint returns an endpoint function for the DeleteWallet method.

func MakeExportWalletEndpoint

func MakeExportWalletEndpoint(s Service) endpoint.Endpoint

MakeExportWalletEndpoint returns an endpoint function for the ExportWallet method.

func MakeGenerateWalletEndpoint

func MakeGenerateWalletEndpoint(s Service) endpoint.Endpoint

MakeGenerateWalletEndpoint returns an endpoint function for the GenerateWallet method.

func MakeGetWalletEndpoint

func MakeGetWalletEndpoint(s Service) endpoint.Endpoint

MakeGetWalletEndpoint returns an endpoint function for the GetWallet method.

func MakeHTTPHandler

func MakeHTTPHandler(e Endpoints, log logger) http.Handler

MakeHTTPHandler ...

func MakeSignAndSendTransactionEndpoint

func MakeSignAndSendTransactionEndpoint(s Service) endpoint.Endpoint

MakeSignAndSendTransactionEndpoint returns an endpoint function for the SignAndSendTransaction method.

func MakeSignMessageEndpoint

func MakeSignMessageEndpoint(s Service) endpoint.Endpoint

MakeSignMessageEndpoint returns an endpoint function for the SignMessage method.

func MakeSignTransactionEndpoint

func MakeSignTransactionEndpoint(s Service) endpoint.Endpoint

MakeSignTransactionEndpoint returns an endpoint function for the SignTransaction method.

func MakeStoreWalletEndpoint

func MakeStoreWalletEndpoint(s Service) endpoint.Endpoint

MakeStoreWalletEndpoint returns an endpoint function for the StoreWallet method.

func MakeUpdateWalletNameEndpoint

func MakeUpdateWalletNameEndpoint(s Service) endpoint.Endpoint

MakeUpdateWalletNameEndpoint returns an endpoint function for the UpdateWalletName method.

Types

type ChangeWalletPinRequest

type ChangeWalletPinRequest struct {
	Pin    string `json:"pin" validate:"required" label:"PIN Code"`
	NewPin string `json:"new_pin" validate:"required|minLen:4|maxLen:50" label:"New PIN Code"`
}

ChangeWalletPinRequest is a request for ChangeWalletPin method

type DeleteWalletRequest

type DeleteWalletRequest struct {
	Pin string `json:"pin" validate:"required" label:"PIN Code"`
}

DeleteWalletRequest is a request for DeleteWallet method

type Endpoints

type Endpoints struct {
	GenerateWallet         endpoint.Endpoint
	StoreWallet            endpoint.Endpoint
	GetWallet              endpoint.Endpoint
	DeleteWallet           endpoint.Endpoint
	UpdateWalletName       endpoint.Endpoint
	ChangeWalletPin        endpoint.Endpoint
	ExportWallet           endpoint.Endpoint
	SignTransaction        endpoint.Endpoint
	SignMessage            endpoint.Endpoint
	SignAndSendTransaction endpoint.Endpoint
}

Endpoints collection of profile Service

func MakeEndpoints

func MakeEndpoints(s Service, m ...endpoint.Middleware) Endpoints

Init endpoints

type ExportWalletRequest

type ExportWalletRequest struct {
	Pin string `json:"pin" validate:"required" label:"PIN Code"`
}

ExportWalletRequest is a request for ExportWallet method

type Service

type Service interface {
	// Generate new wallet
	GenerateWallet(ctx context.Context) (Wallet, error)
	// Store wallet
	StoreWallet(ctx context.Context, uid, pin, mnemonic, name string) error
	// Get wallet by user id
	GetWallet(ctx context.Context, uid string) (Wallet, error)
	// Delete wallet by user id
	DeleteWallet(ctx context.Context, uid string, pin string) error
	// Update wallet name
	UpdateWalletName(ctx context.Context, uid string, pin string, name string) error
	// Change wallet pin
	ChangeWalletPin(ctx context.Context, uid string, pin string, newPin string) error
	// Export wallet
	ExportWallet(ctx context.Context, uid string, pin string) (Wallet, error)
	// Sign transaction and return signed transaction as base64 string
	SignTransaction(ctx context.Context, uid string, pin string, base64Tx string) (string, error)
	// Sign message and return signed message as base64 string
	SignMessage(ctx context.Context, uid string, pin string, base64Msg string) (msg, signature string, err error)
	// Sign and send transaction, return transaction signature
	SignAndSendTransaction(ctx context.Context, uid string, pin string, base64Tx string) (string, error)
}

Service interface

func NewService

func NewService(repo walletRepository, wallet solanaWallet, solana solanaClient) Service

NewService is a factory function, returns a new instance of the Service interface implementation

type SignAndSendTransactionRequest

type SignAndSendTransactionRequest struct {
	Pin string `json:"pin" validate:"required" label:"PIN Code"`
	Tx  string `json:"tx" validate:"required" label:"Base64 encoded transaction"`
}

SignAndSendTransactionRequest is a request for SignAndSendTransaction method

type SignAndSendTransactionResponse

type SignAndSendTransactionResponse struct {
	TxSignature string `json:"tx_signature" label:"Transaction signature"`
}

SignAndSendTransactionResponse is a response for SignAndSendTransaction method

type SignMessageRequest

type SignMessageRequest struct {
	Pin string `json:"pin" validate:"required" label:"PIN Code"`
	Msg string `json:"msg" validate:"required" label:"Message"`
}

SignMessageRequest is a request for SignMessage method

type SignMessageResponse

type SignMessageResponse struct {
	Signature string `json:"signature" label:"Signature"`
	Msg       string `json:"msg" label:"Message"`
}

SignMessageResponse is a response for SignMessage method

type SignTransactionRequest

type SignTransactionRequest struct {
	Pin string `json:"pin" validate:"required" label:"PIN Code"`
	Tx  string `json:"tx" validate:"required" label:"Base64 encoded transaction"`
}

SignTransactionRequest is a request for SignTransaction method

type StoreWalletRequest

type StoreWalletRequest struct {
	Name     string `json:"name" validate:"required|minLen:3|maxLen:50" label:"Name"`
	Pin      string `json:"pin" validate:"required|minLen:4|maxLen:50" label:"PIN Code"`
	Mnemonic string `json:"mnemonic" validate:"required" label:"Mnemonic"`
}

StoreWalletRequest is a request for StoreWallet method

type UpdateWalletNameRequest

type UpdateWalletNameRequest struct {
	Pin  string `json:"pin" validate:"required" label:"PIN Code"`
	Name string `json:"name" validate:"required|minLen:3|maxLen:50" label:"Name"`
}

UpdateWalletNameRequest is a request for UpdateWalletName method

type Wallet

type Wallet struct {
	Name       string `json:"name"`
	PublicKey  string `json:"public_key"`
	PrivateKey string `json:"private_key,omitempty"`
	Mnemonic   string `json:"mnemonic,omitempty"`
}

Wallet struct is a representation of wallet entity.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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