crypto

package
v0.15.2 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: MIT Imports: 5 Imported by: 3

Documentation

Index

Constants

View Source
const (
	SignatureTypeTreasury byte = 0
	SignatureTypeBLS      byte = 1
)
View Source
const (
	AddressSize = 21
)

Variables

View Source
var (
	// AddressHRP is the Human Readable Part (HRP) for address.
	AddressHRP = "pc"
	// PublicKeyHRP is the Human Readable Part (HRP) for public key.
	PublicKeyHRP = "public"
	// PrivateKeyHRP is the Human Readable Part (HRP) for private key.
	PrivateKeyHRP = "secret"
	// XPublicKeyHRP is the Human Readable Part (HRP) for extended public key.
	XPublicKeyHRP = "xpublic"
	// XPrivateKeyHRP is the Human Readable Part (HRP) for extended private key.
	XPrivateKeyHRP = "xsecret"
)
View Source
var ErrInvalidSignature = errors.New("invalid signature")

ErrInvalidSignature is returned when a signature is invalid.

View Source
var TreasuryAddress = Address{0}

Functions

This section is empty.

Types

type Address

type Address [AddressSize]byte

func AddressFromString

func AddressFromString(text string) (Address, error)

AddressFromString decodes the string encoding of an address and returns the Address if text is a valid encoding for a known address type.

func NewAddress added in v0.15.0

func NewAddress(typ AddressType, data []byte) Address

NewAddress create a new address based.

func (Address) Bytes

func (addr Address) Bytes() []byte

Bytes returns the 21 bytes of the address data.

func (*Address) Decode added in v0.15.0

func (addr *Address) Decode(r io.Reader) error

func (Address) Encode added in v0.15.0

func (addr Address) Encode(w io.Writer) error

func (Address) IsAccountAddress added in v0.15.0

func (addr Address) IsAccountAddress() bool

func (Address) IsTreasuryAddress added in v0.15.0

func (addr Address) IsTreasuryAddress() bool

func (Address) IsValidatorAddress added in v0.15.0

func (addr Address) IsValidatorAddress() bool

func (Address) SerializeSize added in v0.15.0

func (addr Address) SerializeSize() int

SerializeSize returns the number of bytes it would take to serialize the address.

func (Address) ShortString added in v0.15.0

func (addr Address) ShortString() string

ShortString returns a short string for the address useful for logger.

func (Address) String

func (addr Address) String() string

String returns a human-readable string for the address.

func (Address) Type added in v0.15.0

func (addr Address) Type() AddressType

type AddressMismatchError added in v0.15.0

type AddressMismatchError struct {
	Expected Address
	Got      Address
}

AddressMismatchError is returned when the provided address is not derived from the corresponding public key.

func (AddressMismatchError) Error added in v0.15.0

func (e AddressMismatchError) Error() string

type AddressType added in v0.15.0

type AddressType byte
const (
	AddressTypeTreasury   AddressType = 0
	AddressTypeValidator  AddressType = 1
	AddressTypeBLSAccount AddressType = 2
)

type InvalidAddressTypeError added in v0.15.0

type InvalidAddressTypeError int

InvalidAddressTypeError is returned when the address type is not recognized or supported.

func (InvalidAddressTypeError) Error added in v0.15.0

func (e InvalidAddressTypeError) Error() string

type InvalidHRPError added in v0.15.0

type InvalidHRPError string

InvalidHRPError is returned when the provided HRP code does not match the expected value.

func (InvalidHRPError) Error added in v0.15.0

func (e InvalidHRPError) Error() string

type InvalidLengthError added in v0.15.0

type InvalidLengthError int

InvalidLengthError is returned when the length of the data does not match the expected length.

func (InvalidLengthError) Error added in v0.15.0

func (e InvalidLengthError) Error() string

type PrivateKey

type PrivateKey interface {
	Bytes() []byte
	String() string
	Sign(msg []byte) Signature
	PublicKey() PublicKey
	EqualsTo(right PrivateKey) bool
}

type PublicKey

type PublicKey interface {
	Bytes() []byte
	String() string
	MarshalCBOR() ([]byte, error)
	UnmarshalCBOR([]byte) error
	Encode(io.Writer) error
	Decode(io.Reader) error
	Verify(msg []byte, sig Signature) error
	VerifyAddress(addr Address) error
	EqualsTo(right PublicKey) bool
}

type Signature

type Signature interface {
	Bytes() []byte
	String() string
	MarshalCBOR() ([]byte, error)
	UnmarshalCBOR([]byte) error
	Encode(io.Writer) error
	Decode(io.Reader) error
	EqualsTo(right Signature) bool
}

Directories

Path Synopsis
bls

Jump to

Keyboard shortcuts

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