Skip to main content

TypeAlias.Hex

type Hex: `0x${string}`;

Represents a hexadecimal value in blockchain-related contexts.

Remarks

The Hex type is a string that starts with the "0x" prefix, followed by a sequence of hexadecimal characters. It is commonly used to represent various types of data in hexadecimal format, such as public keys, signed messages, transaction data, and more. The length of the hexadecimal string can vary depending on what it represents.

Format:

  • Prefix: Must start with "0x".
  • Characters: The characters following the prefix should be valid hexadecimal digits (0-9, a-f, A-F).
  • Length: Variable length, depending on the data being represented.
  • Examples:
    • Public Key (uncompressed): Typically 130 characters (representing 65 bytes).
      • Example: "0x04bfcab42e267cde6bf56789237f24e63bb1b2c4a7a2938a1df47f8e0e3d1b45ae9ef1e3b5a72f2df9f3e6f7d8c1a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8"
    • Signed Message: Length can vary depending on the signature algorithm.
      • Example: "0x1b8e0a12f31f3b5c3c1b6e9f0d4a7f5e6b7d8c9a0e1f2a3b4c5d6e7f8e9f0a1b"

Usage: The Hex type alias ensures that any variable representing a hexadecimal value conforms to the expected format. It is used throughout the SDK to represent binary data in a human-readable hexadecimal string format. This is especially important for serialization, storage, and transmission of data in blockchain applications.

Common Use Cases:

  • Public Keys: Representing public keys in hexadecimal format for cryptographic operations.
  • Signatures: Storing and transmitting digital signatures.
  • Transaction Data: Encoding transaction payloads or other binary data.
  • Hashes and Digests: While specific types like Hash exist, Hex can be used for general-purpose hexadecimal data.