diff --git a/crates/rooch-key/src/key_derive.rs b/crates/rooch-key/src/key_derive.rs index 398eb9f90c..55da662580 100644 --- a/crates/rooch-key/src/key_derive.rs +++ b/crates/rooch-key/src/key_derive.rs @@ -203,7 +203,12 @@ fn validate_derivation_path(path: Option) -> Result Result<(), anyhow::Error>; - // fn update_address_encryption_data( - // &mut self, - // address: &RoochAddress, - // encryption: EncryptionData, - // ) -> Result<(), anyhow::Error>; fn nullify(&mut self, address: &RoochAddress) -> Result<(), anyhow::Error>; fn sign_hashed( @@ -132,53 +127,6 @@ pub trait AccountKeystore { fn addresses(&self) -> Vec; - // fn import_from_mnemonic( - // &mut self, - // phrase: &str, - // derivation_path: Option, - // password: Option, - // ) -> Result { - // let mnemonic = Mnemonic::from_phrase(phrase, Language::English)?; - // let seed = Seed::new(&mnemonic, ""); - - // let sk = derive_private_key_from_path(seed.as_bytes(), derivation_path)?; - - // let encryption = encrypt_key(&sk, password).expect("Encryption failed for private key"); - - // let address = derive_address_from_private_key(sk)?; - - // let result = ImportedMnemonic { - // address, - // encryption: encryption.clone(), - // }; - - // self.add_address_encryption_data(result.address, encryption)?; - - // Ok(result) - // } - - // fn update_address_with_encryption_data( - // &mut self, - // _address: &RoochAddress, - // phrase: String, - // derivation_path: Option, - // password: Option, - // ) -> Result { - // let mnemonic = Mnemonic::from_phrase(&phrase, Language::English)?; - // let seed = Seed::new(&mnemonic, ""); - - // let sk = derive_private_key_from_path(seed.as_bytes(), derivation_path)?; - - // let encryption_data = - // encrypt_key(&sk, password).expect("Encryption failed for private key"); - - // let address = derive_address_from_private_key(sk)?; - - // self.update_address_encryption_data(&address, encryption_data.clone())?; - - // Ok(encryption_data) - // } - fn nullify_address(&mut self, address: &RoochAddress) -> Result<(), anyhow::Error> { self.nullify(address)?; Ok(()) diff --git a/crates/rooch-key/src/keystore/base_keystore.rs b/crates/rooch-key/src/keystore/base_keystore.rs index 24c6a8e85f..6f9358ef30 100644 --- a/crates/rooch-key/src/keystore/base_keystore.rs +++ b/crates/rooch-key/src/keystore/base_keystore.rs @@ -174,15 +174,6 @@ impl AccountKeystore for BaseKeyStore { Ok(()) } - // fn update_address_encryption_data( - // &mut self, - // address: &RoochAddress, - // encryption: EncryptionData, - // ) -> Result<(), anyhow::Error> { - // self.keys.entry(*address).or_insert(encryption); - // Ok(()) - // } - fn nullify(&mut self, address: &RoochAddress) -> Result<(), anyhow::Error> { self.keys.remove(address); Ok(()) @@ -193,10 +184,7 @@ impl AccountKeystore for BaseKeyStore { address: &RoochAddress, password: Option, ) -> Result { - //TODO define derivation_path for session key - let result = generate_new_key_pair(None, None, None, password.clone())?; - let kp: RoochKeyPair = - retrieve_key_pair(&result.key_pair_data.private_key_encryption, password)?; + let kp: RoochKeyPair = RoochKeyPair::generate(); let authentication_key = kp.public().authentication_key(); let inner_map = self.session_keys.entry(*address).or_default(); let local_session_key = LocalSessionKey { @@ -243,15 +231,7 @@ impl AccountKeystore for BaseKeyStore { "Cannot find SessionKey for authentication_key: [{authentication_key}]" )) })?; - //TODO should we check the scope of session key here? - // let session_key = local_session_key.session_key.as_ref().ok_or_else(||{ - // signature::Error::from_source( - // format!("SessionKey for authentication_key:[{authentication_key}] do not binding to on-chain SessionKey") - // ) - // })?; - // ensure!(session_key.is_scope_match_with_action(&msg.action), signature::Error::from_source( - // format!("SessionKey for authentication_key:[{authentication_key}] scope do not match with transaction") - // )); + let kp: RoochKeyPair = retrieve_key_pair(&local_session_key.private_key, password) .map_err(signature::Error::from_source)?; @@ -329,47 +309,5 @@ impl AccountKeystore for BaseKeyStore { "Cannot find mnemonic data, please init the keystore first".to_string(), ))), } - // match self.mnemonic.first_key_value() { - // Some((k, v)) => { - // let nonce = Base64::decode(&v.mnemonic_phrase_encryption.nonce).map_err(|e| { - // anyhow::Error::new(RoochError::KeyConversionError(e.to_string())) - // })?; - // let ciphertext = - // Base64::decode(&v.mnemonic_phrase_encryption.ciphertext).map_err(|e| { - // anyhow::Error::new(RoochError::KeyConversionError(e.to_string())) - // })?; - // let tag = Base64::decode(&v.mnemonic_phrase_encryption.tag).map_err(|e| { - // anyhow::Error::new(RoochError::KeyConversionError(e.to_string())) - // })?; - - // let mnemonic_phrase = decrypt_key( - // nonce.as_slice(), - // ciphertext.as_slice(), - // tag.as_slice(), - // password, - // )?; - - // let mnemonic_phrase = String::from_utf8(mnemonic_phrase) - // .map_err(|e| anyhow::anyhow!("Parse mnemonic phrase error:{}", e))?; - // let mnemonic_generated_address = MnemonicResult { - // mnemonic_phrase, - // mnemonic_phrase_key: k.clone(), - // mnemonic_data: v.clone(), - // }; - // Ok(vec![mnemonic_generated_address]) - // } - // None => Ok(vec![]), - // } } - - // fn add_mnemonic_data( - // &mut self, - // mnemonic_phrase: String, - // mnemonic_data: MnemonicData, - // ) -> Result<(), anyhow::Error> { - // self.mnemonics - // .entry(mnemonic_phrase) - // .or_insert(mnemonic_data); - // Ok(()) - // } } diff --git a/crates/rooch-key/src/keystore/file_keystore.rs b/crates/rooch-key/src/keystore/file_keystore.rs index bec963b340..53f12bd40b 100644 --- a/crates/rooch-key/src/keystore/file_keystore.rs +++ b/crates/rooch-key/src/keystore/file_keystore.rs @@ -57,17 +57,6 @@ impl AccountKeystore for FileBasedKeystore { self.keystore.get_key_pair_with_password(address, password) } - // fn update_address_encryption_data( - // &mut self, - // address: &RoochAddress, - // encryption: EncryptionData, - // ) -> Result<(), anyhow::Error> { - // self.keystore - // .update_address_encryption_data(address, encryption)?; - // self.save()?; - // Ok(()) - // } - fn nullify(&mut self, address: &RoochAddress) -> Result<(), anyhow::Error> { self.keystore.nullify(address)?; self.save()?; @@ -173,28 +162,6 @@ impl AccountKeystore for FileBasedKeystore { fn get_mnemonic(&self, password: Option) -> Result { self.keystore.get_mnemonic(password) } - - // fn add_mnemonic_data( - // &mut self, - // mnemonic_phrase: String, - // mnemonic_data: MnemonicData, - // ) -> Result<(), anyhow::Error> { - // self.keystore - // .add_mnemonic_data(mnemonic_phrase, mnemonic_data)?; - // self.save()?; - // Ok(()) - // } - - // fn update_mnemonic_data( - // &mut self, - // mnemonic_phrase: String, - // mnemonic_data: MnemonicData, - // ) -> Result<(), anyhow::Error> { - // self.keystore - // .update_mnemonic_data(mnemonic_phrase, mnemonic_data)?; - // self.save()?; - // Ok(()) - // } } impl FileBasedKeystore { diff --git a/crates/rooch-key/src/keystore/mod.rs b/crates/rooch-key/src/keystore/mod.rs index 0051f5bc9a..03d8f5df5e 100644 --- a/crates/rooch-key/src/keystore/mod.rs +++ b/crates/rooch-key/src/keystore/mod.rs @@ -125,22 +125,6 @@ impl AccountKeystore for Keystore { } } - // fn update_address_encryption_data( - // &mut self, - // address: &RoochAddress, - // encryption: EncryptionData, - // ) -> Result<(), anyhow::Error> { - // // Implement this method to update the key pair by coin ID for the appropriate variant (File or InMem) - // match self { - // Keystore::File(file_keystore) => { - // file_keystore.update_address_encryption_data(address, encryption) - // } - // Keystore::InMem(inmem_keystore) => { - // inmem_keystore.update_address_encryption_data(address, encryption) - // } - // } - // } - fn nullify(&mut self, address: &RoochAddress) -> Result<(), anyhow::Error> { // Implement this method to nullify the key pair by coin ID for the appropriate variant (File or InMem) match self { @@ -264,21 +248,6 @@ impl AccountKeystore for Keystore { Keystore::InMem(inmem_keystore) => inmem_keystore.get_mnemonic(password), } } - - // fn add_mnemonic_data( - // &mut self, - // mnemonic_phrase: String, - // mnemonic_data: MnemonicData, - // ) -> Result<(), anyhow::Error> { - // match self { - // Keystore::File(file_keystore) => { - // file_keystore.add_mnemonic_data(mnemonic_phrase, mnemonic_data) - // } - // Keystore::InMem(inmem_keystore) => { - // inmem_keystore.add_mnemonic_data(mnemonic_phrase, mnemonic_data) - // } - // } - // } } impl Display for Keystore { diff --git a/crates/rooch-types/src/crypto.rs b/crates/rooch-types/src/crypto.rs index 7347cd94ab..73656802dc 100644 --- a/crates/rooch-types/src/crypto.rs +++ b/crates/rooch-types/src/crypto.rs @@ -75,8 +75,7 @@ impl RoochKeyPair { } } - // #[cfg(test)] - pub fn generate_for_testing() -> Self { + pub fn generate() -> Self { let rng = &mut rand::thread_rng(); let ed25519_keypair = Ed25519KeyPair::generate(rng); RoochKeyPair::Ed25519(ed25519_keypair) diff --git a/crates/testsuite/tests/integration.rs b/crates/testsuite/tests/integration.rs index 4adcc137ed..da080a1a9b 100644 --- a/crates/testsuite/tests/integration.rs +++ b/crates/testsuite/tests/integration.rs @@ -86,9 +86,7 @@ async fn start_server(w: &mut World, _scenario: String) { let mut server_opt = ServerOpt::new(); - let result = generate_new_key_pair(None, None, None, None).unwrap(); - let kp: RoochKeyPair = - retrieve_key_pair(&result.key_pair_data.private_key_encryption, None).unwrap(); + let kp: RoochKeyPair = RoochKeyPair::generate(); server_opt.sequencer_keypair = Some(kp.copy()); server_opt.proposer_keypair = Some(kp.copy());