Skip to content

Commit 3a2f559

Browse files
authored
Merge branch 'trezor:main' into refactor-stellar-sign-flow
2 parents ccf56b4 + 5194e1e commit 3a2f559

File tree

144 files changed

+7887
-763
lines changed

Some content is hidden

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

144 files changed

+7887
-763
lines changed

Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ help: ## show this help
66
## style commands:
77

88
PY_FILES = $(shell find . -type f -name '*.py' | sed 'sO^\./OO' | grep -f ./tools/style.py.include | grep -v -f ./tools/style.py.exclude ) common/protob/pb2py
9+
PY_FILES_LIMITED = $(shell find . -type f -name '*.py' | sed 'sO^\./OO' | grep -f ./tools/style.py.include | grep -v -f ./tools/style.py.exclude | grep -v -f ./tools/style.py.typecheck.exclude ) common/protob/pb2py
910
C_FILES = $(shell find . -type f -name '*.[ch]' | grep -f ./tools/style.c.include | grep -v -f ./tools/style.c.exclude )
1011

1112

@@ -22,7 +23,9 @@ pystyle_check: ## run code style check on application sources and tests
2223
@echo [TYPECHECK]
2324
@make -C core typecheck
2425
@echo [FLAKE8]
25-
@flake8 $(PY_FILES)
26+
@flake8 $(PY_FILES_LIMITED)
27+
@echo [FLAKE8 - limited]
28+
@flake8 --extend-ignore=ANN $(PY_FILES)
2629
@echo [ISORT]
2730
@isort --check-only $(PY_FILES)
2831
@echo [BLACK]
@@ -45,7 +48,9 @@ pystyle: ## apply code style on application sources and tests
4548
@echo [TYPECHECK]
4649
@make -C core typecheck
4750
@echo [FLAKE8]
48-
@flake8 $(PY_FILES)
51+
@flake8 $(PY_FILES_LIMITED)
52+
@echo [FLAKE8 - limited]
53+
@flake8 --extend-ignore=ANN $(PY_FILES)
4954
@echo [PYLINT]
5055
@pylint $(PY_FILES)
5156
@echo [PYTHON]

common/protob/messages-thp.proto

Lines changed: 68 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,44 @@ import "options.proto";
1010
option (include_in_bitcoin_only) = true;
1111

1212

13+
/**
14+
* Mapping between Trezor wire identifier (uint) and a Thp protobuf message
15+
*/
16+
enum ThpMessageType {
17+
option (wire_enum) = true;
18+
19+
reserved 0 to 19; // Values reserved by other messages, see messages.proto
20+
ThpMessageType_Cancel = 20;
21+
reserved 21 to 25;
22+
ThpMessageType_ButtonRequest = 26;
23+
reserved 27 to 999;
24+
25+
reserved 1000; // MessageType_ThpCreateNewSession
26+
reserved 1001 to 1005; // never appeared in a release, reserved for future use
27+
ThpMessageType_ThpPairingRequest = 1006;
28+
ThpMessageType_ThpPairingRequestApproved = 1007;
29+
ThpMessageType_ThpSelectMethod = 1008;
30+
ThpMessageType_ThpPairingPreparationsFinished = 1009;
31+
ThpMessageType_ThpCredentialRequest = 1010;
32+
ThpMessageType_ThpCredentialResponse = 1011;
33+
ThpMessageType_ThpEndRequest = 1012;
34+
ThpMessageType_ThpEndResponse = 1013;
35+
reserved 1014 to 1015; // reserved for future use
36+
ThpMessageType_ThpCodeEntryCommitment = 1016;
37+
ThpMessageType_ThpCodeEntryChallenge = 1017;
38+
ThpMessageType_ThpCodeEntryCpaceTrezor = 1018;
39+
ThpMessageType_ThpCodeEntryCpaceHostTag = 1019;
40+
ThpMessageType_ThpCodeEntrySecret = 1020;
41+
reserved 1021 to 1023; // reserved for future use
42+
ThpMessageType_ThpQrCodeTag = 1024;
43+
ThpMessageType_ThpQrCodeSecret = 1025;
44+
reserved 1026 to 1031; // reserved for future use
45+
ThpMessageType_ThpNfcTagHost = 1032;
46+
ThpMessageType_ThpNfcTagTrezor = 1033;
47+
48+
reserved 1100 to 2147483647; // Values reserved by other messages, see messages.proto
49+
}
50+
1351
/**
1452
* Numeric identifiers of pairing methods.
1553
* @embed
@@ -25,10 +63,10 @@ enum ThpPairingMethod {
2563
* @embed
2664
*/
2765
message ThpDeviceProperties {
28-
optional string internal_model = 1; // Internal model name e.g. "T2B1".
29-
optional uint32 model_variant = 2; // Encodes the device properties such as color.
30-
optional uint32 protocol_version_major = 3; // The major version of the communication protocol used by the firmware.
31-
optional uint32 protocol_version_minor = 4; // The minor version of the communication protocol used by the firmware.
66+
required string internal_model = 1; // Internal model name e.g. "T2B1".
67+
optional uint32 model_variant = 2 [default=0]; // Encodes the device properties such as color.
68+
required uint32 protocol_version_major = 3; // The major version of the communication protocol used by the firmware.
69+
required uint32 protocol_version_minor = 4; // The minor version of the communication protocol used by the firmware.
3270
repeated ThpPairingMethod pairing_methods = 5; // The pairing methods supported by the Trezor.
3371
}
3472

@@ -44,10 +82,10 @@ message ThpHandshakeCompletionReqNoisePayload {
4482
* @start
4583
* @next Success
4684
*/
47-
message ThpCreateNewSession{
85+
message ThpCreateNewSession {
4886
optional string passphrase = 1;
49-
optional bool on_device = 2; // User wants to enter passphrase on the device
50-
optional bool derive_cardano = 3; // If True, Cardano keys will be derived. Ignored with BTC-only
87+
optional bool on_device = 2 [default=false]; // User wants to enter passphrase on the device
88+
optional bool derive_cardano = 3 [default=false]; // If True, Cardano keys will be derived. Ignored with BTC-only
5189
}
5290

5391

@@ -56,7 +94,7 @@ message ThpCreateNewSession{
5694
* @start
5795
* @next ThpPairingRequestApproved
5896
*/
59-
message ThpPairingRequest{
97+
message ThpPairingRequest {
6098
optional string host_name = 1; // Human-readable host name
6199
}
62100

@@ -65,7 +103,7 @@ message ThpPairingRequest{
65103
* @start
66104
* @next ThpSelectMethod
67105
*/
68-
message ThpPairingRequestApproved{
106+
message ThpPairingRequestApproved {
69107
}
70108

71109
/**
@@ -75,7 +113,7 @@ message ThpPairingRequestApproved{
75113
* @next ThpCodeEntryCommitment
76114
*/
77115
message ThpSelectMethod {
78-
optional ThpPairingMethod selected_pairing_method = 1;
116+
required ThpPairingMethod selected_pairing_method = 1;
79117
}
80118

81119
/**
@@ -84,40 +122,40 @@ message ThpSelectMethod {
84122
* @next ThpQrCodeTag
85123
* @next ThpNfcTagHost
86124
*/
87-
message ThpPairingPreparationsFinished{
125+
message ThpPairingPreparationsFinished {
88126
}
89127

90128
/**
91129
* Response: If Code Entry is an allowed pairing option, Trezor responds with a commitment.
92130
* @next ThpCodeEntryChallenge
93131
*/
94132
message ThpCodeEntryCommitment {
95-
optional bytes commitment = 1; // SHA-256 of Trezor's random 32-byte secret
133+
required bytes commitment = 1; // SHA-256 of Trezor's random 32-byte secret
96134
}
97135

98136
/**
99137
* Response: Host responds to Trezor's Code Entry commitment with a challenge.
100138
* @next ThpCodeEntryCpaceTrezor
101139
*/
102140
message ThpCodeEntryChallenge {
103-
optional bytes challenge = 1; // Host's random 32-byte challenge
141+
required bytes challenge = 1; // Host's random 32-byte challenge
104142
}
105143

106144
/**
107145
* Response: Trezor continues with the CPACE protocol.
108146
* @next ThpCodeEntryCpaceHostTag
109147
*/
110148
message ThpCodeEntryCpaceTrezor {
111-
optional bytes cpace_trezor_public_key = 1; // Trezor's ephemeral CPace public key
149+
required bytes cpace_trezor_public_key = 1; // Trezor's ephemeral CPace public key
112150
}
113151

114152
/**
115153
* Request: User selected Code Entry option in Host. Host starts CPACE protocol with Trezor.
116154
* @next ThpCodeEntrySecret
117155
*/
118156
message ThpCodeEntryCpaceHostTag {
119-
optional bytes cpace_host_public_key = 1; // Host's ephemeral CPace public key
120-
optional bytes tag = 2; // SHA-256 of shared secret
157+
required bytes cpace_host_public_key = 1; // Host's ephemeral CPace public key
158+
required bytes tag = 2; // SHA-256 of shared secret
121159

122160
}
123161

@@ -127,15 +165,15 @@ message ThpCodeEntryCpaceTrezor {
127165
* @next ThpEndRequest
128166
*/
129167
message ThpCodeEntrySecret {
130-
optional bytes secret = 1; // Trezor's secret
168+
required bytes secret = 1; // Trezor's secret
131169
}
132170

133171
/**
134172
* Request: User selected QR Code pairing option. Host sends a QR Tag.
135173
* @next ThpQrCodeSecret
136174
*/
137175
message ThpQrCodeTag {
138-
optional bytes tag = 1; // SHA-256 of shared secret
176+
required bytes tag = 1; // SHA-256 of shared secret
139177
}
140178

141179
/**
@@ -144,15 +182,15 @@ message ThpQrCodeTag {
144182
* @next ThpEndRequest
145183
*/
146184
message ThpQrCodeSecret {
147-
optional bytes secret = 1; // Trezor's secret
185+
required bytes secret = 1; // Trezor's secret
148186
}
149187

150188
/**
151189
* Request: User selected Unidirectional NFC pairing option. Host sends an Unidirectional NFC Tag.
152190
* @next ThpNfcTagTrezor
153191
*/
154192
message ThpNfcTagHost {
155-
optional bytes tag = 1; // Host's tag
193+
required bytes tag = 1; // Host's tag
156194
}
157195

158196
/**
@@ -161,7 +199,7 @@ message ThpNfcTagHost {
161199
* @next ThpEndRequest
162200
*/
163201
message ThpNfcTagTrezor {
164-
optional bytes tag = 1; // Trezor's tag
202+
required bytes tag = 1; // Trezor's tag
165203
}
166204

167205
/**
@@ -170,9 +208,9 @@ message ThpNfcTagTrezor {
170208
* @next ThpCredentialResponse
171209
*/
172210
message ThpCredentialRequest {
173-
optional bytes host_static_pubkey = 1; // Host's static public key identifying the credential.
174-
optional bool autoconnect = 2; // Whether host wants to autoconnect without user confirmation
175-
optional bytes credential = 3; // Host's previous credential
211+
required bytes host_static_pubkey = 1; // Host's static public key identifying the credential.
212+
optional bool autoconnect = 2 [default=false]; // Whether host wants to autoconnect without user confirmation
213+
optional bytes credential = 3; // Host's previous credential
176214
}
177215

178216
/**
@@ -181,8 +219,8 @@ message ThpCredentialRequest {
181219
* @next ThpEndRequest
182220
*/
183221
message ThpCredentialResponse {
184-
optional bytes trezor_static_pubkey = 1; // Trezor's static public key used in the handshake.
185-
optional bytes credential = 2; // The pairing credential issued by the Trezor to the host.
222+
required bytes trezor_static_pubkey = 1; // Trezor's static public key used in the handshake.
223+
required bytes credential = 2; // The pairing credential issued by the Trezor to the host.
186224
}
187225

188226
/**
@@ -214,8 +252,8 @@ message ThpEndResponse {}
214252
*/
215253
message ThpPairingCredential {
216254
option (internal_only) = true;
217-
optional ThpCredentialMetadata cred_metadata = 1; // Credential metadata
218-
optional bytes mac = 2; // Message authentication code generated by the Trezor
255+
required ThpCredentialMetadata cred_metadata = 1; // Credential metadata
256+
required bytes mac = 2; // Message authentication code generated by the Trezor
219257
}
220258

221259
/**
@@ -224,6 +262,6 @@ message ThpEndResponse {}
224262
*/
225263
message ThpAuthenticatedCredentialData {
226264
option (internal_only) = true;
227-
optional bytes host_static_pubkey = 1; // Host's static public key used in the handshake
228-
optional ThpCredentialMetadata cred_metadata = 2; // Credential metadata
265+
required bytes host_static_pubkey = 1; // Host's static public key used in the handshake
266+
required ThpCredentialMetadata cred_metadata = 2; // Credential metadata
229267
}

common/protob/messages.proto

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ option (include_in_bitcoin_only) = true;
1818
*/
1919
enum MessageType {
2020
option (has_bitcoin_only_values) = true;
21+
option (wire_enum) = true;
2122

2223
// Management
2324
MessageType_Initialize = 0 [(bitcoin_only) = true, (wire_in) = true, (wire_tiny) = true];
@@ -319,28 +320,11 @@ enum MessageType {
319320
MessageType_SolanaTxSignature = 905 [(wire_out) = true];
320321

321322
// THP
322-
MessageType_ThpCreateNewSession = 1000 [(bitcoin_only) = true, (wire_in) = true];
323-
reserved 1001 to 1005; // never appeared in a release, reserved for future use
324-
MessageType_ThpPairingRequest = 1006 [(bitcoin_only) = true];
325-
MessageType_ThpPairingRequestApproved = 1007 [(bitcoin_only) = true];
326-
MessageType_ThpSelectMethod = 1008 [(bitcoin_only) = true];
327-
MessageType_ThpPairingPreparationsFinished = 1009 [(bitcoin_only) = true];
328-
MessageType_ThpCredentialRequest = 1010 [(bitcoin_only) = true];
329-
MessageType_ThpCredentialResponse = 1011 [(bitcoin_only) = true];
330-
MessageType_ThpEndRequest = 1012 [(bitcoin_only) = true];
331-
MessageType_ThpEndResponse = 1013 [(bitcoin_only) = true];
332-
reserved 1014 to 1015;
333-
MessageType_ThpCodeEntryCommitment = 1016 [(bitcoin_only) = true];
334-
MessageType_ThpCodeEntryChallenge = 1017 [(bitcoin_only) = true];
335-
MessageType_ThpCodeEntryCpaceTrezor = 1018 [(bitcoin_only) = true];
336-
MessageType_ThpCodeEntryCpaceHostTag = 1019 [(bitcoin_only) = true];
337-
MessageType_ThpCodeEntrySecret = 1020 [(bitcoin_only) = true];
338-
reserved 1021 to 1023;
339-
MessageType_ThpQrCodeTag = 1024 [(bitcoin_only) = true];
340-
MessageType_ThpQrCodeSecret = 1025 [(bitcoin_only) = true];
341-
reserved 1026 to 1031;
342-
MessageType_ThpNfcTagHost = 1032 [(bitcoin_only) = true];
343-
MessageType_ThpNfcTagTrezor = 1033 [(bitcoin_only) = true];
323+
MessageType_ThpCreateNewSession = 1000;
324+
reserved 1001 to 1009; // see ThpMessageType in messages-thp.proto
325+
MessageType_ThpCredentialRequest = 1010;
326+
MessageType_ThpCredentialResponse = 1011;
327+
reserved 1012 to 1099; // see ThpMessageType in messages-thp.proto
344328

345329
// Nostr
346330
MessageType_NostrGetPubkey = 2001 [(wire_in) = true];

common/protob/options.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ The convention to achieve this is as follows:
4545
/** Options for tagging enum types */
4646
extend google.protobuf.EnumOptions {
4747
optional bool has_bitcoin_only_values = 51001; // indicate that some values should be excluded on BITCOIN_ONLY builds
48+
optional bool wire_enum = 51002; // this enum is used for mapping wire type integer to message type, it cannot be used as normal enum
4849
}
4950

5051
/** Options for tagging message types */

0 commit comments

Comments
 (0)