-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add keyfile to secretkey conversion. * Add usage example. * Example in readme as well. * Re-export KeyFile.
- Loading branch information
Showing
3 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,29 @@ | ||
# ethsign | ||
|
||
A library to read JSON keyfiles and sign Ethereum stuff. | ||
|
||
## Usage: | ||
```rust | ||
use ethsign::{Protected, KeyFile}; | ||
|
||
fn main() { | ||
let file = std::fs::File::open("./res/wallet.json").unwrap(); | ||
let key: KeyFile = serde_json::from_reader(file).unwrap(); | ||
let password: Protected = "".into(); | ||
let secret = key.to_secret_key(&password).unwrap(); | ||
let message = [1_u8; 32]; | ||
|
||
// Sign the message | ||
let signature = secret.sign(&message).unwrap(); | ||
println!("{:?}", signature); | ||
|
||
// Recover the signer | ||
let public = signature.recover(&message).unwrap(); | ||
println!("{:?}", public); | ||
|
||
// Verify the signature | ||
let res = public.verify(&signature, &message).unwrap(); | ||
println!("{}", if res { "signature correct" } else { "invalid signature" }); | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters