numpy refactor

This commit is contained in:
2025-03-13 04:40:45 -05:00
parent facd9ee318
commit f6bf731186
12 changed files with 261 additions and 140 deletions

View File

@@ -1,6 +1,5 @@
from dataclasses import dataclass, field
from uuid import UUID, uuid4
from typing import Dict, List, Tuple
from src.customer import Customer
from src.models import NKodePolicy, KeypadSize
from src.user import User
@@ -8,12 +7,13 @@ from src.user_cipher import UserCipher
from src.user_signup_session import UserSignupSession
from src.user_keypad import UserKeypad
from src.customer_cipher import CustomerCipher
import numpy as np
@dataclass
class NKodeAPI:
customers: Dict[UUID, Customer] = field(default_factory=dict)
signup_sessions: Dict[UUID, UserSignupSession] = field(default_factory=dict)
customers: dict[UUID, Customer] = field(default_factory=dict)
signup_sessions: dict[UUID, UserSignupSession] = field(default_factory=dict)
def create_new_customer(self, keypad_size: KeypadSize, nkode_policy: NKodePolicy) -> UUID:
new_customer = Customer(
@@ -25,7 +25,7 @@ class NKodeAPI:
self.customers[new_customer.customer_id] = new_customer
return new_customer.customer_id
def generate_signup_keypad(self, customer_id: UUID) -> Tuple[UUID, List[int]]:
def generate_signup_keypad(self, customer_id: UUID) -> tuple[UUID, np.ndarray]:
if customer_id not in self.customers.keys():
raise ValueError(f"Customer with ID '{customer_id}' does not exist")
customer = self.customers[customer_id]
@@ -45,9 +45,9 @@ class NKodeAPI:
self,
username: str,
customer_id: UUID,
key_selection: List[int],
key_selection: list[int],
session_id: UUID
) -> List[int]:
) -> np.ndarray:
if customer_id not in self.customers.keys():
raise ValueError(f"Customer ID {customer_id} not found")
customer = self.customers[customer_id]
@@ -62,7 +62,7 @@ class NKodeAPI:
self,
username: str,
customer_id: UUID,
confirm_key_entry: List[int],
confirm_key_entry: list[int],
session_id: UUID
) -> bool:
if session_id not in self.signup_sessions.keys():
@@ -90,7 +90,7 @@ class NKodeAPI:
del self.signup_sessions[session_id]
return True
def get_login_keypad(self, username: str, customer_id: UUID) -> List[int]:
def get_login_keypad(self, username: str, customer_id: UUID) -> np.ndarray:
if customer_id not in self.customers.keys():
raise ValueError("Customer ID not found")
customer = self.customers[customer_id]
@@ -98,9 +98,10 @@ class NKodeAPI:
raise ValueError("Username not found")
user = customer.users[username]
user.user_keypad.partial_keypad_shuffle()
# TODO: implement split_keypad_shuffle()
return user.user_keypad.keypad
def login(self, customer_id: UUID, username: str, key_selection: List[int]) -> bool:
def login(self, customer_id: UUID, username: str, key_selection: list[int]) -> bool:
if customer_id not in self.customers.keys():
raise ValueError("Customer ID not found")
customer = self.customers[customer_id]