Class PublicKey

Represents a public key with a cryptographic algorithm and key data. Provides utilities for serialization, verification, and obtaining an associated account hash.

Hierarchy

  • PublicKey

Constructors

  • Creates an instance of PublicKey.

    Parameters

    • cryptoAlg: KeyAlgorithm

      The cryptographic algorithm used by the key.

    • key: PublicKeyInternal

      The actual key data.

    Returns PublicKey

Properties

cryptoAlg: KeyAlgorithm

The cryptographic algorithm used for the key.

key: null | PublicKeyInternal

The key data associated with the public key.

Methods

  • Returns the byte representation of the public key.

    Returns

    A Uint8Array of the public key bytes.

    Returns Uint8Array

  • Checks equality between two PublicKey instances.

    Returns

    True if the two PublicKey instances are equal; otherwise, false.

    Parameters

    • other: PublicKey

      The other PublicKey instance to compare.

    Returns boolean

  • Converts the public key to a hexadecimal string representation.

    Returns

    The hexadecimal string representation of the public key.

    • If checksummed is true, the result includes a checksum.
    • If checksummed is false, the raw hex string is returned.

    Throws

    If the public key is not initialized properly (i.e., this.key is missing).

    Parameters

    • checksummed: boolean = false

      A boolean indicating whether to return a checksummed version of the hex string.

      • true: Includes a checksum in the output.
      • false (default): Returns the raw hexadecimal string without a checksum.

    Returns string

  • Serializes the public key to a JSON-compatible string.

    Returns

    A JSON string representation of the public key.

    Returns string

  • Converts the public key to a string representation.

    Returns

    A string representation of the public key in hexadecimal.

    Returns string

  • Verifies a signature for a given message.

    Returns

    A promise that resolves to a boolean indicating the validity of the signature.

    Throws

    Error if the signature or public key is empty, or if the signature is invalid.

    Parameters

    • message: Uint8Array

      The message to verify.

    • sig: Uint8Array

      The signature to verify.

    Returns boolean

  • Returns the bytes encoded as hexadecimal with mixed-case based checksums following a scheme similar to EIP-55. Key differences:

    • Works on any length of data, not just 20-byte addresses
    • Uses Blake2b hashes rather than Keccak
    • Uses hash bits rather than nibbles

    Returns

    checksummed hex presentation string of input

    Parameters

    • input: Uint8Array

      Uint8Array to generate checksummed hex string

    Returns string

  • Creates a PublicKey instance from an ArrayBuffer.

    Returns

    A new PublicKey instance.

    Throws

    Error if the public key algorithm is invalid.

    Parameters

    • buffer: ArrayBuffer

      The ArrayBuffer.

    Returns PublicKey

  • Tries to decode PublicKey from its hex-representation. The hex format should be as produced by PublicKey.toHex

    Parameters

    • publicKeyHex: string

      public key hex string contains key tag

    • checksummed: boolean = false

      throws an Error if true and given string is not checksummed

    Returns PublicKey

  • Verify a mixed-case hexadecimal string that it conforms to the checksum scheme similar to scheme in EIP-55. Key differences:

    • Works on any length of (decoded) data up to SMALL_BYTES_COUNT, not just 20-byte addresses
    • Uses Blake2b hashes rather than Keccak
    • Uses hash bits rather than nibbles For backward compatibility: if the hex string is all uppercase or all lowercase, the check is skipped.

    Returns

    true if input is checksummed

    Parameters

    • input: string

      string to check if it is checksummed

    Returns boolean

Generated using TypeDoc