1#![warn(missing_docs)]
22use sp_core::crypto::KeyTypeId;
23use sp_keystore::Error as TraitError;
24use std::io;
25
26mod local;
28pub use local::LocalKeystore;
29pub use sp_keystore::Keystore;
30
31#[derive(Debug, thiserror::Error)]
33pub enum Error {
34 #[error(transparent)]
36 Io(#[from] io::Error),
37 #[error(transparent)]
39 Json(#[from] serde_json::Error),
40 #[error(
42 "Requested public key and public key of the loaded private key do not match. \n
43 This means either that the keystore password is incorrect or that the private key was stored under a wrong public key."
44 )]
45 PublicKeyMismatch,
46 #[error("Invalid recovery phrase (BIP39) data")]
48 InvalidPhrase,
49 #[error("Invalid seed")]
51 InvalidSeed,
52 #[error("Key crypto type is not supported")]
54 KeyNotSupported(KeyTypeId),
55 #[error("Keystore unavailable")]
57 Unavailable,
58}
59
60pub type Result<T> = std::result::Result<T, Error>;
62
63impl From<Error> for TraitError {
64 fn from(error: Error) -> Self {
65 match error {
66 Error::KeyNotSupported(id) => TraitError::KeyNotSupported(id),
67 Error::InvalidSeed | Error::InvalidPhrase | Error::PublicKeyMismatch =>
68 TraitError::ValidationError(error.to_string()),
69 Error::Unavailable => TraitError::Unavailable,
70 Error::Io(e) => TraitError::Other(e.to_string()),
71 Error::Json(e) => TraitError::Other(e.to_string()),
72 }
73 }
74}