Skip to content

feat(LocalSigner): add public_key method to LocalSigner #2572

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mablr
Copy link

@mablr mablr commented Jun 10, 2025

Motivation

Resolve #2555, by implementing a helper providing a straightforward way to display the public key. See foundry-rs/foundry#10600.

Solution

  • Implemented a public_key() method in LocalSigner that returns the signer's public key as a hex string prefixed with "0x".
  • Added a unit test to verify the functionality of the public_key() method.

This method is specifically implemented for LocalSigner<SigningKey> and leverages its verifying_key method to directly obtain the pubkey without the risk of triggering an error. This contrasts with foundry's "cast wallet pubkey" command implementation, which instantiates a k256::SecretKey.
https://github.com/foundry-rs/foundry/blob/365cbb43b67707fdbe594ae212bd7b718079b70f/crates/cast/src/cmd/wallet/mod.rs#L426-L440

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

* Implemented a public_key() method in LocalSigner that returns the signer's public key as a hex string prefixed with "0x".
* Added a unit test to verify the functionality of the public_key() method.

This helper improves the usability of the LocalSigner by providing a straightforward way to display the public key.
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

smol nit

@github-project-automation github-project-automation bot moved this to In Progress in Alloy Jun 10, 2025
@github-project-automation github-project-automation bot moved this from In Progress to Reviewed in Alloy Jun 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Reviewed
Development

Successfully merging this pull request may close these issues.

[Feature] Add helper fn to obtain publickey from LocalSigner
2 participants