add enrollment diagrams

This commit is contained in:
2025-03-24 04:49:39 -05:00
parent 5031062e87
commit 1f188e82ed
6 changed files with 340 additions and 162 deletions

View File

@@ -0,0 +1,37 @@
# nKode Enrollment
```mermaid
sequenceDiagram
participant User
participant Client
participant Server
Note over User,Client: Enrollment
Client->>User: Signup Form
Note left of User: email: user@example.com
User->>Client: Submit Email
Client->>+Server: Signup Session: user@example.com
Server->>Server: Create Signup Session
Note over User,Client: Set nKode
Server-->>-Client: signup_session_id, set_keypad, icons
Note left of Server: signup_session_id:<br/>92a2a1c6-3146-4d47-ac00-5160a7ebf104
Note left of Server: set_keypad:<br/>Key 0: [ 7 14 3 28 23]<br/>Key 1: [ 1 26 15 10 5]<br/>Key 2: [13 20 27 4 29]<br/>Key 3: [25 8 21 16 11]<br/>Key 4: [19 2 9 22 17]<br/>
Note left of Server: Icons:<br/>[😀,😂,🥳,😍,🤓<br/>😎,🥺,😡,😱,🤯<br/>🥰,😴,🤔,🙃,😇<br/>🤖,👽,👾,🐱,🐶<br/>🦁,🐻,🐸,🐙,🦄<br/>🌟,⚡,🔥,🍕,🎉]
Client->>Client: Order Icons by keypad
Client->>User: Display Keypad
Note left of Client: Key 0: ['😡' '😇' '😍' '🍕' '🐙']<br/>Key 1: ['😂' '⚡' '🤖' '🥰' '😎']<br/>Key 2: ['🙃' '🦁' '🔥' '🤓' '🎉']<br/>Key 3: ['🌟' '😱' '🐻' '👽' '😴']<br/>Key 4: ['🐶' '🥳' '🤯' '🐸' '👾']<br/>
Note left of User: User icons: ['😍' '🤓' '😇' '😡']
User->>Client: Set Key Selection: [0, 2, 0, 0]
Client->>+Server: Set nKode:<br/>92a2a1c6-3146-4d47-ac00-5160a7ebf104<br/>[0, 2, 0, 0]
Server->>Server: Disperse Set Keypad
Note over User,Client: Confirm nKode
Server-->>-Client: signup_session_id, confirm_keypad, icons
Note left of Server: signup_session_id:<br/>92a2a1c6-3146-4d47-ac00-5160a7ebf104
Note left of Server: confirm_keypad:<br/>Key 0: [ 7 26 21 4 17]<br/>Key 1: [19 20 3 16 5]<br/>Key 2: [ 1 8 9 28 29]<br/>Key 3: [13 14 15 22 11]<br/>Key 4: [25 2 27 10 23]<br/>
Client->>Client: Order Icons by keypad
Client->>User: Display Keypad
Note left of Client: Key 0: ['😡' '⚡' '🐻' '🤓' '👾']<br/>Key 1: ['🐶' '🦁' '😍' '👽' '😎']<br/>Key 2: ['😂' '😱' '🤯' '🍕' '🎉']<br/>Key 3: ['🙃' '😇' '🤖' '🐸' '😴']<br/>Key 4: ['🌟' '🥳' '🔥' '🥰' '🐙']<br/>
Note left of User: User icons: ['😍' '🤓' '😇' '😡']
User->>Client: Key Selection: [1, 0, 3, 0]
Client->>+Server: Confirm nKode:<br/>92a2a1c6-3146-4d47-ac00-5160a7ebf104<br/>[1, 0, 3, 0]
Server->>Server: Create User
Server-->-Client: Success
```

View File

@@ -0,0 +1,37 @@
# nKode Enrollment
```mermaid
sequenceDiagram
participant User
participant Client
participant Server
Note over User,Client: Enrollment
Client->>User: Signup Form
Note left of User: email: {{ email }}
User->>Client: Submit Email
Client->>+Server: Signup Session: {{ email }}
Server->>Server: Create Signup Session
Note over User,Client: Set nKode
Server-->>-Client: signup_session_id, set_keypad, icons
Note left of Server: signup_session_id:<br/>{{ signup_session_id }}
Note left of Server: set_keypad:<br/>{{set_keypad}}
Note left of Server: Icons:<br/>{{icon_matrix}}
Client->>Client: Order Icons by keypad
Client->>User: Display Keypad
Note left of Client: {{ ordered_keypad }}
Note left of User: User icons: {{ passcode_user_icons }}
User->>Client: Set Key Selection: {{ selected_keys_set }}
Client->>+Server: Set nKode:<br/>{{ signup_session_id }}<br/>{{ selected_keys_set }}
Server->>Server: Disperse Set Keypad
Note over User,Client: Confirm nKode
Server-->>-Client: signup_session_id, confirm_keypad, icons
Note left of Server: signup_session_id:<br/>{{ signup_session_id }}
Note left of Server: confirm_keypad:<br/>{{confirm_keypad}}
Client->>Client: Order Icons by keypad
Client->>User: Display Keypad
Note left of Client: {{ confirm_ordered_keypad }}
Note left of User: User icons: {{ passcode_user_icons }}
User->>Client: Key Selection: {{ confirm_key_selection }}
Client->>+Server: Confirm nKode:<br/>{{ signup_session_id }}<br/>{{ confirm_key_selection }}
Server->>Server: Create User
Server-->-Client: Success
```

View File

@@ -0,0 +1,107 @@
# Render markdown template for nKode enrollment
from pathlib import Path
import numpy as np
from jinja2 import Environment, FileSystemLoader, select_autoescape
from secrets import choice
from string import ascii_lowercase
from src.models import NKodePolicy, KeypadSize
from src.nkode_api import NKodeAPI
from src.utils import select_keys_with_passcode_values
def render_markdown_template(template_path, output_path, context):
"""
Render a Jinja2 markdown template with the given context and save to output_path.
Args:
template_path (Path): Path to the template file
output_path (Path): Path where the rendered file will be saved
context (dict): Template variables
"""
template_dir = template_path.parent
template_file = template_path.name
env = Environment(
loader=FileSystemLoader(template_dir),
autoescape=select_autoescape(['html', 'xml']),
trim_blocks=True,
lstrip_blocks=True
)
template = env.get_template(template_file)
rendered = template.render(**context)
with open(output_path, 'w') as f:
f.write(rendered)
print(f"Template rendered to {output_path}")
def display_icons(icons_array: np.ndarray, kp: KeypadSize) -> str:
icons = "["
for row in icons_array.reshape(-1, kp.numb_of_keys):
icons += ",".join(row)
icons += "<br/>"
icons = icons[:-5]
icons += "]"
return icons
def display_icons_keypad(icons_array: np.ndarray, kp: KeypadSize) -> str:
icons = ""
for idx, row in enumerate(icons_array.reshape(-1, kp.numb_of_keys)):
icons += f"Key {idx}: "
icons += str(row)
icons += "<br/>"
return icons
if __name__ == "__main__":
api = NKodeAPI()
user_icons = np.array([
"😀", "😂", "🥳", "😍", "🤓",
"😎", "🥺", "😡", "😱", "🤯",
"🥰", "😴", "🤔", "🙃", "😇",
"🤖", "👽", "👾", "🐱", "🐶",
"🦁", "🐻", "🐸", "🐙", "🦄",
"🌟", "", "🔥", "🍕", "🎉"
])
policy = NKodePolicy(
max_nkode_len=10,
min_nkode_len=4,
distinct_positions=0,
distinct_properties=4,
)
keypad_size = KeypadSize(
numb_of_keys=5,
props_per_key=6
)
customer_id = api.create_new_customer(keypad_size, policy)
signup_session_id, set_signup_keypad = api.generate_signup_keypad(customer_id)
ordered_set_icons = user_icons[set_signup_keypad]
username = "test_username" + "".join([choice(ascii_lowercase) for _ in range(6)])
passcode_len = 4
passcode_property_indices = np.random.choice(set_signup_keypad.reshape(-1), size=passcode_len,
replace=False).tolist()
selected_keys_set = select_keys_with_passcode_values(passcode_property_indices, set_signup_keypad,
keypad_size.numb_of_keys)
confirm_keypad = api.set_nkode(username, customer_id, selected_keys_set, signup_session_id)
selected_keys_confirm = select_keys_with_passcode_values(passcode_property_indices, confirm_keypad,
keypad_size.numb_of_keys)
ordered_confirm_icons = user_icons[confirm_keypad]
print(f"Selected Keys\n{selected_keys_confirm}")
success = api.confirm_nkode(username, customer_id, selected_keys_confirm, signup_session_id)
context = {
"email": "user@example.com",
"signup_session_id": signup_session_id,
"set_keypad": display_icons_keypad(set_signup_keypad.reshape(-1, keypad_size.numb_of_keys), keypad_size),
"icon_matrix": display_icons(user_icons, keypad_size),
"ordered_keypad": display_icons_keypad(ordered_set_icons, keypad_size),
"passcode_user_icons": str(user_icons[passcode_property_indices]),
"selected_keys_set": str(selected_keys_set),
"confirm_keypad": display_icons_keypad(confirm_keypad.reshape(-1, keypad_size.numb_of_keys), keypad_size),
"confirm_ordered_keypad": display_icons_keypad(ordered_confirm_icons.reshape(-1, keypad_size.numb_of_keys), keypad_size),
"confirm_key_selection": selected_keys_confirm
}
# Render the template
render_markdown_template(Path("./enrollment_diagram.template.md"), Path("./enrollment_diagram.md"), context)