diff --git a/lib/eth/transaction.ex b/lib/eth/transaction.ex index 1ba88fc..a2e888e 100644 --- a/lib/eth/transaction.ex +++ b/lib/eth/transaction.ex @@ -177,12 +177,9 @@ defmodule ETH.Transaction do chain_id = get_chain_id(v, Enum.at(transaction_list, 9)) v_int = buffer_to_int(v) target_v = if chain_id > 0, do: v_int - (chain_id * 2 + 8), else: v_int - - signature = r <> s recovery_id = target_v - 27 - {:ok, public_key} = - :libsecp256k1.ecdsa_recover_compact(message_hash, signature, :uncompressed, recovery_id) + {:ok, public_key} = ExSecp256k1.recover_compact(message_hash, r <> s, recovery_id) public_key end diff --git a/lib/eth/utils.ex b/lib/eth/utils.ex index 4f7fb1f..e639db9 100644 --- a/lib/eth/utils.ex +++ b/lib/eth/utils.ex @@ -2,13 +2,13 @@ defmodule ETH.Utils do def get_private_key, do: :crypto.strong_rand_bytes(32) def get_public_key(<>) do - {:ok, public_key} = :libsecp256k1.ec_pubkey_create(private_key, :uncompressed) + {:ok, public_key} = ExSecp256k1.create_public_key(private_key) public_key end def get_public_key(<>) do private_key = Base.decode16!(encoded_private_key, case: :mixed) - {:ok, public_key} = :libsecp256k1.ec_pubkey_create(private_key, :uncompressed) + {:ok, public_key} = ExSecp256k1.create_public_key(private_key) public_key end @@ -59,8 +59,7 @@ defmodule ETH.Utils do end def secp256k1_signature(hash, private_key) do - {:ok, signature, recovery} = - :libsecp256k1.ecdsa_sign_compact(hash, private_key, :default, <<>>) + {:ok, {signature, recovery}} = ExSecp256k1.sign_compact(hash, private_key) [signature: signature, recovery: recovery] end diff --git a/mix.exs b/mix.exs index 013b0cb..3f536b0 100644 --- a/mix.exs +++ b/mix.exs @@ -20,7 +20,7 @@ defmodule Eth.Mixfile do # Run "mix help compile.app" to learn about applications. def application() do [ - extra_applications: [:logger, :telemetry, :ethereumex, :libsecp256k1] + extra_applications: [:logger, :telemetry, :ethereumex] ] end @@ -35,7 +35,7 @@ defmodule Eth.Mixfile do {:ex_keccak, "~> 0.1.2"}, {:mnemonic, "~> 0.2.2"}, {:poison, "~> 4.0.1"}, - {:libsecp256k1, "~> 0.1.10"}, + {:ex_secp256k1, "~> 0.1.2"}, {:telemetry, "~> 0.4.2"} ] end diff --git a/mix.lock b/mix.lock index 5d5c631..2073699 100644 --- a/mix.lock +++ b/mix.lock @@ -8,6 +8,7 @@ "ex_doc": {:hex, :ex_doc, "0.23.0", "a069bc9b0bf8efe323ecde8c0d62afc13d308b1fa3d228b65bca5cf8703a529d", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "f5e2c4702468b2fd11b10d39416ddadd2fcdd173ba2a0285ebd92c39827a5a16"}, "ex_keccak": {:hex, :ex_keccak, "0.1.2", "4548914dc250a919712f03b4574fd2d048cd6d1245481b559abe9e7b9adafbd3", [:mix], [{:rustler, "~> 0.21.1", [hex: :rustler, repo: "hexpm", optional: false]}], "hexpm", "da2a11b1f95727193865f9184b6af9e1665e82b84f3c531ab4b7323532dafebd"}, "ex_rlp": {:hex, :ex_rlp, "0.5.3", "9055bddade545ee3e734aaad62c4b4d08211834da3beb43ae269b75785909e5e", [:mix], [], "hexpm", "a755a5f8f9f66079f3ecbe021536b949077fac0df963d9e59a20321bab28722d"}, + "ex_secp256k1": {:hex, :ex_secp256k1, "0.1.2", "affe4e0fa1adc085ab47d7ab3cc44d594249d24bd0a37a9002f6648d112c2081", [:mix], [{:rustler, "~> 0.21.1 ", [hex: :rustler, repo: "hexpm", optional: false]}], "hexpm", "8ae0131380ada331b15924b563f89e7f56b4e74cc10978f3ea0836589e87730a"}, "hackney": {:hex, :hackney, "1.15.2", "07e33c794f8f8964ee86cebec1a8ed88db5070e52e904b8f12209773c1036085", [:rebar3], [{:certifi, "2.5.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.5", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm", "e0100f8ef7d1124222c11ad362c857d3df7cb5f4204054f9f0f4a728666591fc"}, "hexate": {:hex, :hexate, "0.6.1", "1cea42e462c1daa32223127d4752e71016c3d933d492b9bb7fa4709a4a0fd50d", [:mix], [], "hexpm", "667c429c0970e3097107c9fafcc645636302888388845d78a3947a739fd946b7"}, "httpoison": {:hex, :httpoison, "1.6.2", "ace7c8d3a361cebccbed19c283c349b3d26991eff73a1eaaa8abae2e3c8089b6", [:mix], [{:hackney, "~> 1.15 and >= 1.15.2", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "aa2c74bd271af34239a3948779612f87df2422c2fdcfdbcec28d9c105f0773fe"},