Skip to content

Integrate Ecosystem Signing Policies #149

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

0xFirekeeper
Copy link
Member

@0xFirekeeper 0xFirekeeper commented May 27, 2025

Closes TOOL-4019

Pending tests


PR-Codex overview

This PR focuses on enhancing the PersonalSign methods across various wallet classes to include optional parameters for originalMessage and chainId. It also introduces new classes for user operations and improves JSON serialization settings.

Detailed summary

  • Added UserOperationHexifiedV6 and UserOperationHexifiedV7 classes with JSON serialization.
  • Updated PersonalSign methods in PrivateKeyWallet, EngineWallet, and IThirdwebWallet to include originalMessage and chainId parameters.
  • Enhanced JSON serialization in ThirdwebRPC and EcosystemWallet to ignore null values.
  • Modified payloads in EcosystemWallet for signing messages to include new parameters.
  • Adjusted HashAndSignUserOp methods in SmartWallet to pass new parameters during signing.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features

    • Expanded signature methods across various wallet types to accept additional optional parameters for enhanced signing flexibility.
  • Improvements

    • Improved JSON serialization to ignore null values in wallet operations and batch requests, resulting in cleaner and more efficient request payloads.
  • Documentation

    • Updated method documentation to reflect new optional parameters in wallet signing interfaces.

Copy link

linear bot commented May 27, 2025

Copy link

coderabbitai bot commented May 27, 2025

Walkthrough

The changes introduce optional originalMessage and chainId parameters to PersonalSign methods across wallet classes and interfaces. These parameters are included in payloads sent to enclave signing endpoints and used in user operation signing. JSON serialization is updated to ignore null values for these new fields and related user operation classes.

Changes

File(s) Change Summary
Thirdweb/Thirdweb.Wallets/IThirdwebWallet.cs
Thirdweb/Thirdweb.Wallets/EngineWallet/EngineWallet.cs
Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.cs
Thirdweb/Thirdweb.Wallets/PrivateKeyWallet/PrivateKeyWallet.cs
Thirdweb/Thirdweb.Wallets/SmartWallet/SmartWallet.cs
Added optional originalMessage and chainId parameters to PersonalSign methods and updated implementations to include these in signing payloads or calls.
Thirdweb/Thirdweb.Wallets/SmartWallet/Thirdweb.AccountAbstraction/AATypes.cs Added [JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] attribute to user operation classes to ignore null values during serialization.
Thirdweb/Thirdweb.RPC/ThirdwebRPC.cs Updated JSON serialization settings to ignore null values in batch RPC requests by introducing _jsonSerializerSettings.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant SmartWallet
    participant PersonalAccount
    participant EnclaveAPI

    Caller->>SmartWallet: HashAndSignUserOp(userOp, chainId)
    SmartWallet->>SmartWallet: EncodeUserOperation(userOp)
    SmartWallet->>PersonalAccount: PersonalSign(userOpHash, originalMessage=userOp, chainId)
    PersonalAccount->>EnclaveAPI: POST /sign-message { message, isRaw, originalMessage, chainId }
    EnclaveAPI-->>PersonalAccount: signature
    PersonalAccount-->>SmartWallet: signature
    SmartWallet-->>Caller: signature
Loading

Assessment against linked issues

Objective Addressed Explanation
Pass originalMessage and chainId to enclave sign-message API when signing user operations (TOOL-4019)

📜 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 69df32e and edbe643.

📒 Files selected for processing (1)
  • Thirdweb/Thirdweb.Wallets/IThirdwebWallet.cs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Thirdweb/Thirdweb.Wallets/IThirdwebWallet.cs
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-test-cov
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

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

@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

♻️ Duplicate comments (2)
Thirdweb/Thirdweb.Wallets/IThirdwebWallet.cs (1)

68-69: Fix typo in XML documentation.

Same typo as above: "polciies" should be "policies".

Thirdweb/Thirdweb.Wallets/EngineWallet/EngineWallet.cs (1)

210-210: Consider utilizing the new parameters or document why they're unused.

Same issue as the byte array overload - the new parameters should likely be used in the engine request payload for proper ecosystem signing policy support.

🧹 Nitpick comments (3)
Thirdweb/Thirdweb.Wallets/EngineWallet/EngineWallet.cs (1)

191-191: Consider utilizing the new parameters or document why they're unused.

The new optional parameters originalMessage and chainId are added to match the interface but are not used in the implementation. For ecosystem signing policies, these parameters should likely be included in the JSON payload sent to the engine backend.

Consider updating the payload to include these parameters:

 public async Task<string> PersonalSign(byte[] rawMessage, object originalMessage = null, BigInteger? chainId = null)
 {
     if (rawMessage == null)
     {
         throw new ArgumentNullException(nameof(rawMessage), "Message to sign cannot be null.");
     }

-    var payload = new { messagePayload = new { message = rawMessage.BytesToHex(), isBytes = true } };
+    var payload = new { 
+        messagePayload = new { 
+            message = rawMessage.BytesToHex(), 
+            isBytes = true, 
+            originalMessage, 
+            chainId = chainId?.ToString() 
+        } 
+    };
Thirdweb/Thirdweb.Wallets/SmartWallet/SmartWallet.cs (2)

1086-1089: Consider utilizing the new optional parameters.

The PersonalSign method signatures have been properly updated with optional parameters to maintain backward compatibility. However, the implementation doesn't utilize the new originalMessage and chainId parameters - they're passed through but not used locally.

This may be intentional if this SmartWallet is purely delegating to the underlying personal account, but consider documenting this behavior or validating that the parameters are being properly forwarded to the ecosystem signing infrastructure.

The method at line 1098 only passes the message parameter:

-return await this._personalAccount.PersonalSign(message).ConfigureAwait(false);
+return await this._personalAccount.PersonalSign(message, originalMessage, chainId).ConfigureAwait(false);

Also applies to: 1094-1115


876-876: Verify encoding performance impact.

The user operation is now encoded twice in the signing flow - once here to pass as context, and again later when the operation is submitted. Consider if this encoding step could be optimized or cached.

Monitor performance impact in production, especially for high-frequency user operations. The encoding step could potentially be cached if it becomes a bottleneck.

Also applies to: 949-949

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b6541d6 and 69df32e.

📒 Files selected for processing (7)
  • Thirdweb/Thirdweb.RPC/ThirdwebRPC.cs (2 hunks)
  • Thirdweb/Thirdweb.Wallets/EngineWallet/EngineWallet.cs (2 hunks)
  • Thirdweb/Thirdweb.Wallets/IThirdwebWallet.cs (1 hunks)
  • Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.cs (3 hunks)
  • Thirdweb/Thirdweb.Wallets/PrivateKeyWallet/PrivateKeyWallet.cs (2 hunks)
  • Thirdweb/Thirdweb.Wallets/SmartWallet/SmartWallet.cs (3 hunks)
  • Thirdweb/Thirdweb.Wallets/SmartWallet/Thirdweb.AccountAbstraction/AATypes.cs (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-test-cov
🔇 Additional comments (13)
Thirdweb/Thirdweb.RPC/ThirdwebRPC.cs (2)

28-28: LGTM! Good addition of centralized JSON serialization settings.

The addition of _jsonSerializerSettings with NullValueHandling.Ignore is a good practice that ensures consistent JSON serialization behavior across RPC requests.


171-171: LGTM! Proper utilization of the serialization settings.

The updated SendBatchAsync method correctly uses the centralized JSON serialization settings, ensuring null values are ignored in batch requests.

Thirdweb/Thirdweb.Wallets/SmartWallet/Thirdweb.AccountAbstraction/AATypes.cs (2)

122-122: LGTM! Proper JSON serialization configuration.

The JsonObject attribute with ItemNullValueHandling.Ignore ensures that null properties in UserOperationHexifiedV6 are not included in JSON serialization, which is important for clean API payloads.


159-159: LGTM! Consistent serialization behavior.

The JsonObject attribute applied to UserOperationHexifiedV7 maintains consistency with the V6 implementation and ensures proper null value handling during serialization.

Thirdweb/Thirdweb.Wallets/IThirdwebWallet.cs (2)

62-62: LGTM! Well-designed interface extension.

The addition of optional parameters maintains backward compatibility while supporting ecosystem signing policies. The parameter types are appropriate for the intended use case.


71-71: LGTM! Consistent method signature extension.

The string overload of PersonalSign is consistently updated with the same optional parameters as the byte array overload.

Thirdweb/Thirdweb.Wallets/PrivateKeyWallet/PrivateKeyWallet.cs (2)

212-222: LGTM! Interface consistency maintained for ecosystem signing policies.

The addition of optional originalMessage and chainId parameters maintains interface consistency with other wallet implementations. The parameters are appropriately unused in this local signing implementation since ecosystem signing policies likely apply only to remote/enclave-based wallets.


224-234: LGTM! String overload updated consistently.

The string overload of PersonalSign has been updated with the same optional parameters as the byte array overload, maintaining method signature consistency across the interface.

Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.cs (3)

51-51: Good practice: JSON serialization settings configured for optional parameters.

The JsonSerializerSettings with NullValueHandling.Ignore is well-configured to handle the new optional parameters. This ensures that null values are omitted from the JSON payload sent to the enclave signing endpoint, resulting in cleaner API requests.


1006-1025: Well-implemented: Optional parameters integrated into enclave API payload.

The PersonalSign method for byte arrays correctly incorporates the new optional parameters into the messagePayload. The parameters are properly included in the API request to the enclave signing endpoint, enabling ecosystem signing policies to access additional context like the original message and chain ID.


1035-1054: Consistent implementation: String overload matches byte array handling.

The string overload of PersonalSign maintains consistency with the byte array version by including the same optional parameters in the payload structure and using the same JSON serialization settings.

Thirdweb/Thirdweb.Wallets/SmartWallet/SmartWallet.cs (2)

876-883: LGTM - Consistent implementation of ecosystem signing context.

The V6 HashAndSignUserOp method correctly encodes the user operation and passes it as additional context to the personal account's PersonalSign method. The conditional logic properly handles both external and non-external account types.


949-956: LGTM - V7 implementation matches V6 pattern.

The V7 HashAndSignUserOp method follows the same pattern as V6, ensuring consistency across entry point versions. The encoded user operation provides necessary context for ecosystem signing policies.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: Firekeeper <[email protected]>
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 60.96%. Comparing base (b6541d6) to head (edbe643).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #149      +/-   ##
==========================================
+ Coverage   60.94%   60.96%   +0.01%     
==========================================
  Files          41       41              
  Lines        6563     6566       +3     
  Branches      832      832              
==========================================
+ Hits         4000     4003       +3     
  Misses       2376     2376              
  Partials      187      187              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

2 participants