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(EIP712): deduce primaryType if not provided #1632

Merged
merged 9 commits into from
Jan 9, 2025

Conversation

fabiorigam
Copy link
Member

@fabiorigam fabiorigam commented Jan 7, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced signature methods for VeChain signers
    • Added optional primaryType parameter for typed data signing
  • Bug Fixes

    • Corrected documentation for transaction and payload signing methods
    • Improved error handling in signature processes
  • Refactor

    • Simplified signing methods across VeChain signer implementations
    • Streamlined import statements and method signatures
  • Chores

    • Updated type definitions and test cases to support new signing approach

Copy link
Contributor

coderabbitai bot commented Jan 7, 2025

Walkthrough

The pull request introduces significant changes to the VeChain signing functionality across multiple packages. The primary modifications involve simplifying the signing methods, particularly signMessage and signTypedData, by introducing a new signPayload method. The changes streamline the signing process, make the primaryType parameter optional in typed data signing, and remove some redundant methods. These updates affect the signer implementations, type definitions, and associated test suites.

Changes

File Change Summary
packages/aws-kms-adapter/src/KMSVeChainSigner.ts - Removed unused imports
- Changed signPayload method from private to public
- Removed signMessage and signTypedData methods
packages/network/src/signer/signers/types.d.ts - Updated type imports
- Added type aliases
- Made primaryType optional in signTypedData method
packages/network/src/signer/signers/vechain-abstract-signer/... - Implemented concrete signMessage method
- Added signPayload method
- Modified signTypedData to handle optional primaryType
- Added deducePrimaryType private method
packages/network/src/signer/signers/vechain-private-key-signer/... - Removed signMessage method
- Removed signTypedData method
- Added signPayload method
packages/network/src/provider/utils/rpc-mapper/... - Adjusted parameter order in ethSignTypedDataV4 method
Test files - Updated test cases to reflect new method signatures
- Modified parameter order in method calls
- Updated error handling and assertions

Sequence Diagram

sequenceDiagram
    participant Caller
    participant Signer
    participant Crypto
    
    Caller->>Signer: signPayload(payload)
    Signer->>Crypto: Sign payload
    Crypto-->>Signer: Return signature
    Signer-->>Caller: Return signed payload
Loading

Poem

🐰 Hop, hop, signing with grace,
Payload dancing through cyber space
Methods simplified, types now light
VeChain's signature shining bright
A rabbit's code, clean and neat! 🚀


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 595a59e and d8b59b1.

📒 Files selected for processing (8)
  • packages/aws-kms-adapter/src/KMSVeChainSigner.ts (6 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 (2 hunks)
  • packages/network/src/signer/signers/types.d.ts (4 hunks)
  • packages/network/src/signer/signers/vechain-abstract-signer/vechain-abstract-signer.ts (3 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)
🚧 Files skipped from review as they are similar to previous changes (6)
  • packages/network/src/provider/utils/rpc-mapper/methods/eth_signTypedData_v4/eth_signTypedData_v4.ts
  • packages/network/src/signer/signers/types.d.ts
  • packages/aws-kms-adapter/tests/KMSVeChainSigner.solo.test.ts
  • packages/aws-kms-adapter/tests/KMSVeChainSigner.unit.test.ts
  • packages/aws-kms-adapter/src/KMSVeChainSigner.ts
  • packages/network/src/signer/signers/vechain-abstract-signer/vechain-abstract-signer.ts
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: unit-integration-test-browser / Build & Lint (latest)
  • GitHub Check: unit-integration-test-browser / Build & Lint (lts/*)
  • GitHub Check: unit-integration-test-browser / Build & Lint (18)
  • GitHub Check: unit-integration-test / Build & Lint (latest)
  • GitHub Check: unit-integration-test / Build & Lint (lts/*)
  • GitHub Check: unit-integration-test / Build & Lint (18)
🔇 Additional comments (3)
packages/network/src/signer/signers/vechain-private-key-signer/vechain-private-key-signer.ts (1)

150-159: LGTM! Well-implemented signing method.

The implementation correctly follows the EIP-191 standard by adding 27 to the recovery flag. The method is well-documented and focused.

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

257-261: LGTM! Improved error message format.

The error message now provides better context with method name, failure reason, and parameters.


346-363: LGTM! Comprehensive test coverage.

The test suite properly verifies:

  1. Compatibility with ethers.js
  2. Support for optional primaryType parameter
  3. Backward compatibility

Finishing Touches

  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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 Jan 7, 2025

Test Coverage

Summary

Lines Statements Branches Functions
Coverage: 99%
98.98% (4368/4413) 97.47% (1392/1428) 99.01% (906/915)
Title Tests Skipped Failures Errors Time
core 836 0 💤 0 ❌ 0 🔥 2m 31s ⏱️
network 729 0 💤 0 ❌ 0 🔥 4m 58s ⏱️
errors 40 0 💤 0 ❌ 0 🔥 18.968s ⏱️
logging 3 0 💤 0 ❌ 0 🔥 20.278s ⏱️
hardhat-plugin 19 0 💤 0 ❌ 0 🔥 1m 1s ⏱️
aws-kms-adapter 23 0 💤 0 ❌ 0 🔥 1m 24s ⏱️
ethers-adapter 5 0 💤 0 ❌ 0 🔥 1m 19s ⏱️
rpc-proxy 37 0 💤 0 ❌ 0 🔥 1m 7s ⏱️

@fabiorigam fabiorigam marked this pull request as ready for review January 7, 2025 16:01
@fabiorigam fabiorigam requested a review from a team as a code owner January 7, 2025 16:01
Copy link
Contributor

@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

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

77-78: Update function documentation to reflect parameter order.

The JSDoc comment for the method needs to be updated to reflect that primaryType is now optional and comes after message.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 93ea34d and 595a59e.

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

17-17: LGTM! Coverage threshold adjustment is reasonable.

The reduction in branch coverage threshold from 100% to 90% aligns with the introduction of optional parameters and their associated conditional logic.

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

77-78: LGTM! Parameter reordering aligns with making primaryType optional.

The change to move typedData.message before typedData.primaryType is consistent with the PR objective of making primaryType optional.

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

149-150: LGTM! Test cases updated correctly.

The test cases have been properly updated to reflect the new parameter order, maintaining comprehensive test coverage for both success and error scenarios.

Also applies to: 164-165

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

302-303: LGTM! Integration test updated correctly.

The integration test has been properly updated to reflect the new parameter order while maintaining the same test coverage and validation.

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

294-295: Add test coverage for omitted primaryType parameter.

While the test cases are updated to use the new parameter order, there's no test coverage for the scenario where primaryType is omitted. This is important to verify the new optional parameter behavior.

Consider adding the following test case:

test('signTypedData - without primaryType', async () => {
    const signer = new VeChainPrivateKeySigner(
        Hex.of(eip712TestCases.valid.privateKey).bytes,
        provider
    );
    const actual = await signer.signTypedData(
        eip712TestCases.valid.domain,
        eip712TestCases.valid.types,
        eip712TestCases.valid.data
    );
    expect(actual).toBe(eip712TestCases.valid.signature);
});

Also applies to: 318-319, 327-328, 348-349

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

349-349: LGTM!

The abstract method signature is correctly updated to match the interface changes.

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

160-160: Documentation improvements look good!

The grammatical fixes enhance clarity:

  • "bytes payload" → "bytes' payload"
  • "to by signed" → "to be signed"

Also applies to: 315-315


191-194: Good refactoring!

The direct return of concatenated bytes simplifies the code while maintaining the same functionality.


402-407: Verify the impact of optional primaryType.

The changes to make primaryType optional align with the PR objective. However, we should verify that all consumers of this method are updated to handle the new parameter order.

✅ Verification successful

All signTypedData implementations and calls are consistent with optional primaryType parameter

The codebase scan shows that all implementations and calls to signTypedData maintain consistent parameter ordering with primaryType as the last parameter. The interface already defines primaryType as optional, and this pattern is followed throughout the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for calls to signTypedData to ensure they're updated for the new parameter order
rg -A 5 "signTypedData.*\(" --type ts

Length of output: 17824

@freemanzMrojo freemanzMrojo changed the title Make primaryType optional feat: deduce primaryType if not provided Jan 9, 2025
@freemanzMrojo freemanzMrojo changed the title feat: deduce primaryType if not provided feat(EIP712): deduce primaryType if not provided Jan 9, 2025
@freemanzMrojo freemanzMrojo linked an issue Jan 9, 2025 that may be closed by this pull request
@freemanzMrojo freemanzMrojo merged commit 5771ed4 into main Jan 9, 2025
18 checks passed
@freemanzMrojo freemanzMrojo deleted the fix-signtypeddata branch January 9, 2025 14:52
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
2 participants