Skip to content

Commit

Permalink
improve readability of code, some comments and example
Browse files Browse the repository at this point in the history
  • Loading branch information
moneymanolis committed Jan 1, 2025
1 parent 690e4fb commit aeea104
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions src/cryptoadvance/specter/devices/jade.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,40 +48,53 @@ def create_psbts(self, base64_psbt, wallet):
psbts["qrcode"] = f"{self.supported_qr_code_format}:{qr_psbt}"
return psbts

# Enables the export of a multisig wallet to a Jade via QR
def export_wallet(self, wallet):
if not wallet.is_multisig:
return None
# Jade uses ColdCard's style
# Jade uses ColdCard's style (assumes derivaion paths of the keys to be the same)
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(
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 += "{}: {}\n".format(
fingerprint.upper(),
k.xpub,
)

qr_string = b2a_base64(qr_string.encode()).decode()
return f"ur-bytes:{qr_string}"

# Example output:
# """
# Name: MyWallet
# Policy: 2 of 3
# Derivation: m/48'/1'/0'/2'
# Format: P2WSH
# Sorted: False
# A1B2C3D4: tpubD6NzVbkrYhZ...
# F2E3D4C5: tpubE6NzVhkxF7Q...
# """

0 comments on commit aeea104

Please sign in to comment.