-
Notifications
You must be signed in to change notification settings - Fork 795
feat(signers): Allow parsing of private key that has 0x
prefix
#2037
Conversation
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.
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()); |
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.
this looks like a separate change that bumps base64
mind submitting this separately?
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.
see #2032
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() | ||
} | ||
} |
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.
there's no transient impl when there's FromStr
?
I guess we can add these
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.
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>
.
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