-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR integrates https://github.com/Layr-Labs/rust-bls-bn254 - [x] [Keystore] - [x] [Mnemonic] --------- Co-authored-by: ricomateo <mrico@fi.uba.ar> Co-authored-by: tomasarrachea <tomas.arrachea@lambdaclass.com> Co-authored-by: Pablo Deymonnaz <deymonnaz@gmail.com> Co-authored-by: Mateo Rico <ricomateo@users.noreply.github.com> Co-authored-by: Pablo Deymonnaz <pdeymon@fi.uba.ar> Co-authored-by: supernovahs <supernovahs@proton.me>
- Loading branch information
1 parent
ed99b9b
commit 5d9a2cc
Showing
8 changed files
with
286 additions
and
25 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.
Submodule middleware
updated
54 files
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
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,60 @@ | ||
use crate::args::BlsKeystoreType; | ||
use crate::EigenBlsKeyStoreError; | ||
use rust_bls_bn254::keystores::{pbkdf2_keystore::Pbkdf2Keystore, scrypt_keystore::ScryptKeystore}; | ||
|
||
/// BlsKeystore | ||
pub enum BlsKeystore { | ||
Pbkdf2, | ||
Scrypt, | ||
} | ||
|
||
impl BlsKeystore { | ||
/// Create a new [`BlsKeystore`] instance. | ||
/// [`BlsKeystore::Pbkdft`] or [`BlsKeystore::Scrypt`] | ||
pub fn new_keystore( | ||
self, | ||
secret_key: String, | ||
output_path: String, | ||
password: Option<&str>, | ||
) -> Result<(), EigenBlsKeyStoreError> { | ||
match self { | ||
BlsKeystore::Pbkdf2 => { | ||
let key_hex = hex::decode(secret_key)?; | ||
let bls_key = key_hex.as_slice(); | ||
let mut keystore = Pbkdf2Keystore::new(); | ||
keystore.encrypt( | ||
bls_key, | ||
password.unwrap_or_default(), | ||
&output_path.to_string(), | ||
None, | ||
None, | ||
)?; | ||
keystore.to_keystore().save(&output_path.to_string())?; | ||
Ok(()) | ||
} | ||
BlsKeystore::Scrypt => { | ||
let key_hex = hex::decode(secret_key)?; | ||
let bls_key = key_hex.as_slice(); | ||
let mut keystore = ScryptKeystore::new(); | ||
keystore.encrypt( | ||
bls_key, | ||
password.unwrap_or_default(), | ||
&output_path.to_string(), | ||
None, | ||
None, | ||
)?; | ||
keystore.to_keystore().save(&output_path.to_string())?; | ||
Ok(()) | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl From<BlsKeystoreType> for BlsKeystore { | ||
fn from(value: BlsKeystoreType) -> Self { | ||
match value { | ||
BlsKeystoreType::Pbkdf2 => BlsKeystore::Pbkdf2, | ||
BlsKeystoreType::Scrypt => BlsKeystore::Scrypt, | ||
} | ||
} | ||
} |
Oops, something went wrong.