-
Notifications
You must be signed in to change notification settings - Fork 807
refactor: ledger interface to use public keys instead of addresses #4377
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
base: master
Are you sure you want to change the base?
Conversation
Change ledger interface to return public keys instead of addresses, enabling derivation of both Avalanche and Ethereum addresses from the same key.
There was a problem hiding this 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()
andAddresses()
methods withPubKey()
andPubKeys()
in the ledger interface - Updated ledger keychain to store public keys internally and derive addresses on-demand
- Added Ethereum address support with new
EthAddresses()
andGetEth()
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.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
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:EthKeychain
interface, enabling ledger to be used to fully sign C-chain transactions on walletHow this works
Ledger Interface Changes:
Ledger.Address()
→Ledger.PubKey()
- returns*secp256k1.PublicKey
Ledger.Addresses()
→Ledger.PubKeys()
- returns[]*secp256k1.PublicKey
Ledger Keychain Changes:
EthAddresses()
andGetEth()
methods for EthKeychain implementationImplementation:
pubKey.Address()
andpubKey.EthAddress()
How this was tested
Need to be documented in RELEASES.md?