1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-09 06:50:58 +00:00

eth: get public key

This commit is contained in:
Tomas Susanka 2019-01-14 16:27:59 +01:00 committed by Pavol Rusnak
parent 93106a4968
commit 0d4efce5a7
5 changed files with 51 additions and 3 deletions

View File

@ -91,6 +91,7 @@ void fsm_msgDebugLinkFlashErase(const DebugLinkFlashErase *msg);
// ethereum
void fsm_msgEthereumGetAddress(const EthereumGetAddress *msg);
void fsm_msgEthereumGetPublicKey(const EthereumGetPublicKey *msg);
void fsm_msgEthereumSignTx(EthereumSignTx *msg); // not const because we mutate transaction
void fsm_msgEthereumTxAck(const EthereumTxAck *msg);
void fsm_msgEthereumSignMessage(const EthereumSignMessage *msg);

View File

@ -17,6 +17,52 @@
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
void fsm_msgEthereumGetPublicKey(const EthereumGetPublicKey *msg)
{
RESP_INIT(EthereumPublicKey);
CHECK_INITIALIZED
CHECK_PIN
const CoinInfo *coin = fsm_getCoin(true, "Bitcoin"); // we use Bitcoin-like format for ETH
const char *curve = coin->curve_name;
uint32_t fingerprint;
HDNode *node = node = fsm_getDerivedNode(curve, msg->address_n, msg->address_n_count, &fingerprint);
if (!node) return;
hdnode_fill_public_key(node);
if (msg->has_show_display && msg->show_display) {
layoutPublicKey(node->public_key);
if (!protectButton(ButtonRequestType_ButtonRequest_PublicKey, true)) {
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
layoutHome();
return;
}
}
resp->node.depth = node->depth;
resp->node.fingerprint = fingerprint;
resp->node.child_num = node->child_num;
resp->node.chain_code.size = 32;
memcpy(resp->node.chain_code.bytes, node->chain_code, 32);
resp->node.has_private_key = false;
resp->node.has_public_key = true;
resp->node.public_key.size = 33;
memcpy(resp->node.public_key.bytes, node->public_key, 33);
if (node->public_key[0] == 1) {
/* ed25519 public key */
resp->node.public_key.bytes[0] = 0;
}
resp->has_xpub = true;
hdnode_serialize_public(node, fingerprint, coin->xpub_magic, resp->xpub, sizeof(resp->xpub));
msg_write(MessageType_MessageType_EthereumPublicKey, resp);
layoutHome();
}
void fsm_msgEthereumSignTx(EthereumSignTx *msg)
{
CHECK_INITIALIZED

View File

@ -26,7 +26,7 @@ messages_%_pb2.py: messages-%.proto
$(Q)protoc -I/usr/include -I. $< --python_out=.
messages_map.h: messages_map.py messages_pb2.py
$(Q)$(PYTHON) $< | grep -v -e MessageType_Cardano -e MessageType_Tezos -e MessageType_Ripple -e MessageType_Monero -e MessageType_DebugMonero -e MessageType_Ontology -e MessageType_Tron -e EthereumGetPublicKey -e EthereumPublicKey > $@
$(Q)$(PYTHON) $< | grep -v -e MessageType_Cardano -e MessageType_Tezos -e MessageType_Ripple -e MessageType_Monero -e MessageType_DebugMonero -e MessageType_Ontology -e MessageType_Tron > $@
clean:
rm -f *.pb *.o *.d *.pb.c *.pb.h *_pb2.py messages_map.h

View File

@ -22,5 +22,7 @@ EthereumMessageSignature.address max_size:20
EthereumMessageSignature.signature max_size:65
EthereumGetAddress.address_n max_count:8
EthereumGetPublicKey.address_n max_count:8
EthereumAddress.address max_size:20
EthereumPublicKey.xpub max_size:113

View File

@ -49,8 +49,7 @@ def handle_message(message, extension):
)
print("\t// This file is automatically generated"
"by messages_map.py -- DO NOT EDIT!")
print("\t// This file is automatically generated by messages_map.py -- DO NOT EDIT!")
messages = defaultdict(list)