mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-17 18:21:02 +00:00
sc-keystore: Improve weird error message (#10584)
The keystore would print "Invalid password" when a key was stored using an incorrect public key. This pr improves the error message to communicate better to the user on what is wrong.
This commit is contained in:
@@ -35,8 +35,11 @@ pub enum Error {
|
|||||||
/// JSON error.
|
/// JSON error.
|
||||||
Json(serde_json::Error),
|
Json(serde_json::Error),
|
||||||
/// Invalid password.
|
/// Invalid password.
|
||||||
#[display(fmt = "Invalid password")]
|
#[display(
|
||||||
InvalidPassword,
|
fmt = "Requested public key and public key of the loaded private key do not match. \n
|
||||||
|
This means either that the keystore password is incorrect or that the private key was stored under a wrong public key."
|
||||||
|
)]
|
||||||
|
PublicKeyMismatch,
|
||||||
/// Invalid BIP39 phrase
|
/// Invalid BIP39 phrase
|
||||||
#[display(fmt = "Invalid recovery phrase (BIP39) data")]
|
#[display(fmt = "Invalid recovery phrase (BIP39) data")]
|
||||||
InvalidPhrase,
|
InvalidPhrase,
|
||||||
@@ -58,7 +61,7 @@ impl From<Error> for TraitError {
|
|||||||
fn from(error: Error) -> Self {
|
fn from(error: Error) -> Self {
|
||||||
match error {
|
match error {
|
||||||
Error::KeyNotSupported(id) => TraitError::KeyNotSupported(id),
|
Error::KeyNotSupported(id) => TraitError::KeyNotSupported(id),
|
||||||
Error::InvalidSeed | Error::InvalidPhrase | Error::InvalidPassword =>
|
Error::InvalidSeed | Error::InvalidPhrase | Error::PublicKeyMismatch =>
|
||||||
TraitError::ValidationError(error.to_string()),
|
TraitError::ValidationError(error.to_string()),
|
||||||
Error::Unavailable => TraitError::Unavailable,
|
Error::Unavailable => TraitError::Unavailable,
|
||||||
Error::Io(e) => TraitError::Other(e.to_string()),
|
Error::Io(e) => TraitError::Other(e.to_string()),
|
||||||
|
|||||||
@@ -503,7 +503,7 @@ impl KeystoreInner {
|
|||||||
if &pair.public() == public {
|
if &pair.public() == public {
|
||||||
Ok(Some(pair))
|
Ok(Some(pair))
|
||||||
} else {
|
} else {
|
||||||
Err(Error::InvalidPassword)
|
Err(Error::PublicKeyMismatch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user