Tezex.Crypto.PrivateKey (tezex v3.2.0)

View Source

Holds private key data.

Used to create private keys and created public keys from private keys.

Parameters:

Summary

Functions

Holds private key data.

Creates a private key from a Tezos encoded key string.

Creates a private key from a Tezos encoded key string (raises on error).

Gets the public key associated with a private key

Types

t()

@type t() :: %Tezex.Crypto.PrivateKey{curve: Tezex.Crypto.Curve.t(), secret: binary()}

Functions

%Tezex.Crypto.PrivateKey{}

(struct)

Holds private key data.

Parameters:

from_encoded_key(encoded_key, passphrase \\ nil)

@spec from_encoded_key(String.t(), String.t() | nil) :: {:ok, t()} | {:error, atom()}

Creates a private key from a Tezos encoded key string.

Supports both encrypted and unencrypted private keys in the formats:

  • edsk... (Ed25519 seed or secret key)
  • edesk... (Ed25519 encrypted seed)
  • spsk... (Secp256k1 secret key)
  • spesk... (Secp256k1 encrypted secret key)
  • p2sk... (P256 secret key)
  • p2esk... (P256 encrypted secret key)
  • BLsk... (BLS12-381 secret key)
  • BLesk... (BLS12-381 encrypted secret key)

Parameters

  • encoded_key - Base58-encoded private key string
  • passphrase - Passphrase for encrypted keys (optional)

Returns

  • {:ok, private_key} - Successfully parsed private key
  • {:error, reason} - Parsing failed

from_encoded_key!(encoded_key, passphrase \\ nil)

@spec from_encoded_key!(String.t(), String.t() | nil) :: t()

Creates a private key from a Tezos encoded key string (raises on error).

Parameters

  • encoded_key - Base58-encoded private key string
  • passphrase - Passphrase for encrypted keys (optional)

Returns

  • private_key - Successfully parsed private key

Raises

generate(secret \\ nil, curve_name \\ :secp256k1)

@spec generate(nil | binary(), atom()) :: t()

Creates a new private key

Parameters:

  • secret [binary/0]: private key secret. Default: nil -> random key will be generated
  • curve_name [atom/0]: curve name. Default: :secp256k1

Returns:

Example:

iex> Tezex.Crypto.PrivateKey.generate()
%Tezex.Crypto.PrivateKey{...}

get_public_key(private_key)

@spec get_public_key(t()) :: Tezex.Crypto.PublicKey.t()

Gets the public key associated with a private key

Parameters:

Returns:

Example:

iex> Tezex.Crypto.PrivateKey.get_public_key(private_key)
%Tezex.Crypto.PublicKey{...}