Skip to content

Commit

Permalink
Merge #438: Add label field to enumerate
Browse files Browse the repository at this point in the history
8e6d167 Add tests for setting/getting device label (Pavol Rusnak)
f8797b2 Apply label on trezor.setup_device (Pavol Rusnak)
255f567 Add label field to enumerate (Pavol Rusnak)

Pull request description:

  I don't have other devices except Trezor, so maybe others can help with how to retrieve labels for the rest.

ACKs for top commit:
  achow101:
    ACK 8e6d167

Tree-SHA512: d4bdead7d8ccaa72ef9d31aaee318d7c96f4f5e2a36fffee1ca0a91b7dafbc5996a5e224be023e0e34d25f01a2472bcd1497d5c4d00ac5d8333c0229b9645fe2
  • Loading branch information
achow101 committed Oct 24, 2021
2 parents cc5012a + 8e6d167 commit d564b27
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions hwilib/devices/coldcard.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ def enumerate(password: str = "") -> List[Dict[str, Any]]:
path = d['path'].decode()
d_data['type'] = 'coldcard'
d_data['model'] = 'coldcard'
d_data['label'] = None
d_data['path'] = path
d_data['needs_pin_sent'] = False
d_data['needs_passphrase_sent'] = False
Expand Down
1 change: 1 addition & 0 deletions hwilib/devices/digitalbitbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ def enumerate(password: str = "") -> List[Dict[str, Any]]:
path = d['path'].decode()
d_data['type'] = 'digitalbitbox'
d_data['model'] = 'digitalbitbox_01'
d_data['label'] = None
if path == 'udp:127.0.0.1:35345':
d_data['model'] += '_simulator'
d_data['path'] = path
Expand Down
1 change: 1 addition & 0 deletions hwilib/devices/keepkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ def enumerate(password: str = "") -> List[Dict[str, Any]]:
if 'keepkey' not in client.client.features.vendor:
continue

d_data['label'] = client.client.features.label
if d_data['path'].startswith('udp:'):
d_data['model'] += '_simulator'

Expand Down
1 change: 1 addition & 0 deletions hwilib/devices/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ def enumerate(password: str = '') -> List[Dict[str, Any]]:
d_data['model'] = LEDGER_LEGACY_PRODUCT_IDS[d['product_id']]
else:
continue
d_data['label'] = None
d_data['path'] = path

if path == SIMULATOR_PATH:
Expand Down
5 changes: 3 additions & 2 deletions hwilib/devices/trezor.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ def setup_device(self, label: str = "", passphrase: str = "") -> bool:

if self.client.features.initialized:
raise DeviceAlreadyInitError('Device is already initialized. Use wipe first and try again')
device.reset(self.client, passphrase_protection=bool(self.password))
device.reset(self.client, label=label or None, passphrase_protection=bool(self.password))
return True

@trezor_exception
Expand All @@ -693,7 +693,7 @@ def restore_device(self, label: str = "", word_count: int = 24) -> bool:
# Use interactive_get_pin
self.client.ui.get_pin = MethodType(interactive_get_pin, self.client.ui)

device.recover(self.client, word_count=word_count, label=label, input_callback=mnemonic_words(), passphrase_protection=bool(self.password))
device.recover(self.client, word_count=word_count, label=label or None, input_callback=mnemonic_words(), passphrase_protection=bool(self.password))
return True

def backup_device(self, label: str = "", passphrase: str = "") -> bool:
Expand Down Expand Up @@ -775,6 +775,7 @@ def enumerate(password: str = "") -> List[Dict[str, Any]]:
if 'trezor' not in client.client.features.vendor:
continue

d_data['label'] = client.client.features.label
d_data['model'] = 'trezor_' + client.client.features.model.lower()
if d_data['path'].startswith('udp:'):
d_data['model'] += '_simulator'
Expand Down
8 changes: 7 additions & 1 deletion test/test_keepkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,20 @@ def test_setup_wipe(self):
t_client = KeepkeyClient('udp:127.0.0.1:11044', 'test')
t_client.client.ui.get_pin = MethodType(get_pin, t_client.client.ui)
t_client.client.ui.pin = '1234'
result = t_client.setup_device()
result = t_client.setup_device(label='HWI Keepkey')
self.assertTrue(result)

# Make sure device is init, setup should fail
result = self.do_command(self.dev_args + ['-i', 'setup'])
self.assertEquals(result['code'], -10)
self.assertEquals(result['error'], 'Device is already initialized. Use wipe first and try again')

def test_label(self):
result = self.do_command(self.dev_args + ['enumerate'])
for dev in result:
if dev['type'] == 'trezor' and dev['path'] == 'udp:127.0.0.1:11044':
self.assertEqual(result['label'], 'HWI Keepkey')

def test_backup(self):
result = self.do_command(self.dev_args + ['backup'])
self.assertIn('error', result)
Expand Down
8 changes: 7 additions & 1 deletion test/test_trezor.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,20 @@ def test_setup_wipe(self):
t_client = TrezorClient('udp:127.0.0.1:21324', 'test')
t_client.client.ui.get_pin = MethodType(get_pin, t_client.client.ui)
t_client.client.ui.pin = '1234'
result = t_client.setup_device()
result = t_client.setup_device(label='HWI Trezor')
self.assertTrue(result)

# Make sure device is init, setup should fail
result = self.do_command(self.dev_args + ['-i', 'setup'])
self.assertEquals(result['code'], -10)
self.assertEquals(result['error'], 'Device is already initialized. Use wipe first and try again')

def test_label(self):
result = self.do_command(self.dev_args + ['enumerate'])
for dev in result:
if dev['type'] == 'trezor' and dev['path'] == 'udp:127.0.0.1:21324':
self.assertEqual(result['label'], 'HWI Trezor')

def test_backup(self):
result = self.do_command(self.dev_args + ['backup'])
self.assertIn('error', result)
Expand Down

0 comments on commit d564b27

Please sign in to comment.