The BlockRef class represents a Thor block ID value, which is a hexadecimal positive integer having 64 digits.

Hierarchy (view full)

Constructors

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:

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.

  • Check if the given expression is a valid BlockRef.

    Parameters

    • exp: string

      The expression to be validated.

    Returns boolean

    Returns true if the expression is a valid BlockRef, false otherwise.

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

    Parameters

    • exp: string

      The hex number to be checked.

    Returns boolean

    • True if the hex number is valid, false otherwise.
  • Creates a new BlockRef object from the given expression.

    Parameters

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

      The expression to create the BlockRef from. It can be one of the following types: - bigint: A BigInteger value that represents the BlockRef. - number: A number value that represents the BlockRef. - string: A string value that represents the BlockRef. - HexUInt: A HexUInt object that represents the BlockRef. - Uint8Array: A Uint8Array object that represents the BlockRef.

    Returns BlockRef

    • A new BlockRef object created from the given expression.

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

  • 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