v1

package
v0.74.0-preview.7 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: AGPL-3.0 Imports: 33 Imported by: 1

Documentation

Index

Constants

View Source
const (
	TxnValidationFailure   uint32 = 51
	TxnDecodingFailure     uint32 = 60
	TxnInternalError       uint32 = 70
	TxnUnknownCommandError uint32 = 80
	TxnSpamError           uint32 = 89
)
View Source
const (
	LengthForSessionHashSeed = 10
)
View Source
const TXIDLENGTH = 20

Variables

View Source
var (
	ErrInvalidToken              = errors.New("invalid token")
	ErrInvalidClaims             = errors.New("invalid claims")
	ErrInvalidOrMissingToken     = newErrorResponse("invalid or missing token")
	ErrCouldNotReadRequest       = errors.New("couldn't read request")
	ErrCouldNotGetBlockHeight    = errors.New("couldn't get last block height")
	ErrCouldNotGetChainID        = errors.New("couldn't get chain-id")
	ErrShouldBeBase64Encoded     = errors.New("should be base64 encoded")
	ErrRejectedSignRequest       = errors.New("user rejected sign request")
	ErrInterruptedConsentRequest = errors.New("process to request consent has been interrupted")
)
View Source
var ErrSessionNotFound = errors.New("session not found")

Functions

Types

type API

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

func NewAPI

func NewAPI(
	log *zap.Logger,
	handler WalletHandler,
	auth Auth,
	nodeForward NodeForward,
	policy Policy,
	net *network.Network,
	spam SpamHandler,
) *API

func (*API) CheckTx

func (s *API) CheckTx(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

func (*API) CreateWallet

func (s *API) CreateWallet(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

func (*API) GenerateKeyPair

func (s *API) GenerateKeyPair(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

func (*API) GetNetwork

func (s *API) GetNetwork(w http.ResponseWriter, _ *http.Request, _ httprouter.Params)

func (*API) GetNetworkChainID

func (s *API) GetNetworkChainID(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

func (*API) GetPublicKey

func (s *API) GetPublicKey(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

func (*API) Health

func (s *API) Health(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

func (*API) ImportWallet

func (s *API) ImportWallet(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

func (*API) ListPublicKeys

func (s *API) ListPublicKeys(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

func (*API) Login

func (s *API) Login(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

func (*API) Revoke

func (s *API) Revoke(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

func (*API) SignAny

func (s *API) SignAny(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

func (*API) SignTx

func (s *API) SignTx(w http.ResponseWriter, r *http.Request, p httprouter.Params)

func (*API) SignTxCommit

func (s *API) SignTxCommit(w http.ResponseWriter, r *http.Request, p httprouter.Params)

func (*API) SignTxSync

func (s *API) SignTxSync(w http.ResponseWriter, r *http.Request, p httprouter.Params)

func (*API) TaintKey

func (s *API) TaintKey(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

func (*API) UpdateMeta

func (s *API) UpdateMeta(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

func (*API) VerifyAny

func (s *API) VerifyAny(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

func (*API) Version

func (s *API) Version(w http.ResponseWriter, _ *http.Request, _ httprouter.Params)

type Auth

type Auth interface {
	NewSession(name string) (string, error)
	VerifyToken(token string) (string, error)
	Revoke(token string) (string, error)
	RevokeAllToken()
}

func NewAuth

func NewAuth(log *zap.Logger, cfgStore RSAStore, tokenExpiry time.Duration) (Auth, error)

type AutomaticConsentPolicy

type AutomaticConsentPolicy struct{}

func (*AutomaticConsentPolicy) Ask

func (*AutomaticConsentPolicy) Report

type Claims

type Claims struct {
	jwt.StandardClaims
	Session string
	Wallet  string
}

type ConsentConfirmation

type ConsentConfirmation struct {
	TxID     string
	Decision bool
}

type ConsentRequest

type ConsentRequest struct {
	TxID         string
	Tx           *v1.SubmitTransactionRequest
	ReceivedAt   time.Time
	Confirmation chan ConsentConfirmation
}

type CreateWalletRequest

type CreateWalletRequest struct {
	Wallet     string `json:"wallet"`
	Passphrase string `json:"passphrase"`
}

CreateWalletRequest describes the request for CreateWallet.

func ParseCreateWalletRequest

func ParseCreateWalletRequest(r *http.Request) (*CreateWalletRequest, commands.Errors)

type CreateWalletResponse

type CreateWalletResponse struct {
	RecoveryPhrase string `json:"recoveryPhrase"`
	Token          string `json:"token"`
}

CreateWalletResponse returns the authentication token and the auto-generated recovery phrase of the created wallet.

type ErrorResponse

type ErrorResponse struct {
	ErrorStr string   `json:"error"`
	Details  []string `json:"details,omitempty"`
}

func (ErrorResponse) Error

func (e ErrorResponse) Error() string

type ErrorsResponse

type ErrorsResponse struct {
	Errors commands.Errors `json:"errors"`
}

type ExplicitConsentPolicy

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

func (*ExplicitConsentPolicy) Ask

func (p *ExplicitConsentPolicy) Ask(tx *v1.SubmitTransactionRequest, txID string, receivedAt time.Time) (bool, error)

func (*ExplicitConsentPolicy) Report

func (p *ExplicitConsentPolicy) Report(tx SentTransaction)

type GenKeyPairRequest

type GenKeyPairRequest struct {
	Passphrase string            `json:"passphrase"`
	Meta       []wallet.Metadata `json:"meta"`
}

GenKeyPairRequest describes the request for GenerateKeyPair.

func ParseGenKeyPairRequest

func ParseGenKeyPairRequest(r *http.Request) (*GenKeyPairRequest, commands.Errors)

type ImportWalletRequest

type ImportWalletRequest struct {
	Wallet         string `json:"wallet"`
	Passphrase     string `json:"passphrase"`
	RecoveryPhrase string `json:"recoveryPhrase"`
	Version        uint32 `json:"version"`
}

ImportWalletRequest describes the request for ImportWallet.

func ParseImportWalletRequest

func ParseImportWalletRequest(r *http.Request) (*ImportWalletRequest, commands.Errors)

type KeyKeyResponse

type KeyKeyResponse struct {
	Idx          uint32            `json:"index"`
	PublicKey    string            `json:"pub"`
	KeyName      string            `json:"name"`
	Algorithm    wallet.Algorithm  `json:"algorithm"`
	Tainted      bool              `json:"tainted"`
	MetadataList []wallet.Metadata `json:"meta"`
}

type KeyResponse

type KeyResponse struct {
	Key KeyKeyResponse `json:"key"`
}

KeyResponse describes the response to a request that returns a single key.

type KeysResponse

type KeysResponse struct {
	Keys []KeyKeyResponse `json:"keys"`
}

KeysResponse describes the response to a request that returns a list of keys.

type LoginWalletRequest

type LoginWalletRequest struct {
	Wallet     string `json:"wallet"`
	Passphrase string `json:"passphrase"`
}

LoginWalletRequest describes the request for CreateWallet, LoginWallet.

func ParseLoginWalletRequest

func ParseLoginWalletRequest(r *http.Request) (*LoginWalletRequest, commands.Errors)

type NetworkResponse

type NetworkResponse struct {
	Network network.Network `json:"network"`
}

NetworkResponse describes the response to a request that returns app hosts info.

type Policy

type Policy interface {
	Ask(tx *v1.SubmitTransactionRequest, txID string, receivedAt time.Time) (bool, error)
	Report(tx SentTransaction)
}

func NewAutomaticConsentPolicy

func NewAutomaticConsentPolicy() Policy

func NewExplicitConsentPolicy

func NewExplicitConsentPolicy(ctx context.Context, consentRequests chan ConsentRequest, sentTransactions chan SentTransaction) Policy

type RSAKeys

type RSAKeys struct {
	Pub  []byte
	Priv []byte
}

func GenerateRSAKeys

func GenerateRSAKeys() (*RSAKeys, error)

type RSAStore

type RSAStore interface {
	GetRsaKeys() (*RSAKeys, error)
}

type SentTransaction

type SentTransaction struct {
	TxHash string
	TxID   string
	Tx     *commandspb.Transaction
	Error  error
	SentAt time.Time
}

type SignAnyRequest

type SignAnyRequest struct {
	// InputData is the payload to generate a signature from. I should be
	// base 64 encoded.
	InputData string `json:"inputData"`
	// PubKey is used to retrieve the private key to sign the InputDate.
	PubKey string `json:"pubKey"`
	// contains filtered or unexported fields
}

SignAnyRequest describes the request for SignAny.

func ParseSignAnyRequest

func ParseSignAnyRequest(r *http.Request) (*SignAnyRequest, commands.Errors)

type SignAnyResponse

type SignAnyResponse struct {
	HexSignature    string `json:"hexSignature"`
	Base64Signature string `json:"base64Signature"`
}

SignAnyResponse describes the response for SignAny.

type SpamHandler added in v0.68.0

type SpamHandler interface {
	GenerateProofOfWork(pubKey string, stats *nodetypes.SpamStatistics) (*commandspb.ProofOfWork, error)
	CheckSubmission(req *walletpb.SubmitTransactionRequest, stats *nodetypes.SpamStatistics) error
}

type SuccessResponse

type SuccessResponse struct {
	Success bool `json:"success"`
}

SuccessResponse describes the response to a request that returns a simple true/false answer.

type TaintKeyRequest

type TaintKeyRequest struct {
	Passphrase string `json:"passphrase"`
}

TaintKeyRequest describes the request for TaintKey.

func ParseTaintKeyRequest

func ParseTaintKeyRequest(r *http.Request, keyID string) (*TaintKeyRequest, commands.Errors)

type TokenResponse

type TokenResponse struct {
	Token string `json:"token"`
}

TokenResponse describes the response to a request that returns a token.

type UpdateMetaRequest

type UpdateMetaRequest struct {
	Passphrase string            `json:"passphrase"`
	Meta       []wallet.Metadata `json:"meta"`
}

UpdateMetaRequest describes the request for UpdateMetadata.

func ParseUpdateMetaRequest

func ParseUpdateMetaRequest(r *http.Request, keyID string) (*UpdateMetaRequest, commands.Errors)

type VerifyAnyRequest

type VerifyAnyRequest struct {
	// InputData is the payload to be verified. It should be base64 encoded.
	InputData string `json:"inputData"`
	// Signature is the signature to check against the InputData. It should be
	// base64 encoded.
	Signature string `json:"signature"`
	// PubKey is the public key used along the signature to check the InputData.
	PubKey string `json:"pubKey"`
	// contains filtered or unexported fields
}

VerifyAnyRequest describes the request for VerifyAny.

func ParseVerifyAnyRequest

func ParseVerifyAnyRequest(r *http.Request) (*VerifyAnyRequest, commands.Errors)

type VerifyAnyResponse

type VerifyAnyResponse struct {
	Valid bool `json:"success"`
}

VerifyAnyResponse describes the response for VerifyAny.

type VersionResponse

type VersionResponse struct {
	Version     string `json:"version"`
	VersionHash string `json:"versionHash"`
}

VersionResponse describes the response to a request that returns app version info.

type WalletHandler

type WalletHandler interface {
	CreateWallet(name, passphrase string) (string, error)
	ImportWallet(name, passphrase, recoveryPhrase string, version uint32) error
	LoginWallet(name, passphrase string) error
	SecureGenerateKeyPair(name, passphrase string, meta []wallet.Metadata) (string, error)
	GetPublicKey(name, pubKey string) (wallet.PublicKey, error)
	ListPublicKeys(name string) ([]wallet.PublicKey, error)
	SignTx(name string, req *walletpb.SubmitTransactionRequest, height uint64, chainID string) (*commandspb.Transaction, error)
	SignAny(name string, inputData []byte, pubKey string) ([]byte, error)
	VerifyAny(inputData, sig []byte, pubKey string) (bool, error)
	TaintKey(name, pubKey, passphrase string) error
	UpdateMeta(name, pubKey, passphrase string, meta []wallet.Metadata) error
}

Directories

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

Jump to

Keyboard shortcuts

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