crypto

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2025 License: MIT Imports: 6 Imported by: 0

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 = "ae"
	// 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 ToMainnetHRP

func ToMainnetHRP()

ToMainnetHRP makes HRPs mainnet specified.

func ToTestnetHRP

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

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

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

func (Address) Encode

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

func (Address) IsAccountAddress

func (addr Address) IsAccountAddress() bool

func (Address) IsTreasuryAddress

func (addr Address) IsTreasuryAddress() bool

func (Address) IsValidatorAddress

func (addr Address) IsValidatorAddress() bool

func (Address) SerializeSize

func (addr Address) SerializeSize() int

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

func (Address) ShortString

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

func (addr Address) Type() AddressType

type AddressMismatchError

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

func (e AddressMismatchError) Error() string

type AddressType

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

func (AddressType) String

func (t AddressType) String() string

type InvalidAddressTypeError

type InvalidAddressTypeError int

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

func (InvalidAddressTypeError) Error

func (e InvalidAddressTypeError) Error() string

type InvalidHRPError

type InvalidHRPError string

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

func (InvalidHRPError) Error

func (e InvalidHRPError) Error() string

type InvalidLengthError

type InvalidLengthError int

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

func (InvalidLengthError) Error

func (e InvalidLengthError) Error() string

type InvalidSignatureTypeError

type InvalidSignatureTypeError int

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

func (InvalidSignatureTypeError) Error

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