Skip to content

Commit 945a0f8

Browse files
authored
feat(legacy): support external ethereum definitions & onekey ethereum (#447)
* feat(legacy): support external ethereum definitions & onekey ethereum * refactor(legacy): bump version to 3.3.0
1 parent a013aec commit 945a0f8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+4468
-358
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2023-04-03T13:44:24+00:00
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
syntax = "proto2";
2+
package hw.trezor.messages.ethereum_definitions;
3+
4+
// Sugar for easier handling in Java
5+
option java_package = "com.satoshilabs.trezor.lib.protobuf";
6+
option java_outer_classname = "TrezorMessageEthereumDefinitions";
7+
8+
9+
/**
10+
* Ethereum definitions type enum.
11+
* Used to check the encoded EthereumNetworkInfo or EthereumTokenInfo message.
12+
*/
13+
enum EthereumDefinitionType {
14+
NETWORK = 0;
15+
TOKEN = 1;
16+
}
17+
18+
/**
19+
* Ethereum network definition. Used to (de)serialize the definition.
20+
*
21+
* Definition types should not be cross-parseable, i.e., it should not be possible to
22+
* incorrectly parse network info as token info or vice versa.
23+
* To achieve that, the first field is wire type varint while the second field is wire type
24+
* length-delimited. Both are a mismatch for the token definition.
25+
*
26+
* @embed
27+
*/
28+
message EthereumNetworkInfo {
29+
required uint64 chain_id = 1;
30+
required string symbol = 2;
31+
required uint32 slip44 = 3;
32+
required string name = 4;
33+
optional string icon = 101;
34+
optional uint64 primary_color = 102;
35+
}
36+
37+
/**
38+
* Ethereum token definition. Used to (de)serialize the definition.
39+
*
40+
* Definition types should not be cross-parseable, i.e., it should not be possible to
41+
* incorrectly parse network info as token info or vice versa.
42+
* To achieve that, the first field is wire type length-delimited while the second field
43+
* is wire type varint. Both are a mismatch for the network definition.
44+
*
45+
* @embed
46+
*/
47+
message EthereumTokenInfo {
48+
required bytes address = 1;
49+
required uint64 chain_id = 2;
50+
required string symbol = 3;
51+
required uint32 decimals = 4;
52+
required string name = 5;
53+
}
54+
55+
/**
56+
* Contains an encoded Ethereum network and/or token definition. See ethereum-definitions.md for details.
57+
* @embed
58+
*/
59+
message EthereumDefinitions {
60+
optional bytes encoded_network = 1; // encoded Ethereum network
61+
optional bytes encoded_token = 2; // encoded Ethereum token
62+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
syntax = "proto2";
2+
package hw.trezor.messages.ethereum_eip712_onekey;
3+
4+
// Sugar for easier handling in Java
5+
option java_package = "com.satoshilabs.trezor.lib.protobuf";
6+
option java_outer_classname = "TrezorMessageEthereumEIP712OneKey";
7+
8+
9+
// Separated from messages-ethereum.proto as it is not implemented on T1 side
10+
// and defining all the messages and fields could be even impossible as recursive
11+
// messages are used here
12+
13+
14+
/**
15+
* Request: Ask device to sign typed data
16+
* @start
17+
* @next EthereumTypedDataStructRequestOneKey
18+
* @next EthereumTypedDataValueRequestOneKey
19+
* @next EthereumTypedDataSignatureOneKey
20+
* @next Failure
21+
*/
22+
message EthereumSignTypedDataOneKey {
23+
repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node
24+
required string primary_type = 2; // name of the root message struct
25+
optional bool metamask_v4_compat = 3 [default=true]; // use MetaMask v4 (see https://github.com/MetaMask/eth-sig-util/issues/106)
26+
optional uint64 chain_id = 4; // used to personalized display
27+
}
28+
29+
/**
30+
* Response: Device asks for type information about a struct.
31+
* @next EthereumTypedDataStructAckOneKey
32+
*/
33+
message EthereumTypedDataStructRequestOneKey {
34+
required string name = 1; // name of the requested struct
35+
}
36+
37+
/**
38+
* Request: Type information about a struct.
39+
* @next EthereumTypedDataStructRequestOneKey
40+
*/
41+
message EthereumTypedDataStructAckOneKey {
42+
repeated EthereumStructMemberOneKey members = 1;
43+
44+
message EthereumStructMemberOneKey {
45+
required EthereumFieldTypeOneKey type = 1;
46+
required string name = 2;
47+
}
48+
49+
message EthereumFieldTypeOneKey {
50+
required EthereumDataTypeOneKey data_type = 1;
51+
optional uint32 size = 2; // for integer types: size in bytes (uint8 has size 1, uint256 has size 32)
52+
// for bytes types: size in bytes, or unset for dynamic
53+
// for arrays: size in elements, or unset for dynamic
54+
// for structs: number of members
55+
// for string, bool and address: unset
56+
optional EthereumFieldTypeOneKey entry_type = 3; // for array types, type of single entry
57+
optional string struct_name = 4; // for structs: its name
58+
}
59+
60+
enum EthereumDataTypeOneKey {
61+
UINT = 1;
62+
INT = 2;
63+
BYTES = 3;
64+
STRING = 4;
65+
BOOL = 5;
66+
ADDRESS = 6;
67+
ARRAY = 7;
68+
STRUCT = 8;
69+
}
70+
}
71+
72+
/**
73+
* Response: Device asks for data at the specific member path.
74+
* @next EthereumTypedDataValueAckOneKey
75+
*/
76+
message EthereumTypedDataValueRequestOneKey {
77+
repeated uint32 member_path = 1; // member path requested by device
78+
}
79+
80+
/**
81+
* Request: Single value of a specific atomic field.
82+
* @next EthereumTypedDataValueRequestOneKey
83+
*/
84+
message EthereumTypedDataValueAckOneKey {
85+
required bytes value = 1;
86+
// * atomic types: value of the member.
87+
// Length must match the `size` of the corresponding field type, unless the size is dynamic.
88+
// * array types: number of elements, encoded as uint16.
89+
// * struct types: undefined, Trezor will not query a struct field.
90+
}

common/protob/messages-ethereum-eip712.proto

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ package hw.trezor.messages.ethereum_eip712;
55
option java_package = "com.satoshilabs.trezor.lib.protobuf";
66
option java_outer_classname = "TrezorMessageEthereumEIP712";
77

8+
import "messages-ethereum-definitions.proto";
9+
810

911
// Separated from messages-ethereum.proto as it is not implemented on T1 side
1012
// and defining all the messages and fields could be even impossible as recursive
@@ -20,9 +22,10 @@ option java_outer_classname = "TrezorMessageEthereumEIP712";
2022
* @next Failure
2123
*/
2224
message EthereumSignTypedData {
23-
repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node
24-
required string primary_type = 2; // name of the root message struct
25-
optional bool metamask_v4_compat = 3 [default=true]; // use MetaMask v4 (see https://github.com/MetaMask/eth-sig-util/issues/106)
25+
repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node
26+
required string primary_type = 2; // name of the root message struct
27+
optional bool metamask_v4_compat = 3 [default=true]; // use MetaMask v4 (see https://github.com/MetaMask/eth-sig-util/issues/106)
28+
optional ethereum_definitions.EthereumDefinitions definitions = 4; // network and/or token definitions
2629
}
2730

2831
/**
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
syntax = "proto2";
2+
package hw.trezor.messages.ethereum_onekey;
3+
4+
// Sugar for easier handling in Java
5+
option java_package = "com.satoshilabs.trezor.lib.protobuf";
6+
option java_outer_classname = "TrezorMessageEthereumOnekey";
7+
8+
import "messages-common.proto";
9+
10+
11+
/**
12+
* Request: Ask device for public key corresponding to address_n path
13+
* @start
14+
* @next EthereumGetPublicKeyOneKey
15+
* @next Failure
16+
*/
17+
message EthereumGetPublicKeyOneKey {
18+
repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node
19+
optional bool show_display = 2; // optionally show on display before sending the result
20+
optional uint64 chain_id = 3; // used to personalized display
21+
}
22+
23+
/**
24+
* Response: Contains public key derived from device private seed
25+
* @end
26+
*/
27+
message EthereumPublicKeyOneKey {
28+
required hw.trezor.messages.common.HDNodeType node = 1; // BIP32 public node
29+
required string xpub = 2; // serialized form of public node
30+
}
31+
32+
/**
33+
* Request: Ask device for Ethereum address corresponding to address_n path
34+
* @start
35+
* @next EthereumAddressOneKey
36+
* @next Failure
37+
*/
38+
message EthereumGetAddressOneKey {
39+
repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node
40+
optional bool show_display = 2; // optionally show on display before sending the result
41+
optional uint64 chain_id = 3; // used to personalized display
42+
}
43+
44+
/**
45+
* Response: Contains an Ethereum address derived from device private seed
46+
* @end
47+
*/
48+
message EthereumAddressOneKey {
49+
optional bytes _old_address = 1 [deprecated=true]; // trezor <1.8.0, <2.1.0 - raw bytes of Ethereum address
50+
optional string address = 2; // Ethereum address as hex-encoded string
51+
}
52+
53+
/**
54+
* Request: Ask device to sign transaction
55+
* gas_price, gas_limit and chain_id must be provided and non-zero.
56+
* All other fields are optional and default to value `0` if missing.
57+
* Note: the first at most 1024 bytes of data MUST be transmitted as part of this message.
58+
* @start
59+
* @next EthereumTxRequestOnekey
60+
* @next Failure
61+
*/
62+
message EthereumSignTxOneKey {
63+
repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node
64+
optional bytes nonce = 2 [default='']; // <=256 bit unsigned big endian
65+
required bytes gas_price = 3; // <=256 bit unsigned big endian (in wei)
66+
required bytes gas_limit = 4; // <=256 bit unsigned big endian
67+
optional string to = 11 [default='']; // recipient address
68+
optional bytes value = 6 [default='']; // <=256 bit unsigned big endian (in wei)
69+
optional bytes data_initial_chunk = 7 [default='']; // The initial data chunk (<= 1024 bytes)
70+
optional uint32 data_length = 8 [default=0]; // Length of transaction payload
71+
required uint64 chain_id = 9; // Chain Id for EIP 155
72+
optional uint32 tx_type = 10; // Used for Wanchain
73+
}
74+
75+
/**
76+
* Request: Ask device to sign EIP1559 transaction
77+
* Note: the first at most 1024 bytes of data MUST be transmitted as part of this message.
78+
* @start
79+
* @next EthereumTxRequestOneKey
80+
* @next Failure
81+
*/
82+
message EthereumSignTxEIP1559OneKey {
83+
repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node
84+
required bytes nonce = 2; // <=256 bit unsigned big endian
85+
required bytes max_gas_fee = 3; // <=256 bit unsigned big endian (in wei)
86+
required bytes max_priority_fee = 4; // <=256 bit unsigned big endian (in wei)
87+
required bytes gas_limit = 5; // <=256 bit unsigned big endian
88+
optional string to = 6 [default='']; // recipient address
89+
required bytes value = 7; // <=256 bit unsigned big endian (in wei)
90+
optional bytes data_initial_chunk = 8 [default='']; // The initial data chunk (<= 1024 bytes)
91+
required uint32 data_length = 9; // Length of transaction payload
92+
required uint64 chain_id = 10; // Chain Id for EIP 155
93+
repeated EthereumAccessListOneKey access_list = 11; // Access List
94+
95+
message EthereumAccessListOneKey {
96+
required string address = 1;
97+
repeated bytes storage_keys = 2;
98+
}
99+
}
100+
101+
/**
102+
* Response: Device asks for more data from transaction payload, or returns the signature.
103+
* If data_length is set, device awaits that many more bytes of payload.
104+
* Otherwise, the signature_* fields contain the computed transaction signature. All three fields will be present.
105+
* @end
106+
* @next EthereumTxAckOneKey
107+
*/
108+
message EthereumTxRequestOneKey {
109+
optional uint32 data_length = 1; // Number of bytes being requested (<= 1024)
110+
optional uint32 signature_v = 2; // Computed signature (recovery parameter, limited to 27 or 28)
111+
optional bytes signature_r = 3; // Computed signature R component (256 bit)
112+
optional bytes signature_s = 4; // Computed signature S component (256 bit)
113+
}
114+
115+
/**
116+
* Request: Transaction payload data.
117+
* @next EthereumTxRequestOneKey
118+
*/
119+
message EthereumTxAckOneKey {
120+
required bytes data_chunk = 1; // Bytes from transaction payload (<= 1024 bytes)
121+
}
122+
123+
/**
124+
* Request: Ask device to sign message
125+
* @start
126+
* @next EthereumMessageSignatureOneKey
127+
* @next Failure
128+
*/
129+
message EthereumSignMessageOneKey {
130+
repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node
131+
required bytes message = 2; // message to be signed
132+
optional uint64 chain_id = 3; // used to personalized display
133+
}
134+
135+
/**
136+
* Response: Signed message
137+
* @end
138+
*/
139+
message EthereumMessageSignatureOneKey {
140+
required bytes signature = 2; // signature of the message
141+
required string address = 3; // address used to sign the message
142+
}
143+
144+
/**
145+
* Request: Ask device to verify message
146+
* @start
147+
* @next Success
148+
* @next Failure
149+
*/
150+
message EthereumVerifyMessageOneKey {
151+
required bytes signature = 2; // signature to verify
152+
required bytes message = 3; // message to verify
153+
required string address = 4; // address to verify
154+
optional uint64 chain_id = 5; // used to personalized display
155+
}
156+
157+
/**
158+
* Request: Ask device to sign hash of typed data
159+
* @start
160+
* @next EthereumTypedDataSignatureOneKey
161+
* @next Failure
162+
*/
163+
message EthereumSignTypedHashOneKey {
164+
repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node
165+
required bytes domain_separator_hash = 2; // Hash of domainSeparator of typed data to be signed
166+
optional bytes message_hash = 3; // Hash of the data of typed data to be signed (empty if domain-only data)
167+
optional uint64 chain_id = 4; // used to personalized display
168+
}
169+
170+
/**
171+
* Response: Signed typed data
172+
* @end
173+
*/
174+
message EthereumTypedDataSignatureOneKey {
175+
required bytes signature = 1; // signature of the typed data
176+
required string address = 2; // address used to sign the typed data
177+
}
178+
179+
180+
/**
181+
* Request: Ask device to sign message EIP712
182+
* @start
183+
* @next EthereumMessageSignature
184+
* @next Failure
185+
*/
186+
message EthereumSignMessageEIP712 {
187+
repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node
188+
optional bytes domain_hash = 2; // domainSeparator hash
189+
optional bytes message_hash = 3; // message hash
190+
}
191+

0 commit comments

Comments
 (0)