fedimint_lnv2_common/
lnurl.rs

1use bitcoin::secp256k1::PublicKey;
2use fedimint_core::config::FederationId;
3use fedimint_core::encoding::{Decodable, Encodable};
4use fedimint_core::util::SafeUrl;
5use lnurl::lnurl::LnUrl;
6use serde::{Deserialize, Serialize};
7use tpe::AggregatePublicKey;
8
9#[derive(Debug, Clone, Serialize, Deserialize, Encodable, Decodable)]
10pub struct LnurlRequest {
11    pub federation_id: FederationId,
12    pub recipient_pk: PublicKey,
13    pub aggregate_pk: AggregatePublicKey,
14    pub gateways: Vec<SafeUrl>,
15}
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
18pub struct LnurlResponse {
19    pub lnurl: String,
20}
21
22pub async fn generate_lnurl(
23    recurringd: SafeUrl,
24    federation_id: FederationId,
25    recipient_pk: PublicKey,
26    aggregate_pk: AggregatePublicKey,
27    gateways: Vec<SafeUrl>,
28) -> anyhow::Result<String> {
29    let payload = LnurlRequest {
30        federation_id,
31        recipient_pk,
32        aggregate_pk,
33        gateways,
34    };
35
36    let response = reqwest::Client::new()
37        .post(format!("{recurringd}lnurl"))
38        .json(&payload)
39        .send()
40        .await?
41        .json::<LnurlResponse>()
42        .await?;
43
44    Ok(LnUrl::from_url(response.lnurl).encode())
45}
46
47#[derive(Debug, Clone, Serialize, Deserialize)]
48pub struct VerifyResponse {
49    pub status: String,
50    pub settled: bool,
51    pub preimage: Option<[u8; 32]>,
52}