Skip to main content

smplx_sdk/signer/
error.rs

1use crate::program::ProgramError;
2use crate::provider::ProviderError;
3
4/// Core error types for the Signer component.
5#[derive(Debug, thiserror::Error)]
6pub enum SignerError {
7    /// Errors originating from Simplicity program evaluation and state.
8    #[error(transparent)]
9    Program(#[from] ProgramError),
10
11    /// Errors originating from provider network interactions.
12    #[error(transparent)]
13    Provider(#[from] ProviderError),
14
15    /// Errors encountered when attempting to inject or wrap witness fields.
16    #[error(transparent)]
17    WtnsInjectError(#[from] WtnsWrappingError),
18
19    /// Error indicating an incorrectly formatted mnemonic phrase.
20    #[error("Failed to parse a mnemonic: {0}")]
21    Mnemonic(String),
22
23    /// Error thrown when PSET transaction extraction fails.
24    #[error("Failed to extract tx from pst: {0}")]
25    TxExtraction(#[from] simplicityhl::elements::pset::Error),
26
27    /// Error indicating failure to unblind a confidential transaction output.
28    #[error("Failed to unblind txout: {0}")]
29    Unblind(#[from] simplicityhl::elements::UnblindError),
30
31    /// Error thrown when PSET blinding fails.
32    #[error("Failed to blind a PST: {0}")]
33    PsetBlind(#[from] simplicityhl::elements::pset::PsetBlindError),
34
35    /// Error indicating failure to construct sighash for input spending.
36    #[error("Failed to construct a message for the input spending: {0}")]
37    SighashConstruction(#[from] elements_miniscript::psbt::SighashError),
38
39    /// Error indicating the transaction inputs cover an amount that is lower than the dust limit.
40    #[error("Fee amount is too low: {0}")]
41    DustAmount(i64),
42
43    /// Error indicating the defined fee amount cannot cover the calculated transaction costs.
44    #[error("Not enough fee amount {0} to cover transaction costs: {1}")]
45    NotEnoughFeeAmount(i64, u64),
46
47    /// Error indicating that the available UTXO funds are not enough to cover total costs.
48    #[error("Not enough funds on account to cover transaction costs: {0}")]
49    NotEnoughFunds(u64),
50
51    /// Error indicating an invalid upstream `secp256k1` secret key.
52    #[error("Invalid secret key")]
53    InvalidSecretKey(#[from] simplicityhl::elements::secp256k1_zkp::UpstreamError),
54
55    /// Error thrown when HD wallet private key derivation fails.
56    #[error("Failed to derive a private key: {0}")]
57    PrivateKeyDerivation(#[from] elements_miniscript::bitcoin::bip32::Error),
58
59    /// Error thrown when constructing a derivation path string fails.
60    #[error("Failed to construct a derivation path: {0}")]
61    DerivationPath(String),
62
63    /// Error indicating failure to construct a valid WPKH (Witness Public Key Hash) descriptor.
64    #[error("Failed to construct a wpkh descriptor: {0}")]
65    WpkhDescriptor(String),
66
67    /// Error indicating failure to construct a valid SLIP77 blinding key descriptor.
68    #[error("Failed to construct a slip77 descriptor: {0}")]
69    Slip77Descriptor(String),
70
71    /// Error thrown if there's a problem during descriptor conversion.
72    #[error("Failed to convert a descriptor: {0}")]
73    DescriptorConversion(#[from] elements_miniscript::descriptor::ConversionError),
74
75    /// Error thrown when WPKH address creation fails.
76    #[error("Failed to construct a wpkh address: {0}")]
77    WpkhAddressConstruction(#[from] elements_miniscript::Error),
78
79    /// Error indicating an expected witness field could not be found.
80    #[error("Missing such witness field: {0}")]
81    WtnsFieldNotFound(String),
82}
83
84/// Errors originating from manipulating witness paths and injecting values.
85#[derive(Debug, thiserror::Error)]
86pub enum WtnsWrappingError {
87    /// Error indicating a failure while parsing the provided witness path string.
88    #[error("Failed to parse path")]
89    ParsingError,
90
91    /// Error pointing to the use of a path type that is currently not supported.
92    #[error("Unsupported path type: {0}")]
93    UnsupportedPathType(String),
94
95    /// Error thrown during path traversal when an index exceeds the inner array lengths.
96    #[error("Path index out of bounds: len is {0}, got {1}")]
97    IdxOutOfBounds(usize, usize),
98
99    /// Error indicating that the runtime type at the path root expected one type but encountered another.
100    #[error("Root type mismatch: expected {0}, got {1}")]
101    RootTypeMismatch(String, String),
102
103    /// Error indicating that a path traversal attempted to reach an undefined or mismatched Either branch.
104    #[error("Path reached undefined branch of Either")]
105    EitherBranchMismatch,
106}