Skip to content

Commit

Permalink
Merge pull request #406 from Foundation-Devices/SFT-36-device-names
Browse files Browse the repository at this point in the history
SFT-36: device names
  • Loading branch information
mjg-foundation authored Oct 20, 2023
2 parents 3f1111d + 29ceaeb commit 52956b5
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 3 deletions.
1 change: 1 addition & 0 deletions ports/stm32/boards/Passport/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
'flows/remove_dev_pubkey_flow.py',
'flows/rename_account_flow.py',
'flows/rename_derived_key_flow.py',
'flows/rename_device_flow.py',
'flows/rename_multisig_flow.py',
'flows/reset_pin_flow.py',
'flows/restore_backup_flow.py',
Expand Down
1 change: 1 addition & 0 deletions ports/stm32/boards/Passport/modules/flows/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
from .remove_dev_pubkey_flow import *
from .rename_account_flow import *
from .rename_derived_key_flow import *
from .rename_device_flow import *
from .rename_multisig_flow import *
from .reset_pin_flow import *
from .restore_backup_flow import *
Expand Down
3 changes: 3 additions & 0 deletions ports/stm32/boards/Passport/modules/flows/change_pin_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from utils import spinner_task
from translations import t, T
import microns
from common import settings
from serializations import sha256


class ChangePINFlow(Flow):
Expand Down Expand Up @@ -58,6 +60,7 @@ async def change_pin(self):
(result, error) = await spinner_task('Changing PIN', change_pin_task,
args=[self.old_pin, self.new_pin])
if result:
settings.set_volatile('pin_prefix_hash', sha256(self.new_pin[:4]))
self.goto(self.show_success)
else:
self.goto(self.show_error)
Expand Down
6 changes: 6 additions & 0 deletions ports/stm32/boards/Passport/modules/flows/login_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ def __init__(self):
super().__init__(initial_state=self.enter_pin, name='LoginFlow')

async def enter_pin(self):

device_name = common.settings.get('device_name', None)
if device_name is not None:
device_name = device_name.upper()

try:
(self.pin, is_done) = await PINEntryPage(
card_header={'title': 'Enter PIN'},
statusbar={'title': device_name},
security_words_message='Recognize these Security Words?',
left_micron=microns.Shutdown,
right_micron=microns.Checkmark,
Expand Down
40 changes: 40 additions & 0 deletions ports/stm32/boards/Passport/modules/flows/rename_device_flow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# SPDX-FileCopyrightText: © 2023 Foundation Devices, Inc. <[email protected]>
# SPDX-License-Identifier: GPL-3.0-or-later
#
# name_device_flow.py - Name or rename the device

from flows import Flow
from serializations import sha256
from pages import TextInputPage, ErrorPage
from common import settings
from constants import MAX_ACCOUNT_NAME_LEN
import microns


class RenameDeviceFlow(Flow):
def __init__(self):
super().__init__(initial_state=self.rename_device, name='NameDeviceFLow')

async def rename_device(self):
name = settings.get('device_name', None) or ''
result = await TextInputPage(initial_text=name,
max_length=MAX_ACCOUNT_NAME_LEN,
left_micron=microns.Cancel,
right_micron=microns.Checkmark).show()
if result is None:
self.set_result(False)
return

if len(result) == 0:
settings.set('device_name', None)
self.set_result(True)
return

prefix = result[:4]
hashes = [sha256(prefix), sha256(prefix.upper()), sha256(prefix.lower())]
if settings.get('pin_prefix_hash') in hashes:
await ErrorPage("Don't use your pin as the device name, because it will be shown on the login page.").show()
return

settings.set('device_name', result)
self.set_result(True)
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ async def confirm_new_pin(self):
from pages import PINEntryPage
from tasks import set_initial_pin_task, login_task
from utils import spinner_task
from common import settings
from serializations import sha256

(confirmed_pin, is_done) = await PINEntryPage(
card_header={'title': 'Confirm PIN'},
Expand All @@ -61,6 +63,7 @@ async def confirm_new_pin(self):
self.back()
else:
if self.new_pin == confirmed_pin:
settings.set_volatile('pin_prefix_hash', sha256(self.new_pin[:4]))

(result, error) = await spinner_task('Setting initial PIN', set_initial_pin_task,
args=[self.new_pin])
Expand Down
5 changes: 3 additions & 2 deletions ports/stm32/boards/Passport/modules/menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,17 @@ def plus_menu():


def device_menu():
from flows import AboutFlow, ChangePINFlow
from flows import AboutFlow, ChangePINFlow, RenameDeviceFlow
from pages import AutoShutdownSettingPage, BrightnessSettingPage, BatteryPage
from utils import is_logged_in

return [
{'icon': 'ICON_BRIGHTNESS', 'label': 'Screen Brightness', 'page': BrightnessSettingPage},
{'icon': 'ICON_COUNTDOWN', 'label': 'Auto-Shutdown', 'page': AutoShutdownSettingPage},
{'icon': 'ICON_PIN', 'label': 'Change PIN', 'flow': ChangePINFlow, 'is_visible': is_logged_in},
{'icon': 'ICON_INFO', 'label': 'About', 'flow': AboutFlow},
{'icon': 'ICON_BATTERY', 'label': 'Battery', 'page': BatteryPage},
{'icon': 'ICON_SIGN', 'label': 'Device Name', 'flow': RenameDeviceFlow},
{'icon': 'ICON_INFO', 'label': 'About', 'flow': AboutFlow},
]


Expand Down
5 changes: 4 additions & 1 deletion ports/stm32/boards/Passport/modules/wallets/envoy.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,17 @@ def create_envoy_export(sw_wallet=None,
if acct is not None:
acct_name = acct.get('name', '')

device_name = common.settings.get('device_name', '')

rv = dict(derivation=acct_path,
xfp=xfp,
xpub=xpub,
acct_name=acct_name,
acct_num=acct_num,
hw_version=1.2 if passport.IS_COLOR else 1,
fw_version=fw_version,
serial=serial_num)
serial=serial_num,
device_name=device_name)

# Return the possible account mappings that the exported wallet can choose from
# When we get the address back, we can determine the 'fmt' from the address and then look it up to
Expand Down

0 comments on commit 52956b5

Please sign in to comment.