Skip to content

Conversation

felipemadero
Copy link
Contributor

Why this should be merged

The current ledger interface returns addresses (ids.ShortID) directly, which couples the ledger abstraction to a specific address format. This refactor changes the interface to return public keys instead, enabling:

  • Support for multiple address formats (Avalanche and Ethereum) from the same ledger key
  • Satisfies EthKeychain interface, enabling ledger to be used to fully sign C-chain transactions on wallet

How this works

Ledger Interface Changes:

  • Ledger.Address()Ledger.PubKey() - returns *secp256k1.PublicKey
  • Ledger.Addresses()Ledger.PubKeys() - returns []*secp256k1.PublicKey

Ledger Keychain Changes:

  • Stores public keys internally instead of addresses
  • Derives both Avalanche and Ethereum addresses from public keys
  • Added EthAddresses() and GetEth() methods for EthKeychain implementation

Implementation:

  • The ledger now queries the hardware device for public keys without requiring to provide HRP or display
  • Public keys are cached with their ledger indices
  • Addresses are derived on-demand using pubKey.Address() and pubKey.EthAddress()
  • Both address types share the same derivation path from the ledger

How this was tested

  • unit tests
  • ledger operations on CLI to deploy a L1 locally

Need to be documented in RELEASES.md?

Change ledger interface to return public keys instead of addresses,
enabling derivation of both Avalanche and Ethereum addresses from
the same key.
@Copilot Copilot AI review requested due to automatic review settings October 1, 2025 16:07
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 ledger interface to return public keys instead of addresses, decoupling the ledger abstraction from specific address formats. This enables support for both Avalanche and Ethereum address formats from the same ledger key and allows the ledger to implement the EthKeychain interface for C-chain transaction signing.

  • Replaced Address() and Addresses() methods with PubKey() and PubKeys() in the ledger interface
  • Updated ledger keychain to store public keys internally and derive addresses on-demand
  • Added Ethereum address support with new EthAddresses() and GetEth() methods

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
utils/crypto/ledger/ledger.go Updated core ledger implementation to return public keys instead of addresses
utils/crypto/keychain/ledger.go Modified ledger interface definition to use public key methods
utils/crypto/keychain/keychain.go Refactored keychain to support dual address formats and store key information
utils/crypto/keychain/keychainmock/ledger.go Updated mock implementation to match new interface
utils/crypto/ledger/ledger_test.go Updated tests to use new public key methods
utils/crypto/keychain/keychain_test.go Updated tests to work with public keys and derive addresses

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

felipemadero and others added 2 commits October 1, 2025 13:15
The condition i > math.MaxUint32 in the loop was unreachable since i is
a slice index. Moved the validation to check numToDerive parameter before
creating the slice, which is more appropriate and catches invalid input early.
addrs set.Set[ids.ShortID]
addrToIdx map[ids.ShortID]uint32
ledger Ledger
avaAddrToKeyInfo map[ids.ShortID]*keyInfo // Maps Avalanche addresses to key info
Copy link
Contributor

Choose a reason for hiding this comment

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

why not set.Set[keyInfo] ?

ledger Ledger
idx uint32
addr ids.ShortID
pubKey *secp256k1.PublicKey
Copy link
Contributor

Choose a reason for hiding this comment

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

why a pointer vs a non pointer?

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.

2 participants