1use thiserror::Error as ThisError;
23
24#[derive(ThisError, Debug)]
26pub enum Error {
27 #[error("{0} Key format is not supported")]
28 InvalidKeyFormat(String),
29}
30
31#[derive(ThisError, Debug)]
33pub enum DecodingError {
34 #[error("Failed to decode, invalid length: {0}")]
35 InvalidLength(#[from] std::array::TryFromSliceError),
36 #[error("Failed to decode with ed25519: {0}")]
37 Ed25519(
38 #[from]
39 #[source]
40 ed25519_dalek::ed25519::Error,
41 ),
42 #[error("Failed to decode with RSA")]
43 Rsa,
44 #[error("Failed to decode with secp256k1")]
45 Secp256k1,
46 #[error("RSA keypair decoding is not supported yet")]
47 KeypairDecodingIsNotSupported,
48 #[error("Invalid type prefix")]
49 InvalidTypeByte,
50 #[error("Cannot decode public key from base58 :{0}")]
51 Base58DecodeError(#[source] bs58::decode::Error),
52 #[error("Raw signature decoding failed: type {0} not supported")]
53 RawSignatureUnsupportedType(String),
54 #[error("public key is not inlined in peer id: {0}")]
55 PublicKeyNotInlined(String),
56}
57
58#[derive(ThisError, Debug)]
60pub enum SigningError {
61 #[error("Failed to sign with ed25519: {0}")]
62 Ed25519(
63 #[from]
64 #[source]
65 ed25519_dalek::ed25519::Error,
66 ),
67 #[error("Failed to sign with RSA")]
68 Rsa,
69 #[error("Failed to sign with secp256k1: {0}")]
70 Secp256k1(
71 #[from]
72 #[source]
73 libsecp256k1::Error,
74 ),
75}
76
77#[derive(ThisError, Debug)]
79pub enum VerificationError {
80 #[error("Failed to verify signature {1} with {2} ed25519 public key: {0}")]
81 Ed25519(#[source] ed25519_dalek::ed25519::Error, String, String),
82
83 #[cfg(not(target_arch = "wasm32"))]
84 #[error("Failed to verify signature {1} with {2} RSA public key: {0}")]
85 Rsa(#[source] ring::error::Unspecified, String, String),
86
87 #[error("Failed to verify signature {1} with {2} secp256k1 public key: {0}")]
88 Secp256k1(#[source] libsecp256k1::Error, String, String),
89}