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 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 Currency {
127 iso4217_code: String,
129 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 pub src_node_id: String,
185 pub short_channel_id: String,
187 pub fees_base_msat: u32,
189 pub fees_proportional_millionths: u32,
190
191 pub cltv_expiry_delta: u16,
193 pub htlc_minimum_msat: Option<u64>,
195 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 }
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 pub min_sendable: u64,
324 pub max_sendable: u64,
326 #[serde(rename(deserialize = "metadata"))]
329 pub metadata_str: String,
330 #[serde(default)]
334 pub comment_allowed: u16,
335
336 #[serde(skip)]
341 pub domain: String,
342
343 #[serde(skip)]
344 pub url: String,
345
346 #[serde(skip)]
348 pub address: Option<String>,
349
350 pub allows_nostr: Option<bool>,
354 pub nostr_pubkey: Option<String>,
360}
361
362#[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 pub k1: String,
374
375 pub action: Option<String>,
377
378 #[serde(skip_serializing, skip_deserializing)]
381 pub domain: String,
382
383 #[serde(skip_serializing, skip_deserializing)]
386 pub url: String,
387}
388
389#[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#[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 Ok,
406 #[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 pub min_withdrawable: u64,
425 pub max_withdrawable: u64,
427 #[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 pub address: String,
442 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 pub invoice: String,
454 pub identity_public_key: String,
456 pub network: BitcoinNetwork,
457 pub amount: Option<u128>,
459 pub token_identifier: Option<String>,
461 pub expiry_time: Option<u64>,
463 pub description: Option<String>,
465 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#[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 pub provider_id: String,
493 pub input_regex: String,
495 pub parser_url: String,
498}
499
500#[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 {
513 #[serde(flatten)]
514 data: AesSuccessActionData,
515 },
516
517 Message {
519 #[serde(flatten)]
520 data: MessageSuccessActionData,
521 },
522
523 Url {
525 #[serde(flatten)]
526 data: UrlSuccessActionData,
527 },
528}
529
530#[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 Aes { result: AesSuccessActionDataResult },
542
543 Message { data: MessageSuccessActionData },
545
546 Url { data: UrlSuccessActionData },
548}
549
550#[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 pub description: String,
560
561 pub ciphertext: String,
563
564 pub iv: String,
566}
567
568#[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#[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 pub description: String,
586
587 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 pub description: String,
606
607 pub url: String,
609
610 pub matches_callback_domain: bool,
614}
615
616#[cfg(test)]
617mod tests {
618 use super::LnurlWithdrawRequestDetails;
619
620 #[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}