Skip to content

Commit

Permalink
Merge branch 'develop' into directories_show_slash
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean Do committed Jul 19, 2024
2 parents 8c9b058 + 5c42590 commit 8bd8cbe
Show file tree
Hide file tree
Showing 21 changed files with 131 additions and 88 deletions.
2 changes: 1 addition & 1 deletion docs/getting-started/usage/navigating-the-main-menu.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ This metal backup format represents the BIP-39 mnemonic word's numbers (1-2048)

### Extended Public Key

A menu will be presented with options to display your master extended public key (xPub) as text and as a QR code. Depending on the script type or whether a single-sig or multisig wallet was loaded, the options shown will be xPub, yPub, zPub, or ZPub. When displayed as text, the extended public key can be stored on an SD card if available. If you choose to export a QR code, you can not only scan it but also save it as an image on an SD card or print it if a thermal printer is attached.
A menu will be presented with options to display your master extended public key (xpub) as text and as a QR code. Depending on the script type or whether a single-sig or multisig wallet was loaded, the options shown will be xpub, ypub, zpub, or Zpub. When displayed as text, the extended public key can be stored on an SD card if available. If you choose to export a QR code, you can not only scan it but also save it as an image on an SD card or print it if a thermal printer is attached.

<img src="../../../img/maixpy_m5stickv/extended-public-key-menu-125.png" align="bottom">
<img src="../../../img/maixpy_m5stickv/extended-public-key-wsh-xpub-text-125.png" align="bottom">
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

[tool.poetry]
name = "krux"
version = "24.07.0"
version = "24.09.beta0"
description = "Open-source signing device firmware for Bitcoin"
authors = ["Jeff S <[email protected]>"]

Expand Down
3 changes: 2 additions & 1 deletion src/krux/encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import ucryptolib
from .baseconv import base_encode, base_decode
from .sd_card import SDHandler
from .krux_settings import Settings, PBKDF2_HMAC_ECB, PBKDF2_HMAC_CBC, AES_BLOCK_SIZE
from .krux_settings import Settings, PBKDF2_HMAC_ECB, PBKDF2_HMAC_CBC
from embit.wordlists.bip39 import WORDLIST


Expand All @@ -47,6 +47,7 @@
"AES-CBC": PBKDF2_HMAC_CBC,
}

AES_BLOCK_SIZE = 16
QR_CODE_ITER_MULTIPLE = 10000


Expand Down
7 changes: 7 additions & 0 deletions src/krux/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@
# address starts with bc1p (mainnet) or tb1p (testnet)
P2TR = "p2tr"

SCRIPT_LONG_NAMES = {
"Legacy - 44": P2PKH,
"Nested Segwit - 49": P2SH_P2WPKH,
"Native Segwit - 84": P2WPKH,
"Taproot - 86": P2TR,
}

SINGLESIG_SCRIPT_PURPOSE = {
P2PKH: 44,
P2SH_P2WPKH: 49,
Expand Down
19 changes: 11 additions & 8 deletions src/krux/krux_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

import board
import binascii
from .settings import (
SettingsNamespace,
CategorySetting,
Expand All @@ -29,9 +30,8 @@
MAIN_TXT,
TEST_TXT,
)
import board
import binascii
from .translations import translation_table
from .key import SCRIPT_LONG_NAMES

BAUDRATES = [1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200]

Expand All @@ -50,7 +50,6 @@
# Encription Versions
PBKDF2_HMAC_ECB = 0
PBKDF2_HMAC_CBC = 1
AES_BLOCK_SIZE = 16

THERMAL_ADAFRUIT_TXT = "thermal/adafruit"

Expand All @@ -77,12 +76,16 @@ class DefaultWallet(SettingsNamespace):
namespace = "settings.wallet"
network = CategorySetting("network", MAIN_TXT, [MAIN_TXT, TEST_TXT])
multisig = CategorySetting("multisig", False, [False, True])
script_type = CategorySetting(
"script_type", "Native Segwit - 84", list(SCRIPT_LONG_NAMES.keys())
)

def label(self, attr):
"""Returns a label for UI when given a setting name or namespace"""
return {
"network": t("Network"),
"multisig": t("Multisig"),
"script_type": t("Script Type"),
}[attr]


Expand Down Expand Up @@ -242,10 +245,10 @@ def label(self, attr):
}[attr]


class AmgDisplaySettings(SettingsNamespace):
class DisplayAmgSettings(SettingsNamespace):
"""Custom display settings for Maix Amigo"""

namespace = "settings.amg_display"
namespace = "settings.display_amg"
flipped_x_coordinates = CategorySetting("flipped_x", True, [False, True])
inverted_colors = CategorySetting("inverted_colors", True, [False, True])
bgr_colors = CategorySetting("bgr_colors", True, [False, True])
Expand Down Expand Up @@ -288,7 +291,7 @@ def __init__(self):
if board.config["type"] in ["amigo", "yahboom"]:
self.touch = TouchSettings()
if board.config["type"] == "amigo":
self.display = AmgDisplaySettings()
self.display = DisplayAmgSettings()
elif board.config["type"] in ["cube", "m5stickv"]:
self.display = DisplaySettings()

Expand All @@ -302,7 +305,7 @@ def label(self, attr):
if board.config["type"] in ["amigo", "yahboom"]:
hardware_menu["touchscreen"] = t("Touchscreen")
if board.config["type"] == "amigo":
hardware_menu["amg_display"] = t("Display")
hardware_menu["display_amg"] = t("Display")
elif board.config["type"] in ["cube", "m5stickv"]:
hardware_menu["display"] = t("Display")

Expand Down
2 changes: 1 addition & 1 deletion src/krux/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
VERSION = "24.07.0"
VERSION = "24.09.beta0"
SIGNER_PUBKEY = "03339e883157e45891e61ca9df4cd3bb895ef32d475b8e793559ea10a36766689b"
36 changes: 20 additions & 16 deletions src/krux/pages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
FIXED_KEYS = 3 # 'More' key only appears when there are multiple keysets

ANTI_GLARE_WAIT_TIME = 500
QR_CODE_STEP_TIME = 100
SHUTDOWN_WAIT_TIME = 300

TOGGLE_BRIGHTNESS = (BUTTON_PAGE, BUTTON_PAGE_PREV)
Expand Down Expand Up @@ -109,7 +108,7 @@ def load_method(self):
t("Load from SD card"),
None if not self.has_sd_card() else lambda: None,
),
(t("Back"), lambda: None),
cta_back(lambda: None),
],
)
index, _ = load_menu.run_loop()
Expand Down Expand Up @@ -266,7 +265,6 @@ def callback(part_total, num_parts_captured, new_part):
15,
theme.fg_color,
)
time.sleep_ms(QR_CODE_STEP_TIME)
self.ctx.display.to_landscape()

return 0
Expand Down Expand Up @@ -405,9 +403,9 @@ def prompt(self, text, offset_y=0):
self.x_keypad_map.append(DEFAULT_PADDING)
self.x_keypad_map.append(self.ctx.display.width() // 2)
self.x_keypad_map.append(self.ctx.display.width() - DEFAULT_PADDING)
y_key_map = offset_y - FONT_HEIGHT // 2
y_key_map = offset_y - (3 * FONT_HEIGHT // 2)
self.y_keypad_map.append(y_key_map)
y_key_map += 2 * FONT_HEIGHT
y_key_map += 4 * FONT_HEIGHT
self.y_keypad_map.append(y_key_map)
if self.ctx.input.touch is not None:
self.ctx.input.touch.clear_regions()
Expand Down Expand Up @@ -448,9 +446,9 @@ def prompt(self, text, offset_y=0):
for region in self.x_keypad_map:
self.ctx.display.draw_line(
region,
self.y_keypad_map[0],
self.y_keypad_map[0] + FONT_HEIGHT,
region,
self.y_keypad_map[0] + 2 * FONT_HEIGHT,
self.y_keypad_map[0] + 3 * FONT_HEIGHT,
theme.frame_color,
)
btn = self.ctx.input.wait_for_button()
Expand Down Expand Up @@ -802,6 +800,8 @@ def _draw_touch_menu(self, selected_item_index):
Page.y_keypad_map = [
int(n * height_multiplier) + self.menu_offset for n in Page.y_keypad_map
]
# Expand last region to the bottom of the screen
Page.y_keypad_map[-1] = self.ctx.display.height()
self.ctx.input.touch.y_regions = Page.y_keypad_map

# draw dividers and outline
Expand All @@ -816,6 +816,9 @@ def _draw_touch_menu(self, selected_item_index):
menu_item_lines = self.ctx.display.to_lines(menu_item[0])
offset_y = Page.y_keypad_map[i + 1] - Page.y_keypad_map[i]
offset_y -= len(menu_item_lines) * FONT_HEIGHT
if i == len(self.menu_view) - 1:
# Compensate for the expanded last region
offset_y -= DEFAULT_PADDING
offset_y //= 2
offset_y += Page.y_keypad_map[i]
fg_color = (
Expand Down Expand Up @@ -902,15 +905,16 @@ def choose_len_mnemonic(ctx):
submenu = Menu(
ctx,
[
(t("12 words"), lambda: MENU_EXIT),
(t("24 words"), lambda: MENU_EXIT),
(t("Back"), lambda: MENU_EXIT),
(t("12 words"), lambda: 12),
(t("24 words"), lambda: 24),
cta_back(lambda: None),
],
)
index, _ = submenu.run_loop()
_, num_words = submenu.run_loop()
ctx.display.clear()
if index == 0:
return 12
if index == 1:
return 24
return None
return num_words


def cta_back(status=lambda: MENU_EXIT, label=t("Back")):
"""Reusable 'call-to-action: go back'. Currently a menu item tuple"""
return ("< " + label, status)
3 changes: 2 additions & 1 deletion src/krux/pages/encryption_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
# THE SOFTWARE.

from ..display import BOTTOM_PROMPT_LINE
from ..krux_settings import t, Settings, AES_BLOCK_SIZE
from ..krux_settings import t, Settings
from ..encryption import AES_BLOCK_SIZE
from . import (
Page,
Menu,
Expand Down
4 changes: 2 additions & 2 deletions src/krux/pages/file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import board
import gc
from . import Page, Menu, MENU_EXIT, MENU_CONTINUE
from . import Page, Menu, MENU_EXIT, MENU_CONTINUE, cta_back
from ..sd_card import SDHandler
from ..krux_settings import t
from ..format import generate_thousands_separator, render_decimal_separator
Expand Down Expand Up @@ -119,7 +119,7 @@ def select_file(

# We need to add this option because /sd can be empty!
items.append("Back")
menu_items.append((t("Back"), lambda: MENU_EXIT))
menu_items.append(cta_back())

submenu = Menu(self.ctx, menu_items)
index, _ = submenu.run_loop()
Expand Down
7 changes: 4 additions & 3 deletions src/krux/pages/home_pages/addresses.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
Menu,
MENU_CONTINUE,
MENU_EXIT,
cta_back,
)

SCAN_ADDRESS_LIMIT = 50
Expand All @@ -50,7 +51,7 @@ def addresses_menu(self):
(t("Scan Address"), self.pre_scan_address),
(t("Receive Addresses"), self.list_address_type),
(t("Change Addresses"), lambda: self.list_address_type(1)),
(t("Back"), lambda: None),
cta_back(),
],
)
submenu.run_loop()
Expand Down Expand Up @@ -102,7 +103,7 @@ def list_address_type(self, addr_type=0):
lambda: MENU_EXIT,
)
)
items.append((t("Back"), lambda: MENU_EXIT))
items.append(cta_back())

submenu = Menu(self.ctx, items)
stay_on_this_addr_menu = True
Expand Down Expand Up @@ -137,7 +138,7 @@ def pre_scan_address(self):
[
(t("Receive"), self.scan_address),
(t("Change"), lambda: self.scan_address(1)),
(t("Back"), lambda: MENU_EXIT),
cta_back(),
],
)
submenu.run_loop()
Expand Down
8 changes: 4 additions & 4 deletions src/krux/pages/home_pages/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
Page,
Menu,
MENU_CONTINUE,
MENU_EXIT,
ESC_KEY,
LOAD_FROM_CAMERA,
LOAD_FROM_SD,
cta_back,
)

MAX_POLICY_COSIGNERS_DISPLAYED = 5
Expand Down Expand Up @@ -169,7 +169,7 @@ def wallet(self):
(t("Passphrase"), self.passphrase),
(t("Customize"), self.customize),
("BIP85", self.bip85),
(t("Back"), lambda: MENU_EXIT),
cta_back(),
],
)
submenu.run_loop()
Expand All @@ -189,7 +189,7 @@ def sign(self):
[
("PSBT", self.sign_psbt),
(t("Message"), self.sign_message),
(t("Back"), lambda: MENU_EXIT),
cta_back(),
],
)
index, status = submenu.run_loop()
Expand Down Expand Up @@ -228,7 +228,7 @@ def _sign_menu(self):
t("Sign to SD card"),
None if not self.has_sd_card() else lambda: None,
),
(t("Back"), lambda: None),
cta_back(lambda: None),
],
)
index, _ = sign_menu.run_loop()
Expand Down
10 changes: 5 additions & 5 deletions src/krux/pages/home_pages/mnemonic_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
Page,
Menu,
MENU_CONTINUE,
MENU_EXIT,
cta_back,
)


Expand All @@ -42,7 +42,7 @@ def mnemonic(self):
(t("QR Code"), self.qr_code_backup),
(t("Encrypted"), self.encrypt_mnemonic_menu),
(t("Other Formats"), self.other_backup_formats),
(t("Back"), lambda: MENU_EXIT),
cta_back(),
],
)
submenu.run_loop()
Expand All @@ -57,7 +57,7 @@ def qr_code_backup(self):
("Compact SeedQR", lambda: self.display_seed_qr(True)),
("SeedQR", self.display_seed_qr),
(t("Encrypted QR Code"), self.encrypt_qr_code),
(t("Back"), lambda: MENU_EXIT),
cta_back(),
],
)
submenu.run_loop()
Expand All @@ -77,7 +77,7 @@ def other_backup_formats(self):
(t("Numbers"), self.display_mnemonic_numbers),
("Stackbit 1248", self.stackbit),
("Tiny Seed", self.tiny_seed),
(t("Back"), lambda: MENU_EXIT),
cta_back(),
],
)
submenu.run_loop()
Expand Down Expand Up @@ -149,7 +149,7 @@ def display_mnemonic_numbers(self):
Utils.BASE_OCT_SUFFIX,
),
),
(t("Back"), lambda: MENU_EXIT),
cta_back(),
],
)
submenu.run_loop()
Expand Down
5 changes: 3 additions & 2 deletions src/krux/pages/home_pages/pub_key_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
Menu,
MENU_CONTINUE,
MENU_EXIT,
cta_back,
)
from ...sd_card import PUBKEY_FILE_EXTENSION
from ...key import P2SH_P2WPKH, P2SH_P2WSH, P2WPKH, P2WSH
Expand Down Expand Up @@ -68,7 +69,7 @@ def _pub_key_text(version):
else lambda: _save_xpub_to_sd(version)
),
),
(t("Back"), lambda: MENU_EXIT),
cta_back(),
]
full_pub_key = self.ctx.wallet.key.account_pubkey_str(version)
menu_offset = 5 + len(self.ctx.display.to_lines(full_pub_key))
Expand Down Expand Up @@ -116,7 +117,7 @@ def _pub_key_qr(version):
pub_key_menu_items.append(
(title + " - " + t("QR Code"), lambda ver=version: _pub_key_qr(ver))
)
pub_key_menu_items.append((t("Back"), lambda: MENU_EXIT))
pub_key_menu_items.append(cta_back())
pub_key_menu = Menu(self.ctx, pub_key_menu_items)
while True:
_, status = pub_key_menu.run_loop()
Expand Down
Loading

0 comments on commit 8bd8cbe

Please sign in to comment.