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

KeyfileAccount should have a publicKey method #1701

Closed
Aviksaikat opened this issue Oct 16, 2023 · 4 comments · Fixed by #1702
Closed

KeyfileAccount should have a publicKey method #1701

Aviksaikat opened this issue Oct 16, 2023 · 4 comments · Fixed by #1702
Labels
category: feature New feature or request

Comments

@Aviksaikat
Copy link
Contributor

Aviksaikat commented Oct 16, 2023

Overview

  • It will be nice to have a account.public_key method to the KeyfileAccount or AccountAPI object.

Specification

  • I have something in my mind. If I can get a green signal then I will dive right in.

Approach

  • Using the keyfile property of the KeyfileAccount object I would like to implement this feature.
  • Something like this
self.wallet = self.keyfile
passphrase = self._prompt_for_passphrase(default="")
# Decrypt the private key
self.private_key = Account.decrypt(self.wallet, passphrase)

# Derive the public key from the private key
self.pk = keys.PrivateKey(private_key)
self.public_key = self.pk.public_key

Dependencies

  • eth_account
  • eth_keys
    I believe both of them are already in use.
@Aviksaikat Aviksaikat added the category: feature New feature or request label Oct 16, 2023
@Aviksaikat Aviksaikat changed the title KeyfileAccount should have a publickKey method KeyfileAccount should have a publicKey method Oct 16, 2023
@fubuloubu
Copy link
Member

fubuloubu commented Oct 18, 2023

Yeah, this seems fine. Implementation suggestion would be to add this property to KeyfileAccount:

class KeyfileAccount(AccountAPI):
    ...

    @property  # NOTE: consider `cached_property`
    def public_key(self) -> HexBytes:
        ... # logic you outlined above

@antazoey
Copy link
Member

I am just perplexed that we have to decrypt an account's private key in order to obtain the public key... that just seems backwards?

@fubuloubu
Copy link
Member

I am just perplexed that we have to decrypt an account's private key in order to obtain the public key... that just seems backwards?

Not really, and address is a keccak hash so it is not able to be obtained like this, so you need to to run the key derivation to get the public key again

But yes, you can obtain the public key during the address derivation process

@Aviksaikat
Copy link
Contributor Author

I have made some changes to cache the public key in the keyfile please review this pr #1702

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants