address

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: LGPL-3.0 Imports: 9 Imported by: 164

Documentation

Overview

Package address provides TRON address encoding, decoding, and validation.

Index

Constants

View Source
const (
	// HashLength is the expected length of the hash
	HashLength = 32
	// AddressLength is the expected length of the address
	AddressLength = 21
	// AddressLengthBase58 is the expected length of the address in base58format
	AddressLengthBase58 = 34
	// TronBytePrefix is the hex prefix to address
	TronBytePrefix = byte(0x41)
)

Variables

View Source
var (
	ErrInvalidAddressLength   = errors.New("invalid address length")
	ErrInvalidAddressPrefix   = errors.New("invalid address prefix")
	ErrInvalidAddressChecksum = errors.New("invalid address checksum")
	ErrOversizeBigInt         = errors.New("big.Int too large for address")
	ErrInvalidHex             = errors.New("invalid hex string")
)

Sentinel errors for address validation. Callers can test with errors.Is.

Functions

This section is empty.

Types

type Address

type Address []byte

Address represents the 21 byte address of an Tron account.

func BTCECPrivkeyToAddress added in v0.24.1

func BTCECPrivkeyToAddress(p *btcec.PrivateKey) Address

BTCECPrivkeyToAddress derives a TRON address from a btcec private key.

func BTCECPubkeyToAddress added in v0.24.1

func BTCECPubkeyToAddress(p *btcec.PublicKey) Address

BTCECPubkeyToAddress derives a TRON address from a btcec public key.

func Base58ToAddress

func Base58ToAddress(s string) (Address, error)

Base58ToAddress returns Address with byte values of s.

func Base64ToAddress

func Base64ToAddress(s string) (Address, error)

Base64ToAddress returns Address with byte values of s.

func BigToAddress

func BigToAddress(b *big.Int) (Address, error)

BigToAddress returns Address with byte values of b. Returns an error if b requires more than AddressLength bytes.

func BytesToAddress added in v0.25.2

func BytesToAddress(b []byte) Address

BytesToAddress converts raw bytes to a TRON Address. For 20-byte input, the TRON mainnet prefix (0x41) is prepended. For 21-byte input, the bytes are copied as-is. For any other length, a copy of the input bytes is returned without validation.

func EthAddressToAddress added in v0.25.2

func EthAddressToAddress(ethAddr []byte) (Address, error)

EthAddressToAddress converts a 20-byte Ethereum address to a 21-byte TRON address. It prepends the TRON mainnet prefix (0x41). Returns an error if the input is not exactly 20 bytes.

func HexToAddress

func HexToAddress(s string) (Address, error)

HexToAddress returns Address with byte values of s. Returns an error if s is not valid hex.

func PubkeyToAddress

func PubkeyToAddress(p ecdsa.PublicKey) Address

PubkeyToAddress derives a TRON address from an ECDSA public key.

func (Address) Bytes

func (a Address) Bytes() []byte

Bytes returns a copy of the raw byte representation of the address.

func (Address) Hex

func (a Address) Hex() string

Hex returns the address encoded as a hex string (e.g. "41..." for mainnet).

func (Address) IsValid

func (a Address) IsValid() bool

IsValid checks if the address is a valid TRON address with checksum validation.

func (*Address) Scan

func (a *Address) Scan(src interface{}) error

Scan implements the database/sql.Scanner interface for reading addresses from database columns.

func (Address) String

func (a Address) String() string

String implements fmt.Stringer.

func (Address) Value

func (a Address) Value() (driver.Value, error)

Value implements the database/sql/driver.Valuer interface for storing addresses in database columns.

Jump to

Keyboard shortcuts

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