crypto

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2024 License: MIT Imports: 6 Imported by: 3

Documentation

Index

Constants

View Source
const (
	SignatureTypeBLS     byte = 1
	SignatureTypeEd25519 byte = 3
)
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 ErrInvalidPublicKey = errors.New("invalid public key")

ErrInvalidPublicKey is returned when a public key is invalid.

View Source
var ErrInvalidSignature = errors.New("invalid signature")

ErrInvalidSignature is returned when a signature is invalid.

View Source
var TreasuryAddress = Address{0}

Functions

func ToTestnetHRP added in v1.6.0

func ToTestnetHRP()

ToTestnetHRP makes HRPs testnet specified.

Types

type Address

type Address [AddressSize]byte

func AddressFromString

func AddressFromString(text string) (Address, error)

AddressFromString decodes the input string and returns the Address if the string is a valid bech32m encoding of an address.

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
	AddressTypeEd25519Account AddressType = 3
)

func (AddressType) String added in v1.6.0

func (t AddressType) String() string

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 InvalidSignatureTypeError added in v1.5.0

type InvalidSignatureTypeError int

InvalidSignatureTypeError is returned when the signature type is not recognized or supported.

func (InvalidSignatureTypeError) Error added in v1.5.0

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
	SerializeSize() int
	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
	SerializeSize() int
	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