Skip to content

Release/2.0.1 #42

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

Merged
merged 5 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "bittensor-wallet"
version = "2.0.0"
version = "2.0.1"
description = ""
readme = "README.md"
license = {file = "LICENSE"}
Expand Down
35 changes: 18 additions & 17 deletions src/keyfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,18 @@ pub fn validate_password(_py: Python, password: &str) -> PyResult<bool> {
/// Returns:
/// password (str): The valid password entered by the user.
#[pyfunction]
pub fn ask_password(py: Python) -> PyResult<String> {
pub fn ask_password(py: Python, validation_required: bool) -> PyResult<String> {

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
}
}
}

Expand Down Expand Up @@ -300,7 +302,7 @@ pub fn legacy_encrypt_keyfile_data(
) -> PyResult<PyObject> {
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());

Expand Down Expand Up @@ -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
}

Expand All @@ -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());
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -522,12 +524,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<bool>{
// self.get_keypair(None, py)
// }
#[getter(keypair)]
pub fn keypair_py(&self, py: Python) -> PyResult<Keypair>{
self.get_keypair(None, py)
}

/// Returns the keypair from the path, decrypts data if the file is encrypted.
#[pyo3(signature = (password = None))]
Expand Down Expand Up @@ -694,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"
}
Expand Down Expand Up @@ -760,7 +761,7 @@ impl Keyfile {
let mut decrypted_keyfile_data: Option<Vec<u8>> = None;
let mut password: Option<String> = 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(
Expand Down
Loading