forked from bluealloy/revm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(revme): add recovery of address from secret key (bluealloy#992)
* feat(revme): make it usable by goevmlab * print outcome of test, propagate json flag * chore(revme): add recovery of address from secret key
- Loading branch information
Showing
5 changed files
with
36 additions
and
39 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
pub mod merkle_trie; | ||
pub mod models; | ||
mod runner; | ||
pub mod utils; | ||
|
||
pub use runner::TestError as Error; | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use k256::ecdsa::SigningKey; | ||
use revm::primitives::Address; | ||
|
||
/// Recover the address from a private key (SigningKey). | ||
pub fn recover_address(private_key: &[u8]) -> Option<Address> { | ||
let key = SigningKey::from_slice(private_key).ok()?; | ||
let public_key = key.verifying_key().to_encoded_point(false); | ||
Some(Address::from_raw_public_key(&public_key.as_bytes()[1..])) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use revm::primitives::{address, hex}; | ||
|
||
#[test] | ||
fn sanity_test() { | ||
assert_eq!( | ||
Some(address!("a94f5374fce5edbc8e2a8697c15331677e6ebf0b")), | ||
recover_address(&hex!( | ||
"45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8" | ||
)) | ||
) | ||
} | ||
} |