What changed, and why it matters
This commit only reformats Rust source code in the Tron app. It removes blank lines, reorders imports, and adjusts line breaks to match the project's style guide. No program logic, calculations, or security behavior was changed.
No security action needed. Treat as routine code-style maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff is a pure formatting patch (fix fmt) across four Rust files in rust/apps/tron. Changes include whitespace cleanup, import reordering, and minor style adjustments such as collapsing multi-line function calls. There are no semantic changes to address derivation, transaction signing, message hashing, or error handling.
Changed components
rust/apps/tron/src/address.rsrust/apps/tron/src/lib.rsrust/apps/tron/src/structs.rsrust/apps/tron/src/transaction/signer.rsInspect captured patch +21 / −26
diff --git a/rust/apps/tron/src/address.rs b/rust/apps/tron/src/address.rs
index 49754f5..18623f2 100644
--- a/rust/apps/tron/src/address.rs
+++ b/rust/apps/tron/src/address.rs
@@ -58,11 +58,11 @@ pub fn get_address(path: String, extended_pub_key: &String) -> Result<String> {
pub fn public_key_to_address(public_key: &PublicKey) -> String {
let pubkey_bytes = public_key.serialize_uncompressed();
let hash = keccak256(&pubkey_bytes[1..]);
-
+
let mut address_bytes = [0u8; 21];
address_bytes[0] = 0x41;
address_bytes[1..].copy_from_slice(&hash[hash.len() - 20..]);
-
+
base58::encode_check(&address_bytes)
}
diff --git a/rust/apps/tron/src/lib.rs b/rust/apps/tron/src/lib.rs
index 4bd8b29..9cdd2b5 100644
--- a/rust/apps/tron/src/lib.rs
+++ b/rust/apps/tron/src/lib.rs
@@ -15,21 +15,20 @@ use ur_registry::pb::protoc;
mod address;
pub mod errors;
mod pb;
+pub mod structs;
mod transaction;
mod utils;
-pub mod structs;
pub use crate::address::get_address;
+use crate::structs::PersonalMessage;
pub use crate::transaction::parser::{DetailTx, OverviewTx, ParsedTx, TxParser};
use crate::transaction::wrapped_tron::WrappedTron;
use alloc::string::ToString;
use alloc::vec::Vec;
use app_utils::keystone;
+use bitcoin::secp256k1::PublicKey;
use transaction::checker::TxChecker;
use transaction::signer::Signer;
-use bitcoin::secp256k1::{PublicKey};
-use crate::structs::{PersonalMessage};
-
pub fn sign_raw_tx(
raw_tx: protoc::Payload,
@@ -90,13 +89,13 @@ pub fn check_tx_request(sign_data: &[u8], path: &str, xpub: &str) -> errors::Res
}
pub fn sign_personal_message(
- sign_data: &[u8],
- path: &String,
- seed: &[u8]
+ sign_data: &[u8],
+ path: &String,
+ seed: &[u8],
) -> errors::Result<String> {
let prefix = b"\x19TRON Signed Message:\n";
let len_str = sign_data.len().to_string();
-
+
let mut message_to_hash = Vec::with_capacity(prefix.len() + len_str.len() + sign_data.len());
message_to_hash.extend_from_slice(prefix);
message_to_hash.extend_from_slice(len_str.as_bytes());
@@ -121,7 +120,6 @@ pub fn parse_personal_message(
tx_hex: &[u8],
from_key: Option<PublicKey>,
) -> Result<PersonalMessage> {
-
let raw_message = hex::encode(tx_hex);
let utf8_message = match String::from_utf8(tx_hex.to_vec()) {
Ok(utf8_message) => {
diff --git a/rust/apps/tron/src/structs.rs b/rust/apps/tron/src/structs.rs
index e9bc648..be6775a 100644
--- a/rust/apps/tron/src/structs.rs
+++ b/rust/apps/tron/src/structs.rs
@@ -1,6 +1,6 @@
use crate::address::public_key_to_address;
use crate::errors::Result;
-use alloc::string::{String};
+use alloc::string::String;
use bitcoin::secp256k1::PublicKey;
@@ -24,4 +24,3 @@ impl PersonalMessage {
})
}
}
-
diff --git a/rust/apps/tron/src/transaction/signer.rs b/rust/apps/tron/src/transaction/signer.rs
index 9e47ffa..ec1c835 100644
--- a/rust/apps/tron/src/transaction/signer.rs
+++ b/rust/apps/tron/src/transaction/signer.rs
@@ -17,20 +17,16 @@ pub trait Signer {
impl WrappedTron {
fn do_sign_digest(&self, seed: &[u8]) -> Result<[u8; 65]> {
let sig_hash = self.signature_hash()?;
-
+
let message = bitcoin::secp256k1::Message::from_digest_slice(sig_hash.as_slice())
.map_err(|e| TronError::SignFailure(e.to_string()))?;
-
- let (rec_id, signature) = secp256k1::sign_message_by_seed(
- seed,
- &self.hd_path,
- &message
- )?;
-
+
+ let (rec_id, signature) = secp256k1::sign_message_by_seed(seed, &self.hd_path, &message)?;
+
let mut sig_bytes = [0u8; 65];
sig_bytes[..64].copy_from_slice(&signature);
sig_bytes[64..].copy_from_slice(&rec_id.to_le_bytes()[..1]);
-
+
Ok(sig_bytes)
}
}
@@ -39,13 +35,15 @@ impl Signer for WrappedTron {
fn sign(&self, seed: &[u8]) -> Result<(String, String)> {
let sig_hash = self.signature_hash()?;
let sig_bytes = self.do_sign_digest(seed)?;
-
+
let mut tx = self.tron_tx.to_owned();
- let count: usize = tx.raw_data.as_ref()
+ let count: usize = tx
+ .raw_data
+ .as_ref()
.map_or(0, |raw_data| raw_data.contract.len());
-
+
tx.signature = vec![sig_bytes.to_vec(); count];
-
+
let tx_hex = tx.encode_to_vec();
Ok((hex::encode(tx_hex), hex::encode(sig_hash)))
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.