Skip to content

Add selection of trezor device#1895

Closed
OBorce wants to merge 2 commits into
feature/trezor-standalone-keysfrom
feature/trezor-device-selection
Closed

Add selection of trezor device#1895
OBorce wants to merge 2 commits into
feature/trezor-standalone-keysfrom
feature/trezor-device-selection

Conversation

@OBorce

@OBorce OBorce commented Mar 20, 2025

Copy link
Copy Markdown
Contributor
  • add a choice menu for the CLI wallet to select a trezor device if there are multiple devices available
  • add optional parameters to the create and recover wallet commands to specify a trezor device name or device ID
  • Fixed the leftover empty wallet when a create wallet command fails

@OBorce OBorce force-pushed the feature/trezor-device-selection branch from 1867f28 to 7c3dca3 Compare March 20, 2025 09:12

@ImplOfAnImpl ImplOfAnImpl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't look at the UI part of the manual device selection yet, I only looked at the "automatic" selection logic.

The automatic selection didn't work for me out of the box - I connected 2 devices and opening a wallet immediately produced "No connected Trezor device found". Both in GUI and in CLI.
Turns out my wallet was created before I reset my device (wchich also resets the device id), so the device_id stored in the file was no longer relevant.
I guess we should always update the trezor data in the db once the wallet is successfully opened and keys are checked. This way the device id in the file will always be the latest one.

Anyway, as I've said in #1874, it's better to extract the automatic selection logic from this PR into 1874 and fix all the issues there as well.

Comment thread wallet/src/signer/trezor_signer/mod.rs Outdated
Comment on lines +123 to +128
impl PartialEq<FoundDevice> for SelectedDevice {
fn eq(&self, other: &FoundDevice) -> bool {
self.name.as_ref().is_none_or(|name| name == &other.name)
&& self.device_id.as_ref().is_none_or(|id| id == &other.device_id)
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's a good idea to compare labels when looking for a device. I think SelectedDevice should only contain device_id. Also, it should be non-optional, and Option<SelectedDevice> should be passed around instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed name

Comment thread wallet/src/signer/trezor_signer/mod.rs Outdated
Comment on lines +1471 to +1489
let selected = SelectedDevice::NONE;
let (client, data, session_id) = match find_trezor_device(selected) {
Ok(data) => (data.0, data.1, data.2),
Err(TrezorError::NoUniqueDeviceFound(_)) => {
if let Some(HardwareWalletData::Trezor(data)) = db_tx.get_hardware_wallet_data()? {
let selected = SelectedDevice {
device_id: Some(data.device_id),
name: Some(data.label),
};

find_trezor_device(selected).map_err(SignerError::TrezorError)?
} else {
return Err(
SignerError::TrezorError(TrezorError::MissingHardwareWalletData).into(),
);
}
}
Err(err) => return Err(SignerError::TrezorError(err).into()),
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the logic should be reversed - first we should look for the device with the device id stored in the db. And if it's not found, then we can try connecting to whatever device we have, provided that there is only one device.

Also, we shouldn't need 2 calls of find_trezor_device for that - find_trezor_device can itself choose the device.

Comment thread wallet/src/signer/trezor_signer/mod.rs Outdated
Comment on lines +211 to +212
let selected = SelectedDevice::NONE;
let (mut new_client, data, session_id) = find_trezor_device(selected)?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The device selection logic should work for reconnections too.

Comment on lines +653 to +656
pub struct FoundDevice {
pub name: String,
pub device_id: String,
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name will be empty if the label was never set (or if it was removed). I guess you have to obtain the model name too and then use it instead if the label is empty (it looks like Trezor Suite does exactly this).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed to choose the label if not empty or use the model name

@OBorce OBorce marked this pull request as draft March 25, 2025 10:01
@OBorce OBorce closed this Mar 26, 2025
@ImplOfAnImpl ImplOfAnImpl deleted the feature/trezor-device-selection branch February 4, 2026 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants