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: add deprecation, isDecryptionEnabled function and lerna caching #1502

Merged
merged 2 commits into from
Dec 2, 2024

Conversation

rodrigopavezi
Copy link
Member

@rodrigopavezi rodrigopavezi commented Dec 2, 2024

Description of the changes

After reviewing the changes with @MantisClone we decided to

  • add isDecryptionEnabled function to the cipher provider
  • Change default EthereumPrivateKeyCipherProvider.isDecryptionEnabled to True, to match legacy behavior of EthereumPrivateKeyDecryptionProvider
  • add deprecation for the epk decryption provider
  • fix lerna caching

Summary by CodeRabbit

  • New Features

    • Introduced a new method isDecryptionEnabled() across various providers to check if decryption is enabled.
    • Added a new clean task to enhance task management.
  • Deprecations

    • Marked EthereumPrivateKeyDecryptionProvider as deprecated, recommending the use of EthereumPrivateKeyCipherProvider instead.
  • Bug Fixes

    • Updated logic for decryption state management for clarity and consistency in multiple classes.

Copy link
Contributor

coderabbitai bot commented Dec 2, 2024

Walkthrough

The pull request introduces several changes across multiple files, primarily focusing on updating the configuration in nx.json to enhance task management by incorporating a new "clean" operation and modifying dependencies for existing targets. Additionally, it involves renaming variables and methods related to decryption in several classes, improving clarity in their interfaces. The EthereumPrivateKeyDecryptionProvider class is marked as deprecated, directing users to the EthereumPrivateKeyCipherProvider instead. A new method, isDecryptionEnabled, is added to multiple classes and an interface to facilitate checking the decryption status.

Changes

File Path Change Summary
nx.json - Updated cacheableOperations to include "clean".
- Modified test target's dependsOn to include "clean".
- Added new target clean with dependsOn set to ["^clean"].
packages/epk-cipher/src/ethereum-private-key-cipher-provider.ts - Renamed variable isDecryptionOn to decryptionEnabled.
- Updated methods to use the new variable.
- Added method isDecryptionEnabled().
packages/epk-decryption/src/ethereum-private-key-decryption-provider.ts - Marked class as deprecated with a warning message directing to EthereumPrivateKeyCipherProvider.
packages/lit-protocol-cipher/src/lit-protocol-cipher-provider.ts - Renamed variable isDecryptionOn to decryptionEnabled.
- Updated methods to use the new variable.
- Added method isDecryptionEnabled().
packages/types/src/cipher-provider-types.ts - Added method isDecryptionEnabled(): boolean to ICipherProvider interface.

Possibly related PRs

  • refactor: rename decryption enable method #1499: The changes in this PR involve renaming the switchOnOffDecryption method to enableDecryption in the EthereumPrivateKeyCipherProvider class, which is related to the overall theme of improving clarity in method naming, similar to the restructuring of dependencies in the main PR.

Suggested reviewers

  • MantisClone
  • aimensahnoun
  • sstefdev

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 321fbe8 and 78ce4f2.

📒 Files selected for processing (5)
  • nx.json (2 hunks)
  • packages/epk-cipher/src/ethereum-private-key-cipher-provider.ts (3 hunks)
  • packages/epk-decryption/src/ethereum-private-key-decryption-provider.ts (2 hunks)
  • packages/lit-protocol-cipher/src/lit-protocol-cipher-provider.ts (3 hunks)
  • packages/types/src/cipher-provider-types.ts (1 hunks)
🧰 Additional context used
📓 Learnings (2)
packages/epk-decryption/src/ethereum-private-key-decryption-provider.ts (1)
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1475
File: packages/epk-cipher/src/ethereum-private-key-cipher-provider.ts:129-136
Timestamp: 2024-11-20T16:40:07.257Z
Learning: In `packages/epk-cipher/src/ethereum-private-key-cipher-provider.ts`, code copied from `EthereumPrivateKeyDecryptionProvider` is considered legacy working code, and changes to it are out of scope for PRs.
packages/epk-cipher/src/ethereum-private-key-cipher-provider.ts (1)
Learnt from: MantisClone
PR: RequestNetwork/requestNetwork#1475
File: packages/epk-cipher/src/ethereum-private-key-cipher-provider.ts:129-136
Timestamp: 2024-11-20T16:40:07.257Z
Learning: In `packages/epk-cipher/src/ethereum-private-key-cipher-provider.ts`, code copied from `EthereumPrivateKeyDecryptionProvider` is considered legacy working code, and changes to it are out of scope for PRs.
🔇 Additional comments (9)
nx.json (1)

6-6: LGTM! Verify the clean target implementation

The changes to improve caching and build dependencies look good. The addition of the "clean" operation and its dependencies creates a more robust build pipeline.

Let's verify the clean target implementation across packages:

Also applies to: 15-18

✅ Verification successful

Clean scripts are properly implemented across all packages

All packages have appropriate clean scripts defined:

  • Root package.json uses lerna run clean to orchestrate cleaning across packages
  • Most packages use standard cleanup: rm -rf dist tsconfig.tsbuildinfo tsconfig.build.tsbuildinfo
  • Special cases are properly handled:
    • smart-contracts: Uses additional clean targets for lib, types and hardhat
    • payment-detection: Includes cleaning of generated files
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for clean scripts in package.json files
# Expected: Each package should have a clean script defined

# Find all package.json files and check for clean scripts
fd package.json --type f --exec sh -c 'echo "=== {} ===" && cat {} | jq -r ".scripts.clean"'

Length of output: 2694

packages/types/src/cipher-provider-types.ts (1)

38-43: LGTM! Well-documented interface addition

The new isDecryptionEnabled method is a logical addition that complements the existing enableDecryption method, providing a way to check the current state. The documentation follows the established pattern.

packages/epk-decryption/src/ethereum-private-key-decryption-provider.ts (2)

11-11: LGTM! Clear deprecation notice

The @deprecated JSDoc tag with migration guidance is a good practice for deprecating APIs.


25-27: Verify the migration path to EthereumPrivateKeyCipherProvider

The runtime warning helps users identify deprecated usage. Let's verify the availability of the replacement implementation.

✅ Verification successful

Let me gather more information about both classes to compare their interfaces.


Let me get the implementation of the deprecated class to complete the comparison.


Migration path to EthereumPrivateKeyCipherProvider is clear and complete

The replacement EthereumPrivateKeyCipherProvider is available in packages/epk-cipher and provides a superset of functionality compared to the deprecated class:

  • It maintains all existing methods with identical signatures (decrypt, isIdentityRegistered, addDecryptionParameters, etc.)
  • It adds encryption capabilities through the new encrypt method
  • It includes additional control over decryption through enableDecryption, isDecryptionEnabled
  • It implements the more comprehensive ICipherProvider interface while maintaining backward compatibility
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence and compatibility of EthereumPrivateKeyCipherProvider
# Expected: Find the replacement class and compare interfaces

# Check for the replacement class
echo "=== Searching for replacement class ==="
rg -l "class EthereumPrivateKeyCipherProvider"

# Compare method signatures to ensure compatibility
echo "=== Comparing interfaces ==="
ast-grep --pattern 'class EthereumPrivateKeyCipherProvider {
  $$$
}'

Length of output: 340


Script:

#!/bin/bash
# Get the interface of both classes for comparison
echo "=== EthereumPrivateKeyDecryptionProvider interface ==="
ast-grep --pattern 'class EthereumPrivateKeyDecryptionProvider {
  $$$
}'

echo -e "\n=== EthereumPrivateKeyCipherProvider interface ==="
cat packages/epk-cipher/src/ethereum-private-key-cipher-provider.ts

Length of output: 6894


Script:

#!/bin/bash
echo "=== EthereumPrivateKeyDecryptionProvider implementation ==="
cat packages/epk-decryption/src/ethereum-private-key-decryption-provider.ts

Length of output: 5159

packages/epk-cipher/src/ethereum-private-key-cipher-provider.ts (2)

23-23: LGTM! Variable renaming improves clarity

The renaming of isDecryptionOn to decryptionEnabled follows better boolean naming conventions and makes the code more readable. The related changes in isDecryptionAvailable() and enableDecryption() are consistent with this renaming.

Also applies to: 47-47, 56-56


59-65: LGTM! New method enhances the interface

The addition of isDecryptionEnabled() provides a clear way to check the decryption state externally. The implementation is straightforward and follows the interface requirements.

packages/lit-protocol-cipher/src/lit-protocol-cipher-provider.ts (3)

66-66: LGTM! Consistent variable renaming across providers

The renaming of isDecryptionOn to decryptionEnabled maintains consistency with the EthereumPrivateKeyCipherProvider implementation. The changes in enableDecryption() and isDecryptionAvailable() correctly reflect this renaming.

Also applies to: 287-288, 345-345


290-295: LGTM! New method matches interface requirements

The implementation of isDecryptionEnabled() is consistent with the EthereumPrivateKeyCipherProvider implementation and provides the same functionality.


345-345: Verify the additional checks in isDecryptionAvailable

The isDecryptionAvailable() method includes additional checks for client and sessionSigs compared to the EthereumPrivateKeyCipherProvider implementation. This difference appears intentional due to the different nature of the providers, but it would be good to verify this is expected behavior.

✅ Verification successful

Different isDecryptionAvailable implementations are correct by design

The implementations differ based on their specific requirements:

  • LitProvider checks client !== null && sessionSigs !== null && this.decryptionEnabled because it needs both an initialized client and valid session signatures to perform decryption operations.
  • EthereumPrivateKeyCipherProvider checks this.decryptionParametersDictionary.size > 0 && this.decryptionEnabled because it requires at least one private key to be available for decryption.

These differences are intentional and align with each provider's unique encryption/decryption mechanism:

  • Lit Protocol requires an active client connection and session signatures for its decentralized key management
  • EPK requires locally stored private keys for its direct encryption/decryption
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if other cipher providers have similar checks in their isDecryptionAvailable methods
ast-grep --pattern 'isDecryptionAvailable() {
  $$$
}'

Length of output: 56


Script:

#!/bin/bash
# Search for isDecryptionAvailable method implementations with context
rg "isDecryptionAvailable" -A 5 --type typescript

# Also search for class definitions containing cipher provider to ensure we find all implementations
rg "class.*CipherProvider" -A 20 --type typescript

Length of output: 172


Script:

#!/bin/bash
# Search for isDecryptionAvailable method implementations with context
rg "isDecryptionAvailable" -A 5

# Also search for class definitions containing cipher provider to ensure we find all implementations
rg "class.*CipherProvider" -A 20

Length of output: 11619


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 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.

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.

3 participants