Updated README
This commit is contained in:
parent
53b4d36a29
commit
2946ac84f8
17
README.md
17
README.md
@ -1,25 +1,14 @@
|
||||
# ecrecover
|
||||
FFI (NIF) export of Ethereum's ecrecover for use from Erlang.
|
||||
FFI (NIF) export of Ethereum's ecrecover for use from Erlang based on
|
||||
https://github.com/bitcoin-core/secp256k1.git
|
||||
|
||||
### Prerequisites
|
||||
The NIF is written in Rust, therefore the following additional build
|
||||
dependencies are needed:
|
||||
|
||||
- Rust
|
||||
- Cargo
|
||||
- Cmake
|
||||
|
||||
### Build
|
||||
Execute:
|
||||
```
|
||||
make
|
||||
./rebar3 compile
|
||||
```
|
||||
|
||||
To disable the local build of the NIF library, e.g. to use a prebuilt binary,
|
||||
use the following command:
|
||||
```
|
||||
ECRECOVER_DISABLE_NIF_BUILD=true make
|
||||
```
|
||||
|
||||
## Erlang integration
|
||||
|
||||
|
13
rebar.lock
13
rebar.lock
@ -1 +1,12 @@
|
||||
[].
|
||||
{"1.2.0",
|
||||
[{<<"hex2bin">>,{pkg,<<"hex2bin">>,<<"1.0.0">>},1},
|
||||
{<<"sha3">>,
|
||||
{git,"https://github.com/aeternity/erlang-sha3",
|
||||
{ref,"b5f27a29ba1179e5907c50d7ec7aa79b2857e981"}},
|
||||
0}]}.
|
||||
[
|
||||
{pkg_hash,[
|
||||
{<<"hex2bin">>, <<"AAC26EAB998AE80EACEE1C7607C629AB503EBF77A62B9242BAE2B94D47DCB71E">>}]},
|
||||
{pkg_hash_ext,[
|
||||
{<<"hex2bin">>, <<"E7012D1D9AADD26E680F0983D26FB8923707F05FAC9688F19F530FA3795E716F">>}]}
|
||||
].
|
||||
|
28
src/ecrecover_util.erl
Normal file
28
src/ecrecover_util.erl
Normal file
@ -0,0 +1,28 @@
|
||||
-module(ecrecover_util).
|
||||
|
||||
-export([ recover_from_hex/1
|
||||
, bin_to_hex/1
|
||||
, hex_to_bin/1
|
||||
]).
|
||||
|
||||
%%=============================================================================
|
||||
%% External API
|
||||
|
||||
recover_from_hex(Input) ->
|
||||
<<Hash:32/binary, _:31/binary, Sig:65/binary>> = hex_to_bin(Input),
|
||||
PubKey = ecrecover:recover(Hash, Sig),
|
||||
bin_to_hex(PubKey).
|
||||
|
||||
bin_to_hex(Bin) ->
|
||||
lists:flatten([io_lib:format("~2.16.0B", [X]) || X <- binary_to_list(Bin)]).
|
||||
|
||||
hex_to_bin(S) ->
|
||||
hex_to_bin(S, []).
|
||||
hex_to_bin([], Acc) ->
|
||||
list_to_binary(lists:reverse(Acc));
|
||||
hex_to_bin([X,Y|T], Acc) ->
|
||||
{ok, [V], []} = io_lib:fread("~16u", [X,Y]),
|
||||
hex_to_bin(T, [V | Acc]);
|
||||
hex_to_bin([X|T], Acc) ->
|
||||
{ok, [V], []} = io_lib:fread("~16u", lists:flatten([X,"0"])),
|
||||
hex_to_bin(T, [V | Acc]).
|
Loading…
x
Reference in New Issue
Block a user