View Source Signet.Recover (Signet v1.0.0-beta7)
Summary
Functions
Finds the given recid which recovers the given signature for the message to the given Ethereum address. This is a very simple guess-check-revise since there are only four possible values, and we only accept two of those.
Prefixes a message with "Etheruem Signed Message" prefix, as per EIP-191.
Recovers a signer's Ethereum address from a signed message. The message will be digested by keccak first. Note: the rec_id can be embeded in the signature or passed separately.
Recovers a signer's public key from a signed message. The message will be digested by keccak first. Note: the rec_id can be embeded in the signature or passed separately.
Functions
Finds the given recid which recovers the given signature for the message to the given Ethereum address. This is a very simple guess-check-revise since there are only four possible values, and we only accept two of those.
Examples
iex> priv_key = Base.decode16!("800509fa3e80882ad0be77c27505bdc91380f800d51ed80897d22f9fcc75f4bf", case: :mixed) iex> {:ok, sig} = Signet.Signer.Curvy.sign("test", priv_key) iex> {:ok, recid} = Signet.Recover.find_recid("test", sig, Base.decode16!("63CC7C25E0CDB121ABB0FE477A6B9901889F99A7")) iex> Signet.Recover.recover_eth("test", %{sig|recid: recid}) |> Base.encode16() "63CC7C25E0CDB121ABB0FE477A6B9901889F99A7"
Prefixes a message with "Etheruem Signed Message" prefix, as per EIP-191.
Examples
iex> Signet.Recover.prefix_eth("hello") "Ethereum Signed Message:\n5hello"
Recovers a signer's Ethereum address from a signed message. The message will be digested by keccak first. Note: the rec_id can be embeded in the signature or passed separately.
Examples
iex> priv_key = Base.decode16!("800509fa3e80882ad0be77c27505bdc91380f800d51ed80897d22f9fcc75f4bf", case: :mixed) iex> {:ok, sig} = Signet.Signer.Curvy.sign("test", priv_key) iex> {:ok, recid} = Signet.Recover.find_recid("test", sig, Base.decode16!("63CC7C25E0CDB121ABB0FE477A6B9901889F99A7")) iex> Signet.Recover.recover_eth("test", %{sig|recid: recid}) |> Base.encode16() "63CC7C25E0CDB121ABB0FE477A6B9901889F99A7"
Recovers a signer's public key from a signed message. The message will be digested by keccak first. Note: the rec_id can be embeded in the signature or passed separately.
Examples
iex> # Decoded Signature iex> priv_key = Base.decode16!("800509fa3e80882ad0be77c27505bdc91380f800d51ed80897d22f9fcc75f4bf", case: :mixed) iex> {:ok, sig} = Signet.Signer.Curvy.sign("test", priv_key) iex> {:ok, recid} = Signet.Recover.find_recid("test", sig, Base.decode16!("63CC7C25E0CDB121ABB0FE477A6B9901889F99A7")) iex> Signet.Recover.recover_public_key("test", %{sig|recid: recid}) |> Base.encode16() "0480076BFB96955526052B2676DFCA87E0B7869CE85E00C5DBCE29E76B8429D6DBF0F33B1A0095B2A9A4D9EA2A9746B122995A5B5874EE3161138C9D19F072B2D9"
iex> # Binary Signature iex> priv_key = Base.decode16!("800509fa3e80882ad0be77c27505bdc91380f800d51ed80897d22f9fcc75f4bf", case: :mixed) iex> {:ok, sig} = Signet.Signer.Curvy.sign("test", priv_key) iex> {:ok, recid} = Signet.Recover.find_recid("test", sig, Base.decode16!("63CC7C25E0CDB121ABB0FE477A6B9901889F99A7")) iex> signature = <<sig.r::256, sig.s::256, recid>> iex> Signet.Recover.recover_public_key("test", signature) |> Base.encode16() "0480076BFB96955526052B2676DFCA87E0B7869CE85E00C5DBCE29E76B8429D6DBF0F33B1A0095B2A9A4D9EA2A9746B122995A5B5874EE3161138C9D19F072B2D9"
iex> # EIP-155 Signature iex> priv_key = Base.decode16!("800509fa3e80882ad0be77c27505bdc91380f800d51ed80897d22f9fcc75f4bf", case: :mixed) iex> {:ok, sig} = Signet.Signer.Curvy.sign("test", priv_key) iex> {:ok, recid} = Signet.Recover.find_recid("test", sig, Base.decode16!("63CC7C25E0CDB121ABB0FE477A6B9901889F99A7")) iex> recovery_bit = 35 + 5 * 2 + recid iex> signature = <<sig.r::256, sig.s::256, recovery_bit::8>> iex> Signet.Recover.recover_public_key("test", signature) |> Base.encode16() "0480076BFB96955526052B2676DFCA87E0B7869CE85E00C5DBCE29E76B8429D6DBF0F33B1A0095B2A9A4D9EA2A9746B122995A5B5874EE3161138C9D19F072B2D9"