Skip to main content

smplx_sdk_test/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    /// Error indicating that a Simplicity program failed to satisfy, prune or execute.
12    #[error(
13        "Covenant input {index} did not execute (transaction locktime {locktime}, input sequence {sequence}): {source}"
14    )]
15    CovenantExecution {
16        /// The index of the input whose program failed.
17        index: usize,
18        /// The locktime the transaction being satisfied carries.
19        locktime: u32,
20        /// The sequence of the failing input.
21        sequence: u32,
22        /// The underlying program failure.
23        source: ProgramError,
24    },
25
26    /// Errors originating from provider network interactions.
27    #[error(transparent)]
28    Provider(#[from] ProviderError),
29
30    /// Error indicating a provider-backed operation was requested on a signer built without one.
31    #[cfg(feature = "provider")]
32    #[error("This signer was constructed without a provider")]
33    ProviderUnavailable,
34
35    /// Errors encountered when attempting to inject or wrap witness fields.
36    #[error(transparent)]
37    WtnsInjectError(#[from] WtnsWrappingError),
38
39    /// Error indicating an incorrectly formatted mnemonic phrase.
40    #[error("Failed to parse a mnemonic: {0}")]
41    Mnemonic(String),
42
43    /// Error thrown when PSET transaction extraction fails.
44    #[error("Failed to extract tx from pst: {0}")]
45    TxExtraction(#[from] simplicityhl::elements::pset::Error),
46
47    /// Error indicating failure to unblind a confidential transaction output.
48    #[error("Failed to unblind txout: {0}")]
49    Unblind(#[from] simplicityhl::elements::UnblindError),
50
51    /// Error thrown when PSET blinding fails.
52    #[error("Failed to blind a PST: {0}")]
53    PsetBlind(#[from] simplicityhl::elements::pset::PsetBlindError),
54
55    /// Error indicating failure to construct sighash for input spending.
56    #[error("Failed to construct a message for the input spending: {0}")]
57    SighashConstruction(#[from] elements_miniscript::psbt::SighashError),
58
59    /// Error indicating the transaction is not balanced.
60    #[error("Transaction is not balanced or malformed")]
61    Unbalanced(),
62
63    /// Error indicating the transaction inputs cover an amount that is lower than the dust limit.
64    #[error("Fee amount is too low: {0}")]
65    DustAmount(i64),
66
67    /// Error indicating the defined fee amount cannot cover the calculated transaction costs.
68    #[error("Not enough fee amount {0} to cover transaction costs: {1}")]
69    NotEnoughFeeAmount(i64, u64),
70
71    /// Error indicating that the available UTXO funds are not enough to cover total costs.
72    #[error("Not enough funds on account to cover transaction costs: {0}")]
73    NotEnoughFunds(u64),
74
75    /// Error indicating a confidential input was left with no blinded output to balance against.
76    ///
77    /// Raised when the caller pins an explicit change target while spending confidential inputs,
78    /// which the node would reject as `bad-txns-in-ne-out`.
79    #[error("A confidential input needs at least one blinded output, but the change target is explicit")]
80    ConfidentialInputWithoutBlindedOutput,
81
82    /// Error indicating an invalid upstream `secp256k1` secret key.
83    #[error("Invalid secret key")]
84    InvalidSecretKey(#[from] simplicityhl::elements::secp256k1_zkp::UpstreamError),
85
86    /// Error thrown when HD wallet private key derivation fails.
87    #[error("Failed to derive a private key: {0}")]
88    PrivateKeyDerivation(#[from] elements_miniscript::bitcoin::bip32::Error),
89
90    /// Error thrown when constructing a derivation path string fails.
91    #[error("Failed to construct a derivation path: {0}")]
92    DerivationPath(String),
93
94    /// Error indicating failure to construct a valid WPKH (Witness Public Key Hash) descriptor.
95    #[error("Failed to construct a wpkh descriptor: {0}")]
96    WpkhDescriptor(String),
97
98    /// Error indicating failure to construct a valid SLIP77 blinding key descriptor.
99    #[error("Failed to construct a slip77 descriptor: {0}")]
100    Slip77Descriptor(String),
101
102    /// Error thrown if there's a problem during descriptor conversion.
103    #[error("Failed to convert a descriptor: {0}")]
104    DescriptorConversion(#[from] elements_miniscript::descriptor::ConversionError),
105
106    /// Error thrown when WPKH address creation fails.
107    #[error("Failed to construct a wpkh address: {0}")]
108    WpkhAddressConstruction(#[from] elements_miniscript::Error),
109
110    /// Error indicating an expected witness field could not be found.
111    #[error("Missing such witness field: {0}")]
112    WtnsFieldNotFound(String),
113}
114
115/// Errors originating from manipulating witness paths and injecting values.
116#[derive(Debug, thiserror::Error)]
117pub enum WtnsWrappingError {
118    /// Error indicating a failure while parsing the provided witness path string.
119    #[error("Failed to parse path")]
120    ParsingError,
121
122    /// Error pointing to the use of a path type that is currently not supported.
123    #[error("Unsupported path type: {0}")]
124    UnsupportedPathType(String),
125
126    /// Error thrown during path traversal when an index exceeds the inner array lengths.
127    #[error("Path index out of bounds: len is {0}, got {1}")]
128    IdxOutOfBounds(usize, usize),
129
130    /// Error indicating that the runtime type at the path root expected one type but encountered another.
131    #[error("Root type mismatch: expected {0}, got {1}")]
132    RootTypeMismatch(String, String),
133
134    /// Error indicating that a path traversal attempted to reach an undefined or mismatched Either branch.
135    #[error("Path reached undefined branch of Either")]
136    EitherBranchMismatch,
137}