use serde_json::Value;
use crate::pc20::tlv::Record;
pub use crate::svix::webhooks::{HeaderMap, WebhookError as Error};
pub fn verify_signature<HM: HeaderMap>(
secret: &str,
payload: &[u8],
headers: &HM,
) -> Result<(), Error> {
crate::svix::webhooks::Webhook::new(secret)?.verify(payload, headers)
}
#[derive(Debug, serde::Deserialize, Clone)]
pub struct AlbyInvoice {
pub identifier: String,
#[serde(rename = "type")]
pub type_: String,
#[serde(default)]
pub memo: Option<String>,
pub state: String,
#[serde(default)]
pub metadata: Value,
#[serde(default)]
pub payer_name: Option<String>,
#[serde(rename = "amount")]
pub num_sats: u64,
pub created_at: chrono::DateTime<chrono::Utc>,
#[serde(
default,
deserialize_with = "crate::pc20::tlv::deserialize_untrusted_tlv_record"
)]
pub boostagram: Option<Record>,
}
pub fn extract_alby_invoice(body: &Value) -> Result<AlbyInvoice, String> {
serde_json::from_value(body.clone()).map_err(|e| e.to_string())
}