diff --git a/crates/cdk-cli/src/sub_commands/mint.rs b/crates/cdk-cli/src/sub_commands/mint.rs index f6f4329c..11771fdf 100644 --- a/crates/cdk-cli/src/sub_commands/mint.rs +++ b/crates/cdk-cli/src/sub_commands/mint.rs @@ -6,7 +6,7 @@ use anyhow::Result; use cdk::amount::SplitTarget; use cdk::cdk_database::{Error, WalletDatabase}; use cdk::mint_url::MintUrl; -use cdk::nuts::{CurrencyUnit, MintQuoteState, PaymentMethod}; +use cdk::nuts::{CurrencyUnit, MintQuoteState, PaymentMethod, SecretKey}; use cdk::wallet::multi_mint_wallet::WalletKey; use cdk::wallet::{MultiMintWallet, Wallet}; use clap::Args; @@ -57,6 +57,8 @@ pub async fn mint( } }; + let secret_key = SecretKey::generate(); + let method = PaymentMethod::from_str(&sub_command_args.method)?; let quote = match method { @@ -69,8 +71,7 @@ pub async fn mint( .expect("Amount must be defined") .into(), description, - // TODO: Get pubkey - None, + Some(secret_key.public_key()), ) .await? } @@ -81,6 +82,7 @@ pub async fn mint( description, sub_command_args.single_use.unwrap_or(false), sub_command_args.expiry, + secret_key.public_key(), ) .await? } diff --git a/crates/cdk/src/mint/mint_18.rs b/crates/cdk/src/mint/mint_20.rs similarity index 96% rename from crates/cdk/src/mint/mint_18.rs rename to crates/cdk/src/mint/mint_20.rs index 0641b913..72fcaa9c 100644 --- a/crates/cdk/src/mint/mint_18.rs +++ b/crates/cdk/src/mint/mint_20.rs @@ -18,6 +18,7 @@ impl Mint { description, single_use, expiry, + pubkey, } = mint_quote_request; let nut18 = &self @@ -68,8 +69,7 @@ impl Mint { Amount::ZERO, single_use, vec![], - // TODO: Add pubkey to request - None, + Some(pubkey), ); tracing::debug!( @@ -82,7 +82,7 @@ impl Mint { self.localstore.add_mint_quote(quote.clone()).await?; - Ok(quote.into()) + Ok(quote.try_into()?) } /// Check mint quote @@ -97,6 +97,6 @@ impl Mint { .await? .ok_or(Error::UnknownQuote)?; - Ok(quote.into()) + Ok(quote.try_into()?) } } diff --git a/crates/cdk/src/mint/mod.rs b/crates/cdk/src/mint/mod.rs index 8d47378f..42eaf8b5 100644 --- a/crates/cdk/src/mint/mod.rs +++ b/crates/cdk/src/mint/mod.rs @@ -30,7 +30,7 @@ mod check_spendable; mod info; mod keysets; mod melt; -mod mint_18; +mod mint_20; mod mint_nut04; mod start_up_check; mod swap; diff --git a/crates/cdk/src/nuts/nut20.rs b/crates/cdk/src/nuts/nut20.rs index a1552900..a3429c9a 100644 --- a/crates/cdk/src/nuts/nut20.rs +++ b/crates/cdk/src/nuts/nut20.rs @@ -6,6 +6,7 @@ use serde::{Deserialize, Serialize}; use thiserror::Error; use super::nut00::CurrencyUnit; +use super::PublicKey; use crate::Amount; /// NUT04 Error @@ -17,6 +18,9 @@ pub enum Error { /// Amount overflow #[error("Amount overflow")] AmountOverflow, + /// Publickey not defined + #[error("Publickey not defined")] + PublickeyUndefined, } /// Mint quote request [NUT-19] @@ -32,6 +36,8 @@ pub struct MintQuoteBolt12Request { pub single_use: bool, /// Expiry pub expiry: Option, + /// Pubkey + pub pubkey: PublicKey, } /// Mint quote response [NUT-19] @@ -49,18 +55,23 @@ pub struct MintQuoteBolt12Response { pub amount_paid: Amount, /// Amount that has been issued pub amount_issued: Amount, + /// Pubkey + pub pubkey: PublicKey, } #[cfg(feature = "mint")] -impl From for MintQuoteBolt12Response { - fn from(mint_quote: crate::mint::MintQuote) -> MintQuoteBolt12Response { - MintQuoteBolt12Response { +impl TryFrom for MintQuoteBolt12Response { + type Error = Error; + + fn try_from(mint_quote: crate::mint::MintQuote) -> Result { + Ok(MintQuoteBolt12Response { quote: mint_quote.id, request: mint_quote.request, expiry: Some(mint_quote.expiry), amount_paid: mint_quote.amount_paid, amount_issued: mint_quote.amount_issued, single_use: mint_quote.single_use, - } + pubkey: mint_quote.pubkey.ok_or(Error::PublickeyUndefined)?, + }) } } diff --git a/crates/cdk/src/wallet/mint_bolt12.rs b/crates/cdk/src/wallet/mint_bolt12.rs index 60d14832..18c808a7 100644 --- a/crates/cdk/src/wallet/mint_bolt12.rs +++ b/crates/cdk/src/wallet/mint_bolt12.rs @@ -6,7 +6,7 @@ use crate::dhke::construct_proofs; use crate::nuts::nut00::ProofsMethods; use crate::nuts::{ nut12, MintBolt11Request, MintQuoteBolt12Request, MintQuoteBolt12Response, PaymentMethod, - PreMintSecrets, SpendingConditions, State, + PreMintSecrets, PublicKey, SpendingConditions, State, }; use crate::types::ProofInfo; use crate::util::unix_time; @@ -21,6 +21,7 @@ impl Wallet { description: Option, single_use: bool, expiry: Option, + pubkey: PublicKey, ) -> Result { let mint_url = self.mint_url.clone(); let unit = &self.unit; @@ -48,6 +49,7 @@ impl Wallet { description, single_use, expiry, + pubkey, }; let quote_res = self