-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Snafu error types and proper Rust typed functions (#21)
- Loading branch information
Showing
10 changed files
with
428 additions
and
265 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,63 @@ | ||
#[derive(Debug, PartialEq, Eq)] | ||
pub enum Bip322Error { | ||
InvalidAddress, // for legacy addresses 1... (p2pkh) not supported, also any non taproot | ||
Invalid, // Address no key; pubkey not recovered, invalid signature | ||
MalformedSignature, // wrong length, etc. | ||
InvalidSigHash, // only sighash All and Default supported | ||
NotKeyPathSpend, // only single key path spend supported | ||
use super::*; | ||
|
||
#[derive(Debug, Snafu)] | ||
#[snafu(context(suffix(false)), visibility(pub))] | ||
pub enum Error { | ||
#[snafu(display("Failed to parse address `{address}`"))] | ||
AddressParse { | ||
source: bitcoin::address::ParseError, | ||
address: String, | ||
}, | ||
#[snafu(display("Failed to parse private key"))] | ||
PrivateKeyParse { source: bitcoin::key::Error }, | ||
#[snafu(display("Unsuported address `{address}`, only P2TR allowed"))] | ||
UnsupportedAddress { address: String }, | ||
#[snafu(display("Decode error for signature `{signature}`"))] | ||
SignatureDecode { | ||
source: base64::DecodeError, | ||
signature: String, | ||
}, | ||
#[snafu(display("Transaction encode error"))] | ||
TransactionEncode { source: std::io::Error }, | ||
#[snafu(display("Transaction extract error"))] | ||
TransactionExtract { | ||
source: bitcoin::psbt::ExtractTxError, | ||
}, | ||
#[snafu(display("To sign transaction invalid"))] | ||
ToSignInvalid, | ||
#[snafu(display("PSBT extract error"))] | ||
PsbtExtract { source: bitcoin::psbt::Error }, | ||
#[snafu(display("Base64 decode error for transaction `{transaction}`"))] | ||
TransactionBase64Decode { | ||
source: base64::DecodeError, | ||
transaction: String, | ||
}, | ||
#[snafu(display("Consensus decode error for transaction `{transaction}`"))] | ||
TransactionConsensusDecode { | ||
source: bitcoin::consensus::encode::Error, | ||
transaction: String, | ||
}, | ||
#[snafu(display("Witness malformed"))] | ||
WitnessMalformed { | ||
source: bitcoin::consensus::encode::Error, | ||
}, | ||
#[snafu(display("Witness empty"))] | ||
WitnessEmpty, | ||
#[snafu(display("Encode witness error"))] | ||
WitnessEncoding { source: std::io::Error }, | ||
#[snafu(display("Signature of wrong length `{length}`"))] | ||
SignatureLength { | ||
length: usize, | ||
encoded_signature: Vec<u8>, | ||
}, | ||
#[snafu(display("Invalid signature"))] | ||
SignatureInvalid { source: bitcoin::secp256k1::Error }, | ||
#[snafu(display("Invalid sighash"))] | ||
SigHashTypeInvalid { | ||
source: bitcoin::sighash::InvalidSighashTypeError, | ||
}, | ||
#[snafu(display("Unsupported sighash type `{sighash_type}`"))] | ||
SigHashTypeUnsupported { sighash_type: String }, | ||
#[snafu(display("Not key path spend"))] | ||
NotKeyPathSpend, | ||
} |
Oops, something went wrong.