Create a new Hex instance from a Uint8Array.
The Uint8Array containing the data to initialize the Hex instance.
Determine if two Hex instances are equal by comparing their underlying byte data.
The Hex instance to compare to.
true if the Hex instances are equal, false if not.
Get the hex data as a string with the 0x prefix.
Hex string with 0x prefix
Get the hex data as a string without the 0x prefix.
Hex string without 0x prefix
Get the inner hex data as a Uint8Array. The inner data is already a Uint8Array, so no conversion takes place.
Hex data as Uint8Array
Static
fromConverts an instance of HexInput, which can be a string or a Uint8Array, into a Hex instance. This function is useful for transforming hexadecimal representations into a structured Hex object for further manipulation.
A HexInput which can be a string or Uint8Array.
A Hex instance created from the provided hexInput.
Static
fromConverts a hex string into a Hex instance, allowing for both prefixed and non-prefixed formats.
A hex string, with or without the 0x prefix.
Hex - The resulting Hex instance created from the provided string.
Static
isCheck if the provided string is a valid hexadecimal representation.
A hex string representing byte data.
An object containing:
Static
hexConverts a HexInput (string or Uint8Array) to a hex string with '0x' prefix.
The input to convert, either a hex string (with/without '0x' prefix) or Uint8Array
A hex string with '0x' prefix (e.g., "0x1234")
Static
hexConverts a HexInput (string or Uint8Array) to a hex string without '0x' prefix.
The input to convert, either a hex string (with/without '0x' prefix) or Uint8Array
A hex string without '0x' prefix (e.g., "1234")
Static
hexConverts an instance of HexInput, which can be a string or a Uint8Array, into a Uint8Array.
A HexInput which can be a string or Uint8Array.
A Uint8Array created from the provided hexInput.
NOTE: Do not use this class when working with account addresses; use AccountAddress instead. When accepting hex data as input to a function, prefer to accept HexInput and
A helper class for working with hex data. Hex data, when represented as a string, generally looks like this, for example: 0xaabbcc, 45cd32, etc.
then use the static helper methods of this class to convert it into the desired format. This enables the greatest flexibility for the developer.
Example usage:
This call to
Hex.fromHexInput().toString()
converts the HexInput to a hex string with a leading 0x prefix, regardless of what the input format was.Other ways to chain the functions together:
Hex.fromHexString({ hexInput: "0x1f" }).toUint8Array()
new Hex([1, 3]).toStringWithoutPrefix()