|
1 |
| -#[derive(Debug, PartialEq, Eq)] |
2 |
| -pub enum Bip322Error { |
3 |
| - InvalidAddress, // for legacy addresses 1... (p2pkh) not supported, also any non taproot |
4 |
| - Invalid, // Address no key; pubkey not recovered, invalid signature |
5 |
| - MalformedSignature, // wrong length, etc. |
6 |
| - InvalidSigHash, // only sighash All and Default supported |
7 |
| - NotKeyPathSpend, // only single key path spend supported |
| 1 | +use super::*; |
| 2 | + |
| 3 | +#[derive(Debug, Snafu)] |
| 4 | +#[snafu(context(suffix(false)), visibility(pub))] |
| 5 | +pub enum Error { |
| 6 | + #[snafu(display("Failed to parse address `{address}`"))] |
| 7 | + AddressParse { |
| 8 | + source: bitcoin::address::ParseError, |
| 9 | + address: String, |
| 10 | + }, |
| 11 | + #[snafu(display("Failed to parse private key"))] |
| 12 | + PrivateKeyParse { source: bitcoin::key::Error }, |
| 13 | + #[snafu(display("Unsuported address `{address}`, only P2TR allowed"))] |
| 14 | + UnsupportedAddress { address: String }, |
| 15 | + #[snafu(display("Decode error for signature `{signature}`"))] |
| 16 | + SignatureDecode { |
| 17 | + source: base64::DecodeError, |
| 18 | + signature: String, |
| 19 | + }, |
| 20 | + #[snafu(display("Transaction encode error"))] |
| 21 | + TransactionEncode { source: std::io::Error }, |
| 22 | + #[snafu(display("Transaction extract error"))] |
| 23 | + TransactionExtract { |
| 24 | + source: bitcoin::psbt::ExtractTxError, |
| 25 | + }, |
| 26 | + #[snafu(display("To sign transaction invalid"))] |
| 27 | + ToSignInvalid, |
| 28 | + #[snafu(display("PSBT extract error"))] |
| 29 | + PsbtExtract { source: bitcoin::psbt::Error }, |
| 30 | + #[snafu(display("Base64 decode error for transaction `{transaction}`"))] |
| 31 | + TransactionBase64Decode { |
| 32 | + source: base64::DecodeError, |
| 33 | + transaction: String, |
| 34 | + }, |
| 35 | + #[snafu(display("Consensus decode error for transaction `{transaction}`"))] |
| 36 | + TransactionConsensusDecode { |
| 37 | + source: bitcoin::consensus::encode::Error, |
| 38 | + transaction: String, |
| 39 | + }, |
| 40 | + #[snafu(display("Witness malformed"))] |
| 41 | + WitnessMalformed { |
| 42 | + source: bitcoin::consensus::encode::Error, |
| 43 | + }, |
| 44 | + #[snafu(display("Witness empty"))] |
| 45 | + WitnessEmpty, |
| 46 | + #[snafu(display("Encode witness error"))] |
| 47 | + WitnessEncoding { source: std::io::Error }, |
| 48 | + #[snafu(display("Signature of wrong length `{length}`"))] |
| 49 | + SignatureLength { |
| 50 | + length: usize, |
| 51 | + encoded_signature: Vec<u8>, |
| 52 | + }, |
| 53 | + #[snafu(display("Invalid signature"))] |
| 54 | + SignatureInvalid { source: bitcoin::secp256k1::Error }, |
| 55 | + #[snafu(display("Invalid sighash"))] |
| 56 | + SigHashTypeInvalid { |
| 57 | + source: bitcoin::sighash::InvalidSighashTypeError, |
| 58 | + }, |
| 59 | + #[snafu(display("Unsupported sighash type `{sighash_type}`"))] |
| 60 | + SigHashTypeUnsupported { sighash_type: String }, |
| 61 | + #[snafu(display("Not key path spend"))] |
| 62 | + NotKeyPathSpend, |
8 | 63 | }
|
0 commit comments