Tezex.Crypto.PrivateKey (tezex v3.2.0)
View SourceHolds private key data.
Used to create private keys and created public keys from private keys.
Parameters:
:secret
[binary/0
]: public key point data;:curve
[Tezex.Crypto.Curve.t/0
]: public key curve information.
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).
Creates a new private key
Gets the public key associated with a private key
Types
@type t() :: %Tezex.Crypto.PrivateKey{curve: Tezex.Crypto.Curve.t(), secret: binary()}
Functions
Holds private key data.
Parameters:
:secret
[binary/0
]: private key secret number as bytes:curve
[Tezex.Crypto.Curve.t/0
]: private key curve information
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 stringpassphrase
- Passphrase for encrypted keys (optional)
Returns
{:ok, private_key}
- Successfully parsed private key{:error, reason}
- Parsing failed
Creates a private key from a Tezos encoded key string (raises on error).
Parameters
encoded_key
- Base58-encoded private key stringpassphrase
- Passphrase for encrypted keys (optional)
Returns
private_key
- Successfully parsed private key
Raises
RuntimeError
- When key parsing fails
Creates a new private key
Parameters:
secret
[binary/0
]: private key secret. Default: nil -> random key will be generatedcurve_name
[atom/0
]: curve name. Default: :secp256k1
Returns:
private_key
[Tezex.Crypto.PrivateKey.t/0
]: private key struct
Example:
iex> Tezex.Crypto.PrivateKey.generate()
%Tezex.Crypto.PrivateKey{...}
@spec get_public_key(t()) :: Tezex.Crypto.PublicKey.t()
Gets the public key associated with a private key
Parameters:
private_key
[Tezex.Crypto.PrivateKey.t/0
]: private key struct
Returns:
public_key
[Tezex.Crypto.PublicKey.t/0
]: public key struct
Example:
iex> Tezex.Crypto.PrivateKey.get_public_key(private_key)
%Tezex.Crypto.PublicKey{...}