ExPlasma.Signature (ExPlasma v0.3.0)

Adapted from https://github.com/exthereum/blockchain. Defines helper functions for signing and getting the signature of a transaction, as defined in Appendix F of the Yellow Paper.

For any of the following functions, if chain_id is specified, it's assumed that we're post-fork and we should follow the specification EIP-155 from:

https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md

Link to this section Summary

Functions

Recovers a public key from a signed hash.

Recovers a public key from a signed hash.

Produces a stand-alone, 65 bytes long, signature for message hash.

Link to this section Types

Specs

hash_r() :: integer()

Specs

hash_s() :: integer()

Specs

hash_v() :: integer()
Link to this type

keccak_hash()

Specs

keccak_hash() :: binary()
Link to this type

public_key()

Specs

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

signature_len()

Specs

signature_len() :: 32

Link to this section Functions

Link to this function

recover_public(hash, arg, chain_id \\ nil)

Recovers a public key from a signed hash.

This implements Eq.(208) of the Yellow Paper, adapted from https://stackoverflow.com/a/20000007

Example

iex(1)> ExPlasma.Signature.recover_public(<<2::256>>, <<168, 39, 110, 198, 11, 113, 141, 8, 168, 151, 22, 210, 198, 150, 24, 111, 23,
...(1)>         173, 42, 122, 59, 152, 143, 224, 214, 70, 96, 204, 31, 173, 154, 198, 97, 94,
...(1)>         203, 172, 169, 136, 182, 131, 11, 106, 54, 190, 96, 128, 227, 222, 248, 231,
...(1)>         75, 254, 141, 233, 113, 49, 74, 28, 189, 73, 249, 32, 89, 165, 27>>)
{:ok,
  <<233, 102, 200, 175, 51, 251, 139, 85, 204, 181, 94, 133, 233, 88, 251, 156,
    123, 157, 146, 192, 53, 73, 125, 213, 245, 12, 143, 102, 54, 70, 126, 35, 34,
    167, 2, 255, 248, 68, 210, 117, 183, 156, 4, 185, 77, 27, 53, 239, 10, 57,
    140, 63, 81, 87, 133, 241, 241, 210, 250, 35, 76, 232, 2, 153>>}
Link to this function

recover_public(hash, v, r, s, chain_id \\ nil)

Specs

recover_public(keccak_hash(), hash_v(), hash_r(), hash_s(), integer() | nil) ::
  {:ok, public_key()} | {:error, String.t()}

Recovers a public key from a signed hash.

This implements Eq.(208) of the Yellow Paper, adapted from https://stackoverflow.com/a/20000007

Example

iex(1)> ExPlasma.Signature.recover_public(<<2::256>>,
...(1)>     28,
...(1)>     38_938_543_279_057_362_855_969_661_240_129_897_219_713_373_336_787_331_739_561_340_553_100_525_404_231,
...(1)>     23_772_455_091_703_794_797_226_342_343_520_955_590_158_385_983_376_086_035_257_995_824_653_222_457_926
...(1)>     )
{:ok,
 <<121, 190, 102, 126, 249, 220, 187, 172, 85, 160, 98, 149, 206, 135, 11, 7, 2, 155, 252, 219, 45, 206, 40,
   217, 89, 242, 129, 91, 22, 248, 23, 152, 72, 58, 218, 119, 38, 163, 196, 101, 93, 164, 251, 252, 14, 17,
   8, 168, 253, 23, 180, 72, 166, 133, 84, 25, 156, 71, 208, 143, 251, 16, 212, 184>>}
Link to this function

signature_digest(hash_digest, private_key_hash)

Specs

signature_digest(keccak_hash(), String.t()) :: ExPlasma.Crypto.sig_t()

Produces a stand-alone, 65 bytes long, signature for message hash.