api

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2020 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package api provides API and client to Cerberus.

Package api is a generated GoMock package.

Index

Constants

View Source
const PublicKeyHeader = "Public-Key"

PublicKeyHeader is name for public key http header.

View Source
const SignatureHeader = "Signature"

SignatureHeader is name for signature http header.

Variables

View Source
var ErrInvalidPublicKey = fmt.Errorf("%w: public key is invalid", ErrInvalidRequest)

ErrInvalidPublicKey is returned when public key is invalid.

View Source
var ErrInvalidRequest = errors.New("invalid request")

ErrInvalidRequest is returned when request is invalid.

View Source
var ErrInvalidSignature = fmt.Errorf("%w: signature is invalid", ErrInvalidRequest)

ErrInvalidSignature is returned when signature is invalid.

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned when object is not found.

View Source
var ErrNotVerified = errors.New("failed to verify message")

ErrNotVerified is returned when signature is wrong.

Functions

func Digest

func Digest(r *http.Request) ([]byte, error)

Digest returns sha256 of request body.

func IsAddressValid

func IsAddressValid(s string) bool

IsAddressValid check is address is matching with regexp.

func Sign

func Sign(r *http.Request, pk crypto.PrivKey) error

Sign signs http request.

func Verify

func Verify(r *http.Request) ([]byte, error)

Verify verifies request's signature with public key.

Types

type Cerberus

type Cerberus interface {
	SavePDV(ctx context.Context, p *schema.PDV) (string, error)
	ReceivePDV(ctx context.Context, address string) (json.RawMessage, error)
	DoesPDVExist(ctx context.Context, address string) (bool, error)
}

Cerberus provides user-friendly API methods.

func NewClient

func NewClient(host string, pk secp256k1.PrivKeySecp256k1) Cerberus

NewClient returns client with http.DefaultClient.

func NewClientWithHTTPClient

func NewClientWithHTTPClient(host string, pk secp256k1.PrivKeySecp256k1, c *http.Client) Cerberus

NewClientWithHTTPClient returns client with provided http.Client.

type Error

type Error struct {
	Error string `json:"error"`
}

Error ...

type MockCerberus

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

MockCerberus is a mock of Cerberus interface

func NewMockCerberus

func NewMockCerberus(ctrl *gomock.Controller) *MockCerberus

NewMockCerberus creates a new mock instance

func (*MockCerberus) DoesPDVExist

func (m *MockCerberus) DoesPDVExist(ctx context.Context, address string) (bool, error)

DoesPDVExist mocks base method

func (*MockCerberus) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockCerberus) ReceivePDV

func (m *MockCerberus) ReceivePDV(ctx context.Context, address string) (json.RawMessage, error)

ReceivePDV mocks base method

func (*MockCerberus) SavePDV

func (m *MockCerberus) SavePDV(ctx context.Context, p *schema.PDV) (string, error)

SavePDV mocks base method

type MockCerberusMockRecorder

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

MockCerberusMockRecorder is the mock recorder for MockCerberus

func (*MockCerberusMockRecorder) DoesPDVExist

func (mr *MockCerberusMockRecorder) DoesPDVExist(ctx, address interface{}) *gomock.Call

DoesPDVExist indicates an expected call of DoesPDVExist

func (*MockCerberusMockRecorder) ReceivePDV

func (mr *MockCerberusMockRecorder) ReceivePDV(ctx, address interface{}) *gomock.Call

ReceivePDV indicates an expected call of ReceivePDV

func (*MockCerberusMockRecorder) SavePDV

func (mr *MockCerberusMockRecorder) SavePDV(ctx, p interface{}) *gomock.Call

SavePDV indicates an expected call of SavePDV

type SavePDVResponse

type SavePDVResponse struct {
	Address string `json:"address"`
}

SavePDVResponse ...

Jump to

Keyboard shortcuts

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