Skip to content

Update to tiny-bip39 2.0.0 #2643

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
11 changes: 5 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/atuin-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ reqwest = { workspace = true, optional = true }
hex = { version = "0.4", optional = true }
sha2 = { version = "0.10", optional = true }
indicatif = "0.17.7"
tiny-bip39 = "=1.0.0"
tiny-bip39 = "2.0.0"

# theme
crossterm = { version = "0.28.1", features = ["serde"] }
Expand Down
26 changes: 9 additions & 17 deletions crates/atuin-client/src/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,16 @@ pub async fn login(
let key = match bip39::Mnemonic::from_phrase(&key, bip39::Language::English) {
Ok(mnemonic) => encode_key(Key::from_slice(mnemonic.entropy()))?,
Err(err) => {
match err.downcast_ref::<bip39::ErrorKind>() {
Some(err) => {
match err {
// assume they copied in the base64 key
bip39::ErrorKind::InvalidWord => key,
bip39::ErrorKind::InvalidChecksum => {
bail!("key mnemonic was not valid")
}
bip39::ErrorKind::InvalidKeysize(_)
| bip39::ErrorKind::InvalidWordLength(_)
| bip39::ErrorKind::InvalidEntropyLength(_, _) => {
bail!("key was not the correct length")
}
}
match err {
// assume they copied in the base64 key
bip39::ErrorKind::InvalidWord(_) => key,
bip39::ErrorKind::InvalidChecksum => {
bail!("key mnemonic was not valid")
}
_ => {
// unknown error. assume they copied the base64 key
key
bip39::ErrorKind::InvalidKeysize(_)
| bip39::ErrorKind::InvalidWordLength(_)
| bip39::ErrorKind::InvalidEntropyLength(_, _) => {
bail!("key was not the correct length")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/atuin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ rpassword = "7.0"
semver = { workspace = true }
rustix = { workspace = true }
runtime-format = "0.1.3"
tiny-bip39 = "1"
tiny-bip39 = "2"
futures-util = "0.3"
fuzzy-matcher = "0.3.7"
colored = "2.0.4"
Expand Down
26 changes: 9 additions & 17 deletions crates/atuin/src/command/client/account/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,16 @@ impl Cmd {
match bip39::Mnemonic::from_phrase(&key, bip39::Language::English) {
Ok(mnemonic) => encode_key(Key::from_slice(mnemonic.entropy()))?,
Err(err) => {
match err.downcast_ref::<bip39::ErrorKind>() {
Some(err) => {
match err {
// assume they copied in the base64 key
bip39::ErrorKind::InvalidWord => key,
bip39::ErrorKind::InvalidChecksum => {
bail!("key mnemonic was not valid")
}
bip39::ErrorKind::InvalidKeysize(_)
| bip39::ErrorKind::InvalidWordLength(_)
| bip39::ErrorKind::InvalidEntropyLength(_, _) => {
bail!("key was not the correct length")
}
}
match err {
// assume they copied in the base64 key
bip39::ErrorKind::InvalidWord(_) => key,
bip39::ErrorKind::InvalidChecksum => {
bail!("key mnemonic was not valid")
}
_ => {
// unknown error. assume they copied the base64 key
key
bip39::ErrorKind::InvalidKeysize(_)
| bip39::ErrorKind::InvalidWordLength(_)
| bip39::ErrorKind::InvalidEntropyLength(_, _) => {
bail!("key was not the correct length")
}
}
}
Expand Down
32 changes: 11 additions & 21 deletions crates/atuin/src/command/client/store/rekey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,23 @@ impl Rekey {
let key = if let Some(key) = self.key.clone() {
println!("Re-encrypting store with specified key");

let key = match bip39::Mnemonic::from_phrase(&key, bip39::Language::English) {
match bip39::Mnemonic::from_phrase(&key, bip39::Language::English) {
Ok(mnemonic) => encode_key(Key::from_slice(mnemonic.entropy()))?,
Err(err) => {
match err.downcast_ref::<bip39::ErrorKind>() {
Some(err) => {
match err {
// assume they copied in the base64 key
bip39::ErrorKind::InvalidWord => key,
bip39::ErrorKind::InvalidChecksum => {
bail!("key mnemonic was not valid")
}
bip39::ErrorKind::InvalidKeysize(_)
| bip39::ErrorKind::InvalidWordLength(_)
| bip39::ErrorKind::InvalidEntropyLength(_, _) => {
bail!("key was not the correct length")
}
}
match err {
// assume they copied in the base64 key
bip39::ErrorKind::InvalidWord(_) => key,
bip39::ErrorKind::InvalidChecksum => {
bail!("key mnemonic was not valid")
}
_ => {
// unknown error. assume they copied the base64 key
key
bip39::ErrorKind::InvalidKeysize(_)
| bip39::ErrorKind::InvalidWordLength(_)
| bip39::ErrorKind::InvalidEntropyLength(_, _) => {
bail!("key was not the correct length")
}
}
}
};

key
}
} else {
println!("Re-encrypting store with freshly-generated key");
let (_, encoded) = generate_encoded_key()?;
Expand Down
Loading