Documentation ¶
Index ¶
- Variables
- func AddPrefix(hexStr string) string
- func HasPrefix(hexStr string) bool
- func HexFixLength(hexStr string, bitLength int, withPadding bool) string
- func Reverse(s string) string
- func StripPrefix(hexStr string) string
- func ToBN(hexStr string, isLittleEndian bool, isNegative bool) (*big.Int, error)
- func ToUint8Slice(hexStr string, bitLength int) ([]uint8, error)
- func ValidHex(hexStr string) bool
Constants ¶
This section is empty.
Variables ¶
var ( // Prefix hex prefix Prefix = "0x" // ErrInvalidHex is error for invalid hex ErrInvalidHex = errors.New("invalid hex") )
Functions ¶
func AddPrefix ¶
AddPrefix adds the `0x` prefix to string values. Returns a `0x` prefixed string from the input value. If the input is already prefixed, it is returned unchanged. Adds extra 0 when `length % 2 == 1`.
func HasPrefix ¶
HasPrefix tests for the existence of a `0x` prefix. Checks for a valid hex input value and if the start matched `0x`.
func HexFixLength ¶
HexFixLength shifts a hex string to a specific bitLength. Returns a `0x` prefixed string with the specified number of bits contained in the return value. (If bitLength is -1, length checking is not done). Values with more bits are trimmed to the specified length. Input values with less bits are returned as-is by default. When `withPadding` is set, shorter values are padded with `0`.
func StripPrefix ¶
StripPrefix strips any leading `0x` prefix. Tests for the existence of a `0x` prefix, and returns the value without the prefix. Un-prefixed values are returned as-is.
func ToUint8Slice ¶
ToUint8Slice creates a uint8 array from a hex string. empty inputs returns an empty array result. Hex input values return the actual bytes value converted to a uint8. Anything that is not a hex string (including the `0x` prefix) returns an error.
Types ¶
This section is empty.