lightspark_remote_signing/
lib.rs

1// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2//! Lightspark Remote Signing Library is a library to handle lightspark remote signing webhook
3//! events.
4//!
5//! For most cases, you will want to use the `handler::Handler` to handle the remote signing webhook
6//! event you get from lightspark. The handler will process the request, and form a response that
7//! you can send back to lightspark through Lightspark SDK.
8//!
9//! This crates also provides a `signer::LightsparkSigner` that can be used to sign transactions.
10use std::fmt;
11
12pub extern crate lightspark;
13pub mod handler;
14pub mod invoice;
15pub mod response;
16pub mod signer;
17pub mod validation;
18
19#[derive(Debug)]
20pub enum Error {
21    WebhookEventNotRemoteSigning,
22    WebhookEventDataMissing,
23    UnknownSubEventType,
24    PublicKeyDecodeError(hex::FromHexError),
25    HexEncodingError,
26    SignerError(signer::Error),
27}
28
29impl fmt::Display for Error {
30    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31        let msg = match self {
32            Error::WebhookEventNotRemoteSigning => {
33                "Webhook event is not a remote signing event".to_string()
34            }
35            Error::WebhookEventDataMissing => "Webhook event data is missing".to_string(),
36            Error::UnknownSubEventType => "Unknown sub event type".to_string(),
37            Error::PublicKeyDecodeError(e) => format!("Error decoding public key: {}", e),
38            Error::HexEncodingError => "Error encoding hex".to_string(),
39            Error::SignerError(e) => format!("Error signing: {}", e),
40        };
41        write!(f, "{}", msg)
42    }
43}