-
Notifications
You must be signed in to change notification settings - Fork 967
chore: integrate rust-secp256k1 #1915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
2324c9c
265b3bd
6027fc3
5f3311b
ec268ac
c95c51a
9afbfbd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,20 +45,23 @@ mod secp256k1 { | |
| #[allow(clippy::module_inception)] | ||
| mod secp256k1 { | ||
| use primitives::{alloy_primitives::B512, keccak256, B256}; | ||
| use secp256k1::{ | ||
| use rust_secp256k1::{ | ||
| ecdsa::{RecoverableSignature, RecoveryId}, | ||
| Message, SECP256K1, | ||
| Message, Secp256k1, | ||
| }; | ||
|
|
||
| // Silence the unused crate dependency warning. | ||
| use k256 as _; | ||
| use secp256k1 as _; | ||
|
|
||
| pub fn ecrecover(sig: &B512, recid: u8, msg: &B256) -> Result<B256, rust_secp256k1::Error> { | ||
| let engine = Secp256k1::new(); | ||
|
||
|
|
||
| pub fn ecrecover(sig: &B512, recid: u8, msg: &B256) -> Result<B256, secp256k1::Error> { | ||
| let recid = RecoveryId::from_i32(recid as i32).expect("recovery ID is valid"); | ||
| let sig = RecoverableSignature::from_compact(sig.as_slice(), recid)?; | ||
|
|
||
| let msg = Message::from_digest(msg.0); | ||
| let public = SECP256K1.recover_ecdsa(&msg, &sig)?; | ||
| let msg = Message::from_slice(msg.as_ref())?; | ||
| let public = engine.recover_ecdsa(&msg, &sig)?; | ||
|
|
||
| let mut hash = keccak256(&public.serialize_uncompressed()[1..]); | ||
| hash[..12].fill(0); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @stevencartavia, the idea is not to replace it but to add a new option with a feature flag for
rust_secp256k1.I would see to try
cfg_if(there are a few examples of its usage in the repo)