Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hardware wallet fixes #416

Merged
merged 4 commits into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 29 additions & 24 deletions src/cryptoadvance/specter/hwi_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,35 @@ def enumerate(self, passphrase='', chain=''):
devices = []
# going through all device classes
for devcls in hwi_classes:
# calling device-specific enumerate
if passphrase is not None:
devs = devcls.enumerate(passphrase)
# not sure if it will handle passphrase correctly
# so remove it if None
else:
devs = devcls.enumerate()
# extracting fingerprint info
for dev in devs:
# we can't get fingerprint if device is locked
if "needs_pin_sent" in dev and dev["needs_pin_sent"]:
continue
# we can't get fingerprint if passphrase is not provided
if ("needs_passphrase_sent" in dev
and dev["needs_passphrase_sent"]
and passphrase is None
):
continue
client = devcls.get_client(dev["path"], passphrase)
try:
dev['fingerprint'] = client.get_master_fingerprint_hex()
finally:
client.close()
devices += devs
try:
# calling device-specific enumerate
if passphrase is not None:
devs = devcls.enumerate(passphrase)
# not sure if it will handle passphrase correctly
# so remove it if None
else:
devs = devcls.enumerate()
# extracting fingerprint info
for dev in devs:
# we can't get fingerprint if device is locked
if "needs_pin_sent" in dev and dev["needs_pin_sent"]:
continue
# we can't get fingerprint if passphrase is not provided
if ("needs_passphrase_sent" in dev
and dev["needs_passphrase_sent"]
and passphrase is None
):
continue
client = None
try:
client = devcls.get_client(dev["path"], passphrase)
dev['fingerprint'] = client.get_master_fingerprint_hex()
finally:
if client is not None:
client.close()
devices += devs
except Exception as e:
logger.warn(f"enumerate failed: {e}")

self.devices = devices
return self.devices
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
{% set supports_hwi = supports_hwi.append(device) %}
{% endfor %}
{% if supports_hwi != [] and (supports_hwi_multisig_display_address != [] or not wallet.is_multisig) %}
<button type="button" onclick="displayAddressOnDevice(`{{ wallet.address }}`, `{{ (wallet.rpc.getaddressinfo(wallet.address)['desc']) }}`)" class="btn centered optional">Display address on device</button><br>
<button type="button" onclick="displayAddressOnDevice(`{{ wallet.address }}`, `{{ wallet.get_descriptor() }}`)" class="btn centered optional">Display address on device</button><br>
{% if wallet.is_multisig %}
<p class="note center optional">Multsig address on-device display is only available for ColdCard, KeepKey, Specter, and Trezor devices.</p>
{% endif %}
Expand All @@ -96,7 +96,7 @@
<button onclick="verifyQRCode('{{ address }}', '{{ loop.index0 }}')" type="button" class="btn" style="width:170px; float: left; margin-right: 20px; margin-bottom: 2px; margin-top: 2px;">Verify address via QR code</button>
{% endif %}
{% if supports_hwi != [] and (supports_hwi_multisig_display_address != [] or not wallet.is_multisig) %}
<button type="button" onclick="displayAddressOnDevice(`{{ address }}`, `{{ (wallet.rpc.getaddressinfo(address)['desc']) }}`)" class="btn" style="width:170px; margin-bottom: 2px; margin-top: 2px;">Display address on device</button>
<button type="button" onclick="displayAddressOnDevice(`{{ address }}`, `{{ wallet.get_descriptor(loop.revindex0) }}`)" class="btn" style="width:170px; margin-bottom: 2px; margin-top: 2px;">Display address on device</button>
{% endif %}
</td>
</tr>
Expand Down
16 changes: 16 additions & 0 deletions src/cryptoadvance/specter/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,22 @@ def get_address(self, index, change=False):
return addr
return self.rpc.deriveaddresses(desc, [index, index + 1])[0]

def get_descriptor(self, index=None, change=False, address=None):
"""
Returns address descriptor from index, change
or from address belonging to the wallet.
"""
if address is not None:
d = self.rpc.getaddressinfo(address)['desc']
path = d.split("[")[1].split("]")[0].split("/")
change = bool(int(path[-2]))
index = int(path[-1])
if index is None:
index = self.change_index if change else self.address_index
desc = self.change_descriptor if change else self.recv_descriptor
desc = desc.split("#")[0]
return AddChecksum(desc.replace("*",f"{index}"))

def get_balance(self):
try:
self.balance = self.rpc.getbalances()["watchonly"]
Expand Down