Search documentation of Cartouche

# Cartouche.Signer.Curvy (Cartouche v0.1.3)

Copy Markdown View Source

Signer to sign messages using a private key directly.

Note: this should not be used in production systems. Please see `Cartouche.Signer.CloudKMS`.

## Summary

### Functions

get_address(private_key)

Get the Ethereum address associated with the given private key.

sign(message, private_key)

Signs the given message using the private key, after digesting the message with keccak.

sign_digest(message_hash, private_key)

Signs the given message which was already digested.

## Functions

# get_address(private_key)

    @spec get_address(binary()) :: {:ok, binary()} | {:error, String.t()}

Get the Ethereum address associated with the given private key.

## Examples

    iex> priv_key = "800509fa3e80882ad0be77c27505bdc91380f800d51ed80897d22f9fcc75f4bf" |> Base.decode16!(case: :mixed)
    iex> {:ok, address} = Cartouche.Signer.Curvy.get_address(priv_key)
    iex> Cartouche.Hex.to_address(address)
    "0x63Cc7c25e0cdb121aBb0fE477a6b9901889F99A7"

# sign(message, private_key)

    @spec sign(String.t(), binary()) :: {:ok, Curvy.Signature.t()} | {:error, String.t()}

Signs the given message using the private key, after digesting the message with keccak.

## Examples

    iex> use Cartouche.Hex
    iex> priv_key = ~h[0x800509fa3e80882ad0be77c27505bdc91380f800d51ed80897d22f9fcc75f4bf]
    iex> {:ok, sig} = Cartouche.Signer.Curvy.sign("test", priv_key)
    iex> {:ok, recid} = Cartouche.Recover.find_recid("test", sig, ~h[0x63Cc7c25e0cdb121aBb0fE477a6b9901889F99A7])
    iex> Cartouche.Recover.recover_eth("test", %{sig|recid: recid}) |> Cartouche.Hex.to_address()
    "0x63Cc7c25e0cdb121aBb0fE477a6b9901889F99A7"

# sign_digest(message_hash, private_key)

    @spec sign_digest(String.t(), binary()) ::
      {:ok, Curvy.Signature.t()} | {:error, String.t()}

Signs the given message which was already digested.

## Examples

    iex> use Cartouche.Hex
    iex> priv_key = ~h[0x800509fa3e80882ad0be77c27505bdc91380f800d51ed80897d22f9fcc75f4bf]
    iex> message_hash = ~h[0x9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658]
    iex> {:ok, sig} = Cartouche.Signer.Curvy.sign_digest(message_hash, priv_key)
    iex> {:ok, recid} = Cartouche.Recover.find_recid("test", sig, ~h[0x63Cc7c25e0cdb121aBb0fE477a6b9901889F99A7])
    iex> Cartouche.Recover.recover_eth("test", %{sig|recid: recid}) |> Cartouche.Hex.to_address()
    "0x63Cc7c25e0cdb121aBb0fE477a6b9901889F99A7"