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

adapt to new base58 api, use CoinType.address_type_p2sh field

This commit is contained in:
Pavol Rusnak 2014-12-23 01:33:08 +01:00
parent 1674edcbac
commit 48cc36b1b9
7 changed files with 31 additions and 22 deletions

View File

@ -21,11 +21,11 @@
#include "coins.h"
const CoinType coins[COINS_COUNT] = {
{true, "Bitcoin", true, "BTC", true, 0, true, 10000},
{true, "Testnet", true, "TEST", true, 111, true, 10000000},
{true, "Namecoin", true, "NMC", true, 52, true, 10000000},
{true, "Litecoin", true, "LTC", true, 48, true, 10000000},
{true, "Dogecoin", true, "DOGE", true, 30, true, 100000000},
{true, "Bitcoin", true, "BTC", true, 0, true, 10000, true, 5},
{true, "Testnet", true, "TEST", true, 111, true, 10000000, true, 196},
{true, "Namecoin", true, "NMC", true, 52, true, 10000000, true, 5},
{true, "Litecoin", true, "LTC", true, 48, true, 10000000, true, 5},
{true, "Dogecoin", true, "DOGE", true, 30, true, 100000000, true, 22},
};
const CoinType *coinByShortcut(const char *shortcut)

View File

@ -282,7 +282,7 @@ void fsm_msgGetPublicKey(GetPublicKey *msg)
resp->node.public_key.size = 33;
memcpy(resp->node.public_key.bytes, node->public_key, 33);
resp->has_xpub = true;
hdnode_serialize_public(node, resp->xpub);
hdnode_serialize_public(node, resp->xpub, sizeof(resp->xpub));
msg_write(MessageType_MessageType_PublicKey, resp);
layoutHome();
}
@ -506,6 +506,7 @@ void fsm_msgGetAddress(GetAddress *msg)
if (fsm_deriveKey(node, msg->address_n, msg->address_n_count) == 0) return;
if (msg->has_multisig) {
layoutProgressSwipe("Preparing", 0);
if (cryptoMultisigPubkeyIndex(&(msg->multisig), node->public_key) < 0) {
fsm_sendFailure(FailureType_Failure_Other, "Pubkey not found in multisig script");
layoutHome();
@ -518,10 +519,10 @@ void fsm_msgGetAddress(GetAddress *msg)
return;
}
ripemd160(buf, 32, buf + 1);
buf[0] = 0x05; // multisig cointype
base58_encode_check(buf, 21, resp->address);
buf[0] = coin->address_type_p2sh; // multisig cointype
base58_encode_check(buf, 21, resp->address, sizeof(resp->address));
} else {
ecdsa_get_address(node->public_key, coin->address_type, resp->address);
ecdsa_get_address(node->public_key, coin->address_type, resp->address, sizeof(resp->address));
}
if (msg->has_show_display && msg->show_display) {
@ -577,7 +578,7 @@ void fsm_msgSignMessage(SignMessage *msg)
resp->has_address = true;
uint8_t addr_raw[21];
ecdsa_get_address_raw(node->public_key, coin->address_type, addr_raw);
base58_encode_check(addr_raw, 21, resp->address);
base58_encode_check(addr_raw, 21, resp->address, sizeof(resp->address));
resp->has_signature = true;
resp->signature.size = 65;
msg_write(MessageType_MessageType_MessageSignature, resp);
@ -707,7 +708,7 @@ void fsm_msgDecryptMessage(DecryptMessage *msg)
return;
}
if (signing) {
base58_encode_check(address_raw, 21, resp->address);
base58_encode_check(address_raw, 21, resp->address, sizeof(resp->address));
}
layoutDecryptMessage(resp->message.bytes, resp->message.size, signing ? resp->address : 0);
protectButton(ButtonRequestType_ButtonRequest_Other, true);

View File

@ -7,6 +7,8 @@
#error Regenerate this file with the current version of nanopb generator.
#endif
const uint32_t CoinType_address_type_default = 0u;
const uint32_t CoinType_address_type_p2sh_default = 5u;
const uint32_t TxInputType_sequence_default = 4294967295u;
const InputScriptType TxInputType_script_type_default = InputScriptType_SPENDADDRESS;
@ -27,11 +29,12 @@ const pb_field_t HDNodePathType_fields[3] = {
PB_LAST_FIELD
};
const pb_field_t CoinType_fields[5] = {
const pb_field_t CoinType_fields[6] = {
PB_FIELD( 1, STRING , OPTIONAL, STATIC , FIRST, CoinType, coin_name, coin_name, 0),
PB_FIELD( 2, STRING , OPTIONAL, STATIC , OTHER, CoinType, coin_shortcut, coin_name, 0),
PB_FIELD( 3, UINT32 , OPTIONAL, STATIC , OTHER, CoinType, address_type, coin_shortcut, 0),
PB_FIELD( 3, UINT32 , OPTIONAL, STATIC , OTHER, CoinType, address_type, coin_shortcut, &CoinType_address_type_default),
PB_FIELD( 4, UINT64 , OPTIONAL, STATIC , OTHER, CoinType, maxfee_kb, address_type, 0),
PB_FIELD( 5, UINT32 , OPTIONAL, STATIC , OTHER, CoinType, address_type_p2sh, maxfee_kb, &CoinType_address_type_p2sh_default),
PB_LAST_FIELD
};

View File

@ -75,6 +75,8 @@ typedef struct _CoinType {
uint32_t address_type;
bool has_maxfee_kb;
uint64_t maxfee_kb;
bool has_address_type_p2sh;
uint32_t address_type_p2sh;
} CoinType;
typedef PB_BYTES_ARRAY_T(32) HDNodeType_chain_code_t;
@ -194,13 +196,15 @@ extern const pb_extension_type_t wire_debug_in;
extern const pb_extension_type_t wire_debug_out;
/* Default values for struct fields */
extern const uint32_t CoinType_address_type_default;
extern const uint32_t CoinType_address_type_p2sh_default;
extern const uint32_t TxInputType_sequence_default;
extern const InputScriptType TxInputType_script_type_default;
/* Initializer values for message structs */
#define HDNodeType_init_default {0, 0, 0, {0, {0}}, false, {0, {0}}, false, {0, {0}}}
#define HDNodePathType_init_default {HDNodeType_init_default, 0, {0, 0, 0, 0, 0, 0, 0, 0}}
#define CoinType_init_default {false, "", false, "", false, 0, false, 0}
#define CoinType_init_default {false, "", false, "", false, 0u, false, 0, false, 5u}
#define MultisigRedeemScriptType_init_default {0, {HDNodePathType_init_default, HDNodePathType_init_default, HDNodePathType_init_default, HDNodePathType_init_default, HDNodePathType_init_default, HDNodePathType_init_default, HDNodePathType_init_default, HDNodePathType_init_default, HDNodePathType_init_default, HDNodePathType_init_default, HDNodePathType_init_default, HDNodePathType_init_default, HDNodePathType_init_default, HDNodePathType_init_default, HDNodePathType_init_default}, 0, {{0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}}, false, 0}
#define TxInputType_init_default {0, {0, 0, 0, 0, 0, 0, 0, 0}, {0, {0}}, 0, false, {0, {0}}, false, 4294967295u, false, InputScriptType_SPENDADDRESS, false, MultisigRedeemScriptType_init_default}
#define TxOutputType_init_default {false, "", 0, {0, 0, 0, 0, 0, 0, 0, 0}, 0, (OutputScriptType)0, false, MultisigRedeemScriptType_init_default}
@ -210,7 +214,7 @@ extern const InputScriptType TxInputType_script_type_default;
#define TxRequestSerializedType_init_default {false, 0, false, {0, {0}}, false, {0, {0}}}
#define HDNodeType_init_zero {0, 0, 0, {0, {0}}, false, {0, {0}}, false, {0, {0}}}
#define HDNodePathType_init_zero {HDNodeType_init_zero, 0, {0, 0, 0, 0, 0, 0, 0, 0}}
#define CoinType_init_zero {false, "", false, "", false, 0, false, 0}
#define CoinType_init_zero {false, "", false, "", false, 0, false, 0, false, 0}
#define MultisigRedeemScriptType_init_zero {0, {HDNodePathType_init_zero, HDNodePathType_init_zero, HDNodePathType_init_zero, HDNodePathType_init_zero, HDNodePathType_init_zero, HDNodePathType_init_zero, HDNodePathType_init_zero, HDNodePathType_init_zero, HDNodePathType_init_zero, HDNodePathType_init_zero, HDNodePathType_init_zero, HDNodePathType_init_zero, HDNodePathType_init_zero, HDNodePathType_init_zero, HDNodePathType_init_zero}, 0, {{0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}, {0, {0}}}, false, 0}
#define TxInputType_init_zero {0, {0, 0, 0, 0, 0, 0, 0, 0}, {0, {0}}, 0, false, {0, {0}}, false, 0, false, (InputScriptType)0, false, MultisigRedeemScriptType_init_zero}
#define TxOutputType_init_zero {false, "", 0, {0, 0, 0, 0, 0, 0, 0, 0}, 0, (OutputScriptType)0, false, MultisigRedeemScriptType_init_zero}
@ -224,6 +228,7 @@ extern const InputScriptType TxInputType_script_type_default;
#define CoinType_coin_shortcut_tag 2
#define CoinType_address_type_tag 3
#define CoinType_maxfee_kb_tag 4
#define CoinType_address_type_p2sh_tag 5
#define HDNodeType_depth_tag 1
#define HDNodeType_fingerprint_tag 2
#define HDNodeType_child_num_tag 3
@ -269,7 +274,7 @@ extern const InputScriptType TxInputType_script_type_default;
/* Struct field encoding specification for nanopb */
extern const pb_field_t HDNodeType_fields[7];
extern const pb_field_t HDNodePathType_fields[3];
extern const pb_field_t CoinType_fields[5];
extern const pb_field_t CoinType_fields[6];
extern const pb_field_t MultisigRedeemScriptType_fields[4];
extern const pb_field_t TxInputType_fields[8];
extern const pb_field_t TxOutputType_fields[6];
@ -281,7 +286,7 @@ extern const pb_field_t TxRequestSerializedType_fields[4];
/* Maximum encoded size of messages (where known) */
#define HDNodeType_size 121
#define HDNodePathType_size 171
#define CoinType_size 47
#define CoinType_size 53
#define MultisigRedeemScriptType_size 3741
#define TxInputType_size 5497
#define TxOutputType_size 3847

View File

@ -108,7 +108,7 @@ int compile_output(const CoinType *coin, const HDNode *root, TxOutputType *in, T
if (!in->has_address || !ecdsa_address_decode(in->address, addr_raw)) {
return 0;
}
if (addr_raw[0] != 0x05) { // 0x05 is P2SH
if (addr_raw[0] != coin->address_type_p2sh) {
return 0;
}
if (needs_confirm) {
@ -133,10 +133,10 @@ int compile_output(const CoinType *coin, const HDNode *root, TxOutputType *in, T
if (compile_script_multisig_hash(&(in->multisig), buf) == 0) {
return 0;
}
addr_raw[0] = 0x05;
addr_raw[0] = coin->address_type_p2sh;
ripemd160(buf, 32, addr_raw + 1);
if (needs_confirm) {
base58_encode_check(addr_raw, 21, in->address);
base58_encode_check(addr_raw, 21, in->address, sizeof(in->address));
layoutConfirmOutput(coin, in);
if (!protectButton(ButtonRequestType_ButtonRequest_ConfirmOutput, false)) {
return -1;

@ -1 +1 @@
Subproject commit 94d17ef8bc56d7c0e6ddfed39e84987543259e05
Subproject commit 60bcde46f584062e3a454bcdfdcf01bff927c8ea

@ -1 +1 @@
Subproject commit c6ca89a8507bd9310c0c92c180525989629fb7d4
Subproject commit 89a7d7797b806face0d023095c6f39c7869c5ff1