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

Feature: Add wallet export to Jade via QR #2370

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
44 changes: 43 additions & 1 deletion src/cryptoadvance/specter/devices/jade.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from .hwi_device import HWIDevice
from .hwi.jade import JadeClient
from .hwi.jade import enumerate as jade_enumerate
from ..helpers import is_liquid
from ..helpers import is_liquid, to_ascii20
from ..util import bcur
from binascii import b2a_base64


class Jade(HWIDevice):
Expand All @@ -17,6 +19,8 @@ class Jade(HWIDevice):
supports_hwi_toggle_passphrase = False
supports_hwi_multisig_display_address = True
liquid_support = True
exportable_to_wallet = True
wallet_export_type = "qr"

@classmethod
def get_client(cls, *args, **kwargs):
Expand All @@ -42,3 +46,41 @@ def create_psbts(self, base64_psbt, wallet):
qr_psbt = wallet.fill_psbt(base64_psbt, non_witness=False, xpubs=False)
psbts["qrcode"] = f"{self.supported_qr_code_format}:{qr_psbt}"
return psbts

def export_wallet(self, wallet):
if not wallet.is_multisig:
return None
# Jade uses ColdCard's style
CC_TYPES = {"legacy": "BIP45", "p2sh-segwit": "P2WSH-P2SH", "bech32": "P2WSH"}
# try to find at least one derivation
# cc assume the same derivation for all keys :(
derivation = None
# find correct key
for k in wallet.keys:
if k in self.keys and k.derivation != "":
derivation = k.derivation.replace("h", "'")
break
if derivation is None:
return None
qr_string = """
Name: {}
Policy: {} of {}
Derivation: {}
Format: {}
Sorted: {}
""".format(
to_ascii20(wallet.name),
wallet.sigs_required,
len(wallet.keys),
derivation,
CC_TYPES[wallet.address_type],
not wallet.uses_multi,
)
for k in wallet.keys:
# cc assumes fingerprint is known
fingerprint = k.fingerprint
if fingerprint == "":
fingerprint = get_xpub_fingerprint(k.xpub).hex()
qr_string += "{}: {}\n".format(fingerprint.upper(), k.xpub)
qr_string = b2a_base64(qr_string.encode()).decode()
return f"ur-bytes:{qr_string}"
Loading