Class CLValueParser

A utility class for parsing CLValues from various formats, including JSON and byte arrays.

Hierarchy

  • CLValueParser

Constructors

Methods

  • Parses a CLValue from a Uint8Array given its type.

    Returns

    An object containing the parsed CLValue and any remaining bytes.

    Throws

    If an unsupported CLType is encountered.

    Parameters

    • bytes: Uint8Array

      The Uint8Array containing the serialized CLValue.

    • sourceType: CLType

      The CLType of the value to parse.

    Returns IResultWithBytes<CLValue>

  • Parses a Uint8Array to extract a CLValue with its corresponding type.

    This method takes a byte array and interprets it as a CLValue by first extracting the length of the value, then splitting the bytes into the value's data and its type.

    Returns

    An IResultWithBytes<CLValue> containing the parsed CLValue and its remaining bytes.

    Throws

    Error - If the length of the value extracted from the bytes is invalid.

    Example

    const bytes = new Uint8Array([...]); // Provide valid CLValue bytes
    const result = CLValueParser.fromBytesWithType(bytes);
    console.log(result.result); // Parsed CLValue

    Parameters

    • bytes: Uint8Array

      The byte array to be parsed.

    Returns IResultWithBytes<CLValue>

  • Parses a CLValue from a JSON representation.

    Returns

    A CLValue instance parsed from the JSON.

    Parameters

    • json: any

      The JSON object representing a CLValue.

    Returns CLValue

  • Serializes a CLValue to bytes, including its type information.

    Returns

    A Uint8Array containing the serialized CLValue with type information.

    Parameters

    • value: CLValue

      The CLValue to serialize.

    Returns Uint8Array

  • Converts a CLValue to its JSON representation.

    Returns

    An object with 'bytes' and 'cl_type' properties representing the CLValue.

    Parameters

    • value: CLValue

      The CLValue to convert.

    Returns {
        bytes: string;
        cl_type: any;
    }

    • bytes: string
    • cl_type: any

Generated using TypeDoc