Skip to content

Commit 3cd326b

Browse files
authored
fix(legacy): misc fix (#624)
* fix(legacy): polkadot update adaption and tron sign message v2 support * fix(legacy): stellar adaption and support for ada testnet message signing
1 parent 75f1721 commit 3cd326b

55 files changed

Lines changed: 1033 additions & 1046 deletions

Some content is hidden

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

common/protob/messages-cardano.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ message CardanoSignMessage {
538538
required CardanoDerivationType derivation_type = 3;
539539
required uint32 network_id = 4; // network id - mainnet or testnet
540540
optional CardanoAddressType address_type = 5; // one of the CardanoAddressType
541+
optional uint32 protocol_magic = 6; // network's protocol magic - needed for Byron addresses on testnets
541542
}
542543

543544
/**

common/protob/messages-polkadot.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ message PolkadotSignTx {
3636
repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node
3737
required bytes raw_tx = 2; // serialized raw transaction
3838
required string network = 3; // Network name
39+
optional uint32 prefix = 4; // SS58 address-type
3940
}
4041

4142
/**

common/protob/messages-tron.proto

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ message TronSignTx {
3535
required bytes ref_block_bytes = 2; // Reference block number
3636
required bytes ref_block_hash = 3; // Reference block hash
3737
required uint64 expiration = 4; // Transaction expiration
38-
optional string data = 5; // Extra transaction info
38+
optional bytes data = 5; // Extra transaction info
3939
required TronContract contract = 6; // Contract messages
4040
required uint64 timestamp = 7; // UTC timestamp
4141
optional uint64 fee_limit = 8; // Fee limit for smartcontracts
@@ -63,6 +63,7 @@ message TronSignTx {
6363
enum TronResourceCode {
6464
BANDWIDTH = 0x00;
6565
ENERGY = 0x01;
66+
TRON_POWER = 0x02;
6667
}
6768

6869
// Freeze TRX balance
@@ -116,6 +117,9 @@ message TronSignTx {
116117
optional TronWithdrawExpireUnfreezeContract withdraw_expire_unfreeze_contract = 56;
117118
optional TronDelegateResourceContract delegate_resource_contract = 57;
118119
optional TronUnDelegateResourceContract undelegate_resource_contract = 58;
120+
optional bytes provider = 3;
121+
optional bytes contract_name = 5;
122+
optional uint32 permission_id = 6;
119123
}
120124
}
121125

@@ -128,6 +132,11 @@ message TronSignedTx {
128132
optional bytes serialized_tx = 2; // Serialized transaction
129133
}
130134

135+
enum TronMessageType {
136+
V1 = 1 [deprecated = true];
137+
V2 = 2;
138+
}
139+
131140
/**
132141
* Request: Ask device to sign message
133142
* @next TronMessageSignature
@@ -136,6 +145,7 @@ message TronSignedTx {
136145
message TronSignMessage {
137146
repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node
138147
required bytes message = 2; // message to be signed
148+
optional TronMessageType message_type = 3[default = V1]; // message type
139149
}
140150

141151
/**

legacy/buttons.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ bool waitButtonResponse(uint8_t btn, uint32_t time_out) {
221221
timer_out_set(timer_out_oper, 0);
222222
return flag;
223223
}
224+
#else
225+
// stub implementations
226+
void enableLongPress(bool on) { (void)on; }
224227
#endif
225228

226229
void buttonUpdate() {

legacy/firmware/ada.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1981,7 +1981,9 @@ bool ada_sign_messages(const CardanoSignMessage *msg,
19811981
fsm_sendFailure(FailureType_Failure_ProcessError, "Deriving root failed");
19821982
return false;
19831983
}
1984-
if (!derive_bytes(&address_params, msg->network_id, MAINNET_PROTOCOL_MAGIC,
1984+
if (!derive_bytes(&address_params, msg->network_id,
1985+
msg->has_protocol_magic ? msg->protocol_magic
1986+
: MAINNET_PROTOCOL_MAGIC,
19851987
address_bytes, &address_bytes_len)) {
19861988
return false;
19871989
}

legacy/firmware/config.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,14 @@ void config_init(void) {
467467
config_upgrade_v10();
468468

469469
storage_init(&protectPinUiCallback, HW_ENTROPY_DATA, HW_ENTROPY_LEN);
470+
// Restore safetyCheckLevel from soft reset if preserved
471+
uint16_t preserved_level = soft_reset_get_preserved_data();
472+
if (preserved_level != PRESERVED_RESET_DATA_INVALID) {
473+
if (preserved_level == SafetyCheckLevel_PromptTemporarily) {
474+
safetyCheckLevel = (SafetyCheckLevel)preserved_level;
475+
}
476+
soft_reset_clear_preserved_data();
477+
}
470478
memzero(HW_ENTROPY_DATA, sizeof(HW_ENTROPY_DATA));
471479

472480
// get whether use se flag

legacy/firmware/ethereum_onekey.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static bool eip1559;
5555
static struct SHA3_CTX keccak_ctx = {0};
5656

5757
static uint32_t signing_access_list_count;
58-
static EthereumAccessListOneKey signing_access_list[8];
58+
static EthereumAccessListOneKey signing_access_list[16];
5959
_Static_assert(sizeof(signing_access_list) ==
6060
sizeof(((EthereumSignTxEIP1559OneKey *)NULL)->access_list),
6161
"access_list buffer size mismatch");

legacy/firmware/fsm.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,8 @@ static const CoinInfo *fsm_getCoin(bool has_name, const char *name) {
301301
return coin;
302302
}
303303

304-
static HDNode *fsm_getDerivedNode(const char *curve, const uint32_t *address_n,
305-
size_t address_n_count,
306-
uint32_t *fingerprint) {
304+
HDNode *fsm_getDerivedNode(const char *curve, const uint32_t *address_n,
305+
size_t address_n_count, uint32_t *fingerprint) {
307306
static CONFIDENTIAL HDNode node;
308307
if (fingerprint) {
309308
*fingerprint = 0;

legacy/firmware/fsm_msg_ada.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ void fsm_msgCardanoGetAddress(CardanoGetAddress *msg) {
9696
if (msg->has_show_display && msg->show_display) {
9797
char desc[20] = {0};
9898
char addr_type[32] = {0};
99-
snprintf(desc, 20, "Cardano %s", _("Address:"));
99+
snprintf(desc, 20, "Cardano %s", _("Address"));
100100
if (msg->address_parameters.address_type == CardanoAddressType_BASE) {
101-
snprintf(addr_type, 32, "Base %s", _("Address:"));
101+
snprintf(addr_type, 32, "Base %s", _("Address"));
102102
} else if (msg->address_parameters.address_type ==
103103
CardanoAddressType_REWARD) {
104-
snprintf(addr_type, 32, "Reward %s", _("Address:"));
104+
snprintf(addr_type, 32, "Reward %s", _("Address"));
105105
}
106106
if (msg->address_parameters.address_n_count > 0) {
107107
if (!fsm_layoutAddress(resp->address, addr_type, desc, false, 0,
@@ -268,8 +268,9 @@ void fsm_msgCardanoSignMessage(CardanoSignMessage *msg) {
268268
"Invalid path");
269269
CHECK_PIN
270270

271-
if ((msg->network_id != 0) && (msg->network_id != 1)) {
272-
fsm_sendFailure(FailureType_Failure_ProcessError, "Invalid Networ ID");
271+
if (!msg->has_protocol_magic && (msg->network_id != 1)) {
272+
fsm_sendFailure(FailureType_Failure_ProcessError,
273+
"Invalid Network ID, need protocol magic provide");
273274
return;
274275
}
275276
if (!ada_sign_messages(msg, resp)) {

legacy/firmware/fsm_msg_algorand.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void fsm_msgAlgorandGetAddress(AlgorandGetAddress *msg) {
3939

4040
if (msg->has_show_display && msg->show_display) {
4141
char desc[20] = {0};
42-
snprintf(desc, 20, "%s %s", "Algorand", _("Address:"));
42+
snprintf(desc, 20, "%s %s", "Algorand", _("Address"));
4343
if (!fsm_layoutAddress(resp->address, NULL, desc, false, 0, msg->address_n,
4444
msg->address_n_count, true, NULL, 0, 0, NULL)) {
4545
return;

0 commit comments

Comments
 (0)