|
@@ -209,6 +209,9 @@ pub enum Error {
|
|
|
/// P2PK spending conditions not met
|
|
/// P2PK spending conditions not met
|
|
|
#[error("P2PK condition not met `{0}`")]
|
|
#[error("P2PK condition not met `{0}`")]
|
|
|
P2PKConditionsNotMet(String),
|
|
P2PKConditionsNotMet(String),
|
|
|
|
|
+ /// Duplicate signature from same pubkey in P2PK
|
|
|
|
|
+ #[error("Duplicate signature from same pubkey in P2PK")]
|
|
|
|
|
+ DuplicateSignatureError,
|
|
|
/// Spending Locktime not provided
|
|
/// Spending Locktime not provided
|
|
|
#[error("Spending condition locktime not provided")]
|
|
#[error("Spending condition locktime not provided")]
|
|
|
LocktimeNotProvided,
|
|
LocktimeNotProvided,
|
|
@@ -438,6 +441,16 @@ impl ErrorResponse {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/// Maps NUT11 errors to appropriate error codes
|
|
|
|
|
+fn map_nut11_error(nut11_error: &crate::nuts::nut11::Error) -> ErrorCode {
|
|
|
|
|
+ match nut11_error {
|
|
|
|
|
+ crate::nuts::nut11::Error::SignaturesNotProvided => ErrorCode::WitnessMissingOrInvalid,
|
|
|
|
|
+ crate::nuts::nut11::Error::InvalidSignature => ErrorCode::WitnessMissingOrInvalid,
|
|
|
|
|
+ crate::nuts::nut11::Error::DuplicateSignature => ErrorCode::DuplicateSignature,
|
|
|
|
|
+ _ => ErrorCode::Unknown(9999), // Parsing/validation errors
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
impl From<Error> for ErrorResponse {
|
|
impl From<Error> for ErrorResponse {
|
|
|
fn from(err: Error) -> ErrorResponse {
|
|
fn from(err: Error) -> ErrorResponse {
|
|
|
match err {
|
|
match err {
|
|
@@ -555,6 +568,23 @@ impl From<Error> for ErrorResponse {
|
|
|
error: Some(err.to_string()),
|
|
error: Some(err.to_string()),
|
|
|
detail: None
|
|
detail: None
|
|
|
},
|
|
},
|
|
|
|
|
+ Error::NUT11(err) => {
|
|
|
|
|
+ let code = map_nut11_error(&err);
|
|
|
|
|
+ let mut detail = None;
|
|
|
|
|
+ if matches!(err, crate::nuts::nut11::Error::SignaturesNotProvided) {
|
|
|
|
|
+ detail = Some("P2PK signatures are required but not provided".to_string());
|
|
|
|
|
+ }
|
|
|
|
|
+ ErrorResponse {
|
|
|
|
|
+ code,
|
|
|
|
|
+ error: Some(err.to_string()),
|
|
|
|
|
+ detail,
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ Error::DuplicateSignatureError => ErrorResponse {
|
|
|
|
|
+ code: ErrorCode::DuplicateSignature,
|
|
|
|
|
+ error: Some(err.to_string()),
|
|
|
|
|
+ detail: None,
|
|
|
|
|
+ },
|
|
|
_ => ErrorResponse {
|
|
_ => ErrorResponse {
|
|
|
code: ErrorCode::Unknown(9999),
|
|
code: ErrorCode::Unknown(9999),
|
|
|
error: Some(err.to_string()),
|
|
error: Some(err.to_string()),
|
|
@@ -612,6 +642,7 @@ impl From<ErrorResponse> for Error {
|
|
|
ErrorCode::UnitMismatch => Self::UnitMismatch,
|
|
ErrorCode::UnitMismatch => Self::UnitMismatch,
|
|
|
ErrorCode::ClearAuthRequired => Self::ClearAuthRequired,
|
|
ErrorCode::ClearAuthRequired => Self::ClearAuthRequired,
|
|
|
ErrorCode::BlindAuthRequired => Self::BlindAuthRequired,
|
|
ErrorCode::BlindAuthRequired => Self::BlindAuthRequired,
|
|
|
|
|
+ ErrorCode::DuplicateSignature => Self::DuplicateSignatureError,
|
|
|
_ => Self::UnknownErrorResponse(err.to_string()),
|
|
_ => Self::UnknownErrorResponse(err.to_string()),
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -671,6 +702,8 @@ pub enum ErrorCode {
|
|
|
BlindAuthRequired,
|
|
BlindAuthRequired,
|
|
|
/// Blind Auth Failed
|
|
/// Blind Auth Failed
|
|
|
BlindAuthFailed,
|
|
BlindAuthFailed,
|
|
|
|
|
+ /// Duplicate signature from same pubkey
|
|
|
|
|
+ DuplicateSignature,
|
|
|
/// Unknown error code
|
|
/// Unknown error code
|
|
|
Unknown(u16),
|
|
Unknown(u16),
|
|
|
}
|
|
}
|
|
@@ -700,6 +733,7 @@ impl ErrorCode {
|
|
|
20006 => Self::InvoiceAlreadyPaid,
|
|
20006 => Self::InvoiceAlreadyPaid,
|
|
|
20007 => Self::QuoteExpired,
|
|
20007 => Self::QuoteExpired,
|
|
|
20008 => Self::WitnessMissingOrInvalid,
|
|
20008 => Self::WitnessMissingOrInvalid,
|
|
|
|
|
+ 20009 => Self::DuplicateSignature,
|
|
|
30001 => Self::ClearAuthRequired,
|
|
30001 => Self::ClearAuthRequired,
|
|
|
30002 => Self::ClearAuthFailed,
|
|
30002 => Self::ClearAuthFailed,
|
|
|
31001 => Self::BlindAuthRequired,
|
|
31001 => Self::BlindAuthRequired,
|
|
@@ -732,6 +766,7 @@ impl ErrorCode {
|
|
|
Self::InvoiceAlreadyPaid => 20006,
|
|
Self::InvoiceAlreadyPaid => 20006,
|
|
|
Self::QuoteExpired => 20007,
|
|
Self::QuoteExpired => 20007,
|
|
|
Self::WitnessMissingOrInvalid => 20008,
|
|
Self::WitnessMissingOrInvalid => 20008,
|
|
|
|
|
+ Self::DuplicateSignature => 20009,
|
|
|
Self::ClearAuthRequired => 30001,
|
|
Self::ClearAuthRequired => 30001,
|
|
|
Self::ClearAuthFailed => 30002,
|
|
Self::ClearAuthFailed => 30002,
|
|
|
Self::BlindAuthRequired => 31001,
|
|
Self::BlindAuthRequired => 31001,
|