Cleanup after merge of PR
This commit is contained in:
parent
3c6b1fae4c
commit
9347bee344
17
README.md
17
README.md
@ -2,18 +2,25 @@
|
|||||||
FFI (NIF) export of Ethereum's ecrecover for use from Erlang.
|
FFI (NIF) export of Ethereum's ecrecover for use from Erlang.
|
||||||
|
|
||||||
### prerequisite:
|
### prerequisite:
|
||||||
- a checked out copy of my fork of parity-ethereum (https://github.com/johnsnewby/parity-ethereum) checked out in the same directory this is (i.e. it will be referenced as `../parity-ethereum`)
|
- a checked out copy of my fork of parity-ethereum (https://github.com/johnsnewby/parity-ethereum) checked out into this directory this is (i.e. it will be referenced as `./parity-ethereum`)
|
||||||
|
|
||||||
### to compile:
|
### to compile:
|
||||||
`cargo build`
|
`cargo build`
|
||||||
|
|
||||||
## Erlang integration
|
## Erlang integration
|
||||||
|
|
||||||
The shared library uses NIF. Use the erlang file `sec/nifecrecover.erl` to use this:
|
The shared library uses NIF. Use the erlang file `src/ecrecover.erl` to use this:
|
||||||
|
|
||||||
```
|
```
|
||||||
c("src/ecrecover").
|
c("src/ecrecover").
|
||||||
Decoded = ecrecover:hexstr_to_bin("47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad000000000000000000000000000000000000000000000000000000000000001b650acf9d3f5f0a2c799776a1254355d5f4061762a237396a99a0e0e3fc2bcd6729514a0dacb2e623ac4abd157cb18163ff942280db4d5caad66ddf941ba12e03").
|
c("src/ecrecover_util").
|
||||||
ecrecover:ecrecover(Decoded).
|
Decoded = ecrecover_util:hex_to_bin("47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad000000000000000000000000000000000000000000000000000000000000001b650acf9d3f5f0a2c799776a1254355d5f4061762a237396a99a0e0e3fc2bcd6729514a0dacb2e623ac4abd157cb18163ff942280db4d5caad66ddf941ba12e03").
|
||||||
ecrecover:time_taken_to_execute(fun() -> ecrecover:ecrecover(Decoded) end).
|
List = binary:bin_to_list(Decoded).
|
||||||
|
Hash = binary:list_to_bin(lists:sublist(List, 1, 32)).
|
||||||
|
Sig = binary:list_to_bin(lists:sublist(List, 64, 65)).
|
||||||
|
Input = <<Hash/binary, 0:(8*31), Sig/binary>>.
|
||||||
|
binary:bin_to_list(Input) == binary:bin_to_list(Decoded).
|
||||||
|
Result = ecrecover:recover(Hash, Sig).
|
||||||
|
Expected = ecrecover_util:hex_to_bin("000000000000000000000000c08b5542d177ac6686946920409741463a15dddb").
|
||||||
|
binary:bin_to_list(Result) == binary:bin_to_list(Expected). %% check result
|
||||||
```
|
```
|
||||||
|
11
src/lib.rs
11
src/lib.rs
@ -7,8 +7,8 @@ extern crate parity_bytes;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate rustler;
|
extern crate rustler;
|
||||||
|
|
||||||
use ethcore_builtin::EcRecover;
|
|
||||||
use crate::ethcore_builtin::Implementation;
|
use crate::ethcore_builtin::Implementation;
|
||||||
|
use ethcore_builtin::EcRecover;
|
||||||
use parity_bytes::BytesRef;
|
use parity_bytes::BytesRef;
|
||||||
use rustler::*;
|
use rustler::*;
|
||||||
|
|
||||||
@ -20,13 +20,10 @@ mod atoms {
|
|||||||
|
|
||||||
rustler_export_nifs!(
|
rustler_export_nifs!(
|
||||||
"ecrecover",
|
"ecrecover",
|
||||||
[
|
[("recover_", 1, nif_ecrecover),],
|
||||||
("ecrecover", 1, nif_ecrecover),
|
|
||||||
],
|
|
||||||
Some(on_load)
|
Some(on_load)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
fn on_load(_env: Env, _load_info: Term) -> bool {
|
fn on_load(_env: Env, _load_info: Term) -> bool {
|
||||||
true
|
true
|
||||||
@ -36,8 +33,8 @@ pub fn nif_ecrecover<'a>(env: Env<'a>, args: &[Term<'a>]) -> Result<Term<'a>, Er
|
|||||||
let input: Binary = args[0].decode()?;
|
let input: Binary = args[0].decode()?;
|
||||||
let mut byte_ref = Vec::new();
|
let mut byte_ref = Vec::new();
|
||||||
let ecrecover = EcRecover {};
|
let ecrecover = EcRecover {};
|
||||||
let _result = match ecrecover.execute(input.as_slice(),
|
let _result = match ecrecover.execute(input.as_slice(), &mut BytesRef::Flexible(&mut byte_ref))
|
||||||
&mut BytesRef::Fixed(&mut byte_ref)) {
|
{
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(_e) => return Err(rustler::Error::Atom("ecrecover_failed")),
|
Err(_e) => return Err(rustler::Error::Atom("ecrecover_failed")),
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user