Class TransferHash

Represents a transfer hash, extending the Hash class, with an additional prefix specific to transfer entities. This prefix aids in identifying transfer-related hashes within the system.

Hierarchy

Constructors

  • Creates an instance of TransferHash. Supports both hex strings (with or without the transfer prefix) and Uint8Array representations of the hash.

    Parameters

    • source: string | Uint8Array

      A hex string or Uint8Array representing the hash.

    Returns TransferHash

Properties

originPrefix: string = PrefixNameTransfer

The origin prefix used to identify transfer-related hashes, defaulting to transfer-.

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

  • Serializes the TransferHash to a JSON-compatible string. Primarily used for JSON-based data exchange or storage.

    Returns

    A JSON-compatible string representation of the TransferHash.

    Returns string

  • Converts the TransferHash to a standardized prefixed string format. This format includes the transfer-specific prefix followed by the hash in hexadecimal format.

    Returns

    A string representation of the TransferHash with its prefix.

    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

  • Instantiates a TransferHash from a JSON-compatible string, allowing for easy deserialization. The string should represent the TransferHash in prefixed hex format.

    Returns

    A new TransferHash instance initialized from the JSON string.

    Parameters

    • json: string

      The JSON string representing the TransferHash.

    Returns TransferHash

  • Parses a source string to extract the hash bytes and verify if it includes the transfer prefix.

    Returns

    An object containing the hash bytes and the detected origin prefix.

    Parameters

    • source: string

      The source string representing the transfer hash, optionally prefixed.

    Returns {
        hashBytes: Uint8Array;
        originPrefix: string;
    }

    • hashBytes: Uint8Array
    • originPrefix: string

Generated using TypeDoc