Raxol.Payments.Tron.Address (Raxol Payments v0.2.0)

Copy Markdown View Source

Tron Base58Check address codec.

Tron mainnet addresses are a 0x41-prefixed 21-byte payload encoded as Base58Check: Base58(payload <> first4(sha256(sha256(payload)))), which always renders with a leading T. This module validates such addresses and converts between the Base58 form and the 0x41-prefixed hex form the chain uses internally, so the Relay client can reject malformed Tron addresses before any network call.

This is not the EVM 0x-20-byte form; a Tron address carries the extra 0x41 network prefix and a checksum.

Summary

Functions

Convert a 0x41-prefixed hex address (with or without the 0x) to its Base58Check Tron form.

Convert a Base58Check Tron address to its 0x41-prefixed hex form (42 hex chars). Returns {:error, :invalid_address} for malformed input.

True when address is a well-formed Tron mainnet Base58Check address.

Types

t()

@type t() :: String.t()

Functions

from_hex(hex)

@spec from_hex(String.t()) :: {:ok, t()} | {:error, :invalid_address}

Convert a 0x41-prefixed hex address (with or without the 0x) to its Base58Check Tron form.

to_hex(address)

@spec to_hex(t()) :: {:ok, String.t()} | {:error, :invalid_address}

Convert a Base58Check Tron address to its 0x41-prefixed hex form (42 hex chars). Returns {:error, :invalid_address} for malformed input.

valid?(address)

@spec valid?(term()) :: boolean()

True when address is a well-formed Tron mainnet Base58Check address.