Represents a VeChain Address as unsigned integer.

Hierarchy (view full)

Constructors

  • Creates a new instance of this class to represent the value built multiplying sign for the absolute value expressed by the hexadecimal digits.

    Parameters

    • sign: number

      The sign of the value.

    • digits: string

      The digits of the absolute value in hexadecimal base.

    • Optionalnormalize: ((digits: string) => string) = ...

      The function used to normalize the digits. Defaults to converting digits to lowercase.

        • (digits): string
        • Parameters

          • digits: string

          Returns string

    Returns Address

Properties

digits: string

Returns the hexadecimal digits expressing this absolute value, sign and 0x prefix omitted.

An empty content results in an empty string returned.

sign: number

Represents the sign multiplier of a given number:

DIGITS: number = 40

The address is 20 bytes hence 40 digits long.

NEGATIVE: number = -1

Negative multiplier of the digits absolute value.

POSITIVE: number = 1

Positive multiplier of the digits absolute value.

PREFIX: "0x" = '0x'

A constant string prefix used in hexadecimal notation.

RADIX: number = 16

The radix used for representing numbers base 16 in a positional numeral notation system.

REGEX_HEX_PREFIX: RegExp = ...

Regular expression pattern to match a prefix indicating hexadecimal number.

REGEX_HEXUINT_PREFIX: RegExp = ...

Regular expression pattern to match a prefix indicating hexadecimal number.

Accessors

  • get abs(): Hex
  • Returns the absolute value of this Hex object.

    Returns Hex

    A new Hex object representing the absolute value of this Hex.

  • get bi(): bigint
  • Returns the value of bi as a BigInt type.

    Returns bigint

    The value of bi as a BigInt.

  • get bytes(): Uint8Array
  • Returns the Uint8Array representation of the aligned bytes.

    Returns Uint8Array

    The Uint8Array representation of the aligned bytes.

  • get n(): number
  • Retrieves the value of n cast from this instance interpreted as the hexadecimal expression of a bigint value.

    Returns number

    The value of n.

    If n is not within the safe number range, if the number representation of this instance results approximated.

    This class makes equal instances created from the same value as number or as bigint.

Methods

  • Compares the current Hex object with another Hex object.

    Parameters

    • that: Hex

      The Hex object to compare with.

    Returns number

    • Returns a negative number if the current Hex object is less than the given Hex object, zero if they are equal, or a positive number if the current Hex object is greater than the given Hex object.
  • Returns a new instance of the Hex class, its value fits to the specified number of digits.

    Parameters

    • digits: number

      The number of digits to fit the Hex value into.

    Returns Hex

    • A new Hex instance that represents the fitted Hex value.
    • If the Hex value cannot be fit into the specified number of digits.
  • Determines whether this Hex instance is equal to the given Hex instance.

    Parameters

    • that: Hex

      The Hex instance to compare with.

    Returns boolean

    • True if the Hex instances are equal, otherwise false.
  • Returns a string representation of the object.

    Parameters

    • compact: boolean = false

      Whether to compact the string representation.

    Returns string

    The string representation of the object.

  • It checksums a given hexadecimal address.

    Parameters

    • huint: HexUInt

      The HexUInt object representing the hexadecimal value.

    Returns string

    The checksummed address.

  • Validate the given expression to be a valid address.

    Parameters

    • exp: string

      Expression to validate

    Returns boolean

    true if the expression is a valid address, false otherwise

  • Determines whether the given string is a valid unsigned hexadecimal number prefixed with '0x'.

    Parameters

    • exp: string

      The string to be evaluated.

    Returns boolean

    • True if the string is a valid unsigned hexadecimal number prefixed with '0x', otherwise false.
  • Create an Address instance from the given expression interpreted as an unsigned integer.

    Parameters

    • exp:
          | string
          | number
          | bigint
          | Uint8Array
          | HexUInt

      The expression to convert. It can be of type bigint, number, string, Uint8Array, or HexUInt. Not meaningful 0 digits on the left of the expression can be omitted, the returned address is always 20 bytes, 40 digits expression.

    Returns Address

    The converted hexadecimal unsigned integer.

    If the expression is not a valid hexadecimal positive integer expression.

  • Generates an Address object from the given private key.

    Parameters

    • privateKey: Uint8Array

      The private key used to derive the corresponding address.

    Returns Address

    The derived Address object.

    If the provided private key is invalid or cannot derive an address.

  • Generates a random Hex value of the given number of bytes length.

    Parameters

    • bytes: number

      The number of bytes to generate.

    Returns Hex

    • A randomly generated Hex value.
    • If the bytes argument is not greater than 0.

    Security auditable method, depends on