Files
nkode-protocol/src/shared/models/app.rs
2025-12-18 19:11:08 -06:00

72 lines
2.3 KiB
Rust

use async_trait::async_trait;
use nkode_rs::nkode_core::chacha20prng::Nonce; use nkode_rs::nkode_core::keypad::Keypad;
use serde::{Deserialize, Serialize};
use getset::Getters;
use nkode_rs::from_bytes::FromBytes;
use nkode_rs::nkode_core::policy::NKodePolicy;
use uuid::Uuid;
use crate::shared::email::Email;
use crate::shared::opaque::{OpaqueSessionKey, UserSecretKey};
#[derive(Debug, Clone)]
pub struct LoggedInSession {
pub(crate) session_id: Uuid,
pub(crate) email: Email,
pub(crate) session_key: OpaqueSessionKey,
}
#[derive(Debug, Clone)]
pub struct KeyLoggedInSession(pub(crate) LoggedInSession);
#[derive(Debug, Clone)]
pub struct CodeLoggedInSession(pub(crate) LoggedInSession);
pub const ICON_ID_SIZE: usize = 32;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct IconID([u8; 32]);
impl FromBytes<ICON_ID_SIZE> for IconID {
fn from_array(arr: [u8; ICON_ID_SIZE]) -> Self {
Self(arr)
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Getters)]
pub struct Icon {
#[get = "pub"]
id: IconID,
#[get = "pub"]
data: Vec<u8>,
}
impl Icon {
pub fn update_id(&mut self, new_id: IconID) {
self.id = new_id
}
}
#[derive(Debug, Clone, Getters, Serialize, Deserialize)]
pub struct CodeLoginData {
#[get = "pub"]
pub(crate) mask: Vec<u64>,
#[get = "pub"]
pub(crate) cipher_nonce: Nonce,
#[get = "pub"]
pub(crate) icon_nonce: Nonce,
#[get = "pub"]
pub(crate) keypad: Keypad,
}
#[async_trait]
pub trait AuthAPI {
async fn register_key(&self, email: &Email, secret_key: &UserSecretKey) -> Result<(), String>;
async fn register_code(&self, email: &Email, passcode: &[u64], key_login_session: &KeyLoggedInSession, data: CodeLoginData) -> Result<(), String>;
async fn login_key(&self, email: &Email, secret_key: &UserSecretKey) -> Result<KeyLoggedInSession, String>;
async fn login_code(&self, email: &Email, passcode: &[u64], key_login_session: &KeyLoggedInSession, keypad: Keypad) -> Result<CodeLoggedInSession, String>;
async fn get_new_icons(&self) -> Result<Vec<Icon>, String>;
async fn get_login_data(&self, key_login_session: &KeyLoggedInSession) -> Result<CodeLoginData, String>;
async fn is_code_registered(&self, key_login_session: &KeyLoggedInSession) -> Result<bool, String>;
async fn get_policy(&self) -> Result<NKodePolicy, String>;
}