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
- Variables
- type Address
- func (a Address) Equal(cmp Address) bool
- func (a Address) IsValid() bool
- func (a Address) MarshalBech32(hrp Bech32HRP) ([]byte, error)
- func (a Address) MarshalBinary() (data []byte, err error)
- func (a *Address) UnmarshalBech32(hrp Bech32HRP, bech []byte) error
- func (a *Address) UnmarshalBinary(data []byte) error
- type Bech32HRP
- type Context
Constants ¶
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 )
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.
const ContextIdentifierMaxSize = 64
ContextIdentifierMaxSize is the maximum size of a context's identifier string.
Variables ¶
var ( // ErrMalformed is the error returned when an address is malformed. ErrMalformed = errors.New("address: malformed address") )
var ( // ErrMalformedBech32HRP is the error returned when a Bech32 HRP is malformed. ErrMalformedBech32HRP = errors.New("address: malformed Bech32 human readable part") )
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 ¶
Address is a versioned context-separated truncated hash of the raw address data.
func NewAddress ¶
NewAddress creates a new address of specified version from address' context and data.
func (Address) MarshalBech32 ¶
MarshalBech32 encodes an address into Bech32-encoded text form.
func (Address) MarshalBinary ¶
MarshalBinary encodes an address into binary form.
func (*Address) UnmarshalBech32 ¶
UnmarshalBech32 decodes a Bech32-encoded text marshaled address.
func (*Address) UnmarshalBinary ¶
UnmarshalBinary decodes a binary marshaled address.
type Bech32HRP ¶
type Bech32HRP string
Bech32HRP is the human readable part (HRP) of Bech32 encoded addresses.
func NewBech32HRP ¶
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.
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 ¶
NewContext creates and registers a new context. This routine will panic if the context is malformed or is already registered.
func (Context) MarshalBinary ¶
MarshalBinary encodes a context into binary form.