-
Notifications
You must be signed in to change notification settings - Fork 74
/
instructions.py
259 lines (196 loc) · 9.31 KB
/
instructions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
from ragger.navigator import NavInsID
from ragger.firmware import Firmware
from ragger_bitcoin.ragger_instructions import Instructions
def message_instruction_approve(model: Firmware, save_screenshot=True) -> Instructions:
instructions = Instructions(model)
if model.name.startswith("nano"):
instructions.nano_skip_screen("Path", save_screenshot=save_screenshot)
instructions.same_request("Sign", save_screenshot=save_screenshot)
else:
instructions.review_message(save_screenshot=save_screenshot)
instructions.confirm_message(save_screenshot=save_screenshot)
return instructions
def message_instruction_approve_long(model: Firmware) -> Instructions:
instructions = Instructions(model)
if model.name.startswith("nano"):
instructions.nano_skip_screen("Path")
instructions.same_request("Processing")
instructions.new_request("Processing")
instructions.new_request("Processing")
instructions.new_request("Processing")
instructions.new_request("Sign")
else:
instructions.review_message(page_count=5)
instructions.confirm_message()
return instructions
def message_instruction_reject(model: Firmware) -> Instructions:
instructions = Instructions(model)
if model.name.startswith("nano"):
instructions.new_request("Reject")
else:
instructions.reject_message()
return instructions
def pubkey_instruction_approve(model: Firmware) -> Instructions:
instructions = Instructions(model)
if model.name.startswith("nano"):
instructions.new_request("Approve")
else:
instructions.choice_confirm()
instructions.status_dismiss("approved")
return instructions
def pubkey_instruction_reject_early(model: Firmware) -> Instructions:
instructions = Instructions(model)
if model.name.startswith("nano"):
instructions.new_request("Reject")
else:
instructions.footer_cancel()
return instructions
def pubkey_reject(model: Firmware) -> Instructions:
instructions = Instructions(model)
if model.name.startswith("nano"):
instructions.nano_skip_screen("Reject")
instructions.same_request("Reject")
else:
instructions.choice_reject()
instructions.status_dismiss("rejected", status_on_same_request=False)
return instructions
def wallet_instruction_approve(model: Firmware) -> Instructions:
instructions = Instructions(model)
if model.name.startswith("nano"):
instructions.new_request("Approve")
else:
instructions.address_confirm()
return instructions
def register_wallet_instruction_approve(model: Firmware) -> Instructions:
instructions = Instructions(model)
if model.name.startswith("nano"):
instructions.new_request("Approve")
instructions.same_request("Approve")
instructions.same_request("Approve")
else:
instructions.choice_confirm()
instructions.choice_confirm()
instructions.choice_confirm()
return instructions
def register_wallet_instruction_approve_long(model: Firmware) -> Instructions:
instructions = Instructions(model)
if model.name.startswith("nano"):
instructions.new_request("Approve")
instructions.same_request("Approve")
instructions.same_request("Approve")
instructions.same_request("Approve")
else:
instructions.choice_confirm()
instructions.choice_confirm()
instructions.choice_confirm()
instructions.choice_confirm()
return instructions
def register_wallet_instruction_approve_unusual(model: Firmware) -> Instructions:
instructions = Instructions(model)
if model.name.startswith("nano"):
instructions.new_request("Approve")
instructions.same_request("Approve")
else:
instructions.choice_confirm()
instructions.choice_confirm()
return instructions
def register_wallet_instruction_reject(model: Firmware) -> Instructions:
instructions = Instructions(model)
if model.name.startswith("nano"):
instructions.new_request("Reject")
else:
instructions.choice_reject()
instructions.status_dismiss("rejected", status_on_same_request=False)
return instructions
def sign_psbt_instruction_tap(model: Firmware) -> Instructions:
instructions = Instructions(model)
if model.name.startswith("nano"):
return instructions
instructions.review_start(save_screenshot=False)
return instructions
def sign_psbt_instruction_approve(model: Firmware, save_screenshot: bool = True, *, has_spend_from_wallet: bool = False, to_on_next_page: bool = False, fees_on_next_page: bool = False, has_unverifiedwarning: bool = False, has_sighashwarning: bool = False, has_feewarning: bool = False) -> Instructions:
instructions = Instructions(model)
if model.name.startswith("nano"):
instructions.new_request("Continue", save_screenshot=save_screenshot)
for has_step in [has_spend_from_wallet, has_unverifiedwarning, has_sighashwarning, has_feewarning]:
if has_step:
instructions.same_request(
"Continue", save_screenshot=save_screenshot)
instructions.same_request("Sign", save_screenshot=save_screenshot)
else:
instructions.new_request("Review", NavInsID.USE_CASE_REVIEW_TAP, NavInsID.USE_CASE_REVIEW_TAP,
save_screenshot=save_screenshot)
if has_sighashwarning:
instructions.same_request(
"Non-default sighash", NavInsID.USE_CASE_REVIEW_TAP, NavInsID.USE_CASE_REVIEW_TAP, save_screenshot=save_screenshot)
if has_unverifiedwarning:
instructions.same_request(
"Unverified inputs", NavInsID.USE_CASE_REVIEW_TAP, NavInsID.USE_CASE_REVIEW_TAP, save_screenshot=save_screenshot)
instructions.same_request("Amount", NavInsID.USE_CASE_REVIEW_TAP, NavInsID.USE_CASE_REVIEW_TAP,
save_screenshot=save_screenshot)
if to_on_next_page:
instructions.same_request("To", NavInsID.USE_CASE_REVIEW_TAP, NavInsID.USE_CASE_REVIEW_TAP,
save_screenshot=save_screenshot)
if fees_on_next_page:
instructions.same_request("Fees", NavInsID.USE_CASE_REVIEW_TAP, NavInsID.USE_CASE_REVIEW_TAP,
save_screenshot=save_screenshot)
if has_feewarning:
instructions.same_request(
"Fees are above", NavInsID.USE_CASE_REVIEW_TAP, NavInsID.USE_CASE_REVIEW_TAP, save_screenshot=save_screenshot)
instructions.confirm_transaction(save_screenshot=save_screenshot)
return instructions
def sign_psbt_instruction_approve_selftransfer(model: Firmware) -> Instructions:
instructions = Instructions(model)
if model.name.startswith("nano"):
instructions.new_request("Sign")
else:
instructions.new_request(
"Review", NavInsID.USE_CASE_REVIEW_TAP, NavInsID.USE_CASE_REVIEW_TAP)
instructions.same_request(
"Amount", NavInsID.USE_CASE_REVIEW_TAP, NavInsID.USE_CASE_REVIEW_TAP)
instructions.confirm_transaction()
return instructions
def sign_psbt_instruction_approve_streaming(model: Firmware, output_count: int, save_screenshot: bool = True) -> Instructions:
instructions = Instructions(model)
if model.name.startswith("nano"):
instructions.new_request("Continue") # first output
for output_index in range(1, output_count):
if output_index < 2:
instructions.same_request("Continue")
else:
instructions.new_request("Continue")
instructions.same_request("Sign", save_screenshot=save_screenshot)
else:
instructions.review_start(
output_count=output_count, save_screenshot=save_screenshot)
instructions.review_fees(save_screenshot=save_screenshot)
instructions.confirm_transaction(save_screenshot=save_screenshot)
return instructions
def sign_psbt_instruction_approve_external_inputs(model: Firmware, output_count) -> Instructions:
instructions = Instructions(model)
if model.name.startswith("nano"):
instructions.new_request("Continue")
for output_index in range(output_count):
if output_index < 2:
instructions.same_request("Continue")
else:
instructions.new_request("Continue")
instructions.same_request("Sign")
else:
instructions.review_start(output_count=output_count, has_warning=True)
instructions.review_fees(fees_on_same_request=True)
instructions.confirm_transaction()
return instructions
def e2e_register_wallet_instruction(model: Firmware, n_keys) -> Instructions:
instructions = Instructions(model)
if model.name.startswith("nano"):
instructions.new_request("Approve", save_screenshot=False)
for _ in range(n_keys):
instructions.same_request("Approve", save_screenshot=False)
else:
for _ in range(n_keys + 1):
instructions.choice_confirm(save_screenshot=False)
instructions.choice_confirm(save_screenshot=False)
return instructions
def e2e_sign_psbt_instruction(model: Firmware) -> Instructions:
return sign_psbt_instruction_approve(model, save_screenshot=False, has_spend_from_wallet=True)