refactor client opaque

This commit is contained in:
2025-12-16 14:07:03 -06:00
parent e29468e0b6
commit be95241ed4
8 changed files with 342 additions and 150 deletions

View File

@@ -1,6 +1,6 @@
use std::marker::PhantomData;
use nkode_rs::nkode_core::keypad::Keypad;
use crate::models::app::{CodeLoginData, CodeLoginSession, Icon, IconID, KeyLoginSession, ServerAPI, ICON_ID_SIZE};
use crate::models::app::{CodeLoginData, CodeLoginSession, Icon, IconID, KeyLoginSession, ClientAuthAPI, ICON_ID_SIZE};
use crate::models::email::Email;
use crate::models::opaque::UserSecretKey;
use anyhow::Result;
@@ -12,14 +12,14 @@ pub struct Login;
pub struct Register;
pub struct ClientAppKey<State, S: ServerAPI> {
pub struct ClientAppKey<State, S: ClientAuthAPI> {
api: S,
email: Email,
user_secret_key: UserSecretKey,
_state: PhantomData<State>
}
impl <S: ServerAPI> ClientAppKey<Register,S> {
impl <S: ClientAuthAPI> ClientAppKey<Register,S> {
pub async fn register(self) -> Result<ClientAppKey<Login, S>, String> {
// self.repo.set_secret_key(&self.email, &self.user_secret_key).await?;
self.api.register_key(&self.email, &self.user_secret_key).await?;
@@ -32,7 +32,7 @@ impl <S: ServerAPI> ClientAppKey<Register,S> {
}
}
impl <S: ServerAPI> ClientAppKey<Login,S> {
impl <S: ClientAuthAPI> ClientAppKey<Login,S> {
pub async fn login(self) -> Result<ClientAppKeyLoggedIn<S>,String> {
let key_login = self.api.login_key(&self.email, &self.user_secret_key).await?;
Ok(ClientAppKeyLoggedIn{
@@ -44,14 +44,14 @@ impl <S: ServerAPI> ClientAppKey<Login,S> {
}
}
pub struct ClientAppKeyLoggedIn<S: ServerAPI> {
pub struct ClientAppKeyLoggedIn<S: ClientAuthAPI> {
api: S,
email: Email,
user_secret_key: UserSecretKey,
key_login: KeyLoginSession,
}
impl <S: ServerAPI> ClientAppKeyLoggedIn<S> {
impl <S: ClientAuthAPI> ClientAppKeyLoggedIn<S> {
pub async fn register_code(self) -> Result<ClientAppCodeRegister<S>, String> {
let icon_nonce = Nonce::new();
let icons = self.get_icons(&icon_nonce).await?;
@@ -98,7 +98,7 @@ impl <S: ServerAPI> ClientAppKeyLoggedIn<S> {
}
}
pub struct ClientAppCodeRegister<S: ServerAPI> {
pub struct ClientAppCodeRegister<S: ClientAuthAPI> {
api: S,
email: Email,
user_secret_key: UserSecretKey,
@@ -108,7 +108,7 @@ pub struct ClientAppCodeRegister<S: ServerAPI> {
keypad: Keypad,
}
impl <S: ServerAPI>ClientAppCodeRegister<S> {
impl <S: ClientAuthAPI>ClientAppCodeRegister<S> {
pub async fn register(self, selected_icons: Vec<IconID>) -> Result<ClientAppCodeLogin<S>, String> {
let policy = self.api.get_policy().await?;
let keypad = Keypad::new(policy.clone());
@@ -137,7 +137,7 @@ impl <S: ServerAPI>ClientAppCodeRegister<S> {
}
}
pub struct ClientAppCodeLogin<S: ServerAPI> {
pub struct ClientAppCodeLogin<S: ClientAuthAPI> {
api: S,
email: Email,
mask: Vec<u64>,
@@ -146,7 +146,7 @@ pub struct ClientAppCodeLogin<S: ServerAPI> {
cipher: NKodeCipher
}
impl <S: ServerAPI>ClientAppCodeLogin<S> {
impl <S: ClientAuthAPI>ClientAppCodeLogin<S> {
pub fn sort_icons(&self) -> Vec<Icon> {
nkode_rs::tensor::reorder(
&self.icons,