Skip to content

Conversation

@DRadmir
Copy link
Contributor

@DRadmir DRadmir commented Dec 5, 2025

No description provided.

@semanticdiff-com
Copy link

semanticdiff-com bot commented Dec 5, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/gem_tron/src/provider/preload_mapper.rs  100% smaller
  gemstone/src/config/wallet_connect.rs  97% smaller
  crates/signer/src/lib.rs  12% smaller
  crates/primitives/src/lib.rs  8% smaller
  crates/primitives/src/wallet_connect_namespace.rs  6% smaller
  gemstone/src/wallet_connect/mod.rs  5% smaller
  gemstone/src/message/decoder.rs  1% smaller
  gemstone/src/wallet_connect/response_handler.rs  1% smaller
  Cargo.lock Unsupported file format
  crates/primitives/src/wallet_connect.rs  0% smaller
  crates/primitives/src/wallet_connector.rs  0% smaller
  crates/signer/Cargo.toml Unsupported file format
  crates/signer/src/ton.rs Unsupported file format
  gemstone/src/message/sign_type.rs  0% smaller
  gemstone/src/signer/crypto.rs  0% smaller
  gemstone/src/wallet_connect/actions.rs  0% smaller
  gemstone/src/wallet_connect/request_handler/mod.rs  0% smaller
  gemstone/src/wallet_connect/request_handler/ton.rs  0% smaller

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @DRadmir, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly expands the platform's blockchain interoperability by integrating TON (The Open Network) with WalletConnect. The changes enable seamless communication between decentralized applications on TON and compatible wallets, allowing users to sign messages and initiate transactions directly through WalletConnect. This broadens the ecosystem's reach and enhances user experience for TON users.

Highlights

  • TON Chain Integration: Added TON (The Open Network) as a supported blockchain for WalletConnect, including its CAIP-2 namespace and chain type mappings.
  • TON-Specific Data Models: Introduced "WCTonMessage" and "WCTonTransactionData" structs to represent TON messages and transaction payloads within the WalletConnect context.
  • WalletConnect Method Extensions: Expanded "WalletConnectionMethods" to include "ton_sendMessage" and "ton_signData" for TON-specific operations.
  • TON Message Handling Logic: Implemented decoding and validation logic for TON personal sign messages, supporting both text and base64-encoded binary data.
  • Request and Response Processing: Developed a dedicated "TonRequestHandler" to parse incoming TON WalletConnect requests and updated "WalletConnectResponseHandler" to format TON-specific responses.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for TON blockchain to WalletConnect. The changes are comprehensive, touching upon primitives to define TON-specific types, and the gemstone crate to handle request/response logic and message decoding. The implementation is mostly solid with good test coverage for the new functionality. I have two main points of feedback. First, a medium-severity suggestion to improve a data structure for better consistency and usability. Second, a high-severity issue in the TON message decoding logic, where silent failures could lead to users signing unintended data. Addressing this is important for security and correctness.

Comment on lines 201 to 226
fn decode_ton_sign_message(&self, data: String) -> SignMessage {
if let Ok(json) = serde_json::from_str::<serde_json::Value>(&data) {
let payload_type = json.get("type").and_then(|v| v.as_str()).unwrap_or("text");

let message_data = match payload_type {
"text" => json.get("text").and_then(|v| v.as_str()).unwrap_or_default().as_bytes().to_vec(),
"binary" => {
let binary_data = json.get("data").and_then(|v| v.as_str()).unwrap_or_default();
base64::engine::general_purpose::STANDARD.decode(binary_data).unwrap_or_default()
}
_ => data.as_bytes().to_vec(),
};

return SignMessage {
chain: Chain::Ton,
sign_type: SignDigestType::TonPersonal,
data: message_data,
};
}

SignMessage {
chain: Chain::Ton,
sign_type: SignDigestType::TonPersonal,
data: data.as_bytes().to_vec(),
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The current implementation of decode_ton_sign_message has several silent failure modes that could lead to users signing something they did not intend to:

  • If base64 decoding fails, it defaults to an empty byte array.
  • If an unknown type is provided in the JSON, it defaults to signing the entire JSON string.
  • If the text field is missing for type: "text", it signs an empty string.

These silent failures are risky. It would be safer to fall back to a consistent behavior, like signing the original raw data string, if any part of the structured parsing fails. This ensures that the user is at least signing the data they provided, even if it's not in the expected format.

Here is a suggested refactoring that handles these cases more robustly by falling back to signing the raw data string in case of parsing errors, which is safer than signing empty or incorrect data.

    fn decode_ton_sign_message(&self, data: String) -> SignMessage {
        if let Ok(json) = serde_json::from_str::<serde_json::Value>(&data) {
            let message_data = match json.get("type").and_then(|v| v.as_str()) {
                Some("text") => json.get("text").and_then(|v| v.as_str()).map(|s| s.as_bytes().to_vec()),
                Some("binary") => json.get("data").and_then(|v| v.as_str()).and_then(|b64| base64::engine::general_purpose::STANDARD.decode(b64).ok()),
                _ => None,
            };

            if let Some(message_data) = message_data {
                return SignMessage {
                    chain: Chain::Ton,
                    sign_type: SignDigestType::TonPersonal,
                    data: message_data,
                };
            }
        }

        SignMessage {
            chain: Chain::Ton,
            sign_type: SignDigestType::TonPersonal,
            data: data.as_bytes().to_vec(),
        }
    }

pub data: Option<String>,
}

#[derive(Debug, Serialize, Deserialize)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better usability and consistency with other data structures in the crate, consider deriving Clone and PartialEq for WCTonMessage. This will make it easier to use in tests and other logic where copying or comparison is needed.

Suggested change
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]

@DRadmir DRadmir marked this pull request as ready for review December 8, 2025 09:52
Cell,
}

impl TonSignDataType {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use strum as AsRefStr EnumString and also replace "text" in other places with using this type instead


pub fn sign_ton_personal_message(input: TonSignDataInput, private_key: Vec<u8>) -> Result<String, SignerError> {
let private_key = Zeroizing::new(private_key);
let payload_str = std::str::from_utf8(&input.payload).map_err(|e| SignerError::new(e.to_string()))?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should not be signing here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be done on app level

let Some(payload_type) = json.get("type").and_then(|v| v.as_str()) else {
return Ok(MessagePreview::Text(string));
};
let preview = match payload_type {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use TonSignDataType

ChainType::Ton => Some(WalletConnectCAIP2::Ton.as_ref().to_string()),
ChainType::Bitcoin
| ChainType::Ton
| ChainType::Tron
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the definition of -239 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants