Class PublicKey

A class representing a public key.

Remarks

The public key is an essential component of asymmetric cryptography. It is intrinsically linked to the private key.

Constructors

Properties

bytes: Uint8Array
hasher: default
prefix: string = PUBLIC_KEY_PREFIX
serializer: default
signer: default
version: Version
versioner: Versioner

Methods

  • Serializes the public key to a string.

    Returns string

    The serialized public key string.

    Remarks

    A public key is serialized as follows:

    • The version is serialized as a varint and prepended to the public key bytes.
    • The result is then sent to the serializer.
  • Checks the message signature with the public key.

    Parameters

    • data: Uint8Array

      The data signed by the signature.

    • signature: Signature

      The signature to verify.

    Returns Promise<boolean>

    A boolean indicating whether the signature is valid.

    Remarks

    This function very a byte-encoded message. The message is first hashed and then verified. Do not pass a digest to this function as it will be hashed twice.

  • Initializes a new public key object from a serialized string.

    Parameters

    • str: string

      The serialized public key string.

    Returns PublicKey

    A new public key instance.

    Throws

    If the public key prefix is invalid.

  • Initializes a new public key object from a version.

    Parameters

    • version: Version = Version.V0

      The version of the private key. If not defined, the last version will be used.

    Returns PublicKey

    A new public key instance.

    Throws

    If the version is not supported.