Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ETH sign_typed_data_v4 #75

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open

Conversation

pedrxlz
Copy link
Contributor

@pedrxlz pedrxlz commented Oct 1, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new method for signing typed data according to EIP-712 standards in the Ethereum module.
    • Added a method to retrieve the keypair associated with the wallet.
    • Implemented a function for signing typed data specifically for the Ethereum chain in the mobile SDK.
  • Bug Fixes

    • Updated the private key retrieval method to ensure consistent behavior when the wallet is locked.
  • Tests

    • Expanded test suite to include tests for new functionality and updated existing tests for compatibility.
  • Dependency Updates

    • Added a new dependency for enhanced functionality and updated existing dependencies for improved performance.

Copy link

coderabbitai bot commented Oct 1, 2024

Walkthrough

The pull request introduces several updates to the kos-sdk package, primarily enhancing the Ethereum module with a new method for signing typed data according to EIP-712 standards. It also adds a new method to the Wallet struct for retrieving the keypair. Additionally, the changes include updates to existing methods and tests to ensure compatibility and functionality.

Changes

File Path Change Summary
packages/kos-sdk/Cargo.toml Added new dependency: alloy-dyn-abi = { version = "0.8.5", features = ["eip712"] }; updated web3 version; added patch for derive_more.
packages/kos-sdk/src/chains/ethereum/mod.rs Added sign_type_data_v4 method for EIP-712 signing; modified sign method; updated transaction handling methods; added test cases.
packages/kos-mobile/src/lib.rs Added sign_typed_data_v4 function for Ethereum chain; included corresponding test case.
packages/kos-sdk/src/wallet.rs Added get_keypair method; updated get_private_key method to handle locked wallet scenarios.

Possibly related PRs

  • fix: trx from raw transaction type #72: The changes in this PR enhance the handling of transaction signatures and contracts in the TRX implementation, which is related to the Ethereum transaction signing capabilities introduced in the main PR.

Suggested reviewers

  • brunocampos-ssa
  • MCysneiros

Poem

In the land of code, a rabbit hops,
With new methods added, the fun never stops.
Signing data, oh what a delight,
EIP-712 shines, making things right.
Wallets now open, keypairs in sight,
Hooray for the changes, let’s code through the night! 🐇✨


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Outside diff range and nitpick comments (1)
packages/kos-sdk/Cargo.toml (1)

52-52: LGTM! Consider using a more flexible version constraint.

The addition of the alloy-dyn-abi dependency with the "eip712" feature aligns well with the PR objective of implementing ETH sign_typed_data_v4. This will enable support for Ethereum's EIP-712 standard for typed structured data hashing and signing.

Consider using a more flexible version constraint to automatically receive compatible updates:

-alloy-dyn-abi = { version = "0.8.5", features = ["eip712"] }
+alloy-dyn-abi = { version = "^0.8.5", features = ["eip712"] }

This change allows for minor version updates (0.8.x) which typically include bug fixes and backwards-compatible changes.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 67de250 and a5f9433.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • packages/kos-sdk/Cargo.toml (1 hunks)
  • packages/kos-sdk/src/chains/ethereum/mod.rs (3 hunks)
  • packages/kos-sdk/src/wallet.rs (1 hunks)

packages/kos-sdk/src/wallet.rs Outdated Show resolved Hide resolved
packages/kos-sdk/src/chains/ethereum/mod.rs Show resolved Hide resolved
packages/kos-sdk/src/chains/ethereum/mod.rs Outdated Show resolved Hide resolved
packages/kos-sdk/src/chains/ethereum/mod.rs Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (2)
packages/kos-sdk/src/chains/ethereum/mod.rs (1)

761-808: Test implementation looks good, consider adding more test cases.

The test for sign_type_data_v4 provides good coverage with a realistic EIP-712 typed data example. It correctly verifies both the hexadecimal representation and the length of the signature.

As suggested in a previous review, consider adding test cases for invalid input scenarios to ensure sign_type_data_v4 handles errors gracefully.

packages/kos-mobile/src/lib.rs (1)

70-83: Consider adding documentation for sign_typed_data_v4

Adding documentation comments to the new sign_typed_data_v4 function will improve code maintainability and help other developers understand its purpose and usage.

You might add something like:

/// Signs typed data using EIP-712 standard for Ethereum chains.
/// 
/// # Arguments
/// 
/// * `account` - The KOSAccount containing chain information and private key.
/// * `data` - The JSON string representing the typed data to be signed.
/// 
/// # Returns
/// 
/// A vector of bytes containing the signature.
///
/// # Errors
///
/// Returns `KOSError::UnsupportedChain` if the chain is not Ethereum.
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f8f688a and c38b39b.

📒 Files selected for processing (2)
  • packages/kos-mobile/src/lib.rs (3 hunks)
  • packages/kos-sdk/src/chains/ethereum/mod.rs (3 hunks)
🔇 Additional comments (4)
packages/kos-sdk/src/chains/ethereum/mod.rs (1)

169-176: LGTM! Implementation looks correct and previous issues addressed.

The sign_type_data_v4 function correctly implements EIP-712 signing. It properly parses the input data, computes the signing hash, and signs the digest. The error handling has been improved, and the serde_json import issue has been resolved.

packages/kos-mobile/src/lib.rs (3)

6-6: Import ETH chain module

The addition of use kos_sdk::chains::ETH; correctly allows access to Ethereum-specific functionalities needed for the new sign_typed_data_v4 function.


392-448: Test should_sign_typed_data_v4 accurately verifies new functionality

The test function should_sign_typed_data_v4 effectively checks the signing process for typed data. It uses a known mnemonic and validates both the signature length and its expected value.


395-395: Verify that chain_id corresponds to Ethereum

Ensure that the chain_id value 3 used in the test corresponds to the Ethereum chain (Chain::ETH). If Chain::ETH uses a different chain_id, the test may not execute as expected.

Run the following script to confirm the chain_id for Ethereum:

packages/kos-mobile/src/lib.rs Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
packages/kos-mobile/src/lib.rs (1)

395-450: Test looks good, consider adding error scenarios.

The should_sign_typed_data_v4 test is well-implemented and covers the basic functionality of the sign_typed_data_v4 function. It uses a known input and checks for a specific output, which is excellent for regression testing.

Consider adding more test cases to cover error scenarios, such as:

  1. Attempting to sign with a non-ETH chain.
  2. Providing invalid typed data structure.
  3. Using an invalid private key.

These additional tests would improve the overall test coverage and robustness of the implementation.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c38b39b and 17bb6a6.

📒 Files selected for processing (1)
  • packages/kos-mobile/src/lib.rs (3 hunks)
🔇 Additional comments (2)
packages/kos-mobile/src/lib.rs (2)

70-84: LGTM! Implementation looks correct and past review comment addressed.

The sign_typed_data_v4 function is well-implemented. It correctly checks for the Ethereum chain and handles the potential None from wallet.get_keypair() as suggested in a past review comment.


Line range hint 1-450: Overall, the changes look good and improve the functionality.

The addition of the sign_typed_data_v4 function and its corresponding test enhances the Ethereum-specific functionality of the library. The implementation addresses a previous review comment and follows good practices. The changes are focused and don't introduce any apparent regressions to existing functionality.

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

Successfully merging this pull request may close these issues.

1 participant