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#[cfg(feature = "turnkey")]
14use alloy_signer_turnkey::TurnkeySignerError;
15
16use crate::wallet_browser::error::BrowserWalletError;
17
18#[derive(Debug, thiserror::Error)]
19pub enum PrivateKeyError {
20    #[error("Failed to create wallet from private key. Private key is invalid hex: {0}")]
21    InvalidHex(#[from] FromHexError),
22    #[error(
23        "Failed to create wallet from private key. Invalid private key. But env var {0} exists. Is the `$` anchor missing?"
24    )]
25    ExistsAsEnvVar(String),
26}
27
28#[derive(Debug, thiserror::Error)]
29pub enum WalletSignerError {
30    #[error(transparent)]
31    Local(#[from] LocalSignerError),
32    #[error("Failed to decrypt keystore: incorrect password")]
33    IncorrectKeystorePassword,
34    #[error(transparent)]
35    Ledger(#[from] LedgerError),
36    #[error(transparent)]
37    Trezor(#[from] TrezorError),
38    #[error(transparent)]
39    #[cfg(feature = "aws-kms")]
40    Aws(#[from] Box<AwsSignerError>),
41    #[error(transparent)]
42    #[cfg(feature = "gcp-kms")]
43    Gcp(#[from] Box<GcpSignerError>),
44    #[error(transparent)]
45    #[cfg(feature = "turnkey")]
46    Turnkey(#[from] TurnkeySignerError),
47    #[error(transparent)]
48    Browser(#[from] BrowserWalletError),
49    #[error(transparent)]
50    Io(#[from] std::io::Error),
51    #[error(transparent)]
52    InvalidHex(#[from] FromHexError),
53    #[error(transparent)]
54    Ecdsa(#[from] ecdsa::Error),
55    #[error("foundry was not built with support for {0} signer")]
56    UnsupportedSigner(&'static str),
57}
58
59impl WalletSignerError {
60    pub fn aws_unsupported() -> Self {
61        Self::UnsupportedSigner("AWS KMS")
62    }
63
64    pub fn gcp_unsupported() -> Self {
65        Self::UnsupportedSigner("Google Cloud KMS")
66    }
67
68    pub fn turnkey_unsupported() -> Self {
69        Self::UnsupportedSigner("Turnkey")
70    }
71
72    pub fn browser_unsupported() -> Self {
73        Self::UnsupportedSigner("Browser Wallet")
74    }
75}