foundry_wallets/
error.rs

1use alloy_primitives::hex::FromHexError;
2use alloy_signer::k256::ecdsa;
3use alloy_signer_ledger::LedgerError;
4use alloy_signer_local::LocalSignerError;
5use alloy_signer_trezor::TrezorError;
6
7#[cfg(feature = "aws-kms")]
8use alloy_signer_aws::AwsSignerError;
9
10#[cfg(feature = "gcp-kms")]
11use alloy_signer_gcp::GcpSignerError;
12
13#[derive(Debug, thiserror::Error)]
14pub enum PrivateKeyError {
15    #[error("Failed to create wallet from private key. Private key is invalid hex: {0}")]
16    InvalidHex(#[from] FromHexError),
17    #[error("Failed to create wallet from private key. Invalid private key. But env var {0} exists. Is the `$` anchor missing?")]
18    ExistsAsEnvVar(String),
19}
20
21#[derive(Debug, thiserror::Error)]
22pub enum WalletSignerError {
23    #[error(transparent)]
24    Local(#[from] LocalSignerError),
25    #[error("Failed to decrypt keystore: incorrect password")]
26    IncorrectKeystorePassword,
27    #[error(transparent)]
28    Ledger(#[from] LedgerError),
29    #[error(transparent)]
30    Trezor(#[from] TrezorError),
31    #[error(transparent)]
32    #[cfg(feature = "aws-kms")]
33    Aws(#[from] AwsSignerError),
34    #[error(transparent)]
35    #[cfg(feature = "gcp-kms")]
36    Gcp(#[from] GcpSignerError),
37    #[error(transparent)]
38    Io(#[from] std::io::Error),
39    #[error(transparent)]
40    InvalidHex(#[from] FromHexError),
41    #[error(transparent)]
42    Ecdsa(#[from] ecdsa::Error),
43    #[error("foundry was not built with support for {0} signer")]
44    UnsupportedSigner(&'static str),
45}
46
47impl WalletSignerError {
48    pub fn aws_unsupported() -> Self {
49        Self::UnsupportedSigner("AWS KMS")
50    }
51
52    pub fn gcp_unsupported() -> Self {
53        Self::UnsupportedSigner("Google Cloud KMS")
54    }
55}