Skip to content

Conversation

felipemadero
Copy link
Contributor

@felipemadero felipemadero commented Sep 25, 2025

Why this should be merged

This refactoring improves code organization by centralizing keychain interfaces in a single package. Currently, the EthKeychain interface is defined in wallet/chain/c, which creates an awkward dependency where core keychain functionality is scattered across different packages. This separation makes it unclear that keychain implementations should provide both AVAX and Ethereum address support.

How this works

  • Interface relocation: The EthKeychain interface with GetEth(addr common.Address) (Signer, bool) and EthAddresses() set.Set[common.Address] methods is moved to the main keychain package

How this was tested

  • Unit tests

Need to be documented in RELEASES.md?

- Move EthKeychain interface from wallet/chain/c to utils/crypto/keychain/keychain.go
- Add EthKeychain interface compliance check to secp256k1fx.Keychain
@Copilot Copilot AI review requested due to automatic review settings September 25, 2025 18:22
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the code organization by moving the EthKeychain interface from the wallet/chain/c package to the utils/crypto/keychain package, centralizing keychain interfaces in one location.

  • Relocates EthKeychain interface definition to improve code organization
  • Updates import statements and type references across affected files
  • Adds compile-time verification that secp256k1fx.Keychain implements EthKeychain

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
utils/crypto/keychain/keychain.go Adds EthKeychain interface definition and imports
wallet/chain/c/signer.go Removes EthKeychain interface and updates type references
vms/secp256k1fx/keychain.go Adds compile-time check for EthKeychain implementation
wallet/subnet/primary/wallet.go Updates parameter type reference

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

yacovm
yacovm previously approved these changes Sep 25, 2025
@StephenButtolph
Copy link
Contributor

Isn't it supposed to be preferred to define the interface where it is used, rather than next to the struct that defines it?

I know that isn't necessarily what we have done in avalanchego in the past, but this PR seems to be pushing us back into a bad pattern (rather than pushing us towards a cleaner pattern).

@felipemadero
Copy link
Contributor Author

felipemadero commented Sep 25, 2025

Isn't it supposed to be preferred to define the interface where it is used, rather than next to the struct that defines it?

You're right about the Go convention. Looking at usage, EthKeychain is primarily used in wallet/chain/c (signer) and wallet/subnet/primary (wallet creation). I moved it to match the existing Keychain pattern and also wanted to provide a single point of reference for keychain implementations (ledger, cubesigner, secp256k1fx). This makes it easier to see what interfaces need to be implemented when adding new keychain types IMO. But given the more limited usage compared to Keychain, would you prefer it back in wallet/chain/c where it's most heavily used?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants