From f79014235e85554e3661b3f2a02b8fa88bc192ff Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Thu, 21 Nov 2024 16:53:17 +0000 Subject: feat(login): overhaul login experience * simplify login menu, making it more accessable to newcomers and easier to select remote signer options * enable `ngit login` to work from anywhere (not just a git repo) * assume fresh login details saved to global git config but fallback to local repository * maintain local repository login via `ngit login --local` * maintain login via CLI arguments eg `ngit send --nsec nsec123` * nudge users to remember nsec when pasting in ncryptsec for a better UX, whilst maintaining the option to be prompted for password everytime * create placeholder menu items for help menu and create account --- src/lib/login/key_encryption.rs | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'src/lib/login/key_encryption.rs') diff --git a/src/lib/login/key_encryption.rs b/src/lib/login/key_encryption.rs index b50b507..efb38d1 100644 --- a/src/lib/login/key_encryption.rs +++ b/src/lib/login/key_encryption.rs @@ -1,23 +1,5 @@ use anyhow::Result; -use nostr::{prelude::*, Keys}; - -pub fn encrypt_key(keys: &Keys, password: &str) -> Result { - let log2_rounds: u8 = if password.len() > 20 { - // we have enough of entropy - no need to spend CPU time adding much more - 1 - } else { - println!("this may take a few seconds..."); - // default (scrypt::Params::RECOMMENDED_LOG_N) is 17 but 30s is too long to wait - 15 - }; - Ok(nostr::nips::nip49::EncryptedSecretKey::new( - keys.secret_key(), - password, - log2_rounds, - KeySecurity::Medium, - )? - .to_bech32()?) -} +use nostr::prelude::*; pub fn decrypt_key(encrypted_key: &str, password: &str) -> Result { let encrypted_key = nostr::nips::nip49::EncryptedSecretKey::from_bech32(encrypted_key)?; @@ -34,6 +16,24 @@ mod tests { use super::*; + pub fn encrypt_key(keys: &Keys, password: &str) -> Result { + let log2_rounds: u8 = if password.len() > 20 { + // we have enough of entropy - no need to spend CPU time adding much more + 1 + } else { + println!("this may take a few seconds..."); + // default (scrypt::Params::RECOMMENDED_LOG_N) is 17 but 30s is too long to wait + 15 + }; + Ok(nostr::nips::nip49::EncryptedSecretKey::new( + keys.secret_key(), + password, + log2_rounds, + KeySecurity::Medium, + )? + .to_bech32()?) + } + #[test] fn encrypt_key_produces_string_prefixed_with() -> Result<()> { let s = encrypt_key(&nostr::Keys::generate(), TEST_PASSWORD)?; -- cgit v1.2.3