diff --git a/firmware/fsm.c b/firmware/fsm.c index f460cd5956..f05e952781 100644 --- a/firmware/fsm.c +++ b/firmware/fsm.c @@ -50,6 +50,7 @@ #include "secp256k1.h" #include #include "ethereum.h" +#include "nem.h" #include "gettext.h" // message methods @@ -1104,6 +1105,45 @@ void fsm_msgSetU2FCounter(SetU2FCounter *msg) layoutHome(); } +void fsm_msgNEMGetAddress(NEMGetAddress *msg) +{ + if (!msg->has_network) { + msg->network = NEM_NETWORK_MAINNET; + } + + const char *network; + CHECK_PARAM((network = nem_network_name(msg->network)), _("Invalid NEM network")); + + CHECK_INITIALIZED + CHECK_PIN + + RESP_INIT(NEMAddress); + + HDNode *node = fsm_getDerivedNode(ED25519_KECCAK_NAME, msg->address_n, msg->address_n_count); + if (!node) return; + + if (!hdnode_get_nem_address(node, msg->network, resp->address)) + return; + + if (msg->has_show_display && msg->show_display) { + char desc[16]; + strlcpy(desc, network, sizeof(desc)); + strlcat(desc, ":", sizeof(desc)); + + bool qrcode = false; + for (;;) { + layoutAddress(resp->address, desc, qrcode); + if (protectButton(ButtonRequestType_ButtonRequest_Address, false)) { + break; + } + qrcode = !qrcode; + } + } + + msg_write(MessageType_MessageType_NEMAddress, resp); + layoutHome(); +} + #if DEBUG_LINK void fsm_msgDebugLinkGetState(DebugLinkGetState *msg) diff --git a/firmware/fsm.h b/firmware/fsm.h index cbd4712c44..e127b386dc 100644 --- a/firmware/fsm.h +++ b/firmware/fsm.h @@ -66,6 +66,8 @@ void fsm_msgEthereumTxAck(EthereumTxAck *msg); void fsm_msgEthereumSignMessage(EthereumSignMessage *msg); void fsm_msgEthereumVerifyMessage(EthereumVerifyMessage *msg); +void fsm_msgNEMGetAddress(NEMGetAddress *msg); + // debug message functions #if DEBUG_LINK //void fsm_msgDebugLinkDecision(DebugLinkDecision *msg);