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

legacy: show xpubs with multisig get_address

This commit is contained in:
Pavol Rusnak 2019-10-23 17:03:31 +00:00
parent 6722215c66
commit 5c01a9459c
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
7 changed files with 107 additions and 15 deletions

View File

@ -232,15 +232,58 @@ static HDNode *fsm_getDerivedNode(const char *curve, const uint32_t *address_n,
static bool fsm_layoutAddress(const char *address, const char *desc,
bool ignorecase, size_t prefixlen,
const uint32_t *address_n, size_t address_n_count,
bool address_is_account) {
bool qrcode = false;
bool address_is_account,
const MultisigRedeemScriptType *multisig,
int multisig_index, const CoinInfo *coin) {
int screen = 0, screens = 2;
if (multisig) {
screens += cryptoMultisigPubkeyCount(multisig);
}
for (;;) {
const char *display_addr = address;
if (prefixlen && !qrcode) {
display_addr += prefixlen;
switch (screen) {
case 0: { // show address
const char *display_addr = address;
// strip cashaddr prefix
if (prefixlen) {
display_addr += prefixlen;
}
layoutAddress(display_addr, desc, false, ignorecase, address_n,
address_n_count, address_is_account);
break;
}
case 1: { // show QR code
layoutAddress(address, desc, true, ignorecase, address_n,
address_n_count, address_is_account);
break;
}
default: { // show XPUBs
int index = (screen - 2);
char xpub[112] = {0};
const HDNodeType *node_ptr = NULL;
if (multisig->nodes_count) { // use multisig->nodes
node_ptr = &(multisig->nodes[index]);
} else if (multisig->pubkeys_count) { // use multisig->pubkeys
node_ptr = &(multisig->pubkeys[index].node);
}
if (!node_ptr) {
strlcat(xpub, "ERROR", sizeof(xpub));
} else {
HDNode node;
if (!hdnode_from_xpub(node_ptr->depth, node_ptr->child_num,
node_ptr->chain_code.bytes,
node_ptr->public_key.bytes, coin->curve_name,
&node)) {
strlcat(xpub, "ERROR", sizeof(xpub));
} else {
hdnode_serialize_public(&node, node_ptr->fingerprint,
coin->xpub_magic, xpub, sizeof(xpub));
}
}
layoutXPUB(xpub, index, multisig_index == index);
break;
}
}
layoutAddress(display_addr, desc, qrcode, ignorecase, address_n,
address_n_count, address_is_account);
if (protectButton(ButtonRequestType_ButtonRequest_Address, false)) {
return true;
}
@ -249,7 +292,7 @@ static bool fsm_layoutAddress(const char *address, const char *desc,
layoutHome();
return false;
}
qrcode = !qrcode;
screen = (screen + 1) % screens;
}
}

View File

@ -216,7 +216,8 @@ void fsm_msgGetAddress(const GetAddress *msg) {
}
if (msg->has_show_display && msg->show_display) {
char desc[20];
char desc[20] = {0};
int multisig_index = 0;
if (msg->has_multisig) {
strlcpy(desc, "Multisig __ of __:", sizeof(desc));
const uint32_t m = msg->multisig.m;
@ -225,6 +226,8 @@ void fsm_msgGetAddress(const GetAddress *msg) {
desc[10] = '0' + (m % 10);
desc[15] = (n < 10) ? ' ' : ('0' + (n / 10));
desc[16] = '0' + (n % 10);
multisig_index =
cryptoMultisigPubkeyIndex(coin, &(msg->multisig), node->public_key);
} else {
strlcpy(desc, _("Address:"), sizeof(desc));
}
@ -246,7 +249,9 @@ void fsm_msgGetAddress(const GetAddress *msg) {
bool is_bech32 = msg->script_type == InputScriptType_SPENDWITNESS;
if (!fsm_layoutAddress(address, desc, is_cashaddr || is_bech32,
is_cashaddr ? strlen(coin->cashaddr_prefix) + 1 : 0,
msg->address_n, msg->address_n_count, false)) {
msg->address_n, msg->address_n_count, false,
msg->has_multisig ? &(msg->multisig) : NULL,
multisig_index, coin)) {
return;
}
}

View File

@ -121,7 +121,7 @@ void fsm_msgEthereumGetAddress(const EthereumGetAddress *msg) {
strlcpy(desc, "Address:", sizeof(desc));
if (!fsm_layoutAddress(resp->address, desc, false, 0, msg->address_n,
msg->address_n_count, true)) {
msg->address_n_count, true, NULL, 0, NULL)) {
return;
}
}

View File

@ -34,7 +34,8 @@ void fsm_msgLiskGetAddress(const LiskGetAddress *msg) {
if (msg->has_show_display && msg->show_display) {
if (!fsm_layoutAddress(resp->address, _("Address:"), true, 0,
msg->address_n, msg->address_n_count, false)) {
msg->address_n, msg->address_n_count, false, NULL, 0,
NULL)) {
return;
}
}

View File

@ -43,7 +43,7 @@ void fsm_msgNEMGetAddress(NEMGetAddress *msg) {
strlcat(desc, ":", sizeof(desc));
if (!fsm_layoutAddress(resp->address, desc, true, 0, msg->address_n,
msg->address_n_count, false)) {
msg->address_n_count, false, NULL, 0, NULL)) {
return;
}
}

View File

@ -562,7 +562,7 @@ void layoutResetWord(const char *word, int pass, int word_pos, bool last) {
void layoutAddress(const char *address, const char *desc, bool qrcode,
bool ignorecase, const uint32_t *address_n,
size_t address_n_count, bool address_is_account) {
if (layoutLast != layoutAddress) {
if (layoutLast != layoutAddress && layoutLast != layoutXPUB) {
layoutSwipe();
} else {
oledClear();
@ -635,7 +635,7 @@ void layoutAddress(const char *address, const char *desc, bool qrcode,
layoutButtonNo(_("QR Code"), NULL);
}
layoutButtonYes(_("Continue"), &bmp_btn_confirm);
layoutButtonYes(_("Confirm"), &bmp_btn_confirm);
oledRefresh();
}
@ -653,6 +653,48 @@ void layoutPublicKey(const uint8_t *pubkey) {
str[1], str[2], str[3], NULL);
}
void layoutXPUB(const char *xpub, int index, bool ours) {
if (layoutLast != layoutAddress && layoutLast != layoutXPUB) {
layoutSwipe();
} else {
oledClear();
}
layoutLast = layoutXPUB;
char desc[] = "XPUB #__ (______)";
if (index + 1 >= 10) {
desc[6] = '0' + (((index + 1) / 10) % 10);
desc[7] = '0' + ((index + 1) % 10);
} else {
desc[6] = '0' + ((index + 1) % 10);
desc[7] = ' ';
}
if (ours) {
desc[10] = 'y';
desc[11] = 'o';
desc[12] = 'u';
desc[13] = 'r';
desc[14] = 's';
desc[15] = ')';
desc[16] = 0;
} else {
desc[10] = 'o';
desc[11] = 't';
desc[12] = 'h';
desc[13] = 'e';
desc[14] = 'r';
desc[15] = 's';
}
const char **str = split_message((const uint8_t *)xpub, strlen(xpub), 21);
oledDrawString(0, 0 * 9, desc, FONT_STANDARD);
for (int i = 0; i < 4; i++) {
oledDrawString(0, (i + 1) * 9 + 4, str[i], FONT_FIXED);
}
layoutButtonNo(_("Next"), NULL);
layoutButtonYes(_("Confirm"), &bmp_btn_confirm);
oledRefresh();
}
void layoutSignIdentity(const IdentityType *identity, const char *challenge) {
char row_proto[8 + 11 + 1] = {0};
char row_hostport[64 + 6 + 1] = {0};

View File

@ -64,6 +64,7 @@ void layoutAddress(const char *address, const char *desc, bool qrcode,
bool ignorecase, const uint32_t *address_n,
size_t address_n_count, bool address_is_account);
void layoutPublicKey(const uint8_t *pubkey);
void layoutXPUB(const char *xpub, int index, bool ours);
void layoutSignIdentity(const IdentityType *identity, const char *challenge);
void layoutDecryptIdentity(const IdentityType *identity);
void layoutU2FDialog(const char *verb, const char *appname);