ExPlasma.Crypto (ExPlasma v0.2.0)

Signs and validates signatures. Constructed signatures can be used directly in Ethereum with ecrecover call.

Link to this section Summary

Functions

Given public key, returns an address.

Produces a KECCAK digest for the message.

Recovers the address of the signer from a binary-encoded signature.

Link to this section Types

Specs

address_t() :: <<_::160>>

Specs

hash_t() :: <<_::256>>

Specs

pub_key_t() :: <<_::512>>
Link to this type

recover_address_error()

Specs

recover_address_error() :: :corrupted_witness | :invalid_message

Specs

sig_t() :: <<_::520>>

Link to this section Functions

Link to this function

generate_address(arg)

Specs

generate_address(pub_key_t()) :: {:ok, address_t()}

Given public key, returns an address.

Link to this function

keccak_hash(message)

Specs

keccak_hash(binary()) :: hash_t()

Produces a KECCAK digest for the message.

Example

iex> ExPlasma.Crypto.keccak_hash("omg!")
<<241, 85, 204, 147, 187, 239, 139, 133, 69, 248, 239, 233, 219, 51, 189, 54,
  171, 76, 106, 229, 69, 102, 203, 7, 21, 134, 230, 92, 23, 209, 187, 12>>
Link to this function

recover_address(arg1, arg2)

Specs

recover_address(hash_t(), sig_t()) ::
  {:ok, address_t()} | {:error, recover_address_error()}

Recovers the address of the signer from a binary-encoded signature.