Documentation
¶
Overview ¶
Package common provides shared utilities for encoding, hashing, and data conversion.
Index ¶
- Constants
- Variables
- func Bytes2Hex(d []byte) string
- func BytesToHexString(bytes []byte) string
- func CopyBytes(b []byte) (copiedBytes []byte)
- func Decode(input string) ([]byte, error)
- func DecodeCheck(input string) ([]byte, error)
- func EnableAllVerbose()
- func Encode(input []byte) string
- func EncodeCheck(input []byte) string
- func FromHex(s string) ([]byte, error)
- func Has0xPrefix(str string) bool
- func Hex2Bytes(str string) ([]byte, error)
- func Hex2BytesFixed(str string, flen int) []byte
- func HexStringToBytes(input string) ([]byte, error)
- func IsHex(str string) bool
- func JSONPrettyFormat(in string) string
- func Keccak256(msg []byte) []byte
- func LeftPadBytes(slice []byte, l int) []byte
- func RightPadBytes(slice []byte, l int) []byte
- func ToHex(b []byte) stringdeprecated
- func ToHexArray(b [][]byte) []string
- func ToJSONUnsafe(payload interface{}, pretty bool) string
- func TrimLeftZeroes(s []byte) []byte
- func ZeroBytes(b []byte)
- type Hash
Constants ¶
const ( // DefaultConfigAccountAliasesDirName is the directory name for account key aliases. DefaultConfigAccountAliasesDirName = "account-keys" // DefaultPassphrase is the default passphrase used when none is provided. DefaultPassphrase = "" // Secp256k1PrivateKeyBytesLength is the required byte length of a secp256k1 private key. Secp256k1PrivateKeyBytesLength = 32 // AmountDecimalPoint is the number of decimal places in TRX (1 TRX = 10^6 SUN). AmountDecimalPoint = 6 )
const (
// HashLength is the expected length of the hash
HashLength = 32
)
Variables ¶
var ( // DefaultConfigDirName is the default directory name for tronctl configuration. DefaultConfigDirName = ".tronctl" // DebugGRPC enables verbose gRPC request/response logging when true. DebugGRPC = false // DebugTransaction enables verbose transaction logging when true. DebugTransaction = false // ErrNotAbsPath is returned when a keypath is not an absolute path. ErrNotAbsPath = errors.New("keypath is not absolute path") // ErrBadKeyLength is returned when a private key has an invalid length. ErrBadKeyLength = errors.New("ivalid private key (wrong length)") // ErrFoundNoPass is returned when no passphrase file is found. ErrFoundNoPass = errors.New("found no passphrase file") )
var EmptyString = &hexError{"empty hex string"}
EmptyString is the error returned when decoding an empty hex string.
Functions ¶
func BytesToHexString ¶
BytesToHexString encodes bytes as a hex string.
func DecodeCheck ¶
DecodeCheck decodes a Base58Check string, validates the checksum and TRON prefix (0x41), and returns the decoded bytes (prefix + 20-byte address payload) without the checksum.
func EnableAllVerbose ¶
func EnableAllVerbose()
EnableAllVerbose enables all debug logging flags (gRPC and transaction).
func EncodeCheck ¶
EncodeCheck returns the Base58Check encoding of input (Base58 with a 4-byte SHA-256d checksum).
func FromHex ¶
FromHex returns the bytes represented by the hexadecimal string s. s may be prefixed with "0x".
func Has0xPrefix ¶
Has0xPrefix validates str begins with '0x' or '0X'.
func Hex2BytesFixed ¶
Hex2BytesFixed returns bytes of a specified fixed length flen.
func HexStringToBytes ¶
HexStringToBytes decodes a hex string (with or without "0x" prefix) into bytes.
func JSONPrettyFormat ¶
JSONPrettyFormat returns the JSON string indented for readability.
func LeftPadBytes ¶
LeftPadBytes zero-pads slice to the left up to length l.
func RightPadBytes ¶
RightPadBytes zero-pads slice to the right up to length l.
func ToHexArray ¶
ToHexArray converts each byte slice in b to a "0x"-prefixed hex string.
func ToJSONUnsafe ¶
ToJSONUnsafe marshals payload to JSON, returning "{}" on failure.
func TrimLeftZeroes ¶
TrimLeftZeroes returns a subslice of s without leading zero bytes.
Types ¶
type Hash ¶
type Hash [HashLength]byte
Hash represents the 32 byte Keccak256 hash of arbitrary data.
func BigToHash ¶
BigToHash sets byte representation of b to hash. If b is larger than len(h), b will be cropped from the left.
func BytesToHash ¶
BytesToHash sets b to hash. If b is larger than len(h), b will be cropped from the left.
func HexToHash ¶
HexToHash sets byte representation of s to hash. If b is larger than len(h), b will be cropped from the left.
func (*Hash) SetBytes ¶
SetBytes sets the hash to the value of b. If b is larger than len(h), b will be cropped from the left.
func (Hash) String ¶
String implements the stringer interface and is used also by the logger when doing full logging into a file.
func (Hash) TerminalString ¶
TerminalString implements log.TerminalStringer, formatting a string for console output during logging.