Class Conversions

A utility class for various data conversions used in the Casper ecosystem. Provides methods to convert between different encodings (Base64, Base16) and to perform conversions between CSPR and motes.

Hierarchy

  • Conversions

Constructors

Methods

  • Converts a Base-64 encoded string to a Base-16 (hexadecimal) encoded string.

    Returns

    A Base-16 encoded string.

    Example

    const base64 = "SGVsbG8=";
    const base16 = Conversions.base64to16(base64);
    console.log(base16); // Outputs: "48656c6c6f"

    Parameters

    • base64: string

      The Base-64 encoded string to be converted.

    Returns string

  • Converts a CSPR amount to its mote equivalent.

    Returns

    A BigNumber containing the equivalent amount in motes.

    Remarks

    1 CSPR = 10^9 motes

    Example

    const cspr = 1;
    const motes = Conversions.csprToMotes(cspr);
    console.log(motes.toString()); // Outputs: "1000000000"

    Parameters

    • cspr: string | number

      A string amount of CSPR to convert to motes.

    Returns BigNumber

  • Decodes a Base-16 (hexadecimal) encoded string and returns a Uint8Array of bytes.

    Returns

    A Uint8Array containing the decoded bytes.

    Example

    const base16 = "48656c6c6f";
    const bytes = Conversions.decodeBase16(base16);
    console.log(bytes); // Outputs: Uint8Array(5) [72, 101, 108, 108, 111]

    Parameters

    • base16String: string

      The Base-16 encoded string to be decoded.

    Returns Uint8Array

  • Decodes a Base-64 encoded string and returns a Uint8Array of bytes.

    Returns

    A Uint8Array containing the decoded bytes.

    Example

    const base64 = "SGVsbG8=";
    const bytes = Conversions.decodeBase64(base64);
    console.log(bytes); // Outputs: Uint8Array(5) [72, 101, 108, 108, 111]

    Parameters

    • base64String: string

      The Base-64 encoded string to be decoded.

    Returns Uint8Array

  • Encodes a Uint8Array into a string using Base-16 (hexadecimal) encoding.

    Returns

    A Base-16 encoded string representation of the input bytes.

    Example

    const bytes = new Uint8Array([72, 101, 108, 108, 111]);
    const base16 = Conversions.encodeBase16(bytes);
    console.log(base16); // Outputs: "48656c6c6f"

    Parameters

    • bytes: Uint8Array

      The Uint8Array to be encoded.

    Returns string

  • Encodes a Uint8Array into a string using Base-64 encoding.

    Returns

    A Base-64 encoded string representation of the input bytes.

    Example

    const bytes = new Uint8Array([72, 101, 108, 108, 111]);
    const base64 = Conversions.encodeBase64(bytes);
    console.log(base64); // Outputs: "SGVsbG8="

    Parameters

    • bytes: Uint8Array

      The Uint8Array to be encoded.

    Returns string

  • Converts an amount in motes to its CSPR equivalent.

    Returns

    A BigNumber containing the equivalent amount in CSPR.

    Remarks

    This function will round to the nearest whole integer. 1 mote = 10^-9 CSPR

    Example

    const motes = BigNumber.from('1000000000');
    const cspr = Conversions.motesToCSPR(motes);
    console.log(cspr.toString()); // Outputs: "1"

    Parameters

    • motes: BigNumberish

      A BigNumberish amount of motes to convert to CSPR.

    Returns string

Generated using TypeDoc