Class Ed25519PrivateKey

Class representing an Ed25519 private key.

An Ed25519 private key is a cryptographic key used in the Ed25519 signature scheme, which is a highly efficient elliptic-curve signature system. It provides secure and fast cryptographic operations, ensuring the integrity and authenticity of data.

The Ed25519 private key is a component in public-key cryptography, where it is primarily used for signing data. The private key generates a digital signature that can be verified using the corresponding Ed25519 public key. The signature confirms the origin of the data and ensures that it has not been tampered with.

Properties

ptr: number

Pointer to the native Ed25519 private key object in the WebAssembly (WASM) memory.

Methods

  • Derives the public key corresponding to this private key.

    Returns Ed25519PublicKey

    An Ed25519PublicKey instance.

    If the operation fails.

    const publicKey = privateKey.getPublicKey();
    console.log('Public key:', publicKey.toHex());
  • The reference count retrieved by this method reflects the number of references maintained internally by libcardano-c for this native instance of the object. This is unrelated to the reference counting mechanism in JavaScript, which is managed by the JavaScript engine's garbage collector.

    This method is primarily intended for diagnostic purposes.

    Returns number

    The current reference count of the object in the WASM context.

  • Signs a message using the private key.

    Parameters

    • message: Uint8Array

      The message to sign as a byte array.

    Returns Ed25519Signature

    An Ed25519Signature instance representing the message signature.

    If signing fails.

    const message = new Uint8Array([0x01, 0x02, 0x03]);
    const signature = privateKey.sign(message);
    console.log('Signature as hex:', signature.toHex());
  • Converts the Ed25519 private key to its raw byte array representation.

    Returns Uint8Array

    A Uint8Array containing the private key bytes.

    If the operation fails.

    const privateKeyData = privateKey.toBytes();
    console.log(privateKeyData); // Outputs the private key bytes
  • Converts the Ed25519 private key to its hexadecimal string representation.

    Returns string

    A string containing the hexadecimal representation of the private key.

    If the operation fails.

    const privateKeyHex = privateKey.toHex();
    console.log(privateKeyHex); // Outputs the private key as a hexadecimal string
  • Creates an Ed25519 private key from a byte array.

    This function is used to create an Ed25519 private key from an "extended" representation of the private key. The extended version includes both the secret scalar (32 bytes) and additional precomputed components (32 bytes), resulting in a total of 64 bytes.

    Parameters

    • data: Uint8Array

      The extended byte array (64 bytes) representing the private key. - Must be exactly 64 bytes in length to conform to the Ed25519 extended key format.

    Returns Ed25519PrivateKey

    An instance of Ed25519PrivateKey.

    If the operation fails, such as if the provided data is not valid.

    const privateKeyData = new Uint8Array([0x01, 0x02, 0x03, ...]); // 64 bytes
    const privateKey = Ed25519PrivateKey.fromExtendedBytes(privateKeyData);
    console.log(privateKey);
  • Creates an Ed25519 private key from a hexadecimal string.

    This method is used to create an Ed25519 private key from its "extended" representation encoded as a hexadecimal string. The extended version includes both the 32-byte scalar (private key) and 32 bytes of precomputed data, encoded as a 128-character hex string.

    Parameters

    • hex: string

      A string representing the hexadecimal encoding of the extended Ed25519 private key. - Must be a valid hexadecimal string of exactly 128 characters (representing 64 bytes).

    Returns Ed25519PrivateKey

    An instance of Ed25519PrivateKey.

    If the operation fails, such as if the provided string is invalid or improperly formatted.

    const extendedPrivateKeyHex = "abcdef0123456789..."; // 128-character hex string
    const privateKey = Ed25519PrivateKey.fromExtendedHex(extendedPrivateKeyHex);
    console.log(privateKey);
  • Creates an Ed25519 private key from a byte array.

    This function is used to create an Ed25519 private key from a "normal" representation of the private key in byte form, as opposed to the "extended" version. The normal version of the key consists of 32 bytes representing the secret scalar directly, as defined by the Ed25519 specification.

    The normal version is used in cryptographic applications where only the core private key (the scalar) is required for signing operations. It does not include additional metadata or derived values that might be present in extended representations.

    Parameters

    • data: Uint8Array

      The byte array representing the private key. - Must be exactly 32 bytes in length to conform to the Ed25519 normal key format.

    Returns Ed25519PrivateKey

    An instance of Ed25519PrivateKey.

    If the operation fails, such as if the provided data is not valid.

    const privateKeyData = new Uint8Array([0x01, 0x02, 0x03, ...]);
    const privateKey = Ed25519PrivateKey.fromNormalBytes(privateKeyData);
    // Can now use the privateKey object
  • Creates an Ed25519 private key from a hexadecimal string.

    This method is used to create an Ed25519 private key from its "normal" representation encoded as a hexadecimal string. The normal version consists of the 32-byte scalar value that serves as the private key, encoded in a human-readable hex format.

    Parameters

    • hex: string

      A string representing the hexadecimal encoding of the normal Ed25519 private key. - Must be a valid hexadecimal string of exactly 64 characters (representing 32 bytes).

    Returns Ed25519PrivateKey

    An instance of Ed25519PrivateKey.

    If the operation fails, such as if the provided string is invalid or improperly formatted.

    const privateKeyHex = "abcdef0123456789..."; // 64-character hex string
    const privateKey = Ed25519PrivateKey.fromNormalHex(privateKeyHex);
    console.log(privateKey);