From a72455cc246b66b1d9bde9a8a68873439ce7242e Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 4 Oct 2024 14:04:51 -0700 Subject: [PATCH 1/3] add keypair getter to Keyfile --- src/keyfile.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/keyfile.rs b/src/keyfile.rs index 49b4cef..51b17db 100644 --- a/src/keyfile.rs +++ b/src/keyfile.rs @@ -522,12 +522,11 @@ impl Keyfile { self.__str__(py) } - // TODO (devs): rust creates the same function automatically by `keypair` getter function and the error accuses. We need to understand how to avoid this. /// Returns the keypair from path, decrypts data if the file is encrypted. - // #[getter] - // pub fn keypair(&self, py: Python) -> PyResult{ - // self.get_keypair(None, py) - // } + #[getter(keypair)] + pub fn keypair_py(&self, py: Python) -> PyResult{ + self.get_keypair(None, py) + } /// Returns the keypair from the path, decrypts data if the file is encrypted. #[pyo3(signature = (password = None))] From 4732a81616af7663189fc506eb9f42bb518d949e Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 4 Oct 2024 14:50:07 -0700 Subject: [PATCH 2/3] avoid double asking pass for unlocking --- src/keyfile.rs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/keyfile.rs b/src/keyfile.rs index 51b17db..d9031e6 100644 --- a/src/keyfile.rs +++ b/src/keyfile.rs @@ -184,16 +184,18 @@ pub fn validate_password(_py: Python, password: &str) -> PyResult { /// Returns: /// password (str): The valid password entered by the user. #[pyfunction] -pub fn ask_password(py: Python) -> PyResult { +pub fn ask_password(py: Python, validation_required: bool) -> PyResult { let mut valid = false; let password = utils::prompt_password("Enter your password: ".to_string()); - while !valid { - if let Some(ref password) = password { - valid = validate_password(py, &password)?; - } else { - valid = true + if validation_required { + while !valid { + if let Some(ref password) = password { + valid = validate_password(py, &password)?; + } else { + valid = true + } } } @@ -300,7 +302,7 @@ pub fn legacy_encrypt_keyfile_data( ) -> PyResult { let password = password.unwrap_or_else(|| // function to get password from user - ask_password(py).unwrap()); + ask_password(py, true).unwrap()); utils::print(":exclamation_mark: Encrypting key with legacy encryption method...".to_string()); @@ -342,7 +344,7 @@ fn derive_key(password: &[u8]) -> secretbox::Key { pwhash::argon2i13::OPSLIMIT_SENSITIVE, pwhash::argon2i13::MEMLIMIT_SENSITIVE, ) - .expect("Failed to derive key for NaCl decryption."); + .expect("Failed to derive key for NaCl decryption."); key } @@ -364,7 +366,7 @@ pub fn encrypt_keyfile_data( // get password or ask user let password = match password { Some(pwd) => pwd, - None => ask_password(py)?, + None => ask_password(py, true)?, }; utils::print("Encrypting...".to_string()); @@ -437,7 +439,7 @@ pub fn decrypt_keyfile_data( // If password is still None, ask the user for input if password.is_none() { - password = Some(ask_password(py)?); + password = Some(ask_password(py, false)?); } let password = password.unwrap(); @@ -693,7 +695,7 @@ impl Keyfile { "File {} already exists. Overwrite? (y/N) ", self.path )) - .expect("Failed to read input."); + .expect("Failed to read input."); choice.trim().to_lowercase() == "y" } @@ -759,7 +761,7 @@ impl Keyfile { let mut decrypted_keyfile_data: Option> = None; let mut password: Option = None; while decrypted_keyfile_data.is_none() { - let pwd = ask_password(py)?; + let pwd = ask_password(py, false)?; password = Some(pwd.clone()); match decrypt_keyfile_data( From 9ed545f58e251cd2b6be471e1bc35abeab2c473f Mon Sep 17 00:00:00 2001 From: ibraheem-opentensor <165814940+ibraheem-opentensor@users.noreply.github.com> Date: Fri, 4 Oct 2024 15:15:01 -0700 Subject: [PATCH 3/3] Bumps version & changelog (#44) --- CHANGELOG.MD | 8 ++++++++ pyproject.toml | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 781656c..793d915 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -1,5 +1,13 @@ # Changelog +## 2.0.1 /2024-10-04 + +## What's Changed +* add keypair getter to Keyfile by @roman-opentensor in https://github.com/opentensor/btwallet/pull/41 +* fix/roman/avoid-double-asking-password-in-unlocking by @roman-opentensor in https://github.com/opentensor/btwallet/pull/43 + +**Full Changelog**: https://github.com/opentensor/btwallet/compare/v2.0.0...v2.0.1 + ## 2.0.0 /2024-10-03 ## What's Changed diff --git a/pyproject.toml b/pyproject.toml index 8fea4cc..e043022 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "bittensor-wallet" -version = "2.0.0" +version = "2.0.1" description = "" readme = "README.md" license = {file = "LICENSE"}