use super::pair;
use super::{SeaError, UserAuth};
use base64::{engine::general_purpose, Engine as _};
use pbkdf2::pbkdf2_hmac;
use sha2::Sha256;
pub async fn create_user(alias: Option<String>) -> Result<UserAuth, SeaError> {
let pair = pair::generate_pair().await?;
Ok(UserAuth { pair, alias })
}
pub async fn authenticate(_alias: &str, _password: &str) -> Result<UserAuth, SeaError> {
Err(SeaError::Crypto(
"Full authentication not yet implemented - requires graph storage integration".to_string(),
))
}
pub fn hash_password(password: &str, salt: &[u8]) -> String {
let mut hash = vec![0u8; 32];
pbkdf2_hmac::<Sha256>(password.as_bytes(), salt, 100000, &mut hash);
general_purpose::STANDARD_NO_PAD.encode(&hash)
}
pub fn verify_password(password: &str, salt: &[u8], hash: &str) -> bool {
let computed_hash = hash_password(password, salt);
computed_hash == hash
}
pub fn generate_salt() -> Vec<u8> {
use rand::RngCore;
let mut salt = vec![0u8; 16];
rand::thread_rng().fill_bytes(&mut salt);
salt
}