crypto

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2022 License: Apache-2.0, MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FIL = byte(1)
)
View Source
const (
	SECP256K1 = byte(1)
)

Variables

This section is empty.

Functions

func Verify

func Verify(currencyID byte, data []byte, keyType byte, sig []byte, addr string) error

Verify is a static method to verify given data with given signature from given address.

@input - currency id, data, key type, signature, signer's address.

@output - error.

Types

type Opts

type Opts struct {
	// The datastore path of the signer.
	Path string
}

Opts is the options for the signer.

type Signer

type Signer interface {
	// SetKey is used to set a private key for a given currency id. It will return error if there is
	// an existing key already associated with the given currency id.
	//
	// @input - context, currency id, key type, private key.
	//
	// @output - error.
	SetKey(ctx context.Context, currencyID byte, keyType byte, prv []byte) error

	// GetAddr is used to obtain the key type and the address derived from the private key associated
	// with the given currency id.
	//
	// @input - context, currency id.
	//
	// @output - key type, address, error.
	GetAddr(ctx context.Context, currencyID byte) (byte, string, error)

	// Sign is used to sign given data with the private key associated with given currency id.
	//
	// @input - context, currency id, data.
	//
	// @output - signature type, signature, error.
	Sign(ctx context.Context, currencyID byte, data []byte) (byte, []byte, error)

	// RetireKey is used to retire a key for a given currency id. If within timeout the key is touched
	// it will return error.
	//
	// @input - context, currency id, timeout.
	//
	// @output - error channel out.
	RetireKey(ctx context.Context, currencyID byte, timeout time.Duration) <-chan error

	// StopRetire is used to stop retiring a key for a given currency id.
	//
	// @input - context, currency id.
	//
	// @output - error.
	StopRetire(ctx context.Context, currencyID byte) error

	// ListCurrencyIDs lists all currencies.
	//
	// @input - context.
	//
	// @output - currency chan out, error chan out.
	ListCurrencyIDs(ctx context.Context) (<-chan byte, <-chan error)
}

Signer is the interface for a secured signing tool. It can save one key for a given currency id. The key is used for signing offers and for transacting on chain.

type SignerImpl

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

SignerImpl is the implementation of the Signer interface.

func NewSignerImpl

func NewSignerImpl(ctx context.Context, opts Opts) (*SignerImpl, error)

NewSignerImpl creates a new Signer.

@input - context, options.

@output - signer, error.

func (*SignerImpl) GetAddr

func (s *SignerImpl) GetAddr(ctx context.Context, currencyID byte) (byte, string, error)

GetAddr is used to obtain the key type and the address derived from the private key associated with the given currency id.

@input - context, currency id.

@output - key type, address, error.

func (*SignerImpl) ListCurrencyIDs

func (s *SignerImpl) ListCurrencyIDs(ctx context.Context) (<-chan byte, <-chan error)

ListCurrencyIDs lists all currencies.

@input - context.

@output - currency chan out, error chan out.

func (*SignerImpl) RetireKey

func (s *SignerImpl) RetireKey(ctx context.Context, currencyID byte, timeout time.Duration) <-chan error

RetireKey is used to retire a key for a given currency id. If within timeout the key is touched it will return error.

@input - context, currency id, timeout.

@output - error channel out.

func (*SignerImpl) SetKey

func (s *SignerImpl) SetKey(ctx context.Context, currencyID byte, keyType byte, prv []byte) error

SetKey is used to set a private key for a given currency id. It will return error if there is an existing key already associated with the given currency id.

@input - context, currency id, key type, private key.

@output - error.

func (*SignerImpl) Shutdown

func (s *SignerImpl) Shutdown()

Shutdown safely shuts down the component.

func (*SignerImpl) Sign

func (s *SignerImpl) Sign(ctx context.Context, currencyID byte, data []byte) (byte, []byte, error)

Sign is used to sign given data with the private key associated with given currency id.

@input - context, currency id, data.

@output - key type, signature, error.

func (*SignerImpl) StopRetire

func (s *SignerImpl) StopRetire(ctx context.Context, currencyID byte) error

StopRetire is used to stop retiring a key for a given currency id.

@input - context, currency id.

@output - error.

Jump to

Keyboard shortcuts

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