soil_client/keystore/
mod.rs1#![warn(missing_docs)]
10use std::io;
11use subsoil::core::crypto::KeyTypeId;
12use subsoil::keystore::Error as TraitError;
13
14mod local;
16pub use local::LocalKeystore;
17pub use subsoil::keystore::Keystore;
18
19#[derive(Debug, thiserror::Error)]
21pub enum Error {
22 #[error(transparent)]
24 Io(#[from] io::Error),
25 #[error(transparent)]
27 Json(#[from] serde_json::Error),
28 #[error(
30 "Requested public key and public key of the loaded private key do not match. \n
31 This means either that the keystore password is incorrect or that the private key was stored under a wrong public key."
32 )]
33 PublicKeyMismatch,
34 #[error("Invalid recovery phrase (BIP39) data")]
36 InvalidPhrase,
37 #[error("Invalid seed")]
39 InvalidSeed,
40 #[error("Key crypto type is not supported")]
42 KeyNotSupported(KeyTypeId),
43 #[error("Keystore unavailable")]
45 Unavailable,
46}
47
48pub type Result<T> = std::result::Result<T, Error>;
50
51impl From<Error> for TraitError {
52 fn from(error: Error) -> Self {
53 match error {
54 Error::KeyNotSupported(id) => TraitError::KeyNotSupported(id),
55 Error::InvalidSeed | Error::InvalidPhrase | Error::PublicKeyMismatch => {
56 TraitError::ValidationError(error.to_string())
57 },
58 Error::Unavailable => TraitError::Unavailable,
59 Error::Io(e) => TraitError::Other(e.to_string()),
60 Error::Json(e) => TraitError::Other(e.to_string()),
61 }
62 }
63}