1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-25 00:48:19 +00:00

feat(common): protobuf messages for Ethereum definitions

This commit is contained in:
Martin Novák 2023-02-03 14:38:42 +01:00 committed by matejcik
parent e42e87174f
commit 5be6d07693
3 changed files with 102 additions and 33 deletions

View File

@ -0,0 +1,60 @@
syntax = "proto2";
package hw.trezor.messages.ethereum_definitions;
// Sugar for easier handling in Java
option java_package = "com.satoshilabs.trezor.lib.protobuf";
option java_outer_classname = "TrezorMessageEthereumDefinitions";
/**
* Ethereum definitions type enum.
* Used to check the encoded EthereumNetworkInfo or EthereumTokenInfo message.
*/
enum EthereumDefinitionType {
NETWORK = 0;
TOKEN = 1;
}
/**
* Ethereum network definition. Used to (de)serialize the definition.
*
* Definition types should not be cross-parseable, i.e., it should not be possible to
* incorrectly parse network info as token info or vice versa.
* To achieve that, the first field is wire type varint while the second field is wire type
* length-delimited. Both are a mismatch for the token definition.
*
* @embed
*/
message EthereumNetworkInfo {
required uint64 chain_id = 1;
required string symbol = 2;
required uint32 slip44 = 3;
required string name = 4;
}
/**
* Ethereum token definition. Used to (de)serialize the definition.
*
* Definition types should not be cross-parseable, i.e., it should not be possible to
* incorrectly parse network info as token info or vice versa.
* To achieve that, the first field is wire type length-delimited while the second field
* is wire type varint. Both are a mismatch for the network definition.
*
* @embed
*/
message EthereumTokenInfo {
required bytes address = 1;
required uint64 chain_id = 2;
required string symbol = 3;
required uint32 decimals = 4;
required string name = 5;
}
/**
* Contains an encoded Ethereum network and/or token definition. See ethereum-definitions.md for details.
* @embed
*/
message EthereumDefinitions {
optional bytes encoded_network = 1; // encoded Ethereum network
optional bytes encoded_token = 2; // encoded Ethereum token
}

View File

@ -5,6 +5,8 @@ package hw.trezor.messages.ethereum_eip712;
option java_package = "com.satoshilabs.trezor.lib.protobuf";
option java_outer_classname = "TrezorMessageEthereumEIP712";
import "messages-ethereum-definitions.proto";
// Separated from messages-ethereum.proto as it is not implemented on T1 side
// and defining all the messages and fields could be even impossible as recursive
@ -23,6 +25,7 @@ message EthereumSignTypedData {
repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node
required string primary_type = 2; // name of the root message struct
optional bool metamask_v4_compat = 3 [default=true]; // use MetaMask v4 (see https://github.com/MetaMask/eth-sig-util/issues/106)
optional ethereum_definitions.EthereumDefinitions definitions = 4; // network and/or token definitions
}
/**

View File

@ -6,6 +6,7 @@ option java_package = "com.satoshilabs.trezor.lib.protobuf";
option java_outer_classname = "TrezorMessageEthereum";
import "messages-common.proto";
import "messages-ethereum-definitions.proto";
/**
@ -37,6 +38,7 @@ message EthereumPublicKey {
message EthereumGetAddress {
repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node
optional bool show_display = 2; // optionally show on display before sending the result
optional bytes encoded_network = 3; // encoded Ethereum network, see ethereum-definitions.md for details
}
/**
@ -68,6 +70,7 @@ message EthereumSignTx {
optional uint32 data_length = 8 [default=0]; // Length of transaction payload
required uint64 chain_id = 9; // Chain Id for EIP 155
optional uint32 tx_type = 10; // Used for Wanchain
optional ethereum_definitions.EthereumDefinitions definitions = 12; // network and/or token definitions for tx
}
/**
@ -89,6 +92,7 @@ message EthereumSignTxEIP1559 {
required uint32 data_length = 9; // Length of transaction payload
required uint64 chain_id = 10; // Chain Id for EIP 155
repeated EthereumAccessList access_list = 11; // Access List
optional ethereum_definitions.EthereumDefinitions definitions = 12; // network and/or token definitions for tx
message EthereumAccessList {
required string address = 1;
@ -127,6 +131,7 @@ message EthereumTxAck {
message EthereumSignMessage {
repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node
required bytes message = 2; // message to be signed
optional bytes encoded_network = 3; // encoded Ethereum network, see ethereum-definitions.md for details
}
/**
@ -160,6 +165,7 @@ message EthereumSignTypedHash {
repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node
required bytes domain_separator_hash = 2; // Hash of domainSeparator of typed data to be signed
optional bytes message_hash = 3; // Hash of the data of typed data to be signed (empty if domain-only data)
optional bytes encoded_network = 4; // encoded Ethereum network, see ethereum-definitions.md for details
}
/**