Skip to content

Commit

Permalink
address jamie's comments: change logic to skip_unlocking + move early…
Browse files Browse the repository at this point in the history
… return up in jade client
  • Loading branch information
moneymanolis committed Mar 14, 2024
1 parent ea5eeb8 commit 473b202
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
19 changes: 11 additions & 8 deletions src/cryptoadvance/specter/devices/hwi/jade.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def __init__(
password: Optional[str] = None,
expert: bool = False,
chain: Chain = Chain.MAIN,
unlock: bool = True,
skip_unlocking: bool = False,
timeout: Optional[int] = None,
) -> None:
super(JadeClient, self).__init__(path, password, expert, chain)
Expand All @@ -166,15 +166,15 @@ def __init__(
)
else:
if uninitialized:
if skip_unlocking:
# We don't want to prompt to unlock the device right now
return
if not HAS_NETWORKING:
# Wallet not initialised/unlocked nor do we have networking dependencies
# User must use 'Recovery Phrase Login' or 'QR Unlock' feature to access wallet
raise DeviceNotReadyError(
'Use "Recovery Phrase Login" or "QR PIN Unlock" feature on Jade hw to access wallet'
)
if not unlock:
# We don't want to prompt to unlock the device right now
return

# Push some host entropy into jade
self.jade.add_entropy(os.urandom(32))
Expand Down Expand Up @@ -717,7 +717,7 @@ def enumerate(
password: Optional[str] = None,
expert: bool = False,
chain: Chain = Chain.MAIN,
unlock=True,
skip_unlocking=True,
) -> List[Dict[str, Any]]:
results = []

Expand All @@ -731,9 +731,12 @@ def _get_device_entry(device_model: str, device_path: str) -> Dict[str, Any]:

client = None
with handle_errors(common_err_msgs["enumerate"], d_data):
client = JadeClient(device_path, password, expert, chain, unlock, timeout=1)
# We don't get the fingerprint from a locked Jade
if client and unlock:
client = JadeClient(
device_path, password, expert, chain, skip_unlocking, timeout=1
)
# The Jade could already be unlocked upon startup (this is the only instance where unlock_required is False right now).
# But, we don't need the fingerpint then.
if client and not skip_unlocking:
d_data["fingerprint"] = client.get_master_fingerprint().hex()
if client:
client.close()
Expand Down
7 changes: 4 additions & 3 deletions src/cryptoadvance/specter/hwi_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,11 @@ def enumerate(self, passphrase="", chain=""):
try:
# Special handling of the Jade to unsure it is not prompting to unlock the device on startup
if devcls.__name__ == "Jade":
unlock = not self.is_startup
skip_unlocking = self.is_startup
client_chain = Chain.argparse(chain) # This returns an enum member
devs = devcls.enumerate(unlock=unlock, chain=client_chain)
devs = devcls.enumerate(
skip_unlocking=skip_unlocking, chain=client_chain
)
else:
if passphrase:
devs = devcls.enumerate(passphrase)
Expand Down Expand Up @@ -449,7 +451,6 @@ def _get_client(
password=passphrase,
expert=False,
chain=client_chain,
unlock=True,
)
else:
client = devcls.get_client(device["path"], passphrase)
Expand Down

0 comments on commit 473b202

Please sign in to comment.