crypto

package
v0.0.1-pre-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AddressLen = 20
	SeedSize   = ed25519.SeedSize
)
View Source
const (
	InvalidAddressLenError        = "the address length is not valid"
	InvalidHashLenError           = "the hash length is not valid"
	CreateAddressError            = "an error occurred creating the address"
	InvalidPrivateKeyLenError     = "the private key length is not valid"
	InvalidPrivateKeySeedLenError = "the seed is too short to create a private key"
	CreatePrivateKeyError         = "an error occurred creating the private key"
	InvalidPublicKeyLenError      = "the public key length is not valid"
	CreatePublicKeyError          = "an error occurred creating the public key"
)

Variables

View Source
var (
	PublicKeyLen  = ed25519.PublicKeySize
	PrivateKeyLen = ed25519.PrivateKeySize
)
View Source
var (
	SHA3HashLen = crypto.SHA3_256.Size()
)

Functions

func ErrCreateAddress

func ErrCreateAddress(err error) error

func ErrCreatePrivateKey

func ErrCreatePrivateKey(err error) error

func ErrCreatePublicKey

func ErrCreatePublicKey(err error) error

func ErrInvalidAddressLen

func ErrInvalidAddressLen(len int) error

func ErrInvalidHashLen

func ErrInvalidHashLen(len int) error

func ErrInvalidPrivateKeyLen

func ErrInvalidPrivateKeyLen(len int) error

func ErrInvalidPrivateKeySeedLenError

func ErrInvalidPrivateKeySeedLenError(seedLen int) error

func ErrInvalidPublicKeyLen

func ErrInvalidPublicKeyLen(len int) error

func SHA3Hash

func SHA3Hash(bz []byte) []byte

Types

type Address

type Address []byte

TODO(discuss): Consider create a type for signature and having constraints for each type as well.

func AddressFromString

func AddressFromString(s string) Address

func GenerateAddress

func GenerateAddress() (Address, error)

func NewAddress

func NewAddress(hexString string) (Address, error)

func NewAddressFromBytes

func NewAddressFromBytes(bz []byte) (Address, error)

func (Address) String

func (a Address) String() string

func (*Address) ToString

func (a *Address) ToString() string

func (*Address) UnmarshalJSON

func (a *Address) UnmarshalJSON(data []byte) error

type Ed25519PrivateKey

type Ed25519PrivateKey ed25519.PrivateKey

func (Ed25519PrivateKey) Address

func (priv Ed25519PrivateKey) Address() Address

func (Ed25519PrivateKey) Bytes

func (priv Ed25519PrivateKey) Bytes() []byte

func (Ed25519PrivateKey) Equals

func (priv Ed25519PrivateKey) Equals(other PrivateKey) bool

func (Ed25519PrivateKey) PublicKey

func (priv Ed25519PrivateKey) PublicKey() PublicKey

func (Ed25519PrivateKey) Seed

func (priv Ed25519PrivateKey) Seed() []byte

func (Ed25519PrivateKey) Sign

func (priv Ed25519PrivateKey) Sign(msg []byte) ([]byte, error)

func (Ed25519PrivateKey) Size

func (priv Ed25519PrivateKey) Size() int

func (Ed25519PrivateKey) String

func (priv Ed25519PrivateKey) String() string

func (*Ed25519PrivateKey) UnmarshalJSON

func (priv *Ed25519PrivateKey) UnmarshalJSON(data []byte) error

type Ed25519PublicKey

type Ed25519PublicKey ed25519.PublicKey

func (Ed25519PublicKey) Address

func (pub Ed25519PublicKey) Address() Address

func (Ed25519PublicKey) Bytes

func (pub Ed25519PublicKey) Bytes() []byte

func (Ed25519PublicKey) Equals

func (pub Ed25519PublicKey) Equals(other PublicKey) bool

func (Ed25519PublicKey) Size

func (pub Ed25519PublicKey) Size() int

func (Ed25519PublicKey) String

func (pub Ed25519PublicKey) String() string

func (*Ed25519PublicKey) UnmarshalJSON

func (pub *Ed25519PublicKey) UnmarshalJSON(data []byte) error

func (Ed25519PublicKey) Verify

func (pub Ed25519PublicKey) Verify(msg []byte, sig []byte) bool

type PrivateKey

type PrivateKey interface {
	Bytes() []byte
	String() string
	Equals(other PrivateKey) bool
	PublicKey() PublicKey
	Address() Address
	Sign(msg []byte) ([]byte, error)
	Size() int
	Seed() []byte
}

func GeneratePrivateKey

func GeneratePrivateKey() (PrivateKey, error)

func NewPrivateKey

func NewPrivateKey(hexString string) (PrivateKey, error)

func NewPrivateKeyFromBytes

func NewPrivateKeyFromBytes(bz []byte) (PrivateKey, error)

func NewPrivateKeyFromSeed

func NewPrivateKeyFromSeed(seed []byte) (PrivateKey, error)

type PublicKey

type PublicKey interface {
	Bytes() []byte
	String() string
	Address() Address
	Equals(other PublicKey) bool
	Verify(msg []byte, sig []byte) bool
	Size() int
}

func GeneratePublicKey

func GeneratePublicKey() (PublicKey, error)

func NewPublicKey

func NewPublicKey(hexString string) (PublicKey, error)

func NewPublicKeyFromBytes

func NewPublicKeyFromBytes(bz []byte) (PublicKey, error)

Jump to

Keyboard shortcuts

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