1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-18 20:38:10 +00:00

chore(legacy): Disable Taproot where it's not supported.

This commit is contained in:
Andrew Kozlik 2021-11-13 12:42:54 +01:00 committed by Andrew Kozlik
parent 10717ddb99
commit 98ad54b7ee
2 changed files with 28 additions and 19 deletions

View File

@ -149,29 +149,35 @@ int cryptoMessageSign(const CoinInfo *coin, HDNode *node,
InputScriptType script_type, bool no_script_type, InputScriptType script_type, bool no_script_type,
const uint8_t *message, size_t message_len, const uint8_t *message, size_t message_len,
uint8_t *signature) { uint8_t *signature) {
uint8_t script_type_info = 0;
switch (script_type) {
case InputScriptType_SPENDADDRESS:
// p2pkh
script_type_info = 0;
break;
case InputScriptType_SPENDP2SHWITNESS:
// segwit-in-p2sh
script_type_info = 4;
break;
case InputScriptType_SPENDWITNESS:
// segwit
script_type_info = 8;
break;
default:
// unsupported script type
return 1;
}
if (no_script_type) {
script_type_info = 0;
}
uint8_t hash[HASHER_DIGEST_LENGTH] = {0}; uint8_t hash[HASHER_DIGEST_LENGTH] = {0};
cryptoMessageHash(coin, message, message_len, hash); cryptoMessageHash(coin, message, message_len, hash);
uint8_t pby = 0; uint8_t pby = 0;
int result = hdnode_sign_digest(node, hash, signature + 1, &pby, NULL); int result = hdnode_sign_digest(node, hash, signature + 1, &pby, NULL);
if (result == 0) { if (result == 0) {
uint8_t script_type_info = 0;
if (!no_script_type) {
switch (script_type) {
case InputScriptType_SPENDP2SHWITNESS:
// segwit-in-p2sh
script_type_info = 4;
break;
case InputScriptType_SPENDWITNESS:
// segwit
script_type_info = 8;
break;
default:
// p2pkh
script_type_info = 0;
break;
}
}
signature[0] = 31 + pby + script_type_info; signature[0] = 31 + pby + script_type_info;
} }
return result; return result;

View File

@ -67,8 +67,7 @@ void fsm_msgGetPublicKey(const GetPublicKey *msg) {
} }
if (coin->xpub_magic && (script_type == InputScriptType_SPENDADDRESS || 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, hdnode_serialize_public(node, fingerprint, coin->xpub_magic, resp->xpub,
sizeof(resp->xpub)); sizeof(resp->xpub));
} else if (coin->has_segwit && } else if (coin->has_segwit &&
@ -89,6 +88,10 @@ void fsm_msgGetPublicKey(const GetPublicKey *msg) {
msg->ignore_xpub_magic && coin->xpub_magic) { msg->ignore_xpub_magic && coin->xpub_magic) {
hdnode_serialize_public(node, fingerprint, coin->xpub_magic, resp->xpub, hdnode_serialize_public(node, fingerprint, coin->xpub_magic, resp->xpub,
sizeof(resp->xpub)); sizeof(resp->xpub));
} else if (coin->has_taproot && script_type == InputScriptType_SPENDTAPROOT &&
coin->xpub_magic) {
hdnode_serialize_public(node, fingerprint, coin->xpub_magic, resp->xpub,
sizeof(resp->xpub));
} else { } else {
fsm_sendFailure(FailureType_Failure_DataError, fsm_sendFailure(FailureType_Failure_DataError,
_("Invalid combination of coin and script_type")); _("Invalid combination of coin and script_type"));