Skip to main content

breez_sdk_spark/common/
models.rs

1use serde::{Deserialize, Serialize};
2use thiserror::Error;
3
4#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
5#[macros::derive_from(breez_sdk_common::network::BitcoinNetwork)]
6#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
7pub enum BitcoinNetwork {
8    /// Mainnet
9    Bitcoin,
10    Testnet3,
11    Testnet4,
12    Signet,
13    Regtest,
14}
15
16#[derive(Clone, Debug, Error)]
17#[macros::derive_from(breez_sdk_common::input::ParseError)]
18pub enum ParseError {
19    #[error("empty input")]
20    EmptyInput,
21    #[error(
22        "input is longer than {} bytes",
23        breez_sdk_common::input::MAX_INPUT_LENGTH
24    )]
25    InputTooLong,
26    #[error("Bip-21 error: {0}")]
27    Bip21Error(Bip21Error),
28    #[error("invalid input")]
29    InvalidInput,
30    #[error("Lnurl error: {0}")]
31    LnurlError(LnurlError),
32    #[error("Service connectivity error: {0}")]
33    ServiceConnectivity(ServiceConnectivityError),
34    #[error("Invalid external input parser: {0}")]
35    InvalidExternalInputParser(String),
36}
37
38#[derive(Clone, Debug, Error)]
39#[macros::derive_from(breez_sdk_common::input::Bip21Error)]
40pub enum Bip21Error {
41    #[error("bip21 contains invalid address")]
42    InvalidAddress,
43    #[error("bip21 contains invalid amount")]
44    InvalidAmount,
45    #[error("bip21 contains invalid parameter value for '{0}'")]
46    InvalidParameter(String),
47    #[error("bip21 contains parameter '{0}' multiple times")]
48    MultipleParams(String),
49    #[error("bip21 contains unknown required parameter '{0}'")]
50    UnknownRequiredParameter(String),
51    #[error("bip21 does not contain any payment methods")]
52    NoPaymentMethods,
53    #[error(
54        "bip21 contains more than {} payment methods",
55        breez_sdk_common::input::MAX_PAYMENT_METHODS
56    )]
57    TooManyPaymentMethods,
58}
59
60#[derive(Clone, Debug, Error)]
61#[macros::derive_from(breez_sdk_common::lnurl::error::LnurlError)]
62pub enum LnurlError {
63    #[error("lnurl missing k1 parameter")]
64    MissingK1,
65    #[error("lnurl contains invalid k1 parameter")]
66    InvalidK1,
67    #[error("lnurl contains unsupported action")]
68    UnsupportedAction,
69    #[error("lnurl missing domain")]
70    MissingDomain,
71    #[error("error calling lnurl endpoint: {0}")]
72    ServiceConnectivity(#[from] ServiceConnectivityError),
73    #[error("endpoint error: {0}")]
74    EndpointError(String),
75    #[error("lnurl has http scheme without onion domain")]
76    HttpSchemeWithoutOnionDomain,
77    #[error("lnurl has https scheme with onion domain")]
78    HttpsSchemeWithOnionDomain,
79    #[error("lnurl error: {0}")]
80    General(String),
81    #[error("lnurl has unknown scheme")]
82    UnknownScheme,
83    #[error("lnurl has invalid uri: {0}")]
84    InvalidUri(String),
85    #[error("lnurl has invalid invoice: {0}")]
86    InvalidInvoice(String),
87    #[error("lnurl has invalid response: {0}")]
88    InvalidResponse(String),
89}
90
91#[derive(Clone, Debug, Error)]
92#[macros::derive_from(breez_sdk_common::error::ServiceConnectivityError)]
93#[macros::derive_into(breez_sdk_common::error::ServiceConnectivityError)]
94#[cfg_attr(feature = "uniffi", derive(uniffi::Error))]
95pub enum ServiceConnectivityError {
96    #[error("Builder error: {0}")]
97    Builder(String),
98    #[error("Redirect error: {0}")]
99    Redirect(String),
100    #[error("Status error: {status} - {body}")]
101    Status { status: u16, body: String },
102    #[error("Timeout error: {0}")]
103    Timeout(String),
104    #[error("Request error: {0}")]
105    Request(String),
106    #[error("Connect error: {0}")]
107    Connect(String),
108    #[error("Body error: {0}")]
109    Body(String),
110    #[error("Decode error: {0}")]
111    Decode(String),
112    #[error("Json error: {0}")]
113    Json(String),
114    #[error("Other error: {0}")]
115    Other(String),
116}
117
118#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
119#[macros::derive_from(breez_sdk_common::input::Amount)]
120#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
121pub enum Amount {
122    Bitcoin {
123        amount_msat: u64,
124    },
125    /// An amount of currency specified using ISO 4712.
126    Currency {
127        /// The currency that the amount is denominated in.
128        iso4217_code: String,
129        /// The amount in the currency unit adjusted by the ISO 4712 exponent (e.g., USD cents).
130        fractional_amount: u64,
131    },
132}
133
134#[derive(Clone, Debug, Default, Deserialize, Serialize)]
135#[macros::derive_from(breez_sdk_common::input::Bip21Details)]
136#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
137pub struct Bip21Details {
138    pub amount_sat: Option<u64>,
139    pub asset_id: Option<String>,
140    pub uri: String,
141    pub extras: Vec<Bip21Extra>,
142    pub label: Option<String>,
143    pub message: Option<String>,
144    pub payment_methods: Vec<InputType>,
145}
146
147#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
148#[macros::derive_from(breez_sdk_common::input::Bip21Extra)]
149#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
150pub struct Bip21Extra {
151    pub key: String,
152    pub value: String,
153}
154
155#[derive(Clone, Debug, Deserialize, Serialize)]
156#[macros::derive_from(breez_sdk_common::input::BitcoinAddressDetails)]
157#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
158pub struct BitcoinAddressDetails {
159    pub address: String,
160    pub network: BitcoinNetwork,
161    pub source: PaymentRequestSource,
162}
163
164#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
165#[macros::derive_from(breez_sdk_common::input::Bolt11Invoice)]
166#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
167pub struct Bolt11Invoice {
168    pub bolt11: String,
169    pub source: PaymentRequestSource,
170}
171
172#[derive(Clone, Default, Debug, PartialEq, Eq, Serialize, Deserialize)]
173#[macros::derive_from(breez_sdk_common::input::Bolt11RouteHint)]
174#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
175pub struct Bolt11RouteHint {
176    pub hops: Vec<Bolt11RouteHintHop>,
177}
178
179#[derive(Clone, Default, Debug, PartialEq, Eq, Serialize, Deserialize)]
180#[macros::derive_from(breez_sdk_common::input::Bolt11RouteHintHop)]
181#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
182pub struct Bolt11RouteHintHop {
183    /// The `node_id` of the non-target end of the route
184    pub src_node_id: String,
185    /// The `short_channel_id` of this channel
186    pub short_channel_id: String,
187    /// The fees which must be paid to use this channel
188    pub fees_base_msat: u32,
189    pub fees_proportional_millionths: u32,
190
191    /// The difference in CLTV values between this node and the next node.
192    pub cltv_expiry_delta: u16,
193    /// The minimum value, in msat, which must be relayed to the next hop.
194    pub htlc_minimum_msat: Option<u64>,
195    /// The maximum value in msat available for routing with a single HTLC.
196    pub htlc_maximum_msat: Option<u64>,
197}
198
199#[derive(Clone, Debug, Deserialize, Serialize)]
200#[macros::derive_from(breez_sdk_common::input::Bolt12Invoice)]
201#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
202pub struct Bolt12Invoice {
203    pub invoice: String,
204    pub source: PaymentRequestSource,
205}
206
207#[derive(Clone, Debug, Deserialize, Serialize)]
208#[macros::derive_from(breez_sdk_common::input::Bolt12InvoiceRequestDetails)]
209#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
210pub struct Bolt12InvoiceRequestDetails {
211    // TODO: Fill fields
212}
213
214#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
215#[macros::derive_from(breez_sdk_common::input::Bolt12OfferBlindedPath)]
216#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
217pub struct Bolt12OfferBlindedPath {
218    pub blinded_hops: Vec<String>,
219}
220
221#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
222#[macros::derive_from(breez_sdk_common::input::Bolt11InvoiceDetails)]
223#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
224pub struct Bolt11InvoiceDetails {
225    pub amount_msat: Option<u64>,
226    pub description: Option<String>,
227    pub description_hash: Option<String>,
228    pub expiry: u64,
229    pub invoice: Bolt11Invoice,
230    pub min_final_cltv_expiry_delta: u64,
231    pub network: BitcoinNetwork,
232    pub payee_pubkey: String,
233    pub payment_hash: String,
234    pub payment_secret: String,
235    pub routing_hints: Vec<Bolt11RouteHint>,
236    pub timestamp: u64,
237}
238
239#[derive(Clone, Debug, Deserialize, Serialize)]
240#[macros::derive_from(breez_sdk_common::input::Bolt12InvoiceDetails)]
241#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
242pub struct Bolt12InvoiceDetails {
243    pub amount_msat: u64,
244    pub invoice: Bolt12Invoice,
245}
246
247#[derive(Clone, Debug, Deserialize, Serialize)]
248#[macros::derive_from(breez_sdk_common::input::Bolt12Offer)]
249#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
250pub struct Bolt12Offer {
251    pub offer: String,
252    pub source: PaymentRequestSource,
253}
254
255#[derive(Clone, Debug, Deserialize, Serialize)]
256#[macros::derive_from(breez_sdk_common::input::Bolt12OfferDetails)]
257#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
258pub struct Bolt12OfferDetails {
259    pub absolute_expiry: Option<u64>,
260    pub chains: Vec<String>,
261    pub description: Option<String>,
262    pub issuer: Option<String>,
263    pub min_amount: Option<Amount>,
264    pub offer: Bolt12Offer,
265    pub paths: Vec<Bolt12OfferBlindedPath>,
266    pub signing_pubkey: Option<String>,
267}
268
269#[derive(Clone, Debug, Deserialize, Serialize)]
270#[macros::derive_from(breez_sdk_common::input::InputType)]
271#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
272pub enum InputType {
273    BitcoinAddress(BitcoinAddressDetails),
274    Bolt11Invoice(Bolt11InvoiceDetails),
275    Bolt12Invoice(Bolt12InvoiceDetails),
276    Bolt12Offer(Bolt12OfferDetails),
277    LightningAddress(LightningAddressDetails),
278    LnurlPay(LnurlPayRequestDetails),
279    SilentPaymentAddress(BitcoinAddressDetails),
280    LnurlAuth(LnurlAuthRequestDetails),
281    Url(String),
282    Bip21(Bip21Details),
283    Bolt12InvoiceRequest(Bolt12InvoiceRequestDetails),
284    LnurlWithdraw(LnurlWithdrawRequestDetails),
285    SparkAddress(SparkAddressDetails),
286    SparkInvoice(SparkInvoiceDetails),
287    CrossChainAddress(CrossChainAddressDetails),
288}
289
290#[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq, Eq)]
291#[macros::derive_from(breez_sdk_common::input::CrossChainAddressFamily)]
292#[macros::derive_into(breez_sdk_common::input::CrossChainAddressFamily)]
293#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
294#[serde(rename_all = "snake_case")]
295pub enum CrossChainAddressFamily {
296    Evm,
297    Solana,
298    Tron,
299    Xrp,
300    Zcash,
301}
302
303#[derive(Clone, Debug, Deserialize, Serialize)]
304#[macros::derive_from(breez_sdk_common::input::CrossChainAddressDetails)]
305#[macros::derive_into(breez_sdk_common::input::CrossChainAddressDetails)]
306#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
307pub struct CrossChainAddressDetails {
308    pub address: String,
309    pub address_family: CrossChainAddressFamily,
310    pub contract_address: Option<String>,
311    pub chain_id: Option<u64>,
312    pub amount: Option<u128>,
313}
314
315#[derive(Clone, Debug, Deserialize, Serialize)]
316#[macros::derive_from(breez_sdk_common::lnurl::pay::LnurlPayRequestDetails)]
317#[macros::derive_into(breez_sdk_common::lnurl::pay::LnurlPayRequestDetails)]
318#[serde(rename_all = "camelCase")]
319#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
320pub struct LnurlPayRequestDetails {
321    pub callback: String,
322    /// The minimum amount, in millisats, that this LNURL-pay endpoint accepts
323    pub min_sendable: u64,
324    /// The maximum amount, in millisats, that this LNURL-pay endpoint accepts
325    pub max_sendable: u64,
326    /// As per LUD-06, `metadata` is a raw string (e.g. a json representation of the inner map).
327    /// Use `metadata_vec()` to get the parsed items.
328    #[serde(rename(deserialize = "metadata"))]
329    pub metadata_str: String,
330    /// The comment length accepted by this endpoint
331    ///
332    /// See <https://github.com/lnurl/luds/blob/luds/12.md>
333    #[serde(default)]
334    pub comment_allowed: u16,
335
336    /// Indicates the domain of the LNURL-pay service, to be shown to the user when asking for
337    /// payment input, as per LUD-06 spec.
338    ///
339    /// Note: this is not the domain of the callback, but the domain of the LNURL-pay endpoint.
340    #[serde(skip)]
341    pub domain: String,
342
343    #[serde(skip)]
344    pub url: String,
345
346    /// Optional lightning address if that was used to resolve the lnurl.
347    #[serde(skip)]
348    pub address: Option<String>,
349
350    /// Value indicating whether the recipient supports Nostr Zaps through NIP-57.
351    ///
352    /// See <https://github.com/nostr-protocol/nips/blob/master/57.md>
353    pub allows_nostr: Option<bool>,
354    /// Optional recipient's lnurl provider's Nostr pubkey for NIP-57. If it exists it should be a
355    /// valid BIP 340 public key in hex.
356    ///
357    /// See <https://github.com/nostr-protocol/nips/blob/master/57.md>
358    /// See <https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki>
359    pub nostr_pubkey: Option<String>,
360}
361
362/// Wrapped in a [`InputType::LnurlAuth`], this is the result of parsing a LNURL-auth endpoint.
363///
364/// It represents the endpoint's parameters for the LNURL workflow.
365///
366/// See <https://github.com/lnurl/luds/blob/luds/04.md>
367#[derive(Clone, Debug, Deserialize, Serialize)]
368#[macros::derive_from(breez_sdk_common::lnurl::auth::LnurlAuthRequestDetails)]
369#[macros::derive_into(breez_sdk_common::lnurl::auth::LnurlAuthRequestDetails)]
370#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
371pub struct LnurlAuthRequestDetails {
372    /// Hex encoded 32 bytes of challenge
373    pub k1: String,
374
375    /// When available, one of: register, login, link, auth
376    pub action: Option<String>,
377
378    /// Indicates the domain of the LNURL-auth service, to be shown to the user when asking for
379    /// auth confirmation, as per LUD-04 spec.
380    #[serde(skip_serializing, skip_deserializing)]
381    pub domain: String,
382
383    /// Indicates the URL of the LNURL-auth service, including the query arguments. This will be
384    /// extended with the signed challenge and the linking key, then called in the second step of the workflow.
385    #[serde(skip_serializing, skip_deserializing)]
386    pub url: String,
387}
388
389/// LNURL error details
390#[derive(Clone, Debug, Deserialize, Serialize)]
391#[macros::derive_from(breez_sdk_common::lnurl::LnurlErrorDetails)]
392#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
393pub struct LnurlErrorDetails {
394    pub reason: String,
395}
396
397/// The response from a LNURL-auth callback, indicating success or failure.
398#[derive(Clone, Debug, Deserialize, Serialize)]
399#[macros::derive_from(breez_sdk_common::lnurl::LnurlCallbackStatus)]
400#[serde(rename_all = "UPPERCASE")]
401#[serde(tag = "status")]
402#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
403pub enum LnurlCallbackStatus {
404    /// On-wire format is: `{"status": "OK"}`
405    Ok,
406    /// On-wire format is: `{"status": "ERROR", "reason": "error details..."}`
407    #[serde(rename = "ERROR")]
408    ErrorStatus {
409        #[serde(flatten)]
410        error_details: LnurlErrorDetails,
411    },
412}
413
414#[derive(Clone, Debug, Deserialize, Serialize)]
415#[macros::derive_from(breez_sdk_common::lnurl::withdraw::LnurlWithdrawRequestDetails)]
416#[macros::derive_into(breez_sdk_common::lnurl::withdraw::LnurlWithdrawRequestDetails)]
417#[serde(rename_all = "camelCase")]
418#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
419pub struct LnurlWithdrawRequestDetails {
420    pub callback: String,
421    pub k1: String,
422    pub default_description: String,
423    /// The minimum amount, in millisats, that this LNURL-withdraw endpoint accepts
424    pub min_withdrawable: u64,
425    /// The maximum amount, in millisats, that this LNURL-withdraw endpoint accepts
426    pub max_withdrawable: u64,
427    /// The URL of the LNURL-withdraw endpoint these details were fetched from.
428    /// Set when the details come from parsing an input; determines how far the
429    /// withdraw flow trusts the endpoint-chosen `callback`. Absent or empty
430    /// means no exemption: the callback is held to the public-host rules.
431    #[serde(default)]
432    #[cfg_attr(feature = "uniffi", uniffi(default = ""))]
433    pub url: String,
434}
435
436#[derive(Clone, Debug, Deserialize, Serialize)]
437#[macros::derive_from(breez_sdk_common::input::SparkAddressDetails)]
438#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
439pub struct SparkAddressDetails {
440    /// The raw address string
441    pub address: String,
442    /// The identity public key of the address owner
443    pub identity_public_key: String,
444    pub network: BitcoinNetwork,
445    pub source: PaymentRequestSource,
446}
447
448#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
449#[macros::derive_from(breez_sdk_common::input::SparkInvoiceDetails)]
450#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
451pub struct SparkInvoiceDetails {
452    /// The raw invoice string
453    pub invoice: String,
454    /// The identity public key of the invoice issuer
455    pub identity_public_key: String,
456    pub network: BitcoinNetwork,
457    /// Optional amount denominated in sats if `token_identifier` is absent, otherwise in the token base units
458    pub amount: Option<u128>,
459    /// The token identifier of the token payment. Absence indicates a Bitcoin payment.
460    pub token_identifier: Option<String>,
461    /// Optional expiry time as a unix timestamp in seconds. If not provided, the invoice will never expire.
462    pub expiry_time: Option<u64>,
463    /// Optional description.
464    pub description: Option<String>,
465    /// If set, the invoice may only be fulfilled by a payer with this public key.
466    pub sender_public_key: Option<String>,
467}
468
469#[derive(Clone, Debug, Deserialize, Serialize)]
470#[macros::derive_from(breez_sdk_common::input::LightningAddressDetails)]
471#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
472pub struct LightningAddressDetails {
473    pub address: String,
474    pub pay_request: LnurlPayRequestDetails,
475}
476
477#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq)]
478#[macros::derive_from(breez_sdk_common::input::PaymentRequestSource)]
479#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
480pub struct PaymentRequestSource {
481    pub bip_21_uri: Option<String>,
482    pub bip_353_address: Option<String>,
483}
484
485/// Configuration for an external input parser
486#[derive(Debug, Clone, Serialize)]
487#[macros::derive_from(breez_sdk_common::input::ExternalInputParser)]
488#[macros::derive_into(breez_sdk_common::input::ExternalInputParser)]
489#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
490pub struct ExternalInputParser {
491    /// An arbitrary parser provider id
492    pub provider_id: String,
493    /// The external parser will be used when an input conforms to this regex
494    pub input_regex: String,
495    /// The URL of the parser containing a placeholder `<input>` that will be replaced with the
496    /// input to be parsed. The input is sanitized using percent encoding.
497    pub parser_url: String,
498}
499
500/// Supported success action types
501///
502/// Receiving any other (unsupported) success action type will result in a failed parsing,
503/// which will abort the LNURL-pay workflow, as per LUD-09.
504#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
505#[macros::derive_from(breez_sdk_common::lnurl::pay::SuccessAction)]
506#[macros::derive_into(breez_sdk_common::lnurl::pay::SuccessAction)]
507#[serde(rename_all = "camelCase")]
508#[serde(tag = "tag")]
509#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
510pub enum SuccessAction {
511    /// AES type, described in LUD-10
512    Aes {
513        #[serde(flatten)]
514        data: AesSuccessActionData,
515    },
516
517    /// Message type, described in LUD-09
518    Message {
519        #[serde(flatten)]
520        data: MessageSuccessActionData,
521    },
522
523    /// URL type, described in LUD-09
524    Url {
525        #[serde(flatten)]
526        data: UrlSuccessActionData,
527    },
528}
529
530/// [`SuccessAction`] where contents are ready to be consumed by the caller
531///
532/// Contents are identical to [`SuccessAction`], except for AES where the ciphertext is decrypted.
533#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
534#[macros::derive_from(breez_sdk_common::lnurl::pay::SuccessActionProcessed)]
535#[macros::derive_into(breez_sdk_common::lnurl::pay::SuccessActionProcessed)]
536#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
537pub enum SuccessActionProcessed {
538    /// See [`SuccessAction::Aes`] for received payload
539    ///
540    /// See [`AesSuccessActionDataDecrypted`] for decrypted payload
541    Aes { result: AesSuccessActionDataResult },
542
543    /// See [`SuccessAction::Message`]
544    Message { data: MessageSuccessActionData },
545
546    /// See [`SuccessAction::Url`]
547    Url { data: UrlSuccessActionData },
548}
549
550/// Payload of the AES success action, as received from the LNURL endpoint
551///
552/// See [`AesSuccessActionDataDecrypted`] for a similar wrapper containing the decrypted payload
553#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
554#[macros::derive_from(breez_sdk_common::lnurl::pay::AesSuccessActionData)]
555#[macros::derive_into(breez_sdk_common::lnurl::pay::AesSuccessActionData)]
556#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
557pub struct AesSuccessActionData {
558    /// Contents description, up to 144 characters
559    pub description: String,
560
561    /// Base64, AES-encrypted data where encryption key is payment preimage, up to 4kb of characters
562    pub ciphertext: String,
563
564    /// Base64, initialization vector, exactly 24 characters
565    pub iv: String,
566}
567
568/// Result of decryption of [`AesSuccessActionData`] payload
569#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
570#[macros::derive_from(breez_sdk_common::lnurl::pay::AesSuccessActionDataResult)]
571#[macros::derive_into(breez_sdk_common::lnurl::pay::AesSuccessActionDataResult)]
572#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
573pub enum AesSuccessActionDataResult {
574    Decrypted { data: AesSuccessActionDataDecrypted },
575    ErrorStatus { reason: String },
576}
577
578/// Wrapper for the decrypted [`AesSuccessActionData`] payload
579#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
580#[macros::derive_from(breez_sdk_common::lnurl::pay::AesSuccessActionDataDecrypted)]
581#[macros::derive_into(breez_sdk_common::lnurl::pay::AesSuccessActionDataDecrypted)]
582#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
583pub struct AesSuccessActionDataDecrypted {
584    /// Contents description, up to 144 characters
585    pub description: String,
586
587    /// Decrypted content
588    pub plaintext: String,
589}
590
591#[derive(PartialEq, Eq, Debug, Clone, Deserialize, Serialize)]
592#[macros::derive_from(breez_sdk_common::lnurl::pay::MessageSuccessActionData)]
593#[macros::derive_into(breez_sdk_common::lnurl::pay::MessageSuccessActionData)]
594#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
595pub struct MessageSuccessActionData {
596    pub message: String,
597}
598
599#[derive(PartialEq, Eq, Debug, Clone, Deserialize, Serialize)]
600#[macros::derive_from(breez_sdk_common::lnurl::pay::UrlSuccessActionData)]
601#[macros::derive_into(breez_sdk_common::lnurl::pay::UrlSuccessActionData)]
602#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
603pub struct UrlSuccessActionData {
604    /// Contents description, up to 144 characters
605    pub description: String,
606
607    /// URL of the success action
608    pub url: String,
609
610    /// Indicates the success URL domain matches the LNURL callback domain.
611    ///
612    /// See <https://github.com/lnurl/luds/blob/luds/09.md>
613    pub matches_callback_domain: bool,
614}
615
616#[cfg(test)]
617mod tests {
618    use super::LnurlWithdrawRequestDetails;
619
620    /// Withdraw details stored by older SDK versions carry no `url`; they must
621    /// keep deserializing, with the empty url falling back to strict callback
622    /// rules.
623    #[test]
624    fn withdraw_details_deserialize_without_url() {
625        let details: LnurlWithdrawRequestDetails = serde_json::from_str(
626            r#"{
627                "callback": "https://service.com/cb",
628                "k1": "abc",
629                "defaultDescription": "d",
630                "minWithdrawable": 1000,
631                "maxWithdrawable": 2000
632            }"#,
633        )
634        .unwrap();
635        assert_eq!(details.url, "");
636    }
637}