From fd8b29c831d803ce6398b00b5bbcbbd7cf354067 Mon Sep 17 00:00:00 2001 From: thesimplekid Date: Tue, 22 Oct 2024 14:19:52 +0100 Subject: [PATCH] feat: payment request payload --- crates/cdk/src/nuts/mod.rs | 2 +- crates/cdk/src/nuts/nut18.rs | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/crates/cdk/src/nuts/mod.rs b/crates/cdk/src/nuts/mod.rs index d0ca745e7..07518bff1 100644 --- a/crates/cdk/src/nuts/mod.rs +++ b/crates/cdk/src/nuts/mod.rs @@ -47,4 +47,4 @@ pub use nut11::{Conditions, P2PKWitness, SigFlag, SpendingConditions}; pub use nut12::{BlindSignatureDleq, ProofDleq}; pub use nut14::HTLCWitness; pub use nut15::{Mpp, MppMethodSettings, Settings as NUT15Settings}; -pub use nut18::{PaymentRequest, Transport}; +pub use nut18::{PaymentRequest, PaymentRequestPayload, Transport}; diff --git a/crates/cdk/src/nuts/nut18.rs b/crates/cdk/src/nuts/nut18.rs index 9a5478509..dcf2936e6 100644 --- a/crates/cdk/src/nuts/nut18.rs +++ b/crates/cdk/src/nuts/nut18.rs @@ -14,7 +14,7 @@ use thiserror::Error; use crate::{mint_url::MintUrl, Amount}; -use super::CurrencyUnit; +use super::{CurrencyUnit, Proofs}; const PAYMENT_REQUEST_PREFIX: &str = "creqA"; @@ -33,7 +33,7 @@ pub enum Error { } /// Transport Type -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, Serialize, Deserialize)] pub enum TransportType { /// Nostr #[serde(rename = "nostr")] @@ -58,7 +58,7 @@ impl FromStr for Transport { } /// Transport -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize, Deserialize)] pub struct Transport { /// Type #[serde(rename = "t")] @@ -72,7 +72,7 @@ pub struct Transport { } /// Payment Request -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize, Deserialize)] pub struct PaymentRequest { /// `Payment id` #[serde(rename = "i")] @@ -123,6 +123,21 @@ impl FromStr for PaymentRequest { } } +/// Payment Request +#[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize, Deserialize)] +pub struct PaymentRequestPayload { + /// Id + pub id: Option, + /// Memo + pub memo: Option, + /// Mint + pub mint: MintUrl, + /// Unit + pub unit: CurrencyUnit, + /// Proofs + pub proofs: Proofs, +} + #[cfg(test)] mod tests { use std::str::FromStr;