address

package
v0.0.0-...-b10619e Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package address provides utility functionality to encode and decode bech32 based addresses.

Index

Constants

View Source
const (
	// OutputIDLength defines the length of an OutputID.
	OutputIDLength = blake2b.Size256 + 2
	// Blake2b160Length defines the size of a BLAKE2b-160 hash in bytes.
	Blake2b160Length = 20
)

Variables

View Source
var (
	ErrInvalidPrefix  = errors.New("invalid prefix")
	ErrInvalidVersion = errors.New("invalid version")
	ErrInvalidLength  = errors.New("invalid length")
)

Errors returned during address parsing.

Functions

func Bech32

func Bech32(hrp Prefix, addr Address) (string, error)

Bech32 encodes the provided addr as a bech32 string.

func ParseBech32

func ParseBech32(s string) (Prefix, Address, error)

ParseBech32 decodes a bech32 encoded string.

Types

type Address

type Address interface {
	Version() Version
	Bytes() []byte

	String() string
}

Address specifies a general address of different underlying types.

type AliasAddress

type AliasAddress struct {
	// contains filtered or unexported fields
}

func AliasAddressFromOutputID

func AliasAddressFromOutputID(outputID [OutputIDLength]byte) AliasAddress

AliasAddressFromOutputID returns the alias address computed from a given OutputID.

func (AliasAddress) Bytes

func (a AliasAddress) Bytes() []byte

func (AliasAddress) String

func (a AliasAddress) String() string

func (AliasAddress) Version

func (AliasAddress) Version() Version

type Ed25519Address

type Ed25519Address struct {
	// contains filtered or unexported fields
}

func AddressFromPublicKey

func AddressFromPublicKey(key ed25519.PublicKey) Ed25519Address

AddressFromPublicKey creates an address from a 32-byte hash.

func (Ed25519Address) Bytes

func (a Ed25519Address) Bytes() []byte

func (Ed25519Address) String

func (a Ed25519Address) String() string

func (Ed25519Address) Version

func (Ed25519Address) Version() Version

type NFTAddress

type NFTAddress struct {
	// contains filtered or unexported fields
}

func NFTAddressFromOutputID

func NFTAddressFromOutputID(outputID [OutputIDLength]byte) NFTAddress

NFTAddressFromOutputID returns the alias address computed from a given OutputID.

func (NFTAddress) Bytes

func (a NFTAddress) Bytes() []byte

func (NFTAddress) String

func (a NFTAddress) String() string

func (NFTAddress) Version

func (NFTAddress) Version() Version

type Prefix

type Prefix int

Prefix denotes the different network prefixes.

const (
	IOTAMainnet Prefix = iota
	IOTADevnet
	ShimmerMainnet
	ShimmerDevnet
)

Network prefix options

func ParsePrefix

func ParsePrefix(s string) (Prefix, error)

func (Prefix) String

func (p Prefix) String() string

type Version

type Version byte

Version denotes the version of an address.

const (
	Ed25519 Version = 0x00
	Alias   Version = 0x08
	NFT     Version = 0x10
)

Supported address versions

func ParseVersion

func ParseVersion(s string) (Version, error)

func (Version) String

func (v Version) String() string

Jump to

Keyboard shortcuts

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