diff --git a/crates/cdk-cli/src/sub_commands/create_request.rs b/crates/cdk-cli/src/sub_commands/create_request.rs index a973d794..fe1a4050 100644 --- a/crates/cdk-cli/src/sub_commands/create_request.rs +++ b/crates/cdk-cli/src/sub_commands/create_request.rs @@ -1,6 +1,9 @@ use anyhow::Result; use cdk::nuts::nut18::TransportType; -use cdk::nuts::{CurrencyUnit, PaymentRequest, PaymentRequestPayload, Token, Transport}; +use cdk::nuts::{ + CurrencyUnit, PaymentRequest, PaymentRequestPayload, PublicKey as CdkPublicKey, Token, + Transport, +}; use cdk::wallet::MultiMintWallet; use clap::Args; use nostr_sdk::nips::nip19::Nip19Profile; @@ -14,6 +17,9 @@ pub struct CreateRequestSubCommand { /// Currency unit e.g. sat #[arg(default_value = "sat")] unit: String, + /// Public key + #[arg(short, long)] + pubkey: Option, /// Quote description description: Option, } @@ -48,6 +54,7 @@ pub async fn create_request( mints: Some(mints), description: sub_command_args.description.clone(), transports: vec![nostr_transport], + public_key: sub_command_args.pubkey, }; println!("{}", req); diff --git a/crates/cdk-cli/src/sub_commands/pay_request.rs b/crates/cdk-cli/src/sub_commands/pay_request.rs index a003072c..13b26c41 100644 --- a/crates/cdk-cli/src/sub_commands/pay_request.rs +++ b/crates/cdk-cli/src/sub_commands/pay_request.rs @@ -3,7 +3,7 @@ use std::io::{self, Write}; use anyhow::{anyhow, Result}; use cdk::amount::SplitTarget; use cdk::nuts::nut18::TransportType; -use cdk::nuts::{PaymentRequest, PaymentRequestPayload}; +use cdk::nuts::{PaymentRequest, PaymentRequestPayload, SpendingConditions}; use cdk::wallet::{MultiMintWallet, SendKind}; use clap::Args; use nostr_sdk::nips::nip19::Nip19Profile; @@ -81,11 +81,15 @@ pub async fn pay_request( }) .ok_or(anyhow!("No supported transport method found"))?; + let conditions = payment_request + .public_key + .map(|pk| SpendingConditions::new_p2pk(pk, None)); + let proofs = matching_wallet .send( amount, None, - None, + conditions, &SplitTarget::default(), &SendKind::default(), true, diff --git a/crates/cdk/src/nuts/nut18.rs b/crates/cdk/src/nuts/nut18.rs index 170af17d..71bfbf90 100644 --- a/crates/cdk/src/nuts/nut18.rs +++ b/crates/cdk/src/nuts/nut18.rs @@ -10,7 +10,7 @@ use bitcoin::base64::{alphabet, Engine}; use serde::{Deserialize, Serialize}; use thiserror::Error; -use super::{CurrencyUnit, Proofs}; +use super::{CurrencyUnit, Proofs, PublicKey}; use crate::mint_url::MintUrl; use crate::Amount; @@ -95,6 +95,9 @@ pub struct PaymentRequest { /// Transport #[serde(rename = "t")] pub transports: Vec, + /// Public key + #[serde(rename = "p")] + pub public_key: Option, } impl fmt::Display for PaymentRequest { @@ -180,6 +183,7 @@ mod tests { mints: Some(vec!["https://nofees.testnut.cashu.space".parse()?]), description: None, transports: vec![transport.clone()], + public_key: None, }; let request_str = request.to_string();