address

package
v0.2103.10 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2022 License: Apache-2.0 Imports: 7 Imported by: 4

Documentation

Overview

Package address implements a generic cryptographic address with versioning and context separation. It can be used to implement specific addresses, e.g. the staking account address.

Index

Constants

View Source
const (
	// VersionSize is the size of address' version.
	VersionSize = 1
	// Size is the size of the whole address where the last 20 bytes represent
	// truncated hash of the concatenation of address' context and data.
	Size = VersionSize + 20
)
View Source
const Bech32HRPMaxSize = 15

Bech32HRPMaxSize is the maximum size of a human readable part (HRP) of Bech32 encoded addresses. NOTE: Although Bech32 HRPs can be up to 83 characters long, the whole Bech32 string is limited to 90 characters, including data and 6 characters for error detection. Hence, it is better to limit HRPs to some smaller number.

View Source
const ContextIdentifierMaxSize = 64

ContextMaxSize is the maximum size of a context's identifier string.

Variables

View Source
var (
	// ErrMalformed is the error returned when an address is malformed.
	ErrMalformed = errors.New("address: malformed address")
)
View Source
var (
	// ErrMalformedBech32HRP is the error returned when a Bech32 HRP is malformed.
	ErrMalformedBech32HRP = errors.New("address: malformed Bech32 human readable part")
)
View Source
var (
	// ErrMalformedContext is the error returned when an address context is malformed.
	ErrMalformedContext = errors.New("address: malformed context")
)

Functions

This section is empty.

Types

type Address

type Address [Size]byte

Address is a versioned context-separated truncated hash of the raw address data.

func NewAddress

func NewAddress(ctx Context, data []byte) (a Address)

NewAddress creates a new address of specified version from address' context and data.

func (Address) Equal

func (a Address) Equal(cmp Address) bool

Equal compares vs another address for equality.

func (Address) IsValid

func (a Address) IsValid() bool

IsValid checks whether an address is well-formed.

func (Address) MarshalBech32

func (a Address) MarshalBech32(hrp Bech32HRP) ([]byte, error)

MarshalBech32 encodes an address into Bech32-encoded text form.

func (Address) MarshalBinary

func (a Address) MarshalBinary() (data []byte, err error)

MarshalBinary encodes an address into binary form.

func (*Address) UnmarshalBech32

func (a *Address) UnmarshalBech32(hrp Bech32HRP, bech []byte) error

UnmarshalBech32 decodes a Bech32-encoded text marshaled address.

func (*Address) UnmarshalBinary

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

UnmarshalBinary decodes a binary marshaled address.

type Bech32HRP

type Bech32HRP string

Bech32HRP is the human readable part (HRP) of Bech32 encoded addresses.

func NewBech32HRP

func NewBech32HRP(rawBech32HRP string) Bech32HRP

NewBech32HRP creates and registers a new human readable part (HRP) of Bech32 encoded addresses. This routine will panic if the Bech32 HRP is malformed or is already registered.

func (Bech32HRP) String

func (hrp Bech32HRP) String() string

String returns the string representation of a HRP of Bech32 encoded addresses.

type Context

type Context struct {
	// Identifier is the context's identifier string.
	Identifier string
	// Version is the context's version.
	Version uint8
}

Context is a domain separation context for addresses.

func NewContext

func NewContext(identifier string, version uint8) Context

NewContext creates and registers a new context. This routine will panic if the context is malformed or is already registered.

func (Context) MarshalBinary

func (c Context) MarshalBinary() (data []byte, err error)

MarshalBinary encodes a context into binary form.

func (Context) String

func (c Context) String() string

String returns a string representation of address' context.

Jump to

Keyboard shortcuts

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