Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

feat(signers): Allow parsing of private key that has 0x prefix #2037

Merged
merged 1 commit into from
Jan 12, 2023

Conversation

oblique
Copy link
Contributor

@oblique oblique commented Jan 10, 2023

Motivation

I wanted to be able to use private keys that have 0x prefix, without stripping it manually.

Solution

Remove prefix in Wallet<SigningKey>::from_str.

PR Checklist

  • Added Tests
  • Added Documentation
  • Updated the changelog
  • Breaking changes

Copy link
Collaborator

@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

@@ -191,7 +192,7 @@ pub enum Authorization {

impl Authorization {
pub fn basic(username: impl Into<String>, password: impl Into<String>) -> Self {
let auth_secret = base64::encode(username.into() + ":" + &password.into());
let auth_secret = BASE64_STANDARD.encode(username.into() + ":" + &password.into());
Copy link
Collaborator

Choose a reason for hiding this comment

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

this looks like a separate change that bumps base64

mind submitting this separately?

Copy link
Collaborator

Choose a reason for hiding this comment

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

see #2032

Comment on lines +140 to +154
impl TryFrom<&str> for Wallet<SigningKey> {
type Error = WalletError;

fn try_from(value: &str) -> Result<Self, Self::Error> {
value.parse()
}
}

impl TryFrom<String> for Wallet<SigningKey> {
type Error = WalletError;

fn try_from(value: String) -> Result<Self, Self::Error> {
value.parse()
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

there's no transient impl when there's FromStr?

I guess we can add these

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason I added this is to enable user to have something like this:

fn create_client(url: &str, priv_key: impl TryInto<LocalWallet>) -> SignerMiddleware<Provider<Http>, LocalWallet>> {
    let wallet = priv_key.try_into().unwrap();
    // ...
}

And be able to pass as argument &str, String, SigningKey, and SecretKey<Secp256k1>.

@gakonst gakonst merged commit 0a7e742 into gakonst:master Jan 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants