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

Display descriptors for BTC Taproot accounts #3475

Closed
Hannsek opened this issue Jan 2, 2024 · 1 comment · Fixed by #3505
Closed

Display descriptors for BTC Taproot accounts #3475

Hannsek opened this issue Jan 2, 2024 · 1 comment · Fixed by #3505
Assignees
Labels
bitcoin Bitcoin related

Comments

@Hannsek
Copy link
Contributor

Hannsek commented Jan 2, 2024

Discussed here.

@Hannsek Hannsek added the bitcoin Bitcoin related label Jan 2, 2024
@Hannsek Hannsek added this to Firmware Jan 2, 2024
@Hannsek Hannsek moved this to 🎯 To do in Firmware Jan 2, 2024
@prusnak
Copy link
Member

prusnak commented Jan 2, 2024

Python code for calculating descriptors is here:

def _get_descriptor(
client: "TrezorClient",
coin: Optional[str],
account: int,
purpose: Optional[int],
script_type: Optional[messages.InputScriptType],
show_display: bool,
) -> str:
if purpose is None:
if script_type is None:
script_type = messages.InputScriptType.SPENDADDRESS
purpose = SCRIPT_TYPE_TO_BIP_PURPOSES[script_type][0]
elif script_type is None:
script_type = BIP_PURPOSE_TO_DEFAULT_SCRIPT_TYPE[purpose]
else:
if purpose not in SCRIPT_TYPE_TO_BIP_PURPOSES[script_type]:
raise ValueError("Invalid script type for account type")
if script_type == messages.InputScriptType.SPENDADDRESS:
fmt = "pkh({})"
elif script_type == messages.InputScriptType.SPENDP2SHWITNESS:
fmt = "sh(wpkh({}))"
elif script_type == messages.InputScriptType.SPENDWITNESS:
fmt = "wpkh({})"
elif script_type == messages.InputScriptType.SPENDTAPROOT:
fmt = "tr({})"
else:
raise ValueError("Unsupported script type")
coin = coin or DEFAULT_COIN
if coin == "Bitcoin":
coin_type = 0
elif coin == "Testnet" or coin == "Regtest":
coin_type = 1
else:
raise ValueError("Unsupported coin")
path = f"m/{purpose}h/{coin_type}h/{account}h"
if purpose == PURPOSE_SLIP25:
if script_type == messages.InputScriptType.SPENDTAPROOT:
path += "/1h"
else:
raise ValueError("Unsupported SLIP25 script type")
n = tools.parse_path(path)
pub = btc.get_public_node(
client,
n,
show_display=show_display,
coin_name=coin,
script_type=script_type,
ignore_xpub_magic=True,
unlock_path=get_unlock_path(n),
)
fingerprint = pub.root_fingerprint if pub.root_fingerprint is not None else 0
descriptor = f"[{fingerprint:08x}{path[1:]}]{pub.xpub}/<0;1>/*"
return _append_descriptor_checksum(fmt.format(descriptor))

@mmilata mmilata moved this from 🎯 To do to 🏃‍♀️ In progress in Firmware Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bitcoin Bitcoin related
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants