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

fix: epk encryption variable name typo #1544

Merged
merged 3 commits into from
Jan 15, 2025
Merged

Conversation

rodrigopavezi
Copy link
Member

@rodrigopavezi rodrigopavezi commented Jan 14, 2025

Problem

EPK encryption through the EthereumPrivateKeyCipherProvider is broken. This issue was reported by @benjaminshafii where he was trying to create encrypted requests with the EthereumPrivateKeyCipherProvider and it was falling with the following error message:

❌ Failed to create encrypted request: Encryption key is required
Error details: 62 |             if (!data) {
63 |                 throw new Error('Data to encrypt cannot be empty');
64 |             }
65 |             console.log('options', options);
66 |             if (!((_a = options === null || options === void 0 ? void 0 : options.encryptionParams) === null || _a === void 0 ? void 0 : _a.key)) {
67 |                 throw new Error('Encryption key is required');

Description of the changes

  • Fix the issue by passing a single encryptionParams item for the cipherProvider.encrypt method as expected.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced encryption process for creating transactions with a single encryption parameter.
  • Bug Fixes

    • Improved test coverage for the transaction creation method using specific cipher providers.
  • Chores

    • Updated the return type of the encryption method to provide more structured information about encryption results.

Note: These changes are internal and should not directly impact end-user functionality.

Copy link
Contributor

coderabbitai bot commented Jan 14, 2025

Walkthrough

The pull request modifies the transactions-factory.ts file in the transaction manager package, specifically changing how encryption parameters are passed to the cipherProvider.encrypt method. In both createEncryptedTransactionInNewChannel and createEncryptedTransaction methods, the code now passes a single encryptionParam instead of the entire encryptionParams array when calling the encryption method. Additionally, a new test case is added to enhance test coverage for the createEncryptedTransactionInNewChannel method, and the return type of the encrypt method in the FakeEpkCipherProvider class is updated to provide a more structured output.

Changes

File Change Summary
packages/transaction-manager/src/transactions-factory.ts Modified createEncryptedTransactionInNewChannel and createEncryptedTransaction methods to pass a single encryptionParam instead of encryptionParams array when calling cipherProvider.encrypt.
packages/transaction-manager/test/unit/transactions-factory.test.ts Added a new test case for createEncryptedTransactionInNewChannel to verify encryption using EthereumPrivateKeyCipherProvider.
packages/transaction-manager/test/unit/utils/test-data.ts Updated encrypt method in FakeEpkCipherProvider to change return type from Promise<string> to Promise<EncryptionTypes.IEncryptedData>, ensuring structured output.

Possibly related PRs

Suggested reviewers

  • aimensahnoun
  • sstefdev
  • MantisClone
  • kevindavee

📜 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 0607c20 and 959aa97.

📒 Files selected for processing (2)
  • packages/transaction-manager/test/unit/transactions-factory.test.ts (1 hunks)
  • packages/transaction-manager/test/unit/utils/test-data.ts (1 hunks)
🧰 Additional context used
📓 Learnings (2)
📓 Common learnings
Learnt from: rodrigopavezi
PR: RequestNetwork/requestNetwork#1475
File: packages/transaction-manager/src/transactions-factory.ts:68-150
Timestamp: 2024-11-15T13:02:55.926Z
Learning: Refactoring of duplicate logic for encryption parameter handling in `packages/transaction-manager/src/transactions-factory.ts` will be addressed when removing `epk-decryption-provider`.
packages/transaction-manager/test/unit/utils/test-data.ts (2)
Learnt from: rodrigopavezi
PR: RequestNetwork/requestNetwork#1475
File: packages/transaction-manager/test/unit/utils/test-data.ts:0-0
Timestamp: 2024-11-22T13:13:26.166Z
Learning: In `packages/transaction-manager/test/unit/utils/test-data.ts`, the `FakeLitProtocolProvider` class uses `{}` as the return type for its methods `encrypt` and `decrypt`. Changing the return type to a more specific interface caused issues, so the current return type `{}` should remain as is.
Learnt from: rodrigopavezi
PR: RequestNetwork/requestNetwork#1475
File: packages/transaction-manager/test/unit/utils/test-data.ts:92-104
Timestamp: 2024-11-21T09:02:26.971Z
Learning: In `packages/transaction-manager/test/unit/utils/test-data.ts`, the `fakeEpkCipherProvider`'s `decrypt` method accepts an `options` object (e.g., `options: { identity }`) instead of directly passing `identity`. This design allows the cipher interface to be more generic and accommodate additional options for different providers' encryption and decryption methods as needed.
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-and-test
🔇 Additional comments (2)
packages/transaction-manager/test/unit/utils/test-data.ts (1)

143-151: LGTM! The return type change improves type safety.

The implementation now correctly returns a structured IEncryptedData object instead of just a string, which better represents the encrypted data format and improves type safety.

packages/transaction-manager/test/unit/transactions-factory.test.ts (1)

73-122: LGTM! Comprehensive test coverage for EPK encryption.

The test case thoroughly validates the encryption functionality:

  • Verifies the encrypted data format and prefixes
  • Checks the combined encryption method (ECIES-AES256_GCM)
  • Validates the number and format of encrypted keys

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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
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: 0

🧹 Nitpick comments (1)
packages/transaction-manager/src/transactions-factory.ts (1)

222-222: LGTM! Consider the planned refactoring.

The fix correctly passes a single encryption parameter, consistent with the previous change. Note that this duplicated encryption logic is already tracked for refactoring when the epk-decryption-provider is removed.

While the current fix is correct, the FIXME comment could be enhanced with a reference to the tracking issue/PR for better documentation:

-      // FIXME: Refactor, duplicated from createEncryptedTransactionInNewChannel
+      // FIXME: Refactor duplicated encryption logic from createEncryptedTransactionInNewChannel
+      // This will be addressed when removing epk-decryption-provider
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a6ddcae and 0607c20.

📒 Files selected for processing (1)
  • packages/transaction-manager/src/transactions-factory.ts (2 hunks)
🧰 Additional context used
📓 Learnings (2)
📓 Common learnings
Learnt from: rodrigopavezi
PR: RequestNetwork/requestNetwork#1475
File: packages/transaction-manager/src/transactions-factory.ts:68-150
Timestamp: 2024-11-15T13:02:55.926Z
Learning: Refactoring of duplicate logic for encryption parameter handling in `packages/transaction-manager/src/transactions-factory.ts` will be addressed when removing `epk-decryption-provider`.
packages/transaction-manager/src/transactions-factory.ts (1)
Learnt from: rodrigopavezi
PR: RequestNetwork/requestNetwork#1475
File: packages/transaction-manager/src/transactions-factory.ts:68-150
Timestamp: 2024-11-15T13:02:55.926Z
Learning: Refactoring of duplicate logic for encryption parameter handling in `packages/transaction-manager/src/transactions-factory.ts` will be addressed when removing `epk-decryption-provider`.
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-and-test
🔇 Additional comments (1)
packages/transaction-manager/src/transactions-factory.ts (1)

88-88: LGTM! Verify the encryption works with the fixed parameter.

The fix correctly passes a single encryption parameter instead of the array, which should resolve the EPK encryption issue.

To verify the fix works as expected, we can check for any error handling or logging related to encryption failures:

✅ Verification successful

✅ The encryption parameter fix is correctly implemented and well-tested

The test suite comprehensively verifies:

  • Correct handling of encryption parameters in both methods
  • Proper encryption output format and structure
  • Error cases for invalid parameters
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for error handling or logging related to encryption failures
rg -A 3 "encryption.*fail|fail.*encrypt" 

Length of output: 1914


Script:

#!/bin/bash
# Get the test implementations for encryption-related tests
ast-grep --pattern 'test($_, async () => {
  $$$
  encryptedData
  $$$
})'

Length of output: 76


Script:

#!/bin/bash
# Search for encryption-related test cases
rg -B 2 -A 10 "describe\(.*encrypt" packages/transaction-manager/test/unit/transactions-factory.test.ts

Length of output: 105


Script:

#!/bin/bash
# First find and then show content of the test file
fd "transactions-factory.test.ts" && cat $(fd "transactions-factory.test.ts")

Length of output: 9862

Copy link
Member

@MantisClone MantisClone left a comment

Choose a reason for hiding this comment

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

@rodrigopavezi Can you add more detail why the current code is broken and the impact of this bug?

Copy link
Member

@alexandre-abrioux alexandre-abrioux left a comment

Choose a reason for hiding this comment

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

Are we missing a test for this?

@rodrigopavezi
Copy link
Member Author

Are we missing a test for this?

@alexandre-abrioux good call. Test added.

Copy link
Member

@MantisClone MantisClone left a comment

Choose a reason for hiding this comment

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

Approved 👍 pending comment resolution 🚧

@rodrigopavezi rodrigopavezi merged commit b557dec into master Jan 15, 2025
10 checks passed
@rodrigopavezi rodrigopavezi deleted the fix/epk-encryption branch January 15, 2025 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants