2014-04-29 12:26:51 +00:00
|
|
|
/*
|
2017-11-05 16:46:34 +00:00
|
|
|
* This file is part of the TREZOR project, https://trezor.io/
|
2014-04-29 12:26:51 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Pavol Rusnak <stick@satoshilabs.com>
|
|
|
|
*
|
|
|
|
* This library is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
2015-03-02 20:33:06 +00:00
|
|
|
#include <ctype.h>
|
2014-04-29 12:26:51 +00:00
|
|
|
|
|
|
|
#include "layout2.h"
|
|
|
|
#include "storage.h"
|
|
|
|
#include "oled.h"
|
|
|
|
#include "bitmaps.h"
|
|
|
|
#include "string.h"
|
|
|
|
#include "util.h"
|
2014-08-08 17:09:54 +00:00
|
|
|
#include "qr_encode.h"
|
2016-11-17 19:10:57 +00:00
|
|
|
#include "timer.h"
|
2017-05-18 14:19:10 +00:00
|
|
|
#include "bignum.h"
|
2017-05-30 16:41:02 +00:00
|
|
|
#include "secp256k1.h"
|
2017-07-20 21:58:19 +00:00
|
|
|
#include "nem2.h"
|
2017-06-18 20:22:33 +00:00
|
|
|
#include "gettext.h"
|
2014-04-29 12:26:51 +00:00
|
|
|
|
2017-07-26 15:51:54 +00:00
|
|
|
#define BITCOIN_DIVISIBILITY (8)
|
|
|
|
|
2018-03-02 17:00:10 +00:00
|
|
|
static const char *slip44_extras(uint32_t coin_type)
|
|
|
|
{
|
|
|
|
if ((coin_type & 0x80000000) == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
switch (coin_type & 0x7fffffff) {
|
|
|
|
case 40: return "EXP"; // Expanse
|
|
|
|
case 43: return "NEM"; // NEM
|
|
|
|
case 60: return "ETH"; // Ethereum Mainnet
|
|
|
|
case 61: return "ETC"; // Ethereum Classic Mainnet
|
|
|
|
case 108: return "UBQ"; // UBIQ
|
|
|
|
case 137: return "RSK"; // Rootstock Mainnet
|
|
|
|
case 37310: return "tRSK"; // Rootstock Testnet
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define BIP32_MAX_LAST_ELEMENT 1000000
|
|
|
|
|
|
|
|
static const char *address_n_str(const uint32_t *address_n, size_t address_n_count)
|
|
|
|
{
|
|
|
|
if (address_n_count > 8) {
|
|
|
|
return _("Unknown long path");
|
|
|
|
}
|
|
|
|
if (address_n_count == 0) {
|
|
|
|
return _("Path: m");
|
|
|
|
}
|
|
|
|
|
|
|
|
// known BIP44/49 path
|
|
|
|
static char path[100];
|
|
|
|
if (address_n_count == 5 &&
|
|
|
|
(address_n[0] == (0x80000000 + 44) || address_n[0] == (0x80000000 + 49) || address_n[0] == (0x80000000 + 84)) &&
|
|
|
|
(address_n[1] & 0x80000000) &&
|
|
|
|
(address_n[2] & 0x80000000) &&
|
|
|
|
(address_n[3] <= 1) &&
|
|
|
|
(address_n[4] <= BIP32_MAX_LAST_ELEMENT)) {
|
|
|
|
bool native_segwit = (address_n[0] == (0x80000000 + 84));
|
|
|
|
bool p2sh_segwit = (address_n[0] == (0x80000000 + 49));
|
|
|
|
bool legacy = false;
|
2018-05-22 16:40:15 +00:00
|
|
|
const CoinInfo *coin = coinBySlip44(address_n[1]);
|
2018-03-02 17:00:10 +00:00
|
|
|
const char *abbr = 0;
|
|
|
|
if (native_segwit) {
|
|
|
|
if (coin && coin->has_segwit && coin->bech32_prefix) {
|
|
|
|
abbr = coin->coin_shortcut + 1;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
if (p2sh_segwit) {
|
|
|
|
if (coin && coin->has_segwit && coin->has_address_type_p2sh) {
|
|
|
|
abbr = coin->coin_shortcut + 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (coin) {
|
|
|
|
if (coin->has_segwit && coin->has_address_type_p2sh) {
|
|
|
|
legacy = true;
|
|
|
|
}
|
|
|
|
abbr = coin->coin_shortcut + 1;
|
|
|
|
} else {
|
|
|
|
abbr = slip44_extras(address_n[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
uint32_t accnum = (address_n[2] & 0x7fffffff) + 1;
|
|
|
|
if (abbr && accnum < 100) {
|
|
|
|
memset(path, 0, sizeof(path));
|
|
|
|
strlcpy(path, abbr, sizeof(path));
|
|
|
|
// TODO: how to name accounts?
|
|
|
|
// currently we have "legacy account", "account" and "segwit account"
|
|
|
|
// for BIP44/P2PKH, BIP49/P2SH-P2WPKH and BIP84/P2WPKH respectivelly
|
|
|
|
if (legacy) {
|
|
|
|
strlcat(path, " legacy", sizeof(path));
|
|
|
|
}
|
|
|
|
if (native_segwit) {
|
|
|
|
strlcat(path, " segwit", sizeof(path));
|
|
|
|
}
|
|
|
|
strlcat(path, " account #", sizeof(path));
|
|
|
|
char acc[3];
|
|
|
|
memset(acc, 0, sizeof(acc));
|
|
|
|
if (accnum < 10) {
|
|
|
|
acc[0] = '0' + accnum;
|
|
|
|
} else {
|
|
|
|
acc[0] = '0' + (accnum / 10);
|
|
|
|
acc[1] = '0' + (accnum % 10);
|
|
|
|
}
|
|
|
|
strlcat(path, acc, sizeof(path));
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// "Path: m" / i '
|
|
|
|
static char address_str[7 + 8 * (1 + 9 + 1) + 1];
|
|
|
|
char *c = address_str + sizeof(address_str) - 1;
|
|
|
|
|
|
|
|
*c = 0; c--;
|
|
|
|
|
|
|
|
for (int n = (int)address_n_count - 1; n >= 0; n--) {
|
|
|
|
uint32_t i = address_n[n];
|
|
|
|
if (i & 0x80000000) {
|
|
|
|
*c = '\''; c--;
|
|
|
|
}
|
|
|
|
i = i & 0x7fffffff;
|
|
|
|
do {
|
|
|
|
*c = '0' + (i % 10); c--;
|
|
|
|
i /= 10;
|
|
|
|
} while (i > 0);
|
|
|
|
*c = '/'; c--;
|
|
|
|
}
|
|
|
|
*c = 'm'; c--;
|
|
|
|
*c = ' '; c--;
|
|
|
|
*c = ':'; c--;
|
|
|
|
*c = 'h'; c--;
|
|
|
|
*c = 't'; c--;
|
|
|
|
*c = 'a'; c--;
|
|
|
|
*c = 'P';
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2017-11-15 14:42:56 +00:00
|
|
|
// split longer string into 4 rows, rowlen chars each
|
2018-06-11 17:13:34 +00:00
|
|
|
const char **split_message(const uint8_t *msg, uint32_t len, uint32_t rowlen)
|
2017-11-15 14:42:56 +00:00
|
|
|
{
|
|
|
|
static char str[4][32 + 1];
|
|
|
|
if (rowlen > 32) {
|
|
|
|
rowlen = 32;
|
|
|
|
}
|
|
|
|
memset(str, 0, sizeof(str));
|
|
|
|
strlcpy(str[0], (char *)msg, rowlen + 1);
|
|
|
|
if (len > rowlen) {
|
|
|
|
strlcpy(str[1], (char *)msg + rowlen, rowlen + 1);
|
|
|
|
}
|
|
|
|
if (len > rowlen * 2) {
|
|
|
|
strlcpy(str[2], (char *)msg + rowlen * 2, rowlen + 1);
|
|
|
|
}
|
|
|
|
if (len > rowlen * 3) {
|
|
|
|
strlcpy(str[3], (char *)msg + rowlen * 3, rowlen + 1);
|
|
|
|
}
|
|
|
|
if (len > rowlen * 4) {
|
|
|
|
str[3][rowlen - 1] = '.';
|
|
|
|
str[3][rowlen - 2] = '.';
|
|
|
|
str[3][rowlen - 3] = '.';
|
|
|
|
}
|
|
|
|
static const char *ret[4] = { str[0], str[1], str[2], str[3] };
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-04-29 12:26:51 +00:00
|
|
|
void *layoutLast = layoutHome;
|
|
|
|
|
2016-06-08 15:55:25 +00:00
|
|
|
void layoutDialogSwipe(const BITMAP *icon, const char *btnNo, const char *btnYes, const char *desc, const char *line1, const char *line2, const char *line3, const char *line4, const char *line5, const char *line6)
|
2014-04-29 12:26:51 +00:00
|
|
|
{
|
|
|
|
layoutLast = layoutDialogSwipe;
|
2017-11-03 17:54:02 +00:00
|
|
|
layoutSwipe();
|
2014-04-29 12:26:51 +00:00
|
|
|
layoutDialog(icon, btnNo, btnYes, desc, line1, line2, line3, line4, line5, line6);
|
|
|
|
}
|
|
|
|
|
2014-12-21 17:58:56 +00:00
|
|
|
void layoutProgressSwipe(const char *desc, int permil)
|
2014-04-29 12:26:51 +00:00
|
|
|
{
|
|
|
|
if (layoutLast == layoutProgressSwipe) {
|
|
|
|
oledClear();
|
|
|
|
} else {
|
|
|
|
layoutLast = layoutProgressSwipe;
|
2017-11-03 17:54:02 +00:00
|
|
|
layoutSwipe();
|
2014-04-29 12:26:51 +00:00
|
|
|
}
|
2014-12-21 17:58:56 +00:00
|
|
|
layoutProgress(desc, permil);
|
2014-04-29 12:26:51 +00:00
|
|
|
}
|
|
|
|
|
2015-04-13 17:52:38 +00:00
|
|
|
void layoutScreensaver(void)
|
|
|
|
{
|
|
|
|
layoutLast = layoutScreensaver;
|
|
|
|
oledClear();
|
|
|
|
oledRefresh();
|
|
|
|
}
|
|
|
|
|
2014-04-29 12:26:51 +00:00
|
|
|
void layoutHome(void)
|
|
|
|
{
|
2015-04-13 17:52:38 +00:00
|
|
|
if (layoutLast == layoutHome || layoutLast == layoutScreensaver) {
|
2014-04-29 12:26:51 +00:00
|
|
|
oledClear();
|
|
|
|
} else {
|
2017-11-03 17:54:02 +00:00
|
|
|
layoutSwipe();
|
2014-04-29 12:26:51 +00:00
|
|
|
}
|
2015-04-13 17:52:38 +00:00
|
|
|
layoutLast = layoutHome;
|
2017-06-18 20:22:33 +00:00
|
|
|
const char *label = storage_isInitialized() ? storage_getLabel() : _("Go to trezor.io/start");
|
2015-02-04 20:27:07 +00:00
|
|
|
const uint8_t *homescreen = storage_getHomescreen();
|
|
|
|
if (homescreen) {
|
|
|
|
BITMAP b;
|
|
|
|
b.width = 128;
|
|
|
|
b.height = 64;
|
|
|
|
b.data = homescreen;
|
|
|
|
oledDrawBitmap(0, 0, &b);
|
2014-04-29 12:26:51 +00:00
|
|
|
} else {
|
2015-02-04 20:27:07 +00:00
|
|
|
if (label && strlen(label) > 0) {
|
|
|
|
oledDrawBitmap(44, 4, &bmp_logo48);
|
2018-02-06 21:29:33 +00:00
|
|
|
oledDrawStringCenter(OLED_HEIGHT - 8, label, FONT_STANDARD);
|
2015-02-04 20:27:07 +00:00
|
|
|
} else {
|
|
|
|
oledDrawBitmap(40, 0, &bmp_logo64);
|
|
|
|
}
|
2014-04-29 12:26:51 +00:00
|
|
|
}
|
2018-04-04 10:42:52 +00:00
|
|
|
if (storage_unfinishedBackup()) {
|
|
|
|
oledBox(0, 0, 127, 8, false);
|
|
|
|
oledDrawStringCenter(0, "BACKUP FAILED!", FONT_STANDARD);
|
|
|
|
} else
|
2017-06-26 17:45:12 +00:00
|
|
|
if (storage_needsBackup()) {
|
|
|
|
oledBox(0, 0, 127, 8, false);
|
2018-02-06 21:29:33 +00:00
|
|
|
oledDrawStringCenter(0, "NEEDS BACKUP!", FONT_STANDARD);
|
2017-06-26 17:45:12 +00:00
|
|
|
}
|
2014-04-29 12:26:51 +00:00
|
|
|
oledRefresh();
|
2016-11-17 19:10:57 +00:00
|
|
|
|
|
|
|
// Reset lock screen timeout
|
2017-12-13 18:38:51 +00:00
|
|
|
system_millis_lock_start = timer_ms();
|
2014-04-29 12:26:51 +00:00
|
|
|
}
|
|
|
|
|
2018-09-06 12:37:42 +00:00
|
|
|
static void render_address_dialog(const CoinInfo *coin, const char *address, const char *line1, const char *line2, const char *extra_line)
|
2014-04-29 12:26:51 +00:00
|
|
|
{
|
2018-09-06 12:37:42 +00:00
|
|
|
if (coin && coin->cashaddr_prefix) {
|
2018-02-07 18:56:50 +00:00
|
|
|
/* If this is a cashaddr address, remove the prefix from the
|
|
|
|
* string presented to the user
|
|
|
|
*/
|
|
|
|
int prefix_len = strlen(coin->cashaddr_prefix);
|
2018-09-06 12:37:42 +00:00
|
|
|
if (strncmp(address, coin->cashaddr_prefix, prefix_len) == 0
|
|
|
|
&& address[prefix_len] == ':') {
|
|
|
|
address += prefix_len + 1;
|
2018-02-07 18:56:50 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-06 12:37:42 +00:00
|
|
|
int addrlen = strlen(address);
|
2018-02-07 19:40:22 +00:00
|
|
|
int numlines = addrlen <= 42 ? 2 : 3;
|
|
|
|
int linelen = (addrlen - 1) / numlines + 1;
|
|
|
|
if (linelen > 21) {
|
|
|
|
linelen = 21;
|
2018-01-15 17:40:54 +00:00
|
|
|
}
|
2018-09-06 12:37:42 +00:00
|
|
|
const char **str = split_message((const uint8_t *)address, addrlen, linelen);
|
2018-02-07 19:40:22 +00:00
|
|
|
layoutLast = layoutDialogSwipe;
|
|
|
|
layoutSwipe();
|
|
|
|
oledClear();
|
|
|
|
oledDrawBitmap(0, 0, &bmp_icon_question);
|
2018-09-06 12:37:42 +00:00
|
|
|
oledDrawString(20, 0 * 9, line1, FONT_STANDARD);
|
|
|
|
oledDrawString(20, 1 * 9, line2, FONT_STANDARD);
|
2018-02-07 19:40:22 +00:00
|
|
|
int left = linelen > 18 ? 0 : 20;
|
|
|
|
oledDrawString(left, 2 * 9, str[0], FONT_FIXED);
|
|
|
|
oledDrawString(left, 3 * 9, str[1], FONT_FIXED);
|
|
|
|
oledDrawString(left, 4 * 9, str[2], FONT_FIXED);
|
|
|
|
oledDrawString(left, 5 * 9, str[3], FONT_FIXED);
|
|
|
|
if (!str[3][0]) {
|
2018-09-06 12:37:42 +00:00
|
|
|
if (extra_line) {
|
|
|
|
oledDrawString(0, 5 * 9, extra_line, FONT_STANDARD);
|
2018-03-02 17:00:10 +00:00
|
|
|
} else {
|
|
|
|
oledHLine(OLED_HEIGHT - 13);
|
|
|
|
}
|
2017-11-01 20:42:52 +00:00
|
|
|
}
|
2018-02-07 19:40:22 +00:00
|
|
|
layoutButtonNo(_("Cancel"));
|
|
|
|
layoutButtonYes(_("Confirm"));
|
|
|
|
oledRefresh();
|
2014-04-29 12:26:51 +00:00
|
|
|
}
|
|
|
|
|
2018-08-27 17:06:11 +00:00
|
|
|
void layoutConfirmOutput(const CoinInfo *coin, const TxOutputType *out)
|
2018-09-06 12:37:42 +00:00
|
|
|
{
|
|
|
|
char str_out[32 + 3];
|
|
|
|
bn_format_uint64(out->amount, NULL, coin->coin_shortcut, BITCOIN_DIVISIBILITY, 0, false, str_out, sizeof(str_out) - 3);
|
|
|
|
strlcat(str_out, " to", sizeof(str_out));
|
|
|
|
const char *address = out->address;
|
|
|
|
const char *extra_line = (out->address_n_count > 0) ? address_n_str(out->address_n, out->address_n_count) : 0;
|
|
|
|
render_address_dialog(coin, address, _("Confirm sending"), str_out, extra_line);
|
|
|
|
}
|
|
|
|
|
2018-09-06 15:41:48 +00:00
|
|
|
bool is_valid_ascii(const uint8_t *data, uint32_t size)
|
2017-11-15 14:42:56 +00:00
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < size; i++) {
|
|
|
|
if (data[i] < ' ' || data[i] > '~') {
|
2018-09-06 15:41:48 +00:00
|
|
|
return false;
|
2017-11-15 14:42:56 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-06 15:41:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void layoutConfirmOpReturn(const uint8_t *data, uint32_t size)
|
|
|
|
{
|
2017-11-15 14:42:56 +00:00
|
|
|
const char **str;
|
2018-09-06 15:41:48 +00:00
|
|
|
if (!is_valid_ascii(data, size)) {
|
2017-11-15 14:42:56 +00:00
|
|
|
char hex[65];
|
|
|
|
memset(hex, 0, sizeof(hex));
|
|
|
|
data2hex(data, (size > 32) ? 32 : size, hex);
|
|
|
|
str = split_message((const uint8_t *)hex, size * 2, 16);
|
|
|
|
} else {
|
|
|
|
str = split_message(data, size, 20);
|
|
|
|
}
|
|
|
|
layoutDialogSwipe(&bmp_icon_question,
|
|
|
|
_("Cancel"),
|
|
|
|
_("Confirm"),
|
|
|
|
NULL,
|
|
|
|
_("Confirm OP_RETURN:"),
|
|
|
|
str[0],
|
|
|
|
str[1],
|
|
|
|
str[2],
|
|
|
|
str[3],
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-10-30 21:13:09 +00:00
|
|
|
void layoutConfirmTx(const CoinInfo *coin, uint64_t amount_out, uint64_t amount_fee)
|
2014-04-29 12:26:51 +00:00
|
|
|
{
|
2017-05-18 14:19:10 +00:00
|
|
|
char str_out[32], str_fee[32];
|
2017-10-30 21:13:09 +00:00
|
|
|
bn_format_uint64(amount_out, NULL, coin->coin_shortcut, BITCOIN_DIVISIBILITY, 0, false, str_out, sizeof(str_out));
|
|
|
|
bn_format_uint64(amount_fee, NULL, coin->coin_shortcut, BITCOIN_DIVISIBILITY, 0, false, str_fee, sizeof(str_fee));
|
2016-06-08 15:55:25 +00:00
|
|
|
layoutDialogSwipe(&bmp_icon_question,
|
2017-06-18 20:22:33 +00:00
|
|
|
_("Cancel"),
|
|
|
|
_("Confirm"),
|
2014-04-29 12:26:51 +00:00
|
|
|
NULL,
|
2017-06-18 20:22:33 +00:00
|
|
|
_("Really send"),
|
2014-04-29 12:26:51 +00:00
|
|
|
str_out,
|
2017-06-18 20:22:33 +00:00
|
|
|
_("from your wallet?"),
|
|
|
|
_("Fee included:"),
|
2014-04-29 12:26:51 +00:00
|
|
|
str_fee,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-10-30 21:13:09 +00:00
|
|
|
void layoutFeeOverThreshold(const CoinInfo *coin, uint64_t fee)
|
2014-04-29 12:26:51 +00:00
|
|
|
{
|
2017-05-18 14:19:10 +00:00
|
|
|
char str_fee[32];
|
2017-10-30 21:13:09 +00:00
|
|
|
bn_format_uint64(fee, NULL, coin->coin_shortcut, BITCOIN_DIVISIBILITY, 0, false, str_fee, sizeof(str_fee));
|
2016-06-08 15:55:25 +00:00
|
|
|
layoutDialogSwipe(&bmp_icon_question,
|
2017-06-18 20:22:33 +00:00
|
|
|
_("Cancel"),
|
|
|
|
_("Confirm"),
|
2014-04-29 12:26:51 +00:00
|
|
|
NULL,
|
2017-06-18 20:22:33 +00:00
|
|
|
_("Fee"),
|
2017-05-18 14:19:10 +00:00
|
|
|
str_fee,
|
2017-06-18 20:22:33 +00:00
|
|
|
_("is unexpectedly high."),
|
2014-04-29 12:26:51 +00:00
|
|
|
NULL,
|
2017-06-18 20:22:33 +00:00
|
|
|
_("Send anyway?"),
|
2014-04-29 12:26:51 +00:00
|
|
|
NULL
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-11-26 17:52:30 +00:00
|
|
|
void layoutSignMessage(const uint8_t *msg, uint32_t len)
|
|
|
|
{
|
2014-11-27 16:23:04 +00:00
|
|
|
const char **str = split_message(msg, len, 16);
|
2017-06-18 20:22:33 +00:00
|
|
|
layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"),
|
|
|
|
_("Sign message?"),
|
2014-06-20 22:31:44 +00:00
|
|
|
str[0], str[1], str[2], str[3], NULL, NULL);
|
2014-04-29 12:26:51 +00:00
|
|
|
}
|
2014-06-02 18:40:20 +00:00
|
|
|
|
2018-09-06 12:37:42 +00:00
|
|
|
void layoutVerifyAddress(const CoinInfo *coin, const char *address)
|
2016-04-25 21:03:57 +00:00
|
|
|
{
|
2018-09-06 12:37:42 +00:00
|
|
|
render_address_dialog(coin, address, _("Confirm address?"), _("Message signed by:"), 0);
|
2016-04-25 21:03:57 +00:00
|
|
|
}
|
|
|
|
|
2014-06-02 18:40:20 +00:00
|
|
|
void layoutVerifyMessage(const uint8_t *msg, uint32_t len)
|
|
|
|
{
|
2014-11-27 16:23:04 +00:00
|
|
|
const char **str = split_message(msg, len, 16);
|
2017-06-18 20:22:33 +00:00
|
|
|
layoutDialogSwipe(&bmp_icon_info, _("Cancel"), _("Confirm"),
|
|
|
|
_("Verified message"),
|
2014-06-20 22:31:44 +00:00
|
|
|
str[0], str[1], str[2], str[3], NULL, NULL);
|
2014-06-02 18:40:20 +00:00
|
|
|
}
|
2014-06-07 12:21:59 +00:00
|
|
|
|
|
|
|
void layoutCipherKeyValue(bool encrypt, const char *key)
|
|
|
|
{
|
2014-11-27 16:23:04 +00:00
|
|
|
const char **str = split_message((const uint8_t *)key, strlen(key), 16);
|
2017-06-18 20:22:33 +00:00
|
|
|
layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"),
|
2017-11-29 12:39:19 +00:00
|
|
|
encrypt ? _("Encrypt value of this key?") : _("Decrypt value of this key?"),
|
2014-06-20 22:31:44 +00:00
|
|
|
str[0], str[1], str[2], str[3], NULL, NULL);
|
2014-06-07 12:21:59 +00:00
|
|
|
}
|
2014-08-08 17:09:54 +00:00
|
|
|
|
2014-11-26 17:52:30 +00:00
|
|
|
void layoutEncryptMessage(const uint8_t *msg, uint32_t len, bool signing)
|
|
|
|
{
|
2014-11-27 16:23:04 +00:00
|
|
|
const char **str = split_message(msg, len, 16);
|
2017-06-18 20:22:33 +00:00
|
|
|
layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"),
|
|
|
|
signing ? _("Encrypt+Sign message?") : _("Encrypt message?"),
|
2014-11-26 17:52:30 +00:00
|
|
|
str[0], str[1], str[2], str[3], NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void layoutDecryptMessage(const uint8_t *msg, uint32_t len, const char *address)
|
|
|
|
{
|
2014-11-27 16:23:04 +00:00
|
|
|
const char **str = split_message(msg, len, 16);
|
2017-06-18 20:22:33 +00:00
|
|
|
layoutDialogSwipe(&bmp_icon_info, NULL, _("OK"),
|
|
|
|
address ? _("Decrypted signed message") : _("Decrypted message"),
|
2014-11-26 17:52:30 +00:00
|
|
|
str[0], str[1], str[2], str[3], NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2017-09-04 06:12:33 +00:00
|
|
|
void layoutResetWord(const char *word, int pass, int word_pos, bool last)
|
|
|
|
{
|
|
|
|
layoutLast = layoutResetWord;
|
2017-11-03 17:54:02 +00:00
|
|
|
layoutSwipe();
|
2017-09-04 06:12:33 +00:00
|
|
|
|
|
|
|
const char *btnYes;
|
|
|
|
if (last) {
|
|
|
|
if (pass == 1) {
|
|
|
|
btnYes = _("Finish");
|
|
|
|
} else {
|
|
|
|
btnYes = _("Again");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
btnYes = _("Next");
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *action;
|
|
|
|
if (pass == 1) {
|
|
|
|
action = _("Please check the seed");
|
|
|
|
} else {
|
|
|
|
action = _("Write down the seed");
|
|
|
|
}
|
|
|
|
|
|
|
|
char index_str[] = "##th word is:";
|
|
|
|
if (word_pos < 10) {
|
|
|
|
index_str[0] = ' ';
|
|
|
|
} else {
|
|
|
|
index_str[0] = '0' + word_pos / 10;
|
|
|
|
}
|
|
|
|
index_str[1] = '0' + word_pos % 10;
|
|
|
|
if (word_pos == 1 || word_pos == 21) {
|
|
|
|
index_str[2] = 's'; index_str[3] = 't';
|
|
|
|
} else
|
|
|
|
if (word_pos == 2 || word_pos == 22) {
|
|
|
|
index_str[2] = 'n'; index_str[3] = 'd';
|
|
|
|
} else
|
|
|
|
if (word_pos == 3 || word_pos == 23) {
|
|
|
|
index_str[2] = 'r'; index_str[3] = 'd';
|
|
|
|
}
|
|
|
|
|
|
|
|
int left = 0;
|
|
|
|
oledClear();
|
|
|
|
oledDrawBitmap(0, 0, &bmp_icon_info);
|
|
|
|
left = bmp_icon_info.width + 4;
|
|
|
|
|
2018-02-06 21:29:33 +00:00
|
|
|
oledDrawString(left, 0 * 9, action, FONT_STANDARD);
|
|
|
|
oledDrawString(left, 2 * 9, word_pos < 10 ? index_str + 1 : index_str, FONT_STANDARD);
|
|
|
|
oledDrawString(left, 3 * 9, word, FONT_STANDARD | FONT_DOUBLE);
|
2017-09-04 06:12:33 +00:00
|
|
|
oledHLine(OLED_HEIGHT - 13);
|
2018-02-06 21:34:31 +00:00
|
|
|
layoutButtonYes(btnYes);
|
2017-09-04 06:12:33 +00:00
|
|
|
oledRefresh();
|
|
|
|
}
|
|
|
|
|
2017-11-14 16:53:17 +00:00
|
|
|
void layoutAddress(const char *address, const char *desc, bool qrcode, bool ignorecase, const uint32_t *address_n, size_t address_n_count)
|
2014-08-08 17:09:54 +00:00
|
|
|
{
|
2017-07-11 19:30:01 +00:00
|
|
|
if (layoutLast != layoutAddress) {
|
2017-11-03 17:54:02 +00:00
|
|
|
layoutSwipe();
|
2017-07-11 19:30:01 +00:00
|
|
|
} else {
|
|
|
|
oledClear();
|
|
|
|
}
|
2014-08-08 17:09:54 +00:00
|
|
|
layoutLast = layoutAddress;
|
|
|
|
|
2017-09-08 13:29:55 +00:00
|
|
|
uint32_t addrlen = strlen(address);
|
2017-07-11 19:30:01 +00:00
|
|
|
if (qrcode) {
|
|
|
|
static unsigned char bitdata[QR_MAX_BITDATA];
|
2017-09-08 13:29:55 +00:00
|
|
|
char address_upcase[addrlen + 1];
|
|
|
|
if (ignorecase) {
|
|
|
|
for (uint32_t i = 0; i < addrlen + 1; i++) {
|
|
|
|
address_upcase[i] = address[i] >= 'a' && address[i] <= 'z' ?
|
|
|
|
address[i] + 'A' - 'a' : address[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int side = qr_encode(addrlen <= (ignorecase ? 60 : 40) ? QR_LEVEL_M : QR_LEVEL_L, 0,
|
|
|
|
ignorecase ? address_upcase : address, 0, bitdata);
|
2014-08-08 17:09:54 +00:00
|
|
|
|
2017-09-08 13:29:55 +00:00
|
|
|
oledInvert(0, 0, 63, 63);
|
2017-07-11 19:30:01 +00:00
|
|
|
if (side > 0 && side <= 29) {
|
2017-11-14 16:53:17 +00:00
|
|
|
int offset = 32 - side;
|
2017-07-11 19:30:01 +00:00
|
|
|
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))) {
|
2017-09-08 13:29:55 +00:00
|
|
|
oledBox(offset + i * 2, offset + j * 2,
|
|
|
|
offset + 1 + i * 2, offset + 1 + j * 2, false);
|
2017-07-11 19:30:01 +00:00
|
|
|
}
|
2014-08-08 17:09:54 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-11 19:30:01 +00:00
|
|
|
} else if (side > 0 && side <= 60) {
|
2017-09-08 13:29:55 +00:00
|
|
|
int offset = 32 - (side / 2);
|
2017-07-11 19:30:01 +00:00
|
|
|
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))) {
|
2017-09-08 13:29:55 +00:00
|
|
|
oledClearPixel(offset + i, offset + j);
|
2017-07-11 19:30:01 +00:00
|
|
|
}
|
2017-01-06 15:18:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2018-02-06 21:57:02 +00:00
|
|
|
uint32_t rowlen = (addrlen - 1) / (addrlen <= 42 ? 2 : addrlen <= 63 ? 3 : 4) + 1;
|
2017-07-11 19:30:01 +00:00
|
|
|
const char **str = split_message((const uint8_t *)address, addrlen, rowlen);
|
|
|
|
if (desc) {
|
2018-02-06 21:29:33 +00:00
|
|
|
oledDrawString(0, 0 * 9, desc, FONT_STANDARD);
|
2017-07-11 19:30:01 +00:00
|
|
|
}
|
|
|
|
for (int i = 0; i < 4; i++) {
|
2018-02-06 21:29:33 +00:00
|
|
|
oledDrawString(0, (i + 1) * 9 + 4, str[i], FONT_FIXED);
|
2017-07-11 19:30:01 +00:00
|
|
|
}
|
2018-02-06 21:29:33 +00:00
|
|
|
oledDrawString(0, 42, address_n_str(address_n, address_n_count), FONT_STANDARD);
|
2016-06-30 12:03:12 +00:00
|
|
|
}
|
2014-08-08 17:09:54 +00:00
|
|
|
|
2017-07-11 19:30:01 +00:00
|
|
|
if (!qrcode) {
|
2018-02-06 21:34:31 +00:00
|
|
|
layoutButtonNo(_("QR Code"));
|
2015-02-18 17:30:54 +00:00
|
|
|
}
|
2014-08-08 17:09:54 +00:00
|
|
|
|
2018-02-06 21:34:31 +00:00
|
|
|
layoutButtonYes(_("Continue"));
|
2014-08-08 17:09:54 +00:00
|
|
|
oledRefresh();
|
|
|
|
}
|
2015-02-20 19:22:05 +00:00
|
|
|
|
2015-11-19 10:48:26 +00:00
|
|
|
void layoutPublicKey(const uint8_t *pubkey)
|
|
|
|
{
|
2018-03-07 13:04:37 +00:00
|
|
|
char hex[32 * 2 + 1], desc[16];
|
2015-11-19 10:48:26 +00:00
|
|
|
strlcpy(desc, "Public Key: 00", sizeof(desc));
|
2018-03-07 13:04:37 +00:00
|
|
|
if (pubkey[0] == 1) {
|
|
|
|
/* ed25519 public key */
|
|
|
|
// pass - leave 00
|
|
|
|
} else {
|
|
|
|
data2hex(pubkey, 1, desc + 12);
|
|
|
|
}
|
2015-11-19 10:48:26 +00:00
|
|
|
data2hex(pubkey + 1, 32, hex);
|
2018-03-07 13:04:37 +00:00
|
|
|
const char **str = split_message((const uint8_t *)hex, 32 * 2, 16);
|
2017-06-18 20:22:33 +00:00
|
|
|
layoutDialogSwipe(&bmp_icon_question, NULL, _("Continue"), NULL,
|
2015-11-19 10:48:26 +00:00
|
|
|
desc, str[0], str[1], str[2], str[3], NULL);
|
|
|
|
}
|
|
|
|
|
2015-02-20 19:22:05 +00:00
|
|
|
void layoutSignIdentity(const IdentityType *identity, const char *challenge)
|
|
|
|
{
|
2015-04-02 14:48:50 +00:00
|
|
|
char row_proto[8 + 11 + 1];
|
2015-03-02 20:33:06 +00:00
|
|
|
char row_hostport[64 + 6 + 1];
|
|
|
|
char row_user[64 + 8 + 1];
|
|
|
|
|
2016-11-26 19:16:15 +00:00
|
|
|
bool is_gpg = (strcmp(identity->proto, "gpg") == 0);
|
|
|
|
|
2015-03-02 20:33:06 +00:00
|
|
|
if (identity->has_proto && identity->proto[0]) {
|
2015-08-21 15:04:38 +00:00
|
|
|
if (strcmp(identity->proto, "https") == 0) {
|
2017-06-18 20:22:33 +00:00
|
|
|
strlcpy(row_proto, _("Web sign in to:"), sizeof(row_proto));
|
2016-11-26 19:16:15 +00:00
|
|
|
} else if (is_gpg) {
|
2017-06-18 20:22:33 +00:00
|
|
|
strlcpy(row_proto, _("GPG sign for:"), sizeof(row_proto));
|
2015-08-21 15:04:38 +00:00
|
|
|
} else {
|
|
|
|
strlcpy(row_proto, identity->proto, sizeof(row_proto));
|
|
|
|
char *p = row_proto;
|
|
|
|
while (*p) { *p = toupper((int)*p); p++; }
|
2017-06-18 20:22:33 +00:00
|
|
|
strlcat(row_proto, _(" login to:"), sizeof(row_proto));
|
2015-08-21 15:04:38 +00:00
|
|
|
}
|
2015-03-02 20:33:06 +00:00
|
|
|
} else {
|
2017-06-18 20:22:33 +00:00
|
|
|
strlcpy(row_proto, _("Login to:"), sizeof(row_proto));
|
2015-03-02 20:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (identity->has_host && identity->host[0]) {
|
|
|
|
strlcpy(row_hostport, identity->host, sizeof(row_hostport));
|
|
|
|
if (identity->has_port && identity->port[0]) {
|
|
|
|
strlcat(row_hostport, ":", sizeof(row_hostport));
|
2015-03-03 16:42:25 +00:00
|
|
|
strlcat(row_hostport, identity->port, sizeof(row_hostport));
|
2015-03-02 20:33:06 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
row_hostport[0] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (identity->has_user && identity->user[0]) {
|
2017-06-18 20:22:33 +00:00
|
|
|
strlcpy(row_user, _("user: "), sizeof(row_user));
|
2015-03-02 20:33:06 +00:00
|
|
|
strlcat(row_user, identity->user, sizeof(row_user));
|
|
|
|
} else {
|
|
|
|
row_user[0] = 0;
|
|
|
|
}
|
|
|
|
|
2016-11-26 19:16:15 +00:00
|
|
|
if (is_gpg) {
|
|
|
|
// Split "First Last <first@last.com>" into 2 lines:
|
|
|
|
// "First Last"
|
|
|
|
// "first@last.com"
|
|
|
|
char *email_start = strchr(row_hostport, '<');
|
|
|
|
if (email_start) {
|
|
|
|
strlcpy(row_user, email_start + 1, sizeof(row_user));
|
|
|
|
*email_start = 0;
|
|
|
|
char *email_end = strchr(row_user, '>');
|
|
|
|
if (email_end) {
|
|
|
|
*email_end = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-18 20:22:33 +00:00
|
|
|
layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"),
|
|
|
|
_("Do you want to sign in?"),
|
2015-03-02 20:33:06 +00:00
|
|
|
row_proto[0] ? row_proto : NULL,
|
|
|
|
row_hostport[0] ? row_hostport : NULL,
|
|
|
|
row_user[0] ? row_user : NULL,
|
2015-02-20 19:22:05 +00:00
|
|
|
challenge,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
}
|
2016-05-16 16:58:13 +00:00
|
|
|
|
2016-07-14 16:11:20 +00:00
|
|
|
void layoutDecryptIdentity(const IdentityType *identity)
|
|
|
|
{
|
|
|
|
char row_proto[8 + 11 + 1];
|
|
|
|
char row_hostport[64 + 6 + 1];
|
|
|
|
char row_user[64 + 8 + 1];
|
|
|
|
|
|
|
|
if (identity->has_proto && identity->proto[0]) {
|
|
|
|
strlcpy(row_proto, identity->proto, sizeof(row_proto));
|
|
|
|
char *p = row_proto;
|
|
|
|
while (*p) { *p = toupper((int)*p); p++; }
|
2017-06-18 20:22:33 +00:00
|
|
|
strlcat(row_proto, _(" decrypt for:"), sizeof(row_proto));
|
2016-07-14 16:11:20 +00:00
|
|
|
} else {
|
2017-06-18 20:22:33 +00:00
|
|
|
strlcpy(row_proto, _("Decrypt for:"), sizeof(row_proto));
|
2016-07-14 16:11:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (identity->has_host && identity->host[0]) {
|
|
|
|
strlcpy(row_hostport, identity->host, sizeof(row_hostport));
|
|
|
|
if (identity->has_port && identity->port[0]) {
|
|
|
|
strlcat(row_hostport, ":", sizeof(row_hostport));
|
|
|
|
strlcat(row_hostport, identity->port, sizeof(row_hostport));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
row_hostport[0] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (identity->has_user && identity->user[0]) {
|
2017-06-18 20:22:33 +00:00
|
|
|
strlcpy(row_user, _("user: "), sizeof(row_user));
|
2016-07-14 16:11:20 +00:00
|
|
|
strlcat(row_user, identity->user, sizeof(row_user));
|
|
|
|
} else {
|
|
|
|
row_user[0] = 0;
|
|
|
|
}
|
|
|
|
|
2017-06-18 20:22:33 +00:00
|
|
|
layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"),
|
|
|
|
_("Do you want to decrypt?"),
|
2016-07-14 16:11:20 +00:00
|
|
|
row_proto[0] ? row_proto : NULL,
|
|
|
|
row_hostport[0] ? row_hostport : NULL,
|
|
|
|
row_user[0] ? row_user : NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2016-06-09 16:11:19 +00:00
|
|
|
void layoutU2FDialog(const char *verb, const char *appname, const BITMAP *appicon) {
|
|
|
|
if (!appicon) {
|
|
|
|
appicon = &bmp_icon_question;
|
|
|
|
}
|
2017-06-18 20:22:33 +00:00
|
|
|
layoutDialog(appicon, NULL, verb, NULL, verb, _("U2F security key?"), NULL, appname, NULL, NULL);
|
2016-05-16 16:58:13 +00:00
|
|
|
}
|
2017-05-30 16:41:02 +00:00
|
|
|
|
2017-07-20 21:58:19 +00:00
|
|
|
void layoutNEMDialog(const BITMAP *icon, const char *btnNo, const char *btnYes, const char *desc, const char *line1, const char *address) {
|
2017-07-01 13:38:04 +00:00
|
|
|
static char first_third[NEM_ADDRESS_SIZE / 3 + 1];
|
|
|
|
strlcpy(first_third, address, sizeof(first_third));
|
|
|
|
|
|
|
|
static char second_third[NEM_ADDRESS_SIZE / 3 + 1];
|
|
|
|
strlcpy(second_third, &address[NEM_ADDRESS_SIZE / 3], sizeof(second_third));
|
|
|
|
|
|
|
|
const char *third_third = &address[NEM_ADDRESS_SIZE * 2 / 3];
|
|
|
|
|
|
|
|
layoutDialogSwipe(icon,
|
|
|
|
btnNo,
|
|
|
|
btnYes,
|
|
|
|
desc,
|
|
|
|
line1,
|
|
|
|
first_third,
|
|
|
|
second_third,
|
|
|
|
third_third,
|
2017-07-20 21:58:19 +00:00
|
|
|
NULL,
|
|
|
|
NULL);
|
2017-07-01 13:38:04 +00:00
|
|
|
}
|
|
|
|
|
2017-07-20 21:58:19 +00:00
|
|
|
void layoutNEMTransferXEM(const char *desc, uint64_t quantity, const bignum256 *multiplier, uint64_t fee) {
|
2017-05-30 16:41:02 +00:00
|
|
|
char str_out[32], str_fee[32];
|
|
|
|
|
2017-07-20 21:58:19 +00:00
|
|
|
nem_mosaicFormatAmount(NEM_MOSAIC_DEFINITION_XEM, quantity, multiplier, str_out, sizeof(str_out));
|
|
|
|
nem_mosaicFormatAmount(NEM_MOSAIC_DEFINITION_XEM, fee, NULL, str_fee, sizeof(str_fee));
|
2017-05-30 16:41:02 +00:00
|
|
|
|
|
|
|
layoutDialogSwipe(&bmp_icon_question,
|
|
|
|
_("Cancel"),
|
|
|
|
_("Next"),
|
|
|
|
desc,
|
|
|
|
_("Confirm transfer of"),
|
|
|
|
str_out,
|
|
|
|
_("and network fee of"),
|
|
|
|
str_fee,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2017-07-01 13:38:04 +00:00
|
|
|
void layoutNEMNetworkFee(const char *desc, bool confirm, const char *fee1_desc, uint64_t fee1, const char *fee2_desc, uint64_t fee2) {
|
|
|
|
char str_fee1[32], str_fee2[32];
|
|
|
|
|
2017-07-20 21:58:19 +00:00
|
|
|
nem_mosaicFormatAmount(NEM_MOSAIC_DEFINITION_XEM, fee1, NULL, str_fee1, sizeof(str_fee1));
|
2017-07-01 13:38:04 +00:00
|
|
|
|
|
|
|
if (fee2_desc) {
|
2017-07-20 21:58:19 +00:00
|
|
|
nem_mosaicFormatAmount(NEM_MOSAIC_DEFINITION_XEM, fee2, NULL, str_fee2, sizeof(str_fee2));
|
2017-07-01 13:38:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
layoutDialogSwipe(&bmp_icon_question,
|
|
|
|
_("Cancel"),
|
|
|
|
confirm ? _("Confirm") : _("Next"),
|
|
|
|
desc,
|
|
|
|
fee1_desc,
|
|
|
|
str_fee1,
|
|
|
|
fee2_desc,
|
|
|
|
fee2_desc ? str_fee2 : NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2018-08-27 17:06:11 +00:00
|
|
|
void layoutNEMTransferMosaic(const NEMMosaicDefinition *definition, uint64_t quantity, const bignum256 *multiplier, uint8_t network) {
|
2017-07-20 21:58:19 +00:00
|
|
|
char str_out[32], str_levy[32];
|
|
|
|
|
|
|
|
nem_mosaicFormatAmount(definition, quantity, multiplier, str_out, sizeof(str_out));
|
|
|
|
|
|
|
|
if (definition->has_levy) {
|
2017-07-22 19:07:03 +00:00
|
|
|
nem_mosaicFormatLevy(definition, quantity, multiplier, network, str_levy, sizeof(str_levy));
|
2017-07-20 21:58:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
layoutDialogSwipe(&bmp_icon_question,
|
|
|
|
_("Cancel"),
|
|
|
|
_("Next"),
|
|
|
|
definition->has_name ? definition->name : _("Mosaic"),
|
|
|
|
_("Confirm transfer of"),
|
|
|
|
str_out,
|
|
|
|
definition->has_levy ? _("and levy of") : NULL,
|
|
|
|
definition->has_levy ? str_levy : NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void layoutNEMTransferUnknownMosaic(const char *namespace, const char *mosaic, uint64_t quantity, const bignum256 *multiplier) {
|
2017-07-22 18:02:41 +00:00
|
|
|
char mosaic_name[32];
|
|
|
|
nem_mosaicFormatName(namespace, mosaic, mosaic_name, sizeof(mosaic_name));
|
2017-05-30 16:41:02 +00:00
|
|
|
|
|
|
|
char str_out[32];
|
2017-07-20 21:58:19 +00:00
|
|
|
nem_mosaicFormatAmount(NULL, quantity, multiplier, str_out, sizeof(str_out));
|
2017-05-30 16:41:02 +00:00
|
|
|
|
|
|
|
char *decimal = strchr(str_out, '.');
|
|
|
|
if (decimal != NULL) {
|
|
|
|
*decimal = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
layoutDialogSwipe(&bmp_icon_question,
|
|
|
|
_("Cancel"),
|
|
|
|
_("I take the risk"),
|
|
|
|
_("Unknown Mosaic"),
|
|
|
|
_("Confirm transfer of"),
|
|
|
|
str_out,
|
|
|
|
_("raw units of"),
|
|
|
|
mosaic_name,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void layoutNEMTransferPayload(const uint8_t *payload, size_t length, bool encrypted) {
|
2018-05-25 14:34:06 +00:00
|
|
|
if (length >= 1 && payload[0] == 0xFE) {
|
2017-05-30 16:41:02 +00:00
|
|
|
char encoded[(length - 1) * 2 + 1];
|
|
|
|
data2hex(&payload[1], length - 1, encoded);
|
|
|
|
|
|
|
|
const char **str = split_message((uint8_t *) encoded, sizeof(encoded) - 1, 16);
|
|
|
|
layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Next"),
|
|
|
|
encrypted ? _("Encrypted hex data") : _("Unencrypted hex data"),
|
|
|
|
str[0], str[1], str[2], str[3], NULL, NULL);
|
|
|
|
} else {
|
|
|
|
const char **str = split_message(payload, length, 16);
|
|
|
|
layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Next"),
|
|
|
|
encrypted ? _("Encrypted message") : _("Unencrypted message"),
|
|
|
|
str[0], str[1], str[2], str[3], NULL, NULL);
|
|
|
|
}
|
|
|
|
}
|
2017-07-22 18:02:41 +00:00
|
|
|
|
|
|
|
void layoutNEMMosaicDescription(const char *description) {
|
|
|
|
const char **str = split_message((uint8_t *) description, strlen(description), 16);
|
|
|
|
layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Next"),
|
|
|
|
_("Mosaic Description"),
|
|
|
|
str[0], str[1], str[2], str[3], NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2018-08-27 17:06:11 +00:00
|
|
|
void layoutNEMLevy(const NEMMosaicDefinition *definition, uint8_t network) {
|
|
|
|
const NEMMosaicDefinition *mosaic;
|
2017-07-22 19:07:03 +00:00
|
|
|
if (nem_mosaicMatches(definition, definition->levy_namespace, definition->levy_mosaic, network)) {
|
2017-07-22 18:02:41 +00:00
|
|
|
mosaic = definition;
|
|
|
|
} else {
|
2017-07-22 19:07:03 +00:00
|
|
|
mosaic = nem_mosaicByName(definition->levy_namespace, definition->levy_mosaic, network);
|
2017-07-22 18:02:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char mosaic_name[32];
|
|
|
|
if (mosaic == NULL) {
|
|
|
|
nem_mosaicFormatName(definition->levy_namespace, definition->levy_mosaic, mosaic_name, sizeof(mosaic_name));
|
|
|
|
}
|
|
|
|
|
|
|
|
char str_out[32];
|
|
|
|
|
|
|
|
switch (definition->levy) {
|
2018-08-27 17:06:11 +00:00
|
|
|
case NEMMosaicLevy_MosaicLevy_Percentile:
|
2017-07-26 18:25:46 +00:00
|
|
|
bn_format_uint64(definition->fee, NULL, NULL, 0, 0, false, str_out, sizeof(str_out));
|
2017-07-22 18:02:41 +00:00
|
|
|
|
|
|
|
layoutDialogSwipe(&bmp_icon_question,
|
|
|
|
_("Cancel"),
|
|
|
|
_("Next"),
|
|
|
|
_("Percentile Levy"),
|
|
|
|
_("Raw levy value is"),
|
|
|
|
str_out,
|
|
|
|
_("in"),
|
|
|
|
mosaic ? (mosaic == definition ? _("the same mosaic") : mosaic->name) : mosaic_name,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
|
2018-08-27 17:06:11 +00:00
|
|
|
case NEMMosaicLevy_MosaicLevy_Absolute:
|
2017-07-22 18:02:41 +00:00
|
|
|
default:
|
|
|
|
nem_mosaicFormatAmount(mosaic, definition->fee, NULL, str_out, sizeof(str_out));
|
|
|
|
layoutDialogSwipe(&bmp_icon_question,
|
|
|
|
_("Cancel"),
|
|
|
|
_("Next"),
|
|
|
|
_("Absolute Levy"),
|
|
|
|
_("Levy is"),
|
|
|
|
str_out,
|
|
|
|
mosaic ? (mosaic == definition ? _("in the same mosaic") : NULL) : _("in raw units of"),
|
|
|
|
mosaic ? NULL : mosaic_name,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-10-03 11:11:53 +00:00
|
|
|
|
2017-10-09 21:02:42 +00:00
|
|
|
static inline bool is_slip18(const uint32_t *address_n, size_t address_n_count)
|
|
|
|
{
|
|
|
|
return address_n_count == 2 && address_n[0] == (0x80000000 + 10018) && (address_n[1] & 0x80000000) && (address_n[1] & 0x7FFFFFFF) <= 9;
|
|
|
|
}
|
|
|
|
|
2017-10-09 19:05:59 +00:00
|
|
|
void layoutCosiCommitSign(const uint32_t *address_n, size_t address_n_count, const uint8_t *data, uint32_t len, bool final_sign)
|
2017-10-03 11:11:53 +00:00
|
|
|
{
|
2017-10-09 19:05:59 +00:00
|
|
|
char *desc = final_sign ? _("CoSi sign message?") : _("CoSi commit message?");
|
2017-10-09 21:02:42 +00:00
|
|
|
char desc_buf[32];
|
|
|
|
if (is_slip18(address_n, address_n_count)) {
|
2017-10-09 19:05:59 +00:00
|
|
|
if (final_sign) {
|
|
|
|
strlcpy(desc_buf, _("CoSi sign index #?"), sizeof(desc_buf));
|
|
|
|
desc_buf[16] = '0' + (address_n[1] & 0x7FFFFFFF);
|
|
|
|
} else {
|
|
|
|
strlcpy(desc_buf, _("CoSi commit index #?"), sizeof(desc_buf));
|
|
|
|
desc_buf[18] = '0' + (address_n[1] & 0x7FFFFFFF);
|
|
|
|
}
|
|
|
|
desc = desc_buf;
|
|
|
|
}
|
2017-10-03 11:11:53 +00:00
|
|
|
char str[4][17];
|
|
|
|
if (len == 32) {
|
|
|
|
data2hex(data , 8, str[0]);
|
|
|
|
data2hex(data + 8, 8, str[1]);
|
|
|
|
data2hex(data + 16, 8, str[2]);
|
|
|
|
data2hex(data + 24, 8, str[3]);
|
|
|
|
} else {
|
|
|
|
strlcpy(str[0], "Data", sizeof(str[0]));
|
|
|
|
strlcpy(str[1], "of", sizeof(str[1]));
|
|
|
|
strlcpy(str[2], "unsupported", sizeof(str[2]));
|
|
|
|
strlcpy(str[3], "length", sizeof(str[3]));
|
|
|
|
}
|
2017-10-09 19:05:59 +00:00
|
|
|
layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"), desc,
|
2017-10-03 11:11:53 +00:00
|
|
|
str[0], str[1], str[2], str[3], NULL, NULL);
|
|
|
|
}
|