mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-08 22:40:59 +00:00
refactor Address dialog (QR code on left button click), use checksum for Ethereum addresses
This commit is contained in:
parent
7ca4b11c3a
commit
5b66c0b956
@ -29,6 +29,7 @@
|
||||
#include "crypto.h"
|
||||
#include "secp256k1.h"
|
||||
#include "sha3.h"
|
||||
#include "address.h"
|
||||
#include "util.h"
|
||||
#include "gettext.h"
|
||||
#include "ethereum_tokens.h"
|
||||
@ -249,16 +250,16 @@ static void layoutEthereumConfirmTx(const uint8_t *to, uint32_t to_len, const ui
|
||||
ethereumFormatAmount(&val, token, amount, sizeof(amount));
|
||||
}
|
||||
|
||||
static char _to1[17] = {0};
|
||||
static char _to2[17] = {0};
|
||||
static char _to3[17] = {0};
|
||||
char _to1[] = "to 0x__________";
|
||||
char _to2[] = "_______________";
|
||||
char _to3[] = "_______________?";
|
||||
|
||||
if (to_len) {
|
||||
strcpy(_to1, _("to "));
|
||||
data2hex(to, 6, _to1 + 3);
|
||||
data2hex(to + 6, 7, _to2);
|
||||
data2hex(to + 13, 7, _to3);
|
||||
_to3[14] = '?'; _to3[15] = 0;
|
||||
char to_str[41];
|
||||
ethereum_address_checksum(to, to_str);
|
||||
memcpy(_to1 + 5, to_str, 10);
|
||||
memcpy(_to2, to_str + 10, 15);
|
||||
memcpy(_to3, to_str + 25, 15);
|
||||
} else {
|
||||
strlcpy(_to1, _("to new contract?"), sizeof(_to1));
|
||||
strlcpy(_to2, "", sizeof(_to2));
|
||||
|
@ -652,11 +652,13 @@ void fsm_msgGetAddress(GetAddress *msg)
|
||||
} else {
|
||||
strlcpy(desc, _("Address:"), sizeof(desc));
|
||||
}
|
||||
layoutAddress(resp->address, desc);
|
||||
if (!protectButton(ButtonRequestType_ButtonRequest_Address, true)) {
|
||||
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
|
||||
layoutHome();
|
||||
return;
|
||||
bool qrcode = false;
|
||||
for (;;) {
|
||||
layoutAddress(resp->address, desc, qrcode);
|
||||
if (protectButton(ButtonRequestType_ButtonRequest_Address, false)) {
|
||||
break;
|
||||
}
|
||||
qrcode = !qrcode;
|
||||
}
|
||||
}
|
||||
|
||||
@ -684,14 +686,16 @@ void fsm_msgEthereumGetAddress(EthereumGetAddress *msg)
|
||||
char desc[16];
|
||||
strlcpy(desc, "Address:", sizeof(desc));
|
||||
|
||||
char address[41];
|
||||
data2hex(resp->address.bytes, 20, address);
|
||||
char address[43] = { '0', 'x' };
|
||||
ethereum_address_checksum(resp->address.bytes, address + 2);
|
||||
|
||||
layoutAddress(address, desc);
|
||||
if (!protectButton(ButtonRequestType_ButtonRequest_Address, true)) {
|
||||
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
|
||||
layoutHome();
|
||||
return;
|
||||
bool qrcode = false;
|
||||
for (;;) {
|
||||
layoutAddress(address, desc, qrcode);
|
||||
if (protectButton(ButtonRequestType_ButtonRequest_Address, false)) {
|
||||
break;
|
||||
}
|
||||
qrcode = !qrcode;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -225,57 +225,62 @@ void layoutDecryptMessage(const uint8_t *msg, uint32_t len, const char *address)
|
||||
str[0], str[1], str[2], str[3], NULL, NULL);
|
||||
}
|
||||
|
||||
void layoutAddress(const char *address, const char *desc)
|
||||
void layoutAddress(const char *address, const char *desc, bool qrcode)
|
||||
{
|
||||
oledSwipeLeft();
|
||||
if (layoutLast != layoutAddress) {
|
||||
oledSwipeLeft();
|
||||
} else {
|
||||
oledClear();
|
||||
}
|
||||
layoutLast = layoutAddress;
|
||||
|
||||
static unsigned char bitdata[QR_MAX_BITDATA];
|
||||
int a, i, j;
|
||||
int side = qr_encode(QR_LEVEL_M, 0, address, 0, bitdata);
|
||||
int startx;
|
||||
if (qrcode) {
|
||||
static unsigned char bitdata[QR_MAX_BITDATA];
|
||||
int side = qr_encode(QR_LEVEL_M, 0, address, 0, bitdata);
|
||||
|
||||
if (side > 0 && side <= 29) {
|
||||
oledInvert(0, 0, (side + 2) * 2, (side + 2) * 2);
|
||||
for (i = 0; i < side; i++) {
|
||||
for (j = 0; j< side; j++) {
|
||||
a = j * side + i;
|
||||
if (bitdata[a / 8] & (1 << (7 - a % 8))) {
|
||||
oledClearPixel(2 + i * 2, 2 + j * 2);
|
||||
oledClearPixel(3 + i * 2, 2 + j * 2);
|
||||
oledClearPixel(2 + i * 2, 3 + j * 2);
|
||||
oledClearPixel(3 + i * 2, 3 + j * 2);
|
||||
if (side > 0 && side <= 29) {
|
||||
oledInvert(0, 0, (side + 2) * 2, (side + 2) * 2);
|
||||
for (int i = 0; i < side; i++) {
|
||||
for (int j = 0; j< side; j++) {
|
||||
int a = j * side + i;
|
||||
if (bitdata[a / 8] & (1 << (7 - a % 8))) {
|
||||
oledClearPixel(2 + i * 2, 2 + j * 2);
|
||||
oledClearPixel(3 + i * 2, 2 + j * 2);
|
||||
oledClearPixel(2 + i * 2, 3 + j * 2);
|
||||
oledClearPixel(3 + i * 2, 3 + j * 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (side > 0 && side <= 60) {
|
||||
oledInvert(0, 0, (side + 3), (side + 3));
|
||||
for (int i = 0; i < side; i++) {
|
||||
for (int j = 0; j< side; j++) {
|
||||
int a = j * side + i;
|
||||
if (bitdata[a / 8] & (1 << (7 - a % 8))) {
|
||||
oledClearPixel(2 + i, 2 + j);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
startx = 68;
|
||||
} else if (side > 0 && side <= 60) {
|
||||
oledInvert(0, 0, (side + 3), (side + 3));
|
||||
for (i = 0; i < side; i++) {
|
||||
for (j = 0; j< side; j++) {
|
||||
a = j * side + i;
|
||||
if (bitdata[a / 8] & (1 << (7 - a % 8))) {
|
||||
oledClearPixel(2 + i, 2 + j);
|
||||
}
|
||||
}
|
||||
}
|
||||
startx = side + 6;
|
||||
} else {
|
||||
startx = 0;
|
||||
uint32_t addrlen = strlen(address);
|
||||
uint32_t rowlen = addrlen / 2;
|
||||
if (addrlen % 2) {
|
||||
rowlen++;
|
||||
}
|
||||
const char **str = split_message((const uint8_t *)address, addrlen, rowlen);
|
||||
if (desc) {
|
||||
oledDrawString(0, 0 * 9, desc);
|
||||
}
|
||||
for (int i = 0; i < 4; i++) {
|
||||
oledDrawString(0, (i + 1) * 9 + 4, str[i]);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t addrlen = strlen(address);
|
||||
uint32_t rowlen = addrlen / 4;
|
||||
if (addrlen % 4) {
|
||||
rowlen++;
|
||||
}
|
||||
const char **str = split_message((const uint8_t *)address, addrlen, rowlen);
|
||||
|
||||
if (desc) {
|
||||
oledDrawString(startx, 0 * 9, desc);
|
||||
}
|
||||
for (i = 0; i < 4; i++) {
|
||||
oledDrawString(startx, (i+1) * 9 + 4, str[i]);
|
||||
if (!qrcode) {
|
||||
static const char *btnNo = _("QR Code");
|
||||
oledDrawString(2, OLED_HEIGHT - 8, btnNo);
|
||||
oledInvert(0, OLED_HEIGHT - 9, oledStringWidth(btnNo) + 3, OLED_HEIGHT - 1);
|
||||
}
|
||||
|
||||
static const char *btnYes = _("Continue");
|
||||
|
@ -40,7 +40,7 @@ void layoutVerifyMessage(const uint8_t *msg, uint32_t len);
|
||||
void layoutCipherKeyValue(bool encrypt, const char *key);
|
||||
void layoutEncryptMessage(const uint8_t *msg, uint32_t len, bool signing);
|
||||
void layoutDecryptMessage(const uint8_t *msg, uint32_t len, const char *address);
|
||||
void layoutAddress(const char *address, const char *desc);
|
||||
void layoutAddress(const char *address, const char *desc, bool qrcode);
|
||||
void layoutPublicKey(const uint8_t *pubkey);
|
||||
void layoutSignIdentity(const IdentityType *identity, const char *challenge);
|
||||
void layoutDecryptIdentity(const IdentityType *identity);
|
||||
|
2
vendor/trezor-crypto
vendored
2
vendor/trezor-crypto
vendored
@ -1 +1 @@
|
||||
Subproject commit 533193562601780c8705ecb80c908916bb80b427
|
||||
Subproject commit f49fe75e15eafaa69ab687857c4ffd0c9410a0e1
|
Loading…
Reference in New Issue
Block a user