Class Hash

Represents a cryptographic hash. This class provides methods for creating, manipulating, and comparing hash values.

Hierarchy

Constructors

  • Creates a new Hash instance.

    Throws

    Error if the byte array length does not match the expected hash length.

    Parameters

    • hashBytes: Uint8Array

      The byte array representing the hash.

    Returns Hash

Properties

hashBytes: Uint8Array
ByteHashLen: number = 32

The fixed length of the hash in bytes.

StringHashLen: number = 64

The fixed length of the hash string representation in hexadecimal characters.

Methods

  • Compares this Hash instance with another Hash instance for equality.

    Returns

    True if the hashes are equal, false otherwise.

    Parameters

    • other: Hash

      The other Hash to compare with.

    Returns boolean

  • Converts the Hash instance to a byte array.

    Returns

    The byte array representation of the hash.

    Returns Uint8Array

  • Converts the Hash instance to a hexadecimal string.

    Returns

    The hexadecimal string representation of the hash.

    Returns string

  • Converts the Hash instance to its JSON representation.

    Returns

    The JSON string representation of the hash.

    Returns string

  • Creates an array of Hash instances from a byte array.

    Returns

    An array of Hash instances created from the byte array.

    Throws

    Error if the byte array length is not a multiple of the hash length.

    Parameters

    • byteArray: Uint8Array

      The byte array containing multiple hash values.

    Returns Hash[]

  • Creates a Hash instance from a Buffer.

    Returns

    A new Hash instance.

    Throws

    Error if the buffer length is less than the required hash length.

    Parameters

    • buffer: Buffer

      The Buffer containing the hash bytes.

    Returns Hash

  • Creates a Hash instance from a byte array.

    Returns

    A result object containing the new Hash instance and the remaining bytes.

    Throws

    Error if the byte array length does not match the expected hash length.

    Parameters

    • source: Uint8Array

      The byte array representing the hash.

    Returns IResultWithBytes<Hash>

  • Creates a Hash instance from a hexadecimal string.

    Returns

    A new Hash instance.

    Throws

    Error if the string length does not match the expected hash length.

    Parameters

    • source: string

      The hexadecimal string representation of the hash.

    Returns Hash

  • Creates a Hash instance from its JSON representation.

    Returns

    A new Hash instance.

    Parameters

    • json: string

      The JSON string representation of the hash.

    Returns Hash

Generated using TypeDoc