keys

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidKey will be returned by operations when the keys being used
	// could not be decoded.
	ErrInvalidKey = errors.New("invalid key")

	// ErrInvalidSignature is returned when the signature is invalid, either
	// through malformation or if it does not verify the message against the
	// provided public key
	ErrInvalidSignature = errors.New("signature verification failed")

	// ErrCannotSign is returned when attempting to sign a message when
	// the keys do not have the secret key available
	ErrCannotSign = errors.New("cannot sign")
)

Functions

This section is empty.

Types

type FromAddress

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

FromAddress represents a keys to which only the address is known. This KP can verify signatures, but cannot sign messages.

func ParseAddress

func ParseAddress(address string) (*FromAddress, error)

ParseAddress constructs a new FromAddress keys from the provided string, which should be an address.

func (*FromAddress) Address

func (kp *FromAddress) Address() string

Address is address getter.

func (*FromAddress) Equal

func (kp *FromAddress) Equal(a *FromAddress) bool

Equal compares two FromAddress instances.

func (*FromAddress) FromAddress

func (kp *FromAddress) FromAddress() (*FromAddress, error)

FromAddress gets the address-only representation of these keys, which is itself.

func (*FromAddress) Hint

func (kp *FromAddress) Hint() (r [4]byte)

Hint provides four last bytes of public key.

func (*FromAddress) PublicKey

func (kp *FromAddress) PublicKey() *[32]byte

PublicKey is public key getter.

func (*FromAddress) Sign

func (kp *FromAddress) Sign(_ []byte) ([]byte, error)

Sign method returns error because this KP cannot sign messages.

func (*FromAddress) Verify

func (kp *FromAddress) Verify(message []byte, sig []byte) error

Verify checks whether message was signed by kp's keys.

type Full

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

Full represents a keys with generated on ed25519 key pair and seed used for its creation. In addition, it stores address which is public key representation in human-readable form.

func FromRawSeed

func FromRawSeed(rawSeed [32]byte) (*Full, error)

FromRawSeed creates a new keys from the provided raw ED25519 seed

func ParseFull

func ParseFull(seed string) (*Full, error)

ParseFull constructs a new Full keys from the provided string, which should be a seed.

func Random

func Random() (*Full, error)

Random creates a random Full keys

func (*Full) Address

func (kp *Full) Address() string

Address is address getter.

func (*Full) Equal

func (kp *Full) Equal(f *Full) bool

Equal compares two Full instances.

func (*Full) FromAddress

func (kp *Full) FromAddress() (*FromAddress, error)

FromAddress gets the address-only representation, or public key, of this Full keys.

func (*Full) Hint

func (kp *Full) Hint() (r [4]byte)

Hint provides four last bytes of public key.

func (*Full) PublicKey

func (kp *Full) PublicKey() ed25519.PublicKey

PublicKey is public key getter.

func (*Full) Seed

func (kp *Full) Seed() string

Seed is seed getter.

func (*Full) Sign

func (kp *Full) Sign(message []byte) ([]byte, error)

Sign signs message using ed25519 package.

func (*Full) Verify

func (kp *Full) Verify(message, signature []byte) error

Verify checks whether message was signed by kp's keys.

type KP

type KP interface {
	Address() string
	FromAddress() (*FromAddress, error)
	Hint() [4]byte
	Verify(input []byte, signature []byte) error
	Sign(input []byte) ([]byte, error)
}

KP is the main interface for this package

func Parse

func Parse(addressOrSeed string) (KP, error)

Parse constructs a new KP from the provided string, which should be either an address, or a seed. If the provided input is a seed, the resulting KP will have signing capabilities.

Jump to

Keyboard shortcuts

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