diff --git a/docs/enrollment_diagram.md b/docs/enrollment_diagram.md index 304fe77..fef2bd0 100644 --- a/docs/enrollment_diagram.md +++ b/docs/enrollment_diagram.md @@ -12,26 +12,26 @@ sequenceDiagram Server->>Server: Create Signup Session Note over User,Server: Set nKode Server-->>-Client: signup_session_id, set_keypad, icons - Note left of Server: signup_session_id:
d7e50a75-d3ff-482a-b0e7-ce99c3838c1a - Note left of Server: set_keypad:
Key 0: [12 13 20 21 16]
Key 1: [ 6 1 14 9 4]
Key 2: [ 0 7 26 15 28]
Key 3: [24 19 2 27 10]
Key 4: [18 25 8 3 22]
- Note left of Server: Icons:
[😀,😂,đŸĨŗ,😍,🤓
😎,đŸĨē,😡,😱,đŸ¤¯
đŸĨ°,😴,🤔,🙃,😇
🤖,đŸ‘Ŋ,👾,🐱,đŸļ
đŸĻ,đŸģ,🐸,🐙,đŸĻ„
🌟,⚡,đŸ”Ĩ,🍕,🎉] + Note left of Server: signup_session_id:
51b187b9-c930-4f5d-81da-c11c082f2c64 + Note left of Server: set_keypad:
Key 0: [ 9 29 3 49 50 25]
Key 1: [27 2 12 22 14 16]
Key 2: [36 47 21 13 23 7]
Key 3: [45 11 30 4 32 43]
Key 4: [18 20 39 40 41 52]
Key 5: [ 0 38 48 31 5 34]
+ Note left of Server: Icons:
[🍎,🍏,🍊,🍋,🍌,🍉
🍇,🍓,🍒,🍑,đŸĨ­,🍍
đŸĨĨ,đŸĨ,🍅,🍆,đŸĨ‘,đŸĨ•
đŸŒŊ,đŸĨ”,🍠,đŸĨ,đŸĨ–,đŸĨ¨
đŸĨ¯,đŸĨž,🧀,🍖,🍗,đŸĨš
🍔,🍟,🍕,🌭,đŸĨĒ,🌮
đŸŒ¯,đŸŖ,🍤,🍙,🍚,🍜
🍲,🍛,🍱,đŸĨŸ,đŸĻ,🍧
🍨,🍩,đŸĒ,🎂,🍰,🧁] Client->>Client: Order Icons by keypad Client->>User: Display Keypad - Note left of Client: Key 0: ['🤔' '🙃' 'đŸĻ' 'đŸģ' 'đŸ‘Ŋ']
Key 1: ['đŸĨē' '😂' '😇' 'đŸ¤¯' '🤓']
Key 2: ['😀' '😡' '⚡' '🤖' '🍕']
Key 3: ['đŸĻ„' 'đŸļ' 'đŸĨŗ' 'đŸ”Ĩ' 'đŸĨ°']
Key 4: ['🐱' '🌟' '😱' '😍' '🐸']
- Note left of User: User icons: ['🤓' 'đŸļ' 'đŸĻ„' 'đŸ‘Ŋ'] - User->>Client: Set Key Selection: [1, 3, 3, 0] - Client->>+Server: Set nKode:
d7e50a75-d3ff-482a-b0e7-ce99c3838c1a
[1, 3, 3, 0] + Note left of Client: Key 0: ['🍑' 'đŸĨš' '🍋' '🍩' 'đŸĒ' 'đŸĨž']
Key 1: ['🍖' '🍊' 'đŸĨĨ' 'đŸĨ–' '🍅' 'đŸĨ‘']
Key 2: ['đŸŒ¯' '🍧' 'đŸĨ' 'đŸĨ' 'đŸĨ¨' '🍓']
Key 3: ['đŸĨŸ' '🍍' '🍔' '🍌' '🍕' '🍛']
Key 4: ['đŸŒŊ' '🍠' '🍙' '🍚' '🍜' '🍰']
Key 5: ['🍎' '🍤' '🍨' '🍟' '🍉' 'đŸĨĒ']
+ Note left of User: User icons: ['đŸŒ¯' '🍖' '🍰' '🍓'] + User->>Client: Set Key Selection: [2, 1, 4, 2] + Client->>+Server: Set nKode:
51b187b9-c930-4f5d-81da-c11c082f2c64
[2, 1, 4, 2] Server->>Server: Disperse Set Keypad Note over User,Server: Confirm nKode Server-->>-Client: signup_session_id, confirm_keypad, icons - Note left of Server: signup_session_id:
d7e50a75-d3ff-482a-b0e7-ce99c3838c1a - Note left of Server: confirm_keypad:
Key 0: [ 6 13 8 15 10]
Key 1: [24 7 14 3 16]
Key 2: [12 25 2 9 28]
Key 3: [ 0 1 20 27 22]
Key 4: [18 19 26 21 4]
+ Note left of Server: signup_session_id:
51b187b9-c930-4f5d-81da-c11c082f2c64 + Note left of Server: confirm_keypad:
Key 0: [27 47 39 4 5 25]
Key 1: [45 20 48 49 14 7]
Key 2: [ 9 38 12 13 32 52]
Key 3: [36 2 30 40 50 34]
Key 4: [18 11 3 31 23 16]
Key 5: [ 0 29 21 22 41 43]
Client->>Client: Order Icons by keypad Client->>User: Display Keypad - Note left of Client: Key 0: ['đŸĨē' '🙃' '😱' '🤖' 'đŸĨ°']
Key 1: ['đŸĻ„' '😡' '😇' '😍' 'đŸ‘Ŋ']
Key 2: ['🤔' '🌟' 'đŸĨŗ' 'đŸ¤¯' '🍕']
Key 3: ['😀' '😂' 'đŸĻ' 'đŸ”Ĩ' '🐸']
Key 4: ['🐱' 'đŸļ' '⚡' 'đŸģ' '🤓']
- Note left of User: User icons: ['🤓' 'đŸļ' 'đŸĻ„' 'đŸ‘Ŋ'] - User->>Client: Key Selection: [4, 4, 1, 1] - Client->>+Server: Confirm nKode:
d7e50a75-d3ff-482a-b0e7-ce99c3838c1a
[4, 4, 1, 1] + Note left of Client: Key 0: ['🍖' '🍧' '🍙' '🍌' '🍉' 'đŸĨž']
Key 1: ['đŸĨŸ' '🍠' '🍨' '🍩' '🍅' '🍓']
Key 2: ['🍑' '🍤' 'đŸĨĨ' 'đŸĨ' '🍕' '🍰']
Key 3: ['đŸŒ¯' '🍊' '🍔' '🍚' 'đŸĒ' 'đŸĨĒ']
Key 4: ['đŸŒŊ' '🍍' '🍋' '🍟' 'đŸĨ¨' 'đŸĨ‘']
Key 5: ['🍎' 'đŸĨš' 'đŸĨ' 'đŸĨ–' '🍜' '🍛']
+ Note left of User: User icons: ['đŸŒ¯' '🍖' '🍰' '🍓'] + User->>Client: Key Selection: [3, 0, 2, 1] + Client->>+Server: Confirm nKode:
51b187b9-c930-4f5d-81da-c11c082f2c64
[3, 0, 2, 1] Server->>Server: Create User Server-->>-Client: Success ``` \ No newline at end of file diff --git a/docs/login_diagram.md b/docs/login_diagram.md index 1ae4167..bfa0962 100644 --- a/docs/login_diagram.md +++ b/docs/login_diagram.md @@ -10,13 +10,13 @@ sequenceDiagram Note left of User: email: user@example.com User->>Server: Submit Email Server->>Client: login_keypad, icons - Note left of Server: Login Keypad:
Key 0: [12 13 20 21 16 23]
Key 1: [ 6 1 14 9 4 29]
Key 2: [ 0 7 26 15 28 11]
Key 3: [24 19 2 27 10 5]
Key 4: [18 25 8 3 22 17]
- Note left of Server: Icons:
[😀,😂,đŸĨŗ,😍,🤓
😎,đŸĨē,😡,😱,đŸ¤¯
đŸĨ°,😴,🤔,🙃,😇
🤖,đŸ‘Ŋ,👾,🐱,đŸļ
đŸĻ,đŸģ,🐸,🐙,đŸĻ„
🌟,⚡,đŸ”Ĩ,🍕,🎉] + Note left of Server: Login Keypad:
Key 0: [ 9 1 29 3 49 50 33 25 35]
Key 1: [27 28 2 12 22 14 24 16 17]
Key 2: [36 37 47 21 13 23 42 7 26]
Key 3: [45 19 11 30 4 32 51 43 8]
Key 4: [18 46 20 39 40 41 15 52 44]
Key 5: [ 0 10 38 48 31 5 6 34 53]
+ Note left of Server: Icons:
[🍎,🍏,🍊,🍋,🍌,🍉
🍇,🍓,🍒,🍑,đŸĨ­,🍍
đŸĨĨ,đŸĨ,🍅,🍆,đŸĨ‘,đŸĨ•
đŸŒŊ,đŸĨ”,🍠,đŸĨ,đŸĨ–,đŸĨ¨
đŸĨ¯,đŸĨž,🧀,🍖,🍗,đŸĨš
🍔,🍟,🍕,🌭,đŸĨĒ,🌮
đŸŒ¯,đŸŖ,🍤,🍙,🍚,🍜
🍲,🍛,🍱,đŸĨŸ,đŸĻ,🍧
🍨,🍩,đŸĒ,🎂,🍰,🧁] Client->>Client: Order Icons Client->>User: Display Keypad - Note left of Client: Key 0: ['🤔' '🙃' 'đŸĻ' 'đŸģ' 'đŸ‘Ŋ' '🐙']
Key 1: ['đŸĨē' '😂' '😇' 'đŸ¤¯' '🤓' '🎉']
Key 2: ['😀' '😡' '⚡' '🤖' '🍕' '😴']
Key 3: ['đŸĻ„' 'đŸļ' 'đŸĨŗ' 'đŸ”Ĩ' 'đŸĨ°' '😎']
Key 4: ['🐱' '🌟' '😱' '😍' '🐸' '👾']
- Note left of User: User passcode icons: ['🤓' 'đŸļ' 'đŸĻ„' 'đŸ‘Ŋ'] - User->>Client: Selected Keys
[1, 3, 3, 0] - Client->>Server: Login:
email: user@example.com
selected_keys: [1, 3, 3, 0] + Note left of Client: Key 0: ['🍑' '🍏' 'đŸĨš' '🍋' '🍩' 'đŸĒ' '🌭' 'đŸĨž' '🌮']
Key 1: ['🍖' '🍗' '🍊' 'đŸĨĨ' 'đŸĨ–' '🍅' 'đŸĨ¯' 'đŸĨ‘' 'đŸĨ•']
Key 2: ['đŸŒ¯' 'đŸŖ' '🍧' 'đŸĨ' 'đŸĨ' 'đŸĨ¨' '🍲' '🍓' '🧀']
Key 3: ['đŸĨŸ' 'đŸĨ”' '🍍' '🍔' '🍌' '🍕' '🎂' '🍛' '🍒']
Key 4: ['đŸŒŊ' 'đŸĻ' '🍠' '🍙' '🍚' '🍜' '🍆' '🍰' '🍱']
Key 5: ['🍎' 'đŸĨ­' '🍤' '🍨' '🍟' '🍉' '🍇' 'đŸĨĒ' '🧁']
+ Note left of User: User passcode icons: ['đŸŒ¯' '🍖' '🍰' '🍓'] + User->>Client: Selected Keys
[2, 1, 4, 2] + Client->>Server: Login:
email: user@example.com
selected_keys: [2, 1, 4, 2] Server-->>Client: Success ``` \ No newline at end of file diff --git a/docs/scripts/render_diagrams_md.py b/docs/scripts/render_diagrams_md.py index ec97b54..09b5281 100644 --- a/docs/scripts/render_diagrams_md.py +++ b/docs/scripts/render_diagrams_md.py @@ -1,35 +1,13 @@ -# 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 docs.scripts.utils import render_markdown_template, emojis 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): - 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): @@ -49,14 +27,7 @@ def display_icons_keypad(icons_array: np.ndarray, props_per_key: int) -> str: if __name__ == "__main__": api = NKodeAPI() - user_icons = np.array([ - "😀", "😂", "đŸĨŗ", "😍", "🤓", - "😎", "đŸĨē", "😡", "😱", "đŸ¤¯", - "đŸĨ°", "😴", "🤔", "🙃", "😇", - "🤖", "đŸ‘Ŋ", "👾", "🐱", "đŸļ", - "đŸĻ", "đŸģ", "🐸", "🐙", "đŸĻ„", - "🌟", "⚡", "đŸ”Ĩ", "🍕", "🎉" - ]) + policy = NKodePolicy( max_nkode_len=10, min_nkode_len=4, @@ -64,12 +35,12 @@ if __name__ == "__main__": distinct_properties=4, ) keypad_size = KeypadSize( - numb_of_keys=5, - props_per_key=6 + numb_of_keys=6, + props_per_key=9 ) 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] + ordered_set_icons = emojis[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, @@ -79,16 +50,16 @@ if __name__ == "__main__": 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] + ordered_confirm_icons = emojis[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.numb_of_keys), - "keypad_icons": display_icons(user_icons, keypad_size), + "keypad_icons": display_icons(emojis[:keypad_size.total_props], keypad_size), "ordered_keypad": display_icons_keypad(ordered_set_icons, keypad_size.numb_of_keys), - "passcode_user_icons": str(user_icons[passcode_property_indices]), + "passcode_user_icons": str(emojis[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.numb_of_keys), "confirm_ordered_keypad": display_icons_keypad(ordered_confirm_icons.reshape(-1, keypad_size.numb_of_keys), keypad_size.numb_of_keys), @@ -98,13 +69,13 @@ if __name__ == "__main__": login_keypad = api.get_login_keypad(username, customer_id) selected_keys_login = select_keys_with_passcode_values(passcode_property_indices, login_keypad, keypad_size.props_per_key) - ordered_login_keypad = user_icons[login_keypad] + ordered_login_keypad = emojis[login_keypad] context = { "email": "user@example.com", - "keypad_icons": display_icons(user_icons, keypad_size), + "keypad_icons": display_icons(emojis[:keypad_size.total_props], keypad_size), "login_keypad": display_icons_keypad(login_keypad.reshape(-1, keypad_size.props_per_key), keypad_size.props_per_key), "ordered_login_icons": display_icons_keypad(ordered_login_keypad.reshape(-1, keypad_size.props_per_key),keypad_size.props_per_key), - "passcode_user_icons": str(user_icons[passcode_property_indices]), + "passcode_user_icons": str(emojis[passcode_property_indices]), "selected_keys_login": str(selected_keys_login) } api.login(customer_id, username, selected_keys_login) diff --git a/docs/scripts/utils.py b/docs/scripts/utils.py new file mode 100644 index 0000000..32531f6 --- /dev/null +++ b/docs/scripts/utils.py @@ -0,0 +1,46 @@ +import numpy as np +from jinja2 import Environment, FileSystemLoader, select_autoescape + + +emojis = np.array([ + "🍎", "🍏", "🍊", "🍋", "🍌", "🍉", "🍇", "🍓", "🍒", "🍑", + "đŸĨ­", "🍍", "đŸĨĨ", "đŸĨ", "🍅", "🍆", "đŸĨ‘", "đŸĨ•", "đŸŒŊ", "đŸĨ”", + "🍠", "đŸĨ", "đŸĨ–", "đŸĨ¨", "đŸĨ¯", "đŸĨž", "🧀", "🍖", "🍗", "đŸĨš", + "🍔", "🍟", "🍕", "🌭", "đŸĨĒ", "🌮", "đŸŒ¯", "đŸŖ", "🍤", "🍙", + "🍚", "🍜", "🍲", "🍛", "🍱", "đŸĨŸ", "đŸĻ", "🍧", "🍨", "🍩", + "đŸĒ", "🎂", "🍰", "🧁", "đŸĢ", "đŸŦ", "🍭", "🍮", "☕", "đŸĩ", + "đŸĨ¤", "🧃", "🍷", "🍸", "🍹", "đŸē", "đŸĨ‚", "đŸĨƒ", "đŸļ", "🐱", + "🐭", "🐹", "🐰", "đŸĻŠ", "đŸģ", "đŸŧ", "🐨", "đŸ¯", "đŸĻ", "🐮", + "🐷", "đŸŊ", "🐴", "đŸĻ„", "đŸĻ“", "đŸĻ’", "🐘", "đŸĻ", "đŸĒ", "đŸĢ", + "🐑", "🐐", "🐓", "🐔", "đŸŖ", "🐤", "đŸĻ", "đŸĻ…", "đŸĻ‡", "đŸĻ‰", + "đŸē", "🐍", "đŸĸ", "đŸĻŽ", "🐙", "đŸĻ‘", "đŸĻ", "đŸĻ€", "🐡", "🐠", + "🐟", "đŸŦ", "đŸŗ", "đŸĻˆ", "🐊", "🐅", "🐆", "🐾", "đŸĻ‹", "🐞", + "🐝", "🐜", "đŸ•ˇī¸", "đŸ•¸ī¸", "🌸", "🌹", "đŸŒē", "đŸŒģ", "đŸŒŧ", "🌷", + "🌱", "🌲", "đŸŒŗ", "🌴", "đŸŒĩ", "🌾", "đŸŒŋ", "🍀", "🍁", "🍂", + "🍃", "⭐", "🌟", "✨", "âšĄī¸", "â˜„ī¸", "â˜€ī¸", "đŸŒ¤ī¸", "⛅", "đŸŒĨī¸", + "â˜ī¸", "đŸŒĻī¸", "đŸŒ§ī¸", "â›ˆī¸", "đŸŒŠī¸", "â„ī¸", "đŸŒŦī¸", "💨", "🌈", "☔", + "💧", "🌊", "đŸ”Ĩ", "đŸ’Ĩ", "⛄", "🌋", "â›°ī¸", "đŸ”ī¸", "đŸ•ī¸", "đŸ–ī¸", + "đŸœī¸", "đŸī¸", "đŸžī¸", "đŸŸī¸", "🏠", "🏡", "đŸĸ", "đŸŖ", "🏤", "đŸĨ", + "đŸĻ", "🏨", "🏩", "đŸĒ", "đŸĢ", "đŸŦ", "🏭", "đŸ¯", "🏰", "â›Ē", + "â›Šī¸", "🕌", "🕍", "đŸ—ŋ", "🎡", "đŸŽĸ", "🎠", "đŸŽĒ", "🎨", "đŸŽŦ", + "🎤", "🎧", "đŸŽŧ", "🎹", "đŸŽē", "🎸", "đŸĨ", "đŸŽģ", "🎮", "🎲" +]) + +def render_markdown_template(template_path, output_path, context: dict): + 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}")