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

Taproot: add support for Taproot descriptors #1710

Merged
merged 5 commits into from Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions common/protob/messages-bitcoin.proto
Expand Up @@ -17,6 +17,7 @@ enum InputScriptType {
EXTERNAL = 2; // reserved for external inputs (coinjoin)
SPENDWITNESS = 3; // native SegWit
SPENDP2SHWITNESS = 4; // SegWit over P2SH (backward compatible)
SPENDTAPROOT = 5; // Taproot
}

/**
Expand All @@ -29,6 +30,7 @@ enum OutputScriptType {
PAYTOOPRETURN = 3; // op_return
PAYTOWITNESS = 4; // only for change output
PAYTOP2SHWITNESS = 5; // only for change output
PAYTOTAPROOT = 6; // only for change output
}

/**
Expand Down
1 change: 1 addition & 0 deletions core/.changelog.d/1710.added
@@ -0,0 +1 @@
Support for Taproot descriptors
7 changes: 6 additions & 1 deletion core/src/apps/bitcoin/get_public_key.py
Expand Up @@ -20,7 +20,12 @@ async def get_public_key(ctx: wire.Context, msg: GetPublicKey) -> PublicKey:
node = keychain.derive(msg.address_n)

if (
script_type in (InputScriptType.SPENDADDRESS, InputScriptType.SPENDMULTISIG)
script_type
in (
InputScriptType.SPENDADDRESS,
InputScriptType.SPENDMULTISIG,
InputScriptType.SPENDTAPROOT,
)
and coin.xpub_magic is not None
):
node_xpub = node.serialize_public(coin.xpub_magic)
Expand Down
1 change: 1 addition & 0 deletions core/src/trezor/enums/InputScriptType.py
Expand Up @@ -7,3 +7,4 @@
EXTERNAL = 2
SPENDWITNESS = 3
SPENDP2SHWITNESS = 4
SPENDTAPROOT = 5
1 change: 1 addition & 0 deletions core/src/trezor/enums/OutputScriptType.py
Expand Up @@ -8,3 +8,4 @@
PAYTOOPRETURN = 3
PAYTOWITNESS = 4
PAYTOP2SHWITNESS = 5
PAYTOTAPROOT = 6
2 changes: 2 additions & 0 deletions core/src/trezor/enums/__init__.py
Expand Up @@ -278,6 +278,7 @@ class InputScriptType(IntEnum):
EXTERNAL = 2
SPENDWITNESS = 3
SPENDP2SHWITNESS = 4
SPENDTAPROOT = 5

class OutputScriptType(IntEnum):
PAYTOADDRESS = 0
Expand All @@ -286,6 +287,7 @@ class OutputScriptType(IntEnum):
PAYTOOPRETURN = 3
PAYTOWITNESS = 4
PAYTOP2SHWITNESS = 5
PAYTOTAPROOT = 6

class DecredStakingSpendType(IntEnum):
SSGen = 0
Expand Down
1 change: 1 addition & 0 deletions legacy/firmware/.changelog.d/1710.added
@@ -0,0 +1 @@
Support for Taproot descriptors
3 changes: 2 additions & 1 deletion legacy/firmware/fsm_msg_coin.h
Expand Up @@ -61,7 +61,8 @@ void fsm_msgGetPublicKey(const GetPublicKey *msg) {
}

if (coin->xpub_magic && (script_type == InputScriptType_SPENDADDRESS ||
script_type == InputScriptType_SPENDMULTISIG)) {
script_type == InputScriptType_SPENDMULTISIG ||
script_type == InputScriptType_SPENDTAPROOT)) {
hdnode_serialize_public(node, fingerprint, coin->xpub_magic, resp->xpub,
sizeof(resp->xpub));
} else if (coin->has_segwit &&
Expand Down
1 change: 1 addition & 0 deletions python/.changelog.d/1710.added
@@ -0,0 +1 @@
Support for Taproot descriptors
5 changes: 5 additions & 0 deletions python/src/trezorlib/cli/btc.py
Expand Up @@ -30,6 +30,7 @@
"pkh": messages.InputScriptType.SPENDADDRESS,
"wpkh": messages.InputScriptType.SPENDWITNESS,
"sh-wpkh": messages.InputScriptType.SPENDP2SHWITNESS,
"tr": messages.InputScriptType.SPENDTAPROOT,
}

OUTPUT_SCRIPTS = {
Expand All @@ -39,6 +40,7 @@
"pkh": messages.OutputScriptType.PAYTOADDRESS,
"wpkh": messages.OutputScriptType.PAYTOWITNESS,
"sh-wpkh": messages.OutputScriptType.PAYTOP2SHWITNESS,
"tr": messages.OutputScriptType.PAYTOTAPROOT,
}

DEFAULT_COIN = "Bitcoin"
Expand Down Expand Up @@ -206,6 +208,9 @@ def _get_descriptor(client, coin, account, script_type, show_display):
elif script_type == messages.InputScriptType.SPENDWITNESS:
acc_type = 84
fmt = "wpkh({})"
elif script_type == messages.InputScriptType.SPENDTAPROOT:
acc_type = 86
fmt = "tr({})"
else:
raise ValueError("Unsupported account type")

Expand Down
2 changes: 2 additions & 0 deletions python/src/trezorlib/messages.py
Expand Up @@ -286,6 +286,7 @@ class InputScriptType(IntEnum):
EXTERNAL = 2
SPENDWITNESS = 3
SPENDP2SHWITNESS = 4
SPENDTAPROOT = 5


class OutputScriptType(IntEnum):
Expand All @@ -295,6 +296,7 @@ class OutputScriptType(IntEnum):
PAYTOOPRETURN = 3
PAYTOWITNESS = 4
PAYTOP2SHWITNESS = 5
PAYTOTAPROOT = 6


class DecredStakingSpendType(IntEnum):
Expand Down
36 changes: 36 additions & 0 deletions tests/device_tests/test_descriptors.py
Expand Up @@ -128,6 +128,42 @@
"wpkh([5c9e228d/84'/1'/1']tpubDCZB6sR48s4T6xoXqaYxScvf23kmQvg5QpyFkYnDBjsmviKHLSG9s6cp593Exg87tuMjXXMWDvBRXnJtzppcQf8Z8HdJP1rothfxm4qnPXo/1/*)#qrgjqk5h",
),
),
(
"Bitcoin",
0,
messages.InputScriptType.SPENDTAPROOT,
(
"tr([5c9e228d/86'/0'/0']xpub6Bw885JisRbcKmowfBvMmCxaFHodKn1VpmRmctmJJoM8D4DzyP4qJv8ZdD9V9r3SSGjmK2KJEDnvLH6f1Q4HrobEvnCeKydNvf1eir3RHZk/0/*)#d8jj22qr",
"tr([5c9e228d/86'/0'/0']xpub6Bw885JisRbcKmowfBvMmCxaFHodKn1VpmRmctmJJoM8D4DzyP4qJv8ZdD9V9r3SSGjmK2KJEDnvLH6f1Q4HrobEvnCeKydNvf1eir3RHZk/1/*)#unhnhlsm",
),
),
(
"Bitcoin",
1,
messages.InputScriptType.SPENDTAPROOT,
(
"tr([5c9e228d/86'/0'/1']xpub6Bw885JisRbcLp1379q64fdNPGTnHKYGcA9wcWqGcUgkKZkYCwXSCb9Qfw8DGDgYMmcDM8QwQGooqCM3Ym4yq8kS5dBjzZSXUdVUdhyfirD/0/*)#dq8u44kn",
"tr([5c9e228d/86'/0'/1']xpub6Bw885JisRbcLp1379q64fdNPGTnHKYGcA9wcWqGcUgkKZkYCwXSCb9Qfw8DGDgYMmcDM8QwQGooqCM3Ym4yq8kS5dBjzZSXUdVUdhyfirD/1/*)#u5zagqxt",
),
),
(
"Testnet",
0,
messages.InputScriptType.SPENDTAPROOT,
(
"tr([5c9e228d/86'/1'/0']tpubDC88gkaZi5HvJGxGDNLADkvtdpni3mLmx6vr2KnXmWMG8zfkBRggsxHVBkUpgcwPe2KKpkyvTJCdXHb1UHEWE64vczyyPQfHr1skBcsRedN/0/*)#4rqwxvej",
"tr([5c9e228d/86'/1'/0']tpubDC88gkaZi5HvJGxGDNLADkvtdpni3mLmx6vr2KnXmWMG8zfkBRggsxHVBkUpgcwPe2KKpkyvTJCdXHb1UHEWE64vczyyPQfHr1skBcsRedN/1/*)#yh90mef2",
),
),
(
"Testnet",
1,
messages.InputScriptType.SPENDTAPROOT,
(
"tr([5c9e228d/86'/1'/1']tpubDC88gkaZi5HvKcrFLNkZwcXx1YyShkmPTkSNoP5MHQnSP9vTrKEYKtoeEkX4oEJmNYSm6Y3fFcNV4xbkDE1uZZBmJe1ircegxgVnBW8j4SL/0/*)#7254x7qg",
"tr([5c9e228d/86'/1'/1']tpubDC88gkaZi5HvKcrFLNkZwcXx1YyShkmPTkSNoP5MHQnSP9vTrKEYKtoeEkX4oEJmNYSm6Y3fFcNV4xbkDE1uZZBmJe1ircegxgVnBW8j4SL/1/*)#0735mtss",
),
),
)


Expand Down