Skip to content

Commit c1414c9

Browse files
authored
fix(legacy): fix ada transaction signing issue (#596)
1 parent d1fcfbb commit c1414c9

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

legacy/firmware/ada.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,11 @@ bool txHashBuilder_addToken(const CardanoToken *msg) {
10081008
if (is_output_state) {
10091009
if ((ada_signer.remainingOutputAssetTokensCount == 0) &&
10101010
(ada_signer.remainingOutputAssetGroupsCount == 0)) {
1011+
if (ada_signer.datum_hash_size > 0 || ada_signer.inline_datum_size > 0) {
1012+
BUILDER_APPEND_CBOR(CBOR_TYPE_UNSIGNED,
1013+
BABBAGE_OUTPUT_KEY_DATUM_OPTION);
1014+
BUILDER_APPEND_CBOR(CBOR_TYPE_ARRAY, 2);
1015+
}
10111016
if (ada_signer.datum_hash_size > 0) {
10121017
BUILDER_APPEND_CBOR(CBOR_TYPE_BYTES, ada_signer.datum_hash_size);
10131018
BUILDER_APPEND_DATA(ada_signer.datum_hash, ada_signer.datum_hash_size);
@@ -1058,6 +1063,7 @@ bool txHashBuilder_addInlineDatumChunk(const CardanoTxInlineDatumChunk *chunk) {
10581063
ada_signer.remainingInlineDatumChunksCount--;
10591064
BUILDER_APPEND_DATA(chunk->data.bytes, chunk->data.size);
10601065
if (ada_signer.remainingInlineDatumChunksCount == 0) {
1066+
ada_signer.inline_datum_size = 0;
10611067
ada_signer.outputState = ada_signer.remainingReferenceScriptChunksCount > 0
10621068
? STATE_OUTPUT_REFERENCE_SCRIPT
10631069
: STATE_OUTPUT_FINISHED;
@@ -1085,6 +1091,7 @@ bool txHashBuilder_addReferenceScriptChunk(
10851091
}
10861092
BUILDER_APPEND_DATA(chunk->data.bytes, chunk->data.size);
10871093
if (ada_signer.remainingReferenceScriptChunksCount == 0) {
1094+
ada_signer.reference_script_size = 0;
10881095
ada_signer.outputState = STATE_OUTPUT_FINISHED;
10891096
}
10901097
return true;

legacy/firmware/layout2.c

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4165,7 +4165,7 @@ bool layoutTransactionSign(const char *chain_name, uint64_t chain_id,
41654165
(void)signer;
41664166
(void)recipient;
41674167
bool result = false, has_chain_id = false;
4168-
int index = 0, sub_index = 0, tokenid_len = 0, token_id_rowcount = 0;
4168+
int index = 0, sub_index = 0;
41694169
int i, y = 0, bar_heght, bar_start = 12, bar_end = 52;
41704170
uint8_t key = KEY_NULL;
41714171
uint8_t max_index = 3;
@@ -4182,10 +4182,10 @@ bool layoutTransactionSign(const char *chain_name, uint64_t chain_id,
41824182
if (strlen(to_str) / rowlen) to_str_rowcount++;
41834183
// if (strlen(signer) / rowlen) signer_rowcount++;
41844184

4185-
if (token_id) {
4186-
tokenid_len = strlen(token_id);
4187-
token_id_rowcount = tokenid_len / rowlen + 1;
4188-
}
4185+
// if (token_id) {
4186+
// tokenid_len = strlen(token_id);
4187+
// // token_id_rowcount = tokenid_len / rowlen + 1;
4188+
// }
41894189
if (strncmp(chain_name, "EVM", 3) == 0) {
41904190
has_chain_id = true;
41914191
max_index++;
@@ -4221,7 +4221,9 @@ bool layoutTransactionSign(const char *chain_name, uint64_t chain_id,
42214221
resp.has_code = true;
42224222
resp.code = ButtonRequestType_ButtonRequest_SignTx;
42234223
msg_write(MessageType_MessageType_ButtonRequest, &resp);
4224-
4224+
#if !EMULATOR
4225+
enableLongPress(true);
4226+
#endif
42254227
refresh_menu:
42264228
layoutSwipe();
42274229
oledClear();
@@ -4390,29 +4392,33 @@ bool layoutTransactionSign(const char *chain_name, uint64_t chain_id,
43904392
oledRefresh();
43914393

43924394
key = protectWaitKey(0, 0);
4395+
#if !EMULATOR
4396+
if (isLongPress(KEY_UP_OR_DOWN) && getLongPressStatus()) {
4397+
if (isLongPress(KEY_UP)) {
4398+
key = KEY_UP;
4399+
} else if (isLongPress(KEY_DOWN)) {
4400+
key = KEY_DOWN;
4401+
}
4402+
delay_ms(75);
4403+
}
4404+
#endif
43934405
switch (key) {
43944406
case KEY_UP:
43954407
if (sub_index > 0) {
43964408
sub_index--;
43974409
}
43984410
goto refresh_menu;
43994411
case KEY_DOWN:
4400-
if ((has_chain_id == false && len > 0 && index == 3 &&
4412+
if ((has_chain_id == false && len > 0 && index == 2 &&
44014413
sub_index < data_rowcount - 4) ||
4402-
(has_chain_id == true && len > 0 && index == 4 &&
4414+
(has_chain_id == true && len > 0 && index == 3 &&
44034415
sub_index < data_rowcount - 4)) {
44044416
sub_index++;
44054417
}
4406-
if ((has_chain_id == false && token_transfer && token_id && index == 2 &&
4407-
sub_index < token_id_rowcount - 3) ||
4408-
(has_chain_id == true && token_transfer && token_id && index == 3 &&
4409-
sub_index < token_id_rowcount - 3)) { // token_id
4410-
sub_index++;
4411-
}
44124418

4413-
if ((has_chain_id == false && 1 == index && token_id == NULL &&
4419+
if ((has_chain_id == false && 0 == index && token_id == NULL &&
44144420
sub_index < to_str_rowcount - 3) ||
4415-
(has_chain_id == true && 2 == index && token_id == NULL &&
4421+
(has_chain_id == true && 1 == index && token_id == NULL &&
44164422
sub_index < to_str_rowcount - 3)) { // To
44174423
sub_index++;
44184424
}
@@ -4440,7 +4446,9 @@ bool layoutTransactionSign(const char *chain_name, uint64_t chain_id,
44404446
default:
44414447
break;
44424448
}
4443-
4449+
#if !EMULATOR
4450+
enableLongPress(false);
4451+
#endif
44444452
return result;
44454453
}
44464454

0 commit comments

Comments
 (0)