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

Remove ethers #1616

Merged
merged 2 commits into from
Dec 30, 2024
Merged

Remove ethers #1616

merged 2 commits into from
Dec 30, 2024

Conversation

fabiorigam
Copy link
Member

@fabiorigam fabiorigam commented Dec 24, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced signTypedData method to include a primaryType parameter for better data handling.
    • Introduced hashTypedData function for improved signing process.
  • Bug Fixes

    • Updated error handling in signTypedData to specify InvalidAbiEncodingTypeError for better error reporting.
  • Documentation

    • Adjusted method signatures across various classes to reflect new parameters and types.
  • Chores

    • Replaced imports from ethers library with viem library for typed data handling.

Copy link

coderabbitai bot commented Dec 24, 2024

Walkthrough

This pull request introduces a comprehensive migration from ethers to viem for handling typed data signatures across multiple components of the VeChain SDK. The changes primarily focus on updating the signTypedData method signature, replacing TypedDataField with TypedDataParameter, and introducing a new primaryType parameter. The modifications span several packages, including aws-kms-adapter, network, and their respective test files, ensuring consistent type handling and signature methods for typed data operations.

Changes

File Change Summary
packages/aws-kms-adapter/src/KMSVeChainSigner.ts - Updated imports from ethers to viem
- Modified signTypedData method signature
packages/aws-kms-adapter/tests/* - Updated test cases to match new signTypedData method signature
- Replaced TypedDataField with TypedDataParameter
packages/network/src/provider/utils/rpc-mapper/methods/eth_signTypedData_v4 - Replaced TypedDataField import with TypedDataParameter
- Updated type definitions
packages/network/src/signer/signers/types.d.ts - Updated imports from ethers to viem
- Modified VeChainSigner interface signature
- Added accessList property to TransactionRequestInput
packages/network/src/signer/signers/vechain-* - Replaced TypedDataField with TypedDataParameter
- Updated signTypedData method signatures
- Added primaryType parameter

Sequence Diagram

sequenceDiagram
    participant Signer
    participant Viem
    participant KMS/PrivateKey
    
    Signer->>Viem: signTypedData(domain, types, primaryType, message)
    Viem->>Viem: hashTypedData(domain, types, primaryType, message)
    Viem->>KMS/PrivateKey: Request signature
    KMS/PrivateKey-->>Viem: Return signed data
    Viem-->>Signer: Return signature
Loading

Possibly Related PRs

Suggested Reviewers

  • Clayton Neal
  • Darren Vechain

Poem

🐰 Typed data dance, a library's new stance
From ethers to viem, we leap with grace
Parameters shift, signatures bright
A rabbit's code takes elegant flight! 🌟

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


🪧 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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

github-actions bot commented Dec 24, 2024

Test Coverage

Summary

Lines Statements Branches Functions
Coverage: 99%
99% (4370/4414) 97.55% (1399/1434) 99.01% (906/915)
Title Tests Skipped Failures Errors Time
core 836 0 💤 0 ❌ 0 🔥 2m 20s ⏱️
network 729 0 💤 0 ❌ 0 🔥 4m 47s ⏱️
errors 40 0 💤 0 ❌ 0 🔥 16.642s ⏱️
logging 3 0 💤 0 ❌ 0 🔥 18.594s ⏱️
hardhat-plugin 19 0 💤 0 ❌ 0 🔥 1m 3s ⏱️
aws-kms-adapter 23 0 💤 0 ❌ 0 🔥 1m 20s ⏱️
ethers-adapter 5 0 💤 0 ❌ 0 🔥 1m 12s ⏱️
rpc-proxy 37 0 💤 0 ❌ 0 🔥 1m 3s ⏱️

@fabiorigam fabiorigam marked this pull request as ready for review December 24, 2024 13:25
@fabiorigam fabiorigam requested a review from a team as a code owner December 24, 2024 13:25
@fabiorigam fabiorigam linked an issue Dec 24, 2024 that may be closed by this pull request
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

🧹 Nitpick comments (6)
packages/network/src/provider/utils/rpc-mapper/methods/eth_signTypedData_v4/eth_signTypedData_v4.ts (1)

77-77: Check for null or empty primaryType values.

When typedData.primaryType is improperly defined or empty, the chain of typed data signing could fail. Consider adding a validation step or a fallback value if primaryType is unexpectedly missing.

packages/aws-kms-adapter/tests/KMSVeChainSigner.unit.test.ts (1)

163-164: Resolution needed for null or incorrect typed data.

The placeholders ({} as unknown) might mask real type mismatches. Ensure correct fixture data is used rather than empty stubs to catch potential regressions.

packages/network/src/signer/signers/types.d.ts (1)

372-375: Signature method refactored successfully.

The newly added primaryType and options parameters harmonize with the updated typed data approach. Recommend verifying these optional parameters are properly handled in all signer implementations.

packages/network/src/signer/signers/vechain-private-key-signer/vechain-private-key-signer.ts (1)

210-212: Documentation updated to match the new parameter names.
This helps users understand the updated typed data signing flow (primaryType, message).

packages/aws-kms-adapter/src/KMSVeChainSigner.ts (1)

406-406: Expanded error context logs the new parameters.
Including primaryType and message helps troubleshoot typed data signing issues.

packages/network/src/signer/signers/vechain-abstract-signer/vechain-abstract-signer.ts (1)

339-341: Comment changes align with the signature updates.
Renaming from value to message clarifies parameter usage for typed data.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c1ee6f1 and 8601825.

📒 Files selected for processing (8)
  • packages/aws-kms-adapter/src/KMSVeChainSigner.ts (2 hunks)
  • packages/aws-kms-adapter/tests/KMSVeChainSigner.solo.test.ts (1 hunks)
  • packages/aws-kms-adapter/tests/KMSVeChainSigner.unit.test.ts (3 hunks)
  • packages/network/src/provider/utils/rpc-mapper/methods/eth_signTypedData_v4/eth_signTypedData_v4.ts (3 hunks)
  • packages/network/src/signer/signers/types.d.ts (3 hunks)
  • packages/network/src/signer/signers/vechain-abstract-signer/vechain-abstract-signer.ts (2 hunks)
  • packages/network/src/signer/signers/vechain-private-key-signer/vechain-private-key-signer.ts (2 hunks)
  • packages/network/tests/signer/signers/vechain-private-key-signer/vechain-private-key-signer.unit.test.ts (5 hunks)
🔇 Additional comments (19)
packages/network/src/provider/utils/rpc-mapper/methods/eth_signTypedData_v4/eth_signTypedData_v4.ts (2)

7-7: Good shift away from ethers to viem.

Removing TypedDataField references from ethers in favor of TypedDataParameter from viem makes the typed data approach more loosely coupled. This aligns with the PR's objective of removing ethers.


64-64: Ensure consistency in typed data usage.

The property types: Record<string, TypedDataParameter[]>; aligns with the new viem-based structure. Verify that all references to these data types across the codebase have been updated to avoid mismatched signatures.

packages/aws-kms-adapter/tests/KMSVeChainSigner.unit.test.ts (2)

8-8: Great job switching to viem.

This keeps the test suite consistent with the rest of the migration away from ethers.


139-139: Confirm typed data correctness.

The additional 'Mail' parameter ensures the primary type is specified. Confirm that all test fixtures are updated to support the new approach if more primary types are introduced.

packages/aws-kms-adapter/tests/KMSVeChainSigner.solo.test.ts (1)

302-302: Validate the primaryType parameter in integration tests.

Line 302 adds the primaryType argument. Confirm that integration tests cover cases where primaryType may be undefined or unexpected to ensure robust error handling.

packages/network/src/signer/signers/types.d.ts (2)

2-2: Migration to viem is consistent.

This new import from viem aligns with the codebase-wide migration goals to retire ethers.


184-184: Consider advanced usage of accessList.

accessList handling is mostly relevant to EVM-based networks. Verify if there’s any VeChain-specific nuance needed or if it remains purely for compatibility.

packages/network/tests/signer/signers/vechain-private-key-signer/vechain-private-key-signer.unit.test.ts (4)

25-25: Use of InvalidAbiEncodingTypeError is appropriate.
The explicit error type helps differentiate ABI encoding failures from generic errors.


294-297: Good to see the tests reflect the new parameter-based typed data approach.
Ensuring the test throws InvalidAbiEncodingTypeError is a clear indication that the signer’s error handling logic is now more specific.


Line range hint 318-327: Check for both new typed data structure and primary type usage.
Verifying exceptions with custom error messages ensures robust error handling. Confirm other references in the codebase also handle invalid typed data similarly for consistency.


348-348: Ethers compatibility check aligned with updated typed data approach.
This test confirms the signature’s consistency with ethers references, which offers reassurance about correctness. Great job maintaining backward compatibility!

packages/network/src/signer/signers/vechain-private-key-signer/vechain-private-key-signer.ts (3)

18-21: Imports from viem used to streamline typed data handling.
Replacing ethers-specific imports with viem fosters uniform data encoding and hashing. No issues noted.


218-220: Clear reflection of the refined typed data signature.
Switching from value to message clarifies usage. Ensure all code references are updated.


225-225: Using hashTypedData ensures robust domain separation.
This approach avoids manual hashing mistakes prevalent in raw hashing.

packages/aws-kms-adapter/src/KMSVeChainSigner.ts (3)

15-20: New imports from viem reflect the move away from ethers.
Including hashTypedData, recoverPublicKey, and toHex helps unify typed data operations.


392-394: primaryType argument integration.
The parameter alignment with VeChainPrivateKeySigner promotes consistency across signers.


398-398: Switch to hashTypedData.
Better clarity and standardization for typed data hashing, reducing reliance on ethers.

packages/network/src/signer/signers/vechain-abstract-signer/vechain-abstract-signer.ts (2)

11-11: Refined import from viem for typed data parameters.
Dropping ethers in favor of viem keeps the code consistent with the rest of the PR.


347-349: Updated abstract method signature to include primaryType.
All implementers now share consistent typed data parameters, reducing friction across signers.

Copy link
Collaborator

@GrandinLuc GrandinLuc left a comment

Choose a reason for hiding this comment

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

Looks good overhaul but two remarks:

@fabiorigam
Copy link
Member Author

Looks good overhaul but two remarks:

This is not the goal of the PR. We'll have another ticket for that.

@lucanicoladebiasi lucanicoladebiasi merged commit c991d52 into main Dec 30, 2024
17 checks passed
@fabiorigam fabiorigam deleted the remove-ethers branch January 7, 2025 11:25
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.

💡 [REQUEST] - Replace ethers by viem for EIP712
3 participants