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

imp(types): Add required wallet types for integration #19

Merged
merged 3 commits into from
Aug 5, 2024

Conversation

MalteHerrmann
Copy link
Collaborator

@MalteHerrmann MalteHerrmann commented Aug 2, 2024

This PR adds the required wallet types for integration with Ledger.

Summary by CodeRabbit

  • New Features

    • Introduced support for managing Ethereum accounts and wallets, enhancing wallet functionalities.
    • Added new interfaces and structures for integrating Ledger hardware wallets with the Cosmos SDK.
    • Implemented a mock wallet for testing interactions with the wallet interface.
  • Improvements

    • Updated configuration to include additional dependencies and enhance integration capabilities.
    • Enhanced changelog to reflect important updates related to required wallet types.
  • Tests

    • Added comprehensive test suites for the new wallet and Ledger functionalities, ensuring robust validation of features.

@MalteHerrmann MalteHerrmann requested a review from a team as a code owner August 2, 2024 18:24
@MalteHerrmann MalteHerrmann requested review from ramacarlucho and 0xstepit and removed request for a team August 2, 2024 18:24
Copy link

coderabbitai bot commented Aug 2, 2024

Walkthrough

The recent changes enhance the wallet management system by introducing new dependencies, refining configuration files, and implementing robust integration for Ledger hardware wallets with the Cosmos SDK. New files establish a structured framework for Ethereum account management, while comprehensive test suites ensure functionality and reliability across various scenarios.

Changes

Files Change Summary
.clconfig.json, CHANGELOG.md Added "types" in dependencies; updated changelog to reflect required wallet types for integration.
go.mod Added several new dependencies related to Cosmos SDK and IBC; optimized existing dependencies.
wallets/accounts/accounts.go Introduced structures and interfaces for managing Ethereum accounts and wallets, detailing methods for account handling and transaction signing.
wallets/ledger/ledger.go, wallets/usbwallet/hub.go, wallets/usbwallet/wallet.go Implemented Ledger wallet integration and USB wallet management, covering device management, account derivation, and signing operations.
wallets/ledger/ledger_suite_test.go, wallets/ledger/ledger_test.go Added comprehensive test suites to verify Ledger functionality and interactions in various scenarios.
wallets/ledger/mocks/wallet.go, wallets/ledger/wallet_test.go Created mock implementations to simulate Wallet behavior for testing.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Wallet as w
    participant Ledger as l
    participant USB as u

    User->>w: Open Wallet
    w->>l: Connect to Ledger
    l-->>w: Connection Established
    w->>u: Manage USB Devices
    u-->>w: List of Connected Wallets
    w->>u: Derive Account
    u-->>w: Provide Account Details
    w->>l: Sign Transaction
    l-->>w: Signature Returned
Loading

🐇 "In the meadow, changes bloom,
New wallets weave a brighter loom.
With Ledger's dance, we sign and play,
Ethereum's joy in a hop, hooray!
Each byte, each key, a tale to tell,
In the world of crypto, all is well!" 🐇


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

@github-actions github-actions bot added the tests label Aug 2, 2024
wallets/usbwallet/hub.go Dismissed Show dismissed Hide dismissed
wallets/usbwallet/hub.go Dismissed Show dismissed Hide dismissed
wallets/usbwallet/wallet.go Dismissed Show dismissed Hide dismissed
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

Outside diff range, codebase verification and nitpick comments (3)
wallets/accounts/accounts.go (1)

20-64: Clarify the usage of the passphrase parameter in the Open method.

The Open method includes a passphrase parameter that may not be used by all implementations. Consider adding documentation to clarify its usage.

-	// The passphrase parameter may or may not be used by the implementation of a
-	// particular wallet instance. The reason there is no password-less open method
-	// is to strive towards a uniform wallet handling, oblivious to the different
-	// backend providers.
+	// The passphrase parameter may not be used by all implementations. If not required,
+	// implementations should document this behavior to avoid confusion.
wallets/usbwallet/hub.go (1)

216-216: System time usage warning.

The usage of time.Now().UTC() is confirmed at wallets/usbwallet/hub.go. Ensure that its usage is necessary and does not introduce non-deterministic behavior.

  • wallets/usbwallet/hub.go:216
Analysis chain

System time usage warning.

The usage of time.Now().UTC() is flagged as a potential source of non-determinism. Ensure that its usage is necessary and does not introduce non-deterministic behavior.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `time.Now().UTC()` to ensure it does not introduce non-deterministic behavior.

# Test: Search for the usage of `time.Now().UTC()`. Expect: Only necessary usages.
rg --type go 'time.Now().UTC()'

Length of output: 33


Script:

#!/bin/bash
# Description: Verify the usage of `time.Now().UTC()` to ensure it does not introduce non-deterministic behavior.

# Test: Search for the usage of `time.Now().UTC()` in all Go files.
rg 'time.Now().UTC()' --glob '*.go' -A 3

Length of output: 42


Script:

#!/bin/bash
# Description: Verify the usage of `time.Now().UTC()` to ensure it does not introduce non-deterministic behavior.

# Test: Search for the usage of `time.Now().UTC()` in all Go files.
rg 'time.Now().UTC()' -t go -A 3

Length of output: 34


Script:

#!/bin/bash
# Description: Verify the usage of `time.Now()` to ensure it does not introduce non-deterministic behavior.

# Test: Search for the usage of `time.Now()` in all Go files.
rg 'time.Now()' -t go -A 3

Length of output: 211

Tools
GitHub Check: CodeQL

[warning] 216-216: Calling the system time
Calling the system time may be a possible source of non-determinism

wallets/usbwallet/wallet.go (1)

111-143: Ensure proper error handling for Open function calls.

The following instances of the Open function do not handle potential errors appropriately:

  • wallets/ledger/ledger.go:
    • Lines with _ = e.PrimaryWallet.Open("")

Please ensure that all calls to the Open function handle potential errors properly to avoid unexpected behavior.

Analysis chain

LGTM! But verify the function usage in the codebase.

The Open function is correctly implemented with proper use of locks and initialization logic.

However, ensure that all function calls to Open handle the potential errors appropriately.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `Open` handle the potential errors appropriately.

# Test: Search for the function usage. Expect: Proper error handling in all occurrences.
rg --type go -A 5 $'Open('

Length of output: 88


Script:

#!/bin/bash
# Description: Verify all function calls to `Open` handle the potential errors appropriately.

# Test: Search for the function usage. Expect: Proper error handling in all occurrences.
rg --type go -A 5 'Open\('

Length of output: 7697

Tools
GitHub Check: CodeQL

[notice] 140-140: Spawning a Go routine
Spawning a Go routine may be a possible source of non-determinism

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9c637f2 and b38681a.

Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
Files selected for processing (12)
  • .clconfig.json (1 hunks)
  • CHANGELOG.md (1 hunks)
  • go.mod (5 hunks)
  • wallets/accounts/accounts.go (1 hunks)
  • wallets/ledger/ledger.go (1 hunks)
  • wallets/ledger/ledger_suite_test.go (1 hunks)
  • wallets/ledger/ledger_test.go (1 hunks)
  • wallets/ledger/mocks/wallet.go (1 hunks)
  • wallets/ledger/wallet_test.go (1 hunks)
  • wallets/usbwallet/hub.go (1 hunks)
  • wallets/usbwallet/ledger.go (1 hunks)
  • wallets/usbwallet/wallet.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • wallets/ledger/mocks/wallet.go
Additional context used
GitHub Check: CodeQL
wallets/usbwallet/hub.go

[warning] 216-216: Calling the system time
Calling the system time may be a possible source of non-determinism


[notice] 14-14: Sensitive package import
Certain system packages contain functions which may be a possible source of non-determinism

wallets/usbwallet/wallet.go

[notice] 140-140: Spawning a Go routine
Spawning a Go routine may be a possible source of non-determinism

Additional comments not posted (62)
CHANGELOG.md (1)

11-11: Changelog entry looks good.

The new entry under the "Improvements" section correctly highlights the addition of required wallet types for integration.

.clconfig.json (1)

22-23: Configuration update looks good.

The addition of "types" in the dependencies array is appropriate and aligns with the PR objectives.

wallets/ledger/wallet_test.go (6)

17-20: Mock function RegisterDerive looks good.

The function correctly mocks the Derive method of a wallet.


22-25: Mock function RegisterDeriveError looks good.

The function correctly mocks the Derive method to return an error.


27-30: Mock function RegisterOpen looks good.

The function correctly mocks the Open method of a wallet.


32-35: Mock function RegisterClose looks good.

The function correctly mocks the Close method of a wallet.


37-41: Mock function RegisterSignTypedData looks good.

The function correctly mocks the SignTypedData method of a wallet.


43-47: Mock function RegisterSignTypedDataError looks good.

The function correctly mocks the SignTypedData method to return an error.

wallets/accounts/accounts.go (2)

13-18: LGTM!

The Account struct is well-defined and correctly represents an Ethereum account.


66-80: LGTM!

The Backend interface is well-defined and straightforward.

wallets/ledger/ledger_suite_test.go (5)

42-54: LGTM!

The SetupTest method is comprehensive and correctly initializes the necessary components for the tests.


38-40: LGTM!

The TestLedgerTestSuite function is correctly implemented and uses the testify suite.


56-63: LGTM!

The newPubKey function is correctly implemented and handles errors appropriately.


65-90: LGTM!

The getMockTxAmino function is correctly implemented and sanitizes the input string.


92-154: LGTM!

The getMockTxProtobuf function is correctly implemented and handles errors appropriately.

wallets/ledger/ledger.go (8)

25-31: LGTM!

The EvmosLedgerDerivation function is correctly implemented and returns the appropriate derivation function.


42-50: LGTM!

The Close method is correctly implemented and handles the case where no wallet is found.


52-70: LGTM!

The GetPublicKeySECP256K1 method is correctly implemented and handles errors appropriately.


72-95: LGTM!

The GetAddressPubKeySECP256K1 method is correctly implemented and handles errors appropriately.


97-132: LGTM!

The SignSECP256K1 method is correctly implemented and handles errors appropriately.


135-152: LGTM!

The displayEIP712Hash method is correctly implemented and handles errors appropriately.


154-184: LGTM!

The connectToLedgerApp method is correctly implemented and handles errors appropriately.


186-190: LGTM!

The bytesToHexString function is correctly implemented.

wallets/usbwallet/hub.go (6)

21-31: Constants look good!

The constants LedgerScheme, onLinux, and refreshThrottling are well-defined and used appropriately in the code.


35-55: Struct Hub looks good!

The Hub struct is well-defined with appropriate fields for managing USB hardware wallets.


57-82: Function NewLedgerHub looks good!

The function correctly initializes a new Hub for Ledger devices and handles unsupported platforms appropriately.


84-100: Function newHub looks good!

The function correctly initializes a new Hub for generic USB devices and handles unsupported platforms appropriately.


102-114: Function Wallets looks good!

The function correctly returns a copy of the currently tracked USB wallet devices, ensuring thread safety with appropriate locking.


6-19: Sensitive package import warning.

The import of the runtime package is flagged as a potential source of non-determinism. Ensure that its usage is justified and does not introduce non-deterministic behavior.

Verification successful

Sensitive package import warning.

The import of the runtime package is used deterministically to check the operating system (runtime.GOOS == "linux"). This usage does not introduce non-deterministic behavior.

  • wallets/usbwallet/hub.go
    • Line 6: Import statement for runtime
    • Line 19: Usage of runtime.GOOS
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the `runtime` package to ensure it does not introduce non-deterministic behavior.

# Test: Search for the usage of the `runtime` package. Expect: Only used for checking the OS.
rg --type go 'runtime'

Length of output: 247

Tools
GitHub Check: CodeQL

[notice] 14-14: Sensitive package import
Certain system packages contain functions which may be a possible source of non-determinism

wallets/ledger/ledger_test.go (7)

22-26: Function init looks good!

The function correctly initializes the encoding configuration for sign doc encoding/decoding.


28-53: Function TestEvmosLedgerDerivation looks good!

The test cases are comprehensive and correctly implemented.


55-89: Function TestClose looks good!

The test cases are comprehensive and correctly implemented.


91-167: Function TestSignatures looks good!

The test cases are comprehensive and correctly implemented.


169-214: Function TestSignatureEquivalence looks good!

The test cases are comprehensive and correctly implemented.


216-276: Function TestGetAddressPubKeySECP256K1 looks good!

The test cases are comprehensive and correctly implemented.


278-326: Function TestGetPublicKeySECP256K1 looks good!

The test cases are comprehensive and correctly implemented.

go.mod (1)

11-19: Dependencies look good!

The newly added dependencies are necessary and correctly declared.

wallets/usbwallet/wallet.go (13)

93-96: LGTM!

The URL function is straightforward and correctly implemented.


98-109: LGTM!

The Status function is correctly implemented with proper use of a read lock.


145-188: LGTM!

The heartbeat function is correctly implemented with proper use of locks and error handling.

Note: There is an existing comment about the potential non-determinism due to spawning a goroutine. This is acknowledged.


190-218: LGTM!

The Close function is correctly implemented with proper use of locks and resource management.


220-236: LGTM!

The close function is correctly implemented with proper resource management.


238-249: LGTM!

The Accounts function is correctly implemented with proper use of a read lock.


251-260: LGTM!

The Contains function is correctly implemented with proper use of a read lock.


262-303: LGTM!

The Derive function is correctly implemented with proper use of locks and error handling.


305-313: LGTM!

The formatPathIfNeeded function is correctly implemented with proper logic.


315-319: LGTM!

The signHash function is correctly implemented to return an error as expected.


321-362: LGTM!

The signData function is correctly implemented with proper use of locks and error handling.


364-390: LGTM!

The verifyTypedDataSignature function is correctly implemented with proper logic and error handling.


392-413: LGTM!

The SignTypedData function is correctly implemented with proper use of locks and error handling.

wallets/usbwallet/ledger.go (12)

57-60: LGTM!

The newLedgerDriver function is correctly implemented.


62-75: LGTM!

The Status function is correctly implemented with proper error handling.


77-82: LGTM!

The offline function is correctly implemented.


108-113: LGTM!

The Close function is correctly implemented.


115-123: LGTM!

The Heartbeat function is correctly implemented with proper error handling.


125-129: LGTM!

The Derive function is correctly implemented.


131-147: LGTM!

The SignTypedMessage function is correctly implemented with proper version checks and error handling.


149-179: LGTM!

The ledgerVersion function is correctly implemented with proper error handling.


181-269: LGTM!

The ledgerDerive function is correctly implemented with proper error handling.


271-334: LGTM!

The ledgerSignTypedMessage function is correctly implemented with proper error handling.


336-433: LGTM!

The ledgerExchange function is correctly implemented with proper error handling.


84-105: LGTM! But verify the function usage in the codebase.

The Open function is correctly implemented with proper initialization logic.

However, ensure that all function calls to Open handle the potential errors appropriately.

wallets/usbwallet/hub.go Show resolved Hide resolved
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b38681a and 974b38b.

Files selected for processing (1)
  • wallets/ledger/ledger_suite_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • wallets/ledger/ledger_suite_test.go

@MalteHerrmann MalteHerrmann merged commit 579bac9 into main Aug 5, 2024
18 of 25 checks passed
@MalteHerrmann MalteHerrmann deleted the add-wallets branch August 5, 2024 11:55
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